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