‫Hello and welcome back, everybody.
‫We are now going to implement the fat 16 f close function, go to fat 16 dot C and just above fat 16
‫STATT.
‫We're going to go in it fat 16 close.
‫And that's going to take in the private data as shown in the prototype and outraged by here.
‫The first function, so implement that prototype now, in fact, 16 that see here off at 16, close
‫function.
‫So in here, we're just going to go for 16 free file descriptor and we're just going to cast this to
‫obstruct.
‫Fat file descriptor and we're going to pass in the private here, we're now going to create this fat
‫16 free file descriptor function and before I forget, just return zero by here as well, guys.
‫So just by here, then we're going to go.
‫Static void fat 16, free file descriptor.
‫That's going to take a fat file descriptor as a argument.
‫OK, and this fat 16 Free-Fall descript functions very easy, we just go fat 16, fat item free and
‫we're going to pass in the descript item and then finally we delete the memory of the descriptor using
‫Kifri.
‫And that's it for our fat 16 close.
‫We just, of course, need to put it in our filesystem structure.
‫So just copy and paste this prototype of Fat 16 close scroll to the top by here and we're just going
‫to paste that in here and we're going to go Duclos equals Fat 16 close.
‫OK, and put your comma here as well.
‫And if we now try to build that, make clean build that S.H., we'll see that build successfully.
‫Let's go to Canada C and we're going to try to close our file.
‫So just by here, we're going to go f close F.T. And we're just going to do a little print by here to
‫see if we got to this point and close successfully.
‫So we're just going to go make a clean bill that S.H. Cribben Kumu.
‫And we can see testing, so the fire was closed successfully.
‫Now, there's one slight problem with our clothes that we haven't dressed yet.
‫We call the clothes on the lower filesystem, which will close the file, which is great.
‫That's exactly what we wanted.
‫But the one slight problem here is the descriptor is not friede.
‫And this is a problem.
‫Because we're not free in that descriptor, right?
‫So what we need to do, we need to actually.
‫Set our file descriptors I index here to zero so that it frees it.
‫That's what we need to do here.
‫And we also need Cafferty File descriptor as well, because if we look at 16 see, I've had 16 close
‫freeze its private dates at the Fab Five descriptor.
‫However, we don't our file descriptor, the generic one that we created here.
‫So there's a memory leak and we also don't blank the array.
‫So we need to do that now.
‫So just by here, we're going to go static in a file free descriptor and we're going to accept this,
‫the file descriptor here.
‫And we're simply going to go file descriptors, descriptor index minus one, remember we minus one because
‫we want the actual index of the descriptor we care about.
‫And here the scripture index is a plus one because that's kind of like a user friendly index generally.
‫But we want a minus one to give us the real index.
‫So we're just going to go equals to zero.
‫OK, and there we are.
‫We blank that array now.
‫Great.
‫And we now need to free the memory of the descriptor.
‫So we just go, OK, free descriptor, OK, and that should be it.
‫Yeah.
‫I can't see anything else that's important in here that we need to free because the private data is
‫freed by the lower filesystems.
‫So there's nothing to worry about.
‫Lower filesystem being fat sixteen in this case.
‫So yeah, there's five free descriptive function then.
‫So that's, that's pretty nice.
‫Very good.
‫So.
‫We're just going to copy for free script and we're going to go to our close and close and just under
‫here, we're going to say if rest is equal to all, OK, then file free descriptor descriptor.
‫And that just ensures that it actually frees the memory.
‫OK, so if we now make a clean bill that S.H..
‫We can see no return statement in function return non void on file 61, so just go to that quickly.
‫Oh, yeah, yeah, just return zero here, guys, OK?
‫In fact, this can be avoided.
‫Let's make it avoid.
‫So that's how far free descriptive function.
‫OK, so back down here to our close, we basically say rascal's filesystem close.
‫If the lower filesystem, i.e. fat 16 said that everything was OK, then we can go ahead and delete
‫our generic file descriptor.
‫OK, and if we now run that, you can see we still see testing and everything works fine.
‫There was no panicking of any kind.
‫So yeah, now that just resolves that memory like a freeze the index.
‫So the next person the calls file new descriptor can now obtain that old index number that that this
‫one has that were free.
‫And it also frees the memory resolve in the memory.
‫So yeah, excellent.
‫Then guys, we've now finished implementing the Fat 16 file system as well as generic file functionality.
‫So congratulations on that.
‫In the next couple of lectures, we're going to move on to more, more concepts such as use the land
‫where we actually start creating our own processes.
‫Now, you know, things can get complicated.
‫The filesystem functionality that we just made here is one of the most complicated things to implement
‫so well in this cost, I mean, so the fact that you managed to do that means that you're ready for
‫anything else that this cost throws at you.
‫So if you did run into problems here, please let me know.
‫You can also find the files on GitHub as well.
‫See the lecture description for that link to the repository.