bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] To add FreeBSD GPT partitions


From: Arun Sharma
Subject: Re: [PATCH] To add FreeBSD GPT partitions
Date: Fri, 25 Jun 2004 15:06:26 -0700
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hi Andrew,

On 6/17/2004 4:49 PM, Andrew Clausen wrote:

On Thu, Jun 17, 2004 at 03:50:12PM -0700, Arun Sharma wrote:
>>The filesystem probe routines are dummy and should not be used. The main >>intent is to be able to create the GUID partitions but not necessarily >>create the filesystem or probe it correctly.
>
>Can we make them work properly?

I was not aware of a mkfs.ufs for Linux. But someone seems to have ported them to Linux recently:

http://lists.debian.org/debian-devel/2004/03/msg02088.html

Probe != mkfs.  Probe is just "tell me if this is a freebsd-ufs
filesystem".  I'm assuming this is 5 lines of code.


Attached is a patch with the filesystem probe code. We should probably not be using this 
probe code with "freebsd-swap". But I can't see how else to provide the 
capability to add a GPT partition with the correct GUID.

        -Arun
--- parted-1.6.11/libparted/fs_ufs/ufs.c-       2004-03-09 02:13:06.000000000 
-0800
+++ parted-1.6.11/libparted/fs_ufs/ufs.c        2004-06-25 14:56:44.000000000 
-0700
@@ -45,6 +45,7 @@
 #define UFS_MAGIC_LFN  0x00095014
 #define UFS_MAGIC_FEA  0x00195612
 #define UFS_MAGIC_4GB  0x05231994
+#define UFS2_MAGIC     0x19540119
 
 struct ufs_csum {
        uint32_t        cs_ndir;        /* number of directories */
@@ -239,6 +240,38 @@
        return NULL;
 }
 
+static PedGeometry*
+ufs_probe_freebsd(PedGeometry* geom)
+{
+       int8_t buf[512 * 3];
+       struct ufs_super_block *sb;
+
+       if (geom->length < 5)
+               return 0;
+       if (!ped_geometry_read (geom, buf, 16, 3))
+               return 0;
+
+       sb = (struct ufs_super_block *)buf;
+
+       /* Little endian is more likely on FreeBSD boxes */
+       if (PED_LE32_TO_CPU(sb->fs_magic) == UFS_MAGIC
+               || PED_LE32_TO_CPU(sb->fs_magic) == UFS2_MAGIC) {
+               PedSector block_size = PED_LE32_TO_CPU(sb->fs_bsize) / 512;
+               PedSector block_count = PED_LE32_TO_CPU(sb->fs_size);
+               return ped_geometry_new (geom->dev, geom->start,
+                                        block_size * block_count);
+       }
+
+       if (PED_BE32_TO_CPU(sb->fs_magic) == UFS_MAGIC
+               || PED_BE32_TO_CPU(sb->fs_magic) == UFS2_MAGIC) {
+               PedSector block_size = PED_BE32_TO_CPU(sb->fs_bsize) / 512;
+               PedSector block_count = PED_BE32_TO_CPU(sb->fs_size);
+               return ped_geometry_new (geom->dev, geom->start,
+                                        block_size * block_count);
+       }
+       return NULL;
+}
+
 #ifndef DISCOVER_ONLY
 static int
 ufs_clobber (PedGeometry* geom)
@@ -290,6 +323,24 @@
        get_copy_constraint:    NULL
 };
 
+static PedFileSystemOps ufs_ops_freebsd = {
+       probe:          ufs_probe_freebsd,
+#ifndef DISCOVER_ONLY
+       clobber:        ufs_clobber,
+#else
+       clobber:        NULL,
+#endif
+       open:           NULL,
+       create:         NULL,
+       close:          NULL,
+       check:          NULL,
+       copy:           NULL,
+       resize:         NULL,
+       get_create_constraint:  NULL,
+       get_resize_constraint:  NULL,
+       get_copy_constraint:    NULL
+};
+
 static PedFileSystemType ufs_type_sun = {
        next:   NULL,
        ops:    &ufs_ops_sun,
@@ -302,6 +353,18 @@
        name:   "hp-ufs"
 };
 
