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