Reduce the size of mount (and bypass /proc/filesystems) by using the sysfs
system call, based on work done by Glenn McGrath in December. -Erik
This commit is contained in:
parent
93ba60f01d
commit
7b91f02021
73
mount.c
73
mount.c
@ -83,6 +83,7 @@ extern int mount (__const char *__special_file, __const char *__dir,
|
|||||||
__const void *__data);
|
__const void *__data);
|
||||||
extern int umount (__const char *__special_file);
|
extern int umount (__const char *__special_file);
|
||||||
extern int umount2 (__const char *__special_file, int __flags);
|
extern int umount2 (__const char *__special_file, int __flags);
|
||||||
|
static _syscall3(int, sysfs, int, option, unsigned int, fs_index, char *, buf);
|
||||||
|
|
||||||
|
|
||||||
extern const char mtab_file[]; /* Defined in utility.c */
|
extern const char mtab_file[]; /* Defined in utility.c */
|
||||||
@ -233,72 +234,24 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
|||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
char buf[255];
|
|
||||||
if (strcmp(filesystemType, "auto") == 0) {
|
if (strcmp(filesystemType, "auto") == 0) {
|
||||||
FILE *f = xfopen("/proc/filesystems", "r");
|
int i=0;
|
||||||
|
const int num_of_filesystems = sysfs(3, 0, 0);
|
||||||
|
char buf[255];
|
||||||
|
filesystemType=buf;
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), f) != NULL) {
|
while(i < num_of_filesystems) {
|
||||||
filesystemType = buf;
|
sysfs(2, i++, filesystemType);
|
||||||
if (*filesystemType == '\t') { // Not a nodev filesystem
|
status = do_mount(blockDevice, directory, filesystemType,
|
||||||
|
flags | MS_MGC_VAL, string_flags,
|
||||||
// Add NULL termination to each line
|
useMtab, fakeIt, mtab_opts);
|
||||||
while (*filesystemType && *filesystemType != '\n')
|
|
||||||
filesystemType++;
|
|
||||||
*filesystemType = '\0';
|
|
||||||
|
|
||||||
filesystemType = buf;
|
|
||||||
filesystemType++; // hop past tab
|
|
||||||
|
|
||||||
status = do_mount(blockDevice, directory, filesystemType,
|
|
||||||
flags | MS_MGC_VAL, string_flags,
|
|
||||||
useMtab, fakeIt, mtab_opts);
|
|
||||||
if (status == TRUE)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
} else
|
|
||||||
#if defined BB_FEATURE_USE_DEVPS_PATCH
|
|
||||||
if (strcmp(filesystemType, "auto") == 0) {
|
|
||||||
int fd, i, numfilesystems;
|
|
||||||
char device[] = "/dev/mtab";
|
|
||||||
struct k_fstype *fslist;
|
|
||||||
|
|
||||||
/* open device */
|
|
||||||
fd = open(device, O_RDONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
perror_msg_and_die("open failed for `%s'", device);
|
|
||||||
|
|
||||||
/* How many filesystems? We need to know to allocate enough space */
|
|
||||||
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
|
|
||||||
if (numfilesystems<0)
|
|
||||||
perror_msg_and_die("\nDEVMTAB_COUNT_FILESYSTEMS");
|
|
||||||
fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
|
|
||||||
|
|
||||||
/* Grab the list of available filesystems */
|
|
||||||
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
|
|
||||||
if (status<0)
|
|
||||||
perror_msg_and_die("\nDEVMTAB_GET_FILESYSTEMS");
|
|
||||||
|
|
||||||
/* Walk the list trying to mount filesystems
|
|
||||||
* that do not claim to be nodev filesystems */
|
|
||||||
for( i = 0 ; i < numfilesystems ; i++) {
|
|
||||||
if (fslist[i].mnt_nodev)
|
|
||||||
continue;
|
|
||||||
status = do_mount(blockDevice, directory, fslist[i].mnt_type,
|
|
||||||
flags | MS_MGC_VAL, string_flags,
|
|
||||||
useMtab, fakeIt, mtab_opts);
|
|
||||||
if (status == TRUE)
|
if (status == TRUE)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free( fslist);
|
} else {
|
||||||
close(fd);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
status = do_mount(blockDevice, directory, filesystemType,
|
status = do_mount(blockDevice, directory, filesystemType,
|
||||||
flags | MS_MGC_VAL, string_flags, useMtab,
|
flags | MS_MGC_VAL, string_flags, useMtab,
|
||||||
fakeIt, mtab_opts);
|
fakeIt, mtab_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == FALSE) {
|
if (status == FALSE) {
|
||||||
|
@ -83,6 +83,7 @@ extern int mount (__const char *__special_file, __const char *__dir,
|
|||||||
__const void *__data);
|
__const void *__data);
|
||||||
extern int umount (__const char *__special_file);
|
extern int umount (__const char *__special_file);
|
||||||
extern int umount2 (__const char *__special_file, int __flags);
|
extern int umount2 (__const char *__special_file, int __flags);
|
||||||
|
static _syscall3(int, sysfs, int, option, unsigned int, fs_index, char *, buf);
|
||||||
|
|
||||||
|
|
||||||
extern const char mtab_file[]; /* Defined in utility.c */
|
extern const char mtab_file[]; /* Defined in utility.c */
|
||||||
@ -233,72 +234,24 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
|||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
char buf[255];
|
|
||||||
if (strcmp(filesystemType, "auto") == 0) {
|
if (strcmp(filesystemType, "auto") == 0) {
|
||||||
FILE *f = xfopen("/proc/filesystems", "r");
|
int i=0;
|
||||||
|
const int num_of_filesystems = sysfs(3, 0, 0);
|
||||||
|
char buf[255];
|
||||||
|
filesystemType=buf;
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), f) != NULL) {
|
while(i < num_of_filesystems) {
|
||||||
filesystemType = buf;
|
sysfs(2, i++, filesystemType);
|
||||||
if (*filesystemType == '\t') { // Not a nodev filesystem
|
status = do_mount(blockDevice, directory, filesystemType,
|
||||||
|
flags | MS_MGC_VAL, string_flags,
|
||||||
// Add NULL termination to each line
|
useMtab, fakeIt, mtab_opts);
|
||||||
while (*filesystemType && *filesystemType != '\n')
|
|
||||||
filesystemType++;
|
|
||||||
*filesystemType = '\0';
|
|
||||||
|
|
||||||
filesystemType = buf;
|
|
||||||
filesystemType++; // hop past tab
|
|
||||||
|
|
||||||
status = do_mount(blockDevice, directory, filesystemType,
|
|
||||||
flags | MS_MGC_VAL, string_flags,
|
|
||||||
useMtab, fakeIt, mtab_opts);
|
|
||||||
if (status == TRUE)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
} else
|
|
||||||
#if defined BB_FEATURE_USE_DEVPS_PATCH
|
|
||||||
if (strcmp(filesystemType, "auto") == 0) {
|
|
||||||
int fd, i, numfilesystems;
|
|
||||||
char device[] = "/dev/mtab";
|
|
||||||
struct k_fstype *fslist;
|
|
||||||
|
|
||||||
/* open device */
|
|
||||||
fd = open(device, O_RDONLY);
|
|
||||||
if (fd < 0)
|
|
||||||
perror_msg_and_die("open failed for `%s'", device);
|
|
||||||
|
|
||||||
/* How many filesystems? We need to know to allocate enough space */
|
|
||||||
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
|
|
||||||
if (numfilesystems<0)
|
|
||||||
perror_msg_and_die("\nDEVMTAB_COUNT_FILESYSTEMS");
|
|
||||||
fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
|
|
||||||
|
|
||||||
/* Grab the list of available filesystems */
|
|
||||||
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
|
|
||||||
if (status<0)
|
|
||||||
perror_msg_and_die("\nDEVMTAB_GET_FILESYSTEMS");
|
|
||||||
|
|
||||||
/* Walk the list trying to mount filesystems
|
|
||||||
* that do not claim to be nodev filesystems */
|
|
||||||
for( i = 0 ; i < numfilesystems ; i++) {
|
|
||||||
if (fslist[i].mnt_nodev)
|
|
||||||
continue;
|
|
||||||
status = do_mount(blockDevice, directory, fslist[i].mnt_type,
|
|
||||||
flags | MS_MGC_VAL, string_flags,
|
|
||||||
useMtab, fakeIt, mtab_opts);
|
|
||||||
if (status == TRUE)
|
if (status == TRUE)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free( fslist);
|
} else {
|
||||||
close(fd);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
status = do_mount(blockDevice, directory, filesystemType,
|
status = do_mount(blockDevice, directory, filesystemType,
|
||||||
flags | MS_MGC_VAL, string_flags, useMtab,
|
flags | MS_MGC_VAL, string_flags, useMtab,
|
||||||
fakeIt, mtab_opts);
|
fakeIt, mtab_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == FALSE) {
|
if (status == FALSE) {
|
||||||
|
@ -63,8 +63,8 @@
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <linux/unistd.h>
|
#include <linux/unistd.h>
|
||||||
|
|
||||||
/* Busybox mount uses either /proc/filesystems or /dev/mtab to get the
|
/* Busybox mount uses either /proc/mounts or /dev/mtab to
|
||||||
* list of available filesystems used for the -t auto option */
|
* get the list of currently mounted filesystems */
|
||||||
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
|
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
|
||||||
# if defined BB_MTAB
|
# if defined BB_MTAB
|
||||||
const char mtab_file[] = "/etc/mtab";
|
const char mtab_file[] = "/etc/mtab";
|
||||||
|
Loading…
Reference in New Issue
Block a user