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 | * |
| 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 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 17 | #if HAVE_ERRNO_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 18 | #include <errno.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 19 | #endif |
| 20 | #if HAVE_STAT_FLAGS |
| 21 | #include <sys/stat.h> |
| 22 | #else |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 23 | #include <sys/ioctl.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 24 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 25 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 26 | #include "e2p.h" |
| 27 | |
| 28 | int getflags (int fd, unsigned long * flags) |
| 29 | { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 30 | #if HAVE_STAT_FLAGS |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 31 | struct stat buf; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 32 | |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 33 | if (fstat (fd, &buf) == -1) |
| 34 | return -1; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 35 | |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 36 | *flags = 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 37 | #ifdef UF_IMMUTABLE |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 38 | if (buf.st_flags & UF_IMMUTABLE) |
| 39 | *flags |= EXT2_IMMUTABLE_FL; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 40 | #endif |
| 41 | #ifdef UF_APPEND |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 42 | if (buf.st_flags & UF_APPEND) |
| 43 | *flags |= EXT2_APPEND_FL; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 44 | #endif |
| 45 | #ifdef UF_NODUMP |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 46 | if (buf.st_flags & UF_NODUMP) |
| 47 | *flags |= EXT2_NODUMP_FL; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 48 | #endif |
| 49 | |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 50 | return 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 51 | #else |
| 52 | #if HAVE_EXT2_IOCTLS |
Theodore Ts'o | cce382b | 1998-03-09 13:07:09 +0000 | [diff] [blame] | 53 | int r, f; |
| 54 | |
| 55 | r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); |
| 56 | *flags = f; |
| 57 | return r; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 58 | #else /* ! HAVE_EXT2_IOCTLS */ |
| 59 | extern int errno; |
| 60 | errno = EOPNOTSUPP; |
| 61 | return -1; |
| 62 | #endif /* ! HAVE_EXT2_IOCTLS */ |
| 63 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 64 | } |