Karel Zak wrote:
> On Fri, Jul 06, 2007 at 06:32:31PM -0700, H. Peter Anvin wrote:
>> Newer Micro$oft operating systems (NT 3 and later) put a 4-byte
>> signature in the MBR at offset 440 decimal. Generate a random such
>> signature when creating a new disk label, and allow it to be changed.
>
> Applied, thanks.
>
> fdisk.c: In function ‘get_random_id’:
> fdisk.c:160: warning: implicit declaration of function ‘time’
> fdisk.c: In function ‘create_doslabel’:
> fdisk.c:803: warning: unused variable ‘i’
>
> fixed ;-)
>
>
> BTW, I've read libparted code and there is:
>
> static inline uint32_t generate_random_id()
> {
> struct timeval tv;
> int rc;
> rc = gettimeofday(&tv, NULL);
> if (rc == -1)
> return 0;
> return (uint32_t)(tv.tv_usec & 0xFFFFFFFFUL);
> }
That explains why all the IDs of the disks I've looked at seem to be
limited to 20 bits -- that will always produce a value that is less than
0x000f4240. It's a parted bug. If you're going to use gettimeofday()
(which isn't a bad idea if urandom is not available) the best option is
probably:
(uint32_t)(tv.tv_sec*1000000+tv.tv_usec);
although /dev/urandom is probably better still.
-hpa
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html