WEBVTT 1 00:00:02.129 --> 00:00:08.280 William Cheng: Welcome to week. A week at our discussion section. So I guess, according to our 2 00:00:09.960 --> 00:00:19.830 William Cheng: Website week he doesn't have a PDF file. There's a text file over here. So we're going to sort of focus on Colonel to polymorphous so we're going to read a bit of code in Colonel to 3 00:00:20.490 --> 00:00:33.420 William Cheng: In the last discussion section, we sort of look at some of the header file. So today, we're going to sort of look at more of the sea file. So over here, there's a bunch of stuff 123456756 there's a bunch of stuff. We're going to look at 4 00:00:34.740 --> 00:00:35.340 William Cheng: So, 5 00:00:36.450 --> 00:00:36.810 William Cheng: I guess. 6 00:00:37.830 --> 00:00:48.390 William Cheng: You know, one of the first thing you have to implement his path to resolution. So again, if you think about one of the function of the implement his surname be given a POS system path, you know, get a 7 00:00:49.440 --> 00:00:58.710 William Cheng: Get, get to to generate be note, you know, for, you know, for this process and past. So again, you know, the way you think about a vino is that the vino points. So I know 8 00:00:59.220 --> 00:01:08.430 William Cheng: So so so in the end over here when you perform path and resolutions that you want that I know for this particular path gazing lecture, we talked about, you know, doing this sort of 9 00:01:08.910 --> 00:01:15.480 William Cheng: Intuitively, we start with the route and then inside the root directory. We're going to. So the example over here right inside system file system. 10 00:01:15.780 --> 00:01:21.150 William Cheng: So how do you find system above us them while you find some of our system in the root directory there. 11 00:01:21.810 --> 00:01:30.690 William Cheng: So, so in that case you need to perform and look up operation. Right. So, given the root directory. Is there a component name as five Fs. If there is, it will return Urbino right 12 00:01:30.930 --> 00:01:37.170 William Cheng: And then what you do is that inside that that vino that will be the vino that correspond to slash as five s 13 00:01:37.620 --> 00:01:43.080 William Cheng: You try to look forward. The been entry over here. So again, Ben is going to be a component name, you're going to use look up 14 00:01:43.590 --> 00:01:49.530 William Cheng: The first argument should be the Beano that correspond to slash f5 Fs, to see if it's such a thing exists. 15 00:01:49.860 --> 00:01:56.400 William Cheng: If it does, that's great. Right. So in the end, he will return to be know that represent slash as five Fs slash Ben dragon that will be the keynote. 16 00:01:56.610 --> 00:02:07.740 William Cheng: And then inside that vino which is a directory be no you need to look up a LS component to see if exist, right. So again, this is sort of shows you how to how to implement the path and resolution, you know, 17 00:02:09.120 --> 00:02:20.070 William Cheng: The basic algorithm. So in the end, you know what it will do is it again. He will return you. I know, but he will put a vino around so you can you can you can get access to the diner. Alright. 18 00:02:21.120 --> 00:02:30.330 William Cheng: So this function right the first argument over here is the process and pads are in the end the resolve, you know, over here, this is the one is going to be the final vino that you that you generate 19 00:02:30.810 --> 00:02:39.420 William Cheng: For this particular I know and then it will also need to return two more pieces of information. One is the name length and number of character in the last part. 20 00:02:39.780 --> 00:02:48.270 William Cheng: Of this fastest and Pat and then the name over here is going to be ls in this example. So again, it's only about the last part of the forces and path. 21 00:02:48.780 --> 00:02:52.770 William Cheng: So when you're doing your kernel to assignment. When you try to pass a bunch of tests inside BFS test. 22 00:02:53.370 --> 00:02:58.260 William Cheng: One of the question that you will get is that what you call during envy. What is the last character is a slash character. 23 00:02:58.710 --> 00:03:02.040 William Cheng: Okay, so in that case, again, you need to, sort of, sort of, sort of figure out what you need to do. 24 00:03:02.700 --> 00:03:14.670 William Cheng: One thing that will recommend us to run a bunch of commands your Linux command shell to see how they behave. Right, so, so I think you lecture I mentioned that if the last character is a slash character. That means that you need to treat it as a directory 25 00:03:15.600 --> 00:03:22.710 William Cheng: Then, so again. So, so you need to you need to take it over the special cases where the you know the last character is a slash 26 00:03:23.310 --> 00:03:31.440 William Cheng: So in that case, there's no component name. In that case, what do you do, etc. Okay, so, so, yeah, feel free to ask me questions, feel free to have a discussion in class. Yeah. 27 00:03:32.850 --> 00:03:40.530 William Cheng: All right. The second point over here is that you know when it's minus and means to start with a blank this right. So with the greater. Great job, all your kernel assignment. 28 00:03:41.190 --> 00:03:53.910 William Cheng: You know, the greater is required to start winning with with minus end right so minus that meaning you start with a blank this. So what's a blank this right a blind. This cannot be completely blank right a blank this meaning that it's a dis that only has the route. 29 00:03:54.330 --> 00:04:01.980 William Cheng: You know the route the route. I know in it. Okay, because it's still have to have root ID and what's inside a rhino at the root. I know is going to be empty. 30 00:04:02.880 --> 00:04:07.710 William Cheng: OK, so the entire file system hierarchy has to have one. I know. And that's the road. I know. But he said, Dude, I know. 31 00:04:08.460 --> 00:04:13.710 William Cheng: So, so what does the end empty rude. I don't look like, right. It has two entries. One is dot the other ones, dot, dot. 32 00:04:14.700 --> 00:04:19.080 William Cheng: Right. I mean, you know, because it because it cannot be completely empty because even complete empty. That's the wrong data surgery. 33 00:04:19.290 --> 00:04:26.400 William Cheng: It's just like, you know, you want my point. When you initialize my forward to listen it. How do you initialize such a data structure, while you still have to have the 34 00:04:26.760 --> 00:04:29.850 William Cheng: The anchor next and previous point to itself. Right. You have to have 35 00:04:30.240 --> 00:04:36.780 William Cheng: You sort of have to have a good starting place and from this point on, you know, you want to make sure that that data structure is always in a consistent state. 36 00:04:37.080 --> 00:04:42.840 William Cheng: Okay so sampling. Over here we have a blank this. You also need to make sure that the blank. This is in a consistent day 37 00:04:43.410 --> 00:04:48.540 William Cheng: So I think the pristine kernel source code sort of give you the code or tour already do that. 38 00:04:48.900 --> 00:05:00.330 William Cheng: Guys, so therefore, as soon as you start running, we make you have a empty desk. Okay, so again you have a rude. I know. And if you open up the rhino is you see to directly entry. One is one is called Da da da da da. Yeah. 39 00:05:01.890 --> 00:05:08.640 William Cheng: All right, the route. I know is cached inside the operating system. Alright so so inside the operating system. We don't really use it. We use the vino 40 00:05:09.090 --> 00:05:16.320 William Cheng: Right, so the vino is the one that points to I node, and will you start doing your kernel to. Will you read the idol proc run 41 00:05:16.770 --> 00:05:31.050 William Cheng: You will see that there's something related to be Fs, and they have to say that you have to set up this road. I know. So once the operating system started y su initialize the bfs operating says that there's always a representation of the root, I note and that's called BFS rufino 42 00:05:32.070 --> 00:05:41.100 William Cheng: Okay, so, so, so over here it says it's cached inside the operating system. So again, what does it mean, what does it mean it's cash. The way that means that that means that there's an in memory image. 43 00:05:41.580 --> 00:05:45.510 William Cheng: For the data on desk. Okay, so, so as soon as you start 44 00:05:46.440 --> 00:05:58.590 William Cheng: To finish initialized BFS that then you have a valid route. I know. Yeah, so therefore you can, I guess you can see that inside the kernel code there are places where they will K assert to say the root, the root vino better be. 45 00:05:58.950 --> 00:06:02.490 William Cheng: Not equal to know. Otherwise, you know, otherwise the code is not gonna work. Yeah. 46 00:06:04.110 --> 00:06:14.640 William Cheng: Oh, yeah. So this is the variable by VM FS Rubina mentioned internet v. So, that will be the the vino so once you initialize the bfs. You know, this, this, you know, 47 00:06:15.000 --> 00:06:21.720 William Cheng: This pointer. I hit this point to initialize initialize initialize so you so you need to make sure that it's point to something. Yeah. 48 00:06:22.860 --> 00:06:30.180 William Cheng: So if you grew up by Rule VF as Rubino instead of pristine kernel source go, you're going to see all this different places. Right. 49 00:06:31.350 --> 00:06:45.180 William Cheng: In name V Darcy over here. They're just a comment and then the rest of his and BFS Darcy so BFS Darcy what show you how this, you know, how does BFS Rubino get creators are gonna sort of briefly take a look at the code there. 50 00:06:46.890 --> 00:07:00.390 William Cheng: VI Colonel FS BFS. See right here. Yeah, so the FS root vino right so we can see that this is already initialized right here. 51 00:07:00.960 --> 00:07:07.020 William Cheng: And then here's a comment and then here's an assignment you know his assignments. They met right so this is 52 00:07:07.770 --> 00:07:14.850 William Cheng: So one of the options to them terminology I use it before. This is called binding okay if you have an unbounded variable, right, what is the unbounded variable. 53 00:07:15.630 --> 00:07:28.740 William Cheng: Variable is equal to know it was initialized. That is unbounded. So when we execute this this day, man, this variable is now bound to something right. What is it down to the bounty FS right arrow, arrow FS route. 54 00:07:29.160 --> 00:07:35.910 William Cheng: Get so efforts is the file system and every file system has a root directory. So we here to say that, you know, it's a we have a process them. 55 00:07:36.120 --> 00:07:46.920 William Cheng: In Colonel to the file system is going to be around us is that the round file system has a Rubino Raza FS route over here, you can see that it's an assignment operator. So therefore, the argument over here has to be a V note. 56 00:07:47.550 --> 00:07:57.480 William Cheng: Okay, so every file system is going to have a Rubino so this one says the current route and fosters that is going to be the root of the fallacies them inside the RAM thousand so 57 00:07:58.200 --> 00:08:07.830 William Cheng: The current root of the entire weeks out the car. The we Unix operating system is going to be the root of the ramp up the ramp our system. 58 00:08:08.520 --> 00:08:15.720 William Cheng: Then, so later on when you are working on Colonel three and that case FS over here is going to be the fastest and for the system five of us is that 59 00:08:15.930 --> 00:08:28.770 William Cheng: Again this isn't part of our system is a different kind of process, then it also has FS Ruiz the vino so again the same, you know, a pointer over here now will be pointing to the route. I know site. The Rubino for this isn't pa pa system. 60 00:08:29.370 --> 00:08:39.840 William Cheng: Yeah, so the bfs ruffian over here. This one is appalling more of a pointer because in Colonel to it will point to the root of the references. I mean, Colonel three will point to the root of this isn't a PA system. 61 00:08:40.170 --> 00:08:54.870 William Cheng: Right, exactly the same pointer point two different things at different times now. So where do you get the FS over here. So if you look at FS over here. FS started out to be a local variable is it initialize over here, we call K Malik to allocate this data structure. 62 00:08:56.700 --> 00:09:04.500 William Cheng: So, and then what you will do is that you will initialize this right so. So as it turns out that the way to initialize is done in 63 00:09:04.920 --> 00:09:08.280 William Cheng: Inside this function is called the mount mount function for the fastest time 64 00:09:08.520 --> 00:09:19.740 William Cheng: So you can see that this code over here. What it will do is that it will go to this file system object and then fill out the the additional data structure inside the cell system. Okay, so you can try to look for the slash 65 00:09:21.000 --> 00:09:25.710 William Cheng: You know, the, the malfunction over here and you will see that this is the last function inside this file. 66 00:09:26.310 --> 00:09:29.430 William Cheng: Okay, so this code is very simple right over here. It says, if that 67 00:09:29.850 --> 00:09:41.160 William Cheng: 655 so right now we're doing code all to. So this one is not defined. So, therefore, this data structure only contains emphasis that and then it contains the pointer that points to a function called grandpa system mount 68 00:09:41.730 --> 00:09:54.360 William Cheng: Okay so mounting the RAM file system is how you create this file system then. So what it will do is that it will go through this list and then call the malfunction over here and the malfunctions emphasis amount. So you can do a graph for the ramparts is the amount of lips. 69 00:09:57.000 --> 00:09:57.810 William Cheng: Dysfunction. 70 00:09:59.370 --> 00:10:09.120 William Cheng: Grip. This one kernel FS star Darcy. This is only reference here, right. So you need to go one level deep over here and you will see that 71 00:10:21.660 --> 00:10:28.530 William Cheng: Hmm, okay. So anyways, it's inside over here. So if I look for this function ran as fast as a mouse right here. Okay, so again, 72 00:10:28.950 --> 00:10:39.090 William Cheng: The mounting over here is doing initialization guys over here. Here's FS over here, this is the fastest in beta stretcher and campaign can be used to represent any faster. Same referral system system of our system. 73 00:10:39.600 --> 00:10:42.360 William Cheng: So what it will do is it will initialize this file system that 74 00:10:43.170 --> 00:10:48.210 William Cheng: So remember the rough us. Isn't it just a fake process them. So what they would do is that it will actually 75 00:10:48.570 --> 00:10:59.670 William Cheng: You know, you use memory to represent us versus them. So this isn't doesn't sit on the desk. It sits inside memory. And that's why it's called a ram file system. Okay so RAM is your memory. 76 00:11:00.150 --> 00:11:04.380 William Cheng: So what it will do is that it will create all these data structure to represent the fake disk. 77 00:11:04.860 --> 00:11:09.270 William Cheng: OK. So again, there's a lot of stuff. I'm not going to go into the detail over here. And then in the end. 78 00:11:09.600 --> 00:11:17.040 William Cheng: They will point to, you know, the first, I note over here which is I know zero inside this data structure over here and that will be the Rubino yeah 79 00:11:17.850 --> 00:11:25.770 William Cheng: Right. And then at the end the call this function called the gap. So what the bigger function does over here. I actually, you know, 80 00:11:26.670 --> 00:11:40.140 William Cheng: In this slide over here at the end. I actually mentioned in point five over here, I talked about V get IV get is a very, very important function to understand. So this, this function given 81 00:11:41.400 --> 00:11:51.180 William Cheng: Sorry, you know, given a file system, which is FS are given. I know number of VM over here, find the I know inside this file system and return the corresponding me know 82 00:11:51.720 --> 00:12:00.210 William Cheng: Okay, so the vino number over here. So remember every file system can have, have I know number zero, guys. So therefore, we tried to look, look. 83 00:12:00.600 --> 00:12:08.970 William Cheng: Look for a particular. I know we need to specify which file system it's inside of that inside of so that's why we need to specify which file system and which I know number 84 00:12:09.540 --> 00:12:18.540 William Cheng: Okay, so be no over here it's going to be. I know number. So go to this file system find this vino okay so over here. If this I know already exists. 85 00:12:19.110 --> 00:12:27.330 William Cheng: You know, so if the given I know already has a corresponding vino why, in that case, you should just returned that vino and you should increment the reference God 86 00:12:29.010 --> 00:12:38.430 William Cheng: OK. So over here, if that vino already exists. So now when you call began, you try to point you out. You try to use another point to the point to a while so definitely this case you should increment the reference count. 87 00:12:39.780 --> 00:12:48.390 William Cheng: Okay, so. So some people ask the questions and say, well, why do we do this inside Vika. Why don't we, when we call Vigo Vigo return a pointer and then we can increment the reference car. 88 00:12:48.660 --> 00:13:02.850 William Cheng: That will also be correct, right. So, again, it depends on their the opposite of the design style for some reason to Brown University people decide that inside we get there if we can find that the corresponding vino which are incremental reference car inside the 89 00:13:04.410 --> 00:13:14.520 William Cheng: Inside the get okay you do the outside. It's also valid. But again, that's not how the other as a how we next word they decide to increment the reference count inside assumption. 90 00:13:15.270 --> 00:13:27.030 William Cheng: Now, or what are the I know it doesn't have corresponding the amino good so so so the the the assumption over here is that the i know that i know number over here is going to be a valid. I don't remember it. But if it doesn't have a corresponding vino 91 00:13:27.210 --> 00:13:30.420 William Cheng: In that case, we need to allocate a data structure and initialize the Beano 92 00:13:30.870 --> 00:13:40.890 William Cheng: Okay, so in this case we're going to create a vino for it and set the reference come to one, because now it's a brand new vino so therefore the reference cards. Why, because when I return this pointer to wherever that needs it. 93 00:13:42.090 --> 00:13:51.210 William Cheng: Okay, so, so the note over here is that this is where a vino get created. Okay, so every time we want to create a vino what you should do. What should you do, you should call the get 94 00:13:51.750 --> 00:14:04.230 William Cheng: Okay, don't try to create a yourself if you create yourself, you know, chances are, chances are it's going to be incorrect. So again, called v. Get over here for you to create a vino right and if it turns out of it already exists. Well, then, in this case, you just increment the reference. Yeah. 95 00:14:06.000 --> 00:14:15.150 William Cheng: Alright, so we're here. So in the end the call call began. So in this case, you know, this FS for Colonel to this is going to be, oh actually full, full for this ranch houses them. 96 00:14:15.690 --> 00:14:24.390 William Cheng: This file system over here will be the referral system. Right. And the vino number over here, sorry that I know number over here is equal to zero. So for our Colonel Sanders against this is a toy operating system. 97 00:14:24.660 --> 00:14:29.280 William Cheng: I know and and vino are exactly the same number. Okay, I know number equal to be no number that 98 00:14:29.790 --> 00:14:39.690 William Cheng: So in this case, the, I don't know, you go to zero. So, so, so, so again, when you create an empty file system, the NT passes that has to have at least one. I know. And that will be the route. I know. So we go to route. I know. 99 00:14:40.200 --> 00:14:48.930 William Cheng: I know number zero, and then it this way, we're going to create a vino around it. And then we're going to return to be no so the vino over here is going to be assigned as the root of the file system. 100 00:14:49.500 --> 00:14:54.300 William Cheng: Okay, so this one says the root of the file system is going to be. I know number zero 101 00:14:55.050 --> 00:15:01.740 William Cheng: Right, so that's that that's what the Simon is and then at this time you finish mounting, you know, the rebels them. 102 00:15:02.100 --> 00:15:12.600 William Cheng: So in that case you return back here. Okay, so now the fastest them over here, this data structure will be initialized. And now we can use it right so we hear the malfunction. When the malfunction return. What is the return 103 00:15:14.490 --> 00:15:22.980 William Cheng: Mount function return right here, right. All right, when it returns over here inside the file system over here. Every feelings that a person that has been initialized. 104 00:15:23.190 --> 00:15:34.110 William Cheng: Especially the most important thing is the root vino so therefore, we're going to take the movie. No. And then this will be the the the the the Phoenix, you know, Rubino is the 105 00:15:35.100 --> 00:15:49.140 William Cheng: The Phoenix Rubino is the vino of referral system in Colonel to okay what is exactly the same code and kernel three so that the root of Phoenix is going to be the Rubino for the system, our system isn't about us there. 106 00:15:50.790 --> 00:15:56.550 William Cheng: Alright, so this is a VM FS in it. Okay, so guess what sort of jumping ahead a little bit already 107 00:15:57.150 --> 00:16:10.620 William Cheng: So okay, so the VM FS Rubino is an FS independent right because you know it's done at the bfs level. It's a poly morphic pointer. So where is this thing bound over here. So again, which addresses that code. Yeah. 108 00:16:11.610 --> 00:16:21.270 William Cheng: The file system is the FS it's interfaces FS FS up over here. What function can be reached via this interface we already see one of the function over here is called a malfunction. 109 00:16:21.600 --> 00:16:27.570 William Cheng: Okay. As it turns out, there are three more functions over here. So we should look at VF s dot h. So let's take a look at 110 00:16:28.050 --> 00:16:40.710 William Cheng: Her know include FS BFS HR. So we have is that he has some of the function or implemented BFS see. So we saw that before that. So over here, they define a FS up offs. 111 00:16:41.490 --> 00:16:51.390 William Cheng: Now, so in the Linux kernel. They tried to name the data structure in a consistent way. Anytime you see anything that's underscore LPS okay 112 00:16:52.170 --> 00:17:03.900 William Cheng: Oh, PS is operation. So, so this, this is a data structure there looking like this is going to be an array of function pointers. Okay, so this one is the file systems array of function pointer. So the passes away from a function wider. 113 00:17:04.110 --> 00:17:12.060 William Cheng: As it turns out, he only has four functions. Okay. The first one is called Rubino so inside the ran fastest, then there's a function called parenthesis and Rubino 114 00:17:12.390 --> 00:17:20.460 William Cheng: Okay, and then a second version is called the levy. No. So instead of emphasis them. There's a function called grandfather's ism believe you know and then there's an emphasis on Kirby know and the other one. 115 00:17:21.390 --> 00:17:28.830 William Cheng: And then also the emphasis amount. And then there's another function called Red file system you mount umami, a mountain. I'm not in the file system. 116 00:17:29.400 --> 00:17:37.350 William Cheng: Okay, so, so I guess you know mount is initialization. So, you know, I'm not over here is that when you try to free you need to clean up data structure that 117 00:17:38.490 --> 00:17:46.530 William Cheng: So we're going to take a look at the first two over here Rubino and deliver, you know, right. So let's take a look at the revision over here that this is called by the get 118 00:17:47.370 --> 00:17:55.680 William Cheng: Gary vino will pass a vino into it. So the first argument is good. I'm going to call vino and the purpose of this function is to 119 00:17:57.360 --> 00:18:07.710 William Cheng: Is to initialize some of the data structure over here. Okay. So the idea of years as a we create a vino in the beginning, it's only partially initialize and then in the end you have to call a 120 00:18:08.430 --> 00:18:17.220 William Cheng: You know, a FS specific initialization function by by by by using FS off over here to initialize initialize the rest of the vino 121 00:18:17.760 --> 00:18:29.340 William Cheng: Okay, so this sort of tell you that the vino part of it is represent stuff inside BFS. And part of it is representing things inside the FS and only the FSA initialize that part of the data structure. 122 00:18:30.180 --> 00:18:36.750 William Cheng: Okay, so therefore the review over here. I don't know why the Brown University will call this Rubino I will call them initialize vino 123 00:18:37.380 --> 00:18:40.350 William Cheng: But they'll maybe there's a good reason they don't call her initialize veto right but 124 00:18:40.770 --> 00:18:48.660 William Cheng: You can read the text over here. It says, try to initialize them. Okay, so here are the function that are supposed to initialize VN ops right so yeah ops over here is a 125 00:18:49.560 --> 00:19:00.420 William Cheng: function pointer, the mode over here. It says, what kind of file, it is right there. So the motor the file, you know, could be a regular file could be a directory file could be you know device file, you know, etc. 126 00:19:03.720 --> 00:19:08.250 William Cheng: And then VN lane over here. That's the size of the file. Okay, so every file. 127 00:19:09.360 --> 00:19:17.880 William Cheng: This file has a full length. So if you could tell you what, how long the fathers and then Vienna over here. That's a voice star pointer that points to the I know 128 00:19:18.870 --> 00:19:26.610 William Cheng: Okay, so what you call this function over here. That's how you bind the side that's how you connect the vino and I know together. 129 00:19:27.060 --> 00:19:33.150 William Cheng: Because inside this data structure. We're gonna, you know, we have a BMI underscore I that's originally unbound 130 00:19:33.660 --> 00:19:38.400 William Cheng: I think it's initialize equal to know pointer over here. So now inside this function you're going to point it to the I know 131 00:19:39.030 --> 00:19:48.870 William Cheng: Okay, so at this point, once you finish run this function. The vino and the I know that are connected together. Yeah. Well, we can actually take a look at that code over here. Let's look for read vino 132 00:19:50.160 --> 00:19:56.010 William Cheng: So, Colonel FS ran file system or emphasis and see 133 00:19:56.910 --> 00:20:08.310 William Cheng: So here's a repeat of ideas. Okay, I just see here, is he, you know, again, ops over here as a reference you pointer. We have the random FS Rubino run at FS to levy know right that's quarter, you know, as, as you mount 134 00:20:08.970 --> 00:20:13.200 William Cheng: So we can take a look at the RAM FS read been over here. So here's the function over here. 135 00:20:14.070 --> 00:20:21.630 William Cheng: That. So this is a very important function because what it will do is that it will initialize the original function pointer inside the vino okay so 136 00:20:22.170 --> 00:20:32.100 William Cheng: So what it would do is, I will be here, you know, given the V note over here we're going to cover this vino to the referral since then. So, this one will will will 137 00:20:32.520 --> 00:20:41.940 William Cheng: Will give you the fastest them. So over here, RFS over here is a ran fastest empty Rob, can actually go to the top to see what a ramp Assistant T is 138 00:20:48.090 --> 00:20:59.160 William Cheng: Okay, so here's the ranch houses empty over here. It's just an array of vinyls okay so so the ramparts is them again it's it's a it's a fake file system right it doesn't have a desk. 139 00:20:59.730 --> 00:21:06.540 William Cheng: only exists in memory. So, what is it, it's just an array of my notes. Okay, so this design is a little different from the system offices and design. 140 00:21:06.750 --> 00:21:13.470 William Cheng: This isn't part of our design divided this into the the boot blog. The Super blog and then the I notes and then that data region. 141 00:21:13.950 --> 00:21:19.560 William Cheng: So again, this is a very simple process. And so what they what they did was that they combined the I note with the data region. 142 00:21:20.100 --> 00:21:30.030 William Cheng: Okay, simply, it's going to be an array of my nose and the mag, the ram file system must also be equal to 64 so it's an array of 6464 files. 143 00:21:30.540 --> 00:21:39.870 William Cheng: Okay, every file is represented by. I know. So, therefore, you know, every idle over here is this data structure run Fs. I know T remembers it is right here. 144 00:21:40.620 --> 00:21:54.300 William Cheng: There. So, this I know to be here. It says that this is the total file size inside this far. And here's the I know number 0123 all the way to 63 and then this is a pointer that points to over here says one page. 145 00:21:55.290 --> 00:22:02.340 William Cheng: Okay, so, so, so in the US is that every file can be can be only as big as 4096 bytes small 146 00:22:03.270 --> 00:22:12.420 William Cheng: OK. So again, it's a faith versus them. So if you want to make this bigger, you can't do it because there's a limitation to the file size. Okay. And that's that that's one page was this four kilobytes. Yeah. 147 00:22:12.870 --> 00:22:20.700 William Cheng: The mode over here. Tell you what type of follow this right. And then the last one of you is going to be a link out right so get this link is the one that inside the file system. 148 00:22:21.210 --> 00:22:30.600 William Cheng: So, so it's sort of it, the account number of hard links that are pointing to a file. Okay. If the number of harming so zero, then that means that you know the stock can be deleted. 149 00:22:32.370 --> 00:22:39.540 William Cheng: Right, so, so you can see that this I know data structure. It's much simpler than the system files of our system. I know data structure or is it again. 150 00:22:39.780 --> 00:22:52.320 William Cheng: This is this is good enough for a fake file system that exists only memory and the every thought is that most four kilobytes in size and we have an array of 64 files. So if you try to create one and 64 files. What's gonna 151 00:22:53.010 --> 00:22:58.230 William Cheng: What's gonna happen is is that it will fail or will you try to create one more file that 152 00:23:00.090 --> 00:23:09.960 William Cheng: Alright, so let's go back to review note over here. So over here, what it will do is is that, you know, given the vino he will try to, you know, give you a pointer to the fastest them. So again, array of I knows over here. 153 00:23:10.230 --> 00:23:16.710 William Cheng: And then the. I know. So given a vino number of the Beano number of years as VN right right arrow, Vienna Vienna. 154 00:23:17.040 --> 00:23:24.990 William Cheng: Okay, so this will give you an array index and this will return to you what I know right and UK assert, make sure that I know is valid and also the I know the 155 00:23:25.440 --> 00:23:30.960 William Cheng: Number. It's the same thing as the vino vino number. Okay, so, under what condition that this will be different. 156 00:23:31.920 --> 00:23:38.880 William Cheng: Okay, so this should always be the same. The I know number and the number there, they should be the same. The only time that this can 157 00:23:39.450 --> 00:23:42.150 William Cheng: They can be different, is when you have a memory corruption, but 158 00:23:42.870 --> 00:23:51.210 William Cheng: Again, we have a memory card number. That means that the vino is pointing to. I know. And the vino still think that is pointing to the original. I know, but somehow because of the memory corruption bar. 159 00:23:51.390 --> 00:23:57.120 William Cheng: You got rid of the I know you allocate a new. I know. And now you have a different I know number. Well, then in that case, you know, my path is going to happen. 160 00:23:57.480 --> 00:24:04.200 William Cheng: Okay, so this chaos, so I should try to help you to catch, catch, catch bugs as early as possible. Yeah. 161 00:24:05.040 --> 00:24:17.520 William Cheng: Alright, so he's had to read the vino over here. Are you try to initialize it. So in this case, the code over here. What incremental the link out and it was said the envy and I over here to be equal to the I know 162 00:24:18.270 --> 00:24:24.780 William Cheng: OK. So again, via night over here, what does, what does that Colonel include FS vino that he 163 00:24:25.800 --> 00:24:34.620 William Cheng: Be an underscore I this is a voice star pointer and we're very familiar with yourself pointer right can be used to point to anything. So in this case, starting from BFS. 164 00:24:34.800 --> 00:24:45.810 William Cheng: It needs to point up, it needs to point a pointer to the actual file systems. I know representation. Right. So in this case, the pointer to the appointed time will via has to be voiced art because this is the polymorphous pointer. 165 00:24:46.890 --> 00:24:53.160 William Cheng: Right, because you know if you're pointing to the system five losses them and then in that case you need to point to a system of awesome. I know. 166 00:24:53.370 --> 00:25:01.890 William Cheng: If you're, if you're using our emphasis and why, in this case, this point or will need to point to a ramp our system. I know. So therefore the only data type there a septum over here is going to be a voice ponder 167 00:25:02.910 --> 00:25:07.320 William Cheng: OK, so again watch off a voice star is usually mean some kind of a level of indirection. Yeah. 168 00:25:08.820 --> 00:25:13.380 William Cheng: Alright, so we're here, we're going to say that Vienna over here. It's a voicemail pointer is going to point to the I know 169 00:25:13.650 --> 00:25:15.960 William Cheng: That that corresponding to this been over here. 170 00:25:16.140 --> 00:25:23.460 William Cheng: And then the I know RF size over here is that for the I know there's a file size. We also need to copy that value into the vino so the so 171 00:25:23.580 --> 00:25:30.030 William Cheng: So, so in this case anytime you need to know the file size. You don't have to go to the actual process and this information is available over here in the Beano 172 00:25:30.510 --> 00:25:36.810 William Cheng: Okay, so they don't even also going to see a kisser to say that these two values over here. They better match all the time. 173 00:25:37.200 --> 00:25:40.740 William Cheng: Okay, if they don't match, again, that means that you probably have a memory corruption bug. 174 00:25:40.950 --> 00:25:50.460 William Cheng: That that somehow you free up a data structure. I didn't realize it, and you still have the vino pointed. I know. But that I know is gone, and I don't get reallocated to a different file and now did, and now 175 00:25:50.910 --> 00:25:59.100 William Cheng: The, the, the, the vino file size is not the same as I know fossa. So again, that's that that's a clear indication that you have some sort of memory corruption, but yeah. 176 00:25:59.850 --> 00:26:07.200 William Cheng: Alright, the next thing over here is that you also initialize some of the other point oh we're sorry again over here. The purpose of this function is to initialize the vino 177 00:26:07.980 --> 00:26:15.870 William Cheng: Many of the pointer inside of you know so you know if the I know type. Right, so I know it over here also has a moat rightly tells you what kind of I know it is 178 00:26:16.170 --> 00:26:22.980 William Cheng: If this one it's a it's a regular file. So in this case, what it's going to be the the monthly vino what the vino should also say that this is a regular file. 179 00:26:23.370 --> 00:26:30.330 William Cheng: Okay, so the way it's done over here is to say VPN right arrow VM mode is equal to s underscore i f reg 180 00:26:30.720 --> 00:26:37.980 William Cheng: Okay, so, so this one says, you know, this particular file is a regular file. Okay, so that's what the red meat is a regular pop that 181 00:26:38.370 --> 00:26:50.670 William Cheng: And then in this case, the, the, the, you know the real function pointer inside the vino is going to be the files are the default operations. Okay. Ram FS file operations over here. So let's take a look at that. 182 00:26:52.830 --> 00:26:58.800 William Cheng: Okay, so this is the area function point over here that allow you to read from, you know, to read a file to out of house. Okay. 183 00:26:59.040 --> 00:27:08.940 William Cheng: These functions has to be FS independent because this function are inside the ranch houses them there. So inside BFS. Will you try to read from a file. All you need to do so. Use a real function pointer. 184 00:27:09.150 --> 00:27:17.850 William Cheng: And then call through the function indirectly. So this way. If you're using a rep houses them, you end up calling referral system read if you're using the system purposes me going to end up calling the system. 185 00:27:18.030 --> 00:27:26.190 William Cheng: Our system rate. Right. So again, we're going to use a poly morphic pointer. So inside your kernel, you can actually perform these operations, independent of the actual file system. 186 00:27:26.700 --> 00:27:34.080 William Cheng: Okay, so you can actually see that is that Rubino. That's what we found all these pointer. So one, this one, or if you just want to refund the file. You don't really care whether it's 187 00:27:34.350 --> 00:27:43.500 William Cheng: Around passes that our system baba says them all you need to do is to use the function pointer number one over here or function number or a index zero you call it, and then you're going to end up reading from, you know, 188 00:27:44.280 --> 00:27:45.270 William Cheng: Reading for us. 189 00:27:45.840 --> 00:27:53.220 William Cheng: There so as over here, the way you read this, is that you know he was an array of function pointer. Right. The first one is your partner over here is for reading from a file. 190 00:27:53.400 --> 00:28:01.530 William Cheng: And the second one is for writing for writing to a file and map over here, useful to know let me stop for a regular file. You are not allowed to map it into address space. 191 00:28:02.370 --> 00:28:07.950 William Cheng: Okay, why aren't you allowed to do that what because because of your grandfather's then, you know, we don't want to make it too complicated. 192 00:28:08.340 --> 00:28:16.470 William Cheng: So we're going to say that the MF function is unavailable on a regular file. Okay, so that's why this got point to point. And what about a creative function. 193 00:28:17.130 --> 00:28:24.810 William Cheng: Well, I will say this is a regular file right this is the follow because that means that regular file in the regular file. Can you create 194 00:28:25.110 --> 00:28:30.150 William Cheng: Is that a regular file. Well, the answer is no. For regular file. The only thing you're allowed to do is to read and write from it. 195 00:28:30.780 --> 00:28:36.180 William Cheng: Okay, so therefore that's what only these two pointers are valid, right. You cannot create inside a regular file, can you 196 00:28:36.690 --> 00:28:44.520 William Cheng: Make no is create a device can you to create devices that are regular file. The answer is no. You can only create a device inside a directory 197 00:28:45.450 --> 00:28:48.300 William Cheng: Okay, so if it's a directory file that you can create a device in there. 198 00:28:48.750 --> 00:28:56.790 William Cheng: You can also create a sub directories that are directly. You can also create a file, instead of sub directory. So that's why these functions are not available for regular file. 199 00:28:56.970 --> 00:29:04.740 William Cheng: You cannot perform and look up on shootings data file, you cannot perform a link function on things, all these funds are available. The only function is the staff function. 200 00:29:05.130 --> 00:29:15.840 William Cheng: Okay, as the stat is trying to get the status of a file. So this guy's whether it's a directory fall or whether it's a regular file, you should always be able to call a stat on a particular file. Okay, so in this guy is what 201 00:29:16.500 --> 00:29:20.520 William Cheng: What a staff do so again you just do a man page a man's that over here. 202 00:29:21.150 --> 00:29:28.770 William Cheng: Okay, so this one is going to be the wrong stat. So if you keep scrolling down over here see is you see that. See also stat to so 203 00:29:29.220 --> 00:29:37.530 William Cheng: You know, let's do this again. So this one is the stat function in section one of the main page. Okay, so you want the the wines that Section two or demand pay 204 00:29:37.740 --> 00:29:43.800 William Cheng: So he's a man minus s to go to Section two or the main page over here and then look for the stat function. 205 00:29:44.100 --> 00:29:51.030 William Cheng: Well guy. So this guy is going to end up getting you know this data structure. So again, this is section two is the Linux programmers manual 206 00:29:51.450 --> 00:30:00.600 William Cheng: Audit define what the staff function is. And then he will fulfill this data structure known as the struck stack. So if you keep scrolling down over here, it sort of shows you 207 00:30:01.350 --> 00:30:02.640 William Cheng: What the State of structure look like 208 00:30:03.480 --> 00:30:14.850 William Cheng: So this data structure tell you which devices on what is the I know number. What is the protection mode so unfortunately over here when it talks about mode, it's actually a protection mode right okay you have read the man pages very carefully. 209 00:30:15.450 --> 00:30:23.790 William Cheng: The number of links over here. User ID group id the device ID. If it's a special file and then the size of the file and then at the end over here. 210 00:30:24.150 --> 00:30:36.210 William Cheng: The time. The last time the file was access. A lot of times last time the file was modified and then on the, the, the, I guess. Over here is the creation time with the file or the last time the status has changed on this particular file. Okay. 211 00:30:38.070 --> 00:30:48.090 William Cheng: So we can also do the same thing. We can look for struck a stat in the kernel includes star dot h. Right. So over here. Where's the divine in 212 00:30:49.590 --> 00:30:58.500 William Cheng: Instead of age right VI Colonel include FS that that age over here. So for our colonel. This is the data structure I you already see this the same thing in 213 00:30:58.680 --> 00:31:08.850 William Cheng: In Linux, right. So again, they all mean pretty much the same thing. I've got to find out the meaning of those, you should look at the Linux men. Men page in Section two of them and page for the staff function. Okay. 214 00:31:09.690 --> 00:31:18.840 William Cheng: Alright, so let's continue over here. So anyways, over here. So, so, you know, all the other function over here and available. Similarly for directory 215 00:31:19.980 --> 00:31:26.340 William Cheng: Directory file right for directory. There are different kinds of operation, you cannot perform a read on the directory file. 216 00:31:27.390 --> 00:31:38.040 William Cheng: Okay. So remember when you're doing a one on one and two, right. You can open a directory, but you cannot read and write from it. Well here it shows you why can I do it because when he tried to reframe it there's no function for it to do it. So, therefore, 217 00:31:38.340 --> 00:31:42.870 William Cheng: Therefore, you will fail. Okay. So inside BFS whenever you need to call one of these function. 218 00:31:43.080 --> 00:31:54.030 William Cheng: You know, indirectly, first you need to make sure that the function pointer is valid, is the financial part equal to zero equal to know when this guy. You should return an error. And you say that this function is not implemented for this particular file type 219 00:31:54.810 --> 00:32:02.190 William Cheng: Okay. Otherwise, you can actually call that. So for the regular for for directory file, you cannot refer me. Can I write to it. And they also, you cannot MFR 220 00:32:02.400 --> 00:32:13.140 William Cheng: But you can create a file, you can create a device you can look up a component, you can create a hard day. You can remove a hard link, you can create a subdirectory in it, you can remove a subdirectory 221 00:32:13.530 --> 00:32:24.990 William Cheng: You can read from a directory so forth directory file, which you can do is that you cannot read from the file, but you can call reader. Okay, so what does reader to reader would return to you one directory entry at a time. 222 00:32:26.220 --> 00:32:34.470 William Cheng: Okay, so the function of the reader over here so we can actually look at the source code or for emphasis and reader to see how it actually return a direct Ranger time. So again, what is the directory 223 00:32:34.860 --> 00:32:41.100 William Cheng: directory entries, the wind has component name and the I know number. So in this case, instead of i know it's probably gonna have a vino in it. Yeah. 224 00:32:41.910 --> 00:32:49.770 William Cheng: And directly also have staff function in that and also all the other functions over here on our I implemented. Okay. Alright, so let's go back here. 225 00:32:52.170 --> 00:32:58.830 William Cheng: So over here, it says if it's a regular file I need to remember that this is a regular file and then I will bind 226 00:32:59.220 --> 00:33:12.390 William Cheng: The array of function point are we here for the file. Okay. What if you know the actual file system says that, you know, this particular file is a directory far. So in that case, the, the be the mode for the veto veto is going to be 227 00:33:12.900 --> 00:33:21.270 William Cheng: So if directory as over here says, you know, this is the directory and then the the operations over here is going to be the directory operations right here. 228 00:33:21.780 --> 00:33:26.100 William Cheng: There as a to the other two more times over here. One is called a character device. 229 00:33:27.000 --> 00:33:36.270 William Cheng: So what I want a character device, right. As it turns out, for Colonel assignment, the stuff that you need to deal with. They're all character devices right slash def sizes as a character device. 230 00:33:36.720 --> 00:33:45.840 William Cheng: Slash deaths know as a character device last slide deck TTY 012 they're all character device. Okay. The only kind of block device is the hard drive. 231 00:33:46.200 --> 00:33:54.240 William Cheng: Okay but but our Colonel assignment, somehow, you don't have to implement it because they're implemented in colonel and by by the Brown University people in the system file system. 232 00:33:54.840 --> 00:34:01.950 William Cheng: Okay, so therefore, in our case, it'll always be the character device. So in this case, the mode over here will say that it's a character device right 233 00:34:02.250 --> 00:34:05.340 William Cheng: And the pointer over here we have a function one over here. 234 00:34:05.580 --> 00:34:12.870 William Cheng: For device, you cannot read for me. Can I write to you. Can you cannot do any of the operation. I just mentioned. So therefore, the real function point over here is going to be able to know 235 00:34:13.140 --> 00:34:16.230 William Cheng: Their brother over here it says the device id over here. 236 00:34:16.410 --> 00:34:28.710 William Cheng: It's going to be the device ID for this particular device. Again, the device ID is going to be a major device number of file by the minus divine number. So if you use the device id over here if you perform the right kind of look up, you will be able to find the device driver. 237 00:34:29.730 --> 00:34:34.050 William Cheng: Okay, so for a device file in order for you to refund the device. What do you have to do you have to reach 238 00:34:34.260 --> 00:34:39.600 William Cheng: The special file read. Nice. Oh, that's okay, using a device ID over here if you set it up properly. 239 00:34:39.810 --> 00:34:49.230 William Cheng: Magically in the code that's provided by the Brown University people they will use this information to do so. So what you try to get to the device driver what it would do is it will call the right function. 240 00:34:50.190 --> 00:34:55.830 William Cheng: And so again, all the magic that happens right here using this one line of code and then everything will work there. 241 00:34:56.490 --> 00:35:02.730 William Cheng: For Brock device. Again, they will say that this is a block device. The there's no array of function pointer over here, but it also specify 242 00:35:03.540 --> 00:35:12.990 William Cheng: Also sort of copy the device ID from the actual forces them to the virtual file system. Okay. Otherwise, it's an error, and he will, you will cause a panic. Okay. 243 00:35:15.870 --> 00:35:17.730 William Cheng: All right, so what does this year. 244 00:35:20.880 --> 00:35:32.820 William Cheng: Okay, so basically the file system or as anyways. I'll finish with this one. The next items over here. FS is the actual file system and interfaces FS ops over here. So again, I guess we saw this code already 245 00:35:34.440 --> 00:35:40.230 William Cheng: So next, look at the array of function point over here I so I guess we just finished looking at these kind of stuff. 246 00:35:40.530 --> 00:35:46.050 William Cheng: In the note over here. They're also something interesting. They also find this VN you know the be an ops over here. 247 00:35:46.470 --> 00:36:01.350 William Cheng: So we can actually execute this command again I'm going to copy it from this webpage over here. Okay. And then I'm going to paste it right here. Right. So this is what we see on the the web page, but we can also grew up for VR ops equals to something 248 00:36:04.290 --> 00:36:11.670 William Cheng: Okay, so this guy went to look for a stream VR ops space equals space. So in this case, we're going to see less number lines over here. 249 00:36:12.030 --> 00:36:15.900 William Cheng: So one of them is inside pipe would only care about pipe on this assignment. 250 00:36:16.200 --> 00:36:21.810 William Cheng: And then the other one is the inside of you know, so let's take a look at Colonel FSB know that see 251 00:36:21.990 --> 00:36:32.520 William Cheng: We need to look for VR ops over here equals to something right so again VR ops and array of function. Why don't we are binding this array of function pointer to another array of function pointer inside HDFS 252 00:36:32.670 --> 00:36:39.120 William Cheng: There. So in this example, we're here inside. Vino de see that this is a place, actually the implement stuff for the special files. 253 00:36:39.540 --> 00:36:41.520 William Cheng: Okay, so therefore you can actually see that over here. 254 00:36:41.760 --> 00:36:51.450 William Cheng: Will you try to initialize a special file vino as of yet. He has called in this special vino. So this is the Beano for I know that's a special that's a special file. 255 00:36:51.660 --> 00:37:07.890 William Cheng: And especially for me it's a device. So we here. What it will do is that you will actually look at the vino. We're here to see what kind of vino it is there. So, it's called an s underscore is char. Right. So what is this grip s understood is char Colonel includes our age over here. 256 00:37:12.510 --> 00:37:17.190 William Cheng: Okay, so I think I misspell is char, maybe I look like this. 257 00:37:19.590 --> 00:37:26.130 William Cheng: Alright so this one just says that you look at this, this mode over here to see if the if char that 258 00:37:26.760 --> 00:37:32.670 William Cheng: This particular bit is set. Okay. And we saw before, right, for a character device over here. This bill will be set. Yeah. 259 00:37:33.420 --> 00:37:41.580 William Cheng: So, so if this is the character device then VM VM ops over here. So we saw that in the emphasis and initialize this pointer to to know 260 00:37:42.540 --> 00:37:56.970 William Cheng: Okay, so not over here. They basically they replace this operations over here with something else. So this one is going to be to to be the address of by Deaf special, special ops over here, special VR ops over here. So again, let's take a look at what this is. 261 00:37:58.140 --> 00:38:08.250 William Cheng: OK. So over here, it says that, you know, for the by device. These are the function right if you try to read from this device you cause special far if you want to write it this way you can specify right 262 00:38:08.760 --> 00:38:14.460 William Cheng: So for your kernel to you have to implement these two functions, especially for our respective. All right, so now you know you know 263 00:38:15.210 --> 00:38:21.150 William Cheng: Now you know exactly where these things become bound right so so so that's what we used to call these functions you actually call through there. 264 00:38:21.540 --> 00:38:26.910 William Cheng: And so in this case for the devices that can actually you are allowed to end map them into address space there. 265 00:38:27.300 --> 00:38:35.370 William Cheng: There's a lot of other stuff over here. I guess that's your file stat I getting the status of a device file and then there's a full page 30 page clean page. 266 00:38:35.940 --> 00:38:41.460 William Cheng: Those, you have to worry about them in kernel three. So right now we don't have to worry about it. Okay, so this is that for the by device. 267 00:38:41.910 --> 00:38:46.770 William Cheng: That you have to read and write. So remember our you try to encourage them to 268 00:38:47.160 --> 00:38:56.280 William Cheng: The phase, why you have to get your cash out to work to get the occasional to work when you try to pre your prom onto the onto the console, you should read special power right 269 00:38:56.520 --> 00:39:05.190 William Cheng: Okay. Will you try to read what the, what the user type, you should call special about read again. The way you get here. Is that what you call do right is you read special file read 270 00:39:05.430 --> 00:39:19.170 William Cheng: For the file descriptor that correspond to the to the two TTY zero. And when you try to a call to read and the file the file descriptor is going to be correspond to the two TTY zero, then they should get to this function. 271 00:39:20.340 --> 00:39:26.310 William Cheng: Alright so so that that's what the by device. What about for the, you know, for the block device. 272 00:39:26.700 --> 00:39:31.710 William Cheng: For the block device, you can actually see that you know the reflection or everything is equal to know especially 273 00:39:32.100 --> 00:39:41.850 William Cheng: Separate a special file stat. Right. So for any kind of art, you should always be able to stand to get the status of this particular file right but a lot of time all the other pointers over here I invalid. 274 00:39:43.500 --> 00:39:45.780 William Cheng: Okay, so let's take a look at this again. 275 00:39:46.530 --> 00:40:00.930 William Cheng: So right here right over here, these things become that bound. If it's a character device you found this why and also there is a pointer inside vino called the character device. So if we go look at the vino again Colonel include Fs. We know that he 276 00:40:02.760 --> 00:40:13.200 William Cheng: Okay. See, Dev. So see, there was right here, right. So, so there's the device ID that we saw before that got said also are the see that initially it will be equal to know or initialize 277 00:40:13.500 --> 00:40:20.580 William Cheng: So inside that function. This one is going to be a reference to the character device. OK. So again, this one is I think this one is 278 00:40:21.630 --> 00:40:25.740 William Cheng: There's a character device interface. And then there's a by device interface over here. Okay. 279 00:40:27.630 --> 00:40:30.390 William Cheng: All right. And what is five device t 280 00:40:31.530 --> 00:40:38.340 William Cheng: Grip grab a bite the T Colonel include FS start at H, er, we get 281 00:40:39.360 --> 00:40:40.260 William Cheng: So, 282 00:40:50.940 --> 00:40:52.410 William Cheng: Alright, so this is the plan in 283 00:40:54.090 --> 00:41:03.510 William Cheng: Oh, there's a file called bite def that age, and this is inside drivers I that's why we were not familiar with it. So if you're doing a kernel include drivers. There's actually a definition for the by device. 284 00:41:04.080 --> 00:41:08.730 William Cheng: By the underscore te over here it's defined as, you know, this data structure. 285 00:41:09.030 --> 00:41:19.770 William Cheng: And then again, there's a up us over here. So again, this is the array of function pointer. So for the by device you can reframe it you can write to it, you can, you know, memory map it and then there. The other function for Colonel three 286 00:41:20.490 --> 00:41:29.670 William Cheng: What about for the, the, the, the other device over here, star dev over here. So this one is a block device. 287 00:41:30.570 --> 00:41:34.650 William Cheng: Okay so block device over here are the array of function pointer over here. 288 00:41:35.130 --> 00:41:42.330 William Cheng: I just sort of showing you for the block device, the function that you have over here. There's no longer read and write, write for the character device you can read and write from that. 289 00:41:42.540 --> 00:41:46.050 William Cheng: For the blog device. There's a function called we block and there's a function called right blah. 290 00:41:46.470 --> 00:41:53.430 William Cheng: Okay, so in this case you are reading and writing from the device one block at a time. So what kind of devices list like that. Why that this is something like that. 291 00:41:54.330 --> 00:42:01.140 William Cheng: Okay, when you try to refund the keyboard. You cannot use, you know, the byte block device because you don't read it, read a block at a time. 292 00:42:01.410 --> 00:42:08.250 William Cheng: Okay so reading and writing the desk, which we don't have to do inside our Colonel assignment. Right. So, therefore, we don't worry about this, there 293 00:42:09.210 --> 00:42:11.580 William Cheng: Alright, so over here again over here says, you know, 294 00:42:11.880 --> 00:42:21.420 William Cheng: If you want to find the character device, it needs to based on a device ID. So, therefore, you call this function called by device woke up and look it up, and then we'll return you do it by device. And then you assign a pointer to it. 295 00:42:21.990 --> 00:42:25.080 William Cheng: So now what you need to call a special file real especially if I write 296 00:42:25.620 --> 00:42:33.030 William Cheng: The comments as look for the character device. Look for the by device and then call the pointer indirectly. So again, all these data structure should be set up. 297 00:42:33.510 --> 00:42:40.800 William Cheng: At this point, so all you have to do is to make sure that you don't equal to know if they equal to know in that case you should return error code, otherwise you could actually call the functions. Okay. 298 00:42:42.900 --> 00:42:44.670 William Cheng: All right, what else is here. 299 00:42:45.840 --> 00:42:47.850 William Cheng: You know, blah, blah, blah. 300 00:42:49.020 --> 00:42:56.100 William Cheng: Okay. Vino is complicated. We look at them already. It's more than understand we get right so we saw we get already. So let's take a look at this again. 301 00:42:57.210 --> 00:43:03.210 William Cheng: VI Colonel FS PFS C v get 302 00:43:05.190 --> 00:43:07.410 William Cheng: Whoops, sorry. It's in Vino de see 303 00:43:10.980 --> 00:43:13.620 William Cheng: All right, so if you know that this co right. What can you tell about the scope 304 00:43:14.640 --> 00:43:20.100 William Cheng: There is a vegan over here, right, given the fastest them and given an I know number over here, we try to 305 00:43:20.850 --> 00:43:26.820 William Cheng: Try to find the corresponding vino if it's there, they will increment the reference cow. Otherwise, we're going to create a new one. 306 00:43:27.210 --> 00:43:36.870 William Cheng: Okay. So over here, what it does. Over here as I iterate through the list of vino that are in use. Okay, so, so apparently in Phoenix, the way they does is, is that 307 00:43:37.290 --> 00:43:41.730 William Cheng: When you create a bunch of vino you're going to keep track of them inside the link this right because again being 308 00:43:41.970 --> 00:43:47.340 William Cheng: You know weeks is a toy operating system. You don't really need a special, you know, fancy data structure. So what they will do they 309 00:43:47.700 --> 00:43:51.960 William Cheng: They fulfill all the vino that have been allocated. They keep them inside a linked list. 310 00:43:52.410 --> 00:43:59.550 William Cheng: So what do we do, is that is that will iterate through this linguists and try to look for them to see if they belong to this file system for the corresponding 311 00:44:00.210 --> 00:44:15.210 William Cheng: I know number. If they are, then you found it myself years has found it right here. Okay. And then he will check whether it's busy or not. Okay. So what is busy so busy over here for vino that means that you know that this is actually transferring data into 312 00:44:16.530 --> 00:44:27.480 William Cheng: Into the memory for this vino or they are taking data from this vino get the vino appointed. I know. So that means that there's a disk operation that's going on with you know the the 313 00:44:28.170 --> 00:44:36.300 William Cheng: That's going on with this, with this. I know. Okay, so if there's a disk activity that's going on. So, therefore, what you should do what she's doing with that you should not touch it. 314 00:44:37.230 --> 00:44:49.080 William Cheng: Okay, so that means that a data, you know, is unstable either we're copying them onto the disk. So if you try to modify the data inside. Inside is pretty good. I know what then in that case the data on this will be different data in memory. 315 00:44:49.650 --> 00:44:56.880 William Cheng: And if you are transferring data from a distant memory if you modify or if you try to read data from that, again, it is not ready. So in this case you will be reading garbage. 316 00:44:57.330 --> 00:45:04.380 William Cheng: Yeah, so therefore, as long as this. I know it over here. Oh, the vino is busy. What you should do is I usually sleep on the queue. 317 00:45:05.310 --> 00:45:18.450 William Cheng: So this way when the data transfer is complete, it will wake you up Brazell again the Colonel. So we need to sleep on Io cues are you sorry interrupt service routine you wake up the colonel through. So in this case, the colonel fed over here it's waiting is waiting for for our completion. 318 00:45:19.710 --> 00:45:25.650 William Cheng: Okay. So this guy's went to interrupt service routine is done right. He needs to wake up a colonel threats or in this case, it would need to broadcast 319 00:45:25.890 --> 00:45:30.780 William Cheng: On this particular cues, so that all the threads are waiting for the data to be completed. Then we'll all get woken up 320 00:45:31.500 --> 00:45:41.640 William Cheng: That was over here, what it would do it is that you're asleep on this cute when it got woken up when you get woken up, you will return for this function. And where would it go, it will go to find over here and try to look this one again. 321 00:45:42.720 --> 00:45:48.600 William Cheng: Okay, so why does it matter statins out a tighter loop over here, right, because it might be unsafe because there might be buggies that occurred or something like that. 322 00:45:49.020 --> 00:45:52.620 William Cheng: So in this case over here. What did decide to do over here is that they were actually, you know, 323 00:45:52.980 --> 00:46:04.410 William Cheng: The call fine. Okay, so what's important to understand over here is that inside Colonel to this function should never block because there's no desk. Okay, but will you'll get to Colonel three over here. Why, in that case, you know, 324 00:46:04.920 --> 00:46:13.890 William Cheng: This particular vino can be busy. So, therefore, this function is potentially a blocking function, right. So, therefore, what the way we say is that this function is a blocking call 325 00:46:14.280 --> 00:46:24.210 William Cheng: Okay, because there's a there's a chance that this function may not return immediately because your, your current that will actually have to have to give up the CPU and then double can have in a later time. 326 00:46:25.380 --> 00:46:32.910 William Cheng: Alright, so, so anyway, so you hear us. Yeah. But if it turns out that you know this. The vino have here is not busy what I mean. So you can actually use this vino 327 00:46:33.330 --> 00:46:42.090 William Cheng: So in this case, all we have to do over here, if not dev mountain. You're not supposed to take this amount equal to y. So in this case, we're going to increment the reference console Wii read what does Viera 328 00:46:42.990 --> 00:46:50.490 William Cheng: Be routed simply incremental reference guide. So if you look at four dB right over here. It's a bunch of care, sir. And then what do we do, is that are incremental reference cow. 329 00:46:50.910 --> 00:47:02.790 William Cheng: And the next slide over here is very important over here. It's a conforming DSR conforming DVD call. It's a DVD call that if you said DB t equals to be and rough. What do we do that, it will actually, you will see that this line will get printed 330 00:47:03.750 --> 00:47:12.750 William Cheng: Okay, so when you get reference counting bugs over here. You should turn on the and rough inside your config. I am k. So, this guy's when the recent slide, you will see that this, I would say. 331 00:47:13.290 --> 00:47:24.330 William Cheng: The be rapid function is getting caught. So therefore on this line over here. I know number, certainly, whatever the number is over here the reference how. Get in. Get increment it up to this new reference count. 332 00:47:25.590 --> 00:47:32.820 William Cheng: Guys. So this is how you debug the reference hunting problem every time, will you call the right, you're going to see the number goes up, and then there's another function called V put 333 00:47:33.360 --> 00:47:43.620 William Cheng: Okay. So every time you call V put over here. We're going to recommend the reference count over here. And then again, there's a similar line over here to say that the the reference count get detrimental down to the 334 00:47:44.490 --> 00:47:52.920 William Cheng: So this guy is going to be the reference got over here, minus one okay so this one is actually get printed before you detrimental by one. So, therefore, again, this, this, get printed out here. 335 00:47:53.400 --> 00:47:58.530 William Cheng: Okay, so by turning on the ref inside configure MK. You can actually debug. You know, people 336 00:47:59.310 --> 00:48:07.680 William Cheng: Alright, so again we get over here, I very important to understand is that you're looking at. You find the vino all it does is to increment the reference count on the Beano and a return to be no yeah 337 00:48:07.980 --> 00:48:13.320 William Cheng: Otherwise, if it cannot find it right over here, there is a, you know, the List, list duration right here. 338 00:48:13.590 --> 00:48:27.030 William Cheng: If it cannot find it. Then we'll go over here. So, what it will do is that it will create a vino by asking the slap allocated create a new why. And then what it will do is that you initialize it by city, the entire data structure to know fix up some of the pointer over here. 339 00:48:28.920 --> 00:48:38.100 William Cheng: And then what it would do is that it will initialize the new Texan, and then you need to initialize the memory management object and LBJ initialize the data structure in here. 340 00:48:38.640 --> 00:48:49.620 William Cheng: What else does it do over here. Okay, so it will set the flight over here to be not busy and then he will add it to the US list over here. 341 00:48:49.860 --> 00:49:02.400 William Cheng: Do some chaos around over here. And then what it will do is that it will call Urbino I remember you know the Beano data structure part of it. We want to be a part of appeal to the actual process them. So we are finished initializing pretty much most of the 342 00:49:03.480 --> 00:49:12.390 William Cheng: The VM FS related stuff and they're in this case we're going to call the reveal function. So remember that Rubino function. There's only one function for the entire file system. 343 00:49:12.660 --> 00:49:17.880 William Cheng: So therefore, we're going to use the vino pointer point to have his really long. You know point over here. 344 00:49:18.090 --> 00:49:27.330 William Cheng: Is going to point to the fastest them. So instead of us them there's already a function called the FS up over here. And then inside the FS over here. There's those for functioning right the read to lead the query. 345 00:49:27.840 --> 00:49:35.820 William Cheng: The human rights, I'm going to call the renal function. So again, this, this one illustrate how you call a function is that array of function pointer. 346 00:49:37.050 --> 00:49:41.340 William Cheng: That I mean, for those of you who are familiar with c++. I mean, it looks like a c++ code right 347 00:49:42.450 --> 00:49:48.330 William Cheng: Okay, so, so the modern compilers actually pretty smart, right when you try to call a function, indirectly, if you use this particular syntax. 348 00:49:48.480 --> 00:49:57.810 William Cheng: It will actually call that function indirectly by following through all these pointer. So the last one over here is going to be a function pointer and then you will use the argument, and it has to it. And this is how you call function indirectly. 349 00:49:58.770 --> 00:50:05.730 William Cheng: Okay, it's okay. You know, there are multiple levels on your action started on vino you pointed the fastest and you pointed or a function point oh you pointed the first 350 00:50:06.150 --> 00:50:10.110 William Cheng: Function over here called the renal function over here and then you call this function. Okay. 351 00:50:10.560 --> 00:50:15.030 William Cheng: By the way over here. I want to call this function as it turns out, the renal function over here is 352 00:50:15.300 --> 00:50:19.530 William Cheng: Is also a blocking call. So that's why what they do over here is either first set 353 00:50:19.740 --> 00:50:30.930 William Cheng: You know the Beano to be busy, because you might actually involve data transfer from this into memory. So, so we're going to make you know there's been a busy and then we call the Rubino when we're done over here, we set it to, I'm busy. 354 00:50:32.340 --> 00:50:41.430 William Cheng: Alright, so this is what's going on over here with the vv know over here so so anytime when you need to call a blocking call. So this guy is what it's showing over here, we need to temporarily said it too busy or something like that. So, 355 00:50:41.850 --> 00:50:49.680 William Cheng: This way to work properly, then I don't really know that if you have to do that in the code that you have to implement it, but this one is actually the sort of the big 356 00:50:50.340 --> 00:51:03.060 William Cheng: I mean, you know, so this one is done, India, so if you only call me get you know that inside V get this thing is taken care already so therefore you don't have to set the busy flag where you're using that vino right because since I began to take care of before you were 357 00:51:04.800 --> 00:51:15.840 William Cheng: So after this one over here. If it turns out that this one is a block device or character device, then you will also call the in this special we know we just saw that function right against the inside that function. You will also find the two pointers over here. 358 00:51:16.320 --> 00:51:27.270 William Cheng: So one of the array of function pointer for the device and the other one is to point to either the character device or the or the block device based on the device identifier. Yeah. 359 00:51:28.650 --> 00:51:39.930 William Cheng: All right. And if I don't know what this one is done over here, we just created a vino so therefore the reference count over equal to one. Yeah, I made a comment over here to say that it's probably a good idea to add the following lines right before 360 00:51:41.040 --> 00:51:51.030 William Cheng: We get is going to return. So, what you should what I'm recommending over here is that you'd copy this line over here. Right. And then you come to here at the end of this function over here. Just add these two or three lines over here. 361 00:51:52.320 --> 00:51:59.910 William Cheng: Okay, so this one says, you know, the vegan is about to return with a brand new vino so he will say that I am, I know, here's the I know number 362 00:52:00.120 --> 00:52:09.720 William Cheng: Reference concept to want right the you know the reference out. We just finished sending to why so so you could print out this line over here. So this way you know exactly what a vino got created 363 00:52:10.320 --> 00:52:15.690 William Cheng: Okay, so I highly recommend that you will add this falling in line over here, right here at the end of, you know, 364 00:52:16.950 --> 00:52:24.600 William Cheng: V get okay so this way will make it easier for you to debug your code. Okay. For some reason, this is not included inside of winning source code. Okay. 365 00:52:26.430 --> 00:52:42.240 William Cheng: All right. And finally, at the last part over here and look at the round file system over here. So let's take a look, see what we have the red file system already have it right. So what are we supposed to look at. We're supposed to look at 366 00:52:43.950 --> 00:52:47.460 William Cheng: The big obstacles. I think we've done this already right copy 367 00:52:50.100 --> 00:52:54.810 William Cheng: Yeah so. So this is, again, it's very, very important to understand when are these pointer. 368 00:52:55.920 --> 00:53:03.840 William Cheng: Become bout right so later on when you try to access the point or a font of the pointer is no, he said, how can it be now, it must be that you forget to call this function right 369 00:53:04.020 --> 00:53:11.670 William Cheng: Because he's not a function like this isn't what Sarah ponder so they don't know if you want to use this pointer. As it turns out, at this point, or is initialized. Wasn't that Mrs. Okay. 370 00:53:11.820 --> 00:53:17.220 William Cheng: What you should do is that you can see this pointer is I initialize, what should you do right, you just say, grab you know 371 00:53:18.030 --> 00:53:24.780 William Cheng: This y equals to something, you know, current all stars. So I started. I see. And then you find out you know where's this pretty good. 372 00:53:25.170 --> 00:53:30.540 William Cheng: Pointer become bout right if that point there is equal to know or they've that point, or is it initialize 373 00:53:31.020 --> 00:53:37.380 William Cheng: How do you know a point is I initialize right, you're going to see something like zero x five, a five or some a five, a five. There are sorry 374 00:53:37.950 --> 00:53:46.260 William Cheng: BB BB BB BB right if you see something like this. That means that data structures are initialized. There's another value because zero DD DD DD DD 375 00:53:46.890 --> 00:53:49.860 William Cheng: So again, that in that case, you also see something on initialized. 376 00:53:50.580 --> 00:54:00.540 William Cheng: Okay. So whenever you see something initialize it must be that you know these functions didn't get call. So if you find you find these phones. You say, Well, how can this function, not be caught right because this assignment needs to be that 377 00:54:00.750 --> 00:54:08.220 William Cheng: Either this function never got call or the mode over here is wrong. If the mode is wrong over here. Well, then in that case it will send it to somebody says something else. 378 00:54:08.460 --> 00:54:16.500 William Cheng: Why would the Mobi wrong. Well, maybe you have a memory corruption, but maybe you forgot the setter, maybe this one actually looks like completely garbage right in that case, maybe I initialize 379 00:54:16.890 --> 00:54:25.590 William Cheng: So there are many, many maybe reason. So, so what you need to do is I need to set breakpoints here so when it gets you over here, you make sure that you're looking at the one with the right, right, right. I know number 380 00:54:25.740 --> 00:54:33.180 William Cheng: How do you know what the right I don't number. So again, you look at inside conflict, I am k, right. So if we go to config that and Kate over here. 381 00:54:33.960 --> 00:54:38.640 William Cheng: VI n ref right that's the one that you need to look for over here. We're glad to see that here's an example. 382 00:54:39.630 --> 00:54:49.620 William Cheng: That if we uncommon out this line right so so by default DB Jeezy able to also say you can look at too much stuff. So if you if you uncommon that right by getting rid of the leading you know 383 00:54:50.400 --> 00:55:03.570 William Cheng: Hashtag so this why he said DVD, you go to this one. So what does this mean. This means that, you know, execute all the DVD DVD DVD DVD printable you test. The test pass your test fail. 384 00:55:07.320 --> 00:55:15.270 William Cheng: A VN ref okay so if you said, this one is it shows that one. So this one, it's going to be a guess. Where is that 385 00:55:18.300 --> 00:55:30.090 William Cheng: Number four. Over here I, oh yeah, right. So this is the db, db and ref, right. So once we set complete that MK to include the NF. Now, you know, this particular segments going to print something, you know, 386 00:55:30.630 --> 00:55:38.850 William Cheng: Maybe something into the terminal. Okay, so if you don't don't don't set as you're not going to see he said this, you're gonna see it is against you. I strongly recommend you you do all this kind of stuff. 387 00:55:39.390 --> 00:55:48.060 William Cheng: For you to debug your code there. So again, when something's not happening. You start debugging your co you start setting breakpoints over here, you need to check if every variable over here all makes sense. 388 00:55:48.390 --> 00:55:56.340 William Cheng: If the vino number over here is equal to zero as BB BB BB BB wasn't in that case you should expect that I know over here will be garbage. 389 00:55:57.330 --> 00:55:59.940 William Cheng: Guys are definitely. I mean, this guy is, you know, is there a memory corruption, but 390 00:56:00.240 --> 00:56:06.240 William Cheng: Well, yeah. Well, the be a note over here. Shouldn't be Xerox PTV. So in this case, technically should be initialized variable. 391 00:56:06.420 --> 00:56:14.700 William Cheng: But will you use initialize variable to give you a beat. I know pointer and now there's no point it will point to the garbage. Right. So definitely, if you start using this I know ponder over here. 392 00:56:14.850 --> 00:56:18.270 William Cheng: And you start modifying data structure of all you going to end up with memory corruption bugs. 393 00:56:19.770 --> 00:56:26.610 William Cheng: Alright, so again, Colonel to you know what you have reference counting problem we have, you know, the, you know, the world will, will you know is crashing left and right. 394 00:56:26.970 --> 00:56:35.910 William Cheng: When you have a search and failure. So again, you need to start setting breakpoint inside the red file system inside all the code that I talked about today, in order for you to track down where the problem is. Then 395 00:56:37.380 --> 00:56:51.810 William Cheng: Oh I so I guess I went over you know everything I needed want to talk about over here. So, so that will be the end of, you know, the week eight you know discussion section. Okay, so I guess we've got, we're going to give you an introduction to Colonel three