WIP - merge from Pandora's port

This commit is contained in:
Dimitris Panokostas 2017-09-18 10:41:47 +02:00
parent 546562cff3
commit a2850730e0
309 changed files with 239342 additions and 114388 deletions

View file

@ -24,6 +24,9 @@
#if HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif
#ifdef STAT_STATVFS
#include <sys/statvfs.h>
#endif
#include "fsusage.h"
@ -46,12 +49,94 @@ static long adjust_blocks(long blocks, int fromsize, int tosize)
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize);
}
#ifdef WINDOWS
#include "od-win32/posixemu.h"
#include <windows.h>
int get_fs_usage (const TCHAR *path, const TCHAR *disk, struct fs_usage *fsp)
{
TCHAR buf2[MAX_DPATH];
ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes, TotalNumberOfFreeBytes;
if (!GetFullPathName (path, sizeof buf2 / sizeof (TCHAR), buf2, NULL)) {
write_log (_T("GetFullPathName('%s') failed err=%d\n"), path, GetLastError ());
return -1;
}
if (!_tcsncmp (buf2, _T("\\\\"), 2)) {
TCHAR *p;
_tcscat (buf2, _T("\\"));
p = _tcschr (buf2 + 2, '\\');
if (!p)
return -1;
p = _tcschr (p + 1, '\\');
if (!p)
return -1;
p[1] = 0;
} else {
buf2[3] = 0;
}
if (!GetDiskFreeSpaceEx (buf2, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes)) {
write_log (_T("GetDiskFreeSpaceEx('%s') failed err=%d\n"), buf2, GetLastError ());
return -1;
}
fsp->total = TotalNumberOfBytes.QuadPart;
fsp->avail = TotalNumberOfFreeBytes.QuadPart;
return 0;
}
#else /* ! _WIN32 */
int statfs ();
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#if HAVE_SYS_MOUNT_H
# include <sys/mount.h>
#endif
#if HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif
#if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */
# include <sys/fs/s5param.h>
#endif
#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
# include <sys/filsys.h> /* SVR2 */
#endif
#if HAVE_FCNTL_H
# include <fcntl.h>
#endif
#if HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif
#if HAVE_DUSTAT_H /* AIX PS/2 */
# include <sys/dustat.h>
#endif
#if HAVE_SYS_STATVFS_H /* SVR4 */
# include <sys/statvfs.h>
int statvfs ();
#endif
/* Read LEN bytes at PTR from descriptor DESC, retrying if interrupted.
Return the actual number of bytes read, zero for EOF, or negative
for an error. */
int safe_read (int desc, TCHAR *ptr, int len)
static int safe_read (int desc, TCHAR *ptr, int len)
{
int n_chars;
@ -215,14 +300,13 @@ int get_fs_usage (const TCHAR *path, const TCHAR *disk, struct fs_usage *fsp)
#if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS)
/* !Ultrix && !SVR2 */
fsp->fsu_blocks = CONVERT_BLOCKS (fsd.f_blocks);
fsp->fsu_bfree = CONVERT_BLOCKS (fsd.f_bfree);
fsp->fsu_bavail = CONVERT_BLOCKS (fsd.f_bavail);
fsp->fsu_files = fsd.f_files;
fsp->fsu_ffree = fsd.f_ffree;
fsp->total = (uae_s64)fsd.f_bsize * (uae_s64)fsd.f_blocks;
fsp->avail = (uae_s64)fsd.f_bsize * (uae_s64)fsd.f_bavail;
#endif /* not STAT_STATFS2_FS_DATA && not STAT_READ_FILSYS */
return 0;
}
#endif
#endif /* ! _WIN32 */