int empty_inline_dir(struct inode *dir, int *has_inline_data) { int err, inline_size; struct ext4_iloc iloc; void *inline_pos; unsigned int offset; struct ext4_dir_entry_2 *de; int ret = 1; err = ext4_get_inode_loc(dir, &iloc); if (err) { EXT4_ERROR_INODE(dir, "error %d getting inode %lu block", err, dir->i_ino); return 1; } down_read(&EXT4_I(dir)->xattr_sem); if (!ext4_has_inline_data(dir)) { *has_inline_data = 0; goto out; } de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block; if (!le32_to_cpu(de->inode)) { ext4_warning(dir->i_sb, "bad inline directory (dir #%lu) - no `..'", dir->i_ino); ret = 1; goto out; } offset = EXT4_INLINE_DOTDOT_SIZE; while (offset < dir->i_size) { de = ext4_get_inline_entry(dir, &iloc, offset, &inline_pos, &inline_size); if (ext4_check_dir_entry(dir, NULL, de, iloc.bh, inline_pos, inline_size, offset)) { ext4_warning(dir->i_sb, "bad inline directory (dir #%lu) - " "inode %u, rec_len %u, name_len %d" "inline size %d\n", dir->i_ino, le32_to_cpu(de->inode), le16_to_cpu(de->rec_len), de->name_len, inline_size); ret = 1; goto out; } if (le32_to_cpu(de->inode)) { ret = 0; goto out; } offset += ext4_rec_len_from_disk(de->rec_len, inline_size); } out: up_read(&EXT4_I(dir)->xattr_sem); brelse(iloc.bh); return ret; }
int ext4_read_inline_dir(struct file *filp, void *dirent, filldir_t filldir) { int error = 0; unsigned int offset; int i, stored; void *inline_pos; struct ext4_dir_entry_2 *de; struct super_block *sb; struct inode *inode = filp->f_path.dentry->d_inode; int ret, inline_size = 0; struct ext4_iloc iloc; ret = ext4_get_inode_loc(inode, &iloc); if (ret) return ret; down_read(&EXT4_I(inode)->xattr_sem); if (!ext4_has_inline_data(inode)) goto out; sb = inode->i_sb; stored = 0; offset = filp->f_pos & (sb->s_blocksize - 1); while (!error && !stored && filp->f_pos < inode->i_size) { revalidate: /* If the version has changed since the last call to * readdir(2), then we might be pointing to an invalid * dirent right now. Scan from the start of the block * to make sure. */ if (filp->f_version != inode->i_version) { for (i = 0; i < inode->i_size && i < offset; ) { de = ext4_get_inline_entry(inode, &iloc, i, NULL, &inline_size); /* It's too expensive to do a full * dirent test each time round this * loop, but we do have to test at * least that it is non-zero. A * failure will be detected in the * dirent test below. */ if (ext4_rec_len_from_disk(de->rec_len, inline_size) < EXT4_DIR_REC_LEN(1)) break; i += ext4_rec_len_from_disk(de->rec_len, inline_size); } offset = i; filp->f_pos = offset; filp->f_version = inode->i_version; } while (!error && filp->f_pos < inode->i_size) { de = ext4_get_inline_entry(inode, &iloc, offset, &inline_pos, &inline_size); if (ext4_check_dir_entry(__func__, inode, de, iloc.bh, inline_pos, inline_size, offset)) { ret = stored; goto out; } offset += ext4_rec_len_from_disk(de->rec_len, inline_size); if (le32_to_cpu(de->inode)) { /* We might block in the next section * if the data destination is * currently swapped out. So, use a * version stamp to detect whether or * not the directory has been modified * during the copy operation. */ u64 version = filp->f_version; error = filldir(dirent, de->name, de->name_len, filp->f_pos, le32_to_cpu(de->inode), get_dtype(sb, de->file_type)); if (error) break; if (version != filp->f_version) goto revalidate; stored++; } filp->f_pos += ext4_rec_len_from_disk(de->rec_len, inline_size); } offset = 0; } out: up_read(&EXT4_I(inode)->xattr_sem); brelse(iloc.bh); return ret; }