Add nilfs2 file system support
authorJiro SEKIBA <jir@unicus.jp>
Sun, 15 Aug 2010 15:23:39 +0000 (17:23 +0200)
committerMartin Pitt <martin.pitt@ubuntu.com>
Sun, 15 Aug 2010 15:23:39 +0000 (17:23 +0200)
This needs util-linux-ng > 2.18.

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
src/daemon.c
src/helpers/job-mkfs.c
tests/run

index 87420e1..a5f34ee 100644 (file)
@@ -373,6 +373,22 @@ static const Filesystem known_file_systems[] =
       FALSE, /* supports_online_resize_shrink */
     },
     {
+      "nilfs2", /* id */
+      "NILFS2", /* name */
+      TRUE, /* supports_unix_owners */
+      TRUE, /* can_mount */
+      TRUE, /* can_create */
+      80, /* max_label_len */
+      FALSE, /* supports_label_rename */
+      FALSE, /* supports_online_label_rename*/
+      FALSE, /* supports_fsck */
+      FALSE, /* supports_online_fsck */
+      FALSE, /* supports_resize_enlarge */
+      FALSE, /* supports_online_resize_enlarge */
+      FALSE, /* supports_resize_shrink */
+      FALSE, /* supports_online_resize_shrink */
+    },
+    {
       "swap", /* id */
       "Swap Space", /* name */
       FALSE, /* supports_unix_owners */
index 8e4dce2..62cdfff 100644 (file)
@@ -337,6 +337,51 @@ main (int argc,
       command_line = g_string_free (s, FALSE);
 
     }
+  else if (strcmp (fstype, "nilfs2") == 0)
+    {
+
+      s = g_string_new ("mkfs.nilfs2");
+      for (n = 0; options[n] != NULL; n++)
+        {
+          if (g_str_has_prefix (options[n], "label="))
+            {
+              label = strdup (options[n] + sizeof("label=") - 1);
+              if (!validate_and_escape_label (&label, 80))
+                {
+                  g_string_free (s, TRUE);
+                  goto out;
+                }
+              g_string_append_printf (s, " -L \"%s\"", label);
+              g_free (label);
+              label = NULL;
+            }
+          else if (g_str_has_prefix (options[n], "take_ownership_uid="))
+            {
+              take_ownership_uid = strtol (options[n] + sizeof("take_ownership_uid=") - 1, &endp, 10);
+              if (endp == NULL || *endp != '\0')
+                {
+                  g_printerr ("option %s is malformed\n", options[n]);
+                  goto out;
+                }
+            }
+          else if (g_str_has_prefix (options[n], "take_ownership_gid="))
+            {
+              take_ownership_gid = strtol (options[n] + sizeof("take_ownership_gid=") - 1, &endp, 10);
+              if (endp == NULL || *endp != '\0')
+                {
+                  g_printerr ("option %s is malformed\n", options[n]);
+                  goto out;
+                }
+            }
+          else
+            {
+              g_printerr ("option %s not supported\n", options[n]);
+              goto out;
+            }
+        }
+      g_string_append_printf (s, " %s", device);
+      command_line = g_string_free (s, FALSE);
+    }
   else if (strcmp (fstype, "swap") == 0)
     {
 
index 420d39e..780fd2c 100755 (executable)
--- a/tests/run
+++ b/tests/run
@@ -46,7 +46,7 @@ import optparse
 import re
 
 NUM_VDEV = 3 # number of virtual test devices that we need
-VDEV_SIZE = 60000000 # size of virtual test devices
+VDEV_SIZE = 160000000 # size of virtual test devices
 test_md_dev = '/dev/md125'
 
 # Those file systems are known to have a broken handling of permissions, in
@@ -465,6 +465,10 @@ class FS(UDisksTestCase):
         '''fs: swap'''
         self._do_fs_check('swap')
 
+    def test_nilfs2(self):
+        '''fs: nilfs2'''
+        self._do_fs_check('nilfs2')
+
     def _do_fs_check(self, type):
         '''Run checks for a particular file system.'''
 
@@ -567,8 +571,8 @@ class FS(UDisksTestCase):
                 self.assertEqual(fs[3], type != 'swap') # can_mount
                 self.assert_(fs[4]) # can_create
                 supports_label_rename = fs[6]
-                # minix does not support labels; EXFAIL: swap doesn't have a program for it
-                self.assertEqual(supports_label_rename, type not in ('minix', 'swap'))
+                # minix does not support labels; EXFAIL: swap and nilfs2 don't have a program for it
+                self.assertEqual(supports_label_rename, type not in ('nilfs2', 'minix', 'swap'))
                 break
         else:
             self.fail('KnownFilesystems does not contain ' + type)
@@ -621,19 +625,28 @@ class FS(UDisksTestCase):
             self.assertEqual((st.st_uid, st.st_gid), (0, 0))
 
             # open files when mounted
-            self.assertEqual(iface.FilesystemListOpenFiles(), [])
+            num_open_file = 0
+            if type == 'nilfs2':
+                # garbage collector opens /.nilfs file
+                num_open_file = 1
+
+            result = iface.FilesystemListOpenFiles()
+            self.assertEqual(len(result), num_open_file)
 
             f = open(os.path.join(mount_path, 'test.txt'), 'w')
+            num_open_file += 1
             result = iface.FilesystemListOpenFiles()
-            self.assertEqual(len(result), 1)
+            self.assertEqual(len(result), num_open_file)
             self.assertEqual(result[0][0], os.getpid())
             self.assertEqual(result[0][1], os.geteuid())
             self.assert_(sys.argv[0] in result[0][2])
             f.close()
-            self.assertEqual(iface.FilesystemListOpenFiles(), [])
+            num_open_file -= 1
 
-            self._do_file_perms_checks(type, mount_path)
+            result = iface.FilesystemListOpenFiles()
+            self.assertEqual(len(result), num_open_file)
 
+            self._do_file_perms_checks(type, mount_path)
             # unmount
             self.retry_busy(self.partition_iface().FilesystemUnmount, [])
             self.failIf(os.path.exists(mount_path), 'mount point was not removed')