Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * statvfs function |
| 3 | * |
| 4 | * Copyright 2004 Alexandre Julliard |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "wine/port.h" |
| 23 | |
| 24 | #ifndef HAVE_STATVFS |
| 25 | |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
Alexandre Julliard | 86a8f4c | 2004-03-10 01:55:12 +0000 | [diff] [blame] | 28 | #include <errno.h> |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 29 | #ifdef HAVE_SYS_PARAM_H |
| 30 | # include <sys/param.h> |
| 31 | #endif |
Robert Millan | 55b7448 | 2006-02-06 21:53:27 +0100 | [diff] [blame] | 32 | #ifdef HAVE_SYS_VFS_H |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 33 | # include <sys/vfs.h> |
Robert Millan | 55b7448 | 2006-02-06 21:53:27 +0100 | [diff] [blame] | 34 | #endif |
| 35 | #ifdef HAVE_SYS_MOUNT_H |
| 36 | # include <sys/mount.h> |
| 37 | #endif |
| 38 | #ifdef HAVE_SYS_STATFS_H |
| 39 | # include <sys/statfs.h> |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 40 | #endif |
| 41 | |
| 42 | int statvfs( const char *path, struct statvfs *buf ) |
| 43 | { |
| 44 | int ret; |
Alexandre Julliard | 86a8f4c | 2004-03-10 01:55:12 +0000 | [diff] [blame] | 45 | #ifdef HAVE_STATFS |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 46 | struct statfs info; |
| 47 | |
| 48 | /* FIXME: add autoconf check for this */ |
| 49 | #if defined(__svr4__) || defined(_SCO_DS) || defined(__sun) |
| 50 | ret = statfs( path, &info, 0, 0 ); |
| 51 | #else |
| 52 | ret = statfs( path, &info ); |
| 53 | #endif |
| 54 | if (ret >= 0) |
| 55 | { |
| 56 | memset( buf, 0, sizeof(*buf) ); |
| 57 | buf->f_bsize = info.f_bsize; |
| 58 | buf->f_blocks = info.f_blocks; |
| 59 | buf->f_files = info.f_files; |
Alexandre Julliard | b859a68 | 2004-03-07 03:16:43 +0000 | [diff] [blame] | 60 | #ifdef HAVE_STRUCT_STATFS_F_NAMELEN |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 61 | buf->f_namemax = info.f_namelen; |
Alexandre Julliard | b859a68 | 2004-03-07 03:16:43 +0000 | [diff] [blame] | 62 | #endif |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 63 | #ifdef HAVE_STRUCT_STATFS_F_FRSIZE |
| 64 | buf->f_frsize = info.f_frsize; |
| 65 | #else |
| 66 | buf->f_frsize = info.f_bsize; |
| 67 | #endif |
| 68 | #ifdef HAVE_STRUCT_STATFS_F_BFREE |
| 69 | buf->f_bfree = info.f_bfree; |
| 70 | #else |
| 71 | buf->f_bfree = info.f_bavail; |
| 72 | #endif |
| 73 | #ifdef HAVE_STRUCT_STATFS_F_BAVAIL |
| 74 | buf->f_bavail = info.f_bavail; |
| 75 | #else |
| 76 | buf->f_bavail = info.f_bfree; |
| 77 | #endif |
| 78 | #ifdef HAVE_STRUCT_STATFS_F_FFREE |
| 79 | buf->f_ffree = info.f_ffree; |
| 80 | #else |
| 81 | buf->f_ffree = info.f_favail; |
| 82 | #endif |
| 83 | #ifdef HAVE_STRUCT_STATFS_F_FAVAIL |
| 84 | buf->f_favail = info.f_favail; |
| 85 | #else |
| 86 | buf->f_favail = info.f_ffree; |
| 87 | #endif |
| 88 | } |
Alexandre Julliard | 86a8f4c | 2004-03-10 01:55:12 +0000 | [diff] [blame] | 89 | #else /* HAVE_STATFS */ |
| 90 | ret = -1; |
| 91 | errno = ENOSYS; |
| 92 | #endif /* HAVE_STATFS */ |
Alexandre Julliard | 13af489 | 2004-03-05 21:03:46 +0000 | [diff] [blame] | 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | #endif /* HAVE_STATVFS */ |