# HG changeset patch # User Pascal Bellard # Date 1403270486 -7200 # Node ID 79c239d4e13fe24eba28a4b08e3d596cf5e13c6d # Parent 3b67429fe7ebcf8d252606c4d075fc0c6dd2abdf busybox: add fatattr diff -r 3b67429fe7eb -r 79c239d4e13f busybox/receipt --- a/busybox/receipt Thu Jun 19 21:46:00 2014 +0000 +++ b/busybox/receipt Fri Jun 20 15:21:26 2014 +0200 @@ -43,6 +43,7 @@ diff.u diet.u losetup.u +fatattr.u EOT cp $stuff/$PACKAGE-${VERSION%.*}.config .config } diff -r 3b67429fe7eb -r 79c239d4e13f busybox/stuff/busybox-1.22-fatattr.u --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/busybox/stuff/busybox-1.22-fatattr.u Fri Jun 20 15:21:26 2014 +0200 @@ -0,0 +1,152 @@ +--- 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 ++ * ++ * 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; ++} diff -r 3b67429fe7eb -r 79c239d4e13f busybox/stuff/busybox-1.22.config --- a/busybox/stuff/busybox-1.22.config Thu Jun 19 21:46:00 2014 +0000 +++ b/busybox/stuff/busybox-1.22.config Fri Jun 20 15:21:26 2014 +0200 @@ -489,6 +489,7 @@ CONFIG_CHATTR=y # CONFIG_FSCK is not set CONFIG_LSATTR=y +CONFIG_FATATTR=y CONFIG_TUNE2FS=y # diff -r 3b67429fe7eb -r 79c239d4e13f busybox/stuff/busybox-1.22.config-ssfs --- a/busybox/stuff/busybox-1.22.config-ssfs Thu Jun 19 21:46:00 2014 +0000 +++ b/busybox/stuff/busybox-1.22.config-ssfs Fri Jun 20 15:21:26 2014 +0200 @@ -489,6 +489,7 @@ # CONFIG_CHATTR is not set # CONFIG_FSCK is not set # CONFIG_LSATTR is not set +# CONFIG_FATATTR is not set # CONFIG_TUNE2FS is not set # diff -r 3b67429fe7eb -r 79c239d4e13f busybox/stuff/busybox-1.22.config-static --- a/busybox/stuff/busybox-1.22.config-static Thu Jun 19 21:46:00 2014 +0000 +++ b/busybox/stuff/busybox-1.22.config-static Fri Jun 20 15:21:26 2014 +0200 @@ -489,6 +489,7 @@ # CONFIG_CHATTR is not set # CONFIG_FSCK is not set # CONFIG_LSATTR is not set +# CONFIG_FATATTR is not set # CONFIG_TUNE2FS is not set #