How does DOS / Windows work out the volume serial number?

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
tom1000000

How does DOS / Windows work out the volume serial number?

Post by tom1000000 »

Hello,

I am probably being lazy and could find this info out if I could get hold of an open source format utility, but I'll ask anyway.

In the FAT specification it says the volume serial number is a 32bit value derived from the current date and time. It would have been really nice if they gave an example.

So if a disk is formatted at 2003 July 4, 12:15:34pm, how is that date / time converted to a 32 bit value by DOS??

Thanks!
Tim

Re:How does DOS / Windows work out the volume serial number?

Post by Tim »

You shouldn't need to know, unless you want to extract the date and time from the volume serial number. The only thing that's important is that two disks formatted at different times will get different serial numbers, which lets DOS tell them apart.
Curufir

Re:How does DOS / Windows work out the volume serial number?

Post by Curufir »

Think it goes a little like this:

Date is converted into this format:
[table]
[tr][td]bits[/td][td]15-9[/td][td]8-5[/td][td]4-0[/td][/tr]
[tr][td][/td][td]Year from 1980[/td][td]Month of year[/td][td]Day of month[/td][/tr]
[/table]
Time is converted into this format:
[table]
[tr][td]bits[/td][td]15-11[/td][td]10-5[/td][td]4-0[/td][/tr]
[tr][td][/td][td]Hours[/td][td]Minutes[/td][td]Seconds[/td][/tr]
[/table]

From memory the time occupies the first 2 bytes of the serial number, the date the second 2 bytes. Should be easy enough for you to figure out which is which anyhow.

Hope that helps.
tom1000000

Re:How does DOS / Windows work out the volume serial number?

Post by tom1000000 »

Hey thanks heaps. I would like to be able to work out when a disk was formatted. Also if you are writing a format utility, its good to use the same method DOS does.
tom1000000

Re:How does DOS / Windows work out the volume serial number?

Post by tom1000000 »

Hello,

Thanks for your help but it doesn't seem to be the right answer. Here is an example from an "chkdsk a:" :

The type of the file system is FAT.
Volume MS-DOS 6 created 6/28/2003 1:22 PM
Volume Serial Number is 1E21-14E7
Windows is verifying files and folders...
blah blah

Using the above formula doesn't seem to work :(. Any suggestions?
Curufir

Re:How does DOS / Windows work out the volume serial number?

Post by Curufir »

Apologies, got myself confused, those are the formats of date/time in directory/file entries :-[.

Kinda looks like nobody has ever bothered to write down exactly how MS creates the Volume ID field aside from that it involves the date, time and a 32 bit value. This page contains the best information I could dig up in 3 hours googling http://neworder.box.sk/newsread.php?newsid=3305. Now when I went and formatted a floppy on XP this didn't give the correct serial number, but I'm leaning towards the idea that MS is just using a random number now instead of creating one out of the date/time. Without disassembling format and taking a look I can't be sure.

If you figure it out then can you put a post on the board? It's bugging me now :).
Tim

Re:How does DOS / Windows work out the volume serial number?

Post by Tim »

I think chkdsk obtains the date and time of formatting from the date/time stamp of the volume ID:

Code: Select all

C:\>chkdsk
The type of the file system is FAT.
Volume Serial Number is 6239-00EF
Windows is verifying files and folders...
^C percent completed..
C:\>label fred

C:\>chkdsk
The type of the file system is FAT.
Volume FRED created 06/07/2003 23:11
Volume Serial Number is 6239-00EF
Windows is verifying files and folders...
^Cpercent completed...
C:\>
As you can see, if you run chkdsk on a drive without a label, it won't print a created date/time. As soon as you label it, it gets stamped with the current date and time. The serial number doesn't seem to come into it.
Curufir

Re:How does DOS / Windows work out the volume serial number?

Post by Curufir »

Thanks Tim, one less thing for me to worry about :).
Post Reply