Page 1 of 1
How to get filename of sector and disk type in INT 13h?
Posted: Mon Jan 16, 2017 3:44 pm
by WaterOS
Hi.
I need help to get the filename of a sector. Would that be possible? Basic programming in Assembly would be good. Also, how would I get the disk type e.g "0' or "1" for floppy and print it?
Thanks.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Mon Jan 16, 2017 4:21 pm
by sortie
Sectors don't have filenames. Harddisks are just a sequence of bytes, or rather, a sequence of blocks of 512 bytes. (Sector size may vary).
Your question doesn't make sense because of that. Maybe if you specified which filesystem is on the harddisk, we can make an algorithm for figuring out what file is stored at a given location, but that doesn't seem like what you are asking. I'll try to guess what you mean:
It sounds like you are doing some BIOS programming. There are resources on how to use the BIOS on the
osdev wiki. There are also online lists of what interrupts BIOSes offers. You can probably find a call for determining whether the device is a floppy or a harddisk or a cdrom or something else.
If you want to learn assembly programming, there are a lot of resources for this available online. You can find some information on the wiki, but I'm sure it's best to follow an online good assembly guide.
We can help you better if you clarify your question, ask the question again.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Mon Jan 16, 2017 6:57 pm
by Brendan
Hi,
WaterOS wrote:I need help to get the filename of a sector. Would that be possible? Basic programming in Assembly would be good.
It should be possible to determine the name/s of the file/s that use a specific sector. However, file systems are not designed for this - they're designed to do the opposite (find the sector/s for a file given the file name). This means that it's going to be extremely slow - e.g. check every file in every directory until you find one that uses the sector.
Also note that there are 3 possible cases:
- Sector is not used by any file: This should be obvious (e.g. sector is free, or used by directory information or metadata)
Sector is used by one file: This is what you seem to be expecting, and includes "sector is only partially used by a file" and "sector contains directory info and a tiny file" (e.g. ReiserFS "tail packing")
Sector is used by 2 or more files: This can happen due to file system's block size being smaller than sector size (e.g. FAT image stored on CD), packing tiny files together (e.g. the old "DriveSpace" disk compression Windows had), data deduplication, hard links (and symbolic links?), etc.
Of course there are very few sane reasons for wanting to do this in the first place; so it's probably better to describe why you think you want to do this (so that we have a chance to describe a much better way of doing whatever you think you're doing).
WaterOS wrote:Also, how would I get the disk type e.g "0' or "1" for floppy and print it?
That depends how often you want to be wrong. If you don't mind being wrong often, then you could assume that "BIOS device numbers" from 0x00 to 0x7F are floppies, "BIOS device numbers" from 0x80 to 0xBF are hard drives, and "BIOS device numbers" from 0xC0 to 0xFF are CD-ROMs.
If you want to be "less wrong, less often"; then you can try to use
"Int 0x13, ah=0x48" to get more information.
If you actually want to be "very right very often" (e.g. including knowing the difference between "hard disk connected to SATA" and "SSD connected to SATA") you have to stop using BIOS and start writing native drivers that don't suck.
Cheers,
Brendan
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 7:24 am
by WaterOS
I'm talking about FAT12.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 8:04 am
by Solar
How you would do this is very much depending on how you implemented your FAT 12 file system driver.
Int13h is a
BIOS-level way to access a given disk sector. The BIOS does not know about file systems, let alone file
names.
FAT12 is a way to organize those sectors,
described in the OSDev Wiki. If you have your file system driver organize data in this way, the disks you write can be read in again by any other FAT12-compatible driver on the same, or a different OS.
But how you
access those driver functions, from Assembly or otherwise, is up to your
implementation of the driver.
You
have a driver, haven't you?
Because otherwise, your question boils down to "how do I write a FAT12 driver"... which again would be very much depend on the implementation of the
rest of your OS...
You
have an OS, haven't you?
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 8:52 am
by WaterOS
I'm not really experienced with drivers right now. I only know basic things with printing strings, graphical things, loading kernel with INT 13h. How would I access the filename? By the way, what is the writing sectors thing for in INT 13h? I've got a BIOS parameter block.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 9:29 am
by SpyderTL
There is no easy way to find the filename for a sector using FAT12. It is designed more for finding all of the sectors that make up a specific file in a specific folder.
The only way you could do what you are asking would be to find the FAT (File Allocation Table), and read each file entry in that table, one by one, and then read each sector, one by one, until you find the one you are looking for. Then you would know what file contained that sector. But this probably isn't terribly useful.
For simplicity, just pretend that the FAT tables (there should be two of them on most disks) are just files that contain information about other files on the disk. To find where a file lives on the disk, you first have to find where the FAT tables live, and read then read them to find your file.
If you want to write data to a floppy disk, you can use INT 13h with AH=03h. It is very similar to reading data from a floppy disk with AH=02h.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 9:32 am
by iansjack
But why do you want to know which file a particular sector belongs to?
I can understand you wanting to know the opposite - which sectors belong to a particular file - but I can't see the use of what you ask.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 9:43 am
by WaterOS
SpyderTL wrote:There is no easy way to find the filename for a sector using FAT12. It is designed more for finding all of the sectors that make up a specific file in a specific folder.
The only way you could do what you are asking would be to find the FAT (File Allocation Table), and read each file entry in that table, one by one, and then read each sector, one by one, until you find the one you are looking for. Then you would know what file contained that sector. But this probably isn't terribly useful.
For simplicity, just pretend that the FAT tables (there should be two of them on most disks) are just files that contain information about other files on the disk. To find where a file lives on the disk, you first have to find where the FAT tables live, and read then read them to find your file.
If you want to write data to a floppy disk, you can use INT 13h with AH=03h. It is very similar to reading data from a floppy disk with AH=02h.
What is an example?
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 12:41 pm
by ggodw000
WaterOS wrote:Hi.
I need help to get the filename of a sector. Would that be possible? Basic programming in Assembly would be good. Also, how would I get the disk type e.g "0' or "1" for floppy and print it?
Thanks.
i am seeing it would be a quite difficult. I am assuming you want to know what kind of file certain sector belong to. File name exist on certain partition which is much higher level than blocks and sectors. You would not need to know how the disk is partitioned and depending on what kind of file system is installed (fat32, ext2) your search will be different. You would need complete knowledge of file system structures in order to do that.
Re: How to get filename of sector and disk type in INT 13h?
Posted: Tue Jan 17, 2017 1:04 pm
by SpyderTL
WaterOS wrote:SpyderTL wrote:There is no easy way to find the filename for a sector using FAT12. It is designed more for finding all of the sectors that make up a specific file in a specific folder.
The only way you could do what you are asking would be to find the FAT (File Allocation Table), and read each file entry in that table, one by one, and then read each sector, one by one, until you find the one you are looking for. Then you would know what file contained that sector. But this probably isn't terribly useful.
For simplicity, just pretend that the FAT tables (there should be two of them on most disks) are just files that contain information about other files on the disk. To find where a file lives on the disk, you first have to find where the FAT tables live, and read then read them to find your file.
If you want to write data to a floppy disk, you can use INT 13h with AH=03h. It is very similar to reading data from a floppy disk with AH=02h.
What is an example?
There is an example on the wiki page here:
http://wiki.osdev.org/FAT12#File_Allocation_Table
That wiki page has everything you need to read the tables and find the sectors that make up a file.
Unfortunately, you aren't going to find many examples that include reading the FAT tables and reading from the floppy drive using INT 10h at the same time. This code is usually separated, because the same INT 10h code works with other file systems, as well. (FAT16, FAT32, NTFS, ext2, etc.)
You are probably going to have to get your INT 10h function working, first. Then once you have the ability to read the FAT tables into memory, you can then write your FAT12 code.