Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ee0bc0d176
Fetching contributors…

Cannot retrieve contributors at this time

file 244 lines (197 sloc) 5.13 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
/*
* <sys/sendfile.h> wrapper functions.
*
* Authors:
* Jonathan Pryor (jonpryor@vt.edu)
*
* Copyright (C) 2004-2006 Jonathan Pryor
*/

#include <errno.h>

#include <string.h>

#include "mph.h"
#include "map.h"

#ifdef HAVE_PATHCONF_H
#include <pathconf.h>
#endif

#ifdef HAVE_SYS_STATVFS_H
#include <sys/statvfs.h>
#elif defined (HAVE_STATFS) || defined (HAVE_FSTATFS)
#include <sys/vfs.h>
#endif /* def HAVE_SYS_STATVFS_H */

#ifdef HAVE_GETFSSTAT
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <unistd.h> /* for pathconf */
#endif /* def HAVE_GETFSSTAT */

G_BEGIN_DECLS

#ifdef HAVE_SYS_STATVFS_H
int
Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
{
struct statvfs *from = _from;

to->f_bsize = from->f_bsize;
to->f_frsize = from->f_frsize;
to->f_blocks = from->f_blocks;
to->f_bfree = from->f_bfree;
to->f_bavail = from->f_bavail;
to->f_files = from->f_files;
to->f_ffree = from->f_ffree;
to->f_favail = from->f_favail;
to->f_fsid = from->f_fsid;
to->f_namemax = from->f_namemax;

if (Mono_Posix_ToMountFlags (from->f_flag, &to->f_flag) != 0)
return -1;

return 0;
}

int
Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
{
struct statvfs *to = _to;
guint64 flag;

to->f_bsize = from->f_bsize;
to->f_frsize = from->f_frsize;
to->f_blocks = from->f_blocks;
to->f_bfree = from->f_bfree;
to->f_bavail = from->f_bavail;
to->f_files = from->f_files;
to->f_ffree = from->f_ffree;
to->f_favail = from->f_favail;
to->f_fsid = from->f_fsid;
to->f_namemax = from->f_namemax;

if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
return -1;
to->f_flag = flag;

return 0;
}
#endif /* ndef HAVE_SYS_STATVFS_H */

/*
* System V-compatible definitions
*/

#ifdef HAVE_STATVFS
gint32
Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
{
struct statvfs s;
int r;

if (buf == NULL) {
errno = EFAULT;
return -1;
}

if ((r = statvfs (path, &s)) == 0)
r = Mono_Posix_ToStatvfs (&s, buf);

return r;
}
#endif /* ndef HAVA_STATVFS */

#ifdef HAVE_FSTATVFS
gint32
Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
{
struct statvfs s;
int r;

if (buf == NULL) {
errno = EFAULT;
return -1;
}

if ((r = fstatvfs (fd, &s)) == 0)
r = Mono_Posix_ToStatvfs (&s, buf);

return r;
}
#endif /* ndef HAVA_FSTATVFS */

/*
* BSD-compatible definitions.
*
* Linux also provides these, but are deprecated in favor of (f)statvfs.
*/

#if (defined (HAVE_STATFS) || defined (HAVE_FSTATFS)) && !defined (HAVE_STATVFS)
int
Mono_Posix_ToStatvfs (void *_from, struct Mono_Posix_Statvfs *to)
{
struct statfs *from = _from;

to->f_bsize = from->f_bsize;
to->f_frsize = from->f_bsize;
to->f_blocks = from->f_blocks;
to->f_bfree = from->f_bfree;
to->f_bavail = from->f_bavail;
to->f_files = from->f_files;
to->f_ffree = from->f_ffree;
to->f_favail = from->f_ffree; /* OSX doesn't have f_avail */

// from->f_fsid is an int32[2], to->f_fsid is a uint64,
// so this shouldn't lose anything.
memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));

#if HAVE_STRUCT_STATFS_F_FLAGS
if (Mono_Posix_ToMountFlags (from->f_flags, &to->f_flag) != 0)
return -1;
#endif /* def HAVE_STRUCT_STATFS_F_FLAGS */

return 0;
}

int
Mono_Posix_FromStatvfs (struct Mono_Posix_Statvfs *from, void *_to)
{
struct statfs *to = _to;
guint64 flag;

to->f_bsize = from->f_bsize;
to->f_blocks = from->f_blocks;
to->f_bfree = from->f_bfree;
to->f_bavail = from->f_bavail;
to->f_files = from->f_files;
to->f_ffree = from->f_ffree;

// from->f_fsid is an int32[2], to->f_fsid is a uint64,
// so this shouldn't lose anything.
memcpy (&to->f_fsid, &from->f_fsid, sizeof(to->f_fsid));

#if HAVE_STRUCT_STATFS_F_FLAGS
if (Mono_Posix_FromMountFlags (from->f_flag, &flag) != 0)
return -1;
to->f_flags = flag;
#endif /* def HAVE_STRUCT_STATFS_F_FLAGS */

return 0;
}

static void
set_namemax (const char *path, struct Mono_Posix_Statvfs *buf)
{
  buf->f_namemax = pathconf (path, _PC_NAME_MAX);
}

static void
set_fnamemax (int fd, struct Mono_Posix_Statvfs *buf)
{
  buf->f_namemax = fpathconf (fd, _PC_NAME_MAX);
}
#endif /* (def HAVE_STATFS || def HAVE_FSTATFS) && !def HAVE_STATVFS */

#if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
gint32
Mono_Posix_Syscall_statvfs (const char *path, struct Mono_Posix_Statvfs *buf)
{
struct statfs s;
int r;

if (buf == NULL) {
errno = EFAULT;
return -1;
}

if ((r = statfs (path, &s)) == 0 &&
(r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
set_namemax (path, buf);
}

return r;
}
#endif /* !def HAVE_STATVFS && def HAVE_STATFS */

#if !defined (HAVE_STATVFS) && defined (HAVE_STATFS)
gint32
Mono_Posix_Syscall_fstatvfs (gint32 fd, struct Mono_Posix_Statvfs *buf)
{
struct statfs s;
int r;

if (buf == NULL) {
errno = EFAULT;
return -1;
}

if ((r = fstatfs (fd, &s)) == 0 &&
(r = Mono_Posix_ToStatvfs (&s, buf)) == 0) {
set_fnamemax (fd, buf);
}

return r;
}
#endif /* !def HAVE_FSTATVFS && def HAVE_STATFS */

G_END_DECLS

/*
* vim: noexpandtab
*/
Something went wrong with that request. Please try again.