@@ -1159,8 +1159,8 @@ static struct ubifs_znode *dirty_cow_bottom_up(struct ubifs_info *c,
11591159 * o exact match, i.e. the found zero-level znode contains key @key, then %1
11601160 * is returned and slot number of the matched branch is stored in @n;
11611161 * o not exact match, which means that zero-level znode does not contain
1162- * @key, then %0 is returned and slot number of the closed branch is stored
1163- * in @n;
1162+ * @key, then %0 is returned and slot number of the closest branch is stored
1163+ * in @n;
11641164 * o @key is so small that it is even less than the lowest key of the
11651165 * leftmost zero-level node, then %0 is returned and %0 is stored in @n.
11661166 *
@@ -1433,7 +1433,7 @@ static int maybe_leb_gced(struct ubifs_info *c, int lnum, int gc_seq1)
14331433 * @lnum: LEB number is returned here
14341434 * @offs: offset is returned here
14351435 *
1436- * This function look up and reads node with key @key. The caller has to make
1436+ * This function looks up and reads node with key @key. The caller has to make
14371437 * sure the @node buffer is large enough to fit the node. Returns zero in case
14381438 * of success, %-ENOENT if the node was not found, and a negative error code in
14391439 * case of failure. The node location can be returned in @lnum and @offs.
@@ -3268,3 +3268,73 @@ int ubifs_dirty_idx_node(struct ubifs_info *c, union ubifs_key *key, int level,
32683268 mutex_unlock (& c -> tnc_mutex );
32693269 return err ;
32703270}
3271+
3272+ #ifdef CONFIG_UBIFS_FS_DEBUG
3273+
3274+ /**
3275+ * dbg_check_inode_size - check if inode size is correct.
3276+ * @c: UBIFS file-system description object
3277+ * @inum: inode number
3278+ * @size: inode size
3279+ *
3280+ * This function makes sure that the inode size (@size) is correct and it does
3281+ * not have any pages beyond @size. Returns zero if the inode is OK, %-EINVAL
3282+ * if it has a data page beyond @size, and other negative error code in case of
3283+ * other errors.
3284+ */
3285+ int dbg_check_inode_size (struct ubifs_info * c , const struct inode * inode ,
3286+ loff_t size )
3287+ {
3288+ int err , n ;
3289+ union ubifs_key from_key , to_key , * key ;
3290+ struct ubifs_znode * znode ;
3291+ unsigned int block ;
3292+
3293+ if (!S_ISREG (inode -> i_mode ))
3294+ return 0 ;
3295+ if (!(ubifs_chk_flags & UBIFS_CHK_GEN ))
3296+ return 0 ;
3297+
3298+ block = (size + UBIFS_BLOCK_SIZE - 1 ) >> UBIFS_BLOCK_SHIFT ;
3299+ data_key_init (c , & from_key , inode -> i_ino , block );
3300+ highest_data_key (c , & to_key , inode -> i_ino );
3301+
3302+ mutex_lock (& c -> tnc_mutex );
3303+ err = ubifs_lookup_level0 (c , & from_key , & znode , & n );
3304+ if (err < 0 )
3305+ goto out_unlock ;
3306+
3307+ if (err ) {
3308+ err = - EINVAL ;
3309+ key = & from_key ;
3310+ goto out_dump ;
3311+ }
3312+
3313+ err = tnc_next (c , & znode , & n );
3314+ if (err == - ENOENT ) {
3315+ err = 0 ;
3316+ goto out_unlock ;
3317+ }
3318+ if (err < 0 )
3319+ goto out_unlock ;
3320+
3321+ ubifs_assert (err == 0 );
3322+ key = & znode -> zbranch [n ].key ;
3323+ if (!key_in_range (c , key , & from_key , & to_key ))
3324+ goto out_unlock ;
3325+
3326+ out_dump :
3327+ block = key_block (c , key );
3328+ ubifs_err ("inode %lu has size %lld, but there are data at offset %lld "
3329+ "(data key %s)" , (unsigned long )inode -> i_ino , size ,
3330+ ((loff_t )block ) << UBIFS_BLOCK_SHIFT , DBGKEY (key ));
3331+ dbg_dump_inode (c , inode );
3332+ dbg_dump_stack ();
3333+ err = - EINVAL ;
3334+
3335+ out_unlock :
3336+ mutex_unlock (& c -> tnc_mutex );
3337+ return err ;
3338+ }
3339+
3340+ #endif /* CONFIG_UBIFS_FS_DEBUG */
0 commit comments