‫Well, coming in this lecture, we're going to implement the fat 16 elfriede function, what coming
‫towards the end of our filesystem implementation, our fat 16 read function will be very simple to make
‫because we've implemented a lot of functions such as Fat 16 read Internal, which carry a lot of the
‫heavy weight for us.
‫So all I want us to do is scroll down and we're going to look for Fat 16 open.
‫This is in the fat 16 dot C file, of course, and just on the fat 16 open, we're going to say in it
‫Fat 16 read struct desk.
‫Void Descriptor, Unit 32, tea size, unit 32, Tea and Man.
‫Cha out pointer.
‫And in this function, we're going to go and address equals zero return address.
‫Now this function should return the amount of end memes that was successfully read.
‫OK, so just want to make that clear.
‫So we're going to go struct fat file descriptor.
‫Fat descript equals just scripter.
‫Struct fat directory item item equals fat descript item and I we're going to go in it offsets equals
‫fat script position and now we're going to go for unit thirty two t i equals zero Ivailo nmm i plus
‫plus gress equals fat sixteen reads internal.
‫Desk fact 16 get first cluster and I was going to pass an item.
‫And now goes off, said our size and our outpoint up.
‫Now let's explain this so far so we get past a void descriptor.
‫This is our private data.
‫We returned in our fat 16 open function.
‫This is pass to us.
‫We cast that back into a fat file descriptor, OK, which is the private data structure we use to represent
‫the fat item and the current position that we seek that.
‫So we then extract the fat directory item from our fat descriptor and we of course set the offset variable
‫to be the fat descriptor position.
‫Now we need to loop through the NMM so the size could be 10 and we might have an end of five.
‫So we want to reach 50 bytes.
‫Yeah.
‫So we loop through the NMM and we go fat 16, read internal and we pass in the disk and we go fat 16
‫get first cluster, which if you remember is very simple.
‫It just joins the high sixteen bits of the first cluster with the low sixteen bits of the first cluster.
‫That's all that does.
‫So now we have a cluster number here.
‫We pass from the offset, we pass in the size and we pass in the outpoint up and now that will literally
‫read from the fat 16 cluster.
‫And that's how that's working guys.
‫So we're actually reading the data into memory.
‫So let's continue then.
‫We're going to go F is error rest then go to about.
‫Other otherwise out pointer plus equals size offset plus equals size, and I was just going to make
‫an out label at the bottom here and just above zero and six online, six, five seven.
‫We're going to go rest's equals NMM, OK, because the response should be equal to the total red.
‫So if there was no error, then we'll set response to the end.
‫OK, so that's off at 16.
‫We function implemented.
‫We now scroll up to the top here.
‫To our file system structure and we're just going to go read Equals Fat 16 Reed and don't forget the
‫column at the top by here on the open function.
‫Scroll back down to Fat 16 read and we're going to copy and paste the prototype at the very top here.
‫Just above.
‫The struct filesystem, so just above here.
‫There we go.
‫So one more thing, guys, scroll down back to 516 read and there's one more thing we need to do.
‫We need to actually access the item of the item because the fat descript item will give us a fat item
‫and a fat item contains.
‫A fat directory item, and that's the one we want to access.
‫OK.
‫So, yeah, because remember, the fat item can either be the directory or it can be the file.
‫OK, so excellent.
‫So once you've done that item item we are ready to go.
‫So if we now open the terminal and we're going to go build that S.H., we can see that works absolutely
‫fine.
‫And now we're going to go to Canada to see and we're going to try to read from a file that we open.
‫OK, so first things first.
‫Put a new line just by here.
‫So it's nice and clean.
‫We're going to create a buffer that can hold six bytes and now we're going to go airfreight both.
‫Size of six, one bite.
‫Well, one block of sex, I should say, and the FDA by the FDA return from my open and I were just
‫going to go print bath and we're going to compile and run that.
‫So we're going to go build the research and we're going to run kumu.
‫Oh, and what's that?
‫We can see a bunch of binary here.
‫Now, I wanted to show you this because this is a mistake I made and this is the reason I'm showing
‫you this is so you know that you really need to take care when doing these things by yourself because
‫the slightest mistake can cause a bug.
‫Now, let me show you how you can fix that, because I spent 20 minutes figuring that out.
‫So if we got a fat 16 that C you will see in our fat 16 reinterred from string function lying four four
‫seven.
‫This line here, I accidentally used multiplication.
‫It should be a plus.
‫So if you switch that to a plus.
‫So the starting position should be starting to multiply by dissector size plus offset from Kluster and
‫show you use the parentheses as I've done here as well, guys.
‫So we now go back when we make a clean build that S.H. Cribben kumu and what's that we see.
‫Hello.
‫So that is not what worked successfully.
‫If we go to hello text, you can see hello here.
‫We read in six bytes.
‫We have hello here.
‫Nice and simple, so let's load in a little more what's the size of the world?
‫Let's take a look at that.
‫So that's 13 bytes.
‫So let's go to Colonel C. We're going to change the buffet, the 14 we're going to load in 13 bytes.
‫OK, and we're just going to go above 13 equals zero zero zero by here, just to add another Terminator.
‫We now go make clean bill that stage Cribben we can see hello world.
‫So it's successfully read from Hello Takechi if we change hello dot text and let's put in.
‫Remember, it has to be 13 bytes.
‫So let's just change this to uh let's change how to test, test the world.
‫So if we now go make clean bill that I say you would seek to the end of the file and stuff like that
‫in a real implementation, you would start it.
‫But we'll get to that later.
‫Go Sidibé and Kumu.
‫And now we see Testor World.
‫So we now have a file system.
‫Our operating system now has files.
‫Congratulations.
‫So we're not quite done.
‫We need to create the ability to stack files and also close the file handles.
‫So we will be doing that shortly.