From 78686294ebae2f064c2655741827488fb43c5857 Mon Sep 17 00:00:00 2001 From: "Koushik K. Dutta" Date: Thu, 25 Mar 2010 17:58:45 -0700 Subject: [PATCH] add free space check --- nandroid.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nandroid.c b/nandroid.c index 8ba1cd5..7201438 100644 --- a/nandroid.c +++ b/nandroid.c @@ -37,6 +37,8 @@ #include "../../external/yaffs2/yaffs2/utils/mkyaffs2image.h" #include "../../external/yaffs2/yaffs2/utils/unyaffs.h" +#include + #include "extendedcommands.h" #include "nandroid.h" @@ -102,11 +104,18 @@ int nandroid_backup(char* backup_path) if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); + int ret; + struct statfs s; + if (0 != (ret = statfs("/sdcard", &s))) + return print_and_error("Unable to stat /sdcard\n"); + int sdcard_free = s.f_bfree * s.f_bsize; + if (sdcard_free < 150000000) + return print_and_error("There is not enough free space on the SD Card! At least 150MB is required to create a backup.\n"); + char tmp[PATH_MAX]; sprintf(tmp, "mkdir -p %s", backup_path); __system(tmp); - int ret; ui_print("Backing up boot...\n"); sprintf(tmp, "%s/%s", backup_path, "boot.img"); ret = dump_image("boot", tmp, NULL);