readdir.c 33 KB

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