• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * %Begin-Header%
9  * This file may be redistributed under the terms of the GNU Library
10  * General Public License, version 2.
11  * %End-Header%
12  */
13 
14 /*
15  * History:
16  * 93/10/30	- Creation
17  */
18 
19 #if HAVE_ERRNO_H
20 #include <errno.h>
21 #endif
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #if HAVE_EXT2_IOCTLS
25 #include <sys/ioctl.h>
26 #endif
27 
28 #include "e2p.h"
29 
30 /*
31  * Deal with lame glibc's that define this function without actually
32  * implementing it.  Can you say "attractive nuisance", boys and girls?
33  * I knew you could!
34  */
35 #ifdef __linux__
36 #undef HAVE_CHFLAGS
37 #endif
38 
setflags(int fd,unsigned long flags)39 int setflags (int fd, unsigned long flags)
40 {
41 	struct stat buf;
42 #if HAVE_CHFLAGS
43 	unsigned long bsd_flags = 0;
44 
45 #ifdef UF_IMMUTABLE
46 	if (flags & EXT2_IMMUTABLE_FL)
47 		bsd_flags |= UF_IMMUTABLE;
48 #endif
49 #ifdef UF_APPEND
50 	if (flags & EXT2_APPEND_FL)
51 		bsd_flags |= UF_APPEND;
52 #endif
53 #ifdef UF_NODUMP
54 	if (flags & EXT2_NODUMP_FL)
55 		bsd_flags |= UF_NODUMP;
56 #endif
57 
58 	return fchflags (fd, bsd_flags);
59 #else
60 #if HAVE_EXT2_IOCTLS
61 	int	f;
62 
63 	if (!fstat(fd, &buf) &&
64 	    !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
65 		errno = EOPNOTSUPP;
66 		return -1;
67 	}
68 	f = (int) flags;
69 	return ioctl (fd, EXT2_IOC_SETFLAGS, &f);
70 #endif /* HAVE_EXT2_IOCTLS */
71 #endif
72 	errno = EOPNOTSUPP;
73 	return -1;
74 }
75