1 /* $NetBSD: udf_create.h,v 1.2 2008/07/26 20:20:56 reinoud Exp $ */
4 * Copyright (c) 2006, 2008 Reinoud Zandijk
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef _FS_UDF_UDF_CREATE_H_
30 #define _FS_UDF_UDF_CREATE_H_
32 #include <sys/types.h>
33 #include <fs/udf/ecma167-udf.h>
34 #include "udf_bswap.h"
38 /* format flags indicating properties of disc to create */
39 #define FORMAT_WRITEONCE 0x00001
40 #define FORMAT_SEQUENTIAL 0x00002
41 #define FORMAT_REWRITABLE 0x00004
42 #define FORMAT_SPARABLE 0x00008
43 #define FORMAT_META 0x00010
44 #define FORMAT_LOW 0x00020
45 #define FORMAT_VAT 0x00040
46 #define FORMAT_WORM 0x00080
47 #define FORMAT_TRACK512 0x00100
48 #define FORMAT_INVALID 0x00200
49 #define FORMAT_FLAGBITS \
50 "\10\1WRITEONCE\2SEQUENTIAL\3REWRITABLE\4SPARABLE\5META\6LOW" \
51 "\7VAT\10WORM\11TRACK512\12INVALID"
55 #define UDF_ANCHORS 4 /* 256, 512, N-256, N */
56 #define UDF_PARTITIONS 4 /* overkill */
57 #define UDF_PMAPS 4 /* overkill */
60 #define UDF_MAX_NAMELEN 255 /* as per SPEC */
62 /* translation constants */
63 #define UDF_VTOP_RAWPART UDF_PMAPS /* [0..UDF_PMAPS> are normal */
65 /* virtual to physical mapping types */
66 #define UDF_VTOP_TYPE_RAW 0
67 #define UDF_VTOP_TYPE_UNKNOWN 0
68 #define UDF_VTOP_TYPE_PHYS 1
69 #define UDF_VTOP_TYPE_VIRT 2
70 #define UDF_VTOP_TYPE_SPARABLE 3
71 #define UDF_VTOP_TYPE_META 4
73 #define UDF_TRANS_ZERO ((uint64_t) -1)
74 #define UDF_TRANS_UNMAPPED ((uint64_t) -2)
75 #define UDF_TRANS_INTERN ((uint64_t) -3)
76 #define UDF_MAX_SECTOR ((uint64_t) -10) /* high water mark */
79 #define UDF_ROUNDUP(val, gran) \
80 ((gran) * (((val) + (gran)-1) / (gran)))
82 #define UDF_ROUNDDOWN(val, gran) \
83 ((gran) * (((val)) / (gran)))
86 /* disc offsets for various structures and their sizes */
87 struct udf_disclayout
{
88 uint32_t wrtrack_skew
;
91 uint32_t anchors
[UDF_ANCHORS
];
92 uint32_t vds_size
, vds1
, vds2
;
93 uint32_t lvis_size
, lvis
;
95 uint32_t first_lba
, last_lba
;
97 uint32_t blockingnr
, align_blockingnr
, sparable_blockingnr
;
98 uint32_t meta_blockingnr
, meta_alignment
;
101 uint32_t sparable_blocks
;
102 uint32_t sparable_area
, sparable_area_size
;
103 uint32_t sparing_table_dscr_lbas
;
104 uint32_t spt_1
, spt_2
;
107 uint32_t alloc_bitmap_dscr_size
;
108 uint32_t unalloc_space
, freed_space
;
110 uint32_t meta_bitmap_dscr_size
;
111 uint32_t meta_bitmap_space
;
113 /* metadata partition */
114 uint32_t meta_file
, meta_mirror
, meta_bitmap
;
115 uint32_t meta_part_start_lba
, meta_part_size_lba
;
118 uint32_t part_start_lba
, part_size_lba
;
120 uint32_t fsd
, rootdir
, vat
;
125 /* all info about discs and descriptors building */
126 struct udf_create_context
{
128 int dscrver
; /* 2 or 3 */
129 int min_udf
; /* hex */
130 int max_udf
; /* hex */
131 int serialnum
; /* format serialno */
133 int gmtoff
; /* in minutes */
136 uint32_t sector_size
;
144 char const *app_name
;
145 char const *impl_name
;
146 int app_version_main
;
150 int vds_seq
; /* for building functions */
151 int unique_id
; /* only first few are used */
153 /* constructed structures */
154 struct anchor_vdp
*anchors
[UDF_ANCHORS
]; /* anchors to VDS */
155 struct pri_vol_desc
*primary_vol
; /* identification */
156 struct logvol_desc
*logical_vol
; /* main mapping v->p */
157 struct unalloc_sp_desc
*unallocated
; /* free UDF space */
158 struct impvol_desc
*implementation
; /* likely reduntant */
159 struct logvol_int_desc
*logvol_integrity
; /* current integrity */
160 struct part_desc
*partitions
[UDF_PARTITIONS
]; /* partitions */
166 /* derived; points *into* other structures */
167 struct udf_logvol_info
*logvol_info
; /* inside integrity */
169 /* fileset and root directories */
170 struct fileset_desc
*fileset_desc
; /* normally one */
172 /* logical to physical translations */
173 int vtop
[UDF_PMAPS
+1]; /* vpartnr trans */
174 int vtop_tp
[UDF_PMAPS
+1]; /* type of trans */
175 int vtop_offset
[UDF_PMAPS
+1]; /* offset in lb */
178 struct udf_sparing_table
*sparing_table
; /* replacements */
180 /* meta data partition */
181 struct extfile_entry
*meta_file
;
182 struct extfile_entry
*meta_mirror
;
183 struct extfile_entry
*meta_bitmap
;
188 uint32_t part_size
[UDF_PARTITIONS
];
189 uint32_t part_free
[UDF_PARTITIONS
];
191 struct space_bitmap_desc
*part_unalloc_bits
[UDF_PARTITIONS
];
192 struct space_bitmap_desc
*part_freed_bits
[UDF_PARTITIONS
];
198 extern struct udf_create_context context
;
199 extern struct udf_disclayout layout
;
202 void udf_init_create_context(void);
203 int udf_calculate_disc_layout(int format_flags
, int min_udf
,
204 uint32_t wrtrack_skew
,
205 uint32_t first_lba
, uint32_t last_lba
,
206 uint32_t sector_size
, uint32_t blockingnr
,
207 uint32_t sparable_blocks
,
210 void udf_osta_charset(struct charspec
*charspec
);
211 void udf_encode_osta_id(char *osta_id
, uint16_t len
, char *text
);
213 void udf_set_regid(struct regid
*regid
, char const *name
);
214 void udf_add_domain_regid(struct regid
*regid
);
215 void udf_add_udf_regid(struct regid
*regid
);
216 void udf_add_impl_regid(struct regid
*regid
);
217 void udf_add_app_regid(struct regid
*regid
);
219 int udf_validate_tag_sum(union dscrptr
*dscr
);
220 int udf_validate_tag_and_crc_sums(union dscrptr
*dscr
);
222 void udf_set_timestamp_now(struct timestamp
*timestamp
);
225 void udf_inittag(struct desc_tag
*tag
, int tagid
, uint32_t loc
);
226 int udf_create_anchor(int num
);
228 void udf_create_terminator(union dscrptr
*dscr
, uint32_t loc
);
229 int udf_create_primaryd(void);
230 int udf_create_partitiond(int part_num
, int part_accesstype
);
231 int udf_create_unalloc_spaced(void);
232 int udf_create_sparing_tabled(void);
233 int udf_create_space_bitmap(uint32_t dscr_size
, uint32_t part_size_lba
,
234 struct space_bitmap_desc
**sbdp
);
235 int udf_create_logical_dscr(int format_flags
);
236 int udf_create_impvold(char *field1
, char *field2
, char *field3
);
237 int udf_create_fsd(void);
238 int udf_create_lvintd(int type
);
239 void udf_update_lvintd(int type
);
241 int udf_register_bad_block(uint32_t location
);
242 void udf_mark_allocated(uint32_t start_lb
, int partnr
, uint32_t blocks
);
244 int udf_create_new_fe(struct file_entry
**fep
, int file_type
,
245 struct long_ad
*parent_icb
);
246 int udf_create_new_efe(struct extfile_entry
**efep
, int file_type
,
247 struct long_ad
*parent_icb
);
249 int udf_create_meta_files(void);
250 int udf_create_new_rootdir(union dscrptr
**dscr
);
251 int udf_create_new_VAT(union dscrptr
**vat_dscr
);
253 #endif /* _FS_UDF_UDF_CREATE_H_ */