readdir.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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 and blocksize %ld",
  197. (unsigned long)tmp_inode->i_size,
  198. (unsigned long long)tmp_inode->i_blocks,
  199. tmp_inode->i_blksize));
  200. if (S_ISREG(tmp_inode->i_mode)) {
  201. cFYI(1, ("File inode"));
  202. tmp_inode->i_op = &cifs_file_inode_ops;
  203. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
  204. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  205. tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
  206. else
  207. tmp_inode->i_fop = &cifs_file_direct_ops;
  208. } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  209. tmp_inode->i_fop = &cifs_file_nobrl_ops;
  210. else
  211. tmp_inode->i_fop = &cifs_file_ops;
  212. if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
  213. (cifs_sb->tcon->ses->server->maxBuf <
  214. PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE))
  215. tmp_inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
  216. else
  217. tmp_inode->i_data.a_ops = &cifs_addr_ops;
  218. if(isNewInode)
  219. return; /* No sense invalidating pages for new inode
  220. since have not started caching readahead file
  221. data yet */
  222. if (timespec_equal(&tmp_inode->i_mtime, &local_mtime) &&
  223. (local_size == tmp_inode->i_size)) {
  224. cFYI(1, ("inode exists but unchanged"));
  225. } else {
  226. /* file may have changed on server */
  227. cFYI(1, ("invalidate inode, readdir detected change"));
  228. invalidate_remote_inode(tmp_inode);
  229. }
  230. } else if (S_ISDIR(tmp_inode->i_mode)) {
  231. cFYI(1, ("Directory inode"));
  232. tmp_inode->i_op = &cifs_dir_inode_ops;
  233. tmp_inode->i_fop = &cifs_dir_ops;
  234. } else if (S_ISLNK(tmp_inode->i_mode)) {
  235. cFYI(1, ("Symbolic Link inode"));
  236. tmp_inode->i_op = &cifs_symlink_inode_ops;
  237. } else {
  238. cFYI(1, ("Init special inode"));
  239. init_special_inode(tmp_inode, tmp_inode->i_mode,
  240. tmp_inode->i_rdev);
  241. }
  242. }
  243. static void unix_fill_in_inode(struct inode *tmp_inode,
  244. FILE_UNIX_INFO *pfindData, int *pobject_type, int isNewInode)
  245. {
  246. loff_t local_size;
  247. struct timespec local_mtime;
  248. struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
  249. struct cifs_sb_info *cifs_sb = CIFS_SB(tmp_inode->i_sb);
  250. __u32 type = le32_to_cpu(pfindData->Type);
  251. __u64 num_of_bytes = le64_to_cpu(pfindData->NumOfBytes);
  252. __u64 end_of_file = le64_to_cpu(pfindData->EndOfFile);
  253. cifsInfo->time = jiffies;
  254. atomic_inc(&cifsInfo->inUse);
  255. /* save mtime and size */
  256. local_mtime = tmp_inode->i_mtime;
  257. local_size = tmp_inode->i_size;
  258. tmp_inode->i_atime =
  259. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime));
  260. tmp_inode->i_mtime =
  261. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastModificationTime));
  262. tmp_inode->i_ctime =
  263. cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastStatusChange));
  264. tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
  265. /* since we set the inode type below we need to mask off type
  266. to avoid strange results if bits above were corrupt */
  267. tmp_inode->i_mode &= ~S_IFMT;
  268. if (type == UNIX_FILE) {
  269. *pobject_type = DT_REG;
  270. tmp_inode->i_mode |= S_IFREG;
  271. } else if (type == UNIX_SYMLINK) {
  272. *pobject_type = DT_LNK;
  273. tmp_inode->i_mode |= S_IFLNK;
  274. } else if (type == UNIX_DIR) {
  275. *pobject_type = DT_DIR;
  276. tmp_inode->i_mode |= S_IFDIR;
  277. } else if (type == UNIX_CHARDEV) {
  278. *pobject_type = DT_CHR;
  279. tmp_inode->i_mode |= S_IFCHR;
  280. tmp_inode->i_rdev = MKDEV(le64_to_cpu(pfindData->DevMajor),
  281. le64_to_cpu(pfindData->DevMinor) & MINORMASK);
  282. } else if (type == UNIX_BLOCKDEV) {
  283. *pobject_type = DT_BLK;
  284. tmp_inode->i_mode |= S_IFBLK;
  285. tmp_inode->i_rdev = MKDEV(le64_to_cpu(pfindData->DevMajor),
  286. le64_to_cpu(pfindData->DevMinor) & MINORMASK);
  287. } else if (type == UNIX_FIFO) {
  288. *pobject_type = DT_FIFO;
  289. tmp_inode->i_mode |= S_IFIFO;
  290. } else if (type == UNIX_SOCKET) {
  291. *pobject_type = DT_SOCK;
  292. tmp_inode->i_mode |= S_IFSOCK;
  293. } else {
  294. /* safest to just call it a file */
  295. *pobject_type = DT_REG;
  296. tmp_inode->i_mode |= S_IFREG;
  297. cFYI(1,("unknown inode type %d",type));
  298. }
  299. tmp_inode->i_uid = le64_to_cpu(pfindData->Uid);
  300. tmp_inode->i_gid = le64_to_cpu(pfindData->Gid);
  301. tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks);
  302. if (is_size_safe_to_change(cifsInfo)) {
  303. /* can not safely change the file size here if the
  304. client is writing to it due to potential races */
  305. i_size_write(tmp_inode,end_of_file);
  306. /* 512 bytes (2**9) is the fake blocksize that must be used */
  307. /* for this calculation, not the real blocksize */
  308. tmp_inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
  309. }
  310. if (S_ISREG(tmp_inode->i_mode)) {
  311. cFYI(1, ("File inode"));
  312. tmp_inode->i_op = &cifs_file_inode_ops;
  313. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
  314. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  315. tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
  316. else
  317. tmp_inode->i_fop = &cifs_file_direct_ops;
  318. } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  319. tmp_inode->i_fop = &cifs_file_nobrl_ops;
  320. else
  321. tmp_inode->i_fop = &cifs_file_ops;
  322. if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
  323. (cifs_sb->tcon->ses->server->maxBuf <
  324. PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE))
  325. tmp_inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
  326. else
  327. tmp_inode->i_data.a_ops = &cifs_addr_ops;
  328. if(isNewInode)
  329. return; /* No sense invalidating pages for new inode since we
  330. have not started caching readahead file data yet */
  331. if (timespec_equal(&tmp_inode->i_mtime, &local_mtime) &&
  332. (local_size == tmp_inode->i_size)) {
  333. cFYI(1, ("inode exists but unchanged"));
  334. } else {
  335. /* file may have changed on server */
  336. cFYI(1, ("invalidate inode, readdir detected change"));
  337. invalidate_remote_inode(tmp_inode);
  338. }
  339. } else if (S_ISDIR(tmp_inode->i_mode)) {
  340. cFYI(1, ("Directory inode"));
  341. tmp_inode->i_op = &cifs_dir_inode_ops;
  342. tmp_inode->i_fop = &cifs_dir_ops;
  343. } else if (S_ISLNK(tmp_inode->i_mode)) {
  344. cFYI(1, ("Symbolic Link inode"));
  345. tmp_inode->i_op = &cifs_symlink_inode_ops;
  346. /* tmp_inode->i_fop = *//* do not need to set to anything */
  347. } else {
  348. cFYI(1, ("Special inode"));
  349. init_special_inode(tmp_inode, tmp_inode->i_mode,
  350. tmp_inode->i_rdev);
  351. }
  352. }
  353. static int initiate_cifs_search(const int xid, struct file *file)
  354. {
  355. int rc = 0;
  356. char * full_path;
  357. struct cifsFileInfo * cifsFile;
  358. struct cifs_sb_info *cifs_sb;
  359. struct cifsTconInfo *pTcon;
  360. if(file->private_data == NULL) {
  361. file->private_data =
  362. kmalloc(sizeof(struct cifsFileInfo),GFP_KERNEL);
  363. }
  364. if(file->private_data == NULL) {
  365. return -ENOMEM;
  366. } else {
  367. memset(file->private_data,0,sizeof(struct cifsFileInfo));
  368. }
  369. cifsFile = file->private_data;
  370. cifsFile->invalidHandle = TRUE;
  371. cifsFile->srch_inf.endOfSearch = FALSE;
  372. if(file->f_dentry == NULL)
  373. return -ENOENT;
  374. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  375. if(cifs_sb == NULL)
  376. return -EINVAL;
  377. pTcon = cifs_sb->tcon;
  378. if(pTcon == NULL)
  379. return -EINVAL;
  380. full_path = build_path_from_dentry(file->f_dentry);
  381. if(full_path == NULL) {
  382. return -ENOMEM;
  383. }
  384. cFYI(1, ("Full path: %s start at: %lld", full_path, file->f_pos));
  385. ffirst_retry:
  386. /* test for Unix extensions */
  387. if (pTcon->ses->capabilities & CAP_UNIX) {
  388. cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX;
  389. } else if ((pTcon->ses->capabilities &
  390. (CAP_NT_SMBS | CAP_NT_FIND)) == 0) {
  391. cifsFile->srch_inf.info_level = SMB_FIND_FILE_INFO_STANDARD;
  392. } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
  393. cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
  394. } else /* not srvinos - BB fixme add check for backlevel? */ {
  395. cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
  396. }
  397. rc = CIFSFindFirst(xid, pTcon,full_path,cifs_sb->local_nls,
  398. &cifsFile->netfid, &cifsFile->srch_inf,
  399. cifs_sb->mnt_cifs_flags &
  400. CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb));
  401. if(rc == 0)
  402. cifsFile->invalidHandle = FALSE;
  403. if((rc == -EOPNOTSUPP) &&
  404. (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) {
  405. cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
  406. goto ffirst_retry;
  407. }
  408. kfree(full_path);
  409. return rc;
  410. }
  411. /* return length of unicode string in bytes */
  412. static int cifs_unicode_bytelen(char *str)
  413. {
  414. int len;
  415. __le16 * ustr = (__le16 *)str;
  416. for(len=0;len <= PATH_MAX;len++) {
  417. if(ustr[len] == 0)
  418. return len << 1;
  419. }
  420. cFYI(1,("Unicode string longer than PATH_MAX found"));
  421. return len << 1;
  422. }
  423. static char *nxt_dir_entry(char *old_entry, char *end_of_smb, int level)
  424. {
  425. char * new_entry;
  426. FILE_DIRECTORY_INFO * pDirInfo = (FILE_DIRECTORY_INFO *)old_entry;
  427. if(level == SMB_FIND_FILE_INFO_STANDARD) {
  428. FIND_FILE_STANDARD_INFO * pfData;
  429. pfData = (FIND_FILE_STANDARD_INFO *)pDirInfo;
  430. new_entry = old_entry + sizeof(FIND_FILE_STANDARD_INFO) +
  431. pfData->FileNameLength;
  432. } else
  433. new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset);
  434. cFYI(1,("new entry %p old entry %p",new_entry,old_entry));
  435. /* validate that new_entry is not past end of SMB */
  436. if(new_entry >= end_of_smb) {
  437. cERROR(1,
  438. ("search entry %p began after end of SMB %p old entry %p",
  439. new_entry, end_of_smb, old_entry));
  440. return NULL;
  441. } else if(((level == SMB_FIND_FILE_INFO_STANDARD) &&
  442. (new_entry + sizeof(FIND_FILE_STANDARD_INFO) > end_of_smb)) ||
  443. ((level != SMB_FIND_FILE_INFO_STANDARD) &&
  444. (new_entry + sizeof(FILE_DIRECTORY_INFO) > end_of_smb))) {
  445. cERROR(1,("search entry %p extends after end of SMB %p",
  446. new_entry, end_of_smb));
  447. return NULL;
  448. } else
  449. return new_entry;
  450. }
  451. #define UNICODE_DOT cpu_to_le16(0x2e)
  452. /* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */
  453. static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile)
  454. {
  455. int rc = 0;
  456. char * filename = NULL;
  457. int len = 0;
  458. if(cfile->srch_inf.info_level == SMB_FIND_FILE_UNIX) {
  459. FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
  460. filename = &pFindData->FileName[0];
  461. if(cfile->srch_inf.unicode) {
  462. len = cifs_unicode_bytelen(filename);
  463. } else {
  464. /* BB should we make this strnlen of PATH_MAX? */
  465. len = strnlen(filename, 5);
  466. }
  467. } else if(cfile->srch_inf.info_level == SMB_FIND_FILE_DIRECTORY_INFO) {
  468. FILE_DIRECTORY_INFO * pFindData =
  469. (FILE_DIRECTORY_INFO *)current_entry;
  470. filename = &pFindData->FileName[0];
  471. len = le32_to_cpu(pFindData->FileNameLength);
  472. } else if(cfile->srch_inf.info_level ==
  473. SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
  474. FILE_FULL_DIRECTORY_INFO * pFindData =
  475. (FILE_FULL_DIRECTORY_INFO *)current_entry;
  476. filename = &pFindData->FileName[0];
  477. len = le32_to_cpu(pFindData->FileNameLength);
  478. } else if(cfile->srch_inf.info_level ==
  479. SMB_FIND_FILE_ID_FULL_DIR_INFO) {
  480. SEARCH_ID_FULL_DIR_INFO * pFindData =
  481. (SEARCH_ID_FULL_DIR_INFO *)current_entry;
  482. filename = &pFindData->FileName[0];
  483. len = le32_to_cpu(pFindData->FileNameLength);
  484. } else if(cfile->srch_inf.info_level ==
  485. SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
  486. FILE_BOTH_DIRECTORY_INFO * pFindData =
  487. (FILE_BOTH_DIRECTORY_INFO *)current_entry;
  488. filename = &pFindData->FileName[0];
  489. len = le32_to_cpu(pFindData->FileNameLength);
  490. } else if(cfile->srch_inf.info_level == SMB_FIND_FILE_INFO_STANDARD) {
  491. FIND_FILE_STANDARD_INFO * pFindData =
  492. (FIND_FILE_STANDARD_INFO *)current_entry;
  493. filename = &pFindData->FileName[0];
  494. len = pFindData->FileNameLength;
  495. } else {
  496. cFYI(1,("Unknown findfirst level %d",cfile->srch_inf.info_level));
  497. }
  498. if(filename) {
  499. if(cfile->srch_inf.unicode) {
  500. __le16 *ufilename = (__le16 *)filename;
  501. if(len == 2) {
  502. /* check for . */
  503. if(ufilename[0] == UNICODE_DOT)
  504. rc = 1;
  505. } else if(len == 4) {
  506. /* check for .. */
  507. if((ufilename[0] == UNICODE_DOT)
  508. &&(ufilename[1] == UNICODE_DOT))
  509. rc = 2;
  510. }
  511. } else /* ASCII */ {
  512. if(len == 1) {
  513. if(filename[0] == '.')
  514. rc = 1;
  515. } else if(len == 2) {
  516. if((filename[0] == '.') && (filename[1] == '.'))
  517. rc = 2;
  518. }
  519. }
  520. }
  521. return rc;
  522. }
  523. /* Check if directory that we are searching has changed so we can decide
  524. whether we can use the cached search results from the previous search */
  525. static int is_dir_changed(struct file * file)
  526. {
  527. struct inode * inode;
  528. struct cifsInodeInfo *cifsInfo;
  529. if(file->f_dentry == NULL)
  530. return 0;
  531. inode = file->f_dentry->d_inode;
  532. if(inode == NULL)
  533. return 0;
  534. cifsInfo = CIFS_I(inode);
  535. if(cifsInfo->time == 0)
  536. return 1; /* directory was changed, perhaps due to unlink */
  537. else
  538. return 0;
  539. }
  540. /* find the corresponding entry in the search */
  541. /* Note that the SMB server returns search entries for . and .. which
  542. complicates logic here if we choose to parse for them and we do not
  543. assume that they are located in the findfirst return buffer.*/
  544. /* We start counting in the buffer with entry 2 and increment for every
  545. entry (do not increment for . or .. entry) */
  546. static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
  547. struct file *file, char **ppCurrentEntry, int *num_to_ret)
  548. {
  549. int rc = 0;
  550. int pos_in_buf = 0;
  551. loff_t first_entry_in_buffer;
  552. loff_t index_to_find = file->f_pos;
  553. struct cifsFileInfo * cifsFile = file->private_data;
  554. /* check if index in the buffer */
  555. if((cifsFile == NULL) || (ppCurrentEntry == NULL) ||
  556. (num_to_ret == NULL))
  557. return -ENOENT;
  558. *ppCurrentEntry = NULL;
  559. first_entry_in_buffer =
  560. cifsFile->srch_inf.index_of_last_entry -
  561. cifsFile->srch_inf.entries_in_buffer;
  562. /* if first entry in buf is zero then is first buffer
  563. in search response data which means it is likely . and ..
  564. will be in this buffer, although some servers do not return
  565. . and .. for the root of a drive and for those we need
  566. to start two entries earlier */
  567. #ifdef CONFIG_CIFS_DEBUG2
  568. dump_cifs_file_struct(file, "In fce ");
  569. #endif
  570. if(((index_to_find < cifsFile->srch_inf.index_of_last_entry) &&
  571. is_dir_changed(file)) ||
  572. (index_to_find < first_entry_in_buffer)) {
  573. /* close and restart search */
  574. cFYI(1,("search backing up - close and restart search"));
  575. cifsFile->invalidHandle = TRUE;
  576. CIFSFindClose(xid, pTcon, cifsFile->netfid);
  577. kfree(cifsFile->search_resume_name);
  578. cifsFile->search_resume_name = NULL;
  579. if(cifsFile->srch_inf.ntwrk_buf_start) {
  580. cFYI(1,("freeing SMB ff cache buf on search rewind"));
  581. if(cifsFile->srch_inf.smallBuf)
  582. cifs_small_buf_release(cifsFile->srch_inf.
  583. ntwrk_buf_start);
  584. else
  585. cifs_buf_release(cifsFile->srch_inf.
  586. ntwrk_buf_start);
  587. }
  588. rc = initiate_cifs_search(xid,file);
  589. if(rc) {
  590. cFYI(1,("error %d reinitiating a search on rewind",rc));
  591. return rc;
  592. }
  593. }
  594. while((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
  595. (rc == 0) && (cifsFile->srch_inf.endOfSearch == FALSE)){
  596. cFYI(1,("calling findnext2"));
  597. rc = CIFSFindNext(xid,pTcon,cifsFile->netfid,
  598. &cifsFile->srch_inf);
  599. if(rc)
  600. return -ENOENT;
  601. }
  602. if(index_to_find < cifsFile->srch_inf.index_of_last_entry) {
  603. /* we found the buffer that contains the entry */
  604. /* scan and find it */
  605. int i;
  606. char * current_entry;
  607. char * end_of_smb = cifsFile->srch_inf.ntwrk_buf_start +
  608. smbCalcSize((struct smb_hdr *)
  609. cifsFile->srch_inf.ntwrk_buf_start);
  610. current_entry = cifsFile->srch_inf.srch_entries_start;
  611. first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry
  612. - cifsFile->srch_inf.entries_in_buffer;
  613. pos_in_buf = index_to_find - first_entry_in_buffer;
  614. cFYI(1,("found entry - pos_in_buf %d",pos_in_buf));
  615. for(i=0;(i<(pos_in_buf)) && (current_entry != NULL);i++) {
  616. /* go entry by entry figuring out which is first */
  617. current_entry = nxt_dir_entry(current_entry,end_of_smb,
  618. cifsFile->srch_inf.info_level);
  619. }
  620. if((current_entry == NULL) && (i < pos_in_buf)) {
  621. /* BB fixme - check if we should flag this error */
  622. cERROR(1,("reached end of buf searching for pos in buf"
  623. " %d index to find %lld rc %d",
  624. pos_in_buf,index_to_find,rc));
  625. }
  626. rc = 0;
  627. *ppCurrentEntry = current_entry;
  628. } else {
  629. cFYI(1,("index not in buffer - could not findnext into it"));
  630. return 0;
  631. }
  632. if(pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
  633. cFYI(1,("can not return entries pos_in_buf beyond last entry"));
  634. *num_to_ret = 0;
  635. } else
  636. *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
  637. return rc;
  638. }
  639. /* inode num, inode type and filename returned */
  640. static int cifs_get_name_from_search_buf(struct qstr *pqst,
  641. char *current_entry, __u16 level, unsigned int unicode,
  642. struct cifs_sb_info * cifs_sb, int max_len, ino_t *pinum)
  643. {
  644. int rc = 0;
  645. unsigned int len = 0;
  646. char * filename;
  647. struct nls_table * nlt = cifs_sb->local_nls;
  648. *pinum = 0;
  649. if(level == SMB_FIND_FILE_UNIX) {
  650. FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
  651. filename = &pFindData->FileName[0];
  652. if(unicode) {
  653. len = cifs_unicode_bytelen(filename);
  654. } else {
  655. /* BB should we make this strnlen of PATH_MAX? */
  656. len = strnlen(filename, PATH_MAX);
  657. }
  658. /* BB fixme - hash low and high 32 bits if not 64 bit arch BB fixme */
  659. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
  660. *pinum = pFindData->UniqueId;
  661. } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
  662. FILE_DIRECTORY_INFO * pFindData =
  663. (FILE_DIRECTORY_INFO *)current_entry;
  664. filename = &pFindData->FileName[0];
  665. len = le32_to_cpu(pFindData->FileNameLength);
  666. } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
  667. FILE_FULL_DIRECTORY_INFO * pFindData =
  668. (FILE_FULL_DIRECTORY_INFO *)current_entry;
  669. filename = &pFindData->FileName[0];
  670. len = le32_to_cpu(pFindData->FileNameLength);
  671. } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
  672. SEARCH_ID_FULL_DIR_INFO * pFindData =
  673. (SEARCH_ID_FULL_DIR_INFO *)current_entry;
  674. filename = &pFindData->FileName[0];
  675. len = le32_to_cpu(pFindData->FileNameLength);
  676. *pinum = pFindData->UniqueId;
  677. } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
  678. FILE_BOTH_DIRECTORY_INFO * pFindData =
  679. (FILE_BOTH_DIRECTORY_INFO *)current_entry;
  680. filename = &pFindData->FileName[0];
  681. len = le32_to_cpu(pFindData->FileNameLength);
  682. } else if(level == SMB_FIND_FILE_INFO_STANDARD) {
  683. FIND_FILE_STANDARD_INFO * pFindData =
  684. (FIND_FILE_STANDARD_INFO *)current_entry;
  685. filename = &pFindData->FileName[0];
  686. /* one byte length, no name conversion */
  687. len = (unsigned int)pFindData->FileNameLength;
  688. } else {
  689. cFYI(1,("Unknown findfirst level %d",level));
  690. return -EINVAL;
  691. }
  692. if(len > max_len) {
  693. cERROR(1,("bad search response length %d past smb end", len));
  694. return -EINVAL;
  695. }
  696. if(unicode) {
  697. /* BB fixme - test with long names */
  698. /* Note converted filename can be longer than in unicode */
  699. if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
  700. pqst->len = cifs_convertUCSpath((char *)pqst->name,
  701. (__le16 *)filename, len/2, nlt);
  702. else
  703. pqst->len = cifs_strfromUCS_le((char *)pqst->name,
  704. (__le16 *)filename,len/2,nlt);
  705. } else {
  706. pqst->name = filename;
  707. pqst->len = len;
  708. }
  709. pqst->hash = full_name_hash(pqst->name,pqst->len);
  710. /* cFYI(1,("filldir on %s",pqst->name)); */
  711. return rc;
  712. }
  713. static int cifs_filldir(char *pfindEntry, struct file *file,
  714. filldir_t filldir, void *direntry, char *scratch_buf, int max_len)
  715. {
  716. int rc = 0;
  717. struct qstr qstring;
  718. struct cifsFileInfo * pCifsF;
  719. unsigned obj_type;
  720. ino_t inum;
  721. struct cifs_sb_info * cifs_sb;
  722. struct inode *tmp_inode;
  723. struct dentry *tmp_dentry;
  724. /* get filename and len into qstring */
  725. /* get dentry */
  726. /* decide whether to create and populate ionde */
  727. if((direntry == NULL) || (file == NULL))
  728. return -EINVAL;
  729. pCifsF = file->private_data;
  730. if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
  731. return -ENOENT;
  732. if(file->f_dentry == NULL)
  733. return -ENOENT;
  734. rc = cifs_entry_is_dot(pfindEntry,pCifsF);
  735. /* skip . and .. since we added them first */
  736. if(rc != 0)
  737. return 0;
  738. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  739. qstring.name = scratch_buf;
  740. rc = cifs_get_name_from_search_buf(&qstring,pfindEntry,
  741. pCifsF->srch_inf.info_level,
  742. pCifsF->srch_inf.unicode,cifs_sb,
  743. max_len,
  744. &inum /* returned */);
  745. if(rc)
  746. return rc;
  747. rc = construct_dentry(&qstring,file,&tmp_inode, &tmp_dentry);
  748. if((tmp_inode == NULL) || (tmp_dentry == NULL))
  749. return -ENOMEM;
  750. if(rc) {
  751. /* inode created, we need to hash it with right inode number */
  752. if(inum != 0) {
  753. /* BB fixme - hash the 2 32 quantities bits together if necessary BB */
  754. tmp_inode->i_ino = inum;
  755. }
  756. insert_inode_hash(tmp_inode);
  757. }
  758. /* we pass in rc below, indicating whether it is a new inode,
  759. so we can figure out whether to invalidate the inode cached
  760. data if the file has changed */
  761. if(pCifsF->srch_inf.info_level == SMB_FIND_FILE_UNIX)
  762. unix_fill_in_inode(tmp_inode,
  763. (FILE_UNIX_INFO *)pfindEntry,
  764. &obj_type, rc);
  765. else if(pCifsF->srch_inf.info_level == SMB_FIND_FILE_INFO_STANDARD)
  766. fill_in_inode(tmp_inode, 0 /* old level 1 buffer type */,
  767. pfindEntry, &obj_type, rc);
  768. else
  769. fill_in_inode(tmp_inode, 1 /* NT */, pfindEntry, &obj_type, rc);
  770. if(rc) /* new inode - needs to be tied to dentry */ {
  771. d_instantiate(tmp_dentry, tmp_inode);
  772. if(rc == 2)
  773. d_rehash(tmp_dentry);
  774. }
  775. rc = filldir(direntry,qstring.name,qstring.len,file->f_pos,
  776. tmp_inode->i_ino,obj_type);
  777. if(rc) {
  778. cFYI(1,("filldir rc = %d",rc));
  779. }
  780. dput(tmp_dentry);
  781. return rc;
  782. }
  783. static int cifs_save_resume_key(const char *current_entry,
  784. struct cifsFileInfo *cifsFile)
  785. {
  786. int rc = 0;
  787. unsigned int len = 0;
  788. __u16 level;
  789. char * filename;
  790. if((cifsFile == NULL) || (current_entry == NULL))
  791. return -EINVAL;
  792. level = cifsFile->srch_inf.info_level;
  793. if(level == SMB_FIND_FILE_UNIX) {
  794. FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
  795. filename = &pFindData->FileName[0];
  796. if(cifsFile->srch_inf.unicode) {
  797. len = cifs_unicode_bytelen(filename);
  798. } else {
  799. /* BB should we make this strnlen of PATH_MAX? */
  800. len = strnlen(filename, PATH_MAX);
  801. }
  802. cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
  803. } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
  804. FILE_DIRECTORY_INFO * pFindData =
  805. (FILE_DIRECTORY_INFO *)current_entry;
  806. filename = &pFindData->FileName[0];
  807. len = le32_to_cpu(pFindData->FileNameLength);
  808. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  809. } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
  810. FILE_FULL_DIRECTORY_INFO * pFindData =
  811. (FILE_FULL_DIRECTORY_INFO *)current_entry;
  812. filename = &pFindData->FileName[0];
  813. len = le32_to_cpu(pFindData->FileNameLength);
  814. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  815. } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
  816. SEARCH_ID_FULL_DIR_INFO * pFindData =
  817. (SEARCH_ID_FULL_DIR_INFO *)current_entry;
  818. filename = &pFindData->FileName[0];
  819. len = le32_to_cpu(pFindData->FileNameLength);
  820. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  821. } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
  822. FILE_BOTH_DIRECTORY_INFO * pFindData =
  823. (FILE_BOTH_DIRECTORY_INFO *)current_entry;
  824. filename = &pFindData->FileName[0];
  825. len = le32_to_cpu(pFindData->FileNameLength);
  826. cifsFile->srch_inf.resume_key = pFindData->FileIndex;
  827. } else if(level == SMB_FIND_FILE_INFO_STANDARD) {
  828. FIND_FILE_STANDARD_INFO * pFindData =
  829. (FIND_FILE_STANDARD_INFO *)current_entry;
  830. filename = &pFindData->FileName[0];
  831. /* one byte length, no name conversion */
  832. len = (unsigned int)pFindData->FileNameLength;
  833. } else {
  834. cFYI(1,("Unknown findfirst level %d",level));
  835. return -EINVAL;
  836. }
  837. cifsFile->srch_inf.resume_name_len = len;
  838. cifsFile->srch_inf.presume_name = filename;
  839. return rc;
  840. }
  841. int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
  842. {
  843. int rc = 0;
  844. int xid,i;
  845. struct cifs_sb_info *cifs_sb;
  846. struct cifsTconInfo *pTcon;
  847. struct cifsFileInfo *cifsFile = NULL;
  848. char * current_entry;
  849. int num_to_fill = 0;
  850. char * tmp_buf = NULL;
  851. char * end_of_smb;
  852. int max_len;
  853. xid = GetXid();
  854. if(file->f_dentry == NULL) {
  855. FreeXid(xid);
  856. return -EIO;
  857. }
  858. cifs_sb = CIFS_SB(file->f_dentry->d_sb);
  859. pTcon = cifs_sb->tcon;
  860. if(pTcon == NULL)
  861. return -EINVAL;
  862. switch ((int) file->f_pos) {
  863. case 0:
  864. if (filldir(direntry, ".", 1, file->f_pos,
  865. file->f_dentry->d_inode->i_ino, DT_DIR) < 0) {
  866. cERROR(1, ("Filldir for current dir failed"));
  867. rc = -ENOMEM;
  868. break;
  869. }
  870. file->f_pos++;
  871. case 1:
  872. if (filldir(direntry, "..", 2, file->f_pos,
  873. file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
  874. cERROR(1, ("Filldir for parent dir failed"));
  875. rc = -ENOMEM;
  876. break;
  877. }
  878. file->f_pos++;
  879. default:
  880. /* 1) If search is active,
  881. is in current search buffer?
  882. if it before then restart search
  883. if after then keep searching till find it */
  884. if(file->private_data == NULL) {
  885. rc = initiate_cifs_search(xid,file);
  886. cFYI(1,("initiate cifs search rc %d",rc));
  887. if(rc) {
  888. FreeXid(xid);
  889. return rc;
  890. }
  891. }
  892. if(file->private_data == NULL) {
  893. rc = -EINVAL;
  894. FreeXid(xid);
  895. return rc;
  896. }
  897. cifsFile = file->private_data;
  898. if (cifsFile->srch_inf.endOfSearch) {
  899. if(cifsFile->srch_inf.emptyDir) {
  900. cFYI(1, ("End of search, empty dir"));
  901. rc = 0;
  902. break;
  903. }
  904. } /* else {
  905. cifsFile->invalidHandle = TRUE;
  906. CIFSFindClose(xid, pTcon, cifsFile->netfid);
  907. }
  908. kfree(cifsFile->search_resume_name);
  909. cifsFile->search_resume_name = NULL; */
  910. rc = find_cifs_entry(xid,pTcon, file,
  911. &current_entry,&num_to_fill);
  912. if(rc) {
  913. cFYI(1,("fce error %d",rc));
  914. goto rddir2_exit;
  915. } else if (current_entry != NULL) {
  916. cFYI(1,("entry %lld found",file->f_pos));
  917. } else {
  918. cFYI(1,("could not find entry"));
  919. goto rddir2_exit;
  920. }
  921. cFYI(1,("loop through %d times filling dir for net buf %p",
  922. num_to_fill,cifsFile->srch_inf.ntwrk_buf_start));
  923. max_len = smbCalcSize((struct smb_hdr *)
  924. cifsFile->srch_inf.ntwrk_buf_start);
  925. end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
  926. /* To be safe - for UCS to UTF-8 with strings loaded
  927. with the rare long characters alloc more to account for
  928. such multibyte target UTF-8 characters. cifs_unicode.c,
  929. which actually does the conversion, has the same limit */
  930. tmp_buf = kmalloc((2 * NAME_MAX) + 4, GFP_KERNEL);
  931. for(i=0;(i<num_to_fill) && (rc == 0);i++) {
  932. if(current_entry == NULL) {
  933. /* evaluate whether this case is an error */
  934. cERROR(1,("past end of SMB num to fill %d i %d",
  935. num_to_fill, i));
  936. break;
  937. }
  938. /* if buggy server returns . and .. late do
  939. we want to check for that here? */
  940. rc = cifs_filldir(current_entry, file,
  941. filldir, direntry, tmp_buf, max_len);
  942. file->f_pos++;
  943. if(file->f_pos ==
  944. cifsFile->srch_inf.index_of_last_entry) {
  945. cFYI(1,("last entry in buf at pos %lld %s",
  946. file->f_pos,tmp_buf));
  947. cifs_save_resume_key(current_entry,cifsFile);
  948. break;
  949. } else
  950. current_entry =
  951. nxt_dir_entry(current_entry, end_of_smb,
  952. cifsFile->srch_inf.info_level);
  953. }
  954. kfree(tmp_buf);
  955. break;
  956. } /* end switch */
  957. rddir2_exit:
  958. FreeXid(xid);
  959. return rc;
  960. }