tools:acrn-crashlog: check blocks size instead of file size

What acrnprobe really care about is the storage capacity taken up from
emmc. This patch checks all the logs' blocks size instead of the file
size before collecting new logs.

Tracked-On: #1024
Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com>
Reviewed-by: Liu, Xiaojing <xiaojing.liu@intel.com>
Acked-by: Chen, Gang <gang.c.chen@intel.com>
This commit is contained in:
Liu, Xinwu 2019-04-19 10:25:10 +08:00 committed by ACRN System Integration
parent fa1216325b
commit 13d50c2296
3 changed files with 24 additions and 9 deletions

View File

@ -57,7 +57,8 @@ static int crashlog_check_space(void)
if (!space_available(crashlog->outdir, quota))
return -1;
if (dir_size(crashlog->outdir, crashlog->outdir_len, &dsize) == -1) {
if (dir_blocks_size(crashlog->outdir, crashlog->outdir_len,
&dsize) == -1) {
LOGE("failed to check outdir size\n");
return -1;
}

View File

@ -1085,11 +1085,12 @@ int find_file(const char *dir, size_t dlen, const char *target_file,
return -1;
}
static int _count_file_size(const char *pdir, struct dirent *dirp, void *arg)
static int _count_file_blocks_size(const char *pdir, struct dirent *dirp,
void *arg)
{
char file[PATH_MAX];
int res;
ssize_t fsize;
ssize_t fbsize;
if (dirp->d_type != DT_REG && dirp->d_type != DT_DIR)
return DIR_SUCCESS;
@ -1098,22 +1099,22 @@ static int _count_file_size(const char *pdir, struct dirent *dirp, void *arg)
if (s_not_expect(res, sizeof(file)))
return DIR_ERROR;
fsize = get_file_size(file);
if (fsize < 0)
fbsize = get_file_blocks_size(file);
if (fbsize < 0)
return DIR_ERROR;
*(size_t *)arg += fsize;
*(size_t *)arg += fbsize;
return DIR_SUCCESS;
}
int dir_size(const char *dir, size_t dlen, size_t *size)
int dir_blocks_size(const char *dir, size_t dlen, size_t *size)
{
if (!dir || !dlen || !size)
return -1;
*size = 0;
if (dir_recursive(dir, dlen, -1, _count_file_size,
if (dir_recursive(dir, dlen, -1, _count_file_blocks_size,
(void *)size) != DIR_SUCCESS) {
LOGE("failed to recursive dir (%s)\n", dir);
return -1;

View File

@ -75,6 +75,19 @@ static inline ssize_t get_file_size(const char *filepath)
return info.st_size;
}
static inline ssize_t get_file_blocks_size(const char *filepath)
{
struct stat info;
if (filepath == NULL)
return -ENOENT;
if (stat(filepath, &info) < 0)
return -errno;
return info.st_blocks * 512;
}
char *mm_get_line(struct mm_file_t *mfile, int line);
int mkdir_p(const char *path);
int remove_r(const char *dir);
@ -114,7 +127,7 @@ int dir_contains(const char *dir, const char *filename, size_t flen, int exact);
int lsdir(const char *dir, char *fullname[], int limit);
int find_file(const char *dir, size_t dlen, const char *target_file,
size_t tflen, int depth, char *path[], int limit);
int dir_size(const char *dir, size_t dlen, size_t *size);
int dir_blocks_size(const char *dir, size_t dlen, size_t *size);
int read_file(const char *path, unsigned long *size, void **data);
int is_ac_filefmt(const char *file_fmt);
int config_fmt_to_files(const char *file_fmt, char ***out);