On Sat, Jun 07, 2008 at 01:22:23AM +0800, Bean wrote:
> > Then for the Vista use case, I suppose the remaining questions are if NTFS
> > supports UUIDs (or otherwise we have to ressort to labels?), and if we can
> > extract filesystem metadata from Windows (if possible without requiring that
> > a Cygwin installation is present).
> 
> ntfs has a 64-bit serial number, it's not quite the same as uuid, but
> it can be used to identify the partition.

This patch adds the 64-bit serial number as UUID.  But I'm not sure what is the
"standard" method to stringify this number.  Apparently, Windows only prints
half of it in the dir command.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)
diff -x ChangeLog -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../grub2/fs/ntfs.c ./fs/ntfs.c
--- ../grub2/fs/ntfs.c	2008-05-29 15:02:13.000000000 +0200
+++ ./fs/ntfs.c	2008-06-07 01:28:13.000000000 +0200
@@ -830,6 +830,8 @@ grub_ntfs_mount (grub_disk_t disk)
       (disk, data->mft_start, 0, data->mft_size << BLK_SHR, data->mmft.buf))
     goto fail;
 
+  *((grub_uint64_t *) &data->uuid) = bpb.num_serial;
+
   if (fixup (data, data->mmft.buf, data->mft_size, "FILE"))
     goto fail;
 
@@ -1078,6 +1080,36 @@ fail:
   return grub_errno;
 }
 
+static grub_err_t
+grub_ntfs_uuid (grub_device_t device, char **uuid)
+{
+  struct grub_ntfs_data *data;
+  grub_disk_t disk = device->disk;
+
+#ifndef GRUB_UTIL
+  grub_dl_ref (my_mod);
+#endif
+
+  data = grub_ntfs_mount (disk);
+  if (data)
+    {
+      *uuid = grub_malloc (sizeof ("xxxx-xxxx-xxxx-xxxx"));
+      grub_sprintf (*uuid, "%04x-%04x-%04x-%04x",
+		    grub_le_to_cpu16 (data->uuid[0]), grub_le_to_cpu16 (data->uuid[1]),
+		    grub_le_to_cpu16 (data->uuid[2]), grub_le_to_cpu16 (data->uuid[3]));
+    }
+  else
+    *uuid = NULL;
+
+#ifndef GRUB_UTIL
+  grub_dl_unref (my_mod);
+#endif
+
+  grub_free (data);
+
+  return grub_errno;
+}
+
 static struct grub_fs grub_ntfs_fs = {
   .name = "ntfs",
   .dir = grub_ntfs_dir,
@@ -1085,6 +1117,7 @@ static struct grub_fs grub_ntfs_fs = {
   .read = grub_ntfs_read,
   .close = grub_ntfs_close,
   .label = grub_ntfs_label,
+  .uuid = grub_ntfs_uuid,
   .next = 0
 };
 
diff -x ChangeLog -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../grub2/include/grub/ntfs.h ./include/grub/ntfs.h
--- ../grub2/include/grub/ntfs.h	2008-04-07 16:34:45.000000000 +0200
+++ ./include/grub/ntfs.h	2008-06-07 01:17:44.000000000 +0200
@@ -115,7 +115,7 @@ struct grub_ntfs_bpb
   grub_int8_t reserved_4[3];
   grub_int8_t clusters_per_index;
   grub_int8_t reserved_5[3];
-  grub_uint64_t serial_number;
+  grub_uint64_t num_serial;
   grub_uint32_t checksum;
 } __attribute__ ((packed));
 
@@ -151,6 +151,7 @@ struct grub_ntfs_data
   grub_uint32_t spc;
   grub_uint32_t blocksize;
   grub_uint32_t mft_start;
+  grub_uint16_t uuid[4];
 };
 
 struct grub_ntfs_comp
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to