summaryrefslogtreecommitdiff
path: root/util-linux/swaponoff.c
diff options
context:
space:
mode:
authorEric Andersen2002-11-03 00:25:23 +0000
committerEric Andersen2002-11-03 00:25:23 +0000
commit97b141ac69b0bd548531f828dc7fdc892b8dd944 (patch)
treed00f6259f19cede37e3f7451cb483fb7d7785ed7 /util-linux/swaponoff.c
parentbf1cc8b1b7a218a4c2f4bfb23ea44c74b65ebbf6 (diff)
downloadbusybox-97b141ac69b0bd548531f828dc7fdc892b8dd944.zip
busybox-97b141ac69b0bd548531f828dc7fdc892b8dd944.tar.gz
Test for holes in swapfiles
-Erik
Diffstat (limited to 'util-linux/swaponoff.c')
-rw-r--r--util-linux/swaponoff.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index a57dfe4..918a5bc 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -48,6 +48,18 @@ static const int SWAPOFF_APP = 1;
static int swap_enable_disable(const char *device)
{
int status;
+ struct stat st;
+
+ if (stat(device, &st) < 0) {
+ perror_msg_and_die("cannot stat %s");
+ }
+
+ /* test for holes */
+ if (S_ISREG(st.st_mode)) {
+ if (st.st_blocks * 512 < st.st_size) {
+ error_msg_and_die("swap file has holes");
+ }
+ }
if (whichApp == SWAPON_APP)
status = swapon(device, 0);