OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 4:17 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How to (re)format a FAT drive?
PostPosted: Thu May 24, 2018 3:40 am 
Offline
Member
Member

Joined: Sun May 01, 2016 7:24 am
Posts: 29
Good morning!

Cosmos OS has good FAT support now you can read, write files, create directories and so on and all this using the normal C# System.IO classes... the missing part now is to format the HDD itself!
The HDD contains already a FAT32 file system with some files that I think was created in Windows so I've not need (for now) to init a totally empty drive but simply to (re)format it.

For now I'd like to support the quick and slow format how you could do on Windows but it is not clear to me what is the difference between these two and what operations I've to do.

Thanks for your help!

_________________
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!


Top
 Profile  
 
 Post subject: Re: How to (re)format a FAT drive?
PostPosted: Thu May 24, 2018 4:08 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
https://www.extremetech.com/extreme/804 ... ull-format


Top
 Profile  
 
 Post subject: Re: How to (re)format a FAT drive?
PostPosted: Thu May 24, 2018 6:53 am 
Offline
Member
Member

Joined: Sun May 01, 2016 7:24 am
Posts: 29
OK the article says regarding quick format:

Quote:
the format removes files from the partition, but does not scan the disk for bad sectors


it means that I should simply find the root directory and recursively remove all files / directory in it?
I don't think this will be a lot "quick"... I tough "quick format" simply removed the "references" to the files from the root directory and make appear all cluster as not in use (filling the FAT table with a special value I suppose).

_________________
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!


Top
 Profile  
 
 Post subject: Re: How to (re)format a FAT drive?
PostPosted: Thu May 24, 2018 7:23 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
"Removing the files" does mean removing the references to them in the directory, not wiping the data from the disk and reinitializing any meta-data (such as the FAT in this case). As far as the file system is concerned the files are removed (as far as recovery utilities are concerned they are not necessarily removed). It's a very quick operation.


Top
 Profile  
 
 Post subject: Re: How to (re)format a FAT drive?
PostPosted: Fri May 25, 2018 2:12 am 
Offline
Member
Member

Joined: Sun May 01, 2016 7:24 am
Posts: 29
Let's take this as example:

Image

I'll need to use File.Delete("Kudzu.txt") and Directory.Delete("Dir Testing", true) or something more low level? Directory.Delete(String path, bool recursive) obviously deletes all files and directories inside "Dir Testing" if they are a lot it will take a little time.
In the case of Cosmos we are tallking of 700 MB drive and I think less that 3 MB used so anything it will be "quick".

It is a lot of time that I've do not do a "quick" format of 300 GB drive really... I do not remember how "quick" is.

_________________
Member of the Cosmos OS CoreTeam
Cosmos Official Site
Do you to help us to develop it? Join our chat!


Top
 Profile  
 
 Post subject: Re: How to (re)format a FAT drive?
PostPosted: Fri May 25, 2018 2:41 am 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
In a quick format you should zero out the data in the root directory and mark all allocated clusters in the FAT as available.
On FAT32 the latter should exclude the clusters belonging to the root directory because it's variable-length and is stored as a chain of clusters similarly to any other file or non-root directory. You may also want to shrink the root directory on FAT32 to just one cluster if it's larger than that.

Also, AFAIR, on FAT32 there are two special values somewhere (boot sectors?) that tell how many clusters are free and which cluster to examine first when looking for a free one. You should update the former and you may also update the latter.

IOW, you need to reset the metadata for the FS to appear empty. You don't need to actually wipe data in all clusters. And you definitely shouldn't low-level-format each sector (that's what the full format does and that's why it's not quick).

P.S. quick format should make sure the counts, sizes, CHS/LBA and cluster values and so on are valid in the boot sectors and FAT cluster chains. Perhaps, an easier implementation should start by examining these (failing if something's horribly wrong) and then simply recreate everything (the root directory and the cluster chains, however, it should remember which clusters were marked bad and preserve those bad marks).


Top
 Profile  
 
 Post subject: Re: How to (re)format a FAT drive?
PostPosted: Fri May 25, 2018 5:19 pm 
Offline
Member
Member

Joined: Mon Jul 25, 2016 6:54 pm
Posts: 223
Location: Adelaide, Australia
So I quickly checked Wikipedia and there are three things you need to do to quick format FAT. In the file system information block, set the number of free clusters (offset 0x1E4) and the last allocated cluster (0x1E8) to 0xFFFFFFFF, then zero out the file allocation table, except the first two clusters (leave them be).
Technically you don't need to set the file system block info, because it's use is optional.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 761 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