Fixed the init problem where it wouldn't unmount filesystems
on reboot. Also fixed swapoff -a so it works. -Erik
This commit is contained in:
@@ -53,7 +53,7 @@
|
||||
#include <linux/loop.h>
|
||||
|
||||
|
||||
static int use_loop = 0;
|
||||
static int use_loop = FALSE;
|
||||
#endif
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
@@ -114,13 +114,14 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
|
||||
char *mtab_opts)
|
||||
{
|
||||
int status = 0;
|
||||
char *lofile = NULL;
|
||||
|
||||
#if defined BB_MTAB
|
||||
if (fakeIt == FALSE)
|
||||
#endif
|
||||
{
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
if (use_loop) {
|
||||
if (use_loop==TRUE) {
|
||||
int loro = flags & MS_RDONLY;
|
||||
char *lofile = specialfile;
|
||||
|
||||
@@ -137,6 +138,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
|
||||
fprintf(stderr, "WARNING: loop device is read-only\n");
|
||||
flags &= ~MS_RDONLY;
|
||||
}
|
||||
use_loop = FALSE;
|
||||
}
|
||||
#endif
|
||||
status =
|
||||
@@ -157,7 +159,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
|
||||
|
||||
/* Bummer. mount failed. Clean up */
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
if (specialfile != NULL) {
|
||||
if (lofile != NULL) {
|
||||
del_loop(specialfile);
|
||||
}
|
||||
#endif
|
||||
@@ -166,20 +168,6 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
|
||||
|
||||
|
||||
|
||||
#if defined BB_MTAB
|
||||
#define whine_if_fstab_is_missing() {}
|
||||
#else
|
||||
extern void whine_if_fstab_is_missing()
|
||||
{
|
||||
struct stat statBuf;
|
||||
|
||||
if (stat("/etc/fstab", &statBuf) < 0)
|
||||
fprintf(stderr,
|
||||
"/etc/fstab file missing -- install one to name /dev/root.\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Seperate standard mount options from the nonstandard string options */
|
||||
static void
|
||||
parse_mount_options(char *options, unsigned long *flags, char *strflags)
|
||||
@@ -204,7 +192,7 @@ parse_mount_options(char *options, unsigned long *flags, char *strflags)
|
||||
}
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
if (gotone == FALSE && !strcasecmp("loop", options)) { /* loop device support */
|
||||
use_loop = 1;
|
||||
use_loop = TRUE;
|
||||
gotone = TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -229,7 +217,7 @@ parse_mount_options(char *options, unsigned long *flags, char *strflags)
|
||||
int
|
||||
mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
unsigned long flags, char *string_flags, int useMtab, int fakeIt,
|
||||
char *mtab_opts)
|
||||
char *mtab_opts, int whineOnErrors)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
@@ -270,9 +258,11 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
fakeIt, mtab_opts);
|
||||
}
|
||||
|
||||
if (status == FALSE) {
|
||||
fprintf(stderr, "Mounting %s on %s failed: %s\n",
|
||||
blockDevice, directory, strerror(errno));
|
||||
if (status == FALSE && whineOnErrors == TRUE) {
|
||||
if (whineOnErrors == TRUE) {
|
||||
fprintf(stderr, "Mounting %s on %s failed: %s\n",
|
||||
blockDevice, directory, strerror(errno));
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
return (TRUE);
|
||||
@@ -387,18 +377,28 @@ extern int mount_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
while ((m = getmntent(f)) != NULL) {
|
||||
// If the file system isn't noauto, and isn't mounted on /,
|
||||
// If the file system isn't noauto,
|
||||
// and isn't swap or nfs, then mount it
|
||||
if ((!strstr(m->mnt_opts, "noauto")) &&
|
||||
(m->mnt_dir[1] != '\0') &&
|
||||
(!strstr(m->mnt_type, "swap")) &&
|
||||
(!strstr(m->mnt_type, "nfs"))) {
|
||||
flags = 0;
|
||||
*string_flags = '\0';
|
||||
parse_mount_options(m->mnt_opts, &flags, string_flags);
|
||||
mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
|
||||
/* If the directory is /, try to remount
|
||||
* with the options specified in fstab */
|
||||
if (m->mnt_dir[0] == '/' && m->mnt_dir[1] == '\0') {
|
||||
flags |= MS_REMOUNT;
|
||||
}
|
||||
if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
|
||||
flags, string_flags, useMtab, fakeIt,
|
||||
extra_opts);
|
||||
extra_opts, FALSE))
|
||||
{
|
||||
/* Try again, but this time try a remount */
|
||||
mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
|
||||
flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
|
||||
extra_opts, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
endmntent(f);
|
||||
@@ -414,7 +414,7 @@ extern int mount_main(int argc, char **argv)
|
||||
#endif
|
||||
exit(mount_one(device, directory, filesystemType,
|
||||
flags, string_flags, useMtab, fakeIt,
|
||||
extra_opts));
|
||||
extra_opts, TRUE));
|
||||
} else {
|
||||
goto goodbye;
|
||||
}
|
||||
|
@@ -36,13 +36,16 @@ static int whichApp;
|
||||
static const char *appName;
|
||||
|
||||
static const char swapoff_usage[] =
|
||||
"swapoff [OPTION] [device]\n\n"
|
||||
"Stop swapping virtual memory pages on the given device.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tStop swapping on all swap devices\n";
|
||||
|
||||
"swapoff device\n"
|
||||
"\nStop swapping virtual memory pages on the given device.\n";
|
||||
static const char swapon_usage[] =
|
||||
|
||||
"swapon device\n"
|
||||
"\nStart swapping virtual memory pages on the given device.\n";
|
||||
"swapon [OPTION] [device]\n\n"
|
||||
"Start swapping virtual memory pages on the given device.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tStart swapping on all swap devices\n";
|
||||
|
||||
|
||||
#define SWAPON_APP 1
|
||||
@@ -85,12 +88,6 @@ static void do_em_all()
|
||||
|
||||
extern int swap_on_off_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statBuf;
|
||||
|
||||
if (stat("/etc/fstab", &statBuf) < 0)
|
||||
fprintf(stderr,
|
||||
"/etc/fstab file missing -- Please install one.\n\n");
|
||||
|
||||
if (strcmp(*argv, "swapon") == 0) {
|
||||
appName = *argv;
|
||||
whichApp = SWAPON_APP;
|
||||
@@ -100,8 +97,9 @@ extern int swap_on_off_main(int argc, char **argv)
|
||||
whichApp = SWAPOFF_APP;
|
||||
}
|
||||
|
||||
if (argc < 2)
|
||||
if (argc != 2) {
|
||||
goto usage_and_exit;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -110,6 +108,7 @@ extern int swap_on_off_main(int argc, char **argv)
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
whine_if_fstab_is_missing();
|
||||
do_em_all();
|
||||
break;
|
||||
default:
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include <fstab.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char umount_usage[] =
|
||||
"umount [flags] filesystem|directory\n\n"
|
||||
"Flags:\n" "\t-a:\tUnmount all file systems"
|
||||
@@ -57,113 +58,6 @@ static int umountAll = FALSE;
|
||||
static int doRemount = FALSE;
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
#define MIN(x,y) (x > y ? x : y)
|
||||
|
||||
static int do_umount(const char *name, int useMtab)
|
||||
{
|
||||
int status;
|
||||
char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE);
|
||||
|
||||
if (blockDevice && strcmp(blockDevice, name) == 0)
|
||||
name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT);
|
||||
|
||||
status = umount(name);
|
||||
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9))
|
||||
/* this was a loop device, delete it */
|
||||
del_loop(blockDevice);
|
||||
#endif
|
||||
#if defined BB_FEATURE_REMOUNT
|
||||
if (status != 0 && doRemount == TRUE && errno == EBUSY) {
|
||||
status = mount(blockDevice, name, NULL,
|
||||
MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL);
|
||||
if (status == 0) {
|
||||
fprintf(stderr, "umount: %s busy - remounted read-only\n",
|
||||
blockDevice);
|
||||
/* TODO: update mtab if BB_MTAB is defined */
|
||||
} else {
|
||||
fprintf(stderr, "umount: Cannot remount %s read-only\n",
|
||||
blockDevice);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (status == 0) {
|
||||
#if defined BB_MTAB
|
||||
if (useMtab == TRUE)
|
||||
erase_mtab(name);
|
||||
#endif
|
||||
return (TRUE);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static int umount_all(int useMtab)
|
||||
{
|
||||
int status = TRUE;
|
||||
char *mountpt;
|
||||
void *iter;
|
||||
|
||||
for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) {
|
||||
status = do_umount(mountpt, useMtab);
|
||||
if (status != 0) {
|
||||
/* Don't bother retrying the umount on busy devices */
|
||||
if (errno == EBUSY) {
|
||||
perror(mountpt);
|
||||
continue;
|
||||
}
|
||||
status = do_umount(mountpt, useMtab);
|
||||
if (status != 0) {
|
||||
printf("Couldn't umount %s on %s: %s\n",
|
||||
mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE),
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
|
||||
extern int umount_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
usage(umount_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
umountAll = TRUE;
|
||||
break;
|
||||
#ifdef BB_MTAB
|
||||
case 'n':
|
||||
useMtab = FALSE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_REMOUNT
|
||||
case 'r':
|
||||
doRemount = TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage(umount_usage);
|
||||
}
|
||||
}
|
||||
|
||||
mtab_read();
|
||||
if (umountAll == TRUE) {
|
||||
exit(umount_all(useMtab));
|
||||
}
|
||||
if (do_umount(*argv, useMtab) == 0)
|
||||
exit(TRUE);
|
||||
else {
|
||||
perror("umount");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* These functions are here because the getmntent functions do not appear
|
||||
* to be re-entrant, which leads to all sorts of problems when we try to
|
||||
@@ -257,3 +151,111 @@ void mtab_free(void)
|
||||
this = next;
|
||||
}
|
||||
}
|
||||
|
||||
static int do_umount(const char *name, int useMtab)
|
||||
{
|
||||
int status;
|
||||
char *blockDevice = mtab_getinfo(name, MTAB_GETDEVICE);
|
||||
|
||||
if (blockDevice && strcmp(blockDevice, name) == 0)
|
||||
name = mtab_getinfo(blockDevice, MTAB_GETMOUNTPT);
|
||||
|
||||
status = umount(name);
|
||||
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9))
|
||||
/* this was a loop device, delete it */
|
||||
del_loop(blockDevice);
|
||||
#endif
|
||||
#if defined BB_FEATURE_REMOUNT
|
||||
if (status != 0 && doRemount == TRUE && errno == EBUSY) {
|
||||
status = mount(blockDevice, name, NULL,
|
||||
MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL);
|
||||
if (status == 0) {
|
||||
fprintf(stderr, "umount: %s busy - remounted read-only\n",
|
||||
blockDevice);
|
||||
/* TODO: update mtab if BB_MTAB is defined */
|
||||
} else {
|
||||
fprintf(stderr, "umount: Cannot remount %s read-only\n",
|
||||
blockDevice);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (status == 0) {
|
||||
#if defined BB_MTAB
|
||||
if (useMtab == TRUE)
|
||||
erase_mtab(name);
|
||||
#endif
|
||||
return (TRUE);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static int umount_all(int useMtab)
|
||||
{
|
||||
int status = TRUE;
|
||||
char *mountpt;
|
||||
void *iter;
|
||||
|
||||
for (mountpt = mtab_first(&iter); mountpt; mountpt = mtab_next(&iter)) {
|
||||
/* Never umount /proc on a umount -a */
|
||||
if (strstr(mountpt, "proc")!= NULL)
|
||||
continue;
|
||||
status = do_umount(mountpt, useMtab);
|
||||
if (status != 0) {
|
||||
/* Don't bother retrying the umount on busy devices */
|
||||
if (errno == EBUSY) {
|
||||
perror(mountpt);
|
||||
continue;
|
||||
}
|
||||
status = do_umount(mountpt, useMtab);
|
||||
if (status != 0) {
|
||||
printf("Couldn't umount %s on %s: %s\n",
|
||||
mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE),
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
return (status);
|
||||
}
|
||||
|
||||
extern int umount_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
usage(umount_usage);
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
umountAll = TRUE;
|
||||
break;
|
||||
#ifdef BB_MTAB
|
||||
case 'n':
|
||||
useMtab = FALSE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_REMOUNT
|
||||
case 'r':
|
||||
doRemount = TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage(umount_usage);
|
||||
}
|
||||
}
|
||||
|
||||
mtab_read();
|
||||
if (umountAll == TRUE) {
|
||||
exit(umount_all(useMtab));
|
||||
}
|
||||
if (do_umount(*argv, useMtab) == 0)
|
||||
exit(TRUE);
|
||||
else {
|
||||
perror("umount");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user