]> Zhao Yanbai Git Server - minix.git/commitdiff
isofs: reworked for better performance 89/2989/2
authorJean-Baptiste Boric <jblbeurope@gmail.com>
Wed, 16 Sep 2015 12:36:11 +0000 (14:36 +0200)
committerLionel Sambuc <lionel.sambuc@gmail.com>
Wed, 7 Oct 2015 10:40:24 +0000 (12:40 +0200)
isofs now uses an in-memory directory listing built on-the-fly instead
of parsing the ISO 9660 data structures over and over for almost every
request. This yields huge performance improvements.

The directory listing is allocated dynamically, but Minix servers aren't
normally supposed to do that because critical servers would crash if the
system runs out of memory. isofs is quite frugal, won't allocate memory
after having the whole directory tree cached and is not that critical
(its most important job is to serve as a root file system during
installation).

The benefits and elegance of this scheme far outweights this small
problem in practice.

Change-Id: I13d070388c07d274cbee0645cbc50295c447c5b6

16 files changed:
etc/system.conf
minix/fs/isofs/const.h
minix/fs/isofs/inode.c
minix/fs/isofs/inode.h
minix/fs/isofs/link.c
minix/fs/isofs/mount.c
minix/fs/isofs/path.c
minix/fs/isofs/proto.h
minix/fs/isofs/read.c
minix/fs/isofs/stadir.c
minix/fs/isofs/super.c
minix/fs/isofs/susp.c
minix/fs/isofs/susp_rock_ridge.c
minix/fs/isofs/uthash.h [new file with mode: 0644]
minix/fs/isofs/utility.c
minix/tests/testisofs.sh

index aab9934ff24c7004904faf28fc1da3d8f838724f..25b5426acecc3e714f735ed7fad4c583a5ed62b5 100644 (file)
@@ -399,7 +399,11 @@ service isofs
 {
        system
                UMAP            # 14
-               ;
+       ;
+       vm      MAPCACHEPAGE
+               SETCACHEPAGE
+               CLEARCACHE
+       ;
        uid     0;
 };
 
@@ -494,12 +498,12 @@ service osscore
                DEVIO           # 21
                SDEVIO          # 22
        ;
-       pci class       
+       pci class
                4/1             # Multimedia / Audio device
        ;
        ipc
                SYSTEM pm rs tty ds vfs vm
-               pci inet lwip amddev 
+               pci inet lwip amddev
                ;
        uid     0;
 };
@@ -567,14 +571,14 @@ service mmc
                IRQCTL          # 19
        ;
        # Interrupts allowed
-       irq     
+       irq
                64
                83
        ;               # IRQs allowed
        priority         4;     # priority queue 4
 };
 
-service fb 
+service fb
 {
        system
                UMAP            # 14
@@ -597,7 +601,7 @@ service gpio
                SETCACHEPAGE
                CLEARCACHE
        ;
-       irq     
+       irq
                29      # GPIO module 1 (dm37xx)
                30      # GPIO module 2 (dm37xx)
                31      # GPIO module 3 (dm37xx)
@@ -610,7 +614,7 @@ service gpio
                97      # GPIO module 0b (am335x)
                98      # GPIO module 1a (am335x)
                99      # GPIO module 1b (am335x)
-       ;               
+       ;
 
 };
 
index 81e80b5aca01ac38d6c46d52e5325b7c965443a7..516342bd91d031499e366cb1d0299523aa7ccff0 100644 (file)
@@ -3,14 +3,10 @@
 
 #define ISO9660_STANDARD_ID     "CD001" /* Standard code for ISO9660 FS */
 
-#define NR_INODE_RECORDS        64
-#define NR_DIR_EXTENT_RECORDS   NR_INODE_RECORDS * 16
-
-#define NO_ADDRESS (-1)         /* Error constants */
-#define NO_FREE_INODES (-1)
-
-#define PATH_PENULTIMATE 001    /* parse_path stops at last but one name */
-#define PATH_NONSYMBOLIC 004    /* parse_path scans final name if symbolic */
+/* Filesystem options support */
+#define ISO9660_OPTION_ROCKRIDGE
+/* TODO: Make MODE3 working. */
+/*#define ISO9660_OPTION_MODE3*/
 
 /* Below there are constant of the ISO9660 fs */
 #define ISO9660_SUPER_BLOCK_POSITION    32768
index 1e4474bac7ec38e2631ae6d622d8af115064ae14..595ad897ccef268c042ec793574de170b05bd4e7 100644 (file)
@@ -6,23 +6,48 @@
 
 #include "inc.h"
 
