Okay, I think this way. Okay, let me go ahead and get started here, I'll start.
Okay, good morning everyone. I started recording.
Let me share my screen screen.
So little small, it's
okay.
Okay, let's start with where we are, for things.
Okay, so I'm going to answer questions in a moment that's where I first start off with.
So October, so we're right now so y'all got a little break last week, hope you appreciate that.
I appreciate it. So, anyway, so here we are lecture 20 we have a lecture Thursday then two more lectures, and that's it. And the final is December 16.
Right now we have two more tutorials, the, you know, basically in, in principle you all shouldn't be done with your tutorials by now.
Because you know you have these for a week if you but you know will still accept them till the assignment assignment for is due December 8 the day before class, I'll accepted, up to, you know, the time of lecture, because I need to go the solutions of
assignment for.
So assignment for is now here I just unmuted finalizes I just finished it yesterday so I haven't, I just wanted someone to at least check it but I think it's basically good just want to make sure there's no little errors.
Yeah tutorial. Yeah, those tutorials seven through nine. Yeah. And if you go to bright space.
Yeah, so this is where you can see like how many people have submitted if you're curious, but let's see what do I show you what, but for actually the due date so if you targeted the tutorials.
You'll notice you know so tutorial 789.
So seven December 8.
Oh, I didn't add, I haven't added some really new and told me I didn't add that here.
What's going to total nine.
Okay, so.
So tutorial seven December eight to early December 809 December eight so that's when you're supposed to have everything done. And if you go to the assignments.
You'll notice that assignment three ends with Simon three times. Oh, I haven't put assignment for here I will do that that will end December 8 two.
Oh, so tutorial nine, so one thing to important to note is these are all shortcuts. This is good to know about bright space like the things here.
If you look here these are just shortcuts. If you go to tools or something like this I'm not sure exactly where, but there's somewhere where you can view all assignments, of all kinds.
Yeah, if you go here, you shouldn't be yours You probably can't see this exactly I'm not sure what how your guys's look. Can I look at as a learner.
So if you go here so this is all restriction but if you Here you go to assignments.
And you can see all of them here.
So ones that are closed, you can't see it oh I never come close to sign okay that's funny, but see here they're all here so you always go here to see everything.
Yeah Table of Contents you too. Okay.
Anyway, Um, so that's where we are right now.
What was there was a question.
So what I'm going to do now is go over assignment, my plan for today is to go over assignment three and assignment three connects back very much to very much the tutorials five and six.
And then we can start talking about things from the later tutorials. So I don't wanna spend too much time on this but it's on the new materials and principles you don't know this but let's talk about the solutions.
Oh yeah we post the solutions.
solutions like.
And there you go.
I want to go through question 11 we're not going to go through question 11 now because I don't have a full solution of it. So, but I will, I will later talk about 11 city
you a breakdown, you want to hear about the.
Listen, there's nothing mysterious about now that you have the assignments three and four, it's going to be based on assignments one through four.
Hey, Let's let the solutions.
So, first one, download an inspector he doesn't make of us is there a risk of data loss or writing the script will commands. The main thing to know is what let's bring up.
Let's go to assignments.
Seven compare this so if you look at the script itself.
It's got all these all these things of removing things forcefully, you know, you know, then RF here, that's very dangerous it's overriding a bunch of files and stuff so you know basically it's like you rigorous as transfer the image MP directories I was
from a CPL files.
So that's, that's the big thing is the version currently is pretty safe but yeah
what what's the point breakdown. I have a question, what's the point breakdown for these things. What I do is because of the way that ta is do is I let them look at your answers and decide what's a fair point breakdown based on how you all did because
I started to make suggestions on like the thing I was really looking for.
I'm looking for, like, you know, is there a risk I want you to recognize the risks of running this, and then 1.4 dangerous. So basically it's a gimme for one point.
Like, So to run it doesn't make a sh.
You're putting a new show, was he still gets back every what's, you know, so basically to get back, you just run pseudo ch route 3000 Fs because you do the changer in the shell script, it's not your regular directory.
And so, that's it.
Oh, she's like she's barking a bit there. We closed door.
Okay, so now we're on the echo things. so here this is rectangular recognize that what we're doing here is creating a shell script.
That's what we're doing is we're creating a shell script in the true rooted environment that we then run with this command.
So, and specifically what it's doing is it's, you know, this tells what the what the problems were run out so we're telling busy box to run as a shell.
And then we're telling it to install busy box to install itself. And then we're telling LD config to set itself up, and then we're mounting profit and Dev.
If you have questions about way these commands or something, now's a good time to ask if you're if a these things are a bit confusing so there's I'm going to go through this quickly.
How about using cd 3000 Fs and see coach change route.com. Sure, it's kind of the same thing.
There's lots of ways you can do it, you know.
Yeah.
I'm not looking for. Oh you did the exact command but you know how to do it.
So there's echo commands for like 26 to 34.
The idea of 26 to 30 is that I'm thinking if you run the command more than once the ideas that you clean up of the previous invocation and then start up again.
So the thing that's missing is we do all these mounts mount proc and debt, we mount proc and dev here, but we only unmapped proc so you supposed to unbound death, if you do that then you can run the script multiple times and it cleans up dr itself without
that it doesn't work as well. And I kind of wonder if that's actually what so have you had, because once you fix this.
So many of you have had problems with def pts exhaustion.
And I wonder if that has to do with remounting Dev and having multiple copies of dev mountain or something, because otherwise I don't quite know what exactly is going on so I certainly didn't see that problem.
Yeah, if you don't have the unknown.
Okay, yes you had to fix it. That makes sense. So that's why I have this question early was fix it.
Here, basically this command this was fix your script.
Before you go on to the rest.
Yes, you said, it's fine. You miss by a minute. It's fine.
What's the largest file that we can create in a confined environment. So this is just realizing that the files in the truth that environment, or in the separate file system which is in a file.
And so the size of that file determines the size of the file system you make it and this determines the maximum size of the file, you put into it because basically whatever's there is there but you should do this experimentally, you know, I you know I
did this I created a file and right after running the script. And this is how many bytes I got you should get something close to this. If you didn't exactly the same, it's okay because maybe you mess with it before running this but should be roughly around
this.
So this is done by the size.
So, um, but if you create.
So how does running df help you. So the question was how does running df help you find the size.
because the size is the free space.
Okay. Well, if you ask I can talk about def PJs so. So basically df tells you the amount of free space. And so, the amount of free space is how big a folly, to me, That's all.
Roughly, and again if you got roughly that is fine but the experimental things I mean, there's some reserve space and file systems and stuff. So, one of the, one little quirks of ext for file systems and a lot of other Unix file systems is.
If you do I.
If you calculate this, you'll if you do a little adding here you'll notice that.
So, if we do 818. So, just copy these two numbers, you'll notice that this number.
Plus, this number should logically equal this number but it does not, it's smaller, And in particular, let's see. No, I'm.
Yeah.
So that's about right. So basically about 5% of a file system by default is reserved in ext for file systems, and the idea of this reserve space, so it doesn't show reserve space doesn't show up as available, basically regular users can only make files
up to this point but route can use all the space.
The idea being that there should always be 5% at least have the file system left free.
space system.
Oh,
so that's that. So, so that's it. So, if you create a file that can find ism and use the space avail outside of it, how do you know yeah for six I said no because the physical side does increase the on the arcade size image.
So, so for six this if you said no, that's wrong because empirically it's true.
You know, so when we run DD as question if you run DD in 3000 Fs that ticket reserved space.
If you run it as root, and you use the maximum out yes you basically are using the reserve space. Exactly. Now, question here is six was I wanted you to do experiments and.
And let me show you the experiment, I was expecting you to do, let's go ahead and let's run through thousand they give us like
we were on lecture.
Okay.
So, Let me show you what I'm talking about here.
Okay.
Okay, we've now run the script, I don't have the unbuilt fixed, but that doesn't matter right once. Now the question is is.
So this is the file it's saying right here.
So it's 364, but now.
This is the number I was expecting you to look at is the amount of space, taking up. So the large. So, this real question is really asking about the logical versus the physical size of the file which is something that we have covered in the files, and
I think tutorial six. So, the idea is that this is the number of bytes that you the logical size which is normally the size here, this is the number of bytes, if you read the file that you can know read that's how many bytes, logically are in the file,
but how much space it takes up on disk.
It only takes up this money. Now, if you, I'm
looking for, I'm looking for this. Okay, so let's.
So 100,000.
You'll notice that food has same logical size, as a reference image, but it takes up the full space.
But if you now do a.
And you'll see that all of a sudden that space on disk greatly trunk is no longer this much.
It's now just this. And that's because when we made the file system. What it did was it put holes into it.
So it does release, so remember it. So, the question is asking specifically.
Does it reduce the space available outside of it, how do you know it's like if I, if you just literally did the experiment of you even have to know these numbers.
All you had to do was.
You don't have to do it as, you know,
Now we're in the confined environment here.
So we
now we're gonna make.
So we do this, we do this.
df.
Okay.
Yeah, you're on zeros. It just treat him as zeros. But if you wrote random stuff that it actually took up space.
Okay, so.
So I think the key thing is, if you, if you didn't experiment.
Three to six ported.
The results.
We
can get full credit.
But if you did this year but up, so.
So basically when you.
The idea is that you if you allocate if you're storing all zeros.
Why.
You should have seen this the tutorial when you played with truncate.
So, if you see past the end of a file and then write the space between your in between will become a whole.
So zeros don't take up space. This was the command, like I remember, you know, saying that you could do crankcase truncate.
So now notice here.
I just create a strong cake basically what it does is it, it basically does a seek and then it writes one bite I'm not exactly what I drink it works but essentially, it creates a file by seeking that lake so basically it's this file is logically one gig
and size.
But it takes up no space on disk at all, beyond the metadata portion.
So, now, where do you do this this was in the Sophie go to
six.
So, this is all run command what's the logical size of barn how much space does this How does this compare with foo. How does a logical size of our chain up needs to do for file system without the command space consumer disk.
This was all just based on that,
where she wants to come in.
Okay, Rosie career rushing me
boxes are great but boy do they draw.
Yes. Okay.
Yeah.
Wrote she can say I never wrote he
wrote is not what you look at anyone
behind me. Ok let's continue the solutions here
is the signing up behind me.
But if you turn on your microphone you can just say hi to Roshi, you'll hear you.
Okay, so we're worried.
I'm
so seven may files and are confined virus and Bach links hide these get created. Well this is why I want you to walk through the script and figure out where these were and it's basically this thing.
If you don't use the dash s option busy box will create them as hard links. And I wanted you to clearly see that there's just one binary system backlinks but you could say a be more robust if you just did the hard links.
on the ground now then.
So for eight copy and make Nana work in the environment files have copy. So, what I was expecting you to do is all your if you looked at.
If you just ran the program.
If you copied nano into the binary would tell you that some file was missing. but all you had to do actually was just, if you noticed how we got bash working this little line right here.
If you just did exactly the same thing for nano.
That would do it.
So, what is the command.
Yeah, well, it just led me to go and check the library dependencies. That's great. Um, the and that's and that's what's happening here all och och is this.
It's a great thing for processing text, essentially what this is saying the input print the third column.
So often will take your text input because you've got.
So if I do Ltd bins. ls, so I get this output. And if I now pipe that to och.
Och syntax I'm not actually a big Aki user, she.
You see what does it got the third column now the current period 68111 is the first column. Let's do 00 does the whole thing. One's there to get them second column and then three.
Get the third column.
You'll have to do that. You don't have to do an arc is like breath, kind of, but grab selects lines. Och is much more flexible offices of all can do all kinds of crap it's, it's this amazing little program you should it's definitely worth knowing about
that if you want to process lines and do operations and like manipulate them. It's like as a, as a stream.
Och is just awesome it's, it's not a tool I know well I would like to know it better, but I know like for doing quick little things like this.
So, yeah, if, if you just copy nano and didn't do anything else, it shouldn't work.
Yeah.
Yeah. So,
was doing this question it seemed like the order of the lines mattered
us. So are we talking, so I get a question your order the lines match only the orders of the script matters.
I sorry I
copy the libraries with DD.
That's all weird. I guess you can, but that's kind of a weird way to do a copy, just new CP. She.
Yeah, as long as long as you've gotten with nano, as long as you copy the right libraries there by some means it doesn't matter how this is just a cute way of doing it
opens new, that's a great one. Yeah,
that's, yeah I always
play with if you're curious what art does play with it.
By the way, there's a question that we're doing just in question this assignment, the order of the script is very sensitive.
There's, there's definitely some dependencies between it.
Okay, if you add a user confined to 3000 Fs. How do you have the users now there's lots of ways you could have done this.
So basically you know become route.
You know change to wherever your directory is where you'd be had 3000 that I made a backup of my old password files. I then add a user.
And then I basically take the last line of all those files and add it to the end of the password files and then I restore from backup.
So, so basically like so and so, I just read me this almost as a little shell script, just so you can kind of see my solution in action. So, add the fall into the password and find the shadow, add this to group and added this to G shadow.
Because cuz you can think about how to do this but
you have to change it manually it's fine just tell you how you change it so there it is. So, but the key thing is you have to add it to the confined environment, and not the regular environment.
So if you just use it Add User and you didn't give anything about to restore the, the login files to their original state.
That's a problem.
Oh, that's a nice little thing Oh right, James, yes you can tell us or add to change directories.
I forgot about that.
That's a much simpler solution. Yes, you can tell it just to do it in that directory and in fact it has that functionality.
So that's a good one. Um,
yeah so definitely nice, um, so this yeah this is, I should probably put that in the solution but yeah this is way complicated, compared to what you can do with this running either at
10.
How can you melt the main falsehood inside the confined environment. So this is just this was really about you.
Understanding that there's that when you run this df, the main file system is here this is a device. And that device is available inside the confined environment.
And so you can just mount it. So, so here right now we're just so you know. ls till the students. So we see.
So we see all this stuff here. Now, if I do a.
So now I'm in the confined environment. And Allah slash Dev.
You know, I've got all the things I normally do so I can do a.
So I got now directory may not fast.
I can do amount of data.
Was it
was dm zero. It's just, if you follow the same model and that's all it is.
It's not
just about.
You see it's all there.
Just like
yeah so yeah physical view lecture 1917 shared folders.
Exactly the same thing just not as.
So yeah, so we change route on its own is not at all secured Yes, because
you add the holy Add User functionality true environment. Yeah, where the man page more carefully. Yeah man sheet, you know.
Yep. man Add User, whereas home directory.
That's, that's home directory.
Wait, it's not as a user app.
user add has the option to add user doesn't
use user out Yeah. Okay.
Anyway, um, so this is just to show you. Yes, you have, if you have access to the device, you have access to everything on the device.
If your route.
It literally recursive RM my VM while trying to aren't 3000 Fs. After that question.
Oh you ran the script again.
Yes. That's why I tried warning you, there's lots of ways to screw yourself overall playing with these commands. Um, yeah i think i trashed at least one VM while I was developing this assignment.
Okay, so that's assignment three so
supposed to.
So let's go to.
Let's go now to the tutorial so now let's.
I don't know if we've talked much about tutorial. Nine. So, yeah, he said let's go to the house go through today I will go through tutorial seven tutorial a real quick here.
tutorial seven I've started to I did do some of tutorial seven because I showed you, modules.
And so I did that initially I was awake when I've gone through is basically simple. I haven't really gone through the other so let's talk about those.
So, what, so the ones module II running it's pretty straightforward. it's not that interesting.
This.
So we make
slot one.
Do
you see here. Loading out of three ones module.
Surprise timestamps until 2038. Oh, okay, this is worth a little digression. Have you all seen this message I didn't notice this before in here.
Okay, well we'll go through so yes you can go ahead and share solutions for assignment three question 11 on teams, that would be great.
We'll talk, we'll go through the 90s I want to spend the time of the lecture so.
So if you. I just noticed this so this is really funny. Does anyone know what this is referring to
it for 2030 years. So, yeah, the idea is that timestamps are represented as number of seconds since the epoch on Unix systems, the epic is like sometime in 1970 and turns out you have 4 billion seconds when you get from them to get to know 2038.
So if you want to represent times about past 2038 you need more bits, but traditionally timestamp for only 32 bits while it represents up to 2038.
July 1 20 1970 Thank you.
So this is a potential problem we still have some time but remember this in another.
So we're 2021.
We 17 years.
Okay.
book what we were trying to buy them.
But yes, potentially a y2k issue. So, um, and but you know systems are moving towards 64 but people have been moving towards 64 bit timestamps, but notice the file system I've got here actually has 32 bit timestamps, so
keep an eye out for this thing. Um, but here the message is relevant loading arbitrary models and kernels so because it isn't properly signed, we have it is not properly science here but then we have the actual message from our code is saying that.
Yeah.
Yes, you can make it make ext for us 64 bit Yes.
Well, I don't know.
I don't know why it doesn't.
Yeah, It doesn't do that okay so definitely so okay so what we have there but let's go through them.
So this is Ivan, so this is the ones device, there's some questions about the other parts of the tutorial, I'll make sure to go through that. Um, so now what do we have now we have la ones.
So this. Now we have a.
We have ones there. It's a, it's a character device, as we expect.
There's a thing there if you go into CES.
You'll see that one shows up. Elsewhere in his last this. I think if you also do a comp.
You'll see. It's the same ones. So you see that.
Don't worry about that. Permission denied ones, but these are there so the module has some other effects that you can see.
And then, So we can do a
will do
one equals
one.
We got ones.
There is now you do a copy or something else. The trouble is logically devil ones is infinite. So, if you run a copy command, it will potentially run forever, it will run to fill up your disk space.
Don't do that for you can't do it and then just race the output up.
But how is it doing this so we have a file now that we create just like dev zero, instead of our putting no bytes and outputs the ASCII character one.
How does this work.
So, basic thing is, we have the initialize or one which goes to all these things, creating the device. So you have to make. we have to register a character device.
And then we have, and then we have to say there is a class now of these things. And then we have to actually create the actual device here in the ones class and then if we made it then, you know, that it exists.
Now, the all this stuff is mostly boilerplate for how you create a character device, which I got from else elsewhere by looking at how character vices great elsewhere in the kernel.
Other examples.
But the important thing here is to write is the idea is that basically the class is, we have multiple character devices of the same type, like we can make multiple ones character devices, in principle, that all happy we're driven by the same code.
That's how you can have a, you know, if you're saying you have a USB disc or whatever you could have multiple instances of them multiple flash drives plugged in, but the colonel is using the same code and how does the same code distinguish between them.
You have a class, which is all the same driver code and then you have instances pipe to last workout.
Random and you random in the same class then.
I don't know if they're in the same class, I think so.
But there, but they're different devices they have different behaviors.
So, but the key important part here is this one's f ops thing, this is really where all the semantics are of the ones device other all the rest of this stuff is most is basically boilerplate and.
And this is a struct of file operations. So,
remember I talked about system calls is essentially an API. It's like, you know, a file is something that you can open read right things and so a device file is a kind of special file which basically means the kernel has that special code in it, to handle
handle open reads rights and everything. So this file operations struct specifies what happens when you get those system calls. So when you do get an open system call, you're going to call one's open when you get to read sizzle call ones or even you call
release which is equivalent of close.
You call ones release, and there's other operations this file structure, we haven't implemented right now implemented seek or things.
If you don't specify it. There are default implementations of the things mostly that don't do much motivates them to say operation not permitted, but there are, you know, you can still call those other things on it, it'll just get an error.
Yeah, it's a cracking close what what actually specifically what release does is, you're locking the I know potentially and this is saying you're not using it anymore.
But what is a lecture bootleg on what is OK,
so what what is this.
This is just the Linux kernel source code uploaded into a big repository and indexed by a web app.
That's what this is. So this is just me, you can download.
I mean, you can go here and download the code here and just unpack it it's a tar ball and your users download it to xz but.
But this is the code index now, is it intimidating. Oh yes it is. If you just try navigating this and go like what's in here.
Oh my god, what's in here. Oh my god, you know it's like you're good at me. There's like 15 million lines of source code.
You're not going to read it all.
But that's why I gave you links to very specific files to look at.
Yeah. And so that's what and the reason why I put this in here was, if you go to this anymore. Some more here.
So here, this is where you use bootleg is like you actually have links to the specific code like you go here.
This is its declaration.
And oh look, they use the code here
at this line right here. So the idea is that you can navigate the code by just clicking through and see exactly how it is there and so this is I gave you the pieces and this is like you could look at the code and put it together.
I mean, I said this is advanced if you didn't do it you can still get full credit for tutorial but if you make dev described you really understand what's going on here.
Yeah,
the Linux kernel does not have lots of comments. That is very true.
Political does not have a lot of cons, but as comments in the key parts, and frankly it's very well structured.
It takes a while to get your head around how its organized but it's pretty darn good.
But it's, it's huge. So, what am I doing here. All right, let's go right here so well so just explain the code here.
We specify the operations. And so what's cool here is you actually see the colonel side of implementing the file API. So, on one's open we just say it succeeded because open we don't need to do any additional ization, we can just say it's open.
The only work is read. And the idea here is we're past in a buffer.
Let's fill it with ones.
Now, the trick here is that any buffer we're given where we're doing this and since the file is infinite. We can oh no it's just once, we don't have to keep track of where we are in the file, we can just fill the buffer always with ones.
Now notice we're not just this is a character array, we could just assigned to it.
But remember, this is in the corresponding processes dress space. This is user space where internal space, if we want, if you're in user space you can't access the kernel, were incredible you can access user space.
But you have to treat it differently than just regular kernel memory, and that's why use this put user function.
So question five on tutorial seven is extra credit not required tutorials are graded on participation.
So, you putting an effort to try to understand things. It's not graded. So you don't need to get every question right. Maybe you could spend a little time and talk about how you tried to do the advanced stuff but
that's the point of it.
Yeah, so like I said yeah targeting dev described the right I tried to name fight.
Oh and name pipe.
Okay, that's a very okay so you cannot do a name pipe for dev described. The reason why it's a pipe is a user space concept that's why it's something that falls with this whole thing you have to do it in terms of dev describe.
So was it so dev described is, you write a process ID to an output of that information to provide a process so dev described is just taking dev get p ID.
You're supposed to take dev get PhD and fiddle with it.
That's all you're supposed to do to make that scribe, it wasn't supposed to be that hard. And the question is how do you do things so so this one is this really stupid.
It's just filling the buffer.
The only real difference with Dev.
New get PID is everything and this is basically the same, except for this function, which is the read function. And so this is a bit more complicated because now we have a buffer, we have to not just manipulate the buffer we had to manipulate the offsets.
But here we do it basically to show that we've actually advanced in the file so that's why we say that if you don't start reading this file from the beginning we just say there's nothing there, which is kind of alive but mean this is a special file we
don't have to be like a real file and but we do have to update the offset after we doing here otherwise little think know bites are actually read will keep reading the same things you'll get into an infinite loop.
But here the.
This is the only real interesting thing we're reading from.
We're getting the process ID, and I'll explain what this thing is doing in a second but this is how you get the process ID.
Yeah.
Yeah. If you didn't, if you update the offset yeah you know you're going to have problems.
And then we just print to a string. So this is your sn print off we print to the message here there. And then we put the message into the buffer.
Save a locally allocated small you don't have a lot of Colonel stock space but this is just hundred characters, we can do that much. And we put the message in there, and then output you know we copy the message into the buffer here remember this need
to move it to user space, and this buffer is kernel space and will be gotten rid of we definitely can't pass it up there.
So what if the buffer is constant.
With a buffer is constant well, then you're not. So, on read you right to the buffer that's given to you on right you read from the buffer that's given to you because you're putting it elsewhere.
So, it's fine for it to be constant because you should not be modifying it. So topia signing to it.
But you'll be doing get user.
If you do a right.
And then storing it.
But yeah so yeah doing the right parts a little trickier. But the read part.
This is blocks playing bass and but it's just manipulating the buffer doing stupid see string stuff. Then once you have this, missing the string. Then you've got to copy it to user space.
So the question is how do we supposed to make it show the UI dg ID and stuff, you just add things to your message.
So what this is doing here is current in the. So if you look up this task TGI DNR
defined here.
And it's the finest This is called this big Tip No but notice what's the type. That's interacting with task struct.
So we can click on that.
And this is where it's defined.
I'll make this a little bigger.
So this is a task shocked.
If you scroll through this and like what is that task dropped.
He looked through it, you know like, you'll see that recently you CPU awake on CPU.
You know, there's a lot of things in migration flags are so your task info tasks personality. As you scroll through this, you know exactly we should realize is to process ID, big, so.
So,
Yes.
you know, so the idea is that you got tough p ID and are.
So this thing has all the stuff for accessing parts of the task.
You want to find the task PIDTRTGID this is all code for accessing the different fields parrot process ID here.
You know,
task state, you know like, all the things you want to access from the tasks drop basic info on a process is all here.
What is in our.
I think it means non resident, I'm actually not sure what the nr is not to see what the bear.
Yeah, so each process has a task struct, and that you get all the info on the task truck from there. Now, in older versions of Linux kernel, I would just do reference the struct.
And I would just set grab the field but now if you do that, it can work but in cause weird things and you're really supposed to go through the access functions.
Follow these things actually are tasked PID they seem like they mostly just do exactly that. So, you know if they're in line functions, they don't even cost anything to call these things.
So by the way when function is in lined it just means that you don't actually have to call you don't do a call and return it just sticks the code into there.
So yes, exactly. So the idea is that current refers to the task dropped of the process that made the system call.
So, the know the tg ID, you know, Vienna, this is getting the, this is, this is a task group ID, which is really what we're looking for, because a process is actually a collection of tasks, potentially and, you know, if you have threads, each of those
is in there and so that's why you want the task group ID as the P ID here but I'm current represents the current process.
So I'm not expecting you to understand everything about how the Colonel's done. And if you look at assignment for, you'll see the level at which I understand this, but this is the thing that represents the process that called this.
And so if I need to communicate with it, find out information on that process. I can always refer in the kernel code to current.
So, current is the current task.
Now if you look at the declarations of current and kind of follow that, that down. It gets a little weird, because of course current has to dynamically represent the current tasks struck on any score that the tunnel is running on.
And so different cores can be servicing different system calls. And so they could have different current so it's a little bit of magic underneath what current is, but conceptually it's very simple, it's the it's a task that made the system call.
And so you know what type car it is because the fact that the compiler is happy when you give it to this function.
That's kind of how you have to use the type information to kind of smooth your way around the code base.
So
the question is, how do I know what thing do I do for these.
So that's so that's the other. The other cool thing is the way, so I'm like, how did I know to use this particular access function, I don't know the kernel code that well.
How do I figure that out.
Well, I know system calls. And I know how do I, what's the system call for doing this for gaining processes Id get p ID. So what I want to do is find the code forget p ID.
And it turns out right here.
So right here so we'll start with. So, find the right task dropped. that's Leo kill system call about the advanced part.
Right. Yeah.
Why they point out Colonel says here,
cheer.
No.
So you'll notice the year or get priority.
Find in page.
says called defined zero, get the ID.
This is the definition of the get p ID system call, and all the get p ID system call is does this.
So that's what I put in the code, and get t ID, this is this get as of as ID so if I know what system called SEO set FSU ID, you know like, all these things for get you ideas right here.
Get your ID here get God is here get eg ID here. Just copy paste code into the thing and you'll get, you know, the thing you wanted.
Current is a global variables, but it's a weird global variable, but technically as well.
So you're getting this their PhD of current
credit also work. Yeah, I mean, basically, you look at the how the system caught, the way you do things in the kernel.
Turtles space
user space system.
credit, that's for credentials.
Right here, credentials.
Oh get current credentials
and a struct grad, is this crowd contains UIDG Id like all the credentials for it.
That's very cool yeah
multiple ways of doing this.
Now you'll notice that doing stuff in the colonel is like this deep hole of things. I tried to make it so that this stuff.
If you look in Colonel Sisson tried to spend some time looking through that you will hopefully have found the system called definitions, and then see the commonality with the code I gave and that's how you do these parts.
Okay so,
but ya know this stuff is hard fiddling with the kernel is hard, and my purpose is not to make your kernel hacker, but it's more to understand what's happening in the kernel.
And that Oh look, the things that create processes and threads and you know files and stuff, it's just code.
There's nothing mysterious about it. It's just crap load of code defining all these API's. And if you want to you can go in and learn it, just like any large program, and give you a little bit of excuse to try developing some techniques for how you do
this now.
in terms of special files and I haven't gone over these. How do you make a block device. So, you make a block device in terms of how you can just do an MA n od.
You can do this thing.
We do the same thing to make a block device, you just do a, B, and give the numbers.
That's how you make a block device now. That just makes the block device that doesn't make the underlying device itself the underlying device itself and the code for doing that.
It's all in the kernel that's a device driver.
So you can't just automatically make a new disk, you have to implement in the kernel that's what every special file, essentially has to have special code the colonel to deal with it.
So, like here we created a new device by creating a kernel module here, but if you want to copy an existing one.
You can by doing this now.
Now there's a little bit of funny things here now.
If you go into slashed down.
So this is the device that represents the route file system on the VM. So I can copy this device and it will act just like it.
So I can go make a new thing with block device with major number 253 with my number zero using.
Make me a MKNOD make new devices things, but so I can do that pretty easily.
And that works, and the new one should work just like the old one.
I'm fine. But if we go into here, def PTs and if you do the same thing for like def pts zero, it won't work the same
numbers the major, can we see the code that makes that makes the VM.
m.
Gordon you what.
So what was what are the numbers, the numbers are to the colonel, whenever you have a special file that's a blocker character device. The major number tells it basically which device driver should do it and the minor number tells it, which instance of
it is here.
And that works for almost everything and slash death, like all these devices, you'll see there may, you'll notice that all the TT wise, have major number four, but we have this other number here for things and not just represents the instances of them.
So these teachings are all for they've all these numbers here. So we have all these, you know TT wise and then we have
the real time clock we have the Luke device that's major number seven, and there's the loop devices, they're all different instances. So basically, if two devices have the same major and minor numbers, they're referring to the same device if they have
different names, but in depth, you won't have to have those because that would be very confusing, but instead they put symbolic link so if you have one have multiple names.
So the question is, so now I said is, so this is the way normal devices work, and that's the way, all these things do dev pts doesn't follow this and it really puzzled me why this is the case, because you can copy this thing elsewhere.
It won't work.
But the reason why is actually interesting. That's because
this is a separate file system,
which has its own semantics.
Now, I didn't real It seems that normally I would assume that special files. Would
special files would kind of be the same anywhere you put them. But I think the implementation of pseudo TT wise checks to see whether it's in depth pts or not.
And the fact is things in depth pts are supposed to be dynamically allocate it. It's supposed to be the one that
cat messing with
things in dev pts are dynamically allocated by the pseudo TTY driver, by things are inputted to PTMX basically requested to make us a new pseudo TTY, and then allocates it if it sees one that's not in here, it didn't allocate it.
So I think the sooner try goes like I don't know what this is and just basically says, I'm not going to deal with you because I didn't make you.
So, let us know memory because that's a special it's us, it's a, you know, single file system.
So,
so, So the question is if I do.
random.
So the question is what's related so you'll notice if you play with my random my random behaves exactly the same as you random is one a hard link to the other know.
And I can tell you this.
Because I do this, if it was a hard link.
They would have the same I know they don't.
My random has I know number 436, you randomize I know number 10, but functionally, they are referred, they are the same, because they are referring to the same underlying device but there's two I nodes in the file system referring to.
So, this is all realized that there's no storage associated with it essentially this is just like a symbolic thing it's just a name to tell the colonel.
Oh, this is a file I have.
So, copy, does in fact create a new thing now could I do a
two
here you'll notice that if I do a hard link my random two and you random are now the same I know, but the CP made a new I know.
So again, these are the, like when you have these kind of questions, you can ask me I'm happy to show you, but nope, just do the experiment.
Check it out think I wonder if this is what how things work.
How do I figure out how things work. I do experiments or I look at the code.
You can only do that once you have enough of mental models you have to build up to that point but hopefully you get to a point where you go like, Hmm, I wonder what that does to experiment and then see it and then see if that fits your mental model if
if it doesn't, then you go, huh.
What do I not understand and then that's when you really want to ask questions.
If you the advice from one will move from both
know.
If you mess up your VM, that's fine, that's why you can make a new VM
know if I remove my random. No, I my random to.
It won't change anything I mean it's just like hard links are all things files there just files.
So, um, so this is here playing with make an od make FIFO.
I think I've shown the, the name pipes already. Um, so this things again you have to
the parent is not to answer the questions. The point is to build a mental model that allows you to answer the questions, because once you have that mental model you can answer other questions.
We want to understand things. So, that's seven we don't have a myth, but let me just talk about tutorial eight real quick.
We've already talked about, we already gone through this one. But one thing I don't think I've talked so much about is just realize we saw
right here.
So, this m map.
You've seen em maps before a member this allocate space. So this is an anonymous and map so instead of mapping a file into the process of address space where instead of just allocating something that's why we have minus one for the file descriptor because
it's not an open file.
When we have map anonymous here, but notice that we say it's readable and rideable and shared.
And the key thing about shared, is that when you do a fork.
The child processes will share that memory.
So if you have if you when you map in a library.
It will be read shared, and that's fine because that shared between probably don't need copies of it. But here, this is weird. We now have memory that shared essentially when you do on Matlock, you're doing a cone the same thing but this is private.
Malik for a large enough that of memory will be this but it will be private and you saw that earlier when you did that.
So it's so it's like if you do a thread.
So all of all the thread is a thread is just like make is,
if you want to make a thread.
It's just like doing a fork and making another process, except instead of a logical copy.
It's all the memories the same.
So, uh for making a new thread is just like doing this, except all memory is like this, all is shared. So if different threads change memory, everything's overlap so it's like, I can make just the thing I want shared shared.
Why do I want everything shared then I have to worry about interference across the whole trust base. I probably just have some memory I needed to share between the threads, why not just do this.
That's the thing I've never understood about multi threaded programming.
I needed all shared. That's just going to make my life more complicated or reason about
know all nap anonymous does is, this is to say that it's anonymous map so there's no file associated with it.
So in tutorial, we have to make them you tech share then where would you want a music that is it. When would you want to mute text that isn't shared.
You would have a mute text not be shared, but the question is are they shared between processes.
Um, you do need to make it shared between processes.
Otherwise, it new tax would always be shared between threads.
I believe initialized with zeros, if you have map anonymous.
I think so.
I'm not sure I certainly, I think it should do it because although I'm pretty sure it does now. Because otherwise, that would be an information leak and information with some bad older operating systems wouldn't initially initialize it but I think nowadays
we initialize it because we don't want to leak memory leak information between things.
Okay, I haven't done a poll. Um,
what I want to know from you guys.
I want to do.
What is the threat.
Silent for isn't there yet. I'll,
I'll do that. So there's a question while you're doing the pole, have a final exam review session.
I can do a review session. So, so well last class, I was playing on December 9 being review session. December 9 is here December 16 is a week away.
I could do a review session on like the 14th, if people would like that so okay I can see about the scheduling of the session on the 14th.
I'll do a poll. I'll do a poll on teams to see what I'm.
So if I went time on the 14 makes sense.
Review form.
Yeah, so that's an optional yeah so I'm going to do I'm going to talk about the solutions and everything, on, on December 9, I can do a last minute optional review section on the 14th.
I'll do a poll to make sure I'm not sure if anyone has exams that time but that's to me a purely optional thing. The idea is I'm going to go through everything here.
I'm going to tell you everything up the exam in on December 9 will talk about topics and things but again it's assignment three and four, was a science one through four, sorry.
Um, but, um,
but yeah I'm happy to let people have last minute questions.
The final is cumulative.
Okay, and I'm stopping the pole.
Okay.
So you okay execution context and a shared address space. That is the correct answer. So half of you got it right.
It's not a group of x, it's not.
It's not these others. The idea is that
extra, extra tenants credits the review. No.
Sorry.
Anyway, we're out of time.
I will talk more about threads next lecture.