readdir.c 33 KB

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