OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 12:54 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: How to get filename of sector and disk type in INT 13h?
PostPosted: Mon Jan 16, 2017 3:44 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Mon Jan 16, 2017 4:21 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
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.


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Mon Jan 16, 2017 6:57 pm 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 7:24 am 
Offline
Member
Member

Joined: Mon Jan 16, 2017 3:39 pm
Posts: 25
I'm talking about FAT12.


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 8:04 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
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.


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 8:52 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 9:29 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 9:32 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 9:43 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 12:41 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: How to get filename of sector and disk type in INT 13h?
PostPosted: Tue Jan 17, 2017 1:04 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 129 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group