| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * fgetflags.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_UNISTD_H |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 21 | #include <unistd.h> |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 22 | #endif |
| 23 | #if HAVE_STAT_FLAGS |
| 24 | #include <sys/stat.h> |
| 25 | #else |
| 26 | #include <fcntl.h> |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 27 | #include <sys/ioctl.h> |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 28 | #endif |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 29 | |
| 30 | #include <linux/ext2_fs.h> |
| 31 | |
| 32 | #include "e2p.h" |
| 33 | |
| 34 | int fgetflags (const char * name, unsigned long * flags) |
| 35 | { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 36 | #if HAVE_STAT_FLAGS |
| 37 | struct stat buf; |
| 38 | |
| 39 | if (stat (name, &buf) == -1) |
| 40 | return -1; |
| 41 | |
| 42 | *flags = 0; |
| 43 | #ifdef UF_IMMUTABLE |
| 44 | if (buf.st_flags & UF_IMMUTABLE) |
| 45 | *flags |= EXT2_IMMUTABLE_FL; |
| 46 | #endif |
| 47 | #ifdef UF_APPEND |
| 48 | if (buf.st_flags & UF_APPEND) |
| 49 | *flags |= EXT2_APPEND_FL; |
| 50 | #endif |
| 51 | #ifdef UF_NODUMP |
| 52 | if (buf.st_flags & UF_NODUMP) |
| 53 | *flags |= EXT2_NODUMP_FL; |
| 54 | #endif |
| 55 | |
| 56 | return 0; |
| 57 | #else |
| 58 | #if HAVE_EXT2_IOCTLS |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 59 | int fd; |
| 60 | int r; |
| 61 | |
| 62 | fd = open (name, O_RDONLY); |
| 63 | if (fd == -1) |
| 64 | return -1; |
| 65 | r = ioctl (fd, EXT2_IOC_GETFLAGS, flags); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 66 | |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 67 | close (fd); |
| 68 | return r; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 69 | #else /* ! HAVE_EXT2_IOCTLS */ |
| 70 | extern int errno; |
| 71 | errno = EOPNOTSUPP; |
| 72 | return -1; |
| 73 | #endif /* ! HAVE_EXT2_IOCTLS */ |
| 74 | #endif |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 75 | } |