4343 * which is not an error as such. This is -ENOENT. It means that @vcn is out
4444 * of bounds of the runlist.
4545 *
46+ * Note the runlist can be NULL after this function returns if @vcn is zero and
47+ * the attribute has zero allocated size, i.e. there simply is no runlist.
48+ *
4649 * Locking: - The runlist must be locked for writing.
4750 * - This function modifies the runlist.
4851 */
@@ -54,6 +57,7 @@ int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn)
5457 ATTR_RECORD * a ;
5558 ntfs_attr_search_ctx * ctx ;
5659 runlist_element * rl ;
60+ unsigned long flags ;
5761 int err = 0 ;
5862
5963 ntfs_debug ("Mapping runlist part containing vcn 0x%llx." ,
@@ -85,8 +89,11 @@ int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn)
8589 * ntfs_mapping_pairs_decompress() fails.
8690 */
8791 end_vcn = sle64_to_cpu (a -> data .non_resident .highest_vcn ) + 1 ;
88- if (unlikely (!a -> data .non_resident .lowest_vcn && end_vcn <= 1 ))
92+ if (unlikely (!a -> data .non_resident .lowest_vcn && end_vcn <= 1 )) {
93+ read_lock_irqsave (& ni -> size_lock , flags );
8994 end_vcn = ni -> allocated_size >> ni -> vol -> cluster_size_bits ;
95+ read_unlock_irqrestore (& ni -> size_lock , flags );
96+ }
9097 if (unlikely (vcn >= end_vcn )) {
9198 err = - ENOENT ;
9299 goto err_out ;
@@ -165,6 +172,7 @@ LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
165172 const BOOL write_locked )
166173{
167174 LCN lcn ;
175+ unsigned long flags ;
168176 BOOL is_retry = FALSE;
169177
170178 ntfs_debug ("Entering for i_ino 0x%lx, vcn 0x%llx, %s_locked." ,
@@ -173,6 +181,14 @@ LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
173181 BUG_ON (!ni );
174182 BUG_ON (!NInoNonResident (ni ));
175183 BUG_ON (vcn < 0 );
184+ if (!ni -> runlist .rl ) {
185+ read_lock_irqsave (& ni -> size_lock , flags );
186+ if (!ni -> allocated_size ) {
187+ read_unlock_irqrestore (& ni -> size_lock , flags );
188+ return LCN_ENOENT ;
189+ }
190+ read_unlock_irqrestore (& ni -> size_lock , flags );
191+ }
176192retry_remap :
177193 /* Convert vcn to lcn. If that fails map the runlist and retry once. */
178194 lcn = ntfs_rl_vcn_to_lcn (ni -> runlist .rl , vcn );
@@ -255,6 +271,7 @@ LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
255271runlist_element * ntfs_attr_find_vcn_nolock (ntfs_inode * ni , const VCN vcn ,
256272 const BOOL write_locked )
257273{
274+ unsigned long flags ;
258275 runlist_element * rl ;
259276 int err = 0 ;
260277 BOOL is_retry = FALSE;
@@ -265,6 +282,14 @@ runlist_element *ntfs_attr_find_vcn_nolock(ntfs_inode *ni, const VCN vcn,
265282 BUG_ON (!ni );
266283 BUG_ON (!NInoNonResident (ni ));
267284 BUG_ON (vcn < 0 );
285+ if (!ni -> runlist .rl ) {
286+ read_lock_irqsave (& ni -> size_lock , flags );
287+ if (!ni -> allocated_size ) {
288+ read_unlock_irqrestore (& ni -> size_lock , flags );
289+ return ERR_PTR (- ENOENT );
290+ }
291+ read_unlock_irqrestore (& ni -> size_lock , flags );
292+ }
268293retry_remap :
269294 rl = ni -> runlist .rl ;
270295 if (likely (rl && vcn >= rl [0 ].vcn )) {
@@ -528,6 +553,11 @@ int load_attribute_list(ntfs_volume *vol, runlist *runlist, u8 *al_start,
528553 block_size_bits = sb -> s_blocksize_bits ;
529554 down_read (& runlist -> lock );
530555 rl = runlist -> rl ;
556+ if (!rl ) {
557+ ntfs_error (sb , "Cannot read attribute list since runlist is "
558+ "missing." );
559+ goto err_out ;
560+ }
531561 /* Read all clusters specified by the runlist one run at a time. */
532562 while (rl -> length ) {
533563 lcn = ntfs_rl_vcn_to_lcn (rl , rl -> vcn );
0 commit comments