4 * Directory search handling
6 * Copyright (C) International Business Machines Corp., 2004
7 * Author(s): Steve French (sfrench@us.ibm.com)
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.
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.
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
24 #include <linux/stat.h>
25 #include <linux/smp_lock.h>
28 #include "cifsproto.h"
29 #include "cifs_unicode.h"
30 #include "cifs_debug.h"
31 #include "cifs_fs_sb.h"
34 /* BB fixme - add debug wrappers around this function to disable it fixme BB */
35 /* static void dump_cifs_file_struct(struct file *file, char *label)
37 struct cifsFileInfo * cf;
40 cf = file->private_data;
42 cFYI(1,("empty cifs private file data"));
45 if(cf->invalidHandle) {
46 cFYI(1,("invalid handle"));
48 if(cf->srch_inf.endOfSearch) {
49 cFYI(1,("end of search"));
51 if(cf->srch_inf.emptyDir) {
52 cFYI(1,("empty dir"));
58 /* Returns one if new inode created (which therefore needs to be hashed) */
59 /* Might check in the future if inode number changed so we can rehash inode */
60 static int construct_dentry(struct qstr *qstring, struct file *file,
61 struct inode **ptmp_inode, struct dentry **pnew_dentry)
63 struct dentry *tmp_dentry;
64 struct cifs_sb_info *cifs_sb;
65 struct cifsTconInfo *pTcon;
68 cFYI(1, ("For %s ", qstring->name));
69 cifs_sb = CIFS_SB(file->f_dentry->d_sb);
70 pTcon = cifs_sb->tcon;
72 qstring->hash = full_name_hash(qstring->name, qstring->len);
73 tmp_dentry = d_lookup(file->f_dentry, qstring);
75 cFYI(0, (" existing dentry with inode 0x%p", tmp_dentry->d_inode));
76 *ptmp_inode = tmp_dentry->d_inode;
77 /* BB overwrite old name? i.e. tmp_dentry->d_name and tmp_dentry->d_name.len??*/
78 if(*ptmp_inode == NULL) {
79 *ptmp_inode = new_inode(file->f_dentry->d_sb);
80 if(*ptmp_inode == NULL)
83 d_instantiate(tmp_dentry, *ptmp_inode);
86 tmp_dentry = d_alloc(file->f_dentry, qstring);
87 if(tmp_dentry == NULL) {
88 cERROR(1,("Failed allocating dentry"));
93 *ptmp_inode = new_inode(file->f_dentry->d_sb);
94 tmp_dentry->d_op = &cifs_dentry_ops;
95 if(*ptmp_inode == NULL)
98 d_instantiate(tmp_dentry, *ptmp_inode);
102 tmp_dentry->d_time = jiffies;
103 *pnew_dentry = tmp_dentry;
107 static void fill_in_inode(struct inode *tmp_inode,
108 FILE_DIRECTORY_INFO *pfindData, int *pobject_type)
110 struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
111 struct cifs_sb_info *cifs_sb = CIFS_SB(tmp_inode->i_sb);
112 __u32 attr = le32_to_cpu(pfindData->ExtFileAttributes);
113 __u64 allocation_size = le64_to_cpu(pfindData->AllocationSize);
114 __u64 end_of_file = le64_to_cpu(pfindData->EndOfFile);
116 cifsInfo->cifsAttrs = attr;
117 cifsInfo->time = jiffies;
119 /* Linux can not store file creation time unfortunately so ignore it */
121 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime));
123 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime));
125 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
126 /* treat dos attribute of read-only as read-only mode bit e.g. 555? */
127 /* 2767 perms - indicate mandatory locking */
128 /* BB fill in uid and gid here? with help from winbind?
129 or retrieve from NTFS stream extended attribute */
130 if (atomic_read(&cifsInfo->inUse) == 0) {
131 tmp_inode->i_uid = cifs_sb->mnt_uid;
132 tmp_inode->i_gid = cifs_sb->mnt_gid;
133 /* set default mode. will override for dirs below */
134 tmp_inode->i_mode = cifs_sb->mnt_file_mode;
137 cFYI(0,("CIFS FFIRST: Attributes came in as 0x%x",attr));
138 if (attr & ATTR_DIRECTORY) {
139 *pobject_type = DT_DIR;
140 /* override default perms since we do not lock dirs */
141 if(atomic_read(&cifsInfo->inUse) == 0) {
142 tmp_inode->i_mode = cifs_sb->mnt_dir_mode;
144 tmp_inode->i_mode |= S_IFDIR;
145 /* we no longer mark these because we could not follow them */
146 /* } else if (attr & ATTR_REPARSE) {
147 *pobject_type = DT_LNK;
148 tmp_inode->i_mode |= S_IFLNK; */
150 *pobject_type = DT_REG;
151 tmp_inode->i_mode |= S_IFREG;
152 if (attr & ATTR_READONLY)
153 tmp_inode->i_mode &= ~(S_IWUGO);
154 } /* could add code here - to validate if device or weird share type? */
156 /* can not fill in nlink here as in qpathinfo version and Unx search */
157 if (atomic_read(&cifsInfo->inUse) == 0) {
158 atomic_set(&cifsInfo->inUse, 1);
161 if (is_size_safe_to_change(cifsInfo)) {
162 /* can not safely change the file size here if the
163 client is writing to it due to potential races */
164 i_size_write(tmp_inode, end_of_file);
166 /* 512 bytes (2**9) is the fake blocksize that must be used */
167 /* for this calculation, even though the reported blocksize is larger */
168 tmp_inode->i_blocks = (512 - 1 + allocation_size) >> 9;
171 if (allocation_size < end_of_file)
172 cFYI(1, ("May be sparse file, allocation less than file size"));
174 ("File Size %ld and blocks %ld and blocksize %ld",
175 (unsigned long)tmp_inode->i_size, tmp_inode->i_blocks,
176 tmp_inode->i_blksize));
177 if (S_ISREG(tmp_inode->i_mode)) {
178 cFYI(1, (" File inode "));
179 tmp_inode->i_op = &cifs_file_inode_ops;
180 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
181 tmp_inode->i_fop = &cifs_file_direct_ops;
183 tmp_inode->i_fop = &cifs_file_ops;
184 tmp_inode->i_data.a_ops = &cifs_addr_ops;
185 } else if (S_ISDIR(tmp_inode->i_mode)) {
186 cFYI(1, (" Directory inode"));
187 tmp_inode->i_op = &cifs_dir_inode_ops;
188 tmp_inode->i_fop = &cifs_dir_ops;
189 } else if (S_ISLNK(tmp_inode->i_mode)) {
190 cFYI(1, (" Symbolic Link inode "));
191 tmp_inode->i_op = &cifs_symlink_inode_ops;
193 cFYI(1, (" Init special inode "));
194 init_special_inode(tmp_inode, tmp_inode->i_mode,
199 static void unix_fill_in_inode(struct inode *tmp_inode,
200 FILE_UNIX_INFO *pfindData, int *pobject_type)
202 struct cifsInodeInfo *cifsInfo = CIFS_I(tmp_inode);
203 struct cifs_sb_info *cifs_sb = CIFS_SB(tmp_inode->i_sb);
205 __u32 type = le32_to_cpu(pfindData->Type);
206 __u64 num_of_bytes = le64_to_cpu(pfindData->NumOfBytes);
207 __u64 end_of_file = le64_to_cpu(pfindData->EndOfFile);
208 cifsInfo->time = jiffies;
209 atomic_inc(&cifsInfo->inUse);
212 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime));
214 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastModificationTime));
216 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastStatusChange));
218 tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
219 if (type == UNIX_FILE) {
220 *pobject_type = DT_REG;
221 tmp_inode->i_mode |= S_IFREG;
222 } else if (type == UNIX_SYMLINK) {
223 *pobject_type = DT_LNK;
224 tmp_inode->i_mode |= S_IFLNK;
225 } else if (type == UNIX_DIR) {
226 *pobject_type = DT_DIR;
227 tmp_inode->i_mode |= S_IFDIR;
228 } else if (type == UNIX_CHARDEV) {
229 *pobject_type = DT_CHR;
230 tmp_inode->i_mode |= S_IFCHR;
231 tmp_inode->i_rdev = MKDEV(le64_to_cpu(pfindData->DevMajor),
232 le64_to_cpu(pfindData->DevMinor) & MINORMASK);
233 } else if (type == UNIX_BLOCKDEV) {
234 *pobject_type = DT_BLK;
235 tmp_inode->i_mode |= S_IFBLK;
236 tmp_inode->i_rdev = MKDEV(le64_to_cpu(pfindData->DevMajor),
237 le64_to_cpu(pfindData->DevMinor) & MINORMASK);
238 } else if (type == UNIX_FIFO) {
239 *pobject_type = DT_FIFO;
240 tmp_inode->i_mode |= S_IFIFO;
241 } else if (type == UNIX_SOCKET) {
242 *pobject_type = DT_SOCK;
243 tmp_inode->i_mode |= S_IFSOCK;
246 tmp_inode->i_uid = le64_to_cpu(pfindData->Uid);
247 tmp_inode->i_gid = le64_to_cpu(pfindData->Gid);
248 tmp_inode->i_nlink = le64_to_cpu(pfindData->Nlinks);
250 if (is_size_safe_to_change(cifsInfo)) {
251 /* can not safely change the file size here if the
252 client is writing to it due to potential races */
253 i_size_write(tmp_inode,end_of_file);
255 /* 512 bytes (2**9) is the fake blocksize that must be used */
256 /* for this calculation, not the real blocksize */
257 tmp_inode->i_blocks = (512 - 1 + num_of_bytes) >> 9;
260 if (S_ISREG(tmp_inode->i_mode)) {
261 cFYI(1, ("File inode"));
262 tmp_inode->i_op = &cifs_file_inode_ops;
263 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
264 tmp_inode->i_fop = &cifs_file_direct_ops;
266 tmp_inode->i_fop = &cifs_file_ops;
267 tmp_inode->i_data.a_ops = &cifs_addr_ops;
268 } else if (S_ISDIR(tmp_inode->i_mode)) {
269 cFYI(1, ("Directory inode"));
270 tmp_inode->i_op = &cifs_dir_inode_ops;
271 tmp_inode->i_fop = &cifs_dir_ops;
272 } else if (S_ISLNK(tmp_inode->i_mode)) {
273 cFYI(1, ("Symbolic Link inode"));
274 tmp_inode->i_op = &cifs_symlink_inode_ops;
275 /* tmp_inode->i_fop = *//* do not need to set to anything */
277 cFYI(1, ("Special inode"));
278 init_special_inode(tmp_inode, tmp_inode->i_mode,
283 static int initiate_cifs_search(const int xid, struct file *file)
287 struct cifsFileInfo * cifsFile;
288 struct cifs_sb_info *cifs_sb;
289 struct cifsTconInfo *pTcon;
291 if(file->private_data == NULL) {
293 kmalloc(sizeof(struct cifsFileInfo),GFP_KERNEL);
296 if(file->private_data == NULL) {
299 memset(file->private_data,0,sizeof(struct cifsFileInfo));
301 cifsFile = file->private_data;
302 cifsFile->invalidHandle = TRUE;
303 cifsFile->srch_inf.endOfSearch = FALSE;
305 if(file->f_dentry == NULL)
308 cifs_sb = CIFS_SB(file->f_dentry->d_sb);
312 pTcon = cifs_sb->tcon;
316 down(&file->f_dentry->d_sb->s_vfs_rename_sem);
317 full_path = build_wildcard_path_from_dentry(file->f_dentry);
318 up(&file->f_dentry->d_sb->s_vfs_rename_sem);
320 if(full_path == NULL) {
324 cFYI(1, ("Full path: %s start at: %lld ", full_path, file->f_pos));
326 /* test for Unix extensions */
327 if (pTcon->ses->capabilities & CAP_UNIX) {
328 cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX;
329 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
330 cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
331 } else /* not srvinos - BB fixme add check for backlevel? */ {
332 cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
335 rc = CIFSFindFirst(xid, pTcon,full_path,cifs_sb->local_nls,
336 &cifsFile->netfid, &cifsFile->srch_inf);
338 cifsFile->invalidHandle = FALSE;
343 /* return length of unicode string in bytes */
344 static int cifs_unicode_bytelen(char *str)
347 __le16 * ustr = (__le16 *)str;
349 for(len=0;len <= PATH_MAX;len++) {
353 cFYI(1,("Unicode string longer than PATH_MAX found"));
357 static char *nxt_dir_entry(char *old_entry, char *end_of_smb)
360 FILE_DIRECTORY_INFO * pDirInfo = (FILE_DIRECTORY_INFO *)old_entry;
362 new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset);
363 cFYI(1,("new entry %p old entry %p",new_entry,old_entry));
364 /* validate that new_entry is not past end of SMB */
365 if(new_entry >= end_of_smb) {
366 cFYI(1,("search entry %p began after end of SMB %p old entry %p",
367 new_entry,end_of_smb,old_entry));
374 #define UNICODE_DOT cpu_to_le16(0x2e)
376 /* return 0 if no match and 1 for . (current directory) and 2 for .. (parent) */
377 static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile)
380 char * filename = NULL;
383 if(cfile->srch_inf.info_level == 0x202) {
384 FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
385 filename = &pFindData->FileName[0];
386 if(cfile->srch_inf.unicode) {
387 len = cifs_unicode_bytelen(filename);
389 /* BB should we make this strnlen of PATH_MAX? */
390 len = strnlen(filename, 5);
392 } else if(cfile->srch_inf.info_level == 0x101) {
393 FILE_DIRECTORY_INFO * pFindData =
394 (FILE_DIRECTORY_INFO *)current_entry;
395 filename = &pFindData->FileName[0];
396 len = le32_to_cpu(pFindData->FileNameLength);
397 } else if(cfile->srch_inf.info_level == 0x102) {
398 FILE_FULL_DIRECTORY_INFO * pFindData =
399 (FILE_FULL_DIRECTORY_INFO *)current_entry;
400 filename = &pFindData->FileName[0];
401 len = le32_to_cpu(pFindData->FileNameLength);
402 } else if(cfile->srch_inf.info_level == 0x105) {
403 SEARCH_ID_FULL_DIR_INFO * pFindData =
404 (SEARCH_ID_FULL_DIR_INFO *)current_entry;
405 filename = &pFindData->FileName[0];
406 len = le32_to_cpu(pFindData->FileNameLength);
407 } else if(cfile->srch_inf.info_level == 0x104) {
408 FILE_BOTH_DIRECTORY_INFO * pFindData =
409 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
410 filename = &pFindData->FileName[0];
411 len = le32_to_cpu(pFindData->FileNameLength);
413 cFYI(1,("Unknown findfirst level %d",cfile->srch_inf.info_level));
417 if(cfile->srch_inf.unicode) {
418 __le16 *ufilename = (__le16 *)filename;
421 if(ufilename[0] == UNICODE_DOT)
423 } else if(len == 4) {
425 if((ufilename[0] == UNICODE_DOT)
426 &&(ufilename[1] == UNICODE_DOT))
431 if(filename[0] == '.')
433 } else if(len == 2) {
434 if((filename[0] == '.') && (filename[1] == '.'))
443 /* find the corresponding entry in the search */
444 /* Note that the SMB server returns search entries for . and .. which
445 complicates logic here if we choose to parse for them and we do not
446 assume that they are located in the findfirst return buffer.*/
447 /* We start counting in the buffer with entry 2 and increment for every
448 entry (do not increment for . or .. entry) */
449 static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
450 struct file *file, char **ppCurrentEntry, int *num_to_ret)
454 loff_t first_entry_in_buffer;
455 loff_t index_to_find = file->f_pos;
456 struct cifsFileInfo * cifsFile = file->private_data;
457 /* check if index in the buffer */
459 if((cifsFile == NULL) || (ppCurrentEntry == NULL) || (num_to_ret == NULL))
462 *ppCurrentEntry = NULL;
463 first_entry_in_buffer =
464 cifsFile->srch_inf.index_of_last_entry -
465 cifsFile->srch_inf.entries_in_buffer;
466 /* dump_cifs_file_struct(file, "In fce ");*/
467 if(index_to_find < first_entry_in_buffer) {
468 /* close and restart search */
469 cFYI(1,("search backing up - close and restart search"));
470 cifsFile->invalidHandle = TRUE;
471 CIFSFindClose(xid, pTcon, cifsFile->netfid);
472 kfree(cifsFile->search_resume_name);
473 cifsFile->search_resume_name = NULL;
474 if(cifsFile->srch_inf.ntwrk_buf_start) {
475 cFYI(1,("freeing SMB ff cache buf on search rewind"));
476 cifs_buf_release(cifsFile->srch_inf.ntwrk_buf_start);
478 rc = initiate_cifs_search(xid,file);
480 cFYI(1,("error %d reinitiating a search on rewind",rc));
485 while((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
486 (rc == 0) && (cifsFile->srch_inf.endOfSearch == FALSE)){
487 cFYI(1,("calling findnext2"));
488 rc = CIFSFindNext(xid,pTcon,cifsFile->netfid, &cifsFile->srch_inf);
492 if(index_to_find < cifsFile->srch_inf.index_of_last_entry) {
493 /* we found the buffer that contains the entry */
494 /* scan and find it */
496 char * current_entry;
497 char * end_of_smb = cifsFile->srch_inf.ntwrk_buf_start +
498 smbCalcSize((struct smb_hdr *)
499 cifsFile->srch_inf.ntwrk_buf_start);
500 /* dump_cifs_file_struct(file,"found entry in fce "); */
501 first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry
502 - cifsFile->srch_inf.entries_in_buffer;
503 pos_in_buf = index_to_find - first_entry_in_buffer;
504 cFYI(1,("found entry - pos_in_buf %d",pos_in_buf));
505 current_entry = cifsFile->srch_inf.srch_entries_start;
506 for(i=0;(i<(pos_in_buf)) && (current_entry != NULL);i++) {
507 /* go entry to next entry figuring out which we need to start with */
510 rc = cifs_entry_is_dot(current_entry,cifsFile);
511 if(rc == 1) /* is . or .. so skip */ {
512 cFYI(1,("Entry is .")); /* BB removeme BB */
514 } else if (rc == 2 ) {
515 cFYI(1,("Entry is ..")); /* BB removeme BB */
518 current_entry = nxt_dir_entry(current_entry,end_of_smb);
520 if((current_entry == NULL) && (i < pos_in_buf)) {
521 /* BB fixme - check if we should flag this error */
522 cERROR(1,("reached end of buf searching for pos in buf"
523 " %d index to find %lld rc %d",
524 pos_in_buf,index_to_find,rc));
527 *ppCurrentEntry = current_entry;
529 cFYI(1,("index not in buffer - could not findnext into it"));
533 if(pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
534 cFYI(1,("can not return entries when pos_in_buf beyond last entry"));
537 *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
538 /* dump_cifs_file_struct(file, "end fce ");*/
543 /* inode num, inode type and filename returned */
544 static int cifs_get_name_from_search_buf(struct qstr *pqst,
545 char *current_entry, __u16 level, unsigned int unicode,
546 struct cifs_sb_info * cifs_sb, ino_t *pinum)
549 unsigned int len = 0;
551 struct nls_table * nlt = cifs_sb->local_nls;
555 if(level == SMB_FIND_FILE_UNIX) {
556 FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
558 filename = &pFindData->FileName[0];
560 len = cifs_unicode_bytelen(filename);
562 /* BB should we make this strnlen of PATH_MAX? */
563 len = strnlen(filename, PATH_MAX);
566 /* BB fixme - hash low and high 32 bits if not 64 bit arch BB fixme */
567 if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
568 *pinum = pFindData->UniqueId;
569 } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
570 FILE_DIRECTORY_INFO * pFindData =
571 (FILE_DIRECTORY_INFO *)current_entry;
572 filename = &pFindData->FileName[0];
573 len = le32_to_cpu(pFindData->FileNameLength);
574 } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
575 FILE_FULL_DIRECTORY_INFO * pFindData =
576 (FILE_FULL_DIRECTORY_INFO *)current_entry;
577 filename = &pFindData->FileName[0];
578 len = le32_to_cpu(pFindData->FileNameLength);
579 } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
580 SEARCH_ID_FULL_DIR_INFO * pFindData =
581 (SEARCH_ID_FULL_DIR_INFO *)current_entry;
582 filename = &pFindData->FileName[0];
583 len = le32_to_cpu(pFindData->FileNameLength);
584 *pinum = pFindData->UniqueId;
585 } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
586 FILE_BOTH_DIRECTORY_INFO * pFindData =
587 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
588 filename = &pFindData->FileName[0];
589 len = le32_to_cpu(pFindData->FileNameLength);
591 cFYI(1,("Unknown findfirst level %d",level));
595 /* BB fixme - test with long names */
596 /* Note converted filename can be longer than in unicode */
597 pqst->len = cifs_strfromUCS_le((char *)pqst->name,(wchar_t *)filename,len/2,nlt);
599 pqst->name = filename;
602 pqst->hash = full_name_hash(pqst->name,pqst->len);
603 /* cFYI(1,("filldir on %s",pqst->name)); */
607 static int cifs_filldir(char *pfindEntry, struct file *file,
608 filldir_t filldir, void *direntry, char *scratch_buf)
612 struct cifsFileInfo * pCifsF;
615 struct cifs_sb_info * cifs_sb;
616 struct inode *tmp_inode;
617 struct dentry *tmp_dentry;
619 /* get filename and len into qstring */
621 /* decide whether to create and populate ionde */
622 if((direntry == NULL) || (file == NULL))
625 pCifsF = file->private_data;
627 if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
630 if(file->f_dentry == NULL)
633 cifs_sb = CIFS_SB(file->f_dentry->d_sb);
635 qstring.name = scratch_buf;
636 rc = cifs_get_name_from_search_buf(&qstring,pfindEntry,
637 pCifsF->srch_inf.info_level,
638 pCifsF->srch_inf.unicode,cifs_sb,
639 &inum /* returned */);
644 rc = construct_dentry(&qstring,file,&tmp_inode, &tmp_dentry);
645 if((tmp_inode == NULL) || (tmp_dentry == NULL))
649 /* inode created, we need to hash it with right inode number */
651 /* BB fixme - hash the 2 32 quantities bits together if necessary BB */
652 tmp_inode->i_ino = inum;
654 insert_inode_hash(tmp_inode);
657 if(pCifsF->srch_inf.info_level == SMB_FIND_FILE_UNIX) {
658 unix_fill_in_inode(tmp_inode,(FILE_UNIX_INFO *)pfindEntry,&obj_type);
660 fill_in_inode(tmp_inode,(FILE_DIRECTORY_INFO *)pfindEntry,&obj_type);
663 rc = filldir(direntry,qstring.name,qstring.len,file->f_pos,tmp_inode->i_ino,obj_type);
665 cFYI(1,("filldir rc = %d",rc));
672 static int cifs_save_resume_key(const char *current_entry,
673 struct cifsFileInfo *cifsFile)
676 unsigned int len = 0;
680 if((cifsFile == NULL) || (current_entry == NULL))
683 level = cifsFile->srch_inf.info_level;
685 if(level == SMB_FIND_FILE_UNIX) {
686 FILE_UNIX_INFO * pFindData = (FILE_UNIX_INFO *)current_entry;
688 filename = &pFindData->FileName[0];
689 if(cifsFile->srch_inf.unicode) {
690 len = cifs_unicode_bytelen(filename);
692 /* BB should we make this strnlen of PATH_MAX? */
693 len = strnlen(filename, PATH_MAX);
695 cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
696 } else if(level == SMB_FIND_FILE_DIRECTORY_INFO) {
697 FILE_DIRECTORY_INFO * pFindData =
698 (FILE_DIRECTORY_INFO *)current_entry;
699 filename = &pFindData->FileName[0];
700 len = le32_to_cpu(pFindData->FileNameLength);
701 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
702 } else if(level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
703 FILE_FULL_DIRECTORY_INFO * pFindData =
704 (FILE_FULL_DIRECTORY_INFO *)current_entry;
705 filename = &pFindData->FileName[0];
706 len = le32_to_cpu(pFindData->FileNameLength);
707 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
708 } else if(level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
709 SEARCH_ID_FULL_DIR_INFO * pFindData =
710 (SEARCH_ID_FULL_DIR_INFO *)current_entry;
711 filename = &pFindData->FileName[0];
712 len = le32_to_cpu(pFindData->FileNameLength);
713 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
714 } else if(level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
715 FILE_BOTH_DIRECTORY_INFO * pFindData =
716 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
717 filename = &pFindData->FileName[0];
718 len = le32_to_cpu(pFindData->FileNameLength);
719 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
721 cFYI(1,("Unknown findfirst level %d",level));
724 cifsFile->srch_inf.resume_name_len = len;
725 cifsFile->srch_inf.presume_name = filename;
729 int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
733 struct cifs_sb_info *cifs_sb;
734 struct cifsTconInfo *pTcon;
735 struct cifsFileInfo *cifsFile = NULL;
736 char * current_entry;
738 char * tmp_buf = NULL;
743 if(file->f_dentry == NULL) {
747 /* dump_cifs_file_struct(file, "Begin rdir "); */
749 cifs_sb = CIFS_SB(file->f_dentry->d_sb);
750 pTcon = cifs_sb->tcon;
754 /* cFYI(1,("readdir2 pos: %lld",file->f_pos)); */
756 switch ((int) file->f_pos) {
758 /*if (filldir(direntry, ".", 1, file->f_pos,
759 file->f_dentry->d_inode->i_ino, DT_DIR) < 0) {
760 cERROR(1, ("Filldir for current dir failed "));
766 /* if (filldir(direntry, "..", 2, file->f_pos,
767 file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
768 cERROR(1, ("Filldir for parent dir failed "));
774 /* 1) If search is active,
775 is in current search buffer?
776 if it before then restart search
777 if after then keep searching till find it */
779 if(file->private_data == NULL) {
780 rc = initiate_cifs_search(xid,file);
781 cFYI(1,("initiate cifs search rc %d",rc));
788 if(file->private_data == NULL) {
793 cifsFile = file->private_data;
794 if (cifsFile->srch_inf.endOfSearch) {
795 if(cifsFile->srch_inf.emptyDir) {
796 cFYI(1, ("End of search, empty dir"));
801 cifsFile->invalidHandle = TRUE;
802 CIFSFindClose(xid, pTcon, cifsFile->netfid);
804 kfree(cifsFile->search_resume_name);
805 cifsFile->search_resume_name = NULL; */
807 /* BB account for . and .. in f_pos as special case */
808 /* dump_cifs_file_struct(file, "rdir after default ");*/
810 rc = find_cifs_entry(xid,pTcon, file,
811 ¤t_entry,&num_to_fill);
813 cFYI(1,("fce error %d",rc));
815 } else if (current_entry != NULL) {
816 cFYI(1,("entry %lld found",file->f_pos));
818 cFYI(1,("could not find entry"));
821 cFYI(1,("loop through %d times filling dir for net buf %p",
822 num_to_fill,cifsFile->srch_inf.ntwrk_buf_start));
823 end_of_smb = cifsFile->srch_inf.ntwrk_buf_start +
824 smbCalcSize((struct smb_hdr *)
825 cifsFile->srch_inf.ntwrk_buf_start);
826 tmp_buf = kmalloc(NAME_MAX+1,GFP_KERNEL);
827 for(i=0;(i<num_to_fill) && (rc == 0);i++) {
828 if(current_entry == NULL) {
829 /* evaluate whether this case is an error */
830 cERROR(1,("past end of SMB num to fill %d i %d",
835 /* BB FIXME - need to enable the below code BB */
837 /* if((!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) ||
838 (cifsFile->srch_inf.info_level !=
839 something that supports server inodes)) {
842 fill in inode new_inode (getting local i_ino)
844 also create local inode for performance reasons (so we
845 have a cache of inode metadata) unless this new mount
846 parm says otherwise */
848 rc = cifs_filldir(current_entry, file,
849 filldir, direntry,tmp_buf);
851 if(file->f_pos == cifsFile->srch_inf.index_of_last_entry) {
852 cFYI(1,("last entry in buf at pos %lld %s",
853 file->f_pos,tmp_buf)); /* BB removeme BB */
854 cifs_save_resume_key(current_entry,cifsFile);
857 current_entry = nxt_dir_entry(current_entry,end_of_smb);
864 /* dump_cifs_file_struct(file, "end rdir "); */