From b95e1bb85c8094ef589bbb1003f59280d869df46 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 7 Sep 2013 21:37:27 +0200 Subject: [PATCH] Giving sort weight 2 as default to El Torito boot images. --- libisofs/eltorito.c | 15 ++++++++++++--- libisofs/node.c | 3 +++ libisofs/node.h | 7 +++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/libisofs/eltorito.c b/libisofs/eltorito.c index b6f0e84..11e9c14 100644 --- a/libisofs/eltorito.c +++ b/libisofs/eltorito.c @@ -312,7 +312,8 @@ int iso_tree_add_boot_node(IsoDir *parent, const char *name, IsoBoot **boot) static int create_image(IsoImage *image, const char *image_path, enum eltorito_boot_media_type type, - struct el_torito_boot_image **bootimg) + struct el_torito_boot_image **bootimg, + IsoFile **bootnode) { int ret; struct el_torito_boot_image *boot; @@ -323,6 +324,7 @@ int create_image(IsoImage *image, const char *image_path, IsoNode *imgfile; IsoStream *stream; + *bootnode = NULL; ret = iso_tree_path_to_node(image, image_path, &imgfile); if (ret < 0) { return ret; @@ -337,6 +339,7 @@ int create_image(IsoImage *image, const char *image_path, if (imgfile->type != LIBISO_FILE) { return ISO_BOOT_IMAGE_NOT_VALID; } + *bootnode = (IsoFile *) imgfile; stream = ((IsoFile*)imgfile)->stream; @@ -461,6 +464,7 @@ int iso_image_set_boot_image(IsoImage *image, const char *image_path, struct el_torito_boot_catalog *catalog; ElToritoBootImage *boot_image= NULL; IsoBoot *cat_node= NULL; + IsoFile *boot_node; if (image == NULL || image_path == NULL || catalog_path == NULL) { return ISO_NULL_POINTER; @@ -513,7 +517,7 @@ int iso_image_set_boot_image(IsoImage *image, const char *image_path, } /* create the boot image */ - ret = create_image(image, image_path, type, &boot_image); + ret = create_image(image, image_path, type, &boot_image, &boot_node); if (ret < 0) { goto boot_image_cleanup; } @@ -530,6 +534,8 @@ int iso_image_set_boot_image(IsoImage *image, const char *image_path, catalog->bootimages[i] = NULL; catalog->node = cat_node; catalog->sort_weight = 1000; /* slightly high */ + if (!boot_node->explicit_weight) + boot_node->sort_weight = 2; iso_node_ref((IsoNode*)cat_node); image->bootcat = catalog; @@ -700,14 +706,17 @@ int iso_image_add_boot_image(IsoImage *image, const char *image_path, int ret; struct el_torito_boot_catalog *catalog = image->bootcat; ElToritoBootImage *boot_img; + IsoFile *boot_node; if(catalog == NULL) return ISO_BOOT_NO_CATALOG; if (catalog->num_bootimages >= Libisofs_max_boot_imageS) return ISO_BOOT_IMAGE_OVERFLOW; - ret = create_image(image, image_path, type, &boot_img); + ret = create_image(image, image_path, type, &boot_img, &boot_node); if (ret < 0) return ret; + if (!boot_node->explicit_weight) + boot_node->sort_weight = 2; catalog->bootimages[catalog->num_bootimages] = boot_img; catalog->num_bootimages++; if (boot != NULL) diff --git a/libisofs/node.c b/libisofs/node.c index 7f7041f..e1545cb 100644 --- a/libisofs/node.c +++ b/libisofs/node.c @@ -1048,6 +1048,7 @@ void iso_node_set_sort_weight(IsoNode *node, int w) } } else if (node->type == LIBISO_FILE) { ((IsoFile*)node)->sort_weight = w; + ((IsoFile*)node)->explicit_weight = 1; } } @@ -1430,6 +1431,8 @@ int iso_node_new_file(char *name, IsoStream *stream, IsoFile **file) new->node.type = LIBISO_FILE; new->node.name = name; new->node.mode = S_IFREG; + new->from_old_session = 0; + new->explicit_weight = 0; new->sort_weight = 0; new->stream = stream; diff --git a/libisofs/node.h b/libisofs/node.h index 6761143..2cdac22 100644 --- a/libisofs/node.h +++ b/libisofs/node.h @@ -149,8 +149,15 @@ struct Iso_File { IsoNode node; + /* 1 = The node was loaded from an existing ISO image and still refers + to its data content there. + */ unsigned int from_old_session : 1; + /* 1 = The node got attributed a weight by iso_node_set_sort_weight(). + */ + unsigned int explicit_weight : 1; + /** * It sorts the order in which the file data is written to the CD image. * Higher weighting files are written at the beginning of image