• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 
fsetversion(const char * name,unsigned long version)39 int fsetversion (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 	ver = (int) version;
49 	r = ioctl (fd, EXT2_IOC_SETVERSION, &ver);
50 	if (r == -1)
51 		save_errno = errno;
52 	close (fd);
53 	if (save_errno)
54 		errno = save_errno;
55 	return r;
56 #else
57    int ver = (int)version;
58    return syscall(SYS_fsctl, name, EXT2_IOC_SETVERSION, &ver, 0);
59 #endif
60 #else /* ! HAVE_EXT2_IOCTLS */
61 	extern int errno;
62 	errno = EOPNOTSUPP;
63 	return -1;
64 #endif /* ! HAVE_EXT2_IOCTLS */
65 }
66