]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: add --raw and --noheadings
authorKarel Zak <kzak@redhat.com>
Mon, 13 May 2013 10:00:24 +0000 (12:00 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 13 May 2013 10:00:24 +0000 (12:00 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.8
sys-utils/losetup.c

index bd735180c0dd8dfd961cc6871e73854fd2220c77..9c4c7c92b05fc35137ce1ca2385f8e6f12afe2e1 100644 (file)
@@ -95,8 +95,12 @@ print help
 show status of all loop devices associated with given
 .I file
 .IP "\fB\-l, \-\-list"
-if a loop device or the -a option is specified, print default columns for either the specified
-loop device or all loop devices, default is to print info about all devices.
+if a loop device or the -a option is specified, print default columns for
+either the specified loop device or all loop devices, default is to print info
+about all devices.  See also \fB\-\-output\fP, \fB\-\-noheadings\fP
+and \fB\-\-raw\fP.
+.IP "\fB\-n, \fB\-\-noheadings\fP"
+don't print headings for \fB\-\-list\fP output format
 .IP "\fB\-o, \-\-offset \fIoffset\fP"
 the data start is moved \fIoffset\fP bytes into the specified file or
 device
@@ -106,6 +110,8 @@ specify which columns are to be printed for the \fB\-\-list\fP output
 the data end is set to no more than \fIsize\fP bytes after the data start
 .IP "\fB\-P, \-\-partscan\fP"
 force kernel to scan partition table on newly created loop device
+.IP "\fB\-\-raw\fP"
+use raw \fB\-\-list\fP output format
 .IP "\fB\-r, \-\-read-only\fP"
 setup read-only loop device
 .IP "\fB\-\-show\fP"
index b44c9e540f2544ddd4bb2f95c31858926eeb99fa..90e75ebbb5a02cc19c6d7fb54debbd295b944476 100644 (file)
@@ -290,14 +290,17 @@ static int set_tt_data(struct loopdev_cxt *lc, struct tt_line *ln)
        return 0;
 }
 
-static int make_table(struct loopdev_cxt *lc, const char *file,
-               uint64_t offset, int flags)
+static int make_table(struct loopdev_cxt *lc,
+                     const char *file,
+                     uint64_t offset,
+                     int flags,
+                     int tt_flags)
 {
        struct stat sbuf, *st = &sbuf;
        struct tt_line *ln;
        int i;
 
-       if (!(tt = tt_new_table(0)))
+       if (!(tt = tt_new_table(tt_flags)))
                errx(EXIT_FAILURE, _("failed to initialize output table"));
 
        for (i = 0; i < ncolumns; i++) {
@@ -307,6 +310,7 @@ static int make_table(struct loopdev_cxt *lc, const char *file,
                        warn(_("failed to initialize output column"));
        }
 
+       /* only one loopdev requested (already assigned to loopdev_cxt) */
        if (loopcxt_get_device(lc)) {
                ln = tt_add_line(tt, NULL);
                if (set_tt_data(lc, ln))
@@ -314,6 +318,7 @@ static int make_table(struct loopdev_cxt *lc, const char *file,
                return 0;
        }
 
+       /* list all loopdevs */
        if (loopcxt_init_iterator(lc, LOOPITER_FL_USED))
                return -1;
        if (!file || stat(file, st))
@@ -353,15 +358,20 @@ static void usage(FILE *out)
                " -j, --associated <file>       list all devices associated with <file>\n"), out);
        fputs(USAGE_SEPARATOR, out);
 
-       fputs(_(" -l, --list                    list info about all or specified\n"), out);
        fputs(_(" -o, --offset <num>            start at offset <num> into file\n"), out);
-       fputs(_(" -O, --output <cols>           specify columns to output for --list\n"), out);
        fputs(_("     --sizelimit <num>         device limited to <num> bytes of the file\n"), out);
        fputs(_(" -P, --partscan                create partitioned loop device\n"), out);
        fputs(_(" -r, --read-only               setup read-only loop device\n"), out);
        fputs(_("     --show                    print device name after setup (with -f)\n"), out);
        fputs(_(" -v, --verbose                 verbose mode\n"), out);
 
+       fputs(USAGE_SEPARATOR, out);
+
+       fputs(_(" -l, --list                    list info about all or specified\n"), out);
+       fputs(_(" -O, --output <cols>           specify columns to output for --list\n"), out);
+       fputs(_(" -n, --noheadings              don't print headings for --list ouput\n"), out);
+       fputs(_("     --raw                     use raw --list output format\n"), out);
+
        fputs(USAGE_SEPARATOR, out);
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
@@ -401,13 +411,14 @@ int main(int argc, char **argv)
        int act = 0, flags = 0, c;
        char *file = NULL;
        uint64_t offset = 0, sizelimit = 0;
-       int res = 0, showdev = 0, lo_flags = 0;
+       int res = 0, showdev = 0, lo_flags = 0, tt_flags = 0;
        char *outarg = NULL;
        int list = 0;
 
        enum {
                OPT_SIZELIMIT = CHAR_MAX + 1,
-               OPT_SHOW
+               OPT_SHOW,
+               OPT_RAW
        };
        static const struct option longopts[] = {
                { "all", 0, 0, 'a' },
@@ -419,12 +430,14 @@ int main(int argc, char **argv)
                { "help", 0, 0, 'h' },
                { "associated", 1, 0, 'j' },
                { "list", 0, 0, 'l' },
+               { "noheadings", 0, 0, 'n' },
                { "offset", 1, 0, 'o' },
                { "output", 1, 0, 'O' },
                { "sizelimit", 1, 0, OPT_SIZELIMIT },
                { "pass-fd", 1, 0, 'p' },
                { "partscan", 0, 0, 'P' },
                { "read-only", 0, 0, 'r' },
+               { "raw", 0, 0, OPT_RAW },
                { "show", 0, 0, OPT_SHOW },
                { "verbose", 0, 0, 'v' },
                { "version", 0, 0, 'V' },
@@ -447,7 +460,7 @@ int main(int argc, char **argv)
        if (loopcxt_init(&lc, 0))
                err(EXIT_FAILURE, _("failed to initialize loopcxt"));
 
-       while ((c = getopt_long(argc, argv, "ac:d:De:E:fhj:lo:O:p:PrvV",
+       while ((c = getopt_long(argc, argv, "ac:d:De:E:fhj:lno:O:p:PrvV",
                                longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
@@ -491,6 +504,12 @@ int main(int argc, char **argv)
                case 'l':
                        list = 1;
                        break;
+               case 'n':
+                       tt_flags |= TT_FL_NOHEADINGS;
+                       break;
+               case OPT_RAW:
+                       tt_flags |= TT_FL_RAW;
+                       break;
                case 'o':
                        offset = strtosize_or_err(optarg, _("failed to parse offset"));
                        flags |= LOOPDEV_FL_OFFSET;
@@ -658,13 +677,13 @@ int main(int argc, char **argv)
                break;
        case A_SHOW:
                if (list)
-                       res = make_table(&lc, file, offset, flags);
+                       res = make_table(&lc, file, offset, flags, tt_flags);
                else
                        res = show_all_loops(&lc, file, offset, flags);
                break;
        case A_SHOW_ONE:
                if (list)
-                       res = make_table( &lc, NULL, 0, 0);
+                       res = make_table( &lc, NULL, 0, 0, tt_flags);
                else
                        res = printf_loopdev(&lc);
                if (res)