Back to index

glibc  2.9
posix_fallocate64.c
Go to the documentation of this file.
00001 /* Copyright (C) 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <fcntl.h>
00020 #include <kernel-features.h>
00021 #include <sysdep.h>
00022 
00023 extern int __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len);
00024 #define __posix_fallocate64_l64 static internal_fallocate64
00025 #include <sysdeps/posix/posix_fallocate64.c>
00026 #undef __posix_fallocate64_l64
00027 
00028 #if !defined __ASSUME_FALLOCATE && defined __NR_fallocate
00029 /* Defined in posix_fallocate.c.  */
00030 extern int __have_fallocate attribute_hidden;
00031 #endif
00032 
00033 
00034 /* Reserve storage for the data of the file associated with FD.  */
00035 int
00036 __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len)
00037 {
00038 #ifdef __NR_fallocate
00039 # ifndef __ASSUME_FALLOCATE
00040   if (__builtin_expect (__have_fallocate >= 0, 1))
00041 # endif
00042     {
00043       INTERNAL_SYSCALL_DECL (err);
00044       int res = INTERNAL_SYSCALL (fallocate, err, 6, fd, 0,
00045                               __LONG_LONG_PAIR ((long int) (offset >> 32),
00046                                               (long int) offset),
00047                               __LONG_LONG_PAIR ((long int) (len >> 32),
00048                                               (long int) len));
00049 
00050       if (! INTERNAL_SYSCALL_ERROR_P (res, err))
00051        return 0;
00052 
00053 # ifndef __ASSUME_FALLOCATE
00054       if (__builtin_expect (INTERNAL_SYSCALL_ERRNO (res, err) == ENOSYS, 0))
00055        __have_fallocate = -1;
00056       else
00057 # endif
00058        if (INTERNAL_SYSCALL_ERRNO (res, err) != EOPNOTSUPP)
00059          return INTERNAL_SYSCALL_ERRNO (res, err);
00060     }
00061 #endif
00062 
00063   return internal_fallocate64 (fd, offset, len);
00064 }