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
fsetproject(const char * name,unsigned long project)42 int fsetproject(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 == -1) {
56 save_errno = errno;
57 goto errout;
58 }
59 fsx.fsx_projid = project;
60 r = ioctl (fd, FS_IOC_FSSETXATTR, &fsx);
61 if (r == -1)
62 save_errno = errno;
63 errout:
64 close (fd);
65 if (save_errno)
66 errno = save_errno;
67 return r;
68 #endif
69 }
70