From 8150805a45af09469ae5d0959ae239dd8103dc3b Mon Sep 17 00:00:00 2001 From: Yi Sun Date: Mon, 16 Nov 2009 18:28:20 -0800 Subject: [PATCH] installd: fix disk_free issue When the available free size of a partition is bigger than 2G, the disk_free function does not work correctly. Fixed it by the correct variable type. --- cmds/installd/commands.c | 31 ++++++++++++++++++++++--------- cmds/installd/installd.h | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c index 41f070ca2775..a35a96718cb6 100644 --- a/cmds/installd/commands.c +++ b/cmds/installd/commands.c @@ -108,14 +108,17 @@ int delete_cache(const char *pkgname) return delete_dir_contents(cachedir, 0, 0); } -static int disk_free() +static int disk_free(long *bsize, long *bavail) { struct statfs sfs; if (statfs(PKG_DIR_PREFIX, &sfs) == 0) { - return sfs.f_bavail * sfs.f_bsize; + *bsize = sfs.f_bsize; + *bavail = sfs.f_bavail; } else { + LOGE("Can not stat %s", PKG_DIR_PREFIX); return -1; } + return 0; } /* Try to ensure free_size bytes of storage are available. @@ -125,18 +128,19 @@ static int disk_free() * also require that apps constantly modify file metadata even * when just reading from the cache, which is pretty awful. */ -int free_cache(int free_size) +int free_cache(size_t free_size) { const char *name; int dfd, subfd; DIR *d; struct dirent *de; - int avail; + long bsz, bavail; + unsigned long long avail; - avail = disk_free(); - if (avail < 0) return -1; + if (disk_free(&bsz, &bavail) < 0) + return -1; + avail = bsz * bavail; - LOGI("free_cache(%d) avail %d\n", free_size, avail); if (avail >= free_size) return 0; d = opendir(PKG_DIR_PREFIX); @@ -161,13 +165,22 @@ int free_cache(int free_size) delete_dir_contents_fd(subfd, "cache"); close(subfd); - - avail = disk_free(); + if (disk_free(&bsz, &bavail) < 0) { + /* + * let it continue and hope we could success next time. + * maybe :-) + */ + LOGI("Can not get the fs size"); + continue; + } + avail = bsz * bavail; if (avail >= free_size) { + LOGI("Get more space"); closedir(d); return 0; } } + LOGI("Can not find free space %d", free_size); closedir(d); /* Fail case - not possible to free space */ diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h index cfcdb98f7e65..86c5ede19810 100644 --- a/cmds/installd/installd.h +++ b/cmds/installd/installd.h @@ -99,6 +99,6 @@ int rm_dex(const char *path); int protect(char *pkgname, gid_t gid); int get_size(const char *pkgname, const char *apkpath, const char *fwdlock_apkpath, int *codesize, int *datasize, int *cachesize); -int free_cache(int free_size); +int free_cache(size_t free_size); int dexopt(const char *apk_path, uid_t uid, int is_public); int movefiles(); -- 2.11.0