+static PedFileSystemType ufs_type_freebsd_ufs = {
+       next:   NULL,
+       ops:    &ufs_ops_freebsd,
+       name:   "freebsd-ufs"
+};
+
+static PedFileSystemType ufs_type_freebsd_swap = {
+       next:   NULL,
+       ops:    &ufs_ops_freebsd,
+       name:   "freebsd-swap"
+};
+
 void
 ped_file_system_ufs_init ()
 {
@@ -309,11 +372,15 @@
 
        ped_file_system_type_register (&ufs_type_sun);
        ped_file_system_type_register (&ufs_type_hp);
+       ped_file_system_type_register (&ufs_type_freebsd_ufs);
+       ped_file_system_type_register (&ufs_type_freebsd_swap);
 }
 
 void
 ped_file_system_ufs_done ()
 {
+       ped_file_system_type_unregister (&ufs_type_freebsd_swap);
+       ped_file_system_type_unregister (&ufs_type_freebsd_ufs);
        ped_file_system_type_unregister (&ufs_type_hp);
        ped_file_system_type_unregister (&ufs_type_sun);
 }
--- parted-1.6.11/libparted/disk_gpt.c.orig     2004-03-10 14:11:42.000000000 
-0800
+++ parted-1.6.11/libparted/disk_gpt.c  2004-06-09 18:19:33.000000000 -0700
@@ -111,6 +111,25 @@
     ((efi_guid_t) { PED_CPU_TO_LE32 (0xe2a1e728), PED_CPU_TO_LE16 (0x32e3), \
                    PED_CPU_TO_LE16 (0x11d6), 0xa6, 0x82, \
                    { 0x7b, 0x03, 0xa0, 0x00, 0x00, 0x00 }})
+#define PARTITION_FREEBSD_GUID \
+   ((efi_guid_t) { PED_CPU_TO_LE32 (0x516e7cb4), PED_CPU_TO_LE16 (0x6ecf), \
+                   PED_CPU_TO_LE16 (0x11d6), 0x8f, 0xf8, \
+                   { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }})
+
+#define PARTITION_FREEBSD_SWAP_GUID \
+   ((efi_guid_t) { PED_CPU_TO_LE32 (0x516e7cb5), PED_CPU_TO_LE16 (0x6ecf), \
+                   PED_CPU_TO_LE16 (0x11d6), 0x8f, 0xf8, \
+                   { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }})
+
+#define PARTITION_FREEBSD_UFS_GUID \
+   ((efi_guid_t) { PED_CPU_TO_LE32 (0x516e7cb6), PED_CPU_TO_LE16 (0x6ecf), \
+                   PED_CPU_TO_LE16 (0x11d6), 0x8f, 0xf8, \
+                   { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }})
+
+#define PARTITION_FREEBSD_VINUM_GUID \
+   ((efi_guid_t) { PED_CPU_TO_LE32 (0x516e7cb8), PED_CPU_TO_LE16 (0x6ecf), \
+                   PED_CPU_TO_LE16 (0x11d6), 0x8f, 0xf8, \
+                   { 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }})
 
 typedef struct _GuidPartitionTableHeader_t {
        uint64_t Signature;
@@ -951,10 +970,21 @@
                        gpt_part_data->type = PARTITION_MSFT_RESERVED_GUID;
                        return 1;
                }
-               if (strstr (fs_type->name, "swap")) {
+
+               if (strncmp(fs_type->name, "swap", 4) == 0) {
                        gpt_part_data->type = PARTITION_SWAP_GUID;
                        return 1;
                }
+
+               if (strncmp(fs_type->name, "freebsd-swap", 12) == 0) {
+                       gpt_part_data->type = PARTITION_FREEBSD_SWAP_GUID;
+                       return 1;
+               }
+
+               if (strncmp(fs_type->name, "freebsd-ufs", 11) == 0) {
+                       gpt_part_data->type = PARTITION_FREEBSD_UFS_GUID;
+                       return 1;
+               }
        }
 
        gpt_part_data->type = PARTITION_BASIC_DATA_GUID;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]