mount: size-optimize mount_options[] and nfs_errtbl[]

777253     974    9676  787903   c05bf busybox_old
 777209     974    9676  787859   c0593 busybox_unstripped
This commit is contained in:
Denis Vlasenko
2007-10-29 19:18:39 +00:00
parent a59f435b5f
commit 63430ae35a

View File

@@ -37,7 +37,7 @@
#if defined(__dietlibc__) #if defined(__dietlibc__)
/* 16.12.2006, Sampo Kellomaki (sampo@iki.fi) /* 16.12.2006, Sampo Kellomaki (sampo@iki.fi)
* dietlibc-0.30 does not have implementation of getmntent_r() */ * dietlibc-0.30 does not have implementation of getmntent_r() */
struct mntent *getmntent_r(FILE* stream, struct mntent* result, char* buffer, int bufsize) static struct mntent *getmntent_r(FILE* stream, struct mntent* result, char* buffer, int bufsize)
{ {
struct mntent* ment = getmntent(stream); struct mntent* ment = getmntent(stream);
memcpy(result, ment, sizeof(struct mntent)); memcpy(result, ment, sizeof(struct mntent));
@@ -66,63 +66,105 @@ enum {
/* Standard mount options (from -o options or --options), with corresponding /* Standard mount options (from -o options or --options), with corresponding
* flags */ * flags */
static const struct { static const int32_t mount_options[] = {
const char *name;
long flags;
} mount_options[] = {
// MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs. // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs.
USE_FEATURE_MOUNT_LOOP( USE_FEATURE_MOUNT_LOOP(
{"loop", 0}, /* "loop" */ 0,
) )
USE_FEATURE_MOUNT_FSTAB( USE_FEATURE_MOUNT_FSTAB(
{"defaults", 0}, /* "defaults" */ 0,
/* {"quiet", 0}, - do not filter out, vfat wants to see it */ /* "quiet" 0 - do not filter out, vfat wants to see it */
{"noauto", MOUNT_NOAUTO}, /* "noauto" */ MOUNT_NOAUTO,
{"sw", MOUNT_SWAP}, /* "sw" */ MOUNT_SWAP,
{"swap", MOUNT_SWAP}, /* "swap" */ MOUNT_SWAP,
USE_DESKTOP({"user", MOUNT_USERS},) USE_DESKTOP(/* "user" */ MOUNT_USERS,)
USE_DESKTOP({"users", MOUNT_USERS},) USE_DESKTOP(/* "users" */ MOUNT_USERS,)
) )
USE_FEATURE_MOUNT_FLAGS( USE_FEATURE_MOUNT_FLAGS(
// vfs flags // vfs flags
{"nosuid", MS_NOSUID}, /* "nosuid" */ MS_NOSUID,
{"suid", ~MS_NOSUID}, /* "suid" */ ~MS_NOSUID,
{"dev", ~MS_NODEV}, /* "dev" */ ~MS_NODEV,
{"nodev", MS_NODEV}, /* "nodev" */ MS_NODEV,
{"exec", ~MS_NOEXEC}, /* "exec" */ ~MS_NOEXEC,
{"noexec", MS_NOEXEC}, /* "noexec" */ MS_NOEXEC,
{"sync", MS_SYNCHRONOUS}, /* "sync" */ MS_SYNCHRONOUS,
{"async", ~MS_SYNCHRONOUS}, /* "async" */ ~MS_SYNCHRONOUS,
{"atime", ~MS_NOATIME}, /* "atime" */ ~MS_NOATIME,
{"noatime", MS_NOATIME}, /* "noatime" */ MS_NOATIME,
{"diratime", ~MS_NODIRATIME}, /* "diratime" */ ~MS_NODIRATIME,
{"nodiratime", MS_NODIRATIME}, /* "nodiratime" */ MS_NODIRATIME,
{"loud", ~MS_SILENT}, /* "loud" */ ~MS_SILENT,
// action flags // action flags
/* "bind" */ MS_BIND,
{"bind", MS_BIND}, /* "move" */ MS_MOVE,
{"move", MS_MOVE}, /* "shared" */ MS_SHARED,
{"shared", MS_SHARED}, /* "slave" */ MS_SLAVE,
{"slave", MS_SLAVE}, /* "private" */ MS_PRIVATE,
{"private", MS_PRIVATE}, /* "unbindable" */ MS_UNBINDABLE,
{"unbindable", MS_UNBINDABLE}, /* "rshared" */ MS_SHARED|MS_RECURSIVE,
{"rshared", MS_SHARED|MS_RECURSIVE}, /* "rslave" */ MS_SLAVE|MS_RECURSIVE,
{"rslave", MS_SLAVE|MS_RECURSIVE}, /* "rprivate" */ MS_SLAVE|MS_RECURSIVE,
{"rprivate", MS_SLAVE|MS_RECURSIVE}, /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE,
{"runbindable", MS_UNBINDABLE|MS_RECURSIVE},
) )
// Always understood. // Always understood.
/* "ro" */ MS_RDONLY, // vfs flag
{"ro", MS_RDONLY}, // vfs flag /* "rw" */ ~MS_RDONLY, // vfs flag
{"rw", ~MS_RDONLY}, // vfs flag /* "remount" */ MS_REMOUNT // action flag
{"remount", MS_REMOUNT}, // action flag
}; };
static const char mount_option_str[] =
USE_FEATURE_MOUNT_LOOP(
"loop" "\0"
)
USE_FEATURE_MOUNT_FSTAB(
"defaults" "\0"
/* "quiet" "\0" - do not filter out, vfat wants to see it */
"noauto" "\0"
"sw" "\0"
"swap" "\0"
USE_DESKTOP("user" "\0")
USE_DESKTOP("users" "\0")
)
USE_FEATURE_MOUNT_FLAGS(
// vfs flags
"nosuid" "\0"
"suid" "\0"
"dev" "\0"
"nodev" "\0"
"exec" "\0"
"noexec" "\0"
"sync" "\0"
"async" "\0"
"atime" "\0"
"noatime" "\0"
"diratime" "\0"
"nodiratime" "\0"
"loud" "\0"
// action flags
"bind" "\0"
"move" "\0"
"shared" "\0"
"slave" "\0"
"private" "\0"
"unbindable" "\0"
"rshared" "\0"
"rslave" "\0"
"rprivate" "\0"
"runbindable" "\0"
)
// Always understood.
"ro" "\0" // vfs flag
"rw" "\0" // vfs flag
"remount" "\0" // action flag
;
/* Append mount options to string */ /* Append mount options to string */
static void append_mount_options(char **oldopts, const char *newopts) static void append_mount_options(char **oldopts, const char *newopts)
@@ -137,7 +179,7 @@ static void append_mount_options(char **oldopts, const char *newopts)
p = *oldopts; p = *oldopts;
while (1) { while (1) {
if (!strncmp(p, newopts, len) if (!strncmp(p, newopts, len)
&& (p[len]==',' || p[len]==0)) && (p[len] == ',' || p[len] == '\0'))
goto skip; goto skip;
p = strchr(p,','); p = strchr(p,',');
if (!p) break; if (!p) break;
@@ -166,17 +208,19 @@ static int parse_mount_options(char *options, char **unrecognized)
for (;;) { for (;;) {
int i; int i;
char *comma = strchr(options, ','); char *comma = strchr(options, ',');
const char *option_str = mount_option_str;
if (comma) *comma = 0; if (comma) *comma = '\0';
// Find this option in mount_options // Find this option in mount_options
for (i = 0; i < ARRAY_SIZE(mount_options); i++) { for (i = 0; i < ARRAY_SIZE(mount_options); i++) {
if (!strcasecmp(mount_options[i].name, options)) { if (!strcasecmp(option_str, options)) {
long fl = mount_options[i].flags; long fl = mount_options[i];
if (fl < 0) flags &= fl; if (fl < 0) flags &= fl;
else flags |= fl; else flags |= fl;
break; break;
} }
option_str += strlen(option_str) + 1;
} }
// If unrecognized not NULL, append unrecognized mount options */ // If unrecognized not NULL, append unrecognized mount options */
if (unrecognized && i == ARRAY_SIZE(mount_options)) { if (unrecognized && i == ARRAY_SIZE(mount_options)) {
@@ -282,6 +326,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
if (ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc && !(vfsflags & MS_REMOUNT)) { if (ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc && !(vfsflags & MS_REMOUNT)) {
char *fsname; char *fsname;
FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
const char *option_str = mount_option_str;
int i; int i;
if (!mountTable) { if (!mountTable) {
@@ -291,14 +336,16 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
// Add vfs string flags // Add vfs string flags
for (i=0; mount_options[i].flags != MS_REMOUNT; i++) for (i = 0; mount_options[i] != MS_REMOUNT; i++) {
if (mount_options[i].flags > 0 && (mount_options[i].flags & vfsflags)) if (mount_options[i] > 0 && (mount_options[i] & vfsflags))
append_mount_options(&(mp->mnt_opts), mount_options[i].name); append_mount_options(&(mp->mnt_opts), option_str);
option_str += strlen(option_str) + 1;
}
// Remove trailing / (if any) from directory we mounted on // Remove trailing / (if any) from directory we mounted on
i = strlen(mp->mnt_dir) - 1; i = strlen(mp->mnt_dir) - 1;
if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = 0; if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0';
// Convert to canonical pathnames as needed // Convert to canonical pathnames as needed
@@ -550,8 +597,8 @@ enum {
// Convert each NFSERR_BLAH into EBLAH // Convert each NFSERR_BLAH into EBLAH
static const struct { static const struct {
int stat; short stat;
int errnum; short errnum;
} nfs_errtbl[] = { } nfs_errtbl[] = {
{0,0}, {1,EPERM}, {2,ENOENT}, {5,EIO}, {6,ENXIO}, {13,EACCES}, {17,EEXIST}, {0,0}, {1,EPERM}, {2,ENOENT}, {5,EIO}, {6,ENXIO}, {13,EACCES}, {17,EEXIST},
{19,ENODEV}, {20,ENOTDIR}, {21,EISDIR}, {22,EINVAL}, {27,EFBIG}, {19,ENODEV}, {20,ENOTDIR}, {21,EISDIR}, {22,EINVAL}, {27,EFBIG},