leftover of e2fsck surgery

This commit is contained in:
Denis Vlasenko 2006-12-26 02:51:29 +00:00
parent c4f623ef2a
commit 0de9375ee6
7 changed files with 61 additions and 101 deletions

View File

@ -429,10 +429,6 @@ libs-y := \
coreutils/libcoreutils/ \ coreutils/libcoreutils/ \
debianutils/ \ debianutils/ \
e2fsprogs/ \ e2fsprogs/ \
e2fsprogs/blkid/ \
e2fsprogs/e2p/ \
e2fsprogs/ext2fs/ \
e2fsprogs/uuid/ \
editors/ \ editors/ \
findutils/ \ findutils/ \
init/ \ init/ \

View File

@ -27,7 +27,6 @@
*/ */
#include "busybox.h" #include "busybox.h"
/*#include "e2fs_lib.h"*/
#define EXIT_OK 0 #define EXIT_OK 0
#define EXIT_NONDESTRUCT 1 #define EXIT_NONDESTRUCT 1
@ -41,9 +40,6 @@
#define DEFAULT_FSTYPE "ext2" #define DEFAULT_FSTYPE "ext2"
#endif #endif
#define MAX_DEVICES 32
#define MAX_ARGS 32
/* /*
* Internal structure for mount tabel entries. * Internal structure for mount tabel entries.
*/ */
@ -76,7 +72,7 @@ struct fsck_instance {
struct fsck_instance *next; struct fsck_instance *next;
}; };
static const char * const ignored_types[] = { static const char *const ignored_types[] = {
"ignore", "ignore",
"iso9660", "iso9660",
"nfs", "nfs",
@ -88,7 +84,8 @@ static const char * const ignored_types[] = {
NULL NULL
}; };
static const char * const really_wanted[] = { #if 0
static const char *const really_wanted[] = {
"minix", "minix",
"ext2", "ext2",
"ext3", "ext3",
@ -98,16 +95,15 @@ static const char * const really_wanted[] = {
"xfs", "xfs",
NULL NULL
}; };
#endif
#define BASE_MD "/dev/md" #define BASE_MD "/dev/md"
/* static volatile int cancel_requested;
* Global variables for options
*/
static char **devices; static char **devices;
static char **args; static char **args;
static int num_devices, num_args; static int num_devices, num_args;
static int verbose; static int verbose;
static int doall; static int doall;
static int noexecute; static int noexecute;
@ -121,13 +117,10 @@ static int progress_fd;
static int force_all_parallel; static int force_all_parallel;
static int num_running; static int num_running;
static int max_running; static int max_running;
static volatile int cancel_requested;
static int kill_sent;
static char *fstype; static char *fstype;
static struct fs_info *filesys_info, *filesys_last; static struct fs_info *filesys_info;
static struct fs_info *filesys_last;
static struct fsck_instance *instance_list; static struct fsck_instance *instance_list;
/*static char *fsck_path;*/
/*static blkid_cache cache;*/
#define FS_TYPE_FLAG_NORMAL 0 #define FS_TYPE_FLAG_NORMAL 0
#define FS_TYPE_FLAG_OPT 1 #define FS_TYPE_FLAG_OPT 1
@ -439,11 +432,10 @@ static void load_fs_info(const char *filename)
fclose(f); fclose(f);
if (old_fstab) { if (old_fstab) {
fputs("\007\007\007" fputs("\007"
"WARNING: Your /etc/fstab does not contain the fsck passno\n" "WARNING: Your /etc/fstab does not contain the fsck passno field.\n"
" field. I will kludge around things for you, but you\n" "I will kludge around things for you, but you should fix\n"
" should fix your /etc/fstab file as soon as you can.\n\n", stderr); "your /etc/fstab file as soon as you can.\n\n", stderr);
for (fs = filesys_info; fs; fs = fs->next) { for (fs = filesys_info; fs; fs = fs->next) {
fs->passno = 1; fs->passno = 1;
} }
@ -455,10 +447,6 @@ static struct fs_info *lookup(char *filesys)
{ {
struct fs_info *fs; struct fs_info *fs;
/* No filesys name given. */
if (filesys == NULL)
return NULL;
for (fs = filesys_info; fs; fs = fs->next) { for (fs = filesys_info; fs; fs = fs->next) {
if (strcmp(filesys, fs->device) == 0 if (strcmp(filesys, fs->device) == 0
|| (fs->mountpt && strcmp(filesys, fs->mountpt) == 0) || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0)
@ -469,29 +457,6 @@ static struct fs_info *lookup(char *filesys)
return fs; return fs;
} }
#if 0
/* Find fsck program for a given fs type. */
static char *find_fsck(char *type)
{
char *s;
const char *tpl;
char *p = xstrdup(fsck_path);
struct stat st;
/* Are we looking for a program or just a type? */
tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
for (s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
s = xasprintf(tpl, s, type);
if (stat(s, &st) == 0)
break;
free(s);
}
free(p);
return s;
}
#endif
static int progress_active(void) static int progress_active(void)
{ {
struct fsck_instance *inst; struct fsck_instance *inst;
@ -588,18 +553,21 @@ static int execute(const char *type, const char *device, const char *mntpt,
/* /*
* Send a signal to all outstanding fsck child processes * Send a signal to all outstanding fsck child processes
*/ */
static int kill_all(int signum) static void kill_all_if_cancel_requested(void)
{ {
static int kill_sent;
struct fsck_instance *inst; struct fsck_instance *inst;
int n = 0;
if (!cancel_requested || kill_sent)
return;
for (inst = instance_list; inst; inst = inst->next) { for (inst = instance_list; inst; inst = inst->next) {
if (inst->flags & FLAG_DONE) if (inst->flags & FLAG_DONE)
continue; continue;
kill(inst->pid, signum); kill(inst->pid, SIGTERM);
n++;
} }
return n; kill_sent = 1;
} }
/* /*
@ -637,14 +605,11 @@ static struct fsck_instance *wait_one(int flags)
do { do {
pid = waitpid(-1, &status, flags); pid = waitpid(-1, &status, flags);
if (cancel_requested && !kill_sent) { kill_all_if_cancel_requested();
kill_all(SIGTERM); if (pid == 0 && (flags & WNOHANG))
kill_sent++;
}
if ((pid == 0) && (flags & WNOHANG))
return NULL; return NULL;
if (pid < 0) { if (pid < 0) {
if ((errno == EINTR) || (errno == EAGAIN)) if (errno == EINTR || errno == EAGAIN)
continue; continue;
if (errno == ECHILD) { if (errno == ECHILD) {
bb_error_msg("wait: no more child process?!?"); bb_error_msg("wait: no more child process?!?");
@ -704,7 +669,7 @@ static struct fsck_instance *wait_one(int flags)
break; break;
} }
} }
ret_inst: ret_inst:
if (prev) if (prev)
prev->next = inst->next; prev->next = inst->next;
else else
@ -758,16 +723,16 @@ static void fsck_device(struct fs_info *fs, int interactive)
interpret_type(fs); interpret_type(fs);
type = DEFAULT_FSTYPE;
if (strcmp(fs->type, "auto") != 0) if (strcmp(fs->type, "auto") != 0)
type = fs->type; type = fs->type;
else if (fstype else if (fstype
&& strncmp(fstype, "no", 2) && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
&& strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4) && strncmp(fstype, "opts=", 5) != 0
&& strncmp(fstype, "loop", 4) != 0
&& !strchr(fstype, ',') && !strchr(fstype, ',')
) )
type = fstype; type = fstype;
else
type = DEFAULT_FSTYPE;
num_running++; num_running++;
retval = execute(type, fs->device, fs->mountpt, interactive); retval = execute(type, fs->device, fs->mountpt, interactive);
@ -1078,17 +1043,14 @@ static int check_all(void)
} else } else
not_done_yet++; not_done_yet++;
} }
if (cancel_requested && !kill_sent) { kill_all_if_cancel_requested();
kill_all(SIGTERM);
kill_sent++;
}
status |= wait_many(FLAG_WAIT_ATLEAST_ONE); status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
return status; return status;
} }
static void signal_cancel(int sig ATTRIBUTE_UNUSED) static void signal_cancel(int sig ATTRIBUTE_UNUSED)
{ {
cancel_requested++; cancel_requested = 1;
} }
static int string_to_int(const char *s) static int string_to_int(const char *s)
@ -1126,9 +1088,6 @@ static void parse_args(int argc, char *argv[])
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
arg = argv[i]; arg = argv[i];
if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) { if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
if (num_devices >= MAX_DEVICES) {
bb_error_msg_and_die("too many devices");
}
#if 0 #if 0
char *dev; char *dev;
dev = blkid_get_devname(cache, arg, NULL); dev = blkid_get_devname(cache, arg, NULL);
@ -1138,8 +1097,8 @@ static void parse_args(int argc, char *argv[])
* /proc/partitions isn't found. * /proc/partitions isn't found.
*/ */
if (access("/proc/partitions", R_OK) < 0) { if (access("/proc/partitions", R_OK) < 0) {
bb_perror_msg_and_die("cannot open /proc/partitions " bb_perror_msg_and_die(
"(is /proc mounted?)"); "cannot open /proc/partitions (is /proc mounted?)");
} }
/* /*
* Check to see if this is because * Check to see if this is because
@ -1147,10 +1106,10 @@ static void parse_args(int argc, char *argv[])
*/ */
if (geteuid()) if (geteuid())
bb_error_msg_and_die( bb_error_msg_and_die(
"must be root to scan for matching filesystems: %s\n", arg); "must be root to scan for matching filesystems: %s\n", arg);
else else
bb_error_msg_and_die( bb_error_msg_and_die(
"cannot find matching filesystem: %s", arg); "cannot find matching filesystem: %s", arg);
} }
devices = xrealloc(devices, (num_devices+1) * sizeof(devices[0])); devices = xrealloc(devices, (num_devices+1) * sizeof(devices[0]));
devices[num_devices++] = dev ? dev : xstrdup(arg); devices[num_devices++] = dev ? dev : xstrdup(arg);
@ -1271,8 +1230,6 @@ int fsck_main(int argc, char *argv[])
fstab = "/etc/fstab"; fstab = "/etc/fstab";
load_fs_info(fstab); load_fs_info(fstab);
/*fsck_path = e2fs_set_sbin_path();*/
if (num_devices == 1 || serialize) if (num_devices == 1 || serialize)
interactive = 1; interactive = 1;
@ -1286,12 +1243,9 @@ int fsck_main(int argc, char *argv[])
return check_all(); return check_all();
} }
for (i = 0 ; i < num_devices; i++) { for (i = 0; i < num_devices; i++) {
if (cancel_requested) { if (cancel_requested) {
if (!kill_sent) { kill_all_if_cancel_requested();
kill_all(SIGTERM);
kill_sent++;
}
break; break;
} }
fs = lookup(devices[i]); fs = lookup(devices[i]);

View File

@ -102,8 +102,8 @@ USE_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, _BB_DIR_USR_BIN, _BB_SUID_NEVER,
USE_DU(APPLET(du, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_DU(APPLET(du, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_DUMPKMAP(APPLET(dumpkmap, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_DUMPKMAP(APPLET(dumpkmap, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_APP_DUMPLEASES(APPLET(dumpleases, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_APP_DUMPLEASES(APPLET(dumpleases, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_E2FSCK(APPLET(e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_E2FSCK(APPLET(e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_E2LABEL(APPLET_NOUSAGE(e2label, tune2fs, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_E2LABEL(APPLET_NOUSAGE(e2label, tune2fs, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_ECHO(APPLET(echo, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_ECHO(APPLET(echo, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_ED(APPLET(ed, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_ED(APPLET(ed, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_FEATURE_GREP_EGREP_ALIAS(APPLET_NOUSAGE(egrep, grep, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_FEATURE_GREP_EGREP_ALIAS(APPLET_NOUSAGE(egrep, grep, _BB_DIR_BIN, _BB_SUID_NEVER))
@ -121,13 +121,13 @@ USE_FDFORMAT(APPLET(fdformat, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_FDISK(APPLET(fdisk, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_FDISK(APPLET(fdisk, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_FEATURE_GREP_FGREP_ALIAS(APPLET_NOUSAGE(fgrep, grep, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_FEATURE_GREP_FGREP_ALIAS(APPLET_NOUSAGE(fgrep, grep, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_FIND(APPLET(find, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_FIND(APPLET(find, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_FINDFS(APPLET_NOUSAGE(findfs, tune2fs, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_FINDFS(APPLET_NOUSAGE(findfs, tune2fs, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_FOLD(APPLET(fold, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_FOLD(APPLET(fold, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_FREE(APPLET(free, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_FREE(APPLET(free, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_FREERAMDISK(APPLET(freeramdisk, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_FREERAMDISK(APPLET(freeramdisk, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_FSCK(APPLET(fsck, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_FSCK(APPLET(fsck, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_E2FSCK(APPLET_NOUSAGE(fsck.ext2, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_E2FSCK(APPLET_NOUSAGE(fsck.ext2, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_E2FSCK(APPLET_NOUSAGE(fsck.ext3, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_E2FSCK(APPLET_NOUSAGE(fsck.ext3, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_minix)) USE_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_minix))
USE_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpget)) USE_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpget))
USE_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpput)) USE_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpput))
@ -191,10 +191,10 @@ USE_MD5SUM(APPLET_ODDNAME(md5sum, md5_sha1_sum, _BB_DIR_USR_BIN, _BB_SUID_NEVER,
USE_MDEV(APPLET(mdev, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_MDEV(APPLET(mdev, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_MESG(APPLET(mesg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_MKDIR(APPLET(mkdir, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_MKDIR(APPLET(mkdir, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_MKE2FS(APPLET(mke2fs, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_MKE2FS(APPLET(mke2fs, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_MKFIFO(APPLET(mkfifo, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_MKFIFO(APPLET(mkfifo, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_MKE2FS(APPLET_NOUSAGE(mkfs.ext2, mke2fs, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_MKE2FS(APPLET_NOUSAGE(mkfs.ext2, mke2fs, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_MKE2FS(APPLET_NOUSAGE(mkfs.ext3, mke2fs, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_MKE2FS(APPLET_NOUSAGE(mkfs.ext3, mke2fs, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_MKFS_MINIX(APPLET_ODDNAME(mkfs.minix, mkfs_minix, _BB_DIR_SBIN, _BB_SUID_NEVER, mkfs_minix)) USE_MKFS_MINIX(APPLET_ODDNAME(mkfs.minix, mkfs_minix, _BB_DIR_SBIN, _BB_SUID_NEVER, mkfs_minix))
USE_MKNOD(APPLET(mknod, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_MKNOD(APPLET(mknod, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_MKSWAP(APPLET(mkswap, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_MKSWAP(APPLET(mkswap, _BB_DIR_SBIN, _BB_SUID_NEVER))
@ -294,7 +294,7 @@ USE_TR(APPLET(tr, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_TRACEROUTE(APPLET(traceroute, _BB_DIR_USR_BIN, _BB_SUID_MAYBE)) USE_TRACEROUTE(APPLET(traceroute, _BB_DIR_USR_BIN, _BB_SUID_MAYBE))
USE_TRUE(APPLET(true, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_TRUE(APPLET(true, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_TTY(APPLET(tty, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_TTY(APPLET(tty, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_TUNE2FS(APPLET(tune2fs, _BB_DIR_SBIN, _BB_SUID_NEVER)) //USE_TUNE2FS(APPLET(tune2fs, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_APP_UDHCPC(APPLET(udhcpc, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_APP_UDHCPC(APPLET(udhcpc, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_APP_UDHCPD(APPLET(udhcpd, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) USE_APP_UDHCPD(APPLET(udhcpd, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
USE_UMOUNT(APPLET(umount, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_UMOUNT(APPLET(umount, _BB_DIR_BIN, _BB_SUID_NEVER))

View File

@ -190,6 +190,7 @@ extern int sysinfo(struct sysinfo* info);
extern void chomp(char *s); extern void chomp(char *s);
extern void trim(char *s); extern void trim(char *s);
extern char *skip_whitespace(const char *); extern char *skip_whitespace(const char *);
extern char *skip_non_whitespace(const char *);
extern const char *bb_mode_string(int mode); extern const char *bb_mode_string(int mode);
extern int is_directory(const char *name, int followLinks, struct stat *statBuf); extern int is_directory(const char *name, int followLinks, struct stat *statBuf);

View File

@ -932,7 +932,7 @@
"$ freeramdisk /dev/ram2\n" "$ freeramdisk /dev/ram2\n"
#define fsck_trivial_usage \ #define fsck_trivial_usage \
"[-ANPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]" "[-ANPRTV] [ -C fd ] [-t fstype] [fs-options] [filesys ...]"
#define fsck_full_usage \ #define fsck_full_usage \
"Check and repair filesystems" \ "Check and repair filesystems" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
@ -941,9 +941,9 @@
" -P When using -A, check filesystems in parallel\n" \ " -P When using -A, check filesystems in parallel\n" \
" -R When using -A, skip the root filesystem\n" \ " -R When using -A, skip the root filesystem\n" \
" -T Don't show title on startup\n" \ " -T Don't show title on startup\n" \
" -V Verbose mode\n" \ " -V Verbose\n" \
" -C Write status information to specified filedescriptor\n" \ " -C n Write status information to specified filedescriptor\n" \
" -t List of filesystem types to check" " -t type List of filesystem types to check"
#define fsck_minix_trivial_usage \ #define fsck_minix_trivial_usage \
"[-larvsmf] /dev/name" "[-larvsmf] /dev/name"

View File

@ -724,7 +724,9 @@ void bb_dump_add(const char *fmt)
/* byte count */ /* byte count */
if (isdigit(*p)) { if (isdigit(*p)) {
for (savep = p; isdigit(*p); ++p); // TODO: use bb_strtou
savep = p;
do p++; while(isdigit(*p));
if (!isspace(*p)) { if (!isspace(*p)) {
bb_error_msg_and_die("bad format {%s}", fmt); bb_error_msg_and_die("bad format {%s}", fmt);
} }

View File

@ -7,12 +7,19 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/ */
#include <ctype.h>
#include "libbb.h" #include "libbb.h"
char *skip_whitespace(const char *s) char *skip_whitespace(const char *s)
{ {
/* NB: isspace('0') returns 0 */
while (isspace(*s)) ++s; while (isspace(*s)) ++s;
return (char *) s; return (char *) s;
} }
char *skip_non_whitespace(const char *s)
{
while (*s && !isspace(*s)) ++s;
return (char *) s;
}