How to get filename of sector and disk type in INT 13h?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
WaterOS
Member
Member
Posts: 25
Joined: Mon Jan 16, 2017 3:39 pm

How to get filename of sector and disk type in INT 13h?

Post 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.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: How to get filename of sector and disk type in INT 13h?

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: How to get filename of sector and disk type in INT 13h?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
WaterOS
Member
Member
Posts: 25
Joined: Mon Jan 16, 2017 3:39 pm

Re: How to get filename of sector and disk type in INT 13h?

Post by WaterOS »

I'm talking about FAT12.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How to get filename of sector and disk type in INT 13h?

Post 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?

8)
Every good solution is obvious once you've found it.
WaterOS
Member
Member
Posts: 25
Joined: Mon Jan 16, 2017 3:39 pm

Re: How to get filename of sector and disk type in INT 13h?

Post 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.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: How to get filename of sector and disk type in INT 13h?

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to get filename of sector and disk type in INT 13h?

Post 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.
WaterOS
Member
Member
Posts: 25
Joined: Mon Jan 16, 2017 3:39 pm

Re: How to get filename of sector and disk type in INT 13h?

Post 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?
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: How to get filename of sector and disk type in INT 13h?

Post 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.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: How to get filename of sector and disk type in INT 13h?

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply