From d89e629e52c3b525424be958de238ed1dc5a0361 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 24 Apr 2005 05:07:59 +0000 Subject: add new subdir for e2fsprogs --- e2fsprogs/e2p/setflags.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 e2fsprogs/e2p/setflags.c (limited to 'e2fsprogs/e2p/setflags.c') diff --git a/e2fsprogs/e2p/setflags.c b/e2fsprogs/e2p/setflags.c new file mode 100644 index 000000000..47c52a7ad --- /dev/null +++ b/e2fsprogs/e2p/setflags.c @@ -0,0 +1,72 @@ +/* + * setflags.c - Set a file flags on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * This file can be redistributed under the terms of the GNU Library General + * Public License + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#include +#include +#if HAVE_EXT2_IOCTLS +#include +#endif + +#include "e2p.h" + +/* + * Deal with lame glibc's that define this function without actually + * implementing it. Can you say "attractive nuisance", boys and girls? + * I knew you could! + */ +#ifdef __linux__ +#undef HAVE_CHFLAGS +#endif + +int setflags (int fd, unsigned long flags) +{ + struct stat buf; +#if HAVE_CHFLAGS + unsigned long bsd_flags = 0; + +#ifdef UF_IMMUTABLE + if (flags & EXT2_IMMUTABLE_FL) + bsd_flags |= UF_IMMUTABLE; +#endif +#ifdef UF_APPEND + if (flags & EXT2_APPEND_FL) + bsd_flags |= UF_APPEND; +#endif +#ifdef UF_NODUMP + if (flags & EXT2_NODUMP_FL) + bsd_flags |= UF_NODUMP; +#endif + + return fchflags (fd, bsd_flags); +#else +#if HAVE_EXT2_IOCTLS + int f; + + if (!fstat(fd, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { + errno = EOPNOTSUPP; + return -1; + } + f = (int) flags; + return ioctl (fd, EXT2_IOC_SETFLAGS, &f); +#endif /* HAVE_EXT2_IOCTLS */ +#endif + errno = EOPNOTSUPP; + return -1; +} -- cgit v1.2.3