[Parted-commits] GNU Parted Official Repository: Changes to 'master'
Jim Meyering
meyering at alioth.debian.org
Sat Mar 5 18:50:27 UTC 2011
configure.ac | 1
libparted/fs/Makefile.am | 6 -
libparted/fs/nilfs2/Makefile.am | 8 +
libparted/fs/nilfs2/nilfs2.c | 199 ++++++++++++++++++++++++++++++++++++++++
libparted/libparted.c | 4
tests/Makefile.am | 2
tests/t1700-ext-probe.sh | 54 ----------
tests/t1700-probe-fs.sh | 57 +++++++++++
8 files changed, 274 insertions(+), 57 deletions(-)
New commits:
commit 0bfe6ac65d42f11730943eeaee754e7749e55de1
Author: Jim Meyering <meyering at redhat.com>
Date: Sat Mar 5 19:47:05 2011 +0100
tests: add a minimal nilfs2 test
* tests/t1700-probe-fs.sh: Adapt to also test nilfs2.
diff --git a/tests/t1700-probe-fs.sh b/tests/t1700-probe-fs.sh
index 00aba3e..749c9ea 100755
--- a/tests/t1700-probe-fs.sh
+++ b/tests/t1700-probe-fs.sh
@@ -21,19 +21,22 @@ require_512_byte_sector_size_
dev=loop-file
ss=$sector_size_
-n_sectors=8000
-for type in ext2 ext3 ext4; do
+for type in ext2 ext3 ext4 nilfs2; do
- ( mkfs.$type -V ) >/dev/null 2>&1 || skip_ "no $type support"
+ ( mkfs.$type -V ) >/dev/null 2>&1 \
+ || { warn_ "$ME: no $type support"; continue; }
+
+ case $type in ext*) n_sectors=8000 force=-F;;
+ *) n_sectors=$((257*1024)) force=;; esac
# create an $type file system
- dd if=/dev/zero of=$dev bs=1024 count=4096 >/dev/null || fail=1
- mkfs.$type -F $dev >/dev/null || fail=1
+ dd if=/dev/zero of=$dev bs=$ss count=$n_sectors >/dev/null || fail=1
+ mkfs.$type $force $dev || { warn_ $ME: mkfs.$type failed; fail=1; continue; }
# probe the $type file system
parted -m -s $dev u s print >out 2>&1 || fail=1
- grep '^1:.*:'$type'::;$' out || fail=1
+ grep '^1:.*:'$type'::;$' out || { cat out; fail=1; }
done
commit f3335f16b523974b3ed3eb1242c2eb6fc34c429d
Author: Jim Meyering <meyering at redhat.com>
Date: Fri Mar 4 08:23:01 2011 +0100
tests: rename a test script, before extending it to handle nilfs
* tests/t1700-probe-fs.sh: Rename from ...
* tests/t1700-ext-probe.sh: ...this.
* tests/Makefile.am (TESTS): Rename it here, too.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ffea90c..feafbed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,7 +20,7 @@ TESTS = \
t0500-dup-clobber.sh \
t1100-busy-label.sh \
t1101-busy-partition.sh \
- t1700-ext-probe.sh \
+ t1700-probe-fs.sh \
t2100-mkswap.sh \
t2200-dos-label-recog.sh \
t2300-dos-label-extended-bootcode.sh \
diff --git a/tests/t1700-ext-probe.sh b/tests/t1700-ext-probe.sh
deleted file mode 100755
index 00aba3e..0000000
--- a/tests/t1700-ext-probe.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/sh
-# Probe Ext2, Ext3 and Ext4 file systems
-
-# Copyright (C) 2008-2011 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/>.
-
-. "${srcdir=.}/init.sh"; path_prepend_ ../parted
-require_512_byte_sector_size_
-
-dev=loop-file
-ss=$sector_size_
-n_sectors=8000
-
-for type in ext2 ext3 ext4; do
-
- ( mkfs.$type -V ) >/dev/null 2>&1 || skip_ "no $type support"
-
- # create an $type file system
- dd if=/dev/zero of=$dev bs=1024 count=4096 >/dev/null || fail=1
- mkfs.$type -F $dev >/dev/null || fail=1
-
- # probe the $type file system
- parted -m -s $dev u s print >out 2>&1 || fail=1
- grep '^1:.*:'$type'::;$' out || fail=1
-
-done
-
-# Some features should indicate ext4 by themselves.
-for feature in uninit_bg flex_bg; do
- # create an ext3 file system
- dd if=/dev/zero of=$dev bs=1024 count=4096 >/dev/null || fail=1
- mkfs.ext3 -F $dev >/dev/null || fail=1
-
- # set the feature
- tune2fs -O $feature $dev || fail=1
-
- # probe the file system, which should now be ext4
- parted -m -s $dev u s print >out 2>&1 || fail=1
- grep '^1:.*:ext4::;$' out || fail=1
-done
-
-Exit $fail
diff --git a/tests/t1700-probe-fs.sh b/tests/t1700-probe-fs.sh
new file mode 100755
index 0000000..00aba3e
--- /dev/null
+++ b/tests/t1700-probe-fs.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# Probe Ext2, Ext3 and Ext4 file systems
+
+# Copyright (C) 2008-2011 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/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+require_512_byte_sector_size_
+
+dev=loop-file
+ss=$sector_size_
+n_sectors=8000
+
+for type in ext2 ext3 ext4; do
+
+ ( mkfs.$type -V ) >/dev/null 2>&1 || skip_ "no $type support"
+
+ # create an $type file system
+ dd if=/dev/zero of=$dev bs=1024 count=4096 >/dev/null || fail=1
+ mkfs.$type -F $dev >/dev/null || fail=1
+
+ # probe the $type file system
+ parted -m -s $dev u s print >out 2>&1 || fail=1
+ grep '^1:.*:'$type'::;$' out || fail=1
+
+done
+
+# Some features should indicate ext4 by themselves.
+for feature in uninit_bg flex_bg; do
+ # create an ext3 file system
+ dd if=/dev/zero of=$dev bs=1024 count=4096 >/dev/null || fail=1
+ mkfs.ext3 -F $dev >/dev/null || fail=1
+
+ # set the feature
+ tune2fs -O $feature $dev || fail=1
+
+ # probe the file system, which should now be ext4
+ parted -m -s $dev u s print >out 2>&1 || fail=1
+ grep '^1:.*:ext4::;$' out || fail=1
+done
+
+Exit $fail
commit d463e7ded8d486c95977f4501969056600a73501
Author: Jiro SEKIBA <jir at unicus.jp>
Date: Fri Jul 9 18:51:56 2010 +0900
libparted: add nilfs2 module
* libparted/fs/nilfs2/Makefile.am: New file.
* libparted/fs/nilfs2/nilfs2.c: New file.
(is_valid_nilfs_sb, nilfs2_probe, nilfs2_clobber): New functions.
(ped_file_system_nilfs2_init, ped_file_system_nilfs2_done): Likewise.
(nilfs2_ops, nilfs2_type): Define.
* libparted/fs/Makefile.am (SUBDIRS): Add nilfs2.
* configure.ac (AC_OUTPUT): Add the new Makefile.
* libparted/libparted.c: Declare and use the _init and _done functions.
Add a new fs module to provide following:
- probe nilfs2 filesystem partition
- clobber nilfs2 filesystem partition
The is_valid_nilfs_sb function came from the grub nilfs2 module,
which is written by me and assigned to FSF.
diff --git a/configure.ac b/configure.ac
index 7548e26..1ed2712 100644
--- a/configure.ac
+++ b/configure.ac
@@ -634,6 +634,7 @@ libparted/fs/ntfs/Makefile
libparted/fs/reiserfs/Makefile
libparted/fs/ufs/Makefile
libparted/fs/xfs/Makefile
+libparted/fs/nilfs2/Makefile
libparted/tests/Makefile
libparted.pc
parted/Makefile
diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
index 449e88f..f3ec7dc 100644
--- a/libparted/fs/Makefile.am
+++ b/libparted/fs/Makefile.am
@@ -3,7 +3,8 @@
#
# This file may be modified and/or distributed without restriction.
-SUBDIRS = amiga ext2 ufs fat ntfs hfs linux_swap xfs jfs reiserfs # bfs
+SUBDIRS = amiga ext2 ufs fat ntfs hfs linux_swap xfs jfs reiserfs \
+ nilfs2 # bfs
partedincludedir = -I$(top_srcdir)/include
noinst_LTLIBRARIES = libfs.la
@@ -23,7 +24,8 @@ libfs_la_LIBADD = $(UUID_LIBS) \
linux_swap/liblinuxswap.la \
xfs/libxfs.la \
jfs/libjfs.la \
- reiserfs/libreiserfs.la
+ reiserfs/libreiserfs.la \
+ nilfs2/libnilfs2.la
# bfs/libbfs.la
libfs_la_SOURCES =
diff --git a/libparted/fs/nilfs2/Makefile.am b/libparted/fs/nilfs2/Makefile.am
new file mode 100644
index 0000000..9bb87b6
--- /dev/null
+++ b/libparted/fs/nilfs2/Makefile.am
@@ -0,0 +1,8 @@
+partedincludedir = -I$(top_srcdir)/include
+
+noinst_LTLIBRARIES = libnilfs2.la
+libnilfs2_la_SOURCES = nilfs2.c
+
+INCLUDES = $(partedincludedir) $(INTLINCS)
+
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/libparted/fs/nilfs2/nilfs2.c b/libparted/fs/nilfs2/nilfs2.c
new file mode 100644
index 0000000..49634c0
--- /dev/null
+++ b/libparted/fs/nilfs2/nilfs2.c
@@ -0,0 +1,199 @@
+/*
+ * nilfs2.c - New Implementation of Log filesystem
+ *
+ * Written by Jiro SEKIBA <jir at unicus.jp>
+ *
+ * Copyright (C) 2011 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/crc32.h>
+#include <parted/endian.h>
+
+/* Magic value for nilfs2 superblock. */
+#define NILFS2_SUPER_MAGIC 0x3434
+
+/* primariy superblock offset in 512bytes blocks. */
+#define NILFS_SB_OFFSET 2
+
+/* secondary superblock offset in 512byte blocks. */
+#define NILFS_SB2_OFFSET(devsize) ((((devsize)>>3) - 1) << 3)
+
+struct nilfs2_super_block
+{
+ uint32_t s_rev_level;
+ uint16_t s_minor_rev_level;
+ uint16_t s_magic;
+ uint16_t s_bytes;
+ uint16_t s_flags;
+ uint32_t s_crc_seed;
+ uint32_t s_sum;
+ uint32_t s_log_block_size;
+ uint64_t s_nsegments;
+ uint64_t s_dev_size;
+ uint64_t s_first_data_block;
+ uint32_t s_blocks_per_segment;
+ uint32_t s_r_segments_percentage;
+ uint64_t s_last_cno;
+ uint64_t s_last_pseg;
+ uint64_t s_last_seq;
+ uint64_t s_free_blocks_count;
+ uint64_t s_ctime;
+ uint64_t s_mtime;
+ uint64_t s_wtime;
+ uint16_t s_mnt_count;
+ uint16_t s_max_mnt_count;
+ uint16_t s_state;
+ uint16_t s_errors;
+ uint64_t s_lastcheck;
+ uint32_t s_checkinterval;
+ uint32_t s_creator_os;
+ uint16_t s_def_resuid;
+ uint16_t s_def_resgid;
+ uint32_t s_first_ino;
+ uint16_t s_inode_size;
+ uint16_t s_dat_entry_size;
+ uint16_t s_checkpoint_size;
+ uint16_t s_segment_usage_size;
+ uint8_t s_uuid[16];
+ char s_volume_name[80];
+ uint32_t s_c_interval;
+ uint32_t s_c_block_max;
+ uint32_t s_reserved[192];
+};
+
+static int
+is_valid_nilfs_sb(struct nilfs2_super_block *sb)
+{
+ static unsigned char sum[4];
+ const int sumoff = offsetof (struct nilfs2_super_block, s_sum);
+ size_t bytes;
+ uint32_t crc;
+
+ if (PED_LE16_TO_CPU(sb->s_magic) != NILFS2_SUPER_MAGIC)
+ return 0;
+
+ bytes = PED_LE16_TO_CPU(sb->s_bytes);
+ if (bytes > 1024)
+ return 0;
+
+ crc = __efi_crc32(sb, sumoff, PED_LE32_TO_CPU(sb->s_crc_seed));
+ crc = __efi_crc32(sum, 4, crc);
+ crc = __efi_crc32((unsigned char *)sb + sumoff + 4,
+ bytes - sumoff - 4, crc);
+
+ return crc == PED_LE32_TO_CPU(sb->s_sum);
+}
+
+PedGeometry*
+nilfs2_probe (PedGeometry* geom)
+{
+ void *sb_v;
+ void *sb2_v;
+ struct nilfs2_super_block *sb = NULL;
+ struct nilfs2_super_block *sb2 = NULL;
+ PedSector length = geom->length;
+ PedSector sb2off;
+
+ /* ignore if sector size is not 512bytes for now */
+ if (geom->dev->sector_size != PED_SECTOR_SIZE_DEFAULT)
+ return NULL;
+
+ sb2off = NILFS_SB2_OFFSET(length);
+
+ if (ped_geometry_read_alloc(geom, &sb_v, 2, 1))
+ sb = sb_v;
+
+ if (ped_geometry_read_alloc(geom, &sb2_v, sb2off, 1))
+ sb2 = sb2_v;
+
+ if ((!sb || !is_valid_nilfs_sb(sb)) &&
+ (!sb2 || !is_valid_nilfs_sb(sb2)) ) {
+ free(sb);
+ free(sb2);
+ return NULL;
+ }
+
+ /* reserve 4k bytes for secondary superblock */
+ length = sb2off + 8;
+
+ free(sb);
+ free(sb2);
+ return ped_geometry_new(geom->dev, geom->start, length);
+}
+
+#ifndef DISCOVER_ONLY
+static int
+nilfs2_clobber (PedGeometry* geom)
+{
+ char buf[512];
+ int ret[2];
+
+ printf("nilfs2_clobber\n");
+ memset (buf, 0, 512);
+
+ ret[0] = ped_geometry_write (geom, buf, NILFS_SB_OFFSET, 1);
+ ret[1] = ped_geometry_write (geom, buf,
+ NILFS_SB2_OFFSET(geom->length), 1);
+
+ return ret[0]|ret[1];
+}
+#endif /* !DISCOVER_ONLY */
+
+static PedFileSystemOps nilfs2_ops = {
+ probe: nilfs2_probe,
+#ifndef DISCOVER_ONLY
+ #if 0
+ clobber: nilfs2_clobber,
+ #else
+ clobber: NULL,
+ #endif
+#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
+};
+
+#define NILFS2_BLOCK_SIZES ((int[5]){1024, 2048, 4096, 8192, 0})
+
+static PedFileSystemType nilfs2_type = {
+ next: NULL,
+ ops: &nilfs2_ops,
+ name: "nilfs2",
+ block_sizes: NILFS2_BLOCK_SIZES
+};
+
+void
+ped_file_system_nilfs2_init ()
+{
+ ped_file_system_type_register (&nilfs2_type);
+}
+
+void
+ped_file_system_nilfs2_done ()
+{
+ ped_file_system_type_unregister (&nilfs2_type);
+}
diff --git a/libparted/libparted.c b/libparted/libparted.c
index 4218f90..db1c413 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -109,6 +109,7 @@ 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_ext2_init (void);
+extern void ped_file_system_nilfs2_init (void);
static void
init_file_system_types ()
@@ -123,6 +124,7 @@ init_file_system_types ()
ped_file_system_hfs_init ();
ped_file_system_fat_init ();
ped_file_system_ext2_init ();
+ ped_file_system_nilfs2_init ();
}
#endif /* ENABLE_FS */
@@ -179,6 +181,7 @@ _init()
}
#ifdef ENABLE_FS
+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_hfs_done (void);
@@ -193,6 +196,7 @@ extern void ped_file_system_amiga_done (void);
static void
done_file_system_types ()
{
+ ped_file_system_nilfs2_done ();
ped_file_system_ext2_done ();
ped_file_system_fat_done ();
ped_file_system_hfs_done ();
More information about the Parted-commits
mailing list