[klibc] [PATCH] fstype: f2fs support

Marc Dietrich marvin24 at gmx.de
Mon Feb 24 04:49:56 PST 2014


This patch adds support for the F2FS filesystem to fstype.

Signed-off-by: Marc Dietrich <marvin24 at gmx.de>
---
 usr/kinit/fstype/f2fs_fs.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 usr/kinit/fstype/fstype.c  | 14 ++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 usr/kinit/fstype/f2fs_fs.h

diff --git a/usr/kinit/fstype/f2fs_fs.h b/usr/kinit/fstype/f2fs_fs.h
new file mode 100644
index 0000000..5774a9b
--- /dev/null
+++ b/usr/kinit/fstype/f2fs_fs.h
@@ -0,0 +1,44 @@
+#ifndef __F2FS_FS_H
+#define __F2FS_FS_H
+
+#define F2FS_SUPER_MAGIC		0xF2F52010	/* F2FS MAGIC */
+#define F2FS_MAX_EXTENSION		64	/* # of extension entries */
+
+/*
+ * For superblock
+ */
+struct f2fs_super_block {
+	__le32 magic;			/* Magic Number */
+	__le16 major_ver;		/* Major Version */
+	__le16 minor_ver;		/* Minor Version */
+	__le32 log_sectorsize;		/* log2 sector size in bytes */
+	__le32 log_sectors_per_block;	/* log2 # of sectors per block */
+	__le32 log_blocksize;		/* log2 block size in bytes */
+	__le32 log_blocks_per_seg;	/* log2 # of blocks per segment */
+	__le32 segs_per_sec;		/* # of segments per section */
+	__le32 secs_per_zone;		/* # of sections per zone */
+	__le32 checksum_offset;		/* checksum offset inside super block */
+	__le64 block_count;		/* total # of user blocks */
+	__le32 section_count;		/* total # of sections */
+	__le32 segment_count;		/* total # of segments */
+	__le32 segment_count_ckpt;	/* # of segments for checkpoint */
+	__le32 segment_count_sit;	/* # of segments for SIT */
+	__le32 segment_count_nat;	/* # of segments for NAT */
+	__le32 segment_count_ssa;	/* # of segments for SSA */
+	__le32 segment_count_main;	/* # of segments for main area */
+	__le32 segment0_blkaddr;	/* start block address of segment 0 */
+	__le32 cp_blkaddr;		/* start block address of checkpoint */
+	__le32 sit_blkaddr;		/* start block address of SIT */
+	__le32 nat_blkaddr;		/* start block address of NAT */
+	__le32 ssa_blkaddr;		/* start block address of SSA */
+	__le32 main_blkaddr;		/* start block address of main area */
+	__le32 root_ino;		/* root inode number */
+	__le32 node_ino;		/* node inode number */
+	__le32 meta_ino;		/* meta inode number */
+	__u8 uuid[16];			/* 128-bit uuid for volume */
+	__le16 volume_name[512];	/* volume name */
+	__le32 extension_count;		/* # of extensions below */
+	__u8 extension_list[F2FS_MAX_EXTENSION][8];	/* extension array */
+} __packed;
+
+#endif  /* F2FS_FS_H */
diff --git a/usr/kinit/fstype/fstype.c b/usr/kinit/fstype/fstype.c
index c5a1432..34d633a 100644
--- a/usr/kinit/fstype/fstype.c
+++ b/usr/kinit/fstype/fstype.c
@@ -37,6 +37,7 @@
 #include "romfs_fs.h"
 #include "squashfs_fs.h"
 #include "xfs_sb.h"
+#include "f2fs_fs.h"
 
 /*
  * Slightly cleaned up version of jfs_superblock to
@@ -472,6 +473,18 @@ static int btrfs_image(const void *buf, unsigned long long *bytes)
 	return 0;
 }
 
+static int f2fs_image(const void *buf, unsigned long long *bytes)
+{
+	const struct f2fs_super_block *sb =
+	    (const struct f2fs_super_block *)buf;
+
+	if (sb->magic == __cpu_to_le32(F2FS_SUPER_MAGIC)) {
+		*bytes = 0;
+		return 1;
+	}
+	return 0;
+}
+
 struct imagetype {
 	off_t block;
 	const char name[12];
@@ -502,6 +515,7 @@ static struct imagetype images[] = {
 	{1, "ext2", ext2_image},
 	{1, "minix", minix_image},
 	{1, "nilfs2", nilfs2_image},
+	{1, "f2fs", f2fs_image},
 	{2, "ocfs2", ocfs2_image},
 	{8, "reiserfs", reiserfs_image},
 	{64, "reiserfs", reiserfs_image},
-- 
1.8.5.2



More information about the klibc mailing list