• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define _LARGEFILE_SOURCE
18 #define _LARGEFILE64_SOURCE
19 
20 #if HAVE_ERRNO_H
21 #include <errno.h>
22 #endif
23 #if HAVE_UNISTD_H
24 #include <unistd.h>
25 #endif
26 #include <fcntl.h>
27 #include <sys/ioctl.h>
28 
29 #include "e2p.h"
30 
31 #ifdef O_LARGEFILE
32 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
33 #else
34 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
35 #endif
36 
fgetversion(const char * name,unsigned long * version)37 int fgetversion (const char * name, unsigned long * version)
38 {
39 #if HAVE_EXT2_IOCTLS
40 #if !APPLE_DARWIN
41 	int fd, r, ver, save_errno = 0;
42 
43 	fd = open (name, OPEN_FLAGS);
44 	if (fd == -1)
45 		return -1;
46 	r = ioctl (fd, EXT2_IOC_GETVERSION, &ver);
47 	if (r == -1)
48 		save_errno = errno;
49 	*version = ver;
50 	close (fd);
51 	if (save_errno)
52 		errno = save_errno;
53 	return r;
54 #else
55    int ver=-1, err;
56    err = syscall(SYS_fsctl, name, EXT2_IOC_GETVERSION, &ver, 0);
57    *version = ver;
58    return(err);
59 #endif
60 #else /* ! HAVE_EXT2_IOCTLS */
61 	extern int errno;
62 	errno = EOPNOTSUPP;
63 	return -1;
64 #endif /* ! HAVE_EXT2_IOCTLS */
65 }
66