Commit bb81864e authored by Anton Altaparmakov's avatar Anton Altaparmakov

NTFS: 2.0.22 - Cleanups, mainly to ntfs_readdir(), and use C99 initializers.

- Change fs/ntfs/dir.c::ntfs_reddir() to only read/write ->f_pos once
  at entry/exit respectively.
- Use C99 initializers for structures.
- Remove unused variable blocks from fs/ntfs/aops.c::ntfs_read_block().
parent 3b89dbbd
......@@ -247,6 +247,8 @@ ChangeLog
Note, a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog.
2.0.22:
- Small internal cleanups.
2.0.21:
These only affect 32-bit architectures:
- Check for, and refuse to mount too large volumes (maximum is 2TiB).
......
......@@ -2,6 +2,13 @@ ToDo:
- Find and fix bugs.
- Enable NFS exporting of NTFS.
2.0.22 - Cleanups, mainly to ntfs_readdir(), and use C99 initializers.
- Change fs/ntfs/dir.c::ntfs_reddir() to only read/write ->f_pos once
at entry/exit respectively.
- Use C99 initializers for structures.
- Remove unused variable blocks from fs/ntfs/aops.c::ntfs_read_block().
2.0.21 - Check for, and refuse to work with too large files/directories/volumes.
- Limit volume size at mount time to 2TiB on architectures where
......
......@@ -5,7 +5,7 @@ obj-$(CONFIG_NTFS_FS) += ntfs.o
ntfs-objs := aops.o attrib.o compress.o debug.o dir.o file.o inode.o mft.o \
mst.o namei.o super.o sysctl.o time.o unistr.o upcase.o
EXTRA_CFLAGS = -DNTFS_VERSION=\"2.0.21\"
EXTRA_CFLAGS = -DNTFS_VERSION=\"2.0.22\"
ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
......
......@@ -171,7 +171,7 @@ static int ntfs_read_block(struct page *page)
run_list_element *rl;
struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
sector_t iblock, lblock, zblock;
unsigned int blocksize, blocks, vcn_ofs;
unsigned int blocksize, vcn_ofs;
int i, nr;
unsigned char blocksize_bits;
......@@ -187,7 +187,6 @@ static int ntfs_read_block(struct page *page)
if (unlikely(!bh))
return -ENOMEM;
blocks = PAGE_CACHE_SIZE >> blocksize_bits;
iblock = page->index << (PAGE_CACHE_SHIFT - blocksize_bits);
lblock = (ni->allocated_size + blocksize - 1) >> blocksize_bits;
zblock = (ni->initialized_size + blocksize - 1) >> blocksize_bits;
......@@ -427,11 +426,8 @@ int ntfs_readpage(struct file *file, struct page *page)
* ntfs_aops - general address space operations for inodes and attributes
*/
struct address_space_operations ntfs_aops = {
writepage: NULL, /* Write dirty page to disk. */
readpage: ntfs_readpage, /* Fill page with data. */
sync_page: block_sync_page, /* Currently, just unplugs the
.readpage = ntfs_readpage, /* Fill page with data. */
.sync_page = block_sync_page, /* Currently, just unplugs the
disk request queue. */
prepare_write: NULL, /* . */
commit_write: NULL, /* . */
};
......@@ -974,7 +974,7 @@ typedef enum {
/**
* ntfs_filldir - ntfs specific filldir method
* @vol: current ntfs volume
* @filp: open file descriptor for the current directory
* @fpos: position in the directory
* @ndir: ntfs inode of current directory
* @index_type: specifies whether @iu is an index root or an index allocation
* @iu: index root or index allocation attribute to which @ie belongs
......@@ -986,7 +986,7 @@ typedef enum {
* Convert the Unicode @name to the loaded NLS and pass it to the @filldir
* callback.
*/
static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
ntfs_inode *ndir, const INDEX_TYPE index_type,
index_union iu, INDEX_ENTRY *ie, u8 *name,
void *dirent, filldir_t filldir)
......@@ -997,12 +997,12 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
/* Advance the position even if going to skip the entry. */
if (index_type == INDEX_TYPE_ALLOCATION)
filp->f_pos = (u8*)ie - (u8*)iu.ia +
*fpos = (u8*)ie - (u8*)iu.ia +
(sle64_to_cpu(iu.ia->index_block_vcn) <<
ndir->_IDM(index_vcn_size_bits)) +
vol->mft_record_size;
else /* if (index_type == INDEX_TYPE_ROOT) */
filp->f_pos = (u8*)ie - (u8*)iu.ir;
*fpos = (u8*)ie - (u8*)iu.ir;
name_type = ie->key.file_name.file_name_type;
if (name_type == FILE_NAME_DOS) {
ntfs_debug("Skipping DOS name space entry.");
......@@ -1029,11 +1029,11 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
dt_type = DT_DIR;
else
dt_type = DT_REG;
ntfs_debug("Calling filldir for %s with len %i, f_pos 0x%Lx, inode "
"0x%lx, DT_%s.", name, name_len, filp->f_pos,
ntfs_debug("Calling filldir for %s with len %i, fpos 0x%Lx, inode "
"0x%lx, DT_%s.", name, name_len, *fpos,
MREF_LE(ie->_IIF(indexed_file)),
dt_type == DT_DIR ? "DIR" : "REG");
return filldir(dirent, name, name_len, filp->f_pos,
return filldir(dirent, name, name_len, *fpos,
MREF_LE(ie->_IIF(indexed_file)), dt_type);
}
......@@ -1053,6 +1053,7 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
s64 ia_pos, ia_start, prev_ia_pos, bmp_pos;
loff_t fpos;
struct inode *bmp_vi, *vdir = filp->f_dentry->d_inode;
struct super_block *sb = vdir->i_sb;
ntfs_inode *ndir = NTFS_I(vdir);
......@@ -1068,30 +1069,31 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
u8 *kaddr, *bmp, *index_end;
attr_search_context *ctx;
ntfs_debug("Entering for inode 0x%lx, f_pos 0x%Lx.",
vdir->i_ino, filp->f_pos);
fpos = filp->f_pos;
ntfs_debug("Entering for inode 0x%lx, fpos 0x%Lx.",
vdir->i_ino, fpos);
rc = err = 0;
/* Are we at end of dir yet? */
if (filp->f_pos >= vdir->i_size + vol->mft_record_size)
if (fpos >= vdir->i_size + vol->mft_record_size)
goto done;
/* Emulate . and .. for all directories. */
if (!filp->f_pos) {
ntfs_debug("Calling filldir for . with len 1, f_pos 0x0, "
if (!fpos) {
ntfs_debug("Calling filldir for . with len 1, fpos 0x0, "
"inode 0x%lx, DT_DIR.", vdir->i_ino);
rc = filldir(dirent, ".", 1, filp->f_pos, vdir->i_ino, DT_DIR);
rc = filldir(dirent, ".", 1, fpos, vdir->i_ino, DT_DIR);
if (rc)
goto done;
filp->f_pos++;
fpos++;
}
if (filp->f_pos == 1) {
ntfs_debug("Calling filldir for .. with len 2, f_pos 0x1, "
if (fpos == 1) {
ntfs_debug("Calling filldir for .. with len 2, fpos 0x1, "
"inode 0x%lx, DT_DIR.",
parent_ino(filp->f_dentry));
rc = filldir(dirent, "..", 2, filp->f_pos,
rc = filldir(dirent, "..", 2, fpos,
parent_ino(filp->f_dentry), DT_DIR);
if (rc)
goto done;
filp->f_pos++;
fpos++;
}
/* Get hold of the mft record for the directory. */
......@@ -1120,10 +1122,10 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
goto err_out;
}
/* Are we jumping straight into the index allocation attribute? */
if (filp->f_pos >= vol->mft_record_size)
if (fpos >= vol->mft_record_size)
goto skip_index_root;
/* Get the offset into the index root attribute. */
ir_pos = (s64)filp->f_pos;
ir_pos = (s64)fpos;
/* Find the index root attribute in the mft record. */
if (unlikely(!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0,
NULL, 0, ctx))) {
......@@ -1158,7 +1160,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (ir_pos > (u8*)ie - (u8*)ir)
continue;
/* Submit the name to the filldir callback. */
rc = ntfs_filldir(vol, filp, ndir, INDEX_TYPE_ROOT, ir, ie,
rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ROOT, ir, ie,
name, dirent, filldir);
if (rc)
goto abort;
......@@ -1166,13 +1168,13 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
/* If there is no index allocation attribute we are finished. */
if (!NInoIndexAllocPresent(ndir))
goto EOD;
/* Advance f_pos to the beginning of the index allocation. */
filp->f_pos = vol->mft_record_size;
/* Advance fpos to the beginning of the index allocation. */
fpos = vol->mft_record_size;
skip_index_root:
kaddr = NULL;
prev_ia_pos = -1LL;
/* Get the offset into the index allocation attribute. */
ia_pos = (s64)filp->f_pos - vol->mft_record_size;
ia_pos = (s64)fpos - vol->mft_record_size;
ia_mapping = vdir->i_mapping;
bmp_vi = ndir->_IDM(bmp_ino);
if (unlikely(!bmp_vi)) {
......@@ -1324,7 +1326,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (ia_pos - ia_start > (u8*)ie - (u8*)ia)
continue;
/* Submit the name to the filldir callback. */
rc = ntfs_filldir(vol, filp, ndir, INDEX_TYPE_ALLOCATION, ia,
rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ALLOCATION, ia,
ie, name, dirent, filldir);
if (rc) {
ntfs_unmap_page(ia_page);
......@@ -1338,8 +1340,8 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
ntfs_unmap_page(ia_page);
ntfs_unmap_page(bmp_page);
EOD:
/* We are finished, set f_pos to EOD. */
filp->f_pos = vdir->i_size + vol->mft_record_size;
/* We are finished, set fpos to EOD. */
fpos = vdir->i_size + vol->mft_record_size;
abort:
put_attr_search_ctx(ctx);
unmap_mft_record(READ, ndir);
......@@ -1347,11 +1349,12 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
done:
#ifdef DEBUG
if (!rc)
ntfs_debug("EOD, f_pos 0x%Lx, returning 0.", filp->f_pos);
ntfs_debug("EOD, fpos 0x%Lx, returning 0.", fpos);
else
ntfs_debug("filldir returned %i, f_pos 0x%Lx, returning 0.",
rc, filp->f_pos);
ntfs_debug("filldir returned %i, fpos 0x%Lx, returning 0.",
rc, fpos);
#endif
filp->f_pos = fpos;
return 0;
err_out:
if (bmp_page)
......@@ -1367,6 +1370,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
if (!err)
err = -EIO;
ntfs_debug("Failed. Returning error code %i.", -err);
filp->f_pos = fpos;
return err;
}
......@@ -1396,9 +1400,9 @@ static int ntfs_dir_open(struct inode *vi, struct file *filp)
}
struct file_operations ntfs_dir_ops = {
llseek: generic_file_llseek, /* Seek inside directory. */
read: generic_read_dir, /* Return -EISDIR. */
readdir: ntfs_readdir, /* Read directory contents. */
open: ntfs_dir_open, /* Open directory. */
.llseek = generic_file_llseek, /* Seek inside directory. */
.read = generic_read_dir, /* Return -EISDIR. */
.readdir = ntfs_readdir, /* Read directory contents. */
.open = ntfs_dir_open, /* Open directory. */
};
......@@ -49,10 +49,11 @@ static int ntfs_file_open(struct inode *vi, struct file *filp)
}
struct file_operations ntfs_file_ops = {
llseek: generic_file_llseek, /* Seek inside file. */
read: generic_file_read, /* Read from file. */
mmap: generic_file_mmap, /* Mmap file. */
open: ntfs_file_open, /* Open file. */
.llseek = generic_file_llseek, /* Seek inside file. */
.read = generic_file_read, /* Read from file. */
.write = generic_file_write, /* Write to a file. */
.mmap = generic_file_mmap, /* Mmap file. */
.open = ntfs_file_open, /* Open file. */
};
struct inode_operations ntfs_file_inode_ops = {};
......
......@@ -282,11 +282,12 @@ void ntfs_destroy_big_inode(struct inode *inode)
kmem_cache_free(ntfs_big_inode_cache, NTFS_I(inode));
}
static ntfs_inode *ntfs_alloc_extent_inode(void)
static inline ntfs_inode *ntfs_alloc_extent_inode(void)
{
ntfs_inode *ni = (ntfs_inode *)kmem_cache_alloc(ntfs_inode_cache,
SLAB_NOFS);
ntfs_inode *ni;
ntfs_debug("Entering.");
ni = (ntfs_inode *)kmem_cache_alloc(ntfs_inode_cache, SLAB_NOFS);
if (likely(ni != NULL)) {
ni->state = 0;
return ni;
......@@ -340,7 +341,7 @@ static void __ntfs_init_inode(struct super_block *sb, ntfs_inode *ni)
return;
}
static void ntfs_init_big_inode(struct inode *vi)
static inline void ntfs_init_big_inode(struct inode *vi)
{
ntfs_inode *ni = NTFS_I(vi);
......@@ -350,7 +351,8 @@ static void ntfs_init_big_inode(struct inode *vi)
return;
}
ntfs_inode *ntfs_new_extent_inode(struct super_block *sb, unsigned long mft_no)
inline ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
unsigned long mft_no)
{
ntfs_inode *ni = ntfs_alloc_extent_inode();
......@@ -445,7 +447,7 @@ static int ntfs_is_extended_system_file(attr_search_context *ctx)
* ntfs_read_locked_inode - read an inode from its device
* @vi: inode to read
*
* ntfs_read_locked_inode() is called from the ntfs_iget() to read the inode
* ntfs_read_locked_inode() is called from ntfs_iget() to read the inode
* described by @vi into memory from the device.
*
* The only fields in @vi that we need to/can look at when the function is
......
......@@ -223,7 +223,7 @@ static inline ntfs_inode *NTFS_I(struct inode *inode)
static inline struct inode *VFS_I(ntfs_inode *ni)
{
return &((big_ntfs_inode*)ni)->vfs_inode;
return &((big_ntfs_inode *)ni)->vfs_inode;
}
extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no);
......
......@@ -107,12 +107,12 @@ extern int ntfs_readpage(struct file *, struct page *);
* ntfs_map_page() in map_mft_record_page().
*/
struct address_space_operations ntfs_mft_aops = {
writepage: NULL, /* Write dirty page to disk. */
readpage: ntfs_readpage, /* Fill page with data. */
sync_page: block_sync_page, /* Currently, just unplugs the
.writepage = NULL, /* Write dirty page to disk. */
.readpage = ntfs_readpage, /* Fill page with data. */
.sync_page = block_sync_page, /* Currently, just unplugs the
disk request queue. */
prepare_write: NULL, /* . */
commit_write: NULL, /* . */
.prepare_write = NULL, /* . */
.commit_write = NULL, /* . */
};
/**
......
......@@ -286,6 +286,6 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent)
* Inode operations for directories.
*/
struct inode_operations ntfs_dir_inode_ops = {
lookup: ntfs_lookup, /* VFS: Lookup directory. */
.lookup = ntfs_lookup, /* VFS: Lookup directory. */
};
......@@ -1260,38 +1260,38 @@ static int ntfs_statfs(struct super_block *sb, struct statfs *sfs)
* proper functions.
*/
struct super_operations ntfs_mount_sops = {
alloc_inode: ntfs_alloc_big_inode, /* VFS: Allocate a new inode. */
destroy_inode: ntfs_destroy_big_inode, /* VFS: Deallocate an inode. */
read_inode: ntfs_read_inode_mount, /* VFS: Load inode from disk,
called from iget(). */
clear_inode: ntfs_clear_big_inode, /* VFS: Called when an inode is
removed from memory. */
.alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */
.destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */
.read_inode = ntfs_read_inode_mount, /* VFS: Load inode from disk,
called from iget(). */
.clear_inode = ntfs_clear_big_inode, /* VFS: Called when inode is
removed from memory. */
};
/**
* The complete super operations.
*/
struct super_operations ntfs_sops = {
alloc_inode: ntfs_alloc_big_inode, /* VFS: Allocate a new inode. */
destroy_inode: ntfs_destroy_big_inode, /* VFS: Deallocate an inode. */
dirty_inode: ntfs_dirty_inode, /* VFS: Called from
__mark_inode_dirty(). */
//write_inode: NULL, /* VFS: Write dirty inode to disk. */
put_inode: ntfs_put_inode, /* VFS: Called just before the inode
reference count is decreased. */
//delete_inode: NULL, /* VFS: Delete inode from disk. Called
// when i_count becomes 0 and i_nlink is
// also 0. */
put_super: ntfs_put_super, /* Syscall: umount. */
//write_super: NULL, /* Flush dirty super block to disk. */
//write_super_lockfs: NULL, /* ? */
//unlockfs: NULL, /* ? */
statfs: ntfs_statfs, /* Syscall: statfs */
remount_fs: ntfs_remount, /* Syscall: mount -o remount. */
clear_inode: ntfs_clear_big_inode, /* VFS: Called when an inode is
.alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */
.destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */
//.dirty_inode = ntfs_dirty_inode, /* VFS: Called from
// __mark_inode_dirty(). */
//.write_inode = NULL, /* VFS: Write dirty inode to disk. */
.put_inode = ntfs_put_inode, /* VFS: Called just before the inode
reference count is decreased. */
//.delete_inode = NULL, /* VFS: Delete inode from disk. Called
// when i_count becomes 0 and i_nlink
// is also 0. */
.put_super = ntfs_put_super, /* Syscall: umount. */
//write_super = NULL, /* Flush dirty super block to disk. */
//write_super_lockfs = NULL, /* ? */
//unlockfs = NULL, /* ? */
.statfs = ntfs_statfs, /* Syscall: statfs */
.remount_fs = ntfs_remount, /* Syscall: mount -o remount. */
.clear_inode = ntfs_clear_big_inode, /* VFS: Called when an inode is
removed from memory. */
//umount_begin: NULL, /* Forced umount. */
show_options: ntfs_show_options, /* Show mount options in proc. */
//.umount_begin = NULL, /* Forced umount. */
.show_options = ntfs_show_options, /* Show mount options in proc. */
};
/**
......@@ -1562,7 +1562,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
ntfs_error(sb, "Busy inodes left. This is most likely a NTFS "
"driver bug.");
/* Copied from fs/super.c. I just love this message. (-; */
printk("VFS: Busy inodes after umount. Self-destruct in 5 "
printk("NTFS: Busy inodes after umount. Self-destruct in 5 "
"seconds. Have a nice day...\n");
}
/* Errors at this stage are irrelevant. */
......@@ -1618,11 +1618,11 @@ static struct super_block *ntfs_get_sb(struct file_system_type *fs_type,
}
static struct file_system_type ntfs_fs_type = {
owner: THIS_MODULE,
name: "ntfs",
get_sb: ntfs_get_sb,
kill_sb: kill_block_super,
fs_flags: FS_REQUIRES_DEV,
.owner = THIS_MODULE,
.name = "ntfs",
.get_sb = ntfs_get_sb,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
/* Stable names for the slab caches. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment