Commit 13af4891 authored by Alexandre Julliard's avatar Alexandre Julliard

Use statvfs instead of statfs, and provide a default implementation in

libwine_port if necessary.
parent 68cc5433
......@@ -1056,6 +1056,7 @@ AC_CHECK_FUNCS(\
snprintf \
spawnvp \
statfs \
statvfs \
strcasecmp \
strerror \
strncasecmp \
......@@ -1137,6 +1138,7 @@ AC_CHECK_HEADERS(\
sys/socket.h \
sys/sockio.h \
sys/statfs.h \
sys/statvfs.h \
sys/strtio.h \
sys/syscall.h \
sys/sysctl.h \
......@@ -1236,7 +1238,7 @@ dnl **** Check for types ****
AC_C_CONST
AC_C_INLINE
AC_CHECK_TYPES([mode_t, off_t, pid_t, size_t, ssize_t, long long])
AC_CHECK_TYPES([mode_t, off_t, pid_t, size_t, ssize_t, long long, fsblkcnt_t, fsfilcnt_t])
AC_CACHE_CHECK([whether linux/input.h is for real],
wine_cv_linux_input_h,
......@@ -1384,7 +1386,7 @@ fi
dnl **** FIXME: what about mixed cases, where we need two of them? ***
dnl Check for statfs members
AC_CHECK_MEMBERS([struct statfs.f_bfree, struct statfs.f_bavail],,,
AC_CHECK_MEMBERS([struct statfs.f_bfree, struct statfs.f_bavail, struct statfs.f_frsize, struct statfs.f_ffree, struct statfs.f_favail],,,
[#include <sys/types.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
......@@ -1401,6 +1403,11 @@ AC_CHECK_MEMBERS([struct statfs.f_bfree, struct statfs.f_bavail],,,
# endif
#endif])
AC_CHECK_MEMBERS([struct statvfs.f_blocks],,,
[#ifdef HAVE_SYS_STATVFS_H
#include <sys/statvfs.h>
#endif])
dnl Check for socket structure members
AC_CHECK_MEMBERS([struct msghdr.msg_accrights, struct sockaddr.sa_len, struct sockaddr_un.sun_len],,,
[#include <sys/types.h>
......
......@@ -43,6 +43,9 @@
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYS_STATVFS_H
# include <sys/statvfs.h>
#endif
#ifdef STATFS_DEFINED_BY_SYS_VFS
# include <sys/vfs.h>
#else
......@@ -1370,7 +1373,7 @@ BOOL WINAPI DefineDosDeviceW(DWORD flags,LPCWSTR devname,LPCWSTR targetpath)
static int DRIVE_GetFreeSpace( int drive, PULARGE_INTEGER size,
PULARGE_INTEGER available )
{
struct statfs info;
struct statvfs info;
if (!DRIVE_IsValid(drive))
{
......@@ -1378,32 +1381,18 @@ static int DRIVE_GetFreeSpace( int drive, PULARGE_INTEGER size,
return 0;
}
/* FIXME: add autoconf check for this */
#if defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
if (statfs( DOSDrives[drive].root, &info, 0, 0) < 0)
#else
if (statfs( DOSDrives[drive].root, &info) < 0)
#endif
if (statvfs( DOSDrives[drive].root, &info ) < 0)
{
FILE_SetDosError();
WARN("cannot do statfs(%s)\n", DOSDrives[drive].root);
WARN("cannot do statvfs(%s)\n", DOSDrives[drive].root);
return 0;
}
size->QuadPart = RtlEnlargedUnsignedMultiply( info.f_bsize, info.f_blocks );
#ifdef HAVE_STRUCT_STATFS_F_BAVAIL
available->QuadPart = RtlEnlargedUnsignedMultiply( info.f_bavail, info.f_bsize );
#else
# ifdef HAVE_STRUCT_STATFS_F_BFREE
available->QuadPart = RtlEnlargedUnsignedMultiply( info.f_bfree, info.f_bsize );
# else
# error "statfs has no bfree/bavail member!"
# endif
#endif
size->QuadPart = RtlEnlargedUnsignedMultiply( info.f_frsize, info.f_blocks );
if (DOSDrives[drive].type == DRIVE_CDROM)
{ /* ALWAYS 0, even if no real CD-ROM mounted there !! */
available->QuadPart = 0;
}
available->QuadPart = 0; /* ALWAYS 0, even if no real CD-ROM mounted there !! */
else
available->QuadPart = RtlEnlargedUnsignedMultiply( info.f_frsize, info.f_bavail );
return 1;
}
......
......@@ -119,6 +119,12 @@
/* Define to 1 if you have the <freetype/tttables.h> header file. */
#undef HAVE_FREETYPE_TTTABLES_H
/* Define to 1 if the system has the type `fsblkcnt_t'. */
#undef HAVE_FSBLKCNT_T
/* Define to 1 if the system has the type `fsfilcnt_t'. */
#undef HAVE_FSFILCNT_T
/* Define to 1 if you have the <ft2build.h> header file. */
#undef HAVE_FT2BUILD_H
......@@ -515,6 +521,9 @@
/* Define to 1 if you have the `statfs' function. */
#undef HAVE_STATFS
/* Define to 1 if you have the `statvfs' function. */
#undef HAVE_STATVFS
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
......@@ -554,6 +563,18 @@
/* Define to 1 if `f_bfree' is member of `struct statfs'. */
#undef HAVE_STRUCT_STATFS_F_BFREE
/* Define to 1 if `f_favail' is member of `struct statfs'. */
#undef HAVE_STRUCT_STATFS_F_FAVAIL
/* Define to 1 if `f_ffree' is member of `struct statfs'. */
#undef HAVE_STRUCT_STATFS_F_FFREE
/* Define to 1 if `f_frsize' is member of `struct statfs'. */
#undef HAVE_STRUCT_STATFS_F_FRSIZE
/* Define to 1 if `f_blocks' is member of `struct statvfs'. */
#undef HAVE_STRUCT_STATVFS_F_BLOCKS
/* Define to 1 if `st_blocks' is member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BLOCKS
......@@ -641,6 +662,9 @@
/* Define to 1 if you have the <sys/statfs.h> header file. */
#undef HAVE_SYS_STATFS_H
/* Define to 1 if you have the <sys/statvfs.h> header file. */
#undef HAVE_SYS_STATVFS_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
......
......@@ -64,19 +64,29 @@ typedef unsigned int size_t;
#ifndef HAVE_SSIZE_T
typedef int ssize_t;
#endif
#ifndef HAVE_FSBLKCNT_T
typedef unsigned long fsblkcnt_t;
#endif
#ifndef HAVE_FSFILCNT_T
typedef unsigned long fsfilcnt_t;
#endif
#ifndef HAVE_STATFS
# ifdef __BEOS__
# define HAVE_STRUCT_STATFS_F_BFREE
struct statfs {
long f_bsize; /* block_size */
long f_blocks; /* total_blocks */
long f_bfree; /* free_blocks */
#ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
struct statvfs
{
unsigned long f_bsize;
unsigned long f_frsize;
fsblkcnt_t f_blocks;
fsblkcnt_t f_bfree;
fsblkcnt_t f_bavail;
fsfilcnt_t f_files;
fsfilcnt_t f_ffree;
fsfilcnt_t f_favail;
unsigned long f_fsid;
unsigned long f_flag;
unsigned long f_namemax;
};
# else /* defined(__BEOS__) */
struct statfs;
# endif /* defined(__BEOS__) */
#endif /* !defined(HAVE_STATFS) */
#endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
/****************************************************************
......@@ -262,10 +272,6 @@ int sigsetjmp( sigjmp_buf buf, int savesigs );
void siglongjmp( sigjmp_buf buf, int val );
#endif /* HAVE_SIGSETJMP */
#ifndef HAVE_STATFS
int statfs(const char *name, struct statfs *info);
#endif /* !defined(HAVE_STATFS) */
#ifndef HAVE_STRNCASECMP
# ifndef HAVE__STRNICMP
int strncasecmp(const char *str1, const char *str2, size_t n);
......
......@@ -21,7 +21,7 @@ C_SRCS = \
readlink.c \
sigsetjmp.c \
spawn.c \
statfs.c \
statvfs.c \
strcasecmp.c \
strerror.c \
strncasecmp.c \
......
/*
* statfs function
*
* Copyright 1996 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#ifdef __BEOS__
#include <be/kernel/fs_info.h>
#include <be/kernel/OS.h>
#endif
#include <errno.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef STATFS_DEFINED_BY_SYS_VFS
# include <sys/vfs.h>
#else
# ifdef STATFS_DEFINED_BY_SYS_MOUNT
# include <sys/mount.h>
# else
# ifdef STATFS_DEFINED_BY_SYS_STATFS
# include <sys/statfs.h>
# endif
# endif
#endif
#ifndef HAVE_STATFS
int statfs(const char *name, struct statfs *info)
{
#ifdef __BEOS__
dev_t mydev;
fs_info fsinfo;
if(!info) {
errno = ENOSYS;
return -1;
}
if ((mydev = dev_for_path(name)) < 0) {
errno = ENOSYS;
return -1;
}
if (fs_stat_dev(mydev,&fsinfo) < 0) {
errno = ENOSYS;
return -1;
}
info->f_bsize = fsinfo.block_size;
info->f_blocks = fsinfo.total_blocks;
info->f_bfree = fsinfo.free_blocks;
return 0;
#else /* defined(__BEOS__) */
errno = ENOSYS;
return -1;
#endif /* defined(__BEOS__) */
}
#endif /* !defined(HAVE_STATFS) */
/*
* statvfs function
*
* Copyright 2004 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#ifndef HAVE_STATVFS
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef STATFS_DEFINED_BY_SYS_VFS
# include <sys/vfs.h>
#else
# ifdef STATFS_DEFINED_BY_SYS_MOUNT
# include <sys/mount.h>
# else
# ifdef STATFS_DEFINED_BY_SYS_STATFS
# include <sys/statfs.h>
# endif
# endif
#endif
int statvfs( const char *path, struct statvfs *buf )
{
int ret;
struct statfs info;
/* FIXME: add autoconf check for this */
#if defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
ret = statfs( path, &info, 0, 0 );
#else
ret = statfs( path, &info );
#endif
if (ret >= 0)
{
memset( buf, 0, sizeof(*buf) );
buf->f_bsize = info.f_bsize;
buf->f_blocks = info.f_blocks;
buf->f_files = info.f_files;
buf->f_namemax = info.f_namelen;
#ifdef HAVE_STRUCT_STATFS_F_FRSIZE
buf->f_frsize = info.f_frsize;
#else
buf->f_frsize = info.f_bsize;
#endif
#ifdef HAVE_STRUCT_STATFS_F_BFREE
buf->f_bfree = info.f_bfree;
#else
buf->f_bfree = info.f_bavail;
#endif
#ifdef HAVE_STRUCT_STATFS_F_BAVAIL
buf->f_bavail = info.f_bavail;
#else
buf->f_bavail = info.f_bfree;
#endif
#ifdef HAVE_STRUCT_STATFS_F_FFREE
buf->f_ffree = info.f_ffree;
#else
buf->f_ffree = info.f_favail;
#endif
#ifdef HAVE_STRUCT_STATFS_F_FAVAIL
buf->f_favail = info.f_favail;
#else
buf->f_favail = info.f_ffree;
#endif
}
return ret;
}
#endif /* HAVE_STATVFS */
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