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