diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-05 04:50:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-05 04:50:36 +0200 |
commit | 09e63bb81f12707d31c8c4570931af0196b53a46 (patch) | |
tree | 1b550ca677e6cd4fdd70eabda1fd402684b8ec7d | |
parent | 9b1b62adc4e4c1e80d9f72180c6b7b1eaef9f95a (diff) | |
download | busybox-w32-09e63bb81f12707d31c8c4570931af0196b53a46.tar.gz busybox-w32-09e63bb81f12707d31c8c4570931af0196b53a46.tar.bz2 busybox-w32-09e63bb81f12707d31c8c4570931af0196b53a46.zip |
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>
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 4 | ||||
-rw-r--r-- | coreutils/df.c | 7 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/find_mount_point.c | 22 | ||||
-rw-r--r-- | loginutils/getty.c | 2 | ||||
-rw-r--r-- | util-linux/fsck_minix.c | 54 | ||||
-rw-r--r-- | util-linux/mkfs_minix.c | 8 | ||||
-rw-r--r-- | util-linux/mkfs_vfat.c | 2 |
8 files changed, 47 insertions, 54 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index 444770d27..123d1de74 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c | |||
@@ -21,7 +21,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) | |||
21 | /* Check if the file already exists */ | 21 | /* Check if the file already exists */ |
22 | if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { | 22 | if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) { |
23 | /* Remove the entry if it exists */ | 23 | /* Remove the entry if it exists */ |
24 | if (((file_header->mode & S_IFMT) != S_IFDIR) | 24 | if ((!S_ISDIR(file_header->mode)) |
25 | && (unlink(file_header->name) == -1) | 25 | && (unlink(file_header->name) == -1) |
26 | && (errno != ENOENT) | 26 | && (errno != ENOENT) |
27 | ) { | 27 | ) { |
@@ -132,7 +132,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) | |||
132 | #endif | 132 | #endif |
133 | lchown(file_header->name, file_header->uid, file_header->gid); | 133 | lchown(file_header->name, file_header->uid, file_header->gid); |
134 | } | 134 | } |
135 | if ((file_header->mode & S_IFMT) != S_IFLNK) { | 135 | if (S_ISLNK(file_header->mode)) { |
136 | /* uclibc has no lchmod, glibc is even stranger - | 136 | /* uclibc has no lchmod, glibc is even stranger - |
137 | * it has lchmod which seems to do nothing! | 137 | * it has lchmod which seems to do nothing! |
138 | * so we use chmod... */ | 138 | * so we use chmod... */ |
diff --git a/coreutils/df.c b/coreutils/df.c index 34b015090..d95aff39d 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -44,7 +44,6 @@ int df_main(int argc, char **argv) | |||
44 | FILE *mount_table; | 44 | FILE *mount_table; |
45 | struct mntent *mount_entry; | 45 | struct mntent *mount_entry; |
46 | struct statfs s; | 46 | struct statfs s; |
47 | static const char ignored_mounts[] ALIGN1 = "rootfs\0"; | ||
48 | 47 | ||
49 | enum { | 48 | enum { |
50 | OPT_KILO = (1 << 0), | 49 | OPT_KILO = (1 << 0), |
@@ -120,7 +119,7 @@ int df_main(int argc, char **argv) | |||
120 | mount_point = *argv++; | 119 | mount_point = *argv++; |
121 | if (!mount_point) | 120 | if (!mount_point) |
122 | break; | 121 | break; |
123 | mount_entry = find_mount_point(mount_point, bb_path_mtab_file); | 122 | mount_entry = find_mount_point(mount_point); |
124 | if (!mount_entry) { | 123 | if (!mount_entry) { |
125 | bb_error_msg("%s: can't find mount point", mount_point); | 124 | bb_error_msg("%s: can't find mount point", mount_point); |
126 | set_error: | 125 | set_error: |
@@ -154,8 +153,8 @@ int df_main(int argc, char **argv) | |||
154 | ) / (blocks_used + s.f_bavail); | 153 | ) / (blocks_used + s.f_bavail); |
155 | } | 154 | } |
156 | 155 | ||
157 | /* GNU coreutils 6.10 skip certain mounts, try to be compatible. */ | 156 | /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */ |
158 | if (index_in_strings(device, ignored_mounts) != -1) | 157 | if (strcmp(device, "rootfs") == 0) |
159 | continue; | 158 | continue; |
160 | 159 | ||
161 | #ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY | 160 | #ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY |
diff --git a/include/libbb.h b/include/libbb.h index 835beb20c..6f4c547e5 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -986,7 +986,7 @@ extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC; | |||
986 | 986 | ||
987 | #ifdef HAVE_MNTENT_H | 987 | #ifdef HAVE_MNTENT_H |
988 | extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC; | 988 | extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC; |
989 | extern struct mntent *find_mount_point(const char *name, const char *table) FAST_FUNC; | 989 | extern struct mntent *find_mount_point(const char *name) FAST_FUNC; |
990 | #endif | 990 | #endif |
991 | extern void erase_mtab(const char * name) FAST_FUNC; | 991 | extern void erase_mtab(const char * name) FAST_FUNC; |
992 | extern unsigned int tty_baud_to_value(speed_t speed) FAST_FUNC; | 992 | extern unsigned int tty_baud_to_value(speed_t speed) FAST_FUNC; |
diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c index 4cd6b1618..12b2cfce4 100644 --- a/libbb/find_mount_point.c +++ b/libbb/find_mount_point.c | |||
@@ -17,7 +17,7 @@ | |||
17 | * Given any other file (or directory), find the mount table entry for its | 17 | * Given any other file (or directory), find the mount table entry for its |
18 | * filesystem. | 18 | * filesystem. |
19 | */ | 19 | */ |
20 | struct mntent* FAST_FUNC find_mount_point(const char *name, const char *table) | 20 | struct mntent* FAST_FUNC find_mount_point(const char *name) |
21 | { | 21 | { |
22 | struct stat s; | 22 | struct stat s; |
23 | dev_t mountDevice; | 23 | dev_t mountDevice; |
@@ -25,27 +25,35 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, const char *table) | |||
25 | struct mntent *mountEntry; | 25 | struct mntent *mountEntry; |
26 | 26 | ||
27 | if (stat(name, &s) != 0) | 27 | if (stat(name, &s) != 0) |
28 | return 0; | 28 | return NULL; |
29 | 29 | ||
30 | if ((s.st_mode & S_IFMT) == S_IFBLK) | 30 | if (S_ISBLK(s.st_mode)) |
31 | mountDevice = s.st_rdev; | 31 | mountDevice = s.st_rdev; |
32 | else | 32 | else |
33 | mountDevice = s.st_dev; | 33 | mountDevice = s.st_dev; |
34 | 34 | ||
35 | 35 | ||
36 | mountTable = setmntent(table ? table : bb_path_mtab_file, "r"); | 36 | mountTable = setmntent(bb_path_mtab_file, "r"); |
37 | if (!mountTable) | 37 | if (!mountTable) |
38 | return 0; | 38 | return 0; |
39 | 39 | ||
40 | while ((mountEntry = getmntent(mountTable)) != 0) { | 40 | while ((mountEntry = getmntent(mountTable)) != NULL) { |
41 | /* rootfs mount in Linux 2.6 exists always, | ||
42 | * and it makes sense to always ignore it. | ||
43 | * Otherwise people can't reference their "real" root! */ | ||
44 | if (strcmp(mountEntry->mnt_fsname, "rootfs") == 0) | ||
45 | continue; | ||
46 | |||
41 | if (strcmp(name, mountEntry->mnt_dir) == 0 | 47 | if (strcmp(name, mountEntry->mnt_dir) == 0 |
42 | || strcmp(name, mountEntry->mnt_fsname) == 0 | 48 | || strcmp(name, mountEntry->mnt_fsname) == 0 |
43 | ) { /* String match. */ | 49 | ) { /* String match. */ |
44 | break; | 50 | break; |
45 | } | 51 | } |
46 | if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ | 52 | /* Match the device. */ |
53 | if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) | ||
47 | break; | 54 | break; |
48 | if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ | 55 | /* Match the directory's mount point. */ |
56 | if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) | ||
49 | break; | 57 | break; |
50 | } | 58 | } |
51 | endmntent(mountTable); | 59 | endmntent(mountTable); |
diff --git a/loginutils/getty.c b/loginutils/getty.c index 34b09cecc..838adf2e7 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -239,7 +239,7 @@ static void open_tty(const char *tty) | |||
239 | // cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK); | 239 | // cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK); |
240 | // xchdir("/dev"); | 240 | // xchdir("/dev"); |
241 | // xstat(tty, &st); | 241 | // xstat(tty, &st); |
242 | // if ((st.st_mode & S_IFMT) != S_IFCHR) | 242 | // if (!S_ISCHR(st.st_mode)) |
243 | // bb_error_msg_and_die("%s: not a character device", tty); | 243 | // bb_error_msg_and_die("%s: not a character device", tty); |
244 | 244 | ||
245 | if (tty[0] != '/') | 245 | if (tty[0] != '/') |
diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index 0c33c1b02..ca0b17efe 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c | |||
@@ -374,38 +374,28 @@ static int ask(const char *string, int def) | |||
374 | */ | 374 | */ |
375 | static void check_mount(void) | 375 | static void check_mount(void) |
376 | { | 376 | { |
377 | FILE *f; | 377 | if (find_mount_point(device_name)) { |
378 | struct mntent *mnt; | 378 | int cont; |
379 | int cont; | 379 | #if ENABLE_FEATURE_MTAB_SUPPORT |
380 | int fd; | 380 | /* |
381 | //XXX:FIXME use find_mount_point() | 381 | * If the root is mounted read-only, then /etc/mtab is |
382 | f = setmntent(MOUNTED, "r"); | 382 | * probably not correct; so we won't issue a warning based on |
383 | if (f == NULL) | 383 | * it. |
384 | return; | 384 | */ |
385 | while ((mnt = getmntent(f)) != NULL) | 385 | int fd = open(bb_path_mtab_file, O_RDWR); |
386 | if (strcmp(device_name, mnt->mnt_fsname) == 0) | 386 | |
387 | break; | 387 | if (fd < 0 && errno == EROFS) |
388 | endmntent(f); | 388 | return; |
389 | if (!mnt) | 389 | close(fd); |
390 | return; | 390 | #endif |
391 | 391 | printf("%s is mounted. ", device_name); | |
392 | /* | 392 | cont = 0; |
393 | * If the root is mounted read-only, then /etc/mtab is | 393 | if (isatty(0) && isatty(1)) |
394 | * probably not correct; so we won't issue a warning based on | 394 | cont = ask("Do you really want to continue", 0); |
395 | * it. | 395 | if (!cont) { |
396 | */ | 396 | printf("Check aborted\n"); |
397 | fd = open(MOUNTED, O_RDWR); | 397 | exit(EXIT_SUCCESS); |
398 | if (fd < 0 && errno == EROFS) | 398 | } |
399 | return; | ||
400 | close(fd); | ||
401 | |||
402 | printf("%s is mounted. ", device_name); | ||
403 | cont = 0; | ||
404 | if (isatty(0) && isatty(1)) | ||
405 | cont = ask("Do you really want to continue", 0); | ||
406 | if (!cont) { | ||
407 | printf("Check aborted\n"); | ||
408 | exit(EXIT_SUCCESS); | ||
409 | } | 399 | } |
410 | } | 400 | } |
411 | 401 | ||
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 2666132f9..18512a395 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c | |||
@@ -624,7 +624,6 @@ static void setup_tables(void) | |||
624 | int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 624 | int mkfs_minix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
625 | int mkfs_minix_main(int argc UNUSED_PARAM, char **argv) | 625 | int mkfs_minix_main(int argc UNUSED_PARAM, char **argv) |
626 | { | 626 | { |
627 | struct mntent *mp; | ||
628 | unsigned opt; | 627 | unsigned opt; |
629 | char *tmp; | 628 | char *tmp; |
630 | struct stat statbuf; | 629 | struct stat statbuf; |
@@ -683,11 +682,8 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv) | |||
683 | G.total_blocks = 65535; | 682 | G.total_blocks = 65535; |
684 | 683 | ||
685 | /* Check if it is mounted */ | 684 | /* Check if it is mounted */ |
686 | mp = find_mount_point(G.device_name, NULL); | 685 | if (find_mount_point(G.device_name)) |
687 | if (mp && strcmp(G.device_name, mp->mnt_fsname) == 0) | 686 | bb_error_msg_and_die("can't format mounted filesystem"); |
688 | bb_error_msg_and_die("%s is mounted on %s; " | ||
689 | "refusing to make a filesystem", | ||
690 | G.device_name, mp->mnt_dir); | ||
691 | 687 | ||
692 | xmove_fd(xopen(G.device_name, O_RDWR), dev_fd); | 688 | xmove_fd(xopen(G.device_name, O_RDWR), dev_fd); |
693 | if (fstat(dev_fd, &statbuf) < 0) | 689 | if (fstat(dev_fd, &statbuf) < 0) |
diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index 98a089502..8c6078d7b 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c | |||
@@ -275,7 +275,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) | |||
275 | ) | 275 | ) |
276 | bb_error_msg_and_die("will not try to make filesystem on full-disk device (use -I if wanted)"); | 276 | bb_error_msg_and_die("will not try to make filesystem on full-disk device (use -I if wanted)"); |
277 | // can't work on mounted filesystems | 277 | // can't work on mounted filesystems |
278 | if (find_mount_point(device_name, NULL)) | 278 | if (find_mount_point(device_name)) |
279 | bb_error_msg_and_die("can't format mounted filesystem"); | 279 | bb_error_msg_and_die("can't format mounted filesystem"); |
280 | #endif | 280 | #endif |
281 | // get true sector size | 281 | // get true sector size |