| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * fsetflags.c - Set 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_CHFLAGS |
| 24 | #include <sys/stat.h> /* For the flag values. */ |
| 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 fsetflags (const char * name, unsigned long flags) |
| 35 | { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 36 | #if HAVE_CHFLAGS |
| 37 | unsigned long bsd_flags = 0; |
| 38 | |
| 39 | #ifdef UF_IMMUTABLE |
| 40 | if (flags & EXT2_IMMUTABLE_FL) |
| 41 | bsd_flags |= UF_IMMUTABLE; |
| 42 | #endif |
| 43 | #ifdef UF_APPEND |
| 44 | if (flags & EXT2_APPEND_FL) |
| 45 | bsd_flags |= UF_APPEND; |
| 46 | #endif |
| 47 | #ifdef UF_NODUMP |
| 48 | if (flags & EXT2_NODUMP_FL) |
| 49 | bsd_flags |= UF_NODUMP; |
| 50 | #endif |
| 51 | |
| 52 | return chflags (name, bsd_flags); |
| 53 | #else |
| 54 | #if HAVE_EXT2_IOCTLS |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 55 | int fd; |
| 56 | int r; |
| 57 | |
| 58 | fd = open (name, O_RDONLY); |
| 59 | if (fd == -1) |
| 60 | return -1; |
| 61 | r = ioctl (fd, EXT2_IOC_SETFLAGS, &flags); |
| 62 | close (fd); |
| 63 | return r; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 64 | #else /* ! HAVE_EXT2_IOCTLS */ |
| 65 | extern int errno; |
| 66 | errno = EOPNOTSUPP; |
| 67 | return -1; |
| 68 | #endif /* ! HAVE_EXT2_IOCTLS */ |
| 69 | #endif |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 70 | } |