WEBVTT 1 00:00:02.460 --> 00:00:15.509 William Cheng: Welcome to lecture 12 Colonel one is due next Tuesday. If you have come from previous semester, don't look at them. Don't copy them best to get rid of it at grading gala is the only way we'll gray. 2 00:00:16.260 --> 00:00:18.810 William Cheng: Really carefully in semi question. If you're not sure 3 00:00:19.620 --> 00:00:30.450 William Cheng: Don't run Kasia in a separate process. I guess all the stuff is similar to what we mentioned last time, testing, Section C and D of the grading. I like my sermon in the foreground and show the correct print out 4 00:00:30.870 --> 00:00:36.750 William Cheng: And if you're confused about self checks, please send me email okay after submission, they show you verify your Colonel submission 5 00:00:37.440 --> 00:00:45.270 William Cheng: So again, you know, I recommend that you designate a person in your team to make sure that this is done properly and to make sure that if you are using 6 00:00:46.020 --> 00:00:58.260 William Cheng: You know Bitbucket to synchronize your code. Make sure you submit the latest version. Yeah. You should also run through the examples in GDP assignment number two to learn some new GDP command for the Colonel. 7 00:00:59.070 --> 00:01:06.300 William Cheng: The Colonel one implementation timeline. So since. Today is Thursday. And again, the goal is to try to beat the submission deadline. 8 00:01:06.840 --> 00:01:17.640 William Cheng: So you should be, you know, I guess, according to my aggressive timeline, you should be doing. Phase three now said driver equal to one company that MK run Keisha insight in the program. 9 00:01:18.090 --> 00:01:26.520 William Cheng: And then you add three K shell commands one to run each each tests mentioned in the in the in the grading guidelines. 10 00:01:26.970 --> 00:01:33.480 William Cheng: You got to make sure that you you know that that you run them in the foreground and also make sure that you get all the credit for self checks. 11 00:01:33.990 --> 00:01:40.200 William Cheng: So this is one of the thing I want to remind people, because you know every semester there. People just, you know, lost all 10 points. 12 00:01:40.710 --> 00:01:45.360 William Cheng: Because they they either they don't read very carefully, or they made mistake or something like that. 13 00:01:45.840 --> 00:01:53.910 William Cheng: For the self checks, you must add the conforming DVD called at the end of every coast sequence. Right. So it's important to me to know exactly what a co sequences. 14 00:01:54.060 --> 00:02:00.570 William Cheng: So you know where the beginning is where the end is. Some people put it in the middle and then in the end they complain that, how come they don't get full credit 15 00:02:00.750 --> 00:02:05.190 William Cheng: If you put it in the middle that that's not the requirement. The requirement is that you have to put it at the end. 16 00:02:05.670 --> 00:02:11.040 William Cheng: Okay, there's no partial credit for putting them the wrong places. Okay, so you need to figure out where the end is 17 00:02:11.700 --> 00:02:23.280 William Cheng: So again, remember, and every time we were we were wondering about self checks will remember the purpose of the child self check the purpose of the soundtrack is to demonstrate to the greater that every co sequence that you have written is useful. 18 00:02:23.760 --> 00:02:32.550 William Cheng: And the way you do this is that is that if the greater can see that the last statement in the CO sequence get executed. Well then, then we know that you know that code is useful. 19 00:02:33.540 --> 00:02:44.010 William Cheng: Okay, if you put a, you know, confirming TVs you calling the middle and it gets printed out, well, what about the rest of the code over here. The rest of the code. There's no way for you to prove that that they're actually useful, right. So, therefore, you have to put it in the 20 00:02:45.000 --> 00:02:53.970 William Cheng: Okay. Some people argue with me or whatever. But anyways, this is the rule is the rule for everyone. So make sure you put at the end because some people they can really figure out exactly what the end is 21 00:02:54.210 --> 00:03:00.570 William Cheng: Well then you just started discussion because Google will be just send me email. Maybe you shouldn't tell you your classmate will co writing 22 00:03:00.960 --> 00:03:08.580 William Cheng: You should ask me email. And then, you know, show me. Now a few lines of code. So where's the is the end right here. Is that a runner right here. And then I can tell you what the end is 23 00:03:09.360 --> 00:03:17.670 William Cheng: Okay, don't just make assumption to say whatever you do, is going to be could be going to be okay because you know the grading rules are very, very strict and we have to follow the guidelines. 24 00:03:18.420 --> 00:03:26.880 William Cheng: Okay, all right, feel free to ask me a question. So we continue to with chapter one and talking about the virtual palaces, then 25 00:03:27.330 --> 00:03:38.730 William Cheng: The next thing we're going to look at this. Look at directories. So remember we mentioned before in UNIX the way so they sort of name file name, you know, files and devices. Everything is named using a file system name. 26 00:03:39.420 --> 00:03:45.540 William Cheng: Okay. So, this way we can name all the all the devices you all the files so that in a uniform way. Okay. 27 00:03:46.200 --> 00:03:50.130 William Cheng: So so so so so officers abuses almost everything has a path name. 28 00:03:50.430 --> 00:04:02.700 William Cheng: Files directories devices right devices Unix and Linux. They're also known as special files is when you see the word special file, they are referring to devices. Right. So these are the father only have two numbers. The major device number 29 00:04:03.030 --> 00:04:07.410 William Cheng: The number. The major device number of master device driver, you know, all that kind of stuff. Yeah. 30 00:04:08.190 --> 00:04:16.020 William Cheng: So, so every device, the keyboards developers displays divide this because the device network interface card with device. Everything's a device. Yeah. Alright, so 31 00:04:16.560 --> 00:04:25.680 William Cheng: So the way that these are name it's file system path is they they can be used uniformly. So for example, if I want to open a file or if I want to open a device. I'm going to use exactly the same system call 32 00:04:26.010 --> 00:04:36.300 William Cheng: Right over here, open a file right open this fall over here, you know, for reading and writing and if I want to open a device right over here. Here's the TTY remember the picture for the teletype right so so that's the the 33 00:04:36.630 --> 00:04:42.660 William Cheng: The device that you can actually your prints up onto the screen I do exactly the same thing. I open it. I opened up a rewrite 34 00:04:43.590 --> 00:04:55.380 William Cheng: Okay, so, so also when when I tried to read data from the file from the device I you exactly the same system calm and he's the resist them call so I can read from a file, whether it's it's a follower device I use it exactly the same way. 35 00:04:55.560 --> 00:04:58.710 William Cheng: If I want to write to the deep. This way I can also write to the keyboard. 36 00:04:59.100 --> 00:05:05.910 William Cheng: file descriptor, says I, the display file descriptor. So once I open this why I got a file descriptor. I can make use of racism call 37 00:05:06.270 --> 00:05:14.730 William Cheng: To write data, data to it to Unix is actually very, very simple, because, you know, no matter. You know what files or devices you talk to use exactly the same system called 38 00:05:15.480 --> 00:05:26.640 William Cheng: Right, although in one more point, you probably noticed that, you know, when we try to open that directory costs, etc. That behavior is a little different. You can open such etc because it's just a file. Okay, so therefore you can 39 00:05:27.000 --> 00:05:34.530 William Cheng: Even as a directory, you can actually open it. But when you try to read from it. I don't know if you have tried that, if you don't read from you're going to get you got return zero. 40 00:05:34.770 --> 00:05:38.160 William Cheng: As if you reach the end the files, even though you know that directory has stuff in it. 41 00:05:39.120 --> 00:05:50.010 William Cheng: Okay, so that kind of behavior reading from a directory. As it turns out, it's not standardized. It depends on the unit simply or Unix, Linux implementation some system will return to you something some system we're doing to something else. 42 00:05:50.310 --> 00:06:02.520 William Cheng: Okay, on, on a 32 bill bunch of 16.04 once you open this etc directory. If you try to reframe it yeah the other. The reason Paul is there and return zero to say that there's really no data to read 43 00:06:03.780 --> 00:06:11.070 William Cheng: Okay, so in that case how do you actually get the data from the directory. So in this case you haven't used a different system call now. So anyway, said that that's sort of besides the point. 44 00:06:12.660 --> 00:06:23.880 William Cheng: Alright, so in the Unix or Linux system, a directory is also implemented file so you can open it. Okay, but the content of the directory. Is it the content of the directory is actually binary data. 45 00:06:24.300 --> 00:06:34.770 William Cheng: Okay, so you have to know the format of the directory in order for you to understand what or what's inside of it. So the operating system will take the data instead of directory and interpret that data differently, right. So obviously, that will not call you know 46 00:06:35.460 --> 00:06:37.530 William Cheng: Man, by the way, the algorithm to make system call 47 00:06:38.220 --> 00:06:45.930 William Cheng: Right, it's the application that makes system call the operating system. They have a way to deal with the data directly, you know, if it's a device or if it's a file that 48 00:06:46.350 --> 00:06:49.500 William Cheng: So, so once operating system, open up a directory 49 00:06:49.680 --> 00:06:57.450 William Cheng: In knows how to interpret the data. But again, interpreted. Oh yeah, it's a it's a data structure that's on this. So at some point, you need to, you know, 50 00:06:57.600 --> 00:07:06.390 William Cheng: The, the virtual classes and doesn't really know what that look like. So in that case, you have to pass that information on to the actual process and maybe the actual process of them can actually tell you what kind of data center. 51 00:07:07.020 --> 00:07:15.600 William Cheng: Right. Alright, so the cells, a directory justify is interpreted differently by the OS as containing references to other files a directory. Right. 52 00:07:15.810 --> 00:07:23.460 William Cheng: I mean the picture that we just, we have a dirt. I mean, here's a picture right at the root directory. Over here we have files we have directories over here and the director will call them subdirectory 53 00:07:23.640 --> 00:07:36.570 William Cheng: In a subdirectory have sub sub directory and I set her up and eventually we're going to reach will we're going to end up reaching to the files. OK, so the criticism over here is going to take a directory inside the directory. There's a bunch of references to other father other directory 54 00:07:37.620 --> 00:07:40.230 William Cheng: Yeah. So in this case, what are these references right so so 55 00:07:41.130 --> 00:07:49.230 William Cheng: I guess we've mentioned a little bit before Unix the file are represented by I nodes. And I know this, you know, we don't know what I know is, but we know that I know represent a file. 56 00:07:49.680 --> 00:08:06.030 William Cheng: Okay, so again I know can be representative regular file that device file Gregory file. So again, this is a recursive data structure that. Alright, so, so, so what's the inside of directory so so inside the directory. Again, it's just a binary data file that try to map a stream to I know number 57 00:08:07.260 --> 00:08:18.750 William Cheng: Okay, so. So again, the way you think about is that instead of directory. If a bunch of sub directories. How do you refer to the sub directory those sub directories are referred to by there. I know numbers. Okay, I know numbers I integers. 58 00:08:19.350 --> 00:08:26.070 William Cheng: Okay, so in that case when you're trying to do instead of the actor is to convert or math, the strings into I know number 59 00:08:26.790 --> 00:08:36.240 William Cheng: Okay, so for example Unix over here pointed this orange. The orange stuff is a fall. I know. So in this case, it will, you know, he said directory, it will map the string units to 60 00:08:36.600 --> 00:08:45.270 William Cheng: To I know number. It will also not etc, which is a directory also to I know number. So this directory is I know number. So every one of these entries over here, it just map a string to 61 00:08:46.380 --> 00:08:59.460 William Cheng: Integer there. So, therefore, a directory maps have found a microphone. I'm over here is units, etc. Home prod dev and they're all see strings to item number, right. So, therefore, the map or string to integer 62 00:09:00.750 --> 00:09:06.840 William Cheng: OK. So, again, is simply a data structure sitting on this that will convert a string into an integer. Now, 63 00:09:08.070 --> 00:09:15.630 William Cheng: And this particular interpretation can be done inside the virtual file system. So he's got a virtual classes and you can actually ask the actual file systems and say hey you know 64 00:09:17.280 --> 00:09:26.910 William Cheng: You know, I have a string called Unix. Okay, so, so, so actually the verge of us. And then what it will do is that it will actually processes to say, can you give me the next entry in the directory 65 00:09:27.150 --> 00:09:33.690 William Cheng: Okay. And then the next engineer is going to contain two things. One is Australia and what is the integer. So by looking at the street, you know what, of course, one injury is 66 00:09:33.870 --> 00:09:42.000 William Cheng: And if that's not the one you're looking for. You can ask the actual file systems that give me the next century over here in the next century. So you can actually get the entry from a directory one entry at a time. 67 00:09:42.270 --> 00:09:48.780 William Cheng: Okay, so they are system called for, for, for doing something like that. So you can do that new user space program. You can also do that inside, Colonel. 68 00:09:49.290 --> 00:09:58.650 William Cheng: Let all right. So, so what is the I know do right so the I know is the one that will map the I know number to a disc address. Right. So in this case, again, if this example is that, you know, 69 00:09:59.310 --> 00:10:09.810 William Cheng: This particular. I DON'T REMEMBER REFER TO A file. Well, in that case it will refer to a disc address okay if this pretty good. I know number referred to to to to to divulge over. Well, in that case, he will not you know need you to 70 00:10:10.110 --> 00:10:19.800 William Cheng: To to at this address and it will lead to, to, to what I sort of get he will lead you to the major device number and minor device number. And now you can use the major device number to get you the device driver. 71 00:10:20.940 --> 00:10:28.740 William Cheng: Okay, so, so, so these are so these kind of sub are done at a lower level, the pastor, Sam, what at the higher level of the virtual your 72 00:10:29.760 --> 00:10:41.730 William Cheng: Process that is simply map a name, you know, to manager. Yeah. So, so this is a picture of what the the directory far look like. So again, I call it a directory five is a directory is 73 00:10:42.210 --> 00:10:45.210 William Cheng: Directory is implemented as a file. And this is a special kind of 74 00:10:45.540 --> 00:10:54.060 William Cheng: shouldn't use the word special kind of file because especially for me as a device, right. So this is a different kind of file. It's called a directory file. So the appearances and willing to have the data differently. 75 00:10:54.330 --> 00:11:02.550 William Cheng: There. So on the right hand side over here. So to show you what the content with director Paul look like. So again, it's simply a lookup table, you're given a string you convert them into 76 00:11:03.390 --> 00:11:11.520 William Cheng: That. So we also see that over here, we're going to add two more strings over here. So these are see string. So here I should actually put double quotes on. So the first century obvious called bar. 77 00:11:11.700 --> 00:11:18.090 William Cheng: Follow that backside zero because that's how you terminate a string. Okay, so what is that that is a self reference 78 00:11:18.690 --> 00:11:23.130 William Cheng: Okay, so this directory basically refer to itself to say I am I know number one. 79 00:11:23.940 --> 00:11:33.480 William Cheng: Okay, the second Andrew over years is two dots over here. So that's the parent directory. So again, it should be to double quotes with a bunch of zeros at the end of year. So data is the parent directory. So in this case, 80 00:11:34.080 --> 00:11:37.590 William Cheng: You know, the parent directory is also, I know it's also, I don't have one. 81 00:11:38.520 --> 00:11:46.830 William Cheng: Okay, so there's only one, you know, one directory that the self reference and the parents are exactly the same thing and that will be the route. I know. 82 00:11:47.490 --> 00:11:54.870 William Cheng: Okay, the route. I know is the sort of the router, the director, the director hierarchy, right. So this is the route. I know over here. So this one is the parent is itself. 83 00:11:55.350 --> 00:12:00.450 William Cheng: Okay, so therefore you both of them is equal to one, then the next entries of you. Again, I'm not going to stop the 84 00:12:01.200 --> 00:12:07.200 William Cheng: Engine. Remember, it's a string over here right units is I know number 117 etc. As I don't know before 85 00:12:08.190 --> 00:12:15.720 William Cheng: I just came up with these random numbers over here. I just feel at home is I don't know 18 progress number 36 and Deb is the number 93 86 00:12:16.560 --> 00:12:27.960 William Cheng: So from this, you know, so from the content of this particular directory. I have no idea what Unix this right units over here is just, I know. Number one, seven. Is it a directory. Is it a file. Is it a device. I have no idea. 87 00:12:28.500 --> 00:12:36.720 William Cheng: Okay, so therefore, how do I find out right at the virtual file system. I have no such information. So I have to ask the actual file system for that information. So the actual vs. I'm gonna tell me 88 00:12:36.930 --> 00:12:44.130 William Cheng: You know where the I know number 117 what kind of father this right. So remember, you know, a whole bunch of 16.04 you can access 89 00:12:44.490 --> 00:12:48.060 William Cheng: You know, Windows file system, okay window forces and doesn't have. I know. So 90 00:12:48.390 --> 00:12:59.130 William Cheng: This guy. Yeah, the obvious isn't he's playing pretend right they're going to give them. I know number and then the actual file system will cover the item number two to something else. Okay, so this way you could tell you what kind of founded this there. 91 00:13:00.690 --> 00:13:09.060 William Cheng: Alright, so over here it says that this is what the system file, file system and they run fast as them directly look like in the winnings operating system. 92 00:13:09.570 --> 00:13:18.300 William Cheng: Okay system for versus them again, if you read a weenies document. It's assignment number four for Brown University for us, we are not doing that assignment, we're getting the binary code. 93 00:13:18.600 --> 00:13:27.630 William Cheng: from Brown University as a library fi, we just going to use it. Okay, real emphasis them is a file system that using your kernel to so your current or two, you don't really have a real forces them. 94 00:13:28.740 --> 00:13:35.340 William Cheng: To is called virtual classes there. So all you have to do is to implement a virtual assistant. So in that case, we still need to implement an actual file system. 95 00:13:35.550 --> 00:13:46.080 William Cheng: The actual file system is going to be. It's going to be around file system. Remember what rants that's where I ran stands for your physical memory. It's random access memory. So in this case, it's a file system implemented in 96 00:13:46.950 --> 00:13:55.170 William Cheng: It's a process that implemented inside your physical memory. Okay, so therefore there's no desk. There's a fake this and the faith. This is represented inside your memory. 97 00:13:55.890 --> 00:14:06.120 William Cheng: Okay, so your carnal to, you know, your virtual assistant will needs to work with the rat bosses that will you start going into Colonel three, we need to switch in the real fast. Is that so at that point. 98 00:14:06.630 --> 00:14:16.380 William Cheng: We're simply going to switch a pointer and now you'll be using this is the boss is that ok every coach every line of code that you've written for virtual versus them should work because you are using polymorphous 99 00:14:16.770 --> 00:14:29.700 William Cheng: Is important, rather than allow you to have your virtual process them independent of the actual file system. Okay, so that's sort of the whole point of the virtual versus them so that no matter what kind of actual file system you're plugged in, they should always work. Yeah. 100 00:14:30.870 --> 00:14:44.880 William Cheng: Alright, so again for the virtual versus the point of view directory, it just a bunch of directory entries over here. So over here, it says that every entry is over here. It's called a directory entry on the left hand side over here is no as a component name. 101 00:14:46.200 --> 00:14:51.360 William Cheng: Okay, so therefore, there was a component. And I was an example over here slash home slash BCS 102 00:14:51.720 --> 00:14:57.120 William Cheng: File or something like that, right, the you know the stuff between the slashes over here. That's a component name. 103 00:14:57.480 --> 00:15:07.200 William Cheng: Okay, so here's a component. And he has a component in his component and the component name cannot contain the slash character because the slash character is used by Unix and Linux as a directory, the limiter. 104 00:15:07.680 --> 00:15:13.650 William Cheng: Okay, so that's how you find out. I have a directory here I have a directory here I have a direct with here because I use the directory directory character. 105 00:15:13.950 --> 00:15:25.860 William Cheng: Okay. Everything in between is a component. So we hear a directory entry. Here's a direct your entry in maps a component name to a corresponding I know number, right, the numbers for fights over here and over here. This is a string. 106 00:15:26.460 --> 00:15:41.160 William Cheng: You know, however big it is beautiful for that particular string. Yeah. Alright. So this is what it should look like, right. So again, when we talk directly hierarchy was sort of draw like this. Okay. So, therefore, you know, the director hierarchy. It's just an abstraction. 107 00:15:42.300 --> 00:15:49.350 William Cheng: Okay, because in reality you know you'll fall actually is flat or every fall over here, you know, sort of exists on their own. You open it up and you try to interpret that 108 00:15:49.470 --> 00:15:56.850 William Cheng: So in this case, instead of over here is I don't. Number four, as it turns out, I don't. Number four is also a directory. So therefore, we draw the picture like this. 109 00:15:57.960 --> 00:16:01.770 William Cheng: Okay, because otherwise you know every I know they all look the same. I mean, 110 00:16:02.850 --> 00:16:14.100 William Cheng: I know they they they only, the only ones I know number right but but but if you know that this is the thought. I know there's directly. I know if the directory. I know. Then it contain references or die notes right then you can interpret them as a file system hierarchy. 111 00:16:14.580 --> 00:16:24.180 William Cheng: Okay. In reality, the inside of our system. It's kind of like a flat space because every file and every directory and every device. They just get I know number 112 00:16:25.230 --> 00:16:32.310 William Cheng: OK, so the I know number of map to the file. So in chapter six. We're going to see how to implement that because we need to talk about a specific actual file system that 113 00:16:34.470 --> 00:16:45.150 William Cheng: All right, so, so, so how do we figure out the I know number for home bc food RC right so now we should open a file. Okay, so we say open and then here's the first argument, right. So I mentioned, you know, in the last 114 00:16:45.750 --> 00:16:47.280 William Cheng: The last lecture to say that, you know, the 115 00:16:47.490 --> 00:16:55.620 William Cheng: System is going to take a lot of time, will you make the open system call because is need to actually figure out whether you have access to this fall or not. And it needs to figure out whether this fight exist or not. 116 00:16:55.770 --> 00:17:03.030 William Cheng: So how do you even figure out what this file exists. Right. So the basic idea here is that you're going to perform an operation know as path name resolution. 117 00:17:03.450 --> 00:17:07.620 William Cheng: Okay, given a Unix path I need to convert that into I know number 118 00:17:08.190 --> 00:17:17.880 William Cheng: Right because India. I tried to open this for a while. So what is the I O number for this file. So that's the purpose of the path of resolution, given the fastest path returned to me and I know number of corresponding to this file. 119 00:17:18.420 --> 00:17:21.450 William Cheng: Okay, so how do we do that, right. So again, we need to do this intuitively 120 00:17:21.690 --> 00:17:24.090 William Cheng: Either effectively starting from the route. I know. 121 00:17:24.270 --> 00:17:33.300 William Cheng: Right. So at the beginning of the route. I don't over here. So what we need to do is that we need to see if there is a home directory inside the route. I know, right. There's no home directory and the route. I know what should we do 122 00:17:33.600 --> 00:17:36.600 William Cheng: We should say invalid path over here the file doesn't exist. 123 00:17:37.530 --> 00:17:42.960 William Cheng: Okay. So remember, one more, one and two. Now, we try to open a father. Father doesn't exist. Well, that's because when we perform path of resolution. 124 00:17:43.140 --> 00:17:53.490 William Cheng: At some point, it failed. So therefore, he says, you know, there's no way for me to to continue because this the the others director doesn't exist or the style doesn't exist. So I so so yeah so so in that case it will get an air air conditioner. 125 00:17:54.210 --> 00:18:06.180 William Cheng: Okay, so I need to go to the root directory first over here. So again, the slashes over here or directory, the limiter. So what I need to do is I need to look for two of these symbols over here and in the bit in between that it's going to be a component 126 00:18:06.630 --> 00:18:09.930 William Cheng: That so so when you're doing your kernel to this is 127 00:18:10.260 --> 00:18:14.910 William Cheng: You have to implement path of resolution. So you when you're given a pass over here. You start with the first character over here. 128 00:18:15.060 --> 00:18:20.400 William Cheng: Is the first character is a slash character. He says, oh, I need to know. I need to go to the route. I know, right. Where is the road. I know. 129 00:18:20.580 --> 00:18:28.410 William Cheng: Well, as it turns out that route. I know since since you always actually the dude I know who that is actually cached inside the fastest. So we always know what the route. I notice 130 00:18:28.740 --> 00:18:36.810 William Cheng: That. So we're going to go the route. I know. And we saw before they would I know look like this. Well, so what we need to do is that, you know, we need to sort of look for something that route. I know what are we looking for 131 00:18:37.200 --> 00:18:48.240 William Cheng: That. So what you will do is it will take this path over here, you're going to look for the next slash character over here. And now what you should do is that you should temporarily replace this backside other the forest slash character with a backside zero 132 00:18:49.290 --> 00:18:56.850 William Cheng: I mean, again, conceptually, you need to do this. You don't have to do this. In reality, you know, there are other ways to do it as a one thing you can do. This is a conceptual is that 133 00:18:57.060 --> 00:19:05.880 William Cheng: If I can replace this character with a backside zero, then I end up with a string and the sea stream over here. Start with the whole character, which is the next character after the first slash 134 00:19:07.170 --> 00:19:18.000 William Cheng: So if I have a character pointed the point right here. If I move up, move down one character over here, then I will end up with the C Street, and that's why I replaced by zero, because I want to oversee strings, right, because all the function 135 00:19:18.360 --> 00:19:27.720 William Cheng: The string function, I can use inside the Colonel, they're all see string functions. Okay. So this guy is I will have home follow that box I zero and that will be the component them. I need to look for 136 00:19:28.260 --> 00:19:37.290 William Cheng: Okay. So, therefore I'm going to go back over here. So what I will do is that I will, you know, either to listen to it. One is that you can get that that directory entry one at a time from the actual process there. 137 00:19:37.500 --> 00:19:43.530 William Cheng: And then you do a string compare with the component name against the one you're looking for, what, what you're looking for, because all right. 138 00:19:43.860 --> 00:19:51.870 William Cheng: So, therefore, what you would do is, I will go to the first entry is over here and you tell the actual positions there hey returned to me the first entry and he competed against the component name is equal to 139 00:19:52.260 --> 00:20:00.120 William Cheng: Not equal to home, so therefore it doesn't work. So I'm going to ask the, the actual file systems they give me the next century. God, that is not the same. Keep the next entry. 140 00:20:00.390 --> 00:20:04.230 William Cheng: UNIX is not the same keeping the index entry. So this is a really, really slow process. 141 00:20:04.770 --> 00:20:12.270 William Cheng: Okay, if this directories that we have contains 1000 enter. You can see how slow, this, this. Okay, so that's why in the open system call this is going to take a really long time. 142 00:20:12.540 --> 00:20:23.790 William Cheng: Then another approach over here. Again, very similar. What I can do is I can simply ask the actual file system to say that, you know, here's a directory. I know number going to that directory over here. Okay, and then look for, you know, 143 00:20:24.330 --> 00:20:30.600 William Cheng: Go down the list and to see if there's a component name cohort is there is returned. And I know number four. 144 00:20:32.070 --> 00:20:32.610 William Cheng: Number for me. 145 00:20:33.870 --> 00:20:41.580 William Cheng: Okay, so again, there are two ways to do it right, one can you do this internally one entry at a time. But that would be really slow or you can ask the actual process me the actual process and 146 00:20:42.420 --> 00:20:44.310 William Cheng: So that particular operator is known as a look up 147 00:20:45.180 --> 00:20:54.000 William Cheng: That. So what you do is that you're given a directory over here. You say, look up the string home for me to see there's a corresponding I know number if there is returned the I know number for me. 148 00:20:54.270 --> 00:21:05.100 William Cheng: Okay, so either case, right, in both cases over here, in the end, you should be able to return the value of at that. So in this case, what I would do is that is that you know I can do either way, but in the end over here to home will be equals 218 149 00:21:06.450 --> 00:21:17.970 William Cheng: Okay, so what can I do with it. Well, so over here I'm performing path and resolution home slash home should be a directory. So what I will do is I will send it to the actual versus have to say is I know at a directory 150 00:21:18.660 --> 00:21:27.660 William Cheng: Okay, if the actual buses and says, I know it is not a directory. So in this case, again, look up failed over here as I say that in Bella path because there's no way for you to get to food Darcy by going this way. 151 00:21:28.290 --> 00:21:35.040 William Cheng: Okay, if it turns out you know the you know the whole over here is a directory. Right. So I said that I don't have a single view of the actual files. 152 00:21:35.250 --> 00:21:43.050 William Cheng: I mean, we are sort of point to the desk, but now the thing about it is the actual file system over here as a FS right here is agile process and to say what does at 153 00:21:43.380 --> 00:21:47.040 William Cheng: That directly as a great and now I can do the next thing over here, I will 154 00:21:47.280 --> 00:21:55.200 William Cheng: You know, so, so, so, so I'm going to replace this batch of zoom back with a slideshow bigger and then I'm going to look for the next slide over here. And then again, conceptually, 155 00:21:55.530 --> 00:22:04.080 William Cheng: Replacement zero. And now I have a string copy. See, I need to look for that. So this will happen is, I'll be here. Now I have a directory over here and this, this is I know 18 156 00:22:04.710 --> 00:22:12.810 William Cheng: OK. So again, why can do is I can retrieve them one entry at a time or I can ask the actual files to them, say hey you know inside this directly. I know number 18 157 00:22:13.050 --> 00:22:20.010 William Cheng: Now that know that it's a directory could just see if there's a component, then that's equal to be see there it is returned to me the I know number 158 00:22:21.330 --> 00:22:30.420 William Cheng: Okay so doing this can be done over here. So in the end, what it will do is that return. I know number over here, or it says there's no such I know why that case again you fail if you return. I don't remember to you over here. 159 00:22:30.660 --> 00:22:32.520 William Cheng: I put a question mark. I don't know what that number is 160 00:22:32.970 --> 00:22:38.670 William Cheng: OK, but whatever that number is, what should I do with that, again, I need to ask actual versus the mistake. Is this a directory 161 00:22:38.790 --> 00:22:47.670 William Cheng: If this is a directory, then in that case I will open that directory over here. Right. They'll have us. Here's the directory search homes, I'd be seen as a directory and then again I can read one entry at a time. 162 00:22:47.850 --> 00:22:58.920 William Cheng: Or I can ask the actual positive to say is there. I know call food does see me there is what it will do is that it will return the item number. Finally, to me, and now I know the I know number for this particular file system path. 163 00:23:00.600 --> 00:23:12.060 William Cheng: Okay, so you can see that this pattern resolution process is actually a very painful process, you have to sort of do this intuitively one directory at a time, eventually you will find the find the number for the Father. You're looking for 164 00:23:13.140 --> 00:23:18.030 William Cheng: Okay, so in Colonel to that's one of the main thing that you have to implement it is the path of resolution that 165 00:23:24.150 --> 00:23:30.450 William Cheng: The UNIX system is a strict hierarchy, right. So again, what does retire. It means. It means that it has one roof under one roof. 166 00:23:30.960 --> 00:23:39.240 William Cheng: And also every intermediate know can only have one parent and also the note that leaf know also can have one parent. But in that case, it's very inconvenient. 167 00:23:39.810 --> 00:23:45.000 William Cheng: There's Alyssa, you have a you know file system hierarchy. And I've every long over here and this is the file that you keep wanting to open 168 00:23:45.780 --> 00:23:52.350 William Cheng: Okay, it's 100 level deep over here. So every, how will you start to open this this fall over here, you have to close the positive resolution. That's a really slow process. 169 00:23:52.920 --> 00:23:58.560 William Cheng: How do you actually speed it up. Right. So again, there's different, we can do it, you can do some kind of a cash to remember what I know number is 170 00:23:58.830 --> 00:24:04.110 William Cheng: Another way to do is that you can actually create links over here so that you can create a shortcut into this file. 171 00:24:05.010 --> 00:24:14.040 William Cheng: Okay. So for example, I can create a shortcut over here. So here's the father always want to open. So this is my food. I'll see over here that. So what I can do is I can create a link that link to this fall over here. 172 00:24:14.550 --> 00:24:20.220 William Cheng: Okay, we're not creating a link like this. Now it's no longer a strict hierarchy, because now this particular 173 00:24:20.460 --> 00:24:27.660 William Cheng: You know, this particular file has two parents that right. What this is apparent, and this is apparent. So yeah, I'm gonna break the streak hierarchy. 174 00:24:28.170 --> 00:24:37.530 William Cheng: Okay, so when you start to break something that's very, very nice. You better have a really good reason. So again, this reason over here is that I'm going to improve the performance by quite a bit by introducing the the shortcut. 175 00:24:37.920 --> 00:24:47.310 William Cheng: Okay, there are two kinds of shortcut. One is called a hard link there the hardening is used to reference to a file, so I can create a hyperlink over here to link to this file that 176 00:24:47.850 --> 00:24:56.310 William Cheng: So, so the reference to a file in one directory that also appear in the other one over here, right. So, so this file now appear in this directory is also impairing another directory 177 00:24:57.270 --> 00:25:02.970 William Cheng: OK. So again, this fall now has to parents. So again, it's kind of confusing. But again, this, this will speed things up. 178 00:25:03.570 --> 00:25:13.230 William Cheng: Now, so the way you add a hardening overhears use the link system call. Also, if you're using a logging show us the LM command over here, you can create a hard link to any file that you want that. 179 00:25:14.070 --> 00:25:18.690 William Cheng: So unfortunately, you know, this can only be created for a file and not a directory 180 00:25:19.560 --> 00:25:24.270 William Cheng: OK, so the reason is that we can use a hardening on a directory. We're going to end up 181 00:25:24.600 --> 00:25:33.360 William Cheng: You know, so, so, so why because if somebody, somebody actually got to do something like that. So, so over here. There's it directly all the way at the bottom. What if I create a link to a to a directory at the top over here. 182 00:25:34.530 --> 00:25:40.230 William Cheng: There. So if I allow the Harlan to perform a directory. So now, if I'm, if I'm trying to traverse 183 00:25:40.500 --> 00:25:50.940 William Cheng: All the files into my in my directory hierarchy. I'm going to end up with a cycle. Right. Start with a route over here. I'm going to traverse down this path. And then I'm going to end up with a cycle over here. So now this will go on forever. 184 00:25:51.930 --> 00:25:59.430 William Cheng: Okay, but he can write you write an algorithm to remember where you have visitors and that's guys you you can actually avoid the cycle. But that's a very, very expensive operation. 185 00:26:00.270 --> 00:26:08.670 William Cheng: Okay, so therefore at the bottom over here to say that, you know, here's a white the link system called cannot be used on a directory, because we want to avoid cycles, even though there's 186 00:26:10.020 --> 00:26:15.360 William Cheng: There's algorithm, you can use to detect cycle, but that algorithm is too expensive and nobody wants to implement that. 187 00:26:15.720 --> 00:26:21.720 William Cheng: Okay, it's much easier to just simply have a rule to say that you are not allowed to create a hard into a directory and this way. 188 00:26:21.900 --> 00:26:31.980 William Cheng: So this way when we tried to visit all the files in our director hierarchy, we could write a very, very simple procedure will get right very simple function by making a recursive call. And what does that recursive call apply 189 00:26:32.550 --> 00:26:38.400 William Cheng: Whereas it again, he could write that code over here. I tried to visit every note over here inside your hierarchy is going to be only five lines of code. 190 00:26:39.300 --> 00:26:43.380 William Cheng: Okay, because we don't have to detect cycles over here and therefore, the code is going to be very, very efficient. 191 00:26:44.280 --> 00:26:51.480 William Cheng: Than I do. Yeah. So again, if you have taken CSI 70, you're probably going to learn about, you know, graph, you know, a little bit of graph theory. 192 00:26:51.870 --> 00:26:56.550 William Cheng: You're going to learn about how the you know the detail. How did he had detect cycle is that directly basically graph. 193 00:26:56.910 --> 00:27:05.550 William Cheng: So in that case is going to be very expensive. Yeah. Anyways, so. So what's important to understand is a Harley can only be used to link to files and not directories now. 194 00:27:06.000 --> 00:27:10.440 William Cheng: The other kind of link over here is called soft link or symbolically, you can use them to link to anything you want. 195 00:27:11.100 --> 00:27:17.970 William Cheng: Okay, but as it turns out, the soft link over here. It's not the same. It's very big enough for the holiday because it's a different kind of file. 196 00:27:18.780 --> 00:27:26.640 William Cheng: Okay, so now we know that a file can be a regular file can be a device file, which called a special file can be a directory file. It can also be a symbolic link. 197 00:27:27.270 --> 00:27:37.650 William Cheng: There so smelly, it says a different kind of either contains the name of another file or directory. So in this case is a file that contains the streaming at the string referred to another part of the file system. 198 00:27:38.550 --> 00:27:47.040 William Cheng: That. So, this can be done using the same link system call or if you're on the command line because LM minus s to create a link, or two, or to anywhere you want inside of our system. 199 00:27:47.610 --> 00:27:56.040 William Cheng: Okay, so let's take a look at some example to see how this is done. So for example, the first one over here. We don't write Ellen minus. So, therefore, we're creating a hard link. 200 00:27:56.400 --> 00:28:04.080 William Cheng: Then, so we here what we're doing over here is that the the LM command over here. The first argument is, what do you want to link to and this better be a file. I know. 201 00:28:04.530 --> 00:28:13.920 William Cheng: Guys. So in this case, we're linking to size unit slashes right here unit is right here. This 1.2 I know don't fall I note over here. So this why. So we're going to create a hardening to a fall. I know. 202 00:28:14.190 --> 00:28:20.400 William Cheng: And the new entries over here is going to be inside a slash etc up directory and the component name will be known as image. 203 00:28:21.900 --> 00:28:34.320 William Cheng: Okay. So this guy is, you know, so, so what we should be the final results. Finally, is, though, is that inside a separate directory. Right now we only have one entry that mot de mot de is a regular file. We're going to add another entry over your image. 204 00:28:35.490 --> 00:28:49.650 William Cheng: Now this image will point to exactly the same file. Okay, this one is the same thing as slash Unix so slash you do this right here is another arrow point right here. Okay, so we're going to create images, etc, to, to, to which is a hard link to the slash Unix. I know. 205 00:28:50.760 --> 00:28:59.490 William Cheng: Okay, so how do we do that in the picture like this right over here, you know, the root directory is this guy over here. This one, I said, or is it. Number four, I don't know, before look like this. Right. He has 206 00:28:59.760 --> 00:29:07.980 William Cheng: He has da da da da. This is a self point of self reference. So this one is I know number for the parent over here is I know, number one, right. So this one tell you where the parent is 207 00:29:08.430 --> 00:29:17.100 William Cheng: That. And then the next one will be your mot de is this entry over here. It's a regular file and this item number 33. And now, how do you add another entry into this directory. I know. 208 00:29:17.520 --> 00:29:24.540 William Cheng: Well, simply by a pending to air. So if you're going to add another directly entry over here to enter as a component name, what would you write in the component 209 00:29:24.870 --> 00:29:39.510 William Cheng: Right, this case, the new entry obvious called image on the right. I am a G zero, we get right and what's going to be the, I don't remember the I know number is going to be the I know number four slash units last year. This is 117 so we just write 117 here and then we're done. 210 00:29:40.650 --> 00:29:47.760 William Cheng: That so creating like a simply like this, right, we add a new entry over here into this directory. I know for a slash etc and then 211 00:29:47.940 --> 00:29:53.010 William Cheng: You know, so this is the actual of what we do right but we draw the picture as a file system hierarchy, we're going to end up with this picture. 212 00:29:53.820 --> 00:30:09.600 William Cheng: OK, so the pointer over here is simply the number that will point to whichever I know that are supposed to point to. OK. So again, I sent over here, point number four. So design on that before. And this one is 117 over here. So again I the image map to all 17117 cetera 213 00:30:11.100 --> 00:30:16.770 William Cheng: Okay, so, so when you look at the picture on the right over here, you will draw the you know the hierarchy picture on the left. Okay. 214 00:30:17.370 --> 00:30:24.030 William Cheng: So, so one thing interesting over here is that once you create this pretty good hardening you know disheartening is kind of symmetric 215 00:30:24.930 --> 00:30:35.220 William Cheng: That if you look at, I don't number 117 over here, right. You said, Well, who is your parents. Okay. Well, I don't want one. Once everyone here has, you know, I chose to parent. One is the parent over here, which is the 216 00:30:35.580 --> 00:30:39.180 William Cheng: Route, I note over here and the other parent over here. It's going to be, I don't. Number four. 217 00:30:40.500 --> 00:30:48.840 William Cheng: Okay, so the UNIX fall over here, right, with no I know number 170 has to parent. What is I know one of the other ones. I know, for which one is their first 218 00:30:49.890 --> 00:30:52.350 William Cheng: Day. So from this picture you actually, you cannot tell 219 00:30:53.340 --> 00:31:04.380 William Cheng: Okay, so these two picture you know this. I know over here design over here. So they're both directly. I know they look kind of symmetrical. I cannot tell whether this entry is, you know, the center. The center is here. First, or there's entries here here first. 220 00:31:04.770 --> 00:31:14.190 William Cheng: I mean maybe inside of our system. I will, you know, I would directory creation time. So maybe if I look at the creation time to me, I'll be I'll be back and figure it out. Okay, but by looking at this picture, you know, 221 00:31:14.550 --> 00:31:19.410 William Cheng: It is possible. I have this entry first and then I create a symbolic link over here to do to link to the same file. 222 00:31:19.590 --> 00:31:27.750 William Cheng: Well maybe it's the other way. I have this entry over here instead of root directory first and then I create a hardening over here inside slices cetera two points. The same file. 223 00:31:28.350 --> 00:31:37.260 William Cheng: Okay, there's no way for you to tell the difference. Okay, so that's one of the sort of the, you know, the characteristic of a hard link is that you can't really tell who is their first. Yeah. 224 00:31:38.760 --> 00:31:45.120 William Cheng: A little bit of symbolically unless anything over here. It's a different kind of file, right. So if I say Ellen minus s right slash Unix or 225 00:31:45.360 --> 00:31:51.690 William Cheng: Linux UNIX is, you know, is this guy over here. I don't. Number one, seven slash home science PC. So inside our homes IPC 226 00:31:51.930 --> 00:31:58.110 William Cheng: I'm going to create a new file and this new file has the file type or symbolically, right. So I told me CSI species here. 227 00:31:58.260 --> 00:32:12.150 William Cheng: Are we going to add another one over here is called my link my link over here. Okay. So in this case, this one is, you know, this one doesn't point to wall and seven over here. This one is actually a new file. And inside this fall. We're going to store the strings slice units in it. 228 00:32:13.320 --> 00:32:20.040 William Cheng: Okay, so if you're going to create a Miley and slash home science PC to soft link to such unique. So when I'm done, you will look like this. 229 00:32:20.250 --> 00:32:33.750 William Cheng: Where I'm actually use a different color over here. It's not orange because the orange is the fall. I know it's not blue because the blue as a director. I know this one is actually pink that so inside this fall over here. There's simply a string to say slash Unix with the backside zero 230 00:32:35.220 --> 00:32:36.330 William Cheng: It's a regular file. 231 00:32:36.930 --> 00:32:46.650 William Cheng: So maybe there's another batch i zero in there. It doesn't really matter. So in this case, you know, this new symbolic link file, it's a different kind of it has a string size Unison that. So, this one will be referred to the same file. 232 00:32:46.920 --> 00:32:55.890 William Cheng: So you know what this is kind of like a, like an alias masters over here size homesites basis is my link why if you open that special file, you will see what is referring to 233 00:32:57.360 --> 00:33:01.440 William Cheng: Okay, so this way. Again, we, you know, when you try to open this file, you don't end up 234 00:33:01.830 --> 00:33:15.660 William Cheng: To be slack UNIX and why don't you try to open the file size unit, you got to go back to the root of the file system hierarchy and then start doing path of resolution all over again. Okay, if you have a hyperlink over here, right, like we had before. If you have a hardening like this go 235 00:33:17.010 --> 00:33:26.820 William Cheng: There. So when you perform path of resolution, you're going to get the I know number right away. You don't have to go back to the root of the file system again. So again, the symbolic link and hardening they behave very, very differently. 236 00:33:27.750 --> 00:33:35.640 William Cheng: There. Alright, so here, serving example I will we try to create a link over here, minus s right. So in this case, we can also do it to a directory so we can 237 00:33:36.240 --> 00:33:48.030 William Cheng: Create a link or slash home science bc inside size, etc. We're going to create a new entry over here as BC. Right. So again, this one is a symbolic link file. So instead of the modeling part over here. I'm going to store the street side homesites BC. 238 00:33:48.240 --> 00:33:49.950 William Cheng: So when I'm done. It will look like this. 239 00:33:50.670 --> 00:34:03.420 William Cheng: Okay, I started center SIPC it's a symbolic link file is a symbolic link over here I have a string slash home science bc my song has like PC over here is, you know, is this guy over here. So when I tried to traverse a particular file. 240 00:34:04.410 --> 00:34:13.140 William Cheng: Okay, so let's take an example, how do you actually use this particular symbolically. Yeah. So for example, I try to do an ls minus out slash, etc. 241 00:34:13.500 --> 00:34:19.380 William Cheng: Etc. So Unix last lecture. Why so again I'm going to do path of resolution, go to the real fine, like I said, 242 00:34:19.860 --> 00:34:31.830 William Cheng: It will be this. I don't number and then go to look for BC over here and then go to this. I know number. And when I get this. I know number I will ask, I choke PA system to say what is this. I know the US is the most say this. I know it's a symbolic thing. 243 00:34:33.210 --> 00:34:41.520 William Cheng: Okay, so I that's why I know I won't get it. I know number over here. So what I need to do I need to open this file and then look at the stream over here. The reissue over here it says I'm you know 244 00:34:41.880 --> 00:34:44.880 William Cheng: You know this pretty good symbolically, it links to slash homesites VC. 245 00:34:45.210 --> 00:34:53.760 William Cheng: Okay, so what I have to do right now if I need to see my contacts and they don't need to restore contacts, because I'm not done yet because I still have, you know, more fastest path to traverse 246 00:34:53.940 --> 00:35:05.910 William Cheng: Guy. So I'm going to say my contact right here, over here, and then I'm going to go traverse slash home science VC. So how do you do that right so you can go to the root thing over here. Look for home and they find BC over here. When you reach the end over here you 247 00:35:06.420 --> 00:35:18.390 William Cheng: Say this guy's PC over here. It's going to be a directory. Right. So, therefore, you're right here and now you restore the contacts you continue to perform path and resolution by looking for Unix by component component A unit inside homes actually see 248 00:35:19.080 --> 00:35:28.140 William Cheng: Okay, so this is our homes RPC over here I have a nother component and call units units over here. I need to verify. It's a directory and then in this case, I have a file called lecture one 249 00:35:29.520 --> 00:35:40.710 William Cheng: Okay, so when you perform path of resolution. If you hit a symbolic link, you need to save the contest go traverses symbolically when you finish reversing this about me. You're going to restore the contacts and continue to to to 250 00:35:41.160 --> 00:35:49.050 William Cheng: Perform path of resolution, but when you continue to perform pathogen resolution you might hit another symbolic thing and you have to say contacts and then do this over and over and over again. 251 00:35:49.920 --> 00:35:59.430 William Cheng: Okay, so using a symbolic link is actually very, very slow, you know, because you have to, you know, do this reversal, all the way from the file system hierarchy again. So why would people want to do that. 252 00:36:00.420 --> 00:36:07.020 William Cheng: Okay, because people are lazy. They don't want to type of rule of law passes and path. And so they just want to type a short name over here. So we're going to end up with symbolic me 253 00:36:07.320 --> 00:36:18.930 William Cheng: Okay. So, people used to volunteer for the purpose of convenience, even though the performance is actually pretty bad. Okay. And also, if you want to create a link to a directory. You can only use a symbolic date because there's no way for you to do. 254 00:36:19.890 --> 00:36:22.350 William Cheng: It. There's no way for you to use a hard link. Yeah. 255 00:36:24.900 --> 00:36:34.080 William Cheng: Oh, I, I, another thing. I'll be I want to sort of briefly mentioned over here is the concept of working directory. I think sort of mentioned that term before. Right. And when you, when we give the 256 00:36:34.950 --> 00:36:47.070 William Cheng: The sort of a third the UNIX command review or this command called PWD over here I PWD stands for peering print working directory. So what is it working directory by the work and drag is where you are inside of our system. 257 00:36:48.090 --> 00:36:50.760 William Cheng: Who are you, anyway. So as I said, where are you in the 258 00:36:51.780 --> 00:36:57.900 William Cheng: Inside your fastest them, you know, who is this, you know, as it turns out, this you is your luggage is a command shell. 259 00:36:58.590 --> 00:37:10.440 William Cheng: Okay, where you you know when you start running a bunch of 16.4 where you started your terminal and then you type PWD it will show you that your current working directory is going to be your he's going to be inside your home directory 260 00:37:11.520 --> 00:37:19.080 William Cheng: Okay, so the idea over here is that every process has a current working directory so that current working directory is stored inside the process control, blah. 261 00:37:19.710 --> 00:37:27.300 William Cheng: Okay, you probably see that already in your current one right corner wines that prosecute roadblock there other stuff in that one of them is called PWD over here. So that's 262 00:37:27.570 --> 00:37:34.080 William Cheng: The that's going to be your current working directory. Okay, so when you type ls over here. So when you have LS 263 00:37:34.800 --> 00:37:45.000 William Cheng: That, well, if you just have LS, you need to say I want to list the directory content of a directory. So in this guy is if I don't say anything, you will listen to the directory content of the current working directory 264 00:37:45.810 --> 00:37:54.330 William Cheng: Okay, so also the UNIX command. If you don't say anything. You're implying that you want to do something to current working directory. So when you talk to Alice. Over here, what he will do is that it will go to the current working directory. So again, 265 00:37:54.540 --> 00:38:04.290 William Cheng: Go to the current working directory. It's a directory. I know you open it up and you list all the directory entries over here. All this other component there, right. So that's the, that's the purpose of the ls command, then 266 00:38:06.030 --> 00:38:12.450 William Cheng: You can also, you know, Chase directory. Right. So you're basically use the command called CD right when you say CD and he has a shared Ruben to 267 00:38:12.660 --> 00:38:16.500 William Cheng: You're changing your work working directory to dislodge been to 268 00:38:16.710 --> 00:38:22.830 William Cheng: The shareable been to the director of your so so so again that. So in that case, when he tried to, you know, execute a CD command over here. 269 00:38:22.950 --> 00:38:33.900 William Cheng: You're going to end up making a system call, will you make a system called you're logging shows and ago he started Colonel, we're going to change the working directory to a new directory and now instead of Colonel, we're going to change the the working directory so now 270 00:38:34.200 --> 00:38:39.390 William Cheng: You know you're logging shall process is going to have a different current working directory now. 271 00:38:40.260 --> 00:38:44.340 William Cheng: Alright, so welcome. Glad to have you has maintained inside the kernel for every process. 272 00:38:44.910 --> 00:38:51.360 William Cheng: The other thing that you can do that whenever you try to open a file. So let's try to open a file, right, so I should open a file fruit I see over here. 273 00:38:52.080 --> 00:38:57.870 William Cheng: That. So what so when you try to implement the open system call i which is what do you need to do in Colonel to, well, you 274 00:38:58.170 --> 00:39:07.680 William Cheng: Know you need to take the file system part over here and look at the first card character if the first character over here is a slash character. Well, then you know where to go, you go to the root of the file system, right, because that will be 275 00:39:08.190 --> 00:39:15.420 William Cheng: Though you know as absolute path. You start from the root of the file system hierarchy. And then you start, you know, using path of resolution to try to 276 00:39:16.080 --> 00:39:24.630 William Cheng: Try to see if you can find this file. Okay. If the first character is now the slash character, then you are using relative you're using relative naming 277 00:39:25.080 --> 00:39:28.800 William Cheng: Okay, you're trying to open this file inside your current working directory 278 00:39:29.760 --> 00:39:36.060 William Cheng: Okay, so your current working directory is already your home search BC, one in this case you can go to your homepage BC and then you try to look for 279 00:39:36.270 --> 00:39:43.440 William Cheng: You know, food. I see. So, therefore, you know, in the inside your process control blah, you're going to remember where you are right. So this way when you try to open a file. 280 00:39:43.620 --> 00:39:46.830 William Cheng: Relative to your current working directory. This will be done very, very fast. 281 00:39:47.040 --> 00:39:56.400 William Cheng: Right, because your home directory might be 100 level D from the root directory. But once you're in your home directory over here, then all your searches over here will be done locally and that can be done a lot faster. 282 00:39:57.120 --> 00:40:07.380 William Cheng: Okay, because you don't really want to go to the root of your hierarchy was a path and resolutions for every so well. So that's another way to improve the speed over here is by using your current working directory. Now, and also 283 00:40:08.190 --> 00:40:15.180 William Cheng: If you look at your make file, right. You may fall over here says, you know, when I try to compile warm up to any warm up to Darcy, I need CSV file to 284 00:40:15.660 --> 00:40:26.250 William Cheng: See all these guys sorry my forward to list. I see over here, all those files are in the current working directory there. So when you try to open, you go, you can also open something like, you know, say, you know, you know, 285 00:40:27.450 --> 00:40:37.440 William Cheng: A warm up on number one food. I see over here. I, something like that. So again, since the first character over here is not slash you're going to perform path and resolution, starting with your kernel current working directory 286 00:40:37.620 --> 00:40:42.840 William Cheng: And then you got to open warm up one and then you can continue the path of resolution until you find food RC. 287 00:40:43.620 --> 00:40:51.900 William Cheng: Okay. You can also you know even do something even more crazy right as they open. Right. Okay. So over here, warm up one slash dot dot 288 00:40:52.320 --> 00:40:56.760 William Cheng: Dot, dot slash, you know, warm up to, or something like that, whatever the path is 289 00:40:57.000 --> 00:41:05.310 William Cheng: That's it again. How do you do a path to resolution. Right. So this one is that you start with your current working directory you try to see if w one w one is going to be a component name. 290 00:41:05.520 --> 00:41:17.910 William Cheng: And you verify that it's a directory and then when you go inside over here. The next component is da da da da da. While me data, we noticed the parent directory. But we also know that inside this directory. One of the component names data. 291 00:41:19.050 --> 00:41:21.660 William Cheng: Okay, so therefore the data over here is just a component name and 292 00:41:21.900 --> 00:41:28.080 William Cheng: By accessing this component day, you're going to get the I know for the parent directory right over here. We're going to end up with the same directory that we start with 293 00:41:28.290 --> 00:41:36.360 William Cheng: And then if we do that again. We're going to go to the parent directory of my working directory or of our current working directory and then we're going to look for w two in the parent directory 294 00:41:37.560 --> 00:41:42.180 William Cheng: Okay, so you can also say, you know, I can also say everyone slash das. Das 295 00:41:42.570 --> 00:41:52.260 William Cheng: Das okay the data self reference. Oh yeah, you go to your same I know you go to your same I know again they go through the parent. I know. And then there's a parallel directory called WSU. So all these things times over here. They're all valid. 296 00:41:53.430 --> 00:42:00.870 William Cheng: Right. So by using the working directly over here. It's going to make your life a lot easier because you only do local searches where you are starting with a working directory that 297 00:42:01.260 --> 00:42:10.830 William Cheng: Alright, so if you need to know what your current working directory is right. So for example, if the login show somebody type PWD over here. How does the logging shower know what's the current working directory 298 00:42:11.070 --> 00:42:17.790 William Cheng: While it's going to make a system calls and this guy is gonna. This is of course called guess cwt. It turns out a copy the system kernel use the 299 00:42:19.470 --> 00:42:24.480 William Cheng: working directory in the process control blah, and then he will return to you what the current working directory and he will print onto the screen. 300 00:42:24.810 --> 00:42:37.410 William Cheng: There, if you want to change the working directory you call change dirt system call that also you can do the same thing your commercial, you can say CD, followed by an argument over here like that because I CD dot dot slash W two over here. 301 00:42:38.040 --> 00:42:47.070 William Cheng: Mindset. Again, it will do exactly the same thing, he will make the change their system call and take this as an argument. And now you let it go inside a car note will change are working directory to the new director over here. 302 00:42:47.970 --> 00:42:55.740 William Cheng: That's what he called the all these options over here changed their can fail if it turns out to be invalid directories. Okay, you should always check the rich uncle. Yeah. 303 00:42:57.180 --> 00:42:59.550 William Cheng: Alright so that is the idea of working directory 304 00:43:01.080 --> 00:43:06.000 William Cheng: So now you have everything you need to know to complete Colonel to okay 305 00:43:06.330 --> 00:43:16.500 William Cheng: Good. I mean, I know we're still in current one over here, but now you know how do you implement the virtual file system, or I mean what are they, you don't know. You need to look up the UNIX man pages and then find out what kind of kind of call you up to right 306 00:43:16.770 --> 00:43:21.420 William Cheng: There so so I've been incredible to there will be some function you have never heard of. Right. 307 00:43:21.660 --> 00:43:26.490 William Cheng: I briefly mentioned there something I do too, or something like that. There are other function function there are similar. 308 00:43:26.730 --> 00:43:38.250 William Cheng: So if you're not familiar with the function. Look at the Linux men page. Okay, I see what you're supposed to do. Okay. But please keep in mind that your job is to to get 100% of the score in your kernel assignment. 309 00:43:39.120 --> 00:43:48.930 William Cheng: Okay. Your job is not to implement the Linux men page. Okay, so if you're in the point of the entire Linux men pay, you're not going to get any extra credit because the highest score you can get is 100 points. 310 00:43:49.830 --> 00:43:56.190 William Cheng: Okay, so please understand, what is your assignment. Okay, so your assignment. Yeah. What is our requirement, our requirement is our Colonel spec. 311 00:43:56.490 --> 00:44:03.210 William Cheng: And the grading nine. So, but if the greater recruiting and I and you get 100% of the score, then that's all you need to do. 312 00:44:03.630 --> 00:44:11.250 William Cheng: Don't write anything more than that. OK. So again, redid Linux man page as a guide. Okay, but don't implement everything inside of Linnaeus fan page. 313 00:44:11.850 --> 00:44:17.370 William Cheng: And also, you know, in Colonel team. We're going to start seeing these things in the comment blog right about the function 314 00:44:17.670 --> 00:44:26.310 William Cheng: You know, again, the comment block come from Brown University, it will say that you have to implement a, b, c, d over here. Okay. But do you have to implement a, b, c, d. 315 00:44:27.270 --> 00:44:34.620 William Cheng: Okay, the answer is no, because if you only implement a and d. And then when we run the grading guidelines, you get a perfect score. Do you have to implement BSE. 316 00:44:35.100 --> 00:44:40.380 William Cheng: Well, no, right, because PNC they are the requirement for Brown University there. Another requirement for us. 317 00:44:40.650 --> 00:44:46.440 William Cheng: Okay, I always get all kinds of you pushing to say, oh, the content blocks that we have to implement this. Do we have to implement as well. So again, 318 00:44:46.830 --> 00:44:54.900 William Cheng: You know, run through the grading guidelines if you if your work if you call work perfectly without implementing that then you don't have to implement it. Okay, what if you want to implement it. 319 00:44:55.530 --> 00:45:05.250 William Cheng: Okay, if you want to implement it get you have to demonstrate to the greater that this code is useful if the code is now useful, the greater will have to deduct points. So again, this is called self checks. 320 00:45:05.730 --> 00:45:18.240 William Cheng: Okay, so if you if you write a special code to take care of the condition that's not required in the grading guidelines, what day you have to introduce additional tests. Okay, in order for you to execute those code they are implemented are useless. 321 00:45:19.620 --> 00:45:29.670 William Cheng: Okay, so why do you want to write new code to to test useless Co. OK, so my recommendation always that if you if you're going to write code that's useless. Make sure you delete all this code before you make a submission 322 00:45:30.450 --> 00:45:37.080 William Cheng: Okay, so this way you don't have to write. I mean, it's because some people with away. Want to do is that they want to write useless code and they want us not to deduct points. 323 00:45:37.320 --> 00:45:42.420 William Cheng: Okay. Is there any way for us not to deduct points. There's no way because the greater has to follow the grading guidelines. 324 00:45:43.470 --> 00:45:49.800 William Cheng: Alright, so even if he asked her special permission not to, you know, to leave junkies at your current. Oh, we have to we have to say no. Right. 325 00:45:50.550 --> 00:45:53.580 William Cheng: Alright, so as I briefly mentioned a while to the museums and Colonel to 326 00:45:54.210 --> 00:45:58.590 William Cheng: Cause one is referenced candy. We saw inside of fallout Jed, there's a reference count over here. 327 00:45:58.860 --> 00:46:07.590 William Cheng: What you need to understand is that, you know, it's not as easy as it sounds like the basic concept of a reference counting is very, very simple. I have an object with the reference count. Well, because it has a rough count. 328 00:46:08.190 --> 00:46:16.380 William Cheng: Count over. Yeah, that it counts the number of point to that points to it. Right. So if I have three pointer pointing out what's up the rough out there should be equal to see. It's that simple. 329 00:46:17.460 --> 00:46:22.650 William Cheng: Okay. What if I remove one of the pointer over here, right. If I remove one of the pointer. Then you got him here. The colonel. 330 00:46:22.800 --> 00:46:31.680 William Cheng: You got to make sure your document reference, kind of, ego, ego. The two and also you need to check if is equal to zero is equal to zero, that means that nobody's putting into this object. So, therefore, you have to free the object. 331 00:46:32.460 --> 00:46:40.590 William Cheng: Okay. Otherwise, if there are still two things, pointing to it and somebody else. Remove another point. So this one go down to why, when the last guy over here, remove this point, you have to change those zero 332 00:46:40.830 --> 00:46:47.400 William Cheng: At the time when you change to a zero day you know that nobody is pointing to this. So, therefore, you need to free up this object, otherwise you're going to end up with 333 00:46:48.420 --> 00:46:56.820 William Cheng: The leak insider insider, Colonel. Okay, so some of the kernel memory leak is going to be okay. Some of the kernel memory is not okay, you're gonna end up losing points. 334 00:46:57.570 --> 00:47:05.670 William Cheng: Okay, so. So again, we need to run your code radio Colonel read the printer very, very carefully. If it says, you're going to lose a lot of points. One thing that gives you should fix your box. 335 00:47:07.290 --> 00:47:13.110 William Cheng: Okay, so, so the reference on over here. So if you have a reference coming back over here. So, for example, let me draw this picture again. Right. 336 00:47:13.320 --> 00:47:19.770 William Cheng: Okay, so that's it. I have three pointer pointing to that over here. Okay. If the revenues got over here it says equal to two. Well, what kind of problem. 337 00:47:20.400 --> 00:47:28.920 William Cheng: Am I going to get right. Whenever we were one of the point over here is going to be. It's going to go down to why whatever you another point over here is going to go to zero. And then this object will get freed up 338 00:47:29.430 --> 00:47:36.390 William Cheng: Okay, we have another Colonel, throw it over your school funding this idea. OK, so now the other Colonel fed over here will be pointing to garbage. 339 00:47:36.900 --> 00:47:41.340 William Cheng: Okay, so even though when you start to look at this. Oh, it's not garbage yet, but it can turn to garbage and anytime 340 00:47:41.520 --> 00:47:46.230 William Cheng: Anytime when you give up the CPU another third start running it will start writing into this memory location or beer. 341 00:47:46.410 --> 00:47:59.040 William Cheng: Or maybe it will call the memory alligator to reallocate this data structure and now putting completely different data on it and then put a pointer on it. Okay, but you still think that this object was the previous version of the object. So therefore, your code will be totally broken 342 00:48:00.210 --> 00:48:04.170 William Cheng: Okay, so what do we call this kind of bug or we call it memory corruption bugs. 343 00:48:04.830 --> 00:48:13.890 William Cheng: Right, right. Because, you know, you have the reference can go go to zero. And now somebody else and other kernel fair will start writing into these memory location and now the memory has been corrupted. 344 00:48:14.400 --> 00:48:22.470 William Cheng: Okay, so to get corrupted by your code because you don't you have a reference County, but that was the only reference object right this object has three pointer over here, I've 345 00:48:23.100 --> 00:48:32.070 William Cheng: Got over here is for when I remove all these three pointer over here the reference car is why. So this is, you know, this optical never go away. Okay, so that my career problem, you know, your current assignment. 346 00:48:33.120 --> 00:48:36.480 William Cheng: Okay, so, so it's your job to make sure that the reference count is always correct 347 00:48:36.870 --> 00:48:46.410 William Cheng: That. So if you're a discipline, every time, will you have a point of point to a object as a reference call to increment the reference calm and every time we remove the pointer that then in that case you 348 00:48:47.130 --> 00:48:54.810 William Cheng: Okay. So one interesting also one sort of common problem is that what if you use a local variable at the point of this object over here. Okay. So in this case, you know, 349 00:48:55.440 --> 00:49:04.080 William Cheng: So, so again, let's create an object over here has to reference cut over here. So now you create a local grab what their findings optical via you need to increase the reference count of three. So when the 350 00:49:04.290 --> 00:49:07.680 William Cheng: What the function return when the function returns the local variables going to disappear. 351 00:49:08.670 --> 00:49:11.790 William Cheng: Okay. So, therefore, you have to remember to detriment to to 352 00:49:11.970 --> 00:49:19.050 William Cheng: You're going to realize that I have a local variable be here. I pointed out. Yeah, so I'm the one that will increment the reference count. So if you implement the reference is that 353 00:49:19.230 --> 00:49:25.950 William Cheng: The function because you use a local variable to point out. Yeah. Now, when the function returns, it's your job to make sure you document the records. 354 00:49:27.180 --> 00:49:36.840 William Cheng: Because otherwise, the number as soon as you return for our function to local variable disappear. So this point to automatically disappear and local grabber or local variable on know is automatic variable. 355 00:49:37.470 --> 00:49:44.160 William Cheng: Okay. So, therefore, you have to take care of the reference count otherwise going to end up with inconsistent count for, you know, for, for the reference count for this object. 356 00:49:44.790 --> 00:49:50.580 William Cheng: Okay, and then you know either either you're going to be over reference on the reference on the end either case can be routed 357 00:49:51.660 --> 00:50:00.270 William Cheng: Right. The second new thing and Colonel to over here is I'm going to incur no one. There's no polymorphous them and then this guy, what does he see plus five polymorphous then 358 00:50:00.600 --> 00:50:03.990 William Cheng: Implementing see right so with the place. Are you going to see this is that 359 00:50:04.470 --> 00:50:10.560 William Cheng: You know, inside the virtual POS system over here. Right. Are they are the virtual process that needs to be made into a DFS independent 360 00:50:10.950 --> 00:50:14.310 William Cheng: Okay so incredible to there will be using the run versus them. 361 00:50:14.490 --> 00:50:21.450 William Cheng: In Colonel three, there were switching the system five hours is there. So if there's any imperfection that you have implemented as soon as we go to Colonel three 362 00:50:21.630 --> 00:50:26.490 William Cheng: You know, even though your program will work perfectly in Colonel to also Chicago three and nine going to end up with 363 00:50:26.880 --> 00:50:33.060 William Cheng: Was about because you can only work with the referral system, but cannot work with the day after the system, follow us as 364 00:50:33.570 --> 00:50:43.290 William Cheng: Well, so what does a real difference between the ranch houses and this isn't my boss. Is that right, the reinforces that everything is done in memory in the system for us is that there's actually a disk inside your operating system. 365 00:50:44.130 --> 00:50:54.420 William Cheng: OK, so the difference between the memory and this is that the this is very, very slow. So whenever you try to start an operation on the desk, your, your, your, your kernel or have to go to sleep in the I O que 366 00:50:55.140 --> 00:51:02.520 William Cheng: OK, and now you will give up a CPA or giving us up to somebody else, right, so before I was mentioning, another Colonel, so why should get a CPU, what now you know why. 367 00:51:02.700 --> 00:51:10.410 William Cheng: Because I go sleep inside IQ than the others will get the CPU and then he will reallocate memory and then it'll cause memory corruption, but all kinds of trouble, you have 368 00:51:11.340 --> 00:51:18.690 William Cheng: Okay. But, but, you know, incredible to there's no disk, right. So, therefore, when you when you make a file system call they will return right away. 369 00:51:19.530 --> 00:51:26.580 William Cheng: Okay. Because, because this case we don't have to wait for the day. So your kernel. So it doesn't go to sleep. So therefore, there's going to be less reference counting bug you know 370 00:51:26.880 --> 00:51:34.470 William Cheng: That Colonel three. But as soon as you close. There's a code or three and you start using a fastest and as a real this then you will expose some of the reference counting bug that you haven't carnal to 371 00:51:35.730 --> 00:51:38.580 William Cheng: Write because. But otherwise, you know, the c++ polymorphous them. 372 00:51:38.820 --> 00:51:47.670 William Cheng: All that means is that when you make function call, you need to make an indirect call through and an array of function pointer. So all you need to do is to find out you whether you should use a re index number one. Are you ready. Yes. Number two. 373 00:51:47.850 --> 00:51:55.380 William Cheng: So, what you should do is that you should read the code for the actual bosses and inside your kernel to you actually get the entire source code for the emphasis that 374 00:51:55.770 --> 00:52:01.620 William Cheng: Because remember, this isn't for viruses, then the solution was implemented at Brown University people so you don't have the source code. 375 00:52:01.890 --> 00:52:08.940 William Cheng: But you have to run file system source code. So when you're doing your kernel to do yourself a favor and read every line of source code in the rampart sister. 376 00:52:09.780 --> 00:52:13.500 William Cheng: Okay, the ramp classism only like 400 lines of code. So it's not very, very big 377 00:52:14.130 --> 00:52:21.090 William Cheng: Okay, so you should try to understand what the rainforest. Is that look like because later on when you go to Colonel three the system for versus them you don't have the source code. But what does it look like 378 00:52:21.360 --> 00:52:27.510 William Cheng: It looks just like the Rand Paul says me except that there's a disconnect. So therefore, when your kernel thread needs to perform this operation. 379 00:52:27.660 --> 00:52:41.250 William Cheng: Your kernel to I will fall asleep and later on. Instead, interrupt service routine, you will got Olga. Olga. Olga woken up when he wakes up, he will return from the disk operation. Right. Right. And also, you know, we didn't Colonel to make sure you read the colonel to FAQ. Yeah. 380 00:52:42.900 --> 00:52:51.030 William Cheng: So this is a good point to break. So next time we're gonna, you know, finished chapter one and look at access protection. So there's some additional topics we need to cop to cover. Okay.