‫Hello and welcome in in this lecture, we're going to start implementing the Fat 16 file system, which
‫will obviously use this call filesystem functionality that we made last time.
‫So in the first directory in your source directory, create a new folder and we're going to call it
‫fat.
‫Inside this directory, create a new file called Fat 16 Dot Hajj.
‫We're now going to populate the header.
‫We're going to have a fat 16 init function that will initialize the fat 16 filesystem and rather than
‫return a type of void, we want to return a type of struct filesystem.
‫OK, we're going to include file dot here.
‫We're now going to create a new file called Fat 16 dot C Fat 16 dot C will include the file fat 16 dot
‫org.
‫And now we're going to implement the fat 16 init function
‫for now over 10 zero above the fat 16 and it function.
‫We're going to create a new structure.
‫Colford, 16, EFS, and this will be equal.
‫So this structure here.
‫We now go to filesystem, we can see the resolve and open functions here, so I just copy these function
‫points and I'm just going to post them here for now just so I can see the prototypes.
‫So under 16 in it, we're going to define our resolve function so that returns integer.
‫I'm going to call it Fat 16 resolve and it upsets the desk because that's what the Function Point prototype
‫says for our first result function.
‫We're just going to return minus seow, which means that it doesn't belong to us, or there was an error
‫or something like that.
‫And we're going to include status nuthatch.
‫And now down here we're going to go resolve equals five 16 resolved and we're going to copy and paste
‫this function definition up here.
‫And we don't need the semicolon by here, guys.
‫OK, if we now look at the open function, we see the percepts, a disk, a path part and a mode.
‫So if we just copy that and we're now going to implement that, so we're going to go void because this
‫returns void pointer that's 16 open and we're going to paste in those variables as defined in the function
‫pointer prototype.
‫And we're just going to return null pointer, which will mean that we fail to open the file.
‫We're now going to get rid of these because we don't need them anymore.
‫We're going to copy and paste the prototype of 16 open and paste it here because we are accessing it
‫in this structure right now.
‫We're going to go comma, dot open because fat 16 open.
‫OK, so we look at the prototype for Streckfuss and again, we can see there's a name here that absorbs
‫20 bytes.
‫So we're going to include string that to the top here, include string, string, nuthatch.
‫And we haven't created string copy function yet, but we're going to need to create that because we're
‫about to copy in the Fat 16 name into this name variable here.
‫So in our fat 16 in it, we're going to go string copy Fat 16, F-stop name Fat 16, OK.
‫And now we need to actually implement that string copy function.
‫So let's start implementing string copy function.
‫If we go to string that C and we're just going to go Charr string copy char dast destination constant
‫source and we're just going to go.
‫While source does not equal zero dast equals source and then we're just going to go source plus equals
‫one just like that.
‫And that should be enough.
‫And then we just hear we just return 10 and we're just going to go at the very top and we're going to
‫go chaar ten people's desks.
‫And here we're going to go, death plus equals one as well, so that should work absolutely fine for
‫us, right?
‫You can rename this to something more appropriate if you want such a result.
‫As a matter of fact, yes.
‫Let's rename it to rest for result.
‫And there we are.
‫There's our string copy now.
‫Now, before we continue, let's just check that that string copy works.
‫If we could kind of see here and you'll see we did all this just stream stuff from previous lecture.
‫You can remove that.
‫We're just going to go chop off 20 string copy buff.
‫Hello, exclamation mark.
‫We now include
‫string string that Hage.
‫OK, and we go make clean bill that I search and see it says in uplinked declaration, and that's because
‫it's not in the header files to go back to the source file here.
‫Copy and paste it in the head of file of string dot org.
‫Won't try that again.
‫OK, I'm just going to quickly attach GDB.
‫And I'm just showing you guys this in the recording to get you into the habit of testing what you're
‫doing because you'll make a mistake if you don't, I'm telling you.
‫So I'm going to break on Colonel Daudzai line 99 and I continue.
‫Oh, wait, target remote kumu, system x 86.
‫No, no, no system.
‫I create six dash Ajda dot forward slash showstopping.
‫That's capitalist's jatt dash gdb studio.
‫We now continue.
‫We can see we've hit the break point.
‫We print buff, we see hello explanation mark with a null terminator so we can see that the string copy
‫is actually working.
‫But now if we go back to string dot hedge string dot see I mean there is one thing missing from this
‫implementation, one tiny thing, and that is we need to spend another Terminator by here on the destination.
‫Because if you look here we go.
‫Source plus equals one, death plus equals one.
‫So now if the source is equal to zero, then we need to set the final byte on the destination to zero
‫as well, because otherwise we're going to have we could end up in a situation where the string doesn't
‫get null terminated.
‫So that is also very important.
‫And we can focus on implementing string and copy and at another time and that will basically ensure
‫that it's copying in bounds.
‫And we don't overflow buffers, but string copies perfectly appropriate for what we are doing.
‫In fact, 16 dot c.
‫OK, so now we've implemented string copy.
‫We can now continue to go to Fat 16 dot C, we now have string copy Fat 16, F-stop named Fat 16.
‫That's absolutely fine.
‫And here we're going to return the address of Fat 16 Neff's.
‫OK, excellent.
‫And you'll see here we return minus EIO.
‫If we go back to Father C. and we look for FDR's resolve, you can see what happens here.
‫It says that if if this resolve function return zero, then they are saying that this filesystem driver,
‫basically fat 16 driver in our case, is responsible for managing the deaths.
‫So because we return minus Scio, we are not responsible for this.
‫However, if we return zero here, we will be binded to the desk.
‫OK, so that's an important thing to note.
‫OK, so let's go to file dot C and we scroll up.
‫We can see we've commented this out.
‫We now need to uncover this.
‫So what we're saying here is insert the fat 16 filesystem because fat 16 in it will return its implementation
‫here, fat 16 FS, which has function pointers to its resolve and open functions.
‫OK, so open is for opening files.
‫Remember guys, resolve is four, binding it to the desk, binding the file system to the desk, the
‫file system, Driveclub.
‫So when you come at that, that is great.
‫That's exactly what we wanted.
‫OK, so let's go to build and EFS and in here we're going to create a new folder called Fax.
‫OK, so we're now going to go to file dot C and we're just going to include Fatfat 16 Dot Hage, OK?
‫And that will ensure that this in this fat 16 in it can be resolved if we now go to our makefile and
‫get a copy and paste file.
‫Dotto here this file, although I'm going to go this fat fat 16 Dotto EFS Fat Fat 16 dot c.
‫And here we go, I saw first we need this because we include Father H, right, but we also need our
‫own so do Dashi dodge sauce fat.
‫And that's absolutely fine.
‫Now here do Dopp forward slash source FS Fat, Fat, 16 doxy.
‫And here we're going to go build EFS Fat Fat 16 Dotto and we just copy and paste this here at the very
‫top of the file and we're just going to go make clean bill that S.H. you see that works absolutely fine.
‫So if we now go to Canada, let's see, we need to actually call the function here.
‫OK, so if we scroll up, we're going to include and we've included string twice here, guys.
‫We can remove that other one.
‫We're going to include AIFS file, dot hate.
‫OK, scroll down.
‫And just after we enable the heap, we're going to initialize the filesystems.
‫So if we go into file that page, we see EFS in it.
‫So we're going to call this function EFS and it initialize filesystems.
‫OK, so that's important to do that.
‫And we're going to make clean Bill DSHEA now we can see that works fine and now you're going to start
‫to see some magic.
‫So if we go CDPR in GDP at symbol file, dot up backslash col, we'll build colorful dot Xerox one,
‫one, two, three, four, five.
‫You know the drill target remotes kumu system three eight six dash Ajda subindex capitalist DSTO.
‫OK, and now to break fat sixteen resolve and I'm just going to press C and look at that.
‫It's called resolver function and we're about to return an error signifying that this file system is
‫not us.
‫And just to demonstrate what's happening, we initialize the file systems.
‫So we go to Air Force in it.
‫This calls Xolo, which calls for static load, and then we insert the fat sixteen file system here
‫because Fat Sixteen in it returns its file implementation here, which has function pointis here pointing
‫to resolve and open.
‫OK, so that explains that bit.
‫If we go back to Canada at C we can Nancy, we do this search and in it now this searching in it just
‫creates one primary disk and we go desktop file system because our first resolve ampersand desk, the
‫address of desk, so that calls FS resolve and FS resolve loops through all of our insert file systems
‫and it looks for the one that returns zero because the one that returns zero is confirming that he can
‫manage this disk because this disk has his file system on it.
‫That's what's happening here because we were Termina CIO.
‫The FS resolve never resolved the file system for this disk.
‫So unfortunately that means that this disk will never, ever have a file system.
‫And just to demonstrate this, if we do see to continue and then we do control C to break again, we
‫can see we're now on the final loop in Canada at see we now go print disked zero VAT returns our disk,
‫so we go asterisk here.
‫We can see the file system is zero because it couldn't resolve a file system.
‫So in fact sixteen dots.
‫See if we now return minus Scio to zero.
‫If we now change this to server 10 zero, we are confirming that we can manage that disk because that
‫disk has our file system on there.
‫And now if we recompile this and run this again, it will bind the disk to Fat Sixteen, which I'll
‫now show you.
‫So we're going to go control D to exit out of this close kumu and we're going to go make a clean bill
‫that S.H..
‫Sidibé in GDP, add single file builds kind of 4.0 Xerox one one, two, three, four, five.
‫Target promotes QMI System by three eight six dash ahj stop and dash capital s gdb studio.
‫And now we're going to break on Fat 16 resolve once again when to do continue.
‫OK, and now we can see we're here now we're about 10 zero now we're going to proceed to continue again
‫press control see to pause the emulator again and then we're going to go print diskettes zero.
‫Let's see that returns the address.
‫Use an asterisk here.
‫And now look at that.
‫We can see that this zero is binded to this file system.
‫So if we now go file system here, you can see this is just like working in C, you can you can write
‫basically C code in this debugging.
‫So we're going to go file system here, right.
‫Asterisk at the start because we want to give you everything, press enter.
‫And now look at that.
‫We can see that the primary disk, just zero, is bind it to the fat sixteen file system so we can see
‫there's the pointer to the open function.
‫There's the point, it's the result function and there's fat sixteen.
‫So you can see how that works.
‫If you look in the presentation that I recently did, you you will see how that's working.
‫Right, because I show you diagrams.
‫So what's going to happen now is, is whenever someone does an F open, uh, we have the disk.
‫No, OK, we resolve the absolute path and then we have the disk.
‫No drive.
‫No, I should say because we have the drive.
‫No, we know which drive to do diskette on because we just did this get in the debugger just now.
‫So you know exactly what that looks like.
‫So in our case, just zero and I just zero has a file system variable.
‫So we know which prototype, which files is implementation that we need to talk with.
‫So the upper layers of the VFW's has no idea about five sixteen NTFS.
‫It just knows they share the same interface.
‫So that's how that works.
‫And this this implementation allows for an infinite amount of filesystems.
‫So I hope that makes sense.
‫And as we keep going through now, we're going to implement open, we're going to implement, read and
‫so on.
‫Now, what's the fact sixteen file system is a simple implementation.
‫It can get very difficult.
‫So just bear that in mind and look back to the presentation I made on this if you need to.
‫So bear with it because we're going to be writing over five hundred lines of code to implement this
‫five sixteen.
‫It's not going to be the easiest task.
‫However, Fat Sixteen is one of the easiest file systems that exist, so it's appropriate for us to
‫use it.