1 /*
2 * fgetversion.c - Get a file version 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 * %Begin-Header%
9 * This file may be redistributed under the terms of the GNU Library
10 * General Public License, version 2.
11 * %End-Header%
12 */
13
14 /*
15 * History:
16 * 93/10/30 - Creation
17 */
18
19 #define _LARGEFILE_SOURCE
20 #define _LARGEFILE64_SOURCE
21
22 #if HAVE_ERRNO_H
23 #include <errno.h>
24 #endif
25 #if HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 #include <fcntl.h>
29 #include <sys/ioctl.h>
30
31 #include "e2p.h"
32
33 #ifdef O_LARGEFILE
34 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
35 #else
36 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
37 #endif
38
fgetversion(const char * name,unsigned long * version)39 int fgetversion (const char * name, unsigned long * version)
40 {
41 #if HAVE_EXT2_IOCTLS
42 #if !APPLE_DARWIN
43 int fd, r, ver, save_errno = 0;
44
45 fd = open (name, OPEN_FLAGS);
46 if (fd == -1)
47 return -1;
48 r = ioctl (fd, EXT2_IOC_GETVERSION, &ver);
49 if (r == -1)
50 save_errno = errno;
51 *version = ver;
52 close (fd);
53 if (save_errno)
54 errno = save_errno;
55 return r;
56 #else
57 int ver=-1, err;
58 err = syscall(SYS_fsctl, name, EXT2_IOC_GETVERSION, &ver, 0);
59 *version = ver;
60 return(err);
61 #endif
62 #else /* ! HAVE_EXT2_IOCTLS */
63 extern int errno;
64 errno = EOPNOTSUPP;
65 return -1;
66 #endif /* ! HAVE_EXT2_IOCTLS */
67 }
68