WEBVTT 1 00:00:04.350 --> 00:00:17.699 William Cheng: Oh, hi. Oh, welcome to the first discussions section on zoom. So I guess today. What I will do is I will, I guess, if you look at the 2 00:00:18.510 --> 00:00:26.520 William Cheng: Discussion section web page. It was a today we're going to talk about sup. We're going to sort of walk through some of the code and kernel to 3 00:00:27.240 --> 00:00:36.930 William Cheng: So in the last discussion section was to give you a quick introduction to to Colonel to. And so today, we're going to read some coat. Yeah. 4 00:00:37.530 --> 00:00:58.350 William Cheng: So in the discussion web page, there is a file call a week nine. So let me take a little bit of what that file this so this file is called week nine dash notes dot txt so they are the notes, sort of, for me to remember what I need to talk about. So I'm gonna 5 00:01:00.240 --> 00:01:10.410 William Cheng: You know, sort of go through some of this. Some of the stuff on this list. Yeah. Alright so today I'm going to try to talk slowly, hopefully this will work out a little better. Okay. 6 00:01:11.280 --> 00:01:21.120 William Cheng: Okay, so the first item on the list is to explain about dirt name v. So, so this is one of the function that does path name resolution. 7 00:01:21.960 --> 00:01:32.580 William Cheng: As and I think last time we sort of talked about. It was a little look at there's a slight you know basically with this example, and this is the example inside the comment block right above it during the 8 00:01:33.120 --> 00:01:45.300 William Cheng: Day. So some of these function are just this is inside a file called name v dot c. So as part of the path name resolution you know function. I have no idea what is it called name v. 9 00:01:46.350 --> 00:01:55.140 William Cheng: So anyways, I have no idea. Alright. So the example that will give an over here is that you know their name be the first argument over here is the path name. 10 00:01:55.890 --> 00:02:02.700 William Cheng: So the idea here is that given a path name, we need to we need to return a V note. 11 00:02:03.330 --> 00:02:09.690 William Cheng: So again, a vino is like a high note. Right. And I know it's something that represented file and the vino is 12 00:02:10.080 --> 00:02:20.850 William Cheng: The I know representation in the virtual file system. So remember the first isn't divided into two parts. One is called BFS. The other one is called the AFL CIO, the FS is the actual file system. 13 00:02:21.510 --> 00:02:28.440 William Cheng: In Colonel to the actual file system is the ramp classes that was made out of memory. There's really no disk. 14 00:02:28.950 --> 00:02:36.750 William Cheng: So, so everything is fake there. So later on we're going to sort of take a look at the code inside grandpa system guys means that around versus them. 15 00:02:37.350 --> 00:02:46.830 William Cheng: That data structure that represent a file is called a node. So there are points are the points to. I know. And I guess when we talk about system, our system, your lectures. 16 00:02:47.370 --> 00:02:58.200 William Cheng: So that's kind of related right so you know so that I know you know this isn't about versus them kind of look like I know you know inside the the Linux operating system. Yeah. 17 00:02:59.040 --> 00:03:06.540 William Cheng: All right, and also when we go to Colonel three we're going to switch to the system versus them mine that case the I know is going to be very, very similar. 18 00:03:06.870 --> 00:03:15.600 William Cheng: Now. Alright, so, so, so this function over here will return a vino T. Again, there are two Asterix over here them. Is that a return of pointer. 19 00:03:16.410 --> 00:03:23.820 William Cheng: You know, so, so what what what's gonna what's pass into this function is an address of a vino pointer. 20 00:03:24.480 --> 00:03:32.250 William Cheng: Okay. So, therefore, what you're supposed to do is you need to set the resolving over here to be whatever they've been on that you find and this vino is going to be a pointer. 21 00:03:32.670 --> 00:03:40.590 William Cheng: So therefore, India, you need to set set up this particular point. Right. So again we seen this before. The two Asterix usually what it means that it's a return value. Yeah. 22 00:03:41.010 --> 00:03:50.430 William Cheng: All right, so there's vino vino is the so so so you know we have the I note that says that actual versus them their equivalent or they're 23 00:03:51.180 --> 00:03:56.250 William Cheng: Probably not their equivalent their counterpart in the virtual file system is called a vino okay 24 00:03:57.030 --> 00:04:02.640 William Cheng: All right, there's another been over here is the base. So what happened is that when you perform perform resolution. 25 00:04:03.180 --> 00:04:14.220 William Cheng: Is the first character over here is a slash character, then you need to ignore the base. I think there's some, you know, document. There's some words in a comment blog saying something like that. 26 00:04:14.730 --> 00:04:20.550 William Cheng: So if the first character is a slash character that you need to perform a path of resolution starting from the root directory 27 00:04:21.000 --> 00:04:29.160 William Cheng: For turns out that this character over here is the first character over here is not the the slash character. Well, that means that you need to perform 28 00:04:29.460 --> 00:04:38.220 William Cheng: You know relative platinum resolution a relative to the base over here, right. So again, so what is the base so so so conceptually the base is going to be the current working directory 29 00:04:38.640 --> 00:04:45.870 William Cheng: Because when you try to open a file with us, you know, without starting from the root directory. You're supposed to perform path and resolution. Oops. 30 00:04:47.250 --> 00:04:54.330 William Cheng: You're supposed to perform pattern resolution starting you know from your current working directory guys are remembering Colonel one you already see that 31 00:04:54.990 --> 00:05:01.260 William Cheng: You know, inside the process control blog. There is the cwt there's the current working directory. So in Colonel to 32 00:05:01.650 --> 00:05:08.040 William Cheng: You have to set the current working directory and you have to, you know, change it. And also you have to implement the functionality, where you you know 33 00:05:08.460 --> 00:05:18.540 William Cheng: When we make the change Ders system call. So again, I'm going to use the word system call, even though we understand that Colonel to there's no user space program. Okay, so this is the Colonel. 34 00:05:19.050 --> 00:05:29.460 William Cheng: Colonel version of the system call guys and we implement a kernel version of this, the, the change their system call you have to change the current working directory inside the process control, blah. Yeah. 35 00:05:30.300 --> 00:05:44.430 William Cheng: Alright, so will you make the songs you call the dirt me. I think the last discussion section I mentioned that this function return for things right number so so so so you know we performed path of resolution over here, assuming that you you you 36 00:05:44.970 --> 00:05:50.220 William Cheng: A successful, we are performed path and resolution, which means that as five Fs over here, you know, 37 00:05:50.520 --> 00:05:57.030 William Cheng: The insert root directory. There is a directory entry call as five Fs, and that direct to entry is a directory 38 00:05:57.300 --> 00:06:04.740 William Cheng: And inside that directory. There's another component name another entry whose name is Ben and this pretty good entries also directory 39 00:06:05.040 --> 00:06:13.410 William Cheng: And then finally, the last argument over here is that inside that slash as five Fs bin directory. There's another directory entry in MLS 40 00:06:13.800 --> 00:06:19.980 William Cheng: Guys, in this case, what we need to do is that when you call your name V in the air. We need to return a resolve vino 41 00:06:20.730 --> 00:06:30.720 William Cheng: That represent. I think it represents slash S5 FS slash been ok so this way or what you can do is that once you end up with this particular vino you can, you know, 42 00:06:31.080 --> 00:06:34.050 William Cheng: You can use this particular been able to perform the lookup operation. 43 00:06:34.440 --> 00:06:43.080 William Cheng: Okay, look up, it's not a function inside, namely Darcy. That's also another function that you need to implement and what you're supposed to do is that you know you can't really look anything up. 44 00:06:43.470 --> 00:06:50.550 William Cheng: You know, inside the virtual file system against the virtual file system doesn't really know anything so they have what you have to do is that you need to find the pointer. 45 00:06:51.030 --> 00:06:59.250 William Cheng: For the lookup function inside the actual file system and then you, you tell the actual file system to do the work for you. Yeah. All right. Anyway, so that's just another function. 46 00:06:59.730 --> 00:07:10.350 William Cheng: So this function when it returns the name lane over here. In this example, right. The last part of the LS is two characters long. So therefore, in the end with this function return. You're supposed to set mainly equals to 47 00:07:10.920 --> 00:07:19.350 William Cheng: The name over here is going to be appointed by the argument over here is again cons charge, star, star fellow by name. Right, so get this return value. 48 00:07:19.590 --> 00:07:29.400 William Cheng: So on return. You're supposed to set the, you know, whatever. This guy, whatever the address you provided for you need to copy inside appointed that point to the L character in LS 49 00:07:30.180 --> 00:07:39.360 William Cheng: There, unless I mentioned something very important. Some people make a copy of this particular the first argument over here in, you know, instead of local variable. 50 00:07:39.720 --> 00:07:46.410 William Cheng: The local variable is a buffer of, you know, 1024 character or whatever the number that you that you want to use the site doesn't really matter. 51 00:07:47.010 --> 00:07:53.910 William Cheng: So what they will do is that in the end of the name over here, what the return is that it's a pointer into the local variable. Well, that's really 52 00:07:54.360 --> 00:08:01.170 William Cheng: You know that the you should never do that. You should never return a pointer pointing to a local variable because as soon as the function returns 53 00:08:01.380 --> 00:08:06.630 William Cheng: The local variable, turning to garbage, right, because if you make another function call, you're going to wipe out everything inside the stack. 54 00:08:07.140 --> 00:08:12.450 William Cheng: So therefore, we shouldn't do that. That. So the idea here is that the name over here needs to point to Ellis over here. 55 00:08:13.020 --> 00:08:29.340 William Cheng: So one thing that you can look at that the path of years. The first character, his character 01 234-567-8910 so we should point to the 10th character inside pathway or the address of the 10th character inside pathway. 56 00:08:29.700 --> 00:08:41.700 William Cheng: Okay, so that's what this function is supposed to do. And then finally, the result of vino will be the directory vino that represents f5 FS slash Ben. And this way you can use the lookout function after to look that up. Okay. 57 00:08:43.260 --> 00:08:57.690 William Cheng: All right, so that's the first thing over here so so against. Let's go back to. So where are we were in the winning steer the directory will be here so we can edit a colonel Fs. So this one. 58 00:08:59.280 --> 00:09:02.790 William Cheng: This one is the name v. Right. So we're gonna take a look at him V does see 59 00:09:03.930 --> 00:09:17.220 William Cheng: The function of yours, don't envy rise again lots of stuff over here to tell you what to do, is the first character over here is slash you you know you ignore the base. Otherwise, you use the current working directory, guys. Oh so anyways it all explain right here. Yeah. 60 00:09:18.270 --> 00:09:28.290 William Cheng: Alright, so also, it also says that the Rubino is BFS route Dino. So again, this is the global variable, okay. So anytime you want to know where the Rubino is 61 00:09:28.620 --> 00:09:36.210 William Cheng: Then they use this global variable. Yeah, yeah, just like her podcast where they are very, very useful global rebel. Okay. And then once you 62 00:09:36.660 --> 00:09:43.710 William Cheng: Once during, during the NBC return successfully. If you want to perform a look up operation us look up function right so this look upon emotion. 63 00:09:43.950 --> 00:09:52.020 William Cheng: The dirt over here. It's a directory Dino right so yeah we saw before the vino vino point are we here sometimes inside the Colonel. 64 00:09:52.410 --> 00:10:04.080 William Cheng: Colonel to the variable name is called a file. So again, that will represent a file vino. This one is called a dirt because it represented directory know. Yeah. So instead of directory vino right, so remember what the director Dino look like 65 00:10:04.770 --> 00:10:11.820 William Cheng: So, so, or directory you know the content of the directory file, it looks at an array of directory entries 66 00:10:12.120 --> 00:10:22.860 William Cheng: Instead of directory entry. There's component name and there's the I know number right over here, what this function does is that you need to iterate through the the the directory entries. Look for a 67 00:10:24.480 --> 00:10:38.700 William Cheng: You know, look for a component name or, you know, certain comparison to see visible to name equal to name. That's the one that you're looking for. Okay, so this one actually use name followed by the number of length over here. So this name doesn't have to be a no terminated character. 68 00:10:39.750 --> 00:10:45.960 William Cheng: Okay, so. So typically we think about see string. They're all terminated by now. But in this case, since we have a specify the length of the string. 69 00:10:46.500 --> 00:10:48.090 William Cheng: The string doesn't have to be now terminated. 70 00:10:48.570 --> 00:11:00.090 William Cheng: Yeah. Alright. So anyways, so look a function over here. If there's return successfully again to return two things. Number one is the return value over here. So I think it was successful, it returns zero or something. I always 71 00:11:00.570 --> 00:11:11.550 William Cheng: You need to look at the the spec. And then finally, the second returned by the over here. It's going to be a vino and this one is the vino that represent the I know that has this component name it's inside this directory 72 00:11:12.180 --> 00:11:19.680 William Cheng: OK. So again, this is the local function you go in, you ask the actual file system to perform a look up function so they don't get to sort of look at 73 00:11:20.280 --> 00:11:26.610 William Cheng: What the lookup function look like in the actual file system, or I guess org window now anyways. Let me follow the procedure over here. 74 00:11:27.330 --> 00:11:38.190 William Cheng: Okay, so we see, look, we see their name and there's a higher level function over here called open name be. So again, we're not going to talk about that. So again, read, read the common, common block over here. Yeah. 75 00:11:39.240 --> 00:11:47.880 William Cheng: All right, the second, the second point over here says will you run the Linux operating system we Unix minus, we always run it with the Phoenix minus and 76 00:11:48.660 --> 00:11:51.030 William Cheng: There's a minus me start with a blank desk. 77 00:11:51.480 --> 00:12:01.410 William Cheng: When you start with a blank this the only thing on this is going to be the root directory. Right, so it's not empty desk, it's a it's a directory that only has one entry in there and that will be the root directory. Yeah. 78 00:12:02.190 --> 00:12:08.910 William Cheng: The, the rule. I know is cash inside the ordinances them. And the way you access. This one is use the bfs Rubino 79 00:12:09.240 --> 00:12:19.560 William Cheng: That we saw before. Right. So again, this is the vino pointer is the VM FS version of the I know pointer. So using this point or you can actually find the I know inside the actual file system. 80 00:12:20.190 --> 00:12:27.510 William Cheng: OK, so again inside a virtual versus me. You don't need to know what you know what is the rule. I know that's for the actual file system to know 81 00:12:27.900 --> 00:12:35.970 William Cheng: Okay. So inside the virtual system over here, we only have a bfs Rubina. Yeah. All right. And this one has mentioned and do an MBA, you know, when they perform path of resolution. 82 00:12:36.540 --> 00:12:43.470 William Cheng: Alright, so you can do that. You can run this command you try to look at the colonel over here to see what kind of code is using BFS a route. 83 00:12:43.800 --> 00:12:52.200 William Cheng: You know that the Rubino so I'm just going to run right here, right, you will see that I guess these are the result over here look exactly the same as here because I just ran it 84 00:12:53.070 --> 00:13:04.080 William Cheng: So inside name Vika. See, we saw that comment about it at all the other places are BFS diocese of BFS RC is the virtual file system. So let's take a look at the FS Darcy. 85 00:13:06.690 --> 00:13:18.120 William Cheng: Alright, so, so what's inside BFS. I see over here. Again, there's a global variable called DFS Rubino or I originally. It's not initialize so you got to make sure that you know it's initialize 86 00:13:20.730 --> 00:13:29.550 William Cheng: Class. So let's look up for the string over here, right. We already saw that it appears 1234567 times. So over here, it says, you know what you call the FS in it. 87 00:13:30.180 --> 00:13:50.280 William Cheng: We initialize BFS. Whereas BFS in that I so grab BFS in it. Current all star star. See, we see that okay there's a in it function over here cobija personnel via net over here is right here where to go BFS in it. 88 00:13:52.620 --> 00:13:58.200 William Cheng: Okay, so it's one of the internet function over here. So I think in it function is. It's called 89 00:13:59.340 --> 00:14:06.330 William Cheng: You know, in the idol proc run right. I know, I know. Proctor on. I don't remember. Colonel one, one of the first thing that will do is that it will 90 00:14:06.870 --> 00:14:12.930 William Cheng: You know, create the in a process, but it won't edit to the wrong queue and then it will call a function called and then call all 91 00:14:13.350 --> 00:14:18.090 William Cheng: That we initialize all the initialization function and this is what initialization function look like 92 00:14:18.330 --> 00:14:27.090 William Cheng: You know, inside the secret over there. This and they function BFS in a in a function. So, therefore, this function will get call at the beginning of the idol process. Yeah. 93 00:14:27.510 --> 00:14:32.910 William Cheng: Alright so this code over here. What it will do is anyway initialize you know initialize BFS. 94 00:14:33.330 --> 00:14:46.590 William Cheng: And that's, take a look at over here it says BFS Rubino so once this function is called the VF as root vino will become ballot. And the way this is done is that is equal to FS right arrow FS route over here. So what does Fs. 95 00:14:47.820 --> 00:15:04.620 William Cheng: So Evers over here is the fastest them. Okay. So over here, you can see the FS somehow FS over here, the way they allocated is that they don't use the page alligator. And they also don't use the slab alligator to use came, Alex. So this is the kernel version of the malfunction. 96 00:15:05.760 --> 00:15:16.050 William Cheng: You know, so I think the reason it's done this way. Is that because they're not too many forces them inside the weenies Colonel so they don't bother with a slab alligator. Okay. So in this case, he just called Cut came out. 97 00:15:16.650 --> 00:15:33.870 William Cheng: To allocate so many bytes and then it will say that if BFS rule the FS data will be here stream copy FS dev and then it called the function called Mount function over here. So what is this thing. Okay. So on the mount function over here is right here. 98 00:15:35.010 --> 00:15:43.380 William Cheng: Okay, so what it says. Over here is that if the system file, file system is define what he would do is that it will mount this isn't part of our system. There's a function versus them purposes amount 99 00:15:43.650 --> 00:15:50.850 William Cheng: Otherwise, you're in Colonel to them. In this case, you're doing BFS. So what it will do is that I will call this function ramp our system out 100 00:15:51.690 --> 00:16:04.170 William Cheng: So what is this time over here. And then what I'll do is over, over here, is it will actually call this function. Okay, so you can actually set a breakpoint there to make sure that you get there. So, this function is not here right so let's grab for it. 101 00:16:06.030 --> 00:16:16.440 William Cheng: Right, so it's only in BFS. So we need to go one level down, we need to go to the the rampart system here that you will see that it's inside Colonel FS ram FS ram FS Darcy. 102 00:16:17.010 --> 00:16:25.380 William Cheng: Colonel FS ram FS inside this directory roadmap as there's only one file. Okay, so that's your emphasis them and it's a very, very small file. 103 00:16:26.130 --> 00:16:34.080 William Cheng: Wife, as you know, that's more 681 lines long. And we can look for this function. So, this function is the one that mount the the rampart system. 104 00:16:34.350 --> 00:16:46.560 William Cheng: Well, guess what I would do is that it will create a run fast is that, and it will mounted in the room. Vino or or the rude. I know. Okay. And then what do we do that I'll create a vino that represented route. I know. And then we'll return from it. Okay. All right. So yeah, why 105 00:16:48.000 --> 00:16:50.880 William Cheng: Not so fast. I guess I'm saying not exactly right. The 106 00:16:51.300 --> 00:16:58.590 William Cheng: What it will do is that it will create a file system. Alright, so over here is it's a struggle Fs. So this one is the fastest them. So this one is a ranch houses them. 107 00:16:58.860 --> 00:17:07.530 William Cheng: Instead of houses, then there's a route. I know. Okay. Alright, so let's take a look at some of the code over here, in the end, when it returns over here. So again, I'm not going to go over too much of this day. 108 00:17:08.490 --> 00:17:18.330 William Cheng: It will call the FS FS going to be the fastest the fastest them has a route I over here called BFS route so VFR through ovary is going to be equal to V get 109 00:17:19.380 --> 00:17:27.660 William Cheng: So we get over here is one of the the vino get function. So the get function over here. So that's one of the reference counting function. 110 00:17:28.110 --> 00:17:35.340 William Cheng: Okay, so what it will do is that whenever you try to create a create a data structure that has a reference count you will call it the get function. 111 00:17:35.670 --> 00:17:44.670 William Cheng: Because it is a function called get and there's a function called ref and then there's a function called put guys, I'm going to sort of copy them right here, even though it doesn't make sense. 112 00:17:45.570 --> 00:17:53.730 William Cheng: What are called get the other one is called ref and the other one is called put. Okay, so you're going to see a lot of these kinds of functions in colonel colonel three 113 00:17:54.420 --> 00:18:02.700 William Cheng: The, the red function over here is the function that increment the reference reference count. Okay. The put function over here is the one that detriment the reference count. 114 00:18:03.510 --> 00:18:08.280 William Cheng: Okay, so, so any kind of a, you know, the data structure. They use a reference counting 115 00:18:08.760 --> 00:18:15.180 William Cheng: Refund counseling mechanism, you're going to see these three functions. One is called get the other one is called ref and the other one is called put 116 00:18:15.480 --> 00:18:21.960 William Cheng: And the ref always increment the reference cow and the poor always document the reference cow, but also when you definitely would recommend the reference 117 00:18:22.500 --> 00:18:27.750 William Cheng: In the reference go down to zero, then you free up the data structure, right, because that's how reference counting work. Okay. 118 00:18:28.260 --> 00:18:37.890 William Cheng: Alright, so what does get right. Get over here is to say that if the object already exists. That's what do you do they need to look for if you find that object already. Then all you do is to increment the reference gap. 119 00:18:39.120 --> 00:18:46.020 William Cheng: Or is it again if you if you find an object that's already exists. That means that you have a data structure and there's a reference count. And now you need to income in the reference 120 00:18:46.440 --> 00:18:53.970 William Cheng: So therefore, F. Get the V. Get over here. So it's a gift function. So, what it will do is that it will try to find this object over here somehow 121 00:18:54.390 --> 00:18:59.580 William Cheng: If the object already exists, it will increment the reference count because now you have an extra point at that point into it. Okay. 122 00:18:59.760 --> 00:19:10.020 William Cheng: If it turns out that this other you cannot find it what you will do is that the way you will create a new one. And then you initialize it and now the reference count will be set to one because they reference have integrated from zero to one. 123 00:19:10.740 --> 00:19:18.930 William Cheng: Okay. All right. So anyway, so. So get it. You know, it doesn't really always increment the reference car. It might create a new object and set the reference count to one. Yeah. 124 00:19:19.710 --> 00:19:27.780 William Cheng: Alright so let me get rid of the other code over here. So over here, what it will do over here is that it will go to this file system over here and try to look for. I know one 125 00:19:27.990 --> 00:19:34.050 William Cheng: And then it will create a vino for it if it turns out this vino already exist. It was simply incremental reference count. 126 00:19:34.890 --> 00:19:37.410 William Cheng: Okay. All right. Let me say that again, what we're doing this. 127 00:19:37.680 --> 00:19:42.780 William Cheng: Wrong again D get is very important function, you need to understand that what he would do is that it will go to this file system. 128 00:19:42.990 --> 00:19:54.300 William Cheng: Look for I know number zero if it cannot find I know number zero it will create your creative. I know and then create a vino for it. And then the Dinos reference count will be good one. 129 00:19:54.720 --> 00:19:58.110 William Cheng: Okay, if you were able to look up this particular I know and it will 130 00:19:58.290 --> 00:20:06.990 William Cheng: It will find it. It will also find the corresponding vino because there's a one to one correspondence between the vino and the I know when this case if the vino already exists. 131 00:20:07.140 --> 00:20:14.130 William Cheng: That means that the reference count for that vino is going to be bigger than zero, right. So in this case you don't create a new one. You simply incremental reference count. 132 00:20:15.060 --> 00:20:17.790 William Cheng: Guys again very important function, you need to remember what it is. 133 00:20:18.330 --> 00:20:25.380 William Cheng: OK, so over here. What it will do is they'll look for I know zero over here and then it will return a vino and this week, you know, represent 134 00:20:25.740 --> 00:20:33.330 William Cheng: The the the route. I know. So therefore it will it will assign it to the file systems that the fastest route. Yeah. 135 00:20:34.140 --> 00:20:40.080 William Cheng: Alright so this function will return zero whatever return zero. Then you know that you know this function returns successfully. 136 00:20:40.590 --> 00:20:47.850 William Cheng: So let's go back to the emphasis amount over here. So when this function. The malecon to return zero. I mean, the file system has 137 00:20:48.210 --> 00:20:53.310 William Cheng: Has was mounted successfully. So let's go back to the malfunction over here again to see where it is. 138 00:20:53.610 --> 00:21:03.540 William Cheng: Right, so you can BFS in that over here, what he will do is that it will mount the fastest them and when this function is done, the file system pointer over here and now will point to a valid file system now. 139 00:21:04.050 --> 00:21:12.240 William Cheng: All right. And then what it would do it is that there's a fastest route right the fastest route we just saw how he got created you got created where you call the get 140 00:21:12.840 --> 00:21:24.480 William Cheng: Okay, which again create the root of the issue with the processor. Yeah. And now they use BFS Rubino which is the global variable to point to it. Okay, so, so, so this is how you actually said it. Yeah. 141 00:21:26.400 --> 00:21:36.450 William Cheng: Alright, so this is the last thing that it does the mountains that we're not implementing mountains all the stuff are skipped. Right. So, so this is the code that initialize the bfs Rubino yeah 142 00:21:36.930 --> 00:21:47.130 William Cheng: You also see that in VFR shut down. We're going to use the Ruby Evers the bfs Rubino again we're going to make sure that the FS Rubino is not equal to know. Otherwise, you feel the exertion, or the colonel will die. 143 00:21:47.520 --> 00:21:55.950 William Cheng: And then what it will do is that it will use a local variable to point to it and then it will go to the V notes a VM Fs. 144 00:21:56.370 --> 00:22:09.960 William Cheng: To point to the fastest Sam and then what it will do is it will check whether this VM FS is in use or not. Okay, so what it will do is that it will go to every vino and try to count. Look at the reference cow to make sure that all the vino the reference count. 145 00:22:12.060 --> 00:22:18.210 William Cheng: Alright, so, so, what it will do is I will try to make sure that there's no vino that's active inside of our system. Right. What does it mean active 146 00:22:18.540 --> 00:22:22.350 William Cheng: After meaning that the reference card is not equal to zero. Let me there's something actually using it. 147 00:22:22.860 --> 00:22:34.230 William Cheng: Okay, I mean technically is not exactly equal to zero. But there are some other situation. I'm not going to get into too much detail. So what it will do is it will scan the file system to make sure that there is no active. There's no active vino 148 00:22:34.650 --> 00:22:43.800 William Cheng: If there is active vino what it will do is that will print this message to say panic BMS shutdown found at the vino in the route. So, therefore, this shouldn't happen. 149 00:22:44.640 --> 00:22:52.260 William Cheng: Okay, so you will see in the spec and then the grading online, they keep mentioning as if you see this error message there, you're going to lose points. 150 00:22:52.950 --> 00:23:03.420 William Cheng: Okay, so, so one thing important about Colonel choose that kind of one. I think if you shut down without in freeing data structure is probably not so bad. But even Colonel to where you 151 00:23:03.780 --> 00:23:13.320 William Cheng: You know, crypto kernel if they're active vino well then that's really. No, no, because the colonel will refuse shut down and then in the end, you're not going to see that message to say, you know, we makes halter cleanly. 152 00:23:14.280 --> 00:23:22.320 William Cheng: So every time when you don't see the weaning sort of cleaning the greater has followed the grading gala and data points. So, therefore, one thing is very important for you to doing curl to 153 00:23:22.500 --> 00:23:28.170 William Cheng: Is to to reference counting correctly. So when you shut down your organism, there's going to be no activity note. 154 00:23:28.770 --> 00:23:38.310 William Cheng: Guys will get this is a very important requirement. Again, this is, this is part of the reason why Colonel two is so difficult, right, because people increment the reference. Now they forget the detriment of reference. Now, 155 00:23:38.940 --> 00:23:46.080 William Cheng: So in that case, you're gonna end up with x Rubino so that's a no no. Some people forgot to encourage the reference cow and then they do the document reference call 156 00:23:46.260 --> 00:23:55.080 William Cheng: In that case, you're going to end up with a memory corruption bug right so that's even worse. Okay, so you have what you have to do is that you have to do a reference counting just right. Yeah. 157 00:23:56.790 --> 00:24:05.220 William Cheng: All right, so, so once this is verified that you know the bfs is not in us. That means that all the, you know, there's no active vino and then can actually 158 00:24:05.610 --> 00:24:16.920 William Cheng: Amount of our system from the root system. Okay. And then what it will do is it will actually make sure that there's no vino in use. And then it was said being equal to zero, they will free up the fastest them and then they will 159 00:24:17.460 --> 00:24:28.050 William Cheng: They will shut down. So it's VM FS shut down over here dysfunction. I think you've seen it already, right, Colonel main a main see BFS shut our over here. 160 00:24:28.650 --> 00:24:36.090 William Cheng: But what if that VM Fs. This one is inside idle proc run right so i don't progress. Once you're in a process die. 161 00:24:36.510 --> 00:24:40.770 William Cheng: The idol process. Wait for the entire process of diet and now you're gonna wake up the idol process. 162 00:24:41.400 --> 00:24:52.530 William Cheng: So in this case, the idol process over here will return from way P ID. Right. And then we're not doing multiple through our process. There's no shadow D. And then there's the bfs. 163 00:24:52.830 --> 00:25:01.500 William Cheng: Code over here. So what it would do that, you'll see a message on to the screen to say we need BFS shutting down and then he will call this function. If it turns out that it couldn't do it. 164 00:25:01.920 --> 00:25:07.980 William Cheng: Because they're actively note. So in that case, you'll also see this error message saying that BFS shut down fail. Yeah. 165 00:25:08.910 --> 00:25:18.840 William Cheng: All right. Otherwise, you know, we're not doing system file, file system. So, therefore, you're going to see the message that get printed to say the winnings is hard to clean. Right. So that's the place you need to go to 166 00:25:19.440 --> 00:25:25.230 William Cheng: Okay. All right. So, so again, this is where you need to go and then it turned off the machine. Okay. 167 00:25:26.430 --> 00:25:36.060 William Cheng: All right, so, so that's the Rubino, you can see that where it's got initialize and then. Alright, the next thing that we need to look at is how the file system work. OK. 168 00:25:36.810 --> 00:25:40.710 William Cheng: So again, we talked about that inside of forces them to these are real function pointers. 169 00:25:41.250 --> 00:25:50.760 William Cheng: As it turns out, there are two kinds of our function pointer there. So the way we're going to sort of look for this is to look at this thing called V and ops as a VM RPC is an 170 00:25:51.540 --> 00:26:08.340 William Cheng: Ops its operations. The operations are done by functions of VR ops. They are vino function which is an array of function pointers. Okay. Alright, so let's take a look at how this is us over here. So again, I'm going to run run this command. We're going to look for VR ops over here. 171 00:26:10.260 --> 00:26:16.950 William Cheng: Okay, so again, that's exactly what we saw you know on this file over here. So I'm gonna go down a little bit over here. 172 00:26:19.170 --> 00:26:30.570 William Cheng: Alright, so here's this comments they be an ops contending the address of an array of function pointers. So over here, there are two kinds of function pointers over here. One is a bite device. 173 00:26:31.140 --> 00:26:40.800 William Cheng: You know, a special you know VR ops and the other one is block device, a special be ops. I think in class. I mentioned that in Linux and Unix 174 00:26:41.220 --> 00:26:49.710 William Cheng: We call it device file a special file guys over here it says special, special VR ops over here. So that means that they are related to IoT devices. 175 00:26:50.220 --> 00:26:58.890 William Cheng: There are two kinds of IOT devices. One is called by devices and the other one's called block device by device you can read one bite at a time. So they have a resolution of a bite. 176 00:26:59.370 --> 00:27:08.010 William Cheng: The blog devices. You can read a bite at a time. You can only read a block at a time. Yeah. So, therefore, we're going to sort of look for this and see what you know what what are the differences over here. 177 00:27:08.910 --> 00:27:15.210 William Cheng: So we can also look for this thing. So let's see a copy this and I'm going to say grip. 178 00:27:16.860 --> 00:27:27.570 William Cheng: So, Colonel start, start to see there is something called by devices. It's in Vino de see. So let's take a look at. We know that see over here to see what they are. 179 00:27:28.530 --> 00:27:37.380 William Cheng: Alright, so we're here, is it shows you that, you know, this is called the vino operations. Right. So we, I think we look for VR ops. So this one is called vino ops. 180 00:27:37.650 --> 00:27:46.290 William Cheng: So again anytime you see underscore up. That's a real function pointer and here's an arrow function pointer. Right. So the first function over here called read the second one is called right. The third one is called em. 181 00:27:46.650 --> 00:27:54.570 William Cheng: You know, so now you know you know why lecture notes look like a certain way and then there's the functional create and they make no look up laying or something like that. 182 00:27:54.960 --> 00:27:59.160 William Cheng: So this one is what by device for by device, you can do all these operations. Yeah. 183 00:27:59.640 --> 00:28:06.540 William Cheng: So, so, so again, these are the device. So all the function over here. It's called special something because they are special files or devices. 184 00:28:06.810 --> 00:28:12.300 William Cheng: As a functional special file really special file right and think, I don't know if you remember from the last 185 00:28:12.840 --> 00:28:19.740 William Cheng: Friday's discussion section. So these functions are the one that you have to write. So again, inside the virtual file system. There's really nothing you can do. 186 00:28:20.340 --> 00:28:28.980 William Cheng: You know, because you have no idea what a device look like. So you need to ask the actual file system for help. And then you find the point in the actual process them and you call you call these multi indirectly. Yeah. 187 00:28:29.700 --> 00:28:37.590 William Cheng: Alright, so for by device over here you can do read and write. So that's why you have read and write the by device can also do the math function. So that's why the functions there. 188 00:28:38.490 --> 00:28:49.200 William Cheng: Yeah, all right. And then it says for device. There is no way to create a file over here. There's no way to make note and there. There's no way to do it. Look up. There's a lot of functions that are invalid. 189 00:28:49.800 --> 00:28:59.100 William Cheng: There also a function costs special file stat stat is a very important function. What it does is that defines the status of a node. 190 00:28:59.850 --> 00:29:05.850 William Cheng: Okay. So to find the status of I Know What is the status of I know as a typical so we sort of saw the data structure of I know before 191 00:29:06.150 --> 00:29:14.730 William Cheng: In Chapter six, when we look at system Papa says them inside. I know. So sorry. So, so he said, I know their information about which device. It belongs to 192 00:29:15.180 --> 00:29:24.240 William Cheng: Major device number minor device number. What is the I know number. What is the file type. What is the size of the file and then at the end, we have a 13 you know pointers. 193 00:29:24.840 --> 00:29:31.290 William Cheng: That's called the disk map the point to the actual data block. Okay. Right. So anyway, so, so, so that's sort of the structure that sort of device. 194 00:29:31.800 --> 00:29:39.660 William Cheng: Describe a particular file in a real fast is then there are also other information like the last time you modify this file, you know. So when you do LS minus l 195 00:29:40.080 --> 00:29:43.320 William Cheng: You know, you know, what was the last time I was modify 196 00:29:43.650 --> 00:29:50.670 William Cheng: There's also something called link count it come number of pointers in the file system that point to a particular file. Again, I think I mentioned before in chapter six. 197 00:29:50.850 --> 00:29:57.960 William Cheng: Those are the number of hard links that point to a file. So again, you need to sort of make some connection between chapter six lecture. And what I'm talking about over here. 198 00:29:58.830 --> 00:30:07.140 William Cheng: All right. And then there are these three files Phil page dirty page clean page that's for Colonel three. So we're going to skip it. Yeah. Alright, so 199 00:30:08.100 --> 00:30:15.270 William Cheng: And for the block device right so that's for the by device, the block device. There's no function or this pretty much everything is now. 200 00:30:15.600 --> 00:30:19.650 William Cheng: Okay, so for the block device. The only thing you can do, they can cost that on it. You can find out 201 00:30:20.250 --> 00:30:28.860 William Cheng: The information about this Bluetooth device. How many bites are there, you know, and things like that. I think you can also get major devices and minor device number of this device. 202 00:30:29.850 --> 00:30:41.820 William Cheng: Alright, so. Okay, so here's the most important function over here way. And this one is inside what far this inside. Vino de see over here. What do you will do is that way, you try to initialize V note. 203 00:30:42.960 --> 00:30:49.920 William Cheng: There is again. Well, you know, when you initialize Veena right when you create a I know you also need to create a vino when you create a vino you need to 204 00:30:50.220 --> 00:31:02.760 William Cheng: Initialize data structure. So what it does. Over here is that assess the VM operations over here in to be equal to the address of the device, a special, you know, amino operations there. 205 00:31:03.240 --> 00:31:12.540 William Cheng: They will also, you know, have another data structure over here called the character device to be by device look up and then he used the device ID. 206 00:31:12.990 --> 00:31:20.340 William Cheng: Guys what does device ID to device ID is those are those two numbers. The major device number and the minor device number right so what it will do is I will use a 207 00:31:20.640 --> 00:31:29.280 William Cheng: Major device number and my advice number and then what we'll do is we'll create some data structure inside of kernel. And then inside vino it will point to that particular device. 208 00:31:29.850 --> 00:31:46.380 William Cheng: OK. So again, these are special files. So therefore you need a special file an array of function pointer. You also need to know, you know you need you need a pointer to point to the the the device that's inside the actual file system. Yeah. 209 00:31:47.760 --> 00:31:54.990 William Cheng: All right, it's not a character device, then it's a it's a block device over here, say, you know, over here, it makes this function call. 210 00:31:55.530 --> 00:31:59.730 William Cheng: So tried to see that if this is a character device if it's not a character device, then it will try to 211 00:32:00.210 --> 00:32:10.680 William Cheng: Call care, sir, to make sure that this is a block device. Okay, so in this case what it would do is, you know, was signed to block device, a special app over here. I think that's the one that we just saw before, right. 212 00:32:10.950 --> 00:32:21.810 William Cheng: For the block device file, you can only do stat on so not not very interesting. Yeah. So I think, you know, for our internal to us. I'm in the only kind of device. Are you have, they're all character device. 213 00:32:22.770 --> 00:32:27.750 William Cheng: Okay. So, therefore, if you write code for the block device or your co will not be in the 214 00:32:28.230 --> 00:32:38.640 William Cheng: That you will not be able to exercise a while. In that case, because of the self check requirement, you have to delete all that code there. So, therefore, I think. All you have to do is to take care of the character devices. Yeah. 215 00:32:40.650 --> 00:32:50.340 William Cheng: Alright, so over here. Let's see. So, so these are the by device, a special file and the the block device special far and that's the array of function pointer. 216 00:32:53.070 --> 00:33:07.170 William Cheng: Alright, so let's take a look at the VM ops over here. Let's do it again. Let's copy it. Oh, OK. So we look for Vienna up over here in these other thing. Let's take a look at them first. 217 00:33:08.340 --> 00:33:13.890 William Cheng: Right. The first thing is that we need to look at the file that see FS file Darcy. 218 00:33:15.030 --> 00:33:20.610 William Cheng: Okay, we need to look at be an ops be on site be an ops right here. 219 00:33:27.360 --> 00:33:34.800 William Cheng: Alright, so I'll be here. So this one is called file I see this is the one that implement the file objects or what is the file. 220 00:33:35.190 --> 00:33:43.170 William Cheng: The file object is the object that has these four fields. He has a reference column. You remember how we open the file. They also keep the cursor position. 221 00:33:43.980 --> 00:33:51.150 William Cheng: Okay, so, so this is where the christophers you know cap and then it's also the one that has the I know pointer. Okay. So I think in the Phoenix implementation. 222 00:33:51.540 --> 00:33:59.130 William Cheng: The last point here is actually a vino pointer. So again it just one level indirection. The vino pointers been appointed. I know. So it's kind of like the winter. Yeah. 223 00:34:00.150 --> 00:34:13.110 William Cheng: All right, these acquire. I don't know what it does. And then there's the output wrestle for the fall over here. The fires a reference count. So again, you have those three function that has to get the has the ref and that has the put 224 00:34:13.620 --> 00:34:17.340 William Cheng: So this one actually use the put function and they cause a release function. 225 00:34:17.850 --> 00:34:27.900 William Cheng: So again, this is how he is an array of function pointer. Again, you have a function pointer. You want to call one of the function over here. All you have to do is the name the function and they are going to end up going to end up calling it and as it again. 226 00:34:28.590 --> 00:34:34.380 William Cheng: As I mentioned before, Colonel to is pretty straightforward because all you need to do is to find the pointer and you call it indirectly through 227 00:34:34.680 --> 00:34:43.110 William Cheng: So this is how you actually call them directly to it. OK. So again, looking into the kernel code. Find out how does the the existing the kernel code that you have 228 00:34:43.350 --> 00:34:49.530 William Cheng: Call those function indirectly, and now all you have to do is to copy the code do exactly the same thing. Okay, so that's what carnal to 229 00:34:50.220 --> 00:35:04.680 William Cheng: Is going to be pretty straightforward. Okay. All right. So, so over here, this is the function I mentioned before, so this one is the one that detriment the reference count inside the file object again the comment over here says if the count over here equals to, I guess, 230 00:35:06.630 --> 00:35:13.290 William Cheng: So you document the F county of f k equal to zero that you need to free it up right so that's why over here says call release, which means to free it up. 231 00:35:14.190 --> 00:35:20.670 William Cheng: Then, and then there's F get function, the function is the opposite of put what he would do is that it will increment the reference 232 00:35:21.570 --> 00:35:27.030 William Cheng: What it will do is that it will check to see if he exists or not. If it exists already well then in this case you allocate to 233 00:35:27.270 --> 00:35:31.590 William Cheng: Exist already, you just implement the increments reference count. Otherwise, you need to create it. 234 00:35:31.890 --> 00:35:38.670 William Cheng: Guys over here, you can look at the code right here. It's very simple. It check if the argument of your equal to minus y is equal to minus one thing you need to create it. 235 00:35:39.090 --> 00:35:44.280 William Cheng: So in this case, you call the slab alligator and you create a file object. Okay, and then 236 00:35:44.790 --> 00:35:55.860 William Cheng: Then, then I guess you if f is is not equal know and they initialize it by setting everything equal to zero. And then what you do is that you call f rap to increment the reference count. Yeah. 237 00:35:56.370 --> 00:36:01.620 William Cheng: Alright, so let's take a look at F F F. As it turns out, if this fit is not equal to not equal to minus one. 238 00:36:01.800 --> 00:36:09.030 William Cheng: Then this guy, you should be able to find out how do you find it right then this fit over here is going to be the file descriptor the file descriptor is a pointer to an 239 00:36:09.240 --> 00:36:18.570 William Cheng: Object right we talked about in class. And that's exactly what it is F over here be equal to, you go to the current process. There's an array of function pointer over here, copy files. 240 00:36:18.810 --> 00:36:26.850 William Cheng: They use FD as the array index. And that's how you find the file object and this fall. I click over here. It exists already so therefore you call ever 241 00:36:27.300 --> 00:36:38.190 William Cheng: Forever on it to increment the reference count now. So again, why are you implementing a reference count because over here, this function is going to return appointed to this file, and now you end up with the actual pointer that point to that file. 242 00:36:39.450 --> 00:36:42.630 William Cheng: Alright, so again this is very important understand, you know, when you know so so 243 00:36:43.170 --> 00:36:49.470 William Cheng: Keep me up. So I draw the picture before. If you have an object as a reference count. And now you have multiple pointer that point to it. 244 00:36:49.650 --> 00:36:56.550 William Cheng: You need to count the number of pointers. Right. So anytime we call a function that will return a pointer that points to it. You have to increment the reference count. 245 00:36:57.570 --> 00:37:09.270 William Cheng: Okay, so in this code over here, we see exactly how this is that okay so they don't need to understand, whenever you add a pointer to to a file object or you call a function that will return a pointer, you know that the reference count. 246 00:37:10.260 --> 00:37:22.260 William Cheng: If you want to add a pointer, you know, to a file object, you need to increment the reference count. But if you call a function that will return a file object, the you know the inside that function, it would it would have increment the reference can already right 247 00:37:24.300 --> 00:37:37.200 William Cheng: Okay, so that's the function f get put and where's F F F F is right here, over here. So what it does, it incrementally reference cow and what's important. Over here you can see that he actually print out a lot of debugging information. 248 00:37:37.800 --> 00:37:47.460 William Cheng: Okay, so if you insert configure MK you know where you use a god big flag if you include the symbol ff, okay. 249 00:37:48.450 --> 00:37:59.310 William Cheng: Because if you include FF so this case. Let me show you how to do it right. So you say DB g equals two. What do we usually have before we have tears error. Right. 250 00:37:59.700 --> 00:38:04.200 William Cheng: Error. And if you say F R E F over here. Now, this line will get printed 251 00:38:04.560 --> 00:38:10.050 William Cheng: Guys again look at complete I am K. There are quite a few example one of them will be the one that you want for Colonel to 252 00:38:10.260 --> 00:38:19.800 William Cheng: Okay. And that will be the one that include F ref and there's also improve the rep and a bunch of stuff over here. Right. Anyways, this function is very simple. All it needs to do all it does is income in the reference 253 00:38:22.170 --> 00:38:34.770 William Cheng: Alright, so where else is the being up over here on the pipe. We're not doing pipe in this class over here in VF that says car Colonel FS BFS call 254 00:38:35.400 --> 00:38:43.050 William Cheng: See, there's a beat and ops over here. Okay, so I guess they're only mentioned in the comment box over here. So again, 255 00:38:43.350 --> 00:38:51.930 William Cheng: Let's take a look at this code over here to link, you have to implement the link you know system call again this is the kernel version of the user spaces and call. It's called do link. 256 00:38:52.290 --> 00:38:57.990 William Cheng: So you need to create a link into a particular file right in class. We mentioned about what to do. 257 00:38:58.530 --> 00:39:05.400 William Cheng: There's a do renamed renamed something that you're angling something and the add a link to it change directory, we mentioned that already. 258 00:39:05.790 --> 00:39:15.510 William Cheng: Get directory entry as well. So again, the directory entries, the data structure is a fixed size data structure. So in this case, you're going to return one of the data structure over here that's mentioned right here. 259 00:39:16.560 --> 00:39:26.730 William Cheng: I thought again inside the virtual file system. You have no idea what a directory entry look like because it depends on the actual file system as well. Yeah, you find the pointer and you call it, etc. Right before LC 260 00:39:27.060 --> 00:39:37.500 William Cheng: LC especially because l seek is only done inside a virtual assistant, because all you're doing is setting the cursor position. Right. So remember, where's the cursor position the cursor position inside the file object. 261 00:39:37.920 --> 00:39:41.490 William Cheng: Okay, as over here again read the comment blot out to find out what you have to do. 262 00:39:42.390 --> 00:39:49.740 William Cheng: The staff function again, you know, again, you don't, you know, in the virtual assistant doesn't know what to do. You need to call a pointer is that actual process. Yeah. 263 00:39:50.340 --> 00:39:57.990 William Cheng: The bottom over here is for mountain. We're not doing any mounting. So over here, let's don't worry about it. Right. So again, their function for reading from a file. 264 00:39:58.440 --> 00:40:09.000 William Cheng: So again, virtual assistant on how to do it. You know, you could call the actual passes them to the right to the close to the dupe where I would talk about dupe. And then we also need to implement do to 265 00:40:10.080 --> 00:40:16.650 William Cheng: Make note over here. So again, that's one of the first function I mentioned in the last discussion section, the first function, you have to implement 266 00:40:16.860 --> 00:40:23.400 William Cheng: You do create a device, you don't know how to create a device, but the actual file system does. So, therefore, you make an actual file system called okay 267 00:40:24.390 --> 00:40:32.160 William Cheng: All right, create a directory and, you know, remove a directory and all this kind of stuff on link. Some of the stuff we talked about it already. Yeah. 268 00:40:32.730 --> 00:40:38.550 William Cheng: So inside this function, you know, all the function over here you have never there's no code, right. So, therefore, you need to sort of figure out 269 00:40:39.150 --> 00:40:45.030 William Cheng: What is the you know how you know you need to basically what you need to do is over here is that 270 00:40:45.330 --> 00:40:52.140 William Cheng: Some of them are the first argument over here is going to be the file descriptor or all of them are the file descriptor over here, right, because they are the file descriptor. 271 00:40:52.770 --> 00:40:57.660 William Cheng: These are the file system call code over here, make no make know 272 00:40:58.080 --> 00:41:05.850 William Cheng: In this case, there's no file descriptor. Make sure there's no far removed her. There's no file descriptor. Alright, so you see that the beginning function over here. 273 00:41:06.270 --> 00:41:11.880 William Cheng: The one they have the file descriptor and the later part over here. Usually the argument over here is a path. 274 00:41:12.180 --> 00:41:21.450 William Cheng: So again, over here in do get directory entry over here. You can only do this after you have open a, you know, you actually have opened up as once you open the file, you can actually read the content. Yeah. 275 00:41:22.530 --> 00:41:28.770 William Cheng: So we perform the seek the first argument is the file descriptor. I guess we all talk about that in class. Okay. 276 00:41:30.330 --> 00:41:44.520 William Cheng: What else is over here, Colonel FS VI n m o BJ. So I guess right now, we don't really care about the MO BJ so VR ops, there is still page. Yeah, I guess we don't care about feel page and dirty page. 277 00:41:45.000 --> 00:41:58.800 William Cheng: And Colonel FS Vino de see over here, be an ops. So this is the color we saw before, and also in the special file stat I mean you know this collection is how you how to implement one of the special function over here. 278 00:41:59.970 --> 00:42:03.180 William Cheng: It says, you know, specify again it's here's a device. How do you 279 00:42:03.690 --> 00:42:13.410 William Cheng: You know, call the stack function inside the virtual versus them. It says, you want to be sure to make sure that this pointer is not now okay because we saw before. 280 00:42:13.830 --> 00:42:18.810 William Cheng: You know, either for a character device for by device this pointer should never be not 281 00:42:19.170 --> 00:42:30.720 William Cheng: Okay and this guy is very simple. You just got to a care, sir. Make sure at this point or is not know and then the color indirectly by doing, you know, you see right here that this line over here and this part is exactly the same. 282 00:42:32.040 --> 00:42:36.810 William Cheng: OK. So again, the stat over here. It's just a function pointer. So all you have to do is to put parentheses and then you can actually 283 00:42:37.050 --> 00:42:49.860 William Cheng: Call this function. Right. So in this case, that takes two arguments. The first one is the vino and the second one over here is the data structure here. So again, so this is how you call a call a function inside the actual file system. 284 00:42:50.280 --> 00:42:56.610 William Cheng: That's all you do is to find the name of this pointer and then you can just call it directly by providing argument for this particular function right 285 00:42:56.850 --> 00:43:04.800 William Cheng: How do you know what the, what the arguments are you look at header file in order for you to figure out what to do. Yeah. Alright, so here this is a good example. I'll tell you how to do that. 286 00:43:05.490 --> 00:43:11.610 William Cheng: So, so you know what you need to write other function for the device you do exactly the same thing. Yeah. 287 00:43:12.060 --> 00:43:20.400 William Cheng: Alright, so again, what are the other ones that you have to implement right there's a special file read a special file right you know basically give you the code to how to do it. All right. 288 00:43:21.450 --> 00:43:31.110 William Cheng: What else is here. Let's see the next part over here for the file system. Alright, the next thing I'll be here is going to look at the referral system. 289 00:43:31.830 --> 00:43:37.620 William Cheng: OK. So again, right now I'm just going to give you a brief overview. The, the, the ramparts is there. 290 00:43:38.370 --> 00:43:43.050 William Cheng: I mean very brief. So what I want you to do is that after you're done with the midterm, look at the code. 291 00:43:43.320 --> 00:43:57.600 William Cheng: Guys so next Friday, I will actually walk through some of the code instead of emphasis there, but it will be best if you actually try to read a call first. Okay, so this way you know hopefully will be more useful. Right. Okay, so, so, so okay if I perform this operation over here. 292 00:43:58.680 --> 00:44:07.380 William Cheng: Just run it right all the functions inside the rabbit, Sam. So again, there's a real function pointer. We look for these vino you know you know operations over here. 293 00:44:08.280 --> 00:44:16.920 William Cheng: At the comment over here is a VR ops contain the address of an array of function pointer and these are called the RAM file system file virtual operations. 294 00:44:17.130 --> 00:44:27.720 William Cheng: And they ran fastest them that directory virtual operations. OK, so the referral systems of faith versus them. The only two things that implement over here is a file or directory net 295 00:44:29.010 --> 00:44:30.960 William Cheng: So actually, so, so, so 296 00:44:32.460 --> 00:44:37.500 William Cheng: Actually it doesn't implement a special files over here so we can only look at a special file to see exactly how it's done. Yeah. 297 00:44:37.920 --> 00:44:45.510 William Cheng: Alright so here it says where is the Wii and Wii Wii and upset over here it's inside a function called emphasis and Rubino 298 00:44:45.840 --> 00:44:57.900 William Cheng: And then what is the emphasis and Rubino it's a member of the RAM file system operation, which is an array of function pointer and so again we're going to dealing with a lot of area function point over here. So let's take a look at the rampart system. 299 00:44:59.640 --> 00:45:10.050 William Cheng: Okay so VI Colonel FS Ren FS over here. So there's a file virtual operations over here. Let's take a look at that. 300 00:45:13.200 --> 00:45:14.790 William Cheng: See, I didn't catch it. 301 00:45:18.870 --> 00:45:25.920 William Cheng: All right, so here is a rare function point over here. Okay, so you can also see that there's a lot of the RAM file system. So let's just start from the top over here. 302 00:45:26.460 --> 00:45:33.570 William Cheng: Implement a bunch of functions over here for reading a vino for deleting Urbino for creating a Urbino for a mounting the palaces them. 303 00:45:34.140 --> 00:45:43.530 William Cheng: Sort of, you know, South Mountain amount of our system, there is an emphasis on operation over here. Basically, they are appointed to all these four functions. Right. These for lunches for reference. 304 00:45:44.190 --> 00:45:50.520 William Cheng: So, therefore, can actually find the right. Oops. Let's do it again over here. Let's look for this function. 305 00:45:51.660 --> 00:45:59.700 William Cheng: Ram classes and Rubino over here. It's right here. Okay, so this is this is one of the most important function that later. You need to understand 306 00:46:00.750 --> 00:46:04.350 William Cheng: So via and then there's a delivery know and then Caribbean, etc. Yeah. 307 00:46:05.220 --> 00:46:10.650 William Cheng: Okay, so it ran file system operations like this again an array of function pointer. You don't see a lot of them, and then 308 00:46:10.890 --> 00:46:16.560 William Cheng: For the files in that directory. These are the function. The ramp our system you you tried to perform read operation. 309 00:46:16.830 --> 00:46:24.900 William Cheng: So again, where he performed a reed operations that actual process and in this case over here, what's coming in over here is no longer the file descriptor. 310 00:46:25.200 --> 00:46:31.260 William Cheng: Right, because the file descriptor is belong to the virtual faster. Sam, where you come inside the actual file system. You want the I note. 311 00:46:31.710 --> 00:46:39.390 William Cheng: Okay, so again, where do you find that I know that I know is inside the vino so if you pass the vino pointer inside this function, you'll be able to find it. I know. Yeah. 312 00:46:39.720 --> 00:46:49.230 William Cheng: Alright, so we hear the referral system read over here says, this one is actually a file, not a directory, the referral system right over here. Again, a file. You can also create a file, create a device. 313 00:46:49.710 --> 00:46:59.820 William Cheng: Performer look up operation perform Lincoln. Lincoln all these function up here, I can see that they're actually use right below it. Over here we have an array of function pointer. They just referenced all these function there the first 314 00:47:00.330 --> 00:47:07.710 William Cheng: Real function. But over here is for directory. Okay, so what are the operation. There are other useful for directory. Can you read from a directory 315 00:47:08.130 --> 00:47:18.480 William Cheng: Over here, it says no right over here is the reporter obvious know pointer. So when you try to perform a reformer directory. I know what should you do you need to make sure that you return an error number 316 00:47:19.860 --> 00:47:29.400 William Cheng: Okay, so for directory. If somebody tried to read our directory inside the Colonel, you have, you are you can call to a null pointer. So over here, you need to return a negative number. 317 00:47:29.730 --> 00:47:33.870 William Cheng: To indicate that this operation has failed. Right. So later on in Colonel to there's lots lots 318 00:47:34.140 --> 00:47:42.630 William Cheng: Lots of tests. Some of the tests will actually tell you to open a directory vino and try to call a read on this directory be know you got to make sure that you return an error code. Okay. 319 00:47:43.170 --> 00:47:49.620 William Cheng: Or I simply if you try to write, you know, into a directory, you're going to, you're going to get an error if you try to call me directly via the 320 00:47:50.520 --> 00:47:57.990 William Cheng: You actually going to error. What about a create what you can actually create a file, instead of directory. So, therefore, you know, this will actually point to a function 321 00:47:58.440 --> 00:48:02.880 William Cheng: The function is the RAM file system, create right. So again, you'll create a power inside the system. 322 00:48:03.510 --> 00:48:17.130 William Cheng: Can a directory, create a device well yeah right inside the slide deck directory you want to create device. So therefore, over here, it says, I need to call the function ram file system make make note right make knows how you created by so take a look at what this function looks like. 323 00:48:19.050 --> 00:48:27.870 William Cheng: Okay, so over here. What it will do is there to perform a lookup function and then it will call this other function and then it will do a bunch of stuff and then it will do, they will allocate the I know 324 00:48:28.110 --> 00:48:33.930 William Cheng: And this I know over here it says one of them is a character device. The other one is a block device. In this case you need to 325 00:48:34.410 --> 00:48:43.770 William Cheng: Provide a device ID again major device number minor device number and this is how you create a vino assessor how you created device or devices just a data structure. 326 00:48:44.520 --> 00:48:54.150 William Cheng: Okay. So inside of our system over here, they would just create the, the, the, these data structure and later on we chat to access the device or since we have a ram file system. Everything's faked. 327 00:48:54.720 --> 00:48:58.920 William Cheng: Okay, so later on we chatted on the device. The ramp up system will have to fake it. Yeah. Alright. 328 00:48:59.760 --> 00:49:12.630 William Cheng: Anyways, it will also do this. I know number, etc. Over here, and then it will return a bunch of stuff in India when we return zero. That means that it was successful. Right. Otherwise, you know, if the mode is wrong, you will panic or 329 00:49:13.200 --> 00:49:17.700 William Cheng: If the referral system is out of space. What it will do is that it will return he no space, right. 330 00:49:19.170 --> 00:49:22.590 William Cheng: Alright, so, so that's the ramp us is to make you know 331 00:49:23.640 --> 00:49:30.720 William Cheng: So some of these function. They're actually surprisingly simple okay because their emphasis to fix everything as in this case, it would just create a fake. Nope. Yeah. 332 00:49:31.740 --> 00:49:38.190 William Cheng: All right. It also these other function look up link or. So again, I'm not going to go through this right now. I'm going to save it for next Friday. 333 00:49:38.580 --> 00:49:44.280 William Cheng: So hopefully after the midterm, you have time to look at these Honshu yeah alright the next one over here is the file. 334 00:49:44.820 --> 00:49:53.310 William Cheng: You know, virtual operations over here. So for file. What kind of functions are valid, right. So, again, for file. You can read it, you can write it. What about open and close 335 00:49:54.090 --> 00:49:58.110 William Cheng: Where I mentioned that even the file system color open, you know, close read and write. 336 00:49:58.410 --> 00:50:08.130 William Cheng: Open and close they are virtual file system functioning. So therefore, they don't have to exist inside the actual faster. Yeah. Alright, so, so you can actually see that read and write, they don't 337 00:50:08.490 --> 00:50:15.870 William Cheng: They don't exist in the directory, but they did. They exist, you know, for file which kind of makes sense, right, because for file, you should be able to read and write from at 338 00:50:16.680 --> 00:50:27.900 William Cheng: The again. The only function that they share over here is the staff. I'm sharing the status, the one that I should try to get the information about a pretty good. I know my funnel how big it is, you know, you know, you know, well, 339 00:50:28.680 --> 00:50:35.970 William Cheng: You know what is encounter, all that kind of stuff. Right. So again, there's a ramp up some stats in both a directory 340 00:50:36.390 --> 00:50:47.910 William Cheng: You know, for directory operation and also for the final option operation all the other stuff. They don't really share the same function, right. So this is the only one I share again. Similarly, instead of our system. They also share this step function. 341 00:50:49.680 --> 00:50:58.620 William Cheng: Alright, so, so I think I'm going to stop right here. And next time we're going to sort of go through a little more of the RAM file system co 342 00:50:59.190 --> 00:51:05.340 William Cheng: So, so again, you should read this to see how they read from a fire, how the allocated and I know how to, you know, do all this kind of stuff. Okay. 343 00:51:05.790 --> 00:51:09.090 William Cheng: I guess the last thing I want to mention over here is that 344 00:51:09.720 --> 00:51:20.820 William Cheng: When you try to perform the Rubino operation over here. This is where they actually assign the the array of function pointer there. So again, we saw before inside. Vino de see over here, we assign 345 00:51:21.240 --> 00:51:29.700 William Cheng: The, the, the, the, the URL function pointer for the fastest them inside there. You know, I should not say we assign either the by device. 346 00:51:30.600 --> 00:51:39.990 William Cheng: malfunction pointer or the character divisor function pointer. Yeah. Similar over here. Will you try to create a vino you try to read it a particular de vino from, you know, from 347 00:51:40.440 --> 00:51:49.500 William Cheng: From the actual file system. Once you finish reading this, this data structure. What you need to do is that you need to assign a direct function pointer there, so I'll be here. 348 00:51:49.860 --> 00:51:58.440 William Cheng: You can see that. So again, we're not gonna, we're gonna skip the, the other code over here. So what will you need to understand over here is that over here. It look at the I know and they try to 349 00:51:58.860 --> 00:52:07.830 William Cheng: Find out what kind of I know it is. So remember in system passes them. I mentioned that you know there's something called the most, the most tells you what kind of I know it is 350 00:52:08.070 --> 00:52:13.770 William Cheng: Guys over here again over here says, you know, if I look at the mode, it will say what this is a regular file is called type data. 351 00:52:14.010 --> 00:52:23.640 William Cheng: This is a directory. I know it's type directory. This is the character device. This is the block device, right. So inside the winning sauces them. They're basically only three kinds of file. 352 00:52:23.880 --> 00:52:34.560 William Cheng: There is a regular file. There's a director file and there's a device file right and the device father two types. One is a character device and the otherwise by device. So one is a character device and the other one is called a block device. 353 00:52:34.860 --> 00:52:45.000 William Cheng: Now, alright. So if it's a character device over here, then the VN up over here is equal to know because we see before that inside the virtual versus them. 354 00:52:45.300 --> 00:52:50.730 William Cheng: They have a point to that point to the, you know, applying to the other by device. 355 00:52:51.300 --> 00:52:57.480 William Cheng: Also this point over your points know because in the special the special file over here. They pointed a block device pointer now. 356 00:52:57.870 --> 00:53:04.170 William Cheng: Alright for regular file over here. If it's a regular file the VM ops over here, point to the ranch houses and device on 357 00:53:04.380 --> 00:53:10.380 William Cheng: This is why, for regular file. You can reframe it you can write from it, right, because this one again this one look like this. Right. 358 00:53:10.620 --> 00:53:17.460 William Cheng: This one you can read and write, because we set up the pointer inside this function when we read the Beano when we read have enough on the disk into 359 00:53:17.760 --> 00:53:24.150 William Cheng: Into the opportunity to say we create this data structure. And then we assign these function pointer, so that they point to the right things. 360 00:53:24.900 --> 00:53:38.220 William Cheng: Alright, so over here. He also says the VM moto here. It's a regular file if our eg over here means that it's a regular file. If there'll be here. I mean, that this is a directory file and then in this case the VM up over here. A will point to the 361 00:53:38.760 --> 00:53:49.380 William Cheng: Directory, you know, virtual operations over here. Again, this is the one that doesn't have read and write, but you can actually have function to create a file, you know, remove a file, you know, other kind of all that kind of stuff. Yeah. 362 00:53:50.100 --> 00:54:02.310 William Cheng: Alright, so again this is a, you know, so so forth device over here again you need to assign the device id over here before regular file and for the directory. They don't have device ID. So therefore you left them initialized to be zero. Yeah. 363 00:54:04.050 --> 00:54:12.480 William Cheng: All right, so, so I guess that's side down to the bottom of this week nine notes over here. So, and so I'm going to stop here. 364 00:54:12.900 --> 00:54:20.460 William Cheng: So next time. So again, after the midterm, the midterms going to be I mentioned before, it's going to be taken midterm after the midterm than next 365 00:54:20.910 --> 00:54:24.930 William Cheng: I guess it's two Fridays. We're not because next Friday is going to be 366 00:54:25.410 --> 00:54:33.930 William Cheng: Spring break and then the week after. We're going to have the midterm after the midterm. In week 10 I'm going to walk, walk down some of the code inside parenthesis and I see 367 00:54:34.170 --> 00:54:43.200 William Cheng: I also if there's time left over. I will also talk about the bfs test that will be the major test, you have to pass in Colonel to go. Alright, see you guys.