‫Hello, everyone, and welcome to this lecture.
‫In this lecture, we're going to be implementing the fat 16 resolver function.
‫We scroll down to our empty fat 16 Resul function.
‫You'll notice that we just return zero to say that this desk belongs to us, that we should be managing
‫all file operations forward.
‫However, this might not always be the case.
‫We need to perform some checks here, read the first sector of the desk and ensure that it is actually
‫a fat 16 file system.
‫So we're going to be implementing that in this lecture.
‫So in fact, 16 resolve function.
‫I want you to go in.
‫Integrase equals zero return address.
‫That's what I want us to do here.
‫We're now going to go Struct Fat Privette.
‫Fat privates equals Casula, size of strut, fat private.
‫So here we're just initialise some private data that we will bring to our desk so that whenever it calls
‫us, we can access this private data and know exactly what's going on with the desk.
‫You know, we can store temporary information, we can cache things in memory.
‫We can do things like that by creating this private.
‫As you noticed, if we go to the private structure, we are storing the root directory in memory.
‫So this is kind of like cached in the way, you know, and we're also storing the the head of the disk
‫as well.
‫So we kind of cash that into memory, too, so we can store things like that in our private and it gets
‫bind to the desk.
‫So whenever there's an operation, you can see it passes the desk here.
‫We can access that private information.
‫OK, so that's what we're doing here.
‫We're initializing that private information.
‫So now we're going to fat 16 in it private.
‫Desk, fat, private, and we're now going to have to create this function, this init function, so
‫just about fat 16 resolve, we're going to go static void, fat 16 in it, private struct desk, desk,
‫struct fat, private, private.
‫I'm going to go set and we need to include that function.
‫Geisa scroll at the top and we're going to include memory, memory, dot Hage.
‫So back down here then mem set and we're going to pass in private.
‫We're going to want to write one byte that's zero and we're going to write that byte.
‫However many times is the size of the private data.
‫So that will completely zero out our private structure.
‫OK, well the memory and I, we're going to initialize some of our streams, so we're going to go private
‫to stream equals just stream new and we're going to provide the deciding desk.
‫And you can see there's no difficulty here, we just have filesystem sex sector size and type.
‫So that's OK.
‫We're going to actually create a guide and our dish structure then.
‫So just to decide here, OK, so if we just go to this stage and just above here, while just under
‫here, I guess we're going to go in it, Heidi.
‫The idea of the desk.
‫So in a better implementation of our desk system, we have an array of desks or whatever, and then
‫the idea would be the index in that array, if that makes sense.
‫And guys, while we're here, we're also going to have to add a voice pointer for the private data,
‫for the file system.
‫So we're going to go void's first data, the private Nofs private side.
‫So this is the private data of our file system because a file system can be binded to multiple desks.
‫Therefore, the first private should be in the structure of desk, not the structure file system, because
‫every desk is going to have different route directories.
‫It's going to have different file headers.
‫So that's why our private data is on the desk here and not in the file system structure.
‫So if we go to this starts C and just by here we're going to go that ID equals zero.
‫And obviously, like I said, and the better representation, we would essentially search an array for
‫a free index that we can use and then that would make an ID.
‫But because we're only focusing on one disk at the moment, we can just do it like this.
‫That's no problem at all.
‫So back to fat 16 dot C, then we can see ideas now resolved successfully.
‫So here we've created the class to read streams there so far and we still have more streams we need
‫to initialize.
‫So next we're going to implement the fat read stream.
‫This stream menu disk ID.
‫And we're going to implement the directory stream.
‫OK, and there we go.
‫Now, you guys, you created your own disk stream because you followed the costs.
‫So you understand what this this is doing then?
‫OK, essentially the disk stream allows us to bind it to a disk and then read however many bytes from
‫the disk we want.
‫We can eliminate having to read sectors.
‫Well, obviously on the lower levels, we're still reading the sectors, but it's abstracted out.
‫So the caller's view, in other words, where the caller here where initializing the disk stream.
‫So, yes, as you know, this stream reads here, this stream I read, it reads a sector into memory
‫and then offsets to the correct position.
‫So check that lecture if you're confused, because you guys did implement this.
‫OK, back to Fab 16 resolve.
‫OK, so here we're going to create a new disk stream and we're going to just use this just for this
‫resolve operation.
‫OK.
‫And we're going to say if the stream does not exist, in other words, if we fail to create a new stream
‫for this desk, then know go to out and we're going to make an out label here.
‫OK, if everything was fine, then we're going to read from the desk.
‫Well, read from this stream, I should say, into our private header.
‫And if that was not OK.
‫Then we're going to go REST's equals minus EIO go to ours.
‫OK, so at this point in time I suggest you find a fat 16 specification online, something you can compare
‫what we're doing to now.
‫Fortunately, finding the fastest specification is a lot harder than finding the Fab 32 specification.
‫So I have the factory to specification open here, but we are only implementing Fat 16 and I'm using
‫this purely for reference only.
‫OK, so now that I've said that, we can continue.
‫So the first thing we're going to do is we're going to check if the fat 16 signature is not present.
‫So to do that, we go if that private header.
‫Todd shed extend it had a dog signature does not equal zero x 29.
‫OK, and again, you can find these numbers in the fat manuals, so you should check that.
‫So you can understand then the responses, Eephus, not us.
‫And we're going to go to our.
‫So we're going to create this now, so if we go to state of Stazi.
‫And we can just add that definition here, so we go to find Eephus, not us five.
‫There we go.
‫Perfect.
‫So back to Fat 16 dot s..
‫So basically what's happening here is we're seeing the how do we load it here online?
‫Hundred and sixty.
‫Does it have a valid fat 16 signature?
‫If it doesn't, then we are not the ones responsible for handling whatever filesystem is on this disk.
‫So we return AIFS, not us, which means filesystem, not us.
‫OK, because remember, unless we return zero, our file system will not be binded to that disk.
‫OK.
‫So when are now going to load the root directory we have and create the function for this yet, but
‫we're going to write the code here anyway, so we go first 16, get root directory desk fact private
‫and percent fat, private root directory.
‫And I explained a little bit about what that root directly was in the presentation for Fat 16.
‫So you should definitely watch that file allocation table presentation lecture.
‫OK, so if that was not OK.
‫Then race equals minus CIO, go to about.
‫OK, so.
‫Let me just sum up for you guys.
‫So that is how it should look.
‫OK, we read the death stream, if it was an OK response, Zio go to our.
‫If the signature is not there, then it's not our fault system, if we fail to load the root directory,
‫then there's an error.
‫So we now need to create the fat 16 GETRUDE directory function.
‫So we're going to create that now.
‫So just by here, we're going to go in it.
‫Fat 16.
‫Getrude directory.
‫Struck desk desk.
‫Struck five private, five private.
‫Struct fat directory directory.
‫OK, so this is the out directory, this is where we're loading the root directory, too, by the way.
‫So we're going to end it Resko zero return address.
‫So in here, we're going to say struct fatheads.
‫Primary header equals ampersands, private header, primary header in it, root directory sector position
‫equals primary header fact copies multiplied by primary header sectors per fact plus primary had reserved
‫sectors.
‫OK, so that is the equation used to calculate the root directory position.
‫OK, so that'll give us the root directory position, the first sector.
‫So it's the fact copy's multiplied by the sectors Pathet plus the reserve sectors and that's the absolute
‫sector position on the desk of the root directory, the start of the root directory.
‫So now we're going to in it.
‫Root directory entries equals five private.
‫Had a primary, had to root directory entries, only specify the directory size, so we do in it root
‫directory size equals root directory entries multiplied by size of struct fat directory item.
‫OK, so if we look at our fat directory item, this is what that looks like.
‫As you know, we created the structures for this.
‫So the root directory size, basically, well, root directory contains what root directory items,
‫right?
‫I mean, fat directory items, not root directory items.
‫It contains fat directory items.
‫So the root directory size is the total entries multiplied by the size of each individual item.
‫So that makes complete sense.
‫So now we're going to go in it.
‫Total sectors equals root directory size, divided by disk sector size.
‫Now we need to go f root directory size.
‫Modulars desk set to size, then we must add one to the sectors, so why are we adding one sector here?
‫Well, we say the root directory size modulus, the sector size, and then here we go, sectors plus
‫equals one.
‫So let me explain that.
‫Let's say that the root directory size was around 600 bytes.
‫So if we divide that by 12, we only get one sector.
‫Now we know 600 bytes exceeds one sector.
‫It does.
‫So if we do 600 by 512, we get 88, which makes this statement true, which means that the total sector's
‫is not one, but instead two.
‫So one plus one is two.
‫So that's the whole point of that, guys, because otherwise we're going to read less than we should.
‫So that's why we need to take this offset into account and we use the modulus operator to determine
‫that.
‫OK, so now down here, we're going to say in it, total items equals 16, get total items for directory
‫and we haven't made this function yet.
‫A broken FAPE private root directory sector.
‫Position, so this will basically get the total items in a directory, we will implement this later
‫on.
‫So now we're going to create a new directory item.
‫So we're going to find directory item die off a directory because Casula.
‫Root directory size, OK, and obviously, if that fails, then there was a memory problem and we should
‫go out and we're going to have to create an out label by here, too, guys.
‫OK, so if that worked, then we now need to read.
‫Into that memory we just created, so we go struct desk, stream stream, because that private directory
‫stream if desk streamer sike.
‫Stream Fat 16 sector to absolute, and we're going to create this function later as well, guys, root
‫directory sector position.
‫OK, so that doesn't equal us all, OK, then we failed to seek to the part in the discourse that we
‫need to read from so we should mind the CIO and go to.
‫OK, so at this point in time, we are exactly where we need to be to read the root directory.
‫So all that we do is, as we say, if this streamer reads.
‫Stream, Diana.
‫Root directory size does not equal us all, OK?
‫Then there was an error go two outs.
‫We need to take into account all these errors, guys.
‫Now down here, this means everything was fine because we haven't we haven't had any errors at this
‫point.
‫So everything's fine now.
‫So we go directory item Kostia directory total equals total items.
‫Directory sector position equals root directory sector position directory ending sector position.
‫Equals root directory SEC topos, plus root directory size divided by desk sector size.
‫OK, so that's what's going on here.
‫So if you remember, this function is forgetting the root directory.
‫So this this directory here is the one that we should set and this is passed to us by the collar.
‫So that's why we're doing this down here.
‫So we said the directory item to the DIA that we allocated here, total items we calculated here, sector
‫position.
‫We calculate that further up with the math here and in sector position.
‫Well, that is basically the root directory size.
‫OK, this is the root directory sector position, plus the directory size divided by the dissector size,
‫which will give us the ending sector.
‫OK, so that's what is going on here.
‫So we now need to implement these other functions that we've missed.
‫So get total items for directory and fat 16 sector to absolute.
‫So we need to implement both of those now.
‫OK, so we're now going to implement fast 16 sector to absolute.
‫And before I forget, we should pass in the desk here as well, guys.
‫OK, so just make sure you change that fast 16 sector to absolute should pass in the desk to somebody
‫here.
‫Then we're going to go in.
‫It had 16 seconds to absolute it's going to accept the desk and the sector number and it's basically
‫going to return an absolute position for that sector.
‫So, for example, if if we have sector if we have the first sector we pass for sector here, then we
‫would return zero.
‫We passed the second sector, which 512.
‫So that's what's going on here.
‫So it's very simple.
‫We just return sector multiplied by desk sector size and it's really that simple.
‫Right?
‫So that is the equation here, because what we want is we know that this stream searches in absolute
‫bytes, not sector numbers.
‫So that's why we convert that here to an absolute byte.
‫So this, for example, if this was the second sector or something, I would term five 12, third sector
‫1024.
‫You understand, right.
‫So that is what that is doing, is converting the sector number into an absolute position for us.
‫OK, now we need to implement the fat 16 Gaturro total items for directory, which is more complicated.
‫So we're going to have to do that.
‫OK, so just above Fantastics, get a root directory, we're going to go in it at 16, get total items
‫for directory.
‫That's going to accept a desk and a directory start sector.
‫OK, so we're going to go struct fat directory item struct fat directory item empty item meme's said
‫empty item zero size of empty item.
‫So we essentially create an empty item here.
‫And just by making it on the stack by here, that will be an initialized.
‫So we need to actually set it and make sure you spell it right by here.
‫OK.
‫So we're going to obstruct private, private equals desk, EFS, private, OK?
‫We can call that private.
‫So we're going to go in it, Rasco zero and I could zero in it, directory start position equals directory
‫start sector multiplied by this sector size.
‫Struck this stream stream.
‫He calls fat private directory stream, and now we're going to six, we're going to go to this stream,
‫a stream directory staff position, and now we're going to go wild one.
‫If this streamer arete stream ampersand, item size of item does not equal us all, OK?
‫Then rest equals minus zero, go to out, OK?
‫And when are now going to have a label down here where we're just going to return rest's and also guys,
‫we're going to do the same here, by the way.
‫So we're going to say if jet stream a seat does not equal all, OK, race equals minus zero.
‫Go to our OK.
‫OK, so let me explain this before we go any further than.
‫So we basically seek to the directory start sector.
‫That's what we do here.
‫And remember, I just ah, just stream requires an absolute address.
‫It does not work on sector numbers.
‫OK, so once we've done that, as soon as we're online 171, we have successfully sneaked to where the
‫directory starts.
‫So we now basically loop through, have an infinite loop and we basically read each directory item and
‫remember that this stream of read will increment the stream position based on the size we pass here.
‫So in our case, 32 bytes.
‫OK, so we're not done down here.
‫Now we need to check the data that we've just read into memory.
‫So we say if item volume zero is equal to zero zero zero, then we have a blank record and we are finally
‫finished.
‫So all we now have to do is, is break.
‫We are done.
‫So we now need to check if the items are news.
‫So we say if item the filename zero equals equals zero x E five, then we can continue because the item
‫is unused.
‫And yeah, because remember, this whole routine is for counting the total items in a directory, so
‫if the items are news, then we should skip it.
‫So we just do a plus plus here now, which will increase the total count.
‫And do not forget the disclaimer read, as I've just said, increases the stream every time we read
‫it.
‫So we're reading the size of items.
‫So every time we call read here, it'll increment the position by 32.
‫So that so this, this will work absolutely fine basically is what I'm trying to say.
‫If we look at the manual for Fat 16 and we search for zero x e e5.
‫We can see that it tells you exactly why we're doing that here, 075 indicates a directory entry is
‫available.
‫OK, so if you just read the manual with these magic numbers I'm doing, it will make a lot more sense
‫to you.
‫So I do suggest you get a manual because it explains all the code I'm doing here.
‫OK, all of the code I'm doing here is explained in this manual and in the presentation I made for you
‫guys.
‫OK, so just after the wall, we're going to say rest's equals ay OK.
‫Which means the response is equal to I.
‫OK, and that's that because then we return address and everything's fine.
‫OK, nice.
‫So.
‫We have now completed our GETRUDE directory function and we need to go back to that 16 resolve now because
‫we have more things that we need to do on there.
‫OK, so what's left to do then?
‫In EFS Resolve, we go desk aifs private equals private desk filesystem equals ampersand fat 16 FS.
‫So we're essentially binding the desk to us.
‫OK, that's what we're doing here.
‫We're binding the desk to us.
‫And then obviously by returning zero it says, yes, it was us.
‫We've binded to you, you carry on.
‫So in the out we say if stream then this stream Miklós stream.
‫So that just closes the stream we created here on line 24 eight because we don't need it anymore.
‫And here we say if rest's is below zero then K free five Privette because there was a problem, just
‫gaffes.
‫Private equals zero.
‫OK, so that ensures that we unbind this because there was some sort of error.
‫OK, and then obviously because there was an error that would return a negative value.
‫So, so we will never actually bind it to the disk.
‫So we just go back to file that C you can CFS resolve.
‫So obviously the disk calls this that calls our 16 driver and if we return zero, then we become we
‫become the filesystem for that desk and that and our file system gets returned to the caller of efforts
‫resolve.
‫So, OK, we're ready to test this implementation now.
‫So we're going to just go make a clean bill that S.H. and we can see a couple errors.
‫That's not a problem.
‫We probably just need to include some header files and stuff like that.
‫So far, 16 to line 213.
‫So we'll go there first fat 16.
‫Two hundred and thirteen.
‫And we can see what passing the private here, we should instead pass the desk.
‫OK.
‫OK, so the next error is implicit declaration of Casula.
‫That's no big deal.
‫Go to the visual studio so we can scrub, in fact, 16 and we're going to include memory, keep keep
‫w.h.
‫And if we now clear this and we're going to build to that stage again so we can see the final errors
‫and we can see a complete declaration of destroying stream read.
‫Did you mean this stream read.
‫Yes, we did.
‫So if we go to Fat 16, we search for this stream, read.
‫And we can see online 256, this should be disc strimmer, right?
‫OK, so that was a minor typo we now build again.
‫We can see that that now Bill is absolutely fine and we can now stop the debugger to check if everything's
‫working.
‫OK, so if we now go CDB in GDP, add symbol file builds of sort of, you know, the drill target remote
‫kumu system.
‫I created six dash HDR Stop and dash capitalist Dash Jaideep studio.
‫OK, and we're going to break on Fat 16 resolve.
‫OK, and we're just going to press to continue and we can see we're now on the fat 16 results.
‫So we're going to go next and step through this.
‫So we've just created a memory for fat private.
‫We've just initialized that memory.
‫So if we now go print askaris, fat, private, you can see all of that nice and initialised.
‫I'm teaching you guys to debug here so you can fix kernel problems after this cost.
‫So that's why we're doing this.
‫So we go next again.
‫We can see that that is all fine.
‫And now we read the header and so we've just read the headers.
‫So let's print it out for private header.
‫OK, so we can see this is our fat header, which is amazing because look at all that stuff we wrote
‫in the bootloader.
‫You can now see it here.
‫OEM identify a picture, respites perspective, FY twelve and so on and our signature.
‫OK, so that's really good.
‫So we're going to go next, we're going to press next again because we get the root directory here.
‫And if we now print fat private root directory, we can see this is our root directory.
‫And it is loaded that and there's the SEC position list and in sector position, we can see the total
‫elements is minus one.
‫We will look into that shortly.
‫So we're going to go next, next, next, next, next.
‫And we can see the response is zero.
‫And our justice files system now points to fact 16.
‫Which is excellent.
‫So, as you know, we saw the total is minus one, so we're going to look into that now.
‫So I attached to the bug outside of the recording just to speed things up for you all, because you
‫will come to the same conclusion as me anyway.
‫The problem is with the fact 16 ghetto's total items for directory, our first private is null.
‫OK, this is the issue and that makes complete sense because if we go to Fat 16 resolve, we can see
‫we only set the private data at the very bottom here.
‫So that's why we're having this problem.
‫So what are we going to do instead is we're going to copy these two lines and we're just going to paste
‫them by here, just by here and that way.
‫Then throughout the rest of the process, these have been resolved already.
‫OK, so that's how we are going to do that.
‫So if we now control these tracks that the Barga and we did make a clean bill that I say we now go CDB
‫in GDP at single file, just do what we just did.
‫And we're going to break on Fat 16 resolve again, and now if we go through it, everything should be
‫OK.
‫So we read the fat root directory.
‫We can see the total items as to which is correct.
‫And let me explain why it's correct, because I know that we only copy over one file.
‫Hello.
‫OK.
‫However, there's a thing called a long name in the fat in the file allocation table, and it basically
‫makes two records on modern systems for the same file.
‫So that's why it says those two items.
‫And that is correct.
‫So there is two items, because the header for Haloti is replicated twice, one for the long name and
‫one for the short name.
‫But we don't have to concern ourselves with that.
‫The point is we've now implemented the file allocation table resolve function, so it's now binds the
‫disk.
‫And if we just go next and we go print disk.
‫Get zero, and we do that.
‫We can see we're now blinded to the desk, so that's all that we needed and our private data is here
‫as well.
‫So congratulations, everybody.
‫You've now imprinted this resolve function.
‫It does get harder from here.
‫Stick with it, I will be sharing the source code in the description of these lectures.
‫If you ran into problems, however, please do try to do this yourself, because if you take shortcuts,
‫you're going to run into bigger problems when things get more complicated than this, this is kernel
‫development.
‫It's very difficult.
‫Please try to go through this again if you run into problems or ask any questions.
‫Thank you.