From 464df1d5e5ab1322e2dd0a7796939fff1aeefa9a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:49:25 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- lib/e2p/setflags.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/e2p/setflags.c (limited to 'lib/e2p/setflags.c') diff --git a/lib/e2p/setflags.c b/lib/e2p/setflags.c new file mode 100644 index 0000000..0f6a3e0 --- /dev/null +++ b/lib/e2p/setflags.c @@ -0,0 +1,77 @@ +/* + * 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) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#include "config.h" +#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) +{ +#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 /* ! HAVE_CHFLAGS */ +#if HAVE_EXT2_IOCTLS + struct stat buf; + 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); +#else + errno = EOPNOTSUPP; + return -1; +#endif /* HAVE_EXT2_IOCTLS */ +#endif /* HAVE_CHFLAGS */ +} -- cgit v1.2.3