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 #ifndef _LARGEFILE_SOURCE
20 #define _LARGEFILE_SOURCE
22 #ifndef _LARGEFILE64_SOURCE
23 #define _LARGEFILE64_SOURCE
33 #include <sys/types.h>
37 #include <sys/ioctl.h>
43 * Deal with lame glibc's that define this function without actually
44 * implementing it. Can you say "attractive nuisance", boys and girls?
52 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
54 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
57 int fsetflags (const char * name, unsigned long flags)
59 #if HAVE_CHFLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS)
60 unsigned long bsd_flags = 0;
63 if (flags & EXT2_IMMUTABLE_FL)
64 bsd_flags |= UF_IMMUTABLE;
67 if (flags & EXT2_APPEND_FL)
68 bsd_flags |= UF_APPEND;
71 if (flags & EXT2_NODUMP_FL)
72 bsd_flags |= UF_NODUMP;
75 return chflags (name, bsd_flags);
76 #else /* !HAVE_CHFLAGS || (APPLE_DARWIN && HAVE_EXT2_IOCTLS) */
78 int fd, r, f, save_errno = 0;
81 if (!lstat(name, &buf) &&
82 !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
86 fd = open (name, OPEN_FLAGS);
90 r = ioctl (fd, EXT2_IOC_SETFLAGS, &f);
96 #else /* APPLE_DARWIN */
98 return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0);
99 #endif /* !APPLE_DARWIN */
103 #endif /* HAVE_EXT2_IOCTLS */