wok-next rev 16773

busybox: add fatattr
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jun 20 15:21:26 2014 +0200 (2014-06-20)
parents 3b67429fe7eb
children 7893304f1666
files busybox/receipt busybox/stuff/busybox-1.22-fatattr.u busybox/stuff/busybox-1.22.config busybox/stuff/busybox-1.22.config-ssfs busybox/stuff/busybox-1.22.config-static
line diff
     1.1 --- a/busybox/receipt	Thu Jun 19 21:46:00 2014 +0000
     1.2 +++ b/busybox/receipt	Fri Jun 20 15:21:26 2014 +0200
     1.3 @@ -43,6 +43,7 @@
     1.4  diff.u
     1.5  diet.u
     1.6  losetup.u
     1.7 +fatattr.u
     1.8  EOT
     1.9      cp $stuff/$PACKAGE-${VERSION%.*}.config .config
    1.10  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/busybox/stuff/busybox-1.22-fatattr.u	Fri Jun 20 15:21:26 2014 +0200
     2.3 @@ -0,0 +1,152 @@
     2.4 +--- busybox-1.22.0/include/applets.src.h
     2.5 ++++ busybox-1.22.0/include/applets.src.h
     2.6 +@@ -138,6 +138,7 @@
     2.7 + IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP))
     2.8 + IF_FAKEIDENTD(APPLET(fakeidentd, BB_DIR_USR_SBIN, BB_SUID_DROP))
     2.9 + IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false))
    2.10 ++IF_FATATTR(APPLET(fatattr, BB_DIR_BIN, BB_SUID_DROP))
    2.11 + IF_FBSET(APPLET(fbset, BB_DIR_USR_SBIN, BB_SUID_DROP))
    2.12 + IF_FBSPLASH(APPLET(fbsplash, BB_DIR_SBIN, BB_SUID_DROP))
    2.13 + IF_FDFLUSH(APPLET_ODDNAME(fdflush, freeramdisk, BB_DIR_BIN, BB_SUID_DROP, fdflush))
    2.14 +--- busybox-1.22.0/e2fsprogs/Config.src
    2.15 ++++ busybox-1.22.0/e2fsprogs/Config.src
    2.16 +@@ -37,6 +37,13 @@
    2.17 + 	help
    2.18 + 	  lsattr lists the file attributes on a second extended file system.
    2.19 + 
    2.20 ++config FATATTR
    2.21 ++	bool "fatattr"
    2.22 ++	default y
    2.23 ++	select PLATFORM_LINUX
    2.24 ++	help
    2.25 ++	  fatattr lists or changes the file attributes on a fat file system.
    2.26 ++
    2.27 + ### config MKE2FS
    2.28 + ###	bool "mke2fs"
    2.29 + ###	default y
    2.30 +--- busybox-1.22.0/e2fsprogs/Kbuild.src
    2.31 ++++ busybox-1.22.0/e2fsprogs/Kbuild.src
    2.32 +@@ -11,5 +11,7 @@
    2.33 + lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o
    2.34 + lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
    2.35 + 
    2.36 ++lib-$(CONFIG_FATATTR) += fatattr.o
    2.37 ++
    2.38 + lib-$(CONFIG_FSCK)    += fsck.o
    2.39 + lib-$(CONFIG_TUNE2FS) += tune2fs.o
    2.40 +--- busybox-1.22.0/e2fsprogs/fatattr.c
    2.41 ++++ busybox-1.22.0/e2fsprogs/fatattr.c
    2.42 +@@ -0,0 +1,113 @@
    2.43 ++/* vi: set sw=4 ts=4: */
    2.44 ++/*
    2.45 ++ * fatattr.c	- Display or change file attributes on a fat file system
    2.46 ++ *
    2.47 ++ * Copyright 2005 H. Peter Anvin
    2.48 ++ * Busybox'ed (2014) by Pascal Bellard <pascal.bellard@ads-lu.com>
    2.49 ++ *
    2.50 ++ * This file can be redistributed under the terms of the GNU General
    2.51 ++ * Public License
    2.52 ++ */
    2.53 ++
    2.54 ++//usage:#define fatattr_trivial_usage
    2.55 ++//usage:       "[-+rhsvda] [FILE]..."
    2.56 ++//usage:#define fatattr_full_usage "\n\n"
    2.57 ++//usage:       "Change file attributes on a fat fs\n"
    2.58 ++//usage:     "\nModifiers:"
    2.59 ++//usage:     "\n	-	Clear attributes"
    2.60 ++//usage:     "\n	+	Set attributes"
    2.61 ++//usage:     "\nAttributes:"
    2.62 ++//usage:     "\n	r	Read only"
    2.63 ++//usage:     "\n	h	Hidden"
    2.64 ++//usage:     "\n	s	System"
    2.65 ++//usage:     "\n	v	Volume label"
    2.66 ++//usage:     "\n	d	Directory"
    2.67 ++//usage:     "\n	a	Archive"
    2.68 ++
    2.69 ++#include "libbb.h"
    2.70 ++/* linux/msdos_fs.h says: */
    2.71 ++#ifndef FAT_IOCTL_GET_ATTRIBUTES
    2.72 ++# define FAT_IOCTL_GET_ATTRIBUTES        _IOR('r', 0x10, __u32)
    2.73 ++#endif
    2.74 ++#ifndef FAT_IOCTL_SET_ATTRIBUTES
    2.75 ++# define FAT_IOCTL_SET_ATTRIBUTES        _IOW('r', 0x11, __u32)
    2.76 ++#endif
    2.77 ++
    2.78 ++#define OPT_ADD 1
    2.79 ++#define OPT_REM 2
    2.80 ++
    2.81 ++struct globals {
    2.82 ++	unsigned long af;
    2.83 ++	unsigned long rf;
    2.84 ++};
    2.85 ++
    2.86 ++/* Currently supports only the FAT flags, not the NTFS ones */
    2.87 ++const char bit_to_char[] = "rhsvda67 ";
    2.88 ++
    2.89 ++static inline unsigned long get_flag(char c)
    2.90 ++{
    2.91 ++	const char *fp = strchr(bit_to_char, c);
    2.92 ++	if (fp)
    2.93 ++		return 1 << (fp - bit_to_char);
    2.94 ++	bb_error_msg_and_die("invalid character '%c' ", c);
    2.95 ++}
    2.96 ++
    2.97 ++static inline int decode_arg(const char *arg, struct globals *gp)
    2.98 ++{
    2.99 ++	unsigned long *fl;
   2.100 ++	char opt = *arg++;
   2.101 ++
   2.102 ++	fl = &gp->af;
   2.103 ++	if (opt == '-') {
   2.104 ++		fl = &gp->rf;
   2.105 ++	} else if (opt != '+') {
   2.106 ++		return 0;
   2.107 ++	}
   2.108 ++
   2.109 ++	while (*arg)
   2.110 ++		*fl |= get_flag(*arg++);
   2.111 ++
   2.112 ++	return 1;
   2.113 ++}
   2.114 ++
   2.115 ++int fatattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
   2.116 ++int fatattr_main(int argc UNUSED_PARAM, char **argv)
   2.117 ++{
   2.118 ++	struct globals g;
   2.119 ++	char *arg;
   2.120 ++
   2.121 ++	g.rf = g.af = 0;
   2.122 ++
   2.123 ++	/* parse the args */
   2.124 ++	while ((arg = *++argv)) {
   2.125 ++		if (!decode_arg(arg, &g))
   2.126 ++			break;
   2.127 ++	}
   2.128 ++
   2.129 ++	/* run sanity checks on all the arguments given us */
   2.130 ++	if (!*argv)
   2.131 ++		bb_show_usage();
   2.132 ++
   2.133 ++	/* now proceed all the files passed to us */
   2.134 ++	do {
   2.135 ++		int fd, i;
   2.136 ++		uint32_t attr;
   2.137 ++
   2.138 ++		fd = xopen(*argv, O_RDONLY);
   2.139 ++		xioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
   2.140 ++		attr |= g.af;
   2.141 ++		attr &= ~g.rf;
   2.142 ++		if (g.af || g.rf)
   2.143 ++			xioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
   2.144 ++		else {
   2.145 ++			for ( i = 0 ; bit_to_char[i] ; i++ ) {
   2.146 ++				bb_putchar( (attr & 1) ? bit_to_char[i] : ' ' );
   2.147 ++				attr >>= 1;
   2.148 ++			}
   2.149 ++			puts(*argv);
   2.150 ++		}
   2.151 ++		close(fd);
   2.152 ++	} while (*++argv);
   2.153 ++
   2.154 ++	return EXIT_SUCCESS;
   2.155 ++}
     3.1 --- a/busybox/stuff/busybox-1.22.config	Thu Jun 19 21:46:00 2014 +0000
     3.2 +++ b/busybox/stuff/busybox-1.22.config	Fri Jun 20 15:21:26 2014 +0200
     3.3 @@ -489,6 +489,7 @@
     3.4  CONFIG_CHATTR=y
     3.5  # CONFIG_FSCK is not set
     3.6  CONFIG_LSATTR=y
     3.7 +CONFIG_FATATTR=y
     3.8  CONFIG_TUNE2FS=y
     3.9  
    3.10  #
     4.1 --- a/busybox/stuff/busybox-1.22.config-ssfs	Thu Jun 19 21:46:00 2014 +0000
     4.2 +++ b/busybox/stuff/busybox-1.22.config-ssfs	Fri Jun 20 15:21:26 2014 +0200
     4.3 @@ -489,6 +489,7 @@
     4.4  # CONFIG_CHATTR is not set
     4.5  # CONFIG_FSCK is not set
     4.6  # CONFIG_LSATTR is not set
     4.7 +# CONFIG_FATATTR is not set
     4.8  # CONFIG_TUNE2FS is not set
     4.9  
    4.10  #
     5.1 --- a/busybox/stuff/busybox-1.22.config-static	Thu Jun 19 21:46:00 2014 +0000
     5.2 +++ b/busybox/stuff/busybox-1.22.config-static	Fri Jun 20 15:21:26 2014 +0200
     5.3 @@ -489,6 +489,7 @@
     5.4  # CONFIG_CHATTR is not set
     5.5  # CONFIG_FSCK is not set
     5.6  # CONFIG_LSATTR is not set
     5.7 +# CONFIG_FATATTR is not set
     5.8  # CONFIG_TUNE2FS is not set
     5.9  
    5.10  #