X-Git-Url: https://git.sven.stormbind.net/?p=sven%2Fexfatprogs.git;a=blobdiff_plain;f=label%2Flabel.c;fp=label%2Flabel.c;h=8cd57488a86046e6c1cfb78f242acd46b9e02d0c;hp=b41e82714c9be485f126f6da134f7705b84f2fff;hb=03290761e3849db9b13d2d3b176b36ab31c395bb;hpb=dcb4e80c267579d1a68e3f34f6b750e2940dbcc2 diff --git a/label/label.c b/label/label.c index b41e827..8cd5748 100644 --- a/label/label.c +++ b/label/label.c @@ -13,6 +13,7 @@ #include "exfat_ondisk.h" #include "libexfat.h" +#include "exfat_fs.h" static void usage(void) { @@ -39,7 +40,6 @@ int main(int argc, char *argv[]) struct exfat_blk_dev bd; struct exfat_user_input ui; bool version_only = false; - off_t root_clu_off; int serial_mode = 0; int flags = 0; @@ -96,15 +96,43 @@ int main(int argc, char *argv[]) ret = exfat_set_volume_serial(&bd, &ui); } } else { - /* Mode to change or display volume label */ - root_clu_off = exfat_get_root_entry_offset(&bd); - if (root_clu_off < 0) + struct exfat *exfat; + struct pbr *bs; + + 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 free_exfat; + } + + 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 free_exfat; + } + + /* Mode to change or display volume label */ 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, argv[2], root_clu_off); + ret = exfat_set_volume_label(exfat, argv[2]); + +free_exfat: + if (exfat) + exfat_free_exfat(exfat); } close_fd_out: