Skip to content

emerz3/OS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

2022 Daily schedule of OS Tranining Camp

Timeline

November

Mon Tues Wed Thur Fri Sat Sun
1
(D1)
2
(D2)
3
(D3)
4
(D4)
5
(D5)
6
(D6)
7
(D11)
8
(D8)
9
(D9)
10
(D10)
11
(D11)
12
(D12)
13
(D13)
14
(D14)
15
(D15)
16
(D16)
17
(D17)
18
(D18)
19
(D19)
20
(D20)
21
(D21)
22
(D22)
23
(D23)
24
(D24)
25
(D25)
26
(D26)
27
(D27)
28
(D28)
29
(D29)
30
(D30)

Day 1 2022/11/1

OS Tranining Camp

ไปŠๅคฉๅฌไบ†่€ๅธˆไปฌ็š„ๆŠฅๅ‘Š๏ผŒๆ„Ÿ่งฆ้ข‡ๅคš๏ผŒไน‹ๅ‰ๅญฆไน ่ฟ‡ไธ€ๆฎตๆ—ถ้—ด็š„Rust๏ผŒๅŒๆ—ถๅˆๆƒณๅฏนOSๆœ‰่พƒไธบๆทฑๅ…ฅ็š„ไบ†่งฃ๏ผŒๅŒ…ๆ‹ฌriscvใ€qemu็ญ‰็Ÿฅ่ฏ†๏ผŒ้‚ๅ†ณๅฎšๆŠฅๅๅ‚ๅŠ ็ง‹ๅ†ฌๅญฃOS่ฎญ็ปƒ่ฅใ€‚

ๅธŒๆœ›้€š่ฟ‡ๆœฌๆฌก็š„่ฎญ็ปƒ่ฅ๏ผŒๅœจๅ‰่พˆไปฌ็š„ๅธฎๅŠฉไธ‹๏ผŒ่ƒฝๅคŸๅฏนRustๅ’ŒOSๆœ‰ๆ›ด่ฟ›ไธ€ๆญฅ็š„่ฎค่ฏ†ใ€‚่™ฝ็„ถๅŽปๅนดๅฐฑๅ…ฅๅ‘ไบ†Rust๏ผŒๅฝ“ๆ—ถๆ˜ฏๅ•ƒ็š„ๅฎ˜ๆ–น็คพๅŒบ็š„TRPL๏ผŒ่™ฝ็„ถ่ฟ‡็จ‹ๅพˆ่‰ฐ้šพ๏ผŒไฝ†ๆ˜ฏrust็š„้…็ฝฎๅฎžๅœจๆ˜ฏๆฏ”c++้…็ฝฎ่ตทๆฅๅฅฝๅคชๅคšไบ†๏ผŒไน‹ๅŽๅˆ็œ‹ไบ†rustๅฎ˜ๆ–น็คพๅŒบ็š„ไธ€ไบ›ๆ–‡ๆกฃ๏ผŒไฝ†ๆ€ปๆ˜ฏๆ„Ÿ่ง‰็ผบๅฐ‘ไธ€็‚นๅฎž่ทตใ€‚ๅ› ๆญคไปŽOS็š„้กน็›ฎๅš่ตท๏ผŒๅธŒๆœ›่ƒฝๅคŸๅฏนRustๅˆๆ›ดๆทฑๅ…ฅ็š„็†่งฃใ€‚

้ฆ–ๅ…ˆไปŽRustlingsๅผ€ๅง‹ๅญฆไน ๏ผŒ่ฎกๅˆ’ๅœจไธ€ๅ‘จไน‹ๅ†…ๅฎŒๆˆrustlingใ€‚ไธŽๆญคๅŒๆ—ถ๏ผŒๅœจWSL2ไธญ้…็ฝฎ็›ธๅบ”็š„ๅฎž้ชŒ็Žฏๅขƒใ€‚

Day 2 2022/11/2

OS Training Camp

