‫Hello and welcome to this lecture.
‫In the last lecture, we talked about the virtual filesystem layer in this lecture, we are going to
‫begin implementing the virtual filesystem layer.
‫Let's start by creating a new file in the first directory in our source directory.
‫We're going to call this file file dot h.
‫This will represent a file in the system.
‫Let's begin writing the header file if and F file and scroll Hajj to find file and disgorge hash tag
‫and if.
‫Typedef unsigned added file seek mode, so we're creating the type for seeking now, you know, when
‫you seek from the beginning of the file to the end and all this sort of stuff, we're creating a type
‫for that now and now we're going to go in.
‫Sikh sects, Sikh current and Sikh, and so if you ever used the F seek function and C, you will be
‫very familiar with what we are doing here now and now we're going to create some function.
‫Pointers were going to go typedef void.
‫And this is a pointer, by the way, guys face and the skull open function.
‫And this is going to accept a desk and a path parts.
‫And a final note, which we are about to create.
‫Let's now create the foulmouthed so we're going to go typedef, unsigned and it foulmouthed inam foulmouthed,
‫read, foulmouthed, writes, foulmouthed, appends foulmouthed invalid's.
‫So these are just different states for the for the particular foulmouthed.
‫OK, so essentially this is a function point to each of our filesystems will implement this function
‫pointer and pointed to its own function.
‫In this case the FS open function, its own internal aifs open function.
‫Now if someone goes to f open a file, it will pass the deskin that they're using and it'll pass the
‫path part, the topmost path part, and then it will pass the mode such as read, write, append and
‫so on.
‫You know, when you open you can pass RWA.
‫That's what this will be translated into.
‫OK, so we now need to forward declare our disk structure, so just do struct disk.
‫And this is important because we specify it here.
‫We now scroll to the top on line three.
‫We need to include poza dot org and that will resolve struct path, path and struct path route.
‫We now need to make a function points for our resolve function, so let's just go typedef in it s resolve
‫function struct desk desk.
‫So the fs resolve function point the implementor seyfarth 16 filesystem java for example, would be
‫required to point the FS result function to its internal fs resolve function and essentially all the
‫all the result function should do as it should take the desk and then return if it's valid or not.
‫So if it's able to process this file system or not.
‫So in other words, if it's fact 16, it will check the first sector of that desk and see if it has
‫a file allocation table header.
‫Now there is plenty more function.
‫Point is, we need to create such as read and write and seek and so on.
‫However, we aren't going to worry about that right now.
‫We're just going to create a new structure called file system.
‫OK, and this will have a FS resolve function and we'll call this resolve and it will have an open function
‫and we'll call this open.
‫So filesystem, I'm just writing a column for us.
‫Should return zero from resolve if the provided desk is using its file system.
‫So in other words, if that 16 reads the first sector of the desk and it says, yes, this is for us,
‫it will return zero from its resolve function and we're now going to have to name twenty.
‫So we'll just allow filesystems to have a name of twenty bytes.
‫So, you know, it can name itself like Fat 16, for example, NTFS will allow the filesystem driver
‫to name itself.
‫So each file system in our system will have one of these structures OK, and we will be able to communicate
‫with it through this structure.
‫It acts as a kind of interface.
‫But as you know, C is not object orientated.
‫However, this gives similar functionality by using these function points here.
‫OK, so we're now going to create a new structure called File Descriptor.
‫And we're going to have a descriptor index.
‫A filesystem
‫avoid points to private data for the file descriptor.
‫So just to let you know what that private data is, essentially when we do an open here on the Fat 16,
‫it's going to return some private data to us because we're basically the manager of the of all of the
‫filesystems.
‫Right.
‫It will return some fat 16 or whatever is NTFS will return the drive implementation now, not the format
‫will return private information.
‫And it will use this private information to locate which file we are talking about whenever the file
‫descriptor is passed to the to the FS, read function AIFS, write function, FSC and so on.
‫So this private data, we as the manager of all the filesystem don't care about it.
‫It's a very pointed to us.
‫However, the fact 16 NTFS, whatever filesystem driver we're creating, will be able to cast this back
‫into its private data structure later on when we pass the file descriptor to its right and read functions.
‫So yeah, we don't need to be aware of this, but we do need to store something here for the underlying
‫file systems.
‫OK, so finally we need to go struct desk desk and this is the desk that the files, the script should
‫be used on.
‫And I've spelt that wrong.
‫There we go.
‫OK, excellent.
‫So now we're going to create some functions here.
‫We're going to avoid FS in it.
‫Now, this is pretty straightforward, right?
‫It initializes the filesystems, OK, here we're going to have init f open.
‫That's going to take a construal file name and icons of mode's.
‫So we're now going to create a new function for inserting filesystems void EFS insert file system.
‫And this is just going to take a file system structure.
‫OK, great.
‫And we now want to implement our first resolve function.
‫So to do that just go struct file system FS resolve struct disk disk.
‫We're now going to create a new file called file dot C we're going to include file dot org.
‫Now we're going to go struct file system file systems, Peatross Max file systems.
‫So we just copy this definition here and we're going to go into our Faktor and we're going to to find
‫that.
‫So we're going to go define Peatross Max File systems and I think 12 filesystems maximum will be absolutely
‫fine.
‫We now need to include configured Hajj.
‫We're now going to go struct file descriptor file descriptors, chose max file descriptors.
‫Now a file descriptor is essentially an open file.
‫OK, so we copy and paste this definition into config w.h.
‫We're going to go define feature as max file descriptors and we're just going to do 512.
‫That should be enough for a small kernel.
‫We could probably do with it being a little larger, but for now this is absolutely fine sevak to file
‫that C and now that's implemented.
‫OK, so we're now going to create a function that will get us a free file system slot in our filesystems
‫array here, because this array basically represents every file system in the system.
‫It's an array of file system pointis.
‫OK, so what we're going to do to do that, we're going to go static struct file system and we're going
‫to ask riskier guys first, get free file system.
‫OK, in Schaikewitz zero four I equals zero I below PCOS max filesystems I plus plus if filesystems
‫I equals zero, which means that it's free because there's no point urana in our array return ampersand
‫get the address of filesystems I.
‫OK, so this will return the address of the empty slot in our array.
‫And because this is a multidimensional pointer, a double pointer here, we can then do something like
‫this, our first pointer, which will then set the correct filesystem in this array because we return
‫it.
‫OK, and then obviously at the bottom here, just return zero because that means there was no free filesystems
‫available.
‫OK, so now we're going to create our FSN filesystem function.
‫So just go void efs insert filesystem struck filesystem filesystem.
‫And we're just going to go struct filesystem AIFS as a multidimensional point of guys, if filesystem
‫equals zero, then we panic the system and we haven't created a function for panicking yet, have we?
‫So what we'll do is we'll just ignore it for now so we can give it up for now.
‫That's basically a safety mechanism.
‫We can prevent panic and let us just get rid of that if and we're going to go first equals aifs get
‫free filesystem.
‫OK, and that will return a free filesystem for us.
‫Now we're going to say efface.
‫Does not exist then, unfortunately, we fail to to insert this false system and here we would panic
‫the system as well.
‫But because we haven't had time to panic yet, we're just going to go print problem, inserting file
‫system and we're just going to have an infinite wallop here as well, guys.
‫OK, but we will we will panic at some point, guys, but not at the moment.
‫And just to let you know, all the panic is is basically a system message and then everything on the
‫whole system.
‫HULTS That's what a panic is.
‫Basically, this is kind of a panic here.
‫Who would have a separate function for this?
‫But we can get to that later on.
‫It's no big deal.
‫So here then we're going to go asterisk FS equals file system.
‫OK, so what this will do, this will get the file system, get a free file system here.
‫So let's say returns index or in the filesystems array of returns, the address of that.
‫Yeah.
‫And then we go asterisk FS equals file system.
‫So that basically says, OK, let's set the value in the array that they in the array element that they
‫return to us to the address of the file system provided.
‫So basically fills an entry in this file array.
‫OK, so that's what this is doing.
‫So as you probably gathered the inserting file system function simply is there to allow drivers to insert
‫their own file systems.
‫So so they might be, for example, NTFS driver.
‫It will insert itself.
‫Into the filesystems array right here, using the offensive file, filesystem function, and then the
‫system will be able to talk with it.
‫OK, so we're now going to create a new function called static void AIFS static load.
‫And this will basically load static files systems.
‫What do I mean?
‫When I say static, I mean filesystems that are built into the core kernel, not ones that are dynamically
‫loaded.
‫OK, so now we're going to go first insert filesystem and here we're just going to go for 16 in it.
‫Now we haven't created that function yet, so we're just going to comment this line out for later.
‫But we will need it.
‫And we're now going to create a new function called Void AIFS Load.
‫And as you probably gathered, this will load all the available file systems that we are aware of.
‫So we go, Mmm said filesystems and we'll notice the mem said is an implement it guys.
‫So we need to include the head of how we're going to go, include memory, memory H.
‫OK, so just like that memory memory w.h.
‫So now down here when men setting it to zero and it's going to be the size of filesystems, the entire
‫ANAO here, we're just going to go for static load, which obviously loads the statically implemented
‫filesystems.
‫Now here we're going to create and it functions so we're going to go void FSN it and this initializes
‫the file system.
‫OK, so we're going to go memsahib file descriptors
‫zero size of file descriptors nice and easy.
‫And now we're going to call our first load.
‫So as you can see, they call the initialize function.
‫We set our file descriptors.
‫We call Fasullo, which sets off filesystems, which call static load, which inserts our file systems.
‫Now, if I'm completely honest, we could even move this if you wanted into the FSN at this set.
‫But we'll keep it here because it's purely responsible for filesystems.
‫Although it may make more sense to be an added method, it'll stay there for now.
‫OK, so we have a lot of boilerplate that we need to solve before we can move forward.
‫So we're going to create a new function now that will create file descriptors for us.
‫OK, so we're going to create a new function then static it
‫file new to scripter struct file descriptor asterisk, asterisk descriptor out.
‫OK, so now we're going to go in it.
‫Redd's equals minus enum and we need to include the head of file for that guy.
‫So include status update.
‫OK.
‫Four inch equals zero, I blow your ass max file to Scripture's high plus plus if file descriptors I
‫equals zero and watch that typo that guy's.
‫Then struct file descriptor DGSE descriptor equals case ALAC, and we need to include the help for this
‫guy to scroll up, include memory, keep keep that.
‫So Casula lock size of struct file descriptor.
‫So we're basically creating a new file descriptor for these guys when they call this function OK.
‫And descriptors starts at one by the way, we don't want them starting to zero.
‫OK, so because of that we need to take that into account.
‫So we're going to go to Scripter Index equals I plus one.
‫OK, because I stouts zero.
‫We need a plus one here to commit to make one, making out the script to start up one.
‫So when I was going to go file descriptors I equals descriptor askaris just script out equals descriptor
‫grass equals zero.
‫Right.
‫And I was just going to return wrests down here.
‫So let me go over this and explain this to you now.
‫OK, so let's explain this function now.
‫First we set the responses in a memory.
‫Just as the default response, we now go in here and we loop through all the possible file descriptors,
‫so 512 we have.
‫And we say is the follow the script index equal to zero, and if it is, then we found a file descriptor
‫this free for us to use.
‫So we then allocate some memory for the file descriptor.
‫We set the index to the plus one.
‫I explained the reasons behind that.
‫We then set the file descriptors index.
‫To the descriptor here, we then pass a descriptor we made back to them and we set the response to zero,
‫meaning everything went OK and we break and then here we return the response.
‫This is how descriptors are made.
‫We now need to write some code that gets us the file descriptor based on index while based on ID, I
‫should say so.
‫To do that we go static struct file to scripter file, get descriptor in it F.T..
‫So in this case there F.T. needs to be a minimum of one and a maximum of the cost 30 to max file descriptors.
‫So what we say is we say if F.T. is below equals zero or F.T. is above or equal Pacho as max file descriptors
‫and they've passed us invalid information.
‫So we're just going to return zero, which is null, otherwise we're going to go in it.
‫Index equals five minus one and we minus one because descriptor started one.
‫OK, so scripture's start at one.
‫So calculating the array index is easy.
‫We just take the ID they provided as the F.T. and we minus one and then we have the index in the array
‫because that's how we made it.
‫We did a plus one here.
‫So now we do F.T. minus one here.
‫OK, now we just go over term file descriptors index and it really is as simple as that.
‫This allows them to pass us an idea of some kind of a file descriptor ID and we will return the correct
‫file descriptor for the ID they provided.
‫So the next step for us is to go to discharge Hajj and we're going to include AIFS file Hajj and here,
‫which is going to have a structure file system.
‫And this will be the file system that's binded to the disk because remember, we call the FS result
‫function, which we haven't created yet, by the way, which will resolve the correct file system for
‫us and set it in the disk by here.
‫So we're now going to create the FS resolve function.
‫So we just go back to file dot C and the file get script.
‫We're going to go struct file system FS resolve and we're going to pass in the disk here, OK, and
‫we're just going to go struct file system.
‫Force equals zero, and then we're just going to go for Insha I equals zero, I believe will equal Peatross
‫Max filesystems
‫and nopal are equal guys just below I plus plus.
‫And I we're going to say, if filesystems eye does not equal zero and filesystems I resolve desk equals
‫equals zero, then EFS equals filesystems.
‫I and then we're just going to break and then down here we're going to return aifs as simple as that.
‫So I'm going to explain this to you.
‫Here we loop through all of our file systems that have been loaded into the system using the insert
‫file system function.
‫We first ensure ensure that there is a file system there and it's not a appointer, if that's true,
‫then we call the result function in that file system structure.
‫Now, this is the internal function further down the result function of the internal file system driver.
‫So if I just go back to Father Heynckes, you can see this.
‫We have our results function here in the file system.
‫So as I've already said, our internal filesystems drivers will will create their own struct filesystem
‫structure and return that to us.
‫OK, and when they do that, we can call filesystems.
‫I resolve on them calling the result function lower in their code.
‫How do they pass that to us?
‫Simply by calling the FSN filesystem function and passing their own internal implementation to us.
‫So that's how the FS resolve function works.
‫Now let's just go back to our Hajj and we're going to take this other function that we created D.F.
‫Open, which we haven't implemented yet, and we're just going to put it down here, OK?
‫And it's just going to return to minus EIO, which means Iora, because we haven't implemented that
‫yet.
‫OK, now we go to this see you'll see in our discussion and a function we need to now set the filesystem.
‫So how do we do that?
‫We go disk filesystem equals aifs resolve and we pass the disk is as simple as that and obviously the
‫address of the disk, not the disk itself.
‫So that's how that'll work.
‫So as we come in here and initialize our very first disk, we call our first resolve, which will loop
‫through all of the file systems and it will then set the correct file system for us.
‫Now, as we don't have any filesystems inserted, this will mean our disk will have a no file system,
‫which means a file system couldn't be found.
‫But anyway, let's now add Father C to the Makefile.
‫So go to the Makefile.
‫Scroll down.
‫And you'll see what we've done FSP poza, just copy and paste that in here and we're going to CoLab
‫5.0 and that's going to compile files that see.
‫And falls out of the OK, so we now making clean that
‫and then you build that S.H..
‫We can see and define reference to AIFS resolve.
‫OK, that's OK if we go back to this start, see?
‫We can see Cole's efforts resolve.
‫We just navigate to that, we can see that here.
‫But it hasn't worked.
‫Why?
‫I know why go to the makefile, we also added at the very top here in the files.
‫So if we just search for people's data and right next to it at the very top here, careful not to delete
‫it, to build afast files.
‫Other if you now do build the research again and now we could see it tries to compile it, but we have
‫an imperfect declaration of print.
‫So just just include Colonel de Hage in Fold-out, see.
‫And if we now rebuild that again, we can see that compels absolutely fine.
‫So that concludes this lecture in the next few lectures will implement more of the filesystem will implement
‫fat 16 in the lower layers.
‫So what have we done today than a brief overview?
‫We've started to create the manager for the filesystems, the functionality in the kernel that manages
‫the filesystems.
‫So we've given them the ability to insert filesystems into the kernel.
‫We've given the ability for new file descriptors to be created and we've given the ability for us to
‫resolve.
‫Filesystems on a desk, so all very good stuff so far, systems, I hear, might be the structure created
‫by Fat 16 and then obviously we call Fat Sixteen's result function.
‫So that's what's going on.
‫But if you still confuse research about function pointers before going any further, because if you
‫don't understand those guys, you aren't going to understand the rest of this course.
‫So, yeah, I hope that makes sense.
‫Any questions?
‫Let me know.
‫Thank you.