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)
8 * This file can be redistributed under the terms of the GNU Library General
17 #define _LARGEFILE_SOURCE
18 #define _LARGEFILE64_SOURCE
26 #include <sys/types.h>
30 #include <sys/ioctl.h>
36 * Deal with lame glibc's that define this function without actually
37 * implementing it. Can you say "attractive nuisance", boys and girls?
45 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
47 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
50 int fsetflags (const char * name, unsigned long flags)
53 #if HAVE_CHFLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS)
54 unsigned long bsd_flags = 0;
57 if (flags & EXT2_IMMUTABLE_FL)
58 bsd_flags |= UF_IMMUTABLE;
61 if (flags & EXT2_APPEND_FL)
62 bsd_flags |= UF_APPEND;
65 if (flags & EXT2_NODUMP_FL)
66 bsd_flags |= UF_NODUMP;
69 return chflags (name, bsd_flags);
72 int fd, r, f, save_errno = 0;
74 if (!lstat(name, &buf) &&
75 !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
79 fd = open (name, OPEN_FLAGS);
83 r = ioctl (fd, EXT2_IOC_SETFLAGS, &f);
91 return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0);
94 #endif /* HAVE_EXT2_IOCTLS */