Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * fgetversion.c - Get a file version on an ext2 file system |
Mike Frysinger | 548ffd4 | 2005-05-07 07:14:41 +0000 | [diff] [blame] | 3 | * fsetversion.c - Set a file version on an ext2 file system |
| 4 | * |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> |
| 7 | * Laboratoire MASI, Institut Blaise Pascal |
| 8 | * Universite Pierre et Marie Curie (Paris VI) |
| 9 | * |
| 10 | * This file can be redistributed under the terms of the GNU Library General |
| 11 | * Public License |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * History: |
| 16 | * 93/10/30 - Creation |
| 17 | */ |
| 18 | |
| 19 | #if HAVE_ERRNO_H |
| 20 | #include <errno.h> |
| 21 | #endif |
| 22 | #if HAVE_UNISTD_H |
| 23 | #include <unistd.h> |
| 24 | #endif |
| 25 | #include <fcntl.h> |
| 26 | #include <sys/ioctl.h> |
| 27 | |
| 28 | #include "e2p.h" |
| 29 | |
| 30 | #ifdef O_LARGEFILE |
| 31 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) |
| 32 | #else |
| 33 | #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) |
| 34 | #endif |
| 35 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 36 | /* |
Mike Frysinger | 548ffd4 | 2005-05-07 07:14:41 +0000 | [diff] [blame] | 37 | To do fsetversion: unsigned long *ptr_version must be set to NULL. |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 38 | and unsigned long version must be set to a value |
Mike Frysinger | 548ffd4 | 2005-05-07 07:14:41 +0000 | [diff] [blame] | 39 | To do fgetversion: unsigned long *ptr_version must NOT be set to NULL |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 40 | and unsigned long version is ignored. |
Mike Frysinger | 548ffd4 | 2005-05-07 07:14:41 +0000 | [diff] [blame] | 41 | TITO. |
| 42 | */ |
| 43 | |
| 44 | int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version) |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 45 | { |
| 46 | #if HAVE_EXT2_IOCTLS |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 47 | int fd, r, ver, save_errno = 0; |
| 48 | |
| 49 | fd = open (name, OPEN_FLAGS); |
| 50 | if (fd == -1) |
| 51 | return -1; |
Mike Frysinger | 548ffd4 | 2005-05-07 07:14:41 +0000 | [diff] [blame] | 52 | if (!get_version) { |
| 53 | ver = (int) set_version; |
| 54 | r = ioctl (fd, EXT2_IOC_SETVERSION, &ver); |
| 55 | } else { |
| 56 | r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); |
| 57 | *get_version = ver; |
| 58 | } |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 59 | if (r == -1) |
| 60 | save_errno = errno; |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 61 | close (fd); |
| 62 | if (save_errno) |
| 63 | errno = save_errno; |
| 64 | return r; |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 65 | #else /* ! HAVE_EXT2_IOCTLS */ |
Mike Frysinger | d89e629 | 2005-04-24 05:07:59 +0000 | [diff] [blame] | 66 | errno = EOPNOTSUPP; |
| 67 | return -1; |
| 68 | #endif /* ! HAVE_EXT2_IOCTLS */ |
| 69 | } |