dir.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. /**
  2. * dir.c - NTFS kernel directory operations. Part of the Linux-NTFS project.
  3. *
  4. * Copyright (c) 2001-2004 Anton Altaparmakov
  5. * Copyright (c) 2002 Richard Russon
  6. *
  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.
  11. *
  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.
  16. *
  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
  21. */
  22. #include <linux/smp_lock.h>
  23. #include <linux/buffer_head.h>
  24. #include "dir.h"
  25. #include "aops.h"
  26. #include "attrib.h"
  27. #include "mft.h"
  28. #include "debug.h"
  29. #include "ntfs.h"
  30. /**
  31. * The little endian Unicode string $I30 as a global constant.
  32. */
  33. ntfschar I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'),
  34. const_cpu_to_le16('3'), const_cpu_to_le16('0'), 0 };
  35. /**
  36. * ntfs_lookup_inode_by_name - find an inode in a directory given its name
  37. * @dir_ni: ntfs inode of the directory in which to search for the name
  38. * @uname: Unicode name for which to search in the directory
  39. * @uname_len: length of the name @uname in Unicode characters
  40. * @res: return the found file name if necessary (see below)
  41. *
  42. * Look for an inode with name @uname in the directory with inode @dir_ni.
  43. * ntfs_lookup_inode_by_name() walks the contents of the directory looking for
  44. * the Unicode name. If the name is found in the directory, the corresponding
  45. * inode number (>= 0) is returned as a mft reference in cpu format, i.e. it
  46. * is a 64-bit number containing the sequence number.
  47. *
  48. * On error, a negative value is returned corresponding to the error code. In
  49. * particular if the inode is not found -ENOENT is returned. Note that you
  50. * can't just check the return value for being negative, you have to check the
  51. * inode number for being negative which you can extract using MREC(return
  52. * value).
  53. *
  54. * Note, @uname_len does not include the (optional) terminating NULL character.
  55. *
  56. * Note, we look for a case sensitive match first but we also look for a case
  57. * insensitive match at the same time. If we find a case insensitive match, we
  58. * save that for the case that we don't find an exact match, where we return
  59. * the case insensitive match and setup @res (which we allocate!) with the mft
  60. * reference, the file name type, length and with a copy of the little endian
  61. * Unicode file name itself. If we match a file name which is in the DOS name
  62. * space, we only return the mft reference and file name type in @res.
  63. * ntfs_lookup() then uses this to find the long file name in the inode itself.
  64. * This is to avoid polluting the dcache with short file names. We want them to
  65. * work but we don't care for how quickly one can access them. This also fixes
  66. * the dcache aliasing issues.
  67. *
  68. * Locking: - Caller must hold i_sem on the directory.
  69. * - Each page cache page in the index allocation mapping must be
  70. * locked whilst being accessed otherwise we may find a corrupt
  71. * page due to it being under ->writepage at the moment which
  72. * applies the mst protection fixups before writing out and then
  73. * removes them again after the write is complete after which it
  74. * unlocks the page.
  75. */
  76. MFT_REF ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
  77. const int uname_len, ntfs_name **res)
  78. {
  79. ntfs_volume *vol = dir_ni->vol;
  80. struct super_block *sb = vol->sb;
  81. MFT_RECORD *m;
  82. INDEX_ROOT *ir;
  83. INDEX_ENTRY *ie;
  84. INDEX_ALLOCATION *ia;
  85. u8 *index_end;
  86. u64 mref;
  87. ntfs_attr_search_ctx *ctx;
  88. int err, rc;
  89. VCN vcn, old_vcn;
  90. struct address_space *ia_mapping;
  91. struct page *page;
  92. u8 *kaddr;
  93. ntfs_name *name = NULL;
  94. BUG_ON(!S_ISDIR(VFS_I(dir_ni)->i_mode));
  95. BUG_ON(NInoAttr(dir_ni));
  96. /* Get hold of the mft record for the directory. */
  97. m = map_mft_record(dir_ni);
  98. if (IS_ERR(m)) {
  99. ntfs_error(sb, "map_mft_record() failed with error code %ld.",
  100. -PTR_ERR(m));
  101. return ERR_MREF(PTR_ERR(m));
  102. }
  103. ctx = ntfs_attr_get_search_ctx(dir_ni, m);
  104. if (unlikely(!ctx)) {
  105. err = -ENOMEM;
  106. goto err_out;
  107. }
  108. /* Find the index root attribute in the mft record. */
  109. err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
  110. 0, ctx);
  111. if (unlikely(err)) {
  112. if (err == -ENOENT) {
  113. ntfs_error(sb, "Index root attribute missing in "
  114. "directory inode 0x%lx.",
  115. dir_ni->mft_no);
  116. err = -EIO;
  117. }
  118. goto err_out;
  119. }
  120. /* Get to the index root value (it's been verified in read_inode). */
  121. ir = (INDEX_ROOT*)((u8*)ctx->attr +
  122. le16_to_cpu(ctx->attr->data.resident.value_offset));
  123. index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
  124. /* The first index entry. */
  125. ie = (INDEX_ENTRY*)((u8*)&ir->index +
  126. le32_to_cpu(ir->index.entries_offset));
  127. /*
  128. * Loop until we exceed valid memory (corruption case) or until we
  129. * reach the last entry.
  130. */
  131. for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
  132. /* Bounds checks. */
  133. if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie +
  134. sizeof(INDEX_ENTRY_HEADER) > index_end ||
  135. (u8*)ie + le16_to_cpu(ie->key_length) >
  136. index_end)
  137. goto dir_err_out;
  138. /*
  139. * The last entry cannot contain a name. It can however contain
  140. * a pointer to a child node in the B+tree so we just break out.
  141. */
  142. if (ie->flags & INDEX_ENTRY_END)
  143. break;
  144. /*
  145. * We perform a case sensitive comparison and if that matches
  146. * we are done and return the mft reference of the inode (i.e.
  147. * the inode number together with the sequence number for
  148. * consistency checking). We convert it to cpu format before
  149. * returning.
  150. */
  151. if (ntfs_are_names_equal(uname, uname_len,
  152. (ntfschar*)&ie->key.file_name.file_name,
  153. ie->key.file_name.file_name_length,
  154. CASE_SENSITIVE, vol->upcase, vol->upcase_len)) {
  155. found_it:
  156. /*
  157. * We have a perfect match, so we don't need to care
  158. * about having matched imperfectly before, so we can
  159. * free name and set *res to NULL.
  160. * However, if the perfect match is a short file name,
  161. * we need to signal this through *res, so that
  162. * ntfs_lookup() can fix dcache aliasing issues.
  163. * As an optimization we just reuse an existing
  164. * allocation of *res.
  165. */
  166. if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
  167. if (!name) {
  168. name = kmalloc(sizeof(ntfs_name),
  169. GFP_NOFS);
  170. if (!name) {
  171. err = -ENOMEM;
  172. goto err_out;
  173. }
  174. }
  175. name->mref = le64_to_cpu(
  176. ie->data.dir.indexed_file);
  177. name->type = FILE_NAME_DOS;
  178. name->len = 0;
  179. *res = name;
  180. } else {
  181. if (name)
  182. kfree(name);
  183. *res = NULL;
  184. }
  185. mref = le64_to_cpu(ie->data.dir.indexed_file);
  186. ntfs_attr_put_search_ctx(ctx);
  187. unmap_mft_record(dir_ni);
  188. return mref;
  189. }
  190. /*
  191. * For a case insensitive mount, we also perform a case
  192. * insensitive comparison (provided the file name is not in the
  193. * POSIX namespace). If the comparison matches, and the name is
  194. * in the WIN32 namespace, we cache the filename in *res so
  195. * that the caller, ntfs_lookup(), can work on it. If the
  196. * comparison matches, and the name is in the DOS namespace, we
  197. * only cache the mft reference and the file name type (we set
  198. * the name length to zero for simplicity).
  199. */
  200. if (!NVolCaseSensitive(vol) &&
  201. ie->key.file_name.file_name_type &&
  202. ntfs_are_names_equal(uname, uname_len,
  203. (ntfschar*)&ie->key.file_name.file_name,
  204. ie->key.file_name.file_name_length,
  205. IGNORE_CASE, vol->upcase, vol->upcase_len)) {
  206. int name_size = sizeof(ntfs_name);
  207. u8 type = ie->key.file_name.file_name_type;
  208. u8 len = ie->key.file_name.file_name_length;
  209. /* Only one case insensitive matching name allowed. */
  210. if (name) {
  211. ntfs_error(sb, "Found already allocated name "
  212. "in phase 1. Please run chkdsk "
  213. "and if that doesn't find any "
  214. "errors please report you saw "
  215. "this message to "
  216. "linux-ntfs-dev@lists."
  217. "sourceforge.net.");
  218. goto dir_err_out;
  219. }
  220. if (type != FILE_NAME_DOS)
  221. name_size += len * sizeof(ntfschar);
  222. name = kmalloc(name_size, GFP_NOFS);
  223. if (!name) {
  224. err = -ENOMEM;
  225. goto err_out;
  226. }
  227. name->mref = le64_to_cpu(ie->data.dir.indexed_file);
  228. name->type = type;
  229. if (type != FILE_NAME_DOS) {
  230. name->len = len;
  231. memcpy(name->name, ie->key.file_name.file_name,
  232. len * sizeof(ntfschar));
  233. } else
  234. name->len = 0;
  235. *res = name;
  236. }
  237. /*
  238. * Not a perfect match, need to do full blown collation so we
  239. * know which way in the B+tree we have to go.
  240. */
  241. rc = ntfs_collate_names(uname, uname_len,
  242. (ntfschar*)&ie->key.file_name.file_name,
  243. ie->key.file_name.file_name_length, 1,
  244. IGNORE_CASE, vol->upcase, vol->upcase_len);
  245. /*
  246. * If uname collates before the name of the current entry, there
  247. * is definitely no such name in this index but we might need to
  248. * descend into the B+tree so we just break out of the loop.
  249. */
  250. if (rc == -1)
  251. break;
  252. /* The names are not equal, continue the search. */
  253. if (rc)
  254. continue;
  255. /*
  256. * Names match with case insensitive comparison, now try the
  257. * case sensitive comparison, which is required for proper
  258. * collation.
  259. */
  260. rc = ntfs_collate_names(uname, uname_len,
  261. (ntfschar*)&ie->key.file_name.file_name,
  262. ie->key.file_name.file_name_length, 1,
  263. CASE_SENSITIVE, vol->upcase, vol->upcase_len);
  264. if (rc == -1)
  265. break;
  266. if (rc)
  267. continue;
  268. /*
  269. * Perfect match, this will never happen as the
  270. * ntfs_are_names_equal() call will have gotten a match but we
  271. * still treat it correctly.
  272. */
  273. goto found_it;
  274. }
  275. /*
  276. * We have finished with this index without success. Check for the
  277. * presence of a child node and if not present return -ENOENT, unless
  278. * we have got a matching name cached in name in which case return the
  279. * mft reference associated with it.
  280. */
  281. if (!(ie->flags & INDEX_ENTRY_NODE)) {
  282. if (name) {
  283. ntfs_attr_put_search_ctx(ctx);
  284. unmap_mft_record(dir_ni);
  285. return name->mref;
  286. }
  287. ntfs_debug("Entry not found.");
  288. err = -ENOENT;
  289. goto err_out;
  290. } /* Child node present, descend into it. */
  291. /* Consistency check: Verify that an index allocation exists. */
  292. if (!NInoIndexAllocPresent(dir_ni)) {
  293. ntfs_error(sb, "No index allocation attribute but index entry "
  294. "requires one. Directory inode 0x%lx is "
  295. "corrupt or driver bug.", dir_ni->mft_no);
  296. goto err_out;
  297. }
  298. /* Get the starting vcn of the index_block holding the child node. */
  299. vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8));
  300. ia_mapping = VFS_I(dir_ni)->i_mapping;
  301. /*
  302. * We are done with the index root and the mft record. Release them,
  303. * otherwise we deadlock with ntfs_map_page().
  304. */
  305. ntfs_attr_put_search_ctx(ctx);
  306. unmap_mft_record(dir_ni);
  307. m = NULL;
  308. ctx = NULL;
  309. descend_into_child_node:
  310. /*
  311. * Convert vcn to index into the index allocation attribute in units
  312. * of PAGE_CACHE_SIZE and map the page cache page, reading it from
  313. * disk if necessary.
  314. */
  315. page = ntfs_map_page(ia_mapping, vcn <<
  316. dir_ni->itype.index.vcn_size_bits >> PAGE_CACHE_SHIFT);
  317. if (IS_ERR(page)) {
  318. ntfs_error(sb, "Failed to map directory index page, error %ld.",
  319. -PTR_ERR(page));
  320. err = PTR_ERR(page);
  321. goto err_out;
  322. }
  323. lock_page(page);
  324. kaddr = (u8*)page_address(page);
  325. fast_descend_into_child_node:
  326. /* Get to the index allocation block. */
  327. ia = (INDEX_ALLOCATION*)(kaddr + ((vcn <<
  328. dir_ni->itype.index.vcn_size_bits) & ~PAGE_CACHE_MASK));
  329. /* Bounds checks. */
  330. if ((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE) {
  331. ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
  332. "inode 0x%lx or driver bug.", dir_ni->mft_no);
  333. goto unm_err_out;
  334. }
  335. /* Catch multi sector transfer fixup errors. */
  336. if (unlikely(!ntfs_is_indx_record(ia->magic))) {
  337. ntfs_error(sb, "Directory index record with vcn 0x%llx is "
  338. "corrupt. Corrupt inode 0x%lx. Run chkdsk.",
  339. (unsigned long long)vcn, dir_ni->mft_no);
  340. goto unm_err_out;
  341. }
  342. if (sle64_to_cpu(ia->index_block_vcn) != vcn) {
  343. ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
  344. "different from expected VCN (0x%llx). "
  345. "Directory inode 0x%lx is corrupt or driver "
  346. "bug.", (unsigned long long)
  347. sle64_to_cpu(ia->index_block_vcn),
  348. (unsigned long long)vcn, dir_ni->mft_no);
  349. goto unm_err_out;
  350. }
  351. if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
  352. dir_ni->itype.index.block_size) {
  353. ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
  354. "0x%lx has a size (%u) differing from the "
  355. "directory specified size (%u). Directory "
  356. "inode is corrupt or driver bug.",
  357. (unsigned long long)vcn, dir_ni->mft_no,
  358. le32_to_cpu(ia->index.allocated_size) + 0x18,
  359. dir_ni->itype.index.block_size);
  360. goto unm_err_out;
  361. }
  362. index_end = (u8*)ia + dir_ni->itype.index.block_size;
  363. if (index_end > kaddr + PAGE_CACHE_SIZE) {
  364. ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
  365. "0x%lx crosses page boundary. Impossible! "
  366. "Cannot access! This is probably a bug in the "
  367. "driver.", (unsigned long long)vcn,
  368. dir_ni->mft_no);
  369. goto unm_err_out;
  370. }
  371. index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
  372. if (index_end > (u8*)ia + dir_ni->itype.index.block_size) {
  373. ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of directory "
  374. "inode 0x%lx exceeds maximum size.",
  375. (unsigned long long)vcn, dir_ni->mft_no);
  376. goto unm_err_out;
  377. }
  378. /* The first index entry. */
  379. ie = (INDEX_ENTRY*)((u8*)&ia->index +
  380. le32_to_cpu(ia->index.entries_offset));
  381. /*
  382. * Iterate similar to above big loop but applied to index buffer, thus
  383. * loop until we exceed valid memory (corruption case) or until we
  384. * reach the last entry.
  385. */
  386. for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
  387. /* Bounds check. */
  388. if ((u8*)ie < (u8*)ia || (u8*)ie +
  389. sizeof(INDEX_ENTRY_HEADER) > index_end ||
  390. (u8*)ie + le16_to_cpu(ie->key_length) >
  391. index_end) {
  392. ntfs_error(sb, "Index entry out of bounds in "
  393. "directory inode 0x%lx.",
  394. dir_ni->mft_no);
  395. goto unm_err_out;
  396. }
  397. /*
  398. * The last entry cannot contain a name. It can however contain
  399. * a pointer to a child node in the B+tree so we just break out.
  400. */
  401. if (ie->flags & INDEX_ENTRY_END)
  402. break;
  403. /*
  404. * We perform a case sensitive comparison and if that matches
  405. * we are done and return the mft reference of the inode (i.e.
  406. * the inode number together with the sequence number for
  407. * consistency checking). We convert it to cpu format before
  408. * returning.
  409. */
  410. if (ntfs_are_names_equal(uname, uname_len,
  411. (ntfschar*)&ie->key.file_name.file_name,
  412. ie->key.file_name.file_name_length,
  413. CASE_SENSITIVE, vol->upcase, vol->upcase_len)) {
  414. found_it2:
  415. /*
  416. * We have a perfect match, so we don't need to care
  417. * about having matched imperfectly before, so we can
  418. * free name and set *res to NULL.
  419. * However, if the perfect match is a short file name,
  420. * we need to signal this through *res, so that
  421. * ntfs_lookup() can fix dcache aliasing issues.
  422. * As an optimization we just reuse an existing
  423. * allocation of *res.
  424. */
  425. if (ie->key.file_name.file_name_type == FILE_NAME_DOS) {
  426. if (!name) {
  427. name = kmalloc(sizeof(ntfs_name),
  428. GFP_NOFS);
  429. if (!name) {
  430. err = -ENOMEM;
  431. goto unm_err_out;
  432. }
  433. }
  434. name->mref = le64_to_cpu(
  435. ie->data.dir.indexed_file);
  436. name->type = FILE_NAME_DOS;
  437. name->len = 0;
  438. *res = name;
  439. } else {
  440. if (name)
  441. kfree(name);
  442. *res = NULL;
  443. }
  444. mref = le64_to_cpu(ie->data.dir.indexed_file);
  445. unlock_page(page);
  446. ntfs_unmap_page(page);
  447. return mref;
  448. }
  449. /*
  450. * For a case insensitive mount, we also perform a case
  451. * insensitive comparison (provided the file name is not in the
  452. * POSIX namespace). If the comparison matches, and the name is
  453. * in the WIN32 namespace, we cache the filename in *res so
  454. * that the caller, ntfs_lookup(), can work on it. If the
  455. * comparison matches, and the name is in the DOS namespace, we
  456. * only cache the mft reference and the file name type (we set
  457. * the name length to zero for simplicity).
  458. */
  459. if (!NVolCaseSensitive(vol) &&
  460. ie->key.file_name.file_name_type &&
  461. ntfs_are_names_equal(uname, uname_len,
  462. (ntfschar*)&ie->key.file_name.file_name,
  463. ie->key.file_name.file_name_length,
  464. IGNORE_CASE, vol->upcase, vol->upcase_len)) {
  465. int name_size = sizeof(ntfs_name);
  466. u8 type = ie->key.file_name.file_name_type;
  467. u8 len = ie->key.file_name.file_name_length;
  468. /* Only one case insensitive matching name allowed. */
  469. if (name) {
  470. ntfs_error(sb, "Found already allocated name "
  471. "in phase 2. Please run chkdsk "
  472. "and if that doesn't find any "
  473. "errors please report you saw "
  474. "this message to "
  475. "linux-ntfs-dev@lists."
  476. "sourceforge.net.");
  477. unlock_page(page);
  478. ntfs_unmap_page(page);
  479. goto dir_err_out;
  480. }
  481. if (type != FILE_NAME_DOS)
  482. name_size += len * sizeof(ntfschar);
  483. name = kmalloc(name_size, GFP_NOFS);
  484. if (!name) {
  485. err = -ENOMEM;
  486. goto unm_err_out;
  487. }
  488. name->mref = le64_to_cpu(ie->data.dir.indexed_file);
  489. name->type = type;
  490. if (type != FILE_NAME_DOS) {
  491. name->len = len;
  492. memcpy(name->name, ie->key.file_name.file_name,
  493. len * sizeof(ntfschar));
  494. } else
  495. name->len = 0;
  496. *res = name;
  497. }
  498. /*
  499. * Not a perfect match, need to do full blown collation so we
  500. * know which way in the B+tree we have to go.
  501. */
  502. rc = ntfs_collate_names(uname, uname_len,
  503. (ntfschar*)&ie->key.file_name.file_name,
  504. ie->key.file_name.file_name_length, 1,
  505. IGNORE_CASE, vol->upcase, vol->upcase_len);
  506. /*
  507. * If uname collates before the name of the current entry, there
  508. * is definitely no such name in this index but we might need to
  509. * descend into the B+tree so we just break out of the loop.
  510. */
  511. if (rc == -1)
  512. break;
  513. /* The names are not equal, continue the search. */
  514. if (rc)
  515. continue;
  516. /*
  517. * Names match with case insensitive comparison, now try the
  518. * case sensitive comparison, which is required for proper
  519. * collation.
  520. */
  521. rc = ntfs_collate_names(uname, uname_len,
  522. (ntfschar*)&ie->key.file_name.file_name,
  523. ie->key.file_name.file_name_length, 1,
  524. CASE_SENSITIVE, vol->upcase, vol->upcase_len);
  525. if (rc == -1)
  526. break;
  527. if (rc)
  528. continue;
  529. /*
  530. * Perfect match, this will never happen as the
  531. * ntfs_are_names_equal() call will have gotten a match but we
  532. * still treat it correctly.
  533. */
  534. goto found_it2;
  535. }
  536. /*
  537. * We have finished with this index buffer without success. Check for
  538. * the presence of a child node.
  539. */
  540. if (ie->flags & INDEX_ENTRY_NODE) {
  541. if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
  542. ntfs_error(sb, "Index entry with child node found in "
  543. "a leaf node in directory inode 0x%lx.",
  544. dir_ni->mft_no);
  545. goto unm_err_out;
  546. }
  547. /* Child node present, descend into it. */
  548. old_vcn = vcn;
  549. vcn = sle64_to_cpup((sle64*)((u8*)ie +
  550. le16_to_cpu(ie->length) - 8));
  551. if (vcn >= 0) {
  552. /* If vcn is in the same page cache page as old_vcn we
  553. * recycle the mapped page. */
  554. if (old_vcn << vol->cluster_size_bits >>
  555. PAGE_CACHE_SHIFT == vcn <<
  556. vol->cluster_size_bits >>
  557. PAGE_CACHE_SHIFT)
  558. goto fast_descend_into_child_node;
  559. unlock_page(page);
  560. ntfs_unmap_page(page);
  561. goto descend_into_child_node;
  562. }
  563. ntfs_error(sb, "Negative child node vcn in directory inode "
  564. "0x%lx.", dir_ni->mft_no);
  565. goto unm_err_out;
  566. }
  567. /*
  568. * No child node present, return -ENOENT, unless we have got a matching
  569. * name cached in name in which case return the mft reference
  570. * associated with it.
  571. */
  572. if (name) {
  573. unlock_page(page);
  574. ntfs_unmap_page(page);
  575. return name->mref;
  576. }
  577. ntfs_debug("Entry not found.");
  578. err = -ENOENT;
  579. unm_err_out:
  580. unlock_page(page);
  581. ntfs_unmap_page(page);
  582. err_out:
  583. if (!err)
  584. err = -EIO;
  585. if (ctx)
  586. ntfs_attr_put_search_ctx(ctx);
  587. if (m)
  588. unmap_mft_record(dir_ni);
  589. if (name) {
  590. kfree(name);
  591. *res = NULL;
  592. }
  593. return ERR_MREF(err);
  594. dir_err_out:
  595. ntfs_error(sb, "Corrupt directory. Aborting lookup.");
  596. goto err_out;
  597. }
  598. #if 0
  599. // TODO: (AIA)
  600. // The algorithm embedded in this code will be required for the time when we
  601. // want to support adding of entries to directories, where we require correct
  602. // collation of file names in order not to cause corruption of the file system.
  603. /**
  604. * ntfs_lookup_inode_by_name - find an inode in a directory given its name
  605. * @dir_ni: ntfs inode of the directory in which to search for the name
  606. * @uname: Unicode name for which to search in the directory
  607. * @uname_len: length of the name @uname in Unicode characters
  608. *
  609. * Look for an inode with name @uname in the directory with inode @dir_ni.
  610. * ntfs_lookup_inode_by_name() walks the contents of the directory looking for
  611. * the Unicode name. If the name is found in the directory, the corresponding
  612. * inode number (>= 0) is returned as a mft reference in cpu format, i.e. it
  613. * is a 64-bit number containing the sequence number.
  614. *
  615. * On error, a negative value is returned corresponding to the error code. In
  616. * particular if the inode is not found -ENOENT is returned. Note that you
  617. * can't just check the return value for being negative, you have to check the
  618. * inode number for being negative which you can extract using MREC(return
  619. * value).
  620. *
  621. * Note, @uname_len does not include the (optional) terminating NULL character.
  622. */
  623. u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
  624. const int uname_len)
  625. {
  626. ntfs_volume *vol = dir_ni->vol;
  627. struct super_block *sb = vol->sb;
  628. MFT_RECORD *m;
  629. INDEX_ROOT *ir;
  630. INDEX_ENTRY *ie;
  631. INDEX_ALLOCATION *ia;
  632. u8 *index_end;
  633. u64 mref;
  634. ntfs_attr_search_ctx *ctx;
  635. int err, rc;
  636. IGNORE_CASE_BOOL ic;
  637. VCN vcn, old_vcn;
  638. struct address_space *ia_mapping;
  639. struct page *page;
  640. u8 *kaddr;
  641. /* Get hold of the mft record for the directory. */
  642. m = map_mft_record(dir_ni);
  643. if (IS_ERR(m)) {
  644. ntfs_error(sb, "map_mft_record() failed with error code %ld.",
  645. -PTR_ERR(m));
  646. return ERR_MREF(PTR_ERR(m));
  647. }
  648. ctx = ntfs_attr_get_search_ctx(dir_ni, m);
  649. if (!ctx) {
  650. err = -ENOMEM;
  651. goto err_out;
  652. }
  653. /* Find the index root attribute in the mft record. */
  654. err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
  655. 0, ctx);
  656. if (unlikely(err)) {
  657. if (err == -ENOENT) {
  658. ntfs_error(sb, "Index root attribute missing in "
  659. "directory inode 0x%lx.",
  660. dir_ni->mft_no);
  661. err = -EIO;
  662. }
  663. goto err_out;
  664. }
  665. /* Get to the index root value (it's been verified in read_inode). */
  666. ir = (INDEX_ROOT*)((u8*)ctx->attr +
  667. le16_to_cpu(ctx->attr->data.resident.value_offset));
  668. index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
  669. /* The first index entry. */
  670. ie = (INDEX_ENTRY*)((u8*)&ir->index +
  671. le32_to_cpu(ir->index.entries_offset));
  672. /*
  673. * Loop until we exceed valid memory (corruption case) or until we
  674. * reach the last entry.
  675. */
  676. for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
  677. /* Bounds checks. */
  678. if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie +
  679. sizeof(INDEX_ENTRY_HEADER) > index_end ||
  680. (u8*)ie + le16_to_cpu(ie->key_length) >
  681. index_end)
  682. goto dir_err_out;
  683. /*
  684. * The last entry cannot contain a name. It can however contain
  685. * a pointer to a child node in the B+tree so we just break out.
  686. */
  687. if (ie->flags & INDEX_ENTRY_END)
  688. break;
  689. /*
  690. * If the current entry has a name type of POSIX, the name is
  691. * case sensitive and not otherwise. This has the effect of us
  692. * not being able to access any POSIX file names which collate
  693. * after the non-POSIX one when they only differ in case, but
  694. * anyone doing screwy stuff like that deserves to burn in
  695. * hell... Doing that kind of stuff on NT4 actually causes
  696. * corruption on the partition even when using SP6a and Linux
  697. * is not involved at all.
  698. */
  699. ic = ie->key.file_name.file_name_type ? IGNORE_CASE :
  700. CASE_SENSITIVE;
  701. /*
  702. * If the names match perfectly, we are done and return the
  703. * mft reference of the inode (i.e. the inode number together
  704. * with the sequence number for consistency checking. We
  705. * convert it to cpu format before returning.
  706. */
  707. if (ntfs_are_names_equal(uname, uname_len,
  708. (ntfschar*)&ie->key.file_name.file_name,
  709. ie->key.file_name.file_name_length, ic,
  710. vol->upcase, vol->upcase_len)) {
  711. found_it:
  712. mref = le64_to_cpu(ie->data.dir.indexed_file);
  713. ntfs_attr_put_search_ctx(ctx);
  714. unmap_mft_record(dir_ni);
  715. return mref;
  716. }
  717. /*
  718. * Not a perfect match, need to do full blown collation so we
  719. * know which way in the B+tree we have to go.
  720. */
  721. rc = ntfs_collate_names(uname, uname_len,
  722. (ntfschar*)&ie->key.file_name.file_name,
  723. ie->key.file_name.file_name_length, 1,
  724. IGNORE_CASE, vol->upcase, vol->upcase_len);
  725. /*
  726. * If uname collates before the name of the current entry, there
  727. * is definitely no such name in this index but we might need to
  728. * descend into the B+tree so we just break out of the loop.
  729. */
  730. if (rc == -1)
  731. break;
  732. /* The names are not equal, continue the search. */
  733. if (rc)
  734. continue;
  735. /*
  736. * Names match with case insensitive comparison, now try the
  737. * case sensitive comparison, which is required for proper
  738. * collation.
  739. */
  740. rc = ntfs_collate_names(uname, uname_len,
  741. (ntfschar*)&ie->key.file_name.file_name,
  742. ie->key.file_name.file_name_length, 1,
  743. CASE_SENSITIVE, vol->upcase, vol->upcase_len);
  744. if (rc == -1)
  745. break;
  746. if (rc)
  747. continue;
  748. /*
  749. * Perfect match, this will never happen as the
  750. * ntfs_are_names_equal() call will have gotten a match but we
  751. * still treat it correctly.
  752. */
  753. goto found_it;
  754. }
  755. /*
  756. * We have finished with this index without success. Check for the
  757. * presence of a child node.
  758. */
  759. if (!(ie->flags & INDEX_ENTRY_NODE)) {
  760. /* No child node, return -ENOENT. */
  761. err = -ENOENT;
  762. goto err_out;
  763. } /* Child node present, descend into it. */
  764. /* Consistency check: Verify that an index allocation exists. */
  765. if (!NInoIndexAllocPresent(dir_ni)) {
  766. ntfs_error(sb, "No index allocation attribute but index entry "
  767. "requires one. Directory inode 0x%lx is "
  768. "corrupt or driver bug.", dir_ni->mft_no);
  769. goto err_out;
  770. }
  771. /* Get the starting vcn of the index_block holding the child node. */
  772. vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
  773. ia_mapping = VFS_I(dir_ni)->i_mapping;
  774. /*
  775. * We are done with the index root and the mft record. Release them,
  776. * otherwise we deadlock with ntfs_map_page().
  777. */
  778. ntfs_attr_put_search_ctx(ctx);
  779. unmap_mft_record(dir_ni);
  780. m = NULL;
  781. ctx = NULL;
  782. descend_into_child_node:
  783. /*
  784. * Convert vcn to index into the index allocation attribute in units
  785. * of PAGE_CACHE_SIZE and map the page cache page, reading it from
  786. * disk if necessary.
  787. */
  788. page = ntfs_map_page(ia_mapping, vcn <<
  789. dir_ni->itype.index.vcn_size_bits >> PAGE_CACHE_SHIFT);
  790. if (IS_ERR(page)) {
  791. ntfs_error(sb, "Failed to map directory index page, error %ld.",
  792. -PTR_ERR(page));
  793. err = PTR_ERR(page);
  794. goto err_out;
  795. }
  796. lock_page(page);
  797. kaddr = (u8*)page_address(page);
  798. fast_descend_into_child_node:
  799. /* Get to the index allocation block. */
  800. ia = (INDEX_ALLOCATION*)(kaddr + ((vcn <<
  801. dir_ni->itype.index.vcn_size_bits) & ~PAGE_CACHE_MASK));
  802. /* Bounds checks. */
  803. if ((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE) {
  804. ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
  805. "inode 0x%lx or driver bug.", dir_ni->mft_no);
  806. goto unm_err_out;
  807. }
  808. /* Catch multi sector transfer fixup errors. */
  809. if (unlikely(!ntfs_is_indx_record(ia->magic))) {
  810. ntfs_error(sb, "Directory index record with vcn 0x%llx is "
  811. "corrupt. Corrupt inode 0x%lx. Run chkdsk.",
  812. (unsigned long long)vcn, dir_ni->mft_no);
  813. goto unm_err_out;
  814. }
  815. if (sle64_to_cpu(ia->index_block_vcn) != vcn) {
  816. ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
  817. "different from expected VCN (0x%llx). "
  818. "Directory inode 0x%lx is corrupt or driver "
  819. "bug.", (unsigned long long)
  820. sle64_to_cpu(ia->index_block_vcn),
  821. (unsigned long long)vcn, dir_ni->mft_no);
  822. goto unm_err_out;
  823. }
  824. if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
  825. dir_ni->itype.index.block_size) {
  826. ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
  827. "0x%lx has a size (%u) differing from the "
  828. "directory specified size (%u). Directory "
  829. "inode is corrupt or driver bug.",
  830. (unsigned long long)vcn, dir_ni->mft_no,
  831. le32_to_cpu(ia->index.allocated_size) + 0x18,
  832. dir_ni->itype.index.block_size);
  833. goto unm_err_out;
  834. }
  835. index_end = (u8*)ia + dir_ni->itype.index.block_size;
  836. if (index_end > kaddr + PAGE_CACHE_SIZE) {
  837. ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
  838. "0x%lx crosses page boundary. Impossible! "
  839. "Cannot access! This is probably a bug in the "
  840. "driver.", (unsigned long long)vcn,
  841. dir_ni->mft_no);
  842. goto unm_err_out;
  843. }
  844. index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
  845. if (index_end > (u8*)ia + dir_ni->itype.index.block_size) {
  846. ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of directory "
  847. "inode 0x%lx exceeds maximum size.",
  848. (unsigned long long)vcn, dir_ni->mft_no);
  849. goto unm_err_out;
  850. }
  851. /* The first index entry. */
  852. ie = (INDEX_ENTRY*)((u8*)&ia->index +
  853. le32_to_cpu(ia->index.entries_offset));
  854. /*
  855. * Iterate similar to above big loop but applied to index buffer, thus
  856. * loop until we exceed valid memory (corruption case) or until we
  857. * reach the last entry.
  858. */
  859. for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
  860. /* Bounds check. */
  861. if ((u8*)ie < (u8*)ia || (u8*)ie +
  862. sizeof(INDEX_ENTRY_HEADER) > index_end ||
  863. (u8*)ie + le16_to_cpu(ie->key_length) >
  864. index_end) {
  865. ntfs_error(sb, "Index entry out of bounds in "
  866. "directory inode 0x%lx.",
  867. dir_ni->mft_no);
  868. goto unm_err_out;
  869. }
  870. /*
  871. * The last entry cannot contain a name. It can however contain
  872. * a pointer to a child node in the B+tree so we just break out.
  873. */
  874. if (ie->flags & INDEX_ENTRY_END)
  875. break;
  876. /*
  877. * If the current entry has a name type of POSIX, the name is
  878. * case sensitive and not otherwise. This has the effect of us
  879. * not being able to access any POSIX file names which collate
  880. * after the non-POSIX one when they only differ in case, but
  881. * anyone doing screwy stuff like that deserves to burn in
  882. * hell... Doing that kind of stuff on NT4 actually causes
  883. * corruption on the partition even when using SP6a and Linux
  884. * is not involved at all.
  885. */
  886. ic = ie->key.file_name.file_name_type ? IGNORE_CASE :
  887. CASE_SENSITIVE;
  888. /*
  889. * If the names match perfectly, we are done and return the
  890. * mft reference of the inode (i.e. the inode number together
  891. * with the sequence number for consistency checking. We
  892. * convert it to cpu format before returning.
  893. */
  894. if (ntfs_are_names_equal(uname, uname_len,
  895. (ntfschar*)&ie->key.file_name.file_name,
  896. ie->key.file_name.file_name_length, ic,
  897. vol->upcase, vol->upcase_len)) {
  898. found_it2:
  899. mref = le64_to_cpu(ie->data.dir.indexed_file);
  900. unlock_page(page);
  901. ntfs_unmap_page(page);
  902. return mref;
  903. }
  904. /*
  905. * Not a perfect match, need to do full blown collation so we
  906. * know which way in the B+tree we have to go.
  907. */
  908. rc = ntfs_collate_names(uname, uname_len,
  909. (ntfschar*)&ie->key.file_name.file_name,
  910. ie->key.file_name.file_name_length, 1,
  911. IGNORE_CASE, vol->upcase, vol->upcase_len);
  912. /*
  913. * If uname collates before the name of the current entry, there
  914. * is definitely no such name in this index but we might need to
  915. * descend into the B+tree so we just break out of the loop.
  916. */
  917. if (rc == -1)
  918. break;
  919. /* The names are not equal, continue the search. */
  920. if (rc)
  921. continue;
  922. /*
  923. * Names match with case insensitive comparison, now try the
  924. * case sensitive comparison, which is required for proper
  925. * collation.
  926. */
  927. rc = ntfs_collate_names(uname, uname_len,
  928. (ntfschar*)&ie->key.file_name.file_name,
  929. ie->key.file_name.file_name_length, 1,
  930. CASE_SENSITIVE, vol->upcase, vol->upcase_len);
  931. if (rc == -1)
  932. break;
  933. if (rc)
  934. continue;
  935. /*
  936. * Perfect match, this will never happen as the
  937. * ntfs_are_names_equal() call will have gotten a match but we
  938. * still treat it correctly.
  939. */
  940. goto found_it2;
  941. }
  942. /*
  943. * We have finished with this index buffer without success. Check for
  944. * the presence of a child node.
  945. */
  946. if (ie->flags & INDEX_ENTRY_NODE) {
  947. if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
  948. ntfs_error(sb, "Index entry with child node found in "
  949. "a leaf node in directory inode 0x%lx.",
  950. dir_ni->mft_no);
  951. goto unm_err_out;
  952. }
  953. /* Child node present, descend into it. */
  954. old_vcn = vcn;
  955. vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8);
  956. if (vcn >= 0) {
  957. /* If vcn is in the same page cache page as old_vcn we
  958. * recycle the mapped page. */
  959. if (old_vcn << vol->cluster_size_bits >>
  960. PAGE_CACHE_SHIFT == vcn <<
  961. vol->cluster_size_bits >>
  962. PAGE_CACHE_SHIFT)
  963. goto fast_descend_into_child_node;
  964. unlock_page(page);
  965. ntfs_unmap_page(page);
  966. goto descend_into_child_node;
  967. }
  968. ntfs_error(sb, "Negative child node vcn in directory inode "
  969. "0x%lx.", dir_ni->mft_no);
  970. goto unm_err_out;
  971. }
  972. /* No child node, return -ENOENT. */
  973. ntfs_debug("Entry not found.");
  974. err = -ENOENT;
  975. unm_err_out:
  976. unlock_page(page);
  977. ntfs_unmap_page(page);
  978. err_out:
  979. if (!err)
  980. err = -EIO;
  981. if (ctx)
  982. ntfs_attr_put_search_ctx(ctx);
  983. if (m)
  984. unmap_mft_record(dir_ni);
  985. return ERR_MREF(err);
  986. dir_err_out:
  987. ntfs_error(sb, "Corrupt directory. Aborting lookup.");
  988. goto err_out;
  989. }
  990. #endif
  991. /**
  992. * ntfs_filldir - ntfs specific filldir method
  993. * @vol: current ntfs volume
  994. * @fpos: position in the directory
  995. * @ndir: ntfs inode of current directory
  996. * @ia_page: page in which the index allocation buffer @ie is in resides
  997. * @ie: current index entry
  998. * @name: buffer to use for the converted name
  999. * @dirent: vfs filldir callback context
  1000. * @filldir: vfs filldir callback
  1001. *
  1002. * Convert the Unicode @name to the loaded NLS and pass it to the @filldir
  1003. * callback.
  1004. *
  1005. * If @ia_page is not NULL it is the locked page containing the index
  1006. * allocation block containing the index entry @ie.
  1007. *
  1008. * Note, we drop (and then reacquire) the page lock on @ia_page across the
  1009. * @filldir() call otherwise we would deadlock with NFSd when it calls ->lookup
  1010. * since ntfs_lookup() will lock the same page. As an optimization, we do not
  1011. * retake the lock if we are returning a non-zero value as ntfs_readdir()
  1012. * would need to drop the lock immediately anyway.
  1013. */
  1014. static inline int ntfs_filldir(ntfs_volume *vol, loff_t fpos,
  1015. ntfs_inode *ndir, struct page *ia_page, INDEX_ENTRY *ie,
  1016. u8 *name, void *dirent, filldir_t filldir)
  1017. {
  1018. unsigned long mref;
  1019. int name_len, rc;
  1020. unsigned dt_type;
  1021. FILE_NAME_TYPE_FLAGS name_type;
  1022. name_type = ie->key.file_name.file_name_type;
  1023. if (name_type == FILE_NAME_DOS) {
  1024. ntfs_debug("Skipping DOS name space entry.");
  1025. return 0;
  1026. }
  1027. if (MREF_LE(ie->data.dir.indexed_file) == FILE_root) {
  1028. ntfs_debug("Skipping root directory self reference entry.");
  1029. return 0;
  1030. }
  1031. if (MREF_LE(ie->data.dir.indexed_file) < FILE_first_user &&
  1032. !NVolShowSystemFiles(vol)) {
  1033. ntfs_debug("Skipping system file.");
  1034. return 0;
  1035. }
  1036. name_len = ntfs_ucstonls(vol, (ntfschar*)&ie->key.file_name.file_name,
  1037. ie->key.file_name.file_name_length, &name,
  1038. NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1);
  1039. if (name_len <= 0) {
  1040. ntfs_debug("Skipping unrepresentable file.");
  1041. return 0;
  1042. }
  1043. if (ie->key.file_name.file_attributes &
  1044. FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT)
  1045. dt_type = DT_DIR;
  1046. else
  1047. dt_type = DT_REG;
  1048. mref = MREF_LE(ie->data.dir.indexed_file);
  1049. /*
  1050. * Drop the page lock otherwise we deadlock with NFS when it calls
  1051. * ->lookup since ntfs_lookup() will lock the same page.
  1052. */
  1053. if (ia_page)
  1054. unlock_page(ia_page);
  1055. ntfs_debug("Calling filldir for %s with len %i, fpos 0x%llx, inode "
  1056. "0x%lx, DT_%s.", name, name_len, fpos, mref,
  1057. dt_type == DT_DIR ? "DIR" : "REG");
  1058. rc = filldir(dirent, name, name_len, fpos, mref, dt_type);
  1059. /* Relock the page but not if we are aborting ->readdir. */
  1060. if (!rc && ia_page)
  1061. lock_page(ia_page);
  1062. return rc;
  1063. }
  1064. /*
  1065. * We use the same basic approach as the old NTFS driver, i.e. we parse the
  1066. * index root entries and then the index allocation entries that are marked
  1067. * as in use in the index bitmap.
  1068. *
  1069. * While this will return the names in random order this doesn't matter for
  1070. * ->readdir but OTOH results in a faster ->readdir.
  1071. *
  1072. * VFS calls ->readdir without BKL but with i_sem held. This protects the VFS
  1073. * parts (e.g. ->f_pos and ->i_size, and it also protects against directory
  1074. * modifications).
  1075. *
  1076. * Locking: - Caller must hold i_sem on the directory.
  1077. * - Each page cache page in the index allocation mapping must be
  1078. * locked whilst being accessed otherwise we may find a corrupt
  1079. * page due to it being under ->writepage at the moment which
  1080. * applies the mst protection fixups before writing out and then
  1081. * removes them again after the write is complete after which it
  1082. * unlocks the page.
  1083. */
  1084. static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
  1085. {
  1086. s64 ia_pos, ia_start, prev_ia_pos, bmp_pos;
  1087. loff_t fpos;
  1088. struct inode *bmp_vi, *vdir = filp->f_dentry->d_inode;
  1089. struct super_block *sb = vdir->i_sb;
  1090. ntfs_inode *ndir = NTFS_I(vdir);
  1091. ntfs_volume *vol = NTFS_SB(sb);
  1092. MFT_RECORD *m;
  1093. INDEX_ROOT *ir = NULL;
  1094. INDEX_ENTRY *ie;
  1095. INDEX_ALLOCATION *ia;
  1096. u8 *name = NULL;
  1097. int rc, err, ir_pos, cur_bmp_pos;
  1098. struct address_space *ia_mapping, *bmp_mapping;
  1099. struct page *bmp_page = NULL, *ia_page = NULL;
  1100. u8 *kaddr, *bmp, *index_end;
  1101. ntfs_attr_search_ctx *ctx;
  1102. fpos = filp->f_pos;
  1103. ntfs_debug("Entering for inode 0x%lx, fpos 0x%llx.",
  1104. vdir->i_ino, fpos);
  1105. rc = err = 0;
  1106. /* Are we at end of dir yet? */
  1107. if (fpos >= vdir->i_size + vol->mft_record_size)
  1108. goto done;
  1109. /* Emulate . and .. for all directories. */
  1110. if (!fpos) {
  1111. ntfs_debug("Calling filldir for . with len 1, fpos 0x0, "
  1112. "inode 0x%lx, DT_DIR.", vdir->i_ino);
  1113. rc = filldir(dirent, ".", 1, fpos, vdir->i_ino, DT_DIR);
  1114. if (rc)
  1115. goto done;
  1116. fpos++;
  1117. }
  1118. if (fpos == 1) {
  1119. ntfs_debug("Calling filldir for .. with len 2, fpos 0x1, "
  1120. "inode 0x%lx, DT_DIR.",
  1121. parent_ino(filp->f_dentry));
  1122. rc = filldir(dirent, "..", 2, fpos,
  1123. parent_ino(filp->f_dentry), DT_DIR);
  1124. if (rc)
  1125. goto done;
  1126. fpos++;
  1127. }
  1128. m = NULL;
  1129. ctx = NULL;
  1130. /*
  1131. * Allocate a buffer to store the current name being processed
  1132. * converted to format determined by current NLS.
  1133. */
  1134. name = (u8*)kmalloc(NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1,
  1135. GFP_NOFS);
  1136. if (unlikely(!name)) {
  1137. err = -ENOMEM;
  1138. goto err_out;
  1139. }
  1140. /* Are we jumping straight into the index allocation attribute? */
  1141. if (fpos >= vol->mft_record_size)
  1142. goto skip_index_root;
  1143. /* Get hold of the mft record for the directory. */
  1144. m = map_mft_record(ndir);
  1145. if (IS_ERR(m)) {
  1146. err = PTR_ERR(m);
  1147. m = NULL;
  1148. goto err_out;
  1149. }
  1150. ctx = ntfs_attr_get_search_ctx(ndir, m);
  1151. if (unlikely(!ctx)) {
  1152. err = -ENOMEM;
  1153. goto err_out;
  1154. }
  1155. /* Get the offset into the index root attribute. */
  1156. ir_pos = (s64)fpos;
  1157. /* Find the index root attribute in the mft record. */
  1158. err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
  1159. 0, ctx);
  1160. if (unlikely(err)) {
  1161. ntfs_error(sb, "Index root attribute missing in directory "
  1162. "inode 0x%lx.", vdir->i_ino);
  1163. goto err_out;
  1164. }
  1165. /*
  1166. * Copy the index root attribute value to a buffer so that we can put
  1167. * the search context and unmap the mft record before calling the
  1168. * filldir() callback. We need to do this because of NFSd which calls
  1169. * ->lookup() from its filldir callback() and this causes NTFS to
  1170. * deadlock as ntfs_lookup() maps the mft record of the directory and
  1171. * we have got it mapped here already. The only solution is for us to
  1172. * unmap the mft record here so that a call to ntfs_lookup() is able to
  1173. * map the mft record without deadlocking.
  1174. */
  1175. rc = le32_to_cpu(ctx->attr->data.resident.value_length);
  1176. ir = (INDEX_ROOT*)kmalloc(rc, GFP_NOFS);
  1177. if (unlikely(!ir)) {
  1178. err = -ENOMEM;
  1179. goto err_out;
  1180. }
  1181. /* Copy the index root value (it has been verified in read_inode). */
  1182. memcpy(ir, (u8*)ctx->attr +
  1183. le16_to_cpu(ctx->attr->data.resident.value_offset), rc);
  1184. ntfs_attr_put_search_ctx(ctx);
  1185. unmap_mft_record(ndir);
  1186. ctx = NULL;
  1187. m = NULL;
  1188. index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
  1189. /* The first index entry. */
  1190. ie = (INDEX_ENTRY*)((u8*)&ir->index +
  1191. le32_to_cpu(ir->index.entries_offset));
  1192. /*
  1193. * Loop until we exceed valid memory (corruption case) or until we
  1194. * reach the last entry or until filldir tells us it has had enough
  1195. * or signals an error (both covered by the rc test).
  1196. */
  1197. for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
  1198. ntfs_debug("In index root, offset 0x%zx.", (u8*)ie - (u8*)ir);
  1199. /* Bounds checks. */
  1200. if (unlikely((u8*)ie < (u8*)ir || (u8*)ie +
  1201. sizeof(INDEX_ENTRY_HEADER) > index_end ||
  1202. (u8*)ie + le16_to_cpu(ie->key_length) >
  1203. index_end))
  1204. goto err_out;
  1205. /* The last entry cannot contain a name. */
  1206. if (ie->flags & INDEX_ENTRY_END)
  1207. break;
  1208. /* Skip index root entry if continuing previous readdir. */
  1209. if (ir_pos > (u8*)ie - (u8*)ir)
  1210. continue;
  1211. /* Advance the position even if going to skip the entry. */
  1212. fpos = (u8*)ie - (u8*)ir;
  1213. /* Submit the name to the filldir callback. */
  1214. rc = ntfs_filldir(vol, fpos, ndir, NULL, ie, name, dirent,
  1215. filldir);
  1216. if (rc) {
  1217. kfree(ir);
  1218. goto abort;
  1219. }
  1220. }
  1221. /* We are done with the index root and can free the buffer. */
  1222. kfree(ir);
  1223. ir = NULL;
  1224. /* If there is no index allocation attribute we are finished. */
  1225. if (!NInoIndexAllocPresent(ndir))
  1226. goto EOD;
  1227. /* Advance fpos to the beginning of the index allocation. */
  1228. fpos = vol->mft_record_size;
  1229. skip_index_root:
  1230. kaddr = NULL;
  1231. prev_ia_pos = -1LL;
  1232. /* Get the offset into the index allocation attribute. */
  1233. ia_pos = (s64)fpos - vol->mft_record_size;
  1234. ia_mapping = vdir->i_mapping;
  1235. bmp_vi = ndir->itype.index.bmp_ino;
  1236. if (unlikely(!bmp_vi)) {
  1237. ntfs_debug("Inode 0x%lx, regetting index bitmap.", vdir->i_ino);
  1238. bmp_vi = ntfs_attr_iget(vdir, AT_BITMAP, I30, 4);
  1239. if (IS_ERR(bmp_vi)) {
  1240. ntfs_error(sb, "Failed to get bitmap attribute.");
  1241. err = PTR_ERR(bmp_vi);
  1242. goto err_out;
  1243. }
  1244. ndir->itype.index.bmp_ino = bmp_vi;
  1245. }
  1246. bmp_mapping = bmp_vi->i_mapping;
  1247. /* Get the starting bitmap bit position and sanity check it. */
  1248. bmp_pos = ia_pos >> ndir->itype.index.block_size_bits;
  1249. if (unlikely(bmp_pos >> 3 >= bmp_vi->i_size)) {
  1250. ntfs_error(sb, "Current index allocation position exceeds "
  1251. "index bitmap size.");
  1252. goto err_out;
  1253. }
  1254. /* Get the starting bit position in the current bitmap page. */
  1255. cur_bmp_pos = bmp_pos & ((PAGE_CACHE_SIZE * 8) - 1);
  1256. bmp_pos &= ~(u64)((PAGE_CACHE_SIZE * 8) - 1);
  1257. get_next_bmp_page:
  1258. ntfs_debug("Reading bitmap with page index 0x%llx, bit ofs 0x%llx",
  1259. (unsigned long long)bmp_pos >> (3 + PAGE_CACHE_SHIFT),
  1260. (unsigned long long)bmp_pos &
  1261. (unsigned long long)((PAGE_CACHE_SIZE * 8) - 1));
  1262. bmp_page = ntfs_map_page(bmp_mapping,
  1263. bmp_pos >> (3 + PAGE_CACHE_SHIFT));
  1264. if (IS_ERR(bmp_page)) {
  1265. ntfs_error(sb, "Reading index bitmap failed.");
  1266. err = PTR_ERR(bmp_page);
  1267. bmp_page = NULL;
  1268. goto err_out;
  1269. }
  1270. bmp = (u8*)page_address(bmp_page);
  1271. /* Find next index block in use. */
  1272. while (!(bmp[cur_bmp_pos >> 3] & (1 << (cur_bmp_pos & 7)))) {
  1273. find_next_index_buffer:
  1274. cur_bmp_pos++;
  1275. /*
  1276. * If we have reached the end of the bitmap page, get the next
  1277. * page, and put away the old one.
  1278. */
  1279. if (unlikely((cur_bmp_pos >> 3) >= PAGE_CACHE_SIZE)) {
  1280. ntfs_unmap_page(bmp_page);
  1281. bmp_pos += PAGE_CACHE_SIZE * 8;
  1282. cur_bmp_pos = 0;
  1283. goto get_next_bmp_page;
  1284. }
  1285. /* If we have reached the end of the bitmap, we are done. */
  1286. if (unlikely(((bmp_pos + cur_bmp_pos) >> 3) >= vdir->i_size))
  1287. goto unm_EOD;
  1288. ia_pos = (bmp_pos + cur_bmp_pos) <<
  1289. ndir->itype.index.block_size_bits;
  1290. }
  1291. ntfs_debug("Handling index buffer 0x%llx.",
  1292. (unsigned long long)bmp_pos + cur_bmp_pos);
  1293. /* If the current index buffer is in the same page we reuse the page. */
  1294. if ((prev_ia_pos & PAGE_CACHE_MASK) != (ia_pos & PAGE_CACHE_MASK)) {
  1295. prev_ia_pos = ia_pos;
  1296. if (likely(ia_page != NULL)) {
  1297. unlock_page(ia_page);
  1298. ntfs_unmap_page(ia_page);
  1299. }
  1300. /*
  1301. * Map the page cache page containing the current ia_pos,
  1302. * reading it from disk if necessary.
  1303. */
  1304. ia_page = ntfs_map_page(ia_mapping, ia_pos >> PAGE_CACHE_SHIFT);
  1305. if (IS_ERR(ia_page)) {
  1306. ntfs_error(sb, "Reading index allocation data failed.");
  1307. err = PTR_ERR(ia_page);
  1308. ia_page = NULL;
  1309. goto err_out;
  1310. }
  1311. lock_page(ia_page);
  1312. kaddr = (u8*)page_address(ia_page);
  1313. }
  1314. /* Get the current index buffer. */
  1315. ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
  1316. ~(s64)(ndir->itype.index.block_size - 1)));
  1317. /* Bounds checks. */
  1318. if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
  1319. ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
  1320. "inode 0x%lx or driver bug.", vdir->i_ino);
  1321. goto err_out;
  1322. }
  1323. /* Catch multi sector transfer fixup errors. */
  1324. if (unlikely(!ntfs_is_indx_record(ia->magic))) {
  1325. ntfs_error(sb, "Directory index record with vcn 0x%llx is "
  1326. "corrupt. Corrupt inode 0x%lx. Run chkdsk.",
  1327. (unsigned long long)ia_pos >>
  1328. ndir->itype.index.vcn_size_bits, vdir->i_ino);
  1329. goto err_out;
  1330. }
  1331. if (unlikely(sle64_to_cpu(ia->index_block_vcn) != (ia_pos &
  1332. ~(s64)(ndir->itype.index.block_size - 1)) >>
  1333. ndir->itype.index.vcn_size_bits)) {
  1334. ntfs_error(sb, "Actual VCN (0x%llx) of index buffer is "
  1335. "different from expected VCN (0x%llx). "
  1336. "Directory inode 0x%lx is corrupt or driver "
  1337. "bug. ", (unsigned long long)
  1338. sle64_to_cpu(ia->index_block_vcn),
  1339. (unsigned long long)ia_pos >>
  1340. ndir->itype.index.vcn_size_bits, vdir->i_ino);
  1341. goto err_out;
  1342. }
  1343. if (unlikely(le32_to_cpu(ia->index.allocated_size) + 0x18 !=
  1344. ndir->itype.index.block_size)) {
  1345. ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
  1346. "0x%lx has a size (%u) differing from the "
  1347. "directory specified size (%u). Directory "
  1348. "inode is corrupt or driver bug.",
  1349. (unsigned long long)ia_pos >>
  1350. ndir->itype.index.vcn_size_bits, vdir->i_ino,
  1351. le32_to_cpu(ia->index.allocated_size) + 0x18,
  1352. ndir->itype.index.block_size);
  1353. goto err_out;
  1354. }
  1355. index_end = (u8*)ia + ndir->itype.index.block_size;
  1356. if (unlikely(index_end > kaddr + PAGE_CACHE_SIZE)) {
  1357. ntfs_error(sb, "Index buffer (VCN 0x%llx) of directory inode "
  1358. "0x%lx crosses page boundary. Impossible! "
  1359. "Cannot access! This is probably a bug in the "
  1360. "driver.", (unsigned long long)ia_pos >>
  1361. ndir->itype.index.vcn_size_bits, vdir->i_ino);
  1362. goto err_out;
  1363. }
  1364. ia_start = ia_pos & ~(s64)(ndir->itype.index.block_size - 1);
  1365. index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length);
  1366. if (unlikely(index_end > (u8*)ia + ndir->itype.index.block_size)) {
  1367. ntfs_error(sb, "Size of index buffer (VCN 0x%llx) of directory "
  1368. "inode 0x%lx exceeds maximum size.",
  1369. (unsigned long long)ia_pos >>
  1370. ndir->itype.index.vcn_size_bits, vdir->i_ino);
  1371. goto err_out;
  1372. }
  1373. /* The first index entry in this index buffer. */
  1374. ie = (INDEX_ENTRY*)((u8*)&ia->index +
  1375. le32_to_cpu(ia->index.entries_offset));
  1376. /*
  1377. * Loop until we exceed valid memory (corruption case) or until we
  1378. * reach the last entry or until filldir tells us it has had enough
  1379. * or signals an error (both covered by the rc test).
  1380. */
  1381. for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) {
  1382. ntfs_debug("In index allocation, offset 0x%llx.",
  1383. (unsigned long long)ia_start +
  1384. (unsigned long long)((u8*)ie - (u8*)ia));
  1385. /* Bounds checks. */
  1386. if (unlikely((u8*)ie < (u8*)ia || (u8*)ie +
  1387. sizeof(INDEX_ENTRY_HEADER) > index_end ||
  1388. (u8*)ie + le16_to_cpu(ie->key_length) >
  1389. index_end))
  1390. goto err_out;
  1391. /* The last entry cannot contain a name. */
  1392. if (ie->flags & INDEX_ENTRY_END)
  1393. break;
  1394. /* Skip index block entry if continuing previous readdir. */
  1395. if (ia_pos - ia_start > (u8*)ie - (u8*)ia)
  1396. continue;
  1397. /* Advance the position even if going to skip the entry. */
  1398. fpos = (u8*)ie - (u8*)ia +
  1399. (sle64_to_cpu(ia->index_block_vcn) <<
  1400. ndir->itype.index.vcn_size_bits) +
  1401. vol->mft_record_size;
  1402. /*
  1403. * Submit the name to the @filldir callback. Note,
  1404. * ntfs_filldir() drops the lock on @ia_page but it retakes it
  1405. * before returning, unless a non-zero value is returned in
  1406. * which case the page is left unlocked.
  1407. */
  1408. rc = ntfs_filldir(vol, fpos, ndir, ia_page, ie, name, dirent,
  1409. filldir);
  1410. if (rc) {
  1411. /* @ia_page is already unlocked in this case. */
  1412. ntfs_unmap_page(ia_page);
  1413. ntfs_unmap_page(bmp_page);
  1414. goto abort;
  1415. }
  1416. }
  1417. goto find_next_index_buffer;
  1418. unm_EOD:
  1419. if (ia_page) {
  1420. unlock_page(ia_page);
  1421. ntfs_unmap_page(ia_page);
  1422. }
  1423. ntfs_unmap_page(bmp_page);
  1424. EOD:
  1425. /* We are finished, set fpos to EOD. */
  1426. fpos = vdir->i_size + vol->mft_record_size;
  1427. abort:
  1428. kfree(name);
  1429. done:
  1430. #ifdef DEBUG
  1431. if (!rc)
  1432. ntfs_debug("EOD, fpos 0x%llx, returning 0.", fpos);
  1433. else
  1434. ntfs_debug("filldir returned %i, fpos 0x%llx, returning 0.",
  1435. rc, fpos);
  1436. #endif
  1437. filp->f_pos = fpos;
  1438. return 0;
  1439. err_out:
  1440. if (bmp_page)
  1441. ntfs_unmap_page(bmp_page);
  1442. if (ia_page) {
  1443. unlock_page(ia_page);
  1444. ntfs_unmap_page(ia_page);
  1445. }
  1446. if (ir)
  1447. kfree(ir);
  1448. if (name)
  1449. kfree(name);
  1450. if (ctx)
  1451. ntfs_attr_put_search_ctx(ctx);
  1452. if (m)
  1453. unmap_mft_record(ndir);
  1454. if (!err)
  1455. err = -EIO;
  1456. ntfs_debug("Failed. Returning error code %i.", -err);
  1457. filp->f_pos = fpos;
  1458. return err;
  1459. }
  1460. /**
  1461. * ntfs_dir_open - called when an inode is about to be opened
  1462. * @vi: inode to be opened
  1463. * @filp: file structure describing the inode
  1464. *
  1465. * Limit directory size to the page cache limit on architectures where unsigned
  1466. * long is 32-bits. This is the most we can do for now without overflowing the
  1467. * page cache page index. Doing it this way means we don't run into problems
  1468. * because of existing too large directories. It would be better to allow the
  1469. * user to read the accessible part of the directory but I doubt very much
  1470. * anyone is going to hit this check on a 32-bit architecture, so there is no
  1471. * point in adding the extra complexity required to support this.
  1472. *
  1473. * On 64-bit architectures, the check is hopefully optimized away by the
  1474. * compiler.
  1475. */
  1476. static int ntfs_dir_open(struct inode *vi, struct file *filp)
  1477. {
  1478. if (sizeof(unsigned long) < 8) {
  1479. if (vi->i_size > MAX_LFS_FILESIZE)
  1480. return -EFBIG;
  1481. }
  1482. return 0;
  1483. }
  1484. #ifdef NTFS_RW
  1485. /**
  1486. * ntfs_dir_fsync - sync a directory to disk
  1487. * @filp: directory to be synced
  1488. * @dentry: dentry describing the directory to sync
  1489. * @datasync: if non-zero only flush user data and not metadata
  1490. *
  1491. * Data integrity sync of a directory to disk. Used for fsync, fdatasync, and
  1492. * msync system calls. This function is based on file.c::ntfs_file_fsync().
  1493. *
  1494. * Write the mft record and all associated extent mft records as well as the
  1495. * $INDEX_ALLOCATION and $BITMAP attributes and then sync the block device.
  1496. *
  1497. * If @datasync is true, we do not wait on the inode(s) to be written out
  1498. * but we always wait on the page cache pages to be written out.
  1499. *
  1500. * Note: In the past @filp could be NULL so we ignore it as we don't need it
  1501. * anyway.
  1502. *
  1503. * Locking: Caller must hold i_sem on the inode.
  1504. *
  1505. * TODO: We should probably also write all attribute/index inodes associated
  1506. * with this inode but since we have no simple way of getting to them we ignore
  1507. * this problem for now. We do write the $BITMAP attribute if it is present
  1508. * which is the important one for a directory so things are not too bad.
  1509. */
  1510. static int ntfs_dir_fsync(struct file *filp, struct dentry *dentry,
  1511. int datasync)
  1512. {
  1513. struct inode *vi = dentry->d_inode;
  1514. ntfs_inode *ni = NTFS_I(vi);
  1515. int err, ret;
  1516. ntfs_debug("Entering for inode 0x%lx.", vi->i_ino);
  1517. BUG_ON(!S_ISDIR(vi->i_mode));
  1518. if (NInoIndexAllocPresent(ni) && ni->itype.index.bmp_ino)
  1519. write_inode_now(ni->itype.index.bmp_ino, !datasync);
  1520. ret = ntfs_write_inode(vi, 1);
  1521. write_inode_now(vi, !datasync);
  1522. err = sync_blockdev(vi->i_sb->s_bdev);
  1523. if (unlikely(err && !ret))
  1524. ret = err;
  1525. if (likely(!ret))
  1526. ntfs_debug("Done.");
  1527. else
  1528. ntfs_warning(vi->i_sb, "Failed to f%ssync inode 0x%lx. Error "
  1529. "%u.", datasync ? "data" : "", vi->i_ino, -ret);
  1530. return ret;
  1531. }
  1532. #endif /* NTFS_RW */
  1533. struct file_operations ntfs_dir_ops = {
  1534. .llseek = generic_file_llseek, /* Seek inside directory. */
  1535. .read = generic_read_dir, /* Return -EISDIR. */
  1536. .readdir = ntfs_readdir, /* Read directory contents. */
  1537. #ifdef NTFS_RW
  1538. .fsync = ntfs_dir_fsync, /* Sync a directory to disk. */
  1539. /*.aio_fsync = ,*/ /* Sync all outstanding async
  1540. i/o operations on a kiocb. */
  1541. #endif /* NTFS_RW */
  1542. /*.ioctl = ,*/ /* Perform function on the
  1543. mounted filesystem. */
  1544. .open = ntfs_dir_open, /* Open directory. */
  1545. };