diff options
author | bigbiff bigbiff <bigbiff@teamw.in> | 2013-07-03 20:52:12 +0200 |
---|---|---|
committer | bigbiff bigbiff <bigbiff@teamw.in> | 2013-07-03 20:52:12 +0200 |
commit | 004e2df74a3a92d431e573c60626b5dce36cca98 (patch) | |
tree | af8203944e665972cd3c09ec2d5f7c4ca8cdf4f2 | |
parent | Rewrite TWFunc::Exec_Cmd() to use pipe() instead of popen() (diff) | |
download | android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.tar android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.tar.gz android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.tar.bz2 android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.tar.lz android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.tar.xz android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.tar.zst android_bootable_recovery-004e2df74a3a92d431e573c60626b5dce36cca98.zip |
-rw-r--r-- | exfat/dump/dumpexfat.8 | 4 | ||||
-rw-r--r-- | exfat/dump/main.c | 26 | ||||
-rw-r--r-- | exfat/exfat-fuse/main.c | 64 | ||||
-rw-r--r-- | exfat/exfat-fuse/mount.exfat-fuse.8 | 16 | ||||
-rw-r--r-- | exfat/fsck/exfatfsck.8 | 4 | ||||
-rw-r--r-- | exfat/fsck/main.c | 33 | ||||
-rw-r--r-- | exfat/label/exfatlabel.8 | 4 | ||||
-rw-r--r-- | exfat/label/main.c | 4 | ||||
-rw-r--r-- | exfat/libexfat/exfat.h | 4 | ||||
-rw-r--r-- | exfat/libexfat/node.c | 19 | ||||
-rw-r--r-- | exfat/mkfs/main.c | 61 | ||||
-rw-r--r-- | exfat/mkfs/mkexfatfs.8 | 4 |
12 files changed, 127 insertions, 116 deletions
diff --git a/exfat/dump/dumpexfat.8 b/exfat/dump/dumpexfat.8 index 36fb28ad1..7fea0653c 100644 --- a/exfat/dump/dumpexfat.8 +++ b/exfat/dump/dumpexfat.8 @@ -13,7 +13,7 @@ .B \-u ] [ -.B \-v +.B \-V ] .I device @@ -33,7 +33,7 @@ systems. Dump ranges of used sectors starting from 0 and separated with spaces. May be useful for backup tools. .TP -.BI \-v +.BI \-V Print version and copyright. .SH EXIT CODES diff --git a/exfat/dump/main.c b/exfat/dump/main.c index fa80903b8..8650d5170 100644 --- a/exfat/dump/main.c +++ b/exfat/dump/main.c @@ -140,13 +140,13 @@ static int dump_full(const char* spec, bool used_sectors) 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[]) { - char** pp; + int opt; const char* spec = NULL; bool sb_only = false; bool used_sectors = false; @@ -154,24 +154,26 @@ int main(int argc, char* argv[]) 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) + switch (opt) + { + case 's': sb_only = true; - else if (strcmp(*pp, "-u") == 0) + break; + case 'u': used_sectors = true; - else if (strcmp(*pp, "-v") == 0) - { + break; + case 'V': puts("Copyright (C) 2011-2013 Andrew Nayenko"); return 0; - } - else if (spec == NULL) - spec = *pp; - else + default: usage(argv[0]); + } } - if (spec == NULL) + if (argc - optind != 1) usage(argv[0]); + spec = argv[optind]; if (sb_only) return dump_sb(spec); diff --git a/exfat/exfat-fuse/main.c b/exfat/exfat-fuse/main.c index 0023b9d13..53ce2feb5 100644 --- a/exfat/exfat-fuse/main.c +++ b/exfat/exfat-fuse/main.c @@ -92,7 +92,7 @@ static int fuse_exfat_readdir(const char* path, void* buffer, struct exfat_node* node; struct exfat_iterator it; int rc; - char name[EXFAT_NAME_MAX + 1]; + char name[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; exfat_debug("[%s] %s", __func__, path); @@ -118,7 +118,7 @@ static int fuse_exfat_readdir(const char* path, void* buffer, } while ((node = exfat_readdir(&ef, &it))) { - exfat_get_name(node, name, EXFAT_NAME_MAX); + exfat_get_name(node, name, sizeof(name) - 1); exfat_debug("[%s] %s: %s, %"PRId64" bytes, cluster 0x%x", __func__, name, IS_CONTIGUOUS(*node) ? "contiguous" : "fragmented", node->size, node->start_cluster); @@ -242,14 +242,24 @@ static int fuse_exfat_utimens(const char* path, const struct timespec tv[2]) return 0; } -#ifdef __APPLE__ static int fuse_exfat_chmod(const char* path, mode_t mode) { + const mode_t VALID_MODE_MASK = S_IFREG | S_IFDIR | + S_IRWXU | S_IRWXG | S_IRWXO; + exfat_debug("[%s] %s 0%ho", __func__, path, mode); - /* make OS X utilities happy */ + if (mode & ~VALID_MODE_MASK) + return -EPERM; + return 0; +} + +static int fuse_exfat_chown(const char* path, uid_t uid, gid_t gid) +{ + exfat_debug("[%s] %s %u:%u", __func__, path, uid, gid); + if (uid != ef.uid || gid != ef.gid) + return -EPERM; return 0; } -#endif static int fuse_exfat_statfs(const char* path, struct statvfs* sfs) { @@ -292,7 +302,7 @@ static void fuse_exfat_destroy(void* unused) static void usage(const char* prog) { - fprintf(stderr, "Usage: %s [-d] [-o options] [-v] <device> <dir>\n", prog); + fprintf(stderr, "Usage: %s [-d] [-o options] [-V] <device> <dir>\n", prog); exit(1); } @@ -311,9 +321,8 @@ static struct fuse_operations fuse_exfat_ops = .mkdir = fuse_exfat_mkdir, .rename = fuse_exfat_rename, .utimens = fuse_exfat_utimens, -#ifdef __APPLE__ .chmod = fuse_exfat_chmod, -#endif + .chown = fuse_exfat_chown, .statfs = fuse_exfat_statfs, .init = fuse_exfat_init, .destroy = fuse_exfat_destroy, @@ -398,7 +407,7 @@ int main(int argc, char* argv[]) int debug = 0; struct fuse_chan* fc = NULL; struct fuse* fh = NULL; - char** pp; + int opt; printf("FUSE exfat %u.%u.%u\n", EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH); @@ -410,40 +419,39 @@ int main(int argc, char* argv[]) return 1; } - for (pp = argv + 1; *pp; pp++) + while ((opt = getopt(argc, argv, "dno:Vv")) != -1) { - if (strcmp(*pp, "-o") == 0) + switch (opt) { - pp++; - if (*pp == NULL) - usage(argv[0]); - mount_options = add_option(mount_options, *pp, NULL); + case 'd': + debug = 1; + break; + case 'n': + break; + case 'o': + mount_options = add_option(mount_options, optarg, NULL); if (mount_options == NULL) return 1; - } - else if (strcmp(*pp, "-d") == 0) - debug = 1; - else if (strcmp(*pp, "-v") == 0) - { + break; + case 'V': free(mount_options); puts("Copyright (C) 2010-2013 Andrew Nayenko"); return 0; - } - else if (spec == NULL) - spec = *pp; - else if (mount_point == NULL) - mount_point = *pp; - else - { + case 'v': + break; + default: free(mount_options); usage(argv[0]); + break; } } - if (spec == NULL || mount_point == NULL) + if (argc - optind != 2) { free(mount_options); usage(argv[0]); } + spec = argv[optind]; + mount_point = argv[optind + 1]; if (exfat_mount(&ef, spec, mount_options) != 0) { diff --git a/exfat/exfat-fuse/mount.exfat-fuse.8 b/exfat/exfat-fuse/mount.exfat-fuse.8 index 83d2e6301..b7e9d5682 100644 --- a/exfat/exfat-fuse/mount.exfat-fuse.8 +++ b/exfat/exfat-fuse/mount.exfat-fuse.8 @@ -9,10 +9,16 @@ mount.exfat-fuse \- mount an exFAT file system .B \-d ] [ +.B \-n +] +[ .B \-o .I options ] [ +.B \-V +] +[ .B \-v ] .I device dir @@ -21,7 +27,7 @@ mount.exfat-fuse \- mount an exFAT file system .B mount.exfat-fuse is a free exFAT file system implementation with write support. exFAT is a simple file system created by Microsoft. It is intended to replace FAT32 -removing some of it's limitations. exFAT is a standard FS for SDXC memory +removing some of its limitations. exFAT is a standard FS for SDXC memory cards. .SH COMMAND LINE OPTIONS @@ -30,13 +36,19 @@ Command line options available: .BI \-d Enable debug logging and do not detach from shell. .TP +.BI \-n +Ignored. +.TP .BI \-o " options" File system specific options. For more details see .B FILE SYSTEM OPTIONS section below. .TP -.BI \-v +.BI \-V Print version and copyright. +.TP +.BI \-v +Ignored. .SH FILE SYSTEM OPTIONS .TP diff --git a/exfat/fsck/exfatfsck.8 b/exfat/fsck/exfatfsck.8 index 985500cd7..40d7c85f5 100644 --- a/exfat/fsck/exfatfsck.8 +++ b/exfat/fsck/exfatfsck.8 @@ -7,7 +7,7 @@ .SH SYNOPSIS .B exfatfsck [ -.B \-v +.B \-V ] .I device @@ -19,7 +19,7 @@ FS, it just reports found errors. .SH COMMAND LINE OPTIONS Command line options available: .TP -.BI \-v +.BI \-V Print version and copyright. .SH EXIT CODES diff --git a/exfat/fsck/main.c b/exfat/fsck/main.c index 9eefd747d..e865641c2 100644 --- a/exfat/fsck/main.c +++ b/exfat/fsck/main.c @@ -23,6 +23,7 @@ #include <exfat.h> #include <exfatfs.h> #include <inttypes.h> +#include <unistd.h> #define exfat_debug(format, ...) @@ -39,18 +40,18 @@ static int nodeck(struct exfat* ef, struct exfat_node* node) { if (CLUSTER_INVALID(c)) { - char name[EXFAT_NAME_MAX + 1]; + char name[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; - exfat_get_name(node, name, EXFAT_NAME_MAX); + exfat_get_name(node, name, sizeof(name) - 1); exfat_error("file `%s' has invalid cluster 0x%x", name, c); rc = 1; break; } if (BMAP_GET(ef->cmap.chunk, c - EXFAT_FIRST_DATA_CLUSTER) == 0) { - char name[EXFAT_NAME_MAX + 1]; + char name[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; - exfat_get_name(node, name, EXFAT_NAME_MAX); + exfat_get_name(node, name, sizeof(name) - 1); exfat_error("cluster 0x%x of file `%s' is not allocated", c, name); rc = 1; } @@ -76,7 +77,7 @@ static void dirck(struct exfat* ef, const char* path) return; path_length = strlen(path); - entry_path = malloc(path_length + 1 + EXFAT_NAME_MAX); + entry_path = malloc(path_length + 1 + UTF8_BYTES(EXFAT_NAME_MAX) + 1); if (entry_path == NULL) { exfat_error("out of memory"); @@ -95,7 +96,8 @@ static void dirck(struct exfat* ef, const char* path) } while ((node = exfat_readdir(ef, &it))) { - exfat_get_name(node, entry_path + path_length + 1, EXFAT_NAME_MAX); + exfat_get_name(node, entry_path + path_length + 1, + UTF8_BYTES(EXFAT_NAME_MAX)); exfat_debug("%s: %s, %"PRIu64" bytes, cluster %u", entry_path, IS_CONTIGUOUS(*node) ? "contiguous" : "fragmented", node->size, node->start_cluster); @@ -124,33 +126,34 @@ static void fsck(struct exfat* ef) static void usage(const char* prog) { - fprintf(stderr, "Usage: %s [-v] <device>\n", prog); + fprintf(stderr, "Usage: %s [-V] <device>\n", prog); exit(1); } int main(int argc, char* argv[]) { - char** pp; + int opt; const char* spec = NULL; struct exfat ef; printf("exfatfsck %u.%u.%u\n", EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH); - for (pp = argv + 1; *pp; pp++) + while ((opt = getopt(argc, argv, "V")) != -1) { - if (strcmp(*pp, "-v") == 0) + switch (opt) { + case 'V': puts("Copyright (C) 2011-2013 Andrew Nayenko"); return 0; - } - else if (spec == NULL) - spec = *pp; - else + default: usage(argv[0]); + break; + } } - if (spec == NULL) + if (argc - optind != 1) usage(argv[0]); + spec = argv[optind]; if (exfat_mount(&ef, spec, "ro") != 0) return 1; diff --git a/exfat/label/exfatlabel.8 b/exfat/label/exfatlabel.8 index 429f3cc02..dd2ef1c00 100644 --- a/exfat/label/exfatlabel.8 +++ b/exfat/label/exfatlabel.8 @@ -7,7 +7,7 @@ .SH SYNOPSIS .B exfatlabel [ -.B \-v +.B \-V ] .I device [ @@ -35,7 +35,7 @@ just prints current volume name. .SH COMMAND LINE OPTIONS Command line options available: .TP -.BI \-v +.BI \-V Print version and copyright. .SH EXIT CODES diff --git a/exfat/label/main.c b/exfat/label/main.c index 8a429d58d..559503509 100644 --- a/exfat/label/main.c +++ b/exfat/label/main.c @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) int rc = 0; for (pp = argv + 1; *pp; pp++) - if (strcmp(*pp, "-v") == 0) + if (strcmp(*pp, "-V") == 0) { printf("exfatlabel %u.%u.%u\n", EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH); @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) if (argc != 2 && argc != 3) { - fprintf(stderr, "Usage: %s [-v] <device> [label]\n", argv[0]); + fprintf(stderr, "Usage: %s [-V] <device> [label]\n", argv[0]); return 1; } diff --git a/exfat/libexfat/exfat.h b/exfat/libexfat/exfat.h index 3e4223e5d..a6a9f706d 100644 --- a/exfat/libexfat/exfat.h +++ b/exfat/libexfat/exfat.h @@ -46,6 +46,7 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define DIV_ROUND_UP(x, d) (((x) + (d) - 1) / (d)) #define ROUND_UP(x, d) (DIV_ROUND_UP(x, d) * (d)) +#define UTF8_BYTES(c) ((c) * 6) /* UTF-8 character can occupy up to 6 bytes */ #define BMAP_GET(bitmap, index) \ (((uint8_t*) bitmap)[(index) / 8] & (1u << ((index) % 8))) @@ -98,8 +99,7 @@ struct exfat bool dirty; } cmap; - char label[EXFAT_ENAME_MAX * 6 + 1]; /* a character can occupy up to - 6 bytes in UTF-8 */ + char label[UTF8_BYTES(EXFAT_ENAME_MAX) + 1]; void* zero_cluster; int dmask, fmask; uid_t uid; diff --git a/exfat/libexfat/node.c b/exfat/libexfat/node.c index c2ee0da38..f89b5731d 100644 --- a/exfat/libexfat/node.c +++ b/exfat/libexfat/node.c @@ -44,8 +44,8 @@ void exfat_put_node(struct exfat* ef, struct exfat_node* node) { if (--node->references < 0) { - char buffer[EXFAT_NAME_MAX + 1]; - exfat_get_name(node, buffer, EXFAT_NAME_MAX); + char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; + exfat_get_name(node, buffer, sizeof(buffer) - 1); exfat_bug("reference counter of `%s' is below zero", buffer); } @@ -293,9 +293,9 @@ static int readdir(struct exfat* ef, const struct exfat_node* parent, */ if (real_size != (*node)->size) { - char buffer[EXFAT_NAME_MAX + 1]; + char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; - exfat_get_name(*node, buffer, EXFAT_NAME_MAX); + exfat_get_name(*node, buffer, sizeof(buffer) - 1); exfat_error("`%s' real size does not equal to size " "(%"PRIu64" != %"PRIu64")", buffer, real_size, (*node)->size); @@ -303,9 +303,9 @@ static int readdir(struct exfat* ef, const struct exfat_node* parent, } if (actual_checksum != reference_checksum) { - char buffer[EXFAT_NAME_MAX + 1]; + char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; - exfat_get_name(*node, buffer, EXFAT_NAME_MAX); + exfat_get_name(*node, buffer, sizeof(buffer) - 1); exfat_error("`%s' has invalid checksum (0x%hx != 0x%hx)", buffer, actual_checksum, reference_checksum); goto error; @@ -389,7 +389,7 @@ static int readdir(struct exfat* ef, const struct exfat_node* parent, goto error; } if (utf16_to_utf8(ef->label, label->name, - sizeof(ef->label), EXFAT_ENAME_MAX) != 0) + sizeof(ef->label) - 1, EXFAT_ENAME_MAX) != 0) goto error; break; @@ -493,8 +493,8 @@ static void reset_cache(struct exfat* ef, struct exfat_node* node) node->flags &= ~EXFAT_ATTRIB_CACHED; if (node->references != 0) { - char buffer[EXFAT_NAME_MAX + 1]; - exfat_get_name(node, buffer, EXFAT_NAME_MAX); + char buffer[UTF8_BYTES(EXFAT_NAME_MAX) + 1]; + exfat_get_name(node, buffer, sizeof(buffer) - 1); exfat_warn("non-zero reference counter (%d) for `%s'", node->references, buffer); } @@ -1051,5 +1051,6 @@ int exfat_set_label(struct exfat* ef, const char* label) exfat_pwrite(ef->dev, &entry, sizeof(struct exfat_entry_label), co2o(ef, cluster, offset)); + strcpy(ef->label, label); return 0; } diff --git a/exfat/mkfs/main.c b/exfat/mkfs/main.c index 97e465a5b..12bb838b5 100644 --- a/exfat/mkfs/main.c +++ b/exfat/mkfs/main.c @@ -188,14 +188,14 @@ static void usage(const char* prog) { fprintf(stderr, "Usage: %s [-i volume-id] [-n label] " "[-p partition-first-sector] " - "[-s sectors-per-cluster] [-v] <device>\n", prog); + "[-s sectors-per-cluster] [-V] <device>\n", prog); exit(1); } int main(int argc, char* argv[]) { const char* spec = NULL; - char** pp; + int opt; int spc_bits = -1; const char* volume_label = NULL; uint32_t volume_serial = 0; @@ -205,53 +205,38 @@ int main(int argc, char* argv[]) printf("mkexfatfs %u.%u.%u\n", EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH); - for (pp = argv + 1; *pp; pp++) + while ((opt = getopt(argc, argv, "i:n:p:s:V")) != -1) { - if (strcmp(*pp, "-s") == 0) + switch (opt) { - pp++; - if (*pp == NULL) - usage(argv[0]); - spc_bits = logarithm2(atoi(*pp)); + case 'i': + volume_serial = strtol(optarg, NULL, 16); + break; + case 'n': + volume_label = optarg; + break; + case 'p': + first_sector = strtoll(optarg, NULL, 10); + break; + case 's': + spc_bits = logarithm2(atoi(optarg)); if (spc_bits < 0) { - exfat_error("invalid option value: `%s'", *pp); + exfat_error("invalid option value: `%s'", optarg); return 1; } - } - else if (strcmp(*pp, "-n") == 0) - { - pp++; - if (*pp == NULL) - usage(argv[0]); - volume_label = *pp; - } - else if (strcmp(*pp, "-i") == 0) - { - pp++; - if (*pp == NULL) - usage(argv[0]); - volume_serial = strtol(*pp, NULL, 16); - } - else if (strcmp(*pp, "-p") == 0) - { - pp++; - if (*pp == NULL) - usage(argv[0]); - first_sector = strtoll(*pp, NULL, 10); - } - else if (strcmp(*pp, "-v") == 0) - { + break; + case 'V': puts("Copyright (C) 2011-2013 Andrew Nayenko"); return 0; - } - else if (spec == NULL) - spec = *pp; - else + default: usage(argv[0]); + break; + } } - if (spec == NULL) + if (argc - optind != 1) usage(argv[0]); + spec = argv[optind]; dev = exfat_open(spec, EXFAT_MODE_RW); if (dev == NULL) diff --git a/exfat/mkfs/mkexfatfs.8 b/exfat/mkfs/mkexfatfs.8 index 7d3ffecc1..5f6ba3db7 100644 --- a/exfat/mkfs/mkexfatfs.8 +++ b/exfat/mkfs/mkexfatfs.8 @@ -23,7 +23,7 @@ .I sectors-per-cluster ] [ -.B \-v +.B \-V ] .I device @@ -55,7 +55,7 @@ exceed 32 MB. Default cluster sizes are: 32 KB if volume size is from 256 MB to 32 GB, 128 KB if volume size is 32 GB or larger. .TP -.BI \-v +.BI \-V Print version and copyright. .SH EXIT CODES |