- use emalloc and friends
- kill a bunch of global variables, more work to be done here - homogenize option parsing. more work for cd9660 - use the new options parsing code to print an fs-specific usage
This commit is contained in:
parent
2157479565
commit
e4989541fe
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cd9660.h,v 1.18 2012/01/28 02:35:46 christos Exp $ */
|
||||
/* $NetBSD: cd9660.h,v 1.19 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
||||
|
@ -311,9 +311,6 @@ typedef struct _iso9660_disk {
|
|||
|
||||
} iso9660_disk;
|
||||
|
||||
/******** GLOBAL VARIABLES ***********/
|
||||
extern iso9660_disk diskStructure;
|
||||
|
||||
/************ FUNCTIONS **************/
|
||||
int cd9660_valid_a_chars(const char *);
|
||||
int cd9660_valid_d_chars(const char *);
|
||||
|
@ -332,25 +329,26 @@ void cd9660_time_915(unsigned char *, time_t);
|
|||
|
||||
/*** Boot Functions ***/
|
||||
int cd9660_write_generic_bootimage(FILE *);
|
||||
int cd9660_add_generic_bootimage(const char *);
|
||||
int cd9660_write_boot(FILE *);
|
||||
int cd9660_add_boot_disk(const char *);
|
||||
int cd9660_eltorito_add_boot_option(const char *, const char *);
|
||||
int cd9660_setup_boot(int);
|
||||
int cd9660_setup_boot_volume_descriptor(volume_descriptor *);
|
||||
int cd9660_write_boot(iso9660_disk *, FILE *);
|
||||
int cd9660_add_boot_disk(iso9660_disk *, const char *);
|
||||
int cd9660_eltorito_add_boot_option(iso9660_disk *, const char *,
|
||||
const char *);
|
||||
int cd9660_setup_boot(iso9660_disk *, int);
|
||||
int cd9660_setup_boot_volume_descriptor(iso9660_disk *,
|
||||
volume_descriptor *);
|
||||
|
||||
|
||||
/*** Write Functions ***/
|
||||
int cd9660_write_image(const char *image);
|
||||
int cd9660_copy_file(FILE *, off_t, const char *);
|
||||
int cd9660_write_image(iso9660_disk *, const char *image);
|
||||
int cd9660_copy_file(iso9660_disk *, FILE *, off_t, const char *);
|
||||
|
||||
void cd9660_compute_full_filename(cd9660node *, char *);
|
||||
int cd9660_compute_record_size(cd9660node *);
|
||||
int cd9660_compute_record_size(iso9660_disk *, cd9660node *);
|
||||
|
||||
/* Debugging functions */
|
||||
void debug_print_tree(cd9660node *,int);
|
||||
void debug_print_tree(iso9660_disk *, cd9660node *,int);
|
||||
void debug_print_path_tree(cd9660node *);
|
||||
void debug_print_volume_descriptor_information(void);
|
||||
void debug_print_volume_descriptor_information(iso9660_disk *);
|
||||
void debug_dump_to_xml_ptentry(path_table_entry *,int, int);
|
||||
void debug_dump_to_xml_path_table(FILE *, off_t, int, int);
|
||||
void debug_dump_to_xml(FILE *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $ */
|
||||
/* $NetBSD: cd9660_archimedes.c,v 1.2 2013/01/28 21:03:28 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2009 Ben Harris
|
||||
|
@ -43,13 +43,14 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: cd9660_archimedes.c,v 1.1 2009/01/10 22:06:29 bjh21 Exp $");
|
||||
__RCSID("$NetBSD: cd9660_archimedes.c,v 1.2 2013/01/28 21:03:28 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "cd9660.h"
|
||||
|
@ -97,11 +98,8 @@ archimedes_convert_node(cd9660node *node)
|
|||
return;
|
||||
if (type == -1) type = 0;
|
||||
|
||||
assert(sizeof(struct ISO_ARCHIMEDES) == 32);
|
||||
if ((arc = calloc(1, sizeof(struct ISO_ARCHIMEDES))) == NULL) {
|
||||
CD9660_MEM_ALLOC_ERROR("archimedes_convert_node");
|
||||
exit(1);
|
||||
}
|
||||
assert(sizeof(*arc) == 32);
|
||||
arc = ecalloc(1, sizeof(*arc));
|
||||
|
||||
stamp = riscos_date(node->node->inode->st.st_mtime);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $ */
|
||||
/* $NetBSD: cd9660_debug.c,v 1.12 2013/01/28 21:03:28 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
||||
|
@ -40,7 +40,7 @@
|
|||
#include <sys/param.h>
|
||||
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: cd9660_debug.c,v 1.11 2010/10/27 18:51:35 christos Exp $");
|
||||
__RCSID("$NetBSD: cd9660_debug.c,v 1.12 2013/01/28 21:03:28 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#if !HAVE_NBTOOL_CONFIG_H
|
||||
|
@ -92,7 +92,7 @@ debug_print_susp_attrs(cd9660node *n, int indent)
|
|||
}
|
||||
|
||||
void
|
||||
debug_print_tree(cd9660node *node, int level)
|
||||
debug_print_tree(iso9660_disk *diskStructure, cd9660node *node, int level)
|
||||
{
|
||||
#if !HAVE_NBTOOL_CONFIG_H
|
||||
cd9660node *cn;
|
||||
|
@ -120,10 +120,10 @@ debug_print_tree(cd9660node *node, int level)
|
|||
node->fileDataSector
|
||||
+ node->fileSectorsUsed - 1);
|
||||
}
|
||||
if (diskStructure.rock_ridge_enabled)
|
||||
if (diskStructure->rock_ridge_enabled)
|
||||
debug_print_susp_attrs(node, level + 1);
|
||||
TAILQ_FOREACH(cn, &node->cn_children, cn_next_child)
|
||||
debug_print_tree(cn, level + 1);
|
||||
debug_print_tree(diskStructure, cn, level + 1);
|
||||
#else
|
||||
printf("Sorry, debugging is not supported in host-tools mode.\n");
|
||||
#endif
|
||||
|
@ -150,9 +150,9 @@ debug_print_path_tree(cd9660node *n)
|
|||
}
|
||||
|
||||
void
|
||||
debug_print_volume_descriptor_information(void)
|
||||
debug_print_volume_descriptor_information(iso9660_disk *diskStructure)
|
||||
{
|
||||
volume_descriptor *tmp = diskStructure.firstVolumeDescriptor;
|
||||
volume_descriptor *tmp = diskStructure->firstVolumeDescriptor;
|
||||
char temp[CD9660_SECTOR_SIZE];
|
||||
|
||||
printf("==Listing Volume Descriptors==\n");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cd9660_eltorito.c,v 1.19 2012/04/19 17:28:25 christos Exp $ */
|
||||
/* $NetBSD: cd9660_eltorito.c,v 1.20 2013/01/28 21:03:28 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
||||
|
@ -36,10 +36,11 @@
|
|||
#include "cd9660.h"
|
||||
#include "cd9660_eltorito.h"
|
||||
#include <sys/bootblock.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: cd9660_eltorito.c,v 1.19 2012/04/19 17:28:25 christos Exp $");
|
||||
__RCSID("$NetBSD: cd9660_eltorito.c,v 1.20 2013/01/28 21:03:28 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -48,6 +49,8 @@ __RCSID("$NetBSD: cd9660_eltorito.c,v 1.19 2012/04/19 17:28:25 christos Exp $");
|
|||
#define ELTORITO_DPRINTF(__x)
|
||||
#endif
|
||||
|
||||
#include <util.h>
|
||||
|
||||
static struct boot_catalog_entry *cd9660_init_boot_catalog_entry(void);
|
||||
static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char);
|
||||
static struct boot_catalog_entry *cd9660_boot_setup_default_entry(
|
||||
|
@ -59,7 +62,7 @@ static u_char cd9660_boot_get_system_type(struct cd9660_boot_image *);
|
|||
#endif
|
||||
|
||||
int
|
||||
cd9660_add_boot_disk(const char *boot_info)
|
||||
cd9660_add_boot_disk(iso9660_disk *diskStructure, const char *boot_info)
|
||||
{
|
||||
struct stat stbuf;
|
||||
const char *mode_msg;
|
||||
|
@ -77,10 +80,7 @@ cd9660_add_boot_disk(const char *boot_info)
|
|||
}
|
||||
|
||||
/* First decode the boot information */
|
||||
if ((temp = strdup(boot_info)) == NULL) {
|
||||
warn("%s: strdup", __func__);
|
||||
return 0;
|
||||
}
|
||||
temp = estrdup(boot_info);
|
||||
|
||||
sysname = temp;
|
||||
filename = strchr(sysname, ';');
|
||||
|
@ -93,16 +93,11 @@ cd9660_add_boot_disk(const char *boot_info)
|
|||
|
||||
*filename++ = '\0';
|
||||
|
||||
if (diskStructure.verbose_level > 0) {
|
||||
if (diskStructure->verbose_level > 0) {
|
||||
printf("Found bootdisk with system %s, and filename %s\n",
|
||||
sysname, filename);
|
||||
}
|
||||
if ((new_image = malloc(sizeof(*new_image))) == NULL) {
|
||||
warn("%s: malloc", __func__);
|
||||
free(temp);
|
||||
return 0;
|
||||
}
|
||||
(void)memset(new_image, 0, sizeof(*new_image));
|
||||
new_image = ecalloc(1, sizeof(*new_image));
|
||||
new_image->loadSegment = 0; /* default for now */
|
||||
|
||||
/* Decode System */
|
||||
|
@ -122,12 +117,7 @@ cd9660_add_boot_disk(const char *boot_info)
|
|||
}
|
||||
|
||||
|
||||
if ((new_image->filename = strdup(filename)) == NULL) {
|
||||
warn("%s: strdup", __func__);
|
||||
free(temp);
|
||||
free(new_image);
|
||||
return 0;
|
||||
}
|
||||
new_image->filename = estrdup(filename);
|
||||
|
||||
free(temp);
|
||||
|
||||
|
@ -155,14 +145,14 @@ cd9660_add_boot_disk(const char *boot_info)
|
|||
break;
|
||||
}
|
||||
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("%s\n", mode_msg);
|
||||
|
||||
new_image->size = stbuf.st_size;
|
||||
new_image->num_sectors =
|
||||
howmany(new_image->size, diskStructure.sectorSize) *
|
||||
howmany(diskStructure.sectorSize, 512);
|
||||
if (diskStructure.verbose_level > 0) {
|
||||
howmany(new_image->size, diskStructure->sectorSize) *
|
||||
howmany(diskStructure->sectorSize, 512);
|
||||
if (diskStructure->verbose_level > 0) {
|
||||
printf("New image has size %d, uses %d 512-byte sectors\n",
|
||||
new_image->size, new_image->num_sectors);
|
||||
}
|
||||
|
@ -172,27 +162,28 @@ cd9660_add_boot_disk(const char *boot_info)
|
|||
/* Add boot disk */
|
||||
|
||||
/* Group images for the same platform together. */
|
||||
TAILQ_FOREACH(tmp_image, &diskStructure.boot_images, image_list) {
|
||||
TAILQ_FOREACH(tmp_image, &diskStructure->boot_images, image_list) {
|
||||
if (tmp_image->system != new_image->system)
|
||||
break;
|
||||
}
|
||||
|
||||
if (tmp_image == NULL) {
|
||||
TAILQ_INSERT_HEAD(&diskStructure.boot_images, new_image,
|
||||
TAILQ_INSERT_HEAD(&diskStructure->boot_images, new_image,
|
||||
image_list);
|
||||
} else
|
||||
TAILQ_INSERT_BEFORE(tmp_image, new_image, image_list);
|
||||
|
||||
new_image->serialno = diskStructure.image_serialno++;
|
||||
new_image->serialno = diskStructure->image_serialno++;
|
||||
|
||||
/* TODO : Need to do anything about the boot image in the tree? */
|
||||
diskStructure.is_bootable = 1;
|
||||
diskStructure->is_bootable = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
cd9660_eltorito_add_boot_option(const char *option_string, const char *value)
|
||||
cd9660_eltorito_add_boot_option(iso9660_disk *diskStructure,
|
||||
const char *option_string, const char *value)
|
||||
{
|
||||
char *eptr;
|
||||
struct cd9660_boot_image *image;
|
||||
|
@ -200,8 +191,8 @@ cd9660_eltorito_add_boot_option(const char *option_string, const char *value)
|
|||
assert(option_string != NULL);
|
||||
|
||||
/* Find the last image added */
|
||||
TAILQ_FOREACH(image, &diskStructure.boot_images, image_list) {
|
||||
if (image->serialno + 1 == diskStructure.image_serialno)
|
||||
TAILQ_FOREACH(image, &diskStructure->boot_images, image_list) {
|
||||
if (image->serialno + 1 == diskStructure->image_serialno)
|
||||
break;
|
||||
}
|
||||
if (image == NULL)
|
||||
|
@ -229,12 +220,7 @@ cd9660_eltorito_add_boot_option(const char *option_string, const char *value)
|
|||
static struct boot_catalog_entry *
|
||||
cd9660_init_boot_catalog_entry(void)
|
||||
{
|
||||
struct boot_catalog_entry *temp;
|
||||
|
||||
if ((temp = malloc(sizeof(*temp))) == NULL)
|
||||
return NULL;
|
||||
|
||||
return memset(temp, 0, sizeof(*temp));
|
||||
return ecalloc(1, sizeof(struct boot_catalog_entry));
|
||||
}
|
||||
|
||||
static struct boot_catalog_entry *
|
||||
|
@ -247,11 +233,6 @@ cd9660_boot_setup_validation_entry(char sys)
|
|||
size_t i;
|
||||
entry = cd9660_init_boot_catalog_entry();
|
||||
|
||||
if (entry == NULL) {
|
||||
warnx("Error: memory allocation failed in "
|
||||
"cd9660_boot_setup_validation_entry");
|
||||
return 0;
|
||||
}
|
||||
ve = &entry->entry_data.VE;
|
||||
|
||||
ve->header_id[0] = 1;
|
||||
|
@ -355,7 +336,7 @@ cd9660_boot_get_system_type(struct cd9660_boot_image *disk)
|
|||
* Set up the BVD, Boot catalog, and the boot entries, but do no writing
|
||||
*/
|
||||
int
|
||||
cd9660_setup_boot(int first_sector)
|
||||
cd9660_setup_boot(iso9660_disk *diskStructure, int first_sector)
|
||||
{
|
||||
int sector;
|
||||
int used_sectors;
|
||||
|
@ -369,14 +350,14 @@ cd9660_setup_boot(int first_sector)
|
|||
x86_head = mac_head = ppc_head = NULL;
|
||||
|
||||
/* If there are no boot disks, don't bother building boot information */
|
||||
if (TAILQ_EMPTY(&diskStructure.boot_images))
|
||||
if (TAILQ_EMPTY(&diskStructure->boot_images))
|
||||
return 0;
|
||||
|
||||
/* Point to catalog: For now assume it consumes one sector */
|
||||
ELTORITO_DPRINTF(("Boot catalog will go in sector %d\n", first_sector));
|
||||
diskStructure.boot_catalog_sector = first_sector;
|
||||
diskStructure->boot_catalog_sector = first_sector;
|
||||
cd9660_bothendian_dword(first_sector,
|
||||
diskStructure.boot_descriptor->boot_catalog_pointer);
|
||||
diskStructure->boot_descriptor->boot_catalog_pointer);
|
||||
|
||||
/* Step 1: Generate boot catalog */
|
||||
/* Step 1a: Validation entry */
|
||||
|
@ -391,16 +372,16 @@ cd9660_setup_boot(int first_sector)
|
|||
num_entries = 1;
|
||||
used_sectors = 0;
|
||||
|
||||
TAILQ_FOREACH(tmp_disk, &diskStructure.boot_images, image_list) {
|
||||
TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) {
|
||||
used_sectors += tmp_disk->num_sectors;
|
||||
|
||||
/* One default entry per image */
|
||||
num_entries++;
|
||||
}
|
||||
catalog_sectors = howmany(num_entries * 0x20, diskStructure.sectorSize);
|
||||
catalog_sectors = howmany(num_entries * 0x20, diskStructure->sectorSize);
|
||||
used_sectors += catalog_sectors;
|
||||
|
||||
if (diskStructure.verbose_level > 0) {
|
||||
if (diskStructure->verbose_level > 0) {
|
||||
printf("%s: there will be %i entries consuming %i sectors. "
|
||||
"Catalog is %i sectors\n", __func__, num_entries,
|
||||
used_sectors, catalog_sectors);
|
||||
|
@ -408,16 +389,16 @@ cd9660_setup_boot(int first_sector)
|
|||
|
||||
/* Populate sector numbers */
|
||||
sector = first_sector + catalog_sectors;
|
||||
TAILQ_FOREACH(tmp_disk, &diskStructure.boot_images, image_list) {
|
||||
TAILQ_FOREACH(tmp_disk, &diskStructure->boot_images, image_list) {
|
||||
tmp_disk->sector = sector;
|
||||
sector += tmp_disk->num_sectors;
|
||||
}
|
||||
|
||||
LIST_INSERT_HEAD(&diskStructure.boot_entries, valid_entry, ll_struct);
|
||||
LIST_INSERT_HEAD(&diskStructure->boot_entries, valid_entry, ll_struct);
|
||||
|
||||
/* Step 1b: Initial/default entry */
|
||||
/* TODO : PARAM */
|
||||
tmp_disk = TAILQ_FIRST(&diskStructure.boot_images);
|
||||
tmp_disk = TAILQ_FIRST(&diskStructure->boot_images);
|
||||
default_entry = cd9660_boot_setup_default_entry(tmp_disk);
|
||||
if (default_entry == NULL) {
|
||||
warnx("Error: memory allocation failed in cd9660_setup_boot");
|
||||
|
@ -487,7 +468,8 @@ cd9660_setup_boot(int first_sector)
|
|||
}
|
||||
|
||||
int
|
||||
cd9660_setup_boot_volume_descriptor(volume_descriptor *bvd)
|
||||
cd9660_setup_boot_volume_descriptor(iso9660_disk *diskStructure,
|
||||
volume_descriptor *bvd)
|
||||
{
|
||||
boot_volume_descriptor *bvdData =
|
||||
(boot_volume_descriptor*)bvd->volumeDescriptorData;
|
||||
|
@ -497,7 +479,7 @@ cd9660_setup_boot_volume_descriptor(volume_descriptor *bvd)
|
|||
bvdData->version[0] = 1;
|
||||
memcpy(bvdData->boot_system_identifier, ET_ID, 23);
|
||||
memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5);
|
||||
diskStructure.boot_descriptor =
|
||||
diskStructure->boot_descriptor =
|
||||
(boot_volume_descriptor*) bvd->volumeDescriptorData;
|
||||
return 1;
|
||||
}
|
||||
|
@ -593,7 +575,7 @@ cd9660_write_apm_partition_entry(FILE *fd, int idx, int total_partitions,
|
|||
}
|
||||
|
||||
int
|
||||
cd9660_write_boot(FILE *fd)
|
||||
cd9660_write_boot(iso9660_disk *diskStructure, FILE *fd)
|
||||
{
|
||||
struct boot_catalog_entry *e;
|
||||
struct cd9660_boot_image *t;
|
||||
|
@ -601,16 +583,16 @@ cd9660_write_boot(FILE *fd)
|
|||
int mbr_partitions = 0;
|
||||
|
||||
/* write boot catalog */
|
||||
if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector *
|
||||
diskStructure.sectorSize, SEEK_SET) == -1)
|
||||
if (fseeko(fd, (off_t)diskStructure->boot_catalog_sector *
|
||||
diskStructure->sectorSize, SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
||||
if (diskStructure.verbose_level > 0) {
|
||||
if (diskStructure->verbose_level > 0) {
|
||||
printf("Writing boot catalog to sector %" PRId64 "\n",
|
||||
diskStructure.boot_catalog_sector);
|
||||
diskStructure->boot_catalog_sector);
|
||||
}
|
||||
LIST_FOREACH(e, &diskStructure.boot_entries, ll_struct) {
|
||||
if (diskStructure.verbose_level > 0) {
|
||||
LIST_FOREACH(e, &diskStructure->boot_entries, ll_struct) {
|
||||
if (diskStructure->verbose_level > 0) {
|
||||
printf("Writing catalog entry of type %d\n",
|
||||
e->entry_type);
|
||||
}
|
||||
|
@ -620,16 +602,16 @@ cd9660_write_boot(FILE *fd)
|
|||
*/
|
||||
fwrite(&(e->entry_data.VE), 1, 32, fd);
|
||||
}
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Finished writing boot catalog\n");
|
||||
|
||||
/* copy boot images */
|
||||
TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) {
|
||||
if (diskStructure.verbose_level > 0) {
|
||||
TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) {
|
||||
if (diskStructure->verbose_level > 0) {
|
||||
printf("Writing boot image from %s to sectors %d\n",
|
||||
t->filename, t->sector);
|
||||
}
|
||||
cd9660_copy_file(fd, t->sector, t->filename);
|
||||
cd9660_copy_file(diskStructure, fd, t->sector, t->filename);
|
||||
|
||||
if (t->system == ET_SYS_MAC)
|
||||
apm_partitions++;
|
||||
|
@ -638,7 +620,7 @@ cd9660_write_boot(FILE *fd)
|
|||
}
|
||||
|
||||
/* some systems need partition tables as well */
|
||||
if (mbr_partitions > 0 || diskStructure.chrp_boot) {
|
||||
if (mbr_partitions > 0 || diskStructure->chrp_boot) {
|
||||
uint16_t sig;
|
||||
|
||||
fseek(fd, 0x1fe, SEEK_SET);
|
||||
|
@ -648,18 +630,18 @@ cd9660_write_boot(FILE *fd)
|
|||
mbr_partitions = 0;
|
||||
|
||||
/* Write ISO9660 descriptor, enclosing the whole disk */
|
||||
if (diskStructure.chrp_boot)
|
||||
if (diskStructure->chrp_boot)
|
||||
cd9660_write_mbr_partition_entry(fd, mbr_partitions++,
|
||||
0, diskStructure.totalSectors *
|
||||
(diskStructure.sectorSize / 512), 0x96);
|
||||
0, diskStructure->totalSectors *
|
||||
(diskStructure->sectorSize / 512), 0x96);
|
||||
|
||||
/* Write all partition entries */
|
||||
TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) {
|
||||
TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) {
|
||||
if (t->system != ET_SYS_PPC)
|
||||
continue;
|
||||
cd9660_write_mbr_partition_entry(fd, mbr_partitions++,
|
||||
t->sector * (diskStructure.sectorSize / 512),
|
||||
t->num_sectors * (diskStructure.sectorSize / 512),
|
||||
t->sector * (diskStructure->sectorSize / 512),
|
||||
t->num_sectors * (diskStructure->sectorSize / 512),
|
||||
0x41 /* PReP Boot */);
|
||||
}
|
||||
}
|
||||
|
@ -677,8 +659,8 @@ cd9660_write_boot(FILE *fd)
|
|||
apm16 = htobe16(512);
|
||||
fwrite(&apm16, sizeof(apm16), 1, fd);
|
||||
/* Device block count */
|
||||
apm32 = htobe32(diskStructure.totalSectors *
|
||||
(diskStructure.sectorSize / 512));
|
||||
apm32 = htobe32(diskStructure->totalSectors *
|
||||
(diskStructure->sectorSize / 512));
|
||||
fwrite(&apm32, sizeof(apm32), 1, fd);
|
||||
/* Device type/id */
|
||||
apm16 = htobe16(1);
|
||||
|
@ -694,24 +676,23 @@ cd9660_write_boot(FILE *fd)
|
|||
|
||||
/* Write all partition entries */
|
||||
apm_partitions = 0;
|
||||
TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) {
|
||||
TAILQ_FOREACH(t, &diskStructure->boot_images, image_list) {
|
||||
if (t->system != ET_SYS_MAC)
|
||||
continue;
|
||||
|
||||
cd9660_write_apm_partition_entry(fd,
|
||||
1 + apm_partitions++, total_parts,
|
||||
t->sector * (diskStructure.sectorSize / 512),
|
||||
t->num_sectors * (diskStructure.sectorSize / 512),
|
||||
t->sector * (diskStructure->sectorSize / 512),
|
||||
t->num_sectors * (diskStructure->sectorSize / 512),
|
||||
512, "CD Boot", "Apple_Bootstrap");
|
||||
}
|
||||
|
||||
/* Write ISO9660 descriptor, enclosing the whole disk */
|
||||
cd9660_write_apm_partition_entry(fd, 2 + apm_partitions,
|
||||
total_parts, 0, diskStructure.totalSectors *
|
||||
(diskStructure.sectorSize / 512), 512, "ISO9660",
|
||||
total_parts, 0, diskStructure->totalSectors *
|
||||
(diskStructure->sectorSize / 512), 512, "ISO9660",
|
||||
"CD_ROM_Mode_1");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cd9660_write.c,v 1.15 2012/01/28 02:35:46 christos Exp $ */
|
||||
/* $NetBSD: cd9660_write.c,v 1.16 2013/01/28 21:03:28 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
||||
|
@ -37,18 +37,21 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: cd9660_write.c,v 1.15 2012/01/28 02:35:46 christos Exp $");
|
||||
__RCSID("$NetBSD: cd9660_write.c,v 1.16 2013/01/28 21:03:28 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
static int cd9660_write_volume_descriptors(FILE *);
|
||||
static int cd9660_write_path_table(FILE *, off_t, int);
|
||||
static int cd9660_write_path_tables(FILE *);
|
||||
static int cd9660_write_file(FILE *, cd9660node *);
|
||||
static int cd9660_write_filedata(FILE *, off_t, const unsigned char *, int);
|
||||
#include <util.h>
|
||||
|
||||
static int cd9660_write_volume_descriptors(iso9660_disk *, FILE *);
|
||||
static int cd9660_write_path_table(iso9660_disk *, FILE *, off_t, int);
|
||||
static int cd9660_write_path_tables(iso9660_disk *, FILE *);
|
||||
static int cd9660_write_file(iso9660_disk *, FILE *, cd9660node *);
|
||||
static int cd9660_write_filedata(iso9660_disk *, FILE *, off_t,
|
||||
const unsigned char *, int);
|
||||
#if 0
|
||||
static int cd9660_write_buffered(FILE *, off_t, int, const unsigned char *);
|
||||
#endif
|
||||
static void cd9660_write_rr(FILE *, cd9660node *, off_t, off_t);
|
||||
static void cd9660_write_rr(iso9660_disk *, FILE *, cd9660node *, off_t, off_t);
|
||||
|
||||
/*
|
||||
* Write the image
|
||||
|
@ -57,7 +60,7 @@ static void cd9660_write_rr(FILE *, cd9660node *, off_t, off_t);
|
|||
* @returns int 1 on success, 0 on failure
|
||||
*/
|
||||
int
|
||||
cd9660_write_image(const char* image)
|
||||
cd9660_write_image(iso9660_disk *diskStructure, const char* image)
|
||||
{
|
||||
FILE *fd;
|
||||
int status;
|
||||
|
@ -68,12 +71,12 @@ cd9660_write_image(const char* image)
|
|||
image);
|
||||
}
|
||||
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Writing image\n");
|
||||
|
||||
if (diskStructure.has_generic_bootimage) {
|
||||
status = cd9660_copy_file(fd, 0,
|
||||
diskStructure.generic_bootimage);
|
||||
if (diskStructure->has_generic_bootimage) {
|
||||
status = cd9660_copy_file(diskStructure, fd, 0,
|
||||
diskStructure->generic_bootimage);
|
||||
if (status == 0) {
|
||||
warnx("%s: Error writing generic boot image",
|
||||
__func__);
|
||||
|
@ -82,70 +85,71 @@ cd9660_write_image(const char* image)
|
|||
}
|
||||
|
||||
/* Write the volume descriptors */
|
||||
status = cd9660_write_volume_descriptors(fd);
|
||||
status = cd9660_write_volume_descriptors(diskStructure, fd);
|
||||
if (status == 0) {
|
||||
warnx("%s: Error writing volume descriptors to image",
|
||||
__func__);
|
||||
goto cleanup_bad_image;
|
||||
}
|
||||
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Volume descriptors written\n");
|
||||
|
||||
/*
|
||||
* Write the path tables: there are actually four, but right
|
||||
* now we are only concearned with two.
|
||||
*/
|
||||
status = cd9660_write_path_tables(fd);
|
||||
status = cd9660_write_path_tables(diskStructure, fd);
|
||||
if (status == 0) {
|
||||
warnx("%s: Error writing path tables to image", __func__);
|
||||
goto cleanup_bad_image;
|
||||
}
|
||||
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Path tables written\n");
|
||||
|
||||
/* Write the directories and files */
|
||||
status = cd9660_write_file(fd, diskStructure.rootNode);
|
||||
status = cd9660_write_file(diskStructure, fd, diskStructure->rootNode);
|
||||
if (status == 0) {
|
||||
warnx("%s: Error writing files to image", __func__);
|
||||
goto cleanup_bad_image;
|
||||
}
|
||||
|
||||
if (diskStructure.is_bootable) {
|
||||
cd9660_write_boot(fd);
|
||||
if (diskStructure->is_bootable) {
|
||||
cd9660_write_boot(diskStructure, fd);
|
||||
}
|
||||
|
||||
/* Write padding bits. This is temporary */
|
||||
memset(buf, 0, CD9660_SECTOR_SIZE);
|
||||
cd9660_write_filedata(fd, diskStructure.totalSectors - 1, buf, 1);
|
||||
cd9660_write_filedata(diskStructure, fd,
|
||||
diskStructure->totalSectors - 1, buf, 1);
|
||||
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Files written\n");
|
||||
fclose(fd);
|
||||
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Image closed\n");
|
||||
return 1;
|
||||
|
||||
cleanup_bad_image:
|
||||
fclose(fd);
|
||||
if (!diskStructure.keep_bad_images)
|
||||
if (!diskStructure->keep_bad_images)
|
||||
unlink(image);
|
||||
if (diskStructure.verbose_level > 0)
|
||||
if (diskStructure->verbose_level > 0)
|
||||
printf("Bad image cleaned up\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
cd9660_write_volume_descriptors(FILE *fd)
|
||||
cd9660_write_volume_descriptors(iso9660_disk *diskStructure, FILE *fd)
|
||||
{
|
||||
volume_descriptor *vd_temp = diskStructure.firstVolumeDescriptor;
|
||||
volume_descriptor *vd_temp = diskStructure->firstVolumeDescriptor;
|
||||
int pos;
|
||||
|
||||
while (vd_temp != NULL) {
|
||||
pos = vd_temp->sector * diskStructure.sectorSize;
|
||||
cd9660_write_filedata(fd, vd_temp->sector,
|
||||
pos = vd_temp->sector * diskStructure->sectorSize;
|
||||
cd9660_write_filedata(diskStructure, fd, vd_temp->sector,
|
||||
vd_temp->volumeDescriptorData, 1);
|
||||
vd_temp = vd_temp->next;
|
||||
}
|
||||
|
@ -161,26 +165,21 @@ cd9660_write_volume_descriptors(FILE *fd)
|
|||
* @returns int 1 on success, 0 on failure
|
||||
*/
|
||||
static int
|
||||
cd9660_write_path_table(FILE *fd, off_t sector, int mode)
|
||||
cd9660_write_path_table(iso9660_disk *diskStructure, FILE *fd, off_t sector,
|
||||
int mode)
|
||||
{
|
||||
int path_table_sectors = CD9660_BLOCKS(diskStructure.sectorSize,
|
||||
diskStructure.pathTableLength);
|
||||
int path_table_sectors = CD9660_BLOCKS(diskStructure->sectorSize,
|
||||
diskStructure->pathTableLength);
|
||||
unsigned char *buffer;
|
||||
unsigned char *buffer_head;
|
||||
int len;
|
||||
path_table_entry temp_entry;
|
||||
cd9660node *ptcur;
|
||||
|
||||
buffer = malloc(diskStructure.sectorSize * path_table_sectors);
|
||||
if (buffer == NULL) {
|
||||
warnx("%s: Memory allocation error allocating buffer",
|
||||
__func__);
|
||||
return 0;
|
||||
}
|
||||
buffer = ecalloc(path_table_sectors, diskStructure->sectorSize);
|
||||
buffer_head = buffer;
|
||||
memset(buffer, 0, diskStructure.sectorSize * path_table_sectors);
|
||||
|
||||
ptcur = diskStructure.rootNode;
|
||||
ptcur = diskStructure->rootNode;
|
||||
|
||||
while (ptcur != NULL) {
|
||||
memset(&temp_entry, 0, sizeof(path_table_entry));
|
||||
|
@ -215,7 +214,7 @@ cd9660_write_path_table(FILE *fd, off_t sector, int mode)
|
|||
ptcur = ptcur->ptnext;
|
||||
}
|
||||
|
||||
return cd9660_write_filedata(fd, sector, buffer_head,
|
||||
return cd9660_write_filedata(diskStructure, fd, sector, buffer_head,
|
||||
path_table_sectors);
|
||||
}
|
||||
|
||||
|
@ -235,14 +234,14 @@ cd9660_write_path_table(FILE *fd, off_t sector, int mode)
|
|||
* @returns int 0 on failure, 1 on success
|
||||
*/
|
||||
static int
|
||||
cd9660_write_path_tables(FILE *fd)
|
||||
cd9660_write_path_tables(iso9660_disk *diskStructure, FILE *fd)
|
||||
{
|
||||
if (cd9660_write_path_table(fd,
|
||||
diskStructure.primaryLittleEndianTableSector, LITTLE_ENDIAN) == 0)
|
||||
if (cd9660_write_path_table(diskStructure, fd,
|
||||
diskStructure->primaryLittleEndianTableSector, LITTLE_ENDIAN) == 0)
|
||||
return 0;
|
||||
|
||||
if (cd9660_write_path_table(fd,
|
||||
diskStructure.primaryBigEndianTableSector, BIG_ENDIAN) == 0)
|
||||
if (cd9660_write_path_table(diskStructure, fd,
|
||||
diskStructure->primaryBigEndianTableSector, BIG_ENDIAN) == 0)
|
||||
return 0;
|
||||
|
||||
/* @TODO: handle remaining two path tables */
|
||||
|
@ -261,7 +260,7 @@ cd9660_write_path_tables(FILE *fd)
|
|||
* @returns int 0 on failure, 1 on success
|
||||
*/
|
||||
static int
|
||||
cd9660_write_file(FILE *fd, cd9660node *writenode)
|
||||
cd9660_write_file(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode)
|
||||
{
|
||||
char *buf;
|
||||
char *temp_file_name;
|
||||
|
@ -275,16 +274,8 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
|
|||
|
||||
/* Todo : clean up variables */
|
||||
|
||||
temp_file_name = malloc(CD9660MAXPATH + 1);
|
||||
if (temp_file_name == NULL)
|
||||
err(EXIT_FAILURE, "%s: malloc", __func__);
|
||||
|
||||
memset(temp_file_name, 0, CD9660MAXPATH + 1);
|
||||
|
||||
buf = malloc(diskStructure.sectorSize);
|
||||
if (buf == NULL)
|
||||
err(EXIT_FAILURE, "%s: malloc", __func__);
|
||||
|
||||
temp_file_name = ecalloc(CD9660MAXPATH + 1, 1);
|
||||
buf = emalloc(diskStructure->sectorSize);
|
||||
if ((writenode->level != 0) &&
|
||||
!(writenode->node->type & S_IFDIR)) {
|
||||
fsinode *inode = writenode->node->inode;
|
||||
|
@ -298,8 +289,8 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
|
|||
inode->flags |= FI_WRITTEN;
|
||||
cd9660_compute_full_filename(writenode,
|
||||
temp_file_name);
|
||||
ret = cd9660_copy_file(fd, writenode->fileDataSector,
|
||||
temp_file_name);
|
||||
ret = cd9660_copy_file(diskStructure, fd,
|
||||
writenode->fileDataSector, temp_file_name);
|
||||
if (ret == 0)
|
||||
goto out;
|
||||
}
|
||||
|
@ -316,7 +307,7 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
|
|||
*/
|
||||
cur_sector_offset = 0;
|
||||
working_sector = writenode->fileDataSector;
|
||||
if (fseeko(fd, working_sector * diskStructure.sectorSize,
|
||||
if (fseeko(fd, working_sector * diskStructure->sectorSize,
|
||||
SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
||||
|
@ -333,27 +324,27 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
|
|||
sizeof(iso_directory_record_cd9660));
|
||||
|
||||
temp_record.length[0] =
|
||||
cd9660_compute_record_size(temp);
|
||||
cd9660_compute_record_size(diskStructure, temp);
|
||||
|
||||
if (temp_record.length[0] + cur_sector_offset >=
|
||||
diskStructure.sectorSize) {
|
||||
diskStructure->sectorSize) {
|
||||
cur_sector_offset = 0;
|
||||
working_sector++;
|
||||
|
||||
/* Seek to the next sector. */
|
||||
if (fseeko(fd, working_sector *
|
||||
diskStructure.sectorSize, SEEK_SET) == -1)
|
||||
diskStructure->sectorSize, SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
}
|
||||
/* Write out the basic ISO directory record */
|
||||
written = fwrite(&temp_record, 1,
|
||||
temp->isoDirRecord->length[0], fd);
|
||||
if (diskStructure.rock_ridge_enabled) {
|
||||
cd9660_write_rr(fd, temp,
|
||||
if (diskStructure->rock_ridge_enabled) {
|
||||
cd9660_write_rr(diskStructure, fd, temp,
|
||||
cur_sector_offset, working_sector);
|
||||
}
|
||||
if (fseeko(fd, working_sector *
|
||||
diskStructure.sectorSize + cur_sector_offset +
|
||||
diskStructure->sectorSize + cur_sector_offset +
|
||||
temp_record.length[0] - temp->su_tail_size,
|
||||
SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
@ -372,7 +363,8 @@ cd9660_write_file(FILE *fd, cd9660node *writenode)
|
|||
* Recurse on children.
|
||||
*/
|
||||
TAILQ_FOREACH(temp, &writenode->cn_children, cn_next_child) {
|
||||
if ((ret = cd9660_write_file(fd, temp)) == 0)
|
||||
if ((ret = cd9660_write_file(diskStructure, fd, temp))
|
||||
== 0)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -397,24 +389,24 @@ out:
|
|||
* is written, the rest should be set to 0.
|
||||
*/
|
||||
static int
|
||||
cd9660_write_filedata(FILE *fd, off_t sector, const unsigned char *buf,
|
||||
int numsecs)
|
||||
cd9660_write_filedata(iso9660_disk *diskStructure, FILE *fd, off_t sector,
|
||||
const unsigned char *buf, int numsecs)
|
||||
{
|
||||
off_t curpos;
|
||||
size_t success;
|
||||
|
||||
curpos = ftello(fd);
|
||||
|
||||
if (fseeko(fd, sector * diskStructure.sectorSize, SEEK_SET) == -1)
|
||||
if (fseeko(fd, sector * diskStructure->sectorSize, SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
||||
success = fwrite(buf, diskStructure.sectorSize * numsecs, 1, fd);
|
||||
success = fwrite(buf, diskStructure->sectorSize * numsecs, 1, fd);
|
||||
|
||||
if (fseeko(fd, curpos, SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
||||
if (success == 1)
|
||||
success = diskStructure.sectorSize * numsecs;
|
||||
success = diskStructure->sectorSize * numsecs;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -431,28 +423,26 @@ cd9660_write_buffered(FILE *fd, off_t offset, int buff_len,
|
|||
#endif
|
||||
|
||||
int
|
||||
cd9660_copy_file(FILE *fd, off_t start_sector, const char *filename)
|
||||
cd9660_copy_file(iso9660_disk *diskStructure, FILE *fd, off_t start_sector,
|
||||
const char *filename)
|
||||
{
|
||||
FILE *rf;
|
||||
int bytes_read;
|
||||
off_t sector = start_sector;
|
||||
int buf_size = diskStructure.sectorSize;
|
||||
int buf_size = diskStructure->sectorSize;
|
||||
char *buf;
|
||||
|
||||
buf = malloc(buf_size);
|
||||
if (buf == NULL)
|
||||
err(EXIT_FAILURE, "%s: malloc", __func__);
|
||||
|
||||
buf = emalloc(buf_size);
|
||||
if ((rf = fopen(filename, "rb")) == NULL) {
|
||||
warn("%s: cannot open %s", __func__, filename);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (diskStructure.verbose_level > 1)
|
||||
if (diskStructure->verbose_level > 1)
|
||||
printf("Writing file: %s\n",filename);
|
||||
|
||||
if (fseeko(fd, start_sector * diskStructure.sectorSize, SEEK_SET) == -1)
|
||||
if (fseeko(fd, start_sector * diskStructure->sectorSize, SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
||||
while (!feof(rf)) {
|
||||
|
@ -480,13 +470,14 @@ cd9660_copy_file(FILE *fd, off_t start_sector, const char *filename)
|
|||
}
|
||||
|
||||
static void
|
||||
cd9660_write_rr(FILE *fd, cd9660node *writenode, off_t offset, off_t sector)
|
||||
cd9660_write_rr(iso9660_disk *diskStructure, FILE *fd, cd9660node *writenode,
|
||||
off_t offset, off_t sector)
|
||||
{
|
||||
int in_ca = 0;
|
||||
struct ISO_SUSP_ATTRIBUTES *myattr;
|
||||
|
||||
offset += writenode->isoDirRecord->length[0];
|
||||
if (fseeko(fd, sector * diskStructure.sectorSize + offset, SEEK_SET) ==
|
||||
if (fseeko(fd, sector * diskStructure->sectorSize + offset, SEEK_SET) ==
|
||||
-1)
|
||||
err(1, "fseeko");
|
||||
/* Offset now points at the end of the record */
|
||||
|
@ -500,9 +491,9 @@ cd9660_write_rr(FILE *fd, cd9660node *writenode, off_t offset, off_t sector)
|
|||
* Point the offset to the start of this
|
||||
* record's CE area
|
||||
*/
|
||||
if (fseeko(fd, ((off_t)diskStructure.
|
||||
if (fseeko(fd, ((off_t)diskStructure->
|
||||
susp_continuation_area_start_sector *
|
||||
diskStructure.sectorSize)
|
||||
diskStructure->sectorSize)
|
||||
+ writenode->susp_entry_ce_start,
|
||||
SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
|
@ -516,7 +507,7 @@ cd9660_write_rr(FILE *fd, cd9660node *writenode, off_t offset, off_t sector)
|
|||
* where we should be.
|
||||
*/
|
||||
if (in_ca)
|
||||
if (fseeko(fd, sector * diskStructure.sectorSize + offset,
|
||||
if (fseeko(fd, sector * diskStructure->sectorSize + offset,
|
||||
SEEK_SET) == -1)
|
||||
err(1, "fseeko");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: iso9660_rrip.c,v 1.11 2012/04/29 13:32:21 joerg Exp $ */
|
||||
/* $NetBSD: iso9660_rrip.c,v 1.12 2013/01/28 21:03:28 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
||||
|
@ -40,19 +40,21 @@
|
|||
#include "iso9660_rrip.h"
|
||||
#include <sys/queue.h>
|
||||
#include <stdio.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: iso9660_rrip.c,v 1.11 2012/04/29 13:32:21 joerg Exp $");
|
||||
__RCSID("$NetBSD: iso9660_rrip.c,v 1.12 2013/01/28 21:03:28 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
static void cd9660_rrip_initialize_inode(cd9660node *);
|
||||
static int cd9660_susp_handle_continuation(cd9660node *);
|
||||
static int cd9660_susp_handle_continuation_common(cd9660node *, int);
|
||||
static int cd9660_susp_handle_continuation(iso9660_disk *, cd9660node *);
|
||||
static int cd9660_susp_handle_continuation_common(iso9660_disk *, cd9660node *,
|
||||
int);
|
||||
|
||||
int
|
||||
cd9660_susp_initialize(cd9660node *node, cd9660node *parent,
|
||||
cd9660node *grandparent)
|
||||
cd9660_susp_initialize(iso9660_disk *diskStructure, cd9660node *node,
|
||||
cd9660node *parent, cd9660node *grandparent)
|
||||
{
|
||||
cd9660node *cn;
|
||||
int r;
|
||||
|
@ -69,11 +71,11 @@ cd9660_susp_initialize(cd9660node *node, cd9660node *parent,
|
|||
TAILQ_INIT(&(node->dot_dot_record->head));
|
||||
|
||||
/* SUSP specific entries here */
|
||||
if ((r = cd9660_susp_initialize_node(node)) < 0)
|
||||
if ((r = cd9660_susp_initialize_node(diskStructure, node)) < 0)
|
||||
return r;
|
||||
|
||||
/* currently called cd9660node_rrip_init_links */
|
||||
r = cd9660_rrip_initialize_node(node, parent, grandparent);
|
||||
r = cd9660_rrip_initialize_node(diskStructure, node, parent, grandparent);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -84,35 +86,35 @@ cd9660_susp_initialize(cd9660node *node, cd9660node *parent,
|
|||
* This should be called after all extensions. After
|
||||
* this is called, no new records should be added.
|
||||
*/
|
||||
if ((r = cd9660_susp_handle_continuation(node)) < 0)
|
||||
if ((r = cd9660_susp_handle_continuation(diskStructure, node)) < 0)
|
||||
return r;
|
||||
|
||||
/* Recurse on children. */
|
||||
TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) {
|
||||
if ((r = cd9660_susp_initialize(cn, node, parent)) < 0)
|
||||
if ((r = cd9660_susp_initialize(diskStructure, cn, node, parent)) < 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
cd9660_susp_finalize(cd9660node *node)
|
||||
cd9660_susp_finalize(iso9660_disk *diskStructure, cd9660node *node)
|
||||
{
|
||||
cd9660node *temp;
|
||||
int r;
|
||||
|
||||
assert(node != NULL);
|
||||
|
||||
if (node == diskStructure.rootNode)
|
||||
diskStructure.susp_continuation_area_current_free = 0;
|
||||
if (node == diskStructure->rootNode)
|
||||
diskStructure->susp_continuation_area_current_free = 0;
|
||||
|
||||
if ((r = cd9660_susp_finalize_node(node)) < 0)
|
||||
if ((r = cd9660_susp_finalize_node(diskStructure, node)) < 0)
|
||||
return r;
|
||||
if ((r = cd9660_rrip_finalize_node(node)) < 0)
|
||||
if ((r = cd9660_rrip_finalize_node(diskStructure, node)) < 0)
|
||||
return r;
|
||||
|
||||
TAILQ_FOREACH(temp, &node->cn_children, cn_next_child) {
|
||||
if ((r = cd9660_susp_finalize(temp)) < 0)
|
||||
if ((r = cd9660_susp_finalize(diskStructure, temp)) < 0)
|
||||
return r;
|
||||
}
|
||||
return 1;
|
||||
|
@ -132,15 +134,15 @@ cd9660_susp_finalize(cd9660node *node)
|
|||
* CE (continuation area)
|
||||
*/
|
||||
int
|
||||
cd9660_susp_finalize_node(cd9660node *node)
|
||||
cd9660_susp_finalize_node(iso9660_disk *diskStructure, cd9660node *node)
|
||||
{
|
||||
struct ISO_SUSP_ATTRIBUTES *t;
|
||||
|
||||
/* Handle CE counters */
|
||||
if (node->susp_entry_ce_length > 0) {
|
||||
node->susp_entry_ce_start =
|
||||
diskStructure.susp_continuation_area_current_free;
|
||||
diskStructure.susp_continuation_area_current_free +=
|
||||
diskStructure->susp_continuation_area_current_free;
|
||||
diskStructure->susp_continuation_area_current_free +=
|
||||
node->susp_entry_ce_length;
|
||||
}
|
||||
|
||||
|
@ -149,12 +151,12 @@ cd9660_susp_finalize_node(cd9660node *node)
|
|||
t->entry_type != SUSP_ENTRY_SUSP_CE)
|
||||
continue;
|
||||
cd9660_bothendian_dword(
|
||||
diskStructure.
|
||||
diskStructure->
|
||||
susp_continuation_area_start_sector,
|
||||
t->attr.su_entry.CE.ca_sector);
|
||||
|
||||
cd9660_bothendian_dword(
|
||||
diskStructure.
|
||||
diskStructure->
|
||||
susp_continuation_area_start_sector,
|
||||
t->attr.su_entry.CE.ca_sector);
|
||||
cd9660_bothendian_dword(node->susp_entry_ce_start,
|
||||
|
@ -166,7 +168,8 @@ cd9660_susp_finalize_node(cd9660node *node)
|
|||
}
|
||||
|
||||
int
|
||||
cd9660_rrip_finalize_node(cd9660node *node)
|
||||
cd9660_rrip_finalize_node(iso9660_disk *diskStructure __unused,
|
||||
cd9660node *node)
|
||||
{
|
||||
struct ISO_SUSP_ATTRIBUTES *t;
|
||||
|
||||
|
@ -199,7 +202,8 @@ cd9660_rrip_finalize_node(cd9660node *node)
|
|||
}
|
||||
|
||||
static int
|
||||
cd9660_susp_handle_continuation_common(cd9660node *node, int space)
|
||||
cd9660_susp_handle_continuation_common(iso9660_disk *diskStructure,
|
||||
cd9660node *node, int space)
|
||||
{
|
||||
int ca_used, susp_used, susp_used_pre_ce, working;
|
||||
struct ISO_SUSP_ATTRIBUTES *temp, *pre_ce, *last, *CE, *ST;
|
||||
|
@ -272,18 +276,18 @@ cd9660_susp_handle_continuation_common(cd9660node *node, int space)
|
|||
node->susp_entry_size = susp_used;
|
||||
node->susp_entry_ce_length = ca_used;
|
||||
|
||||
diskStructure.susp_continuation_area_size += ca_used;
|
||||
diskStructure->susp_continuation_area_size += ca_used;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* See if a continuation entry is needed for each of the different types */
|
||||
static int
|
||||
cd9660_susp_handle_continuation(cd9660node *node)
|
||||
cd9660_susp_handle_continuation(iso9660_disk *diskStructure, cd9660node *node)
|
||||
{
|
||||
assert (node != NULL);
|
||||
|
||||
/* Entry */
|
||||
if (cd9660_susp_handle_continuation_common(
|
||||
if (cd9660_susp_handle_continuation_common(diskStructure,
|
||||
node,(int)(node->isoDirRecord->length[0])) < 0)
|
||||
return 0;
|
||||
|
||||
|
@ -291,7 +295,7 @@ cd9660_susp_handle_continuation(cd9660node *node)
|
|||
}
|
||||
|
||||
int
|
||||
cd9660_susp_initialize_node(cd9660node *node)
|
||||
cd9660_susp_initialize_node(iso9660_disk *diskStructure, cd9660node *node)
|
||||
{
|
||||
struct ISO_SUSP_ATTRIBUTES *temp;
|
||||
|
||||
|
@ -307,7 +311,7 @@ cd9660_susp_initialize_node(cd9660node *node)
|
|||
|
||||
/* Check for root directory, add SP and ER if needed. */
|
||||
if (node->type & CD9660_TYPE_DOT) {
|
||||
if (node->parent == diskStructure.rootNode) {
|
||||
if (node->parent == diskStructure->rootNode) {
|
||||
temp = cd9660node_susp_create_node(SUSP_TYPE_SUSP,
|
||||
SUSP_ENTRY_SUSP_SP, "SP", SUSP_LOC_DOT);
|
||||
cd9660_susp_sp(temp, node);
|
||||
|
@ -366,8 +370,8 @@ cd9660_rrip_initialize_inode(cd9660node *node)
|
|||
}
|
||||
|
||||
int
|
||||
cd9660_rrip_initialize_node(cd9660node *node, cd9660node *parent,
|
||||
cd9660node *grandparent)
|
||||
cd9660_rrip_initialize_node(iso9660_disk *diskStructure, cd9660node *node,
|
||||
cd9660node *parent, cd9660node *grandparent)
|
||||
{
|
||||
struct ISO_SUSP_ATTRIBUTES *current = NULL;
|
||||
|
||||
|
@ -378,7 +382,7 @@ cd9660_rrip_initialize_node(cd9660node *node, cd9660node *parent,
|
|||
* Handle ER - should be the only entry to appear on
|
||||
* a "." record
|
||||
*/
|
||||
if (node->parent == diskStructure.rootNode) {
|
||||
if (node->parent == diskStructure->rootNode) {
|
||||
cd9660_susp_ER(node, 1, SUSP_RRIP_ER_EXT_ID,
|
||||
SUSP_RRIP_ER_EXT_DES, SUSP_RRIP_ER_EXT_SRC);
|
||||
}
|
||||
|
@ -416,7 +420,7 @@ cd9660_rrip_initialize_node(cd9660node *node, cd9660node *parent,
|
|||
*
|
||||
* The rr_moved_dir needs to be assigned a NM record as well.
|
||||
*/
|
||||
if (node == diskStructure.rr_moved_dir) {
|
||||
if (node == diskStructure->rr_moved_dir) {
|
||||
cd9660_rrip_add_NM(node, RRIP_DEFAULT_MOVE_DIR_NAME);
|
||||
}
|
||||
else if ((node->node != NULL) &&
|
||||
|
@ -456,11 +460,7 @@ cd9660node_susp_create_node(int susp_type, int entry_type, const char *type_id,
|
|||
{
|
||||
struct ISO_SUSP_ATTRIBUTES* temp;
|
||||
|
||||
if ((temp = malloc(sizeof(struct ISO_SUSP_ATTRIBUTES))) == NULL) {
|
||||
CD9660_MEM_ALLOC_ERROR("cd9660node_susp_create_node");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
temp = emalloc(sizeof(*temp));
|
||||
temp->susp_type = susp_type;
|
||||
temp->entry_type = entry_type;
|
||||
temp->last_in_suf = 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: iso9660_rrip.h,v 1.5 2009/01/10 22:06:29 bjh21 Exp $ */
|
||||
/* $NetBSD: iso9660_rrip.h,v 1.6 2013/01/28 21:03:28 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
|
||||
|
@ -215,11 +215,11 @@ struct ISO_SUSP_ATTRIBUTES {
|
|||
((int) ((entry)->attr.su_entry.SP.h.length[0]))
|
||||
|
||||
/* Recursive function - move later to func pointer code*/
|
||||
int cd9660_susp_finalize(cd9660node *);
|
||||
int cd9660_susp_finalize(iso9660_disk *, cd9660node *);
|
||||
|
||||
/* These two operate on single nodes */
|
||||
int cd9660_susp_finalize_node(cd9660node *);
|
||||
int cd9660_rrip_finalize_node(cd9660node *);
|
||||
int cd9660_susp_finalize_node(iso9660_disk *, cd9660node *);
|
||||
int cd9660_rrip_finalize_node(iso9660_disk *, cd9660node *);
|
||||
|
||||
/* POSIX File attribute */
|
||||
int cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
|
||||
|
@ -270,15 +270,17 @@ struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ES(struct ISO_SUSP_ATTRIBUTES*,
|
|||
/* Helper functions */
|
||||
|
||||
/* Common SUSP/RRIP functions */
|
||||
int cd9660_susp_initialize(cd9660node *, cd9660node *, cd9660node *);
|
||||
int cd9660_susp_initialize_node(cd9660node *);
|
||||
int cd9660_susp_initialize(iso9660_disk *, cd9660node *, cd9660node *,
|
||||
cd9660node *);
|
||||
int cd9660_susp_initialize_node(iso9660_disk *, cd9660node *);
|
||||
struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_create_node(int, int, const char *,
|
||||
int);
|
||||
struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_add_entry(cd9660node *,
|
||||
struct ISO_SUSP_ATTRIBUTES *, struct ISO_SUSP_ATTRIBUTES *, int);
|
||||
|
||||
/* RRIP specific functions */
|
||||
int cd9660_rrip_initialize_node(cd9660node *, cd9660node *, cd9660node *);
|
||||
int cd9660_rrip_initialize_node(iso9660_disk *, cd9660node *, cd9660node *,
|
||||
cd9660node *);
|
||||
void cd9660_createSL(cd9660node *);
|
||||
|
||||
/* Functions that probably can be removed */
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "chfs_makefs.h"
|
||||
|
@ -51,42 +52,46 @@ static void chfs_validate(const char *, fsnode *, fsinfo_t *);
|
|||
static int chfs_create_image(const char *, fsinfo_t *);
|
||||
static int chfs_populate_dir(const char *, fsnode *, fsnode *, fsinfo_t *);
|
||||
|
||||
chfs_opt_t chfs_opts;
|
||||
|
||||
void
|
||||
chfs_prep_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
fsopts->size = 0;
|
||||
fsopts->fs_specific = &chfs_opts;
|
||||
chfs_opt_t *chfs_opts = ecalloc(1, sizeof(*chfs_opts));
|
||||
|
||||
chfs_opts.pagesize = -1;
|
||||
chfs_opts.eraseblock = -1;
|
||||
chfs_opts.mediatype = -1;
|
||||
const option_t chfs_options[] = {
|
||||
{ 'p', "pagesize", &chfs_opts->pagesize, OPT_INT32,
|
||||
1, INT_MAX, "page size" },
|
||||
{ 'e', "eraseblock", &chfs_opts->eraseblock, OPT_INT32,
|
||||
1, INT_MAX, "eraseblock size" },
|
||||
{ 'm', "mediatype", &chfs_opts->mediatype, OPT_INT32,
|
||||
0, 1, "type of the media, 0 (nor) or 1 (nand)" },
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
chfs_opts->pagesize = -1;
|
||||
chfs_opts->eraseblock = -1;
|
||||
chfs_opts->mediatype = -1;
|
||||
|
||||
fsopts->size = 0;
|
||||
fsopts->fs_specific = chfs_opts;
|
||||
fsopts->fs_options = copy_opts(chfs_options);
|
||||
}
|
||||
|
||||
void
|
||||
chfs_cleanup_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
|
||||
free(fsopts->fs_specific);
|
||||
free(fsopts->fs_options);
|
||||
}
|
||||
|
||||
int
|
||||
chfs_parse_opts(const char *option, fsinfo_t *fsopts)
|
||||
{
|
||||
static const option_t chfs_options[] = {
|
||||
{ 'p', "pagesize", &chfs_opts.pagesize, OPT_INT32,
|
||||
1, INT_MAX, "page size" },
|
||||
{ 'e', "eraseblock", &chfs_opts.eraseblock, OPT_INT32,
|
||||
1, INT_MAX, "eraseblock size" },
|
||||
{ 'm', "mediatype", &chfs_opts.mediatype, OPT_INT32,
|
||||
0, 1, "type of the media, 0 (nor) or 1 (nand)" },
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
assert(option != NULL);
|
||||
assert(fsopts != NULL);
|
||||
|
||||
return set_option(chfs_options, option) != -1;
|
||||
return set_option(fsopts->fs_options, option) != -1;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -134,18 +139,21 @@ chfs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts)
|
|||
static void
|
||||
chfs_validate(const char* dir, fsnode *root, fsinfo_t *fsopts)
|
||||
{
|
||||
chfs_opt_t *chfs_opts;
|
||||
assert(dir != NULL);
|
||||
assert(root != NULL);
|
||||
assert(fsopts != NULL);
|
||||
|
||||
if (chfs_opts.pagesize == -1) {
|
||||
chfs_opts.pagesize = DEFAULT_PAGESIZE;
|
||||
chfs_opts = fsopts->fs_specific;
|
||||
|
||||
if (chfs_opts->pagesize == -1) {
|
||||
chfs_opts->pagesize = DEFAULT_PAGESIZE;
|
||||
}
|
||||
if (chfs_opts.eraseblock == -1) {
|
||||
chfs_opts.eraseblock = DEFAULT_ERASEBLOCK;
|
||||
if (chfs_opts->eraseblock == -1) {
|
||||
chfs_opts->eraseblock = DEFAULT_ERASEBLOCK;
|
||||
}
|
||||
if (chfs_opts.mediatype == -1) {
|
||||
chfs_opts.mediatype = DEFAULT_MEDIATYPE;
|
||||
if (chfs_opts->mediatype == -1) {
|
||||
chfs_opts->mediatype = DEFAULT_MEDIATYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "chfs_makefs.h"
|
||||
|
@ -83,9 +84,10 @@ buf_write(fsinfo_t *fsopts, const void *buf, size_t len)
|
|||
void
|
||||
padblock(fsinfo_t *fsopts)
|
||||
{
|
||||
while (img_ofs % chfs_opts.eraseblock) {
|
||||
chfs_opt_t *chfs_opts = fsopts->fs_specific;
|
||||
while (img_ofs % chfs_opts->eraseblock) {
|
||||
buf_write(fsopts, ffbuf, MIN(sizeof(ffbuf),
|
||||
chfs_opts.eraseblock - (img_ofs % chfs_opts.eraseblock)));
|
||||
chfs_opts->eraseblock - (img_ofs % chfs_opts->eraseblock)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,8 +102,9 @@ padword(fsinfo_t *fsopts)
|
|||
static void
|
||||
pad_block_if_less_than(fsinfo_t *fsopts, int req)
|
||||
{
|
||||
if ((img_ofs % chfs_opts.eraseblock) + req >
|
||||
(uint32_t)chfs_opts.eraseblock) {
|
||||
chfs_opt_t *chfs_opts = fsopts->fs_specific;
|
||||
if ((img_ofs % chfs_opts->eraseblock) + req >
|
||||
(uint32_t)chfs_opts->eraseblock) {
|
||||
padblock(fsopts);
|
||||
write_eb_header(fsopts);
|
||||
}
|
||||
|
@ -120,9 +123,7 @@ write_eb_header(fsinfo_t *fsopts)
|
|||
CHFS_EB_HDR_NAND_SIZE)
|
||||
if ((uint32_t)opts->pagesize < MINSIZE)
|
||||
errx(EXIT_FAILURE, "pagesize cannot be less than %zu", MINSIZE);
|
||||
if ((buf = malloc(opts->pagesize)) == NULL)
|
||||
err(EXIT_FAILURE, "Memory allocation failed");
|
||||
|
||||
buf = emalloc(opts->pagesize);
|
||||
memset(buf, 0xFF, opts->pagesize);
|
||||
|
||||
ebhdr.ec_hdr.magic = htole32(CHFS_MAGIC_BITMASK);
|
||||
|
@ -187,15 +188,12 @@ void
|
|||
write_dirent(fsinfo_t *fsopts, fsnode *node)
|
||||
{
|
||||
struct chfs_flash_dirent_node fdirent;
|
||||
char *name = malloc(sizeof(char) * strlen(node->name));
|
||||
char *name;
|
||||
|
||||
if (name == NULL) {
|
||||
err(EXIT_FAILURE, "ERROR memory allocation failed");
|
||||
}
|
||||
|
||||
memset(&fdirent, 0, sizeof(fdirent));
|
||||
name = emalloc(strlen(node->name));
|
||||
memcpy(name, node->name, strlen(node->name));
|
||||
|
||||
memset(&fdirent, 0, sizeof(fdirent));
|
||||
fdirent.magic = htole16(CHFS_FS_MAGIC_BITMASK);
|
||||
fdirent.type = htole16(CHFS_NODETYPE_DIRENT);
|
||||
fdirent.length = htole32(CHFS_PAD(sizeof(fdirent) + strlen(name)));
|
||||
|
@ -233,11 +231,7 @@ write_file(fsinfo_t *fsopts, fsnode *node, const char *dir)
|
|||
uint32_t fileofs = 0;
|
||||
|
||||
opts = fsopts->fs_specific;
|
||||
buf = malloc(opts->pagesize);
|
||||
|
||||
if (buf == NULL)
|
||||
goto out;
|
||||
|
||||
buf = emalloc(opts->pagesize);
|
||||
if (node->type == S_IFREG || node->type == S_IFSOCK) {
|
||||
char *longname;
|
||||
if (asprintf(&longname, "%s/%s", dir, name) == 1)
|
||||
|
|
|
@ -45,6 +45,4 @@ typedef struct {
|
|||
int mediatype; /* type of the media, 0 (nor) or 1 (nand) */
|
||||
} chfs_opt_t;
|
||||
|
||||
extern chfs_opt_t chfs_opts;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ffs.c,v 1.55 2013/01/27 20:05:46 christos Exp $ */
|
||||
/* $NetBSD: ffs.c,v 1.56 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -71,7 +71,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: ffs.c,v 1.55 2013/01/27 20:05:46 christos Exp $");
|
||||
__RCSID("$NetBSD: ffs.c,v 1.56 2013/01/28 21:03:27 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -88,6 +88,7 @@ __RCSID("$NetBSD: ffs.c,v 1.55 2013/01/27 20:05:46 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "ffs.h"
|
||||
|
@ -150,17 +151,42 @@ static void *ffs_build_dinode2(struct ufs2_dinode *, dirbuf_t *, fsnode *,
|
|||
|
||||
int sectorsize; /* XXX: for buf.c::getblk() */
|
||||
|
||||
/* publically visible functions */
|
||||
|
||||
static char optimization[24]; /* XXX: allocate */
|
||||
|
||||
/* publically visible functions */
|
||||
void
|
||||
ffs_prep_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
ffs_opt_t *ffs_opts;
|
||||
ffs_opt_t *ffs_opts = ecalloc(1, sizeof(*ffs_opts));
|
||||
|
||||
if ((ffs_opts = calloc(1, sizeof(ffs_opt_t))) == NULL)
|
||||
err(1, "Allocating memory for ffs_options");
|
||||
|
||||
fsopts->fs_specific = ffs_opts;
|
||||
const option_t ffs_options[] = {
|
||||
{ 'b', "bsize", &ffs_opts->bsize, OPT_INT32,
|
||||
1, INT_MAX, "block size" },
|
||||
{ 'f', "fsize", &ffs_opts->fsize, OPT_INT32,
|
||||
1, INT_MAX, "fragment size" },
|
||||
{ 'd', "density", &ffs_opts->density, OPT_INT32,
|
||||
1, INT_MAX, "bytes per inode" },
|
||||
{ 'm', "minfree", &ffs_opts->minfree, OPT_INT32,
|
||||
0, 99, "minfree" },
|
||||
{ 'M', "maxbpf", &ffs_opts->maxbpg, OPT_INT32,
|
||||
1, INT_MAX, "max blocks per file in a cg" },
|
||||
{ 'a', "avgfilesize", &ffs_opts->avgfilesize, OPT_INT32,
|
||||
1, INT_MAX, "expected average file size" },
|
||||
{ 'n', "avgfpdir", &ffs_opts->avgfpdir, OPT_INT32,
|
||||
1, INT_MAX, "expected # of files per directory" },
|
||||
{ 'x', "extent", &ffs_opts->maxbsize, OPT_INT32,
|
||||
1, INT_MAX, "maximum # extent size" },
|
||||
{ 'g', "maxbpcg", &ffs_opts->maxblkspercg, OPT_INT32,
|
||||
1, INT_MAX, "max # of blocks per group" },
|
||||
{ 'v', "version", &ffs_opts->version, OPT_INT32,
|
||||
1, 2, "UFS version" },
|
||||
{ 'o', "optimization", optimization, OPT_STRARRAY,
|
||||
1, sizeof(optimization), "Optimization (time|space)" },
|
||||
{ 'l', "label", ffs_opts->label, OPT_STRARRAY,
|
||||
1, sizeof(ffs_opts->label), "UFS label" },
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
ffs_opts->bsize= -1;
|
||||
ffs_opts->fsize= -1;
|
||||
|
@ -173,48 +199,23 @@ ffs_prep_opts(fsinfo_t *fsopts)
|
|||
ffs_opts->avgfilesize= -1;
|
||||
ffs_opts->avgfpdir= -1;
|
||||
ffs_opts->version = 1;
|
||||
|
||||
fsopts->fs_specific = ffs_opts;
|
||||
fsopts->fs_options = copy_opts(ffs_options);
|
||||
}
|
||||
|
||||
void
|
||||
ffs_cleanup_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
if (fsopts->fs_specific)
|
||||
free(fsopts->fs_specific);
|
||||
free(fsopts->fs_specific);
|
||||
free(fsopts->fs_options);
|
||||
}
|
||||
|
||||
int
|
||||
ffs_parse_opts(const char *option, fsinfo_t *fsopts)
|
||||
{
|
||||
ffs_opt_t *ffs_opts = fsopts->fs_specific;
|
||||
char optimization[24];
|
||||
|
||||
option_t ffs_options[] = {
|
||||
{ '\0', "bsize", &ffs_opts->bsize, OPT_INT32,
|
||||
1, INT_MAX, "block size" },
|
||||
{ '\0', "fsize", &ffs_opts->fsize, OPT_INT32,
|
||||
1, INT_MAX, "fragment size" },
|
||||
{ '\0', "density", &ffs_opts->density, OPT_INT32,
|
||||
1, INT_MAX, "bytes per inode" },
|
||||
{ '\0', "minfree", &ffs_opts->minfree, OPT_INT32,
|
||||
0, 99, "minfree" },
|
||||
{ '\0', "maxbpf", &ffs_opts->maxbpg, OPT_INT32,
|
||||
1, INT_MAX, "max blocks per file in a cg" },
|
||||
{ '\0', "avgfilesize", &ffs_opts->avgfilesize, OPT_INT32,
|
||||
1, INT_MAX, "expected average file size" },
|
||||
{ '\0', "avgfpdir", &ffs_opts->avgfpdir, OPT_INT32,
|
||||
1, INT_MAX, "expected # of files per directory" },
|
||||
{ '\0', "extent", &ffs_opts->maxbsize, OPT_INT32,
|
||||
1, INT_MAX, "maximum # extent size" },
|
||||
{ '\0', "maxbpcg", &ffs_opts->maxblkspercg, OPT_INT32,
|
||||
1, INT_MAX, "max # of blocks per group" },
|
||||
{ '\0', "version", &ffs_opts->version, OPT_INT32,
|
||||
1, 2, "UFS version" },
|
||||
{ '\0', "optimization", optimization, OPT_STRARRAY,
|
||||
1, sizeof(optimization), "Optimization (time|space)" },
|
||||
{ '\0', "label", ffs_opts->label, OPT_STRARRAY,
|
||||
1, sizeof(ffs_opts->label), "UFS label" },
|
||||
{ .name = NULL }
|
||||
};
|
||||
option_t *ffs_options = fsopts->fs_options;
|
||||
|
||||
int rv;
|
||||
|
||||
|
@ -505,10 +506,8 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
|
|||
printf(
|
||||
"zero-ing image `%s', %lld sectors, using %d byte chunks\n",
|
||||
image, (long long)bufrem, bufsize);
|
||||
if ((bufrem > 0) && ((buf = calloc(1, bufsize)) == NULL)) {
|
||||
warn("Can't create buffer for sector");
|
||||
return (-1);
|
||||
}
|
||||
if (bufrem > 0)
|
||||
buf = ecalloc(1, bufsize);
|
||||
while (bufrem > 0) {
|
||||
i = write(fsopts->fd, buf, MIN(bufsize, bufrem));
|
||||
if (i == -1) {
|
||||
|
@ -894,8 +893,7 @@ ffs_write_file(union dinode *din, uint32_t ino, void *buf, fsinfo_t *fsopts)
|
|||
goto write_inode_and_leave; /* mmm, cheating */
|
||||
|
||||
if (isfile) {
|
||||
if ((fbuf = malloc(ffs_opts->bsize)) == NULL)
|
||||
err(1, "Allocating memory for write buffer");
|
||||
fbuf = emalloc(ffs_opts->bsize);
|
||||
if ((ffd = open((char *)buf, O_RDONLY, 0444)) == -1) {
|
||||
warn("Can't open `%s' for reading", (char *)buf);
|
||||
goto leave_ffs_write_file;
|
||||
|
@ -1021,8 +1019,7 @@ ffs_make_dirbuf(dirbuf_t *dbuf, const char *name, fsnode *node, int needswap)
|
|||
if (debug & DEBUG_FS_MAKE_DIRBUF)
|
||||
printf("ffs_make_dirbuf: growing buf to %d\n",
|
||||
dbuf->size + DIRBLKSIZ);
|
||||
if ((newbuf = realloc(dbuf->buf, dbuf->size + DIRBLKSIZ)) == NULL)
|
||||
err(1, "Allocating memory for directory buffer");
|
||||
newbuf = erealloc(dbuf->buf, dbuf->size + DIRBLKSIZ);
|
||||
dbuf->buf = newbuf;
|
||||
dbuf->size += DIRBLKSIZ;
|
||||
memset(dbuf->buf + dbuf->size - DIRBLKSIZ, 0, DIRBLKSIZ);
|
||||
|
@ -1073,10 +1070,7 @@ ffs_write_inode(union dinode *dp, uint32_t ino, const fsinfo_t *fsopts)
|
|||
|
||||
assert (isclr(cg_inosused(cgp, fsopts->needswap), cgino));
|
||||
|
||||
buf = malloc(fs->fs_bsize);
|
||||
if (buf == NULL)
|
||||
errx(1, "ffs_write_inode: cg %d: can't alloc inode block", cg);
|
||||
|
||||
buf = emalloc(fs->fs_bsize);
|
||||
dp1 = (struct ufs1_dinode *)buf;
|
||||
dp2 = (struct ufs2_dinode *)buf;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: buf.c,v 1.16 2013/01/28 10:16:35 mlelstv Exp $ */
|
||||
/* $NetBSD: buf.c,v 1.17 2013/01/28 21:03:29 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: buf.c,v 1.16 2013/01/28 10:16:35 mlelstv Exp $");
|
||||
__RCSID("$NetBSD: buf.c,v 1.17 2013/01/28 21:03:29 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -52,6 +52,7 @@ __RCSID("$NetBSD: buf.c,v 1.16 2013/01/28 10:16:35 mlelstv Exp $");
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
|
||||
|
@ -210,9 +211,7 @@ getblk(struct vnode *vp, daddr_t blkno, int size, int u1 __unused,
|
|||
}
|
||||
}
|
||||
if (bp == NULL) {
|
||||
if ((bp = calloc(1, sizeof(struct buf))) == NULL)
|
||||
err(1, "getblk: calloc");
|
||||
|
||||
bp = ecalloc(1, sizeof(*bp));
|
||||
bp->b_bufsize = 0;
|
||||
bp->b_blkno = bp->b_lblkno = blkno;
|
||||
bp->b_fd = fd;
|
||||
|
@ -222,9 +221,7 @@ getblk(struct vnode *vp, daddr_t blkno, int size, int u1 __unused,
|
|||
}
|
||||
bp->b_bcount = size;
|
||||
if (bp->b_data == NULL || bp->b_bcount > bp->b_bufsize) {
|
||||
n = realloc(bp->b_data, size);
|
||||
if (n == NULL)
|
||||
err(1, "getblk: realloc b_data %ld", bp->b_bcount);
|
||||
n = erealloc(bp->b_data, size);
|
||||
memset(n, 0, size);
|
||||
bp->b_data = n;
|
||||
bp->b_bufsize = size;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: buf.h,v 1.6 2013/01/27 20:05:46 christos Exp $ */
|
||||
/* $NetBSD: buf.h,v 1.7 2013/01/28 21:03:29 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -98,7 +98,7 @@ struct pool {
|
|||
};
|
||||
|
||||
#define pool_init(p, s, a1, a2, a3, a4, a5, a6) (p)->size = (s)
|
||||
#define pool_get(p, f) calloc(1, (p)->size)
|
||||
#define pool_get(p, f) ecalloc(1, (p)->size)
|
||||
#define pool_put(p, a) free(a)
|
||||
#define pool_destroy(p)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mkfs.c,v 1.25 2013/01/22 09:39:19 dholland Exp $ */
|
||||
/* $NetBSD: mkfs.c,v 1.26 2013/01/28 21:03:29 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
||||
|
@ -48,7 +48,7 @@
|
|||
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
|
||||
#else
|
||||
#ifdef __RCSID
|
||||
__RCSID("$NetBSD: mkfs.c,v 1.25 2013/01/22 09:39:19 dholland Exp $");
|
||||
__RCSID("$NetBSD: mkfs.c,v 1.26 2013/01/28 21:03:29 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
@ -62,6 +62,7 @@ __RCSID("$NetBSD: mkfs.c,v 1.25 2013/01/22 09:39:19 dholland Exp $");
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "ffs.h"
|
||||
|
@ -415,8 +416,7 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts)
|
|||
blks = howmany(size, sblock.fs_fsize);
|
||||
if (sblock.fs_contigsumsize > 0)
|
||||
size += sblock.fs_ncg * sizeof(int32_t);
|
||||
if ((space = (char *)calloc(1, size)) == NULL)
|
||||
err(1, "memory allocation error for cg summaries");
|
||||
space = ecalloc(1, size);
|
||||
sblock.fs_csp = space;
|
||||
space = (char *)space + sblock.fs_cssize;
|
||||
if (sblock.fs_contigsumsize > 0) {
|
||||
|
@ -504,11 +504,7 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts)
|
|||
iobufsize = SBLOCKSIZE + 3 * sblock.fs_bsize;
|
||||
else
|
||||
iobufsize = 4 * sblock.fs_bsize;
|
||||
if ((iobuf = malloc(iobufsize)) == 0) {
|
||||
printf("Cannot allocate I/O buffer\n");
|
||||
exit(38);
|
||||
}
|
||||
memset(iobuf, 0, iobufsize);
|
||||
iobuf = ecalloc(1, iobufsize);
|
||||
/*
|
||||
* Make a copy of the superblock into the buffer that we will be
|
||||
* writing out in each cylinder group.
|
||||
|
@ -574,8 +570,7 @@ ffs_write_superblock(struct fs *fs, const fsinfo_t *fsopts)
|
|||
size = fs->fs_cssize;
|
||||
blks = howmany(size, fs->fs_fsize);
|
||||
space = (void *)fs->fs_csp;
|
||||
if ((wrbuf = malloc(size)) == NULL)
|
||||
err(1, "ffs_write_superblock: malloc %d", size);
|
||||
wrbuf = emalloc(size);
|
||||
for (i = 0; i < blks; i+= fs->fs_frag) {
|
||||
size = fs->fs_bsize;
|
||||
if (i + fs->fs_frag > blks)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: makefs.c,v 1.40 2013/01/27 14:07:12 christos Exp $ */
|
||||
/* $NetBSD: makefs.c,v 1.41 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Wasabi Systems, Inc.
|
||||
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: makefs.c,v 1.40 2013/01/27 14:07:12 christos Exp $");
|
||||
__RCSID("$NetBSD: makefs.c,v 1.41 2013/01/28 21:03:27 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -53,6 +53,7 @@ __RCSID("$NetBSD: makefs.c,v 1.40 2013/01/27 14:07:12 christos Exp $");
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "mtree.h"
|
||||
|
@ -87,7 +88,7 @@ u_int debug;
|
|||
struct timespec start_time;
|
||||
|
||||
static fstype_t *get_fstype(const char *);
|
||||
static void usage(void) __dead;
|
||||
static void usage(fstype_t *, fsinfo_t *) __dead;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
|
@ -138,7 +139,7 @@ main(int argc, char *argv[])
|
|||
#endif
|
||||
} else {
|
||||
warnx("Invalid endian `%s'.", optarg);
|
||||
usage();
|
||||
usage(fstype, &fsoptions);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -203,7 +204,7 @@ main(int argc, char *argv[])
|
|||
if (*p == '\0')
|
||||
errx(1, "Empty option");
|
||||
if (! fstype->parse_options(p, &fsoptions))
|
||||
usage();
|
||||
usage(fstype, &fsoptions);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -239,7 +240,7 @@ main(int argc, char *argv[])
|
|||
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
usage(fstype, &fsoptions);
|
||||
/* NOTREACHED */
|
||||
|
||||
}
|
||||
|
@ -254,7 +255,7 @@ main(int argc, char *argv[])
|
|||
argv += optind;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
usage(fstype, &fsoptions);
|
||||
|
||||
/* -x must be accompanied by -F */
|
||||
if (fsoptions.onlyspec != 0 && specfile == NULL)
|
||||
|
@ -308,9 +309,7 @@ set_option(const option_t *options, const char *option)
|
|||
|
||||
assert(option != NULL);
|
||||
|
||||
if ((var = strdup(option)) == NULL) {
|
||||
err(EXIT_FAILURE, "Allocating memory for copy of option string");
|
||||
}
|
||||
var = estrdup(option);
|
||||
retval = -1;
|
||||
if ((val = strchr(var, '=')) == NULL) {
|
||||
warnx("Option `%s' doesn't contain a value", var);
|
||||
|
@ -350,7 +349,7 @@ set_option_var(const option_t *options, const char *var, const char *val)
|
|||
options[i].maximum);
|
||||
break;
|
||||
case OPT_STRPTR:
|
||||
if ((s = strdup(val)) == NULL)
|
||||
s = estrdup(val);
|
||||
err(1, NULL);
|
||||
*(char **)options[i].value = s;
|
||||
break;
|
||||
|
@ -386,17 +385,37 @@ get_fstype(const char *type)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
option_t *
|
||||
copy_opts(const option_t *o)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; o[i].name; i++)
|
||||
continue;
|
||||
i++;
|
||||
return memcpy(ecalloc(i, sizeof(*o)), o, i * sizeof(*o));
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
usage(fstype_t *fstype, fsinfo_t *fsoptions)
|
||||
{
|
||||
const char *prog;
|
||||
|
||||
prog = getprogname();
|
||||
fprintf(stderr,
|
||||
"usage: %s [-xZ] [-B endian] [-b free-blocks] [-d debug-mask]\n"
|
||||
"Usage: %s [-xZ] [-B endian] [-b free-blocks] [-d debug-mask]\n"
|
||||
"\t[-F mtree-specfile] [-f free-files] [-M minimum-size]\n"
|
||||
"\t[-m maximum-size] [-N userdb-dir] [-o fs-options] [-S sector-size]\n"
|
||||
"\t[-s image-size] [-t fs-type] image-file directory [extra-directory ...]\n",
|
||||
prog);
|
||||
|
||||
if (fstype) {
|
||||
size_t i;
|
||||
option_t *o = fsoptions->fs_options;
|
||||
|
||||
fprintf(stderr, "\n%s specific options:\n", fstype->type);
|
||||
for (i = 0; o[i].name != NULL; i++)
|
||||
fprintf(stderr, "\t%c,%20.20s\t%s\n", o[i].letter,
|
||||
o[i].name, o[i].desc);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: makefs.h,v 1.29 2013/01/23 21:32:32 christos Exp $ */
|
||||
/* $NetBSD: makefs.h,v 1.30 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -110,6 +110,31 @@ typedef struct _fsnode {
|
|||
|
||||
#define FSNODE_F_HASSPEC 0x01 /* fsnode has a spec entry */
|
||||
|
||||
/*
|
||||
* option_t - contains option name, description, pointer to location to store
|
||||
* result, and range checks for the result. Used to simplify fs specific
|
||||
* option setting
|
||||
*/
|
||||
typedef enum {
|
||||
OPT_STRARRAY,
|
||||
OPT_STRPTR,
|
||||
OPT_BOOL,
|
||||
OPT_INT8,
|
||||
OPT_INT16,
|
||||
OPT_INT32,
|
||||
OPT_INT64
|
||||
} opttype_t;
|
||||
|
||||
typedef struct {
|
||||
char letter; /* option letter NUL for none */
|
||||
const char *name; /* option name */
|
||||
void *value; /* where to stuff the value */
|
||||
opttype_t type; /* type of entry */
|
||||
long long minimum; /* minimum for value */
|
||||
long long maximum; /* maximum for value */
|
||||
const char *desc; /* option description */
|
||||
} option_t;
|
||||
|
||||
/*
|
||||
* fsinfo_t - contains various settings and parameters pertaining to
|
||||
* the image, including current settings, global options, and fs
|
||||
|
@ -139,33 +164,10 @@ typedef struct {
|
|||
int sparse; /* sparse image, don't fill it with zeros */
|
||||
|
||||
void *fs_specific; /* File system specific additions. */
|
||||
option_t *fs_options; /* File system specific options */
|
||||
} fsinfo_t;
|
||||
|
||||
|
||||
/*
|
||||
* option_t - contains option name, description, pointer to location to store
|
||||
* result, and range checks for the result. Used to simplify fs specific
|
||||
* option setting
|
||||
*/
|
||||
typedef enum {
|
||||
OPT_STRARRAY,
|
||||
OPT_STRPTR,
|
||||
OPT_BOOL,
|
||||
OPT_INT8,
|
||||
OPT_INT16,
|
||||
OPT_INT32,
|
||||
OPT_INT64
|
||||
} opttype_t;
|
||||
|
||||
typedef struct {
|
||||
char letter; /* option letter NUL for none */
|
||||
const char *name; /* option name */
|
||||
void *value; /* where to stuff the value */
|
||||
opttype_t type; /* type of entry */
|
||||
long long minimum; /* minimum for value */
|
||||
long long maximum; /* maximum for value */
|
||||
const char *desc; /* option description */
|
||||
} option_t;
|
||||
|
||||
|
||||
void apply_specfile(const char *, const char *, fsnode *, int);
|
||||
|
@ -175,6 +177,7 @@ int set_option(const option_t *, const char *);
|
|||
int set_option_var(const option_t *, const char *, const char *);
|
||||
fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *);
|
||||
void free_fsnodes(fsnode *);
|
||||
option_t * copy_opts(const option_t *);
|
||||
|
||||
#define DECLARE_FUN(fs) \
|
||||
void fs ## _prep_opts(fsinfo_t *); \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msdos.c,v 1.9 2013/01/27 22:53:03 christos Exp $ */
|
||||
/* $NetBSD: msdos.c,v 1.10 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2013 The NetBSD Foundation, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: msdos.c,v 1.9 2013/01/27 22:53:03 christos Exp $");
|
||||
__RCSID("$NetBSD: msdos.c,v 1.10 2013/01/28 21:03:27 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
@ -55,6 +55,7 @@ __RCSID("$NetBSD: msdos.c,v 1.9 2013/01/27 22:53:03 christos Exp $");
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <ffs/buf.h>
|
||||
#include <fs/msdosfs/denode.h>
|
||||
|
@ -70,27 +71,8 @@ static int msdos_populate_dir(const char *, struct denode *, fsnode *,
|
|||
void
|
||||
msdos_prep_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
struct msdos_options *msdos_opts;
|
||||
|
||||
if ((msdos_opts = calloc(1, sizeof(*msdos_opts))) == NULL)
|
||||
err(1, "Allocating memory for msdos_options");
|
||||
|
||||
fsopts->fs_specific = msdos_opts;
|
||||
}
|
||||
|
||||
void
|
||||
msdos_cleanup_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
if (fsopts->fs_specific)
|
||||
free(fsopts->fs_specific);
|
||||
}
|
||||
|
||||
int
|
||||
msdos_parse_opts(const char *option, fsinfo_t *fsopts)
|
||||
{
|
||||
struct msdos_options *msdos_opt = fsopts->fs_specific;
|
||||
|
||||
option_t msdos_options[] = {
|
||||
struct msdos_options *msdos_opt = ecalloc(1, sizeof(*msdos_opt));
|
||||
const option_t msdos_options[] = {
|
||||
#define AOPT(_opt, _type, _name, _min, _desc) { \
|
||||
.letter = _opt, \
|
||||
.name = # _name, \
|
||||
|
@ -110,6 +92,24 @@ ALLOPTS
|
|||
#undef AOPT
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
fsopts->fs_specific = msdos_opt;
|
||||
fsopts->fs_options = copy_opts(msdos_options);
|
||||
}
|
||||
|
||||
void
|
||||
msdos_cleanup_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
free(fsopts->fs_specific);
|
||||
free(fsopts->fs_options);
|
||||
}
|
||||
|
||||
int
|
||||
msdos_parse_opts(const char *option, fsinfo_t *fsopts)
|
||||
{
|
||||
struct msdos_options *msdos_opt = fsopts->fs_specific;
|
||||
option_t *msdos_options = fsopts->fs_options;
|
||||
|
||||
int rv;
|
||||
|
||||
assert(option != NULL);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msdosfs_denode.c,v 1.4 2013/01/28 00:16:24 christos Exp $ */
|
||||
/* $NetBSD: msdosfs_denode.c,v 1.5 2013/01/28 21:03:29 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
|
||||
|
@ -52,7 +52,7 @@
|
|||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.4 2013/01/28 00:16:24 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.5 2013/01/28 21:03:29 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
|
@ -64,6 +64,8 @@ __KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.4 2013/01/28 00:16:24 christos
|
|||
#include <fs/msdosfs/denode.h>
|
||||
#include <fs/msdosfs/fat.h>
|
||||
|
||||
#include <util.h>
|
||||
|
||||
/*
|
||||
* If deget() succeeds it returns with the gotten denode locked().
|
||||
*
|
||||
|
@ -77,7 +79,8 @@ __KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.4 2013/01/28 00:16:24 christos
|
|||
* depp - returns the address of the gotten denode.
|
||||
*/
|
||||
int
|
||||
deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset, struct denode **depp)
|
||||
deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset,
|
||||
struct denode **depp)
|
||||
/* pmp: so we know the maj/min number */
|
||||
/* dirclust: cluster this dir entry came from */
|
||||
/* diroffset: index of entry within the cluster */
|
||||
|
@ -100,9 +103,7 @@ deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset, struct denode
|
|||
if (FAT32(pmp) && dirclust == MSDOSFSROOT)
|
||||
dirclust = pmp->pm_rootdirblk;
|
||||
|
||||
ldep = calloc(1, sizeof(*ldep));
|
||||
if (ldep == NULL)
|
||||
err(1, "calloc");
|
||||
ldep = ecalloc(1, sizeof(*ldep));
|
||||
ldep->de_vnode = NULL;
|
||||
ldep->de_flag = 0;
|
||||
ldep->de_devvp = 0;
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.5 2013/01/27 20:05:46 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.6 2013/01/28 21:03:29 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
|
@ -67,6 +67,7 @@ __KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.5 2013/01/27 20:05:46 christos
|
|||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "msdos.h"
|
||||
|
@ -116,10 +117,7 @@ msdosfs_mount(struct vnode *devvp, int flags)
|
|||
} else
|
||||
bsize = 512;
|
||||
|
||||
pmp = calloc(1, sizeof *pmp);
|
||||
if (pmp == NULL)
|
||||
goto error_exit;
|
||||
|
||||
pmp = ecalloc(1, sizeof *pmp);
|
||||
/*
|
||||
* Compute several useful quantities from the bpb in the
|
||||
* bootsector. Copy in the dos 5 variant of the bpb then fix up
|
||||
|
@ -366,11 +364,8 @@ msdosfs_mount(struct vnode *devvp, int flags)
|
|||
* Allocate memory for the bitmap of allocated clusters, and then
|
||||
* fill it in.
|
||||
*/
|
||||
pmp->pm_inusemap = calloc(sizeof(*pmp->pm_inusemap),
|
||||
pmp->pm_inusemap = ecalloc(sizeof(*pmp->pm_inusemap),
|
||||
((pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS));
|
||||
if (pmp->pm_inusemap == NULL)
|
||||
goto error_exit;
|
||||
|
||||
/*
|
||||
* fillinusemap() needs pm_devvp.
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: v7fs.c,v 1.6 2013/01/24 01:10:47 christos Exp $ */
|
||||
/* $NetBSD: v7fs.c,v 1.7 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: v7fs.c,v 1.6 2013/01/24 01:10:47 christos Exp $");
|
||||
__RCSID("$NetBSD: v7fs.c,v 1.7 2013/01/28 21:03:27 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -43,6 +43,7 @@ __RCSID("$NetBSD: v7fs.c,v 1.6 2013/01/24 01:10:47 christos Exp $");
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "v7fs.h"
|
||||
|
@ -50,7 +51,6 @@ __RCSID("$NetBSD: v7fs.c,v 1.6 2013/01/24 01:10:47 christos Exp $");
|
|||
#include "v7fs_makefs.h"
|
||||
#include "newfs_v7fs.h"
|
||||
|
||||
static v7fs_opt_t v7fs_opts;
|
||||
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
#include "progress.h"
|
||||
|
@ -61,28 +61,31 @@ int v7fs_newfs_verbose;
|
|||
void
|
||||
v7fs_prep_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
v7fs_opt_t *v7fs_opts = ecalloc(1, sizeof(*v7fs_opts));
|
||||
const option_t v7fs_options[] = {
|
||||
{ 'p', "pdp", &v7fs_opts->pdp_endian, OPT_INT32, false, true,
|
||||
"PDP endian" },
|
||||
{ 'P', "progress", &v7fs_opts->progress, OPT_INT32, false, true,
|
||||
"Progress bar" },
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
fsopts->fs_specific = &v7fs_opts;
|
||||
fsopts->fs_specific = v7fs_opts;
|
||||
fsopts->fs_options = copy_opts(v7fs_options);
|
||||
}
|
||||
|
||||
void
|
||||
v7fs_cleanup_opts(fsinfo_t *fsopts)
|
||||
{
|
||||
/*NO-OP*/
|
||||
free(fsopts->fs_specific);
|
||||
free(fsopts->fs_options);
|
||||
}
|
||||
|
||||
int
|
||||
v7fs_parse_opts(const char *option, fsinfo_t *fsopts)
|
||||
{
|
||||
static option_t v7fs_options[] = {
|
||||
{ '\0', "pdp", &v7fs_opts.pdp_endian, OPT_INT32, false, true,
|
||||
"PDP endian" },
|
||||
{ '\0', "progress", &v7fs_opts.progress, OPT_INT32, false, true,
|
||||
"Progress bar" },
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
return set_option_var(v7fs_options, option, "1") != -1;
|
||||
return set_option_var(fsopts->fs_options, option, "1") != -1;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -90,10 +93,11 @@ v7fs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts)
|
|||
{
|
||||
struct v7fs_mount_device v7fs_mount;
|
||||
int fd, endian, error = 1;
|
||||
v7fs_opt_t *v7fs_opts = fsopts->fs_specific;
|
||||
|
||||
v7fs_newfs_verbose = debug;
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
if ((progress_bar_enable = v7fs_opts.progress)) {
|
||||
if ((progress_bar_enable = v7fs_opts->progress)) {
|
||||
progress_switch(progress_bar_enable);
|
||||
progress_init();
|
||||
progress(&(struct progress_arg){ .cdev = image });
|
||||
|
@ -134,7 +138,7 @@ v7fs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts)
|
|||
else
|
||||
endian = BIG_ENDIAN;
|
||||
#endif
|
||||
if (v7fs_opts.pdp_endian) {
|
||||
if (v7fs_opts->pdp_endian) {
|
||||
endian = PDP_ENDIAN;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: walk.c,v 1.26 2012/04/19 17:28:25 christos Exp $ */
|
||||
/* $NetBSD: walk.c,v 1.27 2013/01/28 21:03:27 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -41,10 +41,11 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(__lint)
|
||||
__RCSID("$NetBSD: walk.c,v 1.26 2012/04/19 17:28:25 christos Exp $");
|
||||
__RCSID("$NetBSD: walk.c,v 1.27 2013/01/28 21:03:27 christos Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
@ -54,7 +55,7 @@ __RCSID("$NetBSD: walk.c,v 1.26 2012/04/19 17:28:25 christos Exp $");
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "makefs.h"
|
||||
#include "mtree.h"
|
||||
|
@ -205,8 +206,7 @@ walk_dir(const char *root, const char *dir, fsnode *parent, fsnode *join)
|
|||
if (llen == -1)
|
||||
err(1, "Readlink `%s'", path);
|
||||
slink[llen] = '\0';
|
||||
if ((cur->symlink = strdup(slink)) == NULL)
|
||||
err(1, "Memory allocation error");
|
||||
cur->symlink = estrdup(slink);
|
||||
}
|
||||
}
|
||||
assert(first != NULL);
|
||||
|
@ -224,11 +224,10 @@ create_fsnode(const char *root, const char *path, const char *name,
|
|||
{
|
||||
fsnode *cur;
|
||||
|
||||
if ((cur = calloc(1, sizeof(fsnode))) == NULL ||
|
||||
(cur->path = strdup(path)) == NULL ||
|
||||
(cur->name = strdup(name)) == NULL ||
|
||||
(cur->inode = calloc(1, sizeof(fsinode))) == NULL)
|
||||
err(1, "Memory allocation error");
|
||||
cur = ecalloc(1, sizeof(*cur));
|
||||
cur->path = estrdup(path);
|
||||
cur->name = estrdup(name);
|
||||
cur->inode = ecalloc(1, sizeof(*cur->inode));
|
||||
cur->root = root;
|
||||
cur->type = stbuf->st_mode & S_IFMT;
|
||||
cur->inode->nlink = 1;
|
||||
|
@ -446,9 +445,7 @@ apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode, int speconly)
|
|||
if (curfsnode->type == S_IFLNK) {
|
||||
assert(curnode->slink != NULL);
|
||||
/* for symlinks, copy the target */
|
||||
if ((curfsnode->symlink =
|
||||
strdup(curnode->slink)) == NULL)
|
||||
err(1, "Memory allocation error");
|
||||
curfsnode->symlink = estrdup(curnode->slink);
|
||||
}
|
||||
}
|
||||
apply_specentry(dir, curnode, curfsnode);
|
||||
|
@ -504,8 +501,7 @@ apply_specentry(const char *dir, NODE *specnode, fsnode *dirnode)
|
|||
assert(specnode->slink != NULL);
|
||||
ASEPRINT("symlink", "%s", dirnode->symlink, specnode->slink);
|
||||
free(dirnode->symlink);
|
||||
if ((dirnode->symlink = strdup(specnode->slink)) == NULL)
|
||||
err(1, "Memory allocation error");
|
||||
dirnode->symlink = estrdup(specnode->slink);
|
||||
}
|
||||
if (specnode->flags & F_TIME) {
|
||||
ASEPRINT("time", "%ld",
|
||||
|
@ -640,10 +636,7 @@ link_check(fsinode *entry)
|
|||
htused = 0;
|
||||
|
||||
ohtable = htable;
|
||||
htable = calloc(htmask+1, sizeof(*htable));
|
||||
if (!htable)
|
||||
err(1, "Memory allocation error");
|
||||
|
||||
htable = ecalloc(htmask+1, sizeof(*htable));
|
||||
/* populate newly allocated hashtable */
|
||||
if (ohtable) {
|
||||
int i;
|
||||
|
|
Loading…
Reference in New Issue