]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: Allow root entry in device table
authorDavid Engraf <david.engraf@sysgo.com>
Tue, 6 Mar 2018 08:13:42 +0000 (09:13 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 7 Mar 2018 13:45:55 +0000 (14:45 +0100)
When using a local root folder the permissions, user and group settings
are taken from the local folder. These permissions might be incorrect if
the folder has been created for the local user. Creating an UBIFS image
on my local system resulted in the following output on the target:

drwx------   17 1000     1000   1264 Jan  1 00:00 .
drwx------   17 1000     1000   1264 Jan  1 00:00 ..
drwxr-xr-x    2 root     root   9104 May 30  2017 bin
drwxr-xr-x    7 root     root   2760 Jan  1 00:00 dev
...

mkfs.ubifs aborts with an error message when the device table contains
a root entry. This patch allows setting the root folder permissions,
user and group to overwrite local configurations.

Signed-off-by: David Engraf <david.engraf@sysgo.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/mkfs.ubifs/devtable.c
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index 3b46abc0f3189503bf2f12e67ce96682b7cd4b55..10faaca362da1c901676dd9bfbbbd688a74d7bba 100644 (file)
@@ -146,16 +146,16 @@ static int interpret_table_entry(const char *line)
                increment, count);
 
        len = strnlen(buf, 1024);
+       if (len == 0)
+               return err_msg("empty path");
        if (len == 1024)
                return err_msg("too long path");
 
-       if (!strcmp(buf, "/"))
+       if (buf[0] != '/')
                return err_msg("device table entries require absolute paths");
-       if (buf[1] == '\0')
-               return err_msg("root directory cannot be created");
        if (strstr(buf, "//"))
                return err_msg("'//' cannot be used in the path");
-       if (buf[len - 1] == '/')
+       if (len > 1 && buf[len - 1] == '/')
                return err_msg("do not put '/' at the end");
 
        if (strstr(buf, "/./") || strstr(buf, "/../") ||
index c916f489176a38798e21ed09e83813a9a8876483..2e18fdc54366b89a35335449a77a75fc2a6f1e7d 100644 (file)
@@ -1825,6 +1825,8 @@ static int write_data(void)
 {
        int err;
        mode_t mode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+       struct path_htbl_element *ph_elt;
+       struct name_htbl_element *nh_elt;
 
        if (root) {
                err = stat(root, &root_st);
@@ -1839,6 +1841,17 @@ static int write_data(void)
                root_st.st_mode = mode;
        }
 
+       /*
+        * Check for root entry and update permissions if it exists. This will
+        * also remove the entry from the device table list.
+        */
+       ph_elt = devtbl_find_path("/");
+       if (ph_elt) {
+               nh_elt = devtbl_find_name(ph_elt, "");
+               if (nh_elt && override_attributes(&root_st, ph_elt, nh_elt))
+                       return -1;
+       }
+
        head_flags = 0;
 
        err = create_inum_attr(UBIFS_ROOT_INO, root);