ไปŠๅคฉๅฎŒๆˆไบ†Rustๅฎž้ชŒ็Žฏๅขƒ็š„้…็ฝฎใ€‚ไบŽๆญคๅŒๆ—ถ๏ผŒๅผ€ๅง‹ๅฎŒๆˆrustlings็š„ๅฎž้ชŒ๏ผŒ็›ฎๅ‰ๅทฒ็ปๅฎŒๆˆ1/3๏ผŒๅœจRust็š„็งปๅŠจ่ฏญไน‰้ƒจๅˆ†่ฟ˜ๆ˜ฏ่พƒไธบๅกๅฃณ๏ผŒๅ› ๆญค่ฟ˜้œ€่ฆๅฏนRust็š„move semantic่ฟ›่กŒ่ฟ›ไธ€ๆญฅ็š„ๅญฆไน ไปฅๅŠ ๆทฑๅฏน็งปๅŠจ่ฏญไน‰็š„็†่งฃใ€‚

Notes:

ๅœจquiz1ไธญ๏ผŒๆˆ‘ไปฌๅฎž็Žฐไบ†ไธ€ไธชๆœ€ไธบๅŸบ็ก€็š„่ฎก็ฎ—ไปทๆ ผ็š„ๅ‡ฝๆ•ฐ๏ผŒไฝ†ๆ˜ฏๆณจๆ„่ฏฅๅ‡ฝๆ•ฐๅช่ƒฝ่ฟ”ๅ›ž็ฑปๅž‹ไธบi32็š„ๅ€ผ๏ผŒๅ› ๆญคไธ่ƒฝ็”จไบŽๅค„็†่พƒๅคๆ‚็š„ๆƒ…ๅฝข๏ผŒๆฏ”ๅฆ‚ๅฝ“่พ“ๅ…ฅๅ€ผไธๅˆๆณ•๏ผˆไพ‹ๅฆ‚่ดŸๆ•ฐ๏ผ‰๏ผŒๅŽ็ปญไผšๅญฆๅˆฐๅˆฉ็”จResultๆฅๅค„็†็ป“ๆžœใ€‚

ๅœจprimitive_typesไธญ๏ผŒๆณจๆ„ๅชๆœ‰char็ฑปๅž‹็š„ๅ˜้‡ๆ‰่ƒฝๅคŸไฝฟ็”จis_numeric()ๅ’Œis_alphabetical() API. ๅ…ทไฝ“ๅฏไปฅๅ‚่€ƒlink

vector initialization:

let a = vec![1, 2, 3, 4]; // create vector with 4 values
let b = vec![1; 100]; // in Rust, value first, create a vector with size of 100 and all values equal to 1
let c: Vec<i32> = Vec::new(); // this is also a way to creat the vector

fn zeros(size: u32) -> Vec<i32> {
    let mut zero_vec: Vec<i32> = Vec::with_capacity(size as usize); // this is another way to init vec
    for i in 0..size {
        zero_vec.push(0);
    }
    zero_vec
}

ๅœจRustไธญ๏ผŒๆœ‰Vecๅ’Œslice็ฑปๅž‹๏ผŒๅœจไธŠไพ‹็š„vector aไธญ๏ผŒๅฏไปฅ้€š่ฟ‡&a[1..=3]ๅ–ๅ‡บๅ…ถไธญ็‰นๅฎš็š„ๅˆ‡็‰‡

let a = vec![1, 2, 3, 4, 5];
let new_slice = &a[1..=3];
assert_eq!([2, 3, 4], new_slice);

ๅœจvec2ไธญ๏ผŒๆœ‰ไธค็งๆ–นๆณ•ๆ‰น้‡ไฟฎๆ”นvec็š„ๅ€ผ๏ผš

fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
    for in in v.iter_mut() {
        *i *= 2;
    }
}

fn vec_map(v: &Vec<i32>) -> Vec<i32> {
    v.iter().map(|num| {
        num * 2 // closure of this
    }).collect()
}

ๅœจRustไธญ๏ผŒๅฏนstring่ฟ›่กŒๆ“ไฝœ๏ผŒtrim()็”จไบŽๅˆ ้™ค็ฉบๆ ผ๏ผŒ็ฑปไผผไบŽPythonไธญ็š„strip() link to strings3

fn trim_me(input: &str) -> String {
    input.trim().to_string()
}

fn compose_me(input: &str) -> String {
    input.to_string() + " world!"
}

fn replace_me(input: &str) -> String {
    input.replace("cars", "balloons")
}

// there is also another way to replace the string, that is, use regex
use regex::Regex;
fn replace_regex(input: &str) -> String {
    let re = Regex::new(r"[cars]").unwrap();
    let res = re.replace_all(input, "balloons");
    res
}

