‫Hello and welcome back, guys, in this lecture.
‫We're going to start creating some internal structures that the Fat 16 file system uses.
‫So things like the Fat 16 directory, the fat 16 head and so on, we're going to define structures and
‫see to represent those.
‫OK, so let's first create some definitions.
‫Let's go hash tag, define Peatross Fat 16 signature.
‫So the second Shabi to see your X 29.
‫Now we're going to go define Peatross fat 16.
‫Fat entry size zero zero to define Peatross.
‫Fat 16 bed sector CEO X F7 defying PCOS, Fat 16, unused zero zero zero.
‫So don't worry about these right now.
‫We will be using these as we go further on throughout this course, but for now, just to find them.
‫So we are ready for later.
‫OK, so we're going to create a fat directory.
‫Entry attributes, big mask.
‫OK, so we're going to create some definitions for that, so we're going to go define fat file read-only.
‫So remember I showed you in the presentation of the attributes fields for fat directory items.
‫So these are the definitions we are going to be creating to represent those attributes in the pit mask.
‫So that is zero zero one.
‫So now we're going to go define fat file hidden.
‫That's easier to define.
‫Fat file system that selects you for the fine fat file volume label.
‫That is the correct define fat file.
‫Subdirectory, that is zero x 10.
‫So if this bit is set in the pit mascot, Ashbridge Field, in the directory item structure, which
‫we haven't created yet, by the way, then it represents the subdirectory on disk.
‫OK, that particular directory item.
‫So now we go find file archived.
‫A six 20 define fat file device 640, define fat file reserved.
‫And that's exciting.
‫Now, just by here, we're going to go typedef unsigned in it, fat item type.
‫And here we're going to go hashtag, define fat item type directory, define fat item type file.
‫Now, these three lines here will be used for our own internal representation of directories and files.
‫They won't be stored on disk.
‫These attributes that we've just done here where essentially as we go further in the course, we're
‫going to be basically abstracting it out.
‫So that's a little cleaner and easier to work with.
‫So these three lines here don't represent anything on the disk.
‫They're simply for internal use walts whilst it's loaded into memory.
‫OK, so just down here, then we're going to create the fat's extended header, fat fathead extended.
‫This is going to take a year and 80 drive, no, and before I continue, guys, we need to include Usted
‫in it.
‫He said we're going to go unit 80 when A. bets unit 80, signature unit 32 T volume ID, Unit eight
‫T volume it string.
‫And that has 11 bytes.
‫And now we're going to go unit eighty, system IID string, and that has eight bytes and now we need
‫to pack this so we go attributes.
‫Pact.
‫So it should look like that, guys, and as I've already said, attribute pact ensures that the compiler
‫doesn't rearrange these variables in the structure.
‫And it has to be packed, guys, because we are actually writing this desk and we're reading this from
‫the desk.
‫So we can't allow things to just be changed around at.
‫Well, I'm just in case you don't really understand what I'm doing here.
‫I'm basically implementing the structures in the file system.
‫So things like the header that represents that this is the file allocation table.
‫If you open up a specification for fat 16 or maybe even fat 32, you'll see similar headers to what
‫I'm writing now.
‫Best to look for a fat 16 specification, although it's harder to find.
‫I had to rely on Fat 32 when I was figuring this stuff out because I couldn't find the fat 16 specification.
‫Just ensure that you actually implement in Fat 16 and not fat 32.
‫As long as you follow this course correctly and copy what I'm doing, you will be absolutely fine.
‫So now we're going to create the main fat header.
‫Struct fat head of.
‫Unit eight short jump instruction, and that's exactly three bites that contains our short jump and
‫the cooperation that I showed you in the bootloader right by here, jump shot starting up.
‫OK, so one more loading this sector into memory that will be loaded into this array here, OK, a machine
‫code for that.
‫So now we go Unit 80 OEM identifier.
‫This contains eight bytes.
‫So now we go unit 16 T bytes per sector and will ignore this field, but still needs to be there because
‫we are loading the whole sector into memory, right?
‫Well, not the whole sector loading the whole header into memory.
‫So we still need to put it in the structure, even though we're not going to use it.
‫So now we go unit eighty sectors per cluster and we need this.
‫We definitely need to be using that field unit 16 t reserve sectors.
‫This is how many sectors are reserved before our first file allocation table.
‫Watch the presentation if you're confused, Unit eight fact copies and notice the notice.
‫These are bits, right?
‫Eight bits.
‫Sixteen bits.
‫That's what these numbers represent.
‫OK, and they're found in the study and it had a file, by the way.
‫So now we go unit 16 t root directory entries, unit 16 t number of sectors.
‫Unit 80, media type units, 16 T sectors, purrfect units, 16 T sectors per track, unit 16 to number
‫of heads, and we'll just correct that spelling.
‫Now we go Unit 32 T hidden sectors, unit 32 T sectors big.
‫And most of these variables, you won't even have to care about what they mean.
‫So just bear that in mind.
‫You don't have to know all of this.
‫Just follow the costs.
‫And once again, this needs to be packed as well, guys, by the way.
‫OK, so simply put, this head structure basically represents all of the information here.
‫OK, so we load that into the structure and then we we compare it with the identifier and so on to see
‫if this is an actual fat file system.
‫OK, so that is exactly what's going on.
‫Well, we wouldn't compare with the identifier.
‫I mean, we would compare with the system ID string here and, you know, we would check for other things
‫as well.
‫So that's how we can figure out if it's fat, 16, filesystem or not.
‫OK, so we're now going to create the proper fatheads, which contains both the real fatheads and the
‫extended header.
‫So that's pretty important.
‫So we're going to go struct fat H OK, struct fat header, primary header.
‫OK, and now we're going to create a union union fat hajee struct fat had an extended extended head
‫to shed.
‫OK, that just allows us to load the proper header and you can see it's a union because the extended
‫header is optional.
‫OK, there could be something else.
‫Who knows.
‫That's why we, we have a union here for future proofing reasons in case we were to implement something
‫else here.
‫OK, and don't forget the semicolon.
‫OK, so that's the header completed now.
‫So now we're going to create the directory item, check the presentation if you forgot what that is.
‫I explained it in depth.
‫It basically represents either a file or a subdirectory.
‫OK, so we're going to go struct fat directory item, OK?
‫And essentially we're going to be loading bytes from disk directly into these structures.
‫And then that's how we're going to be able to access them, because all the structures do is make sense
‫of the memory that's older, that doing guys.
‫But, you know, you know, C so you probably are already aware of that.
‫So here we're going to go unit eight T filename eight eight bytes for the filename, unit eighty eight
‫for extension.
‫That is three bytes, unit eighty attributes.
‫The HP variable here represents all of these flags here, these, these big mask's.
‫OK, so that's what's going on there.
‫We can do a bitwise operation to see if these flags are set, which can tell us certain things about
‫this directory item.
‫OK, let's carry on.
‫So then we're going to a unity reserved, I guess that's reserved for future purpose in case Microsoft
‫decided to make use of a unit a t creation time.
‫Tenths of a sec.
‫So, you know, we're making the correction time now of the of the directory item, OK, but we won't
‫have to worry about that.
‫So now we're going to a unit 16 T.
‫Croatian time units, 16 t Croatian date, and before I continue, guys, you need to get these bets
‫right.
‫If you do a Unit eight instead of units 16, your implementation will fail.
‫So you need to make sure you're copying this.
‫Exactly.
‫Don't get it wrong because you'll lose track of where you are.
‫So now we're going to go Unit 16 to last access.
‫So this is the last access time unit 16 t high, 16 bits first cluster.
‫So this is the high sixteen bits of the first cluster of the data for this directory item.
‫If this directory item represents a subdirectory, then these are the high sixteen bits of where the
‫other directory items are stored.
‫So it's the high sixteen bits of the cluster, the first cluster of where these directory items are
‫stored.
‫If it's not a directory, then it's the high sixteen bits of where the first data for this file is stored.
‫So hello.
‫For example, if you have a file called Hello T that has the words Hello World, then the high sixteen
‫bits, the first cluster that will represent the high sixteen bits, the first cluster of where the
‫header will be stored in the file.
‫OK, so that's important to note.
‫And I know you might not understand completely what a cluster is yet, but as I've explained in the
‫presentation, it's basically represents sectors combined together.
‫OK, but that's all you need to know right now.
‫So here we're going to go Unit 16 t last time, the last modification time of this file, unit 16 T
‫last mod dates units 16 T low.
‫Sixteen bits of the first cluster.
‫OK, low.
‫Sixteen bits first cluster.
‫Unit 32 t file size, and we're just going to pack that as well, guys, because anything on the dish
‫should be packed.
‫OK, like I said, we don't want it rearranging the variables in memory because the compiler is doing
‫some sort of optimization.
‫We don't want that.
‫So pack the structure or you're going to ask for trouble.
‫So I, I saw directory item created.
‫Make sure the bikes are exactly the same as mine.
‫Eight bit, eight bit a bit.
‫And then you have 16 bits down here and we end with 32 bit.
‫Make sure it's all correct.
‫Otherwise you'll run into problems later down the line.
‫OK, now working with these complicated structures all the time is going to get complicated because
‫we're dealing with high sixteen bits, low sixteen bits, all sorts of stuff like this.
‫And it's just going to get complicated.
‫Right.
‫So to get around this problem, we can create our own internal mechanisms which are much easier to understand.
‫When we then load from the desks, we can use our own special internal structures and do the calculations
‫to, I don't know, combine the high cluster with the low cluster only once, and then we can set that
‫in structure somewhere else.
‫So it gets much more easier if we use our own internal structures.
‫So that's what we're going to do here.
‫We're going to create our own.
‫So we're going to go struct fat directory.
‫And this will represent only a directory, by the way.
‫And we'll have a struct fat directory item here.
‫And this will point to the first item in the directory that this represents.
‫And obviously you could access it like an index.
‫Right.
‫So item one would be the second item in this subdirectory item to be the third and so on.
‫OK, obviously this is a race, an array.
‫So we start from zero.
‫Now, here, here we have in total, this will be the total number of items in the fat directory.
‫Now, here we have in it sector pass.
‫This is the first sector where this fat directory data is.
‫And now here we go in it and SEC topos, we'll call it ending to pass, actually.
‫And, you know, that's pretty self-explanatory.
‫That's the last sector of where this fat directory is storing other directories and files.
‫OK, so now we're going to go struct fat item and fat item will represent either a normal file or a
‫directory.
‫That's what it'll do.
‫So it was simplifying the process by using our own internal structures here.
‫Right.
‫So to do this, we use a union so we can save memory.
‫And this is in the C programming cost, guys.
‫So if you don't know what union is, you need to research about that.
‫OK, it allows us to make variable shed the same memory basically.
‫So here we're going to go struct fat directory item and this will be called item.
‫So this is if it's just the normal file.
‫OK, and then that's when we access this one.
‫Otherwise we have a directory.
‫So if this item represents a file, will access item variable, otherwise the directory variable.
‫OK, they share the same memory.
‫So now here we're going to go fat item type type and item type here, which we've declared at the top,
‫will either be equal to directory or file.
‫And this is for our own internal data structures.
‫As I've already told you earlier, this data is never written to the file.
‫It's just for us so that when we load the raw data into memory, we can make more sense of it by creating
‫these fat items.
‫OK, that's what this is.
‫Now we're going to go struct fat item, just scripter.
‫And this will contain a pointed to the fatheads them, and it will contain our current position in the
‫file.
‫So this here represents an open file essentially.
‫So when someone doesn't have open on this, we will create this fat item here, which either points
‫to a directory or normal item or whatever.
‫And then here this will be the position that we seek to in the actual file.
‫So that's what that is, guys.
‫So now here we're going to create our private data.
‫So struct five private.
‫Struct Fatmeh Chheda, that's not appointed, by the way, guys, struct fat directory rup directory,
‫and now we're going to create some disk strings so used to stream data clusters and we're going to create
‫one for that struct this string cluster read string.
‫Now we're going to go used to stream the file allocation table.
‫Strub this string fat read stream.
‫So remember we've implemented these streams in a few lectures ago.
‫Everything I've done up to this point has been to prepare you for now and later.
‫So now we're going to create one final stream used in situations where we stream the directory strupp.
‫Just stream directory stream.
‫Okay, so we just create a few stream is basically to allow us to easily seek to different parts of
‫the file system and read maybe five or 10 bytes at a time rather than reading the whole sector.
‫And obviously you understand how the disk stream works because we've already implemented it.
‫OK, so we now need to include the header file for that.
‫So we're going to go include disk to storage and we're going to go include disk stream today.
‫OK.
‫And that is it for our actual pedophiles, and you don't have to worry too much about this fat private
‫will be basically implementing this properly later on, but essentially it just contains some information
‫that helps us identify what's going on, you know, contains the header file for the file allocation
‫table and the root directory so we can load all of these temporaries and stored in our private data
‫for later on.
‫But more on that later on.
‫We don't have to worry about that at the moment.
‫So you've implemented all of these structures now.
‫These are all the structures we're going to be using throughout the implementation of the file allocation
‫table.
‫Congratulations.
‫Keep following this course and we will have a working file allocation table driver.