Commit 6f3894e9 authored by Anton Altaparmakov's avatar Anton Altaparmakov

NTFS: The beginning of 2.0.8. - Major updates for handling of case sensitivity.

- Remove unused source file fs/ntfs/attraops.c.
- Remove show_inodes mount option(s), thus dropping support for
  displaying of short file names.
- Remove deprecated mount option posix.
- Restore show_sys_files mount option.
- Add new mount option case_sensitive, to determine if the driver treats
  file names as case sensitive or not. If case sensitive, create file names
  in the POSIX namespace. Otherwise create file names in the WIN32
  namespace. By default, or when case_sensitive is set to FALSE, files
  remain accessible via their short file name, if it exists.
- Add additional argument to ntfs_lookup_inode_by_name() in which we
  return information about the matching file name if the case is not
  matching or the match is a short file name. See comments above the
  function definition for details.
parent 0cf66ffc
...@@ -73,52 +73,27 @@ sloppy=<BOOL> If sloppy is specified, ignore unknown mount options. ...@@ -73,52 +73,27 @@ sloppy=<BOOL> If sloppy is specified, ignore unknown mount options.
Otherwise the default behaviour is to abort mount if Otherwise the default behaviour is to abort mount if
any unknown options are found. any unknown options are found.
posix=<bool> Deprecated option. Still supported but please use show_sys_files=<BOOL> If show_sys_files is specified, show the system files
show_inodes=posix in the future. See description for in directory listings. Otherwise the default behaviour
show_inodes=opt. is to hide the system files.
Note that even when show_sys_files is specified, "$MFT"
show_sys_files=<bool> Deprecated option. Still supported but please use will not be visible due to bugs/mis-features in glibc.
show_inodes=system in the future. See description for Further, note that irrespective of show_sys_files, all
show_inodes=opt. files are accessible by name, i.e. you can always do
"ls -l \$UpCase" for example to specifically show the
show_inodes=opt Allows choice of which types of inode names readdir() system file containing the Unicode upcase table.
returns, i.e. this affects what "ls" shows. Following
values can be used for "opt": case_sensitive=<BOOL> If case_sensitive is specified, treat all file names as
system: show system files case sensitive and create file names in the POSIX
win32: long file names (includes POSIX) [DEFAULT] namespace. Otherwise the default behaviour is to treat
long: same as win32 file names as case insensitive and to create file names
dos: short file names only (excludes POSIX) in the WIN32/LONG name space. Note, the Linux NTFS
short: same as dos driver will never create short file names and will
posix: same as both win32 and dos remove them on rename/delete of the corresponding long
all: all file names file name.
Note that the options are additive, i.e. specifying: Note that by default / when case_sensitive is set to
show_inodes=system,show_inodes=win32,show_inodes=dos FALSE, files remain accessible via their short file
is the same as specifying: name, if it exists.
show_inodes=all
Note that the "posix" and "all" options will show all
directory names, BUT the link count on each directory
inode entry is set to 1, due to Linux not supporting
directory hard links. This may well confuse some
user space applications, since the directory names will
have the same inode numbers. Thus it is NOT advisable
to use the "posix" and "all" options. We provide them
only for completeness sake.
Further, note that the "system" option will not show
"$MFT" due to bugs/mis-features in glibc. Even though
it does not show, you can specifically "ls" it:
ls -l \$MFT
And of course you can stat it, too.
Further, note that irrespective of what show_inodes
option(s) you use, all files are accessible when you
specify the correct name, even though they may not be
shown in a normal "ls", i.e. you can always access the
system files and both the short and long file names of
files and directories.
Finally, note that win32 and dos file names are not
case sensitive and can be accessed using any
combination of lower and upper case, while POSIX file
names are case sensitive and they can only be accessed
given the correct case.
errors=opt What to do when critical file system errors are found. errors=opt What to do when critical file system errors are found.
Following values can be used for "opt": Following values can be used for "opt":
...@@ -174,12 +149,22 @@ Features ...@@ -174,12 +149,22 @@ Features
(from 9:43 minutes on average down to 7:53). The time spent in user space (from 9:43 minutes on average down to 7:53). The time spent in user space
was unchanged but the time spent in the kernel was decreased by a factor of was unchanged but the time spent in the kernel was decreased by a factor of
2.5 (from 85 CPU seconds down to 33). 2.5 (from 85 CPU seconds down to 33).
- The driver does not support short file names in general. For backwards
compatibility, we implement access to files using their short file names if
they exist. The driver will not create short file names however, and a rename
will discard any existing short file name.
Known bugs and (mis-)features Known bugs and (mis-)features
============================= =============================
- None - The link count on each directory inode entry is set to 1, due to Linux not
supporting directory hard links. This may well confuse some user space
applications, since the directory names will have the same inode numbers.
This also speeds up ntfs_read_inode() immensely. And we haven't found any
problems with this approach so far. If you find a problem with this, please
let us know.
Please send bug reports/comments/feedback/abuse to the Linux-NTFS development Please send bug reports/comments/feedback/abuse to the Linux-NTFS development
list at sourceforge: linux-ntfs-dev@lists.sourceforge.net list at sourceforge: linux-ntfs-dev@lists.sourceforge.net
...@@ -262,6 +247,18 @@ ChangeLog ...@@ -262,6 +247,18 @@ ChangeLog
Note that a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog. Note that a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog.
2.0.8:
- Remove now obsolete show_inodes and posix mount option(s).
- Restore show_sys_files mount option.
- Add new mount option case_sensitive, to determine if the driver
treats file names as case sensitive or not.
- Mostly drop support for short file names (for backwards compatibility
we only support accessing files via their short file name if one
exists).
- Fix dcache aliasing issues wrt short/long file names.
- Cleanups.
2.0.7:
- Just cleanups.
2.0.6: 2.0.6:
- Major bugfix to make compatible with other kernel changes. This fixes - Major bugfix to make compatible with other kernel changes. This fixes
the hangs/oopses on umount. the hangs/oopses on umount.
......
...@@ -21,8 +21,29 @@ ToDo: ...@@ -21,8 +21,29 @@ ToDo:
several copies of almost identicall functions and the functions are several copies of almost identicall functions and the functions are
quite big. Modularising them a bit, e.g. a-la get_block(), will make quite big. Modularising them a bit, e.g. a-la get_block(), will make
them cleaner and make code reuse easier. them cleaner and make code reuse easier.
- Want to use dummy inodes for address space i/o. We need some VFS - Want to use dummy inodes for address space i/o.
changes first, which are currently under discussion.
2.0.8 - Major updates for handling of case sensitivity and dcache aliasing.
- Remove unused source file fs/ntfs/attraops.c.
- Remove show_inodes mount option(s), thus dropping support for
displaying of short file names.
- Remove deprecated mount option posix.
- Restore show_sys_files mount option.
- Add new mount option case_sensitive, to determine if the driver
treats file names as case sensitive or not. If case sensitive, create
file names in the POSIX namespace. Otherwise create file names in the
LONG/WIN32 name space. By default, or when case_sensitive is set to
FALSE, files remain accessible via their short file name, if it
exists.
- Fix dcache aliasing issues wrt short/long file names via changes
to fs/ntfs/dir.c::ntfs_lookup_inode_by_name() and
fs/ntfs/namei.c::ntfs_lookup(). (The latter is still TODO:)
- Add additional argument to ntfs_lookup_inode_by_name() in which we
return information about the matching file name if the case is not
matching or the match is a short file name. See comments above the
function definition for details.
- TODO: (AIA) Change ntfs_lookup()...
2.0.7 - Minor cleanups and updates for changes in core kernel code. 2.0.7 - Minor cleanups and updates for changes in core kernel code.
......
...@@ -5,7 +5,7 @@ obj-$(CONFIG_NTFS_FS) += ntfs.o ...@@ -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 \ 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 mst.o namei.o super.o sysctl.o time.o unistr.o upcase.o
EXTRA_CFLAGS = -DNTFS_VERSION=\"2.0.7\" EXTRA_CFLAGS = -DNTFS_VERSION=\"2.0.8\"
ifeq ($(CONFIG_NTFS_DEBUG),y) ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG EXTRA_CFLAGS += -DDEBUG
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include "ntfs.h" #include "ntfs.h"
#include "dir.h"
/* Temporary helper functions -- might become macros */ /* Temporary helper functions -- might become macros */
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include "ntfs.h" #include "ntfs.h"
#include "dir.h"
/** /**
* The little endian Unicode string $I30 as a global constant. * The little endian Unicode string $I30 as a global constant.
...@@ -30,6 +31,564 @@ const uchar_t I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'), ...@@ -30,6 +31,564 @@ const uchar_t I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'),
const_cpu_to_le16('3'), const_cpu_to_le16('0'), const_cpu_to_le16('3'), const_cpu_to_le16('0'),
const_cpu_to_le16(0) }; const_cpu_to_le16(0) };
/**
* ntfs_lookup_inode_by_name - find an inode in a directory given its name
* @dir_ni: ntfs inode of the directory in which to search for the name
* @uname: Unicode name for which to search in the directory
* @uname_len: length of the name @uname in Unicode characters
* @res: return the found file name if necessary (see below)
*
* Look for an inode with name @uname in the directory with inode @dir_ni.
* ntfs_lookup_inode_by_name() walks the contents of the directory looking for
* the Unicode name. If the name is found in the directory, the corresponding
* inode number (>= 0) is returned as a mft reference in cpu format, i.e. it
* is a 64-bit number containing the sequence number.
*
* On error, a negative value is returned corresponding to the error code. In
* particular if the inode is not found -ENOENT is returned. Note that you
* can't just check the return value for being negative, you have to check the
* inode number for being negative which you can extract using MREC(return
* value).
*
* Note, @uname_len does not include the (optional) terminating NULL character.
*
* Note, we look for a case sensitive match first but we also look for a case
* insensitive match at the same time. If we find a case insensitive match, we
* save that for the case that we don't find an exact match, where we return
* the case insensitive match and setup @res (which we allocate!) with the mft
* reference, the file name type, length and with a copy of the little endian
* Unicode file name itself. If we match a file name which is in the DOS name
* space, we only return the mft reference and file name type in @res.
* ntfs_lookup() then uses this to find the long file name in the inode itself.
* This is to avoid polluting the dcache with short file names. We want them to
* work but we don't care for how quickly one can access them. This also fixes
* the dcache aliasing issues.
*/
u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname,
const int uname_len, ntfs_name **res)
{
ntfs_volume *vol = dir_ni->vol;
struct super_block *sb = vol->sb;
MFT_RECORD *m;
INDEX_ROOT *ir;
INDEX_ENTRY *ie;
INDEX_ALLOCATION *ia;
u8 *index_end;
u64 mref;
attr_search_context *ctx;
int err = 0, rc;
VCN vcn, old_vcn;
struct address_space *ia_mapping;
struct page *page;
u8 *kaddr;
ntfs_name *name = NULL;
/* Get hold of the mft record for the directory. */
m = map_mft_record(READ, dir_ni);
if (IS_ERR(m))
goto map_err_out;
ctx = get_attr_search_ctx(dir_ni, m);
if (!ctx) {
err = -ENOMEM;
goto unm_err_out;
}
/* Find the index root attribute in the mft record. */
if (!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0,
ctx)) {
ntfs_error(sb, "Index root attribute missing in directory "
"inode 0x%Lx.",
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto put_unm_err_out;
}
/* Get to the index root value (it's been verified in read_inode). */
ir = (INDEX_ROOT*)((u8*)ctx->attr +
le16_to_cpu(ctx->attr->_ARA(value_offset)));
index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
/* The first index entry. */
ie = (INDEX_ENTRY*)((u8*)&ir->index +
le32_to_cpu(ir->index.entries_offset));
/*
* Loop until we exceed valid memory (corruption case) or until we
* reach the last entry.
*/
for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->_IEH(length)))) {
/* Bounds checks. */
if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie +
sizeof(INDEX_ENTRY_HEADER) > index_end ||
(u8*)ie + le16_to_cpu(ie->_IEH(key_length)) >
index_end)
goto dir_err_out;
/*
* The last entry cannot contain a name. It can however contain
* a pointer to a child node in the B+tree so we just break out.
*/
if (ie->_IEH(flags) & INDEX_ENTRY_END)
break;
/*
* We perform a case sensitive comparison and if that matches
* we are done and return the mft reference of the inode (i.e.
* the inode number together with the sequence number for
* consistency checking). We convert it to cpu format before
* returning.
*/
if (ntfs_are_names_equal(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length,
CASE_SENSITIVE, vol->upcase, vol->upcase_len)) {
found_it:
/*
* We have a perfect match, so we don't need to care
* about having matched imperfectly before, so we can
* free name and set *res to NULL.
* However, if the perfect match is a short file name,
* we need to signal this through *res, so that
* ntfs_lookup() can fix dcache aliasing issues.
* As an optimization we just reuse an existing
* allocation of *res.
*/
if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
if (!name) {
name = kmalloc(sizeof(ntfs_name),
GFP_NOFS);
if (!name) {
err = -ENOMEM;
goto put_unm_err_out;
}
}
name->mref = le64_to_cpu(
ie->_IIF(indexed_file));
name->type = FILE_NAME_DOS;
name->len = 0;
*res = name;
} else {
if (name)
kfree(name);
*res = NULL;
}
mref = le64_to_cpu(ie->_IIF(indexed_file));
put_attr_search_ctx(ctx);
unmap_mft_record(READ, dir_ni);
return mref;
}
/*
* For a case insensitive mount, we also perform a case
* insensitive comparison (provided the file name is not in the
* POSIX namespace). If the comparison matches, and the name is
* in the WIN32 namespace, we cache the filename in *res so
* that the caller, ntfs_lookup(), can work on it. If the
* comparison matches, and the name is in the DOS namespace, we
* only cache the mft reference and the file name type (we set
* the name length to zero for simplicity).
*/
if (!NVolCaseSensitive(vol) &&
ie->key.file_name.file_name_type &&
ntfs_are_names_equal(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length,
IGNORE_CASE, vol->upcase, vol->upcase_len)) {
int name_size = sizeof(ntfs_name);
u8 type = ie->key.file_name.file_name_type;
u8 len = ie->key.file_name.file_name_length;
/* Only one case insensitive matching name allowed. */
if (name) {
ntfs_error(sb, "Found already allocated name "
"in phase 1. Please run chkdsk "
"and if that doesn't find any "
"errors please report you saw "
"this message to "
"linux-ntfs@lists.sf.net.");
goto dir_err_out;
}
if (type != FILE_NAME_DOS)
name_size += len * sizeof(uchar_t);
name = kmalloc(name_size, GFP_NOFS);
if (!name) {
err = -ENOMEM;
goto put_unm_err_out;
}
name->mref = le64_to_cpu(ie->_IIF(indexed_file));
name->type = type;
if (type != FILE_NAME_DOS) {
name->len = len;
memcpy(name->name, ie->key.file_name.file_name,
len * sizeof(uchar_t));
} else
name->len = 0;
*res = name;
}
/*
* Not a perfect match, need to do full blown collation so we
* know which way in the B+tree we have to go.
*/
rc = ntfs_collate_names(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length, 1,
IGNORE_CASE, vol->upcase, vol->upcase_len);
/*
* If uname collates before the name of the current entry, there
* is definitely no such name in this index but we might need to
* descend into the B+tree so we just break out of the loop.
*/
if (rc == -1)
break;
/* The names are not equal, continue the search. */
if (rc)
continue;
/*
* Names match with case insensitive comparison, now try the
* case sensitive comparison, which is required for proper
* collation.
*/
rc = ntfs_collate_names(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length, 1,
CASE_SENSITIVE, vol->upcase, vol->upcase_len);
if (rc == -1)
break;
if (rc)
continue;
/*
* Perfect match, this will never happen as the
* ntfs_are_names_equal() call will have gotten a match but we
* still treat it correctly.
*/
goto found_it;
}
/*
* We have finished with this index without success. Check for the
* presence of a child node and if not present return -ENOENT, unless
* we have got a matching name cached in name in which case return the
* mft reference associated with it.
*/
if (!(ie->_IEH(flags) & INDEX_ENTRY_NODE)) {
if (name) {
put_attr_search_ctx(ctx);
unmap_mft_record(READ, dir_ni);
return name->mref;
}
ntfs_debug("Entry not found.");
err = -ENOENT;
goto put_unm_err_out;
} /* Child node present, descend into it. */
/* Consistency check: Verify that an index allocation exists. */
if (!NInoIndexAllocPresent(dir_ni)) {
ntfs_error(sb, "No index allocation attribute but index entry "
"requires one. Directory inode 0x%Lx is "
"corrupt or driver bug.",
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto put_unm_err_out;
}
/* Get the starting vcn of the index_block holding the child node. */
vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->_IEH(length)) - 8);
ia_mapping = VFS_I(dir_ni)->i_mapping;
descend_into_child_node:
/*
* Convert vcn to index into the index allocation attribute in units
* of PAGE_CACHE_SIZE and map the page cache page, reading it from
* disk if necessary.
*/
page = ntfs_map_page(ia_mapping, vcn <<
dir_ni->_IDM(index_vcn_size_bits) >> PAGE_CACHE_SHIFT);
if (IS_ERR(page)) {
ntfs_error(sb, "Failed to map directory index page, error %ld.",
-PTR_ERR(page));
goto put_unm_err_out;
}
kaddr = (u8*)page_address(page);
fast_descend_into_child_node:
/* Get to the index allocation block. */
ia = (INDEX_ALLOCATION*)(kaddr + ((vcn <<
dir_ni->_IDM(index_vcn_size_bits)) & ~PAGE_CACHE_MASK));
/* Bounds checks. */
if ((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE) {
ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
"inode 0x%Lx or driver bug.",
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
if (sle64_to_cpu(ia->index_block_vcn) != vcn) {
ntfs_error(sb, "Actual VCN (0x%Lx) of index buffer is "
"different from expected VCN (0x%Lx). "
"Directory inode 0x%Lx is corrupt or driver "
"bug.",
(long long)sle64_to_cpu(ia->index_block_vcn),
(long long)vcn,
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
dir_ni->_IDM(index_block_size)) {
ntfs_error(sb, "Index buffer (VCN 0x%Lx) of directory inode "
"0x%Lx has a size (%u) differing from the "
"directory specified size (%u). Directory "
"inode is corrupt or driver bug.",
(long long)vcn,
(unsigned long long)dir_ni->mft_no,
le32_to_cpu(ia->index.allocated_size) + 0x18,
dir_ni->_IDM(index_block_size));
err = -EIO;
goto unm_unm_err_out;
}
index_end = (u8*)ia + dir_ni->_IDM(index_block_size);
if (index_end > kaddr + PAGE_CACHE_SIZE) {
ntfs_error(sb, "Index buffer (VCN 0x%Lx) of directory inode "
"0x%Lx crosses page boundary. Impossible! "
"Cannot access! This is probably a bug in the "
"driver.", (long long)vcn,
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
if (index_end > (u8*)ia + dir_ni->_IDM(index_block_size)) {
ntfs_error(sb, "Size of index buffer (VCN 0x%Lx) of directory "
"inode 0x%Lx exceeds maximum size.",
(long long)vcn,
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
/* The first index entry. */
ie = (INDEX_ENTRY*)((u8*)&ia->index +
le32_to_cpu(ia->index.entries_offset));
/*
* Iterate similar to above big loop but applied to index buffer, thus
* loop until we exceed valid memory (corruption case) or until we
* reach the last entry.
*/
for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->_IEH(length)))) {
/* Bounds check. */
if ((u8*)ie < (u8*)ia || (u8*)ie +
sizeof(INDEX_ENTRY_HEADER) > index_end ||
(u8*)ie + le16_to_cpu(ie->_IEH(key_length)) >
index_end) {
ntfs_error(sb, "Index entry out of bounds in "
"directory inode 0x%Lx.",
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
/*
* The last entry cannot contain a name. It can however contain
* a pointer to a child node in the B+tree so we just break out.
*/
if (ie->_IEH(flags) & INDEX_ENTRY_END)
break;
/*
* We perform a case sensitive comparison and if that matches
* we are done and return the mft reference of the inode (i.e.
* the inode number together with the sequence number for
* consistency checking). We convert it to cpu format before
* returning.
*/
if (ntfs_are_names_equal(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length,
CASE_SENSITIVE, vol->upcase, vol->upcase_len)) {
found_it2:
/*
* We have a perfect match, so we don't need to care
* about having matched imperfectly before, so we can
* free name and set *res to NULL.
* However, if the perfect match is a short file name,
* we need to signal this through *res, so that
* ntfs_lookup() can fix dcache aliasing issues.
* As an optimization we just reuse an existing
* allocation of *res.
*/
if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
if (!name) {
name = kmalloc(sizeof(ntfs_name),
GFP_NOFS);
if (!name) {
err = -ENOMEM;
goto unm_unm_err_out;
}
}
name->mref = le64_to_cpu(
ie->_IIF(indexed_file));
name->type = FILE_NAME_DOS;
name->len = 0;
*res = name;
} else {
if (name)
kfree(name);
*res = NULL;
}
mref = le64_to_cpu(ie->_IIF(indexed_file));
ntfs_unmap_page(page);
put_attr_search_ctx(ctx);
unmap_mft_record(READ, dir_ni);
return mref;
}
/*
* For a case insensitive mount, we also perform a case
* insensitive comparison (provided the file name is not in the
* POSIX namespace). If the comparison matches, and the name is
* in the WIN32 namespace, we cache the filename in *res so
* that the caller, ntfs_lookup(), can work on it. If the
* comparison matches, and the name is in the DOS namespace, we
* only cache the mft reference and the file name type (we set
* the name length to zero for simplicity).
*/
if (!NVolCaseSensitive(vol) &&
ie->key.file_name.file_name_type &&
ntfs_are_names_equal(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length,
IGNORE_CASE, vol->upcase, vol->upcase_len)) {
int name_size = sizeof(ntfs_name);
u8 type = ie->key.file_name.file_name_type;
u8 len = ie->key.file_name.file_name_length;
/* Only one case insensitive matching name allowed. */
if (name) {
ntfs_error(sb, "Found already allocated name "
"in phase 2. Please run chkdsk "
"and if that doesn't find any "
"errors please report you saw "
"this message to "
"linux-ntfs@lists.sf.net.");
ntfs_unmap_page(page);
goto dir_err_out;
}
if (type != FILE_NAME_DOS)
name_size += len * sizeof(uchar_t);
name = kmalloc(name_size, GFP_NOFS);
if (!name) {
err = -ENOMEM;
goto put_unm_err_out;
}
name->mref = le64_to_cpu(ie->_IIF(indexed_file));
name->type = type;
if (type != FILE_NAME_DOS) {
name->len = len;
memcpy(name->name, ie->key.file_name.file_name,
len * sizeof(uchar_t));
} else
name->len = 0;
*res = name;
}
/*
* Not a perfect match, need to do full blown collation so we
* know which way in the B+tree we have to go.
*/
rc = ntfs_collate_names(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length, 1,
IGNORE_CASE, vol->upcase, vol->upcase_len);
/*
* If uname collates before the name of the current entry, there
* is definitely no such name in this index but we might need to
* descend into the B+tree so we just break out of the loop.
*/
if (rc == -1)
break;
/* The names are not equal, continue the search. */
if (rc)
continue;
/*
* Names match with case insensitive comparison, now try the
* case sensitive comparison, which is required for proper
* collation.
*/
rc = ntfs_collate_names(uname, uname_len,
(uchar_t*)&ie->key.file_name.file_name,
ie->key.file_name.file_name_length, 1,
CASE_SENSITIVE, vol->upcase, vol->upcase_len);
if (rc == -1)
break;
if (rc)
continue;
/*
* Perfect match, this will never happen as the
* ntfs_are_names_equal() call will have gotten a match but we
* still treat it correctly.
*/
goto found_it2;
}
/*
* We have finished with this index buffer without success. Check for
* the presence of a child node.
*/
if (ie->_IEH(flags) & INDEX_ENTRY_NODE) {
if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
ntfs_error(sb, "Index entry with child node found in "
"a leaf node in directory inode 0x%Lx.",
(unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
/* Child node present, descend into it. */
old_vcn = vcn;
vcn = sle64_to_cpup((u8*)ie +
le16_to_cpu(ie->_IEH(length)) - 8);
if (vcn >= 0) {
/* If vcn is in the same page cache page as old_vcn we
* recycle the mapped page. */
if (old_vcn << vol->cluster_size_bits >>
PAGE_CACHE_SHIFT == vcn <<
vol->cluster_size_bits >>
PAGE_CACHE_SHIFT)
goto fast_descend_into_child_node;
ntfs_unmap_page(page);
goto descend_into_child_node;
}
ntfs_error(sb, "Negative child node vcn in directory inode "
"0x%Lx.", (unsigned long long)dir_ni->mft_no);
err = -EIO;
goto unm_unm_err_out;
}
/*
* No child node present, return -ENOENT, unless we have got a matching
* name cached in name in which case return the mft reference
* associated with it.
*/
if (name) {
ntfs_unmap_page(page);
put_attr_search_ctx(ctx);
unmap_mft_record(READ, dir_ni);
return name->mref;
}
ntfs_debug("Entry not found.");
err = -ENOENT;
unm_unm_err_out:
ntfs_unmap_page(page);
put_unm_err_out:
put_attr_search_ctx(ctx);
unm_err_out:
unmap_mft_record(READ, dir_ni);
if (name) {
kfree(name);
*res = NULL;
}
return ERR_MREF(err);
map_err_out:
ntfs_error(sb, "map_mft_record(READ) failed with error code %ld.",
-PTR_ERR(m));
return ERR_MREF(PTR_ERR(m));
dir_err_out:
ntfs_error(sb, "Corrupt directory. Aborting lookup.");
err = -EIO;
goto put_unm_err_out;
}
#if 0
// TODO: (AIA)
// The algorithm embedded in this code will be required for the time when we
// want to support adding of entries to directories, where we require correct
// collation of file names in order not to cause corruption of the file system.
/** /**
* ntfs_lookup_inode_by_name - find an inode in a directory given its name * ntfs_lookup_inode_by_name - find an inode in a directory given its name
* @dir_ni: ntfs inode of the directory in which to search for the name * @dir_ni: ntfs inode of the directory in which to search for the name
...@@ -414,6 +973,8 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname, ...@@ -414,6 +973,8 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname,
goto put_unm_err_out; goto put_unm_err_out;
} }
#endif
typedef union { typedef union {
INDEX_ROOT *ir; INDEX_ROOT *ir;
INDEX_ALLOCATION *ia; INDEX_ALLOCATION *ia;
...@@ -447,7 +1008,6 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp, ...@@ -447,7 +1008,6 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
int name_len; int name_len;
unsigned dt_type; unsigned dt_type;
FILE_NAME_TYPE_FLAGS name_type; FILE_NAME_TYPE_FLAGS name_type;
READDIR_OPTIONS readdir_opts;
/* Advance the position even if going to skip the entry. */ /* Advance the position even if going to skip the entry. */
if (index_type == INDEX_TYPE_ALLOCATION) if (index_type == INDEX_TYPE_ALLOCATION)
...@@ -457,25 +1017,17 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp, ...@@ -457,25 +1017,17 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
vol->mft_record_size; vol->mft_record_size;
else /* if (index_type == INDEX_TYPE_ROOT) */ else /* if (index_type == INDEX_TYPE_ROOT) */
filp->f_pos = (u8*)ie - (u8*)iu.ir; filp->f_pos = (u8*)ie - (u8*)iu.ir;
readdir_opts = vol->readdir_opts;
name_type = ie->key.file_name.file_name_type; name_type = ie->key.file_name.file_name_type;
if (name_type == FILE_NAME_DOS && RHideDosNames(readdir_opts)) { if (name_type == FILE_NAME_DOS) {
ntfs_debug("Skipping DOS name space entry."); ntfs_debug("Skipping DOS name space entry.");
return 0; return 0;
} }
if (RHideLongNames(readdir_opts)) {
if (name_type == FILE_NAME_WIN32 ||
name_type == FILE_NAME_POSIX) {
ntfs_debug("Skipping WIN32/POSIX name space entry.");
return 0;
}
}
if (MREF_LE(ie->_IIF(indexed_file)) == FILE_root) { if (MREF_LE(ie->_IIF(indexed_file)) == FILE_root) {
ntfs_debug("Skipping root directory self reference entry."); ntfs_debug("Skipping root directory self reference entry.");
return 0; return 0;
} }
if (MREF_LE(ie->_IIF(indexed_file)) < FILE_first_user && if (MREF_LE(ie->_IIF(indexed_file)) < FILE_first_user &&
RHideSystemFiles(readdir_opts)) { !NVolShowSystemFiles(vol)) {
ntfs_debug("Skipping system file."); ntfs_debug("Skipping system file.");
return 0; return 0;
} }
...@@ -496,7 +1048,8 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp, ...@@ -496,7 +1048,8 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
(unsigned long long)MREF_LE(ie->_IIF(indexed_file)), (unsigned long long)MREF_LE(ie->_IIF(indexed_file)),
dt_type == DT_DIR ? "DIR" : "REG"); dt_type == DT_DIR ? "DIR" : "REG");
return filldir(dirent, name, name_len, filp->f_pos, return filldir(dirent, name, name_len, filp->f_pos,
(unsigned long)MREF_LE(ie->_IIF(indexed_file)), dt_type); (unsigned long)MREF_LE(ie->_IIF(indexed_file)),
dt_type);
} }
/* /*
...@@ -510,7 +1063,7 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp, ...@@ -510,7 +1063,7 @@ static inline int ntfs_filldir(ntfs_volume *vol, struct file *filp,
* index root entries and then the index allocation entries that are marked * index root entries and then the index allocation entries that are marked
* as in use in the index bitmap. * as in use in the index bitmap.
* While this will return the names in random order this doesn't matter for * While this will return the names in random order this doesn't matter for
* readdir but OTOH results in faster readdir. * readdir but OTOH results in a faster readdir.
*/ */
static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir) static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{ {
......
/*
* dir.h - Defines for directory handling in NTFS Linux kernel driver. Part of
* the Linux-NTFS project.
*
* Copyright (c) 2002 Anton Altaparmakov.
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LINUX_NTFS_DIR_H
#define _LINUX_NTFS_DIR_H
#include "layout.h"
/*
* ntfs_name is used to return the file name to the caller of
* ntfs_lookup_inode_by_name() in order for the caller (namei.c::ntfs_lookup())
* to be able to deal with dcache aliasing issues.
*/
typedef struct {
MFT_REF mref;
FILE_NAME_TYPE_FLAGS type;
u8 len;
uchar_t name[0];
} __attribute__ ((__packed__)) ntfs_name;
/* The little endian Unicode string $I30 as a global constant. */
extern const uchar_t I30[5];
extern u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname,
const int uname_len, ntfs_name **res);
#endif /* _LINUX_NTFS_FS_DIR_H */
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include "ntfs.h" #include "ntfs.h"
#include "dir.h"
struct inode *ntfs_alloc_big_inode(struct super_block *sb) struct inode *ntfs_alloc_big_inode(struct super_block *sb)
{ {
...@@ -1337,13 +1338,6 @@ void ntfs_clear_big_inode(struct inode *vi) ...@@ -1337,13 +1338,6 @@ void ntfs_clear_big_inode(struct inode *vi)
return; return;
} }
static const option_t si_readdir_opts_arr[] = {
{ SHOW_SYSTEM, "system" },
{ SHOW_WIN32, "win32" },
{ SHOW_DOS, "dos" },
{ 0, NULL }
};
/** /**
* ntfs_show_options - show mount options in /proc/mounts * ntfs_show_options - show mount options in /proc/mounts
* @sf: seq_file in which to write our mount options * @sf: seq_file in which to write our mount options
...@@ -1368,20 +1362,10 @@ int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt) ...@@ -1368,20 +1362,10 @@ int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt)
seq_printf(sf, ",dmask=0%o", vol->dmask); seq_printf(sf, ",dmask=0%o", vol->dmask);
} }
seq_printf(sf, ",nls=%s", vol->nls_map->charset); seq_printf(sf, ",nls=%s", vol->nls_map->charset);
switch (vol->readdir_opts) { if (NVolCaseSensitive(vol))
case SHOW_ALL: seq_printf(sf, ",case_sensitive");
seq_printf(sf, ",show_inodes=all"); if (NVolShowSystemFiles(vol))
break; seq_printf(sf, ",show_sys_files");
case SHOW_POSIX:
seq_printf(sf, ",show_inodes=posix");
break;
default:
for (i = 0; si_readdir_opts_arr[i].val; i++) {
if (si_readdir_opts_arr[i].val & vol->readdir_opts)
seq_printf(sf, ",show_inodes=%s",
si_readdir_opts_arr[i].str);
}
}
for (i = 0; on_errors_arr[i].val; i++) { for (i = 0; on_errors_arr[i].val; i++) {
if (on_errors_arr[i].val & vol->on_errors) if (on_errors_arr[i].val & vol->on_errors)
seq_printf(sf, ",errors=%s", on_errors_arr[i].str); seq_printf(sf, ",errors=%s", on_errors_arr[i].str);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include "volume.h" #include "types.h"
/* /*
* Constant endianness conversion defines. * Constant endianness conversion defines.
...@@ -679,7 +679,7 @@ typedef ATTR_RECORD ATTR_REC; ...@@ -679,7 +679,7 @@ typedef ATTR_RECORD ATTR_REC;
*/ */
typedef enum { typedef enum {
/* /*
* These flags are only presnt in the STANDARD_INFORMATION attribute * These flags are only present in the STANDARD_INFORMATION attribute
* (in the field file_attributes). * (in the field file_attributes).
*/ */
FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001), FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001),
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
*/ */
#include "ntfs.h" #include "ntfs.h"
#include "dir.h"
/** /**
* ntfs_lookup - find the inode represented by a dentry in a directory inode * ntfs_lookup - find the inode represented by a dentry in a directory inode
...@@ -43,6 +44,48 @@ ...@@ -43,6 +44,48 @@
* dentry @dent. The dentry is then termed a negative dentry. * dentry @dent. The dentry is then termed a negative dentry.
* *
* Only if an actual error occurs, do we return an error via ERR_PTR(). * Only if an actual error occurs, do we return an error via ERR_PTR().
*
* TODO: Implement the below! (AIA)
*
* In order to handle the case insensitivity issues of NTFS with regards to the
* dcache and the dcache requiring only one dentry per directory, we deal with
* dentry aliases that only differ in case in ->ntfs_lookup() while maintining
* a case sensitive dcache. This means that we get the full benefit of dcache
* speed when the file/directory is looked up with the same case as returned by
* ->ntfs_readdir() but that a lookup for any other case (or for the short file
* name) will not find anything in dcache and will enter ->ntfs_lookup()
* instead, where we search the directory for a fully matching file name
* (including case) and if that is not found, we search for a file name that
* matches with different case and if that has non-POSIX semantics we return
* that. We actually do only one search (case sensitive) and keep tabs on
* whether we have found a case insensitive match in the process.
*
* To simplify matters for us, we do not treat the short vs long filenames as
* two hard links but instead if the lookup matches a short filename, we
* return the dentry for the corresponding long filename instead.
*
* There are three cases we need to distinguish here:
*
* 1) @dent perfectly matches (i.e. including case) a directory entry with a
* file name in the WIN32 or POSIX namespaces. In this case
* ntfs_lookup_inode_by_name() will return with name set to NULL and we
* just d_add() @dent.
* 2) @dent matches (not including case) a directory entry with a file name in
* the WIN32 or POSIX namespaces. In this case ntfs_lookup_inode_by_name()
* will return with name set to point to a kmalloc()ed ntfs_name structure
* containing the properly cased little endian Unicode name. We convert the
* name to the current NLS code page, search if a dentry with this name
* already exists and if so return that instead of @dent. The VFS will then
* destroy the old @dent and use the one we returned. If a dentry is not
* found, we allocate a new one, d_add() it, and return it as above.
* 3) @dent matches either perfectly or not (i.e. we don't care about case) a
* directory entry with a file name in the DOS namespace. In this case
* ntfs_lookup_inode_by_name() will return with name set to point to a
* kmalloc()ed ntfs_name structure containing the mft reference (cpu endian)
* of the inode. We use the mft reference to read the inode and to find the
* file name in the WIN32 namespace corresponding to the matched short file
* name. We then convert the name to the current NLS code page, and proceed
* searching for a dentry with this name, etc, as in case 2), above.
*/ */
static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent) static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent)
{ {
...@@ -52,6 +95,7 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent) ...@@ -52,6 +95,7 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent)
unsigned long dent_ino; unsigned long dent_ino;
uchar_t *uname; uchar_t *uname;
int uname_len; int uname_len;
ntfs_name *name = NULL;
ntfs_debug("Looking up %s in directory inode 0x%lx.", ntfs_debug("Looking up %s in directory inode 0x%lx.",
dent->d_name.name, dir_ino->i_ino); dent->d_name.name, dir_ino->i_ino);
...@@ -62,8 +106,12 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent) ...@@ -62,8 +106,12 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent)
ntfs_error(vol->sb, "Failed to convert name to Unicode."); ntfs_error(vol->sb, "Failed to convert name to Unicode.");
return ERR_PTR(uname_len); return ERR_PTR(uname_len);
} }
mref = ntfs_lookup_inode_by_name(NTFS_I(dir_ino), uname, uname_len); mref = ntfs_lookup_inode_by_name(NTFS_I(dir_ino), uname, uname_len,
&name);
kmem_cache_free(ntfs_name_cache, uname); kmem_cache_free(ntfs_name_cache, uname);
// TODO: Handle name. (AIA)
if (name)
kfree(name);
if (!IS_ERR_MREF(mref)) { if (!IS_ERR_MREF(mref)) {
dent_ino = (unsigned long)MREF(mref); dent_ino = (unsigned long)MREF(mref);
ntfs_debug("Found inode 0x%lx. Calling iget.", dent_ino); ntfs_debug("Found inode 0x%lx. Calling iget.", dent_ino);
...@@ -102,7 +150,10 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent) ...@@ -102,7 +150,10 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent)
return ERR_PTR(MREF_ERR(mref)); return ERR_PTR(MREF_ERR(mref));
} }
/*
* Inode operations for directories.
*/
struct inode_operations ntfs_dir_inode_ops = { struct inode_operations ntfs_dir_inode_ops = {
lookup: ntfs_lookup, /* lookup directory. */ lookup: ntfs_lookup, /* VFS: Lookup directory. */
}; };
...@@ -96,9 +96,6 @@ extern kmem_cache_t *ntfs_inode_cache; ...@@ -96,9 +96,6 @@ extern kmem_cache_t *ntfs_inode_cache;
extern kmem_cache_t *ntfs_big_inode_cache; extern kmem_cache_t *ntfs_big_inode_cache;
extern kmem_cache_t *ntfs_attr_ctx_cache; extern kmem_cache_t *ntfs_attr_ctx_cache;
/* The little endian Unicode string $I30 as a global constant. */
extern const uchar_t I30[5];
/* The various operations structs defined throughout the driver files. */ /* The various operations structs defined throughout the driver files. */
extern struct super_operations ntfs_mount_sops; extern struct super_operations ntfs_mount_sops;
extern struct super_operations ntfs_sops; extern struct super_operations ntfs_sops;
...@@ -223,10 +220,6 @@ extern inline s64 utc2ntfs(const time_t time); ...@@ -223,10 +220,6 @@ extern inline s64 utc2ntfs(const time_t time);
extern inline s64 get_current_ntfs_time(void); extern inline s64 get_current_ntfs_time(void);
extern inline time_t ntfs2utc(const s64 time); extern inline time_t ntfs2utc(const s64 time);
/* From fs/ntfs/dir.c */
extern u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname,
const int uname_len);
/* From fs/ntfs/unistr.c */ /* From fs/ntfs/unistr.c */
extern BOOL ntfs_are_names_equal(const uchar_t *s1, size_t s1_len, extern BOOL ntfs_are_names_equal(const uchar_t *s1, size_t s1_len,
const uchar_t *s2, size_t s2_len, const uchar_t *s2, size_t s2_len,
......
...@@ -52,17 +52,6 @@ const option_t on_errors_arr[] = { ...@@ -52,17 +52,6 @@ const option_t on_errors_arr[] = {
{ 0, NULL } { 0, NULL }
}; };
static const option_t readdir_opts_arr[] = {
{ SHOW_SYSTEM, "system" },
{ SHOW_WIN32, "win32" },
{ SHOW_WIN32, "long" },
{ SHOW_DOS, "dos" },
{ SHOW_DOS, "short" },
{ SHOW_POSIX, "posix" },
{ SHOW_ALL, "all" },
{ 0, NULL }
};
/** /**
* simple_getbool - * simple_getbool -
* *
...@@ -98,7 +87,8 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) ...@@ -98,7 +87,8 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
uid_t uid = (uid_t)-1; uid_t uid = (uid_t)-1;
gid_t gid = (gid_t)-1; gid_t gid = (gid_t)-1;
mode_t fmask = (mode_t)-1, dmask = (mode_t)-1; mode_t fmask = (mode_t)-1, dmask = (mode_t)-1;
int mft_zone_multiplier = -1, on_errors = -1, readdir_opts = -1; int mft_zone_multiplier = -1, on_errors = -1;
int show_sys_files = -1, case_sensitive = -1;
struct nls_table *nls_map = NULL, *old_nls; struct nls_table *nls_map = NULL, *old_nls;
/* I am lazy... (-8 */ /* I am lazy... (-8 */
...@@ -120,6 +110,13 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) ...@@ -120,6 +110,13 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
if (*v) \ if (*v) \
goto needs_val; \ goto needs_val; \
} }
#define NTFS_GETOPT_BOOL(option, variable) \
if (!strcmp(p, option)) { \
BOOL val; \
if (!simple_getbool(v, &val)) \
goto needs_bool; \
variable = val; \
}
#define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \ #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \
if (!strcmp(p, option)) { \ if (!strcmp(p, option)) { \
int _i; \ int _i; \
...@@ -146,47 +143,16 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) ...@@ -146,47 +143,16 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
else NTFS_GETOPT("umask", fmask = dmask) else NTFS_GETOPT("umask", fmask = dmask)
else NTFS_GETOPT("fmask", fmask) else NTFS_GETOPT("fmask", fmask)
else NTFS_GETOPT("dmask", dmask) else NTFS_GETOPT("dmask", dmask)
else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE)
else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier)
else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE)
else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive)
else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors,
on_errors_arr) on_errors_arr)
else NTFS_GETOPT_OPTIONS_ARRAY("show_inodes", readdir_opts, else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes"))
readdir_opts_arr) ntfs_warning(vol->sb, "Ignoring obsolete option %s.",
else if (!strcmp(p, "show_sys_files")) { p);
BOOL val = FALSE; else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) {
ntfs_warning(vol->sb, "Option show_sys_files is "
"deprecated. Please use option "
"show_inodes=system in the future.");
if (!v || !*v)
val = TRUE;
else if (!simple_getbool(v, &val))
goto needs_bool;
if (val) {
if (readdir_opts == -1)
readdir_opts = 0;
readdir_opts |= SHOW_SYSTEM;
}
} else if (!strcmp(p, "posix")) {
BOOL val = FALSE;
ntfs_warning(vol->sb, "Option posix is deprecated. "
"Please use option show_inodes=posix "
"instead. Be aware that some userspace "
"applications may be confused by this, "
"since the short and long names of "
"directory inodes will have the same inode "
"numbers, yet each will only have a link "
"count of 1 due to Linux not supporting "
"directory hard links.");
if (!v || !*v)
goto needs_arg;
else if (!simple_getbool(v, &val))
goto needs_bool;
if (val) {
if (readdir_opts == -1)
readdir_opts = 0;
readdir_opts |= SHOW_POSIX;
}
} else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) {
if (!strcmp(p, "iocharset")) if (!strcmp(p, "iocharset"))
ntfs_warning(vol->sb, "Option iocharset is " ntfs_warning(vol->sb, "Option iocharset is "
"deprecated. Please use " "deprecated. Please use "
...@@ -232,6 +198,7 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) ...@@ -232,6 +198,7 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
errors++; errors++;
} }
#undef NTFS_GETOPT_OPTIONS_ARRAY #undef NTFS_GETOPT_OPTIONS_ARRAY
#undef NTFS_GETOPT_BOOL
#undef NTFS_GETOPT #undef NTFS_GETOPT
#undef NTFS_GETOPT_WITH_DEFAULT #undef NTFS_GETOPT_WITH_DEFAULT
} }
...@@ -297,8 +264,18 @@ static BOOL parse_options(ntfs_volume *vol, char *opt) ...@@ -297,8 +264,18 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
vol->fmask = fmask; vol->fmask = fmask;
if (dmask != (mode_t)-1) if (dmask != (mode_t)-1)
vol->dmask = dmask; vol->dmask = dmask;
if (readdir_opts != -1) if (show_sys_files != -1) {
vol->readdir_opts = readdir_opts; if (show_sys_files)
NVolSetShowSystemFiles(vol);
else
NVolClearShowSystemFiles(vol);
}
if (case_sensitive != -1) {
if (case_sensitive)
NVolSetCaseSensitive(vol);
else
NVolClearCaseSensitive(vol);
}
return TRUE; return TRUE;
needs_arg: needs_arg:
ntfs_error(vol->sb, "The %s option requires an argument.", p); ntfs_error(vol->sb, "The %s option requires an argument.", p);
...@@ -1492,6 +1469,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) ...@@ -1492,6 +1469,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
vol->root_ino = NULL; vol->root_ino = NULL;
vol->secure_ino = NULL; vol->secure_ino = NULL;
vol->uid = vol->gid = 0; vol->uid = vol->gid = 0;
vol->flags = 0;
vol->on_errors = 0; vol->on_errors = 0;
vol->mft_zone_multiplier = 0; vol->mft_zone_multiplier = 0;
vol->nls_map = NULL; vol->nls_map = NULL;
...@@ -1531,12 +1509,6 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) ...@@ -1531,12 +1509,6 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
vol->fmask = 0177; vol->fmask = 0177;
vol->dmask = 0077; vol->dmask = 0077;
/*
* Default is to show long file names (including POSIX file names), and
* not to show system files and short file names.
*/
vol->readdir_opts = SHOW_WIN32;
/* Important to get the mount options dealt with now. */ /* Important to get the mount options dealt with now. */
if (!parse_options(vol, (char*)opt)) if (!parse_options(vol, (char*)opt))
goto err_out_now; goto err_out_now;
......
...@@ -26,18 +26,30 @@ ...@@ -26,18 +26,30 @@
#include "types.h" #include "types.h"
/* These are used to determine which inode names are returned by readdir(). */ /*
* Defined bits for the flags field in the ntfs_volume structure.
*/
typedef enum { typedef enum {
SHOW_SYSTEM = 1, NV_ShowSystemFiles, /* 1: Return system files in ntfs_readdir(). */
SHOW_WIN32 = 2, NV_CaseSensitive, /* 1: Treat file names as case sensitive and
SHOW_DOS = 4, create filenames in the POSIX namespace.
SHOW_POSIX = SHOW_WIN32 | SHOW_DOS, Otherwise be case insensitive and create
SHOW_ALL = SHOW_SYSTEM | SHOW_POSIX, file names in WIN32 namespace. */
} READDIR_OPTIONS; } ntfs_volume_flags;
#define NVolShowSystemFiles(n_vol) test_bit(NV_ShowSystemFiles, \
&(n_vol)->flags)
#define NVolSetShowSystemFiles(n_vol) set_bit(NV_ShowSystemFiles, \
&(n_vol)->flags)
#define NVolClearShowSystemFiles(n_vol) clear_bit(NV_ShowSystemFiles, \
&(n_vol)->flags)
#define RHideSystemFiles(x) (!((x) & SHOW_SYSTEM)) #define NVolCaseSensitive(n_vol) test_bit(NV_CaseSensitive, \
#define RHideLongNames(x) (!((x) & SHOW_WIN32)) &(n_vol)->flags)
#define RHideDosNames(x) (!((x) & SHOW_DOS)) #define NVolSetCaseSensitive(n_vol) set_bit(NV_CaseSensitive, \
&(n_vol)->flags)
#define NVolClearCaseSensitive(n_vol) clear_bit(NV_CaseSensitive, \
&(n_vol)->flags)
/* /*
* The NTFS in memory super block structure. * The NTFS in memory super block structure.
...@@ -57,13 +69,13 @@ typedef struct { ...@@ -57,13 +69,13 @@ typedef struct {
LCN nr_blocks; /* Number of NTFS_BLOCK_SIZE bytes LCN nr_blocks; /* Number of NTFS_BLOCK_SIZE bytes
sized blocks on the device. */ sized blocks on the device. */
/* Configuration provided by user at mount time. */ /* Configuration provided by user at mount time. */
unsigned long flags; /* Miscellaneous flags, see above. */
uid_t uid; /* uid that files will be mounted as. */ uid_t uid; /* uid that files will be mounted as. */
gid_t gid; /* gid that files will be mounted as. */ gid_t gid; /* gid that files will be mounted as. */
mode_t fmask; /* The mask for file permissions. */ mode_t fmask; /* The mask for file permissions. */
mode_t dmask; /* The mask for directory mode_t dmask; /* The mask for directory
permissions. */ permissions. */
READDIR_OPTIONS readdir_opts; /* Namespace of inode names to show. */ u8 mft_zone_multiplier; /* Initial mft zone multiplier. */
u8 mft_zone_multiplier; /* Initial mft zone multiplier. */
u8 on_errors; /* What to do on file system errors. */ u8 on_errors; /* What to do on file system errors. */
/* NTFS bootsector provided information. */ /* NTFS bootsector provided information. */
u16 sector_size; /* in bytes */ u16 sector_size; /* in bytes */
......
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