6868 VDS_POS_PRIMARY_VOL_DESC ,
6969 VDS_POS_UNALLOC_SPACE_DESC ,
7070 VDS_POS_LOGICAL_VOL_DESC ,
71- VDS_POS_PARTITION_DESC ,
7271 VDS_POS_IMP_USE_VOL_DESC ,
73- VDS_POS_TERMINATING_DESC ,
7472 VDS_POS_LENGTH
7573};
7674
@@ -1593,18 +1591,57 @@ static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_
15931591 sbi -> s_lvid_bh = NULL ;
15941592}
15951593
1596- static struct udf_vds_record * get_volume_descriptor_record (
1597- struct udf_vds_record * vds , uint16_t ident )
1594+ /*
1595+ * Step for reallocation of table of partition descriptor sequence numbers.
1596+ * Must be power of 2.
1597+ */
1598+ #define PART_DESC_ALLOC_STEP 32
1599+
1600+ struct desc_seq_scan_data {
1601+ struct udf_vds_record vds [VDS_POS_LENGTH ];
1602+ unsigned int size_part_descs ;
1603+ struct udf_vds_record * part_descs_loc ;
1604+ };
1605+
1606+ static struct udf_vds_record * handle_partition_descriptor (
1607+ struct buffer_head * bh ,
1608+ struct desc_seq_scan_data * data )
1609+ {
1610+ struct partitionDesc * desc = (struct partitionDesc * )bh -> b_data ;
1611+ int partnum ;
1612+
1613+ partnum = le16_to_cpu (desc -> partitionNumber );
1614+ if (partnum >= data -> size_part_descs ) {
1615+ struct udf_vds_record * new_loc ;
1616+ unsigned int new_size = ALIGN (partnum , PART_DESC_ALLOC_STEP );
1617+
1618+ new_loc = kzalloc (sizeof (* new_loc ) * new_size , GFP_KERNEL );
1619+ if (!new_loc )
1620+ return ERR_PTR (- ENOMEM );
1621+ memcpy (new_loc , data -> part_descs_loc ,
1622+ data -> size_part_descs * sizeof (* new_loc ));
1623+ kfree (data -> part_descs_loc );
1624+ data -> part_descs_loc = new_loc ;
1625+ data -> size_part_descs = new_size ;
1626+ }
1627+ return & (data -> part_descs_loc [partnum ]);
1628+ }
1629+
1630+
1631+ static struct udf_vds_record * get_volume_descriptor_record (uint16_t ident ,
1632+ struct buffer_head * bh , struct desc_seq_scan_data * data )
15981633{
15991634 switch (ident ) {
16001635 case TAG_IDENT_PVD : /* ISO 13346 3/10.1 */
1601- return & vds [VDS_POS_PRIMARY_VOL_DESC ];
1636+ return & ( data -> vds [VDS_POS_PRIMARY_VOL_DESC ]) ;
16021637 case TAG_IDENT_IUVD : /* ISO 13346 3/10.4 */
1603- return & vds [VDS_POS_IMP_USE_VOL_DESC ];
1638+ return & ( data -> vds [VDS_POS_IMP_USE_VOL_DESC ]) ;
16041639 case TAG_IDENT_LVD : /* ISO 13346 3/10.6 */
1605- return & vds [VDS_POS_LOGICAL_VOL_DESC ];
1640+ return & ( data -> vds [VDS_POS_LOGICAL_VOL_DESC ]) ;
16061641 case TAG_IDENT_USD : /* ISO 13346 3/10.8 */
1607- return & vds [VDS_POS_UNALLOC_SPACE_DESC ];
1642+ return & (data -> vds [VDS_POS_UNALLOC_SPACE_DESC ]);
1643+ case TAG_IDENT_PD : /* ISO 13346 3/10.5 */
1644+ return handle_partition_descriptor (bh , data );
16081645 }
16091646 return NULL ;
16101647}
@@ -1624,7 +1661,6 @@ static noinline int udf_process_sequence(
16241661 struct kernel_lb_addr * fileset )
16251662{
16261663 struct buffer_head * bh = NULL ;
1627- struct udf_vds_record vds [VDS_POS_LENGTH ];
16281664 struct udf_vds_record * curr ;
16291665 struct generic_desc * gd ;
16301666 struct volDescPtr * vdp ;
@@ -1633,8 +1669,15 @@ static noinline int udf_process_sequence(
16331669 uint16_t ident ;
16341670 int ret ;
16351671 unsigned int indirections = 0 ;
1636-
1637- memset (vds , 0 , sizeof (struct udf_vds_record ) * VDS_POS_LENGTH );
1672+ struct desc_seq_scan_data data ;
1673+ unsigned int i ;
1674+
1675+ memset (data .vds , 0 , sizeof (struct udf_vds_record ) * VDS_POS_LENGTH );
1676+ data .size_part_descs = PART_DESC_ALLOC_STEP ;
1677+ data .part_descs_loc = kzalloc (sizeof (* data .part_descs_loc ) *
1678+ data .size_part_descs , GFP_KERNEL );
1679+ if (!data .part_descs_loc )
1680+ return - ENOMEM ;
16381681
16391682 /*
16401683 * Read the main descriptor sequence and find which descriptors
@@ -1672,19 +1715,21 @@ static noinline int udf_process_sequence(
16721715 case TAG_IDENT_IUVD : /* ISO 13346 3/10.4 */
16731716 case TAG_IDENT_LVD : /* ISO 13346 3/10.6 */
16741717 case TAG_IDENT_USD : /* ISO 13346 3/10.8 */
1675- curr = get_volume_descriptor_record (vds , ident );
1718+ case TAG_IDENT_PD : /* ISO 13346 3/10.5 */
1719+ curr = get_volume_descriptor_record (ident , bh , & data );
1720+ if (IS_ERR (curr )) {
1721+ brelse (bh );
1722+ return PTR_ERR (curr );
1723+ }
1724+ /* Descriptor we don't care about? */
1725+ if (!curr )
1726+ break ;
16761727 if (vdsn >= curr -> volDescSeqNum ) {
16771728 curr -> volDescSeqNum = vdsn ;
16781729 curr -> block = block ;
16791730 }
16801731 break ;
1681- case TAG_IDENT_PD : /* ISO 13346 3/10.5 */
1682- curr = & vds [VDS_POS_PARTITION_DESC ];
1683- if (!curr -> block )
1684- curr -> block = block ;
1685- break ;
16861732 case TAG_IDENT_TD : /* ISO 13346 3/10.9 */
1687- vds [VDS_POS_TERMINATING_DESC ].block = block ;
16881733 done = true;
16891734 break ;
16901735 }
@@ -1694,31 +1739,27 @@ static noinline int udf_process_sequence(
16941739 * Now read interesting descriptors again and process them
16951740 * in a suitable order
16961741 */
1697- if (!vds [VDS_POS_PRIMARY_VOL_DESC ].block ) {
1742+ if (!data . vds [VDS_POS_PRIMARY_VOL_DESC ].block ) {
16981743 udf_err (sb , "Primary Volume Descriptor not found!\n" );
16991744 return - EAGAIN ;
17001745 }
1701- ret = udf_load_pvoldesc (sb , vds [VDS_POS_PRIMARY_VOL_DESC ].block );
1746+ ret = udf_load_pvoldesc (sb , data . vds [VDS_POS_PRIMARY_VOL_DESC ].block );
17021747 if (ret < 0 )
17031748 return ret ;
17041749
1705- if (vds [VDS_POS_LOGICAL_VOL_DESC ].block ) {
1750+ if (data . vds [VDS_POS_LOGICAL_VOL_DESC ].block ) {
17061751 ret = udf_load_logicalvol (sb ,
1707- vds [VDS_POS_LOGICAL_VOL_DESC ].block ,
1708- fileset );
1752+ data . vds [VDS_POS_LOGICAL_VOL_DESC ].block ,
1753+ fileset );
17091754 if (ret < 0 )
17101755 return ret ;
17111756 }
17121757
1713- if (vds [VDS_POS_PARTITION_DESC ].block ) {
1714- /*
1715- * We rescan the whole descriptor sequence to find
1716- * partition descriptor blocks and process them.
1717- */
1718- for (block = vds [VDS_POS_PARTITION_DESC ].block ;
1719- block < vds [VDS_POS_TERMINATING_DESC ].block ;
1720- block ++ ) {
1721- ret = udf_load_partdesc (sb , block );
1758+ /* Now handle prevailing Partition Descriptors */
1759+ for (i = 0 ; i < data .size_part_descs ; i ++ ) {
1760+ if (data .part_descs_loc [i ].block ) {
1761+ ret = udf_load_partdesc (sb ,
1762+ data .part_descs_loc [i ].block );
17221763 if (ret < 0 )
17231764 return ret ;
17241765 }
0 commit comments