~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to misc-utils/blkid.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
const char *progname = "blkid";
47
47
 
 
48
int raw_chars;
 
49
 
48
50
static void print_version(FILE *out)
49
51
{
50
52
        fprintf(out, "%s from %s (libblkid %s, %s)\n",
58
60
        print_version(out);
59
61
        fprintf(out,
60
62
                "Usage:\n"
61
 
                "  %1$s -L <label> | -U <uuid>\n\n"
62
 
                "  %1$s [-c <file>] [-ghlLv] [-o format] [-s <tag>] \n"
63
 
                "        [-t <token>] [-w <file>] [dev ...]\n\n"
64
 
                "  %1$s -p [-s <tag>] [-O <offset>] [-S <size>] \n"
65
 
                "        [-o format] <dev> [dev ...]\n\n"
66
 
                "  %1$s -i [-s <tag>] [-o format] <dev> [dev ...]\n\n"
 
63
                " %1$s -L <label> | -U <uuid>\n\n"
 
64
                " %1$s [-c <file>] [-ghlLv] [-o <format>] [-s <tag>] \n"
 
65
                "       [-t <token>] [-w <file>] [<dev> ...]\n\n"
 
66
                " %1$s -p [-s <tag>] [-O <offset>] [-S <size>] \n"
 
67
                "       [-o <format>] <dev> ...\n\n"
 
68
                " %1$s -i [-s <tag>] [-o <format>] <dev> ...\n\n"
67
69
                "Options:\n"
68
 
                "  -c <file>   cache file (default: /etc/blkid.tab, /dev/null = none)\n"
69
 
                "  -h          print this usage message and exit\n"
70
 
                "  -g          garbage collect the blkid cache\n"
71
 
                "  -o <format> output format; can be one of:\n"
72
 
                "              value, device, list, udev, export or full; (default: full)\n"
73
 
                "  -s <tag>    show specified tag(s) (default show all tags)\n"
74
 
                "  -t <token>  find device with a specific token (NAME=value pair)\n"
75
 
                "  -l          lookup the the first device with arguments specified by -t\n"
76
 
                "  -L <label>  convert LABEL to device name\n"
77
 
                "  -U <uuid>   convert UUID to device name\n"
78
 
                "  -v          print version and exit\n"
79
 
                "  -w <file>   write cache to different file (/dev/null = no write)\n"
80
 
                "  <dev>       specify device(s) to probe (default: all devices)\n\n"
 
70
                " -c <file>   cache file (default: /etc/blkid.tab, /dev/null = none)\n"
 
71
                " -d          don't encode non-printing characters\n"
 
72
                " -h          print this usage message and exit\n"
 
73
                " -g          garbage collect the blkid cache\n"
 
74
                " -o <format> output format; can be one of:\n"
 
75
                "               value, device, list, udev, export or full; (default: full)\n"
 
76
                " -k          list all known filesystems/RAIDs and exit\n"
 
77
                " -s <tag>    show specified tag(s) (default show all tags)\n"
 
78
                " -t <token>  find device with a specific token (NAME=value pair)\n"
 
79
                " -l          look up only first device with token specified by -t\n"
 
80
                " -L <label>  convert LABEL to device name\n"
 
81
                " -U <uuid>   convert UUID to device name\n"
 
82
                " -v          print version and exit\n"
 
83
                " -w <file>   write cache to different file (/dev/null = no write)\n"
 
84
                " <dev>       specify device(s) to probe (default: all devices)\n\n"
81
85
                "Low-level probing options:\n"
82
 
                "  -p          low-level superblocks probing (bypass cache)\n"
83
 
                "  -i          gather information about I/O limits\n"
84
 
                "  -S <size>   overwrite device size\n"
85
 
                "  -O <offset> probe at the given offset\n"
86
 
                "  -u <list>   filter by \"usage\" (e.g. -u filesystem,raid)\n"
87
 
                "  -n <list>   filter by filesystem type (e.g. -n vfat,ext3)\n"
88
 
                "\n",
89
 
                                progname);
 
86
                " -p          low-level superblocks probing (bypass cache)\n"
 
87
                " -i          gather information about I/O limits\n"
 
88
                " -S <size>   overwrite device size\n"
 
89
                " -O <offset> probe at the given offset\n"
 
90
                " -u <list>   filter by \"usage\" (e.g. -u filesystem,raid)\n"
 
91
                " -n <list>   filter by filesystem type (e.g. -n vfat,ext3)\n"
 
92
                "\n", progname);
90
93
 
91
94
        exit(error);
92
95
}
104
107
 
