aboutsummaryrefslogtreecommitdiffstats
path: root/lib/e2p/fsetflags.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/e2p/fsetflags.c')
-rw-r--r--lib/e2p/fsetflags.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/e2p/fsetflags.c b/lib/e2p/fsetflags.c
index 180d48f5..a2584432 100644
--- a/lib/e2p/fsetflags.c
+++ b/lib/e2p/fsetflags.c
@@ -14,10 +14,18 @@
* 93/10/30 - Creation
*/
+#if HAVE_ERRNO_H
#include <errno.h>
-#include <fcntl.h>
+#endif
+#if HAVE_UNISTD_H
#include <unistd.h>
+#endif
+#if HAVE_CHFLAGS
+#include <sys/stat.h> /* For the flag values. */
+#else
+#include <fcntl.h>
#include <sys/ioctl.h>
+#endif
#include <linux/ext2_fs.h>
@@ -25,6 +33,25 @@
int fsetflags (const char * name, 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 chflags (name, bsd_flags);
+#else
+#if HAVE_EXT2_IOCTLS
int fd;
int r;
@@ -34,4 +61,10 @@ int fsetflags (const char * name, unsigned long flags)
r = ioctl (fd, EXT2_IOC_SETFLAGS, &flags);
close (fd);
return r;
+#else /* ! HAVE_EXT2_IOCTLS */
+ extern int errno;
+ errno = EOPNOTSUPP;
+ return -1;
+#endif /* ! HAVE_EXT2_IOCTLS */
+#endif
}