source: MondoRescue/branches/stable/mindi-busybox/e2fsprogs/e2p/fgetsetversion.c @ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 13 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 1.6 KB
Line 
1/*
2 * fgetversion.c    - Get a file version on an ext2 file system
3 * fsetversion.c    - Set a file version on an ext2 file system
4 *
5 *
6 * Copyright (C) 1993, 1994  Remy Card <card@masi.ibp.fr>
7 *                           Laboratoire MASI, Institut Blaise Pascal
8 *                           Universite Pierre et Marie Curie (Paris VI)
9 *
10 * This file can be redistributed under the terms of the GNU Library General
11 * Public License
12 */
13
14/*
15 * History:
16 * 93/10/30 - Creation
17 */
18
19#if HAVE_ERRNO_H
20#include <errno.h>
21#endif
22#if HAVE_UNISTD_H
23#include <unistd.h>
24#endif
25#include <fcntl.h>
26#include <sys/ioctl.h>
27
28#include "e2p.h"
29
30#ifdef O_LARGEFILE
31#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
32#else
33#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
34#endif
35
36/*
37   To do fsetversion:     unsigned long *ptr_version must be set to NULL.
38              and unsigned long version must be set to a value
39   To do fgetversion:     unsigned long *ptr_version must NOT be set to NULL
40              and unsigned long version is ignored.
41    TITO.
42*/
43
44int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version)
45{
46#if HAVE_EXT2_IOCTLS
47    int fd, r, ver, save_errno = 0;
48
49    fd = open (name, OPEN_FLAGS);
50    if (fd == -1)
51        return -1;
52    if (!get_version) {
53        ver = (int) set_version;
54        r = ioctl (fd, EXT2_IOC_SETVERSION, &ver);
55    } else {
56        r = ioctl (fd, EXT2_IOC_GETVERSION, &ver);
57        *get_version = ver;
58    }
59    if (r == -1)
60        save_errno = errno;
61    close (fd);
62    if (save_errno)
63        errno = save_errno;
64    return r;
65#else /* ! HAVE_EXT2_IOCTLS */
66    errno = EOPNOTSUPP;
67    return -1;
68#endif /* ! HAVE_EXT2_IOCTLS */
69}
Note: See TracBrowser for help on using the repository browser.