Use more correct integer types in diskspace checks
This adjusts type usage to match POSIX provided types from <sys/types.h> rather than assuming everything will fit in a long or unsigned long. Use fsblkcnt_t (unsigned) and blkcnt_t (signed) as appropriate. These are affected the same way off_t is on 32 bit platforms, where the types are extende to 64 bits if large file support is enabled. Because most numbers here are block counts, this isn't near as pressing as using a 32-bit variable for file sizes where anything over 2GiB can burn you; we likely can support files at least 512 but mainly 4096 times larger. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
b961ebe16f
commit
8ffa2b24a5
2 changed files with 19 additions and 15 deletions
|
@ -179,7 +179,7 @@ static int calculate_removed_size(alpm_handle_t *handle,
|
||||||
|
|
||||||
/* the addition of (divisor - 1) performs ceil() with integer division */
|
/* the addition of (divisor - 1) performs ceil() with integer division */
|
||||||
mp->blocks_needed -=
|
mp->blocks_needed -=
|
||||||
(st.st_size + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize;
|
(st.st_size + mp->fsp.f_bsize - 1) / mp->fsp.f_bsize;
|
||||||
mp->used |= USED_REMOVE;
|
mp->used |= USED_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ static int calculate_installed_size(alpm_handle_t *handle,
|
||||||
|
|
||||||
/* the addition of (divisor - 1) performs ceil() with integer division */
|
/* the addition of (divisor - 1) performs ceil() with integer division */
|
||||||
mp->blocks_needed +=
|
mp->blocks_needed +=
|
||||||
(file->size + mp->fsp.f_bsize - 1l) / mp->fsp.f_bsize;
|
(file->size + mp->fsp.f_bsize - 1) / mp->fsp.f_bsize;
|
||||||
mp->used |= USED_INSTALL;
|
mp->used |= USED_INSTALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,18 +301,19 @@ int _alpm_check_diskspace(alpm_handle_t *handle)
|
||||||
error = 1;
|
error = 1;
|
||||||
} else if(data->used & USED_INSTALL) {
|
} else if(data->used & USED_INSTALL) {
|
||||||
/* cushion is roughly min(5% capacity, 20MiB) */
|
/* cushion is roughly min(5% capacity, 20MiB) */
|
||||||
long fivepc = ((long)data->fsp.f_blocks / 20) + 1;
|
fsblkcnt_t fivepc = (data->fsp.f_blocks / 20) + 1;
|
||||||
long twentymb = (20 * 1024 * 1024 / (long)data->fsp.f_bsize) + 1;
|
fsblkcnt_t twentymb = (20 * 1024 * 1024 / data->fsp.f_bsize) + 1;
|
||||||
long cushion = fivepc < twentymb ? fivepc : twentymb;
|
fsblkcnt_t cushion = fivepc < twentymb ? fivepc : twentymb;
|
||||||
|
blkcnt_t needed = data->max_blocks_needed + cushion;
|
||||||
|
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "partition %s, needed %ld, cushion %ld, free %ld\n",
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
||||||
data->mount_dir, data->max_blocks_needed, cushion,
|
"partition %s, needed %jd, cushion %ju, free %ju\n",
|
||||||
(unsigned long)data->fsp.f_bfree);
|
data->mount_dir, (intmax_t)data->max_blocks_needed,
|
||||||
if(data->max_blocks_needed + cushion >= 0 &&
|
(uintmax_t)cushion, (uintmax_t)data->fsp.f_bfree);
|
||||||
(unsigned long)(data->max_blocks_needed + cushion) > data->fsp.f_bfree) {
|
if(needed >= 0 && (fsblkcnt_t)needed > data->fsp.f_bfree) {
|
||||||
_alpm_log(handle, ALPM_LOG_ERROR, _("Partition %s too full: %ld blocks needed, %ld blocks free\n"),
|
_alpm_log(handle, ALPM_LOG_ERROR,
|
||||||
data->mount_dir, data->max_blocks_needed + cushion,
|
_("Partition %s too full: %jd blocks needed, %jd blocks free\n"),
|
||||||
(unsigned long)data->fsp.f_bfree);
|
data->mount_dir, (intmax_t)needed, (uintmax_t)data->fsp.f_bfree);
|
||||||
error = 1;
|
error = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
#if defined(HAVE_SYS_STATVFS_H)
|
#if defined(HAVE_SYS_STATVFS_H)
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(HAVE_SYS_TYPES_H)
|
||||||
|
#include <sys/types.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
|
|
||||||
|
@ -39,8 +42,8 @@ typedef struct __alpm_mountpoint_t {
|
||||||
char *mount_dir;
|
char *mount_dir;
|
||||||
size_t mount_dir_len;
|
size_t mount_dir_len;
|
||||||
/* storage for additional disk usage calculations */
|
/* storage for additional disk usage calculations */
|
||||||
long blocks_needed;
|
blkcnt_t blocks_needed;
|
||||||
long max_blocks_needed;
|
blkcnt_t max_blocks_needed;
|
||||||
enum mount_used_level used;
|
enum mount_used_level used;
|
||||||
int read_only;
|
int read_only;
|
||||||
FSSTATSTYPE fsp;
|
FSSTATSTYPE fsp;
|
||||||
|
|
Loading…
Add table
Reference in a new issue