FAT and Physical Disk Information

This is a discussion on FAT and Physical Disk Information within the Tech Board forums, part of the Community Boards category; Are you sure windows is misreading it or are you just getting confused with the difference between 1 megabyte and ...

  1. #16
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Are you sure windows is misreading it or are you just getting confused with the difference between 1 megabyte and 1 million bytes (they aren't the same).
    Man, I'm a programmer.

    There are many scam USB drives from China (less than reputable vendors) that intentionally mislabel flash drives. It would say, for example, 4GB on the box and the drive, and Windows would detect it as a 4GB drive, and it will work fine until you try to write, say, more than 128MB of data to it. Then bad things start to happen.
    You missed the point. How Windows or any other software can obtain disk size info? Its only FAT or there is some other place? There can be a readonly sector on disk to keep such info!
    Imagine a fake Flash Mem like your example. It is 256MBs. But it has fake info in it(beside the label) that makes Windows think that its a 4GBs one. Can we fix this by knowing the exact disk specs and rewrite them on FAT? Can we obtain exact right specs from flash somehow?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #17
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by siavoshkc View Post
    Man, I'm a programmer.


    You missed the point. How Windows or any other software can obtain disk size info? Its only FAT or there is some other place? There can be a readonly sector on disk to keep such info!
    Imagine a fake Flash Mem like your example. It is 256MBs. But it has fake info in it(beside the label) that makes Windows think that its a 4GBs one. Can we fix this by knowing the exact disk specs and rewrite them on FAT? Can we obtain exact right specs from flash somehow?
    That's what I was originally trying to point out, actually. All hardware devices contain control registers that provide access to that information. The problem is you have to know how the OS maps to that device (used to be that I/O ports that could be accessed directly with assembly, but now I think the situation is more complicated) and the protocol required to communicate to that specific device (and USB is not simple in that respect). That said, there may be an existing library that can do all that, but I haven't personally seen one myself. Writing a device driver and USB software interface isn't exactly trivial, so I think your best bet is to find a flash-drive format tool (I've heard Hewlett-Packard has one that works for all kinds - just be careful where you download it from, obviously).

  3. #18
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    You missed the point. How Windows or any other software can obtain disk size info? Its only FAT or there is some other place? There can be a readonly sector on disk to keep such info!
    Imagine a fake Flash Mem like your example. It is 256MBs. But it has fake info in it(beside the label) that makes Windows think that its a 4GBs one. Can we fix this by knowing the exact disk specs and rewrite them on FAT? Can we obtain exact right specs from flash somehow?
    I didn't post it as a solution to your problem. It's just a FYI thing .

  4. #19
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    Quote Originally Posted by siavoshkc View Post
    Can we fix this by knowing the exact disk specs and rewrite them on FAT? Can we obtain exact right specs from flash somehow?
    To my knowledge you get this information from the FAT. However it is not shown in itself. The first 32 bits of the FAT contain it somewhere. You need to find the offsets for the following information:

    B. Bytes per Sector
    S. Sectors per Cluster
    C. Number of Clusters

    The partition size is then a simple mathematical exercise.

    Do note that there may be two offsets for C. One is 2 bytes which may read 0 in which case you'll need to find the other of 4 bytes for larger disk sizes. The FAT structure can be found a little all over the web.

    Another place to get the disk size is the MBR. I'm unsure how to get to it, but just grab some documentation on its structure. I suspect this to be the best place since it contains information for all disk partitions and you won't have to be fishing around for FATs. However the structure is certainly more complex and deserves a little more study.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #20
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by abachler View Post
    Are you sure windows is misreading it or are you just getting confused with the difference between 1 megabyte and 1 million bytes (they aren't the same).
    Actually they are (now), you should be using the new terms "Mibibyte" if you mean 2^20 bytes . Unless you disagree with the IEC 60027 standard.

  6. #21
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    The FAT is not the authoratative source for disk size information. Never was, never will be. How you get the actual size is probably hardware dependent, and certainly, from a program's point-of-view, OS dependent.

    Quote Originally Posted by zacs7
    Actually they are (now), you should be using the new terms "Mibibyte" if you mean 2^20 bytes . Unless you disagree with the IEC 60027 standard.
    I can't stand that "standard". First, let me acknowledge by bias - these terms sound retarded as hell. "Pebibyte", I mean... really?

    First, I cannot use the terms professionally. One, nobody would know what I'm talking about, and two, they would not stop laughing. "MiB" sorta works in writing, but the terms are not widespread enough.

    Second, what's the point? 1,000 bytes is meaningless in most contexts. 1,024 is a round number (;-)) and it's meaningfully - generally 2 sectors, a power of 2, etc. Take the other perspective - if someone says "1 KB" or "1 kilobyte", they probably mean 1,024 bytes.

    Kibibyte... right. Stupid disk manufacturers.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #22
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    So, the real answer to the initial question is that nobody knows?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #23
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    IOCTL_DISK_GET_DRIVE_GEOMETRY

    IOCTL_DISK_GET_DRIVE_GEOMETRY

    This takes the geometry of the physical disk, not whatever garbage is reported in the MBR
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #24
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Cactus_Hugger View Post
    Kibibyte... right. Stupid disk manufacturers.
    Yeah I kind of roll my eyes whenever i see the kibibit, mibibyte thing. Everyone knows that disk manufacturers call a megabyte 1 million bytes, not 1048576 bytes, which it actually is. They are the ONLY ones that do so, so there is no reason to rewrite all the technical documentation to accommodate their arrogance. It's really a joke that they even think they are the authority on such matters. It would be like the automotive industry thinking it is the authority on what a mile is, and deciding they would call a mile 5000 feet so they could boost their speeds and MPG ratings, then expecting everyone else in all other fields to call 5280 feet a 'myle'.
    Last edited by abachler; 08-20-2009 at 01:41 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  10. #25
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    It would be like the automotive industry thinking it is the authority on what a mile is, and deciding they would call a mile 5000 feet so they could boost their speeds and MPG ratings, then expecting everyone else in all other fields to call 5280 feet a 'myle'.
    It's a little different than that. The prefixes kilo, mega, giga, existed long before computers came around. Someone can just as easily argue that it was computer engineers who modified the terms to mean something else than they originally did (kilo now means 1024 instead of 1000).

    That being said, "kibibyte" just sounds stupid.
    bit∙hub [bit-huhb] n. A source and destination for information.

  11. #26
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Sure "kibibyte" may sound stupid, but "kilo" is a SI-prefix for 1000 (since the year 1795 it seems), so I would say "the computer industry" got it wrong from the start. If anything the disk manufacturers have done the technically correct thing.

    Excuse me for living in the 21st century with the metric system

    That being said, I won't be using the "kibi"-like prefixes since they're stupid, even if they are correct. :-)
    Last edited by zacs7; 08-20-2009 at 05:10 AM.

  12. #27
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by bithub View Post
    It's a little different than that. The prefixes kilo, mega, giga, existed long before computers came around. Someone can just as easily argue that it was computer engineers who modified the terms to mean something else than they originally did (kilo now means 1024 instead of 1000).

    That being said, "kibibyte" just sounds stupid.
    except that computer engineers reassign the metric for kilo etc only within their specialized field.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  13. #28
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    Quote Originally Posted by brewbuck View Post
    IOCTL_DISK_GET_DRIVE_GEOMETRY

    IOCTL_DISK_GET_DRIVE_GEOMETRY

    This takes the geometry of the physical disk, not whatever garbage is reported in the MBR
    Nice brewbuck, thanks. That definitely puts us in the right track.

    Reading through it though, I feel the need to point out that the above IOCTL does use the MBR exclusively. It's also obsolete. You may be referring to IOCTL_DISK_GET_DRIVE_GEOMETRY_EX.

    The difference between IOCTL_DISK_GET_DRIVE_GEOMETRY_EX and the older IOCTL_DISK_GET_DRIVE_GEOMETRY request is that IOCTL_DISK_GET_DRIVE_GEOMETRY_EX can retrieve information from both Master Boot Record (MBR) and GUID Partition Table (GPT)-type partitioned media, whereas IOCTL_DISK_GET_DRIVE_GEOMETRY can only read MBR-style media.
    In any case, this also offers the needed information on where to look in case one doesn't want to use the WinAPI.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #29
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    This takes the geometry of the physical disk, not whatever garbage is reported in the MBR
    The difference between IOCTL_DISK_GET_DRIVE_GEOMETRY_EX and the older IOCTL_DISK_GET_DRIVE_GEOMETRY request is that IOCTL_DISK_GET_DRIVE_GEOMETRY_EX can retrieve information from both Master Boot Record (MBR) and GUID Partition Table (GPT)-type partitioned media, whereas IOCTL_DISK_GET_DRIVE_GEOMETRY can only read MBR-style media.
    It still doesn't say where that informaion are read from.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  15. #30
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    I don't feel like studying the MBR and GPT structures for you. Thank you very much.
    I thought it would be clear by now all you need to do is study them yourself. You are bound to get this information from online references.

    Start here. And after that get to the External References and Further Reading sections at the bottom.
    GUID Partition Table - Wikipedia, the free encyclopedia
    Master boot record - Wikipedia, the free encyclopedia
    Last edited by Mario F.; 08-29-2009 at 01:02 PM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where is my file on disk
    By Salem in forum Windows Programming
    Replies: 7
    Last Post: 10-28-2007, 05:41 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21