From 535dee52f6736f7d470f44f91b2967146fd001fe Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 7 Apr 2007 17:14:58 +0000 Subject: [PATCH] Fix deep directory move rock-ridge extension. Code was there, but it had bit-rotted. --- usr.sbin/makefs/cd9660.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c index bfc32d05c7ae..8556c0039dea 100644 --- a/usr.sbin/makefs/cd9660.c +++ b/usr.sbin/makefs/cd9660.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660.c,v 1.18 2007/01/16 17:32:05 hubertf Exp $ */ +/* $NetBSD: cd9660.c,v 1.19 2007/04/07 17:14:58 christos Exp $ */ /* * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan @@ -103,7 +103,7 @@ #include #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: cd9660.c,v 1.18 2007/01/16 17:32:05 hubertf Exp $"); +__RCSID("$NetBSD: cd9660.c,v 1.19 2007/04/07 17:14:58 christos Exp $"); #endif /* !__lint */ #include @@ -163,8 +163,9 @@ static int cd9660_copy_stat_info(cd9660node *, cd9660node *, int); #endif static cd9660node *cd9660_create_virtual_entry(const char *, cd9660node *, int, int); -static cd9660node *cd9660_create_file(const char *, cd9660node *); -static cd9660node *cd9660_create_directory(const char *, cd9660node *); +static cd9660node *cd9660_create_file(const char *, cd9660node *, cd9660node *); +static cd9660node *cd9660_create_directory(const char *, cd9660node *, + cd9660node *); static cd9660node *cd9660_create_special_directory(u_char, cd9660node *); @@ -951,13 +952,6 @@ cd9660_sorted_child_insert(cd9660node *parent, cd9660node *cn_new) /* TODO: Optimize? */ cn_new->parent = parent; -#if 0 /* XXXDCY did this serve any purpose when head was a cd9660node? */ - if (head == cn_new) { - head->parent->child = head; - return; - } -#endif - /* * first will either be 0, the . or the .. * if . or .., this means no other entry may be written before first @@ -969,7 +963,8 @@ cd9660_sorted_child_insert(cd9660node *parent, cd9660node *cn_new) * Dont insert a node twice - * that would cause an infinite loop */ - assert(cn_new != cn); + if (cn_new == cn) + return; compare = cd9660_compare_filename(cn_new->isoDirRecord->name, cn->isoDirRecord->name); @@ -1251,18 +1246,19 @@ cd9660_rrip_move_directory(cd9660node *dir) if (diskStructure.rr_moved_dir == NULL) { diskStructure.rr_moved_dir = cd9660_create_directory(ISO_RRIP_DEFAULT_MOVE_DIR_NAME, - diskStructure.rootNode); + diskStructure.rootNode, dir); if (diskStructure.rr_moved_dir == NULL) return 0; } /* Create a file with the same ORIGINAL name */ - tfile = cd9660_create_file(dir->node->name, dir->parent); + tfile = cd9660_create_file(dir->node->name, dir->parent, dir); if (tfile == NULL) return NULL; diskStructure.rock_ridge_move_count++; - sprintf(newname,"%08i", diskStructure.rock_ridge_move_count); + snprintf(newname, sizeof(newname), "%08i", + diskStructure.rock_ridge_move_count); /* Point to old parent */ dir->rr_real_parent = dir->parent; @@ -1988,7 +1984,7 @@ cd9660_create_virtual_entry(const char *name, cd9660node *parent, int file, } static cd9660node * -cd9660_create_file(const char * name, cd9660node *parent) +cd9660_create_file(const char * name, cd9660node *parent, cd9660node *me) { cd9660node *temp; @@ -2000,6 +1996,10 @@ cd9660_create_file(const char * name, cd9660node *parent) temp->type = CD9660_TYPE_FILE | CD9660_TYPE_VIRTUAL; + if ((temp->node->inode = calloc(1, sizeof(fsinode))) == NULL) + return NULL; + *temp->node->inode = *me->node->inode; + if (cd9960_translate_node_common(temp) == 0) return NULL; return temp; @@ -2012,7 +2012,7 @@ cd9660_create_file(const char * name, cd9660node *parent) * @returns cd9660node * Pointer to the new directory */ static cd9660node * -cd9660_create_directory(const char *name, cd9660node *parent) +cd9660_create_directory(const char *name, cd9660node *parent, cd9660node *me) { cd9660node *temp; @@ -2023,6 +2023,10 @@ cd9660_create_directory(const char *name, cd9660node *parent) temp->type = CD9660_TYPE_DIR | CD9660_TYPE_VIRTUAL; + if ((temp->node->inode = calloc(1, sizeof(fsinode))) == NULL) + return NULL; + *temp->node->inode = *me->node->inode; + if (cd9960_translate_node_common(temp) == 0) return NULL; return temp;