<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Dear parted maintainers,</p>
    <p>I would like to add support for the ExFAT filesystem to parted.
      This includes displaying correctly ExFAT partitions and
      interpreting "exfat" as a correct entry when specifying the fs
      type upon partition creation.</p>
    <p>Please find my implementation below. I relied on the official
      specs publicly released by Microsoft in 2019 for fs signature and
      allocation size detection and i used mostly the current
      implementation of ntfs as a reference. It has been tested to the
      best of my knowledge, but this is my first contribution to a GNU
      project, let me know if this submission needs rework.</p>
    <p>Have a nice day.</p>
    <p>Victor Couty</p>
    <pre>diff --git a/doc/C/parted.8 b/doc/C/parted.8
index c852112..13973fa 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -81,7 +81,7 @@ should be one of "aix", "amiga", "bsd", "dvh", "gpt", "loop", "mac", "msdos",
 Create a new partition. \fIpart-type\fP may be specified only with msdos and
 dvh partition tables, it should be one of "primary", "logical", or "extended".
 \fIname\fP is required for GPT partition tables and \fIfs-type\fP is optional.
-\fIfs-type\fP can be one of "btrfs", "ext2", "ext3", "ext4", "fat16", "fat32",
+\fIfs-type\fP can be one of "btrfs", "exfat", "ext2", "ext3", "ext4", "fat16", "fat32",
 "hfs", "hfs+", "linux-swap", "ntfs", "reiserfs", "udf", or "xfs".
 .TP
 .B name \fIpartition\fP \fIname\fP
diff --git a/doc/parted.texi b/doc/parted.texi
index 5d4074d..10fdd3e 100644
--- a/doc/parted.texi
+++ b/doc/parted.texi
@@ -624,6 +624,7 @@ partition table.
 @itemize @bullet
 @item btrfs
 @item ext2, ext3, ext4
+@item exfat
 @item fat16, fat32
 @item hfs, hfs+, hfsx
 @item hp-ufs
diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
index 7fa8d14..66cbffd 100644
--- a/libparted/fs/Makefile.am
+++ b/libparted/fs/Makefile.am
@@ -28,6 +28,7 @@ libfs_la_SOURCES =            \
   ext2/ext2.h                  \
   ext2/ext2_fs.h               \
   ext2/interface.c             \
+  exfat/exfat.c                        \
   fat/bootsector.c             \
   fat/bootsector.h             \
   fat/count.h                  \
diff --git a/libparted/fs/exfat/exfat.c b/libparted/fs/exfat/exfat.c
new file mode 100644
index 0000000..87bdafc
--- /dev/null
+++ b/libparted/fs/exfat/exfat.c
@@ -0,0 +1,74 @@
+/*
+libparted
+    Copyright (C) 1998-2000, 2002, 2004, 2007, 2009-2014, 2019-2023 Free
+    Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <a class="moz-txt-link-rfc2396E" href="http://www.gnu.org/licenses/"><http://www.gnu.org/licenses/></a>.
+*/
+
+#include <config.h>
+
+#include <parted/parted.h>
+#include <parted/endian.h>
+
+#include <unistd.h>
+
+#define EXFAT_SIGNATURE "EXFAT   "
+
+static PedGeometry* exfat_probe (PedGeometry* geom)
+{
+    uint8_t *buf = alloca(geom->dev->sector_size);
+
+    if (!ped_geometry_read(geom, buf, 0, 1)) {
+        return NULL;
+    }
+    if (strncmp (EXFAT_SIGNATURE, ((char *)buf + 3), strlen (EXFAT_SIGNATURE)) == 0) {
+        uint64_t sector_count;
+        unsigned char bytes_per_sector_shift;
+        uint64_t fs_size;
+        PedGeometry *newg = NULL;
+
+        memcpy(&sector_count, buf + 0x48, sizeof(uint64_t));
+        memcpy(&bytes_per_sector_shift, buf + 0x6c, sizeof(unsigned char));
+        if (bytes_per_sector_shift < 9 || bytes_per_sector_shift > 12) {
+            return NULL;
+        }
+        fs_size = sector_count * (1ULL << bytes_per_sector_shift);
+        newg = ped_geometry_new(geom->dev, geom->start, fs_size);
+
+        return newg;
+    }
+
+    return NULL;
+}
+
+static PedFileSystemOps exfat_ops = {
+    probe: exfat_probe,
+};
+
+static PedFileSystemType exfat_type = {
+    next: NULL,
+    ops: &exfat_ops,
+    name: "exfat",
+};
+
+void ped_file_system_exfat_init()
+{
+    ped_file_system_type_register (&exfat_type);
+}
+
+void ped_file_system_exfat_done ()
+{
+    ped_file_system_type_unregister (&exfat_type);
+}
diff --git a/libparted/libparted.c b/libparted/libparted.c
index 204ce00..16ff7fa 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -115,6 +115,7 @@ extern void ped_file_system_ext2_init (void);
 extern void ped_file_system_nilfs2_init (void);
 extern void ped_file_system_btrfs_init (void);
 extern void ped_file_system_udf_init (void);
+extern void ped_file_system_exfat_init (void);
 
 static void
 init_file_system_types ()
@@ -133,6 +134,7 @@ init_file_system_types ()
        ped_file_system_nilfs2_init ();
        ped_file_system_btrfs_init ();
        ped_file_system_udf_init ();
+       ped_file_system_exfat_init ();
 }
 
 extern void ped_disk_aix_done ();
@@ -200,6 +202,7 @@ extern void ped_file_system_xfs_done (void);
 extern void ped_file_system_amiga_done (void);
 extern void ped_file_system_btrfs_done (void);
 extern void ped_file_system_udf_done (void);
+extern void ped_file_system_exfat_done (void);
 
 static void
 done_file_system_types ()
@@ -218,6 +221,7 @@ done_file_system_types ()
        ped_file_system_amiga_done ();
        ped_file_system_btrfs_done ();
        ped_file_system_udf_done ();
+       ped_file_system_exfat_done ();
 }
 
 static void _done() __attribute__ ((destructor));

</pre>
    <p><br>
    </p>
  </body>
</html>