1 /* 2 * fgetproject.c --- get project id 3 * 4 * Copyright (C) 1999 Theodore Ts'o <tytso@mit.edu> 5 * 6 * %Begin-Header% 7 * This file may be redistributed under the terms of the GNU Library 8 * General Public License, version 2. 9 * %End-Header% 10 */ 11 12 #ifndef _LARGEFILE_SOURCE 13 #define _LARGEFILE_SOURCE 14 #endif 15 #ifndef _LARGEFILE64_SOURCE 16 #define _LARGEFILE64_SOURCE 17 #endif 18 19 #include "config.h" 20 #if HAVE_ERRNO_H 21 #include <errno.h> 22 #endif 23 #if HAVE_UNISTD_H 24 #include <unistd.h> 25 #endif 26 #include <sys/types.h> 27 #include <sys/stat.h> 28 #if HAVE_EXT2_IOCTLS 29 #include <fcntl.h> 30 #include <sys/ioctl.h> 31 #include "project.h" 32 #endif 33 34 #include "e2p.h" 35 36 #ifdef O_LARGEFILE 37 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) 38 #else 39 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) 40 #endif 41 fgetproject(const char * name,unsigned long * project)42int fgetproject(const char *name, unsigned long *project) 43 { 44 #ifndef FS_IOC_FSGETXATTR 45 errno = EOPNOTSUPP; 46 return -1; 47 #else 48 int fd, r, save_errno = 0; 49 struct fsxattr fsx; 50 51 fd = open (name, OPEN_FLAGS); 52 if (fd == -1) 53 return -1; 54 r = ioctl (fd, FS_IOC_FSGETXATTR, &fsx); 55 if (r == 0) 56 *project = fsx.fsx_projid; 57 save_errno = errno; 58 close (fd); 59 if (save_errno) 60 errno = save_errno; 61 return r; 62 #endif 63 } 64