mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2025-01-27 14:52:56 +00:00
Fixed ln, df, and removed redundant stuff from mtab.
This commit is contained in:
parent
bc34190694
commit
29d2e362de
@ -1,5 +1,12 @@
|
|||||||
0.33
|
0.33
|
||||||
* Fixed a bug where init could hang instead of rebooting.
|
* Fixed a bug where init could hang instead of rebooting.
|
||||||
|
* Removed some debugging noise from init.c
|
||||||
|
* Fixed ln so it works now (it was very broken).
|
||||||
|
* Fixed df so it won't segfault when there is no /etc/fstab,
|
||||||
|
* If BB_MTAB is not defined, df and mount will whine if /etc/fstab
|
||||||
|
is not installed (since they cannot fixup "/dev/root" to
|
||||||
|
state the real root device name)
|
||||||
|
* merged some redundant code from mtab.c/df.c into utility.c
|
||||||
|
|
||||||
0.32
|
0.32
|
||||||
* More changes -- many thanks to Lineo for paying me to work on
|
* More changes -- many thanks to Lineo for paying me to work on
|
||||||
|
@ -38,6 +38,7 @@ static int df(char *device, const char *mountPoint)
|
|||||||
struct statfs s;
|
struct statfs s;
|
||||||
long blocks_used;
|
long blocks_used;
|
||||||
long blocks_percent_used;
|
long blocks_percent_used;
|
||||||
|
struct fstab* fstabItem;
|
||||||
|
|
||||||
if (statfs(mountPoint, &s) != 0) {
|
if (statfs(mountPoint, &s) != 0) {
|
||||||
perror(mountPoint);
|
perror(mountPoint);
|
||||||
@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint)
|
|||||||
blocks_used = s.f_blocks - s.f_bfree;
|
blocks_used = s.f_blocks - s.f_bfree;
|
||||||
blocks_percent_used = (long)
|
blocks_percent_used = (long)
|
||||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||||
if (strcmp(device, "/dev/root") == 0)
|
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||||
device = (getfsfile("/"))->fs_spec;
|
if (strcmp (device, "/dev/root") == 0) {
|
||||||
|
fstabItem = getfsfile ("/");
|
||||||
|
if (fstabItem != NULL)
|
||||||
|
device = fstabItem->fs_spec;
|
||||||
|
}
|
||||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||||
device,
|
device,
|
||||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||||
@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Given a block device, find the mount table entry if that block device
|
|
||||||
* is mounted.
|
|
||||||
*
|
|
||||||
* Given any other file (or directory), find the mount table entry for its
|
|
||||||
* filesystem.
|
|
||||||
*/
|
|
||||||
extern struct mntent *findMountPoint(const char *name, const char *table)
|
|
||||||
{
|
|
||||||
struct stat s;
|
|
||||||
dev_t mountDevice;
|
|
||||||
FILE *mountTable;
|
|
||||||
struct mntent *mountEntry;
|
|
||||||
|
|
||||||
if (stat(name, &s) != 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if ((s.st_mode & S_IFMT) == S_IFBLK)
|
|
||||||
mountDevice = s.st_rdev;
|
|
||||||
else
|
|
||||||
mountDevice = s.st_dev;
|
|
||||||
|
|
||||||
|
|
||||||
if ((mountTable = setmntent(table, "r")) == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while ((mountEntry = getmntent(mountTable)) != 0) {
|
|
||||||
if (strcmp(name, mountEntry->mnt_dir) == 0
|
|
||||||
|| strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
|
|
||||||
break;
|
|
||||||
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
|
|
||||||
break;
|
|
||||||
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
endmntent(mountTable);
|
|
||||||
return mountEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern int df_main(int argc, char **argv)
|
extern int df_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||||
|
|
||||||
|
/* Only compiled in if BB_MTAB is not defined */
|
||||||
|
whine_if_fstab_is_missing();
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
struct mntent *mountEntry;
|
struct mntent *mountEntry;
|
||||||
int status;
|
int status;
|
||||||
|
@ -27,23 +27,21 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
|
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
|
||||||
"\n"
|
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
|
||||||
"\tAdd a new name that refers to the same file as \"original-name\"\n"
|
"\nOptions:\n"
|
||||||
"\n"
|
"\t-s\tmake symbolic links instead of hard links\n"
|
||||||
"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
|
"\t-f\tremove existing destination files\n";
|
||||||
"\t-f:\tRemove existing destination files.\n";
|
|
||||||
|
|
||||||
|
|
||||||
static int symlinkFlag = FALSE;
|
static int symlinkFlag = FALSE;
|
||||||
static int removeoldFlag = FALSE;
|
static int removeoldFlag = FALSE;
|
||||||
static const char *destName;
|
|
||||||
|
|
||||||
|
|
||||||
extern int ln_main(int argc, char **argv)
|
extern int ln_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
char newdestName[NAME_MAX];
|
static char* linkName;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
usage (ln_usage);
|
usage (ln_usage);
|
||||||
@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
destName = argv[argc - 1];
|
linkName = argv[argc - 1];
|
||||||
|
|
||||||
if ((argc > 3) && !(isDirectory(destName))) {
|
if ((argc > 3) && !(isDirectory(linkName))) {
|
||||||
fprintf(stderr, "%s: not a directory\n", destName);
|
fprintf(stderr, "%s: not a directory\n", linkName);
|
||||||
exit (FALSE);
|
exit (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (argc-- >= 2) {
|
while (argc-- >= 2) {
|
||||||
strcpy(newdestName, destName);
|
|
||||||
strcat(newdestName, (*argv)+(strlen(*(++argv))));
|
|
||||||
|
|
||||||
if (removeoldFlag==TRUE ) {
|
if (removeoldFlag==TRUE ) {
|
||||||
status = ( unlink(newdestName) && errno != ENOENT );
|
status = ( unlink(linkName) && errno != ENOENT );
|
||||||
if ( status != 0 ) {
|
if ( status != 0 ) {
|
||||||
perror(newdestName);
|
perror(linkName);
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( symlinkFlag==TRUE)
|
if ( symlinkFlag==TRUE)
|
||||||
status = symlink(*argv, newdestName);
|
status = symlink(*argv, linkName);
|
||||||
else
|
else
|
||||||
status = link(*argv, newdestName);
|
status = link(*argv, linkName);
|
||||||
if ( status != 0 ) {
|
if ( status != 0 ) {
|
||||||
perror(newdestName);
|
perror(linkName);
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
df.c
54
df.c
@ -38,6 +38,7 @@ static int df(char *device, const char *mountPoint)
|
|||||||
struct statfs s;
|
struct statfs s;
|
||||||
long blocks_used;
|
long blocks_used;
|
||||||
long blocks_percent_used;
|
long blocks_percent_used;
|
||||||
|
struct fstab* fstabItem;
|
||||||
|
|
||||||
if (statfs(mountPoint, &s) != 0) {
|
if (statfs(mountPoint, &s) != 0) {
|
||||||
perror(mountPoint);
|
perror(mountPoint);
|
||||||
@ -48,9 +49,12 @@ static int df(char *device, const char *mountPoint)
|
|||||||
blocks_used = s.f_blocks - s.f_bfree;
|
blocks_used = s.f_blocks - s.f_bfree;
|
||||||
blocks_percent_used = (long)
|
blocks_percent_used = (long)
|
||||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||||
if (strcmp(device, "/dev/root") == 0)
|
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||||
device = (getfsfile("/"))->fs_spec;
|
if (strcmp (device, "/dev/root") == 0) {
|
||||||
|
fstabItem = getfsfile ("/");
|
||||||
|
if (fstabItem != NULL)
|
||||||
|
device = fstabItem->fs_spec;
|
||||||
|
}
|
||||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||||
device,
|
device,
|
||||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||||
@ -63,52 +67,14 @@ static int df(char *device, const char *mountPoint)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Given a block device, find the mount table entry if that block device
|
|
||||||
* is mounted.
|
|
||||||
*
|
|
||||||
* Given any other file (or directory), find the mount table entry for its
|
|
||||||
* filesystem.
|
|
||||||
*/
|
|
||||||
extern struct mntent *findMountPoint(const char *name, const char *table)
|
|
||||||
{
|
|
||||||
struct stat s;
|
|
||||||
dev_t mountDevice;
|
|
||||||
FILE *mountTable;
|
|
||||||
struct mntent *mountEntry;
|
|
||||||
|
|
||||||
if (stat(name, &s) != 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if ((s.st_mode & S_IFMT) == S_IFBLK)
|
|
||||||
mountDevice = s.st_rdev;
|
|
||||||
else
|
|
||||||
mountDevice = s.st_dev;
|
|
||||||
|
|
||||||
|
|
||||||
if ((mountTable = setmntent(table, "r")) == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while ((mountEntry = getmntent(mountTable)) != 0) {
|
|
||||||
if (strcmp(name, mountEntry->mnt_dir) == 0
|
|
||||||
|| strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
|
|
||||||
break;
|
|
||||||
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
|
|
||||||
break;
|
|
||||||
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
endmntent(mountTable);
|
|
||||||
return mountEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern int df_main(int argc, char **argv)
|
extern int df_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||||
|
|
||||||
|
/* Only compiled in if BB_MTAB is not defined */
|
||||||
|
whine_if_fstab_is_missing();
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
struct mntent *mountEntry;
|
struct mntent *mountEntry;
|
||||||
int status;
|
int status;
|
||||||
|
10
internal.h
10
internal.h
@ -29,6 +29,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <mntent.h>
|
||||||
|
|
||||||
|
|
||||||
/* Some useful definitions */
|
/* Some useful definitions */
|
||||||
@ -145,12 +146,19 @@ extern void my_getpwuid(char* name, uid_t uid);
|
|||||||
extern void my_getgrgid(char* group, gid_t gid);
|
extern void my_getgrgid(char* group, gid_t gid);
|
||||||
extern int get_kernel_revision();
|
extern int get_kernel_revision();
|
||||||
extern int get_console_fd(char* tty_name);
|
extern int get_console_fd(char* tty_name);
|
||||||
|
extern struct mntent *findMountPoint(const char *name, const char *table);
|
||||||
extern void write_mtab(char* blockDevice, char* directory,
|
extern void write_mtab(char* blockDevice, char* directory,
|
||||||
char* filesystemType, long flags, char* string_flags);
|
char* filesystemType, long flags, char* string_flags);
|
||||||
extern void erase_mtab(const char * name);
|
extern void erase_mtab(const char * name);
|
||||||
|
|
||||||
|
|
||||||
|
#if defined BB_MTAB
|
||||||
|
#define whine_if_fstab_is_missing() {}
|
||||||
|
#else
|
||||||
|
extern void whine_if_fstab_is_missing();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
|
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
|
||||||
|
|
||||||
static inline int bit(char * addr,unsigned int nr)
|
static inline int bit(char * addr,unsigned int nr)
|
||||||
|
33
ln.c
33
ln.c
@ -27,23 +27,21 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
|
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
|
||||||
"\n"
|
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
|
||||||
"\tAdd a new name that refers to the same file as \"original-name\"\n"
|
"\nOptions:\n"
|
||||||
"\n"
|
"\t-s\tmake symbolic links instead of hard links\n"
|
||||||
"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
|
"\t-f\tremove existing destination files\n";
|
||||||
"\t-f:\tRemove existing destination files.\n";
|
|
||||||
|
|
||||||
|
|
||||||
static int symlinkFlag = FALSE;
|
static int symlinkFlag = FALSE;
|
||||||
static int removeoldFlag = FALSE;
|
static int removeoldFlag = FALSE;
|
||||||
static const char *destName;
|
|
||||||
|
|
||||||
|
|
||||||
extern int ln_main(int argc, char **argv)
|
extern int ln_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
char newdestName[NAME_MAX];
|
static char* linkName;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
usage (ln_usage);
|
usage (ln_usage);
|
||||||
@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
destName = argv[argc - 1];
|
linkName = argv[argc - 1];
|
||||||
|
|
||||||
if ((argc > 3) && !(isDirectory(destName))) {
|
if ((argc > 3) && !(isDirectory(linkName))) {
|
||||||
fprintf(stderr, "%s: not a directory\n", destName);
|
fprintf(stderr, "%s: not a directory\n", linkName);
|
||||||
exit (FALSE);
|
exit (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (argc-- >= 2) {
|
while (argc-- >= 2) {
|
||||||
strcpy(newdestName, destName);
|
|
||||||
strcat(newdestName, (*argv)+(strlen(*(++argv))));
|
|
||||||
|
|
||||||
if (removeoldFlag==TRUE ) {
|
if (removeoldFlag==TRUE ) {
|
||||||
status = ( unlink(newdestName) && errno != ENOENT );
|
status = ( unlink(linkName) && errno != ENOENT );
|
||||||
if ( status != 0 ) {
|
if ( status != 0 ) {
|
||||||
perror(newdestName);
|
perror(linkName);
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( symlinkFlag==TRUE)
|
if ( symlinkFlag==TRUE)
|
||||||
status = symlink(*argv, newdestName);
|
status = symlink(*argv, linkName);
|
||||||
else
|
else
|
||||||
status = link(*argv, newdestName);
|
status = link(*argv, linkName);
|
||||||
if ( status != 0 ) {
|
if ( status != 0 ) {
|
||||||
perror(newdestName);
|
perror(linkName);
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
mount.c
5
mount.c
@ -208,14 +208,13 @@ extern int mount_main (int argc, char **argv)
|
|||||||
char *filesystemType = "auto";
|
char *filesystemType = "auto";
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *directory = NULL;
|
char *directory = NULL;
|
||||||
struct stat statBuf;
|
|
||||||
int all = FALSE;
|
int all = FALSE;
|
||||||
int fakeIt = FALSE;
|
int fakeIt = FALSE;
|
||||||
int useMtab = TRUE;
|
int useMtab = TRUE;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (stat("/etc/fstab", &statBuf) < 0)
|
/* Only compiled in if BB_MTAB is not defined */
|
||||||
fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
|
whine_if_fstab_is_missing();
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
FILE *mountTable = setmntent (mtab_file, "r");
|
FILE *mountTable = setmntent (mtab_file, "r");
|
||||||
|
42
mtab.c
42
mtab.c
@ -59,48 +59,6 @@ erase_mtab(const char * name)
|
|||||||
perror(mtab_file);
|
perror(mtab_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Given a block device, find the mount table entry if that block device
|
|
||||||
* is mounted.
|
|
||||||
*
|
|
||||||
* Given any other file (or directory), find the mount table entry for its
|
|
||||||
* filesystem.
|
|
||||||
*/
|
|
||||||
static struct mntent *
|
|
||||||
findMountPoint(const char * name, const char * table)
|
|
||||||
{
|
|
||||||
struct stat s;
|
|
||||||
dev_t mountDevice;
|
|
||||||
FILE* mountTable;
|
|
||||||
struct mntent* mountEntry;
|
|
||||||
|
|
||||||
if ( stat(name, &s) != 0 )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if ( (s.st_mode & S_IFMT) == S_IFBLK )
|
|
||||||
mountDevice = s.st_rdev;
|
|
||||||
else
|
|
||||||
mountDevice = s.st_dev;
|
|
||||||
|
|
||||||
|
|
||||||
if ( (mountTable = setmntent(table, "r")) == 0 )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
while ( (mountEntry = getmntent(mountTable)) != 0 ) {
|
|
||||||
if ( strcmp(name, mountEntry->mnt_dir) == 0 ||
|
|
||||||
strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
|
|
||||||
break;
|
|
||||||
if ( stat(mountEntry->mnt_fsname, &s) == 0 &&
|
|
||||||
s.st_rdev == mountDevice ) /* Match the device. */
|
|
||||||
break;
|
|
||||||
if ( stat(mountEntry->mnt_dir, &s) == 0 &&
|
|
||||||
s.st_dev == mountDevice ) /* Match the directory's mount point. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
endmntent(mountTable);
|
|
||||||
return mountEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
write_mtab(char* blockDevice, char* directory,
|
write_mtab(char* blockDevice, char* directory,
|
||||||
char* filesystemType, long flags, char* string_flags)
|
char* filesystemType, long flags, char* string_flags)
|
||||||
|
@ -208,14 +208,13 @@ extern int mount_main (int argc, char **argv)
|
|||||||
char *filesystemType = "auto";
|
char *filesystemType = "auto";
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *directory = NULL;
|
char *directory = NULL;
|
||||||
struct stat statBuf;
|
|
||||||
int all = FALSE;
|
int all = FALSE;
|
||||||
int fakeIt = FALSE;
|
int fakeIt = FALSE;
|
||||||
int useMtab = TRUE;
|
int useMtab = TRUE;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (stat("/etc/fstab", &statBuf) < 0)
|
/* Only compiled in if BB_MTAB is not defined */
|
||||||
fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
|
whine_if_fstab_is_missing();
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
FILE *mountTable = setmntent (mtab_file, "r");
|
FILE *mountTable = setmntent (mtab_file, "r");
|
||||||
|
59
utility.c
59
utility.c
@ -868,5 +868,64 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
|
|||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined BB_DF | defined BB_MTAB
|
||||||
|
/*
|
||||||
|
* Given a block device, find the mount table entry if that block device
|
||||||
|
* is mounted.
|
||||||
|
*
|
||||||
|
* Given any other file (or directory), find the mount table entry for its
|
||||||
|
* filesystem.
|
||||||
|
*/
|
||||||
|
extern struct mntent *findMountPoint(const char *name, const char *table)
|
||||||
|
{
|
||||||
|
struct stat s;
|
||||||
|
dev_t mountDevice;
|
||||||
|
FILE *mountTable;
|
||||||
|
struct mntent *mountEntry;
|
||||||
|
|
||||||
|
if (stat(name, &s) != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ((s.st_mode & S_IFMT) == S_IFBLK)
|
||||||
|
mountDevice = s.st_rdev;
|
||||||
|
else
|
||||||
|
mountDevice = s.st_dev;
|
||||||
|
|
||||||
|
|
||||||
|
if ((mountTable = setmntent(table, "r")) == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
while ((mountEntry = getmntent(mountTable)) != 0) {
|
||||||
|
if (strcmp(name, mountEntry->mnt_dir) == 0
|
||||||
|
|| strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
|
||||||
|
break;
|
||||||
|
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
|
||||||
|
break;
|
||||||
|
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
endmntent(mountTable);
|
||||||
|
return mountEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined BB_MTAB && (defined BB_MOUNT || defined BB_DF )
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
/* END CODE */
|
/* END CODE */
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user