Commit 1f4067c9 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Use VFIL_fsinfo in STV_FileSize, and drop the old implementation

parent 22ad1c95
......@@ -54,6 +54,7 @@
#include "storage/storage.h"
#include "vnum.h"
#include "vfil.h"
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
......@@ -132,38 +133,6 @@ STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx)
return (retval);
}
/*--------------------------------------------------------------------
* Figure out how much space is in a filesystem
*/
static uintmax_t
stv_fsspace(int fd, unsigned *bs)
{
uintmax_t bsize, bavail;
#if defined(HAVE_SYS_STATVFS_H)
struct statvfs fsst;
AZ(fstatvfs(fd, &fsst));
bsize = fsst.f_frsize;
bavail = fsst.f_bavail;
#elif defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H)
struct statfs fsst;
AZ(fstatfs(sc->fd, &fsst));
bsize = fsst.f_bsize;
bavail = fsst.f_bavail;
#else
#error no struct statfs / struct statvfs
#endif
/* We use units of the larger of filesystem blocksize and pagesize */
if (*bs < bsize)
*bs = bsize;
XXXAZ(*bs % bsize);
return (bsize * bavail);
}
/*--------------------------------------------------------------------
* Decide file size.
*
......@@ -183,12 +152,16 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
off_t o;
struct stat st;
AN(granularity);
AN(ctx);
AZ(fstat(fd, &st));
xxxassert(S_ISREG(st.st_mode));
bs = *granularity;
fssize = stv_fsspace(fd, &bs);
XXXAZ(bs % *granularity);
AZ(VFIL_fsinfo(fd, &bs, &fssize, NULL));
/* Increase granularity if it is lower than the filesystem block size */
if (*granularity < bs)
*granularity = bs;
if ((size == NULL || *size == '\0') && st.st_size != 0) {
/*
......@@ -235,9 +208,8 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
l = INT32_MAX;
}
/* round down to multiple of filesystem blocksize or pagesize */
l -= (l % bs);
/* Round down */
l -= (l % *granularity);
*granularity = bs;
return(l);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment