annotate toys/pending/fsck.c @ 1539:3e85af1f7e22 draft

First batch of sed tests. Only good for TEST_HOST=1 at the moment because the test infrastructure itself depends on sed, so if an unfinished sed is in the $PATH it goes boing. But hey, corner cases! I have... more.
author Rob Landley <rob@landley.net>
date Wed, 29 Oct 2014 18:44:33 -0500
parents c0c91437138b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* fsck.c - check and repair a Linux filesystem
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright 2013 Sandeep Sharma <sandeep.jack2756@gmail.com>
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
4 * Copyright 2013 Kyungwan Han <asura321@gmail.com>
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
5
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
6 USE_FSCK(NEWTOY(fsck, "?t:ANPRTVsC#", TOYFLAG_USR|TOYFLAG_BIN))
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
7
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
8 config FSCK
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
9 bool "fsck"
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
10 default n
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
11 help
1265
0ecfaa7022e8 usage: is lower case (the help generator looks for that, might as well be consistent).
Rob Landley <rob@landley.net>
parents: 1183
diff changeset
12 usage: fsck [-ANPRTV] [-C FD] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]...
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
13
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
14 Check and repair filesystems
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
15
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
16 -A Walk /etc/fstab and check all filesystems
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
17 -N Don't execute, just show what would be done
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
18 -P With -A, check filesystems in parallel
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
19 -R With -A, skip the root filesystem
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
20 -T Don't show title on startup
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
21 -V Verbose
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
22 -C n Write status information to specified filedescriptor
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
23 -t TYPE List of filesystem types to check
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
24
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
25 */
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
26
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
27 #define FOR_fsck
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
28 #include "toys.h"
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
29 #include <mntent.h>
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
30
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
31 #define FLAG_WITHOUT_NO_PRFX 1
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
32 #define FLAG_WITH_NO_PRFX 2
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
33 #define FLAG_DONE 1
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
34
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
35 GLOBALS(
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
36 int fd_num;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
37 char *t_list;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
38
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
39 struct double_list *devices;
1481
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
40 char *arr_flag;
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
41 char **arr_type;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
42 int negate;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
43 int sum_status;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
44 int nr_run;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
45 int sig_num;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
46 long max_nr_run;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
47 )
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
48
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
49 struct f_sys_info {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
50 char *device, *mountpt, *type, *opts;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
51 int passno, flag;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
52 struct f_sys_info *next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
53 };
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
54
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
55 struct child_list {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
56 struct child_list *next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
57 pid_t pid;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
58 char *prog_name, *dev_name;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
59 };
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
60
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
61 static struct f_sys_info *filesys_info = NULL; //fstab entry list
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
62 static struct child_list *c_list = NULL; //fsck.type child list.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
63
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
64 static void kill_all(void)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
65 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
66 struct child_list *child;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
67
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
68 for (child = c_list; child; child = child->next)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
69 kill(child->pid, SIGTERM);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
70 _exit(0);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
71 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
72
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
73 static long strtol_range(char *str, int min, int max)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
74 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
75 char *endptr = NULL;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
76 errno = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
77 long ret_value = strtol(str, &endptr, 10);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
78
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
79 if(errno) perror_exit("Invalid num %s", str);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
80 else if(endptr && (*endptr != '\0' || endptr == str))
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
81 perror_exit("Not a valid num %s", str);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
82 if(ret_value >= min && ret_value <= max) return ret_value;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
83 else perror_exit("Number %s is not in valid [%d-%d] Range", str, min, max);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
84 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
85
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
86 //create fstab entries list.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
87 static struct f_sys_info* create_db(struct mntent *f_info)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
88 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
89 struct f_sys_info *temp = filesys_info;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
90 if (temp) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
91 while (temp->next) temp = temp->next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
92 temp->next = xzalloc(sizeof(struct f_sys_info));
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
93 temp = temp->next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
94 } else filesys_info = temp = xzalloc(sizeof(struct f_sys_info));
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
95
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
96 temp->device = xstrdup(f_info->mnt_fsname);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
97 temp->mountpt = xstrdup(f_info->mnt_dir);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
98 if (strchr(f_info->mnt_type, ',')) temp->type = xstrdup("auto");
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
99 else temp->type = xstrdup(f_info->mnt_type);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
100 temp->opts = xstrdup(f_info->mnt_opts);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
101 temp->passno = f_info->mnt_passno;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
102 return temp;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
103 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
104
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
105 //is we have 'no' or ! before type.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
106 static int is_no_prefix(char **p)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
107 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
108 int no = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
109
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
110 if ((*p[0] == 'n' && *(*p + 1) == 'o')) no = 2;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
111 else if (*p[0] == '!') no = 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
112 *p += no;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
113 return ((no) ? 1 :0);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
114 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
115
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
116 static void fix_tlist(void)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
117 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
118 char *p, *s = TT.t_list;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
119 int n = 1, no;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
120
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
121 while ((s = strchr(s, ','))) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
122 s++;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
123 n++;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
124 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
125
1481
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
126 TT.arr_flag = xzalloc(n + 1);
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
127 TT.arr_type = xzalloc((n + 1) * sizeof(char *));
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
128 s = TT.t_list;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
129 n = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
130 while ((p = strsep(&s, ","))) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
131 no = is_no_prefix(&p);
1481
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
132 if (!strcmp(p, "loop")) {
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
133 TT.arr_flag[n] = no ? FLAG_WITH_NO_PRFX :FLAG_WITHOUT_NO_PRFX;
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
134 TT.negate = no;
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
135 } else if (!strncmp(p, "opts=", 5)) {
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
136 p+=5;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
137 TT.arr_flag[n] = is_no_prefix(&p) ?FLAG_WITH_NO_PRFX :FLAG_WITHOUT_NO_PRFX;
1481
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
138 TT.negate = no;
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
139 } else {
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
140 if (!n) TT.negate = no;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
141 if (n && TT.negate != no) error_exit("either all or none of the filesystem"
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
142 " types passed to -t must be prefixed with 'no' or '!'");
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
143 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
144 TT.arr_type[n++] = p;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
145 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
146 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
147
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
148 //ignore these types...
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
149 static int ignore_type(char *type)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
150 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
151 int i = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
152 char *str;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
153 char *ignored_types[] = {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
154 "ignore","iso9660", "nfs","proc",
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
155 "sw","swap", "tmpfs","devpts",NULL
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
156 };
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
157 while ((str = ignored_types[i++])) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
158 if (!strcmp(str, type)) return 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
159 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
160 return 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
161 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
162
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
163 // return true if has to ignore the filesystem.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
164 static int to_be_ignored(struct f_sys_info *finfo)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
165 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
166 int i, ret = 0, type_present = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
167
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
168 if (!finfo->passno) return 1; //Ignore with pass num = 0
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
169 if (TT.arr_type) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
170 for (i = 0; TT.arr_type[i]; i++) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
171 if (!TT.arr_flag[i]) { //it is type of filesys.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
172 type_present = 2;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
173 if (!strcmp(TT.arr_type[i], finfo->type)) ret = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
174 else ret = 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
175 } else if (TT.arr_flag[i] == FLAG_WITH_NO_PRFX) { //it is option of filesys
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
176 if (hasmntopt((const struct mntent *)finfo, TT.arr_type[i])) return 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
177 } else { //FLAG_WITHOUT_NO_PRFX
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
178 if (!hasmntopt((const struct mntent *)finfo, TT.arr_type[i])) return 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
179 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
180 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
181 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
182 if (ignore_type(finfo->type)) return 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
183 if (TT.arr_type && type_present != 2) return 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
184 return ((TT.negate) ? !ret : ret);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
185 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
186
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
187 // find type and execute corresponding fsck.type prog.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
188 static void do_fsck(struct f_sys_info *finfo)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
189 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
190 struct child_list *child;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
191 char **args;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
192 char *type;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
193 pid_t pid;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
194 int i = 1, j = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
195
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
196 if (strcmp(finfo->type, "auto")) type = finfo->type;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
197 else if (TT.t_list && (TT.t_list[0] != 'n' || TT.t_list[1] != 'o' || TT.t_list[0] != '!')
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
198 && strncmp(TT.t_list, "opts=", 5) && strncmp(TT.t_list , "loop", 4)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
199 && !TT.arr_type[1]) type = TT.t_list; //one file sys at cmdline
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
200 else type = "auto";
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
201
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
202 args = xzalloc((toys.optc + 2 + 1 + 1) * sizeof(char*)); //+1, for NULL, +1 if -C
1183
0752b2d58909 Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents: 1119
diff changeset
203 args[0] = xmprintf("fsck.%s", type);
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
204
1183
0752b2d58909 Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents: 1119
diff changeset
205 if(toys.optflags & FLAG_C) args[i++] = xmprintf("%s %d","-C", TT.fd_num);
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
206 while(toys.optargs[j]) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
207 if(*toys.optargs[j]) args[i++] = xstrdup(toys.optargs[j]);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
208 j++;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
209 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
210 args[i] = finfo->device;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
211
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
212 TT.nr_run++;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
213 if ((toys.optflags & FLAG_V) || (toys.optflags & FLAG_N)) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
214 printf("[%s (%d) -- %s]", args[0], TT.nr_run,
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
215 finfo->mountpt ? finfo->mountpt : finfo->device);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
216 for (i = 0; args[i]; i++) xprintf(" %s", args[i]);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
217 xputc('\n');
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
218 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
219
1389
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
220 if (toys.optflags & FLAG_N) {
1433
00c20f410c46 Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1389
diff changeset
221 for (j=0;j<i;j++) free(args[i]);
1389
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
222 free(args);
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
223 return;
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
224 } else {
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
225 if ((pid = fork()) < 0) {
1481
c0c91437138b A few fixes for issues reported in static analysis.
Ashwini Sharma <ak.ashwini1981.gmail.com>
parents: 1433
diff changeset
226 perror_msg(args[0]);
1433
00c20f410c46 Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1389
diff changeset
227 for (j=0;j<i;j++) free(args[i]);
00c20f410c46 Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1389
diff changeset
228 free(args);
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
229 return;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
230 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
231 if (!pid) xexec(args); //child, executes fsck.type
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
232 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
233
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
234 child = xzalloc(sizeof(struct child_list)); //Parent, add to child list.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
235 child->dev_name = xstrdup(finfo->device);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
236 child->prog_name = args[0];
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
237 child->pid = pid;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
238
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
239 if (c_list) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
240 child->next = c_list;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
241 c_list = child;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
242 } else {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
243 c_list = child;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
244 child->next =NULL;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
245 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
246 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
247
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
248 // for_all = 1; wait for all child to exit
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
249 // for_all = 0; wait for any one to exit
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
250 static int wait_for(int for_all)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
251 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
252 pid_t pid;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
253 int status = 0, child_exited;
1389
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
254 struct child_list *prev, *temp;
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
255
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
256 errno = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
257 if (!c_list) return 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
258 while ((pid = wait(&status))) {
1389
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
259 temp = c_list;
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
260 prev = temp;
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
261 if (TT.sig_num) kill_all();
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
262 child_exited = 0;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
263 if (pid < 0) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
264 if (errno == EINTR) continue;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
265 else if (errno == ECHILD) break; //No child to wait, break and return status.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
266 else perror_exit("option arg Invalid\n"); //paranoid.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
267 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
268 while (temp) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
269 if (temp->pid == pid) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
270 child_exited = 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
271 break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
272 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
273 prev = temp;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
274 temp = temp->next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
275 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
276 if (child_exited) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
277 if (WIFEXITED(status)) TT.sum_status |= WEXITSTATUS(status);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
278 else if (WIFSIGNALED(status)) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
279 TT.sum_status |= 4; //Uncorrected.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
280 if (WTERMSIG(status) != SIGINT)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
281 perror_msg("child Term. by sig: %d\n",(WTERMSIG(status)));
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
282 TT.sum_status |= 8; //Operatinal error
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
283 } else {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
284 TT.sum_status |= 4; //Uncorrected.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
285 perror_msg("%s %s: status is %x, should never happen\n",
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
286 temp->prog_name, temp->dev_name, status);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
287 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
288 TT.nr_run--;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
289 if (prev == temp) c_list = c_list->next; //first node
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
290 else prev->next = temp->next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
291 free(temp->prog_name);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
292 free(temp->dev_name);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
293 free(temp);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
294 if (!for_all) break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
295 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
296 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
297 return TT.sum_status;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
298 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
299
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
300 //scan all the fstab entries or -t matches with fstab.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
301 static int scan_all(void)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
302 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
303 struct f_sys_info *finfo = filesys_info;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
304 int ret = 0, passno;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
305
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
306 if (toys.optflags & FLAG_V) xprintf("Checking all filesystem\n");
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
307 while (finfo) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
308 if (to_be_ignored(finfo)) finfo->flag |= FLAG_DONE;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
309 finfo = finfo->next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
310 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
311 finfo = filesys_info;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
312
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
313 if (!(toys.optflags & FLAG_P)) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
314 while (finfo) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
315 if (!strcmp(finfo->mountpt, "/")) { // man says: check / in parallel with others if -P is absent.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
316 if ((toys.optflags & FLAG_R) || to_be_ignored(finfo)) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
317 finfo->flag |= FLAG_DONE;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
318 break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
319 } else {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
320 do_fsck(finfo);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
321 finfo->flag |= FLAG_DONE;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
322 if (TT.sig_num) kill_all();
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
323 if ((ret |= wait_for(1)) > 4) return ret; //destruction in filesys.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
324 break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
325 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
326 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
327 finfo = finfo->next;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
328 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
329 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
330 if (toys.optflags & FLAG_R) { // with -PR we choose to skip root.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
331 for (finfo = filesys_info; finfo; finfo = finfo->next) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
332 if(!strcmp(finfo->mountpt, "/")) finfo->flag |= FLAG_DONE;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
333 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
334 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
335 passno = 1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
336 while (1) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
337 for (finfo = filesys_info; finfo; finfo = finfo->next)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
338 if (!finfo->flag) break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
339 if (!finfo) break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
340
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
341 for (finfo = filesys_info; finfo; finfo = finfo->next) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
342 if (finfo->flag) continue;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
343 if (finfo->passno == passno) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
344 do_fsck(finfo);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
345 finfo->flag |= FLAG_DONE;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
346 if ((toys.optflags & FLAG_s) || (TT.nr_run
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
347 && (TT.nr_run >= TT.max_nr_run))) ret |= wait_for(0);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
348 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
349 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
350 if (TT.sig_num) kill_all();
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
351 ret |= wait_for(1);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
352 passno++;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
353 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
354 return ret;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
355 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
356
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
357 void record_sig_num(int sig)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
358 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
359 TT.sig_num = sig;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
360 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
361
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
362 void fsck_main(void)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
363 {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
364 struct mntent mt;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
365 struct double_list *dev;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
366 struct f_sys_info *finfo;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
367 FILE *fp;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
368 char *tmp, **arg = toys.optargs;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
369
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
370 sigatexit(record_sig_num);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
371 while (*arg) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
372 if ((**arg == '/') || strchr(*arg, '=')) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
373 dlist_add(&TT.devices, xstrdup(*arg));
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
374 **arg = '\0';
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
375 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
376 arg++;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
377 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
378 if (toys.optflags & FLAG_t) fix_tlist();
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
379 if (!(tmp = getenv("FSTAB_FILE"))) tmp = "/etc/fstab";
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
380 if (!(fp = setmntent(tmp, "r"))) perror_exit("setmntent failed:");
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
381 while (getmntent_r(fp, &mt, toybuf, 4096)) create_db(&mt);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
382 endmntent(fp);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
383
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
384 if (!(toys.optflags & FLAG_T)) xprintf("fsck ----- (Toybox)\n");
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
385
1297
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
386 if ((tmp = getenv("FSCK_MAX_INST")))
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
387 TT.max_nr_run = strtol_range(tmp, 0, INT_MAX);
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
388 if (!TT.devices || (toys.optflags & FLAG_A)) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
389 toys.exitval = scan_all();
1297
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
390 if (CFG_TOYBOX_FREE) goto free_all;
1433
00c20f410c46 Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1389
diff changeset
391 return; //if CFG_TOYBOX_FREE is not set, exit.
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
392 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
393
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
394 dev = TT.devices;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
395 dev->prev->next = NULL; //break double list to traverse.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
396 for (; dev; dev = dev->next) {
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
397 for (finfo = filesys_info; finfo; finfo = finfo->next)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
398 if (!strcmp(finfo->device, dev->data)
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
399 || !strcmp(finfo->mountpt, dev->data)) break;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
400 if (!finfo) { //if not present, fill def values.
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
401 mt.mnt_fsname = dev->data;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
402 mt.mnt_dir = "";
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
403 mt.mnt_type = "auto";
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
404 mt.mnt_opts = "";
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
405 mt.mnt_passno = -1;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
406 finfo = create_db(&mt);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
407 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
408 do_fsck(finfo);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
409 finfo->flag |= FLAG_DONE;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
410 if ((toys.optflags & FLAG_s) || (TT.nr_run && (TT.nr_run >= TT.max_nr_run)))
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
411 toys.exitval |= wait_for(0);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
412 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
413 if (TT.sig_num) kill_all();
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
414 toys.exitval |= wait_for(1);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
415 finfo = filesys_info;
1297
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
416
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
417 free_all:
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
418 if (CFG_TOYBOX_FREE) {
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
419 struct f_sys_info *finfo, *temp;
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
420
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
421 llist_traverse(TT.devices, llist_free_double);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
422 free(TT.arr_type);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
423 free(TT.arr_flag);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
424 for (finfo = filesys_info; finfo;) {
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
425 temp = finfo->next;
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
426 free(finfo->device);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
427 free(finfo->mountpt);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
428 free(finfo->type);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
429 free(finfo->opts);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
430 free(finfo);
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
431 finfo = temp;
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
432 }
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
433 }
1119
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
434 }