-static struct inode inodes[NR_INODE_RECORDS];
-static struct buf* fetch_inode(struct dir_extent *extent, size_t *offset);
+#include "uthash.h"
+
+struct inode_cache {
+       ino_t key;
+       struct inode *value;
+       UT_hash_handle hh;
+} ;
+
+struct inode_cache *icache = NULL;
+
+void read_inode_iso9660(struct inode_dir_entry *i,
+       const struct iso9660_dir_record *dir_rec, struct dir_extent *extent,
+       size_t offset, int name_only);
+
+#ifdef ISO9660_OPTION_MODE3
+static void read_inode_extents(struct inode_dir_entry *i,
+       const struct iso9660_dir_record *dir_rec, struct dir_extent *extent,
+       size_t *offset);
+#endif
+
+#ifdef ISO9660_OPTION_ROCKRIDGE
+void read_inode_susp(struct inode_dir_entry *i,
+       const struct iso9660_dir_record *dir_rec, struct buf *bp, size_t offset,
+       int name_only);
+#endif
+
+static int check_dir_record(const struct iso9660_dir_record *d, size_t offset);
 
 int fs_putnode(ino_t ino_nr, unsigned int count)
 {
-       /*
-        * Find the inode specified by the request message and decrease its
-        * counter.
-        */
+       /*
+        * Find the inode specified by the request message and decrease its
+        * counter.
+        */
        struct inode *i_node;
 
-       if ((i_node = find_inode(ino_nr)) == NULL) {
-               printf("ISOFS: trying to free unused inode\n");
+       if ((i_node = get_inode(ino_nr)) == NULL) {
+               puts("ISOFS: trying to free unused inode");
                return EINVAL;
        }
        if (count > i_node->i_count) {
-               printf("ISOFS: put_node count too high\n");
+               puts("ISOFS: put_node count too high");
                return EINVAL;
        }
 
@@ -31,211 +56,225 @@ int fs_putnode(ino_t ino_nr, unsigned int count)
        return OK;
 }
 
-struct inode* alloc_inode(void)
-{
-       /*
-        * Return a free inode from the pool.
-        */
-       static int i;
-       int end = i;
-       struct inode *i_node;
-
-       i = (i + 1) % NR_INODE_RECORDS;
-       do {
-               i_node = &inodes[i];
-
-               if (i_node->i_count == 0) {
-                       free_extent(i_node->extent);
 
-                       memset(i_node, 0, sizeof(*i_node));
-                       i_node->i_count = 1;
-
-                       return i_node;
-               }
-
-               i = (i + 1) % NR_INODE_RECORDS;
-       }
-       while(i != end);
-
-       panic("No free inodes in cache");
-}
-
-struct inode* find_inode(ino_t i)
-{
-       /* Get inode from cache. */
-       int cpt;
-       struct inode *i_node;
+struct inode* get_inode(ino_t ino_nr) {
+       /* Return an already opened inode from cache. */
+       struct inode *i_node = inode_cache_get(ino_nr);
 
-       if (i == 0)
+       if (i_node == NULL)
                return NULL;
 
-       for (cpt = 0; cpt < NR_INODE_RECORDS; cpt++) {
-               i_node = &inodes[cpt];
-
-               if ((i_node->i_stat.st_ino == i) && (i_node->i_count > 0))
-                       return i_node;
-       }
+       if (i_node->i_count == 0)
+               return NULL;
 
-       return NULL;
+       return i_node;
 }
 
-struct inode* get_inode(ino_t i)
-{
-       struct inode *i_node;
-       struct dir_extent *extent;
-
-       if (i == 0)
+struct inode* open_inode(ino_t ino_nr) {
+       /* Return an inode from cache. */
+       struct inode *i_node = inode_cache_get(ino_nr);
+       if (i_node == NULL)
                return NULL;
 
-       /* Try to get inode from cache. */
-       i_node = find_inode(i);
-       if (i_node != NULL) {
-               dup_inode(i_node);
-               return i_node;
-       }
-
-       /*
-        * Inode wasn't in cache, try to load it.
-        * FIXME: a fake extent of one logical block is created for
-        * read_inode(). Reading a inode this way could be problematic if
-        * additional extents are stored behind the block boundary.
-        */
-       i_node = alloc_inode();
-       extent = alloc_extent();
-       extent->location = i / v_pri.logical_block_size_l;
-       extent->length = 1;
-
-       if (read_inode(i_node, extent, i % v_pri.logical_block_size_l,
-           NULL) != OK) {
-               free_extent(extent);
-               put_inode(i_node);
-               return NULL;
-       }
+       i_node->i_count++;
 
-       free_extent(extent);
        return i_node;
 }
 
-void put_inode(struct inode *i_node)
-{
+void put_inode(struct inode *i_node) {
        if (i_node == NULL)
                return;
 
        assert(i_node->i_count > 0);
-
        i_node->i_count--;
+
+       if(i_node->i_count == 0)
+               i_node->i_mountpoint = FALSE;
 }
 
-void dup_inode(struct inode *i_node)
-{
+void dup_inode(struct inode *i_node) {
        assert(i_node != NULL);
+       assert(i_node->i_count > 0);
 
        i_node->i_count++;
 }
 
-static struct buf* fetch_inode(struct dir_extent *extent, size_t *offset)
-{
-       struct iso9660_dir_record *dir_rec;
-       struct buf *bp;
+int read_directory(struct inode *dir) {
+#define MAX_ENTRIES 4096
+       /* Read all entries in a directory. */
+       size_t pos = 0, cur_entry = 0, cpt;
+       struct inode_dir_entry entries[MAX_ENTRIES];
+       int status = OK;
 
-       /*
-        * Directory entries aren't allowed to cross a logical block boundary in
-        * ISO 9660, so we keep searching until we find something or reach the
-        * end of the extent.
-        */
-       bp = read_extent_block(extent, *offset / v_pri.logical_block_size_l);
-       while (bp != NULL) {
-               dir_rec = (struct iso9660_dir_record*)(b_data(bp) + *offset %
-                         v_pri.logical_block_size_l);
-               if (dir_rec->length == 0) {
-                       *offset -= *offset % v_pri.logical_block_size_l;
-                       *offset += v_pri.logical_block_size_l;
-               }
-               else {
+       if (dir->dir_contents)
+               return OK;
+
+       if (!S_ISDIR(dir->i_stat.st_mode))
+               return ENOTDIR;
+
+       for (cur_entry = 0; status == OK && cur_entry < MAX_ENTRIES; cur_entry++) {
+               memset(&entries[cur_entry], 0, sizeof(struct inode_dir_entry));
+
+               status = read_inode(&entries[cur_entry], &dir->extent, &pos);
+               if (status != OK)
                        break;
+
+               /* Dump the entry if it's not to be exported to userland. */
+               if (entries[cur_entry].i_node->skip) {
+                       free_inode_dir_entry(&entries[cur_entry]);
+                       continue;
                }
+       }
 
-               lmfs_put_block(bp);
-               bp = read_extent_block(extent, *offset /
-                   v_pri.logical_block_size_l);
+       /* Resize dynamic array to correct size */
+       dir->dir_contents = alloc_mem(sizeof(struct inode_dir_entry) * cur_entry);
+       memcpy(dir->dir_contents, entries, sizeof(struct inode_dir_entry) * cur_entry);
+       dir->dir_size = cur_entry;
+
+       /* The name pointer has to point to the new memory location. */
+       for (cpt = 0; cpt < cur_entry; cpt++) {
+               if (dir->dir_contents[cpt].r_name == NULL)
+                       dir->dir_contents[cpt].name =
+                           dir->dir_contents[cpt].i_name;
+               else
+                       dir->dir_contents[cpt].name =
+                           dir->dir_contents[cpt].r_name;
        }
 
-       return bp;
+       return (status == EOF) ? OK : status;
 }
 
-int read_inode(struct inode *i_node, struct dir_extent *extent, size_t offset,
-       size_t *new_offset)
+int check_inodes(void) {
+       /* Check whether there are no more inodes in use. Called on unmount. */
+       int i;
+
+       /* XXX: actually check for inodes in use. */
+       return TRUE;
+}
+
+int read_inode(struct inode_dir_entry *dir_entry, struct dir_extent *extent,
+       size_t *offset)
 {
        struct iso9660_dir_record *dir_rec;
        struct buf *bp;
+       struct inode *i_node;
+       ino_t ino_nr;
+       int name_only = FALSE;
 
        /* Find inode. */
-       bp = fetch_inode(extent, &offset);
-       if (bp == NULL)
+       bp = read_extent_block(extent, *offset);
+       if (bp == NULL) {
                return EOF;
+       }
+
+       /* Check if we are crossing a sector boundary. */
+       dir_rec = (struct iso9660_dir_record*)(b_data(bp) + *offset %
+                 v_pri.logical_block_size_l);
+
+       if (dir_rec->length == 0) {
+               *offset = ((*offset / v_pri.logical_block_size_l) + 1) *
+                   v_pri.logical_block_size_l;
+
+               lmfs_put_block(bp);
+               bp = read_extent_block(extent, *offset);
+               if (bp == NULL) {
+                       return EOF;
+               }
 
-       dir_rec = (struct iso9660_dir_record*)(b_data(bp) + offset %
+               dir_rec = (struct iso9660_dir_record*)(b_data(bp) + *offset %
                  v_pri.logical_block_size_l);
+       }
 
        /* Parse basic ISO 9660 specs. */
-       if (check_dir_record(dir_rec,
-           offset % v_pri.logical_block_size_l) != OK) {
+       if (check_dir_record(dir_rec, *offset % v_pri.logical_block_size_l)
+           != OK) {
                lmfs_put_block(bp);
                return EINVAL;
        }
 
-       memset(&i_node->i_stat, 0, sizeof(struct stat));
+       /* Get inode */
+       if ((dir_rec->file_flags & D_TYPE) == D_DIRECTORY) {
+               ino_nr = dir_rec->loc_extent_l;
+       }
+       else {
+               ino_nr = get_extent_absolute_block_id(extent, *offset)
+                   * v_pri.logical_block_size_l +
+                   *offset % v_pri.logical_block_size_l;
+       }
 
-       i_node->i_stat.st_ino = get_extent_absolute_block_id(extent,
-           offset / v_pri.logical_block_size_l) * v_pri.logical_block_size_l +
-           offset % v_pri.logical_block_size_l;
+       i_node = inode_cache_get(ino_nr);
+       if (i_node) {
+               /* Inode was already loaded, parse file names only. */
+               dir_entry->i_node = i_node;
+               i_node->i_refcount++;
 
-       read_inode_iso9660(i_node, dir_rec);
+               memset(&dir_entry->i_name[0], 0, sizeof(dir_entry->i_name));
+
+               name_only = TRUE;
+       }
+       else {
+               /* Inode wasn't in memory, parse it. */
+               i_node = alloc_mem(sizeof(struct inode));
+               dir_entry->i_node = i_node;
+               i_node->i_refcount = 1;
+               i_node->i_stat.st_ino = ino_nr;
+               inode_cache_add(ino_nr, i_node);
+       }
+
+       dir_entry->i_node = i_node;
+       read_inode_iso9660(dir_entry, dir_rec, extent, *offset, name_only);
 
        /* Parse extensions. */
-       read_inode_susp(i_node, dir_rec, bp,
-           offset % v_pri.logical_block_size_l);
+#ifdef ISO9660_OPTION_ROCKRIDGE
+       read_inode_susp(dir_entry, dir_rec, bp,
+           *offset % v_pri.logical_block_size_l, name_only);
+#endif
+
+       *offset += dir_rec->length;
+       if (dir_rec->length % 2)
+               (*offset)++;
 
-       offset += dir_rec->length;
-       read_inode_extents(i_node, dir_rec, extent, &offset);
+#ifdef ISO9660_OPTION_MODE3
+       read_inode_extents(dir_entry, dir_rec, extent, offset);
+#endif
 
        lmfs_put_block(bp);
-       if (new_offset != NULL)
-               *new_offset = offset;
+
        return OK;
 }
 
-void read_inode_iso9660(struct inode *i,
-       const struct iso9660_dir_record *dir_rec)
-{
-       char *cp;
+struct inode* inode_cache_get(ino_t ino_nr) {
+       struct inode_cache *i_node;
+       HASH_FIND(hh, icache, &ino_nr, sizeof(ino_t), i_node);
 
-       /* Parse first extent. */
-       if (dir_rec->data_length_l > 0) {
-               assert(i->extent == NULL);
-               i->extent = alloc_extent();
-               i->extent->location = dir_rec->loc_extent_l +
-                                     dir_rec->ext_attr_rec_length;
-               i->extent->length = dir_rec->data_length_l /
-                                   v_pri.logical_block_size_l;
-               if (dir_rec->data_length_l % v_pri.logical_block_size_l)
-                       i->extent->length++;
+       if (i_node)
+               return i_node->value;
+       else
+               return NULL;
+}
 
-               i->i_stat.st_size = dir_rec->data_length_l;
-       }
+void inode_cache_add(ino_t ino_nr, struct inode *i_node) {
+       struct inode_cache *c_check;
+       struct inode_cache *c_entry;
 
-       /* Parse timestamps (record date). */
-       i->i_stat.st_atime = i->i_stat.st_mtime = i->i_stat.st_ctime =
-           i->i_stat.st_birthtime = date7_to_time_t(dir_rec->rec_date);
+       HASH_FIND(hh, icache, &ino_nr, sizeof(ino_t), c_check);
 
-       if ((dir_rec->file_flags & D_TYPE) == D_DIRECTORY) {
-               i->i_stat.st_mode = S_IFDIR;
-               i->i_stat.st_ino =
-                   i->extent->location * v_pri.logical_block_size_l;
+       if (c_check == NULL) {
+               c_entry = alloc_mem(sizeof(struct inode_cache));
+               c_entry->key = ino_nr;
+               c_entry->value = i_node;
+
+               HASH_ADD(hh, icache, key, sizeof(ino_t), c_entry);
        }
        else
-               i->i_stat.st_mode = S_IFREG;
-       i->i_stat.st_mode |= 0555;
+               panic("Trying to insert inode into cache twice");
+}
+
+void read_inode_iso9660(struct inode_dir_entry *i,
+       const struct iso9660_dir_record *dir_rec, struct dir_extent *extent,
+       size_t offset, int name_only)
+{
+       char *cp;
 
        /* Parse file name. */
        if (dir_rec->file_id[0] == 0)
@@ -247,89 +286,57 @@ void read_inode_iso9660(struct inode *i,
 
                /* Truncate/ignore file version suffix. */
                cp = strchr(i->i_name, ';');
-               if (cp != NULL)
+               if (cp != NULL) {
                        *cp = '\0';
-               /* Truncate dot if file has no extension. */
-               if (strchr(i->i_name, '.') + 1 == cp)
-                       *(cp-1) = '\0';
+                       /* Truncate dot if file has no extension. */
+                       if (strchr(i->i_name, '.') + 1 == cp)
+                               *(cp-1) = '\0';
+               }
        }
 
-       /* Initialize stat. */
-       i->i_stat.st_dev = fs_dev;
-       i->i_stat.st_blksize = v_pri.logical_block_size_l;
-       i->i_stat.st_blocks =
-           dir_rec->data_length_l / v_pri.logical_block_size_l;
-       i->i_stat.st_nlink = 1;
-}
-
-void read_inode_extents(struct inode *i,
-       const struct iso9660_dir_record *dir_rec,
-       struct dir_extent *extent, size_t *offset)
-{
-       struct buf *bp;
-       struct iso9660_dir_record *extent_rec;
-       struct dir_extent *cur_extent = i->extent;
-       int done = FALSE;
-
-       /*
-        * No need to search extents if file is empty or has final directory
-        * record flag set.
-        */
-       if (cur_extent == NULL ||
-           ((dir_rec->file_flags & D_NOT_LAST_EXTENT) == 0))
+       if (name_only == TRUE)
                return;
 
-       while (!done) {
-               bp = fetch_inode(extent, offset);
-               if (bp == NULL)
-                       return;
+       /* Parse first extent. */
+       if (dir_rec->data_length_l > 0) {
+               i->i_node->extent.location = dir_rec->loc_extent_l +
+                   dir_rec->ext_attr_rec_length;
+               i->i_node->extent.length = dir_rec->data_length_l /
+                   v_pri.logical_block_size_l;
 
-               bp = read_extent_block(extent,
-                   *offset / v_pri.logical_block_size_l);
-               extent_rec = (struct iso9660_dir_record*)(b_data(bp) +
-                   *offset % v_pri.logical_block_size_l);
+               if (dir_rec->data_length_l % v_pri.logical_block_size_l)
+                       i->i_node->extent.length++;
 
-               if (check_dir_record(dir_rec,
-                   *offset % v_pri.logical_block_size_l) != OK) {
-                       lmfs_put_block(bp);
-                       return;
-               }
+               i->i_node->i_stat.st_size = dir_rec->data_length_l;
+       }
 
-               /* Extent entries should share the same name. */
-               if ((dir_rec->length_file_id == extent_rec->length_file_id) &&
-                   (memcmp(dir_rec->file_id, extent_rec->file_id,
-                   dir_rec->length_file_id) == 0)) {
-                       /* Add the extent at the end of the linked list. */
-                       assert(cur_extent->next == NULL);
-                       cur_extent->next = alloc_extent();
-                       cur_extent->next->location = dir_rec->loc_extent_l +
-                           dir_rec->ext_attr_rec_length;
-                       cur_extent->next->length = dir_rec->data_length_l /
-                           v_pri.logical_block_size_l;
-                       if (dir_rec->data_length_l % v_pri.logical_block_size_l)
-                               cur_extent->next->length++;
-
-                       i->i_stat.st_size += dir_rec->data_length_l;
-                       i->i_stat.st_blocks += cur_extent->next->length;
-
-                       cur_extent = cur_extent->next;
-                       *offset += extent_rec->length;
-               }
-               else
-                       done = TRUE;
+       /* Parse timestamps (record date). */
+       i->i_node->i_stat.st_atime = i->i_node->i_stat.st_mtime =
+           i->i_node->i_stat.st_ctime = i->i_node->i_stat.st_birthtime =
+           date7_to_time_t(dir_rec->rec_date);
 
-               /* Check if not last extent bit is not set. */
-               if ((dir_rec->file_flags & D_NOT_LAST_EXTENT) == 0)
-                       done = TRUE;
+       if ((dir_rec->file_flags & D_TYPE) == D_DIRECTORY)
+               i->i_node->i_stat.st_mode = S_IFDIR;
+       else
+               i->i_node->i_stat.st_mode = S_IFREG;
 
-               lmfs_put_block(bp);
-       }
+       i->i_node->i_stat.st_mode |= 0555;
+
+       /* Initialize stat. */
+       i->i_node->i_stat.st_dev = fs_dev;
+       i->i_node->i_stat.st_blksize = v_pri.logical_block_size_l;
+       i->i_node->i_stat.st_blocks =
+           dir_rec->data_length_l / v_pri.logical_block_size_l;
+       i->i_node->i_stat.st_nlink = 1;
 }
 
-void read_inode_susp(struct inode *i, const struct iso9660_dir_record *dir_rec,
-       struct buf *bp, size_t offset)
+#ifdef ISO9660_OPTION_ROCKRIDGE
+
+void read_inode_susp(struct inode_dir_entry *i,
+       const struct iso9660_dir_record *dir_rec, struct buf *bp, size_t offset,
+       int name_only)
 {
-       int susp_offset, susp_size;
+       int susp_offset, susp_size, name_length;
        struct rrii_dir_record rrii_data;
 
        susp_offset = 33 + dir_rec->length_file_id;
@@ -338,48 +345,79 @@ void read_inode_susp(struct inode *i, const struct iso9660_dir_record *dir_rec,
                susp_offset++;
        }
 
-       if(dir_rec->length - susp_offset >= 4) {
-               susp_size = dir_rec->length - susp_offset;
-
-               /* Initialize record with known, sane data. */
-               memcpy(rrii_data.mtime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
-               memcpy(rrii_data.atime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
-               memcpy(rrii_data.ctime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
-               memcpy(rrii_data.birthtime, dir_rec->rec_date,
-                   ISO9660_SIZE_DATE7);
-
-               rrii_data.d_mode = i->i_stat.st_mode;
-               rrii_data.uid    = 0;
-               rrii_data.gid    = 0;
-               rrii_data.rdev   = NO_DEV;
-               rrii_data.file_id_rrip[0] = '\0';
-               rrii_data.slink_rrip[0]   = '\0';
-
-               parse_susp_buffer(&rrii_data, b_data(bp)+offset+susp_offset,
-                   susp_size);
-
-               /* Copy back data from rrii_dir_record structure. */
-               i->i_stat.st_atime = date7_to_time_t(rrii_data.atime);
-               i->i_stat.st_ctime = date7_to_time_t(rrii_data.ctime);
-               i->i_stat.st_mtime = date7_to_time_t(rrii_data.mtime);
-               i->i_stat.st_birthtime = date7_to_time_t(rrii_data.birthtime);
-
-               i->i_stat.st_mode = rrii_data.d_mode;
-               i->i_stat.st_uid  = rrii_data.uid;
-               i->i_stat.st_gid  = rrii_data.gid;
-               i->i_stat.st_rdev = rrii_data.rdev;
-
-               if (rrii_data.file_id_rrip[0] != '\0')
-                       strlcpy(i->i_name, rrii_data.file_id_rrip,
-                          sizeof(i->i_name));
-               if (rrii_data.slink_rrip[0] != '\0')
-                       strlcpy(i->s_link, rrii_data.slink_rrip,
-                          sizeof(i->s_link));
+       if(dir_rec->length - susp_offset < 4)
+               return;
+
+       susp_size = dir_rec->length - susp_offset;
+
+       /* Initialize record with known, sane data. */
+       memcpy(rrii_data.mtime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
+       memcpy(rrii_data.atime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
+       memcpy(rrii_data.ctime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
+       memcpy(rrii_data.birthtime, dir_rec->rec_date, ISO9660_SIZE_DATE7);
+
+       rrii_data.d_mode = i->i_node->i_stat.st_mode;
+       rrii_data.uid    = SYS_UID;
+       rrii_data.gid    = SYS_GID;
+       rrii_data.rdev   = NO_DEV;
+       rrii_data.file_id_rrip[0] = '\0';
+       rrii_data.slink_rrip[0]   = '\0';
+       rrii_data.reparented_inode = NULL;
+
+       parse_susp_buffer(&rrii_data, b_data(bp)+offset+susp_offset, susp_size);
+
+       /* Copy back data from rrii_dir_record structure. */
+       if (rrii_data.file_id_rrip[0] != '\0') {
+               name_length = strlen(rrii_data.file_id_rrip);
+               i->r_name = alloc_mem(name_length + 1);
+               memcpy(i->r_name, rrii_data.file_id_rrip, name_length);
+       }
+
+       if (rrii_data.slink_rrip[0] != '\0') {
+               name_length = strlen(rrii_data.slink_rrip);
+               i->i_node->s_name = alloc_mem(name_length + 1);
+               memcpy(i->i_node->s_name, rrii_data.slink_rrip, name_length);
        }
+
+       if (rrii_data.reparented_inode) {
+               /* Recycle the inode already parsed. */
+               i->i_node = rrii_data.reparented_inode;
+               return;
+       }
+
+       /* XXX: not the correct way to ignore reparented directory holder... */
+       if (strcmp(rrii_data.file_id_rrip, ".rr_moved") == 0)
+               i->i_node->skip = 1;
+
+       if (name_only == TRUE)
+               return;
+
+       /* Write back all Rock Ridge properties. */
+       i->i_node->i_stat.st_atime = date7_to_time_t(rrii_data.atime);
+       i->i_node->i_stat.st_ctime = date7_to_time_t(rrii_data.ctime);
+       i->i_node->i_stat.st_mtime = date7_to_time_t(rrii_data.mtime);
+       i->i_node->i_stat.st_birthtime = date7_to_time_t(rrii_data.birthtime);
+
+       i->i_node->i_stat.st_mode = rrii_data.d_mode;
+       i->i_node->i_stat.st_uid  = rrii_data.uid;
+       i->i_node->i_stat.st_gid  = rrii_data.gid;
+       i->i_node->i_stat.st_rdev = rrii_data.rdev;
 }
 
-int check_dir_record(const struct iso9660_dir_record *d, size_t offset)
+#endif
+
+#ifdef ISO9660_OPTION_MODE3
+
+void read_inode_extents(struct inode *i,
+       const struct iso9660_dir_record *dir_rec,
+       struct dir_extent *extent, size_t *offset)
 {
+       panic("read_inode_extents() isn't implemented yet!");
+}
+
+#endif
+
+int check_dir_record(const struct iso9660_dir_record *d, size_t offset) {
        /* Run some consistency check on a directory entry. */
        if ((d->length < 33) || (d->length_file_id < 1))
                return EINVAL;
@@ -390,15 +428,3 @@ int check_dir_record(const struct iso9660_dir_record *d, size_t offset)
 
        return OK;
 }
-
-int check_inodes(void)
-{
-       /* Check whether there are no more inodes in use. Called on unmount. */
-       int i;
-
-       for (i = 0; i < NR_INODE_RECORDS; i++)
-               if (inodes[i].i_count > 0)
-                       return FALSE;
-
-       return TRUE;
-}
index 19ce1953e2b24b3ce52aaf118550d1200ca7bdb3..d0635f8aa1351df364d7b735c1077556b8a4dda8 100644 (file)
@@ -32,30 +32,40 @@ struct rrii_dir_record {
        mode_t d_mode;          /* file mode */
        uid_t uid;              /* user ID of the file's owner */
        gid_t gid;              /* group ID of the file's group */
-       dev_t rdev;             /* device ID */
+       dev_t rdev;             /* device major/minor */
 
        char file_id_rrip[ISO9660_RRIP_MAX_FILE_ID_LEN];        /* file name */
        char slink_rrip[ISO9660_RRIP_MAX_FILE_ID_LEN];          /* symbolic link */
+
+       struct inode *reparented_inode;
 } ;
 
 struct dir_extent {
        /*
         * Extent (contiguous array of logical sectors).
         */
-       char in_use;
        u32_t location;
        u32_t length;
        struct dir_extent *next;
 } ;
 
+struct inode_dir_entry {
+       struct inode *i_node;
+       char *name;                     /* Pointer to real name */
+       char i_name[ISO9660_MAX_FILE_ID_LEN+1]; /* ISO 9660 name */
+       char *r_name;                   /* Rock Ridge name */
+} ;
+
 struct inode {
        int i_count;                    /* usage counter of this inode */
+       int i_refcount;                 /* reference counter of this inode */
        int i_mountpoint;               /* flag for inode being used as a mount point */
-       int ea_length;                  /* total size of extended attributes in bytes */
        struct stat i_stat;             /* inode properties */
-       struct dir_extent *extent;      /* first extent of file */
-       char i_name[NAME_MAX];          /* inode name */
-       char s_link[NAME_MAX];          /* symbolic link target */
+       struct dir_extent extent;      /* first extent of file */
+       struct inode_dir_entry *dir_contents;   /* contents of directory */
+       size_t dir_size;                /* number of inodes in this directory */
+       char *s_name;                   /* Rock Ridge symbolic link */
+       int skip;                       /* skip inode because of reparenting */
 } ;
 
 struct opt {
index 5f5f8bbfb27f851dd2683812c24f3fdaf7541199..c6f7e37c525142b5c1f166c2de8f9e110fba506c 100644 (file)
@@ -3,21 +3,21 @@
 ssize_t fs_rdlink(ino_t ino_nr, struct fsdriver_data *data, size_t bytes)
 {
        struct inode *i_node;
-       size_t len;
+       size_t len = 0;
        int r;
 
        /* Try to get inode according to its index */
-       if ((i_node = find_inode(ino_nr)) == NULL)
+       if ((i_node = get_inode(ino_nr)) == NULL)
                return EINVAL; /* no inode found */
 
        if (!S_ISLNK(i_node->i_stat.st_mode))
                return EACCES;
 
-       len = strlen(i_node->s_link);
+       len = strlen(i_node->s_name);
        if (len > bytes)
                len = bytes;
 
-       if ((r = fsdriver_copyout(data, 0, i_node->s_link, len)) != OK)
+       if ((r = fsdriver_copyout(data, 0, i_node->s_name, len)) != OK)
                return r;
 
        return len;
index 5b9266f9b3eed0648db416d94085b3f02a680d48..3e4429531bfaabeaa448d5844ab505b84f9b97d9 100644 (file)
@@ -40,7 +40,7 @@ int fs_mountpt(ino_t ino_nr)
         */
        struct inode *rip;
 
-       if ((rip = find_inode(ino_nr)) == NULL)
+       if ((rip = get_inode(ino_nr)) == NULL)
                return EINVAL;
 
        if (rip->i_mountpoint)
@@ -62,5 +62,5 @@ void fs_unmount(void)
        bdev_close(fs_dev);
 
        if (check_inodes() == FALSE)
-               printf("ISOFS: unmounting with in-use inodes!\n");
+               puts("ISOFS: unmounting with in-use inodes!\n");
 }
index 04af43cdf8eaf668b1a7a72bb093c3654bde6ae1..cd2ad25f1162796266200056329874cb75ff15ca 100644 (file)
@@ -1,17 +1,16 @@
 #include "inc.h"
 
 static int search_dir(
-       struct inode *ldir_ptr,         /* dir record parent */
+       struct inode *ldir_ptr,                 /* dir record parent */
        char string[NAME_MAX],                  /* component to search for */
        ino_t *numb                             /* pointer to new dir record */
 ) {
-       /* The search_dir function performs the operation of searching for the
+       /*
+        * The search_dir function performs the operation of searching for the
         * component ``string" in ldir_ptr. It returns the response and the
         * number of the inode in numb.
         */
-       struct inode *dir_tmp;
-       size_t pos = 0;
-       int r;
+       int r, i;
 
        /*
         * This function search a particular element (in string) in a inode and
@@ -21,69 +20,24 @@ static int search_dir(
        if ((ldir_ptr->i_stat.st_mode & S_IFMT) != S_IFDIR)
                return ENOTDIR;
 
-       if (strcmp(string, ".") == 0) {
+       r = read_directory(ldir_ptr);
+       if (r != OK)
+               return r;
+
+       if (strcmp(".", string) == 0) {
                *numb = ldir_ptr->i_stat.st_ino;
                return OK;
        }
 
-       /*
-        * Parent directories need special attention to make sure directory
-        * inodes stay consistent.
-       */
-       if (strcmp(string, "..") == 0) {
-               if (ldir_ptr->i_stat.st_ino ==
-                   v_pri.inode_root->i_stat.st_ino) {
-                       *numb = v_pri.inode_root->i_stat.st_ino;
-                       return OK;
-               }
-               else {
-                       dir_tmp = alloc_inode();
-                       r = read_inode(dir_tmp, ldir_ptr->extent, pos, &pos);
-                       if ((r != OK) || (pos >= ldir_ptr->i_stat.st_size)) {
-                               put_inode(dir_tmp);
-                               return ENOENT;
-                       }
-                       /* Temporary fix for extent spilling */
-                       put_inode(dir_tmp);
-                       dir_tmp = alloc_inode();
-                       /* End of fix */
-                       r = read_inode(dir_tmp, ldir_ptr->extent, pos, &pos);
-                       if ((r != OK) || (pos >= ldir_ptr->i_stat.st_size)) {
-                               put_inode(dir_tmp);
-                               return ENOENT;
-                       }
-                       *numb = dir_tmp->i_stat.st_ino;
-                       put_inode(dir_tmp);
+       /* Walk the directory listing. */
+       for (i = 0; i < ldir_ptr->dir_size; i++) {
+               if (strcmp(string, ldir_ptr->dir_contents[i].name) == 0) {
+                       *numb = ldir_ptr->dir_contents[i].i_node->i_stat.st_ino;
                        return OK;
                }
        }
 
-       /* Read the dir's content */
-       while (TRUE) {
-               dir_tmp = alloc_inode();
-               r = read_inode(dir_tmp, ldir_ptr->extent, pos, &pos);
-               if ((r != OK) || (pos >= ldir_ptr->i_stat.st_size)) {
-                       put_inode(dir_tmp);
-                       return ENOENT;
-               }
-
-               if ((strcmp(dir_tmp->i_name, string) == 0) ||
-                   (strcmp(dir_tmp->i_name, "..") &&
-                   strcmp(string, "..") == 0)) {
-                       if (dir_tmp->i_stat.st_ino ==
-                           v_pri.inode_root->i_stat.st_ino) {
-                               *numb = v_pri.inode_root->i_stat.st_ino;
-                               put_inode(dir_tmp);
-                               return OK;
-                       }
-
-                       *numb = dir_tmp->i_stat.st_ino;
-                       put_inode(dir_tmp);
-                       return OK;
-               }
-
-               put_inode(dir_tmp);
-       }
+       return ENOENT;
 }
 
 int fs_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node,
@@ -97,7 +51,7 @@ int fs_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node,
        int r;
 
        /* Find the starting inode. */
-       if ((dirp = find_inode(dir_nr)) == NULL)
+       if ((dirp = get_inode(dir_nr)) == NULL)
                return EINVAL;
 
        /* Look up the directory entry. */
@@ -105,7 +59,7 @@ int fs_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node,
                return r;
 
        /* The component has been found in the directory.  Get the inode. */
-       if ((rip = get_inode(ino_nr)) == NULL)
+       if ((rip = open_inode(ino_nr)) == NULL)
                return EIO;     /* FIXME: this could have multiple causes */
 
        /* Return its details to the caller. */
index 051eb052f3ff0d99356a2082eb14dd68d682016f..8fabfcdb040a64b00f67a69868697d88b35c6b92 100644 (file)
@@ -6,27 +6,23 @@ struct rrii_dir_record;
 struct iso9660_dir_record;
 struct iso9660_vol_pri_desc;
 struct inode;
+struct inode_dir_entry;
 
 /* inode.c */
 int fs_putnode(ino_t ino_nr, unsigned int count);
 
-struct inode* alloc_inode(void);
-struct inode* find_inode(ino_t i);
+struct inode* get_inode(ino_t ino_nr);
+struct inode* open_inode(ino_t ino_nr);
 void put_inode(struct inode *i);
 void dup_inode(struct inode *i_node);
-struct inode* get_inode(ino_t i);
 
-int read_inode(struct inode *i_node, struct dir_extent *extent, size_t offset,
-       size_t *new_offset);
-void read_inode_iso9660(struct inode *i,
-       const struct iso9660_dir_record *dir_rec);
-void read_inode_extents(struct inode *i,
-       const struct iso9660_dir_record *dir_rec, struct dir_extent *extent,
-       size_t *offset);
-void read_inode_susp(struct inode *i, const struct iso9660_dir_record *dir_rec,
-       struct buf *bp, size_t offset);
+int read_directory(struct inode *dir);
 
-int check_dir_record(const struct iso9660_dir_record *d, size_t offset);
+int read_inode(struct inode_dir_entry *dir_entry, struct dir_extent *extent,
+    size_t *offset);
+
+struct inode* inode_cache_get(ino_t ino_nr);
+void inode_cache_add(ino_t ino_nr, struct inode *i_node);
 
 int check_inodes(void);
 
@@ -54,7 +50,7 @@ int fs_stat(ino_t ino_nr, struct stat *statbuf);
 int fs_statvfs(struct statvfs *st);
 
 /* super.c */
-int release_vol_pri_desc(struct iso9660_vol_pri_desc *v_pri);
+int release_vol_pri_desc(struct iso9660_vol_pri_desc *vol_pri);
 int read_vds(struct iso9660_vol_pri_desc *v_pri, dev_t dev);
 
 /* susp.c */
@@ -67,9 +63,10 @@ void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer,
 int parse_susp_rock_ridge(struct rrii_dir_record *dir, char *buffer);
 
 /* utility.c */
-struct dir_extent* alloc_extent(void);
+void free_inode_dir_entry(struct inode_dir_entry *e);
 void free_extent(struct dir_extent *extent);
 struct buf* read_extent_block(struct dir_extent *e, size_t block);
 size_t get_extent_absolute_block_id(struct dir_extent *e, size_t block);
 
 time_t date7_to_time_t(const u8_t *date);
+void* alloc_mem(size_t s);
\ No newline at end of file
index e5f6dd45d80b08503a48c89dd6c226012eeb74ce..b286500652a79c50fe06aab606fef310daf880f3 100644 (file)
@@ -12,7 +12,7 @@ ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
        int r;
 
        /* Try to get inode according to its index. */
-       if ((i_node = find_inode(ino_nr)) == NULL)
+       if ((i_node = get_inode(ino_nr)) == NULL)
                return EINVAL; /* No inode found. */
 
        f_size = i_node->i_stat.st_size;
@@ -37,7 +37,7 @@ ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
                        chunk = bytes;
 
                /* Read 'chunk' bytes. */
-               bp = read_extent_block(i_node->extent, pos / block_size);
+               bp = read_extent_block(&i_node->extent, pos);
                if (bp == NULL)
                        panic("bp not valid in rw_chunk; this can't happen");
 
@@ -61,42 +61,38 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
        off_t *pos)
 {
        struct fsdriver_dentry fsdentry;
-       struct inode *i_node, *i_node_tmp;
-       size_t cur_pos, new_pos;
+       struct inode *i_node;
+       off_t cur_pos;
        int r, len;
        char *cp;
 
-       if ((i_node = find_inode(ino_nr)) == NULL)
+       if ((i_node = get_inode(ino_nr)) == NULL)
                return EINVAL;
 
        if (*pos < 0 || *pos > SSIZE_MAX)
                return EINVAL;
 
+       r = read_directory(i_node);
+       if (r != OK)
+               return r;
+
        fsdriver_dentry_init(&fsdentry, data, bytes, getdents_buf,
            sizeof(getdents_buf));
 
        r = OK;
 
-       for (cur_pos = (size_t)*pos; ; cur_pos = new_pos) {
-               i_node_tmp = alloc_inode();
-               r = read_inode(i_node_tmp, i_node->extent, cur_pos, &new_pos);
-               if ((r != OK) || (new_pos >= i_node->i_stat.st_size)) {
-                       put_inode(i_node_tmp);
-                       break;
-               }
-
+       for (cur_pos = *pos; cur_pos < i_node->dir_size; cur_pos++) {
                /* Compute the length of the name */
-               cp = memchr(i_node_tmp->i_name, '\0', NAME_MAX);
+               cp = memchr(i_node->dir_contents[cur_pos].name, '\0', NAME_MAX);
                if (cp == NULL)
                        len = NAME_MAX;
                else
-                       len = cp - i_node_tmp->i_name;
-
-               r = fsdriver_dentry_add(&fsdentry, i_node_tmp->i_stat.st_ino,
-                   i_node_tmp->i_name, len,
-                   IFTODT(i_node_tmp->i_stat.st_mode));
+                       len = cp - i_node->dir_contents[cur_pos].name;
 
-               put_inode(i_node_tmp);
+               r = fsdriver_dentry_add(&fsdentry,
+                   i_node->dir_contents[cur_pos].i_node->i_stat.st_ino,
+                   i_node->dir_contents[cur_pos].name, len,
+                   IFTODT(i_node->dir_contents[cur_pos].i_node->i_stat.st_mode));
 
                if (r <= 0)
                        break;
index 6825b1031e74fc3f20978caa1d9b8f65360900a2..926b98c25e62b442bf34e8335c68d7e83d1b9de5 100644 (file)
@@ -6,7 +6,7 @@ int fs_stat(ino_t ino_nr, struct stat *statbuf)
 {
        struct inode *rip;
 
-       if ((rip = find_inode(ino_nr)) == NULL)
+       if ((rip = get_inode(ino_nr)) == NULL)
                return EINVAL;
 
        *statbuf = rip->i_stat;
index b8d7aa5a932cb154109e0f33f7dde8b8aff364b4..e6f208bfce6a4028f1e4e2ef1449b82ac747b3c4 100644 (file)
@@ -21,16 +21,16 @@ int release_vol_pri_desc(struct iso9660_vol_pri_desc *vol_pri)
        return OK;
 }
 
-static int create_vol_pri_desc(struct iso9660_vol_pri_desc *vol_pri, char *buf,
-       size_t __unused address)
+static int create_vol_pri_desc(struct iso9660_vol_pri_desc *vol_pri, char *buf)
 {
        /*
         * This function fullfill the super block data structure using the
         * information contained in the buffer.
         */
        struct iso9660_dir_record *root_record;
-       struct inode *root;
-       struct dir_extent *extent;
+       struct inode_dir_entry dir_entry;
+       struct dir_extent extent;
+       size_t dummy_offset = 0;
 
        if (vol_pri->i_count > 0)
                release_vol_pri_desc(vol_pri);
@@ -39,10 +39,9 @@ static int create_vol_pri_desc(struct iso9660_vol_pri_desc *vol_pri, char *buf,
 
        /* Check various fields for consistency. */
        if ((memcmp(vol_pri->standard_id, "CD001",
-           ISO9660_SIZE_STANDARD_ID) != 0) ||
-           (vol_pri->vd_version != 1) ||
-           (vol_pri->logical_block_size_l < 2048) ||
-           (vol_pri->file_struct_ver != 1))
+           ISO9660_SIZE_STANDARD_ID) != 0)
+            || (vol_pri->vd_version != 1)
+            || (vol_pri->logical_block_size_l < 2048))
                return EINVAL;
 
        lmfs_set_blocksize(vol_pri->logical_block_size_l);
@@ -51,24 +50,24 @@ static int create_vol_pri_desc(struct iso9660_vol_pri_desc *vol_pri, char *buf,
 
        /* Read root directory record. */
        root_record = (struct iso9660_dir_record *)vol_pri->root_directory;
-       root = alloc_inode();
-       extent = alloc_extent();
 
-       extent->location =
+       extent.location =
            root_record->loc_extent_l + root_record->ext_attr_rec_length;
-       extent->length =
+       extent.length =
            root_record->data_length_l / vol_pri->logical_block_size_l;
+       extent.next = NULL;
+
        if (root_record->data_length_l % vol_pri->logical_block_size_l)
-               extent->length++;
+               extent.length++;
 
-       if (read_inode(root, extent, 0, NULL) != OK) {
-               free_extent(extent);
-               put_inode(root);
+       memset(&dir_entry, 0, sizeof(struct inode_dir_entry));
+       if (read_inode(&dir_entry, &extent, &dummy_offset) != OK) {
                return EINVAL;
        }
 
-       free_extent(extent);
-       vol_pri->inode_root = root;
+       dir_entry.i_node->i_count = 1;
+
+       vol_pri->inode_root = dir_entry.i_node;
        vol_pri->i_count = 1;
 
        return OK;
@@ -99,8 +98,13 @@ int read_vds(struct iso9660_vol_pri_desc *vol_pri, dev_t dev)
                }
 
                if ((sbbuf[0] & BYTE) == VD_PRIMARY) {
+                       /* Free already parsed descriptor, if any. */
+                       if (vol_pri_flag == TRUE) {
+                               release_vol_pri_desc(vol_pri);
+                               vol_pri_flag = FALSE;
+                       }
                        /* Copy the buffer in the data structure. */
-                       if (create_vol_pri_desc(vol_pri, sbbuf, offset) == OK) {
+                       if (create_vol_pri_desc(vol_pri, sbbuf) == OK) {
                                vol_pri_flag = TRUE;
                        }
                }
index 80436e991f3047797a55c7c1260e5506d4a9537b..78005b48a1f01b6118bc73a8f64479b4c3ed582d 100644 (file)
@@ -6,6 +6,8 @@
 #include "inc.h"
 #include <sys/stat.h>
 
+#ifdef ISO9660_OPTION_ROCKRIDGE
+
 int parse_susp(struct rrii_dir_record *dir, char *buffer)
 {
        /* Parse fundamental SUSP entries */
@@ -127,3 +129,4 @@ void parse_susp_buffer(struct rrii_dir_record *dir, char *buffer, u32_t size)
        }
 }
 
+#endif
index d68bb94c140ea60b7796734a54b5f45c1e655482..b98456227ac1cbb5452bb3e8723e16ab279e4fae 100644 (file)
@@ -6,6 +6,43 @@
 #include "inc.h"
 #include <sys/stat.h>
 
+#ifdef ISO9660_OPTION_ROCKRIDGE
+
+void parse_susp_rock_ridge_plcl(struct rrii_dir_record *dir, u32_t block) {
+       struct inode *rep_inode;
+       struct buf *bp;
+       struct iso9660_dir_record *dir_rec;
+       struct dir_extent extent;
+       struct inode_dir_entry dummy_dir_entry;
+       size_t dummy_offset = 0;
+
+       /* Check if inode wasn't already parsed. */
+       rep_inode = inode_cache_get(block);
+       if (rep_inode != NULL) {
+               rep_inode->i_refcount++;
+               dir->reparented_inode = rep_inode;
+               return;
+       }
+
+       /* Peek ahead to build extent for read_inode. */
+       if (lmfs_get_block(&bp, fs_dev, block, NORMAL) != OK)
+               return;
+
+       dir_rec = (struct iso9660_dir_record*)b_data(bp);
+
+       extent.location = block;
+       extent.length = dir_rec->data_length_l / v_pri.logical_block_size_l;
+       if (dir_rec->data_length_l % v_pri.logical_block_size_l)
+               extent.length++;
+       extent.next = NULL;
+       lmfs_put_block(bp);
+
+       memset(&dummy_dir_entry, 0, sizeof(struct inode_dir_entry));
+       read_inode(&dummy_dir_entry, &extent, &dummy_offset);
+       free(dummy_dir_entry.r_name);
+       dir->reparented_inode = dummy_dir_entry.i_node;
+}
+
 void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer, int length)
 {
        /* Parse a Rock Ridge SUSP symbolic link entry (SL). */
@@ -18,13 +55,14 @@ void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer, int len
                component_length = *((u8_t*)(buffer + offset + 1));
 
                /* Add directory separator if necessary. */
-               if (dir->slink_rrip[0] != '\0') {
+               if (strcmp(dir->slink_rrip, "") != 0 &&
+                   strcmp(dir->slink_rrip, "/") != 0) {
                        slink_size = strlen(dir->slink_rrip);
                        if (slink_size + 2 >= ISO9660_RRIP_MAX_FILE_ID_LEN)
                                return;
 
-                       dir->slink_rrip[slink_size] = '/';
-                       slink_size++;
+                       dir->slink_rrip[slink_size++] = '/';
+                       dir->slink_rrip[slink_size] = '\0';
                }
                else
                        slink_size = strlen(dir->slink_rrip);
@@ -43,8 +81,9 @@ void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer, int len
                                        return;
                                }
 
-                               strlcpy(dir->slink_rrip + slink_size,
-                                   buffer + offset + 2, component_length+1);
+                               strlcat(&dir->slink_rrip[slink_size],
+                                       buffer + offset + 2,
+                                       component_length + 1);
 
                                break;
                        }
@@ -55,7 +94,7 @@ void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer, int len
                                        return;
                                }
 
-                               strcat(dir->slink_rrip + slink_size, ".");
+                               strcat(&dir->slink_rrip[slink_size], ".");
 
                                break;
                        }
@@ -66,7 +105,7 @@ void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer, int len
                                        return;
                                }
 
-                               strcat(dir->slink_rrip + slink_size, "..");
+                               strcat(&dir->slink_rrip[slink_size], "..");
 
                                break;
                        }
@@ -78,7 +117,7 @@ void parse_susp_rock_ridge_sl(struct rrii_dir_record *dir, char *buffer, int len
                                        return;
                                }
 
-                               strcat(dir->slink_rrip + slink_size, "/");
+                               strcat(&dir->slink_rrip[slink_size], "/");
 
                                break;
                        }
@@ -106,6 +145,7 @@ int parse_susp_rock_ridge(struct rrii_dir_record *dir, char *buffer)
        u32_t rrii_pn_rdev_major;
        u32_t rrii_pn_rdev_minor;
        mode_t rrii_px_posix_mode;
+       u32_t rrii_pcl_block;
 
        susp_signature[0] = buffer[0];
        susp_signature[1] = buffer[1];
@@ -115,26 +155,7 @@ int parse_susp_rock_ridge(struct rrii_dir_record *dir, char *buffer)
        if ((susp_signature[0] == 'P') && (susp_signature[1] == 'X') &&
            (susp_length >= 36) && (susp_version >= 1)) {
                /* POSIX file mode, UID and GID. */
-               rrii_px_posix_mode = *((u32_t*)(buffer + 4));
-
-               /* Check if file mode is supported by isofs. */
-               switch (rrii_px_posix_mode & _S_IFMT) {
-                       case S_IFCHR:
-                       case S_IFBLK:
-                       case S_IFREG:
-                       case S_IFDIR:
-                       case S_IFLNK: {
-                               dir->d_mode = rrii_px_posix_mode & _S_IFMT;
-                               break;
-                       }
-                       default: {
-                               /* Fall back to what ISO 9660 said. */
-                               dir->d_mode &= _S_IFMT;
-                               break;
-                       }
-               }
-
-               dir->d_mode |= rrii_px_posix_mode & 07777;
+               dir->d_mode = *((u32_t*)(buffer + 4));
                dir->uid = *((u32_t*)(buffer + 20));
                dir->gid = *((u32_t*)(buffer + 28));
 
@@ -143,9 +164,18 @@ int parse_susp_rock_ridge(struct rrii_dir_record *dir, char *buffer)
        else if ((susp_signature[0] == 'P') && (susp_signature[1] == 'N') &&
                 (susp_length >= 20) && (susp_version >= 1)) {
                /* Device ID (for character or block special inode). */
+
+               /*
+                * XXX: Specific to how Minix ISO is generated, will have to
+                * investigate why makefs does that later.
+                */
+#if 0
                rrii_pn_rdev_major = *((u32_t*)(buffer + 4));
                rrii_pn_rdev_minor = *((u32_t*)(buffer + 12));
-
+#else
+               rrii_pn_rdev_major = *((u32_t*)(buffer + 12)) >> 8;
+               rrii_pn_rdev_minor = *((u32_t*)(buffer + 12)) & 0xFF;
+#endif
                dir->rdev = makedev(rrii_pn_rdev_major, rrii_pn_rdev_minor);
 
                return OK;
@@ -174,16 +204,25 @@ int parse_susp_rock_ridge(struct rrii_dir_record *dir, char *buffer)
 
                return OK;
        }
-       else if ((susp_signature[0] == 'C') && (susp_signature[1] == 'L')) {
-               /* Ignored, skip. */
+       else if ((susp_signature[0] == 'P') && (susp_signature[1] == 'L') &&
+                (susp_length >= 12) && (susp_version >= 1)) {
+               /* Reparenting ".." directory entry. */
+               rrii_pcl_block = *((u32_t*)(buffer + 4));
+               parse_susp_rock_ridge_plcl(dir, rrii_pcl_block);
+
                return OK;
        }
-       else if ((susp_signature[0] == 'P') && (susp_signature[1] == 'L')) {
-               /* Ignored, skip. */
+       else if ((susp_signature[0] == 'C') && (susp_signature[1] == 'L') &&
+                (susp_length >= 12) && (susp_version >= 1)) {
+               /* Reorganize deep directory entry. */
+               rrii_pcl_block = *((u32_t*)(buffer + 4));
+               parse_susp_rock_ridge_plcl(dir, rrii_pcl_block);
+
                return OK;
        }
        else if ((susp_signature[0] == 'R') && (susp_signature[1] == 'E')) {
                /* Ignored, skip. */
+
                return OK;
        }
        else if ((susp_signature[0] == 'T') && (susp_signature[1] == 'F') &&
@@ -246,3 +285,4 @@ int parse_susp_rock_ridge(struct rrii_dir_record *dir, char *buffer)
        return EINVAL;
 }
 
+#endif
diff --git a/minix/fs/isofs/uthash.h b/minix/fs/isofs/uthash.h
new file mode 100644 (file)
index 0000000..d2255b1
--- /dev/null
@@ -0,0 +1,960 @@
+/*
+Copyright (c) 2003-2014, Troy D. Hanson     http://troydhanson.github.com/uthash/
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef UTHASH_H
+#define UTHASH_H
+
+#include <string.h>   /* memcmp,strlen */
+#include <stddef.h>   /* ptrdiff_t */
+#include <stdlib.h>   /* exit() */
+
+/* These macros use decltype or the earlier __typeof GNU extension.
+   As decltype is only available in newer compilers (VS2010 or gcc 4.3+
+   when compiling c++ source) this code uses whatever method is needed
+   or, for VS2008 where neither is available, uses casting workarounds. */
+#if defined(_MSC_VER)   /* MS compiler */
+#if _MSC_VER >= 1600 && defined(__cplusplus)  /* VS2010 or newer in C++ mode */
+#define DECLTYPE(x) (decltype(x))
+#else                   /* VS2008 or older (or VS2010 in C mode) */
+#define NO_DECLTYPE
+#define DECLTYPE(x)
+#endif
+#elif defined(__BORLANDC__) || defined(__LCC__) || defined(__WATCOMC__)
+#define NO_DECLTYPE
+#define DECLTYPE(x)
+#else                   /* GNU, Sun and other compilers */
+#define DECLTYPE(x) (__typeof(x))
+#endif
+
+#ifdef NO_DECLTYPE
+#define DECLTYPE_ASSIGN(dst,src)                                                 \
+do {                                                                             \
+  char **_da_dst = (char**)(&(dst));                                             \
+  *_da_dst = (char*)(src);                                                       \
+} while(0)
+#else
+#define DECLTYPE_ASSIGN(dst,src)                                                 \
+do {                                                                             \
+  (dst) = DECLTYPE(dst)(src);                                                    \
+} while(0)
+#endif
+
+/* a number of the hash function use uint32_t which isn't defined on Pre VS2010 */
+#if defined (_WIN32)
+#if defined(_MSC_VER) && _MSC_VER >= 1600
+#include <stdint.h>
+#elif defined(__WATCOMC__)
+#include <stdint.h>
+#else
+typedef unsigned int uint32_t;
+typedef unsigned char uint8_t;
+#endif
+#else
+#include <stdint.h>
+#endif
+
+#define UTHASH_VERSION 1.9.9
+
+#ifndef uthash_fatal
+#define uthash_fatal(msg) exit(-1)        /* fatal error (out of memory,etc) */
+#endif
+#ifndef uthash_malloc
+#define uthash_malloc(sz) malloc(sz)      /* malloc fcn                      */
+#endif
+#ifndef uthash_free
+#define uthash_free(ptr,sz) free(ptr)     /* free fcn                        */
+#endif
+
+#ifndef uthash_noexpand_fyi
+#define uthash_noexpand_fyi(tbl)          /* can be defined to log noexpand  */
+#endif
+#ifndef uthash_expand_fyi
+#define uthash_expand_fyi(tbl)            /* can be defined to log expands   */
+#endif
+
+/* initial number of buckets */
+#define HASH_INITIAL_NUM_BUCKETS 32      /* initial number of buckets        */
+#define HASH_INITIAL_NUM_BUCKETS_LOG2 5  /* lg2 of initial number of buckets */
+#define HASH_BKT_CAPACITY_THRESH 10      /* expand when bucket count reaches */
+
+/* calculate the element whose hash handle address is hhe */
+#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho)))
+
+#define HASH_FIND(hh,head,keyptr,keylen,out)                                     \
+do {                                                                             \
+  out=NULL;                                                                      \
+  if (head) {                                                                    \
+     unsigned _hf_bkt,_hf_hashv;                                                 \
+     HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt);   \
+     if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) {                           \
+       HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ],  \
+                        keyptr,keylen,out);                                      \
+     }                                                                           \
+  }                                                                              \
+} while (0)
+
+#ifdef HASH_BLOOM
+#define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM)
+#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0)
+#define HASH_BLOOM_MAKE(tbl)                                                     \
+do {                                                                             \
+  (tbl)->bloom_nbits = HASH_BLOOM;                                               \
+  (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN);                 \
+  if (!((tbl)->bloom_bv))  { uthash_fatal( "out of memory"); }                   \
+  memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN);                                \
+  (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE;                                       \
+} while (0)
+
+#define HASH_BLOOM_FREE(tbl)                                                     \
+do {                                                                             \
+  uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN);                              \
+} while (0)
+
+#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
+#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
+
+#define HASH_BLOOM_ADD(tbl,hashv)                                                \
+  HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
+
+#define HASH_BLOOM_TEST(tbl,hashv)                                               \
+  HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
+
+#else
+#define HASH_BLOOM_MAKE(tbl)
+#define HASH_BLOOM_FREE(tbl)
+#define HASH_BLOOM_ADD(tbl,hashv)
+#define HASH_BLOOM_TEST(tbl,hashv) (1)
+#define HASH_BLOOM_BYTELEN 0
+#endif
+
+#define HASH_MAKE_TABLE(hh,head)                                                 \
+do {                                                                             \
+  (head)->hh.tbl = (UT_hash_table*)uthash_malloc(                                \
+                  sizeof(UT_hash_table));                                        \
+  if (!((head)->hh.tbl))  { uthash_fatal( "out of memory"); }                    \
+  memset((head)->hh.tbl, 0, sizeof(UT_hash_table));                              \
+  (head)->hh.tbl->tail = &((head)->hh);                                          \
+  (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS;                        \
+  (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2;              \
+  (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head);                    \
+  (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc(                      \
+          HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));               \
+  if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); }             \
+  memset((head)->hh.tbl->buckets, 0,                                             \
+          HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket));               \
+  HASH_BLOOM_MAKE((head)->hh.tbl);                                               \
+  (head)->hh.tbl->signature = HASH_SIGNATURE;                                    \
+} while(0)
+
+#define HASH_ADD(hh,head,fieldname,keylen_in,add)                                \
+        HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add)
+
+#define HASH_REPLACE(hh,head,fieldname,keylen_in,add,replaced)                   \
+do {                                                                             \
+  replaced=NULL;                                                                 \
+  HASH_FIND(hh,head,&((add)->fieldname),keylen_in,replaced);                     \
+  if (replaced!=NULL) {                                                          \
+     HASH_DELETE(hh,head,replaced);                                              \
+  }                                                                              \
+  HASH_ADD(hh,head,fieldname,keylen_in,add);                                     \
+} while(0)
+
+#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add)                            \
+do {                                                                             \
+ unsigned _ha_bkt;                                                               \
+ (add)->hh.next = NULL;                                                          \
+ (add)->hh.key = (char*)(keyptr);                                                \
+ (add)->hh.keylen = (unsigned)(keylen_in);                                       \
+ if (!(head)) {                                                                  \
+    head = (add);                                                                \
+    (head)->hh.prev = NULL;                                                      \
+    HASH_MAKE_TABLE(hh,head);                                                    \
+ } else {                                                                        \
+    (head)->hh.tbl->tail->next = (add);                                          \
+    (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail);         \
+    (head)->hh.tbl->tail = &((add)->hh);                                         \
+ }                                                                               \
+ (head)->hh.tbl->num_items++;                                                    \
+ (add)->hh.tbl = (head)->hh.tbl;                                                 \
+ HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets,                         \
+         (add)->hh.hashv, _ha_bkt);                                              \
+ HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh);                   \
+ HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv);                                 \
+ HASH_EMIT_KEY(hh,head,keyptr,keylen_in);                                        \
+ HASH_FSCK(hh,head);                                                             \
+} while(0)
+
+#define HASH_TO_BKT( hashv, num_bkts, bkt )                                      \
+do {                                                                             \
+  bkt = ((hashv) & ((num_bkts) - 1));                                            \
+} while(0)
+
+/* delete "delptr" from the hash table.
+ * "the usual" patch-up process for the app-order doubly-linked-list.
+ * The use of _hd_hh_del below deserves special explanation.
+ * These used to be expressed using (delptr) but that led to a bug
+ * if someone used the same symbol for the head and deletee, like
+ *  HASH_DELETE(hh,users,users);
+ * We want that to work, but by changing the head (users) below
+ * we were forfeiting our ability to further refer to the deletee (users)
+ * in the patch-up process. Solution: use scratch space to
+ * copy the deletee pointer, then the latter references are via that
+ * scratch pointer rather than through the repointed (users) symbol.
+ */
+#define HASH_DELETE(hh,head,delptr)                                              \
+do {                                                                             \
+    struct UT_hash_handle *_hd_hh_del;                                           \
+    if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) )  {         \
+        uthash_free((head)->hh.tbl->buckets,                                     \
+                    (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \
+        HASH_BLOOM_FREE((head)->hh.tbl);                                         \
+        uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                      \
+        head = NULL;                                                             \
+    } else {                                                                     \
+        unsigned _hd_bkt;                                                        \
+        _hd_hh_del = &((delptr)->hh);                                            \
+        if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) {     \
+            (head)->hh.tbl->tail =                                               \
+                (UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) +               \
+                (head)->hh.tbl->hho);                                            \
+        }                                                                        \
+        if ((delptr)->hh.prev) {                                                 \
+            ((UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) +                  \
+                    (head)->hh.tbl->hho))->next = (delptr)->hh.next;             \
+        } else {                                                                 \
+            DECLTYPE_ASSIGN(head,(delptr)->hh.next);                             \
+        }                                                                        \
+        if (_hd_hh_del->next) {                                                  \
+            ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next +                     \
+                    (head)->hh.tbl->hho))->prev =                                \
+                    _hd_hh_del->prev;                                            \
+        }                                                                        \
+        HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt);   \
+        HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del);        \
+        (head)->hh.tbl->num_items--;                                             \
+    }                                                                            \
+    HASH_FSCK(hh,head);                                                          \
+} while (0)
+
+
+/* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */
+#define HASH_FIND_STR(head,findstr,out)                                          \
+    HASH_FIND(hh,head,findstr,(unsigned)strlen(findstr),out)
+#define HASH_ADD_STR(head,strfield,add)                                          \
+    HASH_ADD(hh,head,strfield[0],strlen(add->strfield),add)
+#define HASH_REPLACE_STR(head,strfield,add,replaced)                             \
+    HASH_REPLACE(hh,head,strfield[0],(unsigned)strlen(add->strfield),add,replaced)
+#define HASH_FIND_INT(head,findint,out)                                          \
+    HASH_FIND(hh,head,findint,sizeof(int),out)
+#define HASH_ADD_INT(head,intfield,add)                                          \
+    HASH_ADD(hh,head,intfield,sizeof(int),add)
+#define HASH_REPLACE_INT(head,intfield,add,replaced)                             \
+    HASH_REPLACE(hh,head,intfield,sizeof(int),add,replaced)
+#define HASH_FIND_PTR(head,findptr,out)                                          \
+    HASH_FIND(hh,head,findptr,sizeof(void *),out)
+#define HASH_ADD_PTR(head,ptrfield,add)                                          \
+    HASH_ADD(hh,head,ptrfield,sizeof(void *),add)
+#define HASH_REPLACE_PTR(head,ptrfield,add,replaced)                             \
+    HASH_REPLACE(hh,head,ptrfield,sizeof(void *),add,replaced)
+#define HASH_DEL(head,delptr)                                                    \
+    HASH_DELETE(hh,head,delptr)
+
+/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined.
+ * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
+ */
+#ifdef HASH_DEBUG
+#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0)
+#define HASH_FSCK(hh,head)                                                       \
+do {                                                                             \
+    struct UT_hash_handle *_thh;                                                 \
+    if (head) {                                                                  \
+        unsigned _bkt_i;                                                         \
+        unsigned _count;                                                         \
+        char *_prev;                                                             \
+        _count = 0;                                                              \
+        for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) {       \
+            unsigned _bkt_count = 0;                                             \
+            _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head;                      \
+            _prev = NULL;                                                        \
+            while (_thh) {                                                       \
+               if (_prev != (char*)(_thh->hh_prev)) {                            \
+                   HASH_OOPS("invalid hh_prev %p, actual %p\n",                  \
+                    _thh->hh_prev, _prev );                                      \
+               }                                                                 \
+               _bkt_count++;                                                     \
+               _prev = (char*)(_thh);                                            \
+               _thh = _thh->hh_next;                                             \
+            }                                                                    \
+            _count += _bkt_count;                                                \
+            if ((head)->hh.tbl->buckets[_bkt_i].count !=  _bkt_count) {          \
+               HASH_OOPS("invalid bucket count %u, actual %u\n",                 \
+                (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count);              \
+            }                                                                    \
+        }                                                                        \
+        if (_count != (head)->hh.tbl->num_items) {                               \
+            HASH_OOPS("invalid hh item count %u, actual %u\n",                   \
+                (head)->hh.tbl->num_items, _count );                             \
+        }                                                                        \
+        /* traverse hh in app order; check next/prev integrity, count */         \
+        _count = 0;                                                              \
+        _prev = NULL;                                                            \
+        _thh =  &(head)->hh;                                                     \
+        while (_thh) {                                                           \
+           _count++;                                                             \
+           if (_prev !=(char*)(_thh->prev)) {                                    \
+              HASH_OOPS("invalid prev %p, actual %p\n",                          \
+                    _thh->prev, _prev );                                         \
+           }                                                                     \
+           _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh);                    \
+           _thh = ( _thh->next ?  (UT_hash_handle*)((char*)(_thh->next) +        \
+                                  (head)->hh.tbl->hho) : NULL );                 \
+        }                                                                        \
+        if (_count != (head)->hh.tbl->num_items) {                               \
+            HASH_OOPS("invalid app item count %u, actual %u\n",                  \
+                (head)->hh.tbl->num_items, _count );                             \
+        }                                                                        \
+    }                                                                            \
+} while (0)
+#else
+#define HASH_FSCK(hh,head)
+#endif
+
+/* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to
+ * the descriptor to which this macro is defined for tuning the hash function.
+ * The app can #include <unistd.h> to get the prototype for write(2). */
+#ifdef HASH_EMIT_KEYS
+#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)                                   \
+do {                                                                             \
+    unsigned _klen = fieldlen;                                                   \
+    write(HASH_EMIT_KEYS, &_klen, sizeof(_klen));                                \
+    write(HASH_EMIT_KEYS, keyptr, fieldlen);                                     \
+} while (0)
+#else
+#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)
+#endif
+
+/* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */
+#ifdef HASH_FUNCTION
+#define HASH_FCN HASH_FUNCTION
+#else
+#define HASH_FCN HASH_JEN
+#endif
+
+/* The Bernstein hash function, used in Perl prior to v5.6. Note (x<<5+x)=x*33. */
+#define HASH_BER(key,keylen,num_bkts,hashv,bkt)                                  \
+do {                                                                             \
+  unsigned _hb_keylen=keylen;                                                    \
+  char *_hb_key=(char*)(key);                                                    \
+  (hashv) = 0;                                                                   \
+  while (_hb_keylen--)  { (hashv) = (((hashv) << 5) + (hashv)) + *_hb_key++; }   \
+  bkt = (hashv) & (num_bkts-1);                                                  \
+} while (0)
+
+
+/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at
+ * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */
+#define HASH_SAX(key,keylen,num_bkts,hashv,bkt)                                  \
+do {                                                                             \
+  unsigned _sx_i;                                                                \
+  char *_hs_key=(char*)(key);                                                    \
+  hashv = 0;                                                                     \
+  for(_sx_i=0; _sx_i < keylen; _sx_i++)                                          \
+      hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i];                     \
+  bkt = hashv & (num_bkts-1);                                                    \
+} while (0)
+/* FNV-1a variation */
+#define HASH_FNV(key,keylen,num_bkts,hashv,bkt)                                  \
+do {                                                                             \
+  unsigned _fn_i;                                                                \
+  char *_hf_key=(char*)(key);                                                    \
+  hashv = 2166136261UL;                                                          \
+  for(_fn_i=0; _fn_i < keylen; _fn_i++) {                                        \
+      hashv = hashv ^ _hf_key[_fn_i];                                            \
+      hashv = hashv * 16777619;                                                  \
+  }                                                                              \
+  bkt = hashv & (num_bkts-1);                                                    \
+} while(0)
+
+#define HASH_OAT(key,keylen,num_bkts,hashv,bkt)                                  \
+do {                                                                             \
+  unsigned _ho_i;                                                                \
+  char *_ho_key=(char*)(key);                                                    \
+  hashv = 0;                                                                     \
+  for(_ho_i=0; _ho_i < keylen; _ho_i++) {                                        \
+      hashv += _ho_key[_ho_i];                                                   \
+      hashv += (hashv << 10);                                                    \
+      hashv ^= (hashv >> 6);                                                     \
+  }                                                                              \
+  hashv += (hashv << 3);                                                         \
+  hashv ^= (hashv >> 11);                                                        \
+  hashv += (hashv << 15);                                                        \
+  bkt = hashv & (num_bkts-1);                                                    \
+} while(0)
+
+#define HASH_JEN_MIX(a,b,c)                                                      \
+do {                                                                             \
+  a -= b; a -= c; a ^= ( c >> 13 );                                              \
+  b -= c; b -= a; b ^= ( a << 8 );                                               \
+  c -= a; c -= b; c ^= ( b >> 13 );                                              \
+  a -= b; a -= c; a ^= ( c >> 12 );                                              \
+  b -= c; b -= a; b ^= ( a << 16 );                                              \
+  c -= a; c -= b; c ^= ( b >> 5 );                                               \
+  a -= b; a -= c; a ^= ( c >> 3 );                                               \
+  b -= c; b -= a; b ^= ( a << 10 );                                              \
+  c -= a; c -= b; c ^= ( b >> 15 );                                              \
+} while (0)
+
+#define HASH_JEN(key,keylen,num_bkts,hashv,bkt)                                  \
+do {                                                                             \
+  unsigned _hj_i,_hj_j,_hj_k;                                                    \
+  unsigned char *_hj_key=(unsigned char*)(key);                                  \
+  hashv = 0xfeedbeef;                                                            \
+  _hj_i = _hj_j = 0x9e3779b9;                                                    \
+  _hj_k = (unsigned)(keylen);                                                    \
+  while (_hj_k >= 12) {                                                          \
+    _hj_i +=    (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 )                      \
+        + ( (unsigned)_hj_key[2] << 16 )                                         \
+        + ( (unsigned)_hj_key[3] << 24 ) );                                      \
+    _hj_j +=    (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 )                      \
+        + ( (unsigned)_hj_key[6] << 16 )                                         \
+        + ( (unsigned)_hj_key[7] << 24 ) );                                      \
+    hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 )                         \
+        + ( (unsigned)_hj_key[10] << 16 )                                        \
+        + ( (unsigned)_hj_key[11] << 24 ) );                                     \
+                                                                                 \
+     HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                          \
+                                                                                 \
+     _hj_key += 12;                                                              \
+     _hj_k -= 12;                                                                \
+  }                                                                              \
+  hashv += keylen;                                                               \
+  switch ( _hj_k ) {                                                             \
+     case 11: hashv += ( (unsigned)_hj_key[10] << 24 );                          \
+     case 10: hashv += ( (unsigned)_hj_key[9] << 16 );                           \
+     case 9:  hashv += ( (unsigned)_hj_key[8] << 8 );                            \
+     case 8:  _hj_j += ( (unsigned)_hj_key[7] << 24 );                           \
+     case 7:  _hj_j += ( (unsigned)_hj_key[6] << 16 );                           \
+     case 6:  _hj_j += ( (unsigned)_hj_key[5] << 8 );                            \
+     case 5:  _hj_j += _hj_key[4];                                               \
+     case 4:  _hj_i += ( (unsigned)_hj_key[3] << 24 );                           \
+     case 3:  _hj_i += ( (unsigned)_hj_key[2] << 16 );                           \
+     case 2:  _hj_i += ( (unsigned)_hj_key[1] << 8 );                            \
+     case 1:  _hj_i += _hj_key[0];                                               \
+  }                                                                              \
+  HASH_JEN_MIX(_hj_i, _hj_j, hashv);                                             \
+  bkt = hashv & (num_bkts-1);                                                    \
+} while(0)
+
+/* The Paul Hsieh hash function */
+#undef get16bits
+#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__)             \
+  || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
+#define get16bits(d) (*((const uint16_t *) (d)))
+#endif
+
+#if !defined (get16bits)
+#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)             \
+                       +(uint32_t)(((const uint8_t *)(d))[0]) )
+#endif
+#define HASH_SFH(key,keylen,num_bkts,hashv,bkt)                                  \
+do {                                                                             \
+  unsigned char *_sfh_key=(unsigned char*)(key);                                 \
+  uint32_t _sfh_tmp, _sfh_len = keylen;                                          \
+                                                                                 \
+  int _sfh_rem = _sfh_len & 3;                                                   \
+  _sfh_len >>= 2;                                                                \
+  hashv = 0xcafebabe;                                                            \
+                                                                                 \
+  /* Main loop */                                                                \
+  for (;_sfh_len > 0; _sfh_len--) {                                              \
+    hashv    += get16bits (_sfh_key);                                            \
+    _sfh_tmp       = (uint32_t)(get16bits (_sfh_key+2)) << 11  ^ hashv;          \
+    hashv     = (hashv << 16) ^ _sfh_tmp;                                        \
+    _sfh_key += 2*sizeof (uint16_t);                                             \
+    hashv    += hashv >> 11;                                                     \
+  }                                                                              \
+                                                                                 \
+  /* Handle end cases */                                                         \
+  switch (_sfh_rem) {                                                            \
+    case 3: hashv += get16bits (_sfh_key);                                       \
+            hashv ^= hashv << 16;                                                \
+            hashv ^= (uint32_t)(_sfh_key[sizeof (uint16_t)] << 18);              \
+            hashv += hashv >> 11;                                                \
+            break;                                                               \
+    case 2: hashv += get16bits (_sfh_key);                                       \
+            hashv ^= hashv << 11;                                                \
+            hashv += hashv >> 17;                                                \
+            break;                                                               \
+    case 1: hashv += *_sfh_key;                                                  \
+            hashv ^= hashv << 10;                                                \
+            hashv += hashv >> 1;                                                 \
+  }                                                                              \
+                                                                                 \
+    /* Force "avalanching" of final 127 bits */                                  \
+    hashv ^= hashv << 3;                                                         \
+    hashv += hashv >> 5;                                                         \
+    hashv ^= hashv << 4;                                                         \
+    hashv += hashv >> 17;                                                        \
+    hashv ^= hashv << 25;                                                        \
+    hashv += hashv >> 6;                                                         \
+    bkt = hashv & (num_bkts-1);                                                  \
+} while(0)
+
+#ifdef HASH_USING_NO_STRICT_ALIASING
+/* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads.
+ * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error.
+ * MurmurHash uses the faster approach only on CPU's where we know it's safe.
+ *
+ * Note the preprocessor built-in defines can be emitted using:
+ *
+ *   gcc -m64 -dM -E - < /dev/null                  (on gcc)
+ *   cc -## a.c (where a.c is a simple test file)   (Sun Studio)
+ */
+#if (defined(__i386__) || defined(__x86_64__)  || defined(_M_IX86))
+#define MUR_GETBLOCK(p,i) p[i]
+#else /* non intel */
+#define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0)
+#define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 0x3) == 1)
+#define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2)
+#define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3)
+#define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL))
+#if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__))
+#define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24))
+#define MUR_TWO_TWO(p)   ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16))
+#define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >>  8))
+#else /* assume little endian non-intel */
+#define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24))
+#define MUR_TWO_TWO(p)   ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16))
+#define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) <<  8))
+#endif
+#define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) :           \
+                            (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \
+                             (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) :  \
+                                                      MUR_ONE_THREE(p))))
+#endif
+#define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
+#define MUR_FMIX(_h) \
+do {                 \
+  _h ^= _h >> 16;    \
+  _h *= 0x85ebca6b;  \
+  _h ^= _h >> 13;    \
+  _h *= 0xc2b2ae35l; \
+  _h ^= _h >> 16;    \
+} while(0)
+
+#define HASH_MUR(key,keylen,num_bkts,hashv,bkt)                        \
+do {                                                                   \
+  const uint8_t *_mur_data = (const uint8_t*)(key);                    \
+  const int _mur_nblocks = (keylen) / 4;                               \
+  uint32_t _mur_h1 = 0xf88D5353;                                       \
+  uint32_t _mur_c1 = 0xcc9e2d51;                                       \
+  uint32_t _mur_c2 = 0x1b873593;                                       \
+  uint32_t _mur_k1 = 0;                                                \
+  const uint8_t *_mur_tail;                                            \
+  const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \
+  int _mur_i;                                                          \
+  for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) {                      \
+    _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i);                        \
+    _mur_k1 *= _mur_c1;                                                \
+    _mur_k1 = MUR_ROTL32(_mur_k1,15);                                  \
+    _mur_k1 *= _mur_c2;                                                \
+                                                                       \
+    _mur_h1 ^= _mur_k1;                                                \
+    _mur_h1 = MUR_ROTL32(_mur_h1,13);                                  \
+    _mur_h1 = _mur_h1*5+0xe6546b64;                                    \
+  }                                                                    \
+  _mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4);            \
+  _mur_k1=0;                                                           \
+  switch((keylen) & 3) {                                               \
+    case 3: _mur_k1 ^= _mur_tail[2] << 16;                             \
+    case 2: _mur_k1 ^= _mur_tail[1] << 8;                              \
+    case 1: _mur_k1 ^= _mur_tail[0];                                   \
+    _mur_k1 *= _mur_c1;                                                \
+    _mur_k1 = MUR_ROTL32(_mur_k1,15);                                  \
+    _mur_k1 *= _mur_c2;                                                \
+    _mur_h1 ^= _mur_k1;                                                \
+  }                                                                    \
+  _mur_h1 ^= (keylen);                                                 \
+  MUR_FMIX(_mur_h1);                                                   \
+  hashv = _mur_h1;                                                     \
+  bkt = hashv & (num_bkts-1);                                          \
+} while(0)
+#endif  /* HASH_USING_NO_STRICT_ALIASING */
+
+/* key comparison function; return 0 if keys equal */
+#define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
+
+/* iterate over items in a known bucket to find desired item */
+#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out)                       \
+do {                                                                             \
+ if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head));          \
+ else out=NULL;                                                                  \
+ while (out) {                                                                   \
+    if ((out)->hh.keylen == keylen_in) {                                           \
+        if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break;             \
+    }                                                                            \
+    if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \
+    else out = NULL;                                                             \
+ }                                                                               \
+} while(0)
+
+/* add an item to a bucket  */
+#define HASH_ADD_TO_BKT(head,addhh)                                              \
+do {                                                                             \
+ head.count++;                                                                   \
+ (addhh)->hh_next = head.hh_head;                                                \
+ (addhh)->hh_prev = NULL;                                                        \
+ if (head.hh_head) { (head).hh_head->hh_prev = (addhh); }                        \
+ (head).hh_head=addhh;                                                           \
+ if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH)             \
+     && (addhh)->tbl->noexpand != 1) {                                           \
+       HASH_EXPAND_BUCKETS((addhh)->tbl);                                        \
+ }                                                                               \
+} while(0)
+
+/* remove an item from a given bucket */
+#define HASH_DEL_IN_BKT(hh,head,hh_del)                                          \
+    (head).count--;                                                              \
+    if ((head).hh_head == hh_del) {                                              \
+      (head).hh_head = hh_del->hh_next;                                          \
+    }                                                                            \
+    if (hh_del->hh_prev) {                                                       \
+        hh_del->hh_prev->hh_next = hh_del->hh_next;                              \
+    }                                                                            \
+    if (hh_del->hh_next) {                                                       \
+        hh_del->hh_next->hh_prev = hh_del->hh_prev;                              \
+    }
+
+/* Bucket expansion has the effect of doubling the number of buckets
+ * and redistributing the items into the new buckets. Ideally the
+ * items will distribute more or less evenly into the new buckets
+ * (the extent to which this is true is a measure of the quality of
+ * the hash function as it applies to the key domain).
+ *
+ * With the items distributed into more buckets, the chain length
+ * (item count) in each bucket is reduced. Thus by expanding buckets
+ * the hash keeps a bound on the chain length. This bounded chain
+ * length is the essence of how a hash provides constant time lookup.
+ *
+ * The calculation of tbl->ideal_chain_maxlen below deserves some
+ * explanation. First, keep in mind that we're calculating the ideal
+ * maximum chain length based on the *new* (doubled) bucket count.
+ * In fractions this is just n/b (n=number of items,b=new num buckets).
+ * Since the ideal chain length is an integer, we want to calculate
+ * ceil(n/b). We don't depend on floating point arithmetic in this
+ * hash, so to calculate ceil(n/b) with integers we could write
+ *
+ *      ceil(n/b) = (n/b) + ((n%b)?1:0)
+ *
+ * and in fact a previous version of this hash did just that.
+ * But now we have improved things a bit by recognizing that b is
+ * always a power of two. We keep its base 2 log handy (call it lb),
+ * so now we can write this with a bit shift and logical AND:
+ *
+ *      ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0)
+ *
+ */
+#define HASH_EXPAND_BUCKETS(tbl)                                                 \
+do {                                                                             \
+    unsigned _he_bkt;                                                            \
+    unsigned _he_bkt_i;                                                          \
+    struct UT_hash_handle *_he_thh, *_he_hh_nxt;                                 \
+    UT_hash_bucket *_he_new_buckets, *_he_newbkt;                                \
+    _he_new_buckets = (UT_hash_bucket*)uthash_malloc(                            \
+             2 * tbl->num_buckets * sizeof(struct UT_hash_bucket));              \
+    if (!_he_new_buckets) { uthash_fatal( "out of memory"); }                    \
+    memset(_he_new_buckets, 0,                                                   \
+            2 * tbl->num_buckets * sizeof(struct UT_hash_bucket));               \
+    tbl->ideal_chain_maxlen =                                                    \
+       (tbl->num_items >> (tbl->log2_num_buckets+1)) +                           \
+       ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0);                    \
+    tbl->nonideal_items = 0;                                                     \
+    for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++)                \
+    {                                                                            \
+        _he_thh = tbl->buckets[ _he_bkt_i ].hh_head;                             \
+        while (_he_thh) {                                                        \
+           _he_hh_nxt = _he_thh->hh_next;                                        \
+           HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt);            \
+           _he_newbkt = &(_he_new_buckets[ _he_bkt ]);                           \
+           if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) {                \
+             tbl->nonideal_items++;                                              \
+             _he_newbkt->expand_mult = _he_newbkt->count /                       \
+                                        tbl->ideal_chain_maxlen;                 \
+           }                                                                     \
+           _he_thh->hh_prev = NULL;                                              \
+           _he_thh->hh_next = _he_newbkt->hh_head;                               \
+           if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev =               \
+                _he_thh;                                                         \
+           _he_newbkt->hh_head = _he_thh;                                        \
+           _he_thh = _he_hh_nxt;                                                 \
+        }                                                                        \
+    }                                                                            \
+    uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \
+    tbl->num_buckets *= 2;                                                       \
+    tbl->log2_num_buckets++;                                                     \
+    tbl->buckets = _he_new_buckets;                                              \
+    tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ?         \
+        (tbl->ineff_expands+1) : 0;                                              \
+    if (tbl->ineff_expands > 1) {                                                \
+        tbl->noexpand=1;                                                         \
+        uthash_noexpand_fyi(tbl);                                                \
+    }                                                                            \
+    uthash_expand_fyi(tbl);                                                      \
+} while(0)
+
+
+/* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */
+/* Note that HASH_SORT assumes the hash handle name to be hh.
+ * HASH_SRT was added to allow the hash handle name to be passed in. */
+#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn)
+#define HASH_SRT(hh,head,cmpfcn)                                                 \
+do {                                                                             \
+  unsigned _hs_i;                                                                \
+  unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize;               \
+  struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail;            \
+  if (head) {                                                                    \
+      _hs_insize = 1;                                                            \
+      _hs_looping = 1;                                                           \
+      _hs_list = &((head)->hh);                                                  \
+      while (_hs_looping) {                                                      \
+          _hs_p = _hs_list;                                                      \
+          _hs_list = NULL;                                                       \
+          _hs_tail = NULL;                                                       \
+          _hs_nmerges = 0;                                                       \
+          while (_hs_p) {                                                        \
+              _hs_nmerges++;                                                     \
+              _hs_q = _hs_p;                                                     \
+              _hs_psize = 0;                                                     \
+              for ( _hs_i = 0; _hs_i  < _hs_insize; _hs_i++ ) {                  \
+                  _hs_psize++;                                                   \
+                  _hs_q = (UT_hash_handle*)((_hs_q->next) ?                      \
+                          ((void*)((char*)(_hs_q->next) +                        \
+                          (head)->hh.tbl->hho)) : NULL);                         \
+                  if (! (_hs_q) ) break;                                         \
+              }                                                                  \
+              _hs_qsize = _hs_insize;                                            \
+              while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) {           \
+                  if (_hs_psize == 0) {                                          \
+                      _hs_e = _hs_q;                                             \
+                      _hs_q = (UT_hash_handle*)((_hs_q->next) ?                  \
+                              ((void*)((char*)(_hs_q->next) +                    \
+                              (head)->hh.tbl->hho)) : NULL);                     \
+                      _hs_qsize--;                                               \
+                  } else if ( (_hs_qsize == 0) || !(_hs_q) ) {                   \
+                      _hs_e = _hs_p;                                             \
+                      if (_hs_p){                                                \
+                        _hs_p = (UT_hash_handle*)((_hs_p->next) ?                \
+                                ((void*)((char*)(_hs_p->next) +                  \
+                                (head)->hh.tbl->hho)) : NULL);                   \
+                       }                                                         \
+                      _hs_psize--;                                               \
+                  } else if ((                                                   \
+                      cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \
+                             DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \
+                             ) <= 0) {                                           \
+                      _hs_e = _hs_p;                                             \
+                      if (_hs_p){                                                \
+                        _hs_p = (UT_hash_handle*)((_hs_p->next) ?                \
+                               ((void*)((char*)(_hs_p->next) +                   \
+                               (head)->hh.tbl->hho)) : NULL);                    \
+                       }                                                         \
+                      _hs_psize--;                                               \
+                  } else {                                                       \
+                      _hs_e = _hs_q;                                             \
+                      _hs_q = (UT_hash_handle*)((_hs_q->next) ?                  \
+                              ((void*)((char*)(_hs_q->next) +                    \
+                              (head)->hh.tbl->hho)) : NULL);                     \
+                      _hs_qsize--;                                               \
+                  }                                                              \
+                  if ( _hs_tail ) {                                              \
+                      _hs_tail->next = ((_hs_e) ?                                \
+                            ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL);          \
+                  } else {                                                       \
+                      _hs_list = _hs_e;                                          \
+                  }                                                              \
+                  if (_hs_e) {                                                   \
+                  _hs_e->prev = ((_hs_tail) ?                                    \
+                     ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL);              \
+                  }                                                              \
+                  _hs_tail = _hs_e;                                              \
+              }                                                                  \
+              _hs_p = _hs_q;                                                     \
+          }                                                                      \
+          if (_hs_tail){                                                         \
+            _hs_tail->next = NULL;                                               \
+          }                                                                      \
+          if ( _hs_nmerges <= 1 ) {                                              \
+              _hs_looping=0;                                                     \
+              (head)->hh.tbl->tail = _hs_tail;                                   \
+              DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list));      \
+          }                                                                      \
+          _hs_insize *= 2;                                                       \
+      }                                                                          \
+      HASH_FSCK(hh,head);                                                        \
+ }                                                                               \
+} while (0)
+
+/* This function selects items from one hash into another hash.
+ * The end result is that the selected items have dual presence
+ * in both hashes. There is no copy of the items made; rather
+ * they are added into the new hash through a secondary hash
+ * hash handle that must be present in the structure. */
+#define HASH_SELECT(hh_dst, dst, hh_src, src, cond)                              \
+do {                                                                             \
+  unsigned _src_bkt, _dst_bkt;                                                   \
+  void *_last_elt=NULL, *_elt;                                                   \
+  UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL;                         \
+  ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst));                 \
+  if (src) {                                                                     \
+    for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) {     \
+      for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head;                \
+          _src_hh;                                                               \
+          _src_hh = _src_hh->hh_next) {                                          \
+          _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh);                       \
+          if (cond(_elt)) {                                                      \
+            _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho);               \
+            _dst_hh->key = _src_hh->key;                                         \
+            _dst_hh->keylen = _src_hh->keylen;                                   \
+            _dst_hh->hashv = _src_hh->hashv;                                     \
+            _dst_hh->prev = _last_elt;                                           \
+            _dst_hh->next = NULL;                                                \
+            if (_last_elt_hh) { _last_elt_hh->next = _elt; }                     \
+            if (!dst) {                                                          \
+              DECLTYPE_ASSIGN(dst,_elt);                                         \
+              HASH_MAKE_TABLE(hh_dst,dst);                                       \
+            } else {                                                             \
+              _dst_hh->tbl = (dst)->hh_dst.tbl;                                  \
+            }                                                                    \
+            HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt);    \
+            HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh);            \
+            (dst)->hh_dst.tbl->num_items++;                                      \
+            _last_elt = _elt;                                                    \
+            _last_elt_hh = _dst_hh;                                              \
+          }                                                                      \
+      }                                                                          \
+    }                                                                            \
+  }                                                                              \
+  HASH_FSCK(hh_dst,dst);                                                         \
+} while (0)
+
+#define HASH_CLEAR(hh,head)                                                      \
+do {                                                                             \
+  if (head) {                                                                    \
+    uthash_free((head)->hh.tbl->buckets,                                         \
+                (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket));      \
+    HASH_BLOOM_FREE((head)->hh.tbl);                                             \
+    uthash_free((head)->hh.tbl, sizeof(UT_hash_table));                          \
+    (head)=NULL;                                                                 \
+  }                                                                              \
+} while(0)
+
+#define HASH_OVERHEAD(hh,head)                                                   \
+ ((head) ? (                                                                     \
+ (size_t)((((head)->hh.tbl->num_items   * sizeof(UT_hash_handle))   +            \
+           ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket))   +            \
+            (sizeof(UT_hash_table))                                 +            \
+            (HASH_BLOOM_BYTELEN)))) : 0)
+
+#ifdef NO_DECLTYPE
+#define HASH_ITER(hh,head,el,tmp)                                                \
+for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL);       \
+  el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL))
+#else
+#define HASH_ITER(hh,head,el,tmp)                                                \
+for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL);                 \
+  el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL))
+#endif
+
+/* obtain a count of items in the hash */
+#define HASH_COUNT(head) HASH_CNT(hh,head)
+#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0)
+
+typedef struct UT_hash_bucket {
+   struct UT_hash_handle *hh_head;
+   unsigned count;
+
+   /* expand_mult is normally set to 0. In this situation, the max chain length
+    * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If
+    * the bucket's chain exceeds this length, bucket expansion is triggered).
+    * However, setting expand_mult to a non-zero value delays bucket expansion
+    * (that would be triggered by additions to this particular bucket)
+    * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.
+    * (The multiplier is simply expand_mult+1). The whole idea of this
+    * multiplier is to reduce bucket expansions, since they are expensive, in
+    * situations where we know that a particular bucket tends to be overused.
+    * It is better to let its chain length grow to a longer yet-still-bounded
+    * value, than to do an O(n) bucket expansion too often.
+    */
+   unsigned expand_mult;
+
+} UT_hash_bucket;
+
+/* random signature used only to find hash tables in external analysis */
+#define HASH_SIGNATURE 0xa0111fe1
+#define HASH_BLOOM_SIGNATURE 0xb12220f2
+
+typedef struct UT_hash_table {
+   UT_hash_bucket *buckets;
+   unsigned num_buckets, log2_num_buckets;
+   unsigned num_items;
+   struct UT_hash_handle *tail; /* tail hh in app order, for fast append    */
+   ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */
+
+   /* in an ideal situation (all buckets used equally), no bucket would have
+    * more than ceil(#items/#buckets) items. that's the ideal chain length. */
+   unsigned ideal_chain_maxlen;
+
+   /* nonideal_items is the number of items in the hash whose chain position
+    * exceeds the ideal chain maxlen. these items pay the penalty for an uneven
+    * hash distribution; reaching them in a chain traversal takes >ideal steps */
+   unsigned nonideal_items;
+
+   /* ineffective expands occur when a bucket doubling was performed, but
+    * afterward, more than half the items in the hash had nonideal chain
+    * positions. If this happens on two consecutive expansions we inhibit any
+    * further expansion, as it's not helping; this happens when the hash
+    * function isn't a good fit for the key domain. When expansion is inhibited
+    * the hash will still work, albeit no longer in constant time. */
+   unsigned ineff_expands, noexpand;
+
+   uint32_t signature; /* used only to find hash tables in external analysis */
+#ifdef HASH_BLOOM
+   uint32_t bloom_sig; /* used only to test bloom exists in external analysis */
+   uint8_t *bloom_bv;
+   char bloom_nbits;
+#endif
+
+} UT_hash_table;
+
+typedef struct UT_hash_handle {
+   struct UT_hash_table *tbl;
+   void *prev;                       /* prev element in app order      */
+   void *next;                       /* next element in app order      */
+   struct UT_hash_handle *hh_prev;   /* previous hh in bucket order    */
+   struct UT_hash_handle *hh_next;   /* next hh in bucket order        */
+   void *key;                        /* ptr to enclosing struct's key  */
+   unsigned keylen;                  /* enclosing struct's key len     */
+   unsigned hashv;                   /* result of hash-fcn(key)        */
+} UT_hash_handle;
+
+#endif /* UTHASH_H */
index bea356d108f34c19a61c3da1809b7062ddd7a40e..e2d99769b6c25ae68f4180e8fa7c68cfd6100752 100644 (file)
@@ -1,67 +1,44 @@
 #include "inc.h"
 
