public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* libblkid: add f2fs support
@ 2013-02-05 17:00 Alejandro Martinez Ruiz
  2013-02-05 17:00 ` [PATCH 1/2] libblkid: add Flash-Friendly File System (f2fs) support Alejandro Martinez Ruiz
  2013-02-05 17:00 ` [PATCH 2/2] tests: add f2fs image test Alejandro Martinez Ruiz
  0 siblings, 2 replies; 5+ messages in thread
From: Alejandro Martinez Ruiz @ 2013-02-05 17:00 UTC (permalink / raw)
  To: kzak; +Cc: util-linux

Hi,

These patches implement support for Samsung's f2fs (Flash-Friendly File System)
in libblkid. f2fs was recently merged into the Linux kernel for the 3.8 release.

The first patch implements superblocks/f2fs.c and adds it to the build system,
while the second one adds a test image.

Thanks,
  Alex


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] libblkid: add Flash-Friendly File System (f2fs) support
  2013-02-05 17:00 libblkid: add f2fs support Alejandro Martinez Ruiz
@ 2013-02-05 17:00 ` Alejandro Martinez Ruiz
  2013-02-06 11:23   ` Karel Zak
  2013-02-05 17:00 ` [PATCH 2/2] tests: add f2fs image test Alejandro Martinez Ruiz
  1 sibling, 1 reply; 5+ messages in thread
From: Alejandro Martinez Ruiz @ 2013-02-05 17:00 UTC (permalink / raw)
  To: kzak; +Cc: util-linux

This adds support for detecting Flash-Friendly File System (f2fs) to libblkid.
Based on work by Sven-Göran Bergh at http://www.mail-archive.com/busybox@busybox.net/msg17874.html

Signed-off-by: Alejandro Martinez Ruiz <alex@nowcomputing.com>
---
 libblkid/src/Makemodule.am             |  1 +
 libblkid/src/superblocks/f2fs.c        | 98 ++++++++++++++++++++++++++++++++++
 libblkid/src/superblocks/superblocks.c |  3 +-
 libblkid/src/superblocks/superblocks.h |  1 +
 4 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100644 libblkid/src/superblocks/f2fs.c

diff --git a/libblkid/src/Makemodule.am b/libblkid/src/Makemodule.am
index de60458..90efa3d 100644
--- a/libblkid/src/Makemodule.am
+++ b/libblkid/src/Makemodule.am
@@ -54,6 +54,7 @@ libblkid_la_SOURCES = \
 	libblkid/src/superblocks/drbdproxy_datalog.c \
 	libblkid/src/superblocks/exfat.c \
 	libblkid/src/superblocks/ext.c \
+	libblkid/src/superblocks/f2fs.c \
 	libblkid/src/superblocks/gfs.c \
 	libblkid/src/superblocks/hfs.c \
 	libblkid/src/superblocks/highpoint_raid.c \
diff --git a/libblkid/src/superblocks/f2fs.c b/libblkid/src/superblocks/f2fs.c
new file mode 100644
index 0000000..ad03441
--- /dev/null
+++ b/libblkid/src/superblocks/f2fs.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2013 Alejandro Martinez Ruiz <alex@nowcomputing.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+#include "superblocks.h"
+
+#define F2FS_MAGIC		"\x10\x20\xF5\xF2"
+#define F2FS_MAGIC_OFF		0
+#define F2FS_UUID_SIZE		16
+#define F2FS_LABEL_SIZE		512
+#define F2FS_SB1_OFF		0x400
+#define F2FS_SB1_KBOFF		(F2FS_SB1_OFF >> 10)
+#define F2FS_SB2_OFF		0x1400
+#define F2FS_SB2_KBOFF		(F2FS_SB2_OFF >> 10)
+
+struct f2fs_super_block {					/* According to version 1.1 */
+/* 0x00 */	uint32_t	magic;				/* Magic Number */
+/* 0x04 */	uint16_t	major_ver;			/* Major Version */
+/* 0x06 */	uint16_t	minor_ver;			/* Minor Version */
+/* 0x08 */	uint32_t	log_sectorsize;			/* log2 sector size in bytes */
+/* 0x0C */	uint32_t	log_sectors_per_block;		/* log2 # of sectors per block */
+/* 0x10 */	uint32_t	log_blocksize;			/* log2 block size in bytes */
+/* 0x14 */	uint32_t	log_blocks_per_seg;		/* log2 # of blocks per segment */
+/* 0x18 */	uint32_t	segs_per_sec;			/* # of segments per section */
+/* 0x1C */	uint32_t	secs_per_zone;			/* # of sections per zone */
+/* 0x20 */	uint32_t	checksum_offset;		/* checksum offset inside super block */
+/* 0x24 */	uint64_t	block_count;			/* total # of user blocks */
+/* 0x2C */	uint32_t	section_count;			/* total # of sections */
+/* 0x30 */	uint32_t	segment_count;			/* total # of segments */
+/* 0x34 */	uint32_t	segment_count_ckpt;		/* # of segments for checkpoint */
+/* 0x38 */	uint32_t	segment_count_sit;		/* # of segments for SIT */
+/* 0x3C */	uint32_t	segment_count_nat;		/* # of segments for NAT */
+/* 0x40 */	uint32_t	segment_count_ssa;		/* # of segments for SSA */
+/* 0x44 */	uint32_t	segment_count_main;		/* # of segments for main area */
+/* 0x48 */	uint32_t	segment0_blkaddr;		/* start block address of segment 0 */
+/* 0x4C */	uint32_t	cp_blkaddr;			/* start block address of checkpoint */
+/* 0x50 */	uint32_t	sit_blkaddr;			/* start block address of SIT */
+/* 0x54 */	uint32_t	nat_blkaddr;			/* start block address of NAT */
+/* 0x58 */	uint32_t	ssa_blkaddr;			/* start block address of SSA */
+/* 0x5C */	uint32_t	main_blkaddr;			/* start block address of main area */
+/* 0x60 */	uint32_t	root_ino;			/* root inode number */
+/* 0x64 */	uint32_t	node_ino;			/* node inode number */
+/* 0x68 */	uint32_t	meta_ino;			/* meta inode number */
+/* 0x6C */	uint8_t		uuid[F2FS_UUID_SIZE];		/* 128-bit uuid for volume */
+/* 0x7C */	uint16_t	volume_name[F2FS_LABEL_SIZE];	/* volume name */
+#if 0
+/* 0x47C */	uint32_t	extension_count;		/* # of extensions below */
+/* 0x480 */	uint8_t		extension_list[64][8];		/* extension array */
+#endif
+} __attribute__((packed));
+
+static int probe_f2fs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+	struct f2fs_super_block *sb;
+	uint16_t major, minor;
+
+	sb = blkid_probe_get_sb(pr, mag, struct f2fs_super_block);
+	if (!sb)
+		return -1;
+
+	major = le16_to_cpu(sb->major_ver);
+	minor = le16_to_cpu(sb->minor_ver);
+
+	/* For version 1.0 we cannot know the correct sb structure */
+	if (major == 1 && minor == 0)
+		return 0;
+
+	if (*((unsigned char *) sb->volume_name))
+		blkid_probe_set_utf8label(pr, (unsigned char *) sb->volume_name,
+						sizeof(sb->volume_name),
+						BLKID_ENC_UTF16LE);
+
+	blkid_probe_set_uuid(pr, sb->uuid);
+	blkid_probe_sprintf_version(pr, "%u.%u", major, minor);
+}
+
+const struct blkid_idinfo f2fs_idinfo =
+{
+	.name           = "f2fs",
+	.usage          = BLKID_USAGE_FILESYSTEM,
+	.probefunc      = probe_f2fs,
+	.magics         =
+        {
+		{
+			.magic = F2FS_MAGIC,
+			.len = 4,
+			.kboff = F2FS_SB1_KBOFF,
+			.sboff = F2FS_MAGIC_OFF
+		},
+		{ NULL }
+	}
+};
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index 2929a5f..62aa662 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -140,7 +140,8 @@ static const struct blkid_idinfo *idinfos[] =
 	&vmfs_fs_idinfo,
 	&befs_idinfo,
 	&nilfs2_idinfo,
-	&exfat_idinfo
+	&exfat_idinfo,
+	&f2fs_idinfo
 };
 
 /*
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index 08f1438..887732a 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -69,6 +69,7 @@ extern const struct blkid_idinfo drbdproxy_datalog_idinfo;
 extern const struct blkid_idinfo befs_idinfo;
 extern const struct blkid_idinfo nilfs2_idinfo;
 extern const struct blkid_idinfo exfat_idinfo;
+extern const struct blkid_idinfo f2fs_idinfo;
 
 /*
  * superblock functions
-- 
1.8.1.2.422.g08c0e7f

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] tests: add f2fs image test
  2013-02-05 17:00 libblkid: add f2fs support Alejandro Martinez Ruiz
  2013-02-05 17:00 ` [PATCH 1/2] libblkid: add Flash-Friendly File System (f2fs) support Alejandro Martinez Ruiz
