Whamcloud - gitweb
Many files:
[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 "e2p.h"
28
29 int setflags (int fd, unsigned long flags)
30 {
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         return ioctl (fd, EXT2_IOC_SETFLAGS, &flags);
51 #else /* ! HAVE_EXT2_IOCTLS */
52         extern int errno;
53         errno = EOPNOTSUPP;
54         return -1;
55 #endif /* ! HAVE_EXT2_IOCTLS */
56 #endif
57 }