1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020 Namjae Jeon <linkinjeon@kernel.org>
14 #include "exfat_ondisk.h"
17 static void usage(void)
19 fprintf(stderr, "Usage: exfatlabel\n");
20 fprintf(stderr, "\t-i | --volume-serial Switch to volume serial mode\n");
21 fprintf(stderr, "\t-V | --version Show version\n");
22 fprintf(stderr, "\t-h | --help Show help\n");
27 static struct option opts[] = {
28 {"volume-serial", no_argument, NULL, 'i' },
29 {"version", no_argument, NULL, 'V' },
30 {"help", no_argument, NULL, 'h' },
31 {"?", no_argument, NULL, '?' },
35 int main(int argc, char *argv[])
38 int ret = EXIT_FAILURE;
39 struct exfat_blk_dev bd;
40 struct exfat_user_input ui;
41 bool version_only = false;
48 if (!setlocale(LC_CTYPE, ""))
49 exfat_err("failed to init locale/codeset\n");
52 flags = EXFAT_GET_VOLUME_LABEL;
54 flags = EXFAT_SET_VOLUME_LABEL;
57 while ((c = getopt_long(argc, argv, "iVh", opts, NULL)) != EOF)
62 flags = EXFAT_GET_VOLUME_SERIAL;
64 flags = EXFAT_SET_VOLUME_SERIAL;
83 memset(ui.dev_name, 0, sizeof(ui.dev_name));
84 snprintf(ui.dev_name, sizeof(ui.dev_name), "%s", argv[serial_mode + 1]);
86 ret = exfat_get_blk_dev_info(&ui, &bd);
91 /* Mode to change or display volume serial */
92 if (flags == EXFAT_GET_VOLUME_SERIAL) {
93 ret = exfat_show_volume_serial(bd.dev_fd);
94 } else if (flags == EXFAT_SET_VOLUME_SERIAL) {
95 ui.volume_serial = strtoul(argv[3], NULL, 0);
96 ret = exfat_set_volume_serial(&bd, &ui);
99 /* Mode to change or display volume label */
100 root_clu_off = exfat_get_root_entry_offset(&bd);
101 if (root_clu_off < 0)
104 if (flags == EXFAT_GET_VOLUME_LABEL)
105 ret = exfat_show_volume_label(&bd, root_clu_off);
106 else if (flags == EXFAT_SET_VOLUME_LABEL)
107 ret = exfat_set_volume_label(&bd, argv[2], root_clu_off);