@ 2013-02-05 17:00 ` Alejandro Martinez Ruiz
  2013-02-06 11:24   ` Karel Zak
  1 sibling, 1 reply; 5+ messages in thread
From: Alejandro Martinez Ruiz @ 2013-02-05 17:00 UTC (permalink / raw)
  To: kzak; +Cc: util-linux

Signed-off-by: Alejandro Martinez Ruiz <alex@nowcomputing.com>
---
 tests/expected/blkid/low-probe-f2fs   |   7 +++++++
 tests/ts/blkid/images-fs/f2fs.img.bz2 | Bin 0 -> 695 bytes
 2 files changed, 7 insertions(+)
 create mode 100644 tests/expected/blkid/low-probe-f2fs
 create mode 100644 tests/ts/blkid/images-fs/f2fs.img.bz2

diff --git a/tests/expected/blkid/low-probe-f2fs b/tests/expected/blkid/low-probe-f2fs
new file mode 100644
index 0000000..ee32864
--- /dev/null
+++ b/tests/expected/blkid/low-probe-f2fs
@@ -0,0 +1,7 @@
+ID_FS_LABEL=test-f2fs
+ID_FS_LABEL_ENC=test-f2fs
+ID_FS_TYPE=f2fs
+ID_FS_USAGE=filesystem
+ID_FS_UUID=f6aee5b9-8cc2-4da7-9f8d-c95aac90e17d
+ID_FS_UUID_ENC=f6aee5b9-8cc2-4da7-9f8d-c95aac90e17d
+ID_FS_VERSION=1.1
diff --git a/tests/ts/blkid/images-fs/f2fs.img.bz2 b/tests/ts/blkid/images-fs/f2fs.img.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..82e86013d833654bc871bd880b8b714d30681d72
GIT binary patch
literal 695
zcmV;o0!aNrT4*^jL0KkKS&byVNdN##fB*k(#Q{JfTt3Yr0T3s<-NHa8Kmd%T0J4}M
z2mm4h6AZus{OG2O2}LMrlLTOxm?3}&WND^G5C@`Z>8a`I4l-oXpfqWS$k4<vCXF!$
zBSC}!7$TykhKzxrF*E}Z21b}b13<ul0;Hy)Fo@IA0L0MH9+T2&F%2{UkO81pvZk-|
zTQhx&4Aoh@zRso2s^(^Pc7cK8USVU`oG%e>Y}A)gmQr0V^R_lRH;d;|u8AA!kS2r#
z9hMHHq9TY!0s;!GhzP2rk99zi0Qk~EL`X@)gO{~3S=VVxrI{B-1`hrBg^k7ak%dxS
zD5X^GHdYvy-L;LR?97uq#^=qspm!A+l_O13LV&7?A>LvLlSm>cil~xED2h=W3Y~>R
zH6&TK@GT|xd9cHJAcT@cXQt&JI&7uw9ox`aQ;|Y4%8>J}&>`TyDu@wOVk$l&y1R-a
zZITWou8M{t7^TxJ^e&wWhNE?KPs+I)%xP&%Yn1Y}mNnfq^L6iGdRztPwTYtQaVcgJ
zlx0}9MVJ^=J_=|U4`Ssmak)-51@=~>Nr@V3$OA*fJgVui>Kq&+5H+4h==k#nL4xSV
zjt#>GhtJ|5ssgGfIE6+p`HBk3GMdP6PZszJ{Bi&W0000%00D#oYBCi8El5-Zxrz$O
zGMda0lj{%)>z9HDzyJUd00{s906_o(gc&gcYM@M+$J_L+;#E)*)~%#e1i8$?P!jiZ
zUhj00pe6Z=3du5>$bOouKmxJL@-N6E5C8xn00962002V(00;mO0!07>fk4wkBPJkH
zluaW|pwmgFo4+>Kru};I(=nT1o^pZ$e_|@B<8IigLX&I?g(tkCp-HcN-+qsHea99)
dT>Q1?IPatGAwrY22LY$}yOJrwgo4$swCHOZEHwZC

literal 0
HcmV?d00001

-- 
1.8.1.2.422.g08c0e7f


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] libblkid: add Flash-Friendly File System (f2fs) support
  2013-02-05 17:00 ` [PATCH 1/2] libblkid: add Flash-Friendly File System (f2fs) support Alejandro Martinez Ruiz
@ 2013-02-06 11:23   ` Karel Zak
  0 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2013-02-06 11:23 UTC (permalink / raw)
  To: Alejandro Martinez Ruiz; +Cc: util-linux

On Tue, Feb 05, 2013 at 06:00:06PM +0100, Alejandro Martinez Ruiz wrote:
> +static int probe_f2fs(blkid_probe pr, const struct blkid_idmag *mag)
> +{
> +	struct f2fs_super_block *sb;
> +	uint16_t major, minor;
> +
> +	sb = blkid_probe_get_sb(pr, mag, struct f2fs_super_block);
> +	if (!sb)
> +		return -1;
> +
> +	major = le16_to_cpu(sb->major_ver);
> +	minor = le16_to_cpu(sb->minor_ver);
> +
> +	/* For version 1.0 we cannot know the correct sb structure */
> +	if (major == 1 && minor == 0)
> +		return 0;
> +
> +	if (*((unsigned char *) sb->volume_name))
> +		blkid_probe_set_utf8label(pr, (unsigned char *) sb->volume_name,
> +						sizeof(sb->volume_name),
> +						BLKID_ENC_UTF16LE);
> +
> +	blkid_probe_set_uuid(pr, sb->uuid);
> +	blkid_probe_sprintf_version(pr, "%u.%u", major, minor);

    return 0;

> +}

 Fixed, applied. Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] tests: add f2fs image test
  2013-02-05 17:00 ` [PATCH 2/2] tests: add f2fs image test Alejandro Martinez Ruiz
@ 2013-02-06 11:24   ` Karel Zak
  0 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2013-02-06 11:24 UTC (permalink / raw)
  To: Alejandro Martinez Ruiz; +Cc: util-linux

On Tue, Feb 05, 2013 at 06:00:07PM +0100, Alejandro Martinez Ruiz wrote:
>  tests/expected/blkid/low-probe-f2fs   |   7 +++++++
>  tests/ts/blkid/images-fs/f2fs.img.bz2 | Bin 0 -> 695 bytes
>  2 files changed, 7 insertions(+)
>  create mode 100644 tests/expected/blkid/low-probe-f2fs
>  create mode 100644 tests/ts/blkid/images-fs/f2fs.img.bz2

 Applied, thanks!

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-02-06 11:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-05 17:00 libblkid: add f2fs support Alejandro Martinez Ruiz
2013-02-05 17:00 ` [PATCH 1/2] libblkid: add Flash-Friendly File System (f2fs) support Alejandro Martinez Ruiz
2013-02-06 11:23   ` Karel Zak
2013-02-05 17:00 ` [PATCH 2/2] tests: add f2fs image test Alejandro Martinez Ruiz
2013-02-06 11:24   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox