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

Last change on this file since 821 was 821, checked in by Bruno Cornec, 18 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.4 KB
RevLine 
[821]1/*
2 * fgetflags.c - Get a file flags on an ext2 file system
3 * fsetflags.c - Set a file flags on an ext2 file system
4 *
5 * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
6 * Laboratoire MASI, Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *
9 * This file can be redistributed under the terms of the GNU Library General
10 * Public License
11 */
12
13/*
14 * History:
15 * 93/10/30 - Creation
16 */
17
18#if HAVE_ERRNO_H
19#include <errno.h>
20#endif
21#if HAVE_UNISTD_H
22#include <unistd.h>
23#endif
24#include <sys/types.h>
25#include <sys/stat.h>
26#if HAVE_EXT2_IOCTLS
27#include <fcntl.h>
28#include <sys/ioctl.h>
29#endif
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
39int fgetsetflags (const char * name, unsigned long * get_flags, unsigned long set_flags)
40{
41#if HAVE_EXT2_IOCTLS
42 struct stat buf;
43 int fd, r, f, save_errno = 0;
44
45 if (!stat(name, &buf) &&
46 !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
47 goto notsupp;
48 }
49 fd = open (name, OPEN_FLAGS);
50 if (fd == -1)
51 return -1;
52 if (!get_flags) {
53 f = (int) set_flags;
54 r = ioctl (fd, EXT2_IOC_SETFLAGS, &f);
55 } else {
56 r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
57 *get_flags = f;
58 }
59 if (r == -1)
60 save_errno = errno;
61 close (fd);
62 if (save_errno)
63 errno = save_errno;
64 return r;
65#endif /* HAVE_EXT2_IOCTLS */
66notsupp:
67 errno = EOPNOTSUPP;
68 return -1;
69}
Note: See TracBrowser for help on using the repository browser.