readdir.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /*
  2. * fs/cifs/readdir.c
  3. *
  4. * Directory search handling
  5. *
  6. * Copyright (C) International Business Machines Corp., 2004, 2005
  7. * Author(s): Steve French (sfrench@us.ibm.com)
  8. *
  9. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published
  11. * by the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/fs.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/stat.h>
  26. #include <linux/smp_lock.h>
  27. #include "cifspdu.h"
  28. #include "cifsglob.h"
  29. #include "cifsproto.h"
  30. #include "cifs_unicode.h"
  31. #include "cifs_debug.h"
  32. #include "cifs_fs_sb.h"
  33. #include "cifsfs.h"
  34. #ifdef CONFIG_CIFS_DEBUG2
  35. static void dump_cifs_file_struct(struct file *file, char *label)
  36. {
  37. struct cifsFileInfo * cf;
  38. if(file) {
  39. cf = file->private_data;
  40. if(cf == NULL) {
  41. cFYI(1,("empty cifs private file data"));
  42. return;
  43. }
  44. if(cf->invalidHandle) {
  45. cFYI(1,("invalid handle"));
  46. }
  47. if(cf->srch_inf.endOfSearch) {
  48. cFYI(1,("end of search"));
  49. }
  50. if(cf->srch_inf.emptyDir) {
  51. cFYI(1,("empty dir"));
  52. }
  53. }
  54. }
  55. #endif /* DEBUG2 */
  56. /* Returns one if new inode created (which therefore needs to be hashed) */
  57. /* Might check in the future if inode number changed so we can rehash inode */
  58. static int construct_dentry(struct qstr *qstring, struct file *file,
  59. struct inode **ptmp_inode, struct dentry **pnew_dentry)
  60. {
  61. struct dentry *tmp_dentry;
  62. struct cifs_sb_info *cifs_sb;
  63. struct cifsTconInfo *pTcon;
  64. int rc = 0;
  65. cFYI(1, ("For %s", qstring->name));
  66. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  67. pTcon = cifs_sb->tcon;
  68. qstring->hash = full_name_hash(qstring->name, qstring->len);
  69. tmp_dentry = d_lookup(file->f_dentry, qstring);
  70. if (tmp_dentry) {
  71. cFYI(0, ("existing dentry with inode 0x%p", tmp_dentry->d_inode));
  72. *ptmp_inode = tmp_dentry->d_inode;
  73. /* BB overwrite old name? i.e. tmp_dentry->d_name and tmp_dentry->d_name.len??*/
  74. if(*ptmp_inode == NULL) {
  75. *ptmp_inode = new_inode(file->f_dentry->d_sb);
  76. if(*ptmp_inode == NULL)
  77. return rc;
  78. rc = 1;
  79. }
  80. } else {
  81. tmp_dentry = d_alloc(file->f_dentry, qstring);
  82. if(tmp_dentry == NULL) {
  83. cERROR(1,("Failed allocating dentry"));
  84. *ptmp_inode = NULL;
  85. return rc;
  86. }
  87. *ptmp_inode = new_inode(file->f_dentry->d_sb);
  88. if (pTcon->nocase)
  89. tmp_dentry->d_op = &cifs_ci_dentry_ops;
  90. else
  91. tmp_dentry->d_op = &cifs_dentry_ops;
  92. if(*ptmp_inode == NULL)
  93. return rc;
  94. rc = 2;
  95. }
  96. tmp_dentry->d_time = jiffies;
  97. *pnew_dentry = tmp_dentry;
  98. return rc;
  99. }
  100. static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
  101. char * buf, int *pobject_type, int isNewInode)
  102. {
  103. loff_t local_size;
  104. struct timespec local_mtime;
  105. struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
  106. struct cifs_sb_info *cifs_sb = CIFS_SB(tmp_inode->i_sb);
  107. __u32 attr;
  108. __u64 allocation_size;
  109. __u64 end_of_file;
  110. /* save mtime and size */
  111. local_mtime = tmp_inode->i_mtime;
  112. local_size = tmp_inode->i_size;
  113. if(new_buf_type) {
  114. FILE_DIRECTORY_INFO *pfindData = (FILE_DIRECTORY_INFO *)buf;
  115. attr = le32_to_cpu(pfindData->ExtFileAttributes);
  116. allocation_size = le64_to_cpu(pfindData->AllocationSize);
  117. end_of_file = le64_to_cpu(pfindData->EndOfFile);
  118. tmp_inode->i_atime =
  119. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime));
  120. tmp_inode->i_mtime =
  121. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
  122. tmp_inode->i_ctime =
  123. cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
  124. } else { /* legacy, OS2 and DOS style */
  125. FIND_FILE_STANDARD_INFO * pfindData =
  126. (FIND_FILE_STANDARD_INFO *)buf;
  127. attr = le16_to_cpu(pfindData->Attributes);
  128. allocation_size = le32_to_cpu(pfindData->AllocationSize);
  129. end_of_file = le32_to_cpu(pfindData->DataSize);
  130. tmp_inode->i_atime = CURRENT_TIME;
  131. /* tmp_inode->i_mtime = BB FIXME - add dos time handling
  132. tmp_inode->i_ctime = 0; BB FIXME */
  133. }
  134. /* Linux can not store file creation time unfortunately so ignore it */
  135. cifsInfo->cifsAttrs = attr;
  136. cifsInfo->time = jiffies;
  137. /* treat dos attribute of read-only as read-only mode bit e.g. 555? */
  138. /* 2767 perms - indicate mandatory locking */
  139. /* BB fill in uid and gid here? with help from winbind?
  140. or retrieve from NTFS stream extended attribute */
  141. if (atomic_read(&cifsInfo->inUse) == 0) {
  142. tmp_inode->i_uid = cifs_sb->mnt_uid;
  143. tmp_inode->i_gid = cifs_sb->mnt_gid;
  144. /* set default mode. will override for dirs below */
  145. tmp_inode->i_mode = cifs_sb->mnt_file_mode;
  146. } else {
  147. /* mask off the type bits since it gets set
  148. below and we do not want to get two type
  149. bits set */
  150. tmp_inode->i_mode &= ~S_IFMT;
  151. }
  152. if (attr & ATTR_DIRECTORY) {
  153. *pobject_type = DT_DIR;
  154. /* override default perms since we do not lock dirs */
  155. if(atomic_read(&cifsInfo->inUse) == 0) {
  156. tmp_inode->i_mode = cifs_sb->mnt_dir_mode;
  157. }
  158. tmp_inode->i_mode |= S_IFDIR;
  159. } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
  160. (attr & ATTR_SYSTEM)) {
  161. if (end_of_file == 0) {
  162. *pobject_type = DT_FIFO;
  163. tmp_inode->i_mode |= S_IFIFO;
  164. } else {
  165. /* rather than get the type here, we mark the
  166. inode as needing revalidate and get the real type
  167. (blk vs chr vs. symlink) later ie in lookup */
  168. *pobject_type = DT_REG;
  169. tmp_inode->i_mode |= S_IFREG;
  170. cifsInfo->time = 0;
  171. }
  172. /* we no longer mark these because we could not follow them */
  173. /* } else if (attr & ATTR_REPARSE) {
  174. *pobject_type = DT_LNK;
  175. tmp_inode->i_mode |= S_IFLNK; */
  176. } else {
  177. *pobject_type = DT_REG;
  178. tmp_inode->i_mode |= S_IFREG;
  179. if (attr & ATTR_READONLY)
  180. tmp_inode->i_mode &= ~(S_IWUGO);
  181. } /* could add code here - to validate if device or weird share type? */
  182. /* can not fill in nlink here as in qpathinfo version and Unx search */
  183. if (atomic_read(&cifsInfo->inUse) == 0) {
  184. atomic_set(&cifsInfo->inUse, 1);
  185. }
  186. if (is_size_safe_to_change(cifsInfo)) {
  187. /* can not safely change the file size here if the
  188. client is writing to it due to potential races */
  189. i_size_write(tmp_inode, end_of_file);
  190. /* 512 bytes (2**9) is the fake blocksize that must be used */
  191. /* for this calculation, even though the reported blocksize is larger */
  192. tmp_inode->i_blocks = (512 - 1 + allocation_size) >> 9;
  193. }
  194. if (allocation_size < end_of_file)
  195. cFYI(1, ("May be sparse file, allocation less than file size"));
  196. cFYI(1, ("File Size %ld and blocks %llu",
  197. (unsigned long)tmp_inode->i_size,
  198. (unsigned long long)tmp_inode->i_blocks));
  199. if (S_ISREG(tmp_inode->i_mode)) {
  200. cFYI(1, ("File inode"));
  201. tmp_inode->i_op = &cifs_file_inode_ops;
  202. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
  203. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  204. tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
  205. else
  206. tmp_inode->i_fop = &cifs_file_direct_ops;
  207. } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  208. tmp_inode->i_fop = &cifs_file_nobrl_ops;
  209. else
  210. tmp_inode->i_fop = &cifs_file_ops;
  211. if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
  212. (cifs_sb->tcon->ses->server->maxBuf <
  213. PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE))
  214. tmp_inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
  215. else
  216. tmp_inode->i_data.a_ops = &cifs_addr_ops;
  217. if(isNewInode)
  218. return; /* No sense invalidating pages for new inode
  219. since have not started caching readahead file
  220. data yet */
  221. if (timespec_equal(&tmp_inode->i_mtime, &local_mtime) &&
  222. (local_size == tmp_inode->i_size)) {
  223. cFYI(1, ("inode exists but unchanged"));
  224. } else {
  225. /* file may have changed on server */
  226. cFYI(1, ("invalidate inode, readdir detected change"));
  227. invalidate_remote_inode(tmp_inode);
  228. }
  229. } else if (S_ISDIR(tmp_inode->i_mode)) {
  230. cFYI(1, ("Directory inode"));
  231. tmp_inode->i_op = &cifs_dir_inode_ops;
  232. tmp_inode->i_fop = &cifs_dir_ops;
  233. } else if (S_ISLNK(tmp_inode->i_mode)) {
  234. cFYI(1, ("Symbolic Link inode"));
  235. tmp_inode->i_op = &cifs_symlink_inode_ops;
  236. } else {
  237. cFYI(1, ("Init special inode"));
  238. init_special_inode(tmp_inode, tmp_inode->i_mode,
  239. tmp_inode->i_rdev);
  240. }
  241. }
  242. static void unix_fill_in_inode(struct inode *tmp_inode,
  243. FILE_UNIX_INFO *pfindData, int *pobject_type, int isNewInode)
  244. {
  245. loff_t local_size;
  246. struct timespec local_mtime;
  247. struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
  248. struct cifs_sb_info *cifs_sb = CIFS_SB(tmp_inode->i_sb);
  249. __u32 type = le32_to_cpu(pfindData->Type);
  250. __u64 num_of_bytes = le64_to_cpu(pfindData->NumOfBytes);
  251. __u64 end_of_file = le64_to_cpu(pfindData->EndOfFile);
  252. cifsInfo->time = jiffies;
  253. atomic_inc(&cifsInfo->inUse);
  254. /* save mtime and size */
  255. local_mtime = tmp_inode->i_mtime;
  256. local_size = tmp_inode->i_size;
  257. tmp_inode->i_atime =
  258. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime));
  259. tmp_inode->i_mtime =
  260. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastModificationTime));
  261. tmp_inode->i_ctime =
  262. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastStatusChange));
  263. tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
  264. /* since we set the inode type below we need to mask off type
  265. to avoid strange results if bits above were corrupt */
  266. tmp_inode->i_mode &= ~S_IFMT;
  267. if (type == UNIX_FILE) {
  268. *pobject_type = DT_REG;
  269. tmp_inode->i_mode |= S_IFREG;
  270. } else if (type == UNIX_SYMLINK) {
  271. *pobject_type = DT_LNK;
  272. tmp_inode->i_mode |= S_IFLNK;
  273. } else if (type == UNIX_DIR) {
  274. *pobject_type = DT_DIR;
  275. tmp_inode->i_mode |= S_IFDIR;
  276. } else if (type == UNIX_CHARDEV) {
  277. *pobject_type = DT_CHR;
  278. tmp_inode->i_mode |= S_IFCHR;
  279. tmp_inode->i_rdev = MKDEV(le64_to_cpu(pfindData->DevMajor),
  280. le64_to_cpu(pfindData->DevMinor) & MINORMASK);
  281. } else if (type == UNIX_BLOCKDEV) {
  282. *pobject_type = DT_BLK;
  283. tmp_inode->i_mode |= S_IFBLK;
  284. tmp_inode->i_rdev = MKDEV(le64_to_cpu(pfindData->DevMajor),
  285. le64_to_cpu(pfindData->DevMinor) & MINORMASK);
  286. } else if (type == UNIX_FIFO) {
  287. *pobject_type = DT_FIFO;
  288. tmp_inode->i_mode |= S_IFIFO;
  289. } else if (type == UNIX_SOCKET) {
  290. *pobject_type = DT_SOCK;
  291. tmp_inode->i_mode |= S_IFSOCK;
  292. } else {
  293. /* safest to just call it a file */
  294. *pobject_type = DT_REG;
  295. tmp_inode->i_mode |= S_IFREG;
  296. cFYI(1,("unknown inode type %d",type));
  297. }
  298. tmp_inode->i_uid = le64_to_cpu(pfindData->Uid);
  299. tmp_inode->i_gid = le64_to_cpu(pfindData->Gid);
  300. tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks);
  301. if (is_size_safe_to_change(cifsInfo)) {
  302. /* can not safely change the file size here if the
  303. client is writing to it due to potential races */
  304. i_size_write(tmp_inode,end_of_file);
  305. /* 512 bytes (2**9) is the fake blocksize that must be used */
  306. /* for this calculation, not the real blocksize */
  307. tmp_inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
  308. }
  309. if (S_ISREG(tmp_inode->i_mode)) {
  310. cFYI(1, ("File inode"));
  311. tmp_inode->i_op = &cifs_file_inode_ops;
  312. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
  313. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  314. tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
  315. else
  316. tmp_inode->i_fop = &cifs_file_direct_ops;
  317. } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  318. tmp_inode->i_fop = &cifs_file_nobrl_ops;
  319. else
  320. tmp_inode->i_fop = &cifs_file_ops;
  321. if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
  322. (cifs_sb->tcon->ses->server->maxBuf <
  323. PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE))
  324. tmp_inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
  325. else
  326. tmp_inode->i_data.a_ops = &cifs_addr_ops;
  327. if(isNewInode)
  328. return; /* No sense invalidating pages for new inode since we
  329. have not started caching readahead file data yet */
  330. if (timespec_equal(&tmp_inode->i_mtime, &local_mtime) &&
  331. (local_size == tmp_inode->i_size)) {
  332. cFYI(1, ("inode exists but unchanged"));
  333. } else {
  334. /* file may have changed on server */
  335. cFYI(1, ("invalidate inode, readdir detected change"));
  336. invalidate_remote_inode(tmp_inode);
  337. }
  338. } else if (S_ISDIR(tmp_inode->i_mode)) {
  339. cFYI(1, ("Directory inode"));
  340. tmp_inode->i_op = &cifs_dir_inode_ops;
  341. tmp_inode->i_fop = &cifs_dir_ops;
  342. } else if (S_ISLNK(tmp_inode->i_mode)) {
  343. cFYI(1, ("Symbolic Link inode"));
  344. tmp_inode->i_op = &cifs_symlink_inode_ops;
  345. /* tmp_inode->i_fop = *//* do not need to set to anything */
  346. } else {
  347. cFYI(1, ("Special inode"));
  348. init_special_inode(tmp_inode, tmp_inode->i_mode,
  349. tmp_inode->i_rdev);
  350. }
  351. }
  352. static int initiate_cifs_search(const int xid, struct file *file)
  353. {
  354. int rc = 0;
  355. char * full_path;
  356. struct cifsFileInfo * cifsFile;
  357. struct cifs_sb_info *cifs_sb;
  358. struct cifsTconInfo *pTcon;
  359. if(file->private_data == NULL) {
  360. file->private_data =
  361. kmalloc(sizeof(struct cifsFileInfo),GFP_KERNEL);
  362. }
  363. if(file->private_data == NULL) {
  364. return -ENOMEM;
  365. } else {
  366. memset(file->private_data,0,sizeof(struct cifsFileInfo));
  367. }
  368. cifsFile = file->private_data;
  369. cifsFile->invalidHandle = TRUE;
  370. cifsFile->srch_inf.endOfSearch = FALSE;
  371. if(file->f_dentry == NULL)
  372. return -ENOENT;
  373. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  374. if(cifs_sb == NULL)
  375. return -EINVAL;
  376. pTcon = cifs_sb->tcon;
  377. if(pTcon == NULL)
  378. return -EINVAL;
  379. full_path = build_path_from_dentry(file->f_dentry);
  380. if(full_path == NULL) {
  381. return -ENOMEM;
  382. }
  383. cFYI(1, ("Full path: %s start at: %lld", full_path, file->f_pos));
  384. ffirst_retry:
  385. /* test for Unix extensions */
  386. if (pTcon->ses->capabilities & CAP_UNIX) {
  387. cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX;
  388. } else if ((pTcon->ses->capabilities &
  389. (CAP_NT_SMBS | CAP_NT_FIND)) == 0) {
  390. cifsFile->srch_inf.info_level = SMB_FIND_FILE_INFO_STANDARD;
  391. } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
  392. cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
  393. } else /* not srvinos - BB fixme add check for backlevel? */ {
  394. cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
  395. }
  396. rc = CIFSFindFirst(xid, pTcon,full_path,cifs_sb->local_nls,
  397. &cifsFile->netfid, &cifsFile->srch_inf,
  398. cifs_sb->mnt_cifs_flags &
  399. CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb));
  400. if(rc == 0)
  401. cifsFile->invalidHandle = FALSE;
  402. if((rc == -EOPNOTSUPP) &&
  403. (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) {
  404. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
  405. goto ffirst_retry;
  406. }
  407. kfree(full_path);
  408. return rc;
  409. }
  410. /* return length of unicode string in bytes */
  411. static int cifs_unicode_bytelen(char *str)
  412. {
  413. int len;
  414. __le16 * ustr = (__le16 *)str;
  415. for(len=0;len <= PATH_MAX;len++) {
  416. if(ustr[len] == 0)
  417. return len << 1;
  418. }
  419. cFYI(1,("Unicode string longer than PATH_MAX found"));
  420. return len << 1;
  421. }
  422. static char *nxt_dir_entry(char *old_entry, char *end_of_smb, int level)
  423. {
  424. char * new_entry;
  425. FILE_DIRECTORY_INFO * pDirInfo = (FILE_DIRECTORY_INFO *)old_entry;
  426. if(level == SMB_FIND_FILE_INFO_STANDARD) {
  427. FIND_FILE_STANDARD_INFO * pfData;
  428. pfData = (FIND_FILE_STANDARD_INFO *)pDirInfo;
  429. new_entry = old_entry + sizeof(FIND_FILE_STANDARD_INFO) +
  430. pfData->FileNameLength;
  431. } else
  432. new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset);
  433. cFYI(1,("new entry %p old entry %p",new_entry,old_entry));
  434. /* validate that new_entry is not past end of SMB */
  435. if(new_entry >= end_of_smb) {
  436. cERROR(1,
  437. ("search entry %p began after end of SMB %p old entry %p",
  438. new_entry, end_of_smb, old_entry));
  439. return NULL;
  440. } else if(((level == SMB_FIND_FILE_INFO_STANDARD) &&
  441. (new_entry + sizeof(FIND_FILE_STANDARD_INFO) > end_of_smb)) ||
  442. ((level != SMB_FIND_FILE_INFO_STANDARD) &&
  443. (new_entry + sizeof(FILE_DIRECTORY_INFO) > end_of_smb))) {
  444. cERROR(1,("search entry %p extends after end of SMB %p",
  445. new_entry, end_of_smb));
  446. return NULL;
  447. } else
  448. return new_entry;
  449. }
  450. #define UNICODE_DOT cpu_to_le16(0x2e)
  451. /* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */
  452. static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile)
  453. {
  454. int rc = 0;
  455. char * filename = NULL;
  456. int len = 0;
  457. if(cfile->srch_inf.info_level == SMB_FIND_FILE_UNIX) {
  458. FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
  459. filename = &pFindData->FileName[0];
  460. if(cfile->srch_inf.unicode) {
  461. len = cifs_unicode_bytelen(filename);
  462. } else {
  463. /* BB should we make this strnlen of PATH_MAX? */
  464. len = strnlen(filename, 5);
  465. }
  466. } else if(cfile->srch_inf.info_level == SMB_FIND_FILE_DIRECTORY_INFO) {
  467. FILE_DIRECTORY_INFO * pFindData =
  468. (FILE_DIRECTORY_INFO *)current_entry;
  469. filename = &pFindData->FileName[0];
  470. len = le32_to_cpu(pFindData->FileNameLength);
  471. } else if(cfile->srch_inf.info_level ==
  472. SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
  473. FILE_FULL_DIRECTORY_INFO * pFindData =
  474. (FILE_FULL_DIRECTORY_INFO *)current_entry;
  475. filename = &pFindData->FileName[0];
  476. len = le32_to_cpu(pFindData->FileNameLength);
  477. } else if(cfile->srch_inf.info_level ==
  478. SMB_FIND_FILE_ID_FULL_DIR_INFO) {
  479. SEARCH_ID_FULL_DIR_INFO * pFindData =
  480. (SEARCH_ID_FULL_DIR_INFO *)current_entry;
  481. filename = &pFindData->FileName[0];
  482. len = le32_to_cpu(pFindData->FileNameLength);
  483. } else if(cfile->srch_inf.info_level ==
  484. SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
  485. FILE_BOTH_DIRECTORY_INFO * pFindData =
  486. (FILE_BOTH_DIRECTORY_INFO *)current_entry;
  487. filename = &pFindData->FileName[0];
  488. len = le32_to_cpu(pFindData->FileNameLength);
  489. } else if(cfile->srch_inf.info_level == SMB_FIND_FILE_INFO_STANDARD) {
  490. FIND_FILE_STANDARD_INFO * pFindData =
  491. (FIND_FILE_STANDARD_INFO *)current_entry;
  492. filename = &pFindData->FileName[0];
  493. len = pFindData->FileNameLength;
  494. } else {
  495. cFYI(1,("Unknown findfirst level %d",cfile->srch_inf.info_level));
  496. }
  497. if(filename) {
  498. if(cfile->srch_inf.unicode) {
  499. __le16 *ufilename = (__le16 *)filename;
  500. if(len == 2) {
  501. /* check for . */
  502. if(ufilename[0] == UNICODE_DOT)
  503. rc = 1;
  504. } else if(len == 4) {
  505. /* check for .. */
  506. if((ufilename[0] == UNICODE_DOT)
  507. &&(ufilename[1] == UNICODE_DOT))
  508. rc = 2;
  509. }
  510. } else /* ASCII */ {
  511. if(len == 1) {
  512. if(filename[0] == '.')
  513. rc = 1;
  514. } else if(len == 2) {
  515. if((filename[0] == '.') && (filename[1] == '.'))
  516. rc = 2;
  517. }
  518. }
  519. }
  520. return rc;
  521. }
  522. /* Check if directory that we are searching has changed so we can decide
  523. whether we can use the cached search results from the previous search */
  524. static int is_dir_changed(struct file * file)
  525. {
  526. struct inode * inode;
  527. struct cifsInodeInfo *cifsInfo;
  528. if(file->f_dentry == NULL)
  529. return 0;
  530. inode = file->f_dentry->d_inode;
  531. if(inode == NULL)
  532. return 0;
  533. cifsInfo = CIFS_I(inode);
  534. if(cifsInfo->time == 0)
  535. return 1; /* directory was changed, perhaps due to unlink */
  536. else
  537. return 0;
  538. }
  539. /* find the corresponding entry in the search */
  540. /* Note that the SMB server returns search entries for . and .. which
  541. complicates logic here if we choose to parse for them and we do not
  542. assume that they are located in the findfirst return buffer.*/
  543. /* We start counting in the buffer with entry 2 and increment for every
  544. entry (do not increment for . or .. entry) */
  545. static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
  546. struct file *file, char **ppCurrentEntry, int *num_to_ret)
  547. {
  548. int rc = 0;
  549. int pos_in_buf = 0;
  550. loff_t first_entry_in_buffer;
  551. loff_t index_to_find = file->f_pos;
  552. struct cifsFileInfo * cifsFile = file->private_data;
  553. /* check if index in the buffer */
  554. if((cifsFile == NULL) || (ppCurrentEntry == NULL) ||
  555. (num_to_ret == NULL))
  556. return -ENOENT;
  557. *ppCurrentEntry = NULL;
  558. first_entry_in_buffer =
  559. cifsFile->srch_inf.index_of_last_entry -
  560. cifsFile->srch_inf.entries_in_buffer;
  561. /* if first entry in buf is zero then is first buffer
  562. in search response data which means it is likely . and ..
  563. will be in this buffer, although some servers do not return
  564. . and .. for the root of a drive and for those we need
  565. to start two entries earlier */
  566. #ifdef CONFIG_CIFS_DEBUG2
  567. dump_cifs_file_struct(file, "In fce ");
  568. #endif
  569. if(((index_to_find < cifsFile->srch_inf.index_of_last_entry) &&
  570. is_dir_changed(file)) ||
  571. (index_to_find < first_entry_in_buffer)) {
  572. /* close and restart search */
  573. cFYI(1,("search backing up - close and restart search"));
  574. cifsFile->invalidHandle = TRUE;
  575. CIFSFindClose(xid, pTcon, cifsFile->netfid);
  576. kfree(cifsFile->search_resume_name);
  577. cifsFile->search_resume_name = NULL;
  578. if(cifsFile->srch_inf.ntwrk_buf_start) {
  579. cFYI(1,("freeing SMB ff cache buf on search rewind"));
  580. if(cifsFile->srch_inf.smallBuf)
  581. cifs_small_buf_release(cifsFile->srch_inf.
  582. ntwrk_buf_start);
  583. else
  584. cifs_buf_release(cifsFile->srch_inf.
  585. ntwrk_buf_start);
  586. }
  587. rc = initiate_cifs_search(xid,file);
  588. if(rc) {
  589. cFYI(1,("error %d reinitiating a search on rewind",rc));
  590. return rc;
  591. }
  592. }
  593. while((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
  594. (rc == 0) && (cifsFile->srch_inf.endOfSearch == FALSE)){
  595. cFYI(1,("calling findnext2"));
  596. rc = CIFSFindNext(xid,pTcon,cifsFile->netfid,
  597. &cifsFile->srch_inf);
  598. if(rc)
  599. return -ENOENT;
  600. }
  601. if(index_to_find < cifsFile->srch_inf.index_of_last_entry) {
  602. /* we found the buffer that contains the entry */
  603. /* scan and find it */
  604. int i;
  605. char * current_entry;
  606. char * end_of_smb = cifsFile->srch_inf.ntwrk_buf_start +
  607. smbCalcSize((struct smb_hdr *)
  608. cifsFile->srch_inf.ntwrk_buf_start);
  609. current_entry = cifsFile->srch_inf.srch_entries_start;
  610. first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry
  611. - cifsFile->srch_inf.entries_in_buffer;
  612. pos_in_buf = index_to_find - first_entry_in_buffer;
  613. cFYI(1,("found entry - pos_in_buf %d",pos_in_buf));
  614. for(i=0;(i<(pos_in_buf)) && (current_entry != NULL);i++) {
  615. /* go entry by entry figuring out which is first */
  616. current_entry = nxt_dir_entry(current_entry,end_of_smb,
  617. cifsFile->srch_inf.info_level);
  618. }
  619. if((current_entry == NULL) && (i < pos_in_buf)) {
  620. /* BB fixme - check if we should flag this error */
  621. cERROR(1,("reached end of buf searching for pos in buf"
  622. " %d index to find %lld rc %d",
  623. pos_in_buf,index_to_find,rc));
  624. }
  625. rc = 0;
  626. *ppCurrentEntry = current_entry;
  627. } else {
  628. cFYI(1,("index not in buffer - could not findnext into it"));
  629. return 0;
  630. }
  631. if(pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
  632. cFYI(1,("can not return entries pos_in_buf beyond last entry"));
  633. *num_to_ret = 0;
  634. } else
  635. *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
  636. return rc;
  637. }
  638. /* inode num, inode type and filename returned */
  639. static int cifs_get_name_from_search_buf(struct qstr *pqst,
  640. char *current_entry, __u16 level, unsigned int unicode,
  641. struct cifs_sb_info * cifs_sb, int max_len, ino_t *pinum)
  642. {
  643. int rc = 0;
  644. unsigned int len = 0;
  645. char * filename;
  646. struct nls_table * nlt = cifs_sb->local_nls;
  647. *pinum = 0;
  648. if(level == SMB_FIND_FILE_UNIX) {
  649. FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
  650. filename = &pFindData->FileName[0];
  651. if(unicode) {
  652. len = cifs_unicode_bytelen(filename);
  653. } else {
  654. /* BB should we make this strnlen of PATH_MAX? */
  655. len = strnlen(filename, PATH_MAX);
  656. }
  657. /* BB fixme - hash low and high 32 bits if not 64 bit arch BB fixme */
  658. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
  659. *pinum = pFindData->UniqueId;
  660. } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
  661. FILE_DIRECTORY_INFO * pFindData =
  662. (FILE_DIRECTORY_INFO *)current_entry;
  663. filename = &pFindData->FileName[0];
  664. len = le32_to_cpu(pFindData->FileNameLength);
  665. } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
  666. FILE_FULL_DIRECTORY_INFO * pFindData =
  667. (FILE_FULL_DIRECTORY_INFO *)current_entry;
  668. filename = &pFindData->FileName[0];
  669. len = le32_to_cpu(pFindData->FileNameLength);
  670. } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
  671. SEARCH_ID_FULL_DIR_INFO * pFindData =
  672. (SEARCH_ID_FULL_DIR_INFO *)current_entry;
  673. filename = &pFindData->FileName[0];
  674. len = le32_to_cpu(pFindData->FileNameLength);
  675. *pinum = pFindData->UniqueId;
  676. } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
  677. FILE_BOTH_DIRECTORY_INFO * pFindData =
  678. (FILE_BOTH_DIRECTORY_INFO *)current_entry;
  679. filename = &pFindData->FileName[0];
  680. len = le32_to_cpu(pFindData->FileNameLength);
  681. } else if(level == SMB_FIND_FILE_INFO_STANDARD) {
  682. FIND_FILE_STANDARD_INFO * pFindData =
  683. (FIND_FILE_STANDARD_INFO *)current_entry;
  684. filename = &pFindData->FileName[0];
  685. /* one byte length, no name conversion */
  686. len = (unsigned int)pFindData->FileNameLength;
  687. } else {
  688. cFYI(1,("Unknown findfirst level %d",level));
  689. return -EINVAL;
  690. }
  691. if(len > max_len) {
  692. cERROR(1,("bad search response length %d past smb end", len));
  693. return -EINVAL;
  694. }
  695. if(unicode) {
  696. /* BB fixme - test with long names */
  697. /* Note converted filename can be longer than in unicode */
  698. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
  699. pqst->len = cifs_convertUCSpath((char *)pqst->name,
  700. (__le16 *)filename, len/2, nlt);
  701. else
  702. pqst->len = cifs_strfromUCS_le((char *)pqst->name,
  703. (__le16 *)filename,len/2,nlt);
  704. } else {
  705. pqst->name = filename;
  706. pqst->len = len;
  707. }
  708. pqst->hash = full_name_hash(pqst->name,pqst->len);
  709. /* cFYI(1,("filldir on %s",pqst->name)); */
  710. return rc;
  711. }
  712. static int cifs_filldir(char *pfindEntry, struct file *file,
  713. filldir_t filldir, void *direntry, char *scratch_buf, int max_len)
  714. {
  715. int rc = 0;
  716. struct qstr qstring;
  717. struct cifsFileInfo * pCifsF;
  718. unsigned obj_type;
  719. ino_t inum;
  720. struct cifs_sb_info * cifs_sb;
  721. struct inode *tmp_inode;
  722. struct dentry *tmp_dentry;
  723. /* get filename and len into qstring */
  724. /* get dentry */
  725. /* decide whether to create and populate ionde */
  726. if((direntry == NULL) || (file == NULL))
  727. return -EINVAL;
  728. pCifsF = file->private_data;
  729. if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
  730. return -ENOENT;
  731. if(file->f_dentry == NULL)
  732. return -ENOENT;
  733. rc = cifs_entry_is_dot(pfindEntry,pCifsF);
  734. /* skip . and .. since we added them first */
  735. if(rc != 0)
  736. return 0;
  737. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  738. qstring.name = scratch_buf;
  739. rc = cifs_get_name_from_search_buf(&qstring,pfindEntry,
  740. pCifsF->srch_inf.info_level,
  741. pCifsF->srch_inf.unicode,cifs_sb,
  742. max_len,
  743. &inum /* returned */);
  744. if(rc)
  745. return rc;
  746. rc = construct_dentry(&qstring,file,&tmp_inode, &tmp_dentry);
  747. if((tmp_inode == NULL) || (tmp_dentry == NULL))
  748. return -ENOMEM;
  749. if(rc) {
  750. /* inode created, we need to hash it with right inode number */
  751. if(inum != 0) {
  752. /* BB fixme - hash the 2 32 quantities bits together if necessary BB */
  753. tmp_inode->i_ino = inum;
  754. }
  755. insert_inode_hash(tmp_inode);
  756. }
  757. /* we pass in rc below, indicating whether it is a new inode,
  758. so we can figure out whether to invalidate the inode cached
  759. data if the file has changed */
  760. if(pCifsF->srch_inf.info_level == SMB_FIND_FILE_UNIX)
  761. unix_fill_in_inode(tmp_inode,
  762. (FILE_UNIX_INFO *)pfindEntry,
  763. &obj_type, rc);
  764. else if(pCifsF->srch_inf.info_level == SMB_FIND_FILE_INFO_STANDARD)
  765. fill_in_inode(tmp_inode, 0 /* old level 1 buffer type */,
  766. pfindEntry, &obj_type, rc);
  767. else
  768. fill_in_inode(tmp_inode, 1 /* NT */, pfindEntry, &obj_type, rc);
  769. if(rc) /* new inode - needs to be tied to dentry */ {
  770. d_instantiate(tmp_dentry, tmp_inode);
  771. if(rc == 2)
  772. d_rehash(tmp_dentry);
  773. }
  774. rc = filldir(direntry,qstring.name,qstring.len,file->f_pos,
  775. tmp_inode->i_ino,obj_type);
  776. if(rc) {
  777. cFYI(1,("filldir rc = %d",rc));
  778. }
  779. dput(tmp_dentry);
  780. return rc;
  781. }
  782. static int cifs_save_resume_key(const char *current_entry,
  783. struct cifsFileInfo *cifsFile)
  784. {
  785. int rc = 0;
  786. unsigned int len = 0;
  787. __u16 level;
  788. char * filename;
  789. if((cifsFile == NULL) || (current_entry == NULL))
  790. return -EINVAL;
  791. level = cifsFile->srch_inf.info_level;
  792. if(level == SMB_FIND_FILE_UNIX) {
  793. FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
  794. filename = &pFindData->FileName[0];
  795. if(cifsFile->srch_inf.unicode) {
  796. len = cifs_unicode_bytelen(filename);
  797. } else {
  798. /* BB should we make this strnlen of PATH_MAX? */
  799. len = strnlen(filename, PATH_MAX);
  800. }
  801. cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
  802. } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
  803. FILE_DIRECTORY_INFO * pFindData =
  804. (FILE_DIRECTORY_INFO *)current_entry;
  805. filename = &pFindData->FileName[0];
  806. len = le32_to_cpu(pFindData->FileNameLength);
  807. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  808. } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
  809. FILE_FULL_DIRECTORY_INFO * pFindData =
  810. (FILE_FULL_DIRECTORY_INFO *)current_entry;
  811. filename = &pFindData->FileName[0];
  812. len = le32_to_cpu(pFindData->FileNameLength);
  813. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  814. } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
  815. SEARCH_ID_FULL_DIR_INFO * pFindData =
  816. (SEARCH_ID_FULL_DIR_INFO *)current_entry;
  817. filename = &pFindData->FileName[0];
  818. len = le32_to_cpu(pFindData->FileNameLength);
  819. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  820. } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
  821. FILE_BOTH_DIRECTORY_INFO * pFindData =
  822. (FILE_BOTH_DIRECTORY_INFO *)current_entry;
  823. filename = &pFindData->FileName[0];
  824. len = le32_to_cpu(pFindData->FileNameLength);
  825. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  826. } else if(level == SMB_FIND_FILE_INFO_STANDARD) {
  827. FIND_FILE_STANDARD_INFO * pFindData =
  828. (FIND_FILE_STANDARD_INFO *)current_entry;
  829. filename = &pFindData->FileName[0];
  830. /* one byte length, no name conversion */
  831. len = (unsigned int)pFindData->FileNameLength;
  832. } else {
  833. cFYI(1,("Unknown findfirst level %d",level));
  834. return -EINVAL;
  835. }
  836. cifsFile->srch_inf.resume_name_len = len;
  837. cifsFile->srch_inf.presume_name = filename;
  838. return rc;
  839. }
  840. int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
  841. {
  842. int rc = 0;
  843. int xid,i;
  844. struct cifs_sb_info *cifs_sb;
  845. struct cifsTconInfo *pTcon;
  846. struct cifsFileInfo *cifsFile = NULL;
  847. char * current_entry;
  848. int num_to_fill = 0;
  849. char * tmp_buf = NULL;
  850. char * end_of_smb;
  851. int max_len;
  852. xid = GetXid();
  853. if(file->f_dentry == NULL) {
  854. FreeXid(xid);
  855. return -EIO;
  856. }
  857. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  858. pTcon = cifs_sb->tcon;
  859. if(pTcon == NULL)
  860. return -EINVAL;
  861. switch ((int) file->f_pos) {
  862. case 0:
  863. if (filldir(direntry, ".", 1, file->f_pos,
  864. file->f_dentry->d_inode->i_ino, DT_DIR) < 0) {
  865. cERROR(1, ("Filldir for current dir failed"));
  866. rc = -ENOMEM;
  867. break;
  868. }
  869. file->f_pos++;
  870. case 1:
  871. if (filldir(direntry, "..", 2, file->f_pos,
  872. file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
  873. cERROR(1, ("Filldir for parent dir failed"));
  874. rc = -ENOMEM;
  875. break;
  876. }
  877. file->f_pos++;
  878. default:
  879. /* 1) If search is active,
  880. is in current search buffer?
  881. if it before then restart search
  882. if after then keep searching till find it */
  883. if(file->private_data == NULL) {
  884. rc = initiate_cifs_search(xid,file);
  885. cFYI(1,("initiate cifs search rc %d",rc));
  886. if(rc) {
  887. FreeXid(xid);
  888. return rc;
  889. }
  890. }
  891. if(file->private_data == NULL) {
  892. rc = -EINVAL;
  893. FreeXid(xid);
  894. return rc;
  895. }
  896. cifsFile = file->private_data;
  897. if (cifsFile->srch_inf.endOfSearch) {
  898. if(cifsFile->srch_inf.emptyDir) {
  899. cFYI(1, ("End of search, empty dir"));
  900. rc = 0;
  901. break;
  902. }
  903. } /* else {
  904. cifsFile->invalidHandle = TRUE;
  905. CIFSFindClose(xid, pTcon, cifsFile->netfid);
  906. }
  907. kfree(cifsFile->search_resume_name);
  908. cifsFile->search_resume_name = NULL; */
  909. rc = find_cifs_entry(xid,pTcon, file,
  910. &current_entry,&num_to_fill);
  911. if(rc) {
  912. cFYI(1,("fce error %d",rc));
  913. goto rddir2_exit;
  914. } else if (current_entry != NULL) {
  915. cFYI(1,("entry %lld found",file->f_pos));
  916. } else {
  917. cFYI(1,("could not find entry"));
  918. goto rddir2_exit;
  919. }
  920. cFYI(1,("loop through %d times filling dir for net buf %p",
  921. num_to_fill,cifsFile->srch_inf.ntwrk_buf_start));
  922. max_len = smbCalcSize((struct smb_hdr *)
  923. cifsFile->srch_inf.ntwrk_buf_start);
  924. end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
  925. /* To be safe - for UCS to UTF-8 with strings loaded
  926. with the rare long characters alloc more to account for
  927. such multibyte target UTF-8 characters. cifs_unicode.c,
  928. which actually does the conversion, has the same limit */
  929. tmp_buf = kmalloc((2 * NAME_MAX) + 4, GFP_KERNEL);
  930. for(i=0;(i<num_to_fill) && (rc == 0);i++) {
  931. if(current_entry == NULL) {
  932. /* evaluate whether this case is an error */
  933. cERROR(1,("past end of SMB num to fill %d i %d",
  934. num_to_fill, i));
  935. break;
  936. }
  937. /* if buggy server returns . and .. late do
  938. we want to check for that here? */
  939. rc = cifs_filldir(current_entry, file,
  940. filldir, direntry, tmp_buf, max_len);
  941. file->f_pos++;
  942. if(file->f_pos ==
  943. cifsFile->srch_inf.index_of_last_entry) {
  944. cFYI(1,("last entry in buf at pos %lld %s",
  945. file->f_pos,tmp_buf));
  946. cifs_save_resume_key(current_entry,cifsFile);
  947. break;
  948. } else
  949. current_entry =
  950. nxt_dir_entry(current_entry, end_of_smb,
  951. cifsFile->srch_inf.info_level);
  952. }
  953. kfree(tmp_buf);
  954. break;
  955. } /* end switch */
  956. rddir2_exit:
  957. FreeXid(xid);
  958. return rc;
  959. }