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