-static struct dir_extent dir_extents[NR_DIR_EXTENT_RECORDS];
-
-struct dir_extent* alloc_extent(void)
-{
-       /* Return a free extent from the pool. */
-       int i;
-       struct dir_extent *extent;
-
-       for (i = 0; i < NR_DIR_EXTENT_RECORDS; i++) {
-               extent = &dir_extents[i];
-
-               if (extent->in_use == 0) {
-                       memset(extent, 0, sizeof(*extent));
-                       extent->in_use = 1;
-
-                       return extent;
-               }
-       }
+void free_extent(struct dir_extent *e) {
+       if (e == NULL)
+               return;
 
-       panic("No free extents in cache");
+       free_extent(e->next);
+       free(e);
 }
 
-void free_extent(struct dir_extent *e)
-{
+/* Free the contents of an inode dir entry, but not the pointer itself. */
+void free_inode_dir_entry(struct inode_dir_entry *e) {
        if (e == NULL)
                return;
 
-       if (e->in_use == 0)
-               panic("Trying to free unused extent");
-
-       free_extent(e->next);
-       e->in_use = 0;
+       free(e->r_name);
+       e->r_name = NULL;
 }
 
-struct buf* read_extent_block(struct dir_extent *e, size_t block)
-{
+struct buf* read_extent_block(struct dir_extent *e, size_t block) {
+       size_t block_id = get_extent_absolute_block_id(e, block);
        struct buf *bp;
-       size_t block_id;
-       int r;
-
-       block_id = get_extent_absolute_block_id(e, block);
 
        if (block_id == 0 || block_id >= v_pri.volume_space_size_l)
                return NULL;
 
-       /* Not all callers deal well with failure, so panic on I/O error. */
-       if ((r = lmfs_get_block(&bp, fs_dev, block_id, NORMAL)) != OK)
-               panic("ISOFS: error getting block (%llu,%zu): %d",
-                   fs_dev, block_id, r);
+       if(lmfs_get_block(&bp, fs_dev, block_id, NORMAL) != OK)
+               return NULL;
 
        return bp;
 }
 
-size_t get_extent_absolute_block_id(struct dir_extent *e, size_t block)
-{
+size_t get_extent_absolute_block_id(struct dir_extent *e, size_t block) {
        size_t extent_offset = 0;
+       block /= v_pri.logical_block_size_l;
 
        if (e == NULL)
                return 0;
 
        /* Retrieve the extent on which the block lies. */
-       while(block > extent_offset + e->length) {
+       while(block >= extent_offset + e->length) {
                if (e->next == NULL)
                        return 0;
 
@@ -72,9 +49,9 @@ size_t get_extent_absolute_block_id(struct dir_extent *e, size_t block)
        return e->location + block - extent_offset;
 }
 
-time_t date7_to_time_t(const u8_t *date)
-{
-       /* This function converts from the ISO 9660 7-byte time format to a
+time_t date7_to_time_t(const u8_t *date) {
+       /*
+        * This function converts from the ISO 9660 7-byte time format to a
         * time_t.
         */
        struct tm ltime;
@@ -94,3 +71,10 @@ time_t date7_to_time_t(const u8_t *date)
 
        return mktime(&ltime);
 }
+
+void* alloc_mem(size_t s) {
+       void *ptr = calloc(1, s);
+       assert(ptr != NULL);
+
+       return ptr;
+}
index 84df95d433d519393d193b6e0855e9361b525ba0..47ac85a8b633d58064b16f7c26d0f077c736686f 100755 (executable)
@@ -6,6 +6,11 @@ set -e
 
 echo -n "isofs test "
 
+# testing ISO 9660 Level 3 compliance isn't possible for the time being
+# (not possible to store a >4GB ISO file into a ramdisk)
+testLevel3=0
+testRockRidge=1
+
 ramdev=/dev/ram
 mp=/mnt
 testdir=isofstest
@@ -13,6 +18,97 @@ fsimage=isofsimage
 contents=CONTENTS
 out1=v1
 out2=v2
+
+create_contents_level3() {
+       # >4GB file
+       seq 1 1000000000 > $testdir/HUGEFILE
+}
+
+create_contents_rockridge() {
+       # long filenames
+       mkdir -p $testdir/rockridge/longnames
+       echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopaz
+       echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopaze
+       echo "this is a test" > $testdir/rockridge/longnames/azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazer
+
+       # devices
+       mkdir -p $testdir/rockridge/devices
+       CURLOC=$(pwd)
+       cd $testdir/rockridge/devices && MAKEDEV -s
+       cd $CURLOC
+
+       # symbolic links
+       mkdir -p $testdir/rockridge/symlinks
+       ln -s . $testdir/rockridge/symlinks/cur_dir
+       ln -s .. $testdir/rockridge/symlinks/parent_dir
+       ln -s / $testdir/rockridge/symlinks/root_dir
+       ln -s /mnt $testdir/rockridge/symlinks/root_mnt_dir
+       ln -s ../../rockridge $testdir/rockridge/symlinks/rockridge_dir
+       ln -s ../../rockridge/symlinks $testdir/rockridge/symlinks/symlinks_dir
+       ln -s ../../rockridge/symlinks/../symlinks $testdir/rockridge/symlinks/symlinks_dir_bis
+       ln -s cur_dir $testdir/rockridge/symlinks/to_cur_dir
+       ln -s rockridge_dir $testdir/rockridge/symlinks/to_rockridge_dir
+
+       # deep directory tree
+       mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think
+       mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes
+       mkdir -p $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no
+       echo "I agree." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes/awnser1
+       echo "Yes, totally." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/yes/awnser2
+       echo "Nah." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no/awnser1
+       echo "Meh." > $testdir/rockridge/deep_dirs/this/is/a/ridiculously/deep/directory/hierarchy/dont/you/think/no/awnser2
+
+       # permissions
+       mkdir -p $testdir/rockridge/permissions
+       for u in $(seq 0 7); do
+               for g in $(seq 0 7); do
+                       for o in $(seq 0 7); do
+                               echo "$u$g$o" > $testdir/rockridge/permissions/mode-$u$g$o
+                               chmod $u$g$o $testdir/rockridge/permissions/mode-$u$g$o
+                       done
+               done
+       done
+       echo "uid-gid test" > $testdir/rockridge/permissions/uid-1-gid-2
+       chown 1:2 $testdir/rockridge/permissions/uid-1-gid-2
+       echo "uid-gid test" > $testdir/rockridge/permissions/uid-128-gid-256
+       chown 128:256 $testdir/rockridge/permissions/uid-128-gid-256
+       echo "uid-gid test" > $testdir/rockridge/permissions/uid-12345-gid-23456
+       chown 12345:23456 $testdir/rockridge/permissions/uid-12345-gid-23456
+}
+
+create_contents_base() {
+       # simple file
+       echo $(date) > $testdir/DATE
+
+       # big file
+       seq 1 100000 > $testdir/BIGFILE
+
+       # lots of files in a directory
+       mkdir $testdir/BIGDIR
+       for i in $(seq 1 250); do
+               HASH=$(cksum -a SHA1 <<EOF
+$i
+EOF
+)
+               FILE=$(echo $HASH | cut -c 1-30 | sed -e "y/abcdef/ABCDEF/")
+               echo $HASH > $testdir/BIGDIR/$FILE
+       done
+
+       # lots of directories
+       mkdir $testdir/SUBDIRS
+       for i in $(seq 1 1000); do
+               HASH=$(cksum -a SHA1 <<EOF
+$i
+EOF
+)
+               DIR1=$(echo $HASH | cut -c 1-2 | sed -e "y/abcdef/ABCDEF/")
+               DIR2=$(echo $HASH | cut -c 3-4 | sed -e "y/abcdef/ABCDEF/")
+               FILE=$(echo $HASH | cut -c 5-12 | sed -e "y/abcdef/ABCDEF/")
+               mkdir -p $testdir/SUBDIRS/$DIR1/$DIR2
+               echo $HASH > $testdir/SUBDIRS/$DIR1/$DIR2/$FILE
+       done
+}
+
 rm -rf $testdir $fsimage $out1 $out2
 
 if [ -d $testdir ]
@@ -21,7 +117,7 @@ then
        exit 1
 fi
 
-mkdir -p $testdir $testdir/$contents
+mkdir -p $testdir
 
 if [ ! -d $testdir ]
 then
@@ -29,33 +125,47 @@ then
        exit 1
 fi
 
-# Make some small & big & bigger files
-
-prevf=$testdir/$contents/FILE
-echo "Test contents 123" >$prevf
-for double in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
-do     fn=$testdir/$contents/FN.$double
-       cat $prevf $prevf >$fn
-       prevf=$fn
-done
+# make some small & big & bigger files
+OPTIONS=
+create_contents_base
+if [ "$testLevel3" -eq 1 ]
+then
+       create_contents_level3
+fi
+if [ "$testRockRidge" -eq 1 ]
+then
+       create_contents_rockridge
+       OPTIONS="-o rockridge"
+else
+       # fixups for the fact that bare ISO 9660 isn't POSIX enough
+       # for mtree
+       # fix permissions
+       find $testdir -exec chmod 555 {} ";"
+fi
 
-# Make an ISO filesystem image out of it
-writeisofs -s0x0 -l MINIX $testdir $fsimage >/dev/null 2>&1
+# make image
+/usr/sbin/makefs -t cd9660 $OPTIONS $fsimage $testdir
 
 # umount previous things
 umount $ramdev >/dev/null 2>&1 || true
 umount $mp >/dev/null 2>&1 || true
 
-# Mount it on a RAM disk
-ramdisk 50000 $ramdev >/dev/null 2>&1
-cp $fsimage $ramdev
+# mount it on a RAM disk
+ramdisk $(expr $(wc -c < $fsimage) / 1024) $ramdev >/dev/null 2>&1
+cat < $fsimage > $ramdev
 mount -t isofs $ramdev $mp >/dev/null 2>&1
 
 # compare contents
-(cd $testdir/$contents && sha1 * | sort) >$out1
-(cd $mp/$contents && sha1 * | sort) >$out2
-
-diff -u $out1 $out2
+if [ "$testRockRidge" -eq 1 ]
+then
+       # get rid of root directory time
+       /usr/sbin/mtree -c -p $testdir | sed -e "s/\. *type=dir.*/\. type=dir/" | /usr/sbin/mtree -p $mp
+else
+       # fixups for the fact that bare ISO 9660 isn't POSIX enough
+       # for mtree
+       # get rid of time
+       /usr/sbin/mtree -c -p $testdir | sed -e "s/time=[0-9]*.[0-9]*//" | /usr/sbin/mtree -p $mp
+fi
 
 umount $ramdev >/dev/null 2>&1