Rustไธญ๏ผŒStringๅ’Œstring_sliceๅ‚ปๅ‚ปๅˆ†ไธๆธ…๏ผš

fn string_slice(arg: &str) {
    println!("{}", arg);
}
fn string(arg: String) {
    println!("{}", arg);
}

fn main() {
    string_slice("blue");
    string("red".to_string());
    string("red".into());
    string("red".to_owned()); // ้œ€่ฆๆณจๆ„็š„ๆ˜ฏ๏ผŒๅœจ็ฑปๅž‹่ฝฌๆขๆ—ถ๏ผŒๆœ€ๅฅฝไฝฟ็”จ`to_owned()`,ไป…ไป…ๅˆ†้…ไธ€ไธชbufferใ€‚
    string(String::from("hi"));
    string("rust is fun!".to_owned());
    string("nice weather".into());
    string(format!("Interpolation {}", "Station"));
    string_slice(&String::from("abc")[0..1]);
    string_slice(" hello there ".trim());
    string("Happy Monday!".to_string().replace("Mon", "Fri"));
    string("mY sHiFt KeY iS sTicKY".to_lowercase());
}

้œ€่ฆๆณจๆ„็š„ๆ˜ฏ๏ผŒๅœจ็ฑปๅž‹่ฝฌๆขๆ—ถ๏ผŒๆœ€ๅฅฝไฝฟ็”จto_owned(),ไป…ไป…ๅˆ†้…ไธ€ไธชbufferใ€‚ๅ‚่€ƒ

Day 3 2022/11/3

OS Training Camp

ไปŠๆ—ฅ่ฟ›ๅบฆ๏ผšไปŠๅคฉๅฎŒๆˆไบ†Rustlings็š„enums๏ผŒstructs๏ผŒoptions็ญ‰ๅฐ่Š‚.

HashMap in Rust. link to hashmap

let map: HashMap<String, i32> = HashMap::new();
map.insert(String::from("apple"), 3);
map.insert(String::from("mongo"), 2);


// remember the following
for fruit in fruit_kinds {
    if !map.contains_key(&fruit) {
        map.insert(fruit, 11);   // [link to hashmap2]
    }
}

ไธŠ่ฟฐไปฃ็ ๆฎตไธญ็š„็ฌฌไบŒ้ƒจๅˆ†ใ€‚link to hashmap2

I don't know how to implement HashMap3, so just reference to reddit.[link to hashmap3] [reddit refer] [stackoverflow refer]

ๅœจRustไธญ๏ผŒๅฝ“ๅค„็†Optionsๆ—ถ๏ผŒไธบไบ†ๆ–นไพฟๅพ—ๅˆฐOk()ไธญ็š„ๅ€ผ๏ผŒ้€šๅธธไฝฟ็”จunwrap()ๆฅ่Žทๅพ—ใ€‚ๆญคๅค„ๅฏนunwrapๆ–นๆณ•ๅญ˜็–‘ใ€‚

link to options3ไธญ๏ผŒๅฎŒๅ…จไพ้ ็ผ–่ฏ‘ๅ™จ็ผ–็จ‹ใ€‚

Rustไธญ็š„errors handling่พƒ้šพใ€‚

fn main() -> Result<(), Box<dyn error::error>> {
    let pretend_user_input = "32";
    let x: i32 = pretend_user_input.parse()?;
    println!("output={:?}", PositiveNonzeroInteger::new(x)?);
    Ok(())
}

There are two different possible Result types produced within main(), which are propagated using ? operators. ? mark

Under the hood, the ? operator calls From::from on the error value to convert it to a boxed trait object, a Box<dyn error::Error>. This boxed trait object is polymorphic, and since all errors implement the error::Error trait, we can capture lots of different errors in one "Box" object. boxing errors

Day 4 2022/11/4

Rustlings

ไปŠๅคฉ้œ€่ฆๅฎŒๆˆrustlingsไธญ็š„ๆ‰€ๆœ‰็ปƒไน ้ข˜๏ผŒไธŽๆญคๅŒๆ—ถ๏ผŒๅฐ่ฏ•ๅฎŒๆˆrustlings็š„ๆ‰€ๆœ‰ๆ€ป็ป“ใ€‚

Day 6 2022/11/6

Rustlings

