Back to index

glibc  2.9
fstatvfs64.c
Go to the documentation of this file.
00001 /* Return information about the filesystem on which FD resides.
00002    Copyright (C) 1996,1997,1998,2000,2001,2004,2006
00003        Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <errno.h>
00022 #include <string.h>
00023 #include <sys/stat.h>
00024 #include <sys/statfs.h>
00025 #include <sys/statvfs.h>
00026 #include <kernel-features.h>
00027 
00028 
00029 extern void __internal_statvfs64 (const char *name, struct statvfs64 *buf,
00030                               struct statfs64 *fsbuf, struct stat64 *st);
00031 
00032 
00033 /* Return information about the filesystem on which FD resides.  */
00034 int
00035 __fstatvfs64 (int fd, struct statvfs64 *buf)
00036 {
00037   struct statfs64 fsbuf;
00038   int res = __fstatfs64 (fd, &fsbuf);
00039 
00040 #ifndef __ASSUME_STATFS64
00041   if (res < 0 && errno == ENOSYS)
00042     {
00043       struct statvfs buf32;
00044 
00045       res = fstatvfs (fd, &buf32);
00046       if (res == 0)
00047        {
00048          buf->f_bsize = buf32.f_bsize;
00049          buf->f_frsize = buf32.f_frsize;
00050          buf->f_blocks = buf32.f_blocks;
00051          buf->f_bfree = buf32.f_bfree;
00052          buf->f_bavail = buf32.f_bavail;
00053          buf->f_files = buf32.f_files;
00054          buf->f_ffree = buf32.f_ffree;
00055          buf->f_favail = buf32.f_favail;
00056          buf->f_fsid = buf32.f_fsid;
00057          buf->f_flag = buf32.f_flag;
00058          buf->f_namemax = buf32.f_namemax;
00059          memcpy (buf->__f_spare, buf32.__f_spare, sizeof (buf32.__f_spare));
00060        }
00061     }
00062 #endif
00063 
00064   if (res == 0)
00065     {
00066       /* Convert the result.  */
00067       struct stat64 st;
00068       __internal_statvfs64 (NULL, buf, &fsbuf,
00069                          fstat64 (fd, &st) == -1 ? NULL : &st);
00070     }
00071 
00072   return res;
00073 }
00074 weak_alias (__fstatvfs64, fstatvfs64)