summaryrefslogtreecommitdiff
path: root/libparted
diff options
context:
space:
mode:
authorRomain Perier <romain.perier@gmail.com>2020-03-20 17:43:16 +0100
committerBrian C. Lane <bcl@redhat.com>2020-05-04 17:13:16 -0700
commitc6b61814cd4cf958e12d35a36184ff7d767e57d9 (patch)
treea21ffeb30843c14a34ab5efe784a2ebc1ec37c7a /libparted
parent8c50fec522f475c51e2aaa3c972ce4c6690dda92 (diff)
downloadparted-c6b61814cd4cf958e12d35a36184ff7d767e57d9.tar.gz
Add support for the F2FS filesystem
This adds a basic support for the Flash-Friendly File System. So we can manipulate the file system by using the PedFileSystem API and we can do basic device probing for autodetecting the current fs. Signed-off-by: Romain Perier <romain.perier@gmail.com> Signed-off-by: Brian C. Lane <bcl@redhat.com>
Diffstat (limited to 'libparted')
-rw-r--r--libparted/fs/Makefile.am2
-rw-r--r--libparted/fs/f2fs/f2fs.c60
-rw-r--r--libparted/fs/f2fs/f2fs.h57
-rw-r--r--libparted/libparted.c4
4 files changed, 123 insertions, 0 deletions
diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
index 74f275a..e40eee8 100644
--- a/libparted/fs/Makefile.am
+++ b/libparted/fs/Makefile.am
@@ -32,6 +32,8 @@ libfs_la_SOURCES = \
fat/count.h \
fat/fat.c \
fat/fat.h \
+ f2fs/f2fs.c \
+ f2fs/f2fs.h \
hfs/hfs.c \
hfs/hfs.h \
hfs/probe.c \
diff --git a/libparted/fs/f2fs/f2fs.c b/libparted/fs/f2fs/f2fs.c
new file mode 100644
index 0000000..64883e9
--- /dev/null
+++ b/libparted/fs/f2fs/f2fs.c
@@ -0,0 +1,60 @@
+/*
+ libparted/fs/f2fs - Flash-Friendly File System
+ Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+
+#include <parted/parted.h>
+#include <parted/endian.h>
+
+#include "f2fs.h"
+
+static PedGeometry*
+f2fs_probe (PedGeometry* geom)
+{
+ struct f2fs_super_block *sb = alloca(geom->dev->sector_size);
+
+ if (!ped_geometry_read (geom, sb, F2FS_SB_OFFSET, 1))
+ return NULL;
+
+ if (PED_LE32_TO_CPU(sb->magic) == F2FS_MAGIC)
+ return ped_geometry_new (geom->dev, geom->start, geom->length);
+
+ return NULL;
+}
+
+static PedFileSystemOps f2fs_ops = {
+ probe: f2fs_probe,
+};
+
+static PedFileSystemType f2fs_type = {
+ next: NULL,
+ ops: &f2fs_ops,
+ name: "f2fs",
+};
+
+void
+ped_file_system_f2fs_init ()
+{
+ ped_file_system_type_register (&f2fs_type);
+}
+
+void
+ped_file_system_f2fs_done ()
+{
+ ped_file_system_type_unregister (&f2fs_type);
+}
diff --git a/libparted/fs/f2fs/f2fs.h b/libparted/fs/f2fs/f2fs.h
new file mode 100644
index 0000000..c96b88f
--- /dev/null
+++ b/libparted/fs/f2fs/f2fs.h
@@ -0,0 +1,57 @@
+/*
+ libparted/fs/f2fs - Flash-Friendly File System
+ Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
+*/
+#ifndef _F2FS_H
+#define _F2FS_H
+
+#define F2FS_MAGIC 0xF2F52010
+#define F2FS_MAX_VOLUME_NAME 512
+#define F2FS_SB_OFFSET 0x02
+
+struct f2fs_super_block {
+ uint32_t magic; /* Magic Number */
+ uint16_t major_ver; /* Major Version */
+ uint16_t minor_ver; /* Minor Version */
+ uint32_t log_sectorsize; /* log2 sector size in bytes */
+ uint32_t log_sectors_per_block; /* log2 # of sectors per block */
+ uint32_t log_blocksize; /* log2 block size in bytes */
+ uint32_t log_blocks_per_seg; /* log2 # of blocks per segment */
+ uint32_t segs_per_sec; /* # of segments per section */
+ uint32_t secs_per_zone; /* # of sections per zone */
+ uint32_t checksum_offset; /* checksum offset inside super block */
+ uint64_t block_count; /* total # of user blocks */
+ uint32_t section_count; /* total # of sections */
+ uint32_t segment_count; /* total # of segments */
+ uint32_t segment_count_ckpt; /* # of segments for checkpoint */
+ uint32_t segment_count_sit; /* # of segments for SIT */
+ uint32_t segment_count_nat; /* # of segments for NAT */
+ uint32_t segment_count_ssa; /* # of segments for SSA */
+ uint32_t segment_count_main; /* # of segments for main area */
+ uint32_t segment0_blkaddr; /* start block address of segment 0 */
+ uint32_t cp_blkaddr; /* start block address of checkpoint */
+ uint32_t sit_blkaddr; /* start block address of SIT */
+ uint32_t nat_blkaddr; /* start block address of NAT */
+ uint32_t ssa_blkaddr; /* start block address of SSA */
+ uint32_t main_blkaddr; /* start block address of main area */
+ uint32_t root_ino; /* root inode number */
+ uint32_t node_ino; /* node inode number */
+ uint32_t meta_ino; /* meta inode number */
+ uint8_t uuid[16]; /* 128-bit uuid for volume */
+ uint16_t volume_name[F2FS_MAX_VOLUME_NAME]; /* volume name */
+} __attribute__((packed));
+
+#endif
diff --git a/libparted/libparted.c b/libparted/libparted.c
index 00f5ff8..4a57a80 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -109,6 +109,7 @@ extern void ped_file_system_linux_swap_init (void);
extern void ped_file_system_jfs_init (void);
extern void ped_file_system_hfs_init (void);
extern void ped_file_system_fat_init (void);
+extern void ped_file_system_f2fs_init (void);
extern void ped_file_system_ext2_init (void);
extern void ped_file_system_nilfs2_init (void);
extern void ped_file_system_btrfs_init (void);
@@ -126,6 +127,7 @@ init_file_system_types ()
ped_file_system_jfs_init ();
ped_file_system_hfs_init ();
ped_file_system_fat_init ();
+ ped_file_system_f2fs_init ();
ped_file_system_ext2_init ();
ped_file_system_nilfs2_init ();
ped_file_system_btrfs_init ();
@@ -186,6 +188,7 @@ _init()
extern void ped_file_system_nilfs2_done (void);
extern void ped_file_system_ext2_done (void);
extern void ped_file_system_fat_done (void);
+extern void ped_file_system_f2fs_done (void);
extern void ped_file_system_hfs_done (void);
extern void ped_file_system_jfs_done (void);
extern void ped_file_system_linux_swap_done (void);
@@ -202,6 +205,7 @@ done_file_system_types ()
{
ped_file_system_nilfs2_done ();
ped_file_system_ext2_done ();
+ ped_file_system_f2fs_done ();
ped_file_system_fat_done ();
ped_file_system_hfs_done ();
ped_file_system_jfs_done ();