📄 super.c
字号:
if (le16_to_cpu(((Uint16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) { UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15; UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15; } else if (le16_to_cpu(((Uint16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) { UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20; UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20; } } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) { Uint32 loc; Uint16 ident; struct SparingTable *st; struct SparablePartitionMap *spm = (struct SparablePartitionMap *)&(lvd->partitionMaps[offset]); UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15; UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength); for (j=0; j<spm->numSparingTables; j++) { loc = le32_to_cpu(spm->locSparingTable[j]); UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = udf_read_tagged(sb, loc, loc, &ident); if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) { st = (struct SparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data; if (ident != 0 || strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) { udf_release_data(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]); UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL; } } } UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15; } else { udf_debug("Unknown ident: %s\n", upm2->partIdent.ident); continue; } UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum); UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum); } udf_debug("Partition (%d:%d) type %d on volume %d\n", i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i)); } if (fileset) { long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]); *fileset = lelb_to_cpu(la->extLocation); udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n", fileset->logicalBlockNum, fileset->partitionReferenceNum); } if (lvd->integritySeqExt.extLength) udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); return 0;}/* * udf_load_logicalvolint * */static voidudf_load_logicalvolint(struct super_block *sb, extent_ad loc){ struct buffer_head *bh = NULL; Uint16 ident; while (loc.extLength > 0 && (bh = udf_read_tagged(sb, loc.extLocation, loc.extLocation, &ident)) && ident == TID_LOGICAL_VOL_INTEGRITY_DESC) { UDF_SB_LVIDBH(sb) = bh; if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength) udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt)); if (UDF_SB_LVIDBH(sb) != bh) udf_release_data(bh); loc.extLength -= sb->s_blocksize; loc.extLocation ++; } if (UDF_SB_LVIDBH(sb) != bh) udf_release_data(bh);}/* * udf_process_sequence * * PURPOSE * Process a main/reserve volume descriptor sequence. * * PRE-CONDITIONS * sb Pointer to _locked_ superblock. * block First block of first extent of the sequence. * lastblock Lastblock of first extent of the sequence. * * HISTORY * July 1, 1997 - Andrew E. Mileski * Written, tested, and released. */static intudf_process_sequence(struct super_block *sb, long block, long lastblock, lb_addr *fileset){ struct buffer_head *bh = NULL; struct udf_vds_record vds[VDS_POS_LENGTH]; struct GenericDesc *gd; struct VolDescPtr *vdp; int done=0; int i,j; Uint32 vdsn; Uint16 ident; long next_s = 0, next_e = 0; memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); /* Read the main descriptor sequence */ for (;(!done && block <= lastblock); block++) { bh = udf_read_tagged(sb, block, block, &ident); if (!bh) break; /* Process each descriptor (ISO 13346 3/8.3-8.4) */ gd = (struct GenericDesc *)bh->b_data; vdsn = le32_to_cpu(gd->volDescSeqNum); switch (ident) { case TID_PRIMARY_VOL_DESC: /* ISO 13346 3/10.1 */ if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) { vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; vds[VDS_POS_PRIMARY_VOL_DESC].block = block; } break; case TID_VOL_DESC_PTR: /* ISO 13346 3/10.3 */ if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) { vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; vds[VDS_POS_VOL_DESC_PTR].block = block; vdp = (struct VolDescPtr *)bh->b_data; next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); next_e = next_e >> sb->s_blocksize_bits; next_e += next_s; } break; case TID_IMP_USE_VOL_DESC: /* ISO 13346 3/10.4 */ if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) { vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; vds[VDS_POS_IMP_USE_VOL_DESC].block = block; } break; case TID_PARTITION_DESC: /* ISO 13346 3/10.5 */ if (!vds[VDS_POS_PARTITION_DESC].block) vds[VDS_POS_PARTITION_DESC].block = block; break; case TID_LOGICAL_VOL_DESC: /* ISO 13346 3/10.6 */ if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) { vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; vds[VDS_POS_LOGICAL_VOL_DESC].block = block; } break; case TID_UNALLOC_SPACE_DESC: /* ISO 13346 3/10.8 */ if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) { vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; } break; case TID_TERMINATING_DESC: /* ISO 13346 3/10.9 */ vds[VDS_POS_TERMINATING_DESC].block = block; if (next_e) { block = next_s; lastblock = next_e; next_s = next_e = 0; } else done = 1; break; } udf_release_data(bh); } for (i=0; i<VDS_POS_LENGTH; i++) { if (vds[i].block) { bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident); if (i == VDS_POS_PRIMARY_VOL_DESC) udf_load_pvoldesc(sb, bh); else if (i == VDS_POS_LOGICAL_VOL_DESC) udf_load_logicalvol(sb, bh, fileset); else if (i == VDS_POS_PARTITION_DESC) { struct buffer_head *bh2 = NULL; udf_load_partdesc(sb, bh); for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++) { bh2 = udf_read_tagged(sb, j, j, &ident); gd = (struct GenericDesc *)bh2->b_data; if (ident == TID_PARTITION_DESC) udf_load_partdesc(sb, bh2); udf_release_data(bh2); } } udf_release_data(bh); } } return 0;}/* * udf_check_valid() */static intudf_check_valid(struct super_block *sb, int novrs, int silent){ long block; if (novrs) { udf_debug("Validity check skipped because of novrs option\n"); return 0; } /* Check that it is NSR02 compliant */ /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ else if ((block = udf_vrs(sb, silent)) == -1) { udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n"); if (!UDF_SB_LASTBLOCK(sb)) UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); return 0; } else return !block;}static intudf_load_partition(struct super_block *sb, lb_addr *fileset){ struct AnchorVolDescPtr *anchor; Uint16 ident; struct buffer_head *bh; long main_s, main_e, reserve_s, reserve_e; int i, j; if (!sb) return 1; for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++) { if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident))) { anchor = (struct AnchorVolDescPtr *)bh->b_data; /* Locate the main sequence */ main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation ); main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength ); main_e = main_e >> sb->s_blocksize_bits; main_e += main_s; /* Locate the reserve sequence */ reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); reserve_e = reserve_e >> sb->s_blocksize_bits; reserve_e += reserve_s; udf_release_data(bh); /* Process the main & reserve sequences */ /* responsible for finding the PartitionDesc(s) */ if (!(udf_process_sequence(sb, main_s, main_e, fileset) && udf_process_sequence(sb, reserve_s, reserve_e, fileset))) { break; } } } if (i == sizeof(UDF_SB_ANCHOR(sb))/sizeof(int)) { udf_debug("No Anchor block found\n"); return 1; } else udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]); for (i=0; i<UDF_SB_NUMPARTS(sb); i++) { switch UDF_SB_PARTTYPE(sb, i) { case UDF_VIRTUAL_MAP15: case UDF_VIRTUAL_MAP20: { lb_addr ino; if (!UDF_SB_LASTBLOCK(sb)) { UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); udf_find_anchor(sb); } if (!UDF_SB_LASTBLOCK(sb)) { udf_debug("Unable to determine Lastblock (For Virtual Partition)\n"); return 1; } for (j=0; j<UDF_SB_NUMPARTS(sb); j++) { if (j != i && UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) && UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j)) { ino.partitionReferenceNum = j; ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) - UDF_SB_PARTROOT(sb,j); break; } } if (j == UDF_SB_NUMPARTS(sb)) return 1; if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino))) return 1; if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15) { UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb)); UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2; } else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20) { struct buffer_head *bh = NULL; Uint32 pos; pos = udf_block_map(UDF_SB_VAT(sb), 0); bh = sb_bread(sb, pos); UDF_SB_TYPEVIRT(sb,i).s_start_offset = le16_to_cpu(((struct VirtualAllocationTable20 *)bh->b_data + udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) + udf_ext0_offset(UDF_SB_VAT(sb)); UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2; udf_release_data(bh); } UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0); UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum); } } } return 0;}static void udf_open_lvid(struct super_block *sb){ if (UDF_SB_LVIDBH(sb)) { int i; timestamp cpu_time; UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; if (udf_time_to_stamp(&cpu_time, CURRENT_TIME, CURRENT_UTIME)) UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); UDF_SB_LVID(sb)->integrityType = INTEGRITY_TYPE_OPEN; UDF_SB_LVID(sb)->descTag.descCRC = cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); UDF_SB_LVID(sb)->descTag.tagChecksum = 0; for (i=0; i<16; i++) if (i != 4) UDF_SB_LVID(sb)->descTag.tagChecksum += ((Uint8 *)&(UDF_SB_LVID(sb)->descTag))[i]; mark_buffer_dirty(UDF_SB_LVIDBH(sb)); }}static void udf_close_lvid(struct super_block *sb){ if (UDF_SB_LVIDBH(sb) && UDF_SB_LVID(sb)->integrityType == INTEGRITY_TYPE_OPEN) { int i; timestamp cpu_time; UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; if (udf_time_to_stamp(&cpu_time, CURRENT_TIME, CURRENT_UTIME)) UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev)) UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev)) UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb)); if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev)) UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb)); UDF_SB_LVID(sb)->integrityType = INTEGRITY_TYPE_CLOSE; UDF_SB_LVID(sb)->descTag.descCRC = cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); UDF_SB_LVID(sb)->descTag.tagChecksum = 0; for (i=0; i<16; i++) if (i != 4) UDF_SB_LVID(sb)->descTag.tagChecksum += ((Uint8 *)&(UDF_SB_LVID(sb)->descTag))[i]; mark_buffer_dirty(UDF_SB_LVIDBH(sb)); }}/* * udf_read_super * * PURPOSE * Complete the specified super block. * * PRE-CONDITIONS * sb Pointer to superblock to complete - never NULL. * sb->s_dev Device to read suberblock from. * options Pointer to mount options. * silent Silent flag. * * HISTORY * July 1, 1997 - Andrew E. Mileski * Written, tested, and released. */static struct super_block *udf_read_super(struct super_block *sb, void *options, int silent){ int i; struct inode *inode=NULL; struct udf_options uopt; lb_addr rootdir, fileset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -