📄 udf.c
字号:
memcpy(dst->character_set_info, "OSTA Compressed Unicode", 23);}static void#ifdef PROTOTYPESset_impl_ident(udf_EntityID *ent)#elseset_impl_ident(ent) udf_EntityID *ent;#endif{ strcpy((char*)ent->ident, "*mkisofs");}static void#ifdef PROTOTYPESset_tag(udf_tag *t, unsigned tid, unsigned lba, int crc_length)#elseset_tag(t,tid,lba,crc_length) udf_tag *t; unsigned tid; unsigned lba; int crc_length;#endif{ unsigned char checksum; int i; set16(&t->tag_ident, tid); set16(&t->desc_version, 2); set16(&t->desc_crc, crc_ccitt((unsigned char*)t+16, crc_length-16)); set16(&t->desc_crc_length, crc_length-16); set32(&t->tag_location, lba); set8(&t->tag_checksum, 0); checksum = 0; for (i=0; i<16; ++i) checksum += ((unsigned char*)t)[i]; set8(&t->tag_checksum, checksum);}static void#ifdef PROTOTYPESset_timestamp_from_iso_date(udf_timestamp *ts, const char *iso_date_raw)#elseset_timestamp_from_iso_date(ts,iso_date_raw) udf_timestamp *ts; const char *iso_date_raw;#endif{ struct { unsigned char years_since_1900; unsigned char month, day; unsigned char hour, minute, second; signed char offset_from_gmt; } *iso_date = (void *)iso_date_raw; set16(&ts->type_and_time_zone, 4096 + ((iso_date->offset_from_gmt * 15) & 4095)); set16(&ts->year, 1900 + iso_date->years_since_1900); set8(&ts->month, iso_date->month); set8(&ts->day, iso_date->day); set8(&ts->hour, iso_date->hour); set8(&ts->minute, iso_date->minute); set8(&ts->second, iso_date->second); /*set8(&ts->centiseconds, 0);*/ /*set8(&ts->hundreds_of_microseconds, 0);*/ /*set8(&ts->microseconds, 0);*/}static void#ifdef PROTOTYPESset_timestamp_from_time_t(udf_timestamp *ts, time_t t)#elseset_timestamp_from_time_t(ts,t) udf_timestamp *ts; time_t t;#endif{ char iso_date[7]; iso9660_date(iso_date, t); set_timestamp_from_iso_date(ts, iso_date);}static void#ifdef PROTOTYPESset_anchor_volume_desc_pointer(unsigned char *buf, unsigned lba)#elseset_anchor_volume_desc_pointer(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_anchor_volume_desc_ptr *avdp = (udf_anchor_volume_desc_ptr *)buf; set_extent(&avdp->main_volume_desc_seq_extent, lba_main_seq, SECTOR_SIZE*UDF_MAIN_SEQ_LENGTH); set_extent(&avdp->reserve_volume_desc_seq_extent, lba_main_seq_copy, SECTOR_SIZE*UDF_MAIN_SEQ_LENGTH); set_tag(&avdp->desc_tag, UDF_TAGID_ANCHOR_VOLUME_DESC_PTR, lba, 512);}static void#ifdef PROTOTYPESset_primary_vol_desc(unsigned char *buf, unsigned lba)#elseset_primary_vol_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ char temp[17]; time_t now; udf_primary_volume_desc *pvd = (udf_primary_volume_desc *)buf; /*set32(&pvd->volume_desc_seq_number, 0);*/ /*set32(&pvd->primary_volume_desc_number, 0);*/ set_dstring(pvd->volume_ident, volume_id, sizeof(pvd->volume_ident)); set16(&pvd->volume_seq_number, 1); set16(&pvd->maximum_volume_seq_number, 1); set16(&pvd->interchange_level, 2); set16(&pvd->maximum_interchange_level, 2); set32(&pvd->character_set_list, 1); set32(&pvd->maximum_character_set_list, 1); sprintf(temp, "%08X%08X", volume_set_id[0], volume_set_id[1]); set_dstring(pvd->volume_set_ident, temp, sizeof(pvd->volume_set_ident)); set_charspec(&pvd->desc_character_set); set_charspec(&pvd->explanatory_character_set); /*pvd->volume_abstract;*/ /*pvd->volume_copyright_notice;*/ /*pvd->application_ident;*/ time(&now); set_timestamp_from_time_t(&pvd->recording_date_and_time, now); set_impl_ident(&pvd->impl_ident); set_tag(&pvd->desc_tag, UDF_TAGID_PRIMARY_VOLUME_DESC, lba, 512);}static void#ifdef PROTOTYPESset_impl_use_vol_desc(unsigned char *buf, unsigned lba)#elseset_impl_use_vol_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_impl_use_volume_desc *iuvd = (udf_impl_use_volume_desc *)buf; set32(&iuvd->volume_desc_seq_number, 1); strcpy((char*)iuvd->impl_ident.ident, "*UDF LV Info"); iuvd->impl_ident.ident_suffix[0] = 2; iuvd->impl_ident.ident_suffix[1] = 1; set_charspec(&iuvd->impl_use.lvi_charset); set_dstring(iuvd->impl_use.logical_volume_ident, volume_id, sizeof(iuvd->impl_use.logical_volume_ident)); /*set_dstring(iuvd->impl_use.lv_info1, "", sizeof(iuvd->impl_use.lv_info1));*/ /*set_dstring(iuvd->impl_use.lv_info2, "", sizeof(iuvd->impl_use.lv_info2));*/ /*set_dstring(iuvd->impl_use.lv_info3, "", sizeof(iuvd->impl_use.lv_info3));*/ set_impl_ident(&iuvd->impl_use.impl_id); set_tag(&iuvd->desc_tag, UDF_TAGID_IMPL_USE_VOLUME_DESC, lba, 512);}static void#ifdef PROTOTYPESset_partition_desc(unsigned char *buf, unsigned lba)#elseset_partition_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_partition_desc *pd = (udf_partition_desc *)buf; set32(&pd->volume_desc_seq_number, 2); set16(&pd->partition_flags, UDF_PARTITION_FLAG_ALLOCATED); /*set16(&pd->partition_number, 0);*/ set8(&pd->partition_contents.flags, UDF_ENTITYID_FLAG_PROTECTED);/*???*/ strcpy((char*)pd->partition_contents.ident, "+NSR02"); set32(&pd->access_type, UDF_ACCESSTYPE_READONLY); set32(&pd->partition_starting_location, lba_udf_partition_start); set32(&pd->partition_length, lba_end_anchor_vol_desc - lba_udf_partition_start); set_impl_ident(&pd->impl_ident); set_tag(&pd->desc_tag, UDF_TAGID_PARTITION_DESC, lba, 512);}static void#ifdef PROTOTYPESset_domain_ident(udf_EntityID *ent)#elseset_domain_ident(ent) udf_EntityID *ent;#endif{ strcpy((char*)ent->ident, "*OSTA UDF Compliant"); memcpy(ent->ident_suffix, "\002\001\003", 3);}static void#ifdef PROTOTYPESset_logical_vol_desc(unsigned char *buf, unsigned lba)#elseset_logical_vol_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_logical_volume_desc *lvd = (udf_logical_volume_desc *)buf; set32(&lvd->volume_desc_seq_number, 3); set_charspec(&lvd->desc_character_set); set_dstring(lvd->logical_volume_ident, volume_id, sizeof(lvd->logical_volume_ident)); set32(&lvd->logical_block_size, SECTOR_SIZE); set_domain_ident(&lvd->domain_ident); set32(&lvd->logical_volume_contents_use.extent_length, 2*SECTOR_SIZE); /*set32(&lvd->logical_volume_contents_use.extent_location.logical_block_number, 0);*/ /*set16(&lvd->logical_volume_contents_use.extent_location.partition_reference_number, 0);*/ set32(&lvd->map_table_length, 6); set32(&lvd->number_of_partition_maps, 1); set_impl_ident(&lvd->impl_ident); set_extent(&lvd->integrity_seq_extent, lba_integ_seq, SECTOR_SIZE*UDF_INTEG_SEQ_LENGTH); set8(&lvd->partition_map[0].partition_map_type, UDF_PARTITION_MAP_TYPE_1); set8(&lvd->partition_map[0].partition_map_length, 6); set16(&lvd->partition_map[0].volume_seq_number, 1); /*set16(&lvd->partition_map[0].partition_number, 0);*/ set_tag(&lvd->desc_tag, UDF_TAGID_LOGICAL_VOLUME_DESC, lba, 446);}static void#ifdef PROTOTYPESset_unallocated_space_desc(unsigned char *buf, unsigned lba)#elseset_unallocated_space_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_unallocated_space_desc *usd = (udf_unallocated_space_desc *)buf; set32(&usd->volume_desc_seq_number, 4); /*set32(&usd->number_of_allocation_descs, 0);*/ set_tag(&usd->desc_tag, UDF_TAGID_UNALLOCATED_SPACE_DESC, lba, 24);}static void#ifdef PROTOTYPESset_terminating_desc(unsigned char *buf, unsigned lba)#elseset_terminating_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_terminating_desc *td = (udf_terminating_desc *)buf; set_tag(&td->desc_tag, UDF_TAGID_TERMINATING_DESC, lba, 512);}static void#ifdef PROTOTYPESset_logical_vol_integrity_desc(unsigned char *buf, unsigned lba)#elseset_logical_vol_integrity_desc(buf,lba) unsigned char *buf; unsigned lba;#endif{ udf_logical_volume_integrity_desc *lvid = (udf_logical_volume_integrity_desc *)buf; time_t now; time(&now); set_timestamp_from_time_t(&lvid->recording_date, now); set32(&lvid->integrity_type, UDF_INTEGRITY_TYPE_CLOSE); /*lvid->next_integrity_extent;*/ set64(&lvid->logical_volume_contents_use.unique_id, lba_last_file_entry+1); set32(&lvid->number_of_partitions, 1); set32(&lvid->length_of_impl_use, 46); /*set32(&lvid->free_space_table, 0);*/ set32(&lvid->size_table, lba_end_anchor_vol_desc - lba_udf_partition_start); set_impl_ident(&lvid->impl_use.impl_id); set32(&lvid->impl_use.number_of_files, num_udf_files); set32(&lvid->impl_use.number_of_directories, num_udf_directories); set16(&lvid->impl_use.minimum_udf_read_revision, 0x102); set16(&lvid->impl_use.minimum_udf_write_revision, 0x102); set16(&lvid->impl_use.maximum_udf_write_revision, 0x102); set_tag(&lvid->desc_tag, UDF_TAGID_LOGICAL_VOLUME_INTEGRITY_DESC, lba, 88+46);}static void#ifdef PROTOTYPESset_file_set_desc(unsigned char *buf, unsigned rba)#elseset_file_set_desc(buf,rba) unsigned char *buf; unsigned rba;#endif{ udf_file_set_desc *fsd = (udf_file_set_desc *)buf; time_t now; time(&now); set_timestamp_from_time_t(&fsd->recording_date_and_time, now); set16(&fsd->interchange_level, 3); set16(&fsd->maximum_interchange_level, 3); set32(&fsd->character_set_list, 1); set32(&fsd->maximum_character_set_list, 1); /*set32(&fsd->file_set_number, 0);*/ /*set32(&fsd->file_set_desc_number, 0);*/ set_charspec(&fsd->logical_volume_ident_character_set); set_dstring(fsd->logical_volume_ident, volume_id, sizeof(fsd->logical_volume_ident)); set_charspec(&fsd->file_set_character_set); set_dstring(fsd->file_set_ident, volume_id, sizeof(fsd->file_set_ident)); /*fsd->copyright_file_ident;*/ /*fsd->abstract_file_ident;*/ set32(&fsd->root_directory_icb.extent_length, SECTOR_SIZE); set32(&fsd->root_directory_icb.extent_location.logical_block_number, root->self->udf_file_entry_sector - lba_udf_partition_start); set_domain_ident(&fsd->domain_ident); /*fsd->next_extent;*/ set_tag(&fsd->desc_tag, UDF_TAGID_FILE_SET_DESC, rba, 512);}static int#ifdef PROTOTYPESset_file_ident_desc(unsigned char *buf, unsigned rba, char *name, int is_directory, unsigned file_entry_rba, unsigned unique_id)#elseset_file_ident_desc(buf,rba,name,is_directory,file_entry_rba,unique_id) unsigned char *buf; unsigned rba; char *name; int is_directory; unsigned file_entry_rba; unsigned unique_id;#endif{ udf_file_ident_desc *fid = (udf_file_ident_desc *)buf; int length_of_file_ident, length, padded_length; set16(&fid->file_version_number, 1); set8(&fid->file_characteristics, (is_directory ? UDF_FILE_CHARACTERISTIC_DIRECTORY : 0) + (name==0) * UDF_FILE_CHARACTERISTIC_PARENT); set32(&fid->icb.extent_length, SECTOR_SIZE); set32(&fid->icb.extent_location.logical_block_number, file_entry_rba); set16(&fid->icb.extent_location.partition_reference_number, 0); set32(&fid->icb.impl_use.unique_id, unique_id); set16(&fid->length_of_impl_use, 0); if (name) { length_of_file_ident = set_ostaunicode((Uchar *)fid->file_ident, 512, name); } else { length_of_file_ident = 0; } set8(&fid->length_of_file_ident, length_of_file_ident); length = 38 + length_of_file_ident; padded_length = PAD(length, 4); while (length < padded_length) { buf[length++] = 0; } set_tag(&fid->desc_tag, UDF_TAGID_FILE_IDENT_DESC, rba, length); return length;}static void#ifdef PROTOTYPESset_file_entry(unsigned char *buf, unsigned rba, unsigned file_rba, unsigned length, const char *iso_date, int is_directory, unsigned link_count, unsigned unique_id)#elseset_file_entry(buf,rba,file_rba,length,iso_date,is_directory,link_count,unique_id) unsigned char *buf; unsigned rba; unsigned file_rba; unsigned length; const char *iso_date; int is_directory; unsigned link_count; unsigned unique_id;#endif{ udf_short_ad *allocation_desc; unsigned chunk; udf_file_entry *fe = (udf_file_entry *)buf; /*set32(&fe->icb_tag.prior_recorded_number_of_direct_entries, 0);*/ set16(&fe->icb_tag.strategy_type, 4); /*set16(&fe->icb_tag.strategy_parameter, 0);*/ set16(&fe->icb_tag.maximum_number_of_entries, 1); set8(&fe->icb_tag.file_type, is_directory ? UDF_ICBTAG_FILETYPE_DIRECTORY : UDF_ICBTAG_FILETYPE_BYTESEQ); /*fe->icb_tag.parent_icb_location;*/ set16(&fe->icb_tag.flags, UDF_ICBTAG_FLAG_NONRELOCATABLE | UDF_ICBTAG_FLAG_ARCHIVE | UDF_ICBTAG_FLAG_CONTIGUOUS); set32(&fe->uid, -1); set32(&fe->gid, -1); if (is_directory) { set32(&fe->permissions, UDF_FILEENTRY_PERMISSION_OR | UDF_FILEENTRY_PERMISSION_OX | UDF_FILEENTRY_PERMISSION_GR | UDF_FILEENTRY_PERMISSION_GX | UDF_FILEENTRY_PERMISSION_UR | UDF_FILEENTRY_PERMISSION_UX); } else { set32(&fe->permissions, UDF_FILEENTRY_PERMISSION_OR | UDF_FILEENTRY_PERMISSION_GR | UDF_FILEENTRY_PERMISSION_UR); } set16(&fe->file_link_count, link_count); /*fe->record_format;*/ /*fe->record_display_attributes;*/ /*fe->record_length;*/ set64(&fe->info_length, length); set64(&fe->logical_blocks_recorded, ISO_BLOCKS(length)); if (iso_date) { set_timestamp_from_iso_date(&fe->access_time, iso_date); fe->modification_time = fe->access_time; fe->attribute_time = fe->access_time; } set32(&fe->checkpoint, 1); /*fe->ext_attribute_icb;*/ set_impl_ident(&fe->impl_ident); set64(&fe->unique_id, unique_id); /* * Extended attributes that may (?) be required for DVD-Video * compliance */#if 0 set32(&fe->length_of_ext_attributes, 24+52+56); set32(&fe->ext_attribute_header.impl_attributes_location, 24); set32(&fe->ext_attribute_header.application_attributes_location, 24+52+56); set_tag(&fe->ext_attribute_header.desc_tag, UDF_TAGID_EXT_ATTRIBUTE_HEADER_DESC, rba, 24/*???*/); set32(&fe->ext_attribute_free_ea_space.attribute_type, SECTOR_SIZE); set8(&fe->ext_attribute_free_ea_space.attribute_subtype, 1); set32(&fe->ext_attribute_free_ea_space.attribute_length, 52); set32(&fe->ext_attribute_free_ea_space.impl_use_length, 4); strcpy((char *)fe->ext_attribute_free_ea_space.impl_ident.ident, "*UDF FreeAppEASpace"); set32(&fe->ext_attribute_dvd_cgms_info.attribute_type, SECTOR_SIZE); set8(&fe->ext_attribute_dvd_cgms_info.attribute_subtype, 1); set32(&fe->ext_attribute_dvd_cgms_info.attribute_length, 56); set32(&fe->ext_attribute_dvd_cgms_info.impl_use_length, 8); strcpy((char *)fe->ext_attribute_free_ea_space.impl_ident.ident, "*UDF DVD CGMS Info"); fe->ext_attribute_free_ea_space.impl_ident.ident_suffix[0] = 2; fe->ext_attribute_free_ea_space.impl_ident.ident_suffix[1] = 1;#else /*set32(&fe->length_of_ext_attributes, 0);*/#endif allocation_desc = &fe->allocation_desc; /* * Only a file size less than 1GB can be expressed by a single * AllocationDescriptor. When the size of a file is larger than 1GB, * 2 or more AllocationDescriptors should be used. We don't know * whether a singl 8-byte AllocationDescriptor should be written or no * one should be written if the size of a file is 0 byte. - FIXME. * * XXX We get called with buf[2048]. This allows a max. file size of * XXX 234 GB. With more we would cause a buffer overflow. * XXX We need to check whether UDF would allow files > 234 GB. */ for (; length > 0; length -= chunk) { chunk = (length > 0x3ffff800) ? 0x3ffff800 : length; set32(&allocation_desc->extent_length, chunk); set32(&allocation_desc->extent_position, file_rba); file_rba += chunk >> 11; allocation_desc++; } set32(&fe->length_of_allocation_descs, (unsigned char *) allocation_desc - (unsigned char *) &fe->allocation_desc); set_tag(&fe->desc_tag, UDF_TAGID_FILE_ENTRY, rba, (unsigned char *) allocation_desc - buf); }static unsigned#ifdef PROTOTYPESdirectory_link_count(struct directory *dpnt)#elsedirectory_link_count(dpnt) struct directory *dpnt;#endif{ /* * The link count is equal to 1 (for the parent) plus the * number of subdirectories. */ unsigned link_count = 1; struct directory_entry *de; /* count relocated subdirectories */ for (de = dpnt->jcontents; de; de = de->jnext) { if ((de->de_flags & (INHIBIT_JOLIET_ENTRY | RELOCATED_DIRECTORY)) == RELOCATED_DIRECTORY) { link_count++; } } /* count ordinary subdirectories */ for (dpnt = dpnt->subdir; dpnt; dpnt = dpnt->next) { if (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY)) { link_count++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -