Can you check the attached patch ?

> https://bugs.busybox.net/show_bug.cgi?id=7202
>
>            Summary: add fatattr support
>            Product: Busybox
>            Version: unspecified
>           Platform: PC
>         OS/Version: Linux
>             Status: NEW
>           Severity: enhancement
>           Priority: P5
>          Component: Other
>         AssignedTo: [email protected]
>         ReportedBy: [email protected]
>                 CC: [email protected]
>    Estimated Hours: 0.0
>
>
> I'm a long time user (and have even submitted patches) of busybox.
>
> One of the regular problems I have to deal with is working with FAT32 file
> systems using busybox.
>
> It is really a hassle that fatattr(1) isn't supported under busybox.
>
> I'd do it myself, but I just don't have the time. So, the best I can do is
> submit an enhancement request.
>
> Given that lsattr and chattr are supported, I'd think that supporting
> fatattr
> shouldn't be a big deal. Given that busybox supports creating and checking
> FAT32 file systems, not having fatattr(1) seems like it's almost a bug
> (only 2
> out of 3 components required for working with FAT32 are present, yet for
> EXT2 3
> out of 3 components are present).
>
> Keep up the good work.
>
> --
> Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.
> _______________________________________________
> busybox-cvs mailing list
> [email protected]
> http://lists.busybox.net/mailman/listinfo/busybox-cvs
>
--- busybox-1.22.0/include/applets.src.h
+++ busybox-1.22.0/include/applets.src.h
@@ -138,6 +138,7 @@
 IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP))
 IF_FAKEIDENTD(APPLET(fakeidentd, BB_DIR_USR_SBIN, BB_SUID_DROP))
 IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false))
+IF_FATATTR(APPLET(fatattr, BB_DIR_BIN, BB_SUID_DROP))
 IF_FBSET(APPLET(fbset, BB_DIR_USR_SBIN, BB_SUID_DROP))
 IF_FBSPLASH(APPLET(fbsplash, BB_DIR_SBIN, BB_SUID_DROP))
 IF_FDFLUSH(APPLET_ODDNAME(fdflush, freeramdisk, BB_DIR_BIN, BB_SUID_DROP, fdflush))
--- busybox-1.22.0/e2fsprogs/Config.src
+++ busybox-1.22.0/e2fsprogs/Config.src
@@ -37,6 +37,13 @@
 	help
 	  lsattr lists the file attributes on a second extended file system.
 
+config FATATTR
+	bool "fatattr"
+	default y
+	select PLATFORM_LINUX
+	help
+	  fatattr lists or changes the file attributes on a fat file system.
+
 ### config MKE2FS
 ###	bool "mke2fs"
 ###	default y
--- busybox-1.22.0/e2fsprogs/Kbuild.src
+++ busybox-1.22.0/e2fsprogs/Kbuild.src
@@ -11,5 +11,7 @@
 lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o
 lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
 
+lib-$(CONFIG_FATATTR) += fatattr.o
+
 lib-$(CONFIG_FSCK)    += fsck.o
 lib-$(CONFIG_TUNE2FS) += tune2fs.o
--- busybox-1.22.0/e2fsprogs/fatattr.c
+++ busybox-1.22.0/e2fsprogs/fatattr.c
@@ -0,0 +1,113 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * fatattr.c	- Display or change file attributes on a fat file system
+ *
+ * Copyright 2005 H. Peter Anvin
+ * Busybox'ed (2014) by Pascal Bellard <[email protected]>
+ *
+ * This file can be redistributed under the terms of the GNU General
+ * Public License
+ */
+
+//usage:#define fatattr_trivial_usage
+//usage:       "[-+rhsvda] [FILE]..."
+//usage:#define fatattr_full_usage "\n\n"
+//usage:       "Change file attributes on a fat fs\n"
+//usage:     "\nModifiers:"
+//usage:     "\n	-	Clear attributes"
+//usage:     "\n	+	Set attributes"
+//usage:     "\nAttributes:"
+//usage:     "\n	r	Read only"
+//usage:     "\n	h	Hidden"
+//usage:     "\n	s	System"
+//usage:     "\n	v	Volume label"
+//usage:     "\n	d	Directory"
+//usage:     "\n	a	Archive"
+
+#include "libbb.h"
+/* linux/msdos_fs.h says: */
+#ifndef FAT_IOCTL_GET_ATTRIBUTES
+# define FAT_IOCTL_GET_ATTRIBUTES        _IOR('r', 0x10, __u32)
+#endif
+#ifndef FAT_IOCTL_SET_ATTRIBUTES
+# define FAT_IOCTL_SET_ATTRIBUTES        _IOW('r', 0x11, __u32)
+#endif
+
+#define OPT_ADD 1
+#define OPT_REM 2
+
+struct globals {
+	unsigned long af;
+	unsigned long rf;
+};
+
+/* Currently supports only the FAT flags, not the NTFS ones */
+const char bit_to_char[] = "rhsvda67 ";
+
+static inline unsigned long get_flag(char c)
+{
+	const char *fp = strchr(bit_to_char, c);
+	if (fp)
+		return 1 << (fp - bit_to_char);
+	bb_error_msg_and_die("invalid character '%c' ", c);
+}
+
+static inline int decode_arg(const char *arg, struct globals *gp)
+{
+	unsigned long *fl;
+	char opt = *arg++;
+
+	fl = &gp->af;
+	if (opt == '-') {
+		fl = &gp->rf;
+	} else if (opt != '+') {
+		return 0;
+	}
+
+	while (*arg)
+		*fl |= get_flag(*arg++);
+
+	return 1;
+}
+
+int fatattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int fatattr_main(int argc UNUSED_PARAM, char **argv)
+{
+	struct globals g;
+	char *arg;
+
+	g.rf = g.af = 0;
+
+	/* parse the args */
+	while ((arg = *++argv)) {
+		if (!decode_arg(arg, &g))
+			break;
+	}
+
+	/* run sanity checks on all the arguments given us */
+	if (!*argv)
+		bb_show_usage();
+
+	/* now proceed all the files passed to us */
+	do {
+		int fd, i;
+		uint32_t attr;
+
+		fd = xopen(*argv, O_RDONLY);
+		xioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
+		attr |= g.af;
+		attr &= ~g.rf;
+		if (g.af || g.rf)
+			xioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
+		else {
+			for ( i = 0 ; bit_to_char[i] ; i++ ) {
+				bb_putchar( (attr & 1) ? bit_to_char[i] : ' ' );
+				attr >>= 1;
+			}
+			puts(*argv);
+		}
+		close(fd);
+	} while (*++argv);
+
+	return EXIT_SUCCESS;
+}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to