‫So we are now going to just make a interface for this driver, because we're going to want something
‫clean for people to work with, right?
‫I mean, if we just keep the implementation we have now, that it'll mean that the programmer who wants
‫to read from the desk will have to be more cautious about which disk he wants to read from.
‫However, if you make a special interface, then we can have the same type of code to talk with multiple
‫different desks.
‫We could give the disks some sort of ID number or something a bit like Windows does.
‫You know, you have drive, drive, BJC, stuff like that.
‫Right.
‫So we need to abstract it out in a similar way, but we'll use numbers to represent ours.
‫Now, I should note, for the time being, we're only going to have the primary hard disk and we will
‫ignore any other number than zero one.
‫They say give me disk one, it'll be rejected.
‫If they say give me this zero, it'll give them disk zero.
‫So, all right, let's go to this stage.
‫We're going to create the substraction now.
‫So we're just going to go struct desk and this will represent a hard disk.
‫OK, now we're going to create some definitions.
‫So if we just go typedef unsigned init process disk type.
‫OK, now think of a disk type, right.
‫What do we have?
‫We have partitions, we have real hard disks.
‫We have virtual file systems, lots of different things that we could do.
‫Right.
‫So if we want to represent each of these as a disk, so a partition could be seen as a separate disk
‫on the system, for example, even though technically it isn't, then, you know, we can make use of
‫a special disk type for that.
‫Now, we're only going to support a real hard disk for the time being.
‫No partitions, no no virtual file systems here.
‫Right.
‫No file systems inside files systems.
‫Because I know in Linux you can make falls into file systems, but we are writing the functionality
‫to make it easier to be able to implement something like that in the future if we chose to, because
‫we're abstracting everything out.
‫So we're going to do then we're going to go define Pekoe as disk type real and that'll be zero.
‫So represents a real physical hard disk.
‫So this is a real physical hard disk on the system.
‫OK, that's what this represents.
‫So now inside this structure, we're going to go Peach's disk type and we're just going to type.
‫So this is what a disk will have.
‫A disk will have a type, it'll have a sector size, OK?
‫And it also should be aware of filesystem functionality and stuff as well.
‫But we aren't going to implement that right now.
‫So for the time being, this is absolutely fine.
‫OK, if we now had to start C, I was simply going to create a new function called Void Disk Search
‫and in it and this function will be responsible for searching for disks and initializing them.
‫However, it's not actually going to search here and we're just going to point it to the primary disk.
‫But again, we're abstracting it out so we can implement those things at a later date.
‫The abstraction is important.
‫OK, so let's just scroll to the top here and we're going to go struct disk desk, OK?
‫And we need to actually also include discharge because we haven't done that yet.
‫And this this this structure here will represent the primary hard disk.
‫OK, now, you know, we might store things in the future, such as which parts represents that particular
‫disk and stuff like this.
‫Right.
‫But we don't have to worry about that at the moment because we're only going to use the primary hard
‫disk and we're just going to write an if statement that says if the indexes in zero, then ignore it.
‫However, in a better implementation, we would go into some sort of disarray and we'll pull the index
‫out that way.
‫But again, you know, we're just right in the abstractions so we have more to work with later on if
‫we need to.
‫OK, so go to this search and in it, then we're going to go set and obviously scroll up here because
‫we need to include said here include memory, memory, dot.
‫So we're going to go meme's said, and we're going to go desk zero size of desk, cast the very first
‫thing, then we're going to go type equals purchase desk type real and we're going to go desktop sector
‫size equals Peatross sector size.
‫I know we don't have that yet.
‫We can add that later on than that.
‫Is it for that initialization.
‫We just need to create this definition now.
‫We may already have it in config and no, we don't.
‫So just go to config Derg and we're just going to go define aspect size five 12, because that's how
‫big the sectors are on a normal hard disk right now.
‫If we go to back, just see and we just include configure Hajjah.
‫We can see that it should resolve that, and it does so that saw this discussion and it done so obviously
‫it's not searching.
‫We're pretending that because we're just making the obstruction.
‫Right.
‫So what'll happen is it will just go in here and it will initialise this desk structure.
‫There's no need to attach any port numbers because we're only dealing with one desk.
‫We just need to create the abstraction.
‫That's all that matters at the moment.
‫OK, so we're now just going to go struct desk diskettes and that's going to take an index.
‫So they so get a desk by index again.
‫There's no array here, so there's no array we can pull the disk from.
‫So we're just going to manually return the disk that we've created here.
‫Right.
‫So we're going to go.
‫If the index does not equal zero, then this must be an invalid disk to return zero, which which is.
‫No.
‫Yeah.
‫Otherwise we'll return the address of disk.
‫So, again, you know, it's very staticky.
‫But the the important thing is that the abstraction is there.
‫OK, now we're going to create a function that will read the block for the disk.
‫So we just go in it disk read block struct desk disk unsigned and it albar in it, total void buff and
‫just rename this decipherable to iDesk.
‫And what we're going to say here is if iDesk does not equal the disk that we've created basically with
‫searching and then return minus EIO and we can resolve that later.
‫Otherwise return discrete sect LBA total.
‫So in the future if we implement a secondary disk, our discrete sector would take a some sort of base
‫part number to read from, which will be the base part number of that other disk, maybe the secondary
‫disk, maybe the primary.
‫And then we would obviously store that number in the disk structure here and then we would take that
‫out and pass it to the read sector.
‫But like I said, because there's only a primary disk, we can just call that.
‫We're just give an illusion here that there's more going on.
‫Right.
‫Which is important because it allows you to expand.
‫If you don't create abstraction, expanding later on becomes much more difficult.
‫OK, so we're going to include status, each of the top here as well, guys.
‫OK, and that looks OK, let's get some of this stuff in the header files, so this search and it put
‫that in, I had a file here.
‫OK, go back to this stuff, see get this get and we're going to put that in here as well.
‫We're going to put disc reblock in here as well, and we can actually remove this sector from this head
‫of our guys because this is a low level function.
‫We don't want higher levels in the kernel using this.
‫They should be using these abstracted functions here, passing in the disk into the reblock and stuff
‫like that.
‫Right.
‫So we can get rid of that one.
‫OK, so that looks absolutely fine like that now.
‫So now if we go to Colonel Dot, see, and just above IDC in it, we're going to go search and initialize
‫the disks disk search and in it.
‫OK, now if we go to the terminal here, I'm going to make a clean bill that S.H..
‫And we see a declaration give it to this thing from last lecture down here, guys, we don't need that
‫anymore and we're just going to run build again.
‫And we can see that boat's fine keeping kumu.
‫And there we are.
‫Everything works.
‫No panicking.
‫OK, so that concludes this lecture.
‫So we now have an abstraction.
‫So we should be able to do things like diskettes zero and then, you know, we can do things like desk
‫reads block and then, you know, we can pass in disked zero and then we could pass another LBA.
‫Maybe we want to read LBA 20.
‫We want to be four sectors and we can, you know, pass in the buffer here.
‫So you can see that's a lot cleaner.
‫Right, because now we're specifying the disk we want to read from as well.
‫Now I know at the lower levels there is no secondary disk, but the point is the abstraction, and that
‫is what we've done here successfully.
‫OK, thanks for watching.