Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 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 | * | ||||
Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame] | 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% | ||||
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 12 | */ |
13 | |||||
14 | /* | ||||
15 | * History: | ||||
16 | * 93/10/30 - Creation | ||||
17 | */ | ||||
18 | |||||
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 19 | #if HAVE_ERRNO_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 20 | #include <errno.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 21 | #endif |
Theodore Ts'o | 023d111 | 2002-08-17 14:44:56 -0400 | [diff] [blame] | 22 | #include <sys/types.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 23 | #include <sys/stat.h> |
Theodore Ts'o | 023d111 | 2002-08-17 14:44:56 -0400 | [diff] [blame] | 24 | #if HAVE_EXT2_IOCTLS |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 25 | #include <sys/ioctl.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 26 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 27 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 28 | #include "e2p.h" |
29 | |||||
30 | int getflags (int fd, unsigned long * flags) | ||||
31 | { | ||||
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 32 | struct stat buf; |
Theodore Ts'o | 023d111 | 2002-08-17 14:44:56 -0400 | [diff] [blame] | 33 | #if HAVE_STAT_FLAGS |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 34 | |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 35 | if (fstat (fd, &buf) == -1) |
36 | return -1; | ||||
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 37 | |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 38 | *flags = 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 39 | #ifdef UF_IMMUTABLE |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 40 | if (buf.st_flags & UF_IMMUTABLE) |
41 | *flags |= EXT2_IMMUTABLE_FL; | ||||
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 42 | #endif |
43 | #ifdef UF_APPEND | ||||
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 44 | if (buf.st_flags & UF_APPEND) |
45 | *flags |= EXT2_APPEND_FL; | ||||
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 46 | #endif |
47 | #ifdef UF_NODUMP | ||||
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 48 | if (buf.st_flags & UF_NODUMP) |
49 | *flags |= EXT2_NODUMP_FL; | ||||
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 50 | #endif |
51 | |||||
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 52 | return 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 53 | #else |
54 | #if HAVE_EXT2_IOCTLS | ||||
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 55 | int r, f; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 56 | |
Theodore Ts'o | 023d111 | 2002-08-17 14:44:56 -0400 | [diff] [blame] | 57 | if (!fstat(fd, &buf) && |
58 | !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) | ||||
59 | goto notsupp; | ||||
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 60 | r = ioctl(fd, EXT2_IOC_GETFLAGS, &f); |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 61 | *flags = f; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 62 | |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 63 | return r; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 64 | notsupp: |
Theodore Ts'o | 023d111 | 2002-08-17 14:44:56 -0400 | [diff] [blame] | 65 | #endif /* HAVE_EXT2_IOCTLS */ |
66 | #endif | ||||
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 67 | errno = EOPNOTSUPP; |
68 | return -1; | ||||
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 69 | } |