diff options
Diffstat (limited to 'libopkg')
-rw-r--r-- | libopkg/opkg_utils.c | 24 | ||||
-rw-r--r-- | libopkg/opkg_utils.h | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c index 6a827e0..fb27b40 100644 --- a/libopkg/opkg_utils.c +++ b/libopkg/opkg_utils.c @@ -26,16 +26,24 @@ void print_pkg_status(pkg_t * pkg, FILE * file); -int get_available_blocks(char * filesystem) +long unsigned int get_available_blocks(char * filesystem) { - struct statfs sfs; + struct statfs sfs; - if(statfs(filesystem, &sfs)){ - fprintf(stderr, "bad statfs\n"); - return 0; - } - /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */ - return ((sfs.f_bavail * sfs.f_bsize) / 1024); + if(statfs(filesystem, &sfs)){ + fprintf(stderr, "bad statfs\n"); + return 0; + } + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */ + + // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024) + // and here we try to avoid overflow. + if (sfs.f_bsize >= 1024) + return (sfs.f_bavail * (sfs.f_bsize / 1024)); + else if (sfs.f_bsize > 0) + return sfs.f_bavail / (1024 / sfs.f_bsize); + fprintf(stderr, "bad statfs f_bsize == 0\n"); + return 0; } char **read_raw_pkgs_from_file(const char *file_name) diff --git a/libopkg/opkg_utils.h b/libopkg/opkg_utils.h index c3e90a9..226c7d1 100644 --- a/libopkg/opkg_utils.h +++ b/libopkg/opkg_utils.h @@ -25,7 +25,7 @@ void push_error_list(struct errlist **errors,char * msg); void reverse_error_list(struct errlist **errors); void free_error_list(); -int get_available_blocks(char * filesystem); +long unsigned int get_available_blocks(char * filesystem); char **read_raw_pkgs_from_file(const char *file_name); char **read_raw_pkgs_from_stream(FILE *fp); char *trim_alloc(char * line); |