aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-01-27 23:41:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-01-27 23:41:34 +0000
commitb5c60fc7870a66d89de571e96596b0745edcd6d9 (patch)
tree29b3595303de8e526b9f64d3a2d2456f783efe2a
parentda42bd5bbe6fdda12133e7305b1a3e7cee506cc8 (diff)
downloadbusybox-w32-b5c60fc7870a66d89de571e96596b0745edcd6d9.tar.gz
busybox-w32-b5c60fc7870a66d89de571e96596b0745edcd6d9.tar.bz2
busybox-w32-b5c60fc7870a66d89de571e96596b0745edcd6d9.zip
mkswap, readahead: stop using fdlength, it is reported to be unreliable
-rw-r--r--libbb/xfuncs.c2
-rw-r--r--miscutils/readahead.c11
-rw-r--r--util-linux/mkswap.c6
3 files changed, 15 insertions, 4 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 25c36bd07..445e07717 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -475,6 +475,7 @@ void xsetuid(uid_t uid)
475} 475}
476 476
477// Return how long the file at fd is, if there's any way to determine it. 477// Return how long the file at fd is, if there's any way to determine it.
478#ifdef UNUSED
478off_t fdlength(int fd) 479off_t fdlength(int fd)
479{ 480{
480 off_t bottom = 0, top = 0, pos; 481 off_t bottom = 0, top = 0, pos;
@@ -513,6 +514,7 @@ off_t fdlength(int fd)
513 514
514 return pos + 1; 515 return pos + 1;
515} 516}
517#endif
516 518
517int bb_putchar(int ch) 519int bb_putchar(int ch)
518{ 520{
diff --git a/miscutils/readahead.c b/miscutils/readahead.c
index 7b375cfff..fb71ce85f 100644
--- a/miscutils/readahead.c
+++ b/miscutils/readahead.c
@@ -22,9 +22,16 @@ int readahead_main(int argc, char **argv)
22 while (*++argv) { 22 while (*++argv) {
23 int fd = open_or_warn(*argv, O_RDONLY); 23 int fd = open_or_warn(*argv, O_RDONLY);
24 if (fd >= 0) { 24 if (fd >= 0) {
25 int r = readahead(fd, 0, fdlength(fd)); 25 off_t len;
26 int r;
27
28 /* fdlength was reported to be unreliable - use seek */
29 len = xlseek(fd, 0, SEEK_END);
30 xlseek(fd, 0, SEEK_SET);
31 r = readahead(fd, 0, len);
26 close(fd); 32 close(fd);
27 if (r >= 0) continue; 33 if (r >= 0)
34 continue;
28 } 35 }
29 retval = EXIT_FAILURE; 36 retval = EXIT_FAILURE;
30 } 37 }
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 8e1fbc384..f047cce26 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -64,9 +64,11 @@ int mkswap_main(int argc, char **argv)
64 // Figure out how big the device is and announce our intentions. 64 // Figure out how big the device is and announce our intentions.
65 65
66 fd = xopen(argv[1], O_RDWR); 66 fd = xopen(argv[1], O_RDWR);
67 len = fdlength(fd); 67 /* fdlength was reported to be unreliable - use seek */
68 len = xlseek(fd, 0, SEEK_END);
69 xlseek(fd, 0, SEEK_SET);
68 pagesize = getpagesize(); 70 pagesize = getpagesize();
69 printf("Setting up swapspace version 1, size = %"OFF_FMT"d bytes\n", 71 printf("Setting up swapspace version 1, size = %"OFF_FMT"u bytes\n",
70 len - pagesize); 72 len - pagesize);
71 mkswap_selinux_setcontext(fd, argv[1]); 73 mkswap_selinux_setcontext(fd, argv[1]);
72 74