]> git.sven.stormbind.net Git - sven/exfat-utils.git/blobdiff - dump/main.c
Extent debian/copyright up to 2014.
[sven/exfat-utils.git] / dump / main.c
index 1536f81231bc10dd7b91cd03ff4f0e47d4da4435..71711c1623bccb279302ce95145c6652385b22ec 100644 (file)
@@ -2,11 +2,12 @@
        main.c (08.11.10)
        Prints detailed information about exFAT volume.
 
        main.c (08.11.10)
        Prints detailed information about exFAT volume.
 
-       Copyright (C) 2011, 2012  Andrew Nayenko
+       Free exFAT implementation.
+       Copyright (C) 2011-2014  Andrew Nayenko
 
 
-       This program is free software: you can redistribute it and/or modify
+       This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        it under the terms of the GNU General Public License as published by
-       the Free Software Foundation, either version 3 of the License, or
+       the Free Software Foundation, either version 2 of the License, or
        (at your option) any later version.
 
        This program is distributed in the hope that it will be useful,
        (at your option) any later version.
 
        This program is distributed in the hope that it will be useful,
@@ -14,8 +15,9 @@
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
 
-       You should have received a copy of the GNU General Public License
-       along with this program.  If not, see <http://www.gnu.org/licenses/>.
+       You should have received a copy of the GNU General Public License along
+       with this program; if not, write to the Free Software Foundation, Inc.,
+       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #include <fcntl.h>
 */
 
 #include <fcntl.h>
@@ -76,20 +78,20 @@ static int dump_sb(const char* spec)
        struct exfat_dev* dev;
        struct exfat_super_block sb;
 
        struct exfat_dev* dev;
        struct exfat_super_block sb;
 
-       dev = exfat_open(spec, 1);
+       dev = exfat_open(spec, EXFAT_MODE_RO);
        if (dev == NULL)
                return 1;
 
        if (exfat_read(dev, &sb, sizeof(struct exfat_super_block)) < 0)
        {
                exfat_close(dev);
        if (dev == NULL)
                return 1;
 
        if (exfat_read(dev, &sb, sizeof(struct exfat_super_block)) < 0)
        {
                exfat_close(dev);
-               exfat_error("failed to read from `%s'", spec);
+               exfat_error("failed to read from '%s'", spec);
                return 1;
        }
        if (memcmp(sb.oem_name, "EXFAT   ", sizeof(sb.oem_name)) != 0)
        {
                exfat_close(dev);
                return 1;
        }
        if (memcmp(sb.oem_name, "EXFAT   ", sizeof(sb.oem_name)) != 0)
        {
                exfat_close(dev);
-               exfat_error("exFAT file system is not found on `%s'", spec);
+               exfat_error("exFAT file system is not found on '%s'", spec);
                return 1;
        }
 
                return 1;
        }
 
@@ -112,7 +114,7 @@ static void dump_sectors(struct exfat* ef)
        puts("");
 }
 
        puts("");
 }
 
-static int dump_full(const char* spec, int used_sectors)
+static int dump_full(const char* spec, bool used_sectors)
 {
        struct exfat ef;
        uint32_t free_clusters;
 {
        struct exfat ef;
        uint32_t free_clusters;
@@ -140,38 +142,40 @@ static int dump_full(const char* spec, int used_sectors)
 
 static void usage(const char* prog)
 {
 
 static void usage(const char* prog)
 {
-       fprintf(stderr, "Usage: %s [-s] [-u] [-v] <device>\n", prog);
+       fprintf(stderr, "Usage: %s [-s] [-u] [-V] <device>\n", prog);
        exit(1);
 }
 
 int main(int argc, char* argv[])
 {
        exit(1);
 }
 
 int main(int argc, char* argv[])
 {
-       char** pp;
+       int opt;
        const char* spec = NULL;
        const char* spec = NULL;
-       int sb_only = 0;
-       int used_sectors = 0;
+       bool sb_only = false;
+       bool used_sectors = false;
 
        printf("dumpexfat %u.%u.%u\n",
                        EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
 
 
        printf("dumpexfat %u.%u.%u\n",
                        EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
 
-       for (pp = argv + 1; *pp; pp++)
+       while ((opt = getopt(argc, argv, "suV")) != -1)
        {
        {
-               if (strcmp(*pp, "-s") == 0)
-                       sb_only = 1;
-               else if (strcmp(*pp, "-u") == 0)
-                       used_sectors = 1;
-               else if (strcmp(*pp, "-v") == 0)
+               switch (opt)
                {
                {
-                       puts("Copyright (C) 2011, 2012  Andrew Nayenko");
+               case 's':
+                       sb_only = true;
+                       break;
+               case 'u':
+                       used_sectors = true;
+                       break;
+               case 'V':
+                       puts("Copyright (C) 2011-2014  Andrew Nayenko");
                        return 0;
                        return 0;
-               }
-               else if (spec == NULL)
-                       spec = *pp;
-               else
+               default:
                        usage(argv[0]);
                        usage(argv[0]);
+               }
        }
        }
-       if (spec == NULL)
+       if (argc - optind != 1)
                usage(argv[0]);
                usage(argv[0]);
+       spec = argv[optind];
 
        if (sb_only)
                return dump_sb(spec);
 
        if (sb_only)
                return dump_sb(spec);