coreutils/libcoreutils/ \
debianutils/ \
e2fsprogs/ \
- e2fsprogs/blkid/ \
- e2fsprogs/e2p/ \
- e2fsprogs/ext2fs/ \
- e2fsprogs/uuid/ \
editors/ \
findutils/ \
init/ \
*/
#include "busybox.h"
-/*#include "e2fs_lib.h"*/
#define EXIT_OK 0
#define EXIT_NONDESTRUCT 1
#define DEFAULT_FSTYPE "ext2"
#endif
-#define MAX_DEVICES 32
-#define MAX_ARGS 32
-
/*
* Internal structure for mount tabel entries.
*/
struct fsck_instance *next;
};
-static const char * const ignored_types[] = {
+static const char *const ignored_types[] = {
"ignore",
"iso9660",
"nfs",
NULL
};
-static const char * const really_wanted[] = {
+#if 0
+static const char *const really_wanted[] = {
"minix",
"ext2",
"ext3",
"xfs",
NULL
};
+#endif
#define BASE_MD "/dev/md"
-/*
- * Global variables for options
- */
+static volatile int cancel_requested;
+
static char **devices;
static char **args;
static int num_devices, num_args;
-
static int verbose;
static int doall;
static int noexecute;
static int force_all_parallel;
static int num_running;
static int max_running;
-static volatile int cancel_requested;
-static int kill_sent;
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 char *fsck_path;*/
-/*static blkid_cache cache;*/
#define FS_TYPE_FLAG_NORMAL 0
#define FS_TYPE_FLAG_OPT 1
fclose(f);
if (old_fstab) {
- fputs("\007\007\007"
- "WARNING: Your /etc/fstab does not contain the fsck passno\n"
- " field. I will kludge around things for you, but you\n"
- " should fix your /etc/fstab file as soon as you can.\n\n", stderr);
-
+ fputs("\007"
+"WARNING: Your /etc/fstab does not contain the fsck passno field.\n"
+"I will kludge around things for you, but you should fix\n"
+"your /etc/fstab file as soon as you can.\n\n", stderr);
for (fs = filesys_info; fs; fs = fs->next) {
fs->passno = 1;
}
{
struct fs_info *fs;
- /* No filesys name given. */
- if (filesys == NULL)
- return NULL;
-
for (fs = filesys_info; fs; fs = fs->next) {
if (strcmp(filesys, fs->device) == 0
|| (fs->mountpt && strcmp(filesys, fs->mountpt) == 0)
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)
{
struct fsck_instance *inst;
/*
* 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;
- int n = 0;
+
+ if (!cancel_requested || kill_sent)
+ return;
for (inst = instance_list; inst; inst = inst->next) {
if (inst->flags & FLAG_DONE)
continue;
- kill(inst->pid, signum);
- n++;
+ kill(inst->pid, SIGTERM);
}
- return n;
+ kill_sent = 1;
}
/*
do {
pid = waitpid(-1, &status, flags);
- if (cancel_requested && !kill_sent) {
- kill_all(SIGTERM);
- kill_sent++;
- }
- if ((pid == 0) && (flags & WNOHANG))
+ kill_all_if_cancel_requested();
+ if (pid == 0 && (flags & WNOHANG))
return NULL;
if (pid < 0) {
- if ((errno == EINTR) || (errno == EAGAIN))
+ if (errno == EINTR || errno == EAGAIN)
continue;
if (errno == ECHILD) {
bb_error_msg("wait: no more child process?!?");
break;
}
}
-ret_inst:
+ ret_inst:
if (prev)
prev->next = inst->next;
else
interpret_type(fs);
+ type = DEFAULT_FSTYPE;
if (strcmp(fs->type, "auto") != 0)
type = fs->type;
else if (fstype
- && strncmp(fstype, "no", 2)
- && strncmp(fstype, "opts=", 5) && strncmp(fstype, "loop", 4)
+ && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
+ && strncmp(fstype, "opts=", 5) != 0
+ && strncmp(fstype, "loop", 4) != 0
&& !strchr(fstype, ',')
)
type = fstype;
- else
- type = DEFAULT_FSTYPE;
num_running++;
retval = execute(type, fs->device, fs->mountpt, interactive);
} else
not_done_yet++;
}
- if (cancel_requested && !kill_sent) {
- kill_all(SIGTERM);
- kill_sent++;
- }
+ kill_all_if_cancel_requested();
status |= wait_many(FLAG_WAIT_ATLEAST_ONE);
return status;
}
static void signal_cancel(int sig ATTRIBUTE_UNUSED)
{
- cancel_requested++;
+ cancel_requested = 1;
}
static int string_to_int(const char *s)
for (i = 1; i < argc; i++) {
arg = argv[i];
if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
- if (num_devices >= MAX_DEVICES) {
- bb_error_msg_and_die("too many devices");
- }
#if 0
char *dev;
dev = blkid_get_devname(cache, arg, NULL);
* /proc/partitions isn't found.
*/
if (access("/proc/partitions", R_OK) < 0) {
- bb_perror_msg_and_die("cannot open /proc/partitions "
- "(is /proc mounted?)");
+ bb_perror_msg_and_die(
+"cannot open /proc/partitions (is /proc mounted?)");
}
/*
* Check to see if this is because
*/
if (geteuid())
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
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[num_devices++] = dev ? dev : xstrdup(arg);
fstab = "/etc/fstab";
load_fs_info(fstab);
- /*fsck_path = e2fs_set_sbin_path();*/
-
if (num_devices == 1 || serialize)
interactive = 1;
return check_all();
}
- for (i = 0 ; i < num_devices; i++) {
+ for (i = 0; i < num_devices; i++) {
if (cancel_requested) {
- if (!kill_sent) {
- kill_all(SIGTERM);
- kill_sent++;
- }
+ kill_all_if_cancel_requested();
break;
}
fs = lookup(devices[i]);
USE_DU(APPLET(du, _BB_DIR_USR_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_E2FSCK(APPLET(e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER))
-USE_E2LABEL(APPLET_NOUSAGE(e2label, tune2fs, _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_ECHO(APPLET(echo, _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_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_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_FREE(APPLET(free, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
USE_FREERAMDISK(APPLET(freeramdisk, _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.ext3, 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_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_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER,ftpput))
USE_MDEV(APPLET(mdev, _BB_DIR_SBIN, _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_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_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.ext2, 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_MKNOD(APPLET(mknod, _BB_DIR_BIN, _BB_SUID_NEVER))
USE_MKSWAP(APPLET(mkswap, _BB_DIR_SBIN, _BB_SUID_NEVER))
USE_TRACEROUTE(APPLET(traceroute, _BB_DIR_USR_BIN, _BB_SUID_MAYBE))
USE_TRUE(APPLET(true, _BB_DIR_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_UDHCPD(APPLET(udhcpd, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
USE_UMOUNT(APPLET(umount, _BB_DIR_BIN, _BB_SUID_NEVER))
extern void chomp(char *s);
extern void trim(char *s);
extern char *skip_whitespace(const char *);
+extern char *skip_non_whitespace(const char *);
extern const char *bb_mode_string(int mode);
extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
"$ freeramdisk /dev/ram2\n"
#define fsck_trivial_usage \
- "[-ANPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]"
+ "[-ANPRTV] [ -C fd ] [-t fstype] [fs-options] [filesys ...]"
#define fsck_full_usage \
"Check and repair filesystems" \
"\n\nOptions:\n" \
" -P When using -A, check filesystems in parallel\n" \
" -R When using -A, skip the root filesystem\n" \
" -T Don't show title on startup\n" \
- " -V Verbose mode\n" \
- " -C Write status information to specified filedescriptor\n" \
- " -t List of filesystem types to check"
+ " -V Verbose\n" \
+ " -C n Write status information to specified filedescriptor\n" \
+ " -t type List of filesystem types to check"
#define fsck_minix_trivial_usage \
"[-larvsmf] /dev/name"
/* byte count */
if (isdigit(*p)) {
- for (savep = p; isdigit(*p); ++p);
+// TODO: use bb_strtou
+ savep = p;
+ do p++; while(isdigit(*p));
if (!isspace(*p)) {
bb_error_msg_and_die("bad format {%s}", fmt);
}
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <ctype.h>
#include "libbb.h"
char *skip_whitespace(const char *s)
{
+ /* NB: isspace('0') returns 0 */
while (isspace(*s)) ++s;
return (char *) s;
}
+
+char *skip_non_whitespace(const char *s)
+{
+ while (*s && !isspace(*s)) ++s;
+
+ return (char *) s;
+}