diff options
Diffstat (limited to 'fs/ubifs/tnc.c')
-rw-r--r-- | fs/ubifs/tnc.c | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index f249f7b0d656..e5b1a7d00fa0 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c | |||
@@ -1159,8 +1159,8 @@ static struct ubifs_znode *dirty_cow_bottom_up(struct ubifs_info *c, | |||
1159 | * o exact match, i.e. the found zero-level znode contains key @key, then %1 | 1159 | * o exact match, i.e. the found zero-level znode contains key @key, then %1 |
1160 | * is returned and slot number of the matched branch is stored in @n; | 1160 | * is returned and slot number of the matched branch is stored in @n; |
1161 | * o not exact match, which means that zero-level znode does not contain | 1161 | * 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 | 1162 | * @key, then %0 is returned and slot number of the closest branch is stored |
1163 | * in @n; | 1163 | * in @n; |
1164 | * o @key is so small that it is even less than the lowest key of the | 1164 | * o @key is so small that it is even less than the lowest key of the |
1165 | * leftmost zero-level node, then %0 is returned and %0 is stored in @n. | 1165 | * leftmost zero-level node, then %0 is returned and %0 is stored in @n. |
1166 | * | 1166 | * |
@@ -1433,7 +1433,7 @@ static int maybe_leb_gced(struct ubifs_info *c, int lnum, int gc_seq1) | |||
1433 | * @lnum: LEB number is returned here | 1433 | * @lnum: LEB number is returned here |
1434 | * @offs: offset is returned here | 1434 | * @offs: offset is returned here |
1435 | * | 1435 | * |
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 |
1437 | * sure the @node buffer is large enough to fit the node. Returns zero in case | 1437 | * sure the @node buffer is large enough to fit the node. Returns zero in case |
1438 | * of success, %-ENOENT if the node was not found, and a negative error code in | 1438 | * of success, %-ENOENT if the node was not found, and a negative error code in |
1439 | * case of failure. The node location can be returned in @lnum and @offs. | 1439 | * case of failure. The node location can be returned in @lnum and @offs. |
@@ -3268,3 +3268,73 @@ out_unlock: | |||
3268 | mutex_unlock(&c->tnc_mutex); | 3268 | mutex_unlock(&c->tnc_mutex); |
3269 | return err; | 3269 | return err; |
3270 | } | 3270 | } |
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 */ | ||