Home | History | Annotate | Download | only in e2p
      1 /*
      2  * fsetversion.c	- Set a file version on an ext2 file system
      3  *
      4  * Copyright (C) 1993, 1994  Remy Card <card (at) 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 
     37 int fsetversion (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 	ver = (int) version;
     47 	r = ioctl (fd, EXT2_IOC_SETVERSION, &ver);
     48 	if (r == -1)
     49 		save_errno = errno;
     50 	close (fd);
     51 	if (save_errno)
     52 		errno = save_errno;
     53 	return r;
     54 #else
     55    int ver = (int)version;
     56    return syscall(SYS_fsctl, name, EXT2_IOC_SETVERSION, &ver, 0);
     57 #endif
     58 #else /* ! HAVE_EXT2_IOCTLS */
     59 	extern int errno;
     60 	errno = EOPNOTSUPP;
     61 	return -1;
     62 #endif /* ! HAVE_EXT2_IOCTLS */
     63 }
     64