chiark / gitweb /
volume_id: add md metadata 1.0, 1.1, 1.2 support
[elogind.git] / extras / volume_id / vol_id.c
index 0a1b756fa3174c62d557234844220faed798ac7b..0427d70da199e312e518c5e48792350de9cc4e26 100644 (file)
@@ -116,6 +116,7 @@ int main(int argc, char *argv[])
                            "  -t             filesystem type\n"
                            "  -l             filesystem label\n"
                            "  -u             filesystem uuid\n"
+                           "  -L             raw label\n"
                            " --skip-raid     don't probe for raid\n"
                            " --probe-all     find possibly conflicting signatures\n"
                            " --help\n"
@@ -125,6 +126,7 @@ int main(int argc, char *argv[])
                PRINT_TYPE,
                PRINT_LABEL,
                PRINT_UUID,
+               PRINT_RAW_LABEL,
        } print = PRINT_EXPORT;
        struct volume_id *vid = NULL;
        static char name[VOLUME_ID_LABEL_SIZE];
@@ -153,6 +155,8 @@ int main(int argc, char *argv[])
                        print = PRINT_LABEL;
                } else if (strcmp(arg, "-u") == 0) {
                        print = PRINT_UUID;
+               } else if (strcmp(arg, "-L") == 0) {
+                       print = PRINT_RAW_LABEL;
                } else if (strcmp(arg, "--skip-raid") == 0) {
                        skip_raid = 1;
                } else if (strcmp(arg, "--probe-all") == 0) {
@@ -179,12 +183,13 @@ int main(int argc, char *argv[])
 
        if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0)
                size = 0;
-       dbg("BLKGETSIZE64=%llu", size);
+       dbg("BLKGETSIZE64=%llu", (unsigned long long)size);
 
        /* try to drop all privileges before reading disk content */
        pw = getpwnam ("nobody");
        if (pw != NULL && pw->pw_uid > 0 && pw->pw_gid > 0) {
-               dbg("dropping privileges to %u:%u", (unsigned int)pw->pw_uid, (unsigned int)pw->pw_gid);
+               dbg("dropping privileges to %u:%u",
+                   (unsigned int)pw->pw_uid, (unsigned int)pw->pw_gid);
                if (setgroups(0, NULL) != 0 ||
                    setgid(pw->pw_gid) != 0 ||
                    setuid(pw->pw_uid) != 0) {
@@ -306,6 +311,13 @@ int main(int argc, char *argv[])
                }
                printf("%s\n", vid->uuid);
                break;
+       case PRINT_RAW_LABEL:
+               if (vid->label[0] == '\0' || vid->usage_id == VOLUME_ID_RAID) {
+                       rc = 3;
+                       goto exit;
+               }
+               printf("%s\n", vid->label);
+               break;
        }
 
 exit: