189857Sobrien/* $NetBSD: udf_create.h,v 1.2 2008/07/26 20:20:56 reinoud Exp $ */ 289857Sobrien 3218822Sdim/* 489857Sobrien * Copyright (c) 2006, 2008 Reinoud Zandijk 589857Sobrien * All rights reserved. 689857Sobrien * 789857Sobrien * Redistribution and use in source and binary forms, with or without 889857Sobrien * modification, are permitted provided that the following conditions 989857Sobrien * are met: 1089857Sobrien * 1. Redistributions of source code must retain the above copyright 1189857Sobrien * notice, this list of conditions and the following disclaimer. 1289857Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1389857Sobrien * notice, this list of conditions and the following disclaimer in the 1489857Sobrien * documentation and/or other materials provided with the distribution. 1589857Sobrien * 1689857Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17218822Sdim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1889857Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1989857Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2089857Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2189857Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2289857Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2389857Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2489857Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2589857Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2689857Sobrien * 2789857Sobrien */ 2889857Sobrien 2989857Sobrien#ifndef _FS_UDF_UDF_CREATE_H_ 3089857Sobrien#define _FS_UDF_UDF_CREATE_H_ 3189857Sobrien 3289857Sobrien#include <sys/types.h> 3389857Sobrien#include <fs/udf/ecma167-udf.h> 3489857Sobrien#include "udf_bswap.h" 3589857Sobrien#include "udf_osta.h" 3689857Sobrien 3789857Sobrien 3889857Sobrien/* format flags indicating properties of disc to create */ 3989857Sobrien#define FORMAT_WRITEONCE 0x00001 4089857Sobrien#define FORMAT_SEQUENTIAL 0x00002 4189857Sobrien#define FORMAT_REWRITABLE 0x00004 4289857Sobrien#define FORMAT_SPARABLE 0x00008 4389857Sobrien#define FORMAT_META 0x00010 4489857Sobrien#define FORMAT_LOW 0x00020 4589857Sobrien#define FORMAT_VAT 0x00040 4689857Sobrien#define FORMAT_WORM 0x00080 4789857Sobrien#define FORMAT_TRACK512 0x00100 4889857Sobrien#define FORMAT_INVALID 0x00200 4989857Sobrien#define FORMAT_FLAGBITS \ 5089857Sobrien "\10\1WRITEONCE\2SEQUENTIAL\3REWRITABLE\4SPARABLE\5META\6LOW" \ 5189857Sobrien "\7VAT\10WORM\11TRACK512\12INVALID" 5289857Sobrien 53218822Sdim 5489857Sobrien/* structure space */ 5589857Sobrien#define UDF_ANCHORS 4 /* 256, 512, N-256, N */ 5689857Sobrien#define UDF_PARTITIONS 4 /* overkill */ 5789857Sobrien#define UDF_PMAPS 4 /* overkill */ 5889857Sobrien 59218822Sdim/* misc constants */ 60218822Sdim#define UDF_MAX_NAMELEN 255 /* as per SPEC */ 61218822Sdim 62218822Sdim/* translation constants */ 63218822Sdim#define UDF_VTOP_RAWPART UDF_PMAPS /* [0..UDF_PMAPS> are normal */ 64218822Sdim 65218822Sdim/* virtual to physical mapping types */ 66218822Sdim#define UDF_VTOP_TYPE_RAW 0 67218822Sdim#define UDF_VTOP_TYPE_UNKNOWN 0 68218822Sdim#define UDF_VTOP_TYPE_PHYS 1 69218822Sdim#define UDF_VTOP_TYPE_VIRT 2 70218822Sdim#define UDF_VTOP_TYPE_SPARABLE 3 71218822Sdim#define UDF_VTOP_TYPE_META 4 72218822Sdim 73218822Sdim#define UDF_TRANS_ZERO ((uint64_t) -1) 7489857Sobrien#define UDF_TRANS_UNMAPPED ((uint64_t) -2) 7589857Sobrien#define UDF_TRANS_INTERN ((uint64_t) -3) 7689857Sobrien#define UDF_MAX_SECTOR ((uint64_t) -10) /* high water mark */ 7789857Sobrien 7889857Sobrien/* handys */ 7989857Sobrien#define UDF_ROUNDUP(val, gran) \ 8089857Sobrien ((gran) * (((val) + (gran)-1) / (gran))) 8189857Sobrien 8289857Sobrien#define UDF_ROUNDDOWN(val, gran) \ 8389857Sobrien ((gran) * (((val)) / (gran))) 8489857Sobrien 8589857Sobrien 8689857Sobrien/* disc offsets for various structures and their sizes */ 8789857Sobrienstruct udf_disclayout { 8889857Sobrien uint32_t wrtrack_skew; 8989857Sobrien 9089857Sobrien uint32_t iso9660_vrs; 9189857Sobrien uint32_t anchors[UDF_ANCHORS]; 9289857Sobrien uint32_t vds_size, vds1, vds2; 9389857Sobrien uint32_t lvis_size, lvis; 9489857Sobrien 9589857Sobrien uint32_t first_lba, last_lba; 9689857Sobrien uint32_t sector_size; 9789857Sobrien uint32_t blockingnr, align_blockingnr, sparable_blockingnr; 9889857Sobrien uint32_t meta_blockingnr, meta_alignment; 9989857Sobrien 10089857Sobrien /* sparables */ 10189857Sobrien uint32_t sparable_blocks; 10289857Sobrien uint32_t sparable_area, sparable_area_size; 10389857Sobrien uint32_t sparing_table_dscr_lbas; 10489857Sobrien uint32_t spt_1, spt_2; 10589857Sobrien 10689857Sobrien /* bitmaps */ 10789857Sobrien uint32_t alloc_bitmap_dscr_size; 10889857Sobrien uint32_t unalloc_space, freed_space; 10989857Sobrien 11089857Sobrien uint32_t meta_bitmap_dscr_size; 11189857Sobrien uint32_t meta_bitmap_space; 11289857Sobrien 11389857Sobrien /* metadata partition */ 11489857Sobrien uint32_t meta_file, meta_mirror, meta_bitmap; 11589857Sobrien uint32_t meta_part_start_lba, meta_part_size_lba; 11689857Sobrien 11789857Sobrien /* main partition */ 11889857Sobrien uint32_t part_start_lba, part_size_lba; 11989857Sobrien 12089857Sobrien uint32_t fsd, rootdir, vat; 12189857Sobrien 12289857Sobrien}; 12389857Sobrien 12489857Sobrien 12589857Sobrien/* all info about discs and descriptors building */ 12689857Sobrienstruct udf_create_context { 12789857Sobrien /* descriptors */ 12889857Sobrien int dscrver; /* 2 or 3 */ 12989857Sobrien int min_udf; /* hex */ 13089857Sobrien int max_udf; /* hex */ 13189857Sobrien int serialnum; /* format serialno */ 13289857Sobrien 13389857Sobrien int gmtoff; /* in minutes */ 13489857Sobrien 13589857Sobrien /* XXX to layout? */ 13689857Sobrien uint32_t sector_size; 13789857Sobrien 13889857Sobrien /* identification */ 13989857Sobrien char *logvol_name; 14089857Sobrien char *primary_name; 14189857Sobrien char *volset_name; 14289857Sobrien char *fileset_name; 14389857Sobrien 14489857Sobrien char const *app_name; 14589857Sobrien char const *impl_name; 14689857Sobrien int app_version_main; 14789857Sobrien int app_version_sub; 14889857Sobrien 14989857Sobrien /* building */ 15089857Sobrien int vds_seq; /* for building functions */ 15189857Sobrien int unique_id; /* only first few are used */ 15289857Sobrien 15389857Sobrien /* constructed structures */ 15489857Sobrien struct anchor_vdp *anchors[UDF_ANCHORS]; /* anchors to VDS */ 15589857Sobrien struct pri_vol_desc *primary_vol; /* identification */ 15689857Sobrien struct logvol_desc *logical_vol; /* main mapping v->p */ 15789857Sobrien struct unalloc_sp_desc *unallocated; /* free UDF space */ 15889857Sobrien struct impvol_desc *implementation; /* likely reduntant */ 15989857Sobrien struct logvol_int_desc *logvol_integrity; /* current integrity */ 16089857Sobrien struct part_desc *partitions[UDF_PARTITIONS]; /* partitions */ 16189857Sobrien 16289857Sobrien /* XXX to layout? */ 16389857Sobrien int data_part; 16489857Sobrien int metadata_part; 16589857Sobrien 16689857Sobrien /* derived; points *into* other structures */ 167218822Sdim struct udf_logvol_info *logvol_info; /* inside integrity */ 16889857Sobrien 16989857Sobrien /* fileset and root directories */ 17089857Sobrien struct fileset_desc *fileset_desc; /* normally one */ 17189857Sobrien 17289857Sobrien /* logical to physical translations */ 17389857Sobrien int vtop[UDF_PMAPS+1]; /* vpartnr trans */ 17489857Sobrien int vtop_tp[UDF_PMAPS+1]; /* type of trans */ 17589857Sobrien int vtop_offset[UDF_PMAPS+1]; /* offset in lb */ 17689857Sobrien 17789857Sobrien /* sparable */ 17889857Sobrien struct udf_sparing_table*sparing_table; /* replacements */ 17989857Sobrien 18089857Sobrien /* meta data partition */ 18189857Sobrien struct extfile_entry *meta_file; 18289857Sobrien struct extfile_entry *meta_mirror; 18389857Sobrien struct extfile_entry *meta_bitmap; 18489857Sobrien 18589857Sobrien /* lvint */ 18689857Sobrien int num_files; 18789857Sobrien int num_directories; 18889857Sobrien uint32_t part_size[UDF_PARTITIONS]; 18989857Sobrien uint32_t part_free[UDF_PARTITIONS]; 19089857Sobrien 19189857Sobrien struct space_bitmap_desc*part_unalloc_bits[UDF_PARTITIONS]; 19289857Sobrien struct space_bitmap_desc*part_freed_bits [UDF_PARTITIONS]; 19389857Sobrien}; 19489857Sobrien 19589857Sobrien 19689857Sobrien/* globals */ 19789857Sobrien 19889857Sobrienextern struct udf_create_context context; 19989857Sobrienextern struct udf_disclayout layout; 20089857Sobrien 20189857Sobrien/* prototypes */ 20289857Sobrienvoid udf_init_create_context(void); 20389857Sobrienint udf_calculate_disc_layout(int format_flags, int min_udf, 20489857Sobrien uint32_t wrtrack_skew, 20589857Sobrien uint32_t first_lba, uint32_t last_lba, 20689857Sobrien uint32_t sector_size, uint32_t blockingnr, 20789857Sobrien uint32_t sparable_blocks, 20889857Sobrien float meta_fract); 20989857Sobrien 21089857Sobrienvoid udf_osta_charset(struct charspec *charspec); 21189857Sobrienvoid udf_encode_osta_id(char *osta_id, uint16_t len, char *text); 21289857Sobrien 21389857Sobrienvoid udf_set_regid(struct regid *regid, char const *name); 21489857Sobrienvoid udf_add_domain_regid(struct regid *regid); 21589857Sobrienvoid udf_add_udf_regid(struct regid *regid); 21689857Sobrienvoid udf_add_impl_regid(struct regid *regid); 21789857Sobrienvoid udf_add_app_regid(struct regid *regid); 21889857Sobrien 21989857Sobrienint udf_validate_tag_sum(union dscrptr *dscr); 22089857Sobrienint udf_validate_tag_and_crc_sums(union dscrptr *dscr); 22189857Sobrien 22289857Sobrienvoid udf_set_timestamp_now(struct timestamp *timestamp); 22389857Sobrien 22489857Sobrien 22589857Sobrienvoid udf_inittag(struct desc_tag *tag, int tagid, uint32_t loc); 22689857Sobrienint udf_create_anchor(int num); 22789857Sobrien 22889857Sobrienvoid udf_create_terminator(union dscrptr *dscr, uint32_t loc); 22989857Sobrienint udf_create_primaryd(void); 23089857Sobrienint udf_create_partitiond(int part_num, int part_accesstype); 23189857Sobrienint udf_create_unalloc_spaced(void); 23289857Sobrienint udf_create_sparing_tabled(void); 23389857Sobrienint udf_create_space_bitmap(uint32_t dscr_size, uint32_t part_size_lba, 23489857Sobrien struct space_bitmap_desc **sbdp); 23589857Sobrienint udf_create_logical_dscr(int format_flags); 23689857Sobrienint udf_create_impvold(char *field1, char *field2, char *field3); 23789857Sobrienint udf_create_fsd(void); 23889857Sobrienint udf_create_lvintd(int type); 23989857Sobrienvoid udf_update_lvintd(int type); 24089857Sobrien 24189857Sobrienint udf_register_bad_block(uint32_t location); 24289857Sobrienvoid udf_mark_allocated(uint32_t start_lb, int partnr, uint32_t blocks); 24389857Sobrien 24489857Sobrienint udf_create_new_fe(struct file_entry **fep, int file_type, 24589857Sobrien struct long_ad *parent_icb); 24689857Sobrienint udf_create_new_efe(struct extfile_entry **efep, int file_type, 24789857Sobrien struct long_ad *parent_icb); 24889857Sobrien 24989857Sobrienint udf_create_meta_files(void); 25089857Sobrienint udf_create_new_rootdir(union dscrptr **dscr); 25189857Sobrienint udf_create_new_VAT(union dscrptr **vat_dscr); 25289857Sobrien 25389857Sobrien#endif /* _FS_UDF_UDF_CREATE_H_ */ 25489857Sobrien 25589857Sobrien