• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * getflags.c		- Get 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 
getflags(int fd,unsigned long * flags)28 int getflags (int fd, unsigned long * flags)
29 {
30 	struct stat buf;
31 #if HAVE_STAT_FLAGS
32 
33 	if (fstat (fd, &buf) == -1)
34 		return -1;
35 
36 	*flags = 0;
37 #ifdef UF_IMMUTABLE
38 	if (buf.st_flags & UF_IMMUTABLE)
39 		*flags |= EXT2_IMMUTABLE_FL;
40 #endif
41 #ifdef UF_APPEND
42 	if (buf.st_flags & UF_APPEND)
43 		*flags |= EXT2_APPEND_FL;
44 #endif
45 #ifdef UF_NODUMP
46 	if (buf.st_flags & UF_NODUMP)
47 		*flags |= EXT2_NODUMP_FL;
48 #endif
49 
50 	return 0;
51 #else
52 #if HAVE_EXT2_IOCTLS
53 	int r, f;
54 
55 	if (!fstat(fd, &buf) &&
56 	    !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode))
57 		goto notsupp;
58 	r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
59 	*flags = f;
60 	return r;
61 #endif /* HAVE_EXT2_IOCTLS */
62 #endif
63 notsupp:
64 	errno = EOPNOTSUPP;
65 	return -1;
66 }
67