#ifndef ELTORITO_H_
#define ELTORITO_H_

#include "tree.h"
#include "file.h"
#include "ecma119.h"

struct el_torito_boot_catalog {
	struct iso_tree_node_boot *node; /* node of the catalog */
	struct el_torito_boot_image *image; /* default boot image */
	enum tree_node_from proc; /* whether the catalog is new or read from a 
	                           * prev session/image */
};

struct el_torito_boot_image {
	struct iso_tree_node_boot *node;

	unsigned int bootable:1; /**< If the entry is bootable. */
	unsigned int isolinux:1; /**< If the image will be patched */
	unsigned char type; /**< The type of image */
	unsigned char partition_type; /**< type of partition for HD-emul images */
	short load_seg; /**< Load segment for the initial boot image. */
	short load_size; /**< Number of sector to load. */
};

struct el_torito_validation_entry {
	uint8_t header_id			BP(1, 1);
	uint8_t platform_id			BP(2, 2);
	uint8_t reserved			BP(3, 4);
	uint8_t id_string			BP(5, 28);
	uint8_t checksum			BP(29, 30);
	uint8_t key_byte1			BP(31, 31);
	uint8_t key_byte2			BP(32, 32);
};

struct el_torito_default_entry {
	uint8_t boot_indicator		BP(1, 1);
	uint8_t boot_media_type		BP(2, 2);
	uint8_t load_seg			BP(3, 4);
	uint8_t system_type			BP(5, 5);
	uint8_t unused1				BP(6, 6);
	uint8_t sec_count			BP(7, 8);
	uint8_t block				BP(9, 12);
	uint8_t unused2				BP(13, 32);
};

struct el_torito_section_header_entry {
	uint8_t header_indicator	BP(1, 1);
	uint8_t platform_id			BP(2, 2);
	uint8_t number				BP(3, 4);
	uint8_t character			BP(5, 32);
};

struct el_torito_section_entry {
	uint8_t boot_indicator		BP(1, 1);
	uint8_t boot_media_type		BP(2, 2);
	uint8_t load_seg			BP(3, 4);
	uint8_t system_type			BP(5, 5);
	uint8_t unused1				BP(6, 6);
	uint8_t sec_count			BP(7, 8);
	uint8_t block				BP(9, 12);
	uint8_t selec_criteria		BP(13, 13);
	uint8_t vendor_sc			BP(14, 32);
};

void el_torito_boot_catalog_free(struct el_torito_boot_catalog *cat);

/**
 * Write the Boot Record Volume Descriptor
 */
void
el_torito_write_boot_vol_desc(struct ecma119_write_target *t, uint8_t *buf);

void
el_torito_wr_boot_vol_desc(struct ecma119_write_target *t, uint8_t *buf);

/**
 * Write catalog + image
 */
void
el_torito_wr_catalog(struct ecma119_write_target *t, uint8_t *buf);

#endif /*ELTORITO_H_*/