ไปŠๅคฉๅฎŒๆˆไบ†Rustlingsไธญthread็ซ ่Š‚ไน‹ๅ‰็š„ๆ‰€ๆœ‰ๅ†…ๅฎนใ€‚ๅฏนTrait๏ผŒไปฅๅŠไธ€ไบ›ๆ™บ่ƒฝๆŒ‡้’ˆๆœ‰ไบ†ไธ€ๅฎš็š„่ฎค่ฏ†ใ€‚

In macro chapters, remeber the macro should be declared before call. To a certain extent, this is just like C/C++ function call. :)

#[macro_use] // notice the use of #[macro_use]
mod macros {
    macro_rules! my_macro {
        () => {
            println!("Check out my macro!");
        };
    }
}

fn main() {
    my_macro!();
}

Day 7 2022/11/7

Rustlings

Rustไธญ็š„iterator็œŸ็š„่ฎฉไบบๅคดๅคงใ€‚

fn count_iter(map: &HashMap<String, Progress>, value: Progress) -> usize {
    map.values().into_iter().filter(|&v| v == &value).count()
}

fn count_collection_for(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
    let mut count = 0;
    for map in collection {
        for val in map.values() {
            if val == &value {
                count += 1;
            }
        }
    }
    count
}

fn count_collection_iterator(collection: &[HashMap<String, Progress>], value: Progress) -> usize {
    collection.iter().map(|m| count_iterator(&m, value)).sum()
}

Day 8 2022/11/8

Rust feature(OOP: T): where T: encapsulation + polymorphism + (inheritance)

  1. encapsulation
    • We have structs and enums to have the
  2. polymorphism
    • Like the trait
๐ŸŽ‰ All exercises completed! ๐ŸŽ‰

+----------------------------------------------------+
|          You made it to the Fe-nish line!          |
+--------------------------  ------------------------+
                          \\/
     โ–’โ–’          โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’      โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’          โ–’โ–’
   โ–’โ–’โ–’โ–’  โ–’โ–’    โ–’โ–’        โ–’โ–’  โ–’โ–’        โ–’โ–’    โ–’โ–’  โ–’โ–’โ–’โ–’
   โ–’โ–’โ–’โ–’  โ–’โ–’  โ–’โ–’            โ–’โ–’            โ–’โ–’  โ–’โ–’  โ–’โ–’โ–’โ–’
 โ–‘โ–‘โ–’โ–’โ–’โ–’โ–‘โ–‘โ–’โ–’  โ–’โ–’            โ–’โ–’            โ–’โ–’  โ–’โ–’โ–‘โ–‘โ–’โ–’โ–’โ–’
   โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“  โ–“โ–“      โ–“โ–“โ–ˆโ–ˆ  โ–“โ–“  โ–“โ–“โ–ˆโ–ˆ      โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“
     โ–’โ–’โ–’โ–’    โ–’โ–’      โ–ˆโ–ˆโ–ˆโ–ˆ  โ–’โ–’  โ–ˆโ–ˆโ–ˆโ–ˆ      โ–’โ–’โ–‘โ–‘  โ–’โ–’โ–’โ–’
       โ–’โ–’  โ–’โ–’โ–’โ–’โ–’โ–’        โ–’โ–’โ–’โ–’โ–’โ–’        โ–’โ–’โ–’โ–’โ–’โ–’  โ–’โ–’
         โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–“โ–“โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–“โ–“โ–’โ–’โ–“โ–“โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’
           โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’
             โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–ˆโ–ˆโ–’โ–’โ–’โ–’โ–’โ–’โ–ˆโ–ˆโ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’
           โ–’โ–’  โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’  โ–’โ–’
         โ–’โ–’    โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’    โ–’โ–’
       โ–’โ–’    โ–’โ–’    โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’โ–’    โ–’โ–’    โ–’โ–’
       โ–’โ–’  โ–’โ–’    โ–’โ–’                  โ–’โ–’    โ–’โ–’  โ–’โ–’
           โ–’โ–’  โ–’โ–’                      โ–’โ–’  โ–’โ–’

We hope you enjoyed learning about the various aspects of Rust!
If you noticed any issues, please don't hesitate to report them to our repo.
You can also contribute your own exercises to help the greater community!

Day 9 2022/11/9

Read the xv6 book, Here are some notes of xv6.

About

Learing the Operating System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published