df: fix "df /"
also, clean up mount checks in mkfs/fsck. function old new delta find_mount_point 243 261 +18 sha1_process_block64 497 510 +13 find_main 436 444 +8 display_speed 85 90 +5 df_main 795 793 -2 parse_command 1463 1460 -3 static.ignored_mounts 8 - -8 mkfs_minix_main 2962 2937 -25 fsck_minix_main 3065 2970 -95 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 4/4 up/down: 44/-133) Total: -89 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
9b1b62adc4
commit
09e63bb81f
@ -21,7 +21,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
|||||||
/* Check if the file already exists */
|
/* Check if the file already exists */
|
||||||
if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||||
/* Remove the entry if it exists */
|
/* Remove the entry if it exists */
|
||||||
if (((file_header->mode & S_IFMT) != S_IFDIR)
|
if ((!S_ISDIR(file_header->mode))
|
||||||
&& (unlink(file_header->name) == -1)
|
&& (unlink(file_header->name) == -1)
|
||||||
&& (errno != ENOENT)
|
&& (errno != ENOENT)
|
||||||
) {
|
) {
|
||||||
@ -132,7 +132,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
|||||||
#endif
|
#endif
|
||||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||||
}
|
}
|
||||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
if (S_ISLNK(file_header->mode)) {
|
||||||
/* uclibc has no lchmod, glibc is even stranger -
|
/* uclibc has no lchmod, glibc is even stranger -
|
||||||
* it has lchmod which seems to do nothing!
|
* it has lchmod which seems to do nothing!
|
||||||
* so we use chmod... */
|
* so we use chmod... */
|
||||||
|
@ -44,7 +44,6 @@ int df_main(int argc, char **argv)
|
|||||||
FILE *mount_table;
|
FILE *mount_table;
|
||||||
struct mntent *mount_entry;
|
struct mntent *mount_entry;
|
||||||
struct statfs s;
|
struct statfs s;
|
||||||
static const char ignored_mounts[] ALIGN1 = "rootfs\0";
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OPT_KILO = (1 << 0),
|
OPT_KILO = (1 << 0),
|
||||||
@ -120,7 +119,7 @@ int df_main(int argc, char **argv)
|
|||||||
mount_point = *argv++;
|
mount_point = *argv++;
|
||||||
if (!mount_point)
|
if (!mount_point)
|
||||||
break;
|
break;
|
||||||
mount_entry = find_mount_point(mount_point, bb_path_mtab_file);
|
mount_entry = find_mount_point(mount_point);
|
||||||
if (!mount_entry) {
|
if (!mount_entry) {
|
||||||
bb_error_msg("%s: can't find mount point", mount_point);
|
bb_error_msg("%s: can't find mount point", mount_point);
|
||||||
set_error:
|
set_error:
|
||||||
@ -154,8 +153,8 @@ int df_main(int argc, char **argv)
|
|||||||
) / (blocks_used + s.f_bavail);
|
) / (blocks_used + s.f_bavail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GNU coreutils 6.10 skip certain mounts, try to be compatible. */
|
/* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
|
||||||
if (index_in_strings(device, ignored_mounts) != -1)
|
if (strcmp(device, "rootfs") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
||||||
|
@ -986,7 +986,7 @@ extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
|
|||||||
|
|
||||||
#ifdef HAVE_MNTENT_H
|
#ifdef HAVE_MNTENT_H
|
||||||
extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC;
|
extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC;
|
||||||
extern struct mntent *find_mount_point(const char *name, const char *table) FAST_FUNC;
|
extern struct mntent *find_mount_point(const char *name) FAST_FUNC;
|
||||||
#endif
|
#endif
|
||||||
extern void erase_mtab(const char * name) FAST_FUNC;
|
extern void erase_mtab(const char * name) FAST_FUNC;
|
||||||
extern unsigned int tty_baud_to_value(speed_t speed) FAST_FUNC;
|
extern unsigned int tty_baud_to_value(speed_t speed) FAST_FUNC;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* Given any other file (or directory), find the mount table entry for its
|
* Given any other file (or directory), find the mount table entry for its
|
||||||
* filesystem.
|
* filesystem.
|
||||||
*/
|
*/
|
||||||
struct mntent* FAST_FUNC find_mount_point(const char *name, const char *table)
|
struct mntent* FAST_FUNC find_mount_point(const char *name)
|
||||||
{
|
{
|
||||||
struct stat s;
|
struct stat s;
|
||||||
dev_t mountDevice;
|
dev_t mountDevice;
|
||||||
@ -25,27 +25,35 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, const char *table)
|
|||||||
struct mntent *mountEntry;
|
struct mntent *mountEntry;
|
||||||
|
|
||||||
if (stat(name, &s) != 0)
|
if (stat(name, &s) != 0)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if ((s.st_mode & S_IFMT) == S_IFBLK)
|
if (S_ISBLK(s.st_mode))
|
||||||
mountDevice = s.st_rdev;
|
mountDevice = s.st_rdev;
|
||||||
else
|
else
|
||||||
mountDevice = s.st_dev;
|
mountDevice = s.st_dev;
|
||||||
|
|
||||||
|
|
||||||
mountTable = setmntent(table ? table : bb_path_mtab_file, "r");
|
mountTable = setmntent(bb_path_mtab_file, "r");
|
||||||
if (!mountTable)
|
if (!mountTable)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while ((mountEntry = getmntent(mountTable)) != 0) {
|
while ((mountEntry = getmntent(mountTable)) != NULL) {
|
||||||
|
/* rootfs mount in Linux 2.6 exists always,
|
||||||
|
* and it makes sense to always ignore it.
|
||||||
|
* Otherwise people can't reference their "real" root! */
|
||||||
|
if (strcmp(mountEntry->mnt_fsname, "rootfs") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (strcmp(name, mountEntry->mnt_dir) == 0
|
if (strcmp(name, mountEntry->mnt_dir) == 0
|
||||||
|| strcmp(name, mountEntry->mnt_fsname) == 0
|
|| strcmp(name, mountEntry->mnt_fsname) == 0
|
||||||
) { /* String match. */
|
) { /* String match. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */
|
/* Match the device. */
|
||||||
|
if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice)
|
||||||
break;
|
break;
|
||||||
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */
|
/* Match the directory's mount point. */
|
||||||
|
if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
endmntent(mountTable);
|
endmntent(mountTable);
|
||||||
|
@ -239,7 +239,7 @@ static void open_tty(const char *tty)
|
|||||||
// cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK);
|
// cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK);
|
||||||
// xchdir("/dev");
|
// xchdir("/dev");
|
||||||
// xstat(tty, &st);
|
// xstat(tty, &st);
|
||||||
// if ((st.st_mode & S_IFMT) != S_IFCHR)
|
// if (!S_ISCHR(st.st_mode))
|
||||||
// bb_error_msg_and_die("%s: not a character device", tty);
|
// bb_error_msg_and_die("%s: not a character device", tty);
|
||||||
|
|
||||||
if (tty[0] != '/')
|
if (tty[0] != '/')
|
||||||
|
@ -374,38 +374,28 @@ static int ask(const char *string, int def)
|
|||||||
*/
|
*/
|
||||||
static void check_mount(void)
|
static void check_mount(void)
|
||||||
{
|
{
|
||||||
FILE *f;
|
if (find_mount_point(device_name)) {
|
||||||
struct mntent *mnt;
|
int cont;
|
||||||
int cont;
|
#if ENABLE_FEATURE_MTAB_SUPPORT
|
||||||
int fd;
|
/*
|
||||||
//XXX:FIXME use find_mount_point()
|
* If the root is mounted read-only, then /etc/mtab is
|
||||||
f = setmntent(MOUNTED, "r");
|
* probably not correct; so we won't issue a warning based on
|
||||||
if (f == NULL)
|
* it.
|
||||||
return;
|
*/
|
||||||
while ((mnt = getmntent(f)) != NULL)
|
int fd = open(bb_path_mtab_file, O_RDWR);
|
||||||
if (strcmp(device_name, mnt->mnt_fsname) == 0)
|
|
||||||
break;
|
|
||||||
endmntent(f);
|
|
||||||
if (!mnt)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
if (fd < 0 && errno == EROFS)
|
||||||
* If the root is mounted read-only, then /etc/mtab is
|
return;
|
||||||
* probably not correct; so we won't issue a warning based on
|
close(fd);
|
||||||
* it.
|
#endif
|
||||||
*/
|
printf("%s is mounted. ", device_name);
|
||||||
fd = open(MOUNTED, O_RDWR);
|
cont = 0;
|
||||||
if (fd < 0 && errno == EROFS)
|
if (isatty(0) && isatty(1))
|
||||||
return;
|
cont = ask("Do you really want to continue", 0);
|
||||||
close(fd);
|
if (!cont) {
|
||||||
|
printf("Check aborted\n");
|
||||||
printf("%s is mounted. ", device_name);
|
exit(EXIT_SUCCESS);
|
||||||
cont = 0;
|
}
|
||||||
if (isatty(0) && isatty(1))
|
|
||||||
cont = ask("Do you really want to continue", 0);
|
|
||||||
if (!cont) {
|
|
||||||
printf("Check aborted\n");
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,7 +624,6 @@ static void setup_tables(void)
|
|||||||
int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
|
int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
struct mntent *mp;
|
|
||||||
unsigned opt;
|
unsigned opt;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
@ -683,11 +682,8 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
G.total_blocks = 65535;
|
G.total_blocks = 65535;
|
||||||
|
|
||||||
/* Check if it is mounted */
|
/* Check if it is mounted */
|
||||||
mp = find_mount_point(G.device_name, NULL);
|
if (find_mount_point(G.device_name))
|
||||||
if (mp && strcmp(G.device_name, mp->mnt_fsname) == 0)
|
bb_error_msg_and_die("can't format mounted filesystem");
|
||||||
bb_error_msg_and_die("%s is mounted on %s; "
|
|
||||||
"refusing to make a filesystem",
|
|
||||||
G.device_name, mp->mnt_dir);
|
|
||||||
|
|
||||||
xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
|
xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
|
||||||
if (fstat(dev_fd, &statbuf) < 0)
|
if (fstat(dev_fd, &statbuf) < 0)
|
||||||
|
@ -275,7 +275,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
)
|
)
|
||||||
bb_error_msg_and_die("will not try to make filesystem on full-disk device (use -I if wanted)");
|
bb_error_msg_and_die("will not try to make filesystem on full-disk device (use -I if wanted)");
|
||||||
// can't work on mounted filesystems
|
// can't work on mounted filesystems
|
||||||
if (find_mount_point(device_name, NULL))
|
if (find_mount_point(device_name))
|
||||||
bb_error_msg_and_die("can't format mounted filesystem");
|
bb_error_msg_and_die("can't format mounted filesystem");
|
||||||
#endif
|
#endif
|
||||||
// get true sector size
|
// get true sector size
|
||||||
|
Loading…
x
Reference in New Issue
Block a user