For example, it can be used to disable udev's parsing of metadata and
the creation of persistent symlinks for that device [1], to avoid
unnecessary network access that can take some time.

```sh
cat << EOF > /etc/udev/rules.d/59-skip-nbd-erofs-persistent-storage.rules

IMPORT{db}="UDEV_DISABLE_PERSISTENT_STORAGE_RULES_FLAG"
IMPORT{program}="/usr/local/bin/dump.erofs --blkid-udev %N"

ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="nbd*", 
ENV{ID_FS_TYPE}=="erofs", ENV{UDEV_DISABLE_PERSISTENT_STORAGE_RULES_FLAG}="1"
EOF
```

[1] https://github.com/systemd/systemd/pull/3714
Cc: Chengyu Zhu <[email protected]>
Signed-off-by: Gao Xiang <[email protected]>
---
 dump/main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dump/main.c b/dump/main.c
index f685799..4ad3f7b 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -26,6 +26,7 @@ struct erofsdump_cfg {
        bool show_statistics;
        bool show_subdirectories;
        bool show_file_content;
+       bool show_blkid_udev;
        erofs_nid_t nid;
        const char *inode_path;
 };
@@ -81,6 +82,7 @@ static struct option long_options[] = {
        {"ls", no_argument, NULL, 5},
        {"offset", required_argument, NULL, 6},
        {"cat", no_argument, NULL, 7},
+       {"blkid-udev", no_argument, NULL, 512},
        {0, 0, 0, 0},
 };
 
@@ -125,6 +127,7 @@ static void usage(int argc, char **argv)
                " -S              show statistic information of the image\n"
                " -e              show extent info (INODE required)\n"
                " -s              show information about superblock\n"
+               " --blkid-udev    print block device attributes for easy import 
into the udev environment\n"
                " --device=X      specify an extra device to be used together\n"
                " --ls            show directory contents (INODE required)\n"
                " --cat           show file contents (INODE required)\n"
@@ -198,6 +201,9 @@ static int erofsdump_parse_options_cfg(int argc, char 
**argv)
                case 7:
                        dumpcfg.show_file_content = true;
                        break;
+               case 512:
+                       dumpcfg.show_blkid_udev = true;
+                       break;
                default:
                        return -EINVAL;
                }
@@ -765,6 +771,9 @@ int main(int argc, char **argv)
                goto exit;
        }
 
+       if (dumpcfg.show_blkid_udev)
+               cfg.c_dbg_lvl = -1;
+
        err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDONLY | O_TRUNC);
        if (err) {
                erofs_err("failed to open image file");
@@ -777,6 +786,15 @@ int main(int argc, char **argv)
                goto exit_dev_close;
        }
 
+       if (dumpcfg.show_blkid_udev) {
+               char uuid_str[37];
+
+               erofs_uuid_unparse_lower(g_sbi.uuid, uuid_str);
+               
printf("ID_FS_UUID=%s\nID_FS_UUID_ENC=%s\nID_FS_TYPE=erofs\nID_FS_USAGE=filesystem\n",
+                      uuid_str, uuid_str);
+               goto exit_put_super;
+       }
+
        if (dumpcfg.show_file_content) {
                if (dumpcfg.show_superblock || dumpcfg.show_statistics || 
dumpcfg.show_subdirectories) {
                        fprintf(stderr, "The '--cat' flag is incompatible with 
'-S', '-e', '-s' and '--ls'.\n");
-- 
2.43.5


Reply via email to