⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkudffs.c

📁 linux下的DVD格式udf文件读取库
💻 C
📖 第 1 页 / 共 3 页
字号:
void setup_pvd(struct udf_disc *disc, struct udf_extent *pvds, struct udf_extent *rvds, uint32_t offset){	struct udf_desc *desc;	int length = sizeof(struct primaryVolDesc);	desc = set_desc(disc, pvds, TAG_IDENT_PVD, offset, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_pvd[0];	disc->udf_pvd[0]->descTag = query_tag(disc, pvds, desc, 1);	desc = set_desc(disc, rvds, TAG_IDENT_PVD, offset, length, NULL);	memcpy(disc->udf_pvd[1] = desc->data->buffer, disc->udf_pvd[0], length);	disc->udf_pvd[1]->descTag = query_tag(disc, rvds, desc, 1);}void setup_lvd(struct udf_disc *disc, struct udf_extent *pvds, struct udf_extent *rvds, struct udf_extent *lvid, uint32_t offset){	struct udf_desc *desc;	int length = sizeof(struct logicalVolDesc) + le32_to_cpu(disc->udf_lvd[0]->mapTableLength);	disc->udf_lvd[0]->integritySeqExt.extLength = cpu_to_le32(lvid->blocks * disc->blocksize);	disc->udf_lvd[0]->integritySeqExt.extLocation = cpu_to_le32(lvid->start);//	((uint16_t *)disc->udf_lvd[0]->domainIdent.identSuffix)[0] = cpu_to_le16(disc->udf_rev);	desc = set_desc(disc, pvds, TAG_IDENT_LVD, offset, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_lvd[0];	disc->udf_lvd[0]->descTag = query_tag(disc, pvds, desc, 1);	desc = set_desc(disc, rvds, TAG_IDENT_LVD, offset, length, NULL);	memcpy(disc->udf_lvd[1] = desc->data->buffer, disc->udf_lvd[0], length);	disc->udf_lvd[1]->descTag = query_tag(disc, rvds, desc, 1);}void setup_pd(struct udf_disc *disc, struct udf_extent *pvds, struct udf_extent *rvds, uint32_t offset){	struct udf_desc *desc;	struct udf_extent *ext;	int length = sizeof(struct partitionDesc);	ext = next_extent(disc->head, PSPACE);	disc->udf_pd[0]->partitionStartingLocation = cpu_to_le32(ext->start);	disc->udf_pd[0]->partitionLength = cpu_to_le32(ext->blocks);#if 0	if (disc->udf_rev >= 0x0200)		strcpy(disc->udf_pd[0]->partitionContents.ident, PARTITION_CONTENTS_NSR03);	else		strcpy(disc->udf_pd[0]->partitionContents.ident, PARTITION_CONTENTS_NSR02);#endif	desc = set_desc(disc, pvds, TAG_IDENT_PD, offset, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_pd[0];	disc->udf_pd[0]->descTag = query_tag(disc, pvds, desc, 1);	desc = set_desc(disc, rvds, TAG_IDENT_PD, offset, length, NULL);	memcpy(disc->udf_pd[1] = desc->data->buffer, disc->udf_pd[0], length);	disc->udf_pd[1]->descTag = query_tag(disc, rvds, desc, 1);}void setup_usd(struct udf_disc *disc, struct udf_extent *pvds, struct udf_extent *rvds, uint32_t offset){	struct udf_desc *desc;	struct udf_extent *ext;	int count = 0;	int length = sizeof(struct unallocSpaceDesc);	ext = next_extent(disc->head, USPACE);	while (ext)	{		length += sizeof(extent_ad);		disc->udf_usd[0] = realloc(disc->udf_usd[0], length);		disc->udf_usd[0]->numAllocDescs = cpu_to_le32(le32_to_cpu(disc->udf_usd[0]->numAllocDescs)+1);		disc->udf_usd[0]->allocDescs[count].extLength = cpu_to_le32(ext->blocks * disc->blocksize);		disc->udf_usd[0]->allocDescs[count].extLocation = cpu_to_le32(ext->start);		count ++;		ext = next_extent(ext->next, USPACE);	}	desc = set_desc(disc, pvds, TAG_IDENT_USD, offset, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_usd[0];	disc->udf_usd[0]->descTag = query_tag(disc, pvds, desc, 1);	desc = set_desc(disc, rvds, TAG_IDENT_USD, offset, length, NULL);	memcpy(disc->udf_usd[1] = desc->data->buffer, disc->udf_usd[0], length);	disc->udf_usd[1]->descTag = query_tag(disc, rvds, desc, 1);}void setup_iuvd(struct udf_disc *disc, struct udf_extent *pvds, struct udf_extent *rvds, uint32_t offset){	struct udf_desc *desc;	int length = sizeof(struct impUseVolDesc);//	((uint16_t *)disc->udf_iuvd[0]->impIdent.identSuffix)[0] = cpu_to_le16(disc->udf_rev);	desc = set_desc(disc, pvds, TAG_IDENT_IUVD, offset, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_iuvd[0];	disc->udf_iuvd[0]->descTag = query_tag(disc, pvds, desc, 1);	desc = set_desc(disc, rvds, TAG_IDENT_IUVD, offset, length, NULL);	memcpy(disc->udf_iuvd[1] = desc->data->buffer, disc->udf_iuvd[0], length);	disc->udf_iuvd[1]->descTag = query_tag(disc, rvds, desc, 1);}void setup_td(struct udf_disc *disc, struct udf_extent *pvds, struct udf_extent *rvds, uint32_t offset){	struct udf_desc *desc;	int length = sizeof(struct terminatingDesc);	desc = set_desc(disc, pvds, TAG_IDENT_TD, offset, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_td[0];	disc->udf_td[0]->descTag = query_tag(disc, pvds, desc, 1);	desc = set_desc(disc, rvds, TAG_IDENT_TD, offset, length, NULL);	memcpy(disc->udf_td[1] = desc->data->buffer, disc->udf_td[0], length);	disc->udf_td[1]->descTag = query_tag(disc, rvds, desc, 1);}void setup_lvid(struct udf_disc *disc, struct udf_extent *lvid){	struct udf_desc *desc;	struct udf_extent *ext;	int length = sizeof(struct logicalVolIntegrityDesc) + le32_to_cpu(disc->udf_lvid->numOfPartitions) * sizeof(uint32_t) * 2 + le32_to_cpu(disc->udf_lvid->lengthOfImpUse);	ext = next_extent(disc->head, PSPACE);//	disc->udf_lvid->freeSpaceTable[0] = cpu_to_le32(ext->blocks);//	disc->udf_lvid->sizeTable[1] = cpu_to_le32(ext->blocks);	if (disc->flags & FLAG_VAT)		disc->udf_lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);	desc = set_desc(disc, lvid, TAG_IDENT_LVID, 0, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_lvid;	disc->udf_lvid->descTag = query_tag(disc, lvid, desc, 1);	if (!(disc->flags & FLAG_BLANK_TERMINAL) && lvid->blocks > 1)	{		desc = set_desc(disc, lvid, TAG_IDENT_TD, 1, sizeof(struct terminatingDesc), NULL);		((struct terminatingDesc *)desc->data->buffer)->descTag = query_tag(disc, lvid, desc, 1);	}}void setup_stable(struct udf_disc *disc, struct udf_extent *stable[4], struct udf_extent *sspace){	struct udf_desc *desc;	int i, length = 0, num, packetlen;	struct sparablePartitionMap *spm;	spm = find_type2_sparable_partition(disc, 0);	packetlen = le16_to_cpu(spm->packetLength);	num = sspace->blocks / packetlen;	length = sizeof(struct sparingTable) + num * sizeof(struct sparingEntry);	spm->sizeSparingTable = cpu_to_le32(length);	for (i=0; i<spm->numSparingTables; i++)		spm->locSparingTable[i] = cpu_to_le32(stable[i]->start);	disc->udf_stable[0] = realloc(disc->udf_stable[0], length);	disc->udf_stable[0]->reallocationTableLen = cpu_to_le16(num);	for (i=0; i<num; i++)	{		disc->udf_stable[0]->mapEntry[i].origLocation = cpu_to_le32(0xFFFFFFFF);		disc->udf_stable[0]->mapEntry[i].mappedLocation = cpu_to_le32(sspace->start + (i * packetlen));	}	desc = set_desc(disc, stable[0], 0, 0, 0, NULL);	desc->length = desc->data->length = length;	desc->data->buffer = disc->udf_stable[0];	disc->udf_stable[0]->descTag = query_tag(disc, stable[0], desc, 1);	for (i=1; i<4 && stable[i]; i++)	{		desc = set_desc(disc, stable[i], 0, 0, length, NULL);		memcpy(disc->udf_stable[i] = desc->data->buffer, disc->udf_stable[0], length);		disc->udf_stable[i]->descTag = query_tag(disc, stable[i], desc, 1);	}}void setup_vat(struct udf_disc *disc, struct udf_extent *ext){	uint32_t offset = 0;	struct udf_desc *vtable, *desc;	struct udf_data *data;	struct fileEntry *fe;	struct extendedFileEntry *efe;	struct fileIdentDesc *fid;	uint32_t *vsector, len;	struct virtualAllocationTable15 *vat15;	struct virtualAllocationTable20 *vat20;	ext = disc->tail;	if (disc->udf_rev >= 0x0200)	{		vtable = udf_create(disc, ext, UDF_ID_ALLOC, strlen(UDF_ID_ALLOC), offset, NULL, FID_FILE_CHAR_HIDDEN, ICBTAG_FILE_TYPE_VAT20, 0);		len = sizeof(struct virtualAllocationTable20);		data = alloc_data(&default_vat20, len);		vat20 = data->buffer;		vat20->numFiles = query_lvidiu(disc)->numFiles;		vat20->numDirs = query_lvidiu(disc)->numDirs;		vat20->logicalVolIdent[127] = strlen(vat20->logicalVolIdent);		insert_data(disc, ext, vtable, data);		data = alloc_data(disc->vat, disc->vat_entries * sizeof(uint32_t));		insert_data(disc, ext, vtable, data);	}	else	{		vtable = udf_create(disc, ext, UDF_ID_ALLOC, strlen(UDF_ID_ALLOC), offset, NULL, FID_FILE_CHAR_HIDDEN, ICBTAG_FILE_TYPE_UNDEF, 0);		len = sizeof(struct virtualAllocationTable15);		data = alloc_data(disc->vat, disc->vat_entries * sizeof(uint32_t));		insert_data(disc, ext, vtable, data);		data = alloc_data(&default_vat15, len);		vat15 = data->buffer;		((uint16_t *)vat15->vatIdent.identSuffix)[0] = cpu_to_le16(disc->udf_rev);		insert_data(disc, ext, vtable, data);	}}void add_type1_partition(struct udf_disc *disc, uint16_t partitionNum){	struct genericPartitionMap1 *pm;	int mtl = le32_to_cpu(disc->udf_lvd[0]->mapTableLength);	int npm = le32_to_cpu(disc->udf_lvd[0]->numPartitionMaps);	disc->udf_lvd[0] = realloc(disc->udf_lvd[0],		sizeof(struct logicalVolDesc) + mtl +		sizeof(struct genericPartitionMap1));	pm = (struct genericPartitionMap1 *)&disc->udf_lvd[0]->partitionMaps[mtl];	mtl += sizeof(struct genericPartitionMap1);	disc->udf_lvd[0]->mapTableLength = cpu_to_le32(mtl);	disc->udf_lvd[0]->numPartitionMaps = cpu_to_le32(npm + 1);	pm->partitionMapType = 1;	pm->partitionMapLength = sizeof(struct genericPartitionMap1);	pm->volSeqNum = cpu_to_le16(1);	pm->partitionNum = cpu_to_le16(partitionNum);	disc->udf_lvid->numOfPartitions = cpu_to_le32(npm + 1);	disc->udf_lvid = realloc(disc->udf_lvid,		sizeof(struct logicalVolIntegrityDesc) +		sizeof(uint32_t) * 2 * (npm + 1) +		sizeof(struct logicalVolIntegrityDescImpUse));	memmove(&disc->udf_lvid->impUse[sizeof(uint32_t) * 2 * (npm + 1)],		&disc->udf_lvid->impUse[sizeof(uint32_t) * 2 * npm],		sizeof(struct logicalVolIntegrityDescImpUse));	memmove(&disc->udf_lvid->impUse[sizeof(uint32_t) * (npm + 1)],		&disc->udf_lvid->impUse[sizeof(uint32_t) * npm],		sizeof(uint32_t));}void add_type2_sparable_partition(struct udf_disc *disc, uint16_t partitionNum, uint8_t spartable, uint16_t packetlen){	struct sparablePartitionMap *pm;	int mtl = le32_to_cpu(disc->udf_lvd[0]->mapTableLength);	int npm = le32_to_cpu(disc->udf_lvd[0]->numPartitionMaps);	disc->udf_lvd[0] = realloc(disc->udf_lvd[0],		sizeof(struct logicalVolDesc) + mtl +		sizeof(struct sparablePartitionMap));	pm = (struct sparablePartitionMap *)&disc->udf_lvd[0]->partitionMaps[mtl];	mtl += sizeof(struct sparablePartitionMap);	disc->udf_lvd[0]->mapTableLength = cpu_to_le32(mtl);	disc->udf_lvd[0]->numPartitionMaps = cpu_to_le32(npm + 1);	memcpy(pm, &default_sparmap, sizeof(struct sparablePartitionMap));	pm->partitionNum = cpu_to_le16(partitionNum);	((uint16_t *)pm->partIdent.identSuffix)[0] = cpu_to_le16(disc->udf_rev);	if (packetlen)		pm->packetLength = cpu_to_le16(packetlen);	pm->numSparingTables = spartable;	pm->sizeSparingTable = cpu_to_le32(sizeof(struct sparingTable));	disc->udf_lvid->numOfPartitions = cpu_to_le32(npm + 1);	disc->udf_lvid = realloc(disc->udf_lvid,		sizeof(struct logicalVolIntegrityDesc) +		sizeof(uint32_t) * 2 * (npm + 1) +		sizeof(struct logicalVolIntegrityDescImpUse));	memmove(&disc->udf_lvid->impUse[sizeof(uint32_t) * 2 * (npm + 1)],		&disc->udf_lvid->impUse[sizeof(uint32_t) * 2 * npm],		sizeof(struct logicalVolIntegrityDescImpUse));	memmove(&disc->udf_lvid->impUse[sizeof(uint32_t) * (npm + 1)],		&disc->udf_lvid->impUse[sizeof(uint32_t) * npm],		sizeof(uint32_t));}struct sparablePartitionMap *find_type2_sparable_partition(struct udf_disc *disc, uint16_t partitionNum){	int i, npm, mtl = 0;	struct genericPartitionMap *pm;	struct udfPartitionMap2 *pm2;	struct sparablePartitionMap *spm;	npm = le32_to_cpu(disc->udf_lvd[0]->numPartitionMaps);	for (i=0; i<npm; i++)	{		pm = (struct genericPartitionMap *)&disc->udf_lvd[0]->partitionMaps[mtl];		if (pm->partitionMapType == 2)		{			pm2 = (struct udfPartitionMap2 *)&disc->udf_lvd[0]->partitionMaps[mtl];			if (!strncmp(pm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE)))			{				spm = (struct sparablePartitionMap *)&disc->udf_lvd[0]->partitionMaps[mtl];				if (le16_to_cpu(spm->partitionNum) == partitionNum)					return spm;			}		}		mtl += pm->partitionMapLength;	}	return NULL;}void add_type2_virtual_partition(struct udf_disc *disc, uint16_t partitionNum){	struct virtualPartitionMap *pm;	int mtl = le32_to_cpu(disc->udf_lvd[0]->mapTableLength);	int npm = le32_to_cpu(disc->udf_lvd[0]->numPartitionMaps);	disc->udf_lvd[0] = realloc(disc->udf_lvd[0],		sizeof(struct logicalVolDesc) + mtl +		sizeof(struct virtualPartitionMap));	pm = (struct virtualPartitionMap *)&disc->udf_lvd[0]->partitionMaps[mtl];	mtl += sizeof(struct virtualPartitionMap);	disc->udf_lvd[0]->mapTableLength = cpu_to_le32(mtl);	disc->udf_lvd[0]->numPartitionMaps = cpu_to_le32(npm + 1);	memcpy(pm, &default_virtmap, sizeof(struct virtualPartitionMap));	pm->partitionNum = cpu_to_le16(partitionNum);	((uint16_t *)pm->partIdent.identSuffix)[0] = cpu_to_le16(disc->udf_rev);	disc->udf_lvid->numOfPartitions = cpu_to_le32(npm + 1);	disc->udf_lvid = realloc(disc->udf_lvid,		sizeof(struct logicalVolIntegrityDesc) +		sizeof(uint32_t) * 2 * (npm + 1) +		sizeof(struct logicalVolIntegrityDescImpUse));	memmove(&disc->udf_lvid->impUse[sizeof(uint32_t) * 2 * (npm + 1)],		&disc->udf_lvid->impUse[sizeof(uint32_t) * 2 * npm],		sizeof(struct logicalVolIntegrityDescImpUse));	memmove(&disc->udf_lvid->impUse[sizeof(uint32_t) * (npm + 1)],		&disc->udf_lvid->impUse[sizeof(uint32_t) * npm],		sizeof(uint32_t));}	char *udf_space_type_str[UDF_SPACE_TYPE_SIZE] = { "RESERVED", "VRS", "ANCHOR", "PVDS", "RVDS", "LVID", "STABLE", "SSPACE", "PSPACE", "USPACE", "BAD" };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -