Whamcloud - gitweb
chattr.1.in: Document the compression attribute flags E, X, and
[tools/e2fsprogs.git] / lib / e2p / setflags.c
1 /*
2  * setflags.c           - Set a file flags on an ext2 file system
3  *
4  * Copyright (C) 1993, 1994  Remy Card <card@masi.ibp.fr>
5  *                           Laboratoire MASI, Institut Blaise Pascal
6  *                           Universite Pierre et Marie Curie (Paris VI)
7  *
8  * This file can be redistributed under the terms of the GNU Library General
9  * Public License
10  */
11
12 /*
13  * History:
14  * 93/10/30     - Creation
15  */
16
17 #if HAVE_ERRNO_H
18 #include <errno.h>
19 #endif
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #if HAVE_EXT2_IOCTLS
23 #include <sys/ioctl.h>
24 #endif
25
26 #include "e2p.h"
27
28 int setflags (int fd, unsigned long flags)
29 {
30         struct stat buf;
31 #if HAVE_CHFLAGS
32         unsigned long bsd_flags = 0;
33
34 #ifdef UF_IMMUTABLE
35         if (flags & EXT2_IMMUTABLE_FL)
36                 bsd_flags |= UF_IMMUTABLE;
37 #endif
38 #ifdef UF_APPEND
39         if (flags & EXT2_APPEND_FL)
40                 bsd_flags |= UF_APPEND;
41 #endif
42 #ifdef UF_NODUMP
43         if (flags & EXT2_NODUMP_FL)
44                 bsd_flags |= UF_NODUMP;
45 #endif
46
47         return fchflags (fd, bsd_flags);
48 #else
49 #if HAVE_EXT2_IOCTLS
50         int     f;
51
52         if (!fstat(fd, &buf) &&
53             !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
54                 errno = EOPNOTSUPP;
55                 return -1;
56         }
57         f = (int) flags;
58         return ioctl (fd, EXT2_IOC_SETFLAGS, &f);
59 #endif /* HAVE_EXT2_IOCTLS */
60 #endif
61         errno = EOPNOTSUPP;
62         return -1;
63 }