1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2019 Namjae Jeon <linkinjeon@kernel.org>
14 #include "exfat_ondisk.h"
18 static void usage(void)
20 fprintf(stderr, "Usage: tune.exfat\n");
21 fprintf(stderr, "\t-l | --print-label Print volume label\n");
22 fprintf(stderr, "\t-L | --set-label=label Set volume label\n");
23 fprintf(stderr, "\t-i | --print-serial Print volume serial\n");
24 fprintf(stderr, "\t-I | --set-serial=value Set volume serial\n");
25 fprintf(stderr, "\t-V | --version Show version\n");
26 fprintf(stderr, "\t-v | --verbose Print debug\n");
27 fprintf(stderr, "\t-h | --help Show help\n");
32 static struct option opts[] = {
33 {"print-label", no_argument, NULL, 'l' },
34 {"set-label", required_argument, NULL, 'L' },
35 {"print-serial", no_argument, NULL, 'i' },
36 {"set-serial", required_argument, NULL, 'I' },
37 {"version", no_argument, NULL, 'V' },
38 {"verbose", no_argument, NULL, 'v' },
39 {"help", no_argument, NULL, 'h' },
40 {"?", no_argument, NULL, '?' },
44 int main(int argc, char *argv[])
47 int ret = EXIT_FAILURE;
48 struct exfat_blk_dev bd;
49 struct exfat_user_input ui;
50 bool version_only = false;
52 char label_input[VOLUME_LABEL_BUFFER_SIZE];
53 struct exfat *exfat = NULL;
58 if (!setlocale(LC_CTYPE, ""))
59 exfat_err("failed to init locale/codeset\n");
62 while ((c = getopt_long(argc, argv, "I:iL:lVvh", opts, NULL)) != EOF)
65 flags = EXFAT_GET_VOLUME_LABEL;
68 snprintf(label_input, sizeof(label_input), "%s",
70 flags = EXFAT_SET_VOLUME_LABEL;
73 flags = EXFAT_GET_VOLUME_SERIAL;
76 ui.volume_serial = strtoul(optarg, NULL, 0);
77 flags = EXFAT_SET_VOLUME_SERIAL;
83 print_level = EXFAT_DEBUG;
98 memset(ui.dev_name, 0, sizeof(ui.dev_name));
99 snprintf(ui.dev_name, sizeof(ui.dev_name), "%s", argv[argc - 1]);
101 ret = exfat_get_blk_dev_info(&ui, &bd);
105 /* Mode to change or display volume serial */
106 if (flags == EXFAT_GET_VOLUME_SERIAL) {
107 ret = exfat_show_volume_serial(bd.dev_fd);
109 } else if (flags == EXFAT_SET_VOLUME_SERIAL) {
110 ret = exfat_set_volume_serial(&bd, &ui);
114 ret = read_boot_sect(&bd, &bs);
118 exfat = exfat_alloc_exfat(&bd, bs);
125 exfat->root = exfat_alloc_inode(ATTR_SUBDIR);
131 exfat->root->first_clus = le32_to_cpu(exfat->bs->bsx.root_cluster);
132 if (exfat_root_clus_count(exfat)) {
133 exfat_err("failed to follow the cluster chain of root\n");
134 exfat_free_inode(exfat->root);
139 if (flags == EXFAT_GET_VOLUME_LABEL)
140 ret = exfat_read_volume_label(exfat);
141 else if (flags == EXFAT_SET_VOLUME_LABEL)
142 ret = exfat_set_volume_label(exfat, label_input);
146 exfat_free_exfat(exfat);