]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - lib/e2p/getflags.c
ChangeLog, ls.c:
[thirdparty/e2fsprogs.git] / lib / e2p / getflags.c
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 #if HAVE_STAT_FLAGS
21 #include <sys/stat.h>
22 #else
23 #include <sys/ioctl.h>
24 #endif
25
26 #include "e2p.h"
27
28 int getflags (int fd, unsigned long * flags)
29 {
30 #if HAVE_STAT_FLAGS
31 struct stat buf;
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 r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
56 *flags = f;
57 return r;
58 #else /* ! HAVE_EXT2_IOCTLS */
59 extern int errno;
60 errno = EOPNOTSUPP;
61 return -1;
62 #endif /* ! HAVE_EXT2_IOCTLS */
63 #endif
64 }