Whamcloud - gitweb
06f127f2ea28f90b58561a05ab2b472617a7842f
[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 #if HAVE_CHFLAGS
21 #include <sys/types.h>
22 #include <sys/stat.h>           /* For the flag values.  */
23 #else
24 #include <sys/ioctl.h>
25 #endif
26
27 #include <linux/ext2_fs.h>
28
29 #include "e2p.h"
30
31 int setflags (int fd, unsigned long flags)
32 {
33 #if HAVE_CHFLAGS
34   unsigned long bsd_flags = 0;
35
36 #ifdef UF_IMMUTABLE
37   if (flags & EXT2_IMMUTABLE_FL)
38     bsd_flags |= UF_IMMUTABLE;
39 #endif
40 #ifdef UF_APPEND
41   if (flags & EXT2_APPEND_FL)
42     bsd_flags |= UF_APPEND;
43 #endif
44 #ifdef UF_NODUMP
45   if (flags & EXT2_NODUMP_FL)
46     bsd_flags |= UF_NODUMP;
47 #endif
48
49   return fchflags (fd, bsd_flags);
50 #else
51 #if HAVE_EXT2_IOCTLS
52         return ioctl (fd, EXT2_IOC_SETFLAGS, &flags);
53 #else /* ! HAVE_EXT2_IOCTLS */
54         extern int errno;
55         errno = EOPNOTSUPP;
56         return -1;
57 #endif /* ! HAVE_EXT2_IOCTLS */
58 #endif
59 }