📄 udf_getudf.c
字号:
} else { /* VAT entry is in some next extent */ if (unresolvedValue > (pVAT_struct->VATEntryBeginningIndex + (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength))) { while (unresolvedValue > (pVAT_struct->VATEntryBeginningIndex + (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength))) { pVAT_struct->VATEntryBeginningIndex += (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength); (pVAT_struct->DescriptorIndex)++; if ((pVAT_struct->DescriptorIndex) >= (pVAT_struct->NumberOfDescriptors)) { /* unresolved value isn't in VAT */ *pResolvedValue = unresolvedValue; /* rewind back to previous values, bcs the VAT entries are still stored in buffer */ (pVAT_struct->DescriptorIndex)--; pVAT_struct->VATEntryBeginningIndex -= (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength); return E_UDF_UNRESOLVED_ENTRY; //??? } } error = UDF_tread(did, pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extPosition, 1, pBuffer, 1); if (error != S_OK) return error; } } /* now we can solve the Value */ resolvedValueTmp = pBuffer[sizeof(UDF_VatEntry)*(unresolvedValue - pVAT_struct->VATEntryBeginningIndex)]; break; } case UDF_DATA_IN_EXTENT_DESC: /* 3 */ { /* The information length is 64 bits * or take the length of alloc descp instead of information * length to be done */ /* no.of the entries [2.2.10, udf150, pp.35] */ *noOfEntries = (pFileEntry->informationLength[0] - 36)/4; //??? 0 or 1 /* If the unresolved value exceeds the number of vat entries * it means that there is no appropriate entry */ if (unresolvedValue > *noOfEntries) { resolvedValueTmp = unresolvedValue; // error? ??? result = E_UDF_UNRESOLVED_ENTRY; //??? } else { /* The total length of a File Entry shall not exceed the size of one Logical Block */ lengthExtendedAttr = pFileEntry->lengthExtendedAttr; /* The resolved value can be found by directly indexing * into the VAT entries */ resolvedValueTmp = *((uint32*)((uint8*)(pFileEntry+1) + lengthExtendedAttr + unresolvedValue*sizeof(UDF_VatEntry))); //??? } break; } default: resolvedValueTmp = unresolvedValue; result = E_UDF_UNRESOLVED_ENTRY; //??? } *pResolvedValue = resolvedValueTmp; return result;} /* UDF_resolveVAT15Address *//* * Function Name : UDF_resolveVAT20Address * * Description : Resolves address whatever from Virt. alloc table for type V2.0,V2.01 * * Parameters : DUID did - device identifier * uint32 unresolvedValue - input value * VAT_struct* pVAT_struct - info about VAT * uint16* pBuffer - buffer containing (allocated for VAT) * * Return Value : uint32* pResolvedValue - resolved val */GRESULT UDF_resolveVAT20Address(DUID did, uint32 unresolvedValue, VAT_struct* pVAT_struct, uint8* pBuffer, uint32* pResolvedValue){ GRESULT error; GRESULT result = S_OK; UDF_FileEntry_i* pFileEntry; /* pointer to file entry */ UDF_ExtAD* pAD; UDF_VAT_i* pVAT; /* Used to store the value read from buffer */ uint32 resolvedValueTmp; //uint32 temp; // [RB] unused uint32 lengthExtendedAttr, lengthVATheader; uint16 counter; UDF_ALLOC_DESC_FLAG desc_flags; uint32* noOfEntries = &(pVAT_struct->noOfEntries);// /* first has to be parsed ICB ( flag from ICB tag is checked ) */// icb_flags = pFileEntry->fe[UDF_ICB_FLAGS_OFFSET]; //prehistorical desc_flags = (UDF_ALLOC_DESC_FLAG)pVAT_struct->flags; /* Extract the first 3 bits and interpret the value * If the value is 0 Short Allocation Descriptors are used * If the value is 1 Long Allocation Descriptors are used * If the value is 2 Extended Allocation Descriptors are used * If the value is 3 the data is recorded as one extent */ /* Get the first 3 bits and store the value in desc_flags */ /* The information length is 64 bits * or take the length of alloc descp instead of information * length To be done */ switch(desc_flags) { case UDF_LONG_ALLOC_DESC: /* 1 */ { if (*noOfEntries <= 0) { /* there wasn't calculated number of VAT entries before */ *noOfEntries = 0; /* Read the first VAT location to get header of VAT */ error = UDF_tread(did, pVAT_struct->VATAllocationDescriptorsTable[0].extPosition, 1, pBuffer, 1); if (error != S_OK) return error; pVAT = (UDF_VAT_i*)pBuffer; /* calculate lenght of VAT header */ lengthVATheader = sizeof(UDF_VAT_i) + pVAT->lengthOfImplUse; /* in first VAT record decrease extLength by the VAT header */ pVAT_struct->VATAllocationDescriptorsTable[0].extLength -= lengthVATheader; /* in the VAT recalculate the extLength to number of VAT entries */ for (counter=0; counter < (pVAT_struct->NumberOfDescriptors); counter++) { pVAT_struct->VATAllocationDescriptorsTable[counter].extLength = pVAT_struct->VATAllocationDescriptorsTable[counter].extLength/4; *noOfEntries += pVAT_struct->VATAllocationDescriptorsTable[counter].extLength; } } if (unresolvedValue < (pVAT_struct->VATEntryBeginningIndex)) { /* VAT entry is in some previous extent */ while (unresolvedValue< (pVAT_struct->VATEntryBeginningIndex)) { (pVAT_struct->DescriptorIndex)--; pVAT_struct->VATEntryBeginningIndex-= (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength); } error = UDF_tread(did, pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extPosition, 1, pBuffer, 1); if (error != S_OK) return error; } else { /* VAT entry is in some next extent */ if (unresolvedValue > (pVAT_struct->VATEntryBeginningIndex + (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength))) { while (unresolvedValue > (pVAT_struct->VATEntryBeginningIndex + (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength))) { pVAT_struct->VATEntryBeginningIndex += (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength); (pVAT_struct->DescriptorIndex)++; if ((pVAT_struct->DescriptorIndex) >= (pVAT_struct->NumberOfDescriptors)) { /* unresolved value isn't in VAT */ *pResolvedValue = unresolvedValue; /* rewind back to previous values, bcs the VAT entries are still stored in buffer */ (pVAT_struct->DescriptorIndex)--; pVAT_struct->VATEntryBeginningIndex -= (pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extLength); return E_UDF_UNRESOLVED_ENTRY; //??? } } error = UDF_tread(did, pVAT_struct->VATAllocationDescriptorsTable[pVAT_struct->DescriptorIndex].extPosition, 1, pBuffer, 1); if (error != S_OK) return error; } } pVAT = (UDF_VAT_i*)pBuffer; /* now we can solve the Value */ if (pVAT_struct->DescriptorIndex == 0) /* first allocation includes VAT header, so skip it */ lengthVATheader = sizeof(UDF_VAT_i) + pVAT->lengthOfImplUse; /* calculate lenght of VAT header */ else lengthVATheader = 0; resolvedValueTmp = *((uint32*)((uint8*)pBuffer + lengthVATheader + sizeof(UDF_VatEntry)*(unresolvedValue - pVAT_struct->VATEntryBeginningIndex))); break; } case UDF_DATA_IN_EXTENT_DESC: /* 3 */ { /* in Buffer already read File entry with VAT */ pFileEntry = (UDF_FileEntry_i*)pBuffer; lengthExtendedAttr = pFileEntry->lengthExtendedAttr; pAD = (UDF_ExtAD*)((uint8*)pBuffer + lengthExtendedAttr); *noOfEntries = (pFileEntry->informationLength[0] - pAD->extLength) / 4; /* If the unresolved value exceeds the number of vat entries * it means that there is no appropriate entry */ if (unresolvedValue > *noOfEntries) { resolvedValueTmp = unresolvedValue; } else { /* To reach the vat entries we have to find the start of * Vat table then from there we have to move along and * find the Vat entries from 152 + LIU */ //temp = UDF_EXT_ATTR_OFFSET + lengthExtendedAttr; /* Its 176 */ //[LL]// temp = sizeof(UDF_FileEntry_i) + lengthExtendedAttr; /* Its 176 */ //[LL] //temp = temp + pFileEntry->fe[temp + 2] + UDF_VAT_IMP_USE_OFFSET; //(ICB header length) + (VAT header length + VAT implementation use length ) //[LL] #if 0 // [RB] set but never used temp = sizeof(UDF_FileEntry_i) + lengthExtendedAttr + pAD->recLength + sizeof(UDF_VAT_i); //[LL] ??? !? #endif /* The resolved value can be found by directly indexing * into the VAT entries */ //UDF_GET_32(pFileEntry->fe[temp + (unresolvedValue * 2)], resolvedValueTmp); //[LL] resolvedValueTmp = *((uint32*)(pAD + pAD->recLength + sizeof(UDF_VAT_i) + unresolvedValue*sizeof(UDF_VatEntry))); //[LL] ??? } break; } default: resolvedValueTmp = unresolvedValue; result = E_UDF_UNRESOLVED_ENTRY; //??? } *pResolvedValue = resolvedValueTmp; return result;} /* UDF_resolveVAT20Address *//* * Function Name : UDF_memcpy * * Description : Copies the number of words from one location * to other location. This function does not take * care of over lapping source and destinations. * * Parameters : pDestination -> points to the destination location. * pSource -> points to the source location. * noOfWords -> no of words to copy. * unitSize -> size of the one element for the 'multi-element' copy * * Return Value : UDF_Error. *///[LL] newGRESULT UDF_memcpy(void* pDestination, void* pSource, uint16 noOfElements){ //uint16 numOfWordsToCopy; //[LL] uint8 tmpCount32, tmpCount8; uint8* pD8; uint8* pS8; uint32* pD32 = (uint32*)pDestination; uint32* pS32 = (uint32*)pSource; if ((pDestination == NULL) || (pSource == NULL) || (noOfElements == UDF_NULL)) {#ifdef UDF_DEBUG DBG_PRINTF("UDF_memcpy: *W - Null length [0x%x] Or Src [0x%x] Or Dst [%d]\r\n", noOfElements, pSource, pDestination);#endif return E_FAIL; } tmpCount32 = ((noOfElements>>2) & 0xFF); tmpCount8 = noOfElements - (tmpCount32<<2); while(tmpCount32--) { *pD32++ = *pS32++; } pD8 = (uint8*)pD32; pS8 = (uint8*)pS32; while(tmpCount8--) { *pD8++ = *pS8++; } return S_OK;} /* UDF_memcpy *//* * Function Name : UDF_tread * * Description : This function gets the sectors from propriate device. * * * Parameters : DUID did - device identifier * uint32 block - LBN * uint16 size - num of data * uint8* pBuffer - data buffer * int index - now unused * * Return Value : S_OK / E_FAIL */GRESULT UDF_tread(DUID did, uint32 block, uint16 size, uint8* pBuffer, int index){ GRESULT error; //error = IO_Read(cdid,fsd->PartitionLBA+volumeDescriptorLba,0,2048,cbuf,6,CD_FAIL_ON_READ_TIMEOUT);#ifdef DEBUGGING error = DEBUG_IO_Read(did, block+TOC_OFFSET_SECTOR, 0, size*2048, (uint8*)pBuffer, 2048, CD_FAIL_ON_READ_TIMEOUT);#else /*DEBUGGING*/#ifdef UDF_DEBUG DBG_PRINTF("LBA = %d : ", block + TOC_OFFSET_SECTOR);#endif /*UDF_DEBUG*/ PREPARE_IOREAD(FS_XFER_command_event, DEV_CD_ID, block+TOC_OFFSET_SECTOR, block+TOC_OFFSET_SECTOR+size-1, 0, 2048, pBuffer, size*2048, IO_READ_IMMEDIATE); error = IO_Read(IO_READ_IMMEDIATE); if (error < 0) { DBG_PRINTF("udf: *E - IOREAD error\r\n"); } DBG_PRINTF("\r\n");#endif /*DEBUGGING*/ return error;} /* UDF_tread *//* * Function Name : UDF_getNode * * Description : This function gets the File Entry data of a particular * node. The file entry is then written onto the buffer. * * * Parameters : pUdfParameters -> Pointer to the udf parameters * structure * uint32 blockNo - This parameter points to the logical block number of the FE. * uint8 pBuffer - Buffer to read File Entry. * * Return Value : S_UDF_FILE_ENTRY_FOUND * E_UDF_FILE_ENTRY_NOT_FOUND * error from subfunc - S_OK / E_FAIL */GRESULT UDF_getNode(DUID did, uint32 blockNo, uint8* pBuffer){ GRESULT error; UDF_Tag* pFileEntryTag; error = UDF_tread(did, blockNo, 1, pBuffer, 1); if (error < 0) { /* Read error */ return error; } pFileEntryTag = (UDF_Tag*)pBuffer; if (pFileEntryTag->tagIdent == UDF_FILE_ENTRY_TAG261) { return S_UDF_FILE_ENTRY_FOUND; } else { return E_FAIL;// return E_UDF_FILE_ENTRY_NOT_FOUND; }} /* UDF_getNode *//* * Function Name : UDF_addPartitionLocations * * Description : This function adds the partition location to the * different locations in pADTableTmp. * * Parameters : UDF_ShortAD* pAddressBuffer - pointer to buffer which has the length * and locations consecutively * uint32 numberOfADs - no of allocation descriptors in pADTableTmp * uint32 partLoc - the partition location to be added * * Return Value : Void */void UDF_addPartitionLocations( UDF_ShortAD* pAddressBuffer, uint32 numberOfADs, uint32 partLoc){ uint16 countAD; UDF_ShortAD* pADTableTmp; if (pAddressBuffer == NULL) { return; } pADTableTmp = pAddressBuffer; for(countAD = 0; countAD < numberOfADs; countAD++) { pADTableTmp->extPosition += partLoc; pADTableTmp++; }} /* UDF_addPartitionLocations *//* * Function Name : UDF_findNumDesc * * Description : This function finds the number of long or extended allocation descriptors in the given file entry. * * Parameters : uint8* pBuff - pointer in the FE from where the AD starts * UDF_ALLOC_DESC_FLAG desc_flags - * * * * Return Value : uint16 */uint16 UDF_findNumDesc(uint8* pBuff, UDF_ALLOC_DESC_FLAG desc_flags){ uint16 noOfDesc = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -