wok-6.x rev 517

Busybox: Add top and cpio (with cpio -o -H new support)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Apr 08 14:42:37 2008 +0000 (2008-04-08)
parents f43146da6d21
children 70b2d74dff92
files busybox/receipt busybox/stuff/busybox-1.10.0-cpio.u busybox/stuff/busybox-1.10.0-vcsa2txt.u busybox/stuff/busybox-1.10.0.config
line diff
     1.1 --- a/busybox/receipt	Tue Apr 08 14:23:22 2008 +0000
     1.2 +++ b/busybox/receipt	Tue Apr 08 14:42:37 2008 +0000
     1.3 @@ -16,6 +16,7 @@
     1.4  {
     1.5      patch -p0 < stuff/$PACKAGE-$VERSION-patch.u
     1.6      patch -p0 < stuff/$PACKAGE-$VERSION-vcsa2txt.u
     1.7 +    patch -p0 < stuff/$PACKAGE-$VERSION-cpio.u
     1.8      cp stuff/$PACKAGE-$VERSION.config $PACKAGE-$VERSION/.config
     1.9      cd $PACKAGE-$VERSION
    1.10      make oldconfig
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/busybox/stuff/busybox-1.10.0-cpio.u	Tue Apr 08 14:42:37 2008 +0000
     2.3 @@ -0,0 +1,220 @@
     2.4 +diff -purN busybox-1.10.0/archival/Config.in busybox/archival/Config.in
     2.5 +--- busybox-1.10.0/archival/Config.in	2008-03-29 21:47:37.000000000 +0100
     2.6 ++++ busybox-1.10.0/archival/Config.in	2008-03-29 21:47:37.000000000 +0100
     2.7 +@@ -78,6 +78,14 @@ config CPIO
     2.8 + 	  Unless you have a specific application which requires cpio, you should
     2.9 + 	  probably say N here.
    2.10 + 
    2.11 ++config FEATURE_CPIO_O
    2.12 ++	bool "Support for archive creation"
    2.13 ++	default n
    2.14 ++	depends on CPIO
    2.15 ++	help
    2.16 ++	  This implementation of cpio can create cpio archives in the "newc"
    2.17 ++	  format only.
    2.18 ++
    2.19 + config DPKG
    2.20 + 	bool "dpkg"
    2.21 + 	default n
    2.22 +diff -purN busybox-1.10.0/archival/cpio.c busybox/archival/cpio.c
    2.23 +--- busybox-1.10.0/archival/cpio.c	2008-03-29 21:47:55.000000000 +0100
    2.24 ++++ busybox-1.10.0/archival/cpio.c	2008-03-29 21:47:55.000000000 +0100
    2.25 +@@ -21,12 +21,146 @@
    2.26 + #define CPIO_OPT_FILE                   0x10
    2.27 + #define CPIO_OPT_CREATE_LEADING_DIR     0x20
    2.28 + #define CPIO_OPT_PRESERVE_MTIME         0x40
    2.29 ++#define CPIO_OPT_CREATE                 0x80
    2.30 ++#define CPIO_OPT_FORMAT                0x100
    2.31 ++
    2.32 ++#if ENABLE_FEATURE_CPIO_O
    2.33 ++static void cpio_pad(off_t *size, int n)
    2.34 ++{
    2.35 ++    int i;
    2.36 ++    for (*size += i = (-*size) & n; --i >= 0; bb_putchar(0));
    2.37 ++}
    2.38 ++
    2.39 ++static void cpio_o(void)
    2.40 ++{
    2.41 ++    struct name_s {
    2.42 ++        struct name_s *next;
    2.43 ++        char name[0];
    2.44 ++    };
    2.45 ++    struct inodes_s {
    2.46 ++        struct name_s *names;
    2.47 ++        struct inodes_s *next;
    2.48 ++        struct stat st;
    2.49 ++    } *links = NULL;
    2.50 ++    off_t bytes = 0; // output bytes count
    2.51 ++#if CONFIG_FEATURE_COPYBUF_KB < 1
    2.52 ++    char buf[1024];
    2.53 ++#else
    2.54 ++    char buf[CONFIG_FEATURE_COPYBUF_KB * 1024];
    2.55 ++#endif
    2.56 ++	
    2.57 ++    while (1) {
    2.58 ++        const char *name = "TRAILER!!!";
    2.59 ++        char *line = xmalloc_getline(stdin);
    2.60 ++        // allocate inode struct each loop to avoid struct stat copy
    2.61 ++        struct inodes_s *inode = xzalloc(sizeof(*inode)); // die if fail
    2.62 ++
    2.63 ++        inode->st.st_nlink++; // =1
    2.64 ++        if (line) {
    2.65 ++            /* Strip leading `./' from the filename.  */
    2.66 ++            for (name = line; name[0] == '.' && name[1] == '/';) {
    2.67 ++                while (*++name == '/');
    2.68 ++            }
    2.69 ++            if (!*name) goto free_and_continue; // line empty
    2.70 ++            if (lstat(name, &inode->st)) {
    2.71 ++          abort_cpio_o:
    2.72 ++                bb_perror_msg_and_die(name);
    2.73 ++            }
    2.74 ++        }
    2.75 ++
    2.76 ++        // hard links will are stored and will be processed later
    2.77 ++        if (!S_ISDIR(inode->st.st_mode) && inode->st.st_nlink > 1) {
    2.78 ++            struct name_s *n;
    2.79 ++            struct inodes_s *l;
    2.80 ++
    2.81 ++            for (l = links; l && l->st.st_ino != inode->st.st_ino; l = l->next);
    2.82 ++            if (l == NULL) { // not found: new hard links set
    2.83 ++                l = inode; // l->names = NULL; l->st = inode->st
    2.84 ++                l->next = links;
    2.85 ++                links = l;
    2.86 ++            }
    2.87 ++            n = xmalloc(sizeof(*n) + strlen(name) + 1); // die if fail
    2.88 ++            strcpy(n->name, name);
    2.89 ++            n->next = l->names;
    2.90 ++            l->names = n; // will not free inode if l == inode
    2.91 ++            goto free_and_continue;
    2.92 ++        }
    2.93 ++
    2.94 ++        // no more files ? process hard links
    2.95 ++        if (!line && links) {
    2.96 ++            struct name_s *n;
    2.97 ++
    2.98 ++            free(inode); // trailer pseudo inode
    2.99 ++            inode = links;
   2.100 ++            n = links->names;
   2.101 ++            name = line = xstrdup(n->name);    // line will free *name memory
   2.102 ++            links->names = n->next;
   2.103 ++            if (links->names == NULL)          // inode will free *links memory
   2.104 ++                links = links->next;
   2.105 ++            else links->st.st_size = 0;        // not last link: no data
   2.106 ++            free(n);
   2.107 ++        }
   2.108 ++
   2.109 ++        bytes += printf("070701%08lx%08lx%08lx%08lx%08lx%08lx%08lx"
   2.110 ++                        "%08lx%08lx%08lx%08lx%08lx%08lx%s%c",
   2.111 ++                        (unsigned long) inode->st.st_ino,
   2.112 ++                        (unsigned long) inode->st.st_mode, 
   2.113 ++                        (unsigned long) inode->st.st_uid,
   2.114 ++                        (unsigned long) inode->st.st_gid,
   2.115 ++                        (unsigned long) inode->st.st_nlink,
   2.116 ++                        (unsigned long) inode->st.st_mtime,
   2.117 ++                        (unsigned long) inode->st.st_size,
   2.118 ++                        (unsigned long) major(inode->st.st_dev),
   2.119 ++                        (unsigned long) minor(inode->st.st_dev),
   2.120 ++                        (unsigned long) major(inode->st.st_rdev), 
   2.121 ++                        (unsigned long) minor(inode->st.st_rdev),
   2.122 ++                        strlen(name) + 1UL, 0UL, name, 0);
   2.123 ++
   2.124 ++        cpio_pad(&bytes, (line) ? 4-1 : 512-1);
   2.125 ++
   2.126 ++        if (inode->st.st_size) {
   2.127 ++
   2.128 ++            if (S_ISLNK(inode->st.st_mode)) {
   2.129 ++                char *lpath = xmalloc_readlink_or_warn(name);
   2.130 ++
   2.131 ++                if (!lpath) goto abort_cpio_o;
   2.132 ++                bytes += printf("%s", lpath);
   2.133 ++                free(lpath);
   2.134 ++            }
   2.135 ++
   2.136 ++            if (S_ISREG(inode->st.st_mode)) {
   2.137 ++                int fd = open_or_warn(name, O_RDONLY);
   2.138 ++
   2.139 ++                while (1) {
   2.140 ++                    int len = full_read(fd, buf, sizeof(buf));
   2.141 ++                    if (len < 0) goto abort_cpio_o;
   2.142 ++                    if (len == 0) break;
   2.143 ++                    bytes += len;
   2.144 ++                    fwrite(buf, 1, len, stdout);
   2.145 ++                }
   2.146 ++                close(fd);
   2.147 ++            }
   2.148 ++
   2.149 ++            cpio_pad(&bytes, 4-1);
   2.150 ++        }
   2.151 ++
   2.152 ++        if (!line) return; // was trailer
   2.153 ++
   2.154 ++    free_and_continue:
   2.155 ++        if (!inode->names) free(inode);
   2.156 ++            free(line);
   2.157 ++    }
   2.158 ++}
   2.159 ++#endif
   2.160 + 
   2.161 + int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
   2.162 + int cpio_main(int argc, char **argv)
   2.163 + {
   2.164 + 	archive_handle_t *archive_handle;
   2.165 + 	char *cpio_filename = NULL;
   2.166 ++#if ENABLE_FEATURE_CPIO_O
   2.167 ++	const char *cpio_fmt = "";
   2.168 ++#endif
   2.169 + 	unsigned opt;
   2.170 + 
   2.171 + 	/* Initialise */
   2.172 +@@ -35,10 +169,26 @@ int cpio_main(int argc, char **argv)
   2.173 + 	archive_handle->seek = seek_by_read;
   2.174 + 	archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
   2.175 + 
   2.176 ++#if ENABLE_FEATURE_CPIO_O
   2.177 ++	opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename,&cpio_fmt);
   2.178 ++
   2.179 ++	if (opt & CPIO_OPT_CREATE) {
   2.180 ++		if (*cpio_fmt != 'n')
   2.181 ++			goto cpio_show_usage;
   2.182 ++		if (cpio_filename) {
   2.183 ++			fclose(stdout);
   2.184 ++			stdout = fopen(cpio_filename,"w");
   2.185 ++		}
   2.186 ++		cpio_o();
   2.187 ++		return EXIT_SUCCESS;
   2.188 ++	}
   2.189 ++#else
   2.190 + 	opt = getopt32(argv, "ituvF:dm", &cpio_filename);
   2.191 ++#endif
   2.192 + 
   2.193 + 	/* One of either extract or test options must be given */
   2.194 + 	if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
   2.195 ++ cpio_show_usage:
   2.196 + 		bb_show_usage();
   2.197 + 	}
   2.198 + 
   2.199 +diff -purN busybox-1.10.0/include/usage.h busybox/include/usage.h
   2.200 +--- busybox-1.10.0/include/usage.h	2008-03-29 21:48:22.000000000 +0100
   2.201 ++++ busybox-1.10.0/include/usage.h	2008-03-29 21:48:22.000000000 +0100
   2.202 +@@ -496,13 +496,19 @@
   2.203 +      "\n	-l,-s	Create (sym)links" \
   2.204 + 
   2.205 + #define cpio_trivial_usage \
   2.206 +-       "-[dimtuv][F cpiofile]"
   2.207 ++       "-[dim" USE_FEATURE_CPIO_O("o") "tuv][F cpiofile]" \
   2.208 ++       USE_FEATURE_CPIO_O( "[H newc]" ) 
   2.209 + #define cpio_full_usage \
   2.210 +-       "Extract or list files from a cpio archive\n" \
   2.211 ++       "Extract or list files from a cpio archive" \
   2.212 ++       USE_FEATURE_CPIO_O( ", or create a cpio archive" ) "\n" \
   2.213 +        "Main operation mode:" \
   2.214 +      "\n	d	Make leading directories" \
   2.215 +      "\n	i	Extract" \
   2.216 +      "\n	m	Preserve mtime" \
   2.217 ++       USE_FEATURE_CPIO_O( \
   2.218 ++     "\n	o	Create" \
   2.219 ++     "\n	H newc	Define format" \
   2.220 ++       ) \
   2.221 +      "\n	t	List" \
   2.222 +      "\n	v	Verbose" \
   2.223 +      "\n	u	Unconditional overwrite" \
     3.1 --- a/busybox/stuff/busybox-1.10.0-vcsa2txt.u	Tue Apr 08 14:23:22 2008 +0000
     3.2 +++ b/busybox/stuff/busybox-1.10.0-vcsa2txt.u	Tue Apr 08 14:42:37 2008 +0000
     3.3 @@ -11,7 +11,7 @@
     3.4  
     3.5  --- busybox-1.10.0/include/usage.h	Sat Mar 22 02:31:50 2008
     3.6  +++ busybox-1.10.0/include/usage.h	Sat Mar 22 02:31:50 2008
     3.7 -@@ -4313,6 +4313,13 @@
     3.8 +@@ -4314,6 +4314,13 @@
     3.9        "\n	set_ingress_map	[vlan-name] [skb_priority] [vlan_qos]" \
    3.10        "\n	set_name_type	[name-type]" \
    3.11   
     4.1 --- a/busybox/stuff/busybox-1.10.0.config	Tue Apr 08 14:23:22 2008 +0000
     4.2 +++ b/busybox/stuff/busybox-1.10.0.config	Tue Apr 08 14:42:37 2008 +0000
     4.3 @@ -1,4 +1,4 @@
     4.4 -# TODO: add RESET CLEAR RMMOD LSMOD, patch CPIO
     4.5 +# TODO: add RESET CLEAR RMMOD LSMOD
     4.6  #
     4.7  # Automatically generated make config: don't edit
     4.8  # Busybox version: 1.10.0
     4.9 @@ -100,7 +100,8 @@
    4.10  # CONFIG_FEATURE_AR_LONG_FILENAMES is not set
    4.11  CONFIG_BUNZIP2=y
    4.12  # CONFIG_BZIP2 is not set
    4.13 -# CONFIG_CPIO is not set
    4.14 +CONFIG_CPIO=y
    4.15 +CONFIG_FEATURE_CPIO_O=y
    4.16  CONFIG_DPKG=y
    4.17  CONFIG_DPKG_DEB=y
    4.18  CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
    4.19 @@ -487,7 +488,7 @@
    4.20  CONFIG_FEATURE_USE_TERMIOS=y
    4.21  CONFIG_VOLUMEID=y
    4.22  CONFIG_FEATURE_VOLUMEID_EXT=y
    4.23 -# CONFIG_FEATURE_VOLUMEID_REISERFS is not set
    4.24 +CONFIG_FEATURE_VOLUMEID_REISERFS=y
    4.25  CONFIG_FEATURE_VOLUMEID_FAT=y
    4.26  # CONFIG_FEATURE_VOLUMEID_HFS is not set
    4.27  # CONFIG_FEATURE_VOLUMEID_JFS is not set
    4.28 @@ -730,11 +731,11 @@
    4.29  # CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
    4.30  CONFIG_RENICE=y
    4.31  CONFIG_BB_SYSCTL=y
    4.32 -# CONFIG_TOP is not set
    4.33 -# CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE is not set
    4.34 -# CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS is not set
    4.35 +CONFIG_TOP=y
    4.36 +CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
    4.37 +CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
    4.38  # CONFIG_FEATURE_TOP_DECIMALS is not set
    4.39 -# CONFIG_FEATURE_TOPMEM is not set
    4.40 +CONFIG_FEATURE_TOPMEM=y
    4.41  CONFIG_UPTIME=y
    4.42  CONFIG_WATCH=y
    4.43