• 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 #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 #if HAVE_SYS_IOCTL_H
35 #include <sys/ioctl.h>
36 #endif
37 
38 #include "e2p.h"
39 
40 #ifdef O_LARGEFILE
41 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
42 #else
43 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
44 #endif
45 
fsetversion(const char * name,unsigned long version)46 int fsetversion (const char * name, unsigned long version)
47 {
48 #if HAVE_EXT2_IOCTLS
49 #if !APPLE_DARWIN
50 	int fd, r, ver, save_errno = 0;
51 
52 	fd = open (name, OPEN_FLAGS);
53 	if (fd == -1)
54 		return -1;
55 	ver = (int) version;
56 	r = ioctl (fd, EXT2_IOC_SETVERSION, &ver);
57 	if (r == -1)
58 		save_errno = errno;
59 	close (fd);
60 	if (save_errno)
61 		errno = save_errno;
62 	return r;
63 #else
64    int ver = (int)version;
65    return syscall(SYS_fsctl, name, EXT2_IOC_SETVERSION, &ver, 0);
66 #endif
67 #else /* ! HAVE_EXT2_IOCTLS */
68 	extern int errno;
69 	errno = EOPNOTSUPP;
70 	return -1;
71 #endif /* ! HAVE_EXT2_IOCTLS */
72 }
73