]> git.sven.stormbind.net Git - sven/exfatprogs.git/blobdiff - label/label.c
releasing package exfatprogs version 1.2.3-1
[sven/exfatprogs.git] / label / label.c
index b41e82714c9be485f126f6da134f7705b84f2fff..278014334aa3ce1021e4580b3bc854ec04c871c7 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "exfat_ondisk.h"
 #include "libexfat.h"
 
 #include "exfat_ondisk.h"
 #include "libexfat.h"
+#include "exfat_fs.h"
 
 static void usage(void)
 {
 
 static void usage(void)
 {
@@ -39,9 +40,9 @@ int main(int argc, char *argv[])
        struct exfat_blk_dev bd;
        struct exfat_user_input ui;
        bool version_only = false;
        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;
        int serial_mode = 0;
        int flags = 0;
+       unsigned long volume_serial;
 
        init_user_input(&ui);
 
 
        init_user_input(&ui);
 
@@ -92,19 +93,56 @@ int main(int argc, char *argv[])
                if (flags == EXFAT_GET_VOLUME_SERIAL) {
                        ret = exfat_show_volume_serial(bd.dev_fd);
                } else if (flags == EXFAT_SET_VOLUME_SERIAL) {
                if (flags == EXFAT_GET_VOLUME_SERIAL) {
                        ret = exfat_show_volume_serial(bd.dev_fd);
                } else if (flags == EXFAT_SET_VOLUME_SERIAL) {
-                       ui.volume_serial = strtoul(argv[3], NULL, 0);
+                       ret = exfat_parse_ulong(argv[3], &volume_serial);
+                       if (volume_serial > UINT_MAX)
+                               ret = -ERANGE;
+
+
+                       if (ret < 0) {
+                               exfat_err("invalid serial number(%s)\n", argv[3]);
+                               goto close_fd_out;
+                       }
+
+                       ui.volume_serial = volume_serial;
                        ret = exfat_set_volume_serial(&bd, &ui);
                }
        } else {
                        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) {
+                       ret = -ENOMEM;
                        goto close_fd_out;
                        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)
                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)
                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:
        }
 
 close_fd_out: