Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / lib / e2p / fgetversion.c
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  * 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
17 #if HAVE_ERRNO_H
18 #include <errno.h>
19 #endif
20 #if HAVE_UNISTD_H
21 #include <unistd.h>
22 #endif
23 #include <fcntl.h>
24 #include <sys/ioctl.h>
25
26 #include "e2p.h"
27
28 int fgetversion (const char * name, unsigned long * version)
29 {
30 #if HAVE_EXT2_IOCTLS
31         int fd;
32         int r;
33
34         fd = open (name, O_RDONLY|O_NONBLOCK);
35         if (fd == -1)
36                 return - 1;
37         r = ioctl (fd, EXT2_IOC_GETVERSION, version);
38         close (fd);
39         return r;
40 #else /* ! HAVE_EXT2_IOCTLS */
41         extern int errno;
42         errno = EOPNOTSUPP;
43         return -1;
44 #endif /* ! HAVE_EXT2_IOCTLS */
45 }