This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / fs / cifs / readdir.c
1 /*
2  *   fs/cifs/readdir.c
3  *
4  *   Directory search handling
5  * 
6  *   Copyright (C) International Business Machines  Corp., 2004
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/stat.h>
25 #include <linux/smp_lock.h>
26 #include "cifspdu.h"
27 #include "cifsglob.h"
28 #include "cifsproto.h"
29 #include "cifs_unicode.h"
30 #include "cifs_debug.h"
31 #include "cifs_fs_sb.h"
32
33 extern int CIFSFindFirst2(const int xid, struct cifsTconInfo *tcon,
34             const char *searchName, const struct nls_table *nls_codepage,
35             __u16 *searchHandle, struct cifs_search_info * psrch_inf);
36
37 extern int CIFSFindNext2(const int xid, struct cifsTconInfo *tcon,
38             __u16 searchHandle, struct cifs_search_info * psrch_inf);
39
40 extern int construct_dentry(struct qstr *qstring, struct file *file,
41                  struct inode **ptmp_inode, struct dentry **pnew_dentry);
42
43 extern void fill_in_inode(struct inode *tmp_inode,
44               FILE_DIRECTORY_INFO * pfindData, int *pobject_type);
45
46 extern void unix_fill_in_inode(struct inode *tmp_inode,
47               FILE_UNIX_INFO * pfindData, int *pobject_type);
48
49
50 /* BB fixme - add debug wrappers around this function to disable it fixme BB */
51 /* static void dump_cifs_file_struct(struct file * file, char * label)
52 {
53         struct cifsFileInfo * cf;
54
55         if(file) {
56                 cf = (struct cifsFileInfo *)file->private_data;
57                 if(cf == NULL) {
58                         cFYI(1,("empty cifs private file data"));
59                         return;
60                 }
61                 if(cf->invalidHandle) {
62                         cFYI(1,("invalid handle"));
63                 }
64                 if(cf->srch_inf.endOfSearch) {
65                         cFYI(1,("end of search"));
66                 }
67                 if(cf->srch_inf.emptyDir) {
68                         cFYI(1,("empty dir"));
69                 }
70                 
71         }
72 } */
73
74 static int initiate_cifs_search(const int xid, struct file * file)
75 {
76         int rc = 0;
77         char * full_path;
78         struct cifsFileInfo * cifsFile;
79         struct cifs_sb_info *cifs_sb;
80         struct cifsTconInfo *pTcon;
81
82         if(file->private_data == NULL) {
83                 file->private_data = 
84                         kmalloc(sizeof(struct cifsFileInfo),GFP_KERNEL);
85         }
86
87         if(file->private_data == NULL) {
88                 return -ENOMEM;
89         } else {
90                 memset(file->private_data,0,sizeof(struct cifsFileInfo));
91         }
92         cifsFile = (struct cifsFileInfo *)file->private_data;
93         cifsFile->invalidHandle = TRUE;
94         cifsFile->srch_inf.endOfSearch = FALSE;
95
96         cifs_sb = CIFS_SB(file->f_dentry->d_sb);
97         if(cifs_sb == NULL)
98                 return -EINVAL;
99
100         pTcon = cifs_sb->tcon;
101         if(pTcon == NULL)
102                 return -EINVAL;
103
104         if(file->f_dentry == NULL)
105                 return -ENOENT;
106
107         down(&file->f_dentry->d_sb->s_vfs_rename_sem);
108         full_path = build_wildcard_path_from_dentry(file->f_dentry);
109         up(&file->f_dentry->d_sb->s_vfs_rename_sem);
110
111         if(full_path == NULL) {
112                 return -ENOMEM;
113         }
114
115         cFYI(1, ("Full path: %s start at: %lld ", full_path, file->f_pos));
116
117         /* test for Unix extensions */
118         if (pTcon->ses->capabilities & CAP_UNIX) {
119                 cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX;
120         } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
121                 cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
122         } else /* not srvinos - BB fixme add check for backlevel? */ {
123                 cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
124         }
125
126         rc = CIFSFindFirst2(xid, pTcon,full_path,cifs_sb->local_nls, 
127                 &cifsFile->netfid, &cifsFile->srch_inf); 
128         if(rc == 0)
129                 cifsFile->invalidHandle = FALSE;
130         if(full_path)
131                 kfree(full_path);
132         return rc;
133 }
134
135 /* return length of unicode string in bytes */
136 static int cifs_unicode_bytelen(char * str)
137 {
138         int len;
139         __le16 * ustr = (__le16 *)str;
140
141         for(len=0;len <= PATH_MAX;len++) {
142                 if(ustr[len] == 0)
143                         return len << 1;
144         }
145         cFYI(1,("Unicode string longer than PATH_MAX found"));
146         return len << 1;
147 }
148
149 static char * nxt_dir_entry(char * old_entry, char * end_of_smb)
150 {
151         char * new_entry;
152         FILE_DIRECTORY_INFO * pDirInfo = (FILE_DIRECTORY_INFO *)old_entry;
153
154         new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset);
155         cFYI(1,("new entry %p old entry %p",new_entry,old_entry));
156         /* validate that new_entry is not past end of SMB */
157         if(new_entry >= end_of_smb) {
158                 cFYI(1,("search entry %p began after end of SMB %p old entry %p",
159                         new_entry,end_of_smb,old_entry)); 
160                 return NULL;
161         } else
162                 return new_entry;
163
164 }
165
166 #define UNICODE_DOT cpu_to_le16(0x2e)
167
168 /* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */
169 static int cifs_entry_is_dot(char * current_entry, struct cifsFileInfo * cfile)
170 {
171         int rc = 0;
172         char * filename = NULL;
173         int len = 0; 
174
175         if(cfile->srch_inf.info_level == 0x202) {
176                 FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
177                 filename = &pFindData->FileName[0];
178                 if(cfile->srch_inf.unicode) {
179                         len = cifs_unicode_bytelen(filename);
180                 } else {
181                         /* BB should we make this strnlen of PATH_MAX? */
182                         len = strnlen(filename, 5);
183                 }
184         } else if(cfile->srch_inf.info_level == 0x101) {
185                 FILE_DIRECTORY_INFO * pFindData = 
186                         (FILE_DIRECTORY_INFO *)current_entry;
187                 filename = &pFindData->FileName[0];
188                 len = le32_to_cpu(pFindData->FileNameLength);
189         } else if(cfile->srch_inf.info_level == 0x102) {
190                 FILE_FULL_DIRECTORY_INFO * pFindData = 
191                         (FILE_FULL_DIRECTORY_INFO *)current_entry;
192                 filename = &pFindData->FileName[0];
193                 len = le32_to_cpu(pFindData->FileNameLength);
194         } else if(cfile->srch_inf.info_level == 0x105) {
195                 SEARCH_ID_FULL_DIR_INFO * pFindData = 
196                         (SEARCH_ID_FULL_DIR_INFO *)current_entry;
197                 filename = &pFindData->FileName[0];
198                 len = le32_to_cpu(pFindData->FileNameLength);
199         } else if(cfile->srch_inf.info_level == 0x104) {
200                 FILE_BOTH_DIRECTORY_INFO * pFindData = 
201                         (FILE_BOTH_DIRECTORY_INFO *)current_entry;
202                 filename = &pFindData->FileName[0];
203                 len = le32_to_cpu(pFindData->FileNameLength);
204         } else {
205                 cFYI(1,("Unknown findfirst level %d",cfile->srch_inf.info_level));
206         }
207
208         if(filename) {
209                 if(cfile->srch_inf.unicode) {
210                         __le16 *ufilename = (__le16 *)filename;
211                         if(len == 2) {
212                                 /* check for . */
213                                 if(ufilename[0] == UNICODE_DOT)
214                                         rc = 1;
215                         } else if(len == 4) {
216                                 /* check for .. */
217                                 if((ufilename[0] == UNICODE_DOT)
218                                    &&(ufilename[1] == UNICODE_DOT))
219                                         rc = 2;
220                         }
221                 } else /* ASCII */ {
222                         if(len == 1) {
223                                 if(filename[0] == '.') 
224                                         rc = 1;
225                         } else if(len == 2) {
226                                 if((filename[0] == '.') && (filename[1] == '.')) 
227                                         rc = 2;
228                         }
229                 }
230         }
231
232         return rc;
233 }
234
235 /* find the corresponding entry in the search */
236 /* Note that the SMB server returns search entries for . and .. which
237    complicates logic here if we choose to parse for them and we do not
238    assume that they are located in the findfirst return buffer.*/
239 /* We start counting in the buffer with entry 2 and increment for every
240    entry (do not increment for . or .. entry) */
241 static int find_cifs_entry(const int xid, struct cifsTconInfo * pTcon, 
242                 struct file * file, char ** ppCurrentEntry,int * num_to_ret) 
243 {
244         int rc = 0;
245         int pos_in_buf = 0;
246         loff_t first_entry_in_buffer;
247         loff_t index_to_find = file->f_pos;
248         struct cifsFileInfo * cifsFile = (struct cifsFileInfo *)file->private_data;
249         /* check if index in the buffer */
250         
251         if((cifsFile == NULL) || (ppCurrentEntry == NULL) || (num_to_ret == NULL))
252                 return -ENOENT;
253         
254         *ppCurrentEntry = NULL;
255         first_entry_in_buffer = 
256                 cifsFile->srch_inf.index_of_last_entry - 
257                         cifsFile->srch_inf.entries_in_buffer;
258 /*      dump_cifs_file_struct(file, "In fce ");*/
259         if(index_to_find < first_entry_in_buffer) {
260                 /* close and restart search */
261                 cFYI(1,("search backing up - close and restart search"));
262                 cifsFile->invalidHandle = TRUE;
263                 CIFSFindClose(xid, pTcon, cifsFile->netfid);
264                 if(cifsFile->search_resume_name) {
265                         kfree(cifsFile->search_resume_name);
266                         cifsFile->search_resume_name = NULL;
267                 }
268                 if(cifsFile->srch_inf.ntwrk_buf_start) {
269                         cFYI(1,("freeing SMB ff cache buf on search rewind")); 
270                         cifs_buf_release(cifsFile->srch_inf.ntwrk_buf_start);
271                 }
272                 rc = initiate_cifs_search(xid,file);
273                 if(rc) {
274                         cFYI(1,("error %d reinitiating a search on rewind",rc));
275                         return rc;
276                 }
277         }
278
279         while((index_to_find >= cifsFile->srch_inf.index_of_last_entry) && 
280               (rc == 0) && (cifsFile->srch_inf.endOfSearch == FALSE)){
281                 cFYI(1,("calling findnext2"));
282                 rc = CIFSFindNext2(xid,pTcon,cifsFile->netfid, &cifsFile->srch_inf);
283                 if(rc)
284                         return -ENOENT;
285         }
286         if(index_to_find < cifsFile->srch_inf.index_of_last_entry) {
287                 /* we found the buffer that contains the entry */
288                 /* scan and find it */
289                 int i;
290                 char * current_entry;
291                 char * end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + 
292                         smbCalcSize((struct smb_hdr *)cifsFile->srch_inf.ntwrk_buf_start);
293 /*      dump_cifs_file_struct(file,"found entry in fce "); */
294                 first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry -
295                         cifsFile->srch_inf.entries_in_buffer;
296                 pos_in_buf = index_to_find - first_entry_in_buffer;
297                 cFYI(1,("found entry - pos_in_buf %d",pos_in_buf)); 
298                 current_entry = cifsFile->srch_inf.srch_entries_start;
299                 for(i=0;(i<(pos_in_buf)) && (current_entry != NULL);i++) {
300                         /* go entry to next entry figuring out which we need to start with */
301                         /* if( . or ..)
302                                 skip */
303                         rc = cifs_entry_is_dot(current_entry,cifsFile);
304                         if(rc == 1) /* is . or .. so skip */ {
305                                 cFYI(1,("Entry is .")); /* BB removeme BB */
306                                 /* continue; */
307                         } else if (rc == 2 ) {
308                                 cFYI(1,("Entry is ..")); /* BB removeme BB */
309                                 /* continue; */
310                         }
311                         current_entry = nxt_dir_entry(current_entry,end_of_smb);
312                 }
313                 if((current_entry == NULL) && (i < pos_in_buf)) {
314                         cERROR(1,("reached end of buf searching for pos in buf %d index to find %lld rc %d",pos_in_buf,index_to_find,rc)); /* BB removeme BB */
315                 }
316                 rc = 0;
317                 *ppCurrentEntry = current_entry;
318         } else {
319                 cFYI(1,("index not in buffer - could not findnext into it"));
320                 return 0;
321         }
322
323         if(pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
324                 cFYI(1,("can not return entries when pos_in_buf beyond last entry"));
325                 *num_to_ret = 0;
326         } else
327                 *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
328 /*      dump_cifs_file_struct(file, "end fce ");*/
329
330         return rc;
331 }
332
333 /* inode num, inode type and filename returned */
334 static int cifs_get_name_from_search_buf(struct qstr * pqst,char * current_entry,
335                         __u16 level,unsigned int unicode,struct nls_table * nlt,
336                         ino_t * pinum)
337 {
338         int rc = 0;
339         unsigned int len = 0;
340         char * filename;
341
342         *pinum = 0;
343
344         if(level == SMB_FIND_FILE_UNIX) {
345                 FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
346
347                 filename = &pFindData->FileName[0];
348                 if(unicode) {
349                         len = cifs_unicode_bytelen(filename);
350                 } else {
351                         /* BB should we make this strnlen of PATH_MAX? */
352                         len = strnlen(filename, PATH_MAX);
353                 }
354
355                 /* BB fixme - hash low and high 32 bits if not 64 bit arch BB fixme */
356                 *pinum = pFindData->UniqueId;
357         } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
358                 FILE_DIRECTORY_INFO * pFindData = 
359                         (FILE_DIRECTORY_INFO *)current_entry;
360                 filename = &pFindData->FileName[0];
361                 len = le32_to_cpu(pFindData->FileNameLength);
362         } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
363                 FILE_FULL_DIRECTORY_INFO * pFindData = 
364                         (FILE_FULL_DIRECTORY_INFO *)current_entry;
365                 filename = &pFindData->FileName[0];
366                 len = le32_to_cpu(pFindData->FileNameLength);
367         } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
368                 SEARCH_ID_FULL_DIR_INFO * pFindData = 
369                         (SEARCH_ID_FULL_DIR_INFO *)current_entry;
370                 filename = &pFindData->FileName[0];
371                 len = le32_to_cpu(pFindData->FileNameLength);
372                 *pinum = pFindData->UniqueId;
373         } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
374                 FILE_BOTH_DIRECTORY_INFO * pFindData = 
375                         (FILE_BOTH_DIRECTORY_INFO *)current_entry;
376                 filename = &pFindData->FileName[0];
377                 len = le32_to_cpu(pFindData->FileNameLength);
378         } else {
379                 cFYI(1,("Unknown findfirst level %d",level));
380                 return -EINVAL;
381         }
382         if(unicode) {
383                 /* BB fixme - test with long names */
384                 /* Note converted filename can be longer than in unicode */
385                 pqst->len = cifs_strfromUCS_le((char *)pqst->name,(wchar_t *)filename,len/2,nlt);
386         } else {
387                 pqst->name = filename;
388                 pqst->len = len;
389         }
390         pqst->hash = full_name_hash(pqst->name,pqst->len);
391 /*      cFYI(1,("filldir on %s",pqst->name));  */
392         return rc;
393 }
394
395
396 static int
397 cifs_filldir2(char * pfindEntry, struct file *file, 
398                           filldir_t filldir, void *direntry,char * scratch_buf)
399 {
400         int rc = 0;
401         struct qstr qstring;
402         struct cifsFileInfo * pCifsF;
403         unsigned obj_type;
404         ino_t  inum;
405         struct cifs_sb_info * cifs_sb;
406         struct inode *tmp_inode;
407         struct dentry *tmp_dentry;
408
409         /* get filename and len into qstring */
410         /* get dentry */
411         /* decide whether to create and populate ionde */
412         if((direntry == NULL) || (file == NULL))
413                 return -EINVAL;
414
415         pCifsF = file->private_data;
416         
417         if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
418                 return -ENOENT;
419
420         if(file->f_dentry == NULL)
421                 return -ENOENT;
422
423         cifs_sb = CIFS_SB(file->f_dentry->d_sb);
424
425         qstring.name = scratch_buf;
426         rc = cifs_get_name_from_search_buf(&qstring,pfindEntry,
427                         pCifsF->srch_inf.info_level,
428                         pCifsF->srch_inf.unicode,cifs_sb->local_nls,
429                         &inum /* returned */);
430
431         if(rc)
432                 return rc;
433
434         rc = construct_dentry(&qstring,file,&tmp_inode, &tmp_dentry);
435         if((tmp_inode == NULL) || (tmp_dentry == NULL))
436                 return -ENOMEM;
437
438         if(rc) {
439                 /* inode created, we need to hash it with right inode number */
440                 if(inum != 0) {
441                         /* BB fixme - hash the 2 32 quantities bits together if necessary BB */
442                         tmp_inode->i_ino = inum;
443                 }
444                 insert_inode_hash(tmp_inode);
445         }
446
447         if(pCifsF->srch_inf.info_level == SMB_FIND_FILE_UNIX) {
448                 unix_fill_in_inode(tmp_inode,(FILE_UNIX_INFO *)pfindEntry,&obj_type);
449         } else {
450                 fill_in_inode(tmp_inode,(FILE_DIRECTORY_INFO *)pfindEntry,&obj_type);
451         }
452         
453         rc = filldir(direntry,qstring.name,qstring.len,file->f_pos,tmp_inode->i_ino,obj_type);
454         if(rc) {
455                 cFYI(1,("filldir rc = %d",rc));
456         }
457
458         dput(tmp_dentry);
459         return rc;
460 }
461
462 int cifs_save_resume_key(const char * current_entry,struct cifsFileInfo * cifsFile)
463 {
464         int rc = 0;
465         unsigned int len = 0;
466         __u16 level;
467         char * filename;
468
469         if((cifsFile == NULL) || (current_entry == NULL))
470                 return -EINVAL;
471
472         level = cifsFile->srch_inf.info_level;
473
474         if(level == SMB_FIND_FILE_UNIX) {
475                 FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
476
477                 filename = &pFindData->FileName[0];
478                 if(cifsFile->srch_inf.unicode) {
479                         len = cifs_unicode_bytelen(filename);
480                 } else {
481                         /* BB should we make this strnlen of PATH_MAX? */
482                         len = strnlen(filename, PATH_MAX);
483                 }
484                 cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
485         } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
486                 FILE_DIRECTORY_INFO * pFindData = 
487                         (FILE_DIRECTORY_INFO *)current_entry;
488                 filename = &pFindData->FileName[0];
489                 len = le32_to_cpu(pFindData->FileNameLength);
490                 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
491         } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
492                 FILE_FULL_DIRECTORY_INFO * pFindData = 
493                         (FILE_FULL_DIRECTORY_INFO *)current_entry;
494                 filename = &pFindData->FileName[0];
495                 len = le32_to_cpu(pFindData->FileNameLength);
496                 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
497         } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
498                 SEARCH_ID_FULL_DIR_INFO * pFindData = 
499                         (SEARCH_ID_FULL_DIR_INFO *)current_entry;
500                 filename = &pFindData->FileName[0];
501                 len = le32_to_cpu(pFindData->FileNameLength);
502                 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
503         } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
504                 FILE_BOTH_DIRECTORY_INFO * pFindData = 
505                         (FILE_BOTH_DIRECTORY_INFO *)current_entry;
506                 filename = &pFindData->FileName[0];
507                 len = le32_to_cpu(pFindData->FileNameLength);
508                 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
509         } else {
510                 cFYI(1,("Unknown findfirst level %d",level));
511                 return -EINVAL;
512         }
513         cifsFile->srch_inf.resume_name_len = len;
514         cifsFile->srch_inf.presume_name = filename;
515         return rc;
516 }
517
518 int cifs_readdir2(struct file *file, void *direntry, filldir_t filldir)
519 {
520         int rc = 0;
521         int xid,i;
522         struct cifs_sb_info *cifs_sb;
523         struct cifsTconInfo *pTcon;
524         struct cifsFileInfo *cifsFile = NULL;
525         char * current_entry;
526         int num_to_fill = 0;
527         char * tmp_buf = NULL;
528         char * end_of_smb;
529
530         xid = GetXid();
531
532         if(file->f_dentry == NULL) {
533                 FreeXid(xid);
534                 return -EIO;
535         }
536 /*      dump_cifs_file_struct(file, "Begin rdir "); */
537
538         cifs_sb = CIFS_SB(file->f_dentry->d_sb);
539         pTcon = cifs_sb->tcon;
540         if(pTcon == NULL)
541                 return -EINVAL;
542
543 /*      cFYI(1,("readdir2 pos: %lld",file->f_pos)); */
544
545         switch ((int) file->f_pos) {
546         case 0:
547                 /*if (filldir(direntry, ".", 1, file->f_pos,
548                      file->f_dentry->d_inode->i_ino, DT_DIR) < 0) {
549                         cERROR(1, ("Filldir for current dir failed "));
550                         rc = -ENOMEM;
551                         break;
552                 }
553                 file->f_pos++; */
554         case 1:
555                 /* if (filldir(direntry, "..", 2, file->f_pos,
556                      file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
557                         cERROR(1, ("Filldir for parent dir failed "));
558                         rc = -ENOMEM;
559                         break;
560                 }
561                 file->f_pos++; */
562         case 2:
563                 /* 1) If search is active, 
564                         is in current search buffer? 
565                         if it before then restart search
566                         if after then keep searching till find it */
567
568                 if(file->private_data == NULL) {
569                         rc = initiate_cifs_search(xid,file);
570                         cFYI(1,("initiate cifs search rc %d",rc));
571                         if(rc) {
572                                 FreeXid(xid);
573                                 return rc;
574                         }
575                 }
576         default:
577                 if(file->private_data == NULL) {
578                         rc = -EINVAL;
579                         FreeXid(xid);
580                         return rc;
581                 }
582                 cifsFile = (struct cifsFileInfo *) file->private_data;
583                 if (cifsFile->srch_inf.endOfSearch) {
584                         if(cifsFile->srch_inf.emptyDir) {
585                                 cFYI(1, ("End of search, empty dir"));
586                                 rc = 0;
587                                 break;
588                         }
589                 } /* else {
590                         cifsFile->invalidHandle = TRUE;
591                         CIFSFindClose(xid, pTcon, cifsFile->netfid);
592                 } 
593                 if(cifsFile->search_resume_name) {
594                         kfree(cifsFile->search_resume_name);
595                         cifsFile->search_resume_name = NULL;
596                 } */
597 /* BB account for . and .. in f_pos */
598                 /* dump_cifs_file_struct(file, "rdir after default ");*/
599
600                 rc = find_cifs_entry(xid,pTcon, file,
601                                 &current_entry,&num_to_fill);
602                 if(rc) {
603                         cFYI(1,("fce error %d",rc)); 
604                         goto rddir2_exit;
605                 } else if (current_entry != NULL) {
606                         cFYI(1,("entry %lld found",file->f_pos));
607                 } else {
608                         cFYI(1,("could not find entry"));
609                         goto rddir2_exit;
610                 }
611                 cFYI(1,("loop through %d times filling dir for net buf %p",
612                         num_to_fill,cifsFile->srch_inf.ntwrk_buf_start)); 
613                 end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + 
614                         smbCalcSize((struct smb_hdr *)cifsFile->srch_inf.ntwrk_buf_start);
615                 tmp_buf = kmalloc(NAME_MAX+1,GFP_KERNEL);
616                 for(i=0;(i<num_to_fill) && (rc == 0);i++) {
617                         if(current_entry == NULL) {
618                                 cERROR(1,("beyond end of smb with num to fill %d i %d",num_to_fill,i)); /* BB removeme BB */
619                                 break;
620                         }
621 /*                      if((!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) || 
622                            (cifsFile->srch_inf.info_level != something that supports server inodes)) {
623                                 create dentry
624                                 create inode
625                                 fill in inode new_inode (which makes number locally)
626                         }
627                         also create local inode for per reasons unless new mount parm says otherwise */
628                         rc = cifs_filldir2(current_entry, file, 
629                                         filldir, direntry,tmp_buf);
630                         file->f_pos++;
631                         if(file->f_pos == cifsFile->srch_inf.index_of_last_entry) {
632                                 cFYI(1,("last entry in buf at pos %lld %s",file->f_pos,tmp_buf)); /* BB removeme BB */
633                                 cifs_save_resume_key(current_entry,cifsFile);
634                                 break;
635                         } else 
636                                 current_entry = nxt_dir_entry(current_entry,end_of_smb);
637                 }
638                 if(tmp_buf != NULL)
639                         kfree(tmp_buf);
640                 break;
641         } /* end switch */
642
643 rddir2_exit:
644         /* dump_cifs_file_struct(file, "end rdir ");  */
645         FreeXid(xid);
646         return rc;
647 }
648