aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-02-15 11:59:00 +0000
committerRon Yorston <rmy@pobox.com>2020-02-15 12:32:12 +0000
commit6885083a7e4f94938ca0a98e2c6c69a84eb08a1f (patch)
tree1251e0b2796afecf15830a6062fc4f00d1f64470
parentadb70e66cffcd47255fc61f109d617b48f7fddd2 (diff)
downloadbusybox-w32-6885083a7e4f94938ca0a98e2c6c69a84eb08a1f.tar.gz
busybox-w32-6885083a7e4f94938ca0a98e2c6c69a84eb08a1f.tar.bz2
busybox-w32-6885083a7e4f94938ca0a98e2c6c69a84eb08a1f.zip
win32: save space in statfs
Place filesystem names in a single null-separated string and search it using index_in_strings(). Use the result (offset by 1 to allow for failure) to index an array of filesytem types. Saves 112 bytes.
-rw-r--r--win32/statfs.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/win32/statfs.c b/win32/statfs.c
index 22fc591ec..6b28792e2 100644
--- a/win32/statfs.c
+++ b/win32/statfs.c
@@ -12,6 +12,10 @@ int statfs(const char *file, struct statfs *buf)
12 DWORD serial, namelen, flags; 12 DWORD serial, namelen, flags;
13 char fsname[100]; 13 char fsname[100];
14 struct mntent *mnt; 14 struct mntent *mnt;
15 /* Valid filesystem names don't seem to be documented. The following
16 * are present in Wine (dlls/kernel32/volume.c). */
17#define FS_NAMES "NTFS\0FAT\0FAT32\0CDFS\0UDF\0"
18 int fstypes[] = {0, 0x5346544e, 0x4006, 0x4006, 0x9660, 0x15013346};
15 19
16 if ( (mnt=find_mount_point(file, 0)) == NULL ) { 20 if ( (mnt=find_mount_point(file, 0)) == NULL ) {
17 return -1; 21 return -1;
@@ -49,26 +53,7 @@ int statfs(const char *file, struct statfs *buf)
49 else 53 else
50 buf->f_bsize = 65536; 54 buf->f_bsize = 65536;
51 55
52 /* 56 buf->f_type = fstypes[index_in_strings(FS_NAMES, fsname)+1];
53 * Valid filesystem names don't seem to be documented. The following
54 * are present in Wine (dlls/kernel32/volume.c).
55 */
56 if ( strcmp(fsname, "NTFS") == 0 ) {
57 buf->f_type = 0x5346544e;
58 }
59 else if ( strcmp(fsname, "FAT") == 0 || strcmp(fsname, "FAT32") == 0 ) {
60 buf->f_type = 0x4006;
61 }
62 else if ( strcmp(fsname, "CDFS") == 0 ) {
63 buf->f_type = 0x9660;
64 }
65 else if ( strcmp(fsname, "UDF") == 0 ) {
66 buf->f_type = 0x15013346;
67 }
68 else {
69 buf->f_type = 0;
70 }
71
72 buf->f_frsize = buf->f_bsize; 57 buf->f_frsize = buf->f_bsize;
73 buf->f_blocks = total_number_of_bytes / buf->f_bsize; 58 buf->f_blocks = total_number_of_bytes / buf->f_bsize;
74 buf->f_bfree = total_number_of_free_bytes / buf->f_bsize; 59 buf->f_bfree = total_number_of_free_bytes / buf->f_bsize;