summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--openembedded/packages/genext2fs/genext2fs-1.3/autosize.patch339
-rw-r--r--openembedded/packages/genext2fs/genext2fs-1.3/misc.patch2143
-rw-r--r--openembedded/packages/genext2fs/genext2fs-native_1.3.bb11
-rw-r--r--openembedded/packages/genext2fs/genext2fs.inc4
-rw-r--r--openembedded/packages/genext2fs/genext2fs_1.3.bb15
5 files changed, 2512 insertions, 0 deletions
diff --git a/openembedded/packages/genext2fs/genext2fs-1.3/autosize.patch b/openembedded/packages/genext2fs/genext2fs-1.3/autosize.patch
new file mode 100644
index 0000000000..a4318a6eee
--- /dev/null
+++ b/openembedded/packages/genext2fs/genext2fs-1.3/autosize.patch
@@ -0,0 +1,339 @@
+
+#
+# Patch managed by http://www.holgerschurig.de/patcher.html
+#
+
+--- genext2fs-1.3.orig/genext2fs.c~autosize.patch
++++ genext2fs-1.3.orig/genext2fs.c
+@@ -4,6 +4,11 @@
+ // ext2 filesystem generator for embedded systems
+ // Copyright (C) 2000 Xavier Bestel <xavier.bestel@free.fr>
+ //
++// 'du' portions taken from coreutils/du.c in busybox:
++// Copyright (C) 1999,2000 by Lineo, inc. and John Beppu
++// Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org>
++// Copyright (C) 2002 Edward Betts <edward@debian.org>
++//
+ // This program is free software; you can redistribute it and/or
+ // modify it under the terms of the GNU General Public License
+ // as published by the Free Software Foundation; version
+@@ -79,9 +84,93 @@
+ #include <ctype.h>
+ #include <errno.h>
+ #include <fcntl.h>
++#include <sys/types.h>
++#include <getopt.h>
++
++#define HASH_SIZE 311 /* Should be prime */
++#define hash_inode(i) ((i) % HASH_SIZE)
++
++typedef struct ino_dev_hash_bucket_struct {
++ struct ino_dev_hash_bucket_struct *next;
++ ino_t ino;
++ dev_t dev;
++ char name[1];
++} ino_dev_hashtable_bucket_t;
++
++static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
++
++struct stats {
++ unsigned long nblocks;
++ unsigned long ninodes;
++};
++
++int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
++{
++ ino_dev_hashtable_bucket_t *bucket;
++
++ bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
++ while (bucket != NULL) {
++ if ((bucket->ino == statbuf->st_ino) &&
++ (bucket->dev == statbuf->st_dev))
++ {
++ if (name) *name = bucket->name;
++ return 1;
++ }
++ bucket = bucket->next;
++ }
++ return 0;
++}
++
++/* Add statbuf to statbuf hash table */
++void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
++{
++ int i;
++ size_t s;
++ ino_dev_hashtable_bucket_t *bucket;
++
++ i = hash_inode(statbuf->st_ino);
++ s = name ? strlen(name) : 0;
++ bucket = malloc(sizeof(ino_dev_hashtable_bucket_t) + s);
++ bucket->ino = statbuf->st_ino;
++ bucket->dev = statbuf->st_dev;
++ if (name)
++ strcpy(bucket->name, name);
++ else
++ bucket->name[0] = '\0';
++ bucket->next = ino_dev_hashtable[i];
++ ino_dev_hashtable[i] = bucket;
++}
++
++/* Clear statbuf hash table */
++void reset_ino_dev_hashtable(void)
++{
++ int i;
++ ino_dev_hashtable_bucket_t *bucket;
++
++ for (i = 0; i < HASH_SIZE; i++) {
++ while (ino_dev_hashtable[i] != NULL) {
++ bucket = ino_dev_hashtable[i]->next;
++ free(ino_dev_hashtable[i]);
++ ino_dev_hashtable[i] = bucket;
++ }
++ }
++}
+
++static int count_ino_in_hashtable(void)
++{
++ long count = 0;
++ int i;
+
++ for (i = 0; i < HASH_SIZE; i++) {
++ ino_dev_hashtable_bucket_t *bucket = ino_dev_hashtable[i];
++ while (bucket != NULL) {
++ count++;
++ bucket = bucket->next;
++ }
++ }
+
++ return count;
++}
+
+ // block size
+
+@@ -1178,6 +1267,38 @@
+ return n;
+ }
+
++void stats_from_dir(struct stats *stats)
++{
++ DIR *dh;
++ struct dirent *dent;
++ struct stat st;
++ if(!(dh = opendir(".")))
++ perror_msg_and_die(".");
++ while((dent = readdir(dh)))
++ {
++ if((!strcmp(dent->d_name, ".")) || (!strcmp(dent->d_name, "..")))
++ continue;
++ lstat(dent->d_name, &st);
++ if (S_ISLNK(st.st_mode)) {
++ stats->ninodes++;
++ } else if (S_ISDIR(st.st_mode)) {
++ if(chdir(dent->d_name) < 0)
++ perror_msg_and_die(dent->d_name);
++ stats->ninodes++;
++ stats_from_dir(stats);
++ chdir("..");
++ } else {
++ if (!is_in_ino_dev_hashtable(&st, NULL)) {
++ add_to_ino_dev_hashtable(&st, NULL);
++ stats->nblocks += (st.st_blocks >> 1);
++ stats->ninodes++;
++ }
++ }
++ }
++ closedir(dh);
++ reset_ino_dev_hashtable();
++}
++
+ // adds a tree of entries to the filesystem from current dir
+ void add2fs_from_dir(filesystem *fs, uint32 this_nod)
+ {
+@@ -1436,7 +1557,6 @@
+ free_blocks_per_group = nbblocks_per_group - overhead_per_group;
+ }
+ nbblocks = nbblocks_per_group * nbgroups + 1;
+-
+
+ if(!(fs = (filesystem*)calloc(nbblocks, BLOCKSIZE)))
+ error_msg_and_die("not enough memory for filesystem");
+@@ -1891,6 +2011,7 @@
+ Regular files must exist in the target root directory. If a char,
+ block, fifo, or directory does not exist, it will be created.
+ */
++
+ static int interpret_table_entry(filesystem *fs, char *line)
+ {
+ char type, *name = NULL, *tmp, *dir, *bname;
+@@ -2026,6 +2147,52 @@
+ return 0;
+ }
+
++static int stats_from_table_entry(char *line, struct stats *stats)
++{
++ char type, *name = NULL, *tmp, *dir, *bname;
++ unsigned long mode = 0755, uid = 0, gid = 0, major = 0, minor = 0;
++ unsigned long start = 0, increment = 1, count = 0;
++ inode *entry;
++
++ if (sscanf (line, "%" SCANF_PREFIX "s %c %lo %lu %lu %lu %lu %lu %lu %lu",
++ SCANF_STRING(name), &type, &mode, &uid, &gid, &major, &minor,
++ &start, &increment, &count) < 0)
++ {
++ return 1;
++ }
++
++ if (!strcmp(name, "/")) {
++ error_msg_and_die("Device table entries require absolute paths");
++ }
++
++ tmp = xstrdup(name);
++ bname = xstrdup(basename(tmp));
++ free(tmp);
++ switch (type) {
++ case 'd':
++ stats->ninodes++;
++ break;
++ case 'c':
++ case 'b':
++ if (count > 0) {
++ dev_t rdev;
++ char *dname;
++ unsigned long i;
++ for (i = start; i < count; i++) {
++ asprintf(&dname, "%s%lu", bname, i);
++ stats->ninodes++;
++ free(dname);
++ }
++ } else {
++ stats->ninodes++;
++ }
++ break;
++ }
++ free(bname);
++ free(name);
++ return 0;
++}
++
+ static int parse_device_table(filesystem *root, FILE * file)
+ {
+ char *line;
+@@ -2070,6 +2237,45 @@
+ return status;
+ }
+
++static int stats_from_dev_table(FILE *file, struct stats *stats)
++{
++ char *line;
++ int status = 0;
++ size_t length = 0;
++
++ /* Looks ok so far. The general plan now is to read in one
++ * line at a time, check for leading comment delimiters ('#'),
++ * then try and parse the line as a device table. If we fail
++ * to parse things, try and help the poor fool to fix their
++ * device table with a useful error msg... */
++ line = NULL;
++ while (getline(&line, &length, file) != -1) {
++ /* First trim off any whitespace */
++ int len = strlen(line);
++
++ /* trim trailing whitespace */
++ while (len > 0 && isspace(line[len - 1]))
++ line[--len] = '\0';
++ /* trim leading whitespace */
++ memmove(line, &line[strspn(line, " \n\r\t\v")], len);
++
++ /* How long are we after trimming? */
++ len = strlen(line);
++
++ /* If this is NOT a comment line, try to interpret it */
++ if (len && *line != '#') {
++ if (stats_from_table_entry(line, stats))
++ status = 1;
++ }
++
++ free(line);
++ line = NULL;
++ }
++ fclose(file);
++
++ return status;
++}
++
+ /*
+ Local Variables:
+ c-file-style: "linux"
+@@ -2112,6 +2318,8 @@
+ int nbblocks = -1;
+ int nbinodes = -1;
+ int nbresrvd = -1;
++ int tmp_nbblocks = -1;
++ int tmp_nbinodes = -1;
+ char * fsout = "-";
+ char * fsin = 0;
+ char * dopt[MAX_DOPT];
+@@ -2128,6 +2336,7 @@
+ int c;
+ struct stat sb;
+ FILE *devtable = NULL;
++ struct stats stats;
+
+ app_name = argv[0];
+ while((c = getopt(argc, argv, "x:d:b:i:r:g:e:zvhD:f:qUP")) != EOF)
+@@ -2184,6 +2393,7 @@
+ default:
+ exit(1);
+ }
++
+ if(optind < (argc - 1))
+ error_msg_and_die("too many arguments");
+ if(optind == (argc - 1))
+@@ -2201,6 +2411,46 @@
+ }
+ else
+ {
++ stats.ninodes = 0;
++ stats.nblocks = 0;
++ for(i = 0; i < didx; i++)
++ {
++ struct stat st;
++ char *pdir;
++ stat(dopt[i], &st);
++ switch(st.st_mode & S_IFMT)
++ {
++ case S_IFDIR:
++ if(!(pdir = getcwd(0, GETCWD_SIZE)))
++ perror_msg_and_die(dopt[i]);
++ if(chdir(dopt[i]) < 0)
++ perror_msg_and_die(dopt[i]);
++ stats_from_dir(&stats);
++ if(chdir(pdir) < 0)
++ perror_msg_and_die(pdir);
++ free(pdir);
++ break;
++ default:
++ error_msg_and_die("%s is neither a file nor a directory", dopt[i]);
++ }
++ }
++
++ if(devtable)
++ stats_from_dev_table(devtable, &stats);
++
++ tmp_nbinodes = stats.ninodes + EXT2_FIRST_INO + 1;
++ tmp_nbblocks = stats.nblocks;
++
++ if(tmp_nbblocks > nbblocks)
++ {
++ printf("Number of blocks too low, increasing to %d\n",tmp_nbblocks);
++ nbblocks = tmp_nbblocks;
++ }
++ if(tmp_nbinodes > nbinodes)
++ {
++ printf("Number of inodes too low, increasing to %d\n",tmp_nbinodes);
++ nbinodes = tmp_nbinodes;
++ }
+ if(nbblocks == -1)
+ error_msg_and_die("filesystem size unspecified");
+ if(nbinodes == -1)
diff --git a/openembedded/packages/genext2fs/genext2fs-1.3/misc.patch b/openembedded/packages/genext2fs/genext2fs-1.3/misc.patch
new file mode 100644
index 0000000000..e5849eb797
--- /dev/null
+++ b/openembedded/packages/genext2fs/genext2fs-1.3/misc.patch
@@ -0,0 +1,2143 @@
+--- genext2fs-1.3.orig/Makefile
++++ genext2fs-1.3/Makefile
+@@ -0,0 +1,25 @@
++all: genext2fs
++INSTALL=install
++
++install:
++ $(INSTALL) -d $(DESTDIR)/usr/bin/
++ $(INSTALL) -m 755 genext2fs $(DESTDIR)/usr/bin/
++ $(INSTALL) -d $(DESTDIR)/usr/share/man/man8/
++ $(INSTALL) -m 644 genext2fs.8 $(DESTDIR)/usr/share/man/man8/
++
++clean:
++ -rm genext2fs
++ rm -rf test ext2.img
++
++check: all
++ mkdir -p test
++ dd if=/dev/zero of=test/zero count=1
++ ./genext2fs -b 4096 -d test ext2.img
++
++ md5=`md5sum ext2.img | cut -f 1 -d " "`; \
++ if [ "$$md5" != "a736fce6d45ea3631b01fd7b8f623131" ] ; then \
++ echo "test failed."; \
++ else \
++ echo "test succeeded."; \
++ fi
++
+diff -urN genext2fs-1.3.orig/dev.txt genext2fs-1.3/dev.txt
+--- genext2fs-1.3.orig/dev.txt 2000-09-28 09:03:19.000000000 -0600
++++ genext2fs-1.3/dev.txt 1969-12-31 17:00:00.000000000 -0700
+@@ -1,94 +0,0 @@
+-drwx /dev
+-crw- 10,190 /dev/lcd
+-crw- 10,191 /dev/splc781
+-crw- 4,0 /dev/console
+-crw- 5,64 /dev/cua0
+-crw- 5,65 /dev/cua1
+-crw- 5,66 /dev/cua2
+-crw- 5,70 /dev/cua6
+-crw- 5,71 /dev/cua7
+-crw- 5,72 /dev/cua8
+-crw- 5,73 /dev/cua9
+-crw- 29,0 /dev/fb0
+-crw- 29,32 /dev/fb1
+-crw- 1,2 /dev/kmem
+-crw- 1,1 /dev/mem
+-crw- 1,3 /dev/null
+-crw- 2,2 /dev/ptyp2
+-crw- 2,3 /dev/ptyp3
+-crw- 2,5 /dev/ptyp5
+-crw- 2,4 /dev/ptyp4
+-crw- 10,178 /dev/triokb
+-crw- 2,0 /dev/ptyp0
+-crw- 2,6 /dev/ptyp6
+-crw- 2,7 /dev/ptyp7
+-crw- 2,8 /dev/ptyp8
+-crw- 2,9 /dev/ptyp9
+-crw- 2,10 /dev/ptypa
+-crw- 2,11 /dev/ptypb
+-crw- 2,12 /dev/ptypc
+-crw- 2,13 /dev/ptypd
+-crw- 2,14 /dev/ptype
+-crw- 2,15 /dev/ptypf
+-brw- 1,0 /dev/ram0
+-brw- 1,1 /dev/ram1
+-brw- 1,2 /dev/ram2
+-brw- 1,3 /dev/ram3
+-br-- 31,0 /dev/rom0
+-brw- 31,1 /dev/rom1
+-brw- 31,2 /dev/rom2
+-brw- 31,3 /dev/rom3
+-crw- 5,0 /dev/tty
+-crw- 4,0 /dev/tty0
+-crwx 4,1 /dev/tty1
+-crwx 4,2 /dev/tty2
+-crwx 4,3 /dev/tty3
+-crwx 4,4 /dev/tty4
+-crw- 4,5 /dev/tty5
+-crwx 4,6 /dev/tty6
+-crw- 4,7 /dev/tty7
+-crw- 4,8 /dev/tty8
+-crw- 4,9 /dev/tty9
+-crw- 4,64 /dev/ttyS0
+-crw- 4,65 /dev/ttyS1
+-crw- 4,66 /dev/ttyS2
+-crw- 4,67 /dev/ttyS3
+-crw- 4,68 /dev/ttyS4
+-crw- 4,69 /dev/ttyS5
+-crw- 4,70 /dev/ttyS6
+-crw- 4,71 /dev/ttyS7
+-crw- 4,72 /dev/ttyS8
+-crw- 4,73 /dev/ttyS9
+-crw- 3,0 /dev/ttyp0
+-crw- 3,1 /dev/ttyp1
+-crw- 3,2 /dev/ttyp2
+-crw- 3,3 /dev/ttyp3
+-crw- 3,4 /dev/ttyp4
+-crw- 3,5 /dev/ttyp5
+-crw- 3,6 /dev/ttyp6
+-crw- 3,7 /dev/ttyp7
+-crw- 3,8 /dev/ttyp8
+-crw- 3,9 /dev/ttyp9
+-crw- 3,10 /dev/ttypa
+-crw- 3,11 /dev/ttypb
+-crw- 3,12 /dev/ttypc
+-crw- 3,13 /dev/ttypd
+-crw- 3,14 /dev/ttype
+-crw- 3,15 /dev/ttypf
+-crw- 1,5 /dev/zero
+-crwx 10,111 /dev/dtedrv
+-crwx 4,110 /dev/ttyM
+-crw- 77,1 /dev/tssnd
+-crw- 77,2 /dev/tstone
+-crw- 2,1 /dev/ptyp1
+-crwx 10,180 /dev/triohook
+-crw- 90,0 /dev/mtd0
+-brw- 44,0 /dev/ftl0
+-crw- 10,175 /dev/tporta
+-crw- 10,176 /dev/tportb
+-crwx 10,100 /dev/softmodem
+-crwx 10,101 /dev/softmodem_signals
+-crwx 10,181 /dev/triovoice
+-crw- 5,67 /dev/cua3
+-crw- 5,68 /dev/cua4
+-crw- 5,69 /dev/cua5
+diff -urN genext2fs-1.3.orig/device_table.txt genext2fs-1.3/device_table.txt
+--- genext2fs-1.3.orig/device_table.txt 1969-12-31 17:00:00.000000000 -0700
++++ genext2fs-1.3/device_table.txt 2003-04-21 01:41:42.000000000 -0600
+@@ -0,0 +1,129 @@
++# When building a target filesystem, it is desirable to not have to
++# become root and then run 'mknod' a thousand times. Using a device
++# table you can create device nodes and directories "on the fly".
++#
++# This is a sample device table file for use with genext2fs. You can
++# do all sorts of interesting things with a device table file. For
++# example, if you want to adjust the permissions on a particular file
++# you can just add an entry like:
++# /sbin/foobar f 2755 0 0 - - - - -
++# and (assuming the file /sbin/foobar exists) it will be made setuid
++# root (regardless of what its permissions are on the host filesystem.
++# Furthermore, you can use a single table entry to create a many device
++# minors. For example, if I wanted to create /dev/hda and /dev/hda[0-15]
++# I could just use the following two table entries:
++# /dev/hda b 640 0 0 3 0 0 0 -
++# /dev/hda b 640 0 0 3 1 1 1 15
++#
++# Device table entries take the form of:
++# <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>
++# where name is the file name, type can be one of:
++# f A regular file
++# d Directory
++# c Character special device file
++# b Block special device file
++# p Fifo (named pipe)
++# uid is the user id for the target file, gid is the group id for the
++# target file. The rest of the entries (major, minor, etc) apply only
++# to device special files.
++
++# Have fun
++# -Erik Andersen <andersen@codepoet.org>
++#
++
++#<name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>
++/dev d 755 0 0 - - - - -
++/dev/mem c 640 0 0 1 1 0 0 -
++/dev/kmem c 640 0 0 1 2 0 0 -
++/dev/null c 640 0 0 1 3 0 0 -
++/dev/zero c 640 0 0 1 5 0 0 -
++/dev/random c 640 0 0 1 8 0 0 -
++/dev/urandom c 640 0 0 1 9 0 0 -
++/dev/tty c 666 0 0 5 0 0 0 -
++/dev/tty c 666 0 0 4 0 0 1 6
++/dev/console c 640 0 0 5 1 0 0 -
++/dev/ram b 640 0 0 1 1 0 0 -
++/dev/ram b 640 0 0 1 0 0 1 4
++/dev/loop b 640 0 0 7 0 0 1 2
++/dev/ptmx c 666 0 0 5 2 0 0 -
++#/dev/ttyS c 640 0 0 4 64 0 1 4
++#/dev/psaux c 640 0 0 10 1 0 0 -
++#/dev/rtc c 640 0 0 10 135 0 0 -
++
++# Adjust permissions on some normal files
++#/etc/shadow f 600 0 0 - - - - -
++#/bin/tinylogin f 4755 0 0 - - - - -
++
++# User-mode Linux stuff
++/dev/ubda b 640 0 0 98 0 0 0 -
++/dev/ubda b 640 0 0 98 1 1 1 15
++
++# IDE Devices
++/dev/hda b 640 0 0 3 0 0 0 -
++/dev/hda b 640 0 0 3 1 1 1 15
++/dev/hdb b 640 0 0 3 64 0 0 -
++/dev/hdb b 640 0 0 3 65 1 1 15
++#/dev/hdc b 640 0 0 22 0 0 0 -
++#/dev/hdc b 640 0 0 22 1 1 1 15
++#/dev/hdd b 640 0 0 22 64 0 0 -
++#/dev/hdd b 640 0 0 22 65 1 1 15
++#/dev/hde b 640 0 0 33 0 0 0 -
++#/dev/hde b 640 0 0 33 1 1 1 15
++#/dev/hdf b 640 0 0 33 64 0 0 -
++#/dev/hdf b 640 0 0 33 65 1 1 15
++#/dev/hdg b 640 0 0 34 0 0 0 -
++#/dev/hdg b 640 0 0 34 1 1 1 15
++#/dev/hdh b 640 0 0 34 64 0 0 -
++#/dev/hdh b 640 0 0 34 65 1 1 15
++
++# SCSI Devices
++#/dev/sda b 640 0 0 8 0 0 0 -
++#/dev/sda b 640 0 0 8 1 1 1 15
++#/dev/sdb b 640 0 0 8 16 0 0 -
++#/dev/sdb b 640 0 0 8 17 1 1 15
++#/dev/sdc b 640 0 0 8 32 0 0 -
++#/dev/sdc b 640 0 0 8 33 1 1 15
++#/dev/sdd b 640 0 0 8 48 0 0 -
++#/dev/sdd b 640 0 0 8 49 1 1 15
++#/dev/sde b 640 0 0 8 64 0 0 -
++#/dev/sde b 640 0 0 8 65 1 1 15
++#/dev/sdf b 640 0 0 8 80 0 0 -
++#/dev/sdf b 640 0 0 8 81 1 1 15
++#/dev/sdg b 640 0 0 8 96 0 0 -
++#/dev/sdg b 640 0 0 8 97 1 1 15
++#/dev/sdh b 640 0 0 8 112 0 0 -
++#/dev/sdh b 640 0 0 8 113 1 1 15
++#/dev/sg c 640 0 0 21 0 0 1 15
++#/dev/scd b 640 0 0 11 0 0 1 15
++#/dev/st c 640 0 0 9 0 0 1 8
++#/dev/nst c 640 0 0 9 128 0 1 8
++#/dev/st c 640 0 0 9 32 1 1 4
++#/dev/st c 640 0 0 9 64 1 1 4
++#/dev/st c 640 0 0 9 96 1 1 4
++
++# Floppy disk devices
++#/dev/fd b 640 0 0 2 0 0 1 2
++#/dev/fd0d360 b 640 0 0 2 4 0 0 -
++#/dev/fd1d360 b 640 0 0 2 5 0 0 -
++#/dev/fd0h1200 b 640 0 0 2 8 0 0 -
++#/dev/fd1h1200 b 640 0 0 2 9 0 0 -
++#/dev/fd0u1440 b 640 0 0 2 28 0 0 -
++#/dev/fd1u1440 b 640 0 0 2 29 0 0 -
++#/dev/fd0u2880 b 640 0 0 2 32 0 0 -
++#/dev/fd1u2880 b 640 0 0 2 33 0 0 -
++
++# All the proprietary cdrom devices in the world
++#/dev/aztcd b 640 0 0 29 0 0 0 -
++#/dev/bpcd b 640 0 0 41 0 0 0 -
++#/dev/capi20 c 640 0 0 68 0 0 1 2
++#/dev/cdu31a b 640 0 0 15 0 0 0 -
++#/dev/cdu535 b 640 0 0 24 0 0 0 -
++#/dev/cm206cd b 640 0 0 32 0 0 0 -
++#/dev/sjcd b 640 0 0 18 0 0 0 -
++#/dev/sonycd b 640 0 0 15 0 0 0 -
++#/dev/gscd b 640 0 0 16 0 0 0 -
++#/dev/sbpcd b 640 0 0 25 0 0 0 -
++#/dev/sbpcd b 640 0 0 25 0 0 1 4
++#/dev/mcd b 640 0 0 23 0 0 0 -
++#/dev/optcd b 640 0 0 17 0 0 0 -
++
+diff -urN genext2fs-1.3.orig/genext2fs.8 genext2fs-1.3/genext2fs.8
+--- genext2fs-1.3.orig/genext2fs.8 1969-12-31 17:00:00.000000000 -0700
++++ genext2fs-1.3/genext2fs.8 2003-04-21 01:41:42.000000000 -0600
+@@ -0,0 +1,125 @@
++.\" Hey, EMACS: -*- nroff -*-
++.\" First parameter, NAME, should be all caps
++.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
++.\" other parameters are allowed: see man(7), man(1)
++.TH GENEXT2FS 8 "July 14, 2001"
++.\" Please adjust this date whenever revising the manpage.
++.\"
++.\" Some roff macros, for reference:
++.\" .nh disable hyphenation
++.\" .hy enable hyphenation
++.\" .ad l left justify
++.\" .ad b justify to both left and right margins
++.\" .nf disable filling
++.\" .fi enable filling
++.\" .br insert line break
++.\" .sp <n> insert n+1 empty lines
++.\" for manpage-specific macros, see man(7)
++.SH NAME
++genext2fs \- ext2 filesystem generator for embedded systems
++.SH SYNOPSIS
++.B genext2fs
++.RI [ options ] " image"
++.SH DESCRIPTION
++\fBgenext2fs\fP generates an ext2 filesystem
++as a normal (non-root) user. It doesn't require you to mount
++the image file to copy files on it. It doesn't even require
++you to be the superuser to make device nodes.
++.SH OPTIONS
++.TP
++.BI -x \ image
++Use this image as a starting point
++.TP
++.BI -d \ directory
++Add this directory as source
++.TP
++.BI -f \ FILE
++.TP
++.BI -D \ FILE
++Uses the named FILE as a device table file, to create device
++nodes and directories "on the fly".
++.TP
++.BI -b \ blocks
++Size in blocks
++.TP
++.BI -i \ inodes
++Number of inodes
++.TP
++.BI -r \ reserved
++Number of reserved blocks
++.TP
++.BI -g \ path
++Generate a block map file for this path
++.TP
++.BI -e \ value
++Fill unallocated blocks with value
++.TP
++.BI -z
++Make files with holes
++.TP
++.BI -U
++Squash owners making all files be owned by root
++.TP
++.BI -P
++Squash permissions on all files
++.TP
++.BI -q
++Squash permissions and owners (same as -P -U)
++.TP
++.BI -v
++Print resulting filesystem structure
++.TP
++.BI -h
++Display help
++.TP
++.SH EXAMPLES
++
++.EX
++.B
++ genext2fs -b 1440 -d src /dev/fd0
++.EE
++
++All files in the
++.I src
++directory will be written to
++.B /dev/fd0
++as a new ext2 filesystem image. You can then mount the floppy as
++usual.
++
++.EX
++.B
++ genext2fs -b 1024 -d src -D device_table.txt flashdisk.img
++.EE
++
++This example builds a filesystem from all the files in
++.I src
++, then device nodes are created based on the content the device_table file
++.I dev.txt.
++An example device file follows:
++
++.EX
++ #<name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>
++ /dev d 755 0 0 - - - - -
++ /dev/mem c 640 0 0 1 1 0 0 -
++ /dev/tty c 666 0 0 5 0 0 0 -
++ /dev/tty c 666 0 0 4 0 0 1 6
++ /dev/loop b 640 0 0 7 0 0 1 2
++ /dev/hda b 640 0 0 3 0 0 0 -
++ /dev/hda b 640 0 0 3 1 1 1 16
++.EE
++
++This device table creates the /dev directory, a character device
++node /dev/mem (major 1, minor 1), it also creates /dev/tty,
++/dev/tty[0-5], /dev/loop[0-1], /dev/hda, and /dev/hda0 to /dev/hda15
++.SH BUGS
++\fBgenext2fs\fP does not support hard links. Hard links present in the input
++tree will be represented as separate files in the ext2 image.
++
++.SH SEE ALSO
++.BR mkfs (8),
++.BR genromfs (8),
++.BR mkisofs (8).
++.br
++.SH AUTHOR
++This manual page was written by David Kimdon <dwhedon@debian.org>,
++for the Debian GNU/Linux system (but may be used by others).
+diff -urN genext2fs-1.3.orig/genext2fs.c genext2fs-1.3/genext2fs.c
+--- genext2fs-1.3.orig/genext2fs.c 2001-06-18 02:11:32.000000000 -0600
++++ genext2fs-1.3/genext2fs.c 2003-04-21 01:48:35.000000000 -0600
+@@ -1,3 +1,4 @@
++/* vi: set sw=8 ts=8: */
+ // genext2fs.c
+ //
+ // ext2 filesystem generator for embedded systems
+@@ -26,6 +27,22 @@
+ // Bugfix: getcwd values for Solaris xavier.gueguen@col.bsf.alcatel.fr
+ // Bugfix: ANSI scanf for non-GNU C xavier.gueguen@col.bsf.alcatel.fr
+ // 28 Jun 2001 Bugfix: getcwd differs for Solaris/GNU mike@sowbug.com
++// 23 Mar 2002 Bugfix: test for IFCHR or IFBLK was flawed
++// 10 Oct 2002 Added comments,makefile targets, vsundar@ixiacom.com
++// endianess swap assert check.
++// Copyright (C) 2002 Ixia communications
++// 12 Oct 2002 Added support for triple indirection vsundar@ixiacom.com
++// Copyright (C) 2002 Ixia communications
++// 14 Oct 2002 Added support for groups vsundar@ixiacom.com
++// Copyright (C) 2002 Ixia communications
++// 5 Jan 2003 Bugfixes: reserved inodes should be set vsundar@usc.edu
++// only in the first group; directory names
++// need to be null padded at the end; and
++// number of blocks per group should be a
++// multiple of 8. Updated md5 values.
++// 6 Jan 2003 Erik Andersen <andersee@debian.org> added
++// mkfs.jffs2 compatible device table support,
++// along with -q, -P, -U
+
+
+ // `genext2fs' is a mean to generate an ext2 filesystem
+@@ -33,10 +50,6 @@
+ // the image file to copy files on it. It doesn't even require
+ // you to be the superuser to make device nodes.
+ //
+-// Warning ! `genext2fs' has been designed for embedded
+-// systems. As such, it will generate a filesystem for single-user
+-// usage: all files/directories/etc... will belong to UID/GID 0
+-//
+ // Example usage:
+ //
+ // # genext2fs -b 1440 -d srcdir /dev/fd0
+@@ -45,21 +58,15 @@
+ // a new ext2 filesystem image. You can then mount the floppy as
+ // usual.
+ //
+-// # genext2fs -b 1024 -d builddir -f devices.txt flashdisk.img
++// # genext2fs -b 1024 -d builddir -D device_table.txt flashdisk.img
+ //
+ // This one would build a filesystem from all the files in builddir,
+-// then would read a devices list and make apropriate nodes. The
+-// format for the device list is:
+-//
+-// drwx /dev
+-// crw- 10,190 /dev/lcd
+-// brw- 1,0 /dev/ram0
+-//
+-// This device list builds the /dev directory, a character device
+-// node /dev/lcd (major 10, minor 190) and a block device node
+-// /dev/ram0 (major 1, minor 0)
++// then would read the device_table.txt file and make apropriate nodes.
++// The format for the device table file is covered in detail in the sample
++// device_table.txt file provided with the genext2fs source.
+
+
++#define _GNU_SOURCE
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -67,6 +74,11 @@
+ #include <stdarg.h>
+ #include <unistd.h>
+ #include <sys/stat.h>
++#include <assert.h>
++#include <time.h>
++#include <ctype.h>
++#include <errno.h>
++#include <fcntl.h>
+
+
+
+@@ -76,10 +88,14 @@
+ #define BLOCKSIZE 1024
+ #define BLOCKS_PER_GROUP 8192
+ #define BYTES_PER_INODE (8*BLOCKSIZE)
++/* Percentage of blocks that are reserved.*/
+ #define RESERVED_INODES 5/100
+
+
+ // inode block size (why is it != BLOCKSIZE ?!?)
++/* The field i_blocks in the ext2 inode stores the number of data blocks
++ but in terms of 512 bytes. That is what INODE_BLOCKSIZE represents.
++ INOBLK is the number of such blocks in an actual disk block */
+
+ #define INODE_BLOCKSIZE 512
+ #define INOBLK (BLOCKSIZE / INODE_BLOCKSIZE)
+@@ -147,6 +163,39 @@
+
+ #define OP_HOLES 0x01 // make files with holes
+
++/* Defines for accessing group details */
++
++// Number of groups in the filesystem
++#define GRP_NBGROUPS(fs) ( ((fs)->sb.s_blocks_count-1)/(fs)->sb.s_blocks_per_group )
++
++// Get group block bitmap (bbm) given the group number
++#define GRP_GET_GROUP_BBM(fs,grp) ( get_blk((fs),(fs)->gd[(grp)].bg_block_bitmap) )
++
++// Get group inode bitmap (ibm) given the group number
++#define GRP_GET_GROUP_IBM(fs,grp) ( get_blk((fs),(fs)->gd[(grp)].bg_inode_bitmap) )
++
++// Given an inode number find the group it belongs to
++#define GRP_GROUP_OF_INODE(fs,nod) ( ((nod)-1) / (fs)->sb.s_inodes_per_group)
++
++//Given an inode number get the inode bitmap that covers it
++#define GRP_GET_INODE_BITMAP(fs,nod) \
++ ( GRP_GET_GROUP_IBM((fs),GRP_GROUP_OF_INODE((fs),(nod))) )
++
++//Given an inode number find its offset within the inode bitmap that covers it
++#define GRP_IBM_OFFSET(fs,nod) \
++ ( (nod) - GRP_GROUP_OF_INODE((fs),(nod))*(fs)->sb.s_inodes_per_group )
++
++// Given a block number find the group it belongs to
++#define GRP_GROUP_OF_BLOCK(fs,blk) ( ((blk)-1) / (fs)->sb.s_blocks_per_group)
++
++//Given a block number get the block bitmap that covers it
++#define GRP_GET_BLOCK_BITMAP(fs,blk) \
++ ( GRP_GET_GROUP_BBM((fs),GRP_GROUP_OF_BLOCK((fs),(blk))) )
++
++//Given a block number find its offset within the block bitmap that covers it
++#define GRP_BBM_OFFSET(fs,blk) \
++ ( (blk) - GRP_GROUP_OF_BLOCK((fs),(blk))*(fs)->sb.s_blocks_per_group )
++
+
+ // used types
+
+@@ -287,7 +336,6 @@
+ {
+ groupdescriptor_decl
+ uint32 bg_reserved[3];
+- uint32 bg_pad_to_bk[(BLOCKSIZE-32)/sizeof(uint32)];
+ } groupdescriptor;
+
+ typedef struct
+@@ -304,6 +352,32 @@
+
+ typedef uint8 block[BLOCKSIZE];
+
++/* blockwalker fields:
++ The blockwalker is used to access all the blocks of a file (including
++ the indirection blocks) through repeated calls to walk_bw.
++
++ bpdir -> index into the inode->i_block[]. Indicates level of indirection.
++ bnum -> total number of blocks so far accessed. including indirection
++ blocks.
++ bpind,bpdind,bptind -> index into indirection blocks.
++
++ bpind, bpdind, bptind do *NOT* index into single, double and triple
++ indirect blocks resp. as you might expect from their names. Instead
++ they are in order the 1st, 2nd & 3rd index to be used
++
++ As an example..
++ To access data block number 70000:
++ bpdir: 15 (we are doing triple indirection)
++ bpind: 0 ( index into the triple indirection block)
++ bpdind: 16 ( index into the double indirection block)
++ bptind: 99 ( index into the single indirection block)
++ 70000 = 12 + 256 + 256*256 + 16*256 + 100 (indexing starts from zero)
++
++ So,for double indirection bpind will index into the double indirection
++ block and bpdind into the single indirection block. For single indirection
++ only bpind will be used.
++*/
++
+ typedef struct
+ {
+ uint32 bnum;
+@@ -313,15 +387,14 @@
+ uint32 bptind;
+ } blockwalker;
+
++
++/* Filesystem structure that support groups */
+ #if BLOCKSIZE == 1024
+ typedef struct
+ {
+ block zero; // The famous block 0
+ superblock sb; // The superblock
+- groupdescriptor gd; // The group desciptor
+- block bbm; // The block bitmap
+- block ibm; // The inode bitmap
+- inode itab[0]; // The inode table
++ groupdescriptor gd[0]; // The group descriptors
+ } filesystem;
+ #else
+ #error UNHANDLED BLOCKSIZE
+@@ -389,25 +462,113 @@
+ #undef udecl32
+ #undef utdecl32
+
+-char * argv0;
++static char * app_name;
++static int squash_uids = 0;
++static int squash_perms = 0;
++static const char *const memory_exhausted = "memory exhausted";
+
+ // error (un)handling
+-inline void errexit(const char *fmt, ...)
++static void verror_msg(const char *s, va_list p)
+ {
+- va_list ap;
+- fprintf(stderr, "%s: ", argv0);
+- va_start(ap, fmt);
+- vfprintf(stderr, fmt, ap);
+- va_end(ap);
+- fprintf(stderr, "\n");
+- exit(1);
++ fflush(stdout);
++ fprintf(stderr, "%s: ", app_name);
++ vfprintf(stderr, s, p);
++}
++static void error_msg(const char *s, ...)
++{
++ va_list p;
++ va_start(p, s);
++ verror_msg(s, p);
++ va_end(p);
++ putc('\n', stderr);
++}
++
++static void error_msg_and_die(const char *s, ...)
++{
++ va_list p;
++ va_start(p, s);
++ verror_msg(s, p);
++ va_end(p);
++ putc('\n', stderr);
++ exit(EXIT_FAILURE);
++}
++
++static void vperror_msg(const char *s, va_list p)
++{
++ int err = errno;
++ if (s == 0)
++ s = "";
++ verror_msg(s, p);
++ if (*s)
++ s = ": ";
++ fprintf(stderr, "%s%s\n", s, strerror(err));
++}
++
++#if 0
++static void perror_msg(const char *s, ...)
++{
++ va_list p;
++ va_start(p, s);
++ vperror_msg(s, p);
++ va_end(p);
++}
++#endif
++static void perror_msg_and_die(const char *s, ...)
++{
++ va_list p;
++ va_start(p, s);
++ vperror_msg(s, p);
++ va_end(p);
++ exit(EXIT_FAILURE);
+ }
+
+-inline void pexit(const char * fname)
++static FILE *xfopen(const char *path, const char *mode)
+ {
+- fprintf(stderr, "%s: ", argv0);
+- perror(fname);
+- exit(1);
++ FILE *fp;
++ if ((fp = fopen(path, mode)) == NULL)
++ perror_msg_and_die("%s", path);
++ return fp;
++}
++
++static char *xstrdup(const char *s)
++{
++ char *t;
++
++ if (s == NULL)
++ return NULL;
++ t = strdup(s);
++ if (t == NULL)
++ error_msg_and_die(memory_exhausted);
++ return t;
++}
++
++extern void *xrealloc(void *ptr, size_t size)
++{
++ ptr = realloc(ptr, size);
++ if (ptr == NULL && size != 0)
++ error_msg_and_die(memory_exhausted);
++ return ptr;
++}
++
++static char *xreadlink(const char *path)
++{
++ static const int GROWBY = 80; /* how large we will grow strings by */
++
++ char *buf = NULL;
++ int bufsize = 0, readsize = 0;
++
++ do {
++ buf = xrealloc(buf, bufsize += GROWBY);
++ readsize = readlink(path, buf, bufsize); /* 1st try */
++ if (readsize == -1) {
++ perror_msg_and_die("%s:%s", app_name, path);
++ }
++ }
++ while (bufsize < readsize + 1);
++
++ buf[readsize] = '\0';
++
++ return buf;
+ }
+
+ // printf helper macro
+@@ -423,7 +584,7 @@
+ {
+ }
+
+-// rounds a quantity up to a blocksize
++/* Rounds qty upto a multiple of siz. siz should be a power of 2 */
+ uint32 rndup(uint32 qty, uint32 siz)
+ {
+ return (qty + (siz - 1)) & ~(siz - 1);
+@@ -444,7 +605,13 @@
+ // return a given inode from a filesystem
+ inline inode * get_nod(filesystem *fs, uint32 nod)
+ {
+- return &fs->itab[nod-1];
++ int grp,offset;
++ inode *itab;
++
++ offset = GRP_IBM_OFFSET(fs,nod);
++ grp = GRP_GROUP_OF_INODE(fs,nod);
++ itab = (inode *)get_blk(fs, fs->gd[grp].bg_inode_table);
++ return itab+offset-1;
+ }
+
+ // allocate a given block/inode in the bitmap
+@@ -479,29 +646,57 @@
+ }
+
+ // allocate a block
+-uint32 alloc_blk(filesystem *fs)
++uint32 alloc_blk(filesystem *fs, uint32 nod)
+ {
+- uint32 bk;
+- if(!(bk = allocate(fs->bbm, 0)))
+- errexit("couldn't allocate a block (no free space)");
+- if(!(fs->gd.bg_free_blocks_count--))
+- errexit("group descr. free blocks count == 0 (corrupted fs?)");
++ uint32 bk=0;
++ uint32 grp,nbgroups;
++
++ grp = nod/fs->sb.s_inodes_per_group;
++ nbgroups = ( fs->sb.s_blocks_count - fs->sb.s_first_data_block + fs->sb.s_blocks_per_group -1 ) /
++ fs->sb.s_blocks_per_group;
++ if(!(bk = allocate(get_blk(fs,fs->gd[grp].bg_block_bitmap), 0))) {
++ for(grp=0;grp<nbgroups && !bk;grp++)
++ bk=allocate(get_blk(fs,fs->gd[grp].bg_block_bitmap),0);
++ grp--;
++ }
++ if (!bk)
++ error_msg_and_die("couldn't allocate a block (no free space)");
++ if(!(fs->gd[grp].bg_free_blocks_count--))
++ error_msg_and_die("group descr %d. free blocks count == 0 (corrupted fs?)",grp);
+ if(!(fs->sb.s_free_blocks_count--))
+- errexit("superblock free blocks count == 0 (corrupted fs?)");
+- return bk;
++ error_msg_and_die("superblock free blocks count == 0 (corrupted fs?)");
++ return fs->sb.s_blocks_per_group*grp + bk;
+ }
+
+ // allocate an inode
+ uint32 alloc_nod(filesystem *fs)
+ {
+- uint32 nod;
+- if(!(nod = allocate(fs->ibm, 0)))
+- errexit("couldn't allocate an inode (no free inode)");
+- if(!(fs->gd.bg_free_inodes_count--))
+- errexit("group descr. free blocks count == 0 (corrupted fs?)");