2 * fsetflags.c - Set a file flags on an ext2 file system
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)
9 * This file may be redistributed under the terms of the GNU Library
10 * General Public License, version 2.
19 #define _LARGEFILE_SOURCE
20 #define _LARGEFILE64_SOURCE
29 #include <sys/types.h>
33 #include <sys/ioctl.h>
39 * Deal with lame glibc's that define this function without actually
40 * implementing it. Can you say "attractive nuisance", boys and girls?
48 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
50 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
53 int fsetflags (const char * name, unsigned long flags)
55 #if HAVE_CHFLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS)
56 unsigned long bsd_flags = 0;
59 if (flags & EXT2_IMMUTABLE_FL)
60 bsd_flags |= UF_IMMUTABLE;
63 if (flags & EXT2_APPEND_FL)
64 bsd_flags |= UF_APPEND;
67 if (flags & EXT2_NODUMP_FL)
68 bsd_flags |= UF_NODUMP;
71 return chflags (name, bsd_flags);
72 #else /* !HAVE_CHFLAGS || (APPLE_DARWIN && HAVE_EXT2_IOCTLS) */
74 int fd, r, f, save_errno = 0;
77 if (!lstat(name, &buf) &&
78 !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
82 fd = open (name, OPEN_FLAGS);
86 r = ioctl (fd, EXT2_IOC_SETFLAGS, &f);
92 #else /* APPLE_DARWIN */
94 return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0);
95 #endif /* !APPLE_DARWIN */
99 #endif /* HAVE_EXT2_IOCTLS */