diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-19 02:03:14 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-19 02:03:14 +0000 |
| commit | cf70d8ec9d1561b5f38b28a77380ad5b1417637c (patch) | |
| tree | f474d4e3c44a64076935fd073b1fed03c0ac17d9 | |
| parent | 1d1e40d1fd9c684fd019a61334145adfe375bab2 (diff) | |
| download | busybox-w32-cf70d8ec9d1561b5f38b28a77380ad5b1417637c.tar.gz busybox-w32-cf70d8ec9d1561b5f38b28a77380ad5b1417637c.tar.bz2 busybox-w32-cf70d8ec9d1561b5f38b28a77380ad5b1417637c.zip | |
fsck: stop using strtok
git-svn-id: svn://busybox.net/trunk/busybox@17371 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | e2fsprogs/fsck.c | 157 |
1 files changed, 84 insertions, 73 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 681bfd15f..357f5eb60 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
| @@ -45,6 +45,7 @@ | |||
| 45 | */ | 45 | */ |
| 46 | 46 | ||
| 47 | struct fs_info { | 47 | struct fs_info { |
| 48 | struct fs_info *next; | ||
| 48 | char *device; | 49 | char *device; |
| 49 | char *mountpt; | 50 | char *mountpt; |
| 50 | char *type; | 51 | char *type; |
| @@ -52,7 +53,6 @@ struct fs_info { | |||
| 52 | int freq; | 53 | int freq; |
| 53 | int passno; | 54 | int passno; |
| 54 | int flags; | 55 | int flags; |
| 55 | struct fs_info *next; | ||
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | #define FLAG_DONE 1 | 58 | #define FLAG_DONE 1 |
| @@ -61,6 +61,7 @@ struct fs_info { | |||
| 61 | * Structure to allow exit codes to be stored | 61 | * Structure to allow exit codes to be stored |
| 62 | */ | 62 | */ |
| 63 | struct fsck_instance { | 63 | struct fsck_instance { |
| 64 | struct fsck_instance *next; | ||
| 64 | int pid; | 65 | int pid; |
| 65 | int flags; | 66 | int flags; |
| 66 | int exit_status; | 67 | int exit_status; |
| @@ -69,7 +70,6 @@ struct fsck_instance { | |||
| 69 | char *type; | 70 | char *type; |
| 70 | char *device; | 71 | char *device; |
| 71 | char *base_device; /* /dev/hda for /dev/hdaN etc */ | 72 | char *base_device; /* /dev/hda for /dev/hdaN etc */ |
| 72 | struct fsck_instance *next; | ||
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | static const char *const ignored_types[] = { | 75 | static const char *const ignored_types[] = { |
| @@ -104,6 +104,14 @@ static char **args; | |||
| 104 | static int num_devices; | 104 | static int num_devices; |
| 105 | static int num_args; | 105 | static int num_args; |
| 106 | static int verbose; | 106 | static int verbose; |
| 107 | |||
| 108 | #define FS_TYPE_FLAG_NORMAL 0 | ||
| 109 | #define FS_TYPE_FLAG_OPT 1 | ||
| 110 | #define FS_TYPE_FLAG_NEGOPT 2 | ||
| 111 | static char **fs_type_list; | ||
| 112 | static uint8_t *fs_type_flag; | ||
| 113 | static smallint fs_type_negated; | ||
| 114 | |||
| 107 | static volatile smallint cancel_requested; | 115 | static volatile smallint cancel_requested; |
| 108 | static smallint doall; | 116 | static smallint doall; |
| 109 | static smallint noexecute; | 117 | static smallint noexecute; |
| @@ -122,13 +130,6 @@ static struct fs_info *filesys_info; | |||
| 122 | static struct fs_info *filesys_last; | 130 | static struct fs_info *filesys_last; |
| 123 | static struct fsck_instance *instance_list; | 131 | static struct fsck_instance *instance_list; |
| 124 | 132 | ||
| 125 | #define FS_TYPE_FLAG_NORMAL 0 | ||
| 126 | #define FS_TYPE_FLAG_OPT 1 | ||
| 127 | #define FS_TYPE_FLAG_NEGOPT 2 | ||
| 128 | static char **fs_type_list; | ||
| 129 | static uint8_t *fs_type_flag; | ||
| 130 | static int fs_type_negated; | ||
| 131 | |||
| 132 | /* | 133 | /* |
| 133 | * Return the "base device" given a particular device; this is used to | 134 | * Return the "base device" given a particular device; this is used to |
| 134 | * assure that we only fsck one partition on a particular drive at any | 135 | * assure that we only fsck one partition on a particular drive at any |
| @@ -742,39 +743,90 @@ static void fsck_device(struct fs_info *fs, int interactive) | |||
| 742 | } | 743 | } |
| 743 | 744 | ||
| 744 | /* | 745 | /* |
| 746 | * Returns TRUE if a partition on the same disk is already being | ||
| 747 | * checked. | ||
| 748 | */ | ||
| 749 | static int device_already_active(char *device) | ||
| 750 | { | ||
| 751 | struct fsck_instance *inst; | ||
| 752 | char *base; | ||
| 753 | |||
| 754 | if (force_all_parallel) | ||
| 755 | return 0; | ||
| 756 | |||
| 757 | #ifdef BASE_MD | ||
| 758 | /* Don't check a soft raid disk with any other disk */ | ||
| 759 | if (instance_list | ||
| 760 | && (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1) | ||
| 761 | || !strncmp(device, BASE_MD, sizeof(BASE_MD)-1)) | ||
| 762 | ) { | ||
| 763 | return 1; | ||
| 764 | } | ||
| 765 | #endif | ||
| 766 | |||
| 767 | base = base_device(device); | ||
| 768 | /* | ||
| 769 | * If we don't know the base device, assume that the device is | ||
| 770 | * already active if there are any fsck instances running. | ||
| 771 | */ | ||
| 772 | if (!base) | ||
| 773 | return (instance_list != NULL); | ||
| 774 | |||
| 775 | for (inst = instance_list; inst; inst = inst->next) { | ||
| 776 | if (!inst->base_device || !strcmp(base, inst->base_device)) { | ||
| 777 | free(base); | ||
| 778 | return 1; | ||
| 779 | } | ||
| 780 | } | ||
| 781 | |||
| 782 | free(base); | ||
| 783 | return 0; | ||
| 784 | } | ||
| 785 | |||
| 786 | /* | ||
| 745 | * This function returns true if a particular option appears in a | 787 | * This function returns true if a particular option appears in a |
| 746 | * comma-delimited options list | 788 | * comma-delimited options list |
| 747 | */ | 789 | */ |
| 748 | static int opt_in_list(char *opt, char *optlist) | 790 | static int opt_in_list(char *opt, char *optlist) |
| 749 | { | 791 | { |
| 750 | char *list, *s; | 792 | char *s; |
| 793 | int len; | ||
| 751 | 794 | ||
| 752 | if (!optlist) | 795 | if (!optlist) |
| 753 | return 0; | 796 | return 0; |
| 754 | list = xstrdup(optlist); | ||
| 755 | 797 | ||
| 756 | s = strtok(list, ","); | 798 | len = strlen(opt); |
| 757 | while (s) { | 799 | s = optlist - 1; |
| 758 | if (strcmp(s, opt) == 0) { | 800 | while (1) { |
| 759 | free(list); | 801 | s = strstr(s + 1, opt); |
| 760 | return 1; | 802 | if (!s) |
| 761 | } | 803 | return 0; |
| 762 | s = strtok(NULL, ","); | 804 | /* neither "opt.." nor "xxx,opt.."? */ |
| 805 | if (s != optlist && s[-1] != ',') | ||
| 806 | continue; | ||
| 807 | /* neither "..opt" nor "..opt,xxx"? */ | ||
| 808 | if (s[len] != '\0' && s[len] != ',') | ||
| 809 | continue; | ||
| 810 | return 1; | ||
| 763 | } | 811 | } |
| 764 | free(list); | ||
| 765 | return 0; | ||
| 766 | } | 812 | } |
| 767 | 813 | ||
| 768 | /* See if the filesystem matches the criteria given by the -t option */ | 814 | /* See if the filesystem matches the criteria given by the -t option */ |
| 769 | static int fs_match(struct fs_info *fs) | 815 | static int fs_match(struct fs_info *fs) |
| 770 | { | 816 | { |
| 771 | int n, ret = 0, checked_type = 0; | 817 | int n, ret, checked_type; |
| 772 | char *cp; | 818 | char *cp; |
| 773 | 819 | ||
| 774 | if (!fs_type_list) | 820 | if (!fs_type_list) |
| 775 | return 1; | 821 | return 1; |
| 776 | 822 | ||
| 777 | for (n = 0; (cp = fs_type_list[n]); n++) { | 823 | ret = 0; |
| 824 | checked_type = 0; | ||
| 825 | n = 0; | ||
| 826 | while (1) { | ||
| 827 | cp = fs_type_list[n]; | ||
| 828 | if (!cp) | ||
| 829 | break; | ||
| 778 | switch (fs_type_flag[n]) { | 830 | switch (fs_type_flag[n]) { |
| 779 | case FS_TYPE_FLAG_NORMAL: | 831 | case FS_TYPE_FLAG_NORMAL: |
| 780 | checked_type++; | 832 | checked_type++; |
| @@ -790,6 +842,7 @@ static int fs_match(struct fs_info *fs) | |||
| 790 | return 0; | 842 | return 0; |
| 791 | break; | 843 | break; |
| 792 | } | 844 | } |
| 845 | n++; | ||
| 793 | } | 846 | } |
| 794 | if (checked_type == 0) | 847 | if (checked_type == 0) |
| 795 | return 1; | 848 | return 1; |
| @@ -836,55 +889,14 @@ static int ignore(struct fs_info *fs) | |||
| 836 | return 0; | 889 | return 0; |
| 837 | } | 890 | } |
| 838 | 891 | ||
| 839 | /* | ||
| 840 | * Returns TRUE if a partition on the same disk is already being | ||
| 841 | * checked. | ||
| 842 | */ | ||
| 843 | static int device_already_active(char *device) | ||
| 844 | { | ||
| 845 | struct fsck_instance *inst; | ||
| 846 | char *base; | ||
| 847 | |||
| 848 | if (force_all_parallel) | ||
| 849 | return 0; | ||
| 850 | |||
| 851 | #ifdef BASE_MD | ||
| 852 | /* Don't check a soft raid disk with any other disk */ | ||
| 853 | if (instance_list | ||
| 854 | && (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1) | ||
| 855 | || !strncmp(device, BASE_MD, sizeof(BASE_MD)-1)) | ||
| 856 | ) { | ||
| 857 | return 1; | ||
| 858 | } | ||
| 859 | #endif | ||
| 860 | |||
| 861 | base = base_device(device); | ||
| 862 | /* | ||
| 863 | * If we don't know the base device, assume that the device is | ||
| 864 | * already active if there are any fsck instances running. | ||
| 865 | */ | ||
| 866 | if (!base) | ||
| 867 | return (instance_list != NULL); | ||
| 868 | |||
| 869 | for (inst = instance_list; inst; inst = inst->next) { | ||
| 870 | if (!inst->base_device || !strcmp(base, inst->base_device)) { | ||
| 871 | free(base); | ||
| 872 | return 1; | ||
| 873 | } | ||
| 874 | } | ||
| 875 | |||
| 876 | free(base); | ||
| 877 | return 0; | ||
| 878 | } | ||
| 879 | |||
| 880 | /* Check all file systems, using the /etc/fstab table. */ | 892 | /* Check all file systems, using the /etc/fstab table. */ |
| 881 | static int check_all(void) | 893 | static int check_all(void) |
| 882 | { | 894 | { |
| 883 | struct fs_info *fs = NULL; | 895 | struct fs_info *fs; |
| 884 | int status = EXIT_OK; | 896 | int status = EXIT_OK; |
| 885 | int not_done_yet = 1; | 897 | smallint not_done_yet; |
| 886 | int passno = 1; | 898 | smallint pass_done; |
| 887 | int pass_done; | 899 | int passno; |
| 888 | 900 | ||
| 889 | if (verbose) | 901 | if (verbose) |
| 890 | puts("Checking all filesystems"); | 902 | puts("Checking all filesystems"); |
| @@ -926,6 +938,8 @@ static int check_all(void) | |||
| 926 | if (LONE_CHAR(fs->mountpt, '/')) | 938 | if (LONE_CHAR(fs->mountpt, '/')) |
| 927 | fs->flags |= FLAG_DONE; | 939 | fs->flags |= FLAG_DONE; |
| 928 | 940 | ||
| 941 | not_done_yet = 1; | ||
| 942 | passno = 1; | ||
| 929 | while (not_done_yet) { | 943 | while (not_done_yet) { |
| 930 | not_done_yet = 0; | 944 | not_done_yet = 0; |
| 931 | pass_done = 1; | 945 | pass_done = 1; |
| @@ -941,7 +955,7 @@ static int check_all(void) | |||
| 941 | * do it yet. | 955 | * do it yet. |
| 942 | */ | 956 | */ |
| 943 | if (fs->passno > passno) { | 957 | if (fs->passno > passno) { |
| 944 | not_done_yet++; | 958 | not_done_yet = 1; |
| 945 | continue; | 959 | continue; |
| 946 | } | 960 | } |
| 947 | /* | 961 | /* |
| @@ -982,7 +996,7 @@ static int check_all(void) | |||
| 982 | puts("----------------------------------"); | 996 | puts("----------------------------------"); |
| 983 | passno++; | 997 | passno++; |
| 984 | } else | 998 | } else |
| 985 | not_done_yet++; | 999 | not_done_yet = 1; |
| 986 | } | 1000 | } |
| 987 | kill_all_if_cancel_requested(); | 1001 | kill_all_if_cancel_requested(); |
| 988 | status |= wait_many(FLAG_WAIT_ATLEAST_ONE); | 1002 | status |= wait_many(FLAG_WAIT_ATLEAST_ONE); |
| @@ -1015,9 +1029,7 @@ static void compile_fs_type(char *fs_type) | |||
| 1015 | if (!fs_type) | 1029 | if (!fs_type) |
| 1016 | return; | 1030 | return; |
| 1017 | 1031 | ||
| 1018 | // list = xstrdup(fs_type); | ||
| 1019 | num = 0; | 1032 | num = 0; |
| 1020 | // s = strtok(list, ","); | ||
| 1021 | s = fs_type; | 1033 | s = fs_type; |
| 1022 | while (1) { | 1034 | while (1) { |
| 1023 | char *comma; | 1035 | char *comma; |
| @@ -1030,6 +1042,7 @@ static void compile_fs_type(char *fs_type) | |||
| 1030 | s++; | 1042 | s++; |
| 1031 | negate = 1; | 1043 | negate = 1; |
| 1032 | } | 1044 | } |
| 1045 | |||
| 1033 | if (strcmp(s, "loop") == 0) | 1046 | if (strcmp(s, "loop") == 0) |
| 1034 | /* loop is really short-hand for opts=loop */ | 1047 | /* loop is really short-hand for opts=loop */ |
| 1035 | goto loop_special_case; | 1048 | goto loop_special_case; |
| @@ -1050,9 +1063,7 @@ static void compile_fs_type(char *fs_type) | |||
| 1050 | if (!comma) | 1063 | if (!comma) |
| 1051 | break; | 1064 | break; |
| 1052 | s = comma + 1; | 1065 | s = comma + 1; |
| 1053 | // s = strtok(NULL, ","); | ||
| 1054 | } | 1066 | } |
| 1055 | // free(list); | ||
| 1056 | } | 1067 | } |
| 1057 | 1068 | ||
| 1058 | static void parse_args(int argc, char *argv[]) | 1069 | static void parse_args(int argc, char *argv[]) |
