2 * dir.c - NTFS kernel directory operations. Part of the Linux-NTFS project.
4 * Copyright (c) 2001-2004 Anton Altaparmakov
5 * Copyright (c) 2002 Richard Russon
7 * This program/include file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program/include file is distributed in the hope that it will be
13 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program (in the main directory of the Linux-NTFS
19 * distribution in the file COPYING); if not, write to the Free Software
20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/smp_lock.h>
28 * The little endian Unicode string $I30 as a global constant.
30 ntfschar I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'),
31 const_cpu_to_le16('3'), const_cpu_to_le16('0'),
32 const_cpu_to_le16(0) };
35 * ntfs_lookup_inode_by_name - find an inode in a directory given its name
36 * @dir_ni: ntfs inode of the directory in which to search for the name
37 * @uname: Unicode name for which to search in the directory
38 * @uname_len: length of the name @uname in Unicode characters
39 * @res: return the found file name if necessary (see below)
41 * Look for an inode with name @uname in the directory with inode @dir_ni.
42 * ntfs_lookup_inode_by_name() walks the contents of the directory looking for
43 * the Unicode name. If the name is found in the directory, the corresponding
44 * inode number (>= 0) is returned as a mft reference in cpu format, i.e. it
45 * is a 64-bit number containing the sequence number.
47 * On error, a negative value is returned corresponding to the error code. In
48 * particular if the inode is not found -ENOENT is returned. Note that you
49 * can't just check the return value for being negative, you have to check the
50 * inode number for being negative which you can extract using MREC(return
53 * Note, @uname_len does not include the (optional) terminating NULL character.
55 * Note, we look for a case sensitive match first but we also look for a case
56 * insensitive match at the same time. If we find a case insensitive match, we
57 * save that for the case that we don't find an exact match, where we return
58 * the case insensitive match and setup @res (which we allocate!) with the mft
59 * reference, the file name type, length and with a copy of the little endian
60 * Unicode file name itself. If we match a file name which is in the DOS name
61 * space, we only return the mft reference and file name type in @res.
62 * ntfs_lookup() then uses this to find the long file name in the inode itself.
63 * This is to avoid polluting the dcache with short file names. We want them to
64 * work but we don't care for how quickly one can access them. This also fixes
65 * the dcache aliasing issues.
67 MFT_REF ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
68 const int uname_len, ntfs_name **res)
70 ntfs_volume *vol = dir_ni->vol;
71 struct super_block *sb = vol->sb;
78 attr_search_context *ctx;
81 struct address_space *ia_mapping;
84 ntfs_name *name = NULL;
86 /* Get hold of the mft record for the directory. */
87 m = map_mft_record(dir_ni);
88 if (unlikely(IS_ERR(m))) {
89 ntfs_error(sb, "map_mft_record() failed with error code %ld.",
91 return ERR_MREF(PTR_ERR(m));
93 ctx = get_attr_search_ctx(dir_ni, m);
98 /* Find the index root attribute in the mft record. */
99 if (!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0,
101 ntfs_error(sb, "Index root attribute missing in directory "
102 "inode 0x%lx.", dir_ni->mft_no);
106 /* Get to the index root value (it's been verified in read_inode). */
107 ir = (INDEX_ROOT*)((u8*)ctx->attr +
108 le16_to_cpu(ctx->attr->data.resident.value_offset));
109 index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
110 /* The first index entry. */
111 ie = (INDEX_ENTRY*)((u8*)&ir->index +
112 le32_to_cpu(ir->index.entries_offset));
114 * Loop until we exceed valid memory (corruption case) or until we
115 * reach the last entry.
117 for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
119 if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie +
120 sizeof(INDEX_ENTRY_HEADER) > index_end ||
121 (u8*)ie + le16_to_cpu(ie->key_length) >
125 * The last entry cannot contain a name. It can however contain
126 * a pointer to a child node in the B+tree so we just break out.
128 if (ie->flags & INDEX_ENTRY_END)
131 * We perform a case sensitive comparison and if that matches
132 * we are done and return the mft reference of the inode (i.e.
133 * the inode number together with the sequence number for
134 * consistency checking). We convert it to cpu format before
137 if (ntfs_are_names_equal(uname, uname_len,
138 (ntfschar*)&ie->key.file_name.file_name,
139 ie->key.file_name.file_name_length,
140 CASE_SENSITIVE, vol->upcase, vol->upcase_len)) {
143 * We have a perfect match, so we don't need to care
144 * about having matched imperfectly before, so we can
145 * free name and set *res to NULL.
146 * However, if the perfect match is a short file name,
147 * we need to signal this through *res, so that
148 * ntfs_lookup() can fix dcache aliasing issues.
149 * As an optimization we just reuse an existing
150 * allocation of *res.
152 if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
154 name = kmalloc(sizeof(ntfs_name),
161 name->mref = le64_to_cpu(
162 ie->data.dir.indexed_file);
163 name->type = FILE_NAME_DOS;
171 mref = le64_to_cpu(ie->data.dir.indexed_file);
172 put_attr_search_ctx(ctx);
173 unmap_mft_record(dir_ni);
177 * For a case insensitive mount, we also perform a case
178 * insensitive comparison (provided the file name is not in the
179 * POSIX namespace). If the comparison matches, and the name is
180 * in the WIN32 namespace, we cache the filename in *res so
181 * that the caller, ntfs_lookup(), can work on it. If the
182 * comparison matches, and the name is in the DOS namespace, we
183 * only cache the mft reference and the file name type (we set
184 * the name length to zero for simplicity).
186 if (!NVolCaseSensitive(vol) &&
187 ie->key.file_name.file_name_type &&
188 ntfs_are_names_equal(uname, uname_len,
189 (ntfschar*)&ie->key.file_name.file_name,
190 ie->key.file_name.file_name_length,
191 IGNORE_CASE, vol->upcase, vol->upcase_len)) {
192 int name_size = sizeof(ntfs_name);
193 u8 type = ie->key.file_name.file_name_type;
194 u8 len = ie->key.file_name.file_name_length;
196 /* Only one case insensitive matching name allowed. */
198 ntfs_error(sb, "Found already allocated name "
199 "in phase 1. Please run chkdsk "
200 "and if that doesn't find any "
201 "errors please report you saw "
203 "linux-ntfs-dev@lists."
208 if (type != FILE_NAME_DOS)
209 name_size += len * sizeof(ntfschar);
210 name = kmalloc(name_size, GFP_NOFS);
215 name->mref = le64_to_cpu(ie->data.dir.indexed_file);
217 if (type != FILE_NAME_DOS) {
219 memcpy(name->name, ie->key.file_name.file_name,
220 len * sizeof(ntfschar));
226 * Not a perfect match, need to do full blown collation so we
227 * know which way in the B+tree we have to go.
229 rc = ntfs_collate_names(uname, uname_len,
230 (ntfschar*)&ie->key.file_name.file_name,
231 ie->key.file_name.file_name_length, 1,
232 IGNORE_CASE, vol->upcase, vol->upcase_len);
234 * If uname collates before the name of the current entry, there
235 * is definitely no such name in this index but we might need to
236 * descend into the B+tree so we just break out of the loop.
240 /* The names are not equal, continue the search. */
244 * Names match with case insensitive comparison, now try the
245 * case sensitive comparison, which is required for proper
248 rc = ntfs_collate_names(uname, uname_len,
249 (ntfschar*)&ie->key.file_name.file_name,
250 ie->key.file_name.file_name_length, 1,
251 CASE_SENSITIVE, vol->upcase, vol->upcase_len);
257 * Perfect match, this will never happen as the
258 * ntfs_are_names_equal() call will have gotten a match but we
259 * still treat it correctly.
264 * We have finished with this index without success. Check for the
265 * presence of a child node and if not present return -ENOENT, unless
266 * we have got a matching name cached in name in which case return the
267 * mft reference associated with it.
269 if (!(ie->flags & INDEX_ENTRY_NODE)) {
271 put_attr_search_ctx(ctx);
272 unmap_mft_record(dir_ni);
275 ntfs_debug("Entry not found.");
278 } /* Child node present, descend into it. */
279 /* Consistency check: Verify that an index allocation exists. */
280 if (!NInoIndexAllocPresent(dir_ni)) {
281 ntfs_error(sb, "No index allocation attribute but index entry "
282 "requires one. Directory inode 0x%lx is "
283 "corrupt or driver bug.", dir_ni->mft_no);
287 /* Get the starting vcn of the index_block holding the child node. */
288 vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
289 ia_mapping = VFS_I(dir_ni)->i_mapping;
291 * We are done with the index root and the mft record. Release them,
292 * otherwise we deadlock with ntfs_map_page().
294 put_attr_search_ctx(ctx);
295 unmap_mft_record(dir_ni);
298 descend_into_child_node:
300 * Convert vcn to index into the index allocation attribute in units
301 * of PAGE_CACHE_SIZE and map the page cache page, reading it from
304 page = ntfs_map_page(ia_mapping, vcn <<
305 dir_ni->itype.index.vcn_size_bits >> PAGE_CACHE_SHIFT);
307 ntfs_error(sb, "Failed to map directory index page, error %ld.",
312 kaddr = (u8*)page_address(page);
313 fast_descend_into_child_node:
314 /* Get to the index allocation block. */
315 ia = (INDEX_ALLOCATION*)(kaddr + ((vcn <<
316 dir_ni->itype.index.vcn_size_bits) & ~PAGE_CACHE_MASK));
318 if ((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE) {
319 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
320 "inode 0x%lx or driver bug.", dir_ni->mft_no);
324 if (sle64_to_cpu(ia->index_block_vcn) != vcn) {
325 ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
326 "different from expected VCN (0x%llx). "
327 "Directory inode 0x%lx is corrupt or driver "
328 "bug.", (unsigned long long)
329 sle64_to_cpu(ia->index_block_vcn),
330 (unsigned long long)vcn, dir_ni->mft_no);
334 if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
335 dir_ni->itype.index.block_size) {
336 ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
337 "0x%lx has a size (%u) differing from the "
338 "directory specified size (%u). Directory "
339 "inode is corrupt or driver bug.",
340 (unsigned long long)vcn, dir_ni->mft_no,
341 le32_to_cpu(ia->index.allocated_size) + 0x18,
342 dir_ni->itype.index.block_size);
346 index_end = (u8*)ia + dir_ni->itype.index.block_size;
347 if (index_end > kaddr + PAGE_CACHE_SIZE) {
348 ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
349 "0x%lx crosses page boundary. Impossible! "
350 "Cannot access! This is probably a bug in the "
351 "driver.", (unsigned long long)vcn,
356 index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
357 if (index_end > (u8*)ia + dir_ni->itype.index.block_size) {
358 ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of directory "
359 "inode 0x%lx exceeds maximum size.",
360 (unsigned long long)vcn, dir_ni->mft_no);
364 /* The first index entry. */
365 ie = (INDEX_ENTRY*)((u8*)&ia->index +
366 le32_to_cpu(ia->index.entries_offset));
368 * Iterate similar to above big loop but applied to index buffer, thus
369 * loop until we exceed valid memory (corruption case) or until we
370 * reach the last entry.
372 for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
374 if ((u8*)ie < (u8*)ia || (u8*)ie +
375 sizeof(INDEX_ENTRY_HEADER) > index_end ||
376 (u8*)ie + le16_to_cpu(ie->key_length) >
378 ntfs_error(sb, "Index entry out of bounds in "
379 "directory inode 0x%lx.",
385 * The last entry cannot contain a name. It can however contain
386 * a pointer to a child node in the B+tree so we just break out.
388 if (ie->flags & INDEX_ENTRY_END)
391 * We perform a case sensitive comparison and if that matches
392 * we are done and return the mft reference of the inode (i.e.
393 * the inode number together with the sequence number for
394 * consistency checking). We convert it to cpu format before
397 if (ntfs_are_names_equal(uname, uname_len,
398 (ntfschar*)&ie->key.file_name.file_name,
399 ie->key.file_name.file_name_length,
400 CASE_SENSITIVE, vol->upcase, vol->upcase_len)) {
403 * We have a perfect match, so we don't need to care
404 * about having matched imperfectly before, so we can
405 * free name and set *res to NULL.
406 * However, if the perfect match is a short file name,
407 * we need to signal this through *res, so that
408 * ntfs_lookup() can fix dcache aliasing issues.
409 * As an optimization we just reuse an existing
410 * allocation of *res.
412 if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
414 name = kmalloc(sizeof(ntfs_name),
421 name->mref = le64_to_cpu(
422 ie->data.dir.indexed_file);
423 name->type = FILE_NAME_DOS;
431 mref = le64_to_cpu(ie->data.dir.indexed_file);
432 ntfs_unmap_page(page);
436 * For a case insensitive mount, we also perform a case
437 * insensitive comparison (provided the file name is not in the
438 * POSIX namespace). If the comparison matches, and the name is
439 * in the WIN32 namespace, we cache the filename in *res so
440 * that the caller, ntfs_lookup(), can work on it. If the
441 * comparison matches, and the name is in the DOS namespace, we
442 * only cache the mft reference and the file name type (we set
443 * the name length to zero for simplicity).
445 if (!NVolCaseSensitive(vol) &&
446 ie->key.file_name.file_name_type &&
447 ntfs_are_names_equal(uname, uname_len,
448 (ntfschar*)&ie->key.file_name.file_name,
449 ie->key.file_name.file_name_length,
450 IGNORE_CASE, vol->upcase, vol->upcase_len)) {
451 int name_size = sizeof(ntfs_name);
452 u8 type = ie->key.file_name.file_name_type;
453 u8 len = ie->key.file_name.file_name_length;
455 /* Only one case insensitive matching name allowed. */
457 ntfs_error(sb, "Found already allocated name "
458 "in phase 2. Please run chkdsk "
459 "and if that doesn't find any "
460 "errors please report you saw "
462 "linux-ntfs-dev@lists."
464 ntfs_unmap_page(page);
468 if (type != FILE_NAME_DOS)
469 name_size += len * sizeof(ntfschar);
470 name = kmalloc(name_size, GFP_NOFS);
475 name->mref = le64_to_cpu(ie->data.dir.indexed_file);
477 if (type != FILE_NAME_DOS) {
479 memcpy(name->name, ie->key.file_name.file_name,
480 len * sizeof(ntfschar));
486 * Not a perfect match, need to do full blown collation so we
487 * know which way in the B+tree we have to go.
489 rc = ntfs_collate_names(uname, uname_len,
490 (ntfschar*)&ie->key.file_name.file_name,
491 ie->key.file_name.file_name_length, 1,
492 IGNORE_CASE, vol->upcase, vol->upcase_len);
494 * If uname collates before the name of the current entry, there
495 * is definitely no such name in this index but we might need to
496 * descend into the B+tree so we just break out of the loop.
500 /* The names are not equal, continue the search. */
504 * Names match with case insensitive comparison, now try the
505 * case sensitive comparison, which is required for proper
508 rc = ntfs_collate_names(uname, uname_len,
509 (ntfschar*)&ie->key.file_name.file_name,
510 ie->key.file_name.file_name_length, 1,
511 CASE_SENSITIVE, vol->upcase, vol->upcase_len);
517 * Perfect match, this will never happen as the
518 * ntfs_are_names_equal() call will have gotten a match but we
519 * still treat it correctly.
524 * We have finished with this index buffer without success. Check for
525 * the presence of a child node.
527 if (ie->flags & INDEX_ENTRY_NODE) {
528 if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
529 ntfs_error(sb, "Index entry with child node found in "
530 "a leaf node in directory inode 0x%lx.",
535 /* Child node present, descend into it. */
537 vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
539 /* If vcn is in the same page cache page as old_vcn we
540 * recycle the mapped page. */
541 if (old_vcn << vol->cluster_size_bits >>
542 PAGE_CACHE_SHIFT == vcn <<
543 vol->cluster_size_bits >>
545 goto fast_descend_into_child_node;
546 ntfs_unmap_page(page);
547 goto descend_into_child_node;
549 ntfs_error(sb, "Negative child node vcn in directory inode "
550 "0x%lx.", dir_ni->mft_no);
555 * No child node present, return -ENOENT, unless we have got a matching
556 * name cached in name in which case return the mft reference
557 * associated with it.
560 ntfs_unmap_page(page);
563 ntfs_debug("Entry not found.");
566 ntfs_unmap_page(page);
569 put_attr_search_ctx(ctx);
571 unmap_mft_record(dir_ni);
576 return ERR_MREF(err);
578 ntfs_error(sb, "Corrupt directory. Aborting lookup.");
586 // The algorithm embedded in this code will be required for the time when we
587 // want to support adding of entries to directories, where we require correct
588 // collation of file names in order not to cause corruption of the file system.
591 * ntfs_lookup_inode_by_name - find an inode in a directory given its name
592 * @dir_ni: ntfs inode of the directory in which to search for the name
593 * @uname: Unicode name for which to search in the directory
594 * @uname_len: length of the name @uname in Unicode characters
596 * Look for an inode with name @uname in the directory with inode @dir_ni.
597 * ntfs_lookup_inode_by_name() walks the contents of the directory looking for
598 * the Unicode name. If the name is found in the directory, the corresponding
599 * inode number (>= 0) is returned as a mft reference in cpu format, i.e. it
600 * is a 64-bit number containing the sequence number.
602 * On error, a negative value is returned corresponding to the error code. In
603 * particular if the inode is not found -ENOENT is returned. Note that you
604 * can't just check the return value for being negative, you have to check the
605 * inode number for being negative which you can extract using MREC(return
608 * Note, @uname_len does not include the (optional) terminating NULL character.
610 u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
613 ntfs_volume *vol = dir_ni->vol;
614 struct super_block *sb = vol->sb;
618 INDEX_ALLOCATION *ia;
621 attr_search_context *ctx;
625 struct address_space *ia_mapping;
629 /* Get hold of the mft record for the directory. */
630 m = map_mft_record(dir_ni);
632 ntfs_error(sb, "map_mft_record() failed with error code %ld.",
634 return ERR_MREF(PTR_ERR(m));
636 ctx = get_attr_search_ctx(dir_ni, m);
641 /* Find the index root attribute in the mft record. */
642 if (!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0,
644 ntfs_error(sb, "Index root attribute missing in directory "
645 "inode 0x%lx.", dir_ni->mft_no);
649 /* Get to the index root value (it's been verified in read_inode). */
650 ir = (INDEX_ROOT*)((u8*)ctx->attr +
651 le16_to_cpu(ctx->attr->data.resident.value_offset));
652 index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
653 /* The first index entry. */
654 ie = (INDEX_ENTRY*)((u8*)&ir->index +
655 le32_to_cpu(ir->index.entries_offset));
657 * Loop until we exceed valid memory (corruption case) or until we
658 * reach the last entry.
660 for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
662 if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie +
663 sizeof(INDEX_ENTRY_HEADER) > index_end ||
664 (u8*)ie + le16_to_cpu(ie->key_length) >
668 * The last entry cannot contain a name. It can however contain
669 * a pointer to a child node in the B+tree so we just break out.
671 if (ie->flags & INDEX_ENTRY_END)
674 * If the current entry has a name type of POSIX, the name is
675 * case sensitive and not otherwise. This has the effect of us
676 * not being able to access any POSIX file names which collate
677 * after the non-POSIX one when they only differ in case, but
678 * anyone doing screwy stuff like that deserves to burn in
679 * hell... Doing that kind of stuff on NT4 actually causes
680 * corruption on the partition even when using SP6a and Linux
681 * is not involved at all.
683 ic = ie->key.file_name.file_name_type ? IGNORE_CASE :
686 * If the names match perfectly, we are done and return the
687 * mft reference of the inode (i.e. the inode number together
688 * with the sequence number for consistency checking. We
689 * convert it to cpu format before returning.
691 if (ntfs_are_names_equal(uname, uname_len,
692 (ntfschar*)&ie->key.file_name.file_name,
693 ie->key.file_name.file_name_length, ic,
694 vol->upcase, vol->upcase_len)) {
696 mref = le64_to_cpu(ie->data.dir.indexed_file);
697 put_attr_search_ctx(ctx);
698 unmap_mft_record(dir_ni);
702 * Not a perfect match, need to do full blown collation so we
703 * know which way in the B+tree we have to go.
705 rc = ntfs_collate_names(uname, uname_len,
706 (ntfschar*)&ie->key.file_name.file_name,
707 ie->key.file_name.file_name_length, 1,
708 IGNORE_CASE, vol->upcase, vol->upcase_len);
710 * If uname collates before the name of the current entry, there
711 * is definitely no such name in this index but we might need to
712 * descend into the B+tree so we just break out of the loop.
716 /* The names are not equal, continue the search. */
720 * Names match with case insensitive comparison, now try the
721 * case sensitive comparison, which is required for proper
724 rc = ntfs_collate_names(uname, uname_len,
725 (ntfschar*)&ie->key.file_name.file_name,
726 ie->key.file_name.file_name_length, 1,
727 CASE_SENSITIVE, vol->upcase, vol->upcase_len);
733 * Perfect match, this will never happen as the
734 * ntfs_are_names_equal() call will have gotten a match but we
735 * still treat it correctly.
740 * We have finished with this index without success. Check for the
741 * presence of a child node.
743 if (!(ie->flags & INDEX_ENTRY_NODE)) {
744 /* No child node, return -ENOENT. */
747 } /* Child node present, descend into it. */
748 /* Consistency check: Verify that an index allocation exists. */
749 if (!NInoIndexAllocPresent(dir_ni)) {
750 ntfs_error(sb, "No index allocation attribute but index entry "
751 "requires one. Directory inode 0x%lx is "
752 "corrupt or driver bug.", dir_ni->mft_no);
756 /* Get the starting vcn of the index_block holding the child node. */
757 vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
758 ia_mapping = VFS_I(dir_ni)->i_mapping;
760 * We are done with the index root and the mft record. Release them,
761 * otherwise we deadlock with ntfs_map_page().
763 put_attr_search_ctx(ctx);
764 unmap_mft_record(dir_ni);
767 descend_into_child_node:
769 * Convert vcn to index into the index allocation attribute in units
770 * of PAGE_CACHE_SIZE and map the page cache page, reading it from
773 page = ntfs_map_page(ia_mapping, vcn <<
774 dir_ni->itype.index.vcn_size_bits >> PAGE_CACHE_SHIFT);
776 ntfs_error(sb, "Failed to map directory index page, error %ld.",
781 kaddr = (u8*)page_address(page);
782 fast_descend_into_child_node:
783 /* Get to the index allocation block. */
784 ia = (INDEX_ALLOCATION*)(kaddr + ((vcn <<
785 dir_ni->itype.index.vcn_size_bits) & ~PAGE_CACHE_MASK));
787 if ((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE) {
788 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
789 "inode 0x%lx or driver bug.", dir_ni->mft_no);
793 if (sle64_to_cpu(ia->index_block_vcn) != vcn) {
794 ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
795 "different from expected VCN (0x%llx). "
796 "Directory inode 0x%lx is corrupt or driver "
797 "bug.", (unsigned long long)
798 sle64_to_cpu(ia->index_block_vcn),
799 (unsigned long long)vcn, dir_ni->mft_no);
803 if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
804 dir_ni->itype.index.block_size) {
805 ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
806 "0x%lx has a size (%u) differing from the "
807 "directory specified size (%u). Directory "
808 "inode is corrupt or driver bug.",
809 (unsigned long long)vcn, dir_ni->mft_no,
810 le32_to_cpu(ia->index.allocated_size) + 0x18,
811 dir_ni->itype.index.block_size);
815 index_end = (u8*)ia + dir_ni->itype.index.block_size;
816 if (index_end > kaddr + PAGE_CACHE_SIZE) {
817 ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
818 "0x%lx crosses page boundary. Impossible! "
819 "Cannot access! This is probably a bug in the "
820 "driver.", (unsigned long long)vcn,
825 index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
826 if (index_end > (u8*)ia + dir_ni->itype.index.block_size) {
827 ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of directory "
828 "inode 0x%lx exceeds maximum size.",
829 (unsigned long long)vcn, dir_ni->mft_no);
833 /* The first index entry. */
834 ie = (INDEX_ENTRY*)((u8*)&ia->index +
835 le32_to_cpu(ia->index.entries_offset));
837 * Iterate similar to above big loop but applied to index buffer, thus
838 * loop until we exceed valid memory (corruption case) or until we
839 * reach the last entry.
841 for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
843 if ((u8*)ie < (u8*)ia || (u8*)ie +
844 sizeof(INDEX_ENTRY_HEADER) > index_end ||
845 (u8*)ie + le16_to_cpu(ie->key_length) >
847 ntfs_error(sb, "Index entry out of bounds in "
848 "directory inode 0x%lx.",
854 * The last entry cannot contain a name. It can however contain
855 * a pointer to a child node in the B+tree so we just break out.
857 if (ie->flags & INDEX_ENTRY_END)
860 * If the current entry has a name type of POSIX, the name is
861 * case sensitive and not otherwise. This has the effect of us
862 * not being able to access any POSIX file names which collate
863 * after the non-POSIX one when they only differ in case, but
864 * anyone doing screwy stuff like that deserves to burn in
865 * hell... Doing that kind of stuff on NT4 actually causes
866 * corruption on the partition even when using SP6a and Linux
867 * is not involved at all.
869 ic = ie->key.file_name.file_name_type ? IGNORE_CASE :
872 * If the names match perfectly, we are done and return the
873 * mft reference of the inode (i.e. the inode number together
874 * with the sequence number for consistency checking. We
875 * convert it to cpu format before returning.
877 if (ntfs_are_names_equal(uname, uname_len,
878 (ntfschar*)&ie->key.file_name.file_name,
879 ie->key.file_name.file_name_length, ic,
880 vol->upcase, vol->upcase_len)) {
882 mref = le64_to_cpu(ie->data.dir.indexed_file);
883 ntfs_unmap_page(page);
887 * Not a perfect match, need to do full blown collation so we
888 * know which way in the B+tree we have to go.
890 rc = ntfs_collate_names(uname, uname_len,
891 (ntfschar*)&ie->key.file_name.file_name,
892 ie->key.file_name.file_name_length, 1,
893 IGNORE_CASE, vol->upcase, vol->upcase_len);
895 * If uname collates before the name of the current entry, there
896 * is definitely no such name in this index but we might need to
897 * descend into the B+tree so we just break out of the loop.
901 /* The names are not equal, continue the search. */
905 * Names match with case insensitive comparison, now try the
906 * case sensitive comparison, which is required for proper
909 rc = ntfs_collate_names(uname, uname_len,
910 (ntfschar*)&ie->key.file_name.file_name,
911 ie->key.file_name.file_name_length, 1,
912 CASE_SENSITIVE, vol->upcase, vol->upcase_len);
918 * Perfect match, this will never happen as the
919 * ntfs_are_names_equal() call will have gotten a match but we
920 * still treat it correctly.
925 * We have finished with this index buffer without success. Check for
926 * the presence of a child node.
928 if (ie->flags & INDEX_ENTRY_NODE) {
929 if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
930 ntfs_error(sb, "Index entry with child node found in "
931 "a leaf node in directory inode 0x%lx.",
936 /* Child node present, descend into it. */
938 vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
940 /* If vcn is in the same page cache page as old_vcn we
941 * recycle the mapped page. */
942 if (old_vcn << vol->cluster_size_bits >>
943 PAGE_CACHE_SHIFT == vcn <<
944 vol->cluster_size_bits >>
946 goto fast_descend_into_child_node;
947 ntfs_unmap_page(page);
948 goto descend_into_child_node;
950 ntfs_error(sb, "Negative child node vcn in directory inode "
951 "0x%lx.", dir_ni->mft_no);
955 /* No child node, return -ENOENT. */
956 ntfs_debug("Entry not found.");
959 ntfs_unmap_page(page);
962 put_attr_search_ctx(ctx);
964 unmap_mft_record(dir_ni);
965 return ERR_MREF(err);
967 ntfs_error(sb, "Corrupt directory. Aborting lookup.");
976 INDEX_ALLOCATION *ia;
977 } index_union __attribute__ ((__transparent_union__));
980 INDEX_TYPE_ROOT, /* index root */
981 INDEX_TYPE_ALLOCATION, /* index allocation */
985 * ntfs_filldir - ntfs specific filldir method
986 * @vol: current ntfs volume
987 * @fpos: position in the directory
988 * @ndir: ntfs inode of current directory
989 * @index_type: specifies whether @iu is an index root or an index allocation
990 * @iu: index root or index allocation attribute to which @ie belongs
991 * @ie: current index entry
992 * @name: buffer to use for the converted name
993 * @dirent: vfs filldir callback context
994 * @filldir: vfs filldir callback
996 * Convert the Unicode @name to the loaded NLS and pass it to the @filldir
999 static inline int ntfs_filldir(ntfs_volume *vol, loff_t *fpos,
1000 ntfs_inode *ndir, const INDEX_TYPE index_type,
1001 index_union iu, INDEX_ENTRY *ie, u8 *name,
1002 void *dirent, filldir_t filldir)
1006 FILE_NAME_TYPE_FLAGS name_type;
1008 /* Advance the position even if going to skip the entry. */
1009 if (index_type == INDEX_TYPE_ALLOCATION)
1010 *fpos = (u8*)ie - (u8*)iu.ia +
1011 (sle64_to_cpu(iu.ia->index_block_vcn) <<
1012 ndir->itype.index.vcn_size_bits) +
1013 vol->mft_record_size;
1014 else /* if (index_type == INDEX_TYPE_ROOT) */
1015 *fpos = (u8*)ie - (u8*)iu.ir;
1016 name_type = ie->key.file_name.file_name_type;
1017 if (name_type == FILE_NAME_DOS) {
1018 ntfs_debug("Skipping DOS name space entry.");
1021 if (MREF_LE(ie->data.dir.indexed_file) == FILE_root) {
1022 ntfs_debug("Skipping root directory self reference entry.");
1025 if (MREF_LE(ie->data.dir.indexed_file) < FILE_first_user &&
1026 !NVolShowSystemFiles(vol)) {
1027 ntfs_debug("Skipping system file.");
1030 name_len = ntfs_ucstonls(vol, (ntfschar*)&ie->key.file_name.file_name,
1031 ie->key.file_name.file_name_length, &name,
1032 NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1);
1033 if (name_len <= 0) {
1034 ntfs_debug("Skipping unrepresentable file.");
1037 if (ie->key.file_name.file_attributes &
1038 FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT)
1042 ntfs_debug("Calling filldir for %s with len %i, fpos 0x%llx, inode "
1043 "0x%lx, DT_%s.", name, name_len, *fpos,
1044 MREF_LE(ie->data.dir.indexed_file),
1045 dt_type == DT_DIR ? "DIR" : "REG");
1046 return filldir(dirent, name, name_len, *fpos,
1047 MREF_LE(ie->data.dir.indexed_file), dt_type);
1051 * VFS calls readdir without BKL but with i_sem held. This protects the VFS
1052 * parts (e.g. ->f_pos and ->i_size, and it also protects against directory
1055 * We use the same basic approach as the old NTFS driver, i.e. we parse the
1056 * index root entries and then the index allocation entries that are marked
1057 * as in use in the index bitmap.
1058 * While this will return the names in random order this doesn't matter for
1059 * readdir but OTOH results in a faster readdir.
1061 static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
1063 s64 ia_pos, ia_start, prev_ia_pos, bmp_pos;
1065 struct inode *bmp_vi, *vdir = filp->f_dentry->d_inode;
1066 struct super_block *sb = vdir->i_sb;
1067 ntfs_inode *ndir = NTFS_I(vdir);
1068 ntfs_volume *vol = NTFS_SB(sb);
1070 INDEX_ROOT *ir = NULL;
1072 INDEX_ALLOCATION *ia;
1074 int rc, err, ir_pos, cur_bmp_pos;
1075 struct address_space *ia_mapping, *bmp_mapping;
1076 struct page *bmp_page = NULL, *ia_page = NULL;
1077 u8 *kaddr, *bmp, *index_end;
1078 attr_search_context *ctx;
1081 ntfs_debug("Entering for inode 0x%lx, fpos 0x%llx.",
1084 /* Are we at end of dir yet? */
1085 if (fpos >= vdir->i_size + vol->mft_record_size)
1087 /* Emulate . and .. for all directories. */
1089 ntfs_debug("Calling filldir for . with len 1, fpos 0x0, "
1090 "inode 0x%lx, DT_DIR.", vdir->i_ino);
1091 rc = filldir(dirent, ".", 1, fpos, vdir->i_ino, DT_DIR);
1097 ntfs_debug("Calling filldir for .. with len 2, fpos 0x1, "
1098 "inode 0x%lx, DT_DIR.",
1099 parent_ino(filp->f_dentry));
1100 rc = filldir(dirent, "..", 2, fpos,
1101 parent_ino(filp->f_dentry), DT_DIR);
1109 * Allocate a buffer to store the current name being processed
1110 * converted to format determined by current NLS.
1112 name = (u8*)kmalloc(NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1,
1114 if (unlikely(!name)) {
1118 /* Are we jumping straight into the index allocation attribute? */
1119 if (fpos >= vol->mft_record_size)
1120 goto skip_index_root;
1121 /* Get hold of the mft record for the directory. */
1122 m = map_mft_record(ndir);
1123 if (unlikely(IS_ERR(m))) {
1128 ctx = get_attr_search_ctx(ndir, m);
1129 if (unlikely(!ctx)) {
1133 /* Get the offset into the index root attribute. */
1135 /* Find the index root attribute in the mft record. */
1136 if (unlikely(!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0,
1138 ntfs_error(sb, "Index root attribute missing in directory "
1139 "inode 0x%lx.", vdir->i_ino);
1143 * Copy the index root attribute value to a buffer so that we can put
1144 * the search context and unmap the mft record before calling the
1145 * filldir() callback. We need to do this because of NFSd which calls
1146 * ->lookup() from its filldir callback() and this causes NTFS to
1147 * deadlock as ntfs_lookup() maps the mft record of the directory and
1148 * we have got it mapped here already. The only solution is for us to
1149 * unmap the mft record here so that a call to ntfs_lookup() is able to
1150 * map the mft record without deadlocking.
1152 rc = le32_to_cpu(ctx->attr->data.resident.value_length);
1153 ir = (INDEX_ROOT*)kmalloc(rc, GFP_NOFS);
1154 if (unlikely(!ir)) {
1158 /* Copy the index root value (it has been verified in read_inode). */
1159 memcpy(ir, (u8*)ctx->attr +
1160 le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
1161 put_attr_search_ctx(ctx);
1162 unmap_mft_record(ndir);
1165 index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
1166 /* The first index entry. */
1167 ie = (INDEX_ENTRY*)((u8*)&ir->index +
1168 le32_to_cpu(ir->index.entries_offset));
1170 * Loop until we exceed valid memory (corruption case) or until we
1171 * reach the last entry or until filldir tells us it has had enough
1172 * or signals an error (both covered by the rc test).
1174 for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
1175 ntfs_debug("In index root, offset 0x%x.", (u8*)ie - (u8*)ir);
1176 /* Bounds checks. */
1177 if (unlikely((u8*)ie < (u8*)ir || (u8*)ie +
1178 sizeof(INDEX_ENTRY_HEADER) > index_end ||
1179 (u8*)ie + le16_to_cpu(ie->key_length) >
1182 /* The last entry cannot contain a name. */
1183 if (ie->flags & INDEX_ENTRY_END)
1185 /* Skip index root entry if continuing previous readdir. */
1186 if (ir_pos > (u8*)ie - (u8*)ir)
1188 /* Submit the name to the filldir callback. */
1189 rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ROOT, ir, ie,
1190 name, dirent, filldir);
1196 /* We are done with the index root and can free the buffer. */
1199 /* If there is no index allocation attribute we are finished. */
1200 if (!NInoIndexAllocPresent(ndir))
1202 /* Advance fpos to the beginning of the index allocation. */
1203 fpos = vol->mft_record_size;
1207 /* Get the offset into the index allocation attribute. */
1208 ia_pos = (s64)fpos - vol->mft_record_size;
1209 ia_mapping = vdir->i_mapping;
1210 bmp_vi = ndir->itype.index.bmp_ino;
1211 if (unlikely(!bmp_vi)) {
1212 ntfs_debug("Inode 0x%lx, regetting index bitmap.", vdir->i_ino);
1213 bmp_vi = ntfs_attr_iget(vdir, AT_BITMAP, I30, 4);
1214 if (unlikely(IS_ERR(bmp_vi))) {
1215 ntfs_error(sb, "Failed to get bitmap attribute.");
1216 err = PTR_ERR(bmp_vi);
1219 ndir->itype.index.bmp_ino = bmp_vi;
1221 bmp_mapping = bmp_vi->i_mapping;
1222 /* Get the starting bitmap bit position and sanity check it. */
1223 bmp_pos = ia_pos >> ndir->itype.index.block_size_bits;
1224 if (unlikely(bmp_pos >> 3 >= bmp_vi->i_size)) {
1225 ntfs_error(sb, "Current index allocation position exceeds "
1226 "index bitmap size.");
1229 /* Get the starting bit position in the current bitmap page. */
1230 cur_bmp_pos = bmp_pos & ((PAGE_CACHE_SIZE * 8) - 1);
1231 bmp_pos &= ~(u64)((PAGE_CACHE_SIZE * 8) - 1);
1233 ntfs_debug("Reading bitmap with page index 0x%llx, bit ofs 0x%llx",
1234 (unsigned long long)bmp_pos >> (3 + PAGE_CACHE_SHIFT),
1235 (unsigned long long)bmp_pos &
1236 ((PAGE_CACHE_SIZE * 8) - 1));
1237 bmp_page = ntfs_map_page(bmp_mapping,
1238 bmp_pos >> (3 + PAGE_CACHE_SHIFT));
1239 if (unlikely(IS_ERR(bmp_page))) {
1240 ntfs_error(sb, "Reading index bitmap failed.");
1241 err = PTR_ERR(bmp_page);
1245 bmp = (u8*)page_address(bmp_page);
1246 /* Find next index block in use. */
1247 while (!(bmp[cur_bmp_pos >> 3] & (1 << (cur_bmp_pos & 7)))) {
1248 find_next_index_buffer:
1251 * If we have reached the end of the bitmap page, get the next
1252 * page, and put away the old one.
1254 if (unlikely((cur_bmp_pos >> 3) >= PAGE_CACHE_SIZE)) {
1255 ntfs_unmap_page(bmp_page);
1256 bmp_pos += PAGE_CACHE_SIZE * 8;
1258 goto get_next_bmp_page;
1260 /* If we have reached the end of the bitmap, we are done. */
1261 if (unlikely(((bmp_pos + cur_bmp_pos) >> 3) >= vdir->i_size))
1263 ia_pos = (bmp_pos + cur_bmp_pos) <<
1264 ndir->itype.index.block_size_bits;
1266 ntfs_debug("Handling index buffer 0x%llx.",
1267 (unsigned long long)bmp_pos + cur_bmp_pos);
1268 /* If the current index buffer is in the same page we reuse the page. */
1269 if ((prev_ia_pos & PAGE_CACHE_MASK) != (ia_pos & PAGE_CACHE_MASK)) {
1270 prev_ia_pos = ia_pos;
1271 if (likely(ia_page != NULL))
1272 ntfs_unmap_page(ia_page);
1274 * Map the page cache page containing the current ia_pos,
1275 * reading it from disk if necessary.
1277 ia_page = ntfs_map_page(ia_mapping, ia_pos >> PAGE_CACHE_SHIFT);
1278 if (unlikely(IS_ERR(ia_page))) {
1279 ntfs_error(sb, "Reading index allocation data failed.");
1280 err = PTR_ERR(ia_page);
1284 kaddr = (u8*)page_address(ia_page);
1286 /* Get the current index buffer. */
1287 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
1288 ~(s64)(ndir->itype.index.block_size - 1)));
1289 /* Bounds checks. */
1290 if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
1291 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
1292 "inode 0x%lx or driver bug.", vdir->i_ino);
1295 if (unlikely(sle64_to_cpu(ia->index_block_vcn) != (ia_pos &
1296 ~(s64)(ndir->itype.index.block_size - 1)) >>
1297 ndir->itype.index.vcn_size_bits)) {
1298 ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
1299 "different from expected VCN (0x%llx). "
1300 "Directory inode 0x%lx is corrupt or driver "
1301 "bug. ", (unsigned long long)
1302 sle64_to_cpu(ia->index_block_vcn),
1303 (unsigned long long)ia_pos >>
1304 ndir->itype.index.vcn_size_bits, vdir->i_ino);
1307 if (unlikely(le32_to_cpu(ia->index.allocated_size) + 0x18 !=
1308 ndir->itype.index.block_size)) {
1309 ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
1310 "0x%lx has a size (%u) differing from the "
1311 "directory specified size (%u). Directory "
1312 "inode is corrupt or driver bug.",
1313 (unsigned long long)ia_pos >>
1314 ndir->itype.index.vcn_size_bits, vdir->i_ino,
1315 le32_to_cpu(ia->index.allocated_size) + 0x18,
1316 ndir->itype.index.block_size);
1319 index_end = (u8*)ia + ndir->itype.index.block_size;
1320 if (unlikely(index_end > kaddr + PAGE_CACHE_SIZE)) {
1321 ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
1322 "0x%lx crosses page boundary. Impossible! "
1323 "Cannot access! This is probably a bug in the "
1324 "driver.", (unsigned long long)ia_pos >>
1325 ndir->itype.index.vcn_size_bits, vdir->i_ino);
1328 ia_start = ia_pos & ~(s64)(ndir->itype.index.block_size - 1);
1329 index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
1330 if (unlikely(index_end > (u8*)ia + ndir->itype.index.block_size)) {
1331 ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of directory "
1332 "inode 0x%lx exceeds maximum size.",
1333 (unsigned long long)ia_pos >>
1334 ndir->itype.index.vcn_size_bits, vdir->i_ino);
1337 /* The first index entry in this index buffer. */
1338 ie = (INDEX_ENTRY*)((u8*)&ia->index +
1339 le32_to_cpu(ia->index.entries_offset));
1341 * Loop until we exceed valid memory (corruption case) or until we
1342 * reach the last entry or until filldir tells us it has had enough
1343 * or signals an error (both covered by the rc test).
1345 for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
1346 ntfs_debug("In index allocation, offset 0x%llx.",
1347 (unsigned long long)ia_start + ((u8*)ie -
1349 /* Bounds checks. */
1350 if (unlikely((u8*)ie < (u8*)ia || (u8*)ie +
1351 sizeof(INDEX_ENTRY_HEADER) > index_end ||
1352 (u8*)ie + le16_to_cpu(ie->key_length) >
1355 /* The last entry cannot contain a name. */
1356 if (ie->flags & INDEX_ENTRY_END)
1358 /* Skip index block entry if continuing previous readdir. */
1359 if (ia_pos - ia_start > (u8*)ie - (u8*)ia)
1361 /* Submit the name to the filldir callback. */
1362 rc = ntfs_filldir(vol, &fpos, ndir, INDEX_TYPE_ALLOCATION, ia,
1363 ie, name, dirent, filldir);
1365 ntfs_unmap_page(ia_page);
1366 ntfs_unmap_page(bmp_page);
1370 goto find_next_index_buffer;
1373 ntfs_unmap_page(ia_page);
1374 ntfs_unmap_page(bmp_page);
1376 /* We are finished, set fpos to EOD. */
1377 fpos = vdir->i_size + vol->mft_record_size;
1383 ntfs_debug("EOD, fpos 0x%llx, returning 0.", fpos);
1385 ntfs_debug("filldir returned %i, fpos 0x%llx, returning 0.",
1392 ntfs_unmap_page(bmp_page);
1394 ntfs_unmap_page(ia_page);
1400 put_attr_search_ctx(ctx);
1402 unmap_mft_record(ndir);
1405 ntfs_debug("Failed. Returning error code %i.", -err);
1411 * ntfs_dir_open - called when an inode is about to be opened
1412 * @vi: inode to be opened
1413 * @filp: file structure describing the inode
1415 * Limit directory size to the page cache limit on architectures where unsigned
1416 * long is 32-bits. This is the most we can do for now without overflowing the
1417 * page cache page index. Doing it this way means we don't run into problems
1418 * because of existing too large directories. It would be better to allow the
1419 * user to read the accessible part of the directory but I doubt very much
1420 * anyone is going to hit this check on a 32-bit architecture, so there is no
1421 * point in adding the extra complexity required to support this.
1423 * On 64-bit architectures, the check is hopefully optimized away by the
1426 static int ntfs_dir_open(struct inode *vi, struct file *filp)
1428 if (sizeof(unsigned long) < 8) {
1429 if (vi->i_size > MAX_LFS_FILESIZE)
1435 struct file_operations ntfs_dir_ops = {
1436 .llseek = generic_file_llseek, /* Seek inside directory. */
1437 .read = generic_read_dir, /* Return -EISDIR. */
1438 .readdir = ntfs_readdir, /* Read directory contents. */
1439 .open = ntfs_dir_open, /* Open directory. */