aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-26 01:47:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-26 01:47:34 +0000
commit68f21872652975e4541cec841c581d4c594273c5 (patch)
tree109a91663d2c73593e91e041e12f89cbfb7f72d4
parent1457915afcb8fb0697f441dce1697b278d25f4a5 (diff)
downloadbusybox-w32-68f21872652975e4541cec841c581d4c594273c5.tar.gz
busybox-w32-68f21872652975e4541cec841c581d4c594273c5.tar.bz2
busybox-w32-68f21872652975e4541cec841c581d4c594273c5.zip
mount: use switch (compare_string_array(..))
where appropriate, saves >100 bytes.
-rw-r--r--util-linux/mount.c141
1 files changed, 105 insertions, 36 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 2c5e23177..a9464baee 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -872,99 +872,168 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts)
872 for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) { 872 for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) {
873 char *opteq = strchr(opt, '='); 873 char *opteq = strchr(opt, '=');
874 if (opteq) { 874 if (opteq) {
875 const char *const options[] = {
876 /* 0 */ "rsize",
877 /* 1 */ "wsize",
878 /* 2 */ "timeo",
879 /* 3 */ "retrans",
880 /* 4 */ "acregmin",
881 /* 5 */ "acregmax",
882 /* 6 */ "acdirmin",
883 /* 7 */ "acdirmax",
884 /* 8 */ "actimeo",
885 /* 9 */ "retry",
886 /* 10 */ "port",
887 /* 11 */ "mountport",
888 /* 12 */ "mounthost",
889 /* 13 */ "mountprog",
890 /* 14 */ "mountvers",
891 /* 15 */ "nfsprog",
892 /* 16 */ "nfsvers",
893 /* 17 */ "vers",
894 /* 18 */ "proto",
895 /* 19 */ "namlen",
896 /* 20 */ "addr",
897 NULL
898 };
875 int val = xatoi_u(opteq + 1); 899 int val = xatoi_u(opteq + 1);
876 *opteq = '\0'; 900 *opteq = '\0';
877 if (!strcmp(opt, "rsize")) 901 switch (compare_string_array(options, opt)) {
902 case 0: // "rsize"
878 data.rsize = val; 903 data.rsize = val;
879 else if (!strcmp(opt, "wsize")) 904 break;
905 case 1: // "wsize"
880 data.wsize = val; 906 data.wsize = val;
881 else if (!strcmp(opt, "timeo")) 907 break;
908 case 2: // "timeo"
882 data.timeo = val; 909 data.timeo = val;
883 else if (!strcmp(opt, "retrans")) 910 break;
911 case 3: // "retrans"
884 data.retrans = val; 912 data.retrans = val;
885 else if (!strcmp(opt, "acregmin")) 913 break;
914 case 4: // "acregmin"
886 data.acregmin = val; 915 data.acregmin = val;
887 else if (!strcmp(opt, "acregmax")) 916 break;
917 case 5: // "acregmax"
888 data.acregmax = val; 918 data.acregmax = val;
889 else if (!strcmp(opt, "acdirmin")) 919 break;
920 case 6: // "acdirmin"
890 data.acdirmin = val; 921 data.acdirmin = val;
891 else if (!strcmp(opt, "acdirmax")) 922 break;
923 case 7: // "acdirmax"
892 data.acdirmax = val; 924 data.acdirmax = val;
893 else if (!strcmp(opt, "actimeo")) { 925 break;
926 case 8: // "actimeo"
894 data.acregmin = val; 927 data.acregmin = val;
895 data.acregmax = val; 928 data.acregmax = val;
896 data.acdirmin = val; 929 data.acdirmin = val;
897 data.acdirmax = val; 930 data.acdirmax = val;
898 } 931 break;
899 else if (!strcmp(opt, "retry")) 932 case 9: // "retry"
900 retry = val; 933 retry = val;
901 else if (!strcmp(opt, "port")) 934 break;
935 case 10: // "port"
902 port = val; 936 port = val;
903 else if (!strcmp(opt, "mountport")) 937 break;
938 case 11: // "mountport"
904 mountport = val; 939 mountport = val;
905 else if (!strcmp(opt, "mounthost")) 940 break;
941 case 12: // "mounthost"
906 mounthost = xstrndup(opteq+1, 942 mounthost = xstrndup(opteq+1,
907 strcspn(opteq+1," \t\n\r,")); 943 strcspn(opteq+1," \t\n\r,"));
908 else if (!strcmp(opt, "mountprog")) 944 break;
945 case 13: // "mountprog"
909 mountprog = val; 946 mountprog = val;
910 else if (!strcmp(opt, "mountvers")) 947 break;
948 case 14: // "mountvers"
911 mountvers = val; 949 mountvers = val;
912 else if (!strcmp(opt, "nfsprog")) 950 break;
951 case 15: // "nfsprog"
913 nfsprog = val; 952 nfsprog = val;
914 else if (!strcmp(opt, "nfsvers") || 953 break;
915 !strcmp(opt, "vers")) 954 case 16: // "nfsvers"
955 case 17: // "vers"
916 nfsvers = val; 956 nfsvers = val;
917 else if (!strcmp(opt, "proto")) { 957 break;
958 case 18: // "proto"
918 if (!strncmp(opteq+1, "tcp", 3)) 959 if (!strncmp(opteq+1, "tcp", 3))
919 tcp = 1; 960 tcp = 1;
920 else if (!strncmp(opteq+1, "udp", 3)) 961 else if (!strncmp(opteq+1, "udp", 3))
921 tcp = 0; 962 tcp = 0;
922 else 963 else
923 bb_error_msg("warning: unrecognized proto= option"); 964 bb_error_msg("warning: unrecognized proto= option");
924 } else if (!strcmp(opt, "namlen")) { 965 break;
966 case 19: // "namlen"
925 if (nfs_mount_version >= 2) 967 if (nfs_mount_version >= 2)
926 data.namlen = val; 968 data.namlen = val;
927 else 969 else
928 bb_error_msg("warning: option namlen is not supported\n"); 970 bb_error_msg("warning: option namlen is not supported\n");
929 } else if (!strcmp(opt, "addr")) 971 break;
930 /* ignore */; 972 case 20: // "addr" - ignore
931 else { 973 break;
974 default:
932 bb_error_msg("unknown nfs mount parameter: %s=%d", opt, val); 975 bb_error_msg("unknown nfs mount parameter: %s=%d", opt, val);
933 goto fail; 976 goto fail;
934 } 977 }
935 } 978 }
936 else { 979 else {
980 const char *const options[] = {
981 "bg",
982 "fg",
983 "soft",
984 "hard",
985 "intr",
986 "posix",
987 "cto",
988 "ac",
989 "tcp",
990 "udp",
991 "lock",
992 NULL
993 };
937 int val = 1; 994 int val = 1;
938 if (!strncmp(opt, "no", 2)) { 995 if (!strncmp(opt, "no", 2)) {
939 val = 0; 996 val = 0;
940 opt += 2; 997 opt += 2;
941 } 998 }
942 if (!strcmp(opt, "bg")) 999 switch (compare_string_array(options, opt)) {
1000 case 0: // "bg"
943 bg = val; 1001 bg = val;
944 else if (!strcmp(opt, "fg")) 1002 break;
1003 case 1: // "fg"
945 bg = !val; 1004 bg = !val;
946 else if (!strcmp(opt, "soft")) 1005 break;
1006 case 2: // "soft"
947 soft = val; 1007 soft = val;
948 else if (!strcmp(opt, "hard")) 1008 break;
1009 case 3: // "hard"
949 soft = !val; 1010 soft = !val;
950 else if (!strcmp(opt, "intr")) 1011 break;
1012 case 4: // "intr"
951 intr = val; 1013 intr = val;
952 else if (!strcmp(opt, "posix")) 1014 break;
1015 case 5: // "posix"
953 posix = val; 1016 posix = val;
954 else if (!strcmp(opt, "cto")) 1017 break;
1018 case 6: // "cto"
955 nocto = !val; 1019 nocto = !val;
956 else if (!strcmp(opt, "ac")) 1020 break;
1021 case 7: // "ac"
957 noac = !val; 1022 noac = !val;
958 else if (!strcmp(opt, "tcp")) 1023 break;
1024 case 8: // "tcp"
959 tcp = val; 1025 tcp = val;
960 else if (!strcmp(opt, "udp")) 1026 break;
1027 case 9: // "udp"
961 tcp = !val; 1028 tcp = !val;
962 else if (!strcmp(opt, "lock")) { 1029 break;
1030 case 10: // "lock"
963 if (nfs_mount_version >= 3) 1031 if (nfs_mount_version >= 3)
964 nolock = !val; 1032 nolock = !val;
965 else 1033 else
966 bb_error_msg("warning: option nolock is not supported"); 1034 bb_error_msg("warning: option nolock is not supported");
967 } else { 1035 break;
1036 default:
968 bb_error_msg("unknown nfs mount option: %s%s", val ? "" : "no", opt); 1037 bb_error_msg("unknown nfs mount option: %s%s", val ? "" : "no", opt);
969 goto fail; 1038 goto fail;
970 } 1039 }