annotate toys/pending/fsck.c @ 1389:e59d4322331b draft

fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong. fsck: memory leak/segfault resolved. ftpget : warning for unused variable 'ptr' removed.
author Ashwini Sharma <ak.ashwini1981@gmail.com>
date Mon, 14 Jul 2014 05:44:29 -0500
parents a87b61ed18ff
children 00c20f410c46
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;
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
40 int *arr_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
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
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
126 TT.arr_flag = 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
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);
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
132 if (!strcmp(p, "loop")) TT.arr_flag[n] = no ? FLAG_WITH_NO_PRFX :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
133 else if (!strncmp(p, "opts=", 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
134 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
135 TT.arr_flag[n] = is_no_prefix(&p) ?FLAG_WITH_NO_PRFX :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
136 }
36a3a6f55154 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 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
138 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
139 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
140 " 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
141 }
36a3a6f55154 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 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
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 }
36a3a6f55154 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 //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
147 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
148 {
36a3a6f55154 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 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
150 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
151 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
152 "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
153 "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
154 };
36a3a6f55154 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 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
156 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
157 }
36a3a6f55154 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 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
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
36a3a6f55154 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 // 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
162 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
163 {
36a3a6f55154 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 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
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 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
167 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
168 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
169 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
170 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
171 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
172 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
173 } 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
174 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
175 } 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
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 }
36a3a6f55154 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 }
36a3a6f55154 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 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
181 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
182 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
183 }
36a3a6f55154 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
36a3a6f55154 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 // 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
186 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
187 {
36a3a6f55154 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 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
189 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
190 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
191 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
192 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
193
36a3a6f55154 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 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
195 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
196 && 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
197 && !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
198 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
199
36a3a6f55154 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 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
201 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
202
1183
0752b2d58909 Rename xmsprintf() to just xmprintf().
Rob Landley <rob@landley.net>
parents: 1119
diff changeset
203 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
204 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
205 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
206 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 }
36a3a6f55154 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 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
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 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
211 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
212 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
213 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
214 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
215 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
216 }
36a3a6f55154 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
1389
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
218 if (toys.optflags & FLAG_N) {
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
219 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
220 return;
e59d4322331b fdisk : partitions > 60, are deleted, offset entry for extended partitions was wrong.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents: 1297
diff changeset
221 } 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
222 if ((pid = fork()) < 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
223 perror_msg(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
224 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
225 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
226 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
227 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
228
36a3a6f55154 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 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
230 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
231 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
232 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
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 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
235 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
236 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
237 } 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
238 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
239 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
240 }
36a3a6f55154 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 }
36a3a6f55154 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
36a3a6f55154 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 // 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
244 // 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
245 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
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 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
248 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
249 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
250
36a3a6f55154 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 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 }
36a3a6f55154 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 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
264 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
265 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
266 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
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 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
269 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
270 }
36a3a6f55154 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 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
272 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
273 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
274 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
275 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
276 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
277 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
278 } 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
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 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
281 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
282 }
36a3a6f55154 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 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
284 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
285 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
286 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
287 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
288 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
289 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
290 }
36a3a6f55154 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 }
36a3a6f55154 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 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
293 }
36a3a6f55154 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
36a3a6f55154 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 //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
296 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
297 {
36a3a6f55154 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 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
299 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
300
36a3a6f55154 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 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
302 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
303 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
304 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
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 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
307
36a3a6f55154 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 (!(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
309 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
310 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
311 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
312 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
313 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
314 } 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
315 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
316 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
317 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
318 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
319 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
320 }
36a3a6f55154 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 }
36a3a6f55154 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 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
323 }
36a3a6f55154 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 }
36a3a6f55154 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 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
326 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
327 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
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 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
331 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
332 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
333 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
334 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
335
36a3a6f55154 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 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
337 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
338 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
339 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
340 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
341 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
342 && (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
343 }
36a3a6f55154 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 }
36a3a6f55154 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 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
346 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
347 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
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 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
350 }
36a3a6f55154 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
36a3a6f55154 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 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
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 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
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 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
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 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
360 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
361 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
362 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
363 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
364
36a3a6f55154 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 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
366 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
367 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
368 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
369 **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
370 }
36a3a6f55154 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 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 }
36a3a6f55154 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 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
374 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
375 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
376 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
377 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
378
36a3a6f55154 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 (!(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
380
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
381 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
382 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
383 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
384 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
385 if (CFG_TOYBOX_FREE) goto free_all;
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
386 }
36a3a6f55154 fsck wrapper from Ashwini Sharma. (Note: this just calls filesystem-specific programs not yet in toybox.)
Rob Landley <rob@landley.net>
parents:
diff changeset
387
36a3a6f55154 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 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
389 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
390 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
391 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
392 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
393 || !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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 }
36a3a6f55154 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 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
403 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
404 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
405 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
406 }
36a3a6f55154 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 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
408 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
409 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
410
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
411 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
412 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
413 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
414
a87b61ed18ff Make fsck.c use common list free function, collate cleanup code and move inline.
Rob Landley <rob@landley.net>
parents: 1265
diff changeset
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 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
426 }
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 }
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
428 }