X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=tune%2Ftune.c;h=f883556c794ed2bcfd82b9837a6c2f7e62298443;hb=HEAD;hp=7989e95f857a040af44a71637e008545aeb90128;hpb=a4f2404c58ad9a1134d98838617019286a680bef;p=sven%2Fexfatprogs.git diff --git a/tune/tune.c b/tune/tune.c index 7989e95..f883556 100644 --- a/tune/tune.c +++ b/tune/tune.c @@ -13,14 +13,17 @@ #include "exfat_ondisk.h" #include "libexfat.h" +#include "exfat_fs.h" static void usage(void) { fprintf(stderr, "Usage: tune.exfat\n"); fprintf(stderr, "\t-l | --print-label Print volume label\n"); fprintf(stderr, "\t-L | --set-label=label Set volume label\n"); + fprintf(stderr, "\t-u | --print-guid Print volume GUID\n"); + fprintf(stderr, "\t-U | --set-guid=guid Set volume GUID\n"); fprintf(stderr, "\t-i | --print-serial Print volume serial\n"); - fprintf(stderr, "\t-L | --set-serial=value Set volume serial\n"); + fprintf(stderr, "\t-I | --set-serial=value Set volume serial\n"); fprintf(stderr, "\t-V | --version Show version\n"); fprintf(stderr, "\t-v | --verbose Print debug\n"); fprintf(stderr, "\t-h | --help Show help\n"); @@ -31,6 +34,8 @@ static void usage(void) static struct option opts[] = { {"print-label", no_argument, NULL, 'l' }, {"set-label", required_argument, NULL, 'L' }, + {"print-guid", no_argument, NULL, 'u' }, + {"set-guid", required_argument, NULL, 'U' }, {"print-serial", no_argument, NULL, 'i' }, {"set-serial", required_argument, NULL, 'I' }, {"version", no_argument, NULL, 'V' }, @@ -49,7 +54,8 @@ int main(int argc, char *argv[]) bool version_only = false; int flags = 0; char label_input[VOLUME_LABEL_BUFFER_SIZE]; - off_t root_clu_off; + struct exfat *exfat = NULL; + struct pbr *bs; init_user_input(&ui); @@ -57,7 +63,7 @@ int main(int argc, char *argv[]) exfat_err("failed to init locale/codeset\n"); opterr = 0; - while ((c = getopt_long(argc, argv, "I:iL:lVvh", opts, NULL)) != EOF) + while ((c = getopt_long(argc, argv, "I:iL:lU:uVvh", opts, NULL)) != EOF) switch (c) { case 'l': flags = EXFAT_GET_VOLUME_LABEL; @@ -67,6 +73,14 @@ int main(int argc, char *argv[]) optarg); flags = EXFAT_SET_VOLUME_LABEL; break; + case 'u': + flags = EXFAT_GET_VOLUME_GUID; + break; + case 'U': + if (*optarg != '\0' && *optarg != '\r') + ui.guid = optarg; + flags = EXFAT_SET_VOLUME_GUID; + break; case 'i': flags = EXFAT_GET_VOLUME_SERIAL; break; @@ -102,23 +116,51 @@ int main(int argc, char *argv[]) /* Mode to change or display volume serial */ if (flags == EXFAT_GET_VOLUME_SERIAL) { - ret = exfat_show_volume_serial(&bd, &ui); + ret = exfat_show_volume_serial(bd.dev_fd); goto close_fd_out; } else if (flags == EXFAT_SET_VOLUME_SERIAL) { ret = exfat_set_volume_serial(&bd, &ui); goto close_fd_out; } - root_clu_off = exfat_get_root_entry_offset(&bd); - if (root_clu_off < 0) + ret = read_boot_sect(&bd, &bs); + if (ret) + goto close_fd_out; + + exfat = exfat_alloc_exfat(&bd, bs); + if (!exfat) { + free(bs); + ret = -ENOMEM; + goto close_fd_out; + } + + exfat->root = exfat_alloc_inode(ATTR_SUBDIR); + if (!exfat->root) { + ret = -ENOMEM; + goto close_fd_out; + } + + exfat->root->first_clus = le32_to_cpu(exfat->bs->bsx.root_cluster); + if (exfat_root_clus_count(exfat)) { + exfat_err("failed to follow the cluster chain of root\n"); + exfat_free_inode(exfat->root); + ret = -EINVAL; goto close_fd_out; + } if (flags == EXFAT_GET_VOLUME_LABEL) - ret = exfat_show_volume_label(&bd, root_clu_off); + ret = exfat_read_volume_label(exfat); else if (flags == EXFAT_SET_VOLUME_LABEL) - ret = exfat_set_volume_label(&bd, label_input, root_clu_off); + ret = exfat_set_volume_label(exfat, label_input); + else if (flags == EXFAT_GET_VOLUME_GUID) + ret = exfat_read_volume_guid(exfat); + else if (flags == EXFAT_SET_VOLUME_GUID) + ret = exfat_set_volume_guid(exfat, ui.guid); + close_fd_out: close(bd.dev_fd); + if (exfat) + exfat_free_exfat(exfat); out: return ret; }