OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: FAT programs not filling FAT tables
PostPosted: Tue Jun 12, 2018 3:06 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Hello,

I've ran into a big problem. The programs I use for virtual HDD management don't want to work anymore, or at least they never have?
This is my setup: FAT 32 partitioned virtual HDD image that I put all the files on and that I use for testing.
So the problem is: when I try to copy a file called Stage_2.sys it gets copied internally but no file allocation table data is being provided, no FAT entries related to that file whatsoever?
Any ideas?

mcopy (mtools) -> same thing
kpartx -> same thing

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Tue Jun 12, 2018 11:33 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
Hi Octacone,

If I were to completely guess, without any more information, I would have to say that you are looking in the wrong place for the table and the table is indeed being written to.

Just my guess.

Ben
- http://www.fysnet.net/osdesign_book_series.htm


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Wed Jun 13, 2018 12:26 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
@BenLunt

I don't think that can be the case. I have a program called "Active @ Disk Editor" that allows me to easily navigate around.
With just one click of a button I can go to standard filesystem locations (such as FAT tables).

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Wed Jun 13, 2018 12:58 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 10, 2016 7:35 am
Posts: 167
Location: Lancaster, England, Disunited Kingdom
Octacone wrote:

So the problem is: when I try to copy a file called Stage_2.sys it gets copied internally but no file allocation table data is being provided, no FAT entries related to that file whatsoever?


I'm struggling with this because it's not quite clear to me how much partial success your copy has had.

Please can you clarify exactly what you mean by "it gets copied internally" and how do you know this?
Is the FAT32 volume visible to Windows?
If so does the directory listing show the copied file or not?

I've use ActiveDisk too but find it needs a bit more guidance than I would expect. For example, the template pane can often be looking at a different bit of memory from the main hex display and the default template displayed is often very much an uninformed guess by the program. The user has to be quite alert to ensure an appropriate template is picked and that the hex display point matches the template display point and that both point to an appropriate place for the selected template.


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Wed Jun 13, 2018 1:08 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
@MichaelFarthing

Okay so when I look inside the root directory there is a valid entry present, everything contained within the file can also be found at sector x and y (standard stuff), but there are no FAT entries present.
Btw I use Linux, not Windows. I am well aware of those issues, but they are just some minor bugs that can be worked around.
How am I supposed to follow the cluster chain when there is no one to follow?
Yes, Linux shows that file (inside its file manager app) just fine.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Wed Jun 13, 2018 1:47 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I've got to agree with Ben - you are looking in the wrong place for the FAT. It is most unlikely that three separate methods of copying the file would produce identical errors.


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Wed Jun 13, 2018 1:57 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
Octacone wrote:
Okay so when I look inside the root directory there is a valid entry present, everything contained within the file can also be found at sector x and y (standard stuff), but there are no FAT entries present.
...
How am I supposed to follow the cluster chain when there is no one to follow?
Yes, Linux shows that file (inside its file manager app) just fine.


And just how do you know those "x and y (standard stuff)", especially when there's more than one "x"? And how do you know where the root directory or the file ends? To know that you'd need to access the cluster chain. If Linux is able to do it and you "observe" problems with several different tools, it's very likely the problem is actually in your code and not elsewhere. Somehow you aren't calculating the location correctly. You must be able to see the last cluster markers for the root directory and for the file (and all preceding clusters in the chain if the size is larger than one cluster).

Start with a clean FAT32-formatted disk image (no files, just the root dir). Look (with your hex editor?) for the two reserved entries for clusters numbered 0 and 1. Those should typically be 0x0F.FF.FF.F8 and 0x0F.FF.FF.FF. If your FAT32 root directory starts at cluster 2 (typical), then the next value should also be 0x0F.FF.FF.FF. Your calculations should give you the sector where you find these three values. I bet the are off by something.

P.S. If you don't find those two/three values anywhere, check with fatgen103.doc. The doc allows for different EOC values, there are reserved bits in FAT32 cluster values, etc etc.


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 6:58 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
I am not doing anything manually. There is a button that says FAT (1), when I press it, it opens a sector which contains the FAT itself so I can take a look at it.
Yes I can see all the reserved entries. I am certain that my code works just fine, I followed the official documentation.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 8:00 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I take it your stage2 is more than one cluster in size. Otherwise the FAT chain will just consist of the one entry FF FF FF 0F.


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 10:07 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Sure, it has more than 512 bytes. 821 bytes to be precise.

Edit: this is what my editor looks like:
Attachment:
My_Hex_Editor.png
My_Hex_Editor.png [ 99.61 KiB | Viewed 5298 times ]

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 10:30 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I would have thought that, on a hard disk, your clusters would be larger than just one sector.


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 11:01 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
What are you trying to point out?
Are you saying that since a cluster is 4 KB in size I should load 8 contiguous 512 byte sectors one after another?
Wait, so a file will always span across 8 512 byte sectors, even if it is just 821 bytes long?

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 11:15 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Octacone wrote:
Wait, so a file will always span across 8 512 byte sectors, even if it is just 821 bytes long?
Yes. This is basic stuff. Clusters and sectors are not the same. FATs record clusters, not sectors.

If your clusters are 4KBthen a 1-byte file will occupy 4KB on the disk.


Top
 Profile  
 
 Post subject: Re: FAT programs not filling FAT tables
PostPosted: Fri Jun 15, 2018 11:29 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Thanks man!

I had an entirely different concept in my head, looks like I screwed something up. Guess I wasn't careful while reading...
Sorry for bothering you all, just a silly mistake.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 22 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