Ticket #2338: use uintmax_t for file system infomation
... to avoid integer overflow in huge file systems. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
bbbb918338
Коммит
ac23f3277b
@ -29,6 +29,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <inttypes.h> /* PRIuMAX */
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/unixcompat.h"
|
||||
@ -142,27 +143,29 @@ info_show_info (struct WInfo *info)
|
||||
|
||||
case 16:
|
||||
widget_move (&info->widget, 16, 3);
|
||||
if (myfs_stats.nfree > 0 || myfs_stats.nodes > 0)
|
||||
tty_printf (_("Free nodes: %ld (%ld%%) of %ld"),
|
||||
(size_t) myfs_stats.nfree,
|
||||
myfs_stats.nodes != 0
|
||||
? 100 * (size_t) myfs_stats.nfree / (size_t) myfs_stats.nodes : 0,
|
||||
(size_t) myfs_stats.nodes);
|
||||
else
|
||||
if (myfs_stats.nfree == 0 && myfs_stats.nodes == 0)
|
||||
tty_print_string (_("No node information"));
|
||||
else
|
||||
tty_printf ("%s %" PRIuMAX "/%" PRIuMAX " (%d%%)",
|
||||
_("Free nodes:"),
|
||||
myfs_stats.nfree, myfs_stats.nodes,
|
||||
myfs_stats.nodes == 0 ? 0 :
|
||||
(int) (100 * (long double) myfs_stats.nfree / myfs_stats.nodes));
|
||||
|
||||
case 15:
|
||||
widget_move (&info->widget, 15, 3);
|
||||
if (myfs_stats.avail > 0 || myfs_stats.total > 0)
|
||||
if (myfs_stats.avail == 0 && myfs_stats.total == 0)
|
||||
tty_print_string (_("No space information"));
|
||||
else
|
||||
{
|
||||
char buffer1[6], buffer2[6];
|
||||
|
||||
size_trunc_len (buffer1, 5, myfs_stats.avail, 1, panels_options.kilobyte_si);
|
||||
size_trunc_len (buffer2, 5, myfs_stats.total, 1, panels_options.kilobyte_si);
|
||||
tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
|
||||
(int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0, buffer2);
|
||||
tty_printf (_("Free space: %s/%s (%d%%)"), buffer1, buffer2,
|
||||
myfs_stats.total == 0 ? 0 :
|
||||
(int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
|
||||
}
|
||||
else
|
||||
tty_print_string (_("No space information"));
|
||||
|
||||
case 14:
|
||||
widget_move (&info->widget, 14, 3);
|
||||
@ -216,7 +219,7 @@ info_show_info (struct WInfo *info)
|
||||
tty_printf (_("Size: %s"), buffer);
|
||||
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
||||
tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
|
||||
(unsigned long int) st.st_blocks), (long int) st.st_blocks);
|
||||
(unsigned long) st.st_blocks), (unsigned long) st.st_blocks);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -159,8 +159,6 @@ struct fs_usage
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static int get_fs_usage (char *path, struct fs_usage *fsp);
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
static struct mount_entry *mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
@ -931,10 +929,10 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
myfs_stats->avail = getuid ()? fs_use.fsu_bavail / 2 : fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
myfs_stats->avail = (uintmax_t) (getuid () ? fs_use.fsu_bavail : fs_use.fsu_bfree) / 2;
|
||||
myfs_stats->total = (uintmax_t) fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = (uintmax_t) fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = (uintmax_t) fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
@ -959,10 +957,10 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
|
||||
myfs_stats->avail = fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
myfs_stats->avail = (uintmax_t) fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = (uintmax_t) fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = (uintmax_t) fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = (uintmax_t) fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef MC__MOUNTLIST_H
|
||||
#define MC__MOUNTLIST_H
|
||||
|
||||
#include <stdint.h> /* uintmax_t */
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
@ -22,20 +24,20 @@ struct my_statfs
|
||||
char *typename;
|
||||
const char *mpoint;
|
||||
const char *device;
|
||||
int avail;
|
||||
int total;
|
||||
int nfree;
|
||||
int nodes;
|
||||
uintmax_t avail;
|
||||
uintmax_t total;
|
||||
uintmax_t nfree;
|
||||
uintmax_t nodes;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
void init_my_statfs (void);
|
||||
void my_statfs (struct my_statfs *myfs_stats, const char *path);
|
||||
void free_my_statfs (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC__MOUNTLIST_H */
|
||||
|
@ -1048,7 +1048,7 @@ show_free_space (WPanel * panel)
|
||||
my_statfs (&myfs_stats, rpath);
|
||||
}
|
||||
|
||||
if (myfs_stats.avail > 0 || myfs_stats.total > 0)
|
||||
if (myfs_stats.avail != 0 || myfs_stats.total != 0)
|
||||
{
|
||||
char buffer1[6], buffer2[6], tmp[BUF_SMALL];
|
||||
size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1,
|
||||
@ -1056,8 +1056,8 @@ show_free_space (WPanel * panel)
|
||||
size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1,
|
||||
panels_options.kilobyte_si);
|
||||
g_snprintf (tmp, sizeof (tmp), " %s/%s (%d%%) ", buffer1, buffer2,
|
||||
myfs_stats.total >
|
||||
0 ? (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0);
|
||||
myfs_stats.total == 0 ? 0 :
|
||||
(int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
|
||||
widget_move (&panel->widget, panel->widget.lines - 1,
|
||||
panel->widget.cols - 2 - (int) strlen (tmp));
|
||||
tty_setcolor (NORMAL_COLOR);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user