105
108
        while (len--) {
106
109
                ch = *cp++;
107
 
                if (ch >= 128) {
108
 
                        fputs("M-", stdout);
109
 
                        ch -= 128;
110
 
                }
111
 
                if ((ch < 32) || (ch == 0x7f)) {
112
 
                        fputc('^', stdout);
113
 
                        ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
 
110
                if (!raw_chars) {
 
111
                        if (ch >= 128) {
 
112
                                fputs("M-", stdout);
 
113
                                ch -= 128;
 
114
                        }
 
115
                        if ((ch < 32) || (ch == 0x7f)) {
 
116
                                fputc('^', stdout);
 
117
                                ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
 
118
                        }
114
119
                }
115
120
                fputc(ch, stdout);
116
121
        }
241
246
        pretty_print_line(devname, fs_type, label, mtpt, uuid);
242
247
}
243
248
 
244
 
static void print_udev_format(const char *name, const char *value, size_t sz)
 
249
static void print_udev_format(const char *name, const char *value)
245
250
{
246
251
        char enc[265], safe[256];
247
252
        size_t namelen = strlen(name);
301
306
                fputc('\n', stdout);
302
307
 
303
308
        } else if (output & OUTPUT_UDEV_LIST) {
304
 
                print_udev_format(name, value, valsz);
 
309
                print_udev_format(name, value);
305
310
 
306
311
        } else if (output & OUTPUT_EXPORT_LIST) {
307
312
                fputs(name, stdout);
615
620
{
616
621
        int i;
617
622
        const char *p = list;
618
 
        char **res;
 
623
        char **res = NULL;
619
624
 
620
625
        if (p && strncmp(p, "no", 2) == 0) {
621
626
                *flag = BLKID_FLTR_NOTIN;
685
690
 
686
691
        show[0] = NULL;
687
692
 
688
 
        while ((c = getopt (argc, argv, "c:f:ghilL:n:o:O:ps:S:t:u:U:w:v")) != EOF)
 
693
        while ((c = getopt (argc, argv, "c:df:ghilL:n:ko:O:ps:S:t:u:U:w:v")) != EOF)
689
694
                switch (c) {
690
695
                case 'c':
691
696
                        if (optarg && !*optarg)
695
700
                        if (!write)
696
701
                                write = read;
697
702
                        break;
 
703
                case 'd':
 
704
                        raw_chars = 1;
 
705
                        break;
698
706
                case 'L':
699
707
                        eval++;
700
708
                        search_value = strdup(optarg);
728
736
                case 'g':
729
737
                        gc = 1;
730
738
                        break;
 
739
                case 'k':
 
740
                {
 
741
                        size_t idx = 0;
 
742
                        const char *name = NULL;
 
743
 
 
744
                        while (blkid_superblocks_get_name(idx++, &name, NULL) == 0)
 
745
                                printf("%s\n", name);
 
746
                        exit(0);
 
747
                }
731
748
                case 'o':
732
749
                        if (!strcmp(optarg, "value"))
733
750
                                output_format = OUTPUT_VALUE_ONLY;
807
824
                        fprintf(stderr, "Failed to allocate device name array\n");
808
825
                        goto exit;
809
826
                }
 
827
 
 
828
                while (optind < argc)
 
829
                        devices[numdev++] = argv[optind++];
810
830
        }
811
831
 
812
 
        while (optind < argc)
813
 
                devices[numdev++] = argv[optind++];
814
 
 
815
832
        if (version) {
816
833
                print_version(stdout);
817
834
                goto exit;