aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /fs/cifs
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'fs/cifs')
-rw-r--r--fs/cifs/Kconfig63
-rw-r--r--fs/cifs/Makefile5
-rw-r--r--fs/cifs/README17
-rw-r--r--fs/cifs/cache.c2
-rw-r--r--fs/cifs/cifs_debug.c177
-rw-r--r--fs/cifs/cifs_debug.h78
-rw-r--r--fs/cifs/cifs_dfs_ref.c7
-rw-r--r--fs/cifs/cifs_fs_sb.h8
-rw-r--r--fs/cifs/cifs_spnego.c16
-rw-r--r--fs/cifs/cifs_unicode.c125
-rw-r--r--fs/cifs/cifs_unicode.h26
-rw-r--r--fs/cifs/cifsacl.c770
-rw-r--r--fs/cifs/cifsacl.h66
-rw-r--r--fs/cifs/cifsencrypt.c235
-rw-r--r--fs/cifs/cifsfs.c226
-rw-r--r--fs/cifs/cifsfs.h19
-rw-r--r--fs/cifs/cifsglob.h657
-rw-r--r--fs/cifs/cifspdu.h50
-rw-r--r--fs/cifs/cifsproto.h407
-rw-r--r--fs/cifs/cifssmb.c1113
-rw-r--r--fs/cifs/connect.c2894
-rw-r--r--fs/cifs/dir.c586
-rw-r--r--fs/cifs/export.c4
-rw-r--r--fs/cifs/file.c2737
-rw-r--r--fs/cifs/inode.c990
-rw-r--r--fs/cifs/ioctl.c30
-rw-r--r--fs/cifs/link.c139
-rw-r--r--fs/cifs/misc.c269
-rw-r--r--fs/cifs/netmisc.c29
-rw-r--r--fs/cifs/nterr.c6
-rw-r--r--fs/cifs/nterr.h22
-rw-r--r--fs/cifs/ntlmssp.h10
-rw-r--r--fs/cifs/readdir.c285
-rw-r--r--fs/cifs/sess.c66
-rw-r--r--fs/cifs/smb1ops.c963
-rw-r--r--fs/cifs/smb2file.c290
-rw-r--r--fs/cifs/smb2glob.h58
-rw-r--r--fs/cifs/smb2inode.c257
-rw-r--r--fs/cifs/smb2maperror.c2479
-rw-r--r--fs/cifs/smb2misc.c583
-rw-r--r--fs/cifs/smb2ops.c747
-rw-r--r--fs/cifs/smb2pdu.c2211
-rw-r--r--fs/cifs/smb2pdu.h857
-rw-r--r--fs/cifs/smb2proto.h163
-rw-r--r--fs/cifs/smb2status.h1782
-rw-r--r--fs/cifs/smb2transport.c331
-rw-r--r--fs/cifs/smbencrypt.c200
-rw-r--r--fs/cifs/transport.c629
-rw-r--r--fs/cifs/xattr.c72
49 files changed, 5236 insertions, 18520 deletions
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
index 21ff76c22a1..f66cc162515 100644
--- a/fs/cifs/Kconfig
+++ b/fs/cifs/Kconfig
@@ -9,14 +9,13 @@ config CIFS
9 select CRYPTO_ARC4 9 select CRYPTO_ARC4
10 select CRYPTO_ECB 10 select CRYPTO_ECB
11 select CRYPTO_DES 11 select CRYPTO_DES
12 select CRYPTO_SHA256
13 help 12 help
14 This is the client VFS module for the Common Internet File System 13 This is the client VFS module for the Common Internet File System
15 (CIFS) protocol which is the successor to the Server Message Block 14 (CIFS) protocol which is the successor to the Server Message Block
16 (SMB) protocol, the native file sharing mechanism for most early 15 (SMB) protocol, the native file sharing mechanism for most early
17 PC operating systems. The CIFS protocol is fully supported by 16 PC operating systems. The CIFS protocol is fully supported by
18 file servers such as Windows 2000 (including Windows 2003, Windows 2008, 17 file servers such as Windows 2000 (including Windows 2003, NT 4
19 NT 4 and Windows XP) as well by Samba (which provides excellent CIFS 18 and Windows XP) as well by Samba (which provides excellent CIFS
20 server support for Linux and many other operating systems). Limited 19 server support for Linux and many other operating systems). Limited
21 support for OS/2 and Windows ME and similar servers is provided as 20 support for OS/2 and Windows ME and similar servers is provided as
22 well. 21 well.
@@ -115,24 +114,9 @@ config CIFS_POSIX
115 (such as Samba 3.10 and later) which can negotiate 114 (such as Samba 3.10 and later) which can negotiate
116 CIFS POSIX ACL support. If unsure, say N. 115 CIFS POSIX ACL support. If unsure, say N.
117 116
118config CIFS_ACL
119 bool "Provide CIFS ACL support"
120 depends on CIFS_XATTR && KEYS
121 help
122 Allows fetching CIFS/NTFS ACL from the server. The DACL blob
123 is handed over to the application/caller.
124
125config CIFS_DEBUG
126 bool "Enable CIFS debugging routines"
127 default y
128 depends on CIFS
129 help
130 Enabling this option adds helpful debugging messages to
131 the cifs code which increases the size of the cifs module.
132 If unsure, say Y.
133config CIFS_DEBUG2 117config CIFS_DEBUG2
134 bool "Enable additional CIFS debugging routines" 118 bool "Enable additional CIFS debugging routines"
135 depends on CIFS_DEBUG 119 depends on CIFS
136 help 120 help
137 Enabling this option adds a few more debugging routines 121 Enabling this option adds a few more debugging routines
138 to the cifs code which slightly increases the size of 122 to the cifs code which slightly increases the size of
@@ -154,37 +138,24 @@ config CIFS_DFS_UPCALL
154 IP addresses) which is needed for implicit mounts of DFS junction 138 IP addresses) which is needed for implicit mounts of DFS junction
155 points. If unsure, say N. 139 points. If unsure, say N.
156 140
157config CIFS_NFSD_EXPORT
158 bool "Allow nfsd to export CIFS file system (EXPERIMENTAL)"
159 depends on CIFS && EXPERIMENTAL && BROKEN
160 help
161 Allows NFS server to export a CIFS mounted share (nfsd over cifs)
162
163config CIFS_SMB2
164 bool "SMB2 network file system support (EXPERIMENTAL)"
165 depends on CIFS && EXPERIMENTAL && INET
166 select NLS
167 select KEYS
168 select FSCACHE
169 select DNS_RESOLVER
170
171 help
172 This enables experimental support for the SMB2 (Server Message Block
173 version 2) protocol. The SMB2 protocol is the successor to the
174 popular CIFS and SMB network file sharing protocols. SMB2 is the
175 native file sharing mechanism for recent versions of Windows
176 operating systems (since Vista). SMB2 enablement will eventually
177 allow users better performance, security and features, than would be
178 possible with cifs. Note that smb2 mount options also are simpler
179 (compared to cifs) due to protocol improvements.
180
181 Unless you are a developer or tester, say N.
182
183config CIFS_FSCACHE 141config CIFS_FSCACHE
184 bool "Provide CIFS client caching support" 142 bool "Provide CIFS client caching support (EXPERIMENTAL)"
143 depends on EXPERIMENTAL
185 depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y 144 depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y
186 help 145 help
187 Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data 146 Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data
188 to be cached locally on disk through the general filesystem cache 147 to be cached locally on disk through the general filesystem cache
189 manager. If unsure, say N. 148 manager. If unsure, say N.
190 149
150config CIFS_ACL
151 bool "Provide CIFS ACL support (EXPERIMENTAL)"
152 depends on EXPERIMENTAL && CIFS_XATTR && KEYS
153 help
154 Allows to fetch CIFS/NTFS ACL from the server. The DACL blob
155 is handed over to the application/caller.
156
157config CIFS_NFSD_EXPORT
158 bool "Allow nfsd to export CIFS file system (EXPERIMENTAL)"
159 depends on CIFS && EXPERIMENTAL && BROKEN
160 help
161 Allows NFS server to export a CIFS mounted share (nfsd over cifs)
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index aa0d68b086e..005d524c3a4 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_CIFS) += cifs.o
6cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \ 6cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
7 link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \ 7 link.o misc.o netmisc.o smbencrypt.o transport.o asn1.o \
8 cifs_unicode.o nterr.o xattr.o cifsencrypt.o \ 8 cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
9 readdir.o ioctl.o sess.o export.o smb1ops.o 9 readdir.o ioctl.o sess.o export.o
10 10
11cifs-$(CONFIG_CIFS_ACL) += cifsacl.o 11cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
12 12
@@ -15,6 +15,3 @@ cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
15cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o 15cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
16 16
17cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o 17cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
18
19cifs-$(CONFIG_CIFS_SMB2) += smb2ops.o smb2maperror.o smb2transport.o \
20 smb2misc.o smb2pdu.o smb2inode.o smb2file.o
diff --git a/fs/cifs/README b/fs/cifs/README
index 2d5622f60e1..c5c2c5e5f0f 100644
--- a/fs/cifs/README
+++ b/fs/cifs/README
@@ -480,7 +480,7 @@ A partial list of the supported mount options follows:
480 Unicode on the wire. 480 Unicode on the wire.
481 nomapchars Do not translate any of these seven characters (default). 481 nomapchars Do not translate any of these seven characters (default).
482 nocase Request case insensitive path name matching (case 482 nocase Request case insensitive path name matching (case
483 sensitive is the default if the server supports it). 483 sensitive is the default if the server suports it).
484 (mount option "ignorecase" is identical to "nocase") 484 (mount option "ignorecase" is identical to "nocase")
485 posixpaths If CIFS Unix extensions are supported, attempt to 485 posixpaths If CIFS Unix extensions are supported, attempt to
486 negotiate posix path name support which allows certain 486 negotiate posix path name support which allows certain
@@ -608,6 +608,11 @@ Stats Lists summary resource usage information as well as per
608 in the kernel configuration. 608 in the kernel configuration.
609 609
610Configuration pseudo-files: 610Configuration pseudo-files:
611MultiuserMount If set to one, more than one CIFS session to
612 the same server ip address can be established
613 if more than one uid accesses the same mount
614 point and if the uids user/password mapping
615 information is available. (default is 0)
611PacketSigningEnabled If set to one, cifs packet signing is enabled 616PacketSigningEnabled If set to one, cifs packet signing is enabled
612 and will be used if the server requires 617 and will be used if the server requires
613 it. If set to two, cifs packet signing is 618 it. If set to two, cifs packet signing is
@@ -740,14 +745,4 @@ installed and something like the following lines should be added to the
740create cifs.spnego * * /usr/local/sbin/cifs.upcall %k 745create cifs.spnego * * /usr/local/sbin/cifs.upcall %k
741create dns_resolver * * /usr/local/sbin/cifs.upcall %k 746create dns_resolver * * /usr/local/sbin/cifs.upcall %k
742 747
743CIFS kernel module parameters
744=============================
745These module parameters can be specified or modified either during the time of
746module loading or during the runtime by using the interface
747 /proc/module/cifs/parameters/<param>
748
749i.e. echo "value" > /sys/module/cifs/parameters/<param>
750
7511. enable_oplocks - Enable or disable oplocks. Oplocks are enabled by default.
752 [Y/y/1]. To disable use any of [N/n/0].
753 748
diff --git a/fs/cifs/cache.c b/fs/cifs/cache.c
index 282d6de7e41..545509c3313 100644
--- a/fs/cifs/cache.c
+++ b/fs/cifs/cache.c
@@ -152,7 +152,7 @@ static uint16_t cifs_super_get_key(const void *cookie_netfs_data, void *buffer,
152 152
153 sharename = extract_sharename(tcon->treeName); 153 sharename = extract_sharename(tcon->treeName);
154 if (IS_ERR(sharename)) { 154 if (IS_ERR(sharename)) {
155 cFYI(1, "%s: couldn't extract sharename", __func__); 155 cFYI(1, "%s: couldn't extract sharename\n", __func__);
156 sharename = NULL; 156 sharename = NULL;
157 return 0; 157 return 0;
158 } 158 }
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index d9ea6ede6a7..6d40656e1e2 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -57,21 +57,18 @@ cifs_dump_mem(char *label, void *data, int length)
57 } 57 }
58} 58}
59 59
60void cifs_dump_detail(void *buf)
61{
62#ifdef CONFIG_CIFS_DEBUG2 60#ifdef CONFIG_CIFS_DEBUG2
63 struct smb_hdr *smb = (struct smb_hdr *)buf; 61void cifs_dump_detail(struct smb_hdr *smb)
64 62{
65 cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d", 63 cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
66 smb->Command, smb->Status.CifsError, 64 smb->Command, smb->Status.CifsError,
67 smb->Flags, smb->Flags2, smb->Mid, smb->Pid); 65 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
68 cERROR(1, "smb buf %p len %u", smb, smbCalcSize(smb)); 66 cERROR(1, "smb buf %p len %d", smb, smbCalcSize(smb));
69#endif /* CONFIG_CIFS_DEBUG2 */
70} 67}
71 68
69
72void cifs_dump_mids(struct TCP_Server_Info *server) 70void cifs_dump_mids(struct TCP_Server_Info *server)
73{ 71{
74#ifdef CONFIG_CIFS_DEBUG2
75 struct list_head *tmp; 72 struct list_head *tmp;
76 struct mid_q_entry *mid_entry; 73 struct mid_q_entry *mid_entry;
77 74
@@ -82,15 +79,15 @@ void cifs_dump_mids(struct TCP_Server_Info *server)
82 spin_lock(&GlobalMid_Lock); 79 spin_lock(&GlobalMid_Lock);
83 list_for_each(tmp, &server->pending_mid_q) { 80 list_for_each(tmp, &server->pending_mid_q) {
84 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
85 cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu", 82 cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %d",
86 mid_entry->mid_state, 83 mid_entry->midState,
87 le16_to_cpu(mid_entry->command), 84 (int)mid_entry->command,
88 mid_entry->pid, 85 mid_entry->pid,
89 mid_entry->callback_data, 86 mid_entry->callback_data,
90 mid_entry->mid); 87 mid_entry->mid);
91#ifdef CONFIG_CIFS_STATS2 88#ifdef CONFIG_CIFS_STATS2
92 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld", 89 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
93 mid_entry->large_buf, 90 mid_entry->largeBuf,
94 mid_entry->resp_buf, 91 mid_entry->resp_buf,
95 mid_entry->when_received, 92 mid_entry->when_received,
96 jiffies); 93 jiffies);
@@ -104,8 +101,8 @@ void cifs_dump_mids(struct TCP_Server_Info *server)
104 } 101 }
105 } 102 }
106 spin_unlock(&GlobalMid_Lock); 103 spin_unlock(&GlobalMid_Lock);
107#endif /* CONFIG_CIFS_DEBUG2 */
108} 104}
105#endif /* CONFIG_CIFS_DEBUG2 */
109 106
110#ifdef CONFIG_PROC_FS 107#ifdef CONFIG_PROC_FS
111static int cifs_debug_data_proc_show(struct seq_file *m, void *v) 108static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
@@ -174,7 +171,8 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
174 seq_printf(m, "TCP status: %d\n\tLocal Users To " 171 seq_printf(m, "TCP status: %d\n\tLocal Users To "
175 "Server: %d SecMode: 0x%x Req On Wire: %d", 172 "Server: %d SecMode: 0x%x Req On Wire: %d",
176 server->tcpStatus, server->srv_count, 173 server->tcpStatus, server->srv_count,
177 server->sec_mode, in_flight(server)); 174 server->sec_mode,
175 atomic_read(&server->inFlight));
178 176
179#ifdef CONFIG_CIFS_STATS2 177#ifdef CONFIG_CIFS_STATS2
180 seq_printf(m, " In Send: %d In MaxReq Wait: %d", 178 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
@@ -220,12 +218,12 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
220 mid_entry = list_entry(tmp3, struct mid_q_entry, 218 mid_entry = list_entry(tmp3, struct mid_q_entry,
221 qhead); 219 qhead);
222 seq_printf(m, "\tState: %d com: %d pid:" 220 seq_printf(m, "\tState: %d com: %d pid:"
223 " %d cbdata: %p mid %llu\n", 221 " %d cbdata: %p mid %d\n",
224 mid_entry->mid_state, 222 mid_entry->midState,
225 le16_to_cpu(mid_entry->command), 223 (int)mid_entry->command,
226 mid_entry->pid, 224 mid_entry->pid,
227 mid_entry->callback_data, 225 mid_entry->callback_data,
228 mid_entry->mid); 226 mid_entry->mid);
229 } 227 }
230 spin_unlock(&GlobalMid_Lock); 228 spin_unlock(&GlobalMid_Lock);
231 } 229 }
@@ -282,8 +280,24 @@ static ssize_t cifs_stats_proc_write(struct file *file,
282 struct cifs_tcon, 280 struct cifs_tcon,
283 tcon_list); 281 tcon_list);
284 atomic_set(&tcon->num_smbs_sent, 0); 282 atomic_set(&tcon->num_smbs_sent, 0);
285 if (server->ops->clear_stats) 283 atomic_set(&tcon->num_writes, 0);
286 server->ops->clear_stats(tcon); 284 atomic_set(&tcon->num_reads, 0);
285 atomic_set(&tcon->num_oplock_brks, 0);
286 atomic_set(&tcon->num_opens, 0);
287 atomic_set(&tcon->num_posixopens, 0);
288 atomic_set(&tcon->num_posixmkdirs, 0);
289 atomic_set(&tcon->num_closes, 0);
290 atomic_set(&tcon->num_deletes, 0);
291 atomic_set(&tcon->num_mkdirs, 0);
292 atomic_set(&tcon->num_rmdirs, 0);
293 atomic_set(&tcon->num_renames, 0);
294 atomic_set(&tcon->num_t2renames, 0);
295 atomic_set(&tcon->num_ffirst, 0);
296 atomic_set(&tcon->num_fnext, 0);
297 atomic_set(&tcon->num_fclose, 0);
298 atomic_set(&tcon->num_hardlinks, 0);
299 atomic_set(&tcon->num_symlinks, 0);
300 atomic_set(&tcon->num_locks, 0);
287 } 301 }
288 } 302 }
289 } 303 }
@@ -342,10 +356,42 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
342 seq_printf(m, "\n%d) %s", i, tcon->treeName); 356 seq_printf(m, "\n%d) %s", i, tcon->treeName);
343 if (tcon->need_reconnect) 357 if (tcon->need_reconnect)
344 seq_puts(m, "\tDISCONNECTED "); 358 seq_puts(m, "\tDISCONNECTED ");
345 seq_printf(m, "\nSMBs: %d", 359 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
346 atomic_read(&tcon->num_smbs_sent)); 360 atomic_read(&tcon->num_smbs_sent),
347 if (server->ops->print_stats) 361 atomic_read(&tcon->num_oplock_brks));
348 server->ops->print_stats(m, tcon); 362 seq_printf(m, "\nReads: %d Bytes: %lld",
363 atomic_read(&tcon->num_reads),
364 (long long)(tcon->bytes_read));
365 seq_printf(m, "\nWrites: %d Bytes: %lld",
366 atomic_read(&tcon->num_writes),
367 (long long)(tcon->bytes_written));
368 seq_printf(m, "\nFlushes: %d",
369 atomic_read(&tcon->num_flushes));
370 seq_printf(m, "\nLocks: %d HardLinks: %d "
371 "Symlinks: %d",
372 atomic_read(&tcon->num_locks),
373 atomic_read(&tcon->num_hardlinks),
374 atomic_read(&tcon->num_symlinks));
375 seq_printf(m, "\nOpens: %d Closes: %d "
376 "Deletes: %d",
377 atomic_read(&tcon->num_opens),
378 atomic_read(&tcon->num_closes),
379 atomic_read(&tcon->num_deletes));
380 seq_printf(m, "\nPosix Opens: %d "
381 "Posix Mkdirs: %d",
382 atomic_read(&tcon->num_posixopens),
383 atomic_read(&tcon->num_posixmkdirs));
384 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
385 atomic_read(&tcon->num_mkdirs),
386 atomic_read(&tcon->num_rmdirs));
387 seq_printf(m, "\nRenames: %d T2 Renames %d",
388 atomic_read(&tcon->num_renames),
389 atomic_read(&tcon->num_t2renames));
390 seq_printf(m, "\nFindFirst: %d FNext %d "
391 "FClose %d",
392 atomic_read(&tcon->num_ffirst),
393 atomic_read(&tcon->num_fnext),
394 atomic_read(&tcon->num_fclose));
349 } 395 }
350 } 396 }
351 } 397 }
@@ -372,8 +418,10 @@ static const struct file_operations cifs_stats_proc_fops = {
372 418
373static struct proc_dir_entry *proc_fs_cifs; 419static struct proc_dir_entry *proc_fs_cifs;
374static const struct file_operations cifsFYI_proc_fops; 420static const struct file_operations cifsFYI_proc_fops;
421static const struct file_operations cifs_oplock_proc_fops;
375static const struct file_operations cifs_lookup_cache_proc_fops; 422static const struct file_operations cifs_lookup_cache_proc_fops;
376static const struct file_operations traceSMB_proc_fops; 423static const struct file_operations traceSMB_proc_fops;
424static const struct file_operations cifs_multiuser_mount_proc_fops;
377static const struct file_operations cifs_security_flags_proc_fops; 425static const struct file_operations cifs_security_flags_proc_fops;
378static const struct file_operations cifs_linux_ext_proc_fops; 426static const struct file_operations cifs_linux_ext_proc_fops;
379 427
@@ -391,8 +439,11 @@ cifs_proc_init(void)
391#endif /* STATS */ 439#endif /* STATS */
392 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops); 440 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
393 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops); 441 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
442 proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
394 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs, 443 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
395 &cifs_linux_ext_proc_fops); 444 &cifs_linux_ext_proc_fops);
445 proc_create("MultiuserMount", 0, proc_fs_cifs,
446 &cifs_multiuser_mount_proc_fops);
396 proc_create("SecurityFlags", 0, proc_fs_cifs, 447 proc_create("SecurityFlags", 0, proc_fs_cifs,
397 &cifs_security_flags_proc_fops); 448 &cifs_security_flags_proc_fops);
398 proc_create("LookupCacheEnabled", 0, proc_fs_cifs, 449 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
@@ -411,6 +462,8 @@ cifs_proc_clean(void)
411#ifdef CONFIG_CIFS_STATS 462#ifdef CONFIG_CIFS_STATS
412 remove_proc_entry("Stats", proc_fs_cifs); 463 remove_proc_entry("Stats", proc_fs_cifs);
413#endif 464#endif
465 remove_proc_entry("MultiuserMount", proc_fs_cifs);
466 remove_proc_entry("OplockEnabled", proc_fs_cifs);
414 remove_proc_entry("SecurityFlags", proc_fs_cifs); 467 remove_proc_entry("SecurityFlags", proc_fs_cifs);
415 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); 468 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
416 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); 469 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
@@ -456,6 +509,43 @@ static const struct file_operations cifsFYI_proc_fops = {
456 .write = cifsFYI_proc_write, 509 .write = cifsFYI_proc_write,
457}; 510};
458 511
512static int cifs_oplock_proc_show(struct seq_file *m, void *v)
513{
514 seq_printf(m, "%d\n", oplockEnabled);
515 return 0;
516}
517
518static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
519{
520 return single_open(file, cifs_oplock_proc_show, NULL);
521}
522
523static ssize_t cifs_oplock_proc_write(struct file *file,
524 const char __user *buffer, size_t count, loff_t *ppos)
525{
526 char c;
527 int rc;
528
529 rc = get_user(c, buffer);
530 if (rc)
531 return rc;
532 if (c == '0' || c == 'n' || c == 'N')
533 oplockEnabled = 0;
534 else if (c == '1' || c == 'y' || c == 'Y')
535 oplockEnabled = 1;
536
537 return count;
538}
539
540static const struct file_operations cifs_oplock_proc_fops = {
541 .owner = THIS_MODULE,
542 .open = cifs_oplock_proc_open,
543 .read = seq_read,
544 .llseek = seq_lseek,
545 .release = single_release,
546 .write = cifs_oplock_proc_write,
547};
548
459static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) 549static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
460{ 550{
461 seq_printf(m, "%d\n", linuxExtEnabled); 551 seq_printf(m, "%d\n", linuxExtEnabled);
@@ -567,6 +657,43 @@ static const struct file_operations traceSMB_proc_fops = {
567 .write = traceSMB_proc_write, 657 .write = traceSMB_proc_write,
568}; 658};
569 659
660static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
661{
662 seq_printf(m, "%d\n", multiuser_mount);
663 return 0;
664}
665
666static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
667{
668 return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
669}
670
671static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
672 const char __user *buffer, size_t count, loff_t *ppos)
673{
674 char c;
675 int rc;
676
677 rc = get_user(c, buffer);
678 if (rc)
679 return rc;
680 if (c == '0' || c == 'n' || c == 'N')
681 multiuser_mount = 0;
682 else if (c == '1' || c == 'y' || c == 'Y')
683 multiuser_mount = 1;
684
685 return count;
686}
687
688static const struct file_operations cifs_multiuser_mount_proc_fops = {
689 .owner = THIS_MODULE,
690 .open = cifs_multiuser_mount_proc_open,
691 .read = seq_read,
692 .llseek = seq_lseek,
693 .release = single_release,
694 .write = cifs_multiuser_mount_proc_write,
695};
696
570static int cifs_security_flags_proc_show(struct seq_file *m, void *v) 697static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
571{ 698{
572 seq_printf(m, "0x%x\n", global_secflags); 699 seq_printf(m, "0x%x\n", global_secflags);
diff --git a/fs/cifs/cifs_debug.h b/fs/cifs/cifs_debug.h
index 69ae3d3c3b3..8942b28cf80 100644
--- a/fs/cifs/cifs_debug.h
+++ b/fs/cifs/cifs_debug.h
@@ -18,57 +18,68 @@
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20*/ 20*/
21#define CIFS_DEBUG /* BB temporary */
21 22
22#ifndef _H_CIFS_DEBUG 23#ifndef _H_CIFS_DEBUG
23#define _H_CIFS_DEBUG 24#define _H_CIFS_DEBUG
24 25
25void cifs_dump_mem(char *label, void *data, int length); 26void cifs_dump_mem(char *label, void *data, int length);
26void cifs_dump_detail(void *);
27void cifs_dump_mids(struct TCP_Server_Info *);
28#ifdef CONFIG_CIFS_DEBUG2 27#ifdef CONFIG_CIFS_DEBUG2
29#define DBG2 2 28#define DBG2 2
29void cifs_dump_detail(struct smb_hdr *);
30void cifs_dump_mids(struct TCP_Server_Info *);
30#else 31#else
31#define DBG2 0 32#define DBG2 0
32#endif 33#endif
33extern int traceSMB; /* flag which enables the function below */ 34extern int traceSMB; /* flag which enables the function below */
34void dump_smb(void *, int); 35void dump_smb(struct smb_hdr *, int);
35#define CIFS_INFO 0x01 36#define CIFS_INFO 0x01
36#define CIFS_RC 0x02 37#define CIFS_RC 0x02
37#define CIFS_TIMER 0x04 38#define CIFS_TIMER 0x04
38 39
39extern int cifsFYI;
40
41/* 40/*
42 * debug ON 41 * debug ON
43 * -------- 42 * --------
44 */ 43 */
45#ifdef CONFIG_CIFS_DEBUG 44#ifdef CIFS_DEBUG
46 45
47/* information message: e.g., configuration, major event */ 46/* information message: e.g., configuration, major event */
48#define cifsfyi(fmt, ...) \ 47extern int cifsFYI;
48#define cifsfyi(fmt, arg...) \
49do { \ 49do { \
50 if (cifsFYI & CIFS_INFO) \ 50 if (cifsFYI & CIFS_INFO) \
51 printk(KERN_DEBUG "%s: " fmt "\n", \ 51 printk(KERN_DEBUG "%s: " fmt "\n", __FILE__, ##arg); \
52 __FILE__, ##__VA_ARGS__); \
53} while (0) 52} while (0)
54 53
55#define cFYI(set, fmt, ...) \ 54#define cFYI(set, fmt, arg...) \
56do { \ 55do { \
57 if (set) \ 56 if (set) \
58 cifsfyi(fmt, ##__VA_ARGS__); \ 57 cifsfyi(fmt, ##arg); \
59} while (0) 58} while (0)
60 59
61#define cifswarn(fmt, ...) \ 60#define cifswarn(fmt, arg...) \
62 printk(KERN_WARNING fmt "\n", ##__VA_ARGS__) 61 printk(KERN_WARNING fmt "\n", ##arg)
63 62
64/* error event message: e.g., i/o error */ 63/* debug event message: */
65#define cifserror(fmt, ...) \ 64extern int cifsERROR;
66 printk(KERN_ERR "CIFS VFS: " fmt "\n", ##__VA_ARGS__); \
67 65
68#define cERROR(set, fmt, ...) \ 66#define cEVENT(fmt, arg...) \
69do { \ 67do { \
70 if (set) \ 68 if (cifsERROR) \
71 cifserror(fmt, ##__VA_ARGS__); \ 69 printk(KERN_EVENT "%s: " fmt "\n", __FILE__, ##arg); \
70} while (0)
71
72/* error event message: e.g., i/o error */
73#define cifserror(fmt, arg...) \
74do { \
75 if (cifsERROR) \
76 printk(KERN_ERR "CIFS VFS: " fmt "\n", ##arg); \
77} while (0)
78
79#define cERROR(set, fmt, arg...) \
80do { \
81 if (set) \
82 cifserror(fmt, ##arg); \
72} while (0) 83} while (0)
73 84
74/* 85/*
@@ -76,27 +87,10 @@ do { \
76 * --------- 87 * ---------
77 */ 88 */
78#else /* _CIFS_DEBUG */ 89#else /* _CIFS_DEBUG */
79#define cifsfyi(fmt, ...) \ 90#define cERROR(set, fmt, arg...)
80do { \ 91#define cEVENT(fmt, arg...)
81 if (0) \ 92#define cFYI(set, fmt, arg...)
82 printk(KERN_DEBUG "%s: " fmt "\n", \ 93#define cifserror(fmt, arg...)
83 __FILE__, ##__VA_ARGS__); \
84} while (0)
85#define cFYI(set, fmt, ...) \
86do { \
87 if (0 && set) \
88 cifsfyi(fmt, ##__VA_ARGS__); \
89} while (0)
90#define cifserror(fmt, ...) \
91do { \
92 if (0) \
93 printk(KERN_ERR "CIFS VFS: " fmt "\n", ##__VA_ARGS__); \
94} while (0)
95#define cERROR(set, fmt, ...) \
96do { \
97 if (0 && set) \
98 cifserror(fmt, ##__VA_ARGS__); \
99} while (0)
100#endif /* _CIFS_DEBUG */ 94#endif /* _CIFS_DEBUG */
101 95
102#endif /* _H_CIFS_DEBUG */ 96#endif /* _H_CIFS_DEBUG */
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index ce5cbd717bf..6873bb634a9 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -275,8 +275,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
275 struct cifs_sb_info *cifs_sb; 275 struct cifs_sb_info *cifs_sb;
276 struct cifs_ses *ses; 276 struct cifs_ses *ses;
277 char *full_path; 277 char *full_path;
278 unsigned int xid; 278 int xid, i;
279 int i;
280 int rc; 279 int rc;
281 struct vfsmount *mnt; 280 struct vfsmount *mnt;
282 struct tcon_link *tlink; 281 struct tcon_link *tlink;
@@ -303,11 +302,11 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
303 } 302 }
304 ses = tlink_tcon(tlink)->ses; 303 ses = tlink_tcon(tlink)->ses;
305 304
306 xid = get_xid(); 305 xid = GetXid();
307 rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls, 306 rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls,
308 &num_referrals, &referrals, 307 &num_referrals, &referrals,
309 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 308 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
310 free_xid(xid); 309 FreeXid(xid);
311 310
312 cifs_put_tlink(tlink); 311 cifs_put_tlink(tlink);
313 312
diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h
index c865bfdfe81..7260e11e21f 100644
--- a/fs/cifs/cifs_fs_sb.h
+++ b/fs/cifs/cifs_fs_sb.h
@@ -43,8 +43,6 @@
43#define CIFS_MOUNT_STRICT_IO 0x40000 /* strict cache mode */ 43#define CIFS_MOUNT_STRICT_IO 0x40000 /* strict cache mode */
44#define CIFS_MOUNT_RWPIDFORWARD 0x80000 /* use pid forwarding for rw */ 44#define CIFS_MOUNT_RWPIDFORWARD 0x80000 /* use pid forwarding for rw */
45#define CIFS_MOUNT_POSIXACL 0x100000 /* mirror of MS_POSIXACL in mnt_cifs_flags */ 45#define CIFS_MOUNT_POSIXACL 0x100000 /* mirror of MS_POSIXACL in mnt_cifs_flags */
46#define CIFS_MOUNT_CIFS_BACKUPUID 0x200000 /* backup intent bit for a user */
47#define CIFS_MOUNT_CIFS_BACKUPGID 0x400000 /* backup intent bit for a group */
48 46
49struct cifs_sb_info { 47struct cifs_sb_info {
50 struct rb_root tlink_tree; 48 struct rb_root tlink_tree;
@@ -57,10 +55,8 @@ struct cifs_sb_info {
57 atomic_t active; 55 atomic_t active;
58 uid_t mnt_uid; 56 uid_t mnt_uid;
59 gid_t mnt_gid; 57 gid_t mnt_gid;
60 uid_t mnt_backupuid; 58 mode_t mnt_file_mode;
61 gid_t mnt_backupgid; 59 mode_t mnt_dir_mode;
62 umode_t mnt_file_mode;
63 umode_t mnt_dir_mode;
64 unsigned int mnt_cifs_flags; 60 unsigned int mnt_cifs_flags;
65 char *mountdata; /* options received at mount time or via DFS refs */ 61 char *mountdata; /* options received at mount time or via DFS refs */
66 struct backing_dev_info bdi; 62 struct backing_dev_info bdi;
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
index 086f381d648..2272fd5fe5b 100644
--- a/fs/cifs/cifs_spnego.c
+++ b/fs/cifs/cifs_spnego.c
@@ -31,18 +31,18 @@
31 31
32/* create a new cifs key */ 32/* create a new cifs key */
33static int 33static int
34cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep) 34cifs_spnego_key_instantiate(struct key *key, const void *data, size_t datalen)
35{ 35{
36 char *payload; 36 char *payload;
37 int ret; 37 int ret;
38 38
39 ret = -ENOMEM; 39 ret = -ENOMEM;
40 payload = kmalloc(prep->datalen, GFP_KERNEL); 40 payload = kmalloc(datalen, GFP_KERNEL);
41 if (!payload) 41 if (!payload)
42 goto error; 42 goto error;
43 43
44 /* attach the data */ 44 /* attach the data */
45 memcpy(payload, prep->data, prep->datalen); 45 memcpy(payload, data, datalen);
46 key->payload.data = payload; 46 key->payload.data = payload;
47 ret = 0; 47 ret = 0;
48 48
@@ -113,11 +113,9 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo)
113 MAX_MECH_STR_LEN + 113 MAX_MECH_STR_LEN +
114 UID_KEY_LEN + (sizeof(uid_t) * 2) + 114 UID_KEY_LEN + (sizeof(uid_t) * 2) +
115 CREDUID_KEY_LEN + (sizeof(uid_t) * 2) + 115 CREDUID_KEY_LEN + (sizeof(uid_t) * 2) +
116 USER_KEY_LEN + strlen(sesInfo->user_name) +
116 PID_KEY_LEN + (sizeof(pid_t) * 2) + 1; 117 PID_KEY_LEN + (sizeof(pid_t) * 2) + 1;
117 118
118 if (sesInfo->user_name)
119 desc_len += USER_KEY_LEN + strlen(sesInfo->user_name);
120
121 spnego_key = ERR_PTR(-ENOMEM); 119 spnego_key = ERR_PTR(-ENOMEM);
122 description = kzalloc(desc_len, GFP_KERNEL); 120 description = kzalloc(desc_len, GFP_KERNEL);
123 if (description == NULL) 121 if (description == NULL)
@@ -154,10 +152,8 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo)
154 dp = description + strlen(description); 152 dp = description + strlen(description);
155 sprintf(dp, ";creduid=0x%x", sesInfo->cred_uid); 153 sprintf(dp, ";creduid=0x%x", sesInfo->cred_uid);
156 154
157 if (sesInfo->user_name) { 155 dp = description + strlen(description);
158 dp = description + strlen(description); 156 sprintf(dp, ";user=%s", sesInfo->user_name);
159 sprintf(dp, ";user=%s", sesInfo->user_name);
160 }
161 157
162 dp = description + strlen(description); 158 dp = description + strlen(description);
163 sprintf(dp, ";pid=0x%x", current->pid); 159 sprintf(dp, ";pid=0x%x", current->pid);
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 71d5d0a5f6b..1b2e180b018 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -27,17 +27,17 @@
27#include "cifs_debug.h" 27#include "cifs_debug.h"
28 28
29/* 29/*
30 * cifs_utf16_bytes - how long will a string be after conversion? 30 * cifs_ucs2_bytes - how long will a string be after conversion?
31 * @utf16 - pointer to input string 31 * @ucs - pointer to input string
32 * @maxbytes - don't go past this many bytes of input string 32 * @maxbytes - don't go past this many bytes of input string
33 * @codepage - destination codepage 33 * @codepage - destination codepage
34 * 34 *
35 * Walk a utf16le string and return the number of bytes that the string will 35 * Walk a ucs2le string and return the number of bytes that the string will
36 * be after being converted to the given charset, not including any null 36 * be after being converted to the given charset, not including any null
37 * termination required. Don't walk past maxbytes in the source buffer. 37 * termination required. Don't walk past maxbytes in the source buffer.
38 */ 38 */
39int 39int
40cifs_utf16_bytes(const __le16 *from, int maxbytes, 40cifs_ucs2_bytes(const __le16 *from, int maxbytes,
41 const struct nls_table *codepage) 41 const struct nls_table *codepage)
42{ 42{
43 int i; 43 int i;
@@ -122,7 +122,7 @@ cp_convert:
122} 122}
123 123
124/* 124/*
125 * cifs_from_utf16 - convert utf16le string to local charset 125 * cifs_from_ucs2 - convert utf16le string to local charset
126 * @to - destination buffer 126 * @to - destination buffer
127 * @from - source buffer 127 * @from - source buffer
128 * @tolen - destination buffer size (in bytes) 128 * @tolen - destination buffer size (in bytes)
@@ -130,7 +130,7 @@ cp_convert:
130 * @codepage - codepage to which characters should be converted 130 * @codepage - codepage to which characters should be converted
131 * @mapchar - should characters be remapped according to the mapchars option? 131 * @mapchar - should characters be remapped according to the mapchars option?
132 * 132 *
133 * Convert a little-endian utf16le string (as sent by the server) to a string 133 * Convert a little-endian ucs2le string (as sent by the server) to a string
134 * in the provided codepage. The tolen and fromlen parameters are to ensure 134 * in the provided codepage. The tolen and fromlen parameters are to ensure
135 * that the code doesn't walk off of the end of the buffer (which is always 135 * that the code doesn't walk off of the end of the buffer (which is always
136 * a danger if the alignment of the source buffer is off). The destination 136 * a danger if the alignment of the source buffer is off). The destination
@@ -139,12 +139,12 @@ cp_convert:
139 * null terminator). 139 * null terminator).
140 * 140 *
141 * Note that some windows versions actually send multiword UTF-16 characters 141 * Note that some windows versions actually send multiword UTF-16 characters
142 * instead of straight UTF16-2. The linux nls routines however aren't able to 142 * instead of straight UCS-2. The linux nls routines however aren't able to
143 * deal with those characters properly. In the event that we get some of 143 * deal with those characters properly. In the event that we get some of
144 * those characters, they won't be translated properly. 144 * those characters, they won't be translated properly.
145 */ 145 */
146int 146int
147cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen, 147cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
148 const struct nls_table *codepage, bool mapchar) 148 const struct nls_table *codepage, bool mapchar)
149{ 149{
150 int i, charlen, safelen; 150 int i, charlen, safelen;
@@ -190,44 +190,23 @@ cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
190} 190}
191 191
192/* 192/*
193 * NAME: cifs_strtoUTF16() 193 * NAME: cifs_strtoUCS()
194 * 194 *
195 * FUNCTION: Convert character string to unicode string 195 * FUNCTION: Convert character string to unicode string
196 * 196 *
197 */ 197 */
198int 198int
199cifs_strtoUTF16(__le16 *to, const char *from, int len, 199cifs_strtoUCS(__le16 *to, const char *from, int len,
200 const struct nls_table *codepage) 200 const struct nls_table *codepage)
201{ 201{
202 int charlen; 202 int charlen;
203 int i; 203 int i;
204 wchar_t wchar_to; /* needed to quiet sparse */ 204 wchar_t wchar_to; /* needed to quiet sparse */
205 205
206 /* special case for utf8 to handle no plane0 chars */
207 if (!strcmp(codepage->charset, "utf8")) {
208 /*
209 * convert utf8 -> utf16, we assume we have enough space
210 * as caller should have assumed conversion does not overflow
211 * in destination len is length in wchar_t units (16bits)
212 */
213 i = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN,
214 (wchar_t *) to, len);
215
216 /* if success terminate and exit */
217 if (i >= 0)
218 goto success;
219 /*
220 * if fails fall back to UCS encoding as this
221 * function should not return negative values
222 * currently can fail only if source contains
223 * invalid encoded characters
224 */
225 }
226
227 for (i = 0; len && *from; i++, from += charlen, len -= charlen) { 206 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
228 charlen = codepage->char2uni(from, len, &wchar_to); 207 charlen = codepage->char2uni(from, len, &wchar_to);
229 if (charlen < 1) { 208 if (charlen < 1) {
230 cERROR(1, "strtoUTF16: char2uni of 0x%x returned %d", 209 cERROR(1, "strtoUCS: char2uni of 0x%x returned %d",
231 *from, charlen); 210 *from, charlen);
232 /* A question mark */ 211 /* A question mark */
233 wchar_to = 0x003f; 212 wchar_to = 0x003f;
@@ -236,14 +215,12 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len,
236 put_unaligned_le16(wchar_to, &to[i]); 215 put_unaligned_le16(wchar_to, &to[i]);
237 } 216 }
238 217
239success:
240 put_unaligned_le16(0, &to[i]); 218 put_unaligned_le16(0, &to[i]);
241 return i; 219 return i;
242} 220}
243 221
244/* 222/*
245 * cifs_strndup_from_utf16 - copy a string from wire format to the local 223 * cifs_strndup_from_ucs - copy a string from wire format to the local codepage
246 * codepage
247 * @src - source string 224 * @src - source string
248 * @maxlen - don't walk past this many bytes in the source string 225 * @maxlen - don't walk past this many bytes in the source string
249 * @is_unicode - is this a unicode string? 226 * @is_unicode - is this a unicode string?
@@ -254,19 +231,19 @@ success:
254 * error. 231 * error.
255 */ 232 */
256char * 233char *
257cifs_strndup_from_utf16(const char *src, const int maxlen, 234cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode,
258 const bool is_unicode, const struct nls_table *codepage) 235 const struct nls_table *codepage)
259{ 236{
260 int len; 237 int len;
261 char *dst; 238 char *dst;
262 239
263 if (is_unicode) { 240 if (is_unicode) {
264 len = cifs_utf16_bytes((__le16 *) src, maxlen, codepage); 241 len = cifs_ucs2_bytes((__le16 *) src, maxlen, codepage);
265 len += nls_nullsize(codepage); 242 len += nls_nullsize(codepage);
266 dst = kmalloc(len, GFP_KERNEL); 243 dst = kmalloc(len, GFP_KERNEL);
267 if (!dst) 244 if (!dst)
268 return NULL; 245 return NULL;
269 cifs_from_utf16(dst, (__le16 *) src, len, maxlen, codepage, 246 cifs_from_ucs2(dst, (__le16 *) src, len, maxlen, codepage,
270 false); 247 false);
271 } else { 248 } else {
272 len = strnlen(src, maxlen); 249 len = strnlen(src, maxlen);
@@ -287,7 +264,7 @@ cifs_strndup_from_utf16(const char *src, const int maxlen,
287 * names are little endian 16 bit Unicode on the wire 264 * names are little endian 16 bit Unicode on the wire
288 */ 265 */
289int 266int
290cifsConvertToUTF16(__le16 *target, const char *source, int srclen, 267cifsConvertToUCS(__le16 *target, const char *source, int srclen,
291 const struct nls_table *cp, int mapChars) 268 const struct nls_table *cp, int mapChars)
292{ 269{
293 int i, j, charlen; 270 int i, j, charlen;
@@ -296,7 +273,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
296 wchar_t tmp; 273 wchar_t tmp;
297 274
298 if (!mapChars) 275 if (!mapChars)
299 return cifs_strtoUTF16(target, source, PATH_MAX, cp); 276 return cifs_strtoUCS(target, source, PATH_MAX, cp);
300 277
301 for (i = 0, j = 0; i < srclen; j++) { 278 for (i = 0, j = 0; i < srclen; j++) {
302 src_char = source[i]; 279 src_char = source[i];
@@ -304,7 +281,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
304 switch (src_char) { 281 switch (src_char) {
305 case 0: 282 case 0:
306 put_unaligned(0, &target[j]); 283 put_unaligned(0, &target[j]);
307 goto ctoUTF16_out; 284 goto ctoUCS_out;
308 case ':': 285 case ':':
309 dst_char = cpu_to_le16(UNI_COLON); 286 dst_char = cpu_to_le16(UNI_COLON);
310 break; 287 break;
@@ -349,67 +326,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
349 put_unaligned(dst_char, &target[j]); 326 put_unaligned(dst_char, &target[j]);
350 } 327 }
351 328
352ctoUTF16_out: 329ctoUCS_out:
353 return j; 330 return i;
354}
355
356#ifdef CONFIG_CIFS_SMB2
357/*
358 * cifs_local_to_utf16_bytes - how long will a string be after conversion?
359 * @from - pointer to input string
360 * @maxbytes - don't go past this many bytes of input string
361 * @codepage - source codepage
362 *
363 * Walk a string and return the number of bytes that the string will
364 * be after being converted to the given charset, not including any null
365 * termination required. Don't walk past maxbytes in the source buffer.
366 */
367
368static int
369cifs_local_to_utf16_bytes(const char *from, int len,
370 const struct nls_table *codepage)
371{
372 int charlen;
373 int i;
374 wchar_t wchar_to;
375
376 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
377 charlen = codepage->char2uni(from, len, &wchar_to);
378 /* Failed conversion defaults to a question mark */
379 if (charlen < 1)
380 charlen = 1;
381 }
382 return 2 * i; /* UTF16 characters are two bytes */
383} 331}
384 332
385/*
386 * cifs_strndup_to_utf16 - copy a string to wire format from the local codepage
387 * @src - source string
388 * @maxlen - don't walk past this many bytes in the source string
389 * @utf16_len - the length of the allocated string in bytes (including null)
390 * @cp - source codepage
391 * @remap - map special chars
392 *
393 * Take a string convert it from the local codepage to UTF16 and
394 * put it in a new buffer. Returns a pointer to the new string or NULL on
395 * error.
396 */
397__le16 *
398cifs_strndup_to_utf16(const char *src, const int maxlen, int *utf16_len,
399 const struct nls_table *cp, int remap)
400{
401 int len;
402 __le16 *dst;
403
404 len = cifs_local_to_utf16_bytes(src, maxlen, cp);
405 len += 2; /* NULL */
406 dst = kmalloc(len, GFP_KERNEL);
407 if (!dst) {
408 *utf16_len = 0;
409 return NULL;
410 }
411 cifsConvertToUTF16(dst, src, strlen(src), cp, remap);
412 *utf16_len = len;
413 return dst;
414}
415#endif /* CONFIG_CIFS_SMB2 */
diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
index 4fb097468e2..6d02fd56056 100644
--- a/fs/cifs/cifs_unicode.h
+++ b/fs/cifs/cifs_unicode.h
@@ -74,21 +74,17 @@ extern const struct UniCaseRange CifsUniLowerRange[];
74#endif /* UNIUPR_NOLOWER */ 74#endif /* UNIUPR_NOLOWER */
75 75
76#ifdef __KERNEL__ 76#ifdef __KERNEL__
77int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen, 77int cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
78 const struct nls_table *codepage, bool mapchar); 78 const struct nls_table *codepage, bool mapchar);
79int cifs_utf16_bytes(const __le16 *from, int maxbytes, 79int cifs_ucs2_bytes(const __le16 *from, int maxbytes,
80 const struct nls_table *codepage); 80 const struct nls_table *codepage);
81int cifs_strtoUTF16(__le16 *, const char *, int, const struct nls_table *); 81int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *);
82char *cifs_strndup_from_utf16(const char *src, const int maxlen, 82char *cifs_strndup_from_ucs(const char *src, const int maxlen,
83 const bool is_unicode, 83 const bool is_unicode,
84 const struct nls_table *codepage); 84 const struct nls_table *codepage);
85extern int cifsConvertToUTF16(__le16 *target, const char *source, int maxlen, 85extern int cifsConvertToUCS(__le16 *target, const char *source, int maxlen,
86 const struct nls_table *cp, int mapChars); 86 const struct nls_table *cp, int mapChars);
87#ifdef CONFIG_CIFS_SMB2 87
88extern __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen,
89 int *utf16_len, const struct nls_table *cp,
90 int remap);
91#endif /* CONFIG_CIFS_SMB2 */
92#endif 88#endif
93 89
94/* 90/*
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 5cbd00e7406..d0f59faefb7 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -42,45 +42,84 @@ static const struct cifs_sid sid_authusers = {
42/* group users */ 42/* group users */
43static const struct cifs_sid sid_user = {1, 2 , {0, 0, 0, 0, 0, 5}, {} }; 43static const struct cifs_sid sid_user = {1, 2 , {0, 0, 0, 0, 0, 5}, {} };
44 44
45static const struct cred *root_cred; 45const struct cred *root_cred;
46
47static void
48shrink_idmap_tree(struct rb_root *root, int nr_to_scan, int *nr_rem,
49 int *nr_del)
50{
51 struct rb_node *node;
52 struct rb_node *tmp;
53 struct cifs_sid_id *psidid;
54
55 node = rb_first(root);
56 while (node) {
57 tmp = node;
58 node = rb_next(tmp);
59 psidid = rb_entry(tmp, struct cifs_sid_id, rbnode);
60 if (nr_to_scan == 0 || *nr_del == nr_to_scan)
61 ++(*nr_rem);
62 else {
63 if (time_after(jiffies, psidid->time + SID_MAP_EXPIRE)
64 && psidid->refcount == 0) {
65 rb_erase(tmp, root);
66 ++(*nr_del);
67 } else
68 ++(*nr_rem);
69 }
70 }
71}
72
73/*
74 * Run idmap cache shrinker.
75 */
76static int
77cifs_idmap_shrinker(struct shrinker *shrink, struct shrink_control *sc)
78{
79 int nr_to_scan = sc->nr_to_scan;
80 int nr_del = 0;
81 int nr_rem = 0;
82 struct rb_root *root;
83
84 root = &uidtree;
85 spin_lock(&siduidlock);
86 shrink_idmap_tree(root, nr_to_scan, &nr_rem, &nr_del);
87 spin_unlock(&siduidlock);
88
89 root = &gidtree;
90 spin_lock(&sidgidlock);
91 shrink_idmap_tree(root, nr_to_scan, &nr_rem, &nr_del);
92 spin_unlock(&sidgidlock);
93
94 return nr_rem;
95}
96
97static struct shrinker cifs_shrinker = {
98 .shrink = cifs_idmap_shrinker,
99 .seeks = DEFAULT_SEEKS,
100};
46 101
47static int 102static int
48cifs_idmap_key_instantiate(struct key *key, struct key_preparsed_payload *prep) 103cifs_idmap_key_instantiate(struct key *key, const void *data, size_t datalen)
49{ 104{
50 char *payload; 105 char *payload;
51 106
52 /* 107 payload = kmalloc(datalen, GFP_KERNEL);
53 * If the payload is less than or equal to the size of a pointer, then
54 * an allocation here is wasteful. Just copy the data directly to the
55 * payload.value union member instead.
56 *
57 * With this however, you must check the datalen before trying to
58 * dereference payload.data!
59 */
60 if (prep->datalen <= sizeof(key->payload)) {
61 key->payload.value = 0;
62 memcpy(&key->payload.value, prep->data, prep->datalen);
63 key->datalen = prep->datalen;
64 return 0;
65 }
66 payload = kmalloc(prep->datalen, GFP_KERNEL);
67 if (!payload) 108 if (!payload)
68 return -ENOMEM; 109 return -ENOMEM;
69 110
70 memcpy(payload, prep->data, prep->datalen); 111 memcpy(payload, data, datalen);
71 key->payload.data = payload; 112 key->payload.data = payload;
72 key->datalen = prep->datalen;
73 return 0; 113 return 0;
74} 114}
75 115
76static inline void 116static inline void
77cifs_idmap_key_destroy(struct key *key) 117cifs_idmap_key_destroy(struct key *key)
78{ 118{
79 if (key->datalen > sizeof(key->payload)) 119 kfree(key->payload.data);
80 kfree(key->payload.data);
81} 120}
82 121
83static struct key_type cifs_idmap_key_type = { 122struct key_type cifs_idmap_key_type = {
84 .name = "cifs.idmap", 123 .name = "cifs.idmap",
85 .instantiate = cifs_idmap_key_instantiate, 124 .instantiate = cifs_idmap_key_instantiate,
86 .destroy = cifs_idmap_key_destroy, 125 .destroy = cifs_idmap_key_destroy,
@@ -88,174 +127,100 @@ static struct key_type cifs_idmap_key_type = {
88 .match = user_match, 127 .match = user_match,
89}; 128};
90 129
91static char * 130static void
92sid_to_key_str(struct cifs_sid *sidptr, unsigned int type) 131sid_to_str(struct cifs_sid *sidptr, char *sidstr)
93{ 132{
94 int i, len; 133 int i;
95 unsigned int saval; 134 unsigned long saval;
96 char *sidstr, *strptr; 135 char *strptr;
97 unsigned long long id_auth_val;
98
99 /* 3 bytes for prefix */
100 sidstr = kmalloc(3 + SID_STRING_BASE_SIZE +
101 (SID_STRING_SUBAUTH_SIZE * sidptr->num_subauth),
102 GFP_KERNEL);
103 if (!sidstr)
104 return sidstr;
105 136
106 strptr = sidstr; 137 strptr = sidstr;
107 len = sprintf(strptr, "%cs:S-%hhu", type == SIDOWNER ? 'o' : 'g',
108 sidptr->revision);
109 strptr += len;
110
111 /* The authority field is a single 48-bit number */
112 id_auth_val = (unsigned long long)sidptr->authority[5];
113 id_auth_val |= (unsigned long long)sidptr->authority[4] << 8;
114 id_auth_val |= (unsigned long long)sidptr->authority[3] << 16;
115 id_auth_val |= (unsigned long long)sidptr->authority[2] << 24;
116 id_auth_val |= (unsigned long long)sidptr->authority[1] << 32;
117 id_auth_val |= (unsigned long long)sidptr->authority[0] << 48;
118 138
119 /* 139 sprintf(strptr, "%s", "S");
120 * MS-DTYP states that if the authority is >= 2^32, then it should be 140 strptr = sidstr + strlen(sidstr);
121 * expressed as a hex value.
122 */
123 if (id_auth_val <= UINT_MAX)
124 len = sprintf(strptr, "-%llu", id_auth_val);
125 else
126 len = sprintf(strptr, "-0x%llx", id_auth_val);
127 141
128 strptr += len; 142 sprintf(strptr, "-%d", sidptr->revision);
143 strptr = sidstr + strlen(sidstr);
144
145 for (i = 0; i < 6; ++i) {
146 if (sidptr->authority[i]) {
147 sprintf(strptr, "-%d", sidptr->authority[i]);
148 strptr = sidstr + strlen(sidstr);
149 }
150 }
129 151
130 for (i = 0; i < sidptr->num_subauth; ++i) { 152 for (i = 0; i < sidptr->num_subauth; ++i) {
131 saval = le32_to_cpu(sidptr->sub_auth[i]); 153 saval = le32_to_cpu(sidptr->sub_auth[i]);
132 len = sprintf(strptr, "-%u", saval); 154 sprintf(strptr, "-%ld", saval);
133 strptr += len; 155 strptr = sidstr + strlen(sidstr);
134 } 156 }
135
136 return sidstr;
137} 157}
138 158
139/* 159static void
140 * if the two SIDs (roughly equivalent to a UUID for a user or group) are 160id_rb_insert(struct rb_root *root, struct cifs_sid *sidptr,
141 * the same returns zero, if they do not match returns non-zero. 161 struct cifs_sid_id **psidid, char *typestr)
142 */
143static int
144compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid)
145{ 162{
146 int i; 163 int rc;
147 int num_subauth, num_sat, num_saw; 164 char *strptr;
148 165 struct rb_node *node = root->rb_node;
149 if ((!ctsid) || (!cwsid)) 166 struct rb_node *parent = NULL;
150 return 1; 167 struct rb_node **linkto = &(root->rb_node);
151 168 struct cifs_sid_id *lsidid;
152 /* compare the revision */ 169
153 if (ctsid->revision != cwsid->revision) { 170 while (node) {
154 if (ctsid->revision > cwsid->revision) 171 lsidid = rb_entry(node, struct cifs_sid_id, rbnode);
155 return 1; 172 parent = node;
156 else 173 rc = compare_sids(sidptr, &((lsidid)->sid));
157 return -1; 174 if (rc > 0) {
158 } 175 linkto = &(node->rb_left);
159 176 node = node->rb_left;
160 /* compare all of the six auth values */ 177 } else if (rc < 0) {
161 for (i = 0; i < NUM_AUTHS; ++i) { 178 linkto = &(node->rb_right);
162 if (ctsid->authority[i] != cwsid->authority[i]) { 179 node = node->rb_right;
163 if (ctsid->authority[i] > cwsid->authority[i])
164 return 1;
165 else
166 return -1;
167 } 180 }
168 } 181 }
169 182
170 /* compare all of the subauth values if any */ 183 memcpy(&(*psidid)->sid, sidptr, sizeof(struct cifs_sid));
171 num_sat = ctsid->num_subauth; 184 (*psidid)->time = jiffies - (SID_MAP_RETRY + 1);
172 num_saw = cwsid->num_subauth; 185 (*psidid)->refcount = 0;
173 num_subauth = num_sat < num_saw ? num_sat : num_saw;
174 if (num_subauth) {
175 for (i = 0; i < num_subauth; ++i) {
176 if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) {
177 if (le32_to_cpu(ctsid->sub_auth[i]) >
178 le32_to_cpu(cwsid->sub_auth[i]))
179 return 1;
180 else
181 return -1;
182 }
183 }
184 }
185 186
186 return 0; /* sids compare/match */ 187 sprintf((*psidid)->sidstr, "%s", typestr);
187} 188 strptr = (*psidid)->sidstr + strlen((*psidid)->sidstr);
189 sid_to_str(&(*psidid)->sid, strptr);
188 190
189static void 191 clear_bit(SID_ID_PENDING, &(*psidid)->state);
190cifs_copy_sid(struct cifs_sid *dst, const struct cifs_sid *src) 192 clear_bit(SID_ID_MAPPED, &(*psidid)->state);
191{
192 int i;
193 193
194 dst->revision = src->revision; 194 rb_link_node(&(*psidid)->rbnode, parent, linkto);
195 dst->num_subauth = min_t(u8, src->num_subauth, SID_MAX_SUB_AUTHORITIES); 195 rb_insert_color(&(*psidid)->rbnode, root);
196 for (i = 0; i < NUM_AUTHS; ++i)
197 dst->authority[i] = src->authority[i];
198 for (i = 0; i < dst->num_subauth; ++i)
199 dst->sub_auth[i] = src->sub_auth[i];
200} 196}
201 197
202static int 198static struct cifs_sid_id *
203id_to_sid(unsigned int cid, uint sidtype, struct cifs_sid *ssid) 199id_rb_search(struct rb_root *root, struct cifs_sid *sidptr)
204{ 200{
205 int rc; 201 int rc;
206 struct key *sidkey; 202 struct rb_node *node = root->rb_node;
207 struct cifs_sid *ksid; 203 struct cifs_sid_id *lsidid;
208 unsigned int ksid_size; 204
209 char desc[3 + 10 + 1]; /* 3 byte prefix + 10 bytes for value + NULL */ 205 while (node) {
210 const struct cred *saved_cred; 206 lsidid = rb_entry(node, struct cifs_sid_id, rbnode);
211 207 rc = compare_sids(sidptr, &((lsidid)->sid));
212 rc = snprintf(desc, sizeof(desc), "%ci:%u", 208 if (rc > 0) {
213 sidtype == SIDOWNER ? 'o' : 'g', cid); 209 node = node->rb_left;
214 if (rc >= sizeof(desc)) 210 } else if (rc < 0) {
215 return -EINVAL; 211 node = node->rb_right;
216 212 } else /* node found */
217 rc = 0; 213 return lsidid;
218 saved_cred = override_creds(root_cred);
219 sidkey = request_key(&cifs_idmap_key_type, desc, "");
220 if (IS_ERR(sidkey)) {
221 rc = -EINVAL;
222 cFYI(1, "%s: Can't map %cid %u to a SID", __func__,
223 sidtype == SIDOWNER ? 'u' : 'g', cid);
224 goto out_revert_creds;
225 } else if (sidkey->datalen < CIFS_SID_BASE_SIZE) {
226 rc = -EIO;
227 cFYI(1, "%s: Downcall contained malformed key "
228 "(datalen=%hu)", __func__, sidkey->datalen);
229 goto invalidate_key;
230 }
231
232 /*
233 * A sid is usually too large to be embedded in payload.value, but if
234 * there are no subauthorities and the host has 8-byte pointers, then
235 * it could be.
236 */
237 ksid = sidkey->datalen <= sizeof(sidkey->payload) ?
238 (struct cifs_sid *)&sidkey->payload.value :
239 (struct cifs_sid *)sidkey->payload.data;
240
241 ksid_size = CIFS_SID_BASE_SIZE + (ksid->num_subauth * sizeof(__le32));
242 if (ksid_size > sidkey->datalen) {
243 rc = -EIO;
244 cFYI(1, "%s: Downcall contained malformed key (datalen=%hu, "
245 "ksid_size=%u)", __func__, sidkey->datalen, ksid_size);
246 goto invalidate_key;
247 } 214 }
248 215
249 cifs_copy_sid(ssid, ksid); 216 return NULL;
250out_key_put: 217}
251 key_put(sidkey);
252out_revert_creds:
253 revert_creds(saved_cred);
254 return rc;
255 218
256invalidate_key: 219static int
257 key_invalidate(sidkey); 220sidid_pending_wait(void *unused)
258 goto out_key_put; 221{
222 schedule();
223 return signal_pending(current) ? -ERESTARTSYS : 0;
259} 224}
260 225
261static int 226static int
@@ -263,67 +228,111 @@ sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
263 struct cifs_fattr *fattr, uint sidtype) 228 struct cifs_fattr *fattr, uint sidtype)
264{ 229{
265 int rc; 230 int rc;
266 struct key *sidkey; 231 unsigned long cid;
267 char *sidstr; 232 struct key *idkey;
268 const struct cred *saved_cred; 233 const struct cred *saved_cred;
269 uid_t fuid = cifs_sb->mnt_uid; 234 struct cifs_sid_id *psidid, *npsidid;
270 gid_t fgid = cifs_sb->mnt_gid; 235 struct rb_root *cidtree;
271 236 spinlock_t *cidlock;
272 /* 237
273 * If we have too many subauthorities, then something is really wrong. 238 if (sidtype == SIDOWNER) {
274 * Just return an error. 239 cid = cifs_sb->mnt_uid; /* default uid, in case upcall fails */
275 */ 240 cidlock = &siduidlock;
276 if (unlikely(psid->num_subauth > SID_MAX_SUB_AUTHORITIES)) { 241 cidtree = &uidtree;
277 cFYI(1, "%s: %u subauthorities is too many!", __func__, 242 } else if (sidtype == SIDGROUP) {
278 psid->num_subauth); 243 cid = cifs_sb->mnt_gid; /* default gid, in case upcall fails */
279 return -EIO; 244 cidlock = &sidgidlock;
280 } 245 cidtree = &gidtree;
281 246 } else
282 sidstr = sid_to_key_str(psid, sidtype); 247 return -ENOENT;
283 if (!sidstr) 248
284 return -ENOMEM; 249 spin_lock(cidlock);
250 psidid = id_rb_search(cidtree, psid);
251
252 if (!psidid) { /* node does not exist, allocate one & attempt adding */
253 spin_unlock(cidlock);
254 npsidid = kzalloc(sizeof(struct cifs_sid_id), GFP_KERNEL);
255 if (!npsidid)
256 return -ENOMEM;
257
258 npsidid->sidstr = kmalloc(SIDLEN, GFP_KERNEL);
259 if (!npsidid->sidstr) {
260 kfree(npsidid);
261 return -ENOMEM;
262 }
285 263
286 saved_cred = override_creds(root_cred); 264 spin_lock(cidlock);
287 sidkey = request_key(&cifs_idmap_key_type, sidstr, ""); 265 psidid = id_rb_search(cidtree, psid);
288 if (IS_ERR(sidkey)) { 266 if (psidid) { /* node happened to get inserted meanwhile */
289 rc = -EINVAL; 267 ++psidid->refcount;
290 cFYI(1, "%s: Can't map SID %s to a %cid", __func__, sidstr, 268 spin_unlock(cidlock);
291 sidtype == SIDOWNER ? 'u' : 'g'); 269 kfree(npsidid->sidstr);
292 goto out_revert_creds; 270 kfree(npsidid);
271 } else {
272 psidid = npsidid;
273 id_rb_insert(cidtree, psid, &psidid,
274 sidtype == SIDOWNER ? "os:" : "gs:");
275 ++psidid->refcount;
276 spin_unlock(cidlock);
277 }
278 } else {
279 ++psidid->refcount;
280 spin_unlock(cidlock);
293 } 281 }
294 282
295 /* 283 /*
296 * FIXME: Here we assume that uid_t and gid_t are same size. It's 284 * If we are here, it is safe to access psidid and its fields
297 * probably a safe assumption but might be better to check based on 285 * since a reference was taken earlier while holding the spinlock.
298 * sidtype. 286 * A reference on the node is put without holding the spinlock
287 * and it is OK to do so in this case, shrinker will not erase
288 * this node until all references are put and we do not access
289 * any fields of the node after a reference is put .
299 */ 290 */
300 if (sidkey->datalen != sizeof(uid_t)) { 291 if (test_bit(SID_ID_MAPPED, &psidid->state)) {
301 rc = -EIO; 292 cid = psidid->id;
302 cFYI(1, "%s: Downcall contained malformed key " 293 psidid->time = jiffies; /* update ts for accessing */
303 "(datalen=%hu)", __func__, sidkey->datalen); 294 goto sid_to_id_out;
304 key_invalidate(sidkey);
305 goto out_key_put;
306 } 295 }
307 296
308 if (sidtype == SIDOWNER) 297 if (time_after(psidid->time + SID_MAP_RETRY, jiffies))
309 memcpy(&fuid, &sidkey->payload.value, sizeof(uid_t)); 298 goto sid_to_id_out;
310 else 299
311 memcpy(&fgid, &sidkey->payload.value, sizeof(gid_t)); 300 if (!test_and_set_bit(SID_ID_PENDING, &psidid->state)) {
312 301 saved_cred = override_creds(root_cred);
313out_key_put: 302 idkey = request_key(&cifs_idmap_key_type, psidid->sidstr, "");
314 key_put(sidkey); 303 if (IS_ERR(idkey))
315out_revert_creds: 304 cFYI(1, "%s: Can't map SID to an id", __func__);
316 revert_creds(saved_cred); 305 else {
317 kfree(sidstr); 306 cid = *(unsigned long *)idkey->payload.value;
307 psidid->id = cid;
308 set_bit(SID_ID_MAPPED, &psidid->state);
309 key_put(idkey);
310 kfree(psidid->sidstr);
311 }
312 revert_creds(saved_cred);
313 psidid->time = jiffies; /* update ts for accessing */
314 clear_bit(SID_ID_PENDING, &psidid->state);
315 wake_up_bit(&psidid->state, SID_ID_PENDING);
316 } else {
317 rc = wait_on_bit(&psidid->state, SID_ID_PENDING,
318 sidid_pending_wait, TASK_INTERRUPTIBLE);
319 if (rc) {
320 cFYI(1, "%s: sidid_pending_wait interrupted %d",
321 __func__, rc);
322 --psidid->refcount; /* decremented without spinlock */
323 return rc;
324 }
325 if (test_bit(SID_ID_MAPPED, &psidid->state))
326 cid = psidid->id;
327 }
318 328
319 /* 329sid_to_id_out:
320 * Note that we return 0 here unconditionally. If the mapping 330 --psidid->refcount; /* decremented without spinlock */
321 * fails then we just fall back to using the mnt_uid/mnt_gid.
322 */
323 if (sidtype == SIDOWNER) 331 if (sidtype == SIDOWNER)
324 fattr->cf_uid = fuid; 332 fattr->cf_uid = cid;
325 else 333 else
326 fattr->cf_gid = fgid; 334 fattr->cf_gid = cid;
335
327 return 0; 336 return 0;
328} 337}
329 338
@@ -334,7 +343,7 @@ init_cifs_idmap(void)
334 struct key *keyring; 343 struct key *keyring;
335 int ret; 344 int ret;
336 345
337 cFYI(1, "Registering the %s key type", cifs_idmap_key_type.name); 346 cFYI(1, "Registering the %s key type\n", cifs_idmap_key_type.name);
338 347
339 /* create an override credential set with a special thread keyring in 348 /* create an override credential set with a special thread keyring in
340 * which requests are cached 349 * which requests are cached
@@ -346,27 +355,37 @@ init_cifs_idmap(void)
346 if (!cred) 355 if (!cred)
347 return -ENOMEM; 356 return -ENOMEM;
348 357
349 keyring = keyring_alloc(".cifs_idmap", 0, 0, cred, 358 keyring = key_alloc(&key_type_keyring, ".cifs_idmap", 0, 0, cred,
350 (KEY_POS_ALL & ~KEY_POS_SETATTR) | 359 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
351 KEY_USR_VIEW | KEY_USR_READ, 360 KEY_USR_VIEW | KEY_USR_READ,
352 KEY_ALLOC_NOT_IN_QUOTA, NULL); 361 KEY_ALLOC_NOT_IN_QUOTA);
353 if (IS_ERR(keyring)) { 362 if (IS_ERR(keyring)) {
354 ret = PTR_ERR(keyring); 363 ret = PTR_ERR(keyring);
355 goto failed_put_cred; 364 goto failed_put_cred;
356 } 365 }
357 366
367 ret = key_instantiate_and_link(keyring, NULL, 0, NULL, NULL);
368 if (ret < 0)
369 goto failed_put_key;
370
358 ret = register_key_type(&cifs_idmap_key_type); 371 ret = register_key_type(&cifs_idmap_key_type);
359 if (ret < 0) 372 if (ret < 0)
360 goto failed_put_key; 373 goto failed_put_key;
361 374
362 /* instruct request_key() to use this special keyring as a cache for 375 /* instruct request_key() to use this special keyring as a cache for
363 * the results it looks up */ 376 * the results it looks up */
364 set_bit(KEY_FLAG_ROOT_CAN_CLEAR, &keyring->flags);
365 cred->thread_keyring = keyring; 377 cred->thread_keyring = keyring;
366 cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING; 378 cred->jit_keyring = KEY_REQKEY_DEFL_THREAD_KEYRING;
367 root_cred = cred; 379 root_cred = cred;
368 380
369 cFYI(1, "cifs idmap keyring: %d", key_serial(keyring)); 381 spin_lock_init(&siduidlock);
382 uidtree = RB_ROOT;
383 spin_lock_init(&sidgidlock);
384 gidtree = RB_ROOT;
385
386 register_shrinker(&cifs_shrinker);
387
388 cFYI(1, "cifs idmap keyring: %d\n", key_serial(keyring));
370 return 0; 389 return 0;
371 390
372failed_put_key: 391failed_put_key:
@@ -382,13 +401,83 @@ exit_cifs_idmap(void)
382 key_revoke(root_cred->thread_keyring); 401 key_revoke(root_cred->thread_keyring);
383 unregister_key_type(&cifs_idmap_key_type); 402 unregister_key_type(&cifs_idmap_key_type);
384 put_cred(root_cred); 403 put_cred(root_cred);
385 cFYI(1, "Unregistered %s key type", cifs_idmap_key_type.name); 404 unregister_shrinker(&cifs_shrinker);
405 cFYI(1, "Unregistered %s key type\n", cifs_idmap_key_type.name);
406}
407
408void
409cifs_destroy_idmaptrees(void)
410{
411 struct rb_root *root;
412 struct rb_node *node;
413
414 root = &uidtree;
415 spin_lock(&siduidlock);
416 while ((node = rb_first(root)))
417 rb_erase(node, root);
418 spin_unlock(&siduidlock);
419
420 root = &gidtree;
421 spin_lock(&sidgidlock);
422 while ((node = rb_first(root)))
423 rb_erase(node, root);
424 spin_unlock(&sidgidlock);
425}
426
427/* if the two SIDs (roughly equivalent to a UUID for a user or group) are
428 the same returns 1, if they do not match returns 0 */
429int compare_sids(const struct cifs_sid *ctsid, const struct cifs_sid *cwsid)
430{
431 int i;
432 int num_subauth, num_sat, num_saw;
433
434 if ((!ctsid) || (!cwsid))
435 return 1;
436
437 /* compare the revision */
438 if (ctsid->revision != cwsid->revision) {
439 if (ctsid->revision > cwsid->revision)
440 return 1;
441 else
442 return -1;
443 }
444
445 /* compare all of the six auth values */
446 for (i = 0; i < 6; ++i) {
447 if (ctsid->authority[i] != cwsid->authority[i]) {
448 if (ctsid->authority[i] > cwsid->authority[i])
449 return 1;
450 else
451 return -1;
452 }
453 }
454
455 /* compare all of the subauth values if any */
456 num_sat = ctsid->num_subauth;
457 num_saw = cwsid->num_subauth;
458 num_subauth = num_sat < num_saw ? num_sat : num_saw;
459 if (num_subauth) {
460 for (i = 0; i < num_subauth; ++i) {
461 if (ctsid->sub_auth[i] != cwsid->sub_auth[i]) {
462 if (le32_to_cpu(ctsid->sub_auth[i]) >
463 le32_to_cpu(cwsid->sub_auth[i]))
464 return 1;
465 else
466 return -1;
467 }
468 }
469 }
470
471 return 0; /* sids compare/match */
386} 472}
387 473
474
388/* copy ntsd, owner sid, and group sid from a security descriptor to another */ 475/* copy ntsd, owner sid, and group sid from a security descriptor to another */
389static void copy_sec_desc(const struct cifs_ntsd *pntsd, 476static void copy_sec_desc(const struct cifs_ntsd *pntsd,
390 struct cifs_ntsd *pnntsd, __u32 sidsoffset) 477 struct cifs_ntsd *pnntsd, __u32 sidsoffset)
391{ 478{
479 int i;
480
392 struct cifs_sid *owner_sid_ptr, *group_sid_ptr; 481 struct cifs_sid *owner_sid_ptr, *group_sid_ptr;
393 struct cifs_sid *nowner_sid_ptr, *ngroup_sid_ptr; 482 struct cifs_sid *nowner_sid_ptr, *ngroup_sid_ptr;
394 483
@@ -404,14 +493,26 @@ static void copy_sec_desc(const struct cifs_ntsd *pntsd,
404 owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + 493 owner_sid_ptr = (struct cifs_sid *)((char *)pntsd +
405 le32_to_cpu(pntsd->osidoffset)); 494 le32_to_cpu(pntsd->osidoffset));
406 nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset); 495 nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset);
407 cifs_copy_sid(nowner_sid_ptr, owner_sid_ptr); 496
497 nowner_sid_ptr->revision = owner_sid_ptr->revision;
498 nowner_sid_ptr->num_subauth = owner_sid_ptr->num_subauth;
499 for (i = 0; i < 6; i++)
500 nowner_sid_ptr->authority[i] = owner_sid_ptr->authority[i];
501 for (i = 0; i < 5; i++)
502 nowner_sid_ptr->sub_auth[i] = owner_sid_ptr->sub_auth[i];
408 503
409 /* copy group sid */ 504 /* copy group sid */
410 group_sid_ptr = (struct cifs_sid *)((char *)pntsd + 505 group_sid_ptr = (struct cifs_sid *)((char *)pntsd +
411 le32_to_cpu(pntsd->gsidoffset)); 506 le32_to_cpu(pntsd->gsidoffset));
412 ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset + 507 ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + sidsoffset +
413 sizeof(struct cifs_sid)); 508 sizeof(struct cifs_sid));
414 cifs_copy_sid(ngroup_sid_ptr, group_sid_ptr); 509
510 ngroup_sid_ptr->revision = group_sid_ptr->revision;
511 ngroup_sid_ptr->num_subauth = group_sid_ptr->num_subauth;
512 for (i = 0; i < 6; i++)
513 ngroup_sid_ptr->authority[i] = group_sid_ptr->authority[i];
514 for (i = 0; i < 5; i++)
515 ngroup_sid_ptr->sub_auth[i] = group_sid_ptr->sub_auth[i];
415 516
416 return; 517 return;
417} 518}
@@ -518,7 +619,7 @@ static __u16 fill_ace_for_sid(struct cifs_ace *pntace,
518 619
519 pntace->sid.revision = psid->revision; 620 pntace->sid.revision = psid->revision;
520 pntace->sid.num_subauth = psid->num_subauth; 621 pntace->sid.num_subauth = psid->num_subauth;
521 for (i = 0; i < NUM_AUTHS; i++) 622 for (i = 0; i < 6; i++)
522 pntace->sid.authority[i] = psid->authority[i]; 623 pntace->sid.authority[i] = psid->authority[i];
523 for (i = 0; i < psid->num_subauth; i++) 624 for (i = 0; i < psid->num_subauth; i++)
524 pntace->sid.sub_auth[i] = psid->sub_auth[i]; 625 pntace->sid.sub_auth[i] = psid->sub_auth[i];
@@ -605,13 +706,11 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
605 acl_size = sizeof(struct cifs_acl); 706 acl_size = sizeof(struct cifs_acl);
606 707
607 num_aces = le32_to_cpu(pdacl->num_aces); 708 num_aces = le32_to_cpu(pdacl->num_aces);
608 if (num_aces > 0) { 709 if (num_aces > 0) {
609 umode_t user_mask = S_IRWXU; 710 umode_t user_mask = S_IRWXU;
610 umode_t group_mask = S_IRWXG; 711 umode_t group_mask = S_IRWXG;
611 umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO; 712 umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO;
612 713
613 if (num_aces > ULONG_MAX / sizeof(struct cifs_ace *))
614 return;
615 ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), 714 ppace = kmalloc(num_aces * sizeof(struct cifs_ace *),
616 GFP_KERNEL); 715 GFP_KERNEL);
617 if (!ppace) { 716 if (!ppace) {
@@ -694,8 +793,8 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)
694 return -EINVAL; 793 return -EINVAL;
695 } 794 }
696 795
697#ifdef CONFIG_CIFS_DEBUG2
698 if (psid->num_subauth) { 796 if (psid->num_subauth) {
797#ifdef CONFIG_CIFS_DEBUG2
699 int i; 798 int i;
700 cFYI(1, "SID revision %d num_auth %d", 799 cFYI(1, "SID revision %d num_auth %d",
701 psid->revision, psid->num_subauth); 800 psid->revision, psid->num_subauth);
@@ -709,8 +808,8 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)
709 num auths and therefore go off the end */ 808 num auths and therefore go off the end */
710 cFYI(1, "RID 0x%x", 809 cFYI(1, "RID 0x%x",
711 le32_to_cpu(psid->sub_auth[psid->num_subauth-1])); 810 le32_to_cpu(psid->sub_auth[psid->num_subauth-1]));
712 }
713#endif 811#endif
812 }
714 813
715 return 0; 814 return 0;
716} 815}
@@ -769,80 +868,52 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
769 else 868 else
770 cFYI(1, "no ACL"); /* BB grant all or default perms? */ 869 cFYI(1, "no ACL"); /* BB grant all or default perms? */
771 870
871/* cifscred->uid = owner_sid_ptr->rid;
872 cifscred->gid = group_sid_ptr->rid;
873 memcpy((void *)(&(cifscred->osid)), (void *)owner_sid_ptr,
874 sizeof(struct cifs_sid));
875 memcpy((void *)(&(cifscred->gsid)), (void *)group_sid_ptr,
876 sizeof(struct cifs_sid)); */
877
772 return rc; 878 return rc;
773} 879}
774 880
881
775/* Convert permission bits from mode to equivalent CIFS ACL */ 882/* Convert permission bits from mode to equivalent CIFS ACL */
776static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd, 883static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
777 __u32 secdesclen, __u64 nmode, uid_t uid, gid_t gid, int *aclflag) 884 struct inode *inode, __u64 nmode)
778{ 885{
779 int rc = 0; 886 int rc = 0;
780 __u32 dacloffset; 887 __u32 dacloffset;
781 __u32 ndacloffset; 888 __u32 ndacloffset;
782 __u32 sidsoffset; 889 __u32 sidsoffset;
783 struct cifs_sid *owner_sid_ptr, *group_sid_ptr; 890 struct cifs_sid *owner_sid_ptr, *group_sid_ptr;
784 struct cifs_sid *nowner_sid_ptr, *ngroup_sid_ptr;
785 struct cifs_acl *dacl_ptr = NULL; /* no need for SACL ptr */ 891 struct cifs_acl *dacl_ptr = NULL; /* no need for SACL ptr */
786 struct cifs_acl *ndacl_ptr = NULL; /* no need for SACL ptr */ 892 struct cifs_acl *ndacl_ptr = NULL; /* no need for SACL ptr */
787 893
788 if (nmode != NO_CHANGE_64) { /* chmod */ 894 if ((inode == NULL) || (pntsd == NULL) || (pnntsd == NULL))
789 owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + 895 return -EIO;
896
897 owner_sid_ptr = (struct cifs_sid *)((char *)pntsd +
790 le32_to_cpu(pntsd->osidoffset)); 898 le32_to_cpu(pntsd->osidoffset));
791 group_sid_ptr = (struct cifs_sid *)((char *)pntsd + 899 group_sid_ptr = (struct cifs_sid *)((char *)pntsd +
792 le32_to_cpu(pntsd->gsidoffset)); 900 le32_to_cpu(pntsd->gsidoffset));
793 dacloffset = le32_to_cpu(pntsd->dacloffset); 901
794 dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset); 902 dacloffset = le32_to_cpu(pntsd->dacloffset);
795 ndacloffset = sizeof(struct cifs_ntsd); 903 dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset);
796 ndacl_ptr = (struct cifs_acl *)((char *)pnntsd + ndacloffset); 904
797 ndacl_ptr->revision = dacl_ptr->revision; 905 ndacloffset = sizeof(struct cifs_ntsd);
798 ndacl_ptr->size = 0; 906 ndacl_ptr = (struct cifs_acl *)((char *)pnntsd + ndacloffset);
799 ndacl_ptr->num_aces = 0; 907 ndacl_ptr->revision = dacl_ptr->revision;
800 908 ndacl_ptr->size = 0;
801 rc = set_chmod_dacl(ndacl_ptr, owner_sid_ptr, group_sid_ptr, 909 ndacl_ptr->num_aces = 0;
802 nmode); 910
803 sidsoffset = ndacloffset + le16_to_cpu(ndacl_ptr->size); 911 rc = set_chmod_dacl(ndacl_ptr, owner_sid_ptr, group_sid_ptr, nmode);
804 /* copy sec desc control portion & owner and group sids */ 912
805 copy_sec_desc(pntsd, pnntsd, sidsoffset); 913 sidsoffset = ndacloffset + le16_to_cpu(ndacl_ptr->size);
806 *aclflag = CIFS_ACL_DACL; 914
807 } else { 915 /* copy security descriptor control portion and owner and group sid */
808 memcpy(pnntsd, pntsd, secdesclen); 916 copy_sec_desc(pntsd, pnntsd, sidsoffset);
809 if (uid != NO_CHANGE_32) { /* chown */
810 owner_sid_ptr = (struct cifs_sid *)((char *)pnntsd +
811 le32_to_cpu(pnntsd->osidoffset));
812 nowner_sid_ptr = kmalloc(sizeof(struct cifs_sid),
813 GFP_KERNEL);
814 if (!nowner_sid_ptr)
815 return -ENOMEM;
816 rc = id_to_sid(uid, SIDOWNER, nowner_sid_ptr);
817 if (rc) {
818 cFYI(1, "%s: Mapping error %d for owner id %d",
819 __func__, rc, uid);
820 kfree(nowner_sid_ptr);
821 return rc;
822 }
823 cifs_copy_sid(owner_sid_ptr, nowner_sid_ptr);
824 kfree(nowner_sid_ptr);
825 *aclflag = CIFS_ACL_OWNER;
826 }
827 if (gid != NO_CHANGE_32) { /* chgrp */
828 group_sid_ptr = (struct cifs_sid *)((char *)pnntsd +
829 le32_to_cpu(pnntsd->gsidoffset));
830 ngroup_sid_ptr = kmalloc(sizeof(struct cifs_sid),
831 GFP_KERNEL);
832 if (!ngroup_sid_ptr)
833 return -ENOMEM;
834 rc = id_to_sid(gid, SIDGROUP, ngroup_sid_ptr);
835 if (rc) {
836 cFYI(1, "%s: Mapping error %d for group id %d",
837 __func__, rc, gid);
838 kfree(ngroup_sid_ptr);
839 return rc;
840 }
841 cifs_copy_sid(group_sid_ptr, ngroup_sid_ptr);
842 kfree(ngroup_sid_ptr);
843 *aclflag = CIFS_ACL_GROUP;
844 }
845 }
846 917
847 return rc; 918 return rc;
848} 919}
@@ -851,16 +922,15 @@ static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
851 __u16 fid, u32 *pacllen) 922 __u16 fid, u32 *pacllen)
852{ 923{
853 struct cifs_ntsd *pntsd = NULL; 924 struct cifs_ntsd *pntsd = NULL;
854 unsigned int xid; 925 int xid, rc;
855 int rc;
856 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); 926 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
857 927
858 if (IS_ERR(tlink)) 928 if (IS_ERR(tlink))
859 return ERR_CAST(tlink); 929 return ERR_CAST(tlink);
860 930
861 xid = get_xid(); 931 xid = GetXid();
862 rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), fid, &pntsd, pacllen); 932 rc = CIFSSMBGetCIFSACL(xid, tlink_tcon(tlink), fid, &pntsd, pacllen);
863 free_xid(xid); 933 FreeXid(xid);
864 934
865 cifs_put_tlink(tlink); 935 cifs_put_tlink(tlink);
866 936
@@ -875,8 +945,7 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
875{ 945{
876 struct cifs_ntsd *pntsd = NULL; 946 struct cifs_ntsd *pntsd = NULL;
877 int oplock = 0; 947 int oplock = 0;
878 unsigned int xid; 948 int xid, rc;
879 int rc, create_options = 0;
880 __u16 fid; 949 __u16 fid;
881 struct cifs_tcon *tcon; 950 struct cifs_tcon *tcon;
882 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); 951 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
@@ -885,21 +954,18 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
885 return ERR_CAST(tlink); 954 return ERR_CAST(tlink);
886 955
887 tcon = tlink_tcon(tlink); 956 tcon = tlink_tcon(tlink);
888 xid = get_xid(); 957 xid = GetXid();
889
890 if (backup_cred(cifs_sb))
891 create_options |= CREATE_OPEN_BACKUP_INTENT;
892 958
893 rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, READ_CONTROL, 959 rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, READ_CONTROL, 0,
894 create_options, &fid, &oplock, NULL, cifs_sb->local_nls, 960 &fid, &oplock, NULL, cifs_sb->local_nls,
895 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 961 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
896 if (!rc) { 962 if (!rc) {
897 rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen); 963 rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen);
898 CIFSSMBClose(xid, tcon, fid); 964 CIFSSMBClose(xid, tcon, fid);
899 } 965 }
900 966
901 cifs_put_tlink(tlink); 967 cifs_put_tlink(tlink);
902 free_xid(xid); 968 FreeXid(xid);
903 969
904 cFYI(1, "%s: rc = %d ACL len %d", __func__, rc, *pacllen); 970 cFYI(1, "%s: rc = %d ACL len %d", __func__, rc, *pacllen);
905 if (rc) 971 if (rc)
@@ -920,55 +986,55 @@ struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb,
920 if (!open_file) 986 if (!open_file)
921 return get_cifs_acl_by_path(cifs_sb, path, pacllen); 987 return get_cifs_acl_by_path(cifs_sb, path, pacllen);
922 988
923 pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->fid.netfid, pacllen); 989 pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen);
924 cifsFileInfo_put(open_file); 990 cifsFileInfo_put(open_file);
925 return pntsd; 991 return pntsd;
926} 992}
927 993
928 /* Set an ACL on the server */ 994static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path,
929int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, 995 struct cifs_ntsd *pnntsd, u32 acllen)
930 struct inode *inode, const char *path, int aclflag)
931{ 996{
932 int oplock = 0; 997 int oplock = 0;
933 unsigned int xid; 998 int xid, rc;
934 int rc, access_flags, create_options = 0;
935 __u16 fid; 999 __u16 fid;
936 struct cifs_tcon *tcon; 1000 struct cifs_tcon *tcon;
937 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
938 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); 1001 struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
939 1002
940 if (IS_ERR(tlink)) 1003 if (IS_ERR(tlink))
941 return PTR_ERR(tlink); 1004 return PTR_ERR(tlink);
942 1005
943 tcon = tlink_tcon(tlink); 1006 tcon = tlink_tcon(tlink);
944 xid = get_xid(); 1007 xid = GetXid();
945
946 if (backup_cred(cifs_sb))
947 create_options |= CREATE_OPEN_BACKUP_INTENT;
948
949 if (aclflag == CIFS_ACL_OWNER || aclflag == CIFS_ACL_GROUP)
950 access_flags = WRITE_OWNER;
951 else
952 access_flags = WRITE_DAC;
953 1008
954 rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, access_flags, 1009 rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, WRITE_DAC, 0,
955 create_options, &fid, &oplock, NULL, cifs_sb->local_nls, 1010 &fid, &oplock, NULL, cifs_sb->local_nls,
956 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 1011 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
957 if (rc) { 1012 if (rc) {
958 cERROR(1, "Unable to open file to set ACL"); 1013 cERROR(1, "Unable to open file to set ACL");
959 goto out; 1014 goto out;
960 } 1015 }
961 1016
962 rc = CIFSSMBSetCIFSACL(xid, tcon, fid, pnntsd, acllen, aclflag); 1017 rc = CIFSSMBSetCIFSACL(xid, tcon, fid, pnntsd, acllen);
963 cFYI(DBG2, "SetCIFSACL rc = %d", rc); 1018 cFYI(DBG2, "SetCIFSACL rc = %d", rc);
964 1019
965 CIFSSMBClose(xid, tcon, fid); 1020 CIFSSMBClose(xid, tcon, fid);
966out: 1021out:
967 free_xid(xid); 1022 FreeXid(xid);
968 cifs_put_tlink(tlink); 1023 cifs_put_tlink(tlink);
969 return rc; 1024 return rc;
970} 1025}
971 1026
1027/* Set an ACL on the server */
1028int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
1029 struct inode *inode, const char *path)
1030{
1031 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1032
1033 cFYI(DBG2, "set ACL for %s from mode 0x%x", path, inode->i_mode);
1034
1035 return set_cifs_acl_by_path(cifs_sb, path, pnntsd, acllen);
1036}
1037
972/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ 1038/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
973int 1039int
974cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, 1040cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
@@ -1000,12 +1066,9 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
1000} 1066}
1001 1067
1002/* Convert mode bits to an ACL so we can update the ACL on the server */ 1068/* Convert mode bits to an ACL so we can update the ACL on the server */
1003int 1069int mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode)
1004id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,
1005 uid_t uid, gid_t gid)
1006{ 1070{
1007 int rc = 0; 1071 int rc = 0;
1008 int aclflag = CIFS_ACL_DACL; /* default flag to set */
1009 __u32 secdesclen = 0; 1072 __u32 secdesclen = 0;
1010 struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */ 1073 struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */
1011 struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */ 1074 struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */
@@ -1014,39 +1077,40 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 nmode,
1014 1077
1015 /* Get the security descriptor */ 1078 /* Get the security descriptor */
1016 pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen); 1079 pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen);
1080
1081 /* Add three ACEs for owner, group, everyone getting rid of
1082 other ACEs as chmod disables ACEs and set the security descriptor */
1083
1017 if (IS_ERR(pntsd)) { 1084 if (IS_ERR(pntsd)) {
1018 rc = PTR_ERR(pntsd); 1085 rc = PTR_ERR(pntsd);
1019 cERROR(1, "%s: error %d getting sec desc", __func__, rc); 1086 cERROR(1, "%s: error %d getting sec desc", __func__, rc);
1020 goto out; 1087 } else {
1021 } 1088 /* allocate memory for the smb header,
1089 set security descriptor request security descriptor
1090 parameters, and secuirty descriptor itself */
1091
1092 secdesclen = secdesclen < DEFSECDESCLEN ?
1093 DEFSECDESCLEN : secdesclen;
1094 pnntsd = kmalloc(secdesclen, GFP_KERNEL);
1095 if (!pnntsd) {
1096 cERROR(1, "Unable to allocate security descriptor");
1097 kfree(pntsd);
1098 return -ENOMEM;
1099 }
1022 1100
1023 /* 1101 rc = build_sec_desc(pntsd, pnntsd, inode, nmode);
1024 * Add three ACEs for owner, group, everyone getting rid of other ACEs
1025 * as chmod disables ACEs and set the security descriptor. Allocate
1026 * memory for the smb header, set security descriptor request security
1027 * descriptor parameters, and secuirty descriptor itself
1028 */
1029 secdesclen = max_t(u32, secdesclen, DEFAULT_SEC_DESC_LEN);
1030 pnntsd = kmalloc(secdesclen, GFP_KERNEL);
1031 if (!pnntsd) {
1032 cERROR(1, "Unable to allocate security descriptor");
1033 kfree(pntsd);
1034 return -ENOMEM;
1035 }
1036 1102
1037 rc = build_sec_desc(pntsd, pnntsd, secdesclen, nmode, uid, gid, 1103 cFYI(DBG2, "build_sec_desc rc: %d", rc);
1038 &aclflag);
1039 1104
1040 cFYI(DBG2, "build_sec_desc rc: %d", rc); 1105 if (!rc) {
1106 /* Set the security descriptor */
1107 rc = set_cifs_acl(pnntsd, secdesclen, inode, path);
1108 cFYI(DBG2, "set_cifs_acl rc: %d", rc);
1109 }
1041 1110
1042 if (!rc) { 1111 kfree(pnntsd);
1043 /* Set the security descriptor */ 1112 kfree(pntsd);
1044 rc = set_cifs_acl(pnntsd, secdesclen, inode, path, aclflag);
1045 cFYI(DBG2, "set_cifs_acl rc: %d", rc);
1046 } 1113 }
1047 1114
1048 kfree(pnntsd);
1049 kfree(pntsd);
1050out:
1051 return rc; 1115 return rc;
1052} 1116}
diff --git a/fs/cifs/cifsacl.h b/fs/cifs/cifsacl.h
index 4f388483526..5c902c7ce52 100644
--- a/fs/cifs/cifsacl.h
+++ b/fs/cifs/cifsacl.h
@@ -23,8 +23,11 @@
23#define _CIFSACL_H 23#define _CIFSACL_H
24 24
25 25
26#define NUM_AUTHS (6) /* number of authority fields */ 26#define NUM_AUTHS 6 /* number of authority fields */
27#define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */ 27#define NUM_SUBAUTHS 5 /* number of sub authority fields */
28#define NUM_WK_SIDS 7 /* number of well known sids */
29#define SIDNAMELENGTH 20 /* long enough for the ones we care about */
30#define DEFSECDESCLEN 192 /* sec desc len contaiting a dacl with three aces */
28 31
29#define READ_BIT 0x4 32#define READ_BIT 0x4
30#define WRITE_BIT 0x2 33#define WRITE_BIT 0x2
@@ -38,32 +41,12 @@
38 41
39#define SIDOWNER 1 42#define SIDOWNER 1
40#define SIDGROUP 2 43#define SIDGROUP 2
44#define SIDLEN 150 /* S- 1 revision- 6 authorities- max 5 sub authorities */
41 45
42/* 46#define SID_ID_MAPPED 0
43 * Security Descriptor length containing DACL with 3 ACEs (one each for 47#define SID_ID_PENDING 1
44 * owner, group and world). 48#define SID_MAP_EXPIRE (3600 * HZ) /* map entry expires after one hour */
45 */ 49#define SID_MAP_RETRY (300 * HZ) /* wait 5 minutes for next attempt to map */
46#define DEFAULT_SEC_DESC_LEN (sizeof(struct cifs_ntsd) + \
47 sizeof(struct cifs_acl) + \
48 (sizeof(struct cifs_ace) * 3))
49
50/*
51 * Maximum size of a string representation of a SID:
52 *
53 * The fields are unsigned values in decimal. So:
54 *
55 * u8: max 3 bytes in decimal
56 * u32: max 10 bytes in decimal
57 *
58 * "S-" + 3 bytes for version field + 15 for authority field + NULL terminator
59 *
60 * For authority field, max is when all 6 values are non-zero and it must be
61 * represented in hex. So "-0x" + 12 hex digits.
62 *
63 * Add 11 bytes for each subauthority field (10 bytes each + 1 for '-')
64 */
65#define SID_STRING_BASE_SIZE (2 + 3 + 15 + 1)
66#define SID_STRING_SUBAUTH_SIZE (11) /* size of a single subauth string */
67 50
68struct cifs_ntsd { 51struct cifs_ntsd {
69 __le16 revision; /* revision level */ 52 __le16 revision; /* revision level */
@@ -77,13 +60,10 @@ struct cifs_ntsd {
77struct cifs_sid { 60struct cifs_sid {
78 __u8 revision; /* revision level */ 61 __u8 revision; /* revision level */
79 __u8 num_subauth; 62 __u8 num_subauth;
80 __u8 authority[NUM_AUTHS]; 63 __u8 authority[6];
81 __le32 sub_auth[SID_MAX_SUB_AUTHORITIES]; /* sub_auth[num_subauth] */ 64 __le32 sub_auth[5]; /* sub_auth[num_subauth] */
82} __attribute__((packed)); 65} __attribute__((packed));
83 66
84/* size of a struct cifs_sid, sans sub_auth array */
85#define CIFS_SID_BASE_SIZE (1 + 1 + NUM_AUTHS)
86
87struct cifs_acl { 67struct cifs_acl {
88 __le16 revision; /* revision level */ 68 __le16 revision; /* revision level */
89 __le16 size; 69 __le16 size;
@@ -98,4 +78,26 @@ struct cifs_ace {
98 struct cifs_sid sid; /* ie UUID of user or group who gets these perms */ 78 struct cifs_sid sid; /* ie UUID of user or group who gets these perms */
99} __attribute__((packed)); 79} __attribute__((packed));
100 80
81struct cifs_wksid {
82 struct cifs_sid cifssid;
83 char sidname[SIDNAMELENGTH];
84} __attribute__((packed));
85
86struct cifs_sid_id {
87 unsigned int refcount; /* increment with spinlock, decrement without */
88 unsigned long id;
89 unsigned long time;
90 unsigned long state;
91 char *sidstr;
92 struct rb_node rbnode;
93 struct cifs_sid sid;
94};
95
96#ifdef __KERNEL__
97extern struct key_type cifs_idmap_key_type;
98extern const struct cred *root_cred;
99#endif /* KERNEL */
100
101extern int compare_sids(const struct cifs_sid *, const struct cifs_sid *);
102
101#endif /* _CIFSACL_H */ 103#endif /* _CIFSACL_H */
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 652f5051be0..30acd22147e 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -29,7 +29,6 @@
29#include "ntlmssp.h" 29#include "ntlmssp.h"
30#include <linux/ctype.h> 30#include <linux/ctype.h>
31#include <linux/random.h> 31#include <linux/random.h>
32#include <linux/highmem.h>
33 32
34/* 33/*
35 * Calculate and return the CIFS signature based on the mac key and SMB PDU. 34 * Calculate and return the CIFS signature based on the mac key and SMB PDU.
@@ -38,32 +37,105 @@
38 * the sequence number before this function is called. Also, this function 37 * the sequence number before this function is called. Also, this function
39 * should be called with the server->srv_mutex held. 38 * should be called with the server->srv_mutex held.
40 */ 39 */
41static int cifs_calc_signature(struct smb_rqst *rqst, 40static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
42 struct TCP_Server_Info *server, char *signature) 41 struct TCP_Server_Info *server, char *signature)
42{
43 int rc;
44
45 if (cifs_pdu == NULL || signature == NULL || server == NULL)
46 return -EINVAL;
47
48 if (!server->secmech.sdescmd5) {
49 cERROR(1, "%s: Can't generate signature\n", __func__);
50 return -1;
51 }
52
53 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
54 if (rc) {
55 cERROR(1, "%s: Could not init md5\n", __func__);
56 return rc;
57 }
58
59 rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
60 server->session_key.response, server->session_key.len);
61 if (rc) {
62 cERROR(1, "%s: Could not update with response\n", __func__);
63 return rc;
64 }
65
66 rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
67 cifs_pdu->Protocol, be32_to_cpu(cifs_pdu->smb_buf_length));
68 if (rc) {
69 cERROR(1, "%s: Could not update with payload\n", __func__);
70 return rc;
71 }
72
73 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
74 if (rc)
75 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
76
77 return rc;
78}
79
80/* must be called with server->srv_mutex held */
81int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
82 __u32 *pexpected_response_sequence_number)
83{
84 int rc = 0;
85 char smb_signature[20];
86
87 if ((cifs_pdu == NULL) || (server == NULL))
88 return -EINVAL;
89
90 if (!(cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) ||
91 server->tcpStatus == CifsNeedNegotiate)
92 return rc;
93
94 if (!server->session_estab) {
95 strncpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8);
96 return rc;
97 }
98
99 cifs_pdu->Signature.Sequence.SequenceNumber =
100 cpu_to_le32(server->sequence_number);
101 cifs_pdu->Signature.Sequence.Reserved = 0;
102
103 *pexpected_response_sequence_number = server->sequence_number++;
104 server->sequence_number++;
105
106 rc = cifs_calculate_signature(cifs_pdu, server, smb_signature);
107 if (rc)
108 memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
109 else
110 memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);
111
112 return rc;
113}
114
115static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
116 struct TCP_Server_Info *server, char *signature)
43{ 117{
44 int i; 118 int i;
45 int rc; 119 int rc;
46 struct kvec *iov = rqst->rq_iov;
47 int n_vec = rqst->rq_nvec;
48 120
49 if (iov == NULL || signature == NULL || server == NULL) 121 if (iov == NULL || signature == NULL || server == NULL)
50 return -EINVAL; 122 return -EINVAL;
51 123
52 if (!server->secmech.sdescmd5) { 124 if (!server->secmech.sdescmd5) {
53 cERROR(1, "%s: Can't generate signature", __func__); 125 cERROR(1, "%s: Can't generate signature\n", __func__);
54 return -1; 126 return -1;
55 } 127 }
56 128
57 rc = crypto_shash_init(&server->secmech.sdescmd5->shash); 129 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
58 if (rc) { 130 if (rc) {
59 cERROR(1, "%s: Could not init md5", __func__); 131 cERROR(1, "%s: Could not init md5\n", __func__);
60 return rc; 132 return rc;
61 } 133 }
62 134
63 rc = crypto_shash_update(&server->secmech.sdescmd5->shash, 135 rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
64 server->session_key.response, server->session_key.len); 136 server->session_key.response, server->session_key.len);
65 if (rc) { 137 if (rc) {
66 cERROR(1, "%s: Could not update with response", __func__); 138 cERROR(1, "%s: Could not update with response\n", __func__);
67 return rc; 139 return rc;
68 } 140 }
69 141
@@ -88,36 +160,26 @@ static int cifs_calc_signature(struct smb_rqst *rqst,
88 iov[i].iov_base, iov[i].iov_len); 160 iov[i].iov_base, iov[i].iov_len);
89 } 161 }
90 if (rc) { 162 if (rc) {
91 cERROR(1, "%s: Could not update with payload", 163 cERROR(1, "%s: Could not update with payload\n",
92 __func__); 164 __func__);
93 return rc; 165 return rc;
94 } 166 }
95 } 167 }
96 168
97 /* now hash over the rq_pages array */
98 for (i = 0; i < rqst->rq_npages; i++) {
99 struct kvec p_iov;
100
101 cifs_rqst_page_to_kvec(rqst, i, &p_iov);
102 crypto_shash_update(&server->secmech.sdescmd5->shash,
103 p_iov.iov_base, p_iov.iov_len);
104 kunmap(rqst->rq_pages[i]);
105 }
106
107 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature); 169 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
108 if (rc) 170 if (rc)
109 cERROR(1, "%s: Could not generate md5 hash", __func__); 171 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
110 172
111 return rc; 173 return rc;
112} 174}
113 175
114/* must be called with server->srv_mutex held */ 176/* must be called with server->srv_mutex held */
115int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, 177int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
116 __u32 *pexpected_response_sequence_number) 178 __u32 *pexpected_response_sequence_number)
117{ 179{
118 int rc = 0; 180 int rc = 0;
119 char smb_signature[20]; 181 char smb_signature[20];
120 struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base; 182 struct smb_hdr *cifs_pdu = iov[0].iov_base;
121 183
122 if ((cifs_pdu == NULL) || (server == NULL)) 184 if ((cifs_pdu == NULL) || (server == NULL))
123 return -EINVAL; 185 return -EINVAL;
@@ -127,7 +189,7 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
127 return rc; 189 return rc;
128 190
129 if (!server->session_estab) { 191 if (!server->session_estab) {
130 memcpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8); 192 strncpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8);
131 return rc; 193 return rc;
132 } 194 }
133 195
@@ -138,7 +200,7 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
138 *pexpected_response_sequence_number = server->sequence_number++; 200 *pexpected_response_sequence_number = server->sequence_number++;
139 server->sequence_number++; 201 server->sequence_number++;
140 202
141 rc = cifs_calc_signature(rqst, server, smb_signature); 203 rc = cifs_calc_signature2(iov, n_vec, server, smb_signature);
142 if (rc) 204 if (rc)
143 memset(cifs_pdu->Signature.SecuritySignature, 0, 8); 205 memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
144 else 206 else
@@ -147,36 +209,13 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
147 return rc; 209 return rc;
148} 210}
149 211
150int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, 212int cifs_verify_signature(struct smb_hdr *cifs_pdu,
151 __u32 *pexpected_response_sequence)
152{
153 struct smb_rqst rqst = { .rq_iov = iov,
154 .rq_nvec = n_vec };
155
156 return cifs_sign_rqst(&rqst, server, pexpected_response_sequence);
157}
158
159/* must be called with server->srv_mutex held */
160int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
161 __u32 *pexpected_response_sequence_number)
162{
163 struct kvec iov;
164
165 iov.iov_base = cifs_pdu;
166 iov.iov_len = be32_to_cpu(cifs_pdu->smb_buf_length) + 4;
167
168 return cifs_sign_smbv(&iov, 1, server,
169 pexpected_response_sequence_number);
170}
171
172int cifs_verify_signature(struct smb_rqst *rqst,
173 struct TCP_Server_Info *server, 213 struct TCP_Server_Info *server,
174 __u32 expected_sequence_number) 214 __u32 expected_sequence_number)
175{ 215{
176 unsigned int rc; 216 unsigned int rc;
177 char server_response_sig[8]; 217 char server_response_sig[8];
178 char what_we_think_sig_should_be[20]; 218 char what_we_think_sig_should_be[20];
179 struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
180 219
181 if (cifs_pdu == NULL || server == NULL) 220 if (cifs_pdu == NULL || server == NULL)
182 return -EINVAL; 221 return -EINVAL;
@@ -208,7 +247,8 @@ int cifs_verify_signature(struct smb_rqst *rqst,
208 cifs_pdu->Signature.Sequence.Reserved = 0; 247 cifs_pdu->Signature.Sequence.Reserved = 0;
209 248
210 mutex_lock(&server->srv_mutex); 249 mutex_lock(&server->srv_mutex);
211 rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be); 250 rc = cifs_calculate_signature(cifs_pdu, server,
251 what_we_think_sig_should_be);
212 mutex_unlock(&server->srv_mutex); 252 mutex_unlock(&server->srv_mutex);
213 253
214 if (rc) 254 if (rc)
@@ -225,7 +265,7 @@ int cifs_verify_signature(struct smb_rqst *rqst,
225} 265}
226 266
227/* first calculate 24 bytes ntlm response and then 16 byte session key */ 267/* first calculate 24 bytes ntlm response and then 16 byte session key */
228int setup_ntlm_response(struct cifs_ses *ses, const struct nls_table *nls_cp) 268int setup_ntlm_response(struct cifs_ses *ses)
229{ 269{
230 int rc = 0; 270 int rc = 0;
231 unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE; 271 unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE;
@@ -242,14 +282,14 @@ int setup_ntlm_response(struct cifs_ses *ses, const struct nls_table *nls_cp)
242 ses->auth_key.len = temp_len; 282 ses->auth_key.len = temp_len;
243 283
244 rc = SMBNTencrypt(ses->password, ses->server->cryptkey, 284 rc = SMBNTencrypt(ses->password, ses->server->cryptkey,
245 ses->auth_key.response + CIFS_SESS_KEY_SIZE, nls_cp); 285 ses->auth_key.response + CIFS_SESS_KEY_SIZE);
246 if (rc) { 286 if (rc) {
247 cFYI(1, "%s Can't generate NTLM response, error: %d", 287 cFYI(1, "%s Can't generate NTLM response, error: %d",
248 __func__, rc); 288 __func__, rc);
249 return rc; 289 return rc;
250 } 290 }
251 291
252 rc = E_md4hash(ses->password, temp_key, nls_cp); 292 rc = E_md4hash(ses->password, temp_key);
253 if (rc) { 293 if (rc) {
254 cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc); 294 cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
255 return rc; 295 return rc;
@@ -348,7 +388,7 @@ build_avpair_blob(struct cifs_ses *ses, const struct nls_table *nls_cp)
348 attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME); 388 attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME);
349 attrptr->length = cpu_to_le16(2 * dlen); 389 attrptr->length = cpu_to_le16(2 * dlen);
350 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name); 390 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
351 cifs_strtoUTF16((__le16 *)blobptr, ses->domainName, dlen, nls_cp); 391 cifs_strtoUCS((__le16 *)blobptr, ses->domainName, dlen, nls_cp);
352 392
353 return 0; 393 return 0;
354} 394}
@@ -397,7 +437,7 @@ find_domain_name(struct cifs_ses *ses, const struct nls_table *nls_cp)
397 kmalloc(attrsize + 1, GFP_KERNEL); 437 kmalloc(attrsize + 1, GFP_KERNEL);
398 if (!ses->domainName) 438 if (!ses->domainName)
399 return -ENOMEM; 439 return -ENOMEM;
400 cifs_from_utf16(ses->domainName, 440 cifs_from_ucs2(ses->domainName,
401 (__le16 *)blobptr, attrsize, attrsize, 441 (__le16 *)blobptr, attrsize, attrsize,
402 nls_cp, false); 442 nls_cp, false);
403 break; 443 break;
@@ -420,12 +460,12 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
420 wchar_t *server; 460 wchar_t *server;
421 461
422 if (!ses->server->secmech.sdeschmacmd5) { 462 if (!ses->server->secmech.sdeschmacmd5) {
423 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash"); 463 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n");
424 return -1; 464 return -1;
425 } 465 }
426 466
427 /* calculate md4 hash of password */ 467 /* calculate md4 hash of password */
428 E_md4hash(ses->password, nt_hash, nls_cp); 468 E_md4hash(ses->password, nt_hash);
429 469
430 rc = crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash, 470 rc = crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash,
431 CIFS_NTHASH_SIZE); 471 CIFS_NTHASH_SIZE);
@@ -436,31 +476,26 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
436 476
437 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash); 477 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
438 if (rc) { 478 if (rc) {
439 cERROR(1, "calc_ntlmv2_hash: could not init hmacmd5"); 479 cERROR(1, "calc_ntlmv2_hash: could not init hmacmd5\n");
440 return rc; 480 return rc;
441 } 481 }
442 482
443 /* convert ses->user_name to unicode and uppercase */ 483 /* convert ses->user_name to unicode and uppercase */
444 len = ses->user_name ? strlen(ses->user_name) : 0; 484 len = strlen(ses->user_name);
445 user = kmalloc(2 + (len * 2), GFP_KERNEL); 485 user = kmalloc(2 + (len * 2), GFP_KERNEL);
446 if (user == NULL) { 486 if (user == NULL) {
447 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure"); 487 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n");
448 rc = -ENOMEM; 488 rc = -ENOMEM;
449 return rc; 489 return rc;
450 } 490 }
451 491 len = cifs_strtoUCS((__le16 *)user, ses->user_name, len, nls_cp);
452 if (len) { 492 UniStrupr(user);
453 len = cifs_strtoUTF16((__le16 *)user, ses->user_name, len, nls_cp);
454 UniStrupr(user);
455 } else {
456 memset(user, '\0', 2);
457 }
458 493
459 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 494 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
460 (char *)user, 2 * len); 495 (char *)user, 2 * len);
461 kfree(user); 496 kfree(user);
462 if (rc) { 497 if (rc) {
463 cERROR(1, "%s: Could not update with user", __func__); 498 cERROR(1, "%s: Could not update with user\n", __func__);
464 return rc; 499 return rc;
465 } 500 }
466 501
@@ -474,14 +509,14 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
474 rc = -ENOMEM; 509 rc = -ENOMEM;
475 return rc; 510 return rc;
476 } 511 }
477 len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len, 512 len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len,
478 nls_cp); 513 nls_cp);
479 rc = 514 rc =
480 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 515 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
481 (char *)domain, 2 * len); 516 (char *)domain, 2 * len);
482 kfree(domain); 517 kfree(domain);
483 if (rc) { 518 if (rc) {
484 cERROR(1, "%s: Could not update with domain", 519 cERROR(1, "%s: Could not update with domain\n",
485 __func__); 520 __func__);
486 return rc; 521 return rc;
487 } 522 }
@@ -494,14 +529,14 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
494 rc = -ENOMEM; 529 rc = -ENOMEM;
495 return rc; 530 return rc;
496 } 531 }
497 len = cifs_strtoUTF16((__le16 *)server, ses->serverName, len, 532 len = cifs_strtoUCS((__le16 *)server, ses->serverName, len,
498 nls_cp); 533 nls_cp);
499 rc = 534 rc =
500 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 535 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
501 (char *)server, 2 * len); 536 (char *)server, 2 * len);
502 kfree(server); 537 kfree(server);
503 if (rc) { 538 if (rc) {
504 cERROR(1, "%s: Could not update with server", 539 cERROR(1, "%s: Could not update with server\n",
505 __func__); 540 __func__);
506 return rc; 541 return rc;
507 } 542 }
@@ -510,7 +545,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
510 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash, 545 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
511 ntlmv2_hash); 546 ntlmv2_hash);
512 if (rc) 547 if (rc)
513 cERROR(1, "%s: Could not generate md5 hash", __func__); 548 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
514 549
515 return rc; 550 return rc;
516} 551}
@@ -522,7 +557,7 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
522 unsigned int offset = CIFS_SESS_KEY_SIZE + 8; 557 unsigned int offset = CIFS_SESS_KEY_SIZE + 8;
523 558
524 if (!ses->server->secmech.sdeschmacmd5) { 559 if (!ses->server->secmech.sdeschmacmd5) {
525 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash"); 560 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n");
526 return -1; 561 return -1;
527 } 562 }
528 563
@@ -548,14 +583,14 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
548 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 583 rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
549 ses->auth_key.response + offset, ses->auth_key.len - offset); 584 ses->auth_key.response + offset, ses->auth_key.len - offset);
550 if (rc) { 585 if (rc) {
551 cERROR(1, "%s: Could not update with response", __func__); 586 cERROR(1, "%s: Could not update with response\n", __func__);
552 return rc; 587 return rc;
553 } 588 }
554 589
555 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash, 590 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
556 ses->auth_key.response + CIFS_SESS_KEY_SIZE); 591 ses->auth_key.response + CIFS_SESS_KEY_SIZE);
557 if (rc) 592 if (rc)
558 cERROR(1, "%s: Could not generate md5 hash", __func__); 593 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
559 594
560 return rc; 595 return rc;
561} 596}
@@ -634,7 +669,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
634 669
635 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash); 670 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
636 if (rc) { 671 if (rc) {
637 cERROR(1, "%s: Could not init hmacmd5", __func__); 672 cERROR(1, "%s: Could not init hmacmd5\n", __func__);
638 goto setup_ntlmv2_rsp_ret; 673 goto setup_ntlmv2_rsp_ret;
639 } 674 }
640 675
@@ -642,14 +677,14 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
642 ses->auth_key.response + CIFS_SESS_KEY_SIZE, 677 ses->auth_key.response + CIFS_SESS_KEY_SIZE,
643 CIFS_HMAC_MD5_HASH_SIZE); 678 CIFS_HMAC_MD5_HASH_SIZE);
644 if (rc) { 679 if (rc) {
645 cERROR(1, "%s: Could not update with response", __func__); 680 cERROR(1, "%s: Could not update with response\n", __func__);
646 goto setup_ntlmv2_rsp_ret; 681 goto setup_ntlmv2_rsp_ret;
647 } 682 }
648 683
649 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash, 684 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
650 ses->auth_key.response); 685 ses->auth_key.response);
651 if (rc) 686 if (rc)
652 cERROR(1, "%s: Could not generate md5 hash", __func__); 687 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
653 688
654setup_ntlmv2_rsp_ret: 689setup_ntlmv2_rsp_ret:
655 kfree(tiblob); 690 kfree(tiblob);
@@ -671,7 +706,7 @@ calc_seckey(struct cifs_ses *ses)
671 tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); 706 tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
672 if (IS_ERR(tfm_arc4)) { 707 if (IS_ERR(tfm_arc4)) {
673 rc = PTR_ERR(tfm_arc4); 708 rc = PTR_ERR(tfm_arc4);
674 cERROR(1, "could not allocate crypto API arc4"); 709 cERROR(1, "could not allocate crypto API arc4\n");
675 return rc; 710 return rc;
676 } 711 }
677 712
@@ -689,7 +724,7 @@ calc_seckey(struct cifs_ses *ses)
689 724
690 rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, CIFS_CPHTXT_SIZE); 725 rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, CIFS_CPHTXT_SIZE);
691 if (rc) { 726 if (rc) {
692 cERROR(1, "could not encrypt session key rc: %d", rc); 727 cERROR(1, "could not encrypt session key rc: %d\n", rc);
693 crypto_free_blkcipher(tfm_arc4); 728 crypto_free_blkcipher(tfm_arc4);
694 return rc; 729 return rc;
695 } 730 }
@@ -707,17 +742,12 @@ calc_seckey(struct cifs_ses *ses)
707void 742void
708cifs_crypto_shash_release(struct TCP_Server_Info *server) 743cifs_crypto_shash_release(struct TCP_Server_Info *server)
709{ 744{
710 if (server->secmech.hmacsha256)
711 crypto_free_shash(server->secmech.hmacsha256);
712
713 if (server->secmech.md5) 745 if (server->secmech.md5)
714 crypto_free_shash(server->secmech.md5); 746 crypto_free_shash(server->secmech.md5);
715 747
716 if (server->secmech.hmacmd5) 748 if (server->secmech.hmacmd5)
717 crypto_free_shash(server->secmech.hmacmd5); 749 crypto_free_shash(server->secmech.hmacmd5);
718 750
719 kfree(server->secmech.sdeschmacsha256);
720
721 kfree(server->secmech.sdeschmacmd5); 751 kfree(server->secmech.sdeschmacmd5);
722 752
723 kfree(server->secmech.sdescmd5); 753 kfree(server->secmech.sdescmd5);
@@ -731,69 +761,46 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server)
731 761
732 server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0); 762 server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0);
733 if (IS_ERR(server->secmech.hmacmd5)) { 763 if (IS_ERR(server->secmech.hmacmd5)) {
734 cERROR(1, "could not allocate crypto hmacmd5"); 764 cERROR(1, "could not allocate crypto hmacmd5\n");
735 return PTR_ERR(server->secmech.hmacmd5); 765 return PTR_ERR(server->secmech.hmacmd5);
736 } 766 }
737 767
738 server->secmech.md5 = crypto_alloc_shash("md5", 0, 0); 768 server->secmech.md5 = crypto_alloc_shash("md5", 0, 0);
739 if (IS_ERR(server->secmech.md5)) { 769 if (IS_ERR(server->secmech.md5)) {
740 cERROR(1, "could not allocate crypto md5"); 770 cERROR(1, "could not allocate crypto md5\n");
741 rc = PTR_ERR(server->secmech.md5); 771 rc = PTR_ERR(server->secmech.md5);
742 goto crypto_allocate_md5_fail; 772 goto crypto_allocate_md5_fail;
743 } 773 }
744 774
745 server->secmech.hmacsha256 = crypto_alloc_shash("hmac(sha256)", 0, 0);
746 if (IS_ERR(server->secmech.hmacsha256)) {
747 cERROR(1, "could not allocate crypto hmacsha256\n");
748 rc = PTR_ERR(server->secmech.hmacsha256);
749 goto crypto_allocate_hmacsha256_fail;
750 }
751
752 size = sizeof(struct shash_desc) + 775 size = sizeof(struct shash_desc) +
753 crypto_shash_descsize(server->secmech.hmacmd5); 776 crypto_shash_descsize(server->secmech.hmacmd5);
754 server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); 777 server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL);
755 if (!server->secmech.sdeschmacmd5) { 778 if (!server->secmech.sdeschmacmd5) {
756 cERROR(1, "cifs_crypto_shash_allocate: can't alloc hmacmd5"); 779 cERROR(1, "cifs_crypto_shash_allocate: can't alloc hmacmd5\n");
757 rc = -ENOMEM; 780 rc = -ENOMEM;
758 goto crypto_allocate_hmacmd5_sdesc_fail; 781 goto crypto_allocate_hmacmd5_sdesc_fail;
759 } 782 }
760 server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5; 783 server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5;
761 server->secmech.sdeschmacmd5->shash.flags = 0x0; 784 server->secmech.sdeschmacmd5->shash.flags = 0x0;
762 785
786
763 size = sizeof(struct shash_desc) + 787 size = sizeof(struct shash_desc) +
764 crypto_shash_descsize(server->secmech.md5); 788 crypto_shash_descsize(server->secmech.md5);
765 server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL); 789 server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL);
766 if (!server->secmech.sdescmd5) { 790 if (!server->secmech.sdescmd5) {
767 cERROR(1, "cifs_crypto_shash_allocate: can't alloc md5"); 791 cERROR(1, "cifs_crypto_shash_allocate: can't alloc md5\n");
768 rc = -ENOMEM; 792 rc = -ENOMEM;
769 goto crypto_allocate_md5_sdesc_fail; 793 goto crypto_allocate_md5_sdesc_fail;
770 } 794 }
771 server->secmech.sdescmd5->shash.tfm = server->secmech.md5; 795 server->secmech.sdescmd5->shash.tfm = server->secmech.md5;
772 server->secmech.sdescmd5->shash.flags = 0x0; 796 server->secmech.sdescmd5->shash.flags = 0x0;
773 797
774 size = sizeof(struct shash_desc) +
775 crypto_shash_descsize(server->secmech.hmacsha256);
776 server->secmech.sdeschmacsha256 = kmalloc(size, GFP_KERNEL);
777 if (!server->secmech.sdeschmacsha256) {
778 cERROR(1, "%s: Can't alloc hmacsha256\n", __func__);
779 rc = -ENOMEM;
780 goto crypto_allocate_hmacsha256_sdesc_fail;
781 }
782 server->secmech.sdeschmacsha256->shash.tfm = server->secmech.hmacsha256;
783 server->secmech.sdeschmacsha256->shash.flags = 0x0;
784
785 return 0; 798 return 0;
786 799
787crypto_allocate_hmacsha256_sdesc_fail:
788 kfree(server->secmech.sdescmd5);
789
790crypto_allocate_md5_sdesc_fail: 800crypto_allocate_md5_sdesc_fail:
791 kfree(server->secmech.sdeschmacmd5); 801 kfree(server->secmech.sdeschmacmd5);
792 802
793crypto_allocate_hmacmd5_sdesc_fail: 803crypto_allocate_hmacmd5_sdesc_fail:
794 crypto_free_shash(server->secmech.hmacsha256);
795
796crypto_allocate_hmacsha256_fail:
797 crypto_free_shash(server->secmech.md5); 804 crypto_free_shash(server->secmech.md5);
798 805
799crypto_allocate_md5_fail: 806crypto_allocate_md5_fail:
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index de7f9168a11..54b8f1e7da9 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -36,7 +36,6 @@
36#include <linux/kthread.h> 36#include <linux/kthread.h>
37#include <linux/freezer.h> 37#include <linux/freezer.h>
38#include <linux/namei.h> 38#include <linux/namei.h>
39#include <linux/random.h>
40#include <net/ipv6.h> 39#include <net/ipv6.h>
41#include "cifsfs.h" 40#include "cifsfs.h"
42#include "cifspdu.h" 41#include "cifspdu.h"
@@ -49,48 +48,44 @@
49#include <linux/key-type.h> 48#include <linux/key-type.h>
50#include "cifs_spnego.h" 49#include "cifs_spnego.h"
51#include "fscache.h" 50#include "fscache.h"
52#ifdef CONFIG_CIFS_SMB2 51#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
53#include "smb2pdu.h"
54#endif
55 52
56int cifsFYI = 0; 53int cifsFYI = 0;
54int cifsERROR = 1;
57int traceSMB = 0; 55int traceSMB = 0;
58bool enable_oplocks = true; 56unsigned int oplockEnabled = 1;
59unsigned int linuxExtEnabled = 1; 57unsigned int linuxExtEnabled = 1;
60unsigned int lookupCacheEnabled = 1; 58unsigned int lookupCacheEnabled = 1;
59unsigned int multiuser_mount = 0;
61unsigned int global_secflags = CIFSSEC_DEF; 60unsigned int global_secflags = CIFSSEC_DEF;
62/* unsigned int ntlmv2_support = 0; */ 61/* unsigned int ntlmv2_support = 0; */
63unsigned int sign_CIFS_PDUs = 1; 62unsigned int sign_CIFS_PDUs = 1;
64static const struct super_operations cifs_super_ops; 63static const struct super_operations cifs_super_ops;
65unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE; 64unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
66module_param(CIFSMaxBufSize, uint, 0); 65module_param(CIFSMaxBufSize, int, 0);
67MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). " 66MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
68 "Default: 16384 Range: 8192 to 130048"); 67 "Default: 16384 Range: 8192 to 130048");
69unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL; 68unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
70module_param(cifs_min_rcv, uint, 0); 69module_param(cifs_min_rcv, int, 0);
71MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: " 70MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
72 "1 to 64"); 71 "1 to 64");
73unsigned int cifs_min_small = 30; 72unsigned int cifs_min_small = 30;
74module_param(cifs_min_small, uint, 0); 73module_param(cifs_min_small, int, 0);
75MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 " 74MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
76 "Range: 2 to 256"); 75 "Range: 2 to 256");
77unsigned int cifs_max_pending = CIFS_MAX_REQ; 76unsigned int cifs_max_pending = CIFS_MAX_REQ;
78module_param(cifs_max_pending, uint, 0444); 77module_param(cifs_max_pending, int, 0);
79MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. " 78MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
80 "Default: 32767 Range: 2 to 32767."); 79 "Default: 50 Range: 2 to 256");
81module_param(enable_oplocks, bool, 0644); 80unsigned short echo_retries = 5;
82MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks. Default: y/Y/1"); 81module_param(echo_retries, ushort, 0644);
83 82MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and "
83 "reconnecting server. Default: 5. 0 means "
84 "never reconnect.");
84extern mempool_t *cifs_sm_req_poolp; 85extern mempool_t *cifs_sm_req_poolp;
85extern mempool_t *cifs_req_poolp; 86extern mempool_t *cifs_req_poolp;
86extern mempool_t *cifs_mid_poolp; 87extern mempool_t *cifs_mid_poolp;
87 88
88struct workqueue_struct *cifsiod_wq;
89
90#ifdef CONFIG_CIFS_SMB2
91__u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE];
92#endif
93
94static int 89static int
95cifs_read_super(struct super_block *sb) 90cifs_read_super(struct super_block *sb)
96{ 91{
@@ -120,32 +115,37 @@ cifs_read_super(struct super_block *sb)
120 115
121 if (IS_ERR(inode)) { 116 if (IS_ERR(inode)) {
122 rc = PTR_ERR(inode); 117 rc = PTR_ERR(inode);
118 inode = NULL;
123 goto out_no_root; 119 goto out_no_root;
124 } 120 }
125 121
126 sb->s_root = d_make_root(inode); 122 sb->s_root = d_alloc_root(inode);
123
127 if (!sb->s_root) { 124 if (!sb->s_root) {
128 rc = -ENOMEM; 125 rc = -ENOMEM;
129 goto out_no_root; 126 goto out_no_root;
130 } 127 }
131 128
132 /* do that *after* d_make_root() - we want NULL ->d_op for root here */ 129 /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
133 if (cifs_sb_master_tcon(cifs_sb)->nocase) 130 if (cifs_sb_master_tcon(cifs_sb)->nocase)
134 sb->s_d_op = &cifs_ci_dentry_ops; 131 sb->s_d_op = &cifs_ci_dentry_ops;
135 else 132 else
136 sb->s_d_op = &cifs_dentry_ops; 133 sb->s_d_op = &cifs_dentry_ops;
137 134
138#ifdef CONFIG_CIFS_NFSD_EXPORT 135#ifdef CIFS_NFSD_EXPORT
139 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { 136 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
140 cFYI(1, "export ops supported"); 137 cFYI(1, "export ops supported");
141 sb->s_export_op = &cifs_export_ops; 138 sb->s_export_op = &cifs_export_ops;
142 } 139 }
143#endif /* CONFIG_CIFS_NFSD_EXPORT */ 140#endif /* CIFS_NFSD_EXPORT */
144 141
145 return 0; 142 return 0;
146 143
147out_no_root: 144out_no_root:
148 cERROR(1, "cifs_read_super: get root inode failed"); 145 cERROR(1, "cifs_read_super: get root inode failed");
146 if (inode)
147 iput(inode);
148
149 return rc; 149 return rc;
150} 150}
151 151
@@ -162,11 +162,12 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
162 struct super_block *sb = dentry->d_sb; 162 struct super_block *sb = dentry->d_sb;
163 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 163 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
164 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 164 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
165 struct TCP_Server_Info *server = tcon->ses->server; 165 int rc = -EOPNOTSUPP;
166 unsigned int xid; 166 int xid;
167 int rc = 0; 167
168 xid = GetXid();
168 169
169 xid = get_xid(); 170 buf->f_type = CIFS_MAGIC_NUMBER;
170 171
171 /* 172 /*
172 * PATH_MAX may be too long - it would presumably be total path, 173 * PATH_MAX may be too long - it would presumably be total path,
@@ -179,10 +180,29 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
179 buf->f_files = 0; /* undefined */ 180 buf->f_files = 0; /* undefined */
180 buf->f_ffree = 0; /* unlimited */ 181 buf->f_ffree = 0; /* unlimited */
181 182
182 if (server->ops->queryfs) 183 /*
183 rc = server->ops->queryfs(xid, tcon, buf); 184 * We could add a second check for a QFS Unix capability bit
185 */
186 if ((tcon->ses->capabilities & CAP_UNIX) &&
187 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
188 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
189
190 /*
191 * Only need to call the old QFSInfo if failed on newer one,
192 * e.g. by OS/2.
193 **/
194 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
195 rc = CIFSSMBQFSInfo(xid, tcon, buf);
196
197 /*
198 * Some old Windows servers also do not support level 103, retry with
199 * older level one if old server failed the previous call or we
200 * bypassed it because we detected that this was an older LANMAN sess
201 */
202 if (rc)
203 rc = SMBOldQFSInfo(xid, tcon, buf);
184 204
185 free_xid(xid); 205 FreeXid(xid);
186 return 0; 206 return 0;
187} 207}
188 208
@@ -221,10 +241,9 @@ cifs_alloc_inode(struct super_block *sb)
221 return NULL; 241 return NULL;
222 cifs_inode->cifsAttrs = 0x20; /* default */ 242 cifs_inode->cifsAttrs = 0x20; /* default */
223 cifs_inode->time = 0; 243 cifs_inode->time = 0;
224 /* 244 /* Until the file is open and we have gotten oplock
225 * Until the file is open and we have gotten oplock info back from the 245 info back from the server, can not assume caching of
226 * server, can not assume caching of file data or metadata. 246 file data or metadata */
227 */
228 cifs_set_oplock_level(cifs_inode, 0); 247 cifs_set_oplock_level(cifs_inode, 0);
229 cifs_inode->delete_pending = false; 248 cifs_inode->delete_pending = false;
230 cifs_inode->invalid_mapping = false; 249 cifs_inode->invalid_mapping = false;
@@ -232,22 +251,18 @@ cifs_alloc_inode(struct super_block *sb)
232 cifs_inode->server_eof = 0; 251 cifs_inode->server_eof = 0;
233 cifs_inode->uniqueid = 0; 252 cifs_inode->uniqueid = 0;
234 cifs_inode->createtime = 0; 253 cifs_inode->createtime = 0;
235#ifdef CONFIG_CIFS_SMB2 254
236 get_random_bytes(cifs_inode->lease_key, SMB2_LEASE_KEY_SIZE); 255 /* Can not set i_flags here - they get immediately overwritten
237#endif 256 to zero by the VFS */
238 /* 257/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
239 * Can not set i_flags here - they get immediately overwritten to zero
240 * by the VFS.
241 */
242 /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME; */
243 INIT_LIST_HEAD(&cifs_inode->openFileList); 258 INIT_LIST_HEAD(&cifs_inode->openFileList);
244 INIT_LIST_HEAD(&cifs_inode->llist);
245 return &cifs_inode->vfs_inode; 259 return &cifs_inode->vfs_inode;
246} 260}
247 261
248static void cifs_i_callback(struct rcu_head *head) 262static void cifs_i_callback(struct rcu_head *head)
249{ 263{
250 struct inode *inode = container_of(head, struct inode, i_rcu); 264 struct inode *inode = container_of(head, struct inode, i_rcu);
265 INIT_LIST_HEAD(&inode->i_dentry);
251 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode)); 266 kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
252} 267}
253 268
@@ -261,7 +276,7 @@ static void
261cifs_evict_inode(struct inode *inode) 276cifs_evict_inode(struct inode *inode)
262{ 277{
263 truncate_inode_pages(&inode->i_data, 0); 278 truncate_inode_pages(&inode->i_data, 0);
264 clear_inode(inode); 279 end_writeback(inode);
265 cifs_fscache_release_inode_cookie(inode); 280 cifs_fscache_release_inode_cookie(inode);
266} 281}
267 282
@@ -318,38 +333,22 @@ cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
318 seq_printf(s, "i"); 333 seq_printf(s, "i");
319} 334}
320 335
321static void
322cifs_show_cache_flavor(struct seq_file *s, struct cifs_sb_info *cifs_sb)
323{
324 seq_printf(s, ",cache=");
325
326 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
327 seq_printf(s, "strict");
328 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
329 seq_printf(s, "none");
330 else
331 seq_printf(s, "loose");
332}
333
334/* 336/*
335 * cifs_show_options() is for displaying mount options in /proc/mounts. 337 * cifs_show_options() is for displaying mount options in /proc/mounts.
336 * Not all settable options are displayed but most of the important 338 * Not all settable options are displayed but most of the important
337 * ones are. 339 * ones are.
338 */ 340 */
339static int 341static int
340cifs_show_options(struct seq_file *s, struct dentry *root) 342cifs_show_options(struct seq_file *s, struct vfsmount *m)
341{ 343{
342 struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb); 344 struct cifs_sb_info *cifs_sb = CIFS_SB(m->mnt_sb);
343 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 345 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
344 struct sockaddr *srcaddr; 346 struct sockaddr *srcaddr;
345 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr; 347 srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
346 348
347 seq_printf(s, ",vers=%s", tcon->ses->server->vals->version_string);
348 cifs_show_security(s, tcon->ses->server); 349 cifs_show_security(s, tcon->ses->server);
349 cifs_show_cache_flavor(s, cifs_sb);
350 350
351 seq_printf(s, ",unc="); 351 seq_printf(s, ",unc=%s", tcon->treeName);
352 seq_escape(s, tcon->treeName, " \t\n\\");
353 352
354 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) 353 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
355 seq_printf(s, ",multiuser"); 354 seq_printf(s, ",multiuser");
@@ -375,13 +374,13 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
375 (int)(srcaddr->sa_family)); 374 (int)(srcaddr->sa_family));
376 } 375 }
377 376
378 seq_printf(s, ",uid=%u", cifs_sb->mnt_uid); 377 seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
379 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) 378 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
380 seq_printf(s, ",forceuid"); 379 seq_printf(s, ",forceuid");
381 else 380 else
382 seq_printf(s, ",noforceuid"); 381 seq_printf(s, ",noforceuid");
383 382
384 seq_printf(s, ",gid=%u", cifs_sb->mnt_gid); 383 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
385 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) 384 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
386 seq_printf(s, ",forcegid"); 385 seq_printf(s, ",forcegid");
387 else 386 else
@@ -390,7 +389,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
390 cifs_show_address(s, tcon->ses->server); 389 cifs_show_address(s, tcon->ses->server);
391 390
392 if (!tcon->unix_ext) 391 if (!tcon->unix_ext)
393 seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho", 392 seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
394 cifs_sb->mnt_file_mode, 393 cifs_sb->mnt_file_mode,
395 cifs_sb->mnt_dir_mode); 394 cifs_sb->mnt_dir_mode);
396 if (tcon->seal) 395 if (tcon->seal)
@@ -413,6 +412,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
413 seq_printf(s, ",rwpidforward"); 412 seq_printf(s, ",rwpidforward");
414 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) 413 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
415 seq_printf(s, ",forcemand"); 414 seq_printf(s, ",forcemand");
415 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
416 seq_printf(s, ",directio");
416 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 417 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
417 seq_printf(s, ",nouser_xattr"); 418 seq_printf(s, ",nouser_xattr");
418 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR) 419 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
@@ -425,25 +426,17 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
425 seq_printf(s, ",cifsacl"); 426 seq_printf(s, ",cifsacl");
426 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) 427 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
427 seq_printf(s, ",dynperm"); 428 seq_printf(s, ",dynperm");
428 if (root->d_sb->s_flags & MS_POSIXACL) 429 if (m->mnt_sb->s_flags & MS_POSIXACL)
429 seq_printf(s, ",acl"); 430 seq_printf(s, ",acl");
430 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) 431 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
431 seq_printf(s, ",mfsymlinks"); 432 seq_printf(s, ",mfsymlinks");
432 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE) 433 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
433 seq_printf(s, ",fsc"); 434 seq_printf(s, ",fsc");
434 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC) 435
435 seq_printf(s, ",nostrictsync"); 436 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
436 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) 437 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
437 seq_printf(s, ",noperm");
438 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
439 seq_printf(s, ",backupuid=%u", cifs_sb->mnt_backupuid);
440 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
441 seq_printf(s, ",backupgid=%u", cifs_sb->mnt_backupgid);
442
443 seq_printf(s, ",rsize=%u", cifs_sb->rsize);
444 seq_printf(s, ",wsize=%u", cifs_sb->wsize);
445 /* convert actimeo and display it in seconds */ 438 /* convert actimeo and display it in seconds */
446 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ); 439 seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
447 440
448 return 0; 441 return 0;
449} 442}
@@ -485,7 +478,7 @@ static void cifs_umount_begin(struct super_block *sb)
485} 478}
486 479
487#ifdef CONFIG_CIFS_STATS2 480#ifdef CONFIG_CIFS_STATS2
488static int cifs_show_stats(struct seq_file *s, struct dentry *root) 481static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
489{ 482{
490 /* BB FIXME */ 483 /* BB FIXME */
491 return 0; 484 return 0;
@@ -537,6 +530,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
537 char *full_path = NULL; 530 char *full_path = NULL;
538 char *s, *p; 531 char *s, *p;
539 char sep; 532 char sep;
533 int xid;
540 534
541 full_path = cifs_build_path_to_root(vol, cifs_sb, 535 full_path = cifs_build_path_to_root(vol, cifs_sb,
542 cifs_sb_master_tcon(cifs_sb)); 536 cifs_sb_master_tcon(cifs_sb));
@@ -545,6 +539,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
545 539
546 cFYI(1, "Get root dentry for %s", full_path); 540 cFYI(1, "Get root dentry for %s", full_path);
547 541
542 xid = GetXid();
548 sep = CIFS_DIR_SEP(cifs_sb); 543 sep = CIFS_DIR_SEP(cifs_sb);
549 dentry = dget(sb->s_root); 544 dentry = dget(sb->s_root);
550 p = s = full_path; 545 p = s = full_path;
@@ -575,6 +570,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
575 dput(dentry); 570 dput(dentry);
576 dentry = child; 571 dentry = child;
577 } while (!IS_ERR(dentry)); 572 } while (!IS_ERR(dentry));
573 _FreeXid(xid);
578 kfree(full_path); 574 kfree(full_path);
579 return dentry; 575 return dentry;
580} 576}
@@ -629,10 +625,7 @@ cifs_do_mount(struct file_system_type *fs_type,
629 mnt_data.cifs_sb = cifs_sb; 625 mnt_data.cifs_sb = cifs_sb;
630 mnt_data.flags = flags; 626 mnt_data.flags = flags;
631 627
632 /* BB should we make this contingent on mount parm? */ 628 sb = sget(fs_type, cifs_match_super, cifs_set_super, &mnt_data);
633 flags |= MS_NODIRATIME | MS_NOATIME;
634
635 sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
636 if (IS_ERR(sb)) { 629 if (IS_ERR(sb)) {
637 root = ERR_CAST(sb); 630 root = ERR_CAST(sb);
638 cifs_umount(cifs_sb); 631 cifs_umount(cifs_sb);
@@ -643,6 +636,10 @@ cifs_do_mount(struct file_system_type *fs_type,
643 cFYI(1, "Use existing superblock"); 636 cFYI(1, "Use existing superblock");
644 cifs_umount(cifs_sb); 637 cifs_umount(cifs_sb);
645 } else { 638 } else {
639 sb->s_flags = flags;
640 /* BB should we make this contingent on mount parm? */
641 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
642
646 rc = cifs_read_super(sb); 643 rc = cifs_read_super(sb);
647 if (rc) { 644 if (rc) {
648 root = ERR_PTR(rc); 645 root = ERR_PTR(rc);
@@ -693,13 +690,13 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
693 return written; 690 return written;
694} 691}
695 692
696static loff_t cifs_llseek(struct file *file, loff_t offset, int whence) 693static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
697{ 694{
698 /* 695 /*
699 * whence == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate 696 * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
700 * the cached file length 697 * the cached file length
701 */ 698 */
702 if (whence != SEEK_SET && whence != SEEK_CUR) { 699 if (origin != SEEK_SET || origin != SEEK_CUR) {
703 int rc; 700 int rc;
704 struct inode *inode = file->f_path.dentry->d_inode; 701 struct inode *inode = file->f_path.dentry->d_inode;
705 702
@@ -726,7 +723,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int whence)
726 if (rc < 0) 723 if (rc < 0)
727 return (loff_t)rc; 724 return (loff_t)rc;
728 } 725 }
729 return generic_file_llseek(file, offset, whence); 726 return generic_file_llseek_unlocked(file, offset, origin);
730} 727}
731 728
732static int cifs_setlease(struct file *file, long arg, struct file_lock **lease) 729static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
@@ -768,7 +765,6 @@ struct file_system_type cifs_fs_type = {
768}; 765};
769const struct inode_operations cifs_dir_inode_ops = { 766const struct inode_operations cifs_dir_inode_ops = {
770 .create = cifs_create, 767 .create = cifs_create,
771 .atomic_open = cifs_atomic_open,
772 .lookup = cifs_lookup, 768 .lookup = cifs_lookup,
773 .getattr = cifs_getattr, 769 .getattr = cifs_getattr,
774 .unlink = cifs_unlink, 770 .unlink = cifs_unlink,
@@ -946,7 +942,7 @@ cifs_init_once(void *inode)
946 struct cifsInodeInfo *cifsi = inode; 942 struct cifsInodeInfo *cifsi = inode;
947 943
948 inode_init_once(&cifsi->vfs_inode); 944 inode_init_once(&cifsi->vfs_inode);
949 init_rwsem(&cifsi->lock_sem); 945 INIT_LIST_HEAD(&cifsi->lockList);
950} 946}
951 947
952static int 948static int
@@ -966,25 +962,12 @@ cifs_init_inodecache(void)
966static void 962static void
967cifs_destroy_inodecache(void) 963cifs_destroy_inodecache(void)
968{ 964{
969 /*
970 * Make sure all delayed rcu free inodes are flushed before we
971 * destroy cache.
972 */
973 rcu_barrier();
974 kmem_cache_destroy(cifs_inode_cachep); 965 kmem_cache_destroy(cifs_inode_cachep);
975} 966}
976 967
977static int 968static int
978cifs_init_request_bufs(void) 969cifs_init_request_bufs(void)
979{ 970{
980 size_t max_hdr_size = MAX_CIFS_HDR_SIZE;
981#ifdef CONFIG_CIFS_SMB2
982 /*
983 * SMB2 maximum header size is bigger than CIFS one - no problems to
984 * allocate some more bytes for CIFS.
985 */
986 max_hdr_size = MAX_SMB2_HDR_SIZE;
987#endif
988 if (CIFSMaxBufSize < 8192) { 971 if (CIFSMaxBufSize < 8192) {
989 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum 972 /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
990 Unicode path name has to fit in any SMB/CIFS path based frames */ 973 Unicode path name has to fit in any SMB/CIFS path based frames */
@@ -996,7 +979,8 @@ cifs_init_request_bufs(void)
996 } 979 }
997/* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */ 980/* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
998 cifs_req_cachep = kmem_cache_create("cifs_request", 981 cifs_req_cachep = kmem_cache_create("cifs_request",
999 CIFSMaxBufSize + max_hdr_size, 0, 982 CIFSMaxBufSize +
983 MAX_CIFS_HDR_SIZE, 0,
1000 SLAB_HWCACHE_ALIGN, NULL); 984 SLAB_HWCACHE_ALIGN, NULL);
1001 if (cifs_req_cachep == NULL) 985 if (cifs_req_cachep == NULL)
1002 return -ENOMEM; 986 return -ENOMEM;
@@ -1121,27 +1105,17 @@ init_cifs(void)
1121 spin_lock_init(&cifs_file_list_lock); 1105 spin_lock_init(&cifs_file_list_lock);
1122 spin_lock_init(&GlobalMid_Lock); 1106 spin_lock_init(&GlobalMid_Lock);
1123 1107
1124#ifdef CONFIG_CIFS_SMB2
1125 get_random_bytes(cifs_client_guid, SMB2_CLIENT_GUID_SIZE);
1126#endif
1127
1128 if (cifs_max_pending < 2) { 1108 if (cifs_max_pending < 2) {
1129 cifs_max_pending = 2; 1109 cifs_max_pending = 2;
1130 cFYI(1, "cifs_max_pending set to min of 2"); 1110 cFYI(1, "cifs_max_pending set to min of 2");
1131 } else if (cifs_max_pending > CIFS_MAX_REQ) { 1111 } else if (cifs_max_pending > 256) {
1132 cifs_max_pending = CIFS_MAX_REQ; 1112 cifs_max_pending = 256;
1133 cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ); 1113 cFYI(1, "cifs_max_pending set to max of 256");
1134 }
1135
1136 cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
1137 if (!cifsiod_wq) {
1138 rc = -ENOMEM;
1139 goto out_clean_proc;
1140 } 1114 }
1141 1115
1142 rc = cifs_fscache_register(); 1116 rc = cifs_fscache_register();
1143 if (rc) 1117 if (rc)
1144 goto out_destroy_wq; 1118 goto out_clean_proc;
1145 1119
1146 rc = cifs_init_inodecache(); 1120 rc = cifs_init_inodecache();
1147 if (rc) 1121 if (rc)
@@ -1189,8 +1163,6 @@ out_destroy_inodecache:
1189 cifs_destroy_inodecache(); 1163 cifs_destroy_inodecache();
1190out_unreg_fscache: 1164out_unreg_fscache:
1191 cifs_fscache_unregister(); 1165 cifs_fscache_unregister();
1192out_destroy_wq:
1193 destroy_workqueue(cifsiod_wq);
1194out_clean_proc: 1166out_clean_proc:
1195 cifs_proc_clean(); 1167 cifs_proc_clean();
1196 return rc; 1168 return rc;
@@ -1200,20 +1172,22 @@ static void __exit
1200exit_cifs(void) 1172exit_cifs(void)
1201{ 1173{
1202 cFYI(DBG2, "exit_cifs"); 1174 cFYI(DBG2, "exit_cifs");
1203 unregister_filesystem(&cifs_fs_type); 1175 cifs_proc_clean();
1176 cifs_fscache_unregister();
1177#ifdef CONFIG_CIFS_DFS_UPCALL
1204 cifs_dfs_release_automount_timer(); 1178 cifs_dfs_release_automount_timer();
1179#endif
1205#ifdef CONFIG_CIFS_ACL 1180#ifdef CONFIG_CIFS_ACL
1181 cifs_destroy_idmaptrees();
1206 exit_cifs_idmap(); 1182 exit_cifs_idmap();
1207#endif 1183#endif
1208#ifdef CONFIG_CIFS_UPCALL 1184#ifdef CONFIG_CIFS_UPCALL
1209 unregister_key_type(&cifs_spnego_key_type); 1185 unregister_key_type(&cifs_spnego_key_type);
1210#endif 1186#endif
1211 cifs_destroy_request_bufs(); 1187 unregister_filesystem(&cifs_fs_type);
1212 cifs_destroy_mids();
1213 cifs_destroy_inodecache(); 1188 cifs_destroy_inodecache();
1214 cifs_fscache_unregister(); 1189 cifs_destroy_mids();
1215 destroy_workqueue(cifsiod_wq); 1190 cifs_destroy_request_bufs();
1216 cifs_proc_clean();
1217} 1191}
1218 1192
1219MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>"); 1193MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 7163419cecd..95da8027983 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -44,17 +44,14 @@ extern const struct address_space_operations cifs_addr_ops_smallbuf;
44/* Functions related to inodes */ 44/* Functions related to inodes */
45extern const struct inode_operations cifs_dir_inode_ops; 45extern const struct inode_operations cifs_dir_inode_ops;
46extern struct inode *cifs_root_iget(struct super_block *); 46extern struct inode *cifs_root_iget(struct super_block *);
47extern int cifs_create(struct inode *, struct dentry *, umode_t, 47extern int cifs_create(struct inode *, struct dentry *, int,
48 bool excl); 48 struct nameidata *);
49extern int cifs_atomic_open(struct inode *, struct dentry *,
50 struct file *, unsigned, umode_t,
51 int *);
52extern struct dentry *cifs_lookup(struct inode *, struct dentry *, 49extern struct dentry *cifs_lookup(struct inode *, struct dentry *,
53 unsigned int); 50 struct nameidata *);
54extern int cifs_unlink(struct inode *dir, struct dentry *dentry); 51extern int cifs_unlink(struct inode *dir, struct dentry *dentry);
55extern int cifs_hardlink(struct dentry *, struct inode *, struct dentry *); 52extern int cifs_hardlink(struct dentry *, struct inode *, struct dentry *);
56extern int cifs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 53extern int cifs_mknod(struct inode *, struct dentry *, int, dev_t);
57extern int cifs_mkdir(struct inode *, struct dentry *, umode_t); 54extern int cifs_mkdir(struct inode *, struct dentry *, int);
58extern int cifs_rmdir(struct inode *, struct dentry *); 55extern int cifs_rmdir(struct inode *, struct dentry *);
59extern int cifs_rename(struct inode *, struct dentry *, struct inode *, 56extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
60 struct dentry *); 57 struct dentry *);
@@ -124,9 +121,9 @@ extern ssize_t cifs_getxattr(struct dentry *, const char *, void *, size_t);
124extern ssize_t cifs_listxattr(struct dentry *, char *, size_t); 121extern ssize_t cifs_listxattr(struct dentry *, char *, size_t);
125extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); 122extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
126 123
127#ifdef CONFIG_CIFS_NFSD_EXPORT 124#ifdef CIFS_NFSD_EXPORT
128extern const struct export_operations cifs_export_ops; 125extern const struct export_operations cifs_export_ops;
129#endif /* CONFIG_CIFS_NFSD_EXPORT */ 126#endif /* CIFS_NFSD_EXPORT */
130 127
131#define CIFS_VERSION "2.0" 128#define CIFS_VERSION "1.75"
132#endif /* _CIFSFS_H */ 129#endif /* _CIFSFS_H */
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index e6899cea1c3..95dad9d14cf 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -22,17 +22,11 @@
22#include <linux/in.h> 22#include <linux/in.h>
23#include <linux/in6.h> 23#include <linux/in6.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/mempool.h>
26#include <linux/workqueue.h> 25#include <linux/workqueue.h>
27#include "cifs_fs_sb.h" 26#include "cifs_fs_sb.h"
28#include "cifsacl.h" 27#include "cifsacl.h"
29#include <crypto/internal/hash.h> 28#include <crypto/internal/hash.h>
30#include <linux/scatterlist.h> 29#include <linux/scatterlist.h>
31#ifdef CONFIG_CIFS_SMB2
32#include "smb2pdu.h"
33#endif
34
35#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
36 30
37/* 31/*
38 * The sizes of various internal tables and strings 32 * The sizes of various internal tables and strings
@@ -49,7 +43,6 @@
49 43
50#define CIFS_MIN_RCV_POOL 4 44#define CIFS_MIN_RCV_POOL 4
51 45
52#define MAX_REOPEN_ATT 5 /* these many maximum attempts to reopen a file */
53/* 46/*
54 * default attribute cache timeout (jiffies) 47 * default attribute cache timeout (jiffies)
55 */ 48 */
@@ -62,9 +55,14 @@
62 55
63/* 56/*
64 * MAX_REQ is the maximum number of requests that WE will send 57 * MAX_REQ is the maximum number of requests that WE will send
65 * on one socket concurrently. 58 * on one socket concurrently. It also matches the most common
59 * value of max multiplex returned by servers. We may
60 * eventually want to use the negotiated value (in case
61 * future servers can handle more) when we are more confident that
62 * we will not have problems oveloading the socket with pending
63 * write data.
66 */ 64 */
67#define CIFS_MAX_REQ 32767 65#define CIFS_MAX_REQ 50
68 66
69#define RFC1001_NAME_LEN 15 67#define RFC1001_NAME_LEN 15
70#define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1) 68#define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
@@ -78,9 +76,6 @@
78/* (max path length + 1 for null) * 2 for unicode */ 76/* (max path length + 1 for null) * 2 for unicode */
79#define MAX_NAME 514 77#define MAX_NAME 514
80 78
81/* SMB echo "timeout" -- FIXME: tunable? */
82#define SMB_ECHO_INTERVAL (60 * HZ)
83
84#include "cifspdu.h" 79#include "cifspdu.h"
85 80
86#ifndef XATTR_DOS_ATTRIB 81#ifndef XATTR_DOS_ATTRIB
@@ -130,10 +125,8 @@ struct sdesc {
130struct cifs_secmech { 125struct cifs_secmech {
131 struct crypto_shash *hmacmd5; /* hmac-md5 hash function */ 126 struct crypto_shash *hmacmd5; /* hmac-md5 hash function */
132 struct crypto_shash *md5; /* md5 hash function */ 127 struct crypto_shash *md5; /* md5 hash function */
133 struct crypto_shash *hmacsha256; /* hmac-sha256 hash function */
134 struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */ 128 struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */
135 struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */ 129 struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */
136 struct sdesc *sdeschmacsha256; /* ctxt to generate smb2 signature */
137}; 130};
138 131
139/* per smb session structure/fields */ 132/* per smb session structure/fields */
@@ -162,251 +155,20 @@ struct cifs_cred {
162 ***************************************************************** 155 *****************************************************************
163 */ 156 */
164 157
165/*
166 * A smb_rqst represents a complete request to be issued to a server. It's
167 * formed by a kvec array, followed by an array of pages. Page data is assumed
168 * to start at the beginning of the first page.
169 */
170struct smb_rqst {
171 struct kvec *rq_iov; /* array of kvecs */
172 unsigned int rq_nvec; /* number of kvecs in array */
173 struct page **rq_pages; /* pointer to array of page ptrs */
174 unsigned int rq_npages; /* number pages in array */
175 unsigned int rq_pagesz; /* page size to use */
176 unsigned int rq_tailsz; /* length of last page */
177};
178
179enum smb_version {
180 Smb_1 = 1,
181 Smb_20,
182 Smb_21,
183 Smb_30,
184};
185
186struct mid_q_entry;
187struct TCP_Server_Info;
188struct cifsFileInfo;
189struct cifs_ses;
190struct cifs_tcon;
191struct dfs_info3_param;
192struct cifs_fattr;
193struct smb_vol;
194struct cifs_fid;
195struct cifs_readdata;
196struct cifs_writedata;
197struct cifs_io_parms;
198struct cifs_search_info;
199struct cifsInodeInfo;
200
201struct smb_version_operations {
202 int (*send_cancel)(struct TCP_Server_Info *, void *,
203 struct mid_q_entry *);
204 bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
205 /* setup request: allocate mid, sign message */
206 struct mid_q_entry *(*setup_request)(struct cifs_ses *,
207 struct smb_rqst *);
208 /* setup async request: allocate mid, sign message */
209 struct mid_q_entry *(*setup_async_request)(struct TCP_Server_Info *,
210 struct smb_rqst *);
211 /* check response: verify signature, map error */
212 int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *,
213 bool);
214 void (*add_credits)(struct TCP_Server_Info *, const unsigned int,
215 const int);
216 void (*set_credits)(struct TCP_Server_Info *, const int);
217 int * (*get_credits_field)(struct TCP_Server_Info *, const int);
218 unsigned int (*get_credits)(struct mid_q_entry *);
219 __u64 (*get_next_mid)(struct TCP_Server_Info *);
220 /* data offset from read response message */
221 unsigned int (*read_data_offset)(char *);
222 /* data length from read response message */
223 unsigned int (*read_data_length)(char *);
224 /* map smb to linux error */
225 int (*map_error)(char *, bool);
226 /* find mid corresponding to the response message */
227 struct mid_q_entry * (*find_mid)(struct TCP_Server_Info *, char *);
228 void (*dump_detail)(void *);
229 void (*clear_stats)(struct cifs_tcon *);
230 void (*print_stats)(struct seq_file *m, struct cifs_tcon *);
231 /* verify the message */
232 int (*check_message)(char *, unsigned int);
233 bool (*is_oplock_break)(char *, struct TCP_Server_Info *);
234 /* process transaction2 response */
235 bool (*check_trans2)(struct mid_q_entry *, struct TCP_Server_Info *,
236 char *, int);
237 /* check if we need to negotiate */
238 bool (*need_neg)(struct TCP_Server_Info *);
239 /* negotiate to the server */
240 int (*negotiate)(const unsigned int, struct cifs_ses *);
241 /* set negotiated write size */
242 unsigned int (*negotiate_wsize)(struct cifs_tcon *, struct smb_vol *);
243 /* set negotiated read size */
244 unsigned int (*negotiate_rsize)(struct cifs_tcon *, struct smb_vol *);
245 /* setup smb sessionn */
246 int (*sess_setup)(const unsigned int, struct cifs_ses *,
247 const struct nls_table *);
248 /* close smb session */
249 int (*logoff)(const unsigned int, struct cifs_ses *);
250 /* connect to a server share */
251 int (*tree_connect)(const unsigned int, struct cifs_ses *, const char *,
252 struct cifs_tcon *, const struct nls_table *);
253 /* close tree connecion */
254 int (*tree_disconnect)(const unsigned int, struct cifs_tcon *);
255 /* get DFS referrals */
256 int (*get_dfs_refer)(const unsigned int, struct cifs_ses *,
257 const char *, struct dfs_info3_param **,
258 unsigned int *, const struct nls_table *, int);
259 /* informational QFS call */
260 void (*qfs_tcon)(const unsigned int, struct cifs_tcon *);
261 /* check if a path is accessible or not */
262 int (*is_path_accessible)(const unsigned int, struct cifs_tcon *,
263 struct cifs_sb_info *, const char *);
264 /* query path data from the server */
265 int (*query_path_info)(const unsigned int, struct cifs_tcon *,
266 struct cifs_sb_info *, const char *,
267 FILE_ALL_INFO *, bool *);
268 /* query file data from the server */
269 int (*query_file_info)(const unsigned int, struct cifs_tcon *,
270 struct cifs_fid *, FILE_ALL_INFO *);
271 /* get server index number */
272 int (*get_srv_inum)(const unsigned int, struct cifs_tcon *,
273 struct cifs_sb_info *, const char *,
274 u64 *uniqueid, FILE_ALL_INFO *);
275 /* set size by path */
276 int (*set_path_size)(const unsigned int, struct cifs_tcon *,
277 const char *, __u64, struct cifs_sb_info *, bool);
278 /* set size by file handle */
279 int (*set_file_size)(const unsigned int, struct cifs_tcon *,
280 struct cifsFileInfo *, __u64, bool);
281 /* set attributes */
282 int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *,
283 const unsigned int);
284 /* check if we can send an echo or nor */
285 bool (*can_echo)(struct TCP_Server_Info *);
286 /* send echo request */
287 int (*echo)(struct TCP_Server_Info *);
288 /* create directory */
289 int (*mkdir)(const unsigned int, struct cifs_tcon *, const char *,
290 struct cifs_sb_info *);
291 /* set info on created directory */
292 void (*mkdir_setinfo)(struct inode *, const char *,
293 struct cifs_sb_info *, struct cifs_tcon *,
294 const unsigned int);
295 /* remove directory */
296 int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *,
297 struct cifs_sb_info *);
298 /* unlink file */
299 int (*unlink)(const unsigned int, struct cifs_tcon *, const char *,
300 struct cifs_sb_info *);
301 /* open, rename and delete file */
302 int (*rename_pending_delete)(const char *, struct dentry *,
303 const unsigned int);
304 /* send rename request */
305 int (*rename)(const unsigned int, struct cifs_tcon *, const char *,
306 const char *, struct cifs_sb_info *);
307 /* send create hardlink request */
308 int (*create_hardlink)(const unsigned int, struct cifs_tcon *,
309 const char *, const char *,
310 struct cifs_sb_info *);
311 /* open a file for non-posix mounts */
312 int (*open)(const unsigned int, struct cifs_tcon *, const char *, int,
313 int, int, struct cifs_fid *, __u32 *, FILE_ALL_INFO *,
314 struct cifs_sb_info *);
315 /* set fid protocol-specific info */
316 void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32);
317 /* close a file */
318 void (*close)(const unsigned int, struct cifs_tcon *,
319 struct cifs_fid *);
320 /* send a flush request to the server */
321 int (*flush)(const unsigned int, struct cifs_tcon *, struct cifs_fid *);
322 /* async read from the server */
323 int (*async_readv)(struct cifs_readdata *);
324 /* async write to the server */
325 int (*async_writev)(struct cifs_writedata *);
326 /* sync read from the server */
327 int (*sync_read)(const unsigned int, struct cifsFileInfo *,
328 struct cifs_io_parms *, unsigned int *, char **,
329 int *);
330 /* sync write to the server */
331 int (*sync_write)(const unsigned int, struct cifsFileInfo *,
332 struct cifs_io_parms *, unsigned int *, struct kvec *,
333 unsigned long);
334 /* open dir, start readdir */
335 int (*query_dir_first)(const unsigned int, struct cifs_tcon *,
336 const char *, struct cifs_sb_info *,
337 struct cifs_fid *, __u16,
338 struct cifs_search_info *);
339 /* continue readdir */
340 int (*query_dir_next)(const unsigned int, struct cifs_tcon *,
341 struct cifs_fid *,
342 __u16, struct cifs_search_info *srch_inf);
343 /* close dir */
344 int (*close_dir)(const unsigned int, struct cifs_tcon *,
345 struct cifs_fid *);
346 /* calculate a size of SMB message */
347 unsigned int (*calc_smb_size)(void *);
348 /* check for STATUS_PENDING and process it in a positive case */
349 bool (*is_status_pending)(char *, struct TCP_Server_Info *, int);
350 /* send oplock break response */
351 int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *,
352 struct cifsInodeInfo *);
353 /* query remote filesystem */
354 int (*queryfs)(const unsigned int, struct cifs_tcon *,
355 struct kstatfs *);
356 /* send mandatory brlock to the server */
357 int (*mand_lock)(const unsigned int, struct cifsFileInfo *, __u64,
358 __u64, __u32, int, int, bool);
359 /* unlock range of mandatory locks */
360 int (*mand_unlock_range)(struct cifsFileInfo *, struct file_lock *,
361 const unsigned int);
362 /* push brlocks from the cache to the server */
363 int (*push_mand_locks)(struct cifsFileInfo *);
364 /* get lease key of the inode */
365 void (*get_lease_key)(struct inode *, struct cifs_fid *fid);
366 /* set lease key of the inode */
367 void (*set_lease_key)(struct inode *, struct cifs_fid *fid);
368 /* generate new lease key */
369 void (*new_lease_key)(struct cifs_fid *fid);
370 int (*calc_signature)(struct smb_rqst *rqst,
371 struct TCP_Server_Info *server);
372};
373
374struct smb_version_values {
375 char *version_string;
376 __u16 protocol_id;
377 __u32 req_capabilities;
378 __u32 large_lock_type;
379 __u32 exclusive_lock_type;
380 __u32 shared_lock_type;
381 __u32 unlock_lock_type;
382 size_t header_size;
383 size_t max_header_size;
384 size_t read_rsp_size;
385 __le16 lock_cmd;
386 unsigned int cap_unix;
387 unsigned int cap_nt_find;
388 unsigned int cap_large_files;
389 unsigned int oplock_read;
390};
391
392#define HEADER_SIZE(server) (server->vals->header_size)
393#define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
394
395struct smb_vol { 158struct smb_vol {
396 char *username; 159 char *username;
397 char *password; 160 char *password;
398 char *domainname; 161 char *domainname;
399 char *UNC; 162 char *UNC;
163 char *UNCip;
400 char *iocharset; /* local code page for mapping to and from Unicode */ 164 char *iocharset; /* local code page for mapping to and from Unicode */
401 char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */ 165 char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
402 char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */ 166 char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
403 uid_t cred_uid; 167 uid_t cred_uid;
404 uid_t linux_uid; 168 uid_t linux_uid;
405 gid_t linux_gid; 169 gid_t linux_gid;
406 uid_t backupuid; 170 mode_t file_mode;
407 gid_t backupgid; 171 mode_t dir_mode;
408 umode_t file_mode;
409 umode_t dir_mode;
410 unsigned secFlg; 172 unsigned secFlg;
411 bool retry:1; 173 bool retry:1;
412 bool intr:1; 174 bool intr:1;
@@ -417,8 +179,6 @@ struct smb_vol {
417 bool noperm:1; 179 bool noperm:1;
418 bool no_psx_acl:1; /* set if posix acl support should be disabled */ 180 bool no_psx_acl:1; /* set if posix acl support should be disabled */
419 bool cifs_acl:1; 181 bool cifs_acl:1;
420 bool backupuid_specified; /* mount option backupuid is specified */
421 bool backupgid_specified; /* mount option backupgid is specified */
422 bool no_xattr:1; /* set if xattr (EA) support should be disabled*/ 182 bool no_xattr:1; /* set if xattr (EA) support should be disabled*/
423 bool server_ino:1; /* use inode numbers from server ie UniqueId */ 183 bool server_ino:1; /* use inode numbers from server ie UniqueId */
424 bool direct_io:1; 184 bool direct_io:1;
@@ -444,11 +204,9 @@ struct smb_vol {
444 unsigned int rsize; 204 unsigned int rsize;
445 unsigned int wsize; 205 unsigned int wsize;
446 bool sockopt_tcp_nodelay:1; 206 bool sockopt_tcp_nodelay:1;
207 unsigned short int port;
447 unsigned long actimeo; /* attribute cache timeout (jiffies) */ 208 unsigned long actimeo; /* attribute cache timeout (jiffies) */
448 struct smb_version_operations *ops;
449 struct smb_version_values *vals;
450 char *prepath; 209 char *prepath;
451 struct sockaddr_storage dstaddr; /* destination address */
452 struct sockaddr_storage srcaddr; /* allow binding to a local IP */ 210 struct sockaddr_storage srcaddr; /* allow binding to a local IP */
453 struct nls_table *local_nls; 211 struct nls_table *local_nls;
454}; 212};
@@ -461,8 +219,7 @@ struct smb_vol {
461 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \ 219 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \
462 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \ 220 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \
463 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \ 221 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \
464 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \ 222 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO)
465 CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)
466 223
467#define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \ 224#define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \
468 MS_NODEV | MS_SYNCHRONOUS) 225 MS_NODEV | MS_SYNCHRONOUS)
@@ -473,26 +230,12 @@ struct cifs_mnt_data {
473 int flags; 230 int flags;
474}; 231};
475 232
476static inline unsigned int
477get_rfc1002_length(void *buf)
478{
479 return be32_to_cpu(*((__be32 *)buf));
480}
481
482static inline void
483inc_rfc1001_len(void *buf, int count)
484{
485 be32_add_cpu((__be32 *)buf, count);
486}
487
488struct TCP_Server_Info { 233struct TCP_Server_Info {
489 struct list_head tcp_ses_list; 234 struct list_head tcp_ses_list;
490 struct list_head smb_ses_list; 235 struct list_head smb_ses_list;
491 int srv_count; /* reference counter */ 236 int srv_count; /* reference counter */
492 /* 15 character server name + 0x20 16th byte indicating type = srv */ 237 /* 15 character server name + 0x20 16th byte indicating type = srv */
493 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 238 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
494 struct smb_version_operations *ops;
495 struct smb_version_values *vals;
496 enum statusEnum tcpStatus; /* what we think the status is */ 239 enum statusEnum tcpStatus; /* what we think the status is */
497 char *hostname; /* hostname portion of UNC string */ 240 char *hostname; /* hostname portion of UNC string */
498 struct socket *ssocket; 241 struct socket *ssocket;
@@ -507,22 +250,14 @@ struct TCP_Server_Info {
507 bool noblocksnd; /* use blocking sendmsg */ 250 bool noblocksnd; /* use blocking sendmsg */
508 bool noautotune; /* do not autotune send buf sizes */ 251 bool noautotune; /* do not autotune send buf sizes */
509 bool tcp_nodelay; 252 bool tcp_nodelay;
510 int credits; /* send no more requests at once */ 253 atomic_t inFlight; /* number of requests on the wire to server */
511 unsigned int in_flight; /* number of requests on the wire to server */
512 spinlock_t req_lock; /* protect the two values above */
513 struct mutex srv_mutex; 254 struct mutex srv_mutex;
514 struct task_struct *tsk; 255 struct task_struct *tsk;
515 char server_GUID[16]; 256 char server_GUID[16];
516 __u16 sec_mode; 257 char sec_mode;
517 bool session_estab; /* mark when very first sess is established */ 258 bool session_estab; /* mark when very first sess is established */
518#ifdef CONFIG_CIFS_SMB2
519 int echo_credits; /* echo reserved slots */
520 int oplock_credits; /* oplock break reserved slots */
521 bool echoes:1; /* enable echoes */
522#endif
523 u16 dialect; /* dialect index that server chose */ 259 u16 dialect; /* dialect index that server chose */
524 enum securityEnum secType; 260 enum securityEnum secType;
525 bool oplocks:1; /* enable oplocks */
526 unsigned int maxReq; /* Clients should submit no more */ 261 unsigned int maxReq; /* Clients should submit no more */
527 /* than maxReq distinct unanswered SMBs to the server when using */ 262 /* than maxReq distinct unanswered SMBs to the server when using */
528 /* multiplexed reads or writes */ 263 /* multiplexed reads or writes */
@@ -536,9 +271,9 @@ struct TCP_Server_Info {
536 unsigned int max_vcs; /* maximum number of smb sessions, at least 271 unsigned int max_vcs; /* maximum number of smb sessions, at least
537 those that can be specified uniquely with 272 those that can be specified uniquely with
538 vcnumbers */ 273 vcnumbers */
539 unsigned int capabilities; /* selective disabling of caps by smb sess */ 274 int capabilities; /* allow selective disabling of caps by smb sess */
540 int timeAdj; /* Adjust for difference in server time zone in sec */ 275 int timeAdj; /* Adjust for difference in server time zone in sec */
541 __u64 CurrentMid; /* multiplex id - rotating counter */ 276 __u16 CurrentMid; /* multiplex id - rotating counter */
542 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */ 277 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
543 /* 16th byte of RFC1001 workstation name is always null */ 278 /* 16th byte of RFC1001 workstation name is always null */
544 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 279 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
@@ -551,13 +286,7 @@ struct TCP_Server_Info {
551 bool sec_kerberosu2u; /* supports U2U Kerberos */ 286 bool sec_kerberosu2u; /* supports U2U Kerberos */
552 bool sec_kerberos; /* supports plain Kerberos */ 287 bool sec_kerberos; /* supports plain Kerberos */
553 bool sec_mskerberos; /* supports legacy MS Kerberos */ 288 bool sec_mskerberos; /* supports legacy MS Kerberos */
554 bool large_buf; /* is current buffer large? */
555 struct delayed_work echo; /* echo ping workqueue job */ 289 struct delayed_work echo; /* echo ping workqueue job */
556 struct kvec *iov; /* reusable kvec array for receives */
557 unsigned int nr_iov; /* number of kvecs in array */
558 char *smallbuf; /* pointer to current "small" buffer */
559 char *bigbuf; /* pointer to current "big" buffer */
560 unsigned int total_read; /* total amount of data read in this pass */
561#ifdef CONFIG_CIFS_FSCACHE 290#ifdef CONFIG_CIFS_FSCACHE
562 struct fscache_cookie *fscache; /* client index cache cookie */ 291 struct fscache_cookie *fscache; /* client index cache cookie */
563#endif 292#endif
@@ -565,96 +294,8 @@ struct TCP_Server_Info {
565 atomic_t in_send; /* requests trying to send */ 294 atomic_t in_send; /* requests trying to send */
566 atomic_t num_waiters; /* blocked waiting to get in sendrecv */ 295 atomic_t num_waiters; /* blocked waiting to get in sendrecv */
567#endif 296#endif
568#ifdef CONFIG_CIFS_SMB2
569 unsigned int max_read;
570 unsigned int max_write;
571#endif /* CONFIG_CIFS_SMB2 */
572}; 297};
573 298
574static inline unsigned int
575in_flight(struct TCP_Server_Info *server)
576{
577 unsigned int num;
578 spin_lock(&server->req_lock);
579 num = server->in_flight;
580 spin_unlock(&server->req_lock);
581 return num;
582}
583
584static inline bool
585has_credits(struct TCP_Server_Info *server, int *credits)
586{
587 int num;
588 spin_lock(&server->req_lock);
589 num = *credits;
590 spin_unlock(&server->req_lock);
591 return num > 0;
592}
593
594static inline void
595add_credits(struct TCP_Server_Info *server, const unsigned int add,
596 const int optype)
597{
598 server->ops->add_credits(server, add, optype);
599}
600
601static inline void
602set_credits(struct TCP_Server_Info *server, const int val)
603{
604 server->ops->set_credits(server, val);
605}
606
607static inline __u64
608get_next_mid(struct TCP_Server_Info *server)
609{
610 return server->ops->get_next_mid(server);
611}
612
613/*
614 * When the server supports very large reads and writes via POSIX extensions,
615 * we can allow up to 2^24-1, minus the size of a READ/WRITE_AND_X header, not
616 * including the RFC1001 length.
617 *
618 * Note that this might make for "interesting" allocation problems during
619 * writeback however as we have to allocate an array of pointers for the
620 * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096.
621 *
622 * For reads, there is a similar problem as we need to allocate an array
623 * of kvecs to handle the receive, though that should only need to be done
624 * once.
625 */
626#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4)
627#define CIFS_MAX_RSIZE ((1<<24) - sizeof(READ_RSP) + 4)
628
629/*
630 * When the server doesn't allow large posix writes, only allow a rsize/wsize
631 * of 2^17-1 minus the size of the call header. That allows for a read or
632 * write up to the maximum size described by RFC1002.
633 */
634#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4)
635#define CIFS_MAX_RFC1002_RSIZE ((1<<17) - 1 - sizeof(READ_RSP) + 4)
636
637/*
638 * The default wsize is 1M. find_get_pages seems to return a maximum of 256
639 * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill
640 * a single wsize request with a single call.
641 */
642#define CIFS_DEFAULT_IOSIZE (1024 * 1024)
643
644/*
645 * Windows only supports a max of 60kb reads and 65535 byte writes. Default to
646 * those values when posix extensions aren't in force. In actuality here, we
647 * use 65536 to allow for a write that is a multiple of 4k. Most servers seem
648 * to be ok with the extra byte even though Windows doesn't send writes that
649 * are that large.
650 *
651 * Citation:
652 *
653 * http://blogs.msdn.com/b/openspecification/archive/2009/04/10/smb-maximum-transmit-buffer-size-and-performance-tuning.aspx
654 */
655#define CIFS_DEFAULT_NON_POSIX_RSIZE (60 * 1024)
656#define CIFS_DEFAULT_NON_POSIX_WSIZE (65536)
657
658/* 299/*
659 * Macros to allow the TCP_Server_Info->net field and related code to drop out 300 * Macros to allow the TCP_Server_Info->net field and related code to drop out
660 * when CONFIG_NET_NS isn't set. 301 * when CONFIG_NET_NS isn't set.
@@ -702,10 +343,10 @@ struct cifs_ses {
702 char *serverOS; /* name of operating system underlying server */ 343 char *serverOS; /* name of operating system underlying server */
703 char *serverNOS; /* name of network operating system of server */ 344 char *serverNOS; /* name of network operating system of server */
704 char *serverDomain; /* security realm of server */ 345 char *serverDomain; /* security realm of server */
705 __u64 Suid; /* remote smb uid */ 346 int Suid; /* remote smb uid */
706 uid_t linux_uid; /* overriding owner of files on the mount */ 347 uid_t linux_uid; /* overriding owner of files on the mount */
707 uid_t cred_uid; /* owner of credentials */ 348 uid_t cred_uid; /* owner of credentials */
708 unsigned int capabilities; 349 int capabilities;
709 char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for 350 char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
710 TCP names - will ipv6 and sctp addresses fit? */ 351 TCP names - will ipv6 and sctp addresses fit? */
711 char *user_name; /* must not be null except during init of sess 352 char *user_name; /* must not be null except during init of sess
@@ -715,11 +356,7 @@ struct cifs_ses {
715 struct session_key auth_key; 356 struct session_key auth_key;
716 struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */ 357 struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
717 bool need_reconnect:1; /* connection reset, uid now invalid */ 358 bool need_reconnect:1; /* connection reset, uid now invalid */
718#ifdef CONFIG_CIFS_SMB2
719 __u16 session_flags;
720#endif /* CONFIG_CIFS_SMB2 */
721}; 359};
722
723/* no more than one of the following three session flags may be set */ 360/* no more than one of the following three session flags may be set */
724#define CIFS_SES_NT4 1 361#define CIFS_SES_NT4 1
725#define CIFS_SES_OS2 2 362#define CIFS_SES_OS2 2
@@ -728,13 +365,6 @@ struct cifs_ses {
728 which do not negotiate NTLM or POSIX dialects, but instead 365 which do not negotiate NTLM or POSIX dialects, but instead
729 negotiate one of the older LANMAN dialects */ 366 negotiate one of the older LANMAN dialects */
730#define CIFS_SES_LANMAN 8 367#define CIFS_SES_LANMAN 8
731
732static inline bool
733cap_unix(struct cifs_ses *ses)
734{
735 return ses->server->vals->cap_unix & ses->capabilities;
736}
737
738/* 368/*
739 * there is one of these for each connection to a resource on a particular 369 * there is one of these for each connection to a resource on a particular
740 * session 370 * session
@@ -747,42 +377,32 @@ struct cifs_tcon {
747 char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */ 377 char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */
748 char *nativeFileSystem; 378 char *nativeFileSystem;
749 char *password; /* for share-level security */ 379 char *password; /* for share-level security */
750 __u32 tid; /* The 4 byte tree id */ 380 __u16 tid; /* The 2 byte tree id */
751 __u16 Flags; /* optional support bits */ 381 __u16 Flags; /* optional support bits */
752 enum statusEnum tidStatus; 382 enum statusEnum tidStatus;
753#ifdef CONFIG_CIFS_STATS 383#ifdef CONFIG_CIFS_STATS
754 atomic_t num_smbs_sent; 384 atomic_t num_smbs_sent;
755 union { 385 atomic_t num_writes;
756 struct { 386 atomic_t num_reads;
757 atomic_t num_writes; 387 atomic_t num_flushes;
758 atomic_t num_reads; 388 atomic_t num_oplock_brks;
759 atomic_t num_flushes; 389 atomic_t num_opens;
760 atomic_t num_oplock_brks; 390 atomic_t num_closes;
761 atomic_t num_opens; 391 atomic_t num_deletes;
762 atomic_t num_closes; 392 atomic_t num_mkdirs;
763 atomic_t num_deletes; 393 atomic_t num_posixopens;
764 atomic_t num_mkdirs; 394 atomic_t num_posixmkdirs;
765 atomic_t num_posixopens; 395 atomic_t num_rmdirs;
766 atomic_t num_posixmkdirs; 396 atomic_t num_renames;
767 atomic_t num_rmdirs; 397 atomic_t num_t2renames;
768 atomic_t num_renames; 398 atomic_t num_ffirst;
769 atomic_t num_t2renames; 399 atomic_t num_fnext;
770 atomic_t num_ffirst; 400 atomic_t num_fclose;
771 atomic_t num_fnext; 401 atomic_t num_hardlinks;
772 atomic_t num_fclose; 402 atomic_t num_symlinks;
773 atomic_t num_hardlinks; 403 atomic_t num_locks;
774 atomic_t num_symlinks; 404 atomic_t num_acl_get;
775 atomic_t num_locks; 405 atomic_t num_acl_set;
776 atomic_t num_acl_get;
777 atomic_t num_acl_set;
778 } cifs_stats;
779#ifdef CONFIG_CIFS_SMB2
780 struct {
781 atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
782 atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
783 } smb2_stats;
784#endif /* CONFIG_CIFS_SMB2 */
785 } stats;
786#ifdef CONFIG_CIFS_STATS2 406#ifdef CONFIG_CIFS_STATS2
787 unsigned long long time_writes; 407 unsigned long long time_writes;
788 unsigned long long time_reads; 408 unsigned long long time_reads;
@@ -813,20 +433,10 @@ struct cifs_tcon {
813 bool local_lease:1; /* check leases (only) on local system not remote */ 433 bool local_lease:1; /* check leases (only) on local system not remote */
814 bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */ 434 bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
815 bool need_reconnect:1; /* connection reset, tid now invalid */ 435 bool need_reconnect:1; /* connection reset, tid now invalid */
816#ifdef CONFIG_CIFS_SMB2
817 bool print:1; /* set if connection to printer share */
818 bool bad_network_name:1; /* set if ret status STATUS_BAD_NETWORK_NAME */
819 __u32 capabilities;
820 __u32 share_flags;
821 __u32 maximal_access;
822 __u32 vol_serial_number;
823 __le64 vol_create_time;
824#endif /* CONFIG_CIFS_SMB2 */
825#ifdef CONFIG_CIFS_FSCACHE 436#ifdef CONFIG_CIFS_FSCACHE
826 u64 resource_id; /* server resource id */ 437 u64 resource_id; /* server resource id */
827 struct fscache_cookie *fscache; /* cookie for share */ 438 struct fscache_cookie *fscache; /* cookie for share */
828#endif 439#endif
829 struct list_head pending_opens; /* list of incomplete opens */
830 /* BB add field for back pointer to sb struct(s)? */ 440 /* BB add field for back pointer to sb struct(s)? */
831}; 441};
832 442
@@ -869,27 +479,15 @@ cifs_get_tlink(struct tcon_link *tlink)
869/* This function is always expected to succeed */ 479/* This function is always expected to succeed */
870extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb); 480extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb);
871 481
872#define CIFS_OPLOCK_NO_CHANGE 0xfe
873
874struct cifs_pending_open {
875 struct list_head olist;
876 struct tcon_link *tlink;
877 __u8 lease_key[16];
878 __u32 oplock;
879};
880
881/* 482/*
882 * This info hangs off the cifsFileInfo structure, pointed to by llist. 483 * This info hangs off the cifsFileInfo structure, pointed to by llist.
883 * This is used to track byte stream locks on the file 484 * This is used to track byte stream locks on the file
884 */ 485 */
885struct cifsLockInfo { 486struct cifsLockInfo {
886 struct list_head llist; /* pointer to next cifsLockInfo */ 487 struct list_head llist; /* pointer to next cifsLockInfo */
887 struct list_head blist; /* pointer to locks blocked on this */
888 wait_queue_head_t block_q;
889 __u64 offset; 488 __u64 offset;
890 __u64 length; 489 __u64 length;
891 __u32 pid; 490 __u8 type;
892 __u32 type;
893}; 491};
894 492
895/* 493/*
@@ -911,34 +509,19 @@ struct cifs_search_info {
911 bool smallBuf:1; /* so we know which buf_release function to call */ 509 bool smallBuf:1; /* so we know which buf_release function to call */
912}; 510};
913 511
914struct cifs_fid {
915 __u16 netfid;
916#ifdef CONFIG_CIFS_SMB2
917 __u64 persistent_fid; /* persist file id for smb2 */
918 __u64 volatile_fid; /* volatile file id for smb2 */
919 __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for smb2 */
920#endif
921 struct cifs_pending_open *pending_open;
922};
923
924struct cifs_fid_locks {
925 struct list_head llist;
926 struct cifsFileInfo *cfile; /* fid that owns locks */
927 struct list_head locks; /* locks held by fid above */
928};
929
930struct cifsFileInfo { 512struct cifsFileInfo {
931 struct list_head tlist; /* pointer to next fid owned by tcon */ 513 struct list_head tlist; /* pointer to next fid owned by tcon */
932 struct list_head flist; /* next fid (file instance) for this inode */ 514 struct list_head flist; /* next fid (file instance) for this inode */
933 struct cifs_fid_locks *llist; /* brlocks held by this fid */
934 unsigned int uid; /* allows finding which FileInfo structure */ 515 unsigned int uid; /* allows finding which FileInfo structure */
935 __u32 pid; /* process id who opened file */ 516 __u32 pid; /* process id who opened file */
936 struct cifs_fid fid; /* file id from remote */ 517 __u16 netfid; /* file id from remote */
937 /* BB add lock scope info here if needed */ ; 518 /* BB add lock scope info here if needed */ ;
938 /* lock scope id (0 if none) */ 519 /* lock scope id (0 if none) */
939 struct dentry *dentry; 520 struct dentry *dentry;
940 unsigned int f_flags; 521 unsigned int f_flags;
941 struct tcon_link *tlink; 522 struct tcon_link *tlink;
523 struct mutex lock_mutex;
524 struct list_head llist; /* list of byte range locks we have. */
942 bool invalidHandle:1; /* file closed via session abend */ 525 bool invalidHandle:1; /* file closed via session abend */
943 bool oplock_break_cancelled:1; 526 bool oplock_break_cancelled:1;
944 int count; /* refcount protected by cifs_file_list_lock */ 527 int count; /* refcount protected by cifs_file_list_lock */
@@ -949,71 +532,21 @@ struct cifsFileInfo {
949 532
950struct cifs_io_parms { 533struct cifs_io_parms {
951 __u16 netfid; 534 __u16 netfid;
952#ifdef CONFIG_CIFS_SMB2
953 __u64 persistent_fid; /* persist file id for smb2 */
954 __u64 volatile_fid; /* volatile file id for smb2 */
955#endif
956 __u32 pid; 535 __u32 pid;
957 __u64 offset; 536 __u64 offset;
958 unsigned int length; 537 unsigned int length;
959 struct cifs_tcon *tcon; 538 struct cifs_tcon *tcon;
960}; 539};
961 540
962struct cifs_readdata;
963
964/* asynchronous read support */
965struct cifs_readdata {
966 struct kref refcount;
967 struct list_head list;
968 struct completion done;
969 struct cifsFileInfo *cfile;
970 struct address_space *mapping;
971 __u64 offset;
972 unsigned int bytes;
973 pid_t pid;
974 int result;
975 struct work_struct work;
976 int (*read_into_pages)(struct TCP_Server_Info *server,
977 struct cifs_readdata *rdata,
978 unsigned int len);
979 struct kvec iov;
980 unsigned int pagesz;
981 unsigned int tailsz;
982 unsigned int nr_pages;
983 struct page *pages[];
984};
985
986struct cifs_writedata;
987
988/* asynchronous write support */
989struct cifs_writedata {
990 struct kref refcount;
991 struct list_head list;
992 struct completion done;
993 enum writeback_sync_modes sync_mode;
994 struct work_struct work;
995 struct cifsFileInfo *cfile;
996 __u64 offset;
997 pid_t pid;
998 unsigned int bytes;
999 int result;
1000 unsigned int pagesz;
1001 unsigned int tailsz;
1002 unsigned int nr_pages;
1003 struct page *pages[1];
1004};
1005
1006/* 541/*
1007 * Take a reference on the file private data. Must be called with 542 * Take a reference on the file private data. Must be called with
1008 * cifs_file_list_lock held. 543 * cifs_file_list_lock held.
1009 */ 544 */
1010static inline void 545static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file)
1011cifsFileInfo_get_locked(struct cifsFileInfo *cifs_file)
1012{ 546{
1013 ++cifs_file->count; 547 ++cifs_file->count;
1014} 548}
1015 549
1016struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file);
1017void cifsFileInfo_put(struct cifsFileInfo *cifs_file); 550void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
1018 551
1019/* 552/*
@@ -1021,9 +554,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
1021 */ 554 */
1022 555
1023struct cifsInodeInfo { 556struct cifsInodeInfo {
1024 bool can_cache_brlcks; 557 struct list_head lockList;
1025 struct list_head llist; /* locks helb by this inode */
1026 struct rw_semaphore lock_sem; /* protect the fields above */
1027 /* BB add in lists for dirty pages i.e. write caching info for oplock */ 558 /* BB add in lists for dirty pages i.e. write caching info for oplock */
1028 struct list_head openFileList; 559 struct list_head openFileList;
1029 __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ 560 __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
@@ -1032,12 +563,9 @@ struct cifsInodeInfo {
1032 bool delete_pending; /* DELETE_ON_CLOSE is set */ 563 bool delete_pending; /* DELETE_ON_CLOSE is set */
1033 bool invalid_mapping; /* pagecache is invalid */ 564 bool invalid_mapping; /* pagecache is invalid */
1034 unsigned long time; /* jiffies of last update of inode */ 565 unsigned long time; /* jiffies of last update of inode */
1035 u64 server_eof; /* current file size on server -- protected by i_lock */ 566 u64 server_eof; /* current file size on server */
1036 u64 uniqueid; /* server inode number */ 567 u64 uniqueid; /* server inode number */
1037 u64 createtime; /* creation time on server */ 568 u64 createtime; /* creation time on server */
1038#ifdef CONFIG_CIFS_SMB2
1039 __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */
1040#endif
1041#ifdef CONFIG_CIFS_FSCACHE 569#ifdef CONFIG_CIFS_FSCACHE
1042 struct fscache_cookie *fscache; 570 struct fscache_cookie *fscache;
1043#endif 571#endif
@@ -1067,16 +595,21 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
1067static inline void 595static inline void
1068convert_delimiter(char *path, char delim) 596convert_delimiter(char *path, char delim)
1069{ 597{
1070 char old_delim, *pos; 598 int i;
599 char old_delim;
600
601 if (path == NULL)
602 return;
1071 603
1072 if (delim == '/') 604 if (delim == '/')
1073 old_delim = '\\'; 605 old_delim = '\\';
1074 else 606 else
1075 old_delim = '/'; 607 old_delim = '/';
1076 608
1077 pos = path; 609 for (i = 0; path[i] != '\0'; i++) {
1078 while ((pos = strchr(pos, old_delim))) 610 if (path[i] == old_delim)
1079 *pos = delim; 611 path[i] = delim;
612 }
1080} 613}
1081 614
1082#ifdef CONFIG_CIFS_STATS 615#ifdef CONFIG_CIFS_STATS
@@ -1107,26 +640,11 @@ static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,
1107 640
1108#endif 641#endif
1109 642
643struct mid_q_entry;
1110 644
1111/* 645/*
1112 * This is the prototype for the mid receive function. This function is for 646 * This is the prototype for the mid callback function. When creating one,
1113 * receiving the rest of the SMB frame, starting with the WordCount (which is 647 * take special care to avoid deadlocks. Things to bear in mind:
1114 * just after the MID in struct smb_hdr). Note:
1115 *
1116 * - This will be called by cifsd, with no locks held.
1117 * - The mid will still be on the pending_mid_q.
1118 * - mid->resp_buf will point to the current buffer.
1119 *
1120 * Returns zero on a successful receive, or an error. The receive state in
1121 * the TCP_Server_Info will also be updated.
1122 */
1123typedef int (mid_receive_t)(struct TCP_Server_Info *server,
1124 struct mid_q_entry *mid);
1125
1126/*
1127 * This is the prototype for the mid callback function. This is called once the
1128 * mid has been received off of the socket. When creating one, take special
1129 * care to avoid deadlocks. Things to bear in mind:
1130 * 648 *
1131 * - it will be called by cifsd, with no locks held 649 * - it will be called by cifsd, with no locks held
1132 * - the mid will be removed from any lists 650 * - the mid will be removed from any lists
@@ -1136,22 +654,20 @@ typedef void (mid_callback_t)(struct mid_q_entry *mid);
1136/* one of these for every pending CIFS request to the server */ 654/* one of these for every pending CIFS request to the server */
1137struct mid_q_entry { 655struct mid_q_entry {
1138 struct list_head qhead; /* mids waiting on reply from this server */ 656 struct list_head qhead; /* mids waiting on reply from this server */
1139 struct TCP_Server_Info *server; /* server corresponding to this mid */ 657 __u16 mid; /* multiplex id */
1140 __u64 mid; /* multiplex id */ 658 __u16 pid; /* process id */
1141 __u32 pid; /* process id */
1142 __u32 sequence_number; /* for CIFS signing */ 659 __u32 sequence_number; /* for CIFS signing */
1143 unsigned long when_alloc; /* when mid was created */ 660 unsigned long when_alloc; /* when mid was created */
1144#ifdef CONFIG_CIFS_STATS2 661#ifdef CONFIG_CIFS_STATS2
1145 unsigned long when_sent; /* time when smb send finished */ 662 unsigned long when_sent; /* time when smb send finished */
1146 unsigned long when_received; /* when demux complete (taken off wire) */ 663 unsigned long when_received; /* when demux complete (taken off wire) */
1147#endif 664#endif
1148 mid_receive_t *receive; /* call receive callback */
1149 mid_callback_t *callback; /* call completion callback */ 665 mid_callback_t *callback; /* call completion callback */
1150 void *callback_data; /* general purpose pointer for callback */ 666 void *callback_data; /* general purpose pointer for callback */
1151 void *resp_buf; /* pointer to received SMB header */ 667 struct smb_hdr *resp_buf; /* response buffer */
1152 int mid_state; /* wish this were enum but can not pass to wait_event */ 668 int midState; /* wish this were enum but can not pass to wait_event */
1153 __le16 command; /* smb command code */ 669 __u8 command; /* smb command code */
1154 bool large_buf:1; /* if valid response, is pointer to large buf */ 670 bool largeBuf:1; /* if valid response, is pointer to large buf */
1155 bool multiRsp:1; /* multiple trans2 responses for one request */ 671 bool multiRsp:1; /* multiple trans2 responses for one request */
1156 bool multiEnd:1; /* both received */ 672 bool multiEnd:1; /* both received */
1157}; 673};
@@ -1300,12 +816,6 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
1300#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */ 816#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */
1301#define CIFS_NO_RESP 0x040 /* no response buffer required */ 817#define CIFS_NO_RESP 0x040 /* no response buffer required */
1302 818
1303/* Type of request operation */
1304#define CIFS_ECHO_OP 0x080 /* echo request */
1305#define CIFS_OBREAK_OP 0x0100 /* oplock break request */
1306#define CIFS_NEG_OP 0x0200 /* negotiate request */
1307#define CIFS_OP_MASK 0x0380 /* mask request type */
1308
1309/* Security Flags: indicate type of session setup needed */ 819/* Security Flags: indicate type of session setup needed */
1310#define CIFSSEC_MAY_SIGN 0x00001 820#define CIFSSEC_MAY_SIGN 0x00001
1311#define CIFSSEC_MAY_NTLM 0x00002 821#define CIFSSEC_MAY_NTLM 0x00002
@@ -1337,8 +847,6 @@ require use of the stronger protocol */
1337#define CIFSSEC_MASK 0xB70B7 /* current flags supported if weak */ 847#define CIFSSEC_MASK 0xB70B7 /* current flags supported if weak */
1338#endif /* UPCALL */ 848#endif /* UPCALL */
1339#else /* do not allow weak pw hash */ 849#else /* do not allow weak pw hash */
1340#define CIFSSEC_MUST_LANMAN 0
1341#define CIFSSEC_MUST_PLNTXT 0
1342#ifdef CONFIG_CIFS_UPCALL 850#ifdef CONFIG_CIFS_UPCALL
1343#define CIFSSEC_MASK 0x8F08F /* flags supported if no weak allowed */ 851#define CIFSSEC_MASK 0x8F08F /* flags supported if no weak allowed */
1344#else 852#else
@@ -1348,7 +856,7 @@ require use of the stronger protocol */
1348#define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */ 856#define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */
1349#define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */ 857#define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */
1350 858
1351#define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLMSSP) 859#define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2)
1352#define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2) 860#define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2)
1353#define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP) 861#define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
1354/* 862/*
@@ -1452,7 +960,11 @@ GLOBAL_EXTERN atomic_t smBufAllocCount;
1452GLOBAL_EXTERN atomic_t midCount; 960GLOBAL_EXTERN atomic_t midCount;
1453 961
1454/* Misc globals */ 962/* Misc globals */
1455GLOBAL_EXTERN bool enable_oplocks; /* enable or disable oplocks */ 963GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
964 to be established on existing mount if we
965 have the uid/password or Kerberos credential
966 or equivalent for current user */
967GLOBAL_EXTERN unsigned int oplockEnabled;
1456GLOBAL_EXTERN unsigned int lookupCacheEnabled; 968GLOBAL_EXTERN unsigned int lookupCacheEnabled;
1457GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent 969GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent
1458 with more secure ntlmssp2 challenge/resp */ 970 with more secure ntlmssp2 challenge/resp */
@@ -1463,35 +975,16 @@ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
1463GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */ 975GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
1464GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/ 976GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/
1465 977
1466#ifdef CONFIG_CIFS_ACL 978/* reconnect after this many failed echo attempts */
979GLOBAL_EXTERN unsigned short echo_retries;
980
1467GLOBAL_EXTERN struct rb_root uidtree; 981GLOBAL_EXTERN struct rb_root uidtree;
1468GLOBAL_EXTERN struct rb_root gidtree; 982GLOBAL_EXTERN struct rb_root gidtree;
1469GLOBAL_EXTERN spinlock_t siduidlock; 983GLOBAL_EXTERN spinlock_t siduidlock;
1470GLOBAL_EXTERN spinlock_t sidgidlock; 984GLOBAL_EXTERN spinlock_t sidgidlock;
1471GLOBAL_EXTERN struct rb_root siduidtree;
1472GLOBAL_EXTERN struct rb_root sidgidtree;
1473GLOBAL_EXTERN spinlock_t uidsidlock;
1474GLOBAL_EXTERN spinlock_t gidsidlock;
1475#endif /* CONFIG_CIFS_ACL */
1476 985
1477void cifs_oplock_break(struct work_struct *work); 986void cifs_oplock_break(struct work_struct *work);
1478 987
1479extern const struct slow_work_ops cifs_oplock_break_ops; 988extern const struct slow_work_ops cifs_oplock_break_ops;
1480extern struct workqueue_struct *cifsiod_wq; 989
1481
1482extern mempool_t *cifs_mid_poolp;
1483
1484/* Operations for different SMB versions */
1485#define SMB1_VERSION_STRING "1.0"
1486extern struct smb_version_operations smb1_operations;
1487extern struct smb_version_values smb1_values;
1488#define SMB20_VERSION_STRING "2.0"
1489/*extern struct smb_version_operations smb20_operations; */ /* not needed yet */
1490extern struct smb_version_values smb20_values;
1491#define SMB21_VERSION_STRING "2.1"
1492extern struct smb_version_operations smb21_operations;
1493extern struct smb_version_values smb21_values;
1494#define SMB30_VERSION_STRING "3.0"
1495extern struct smb_version_operations smb30_operations;
1496extern struct smb_version_values smb30_values;
1497#endif /* _CIFS_GLOB_H */ 990#endif /* _CIFS_GLOB_H */
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index b9d59a948a2..de3aa285de0 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -1089,7 +1089,9 @@ typedef struct smb_com_read_rsp {
1089 __le16 DataLengthHigh; 1089 __le16 DataLengthHigh;
1090 __u64 Reserved2; 1090 __u64 Reserved2;
1091 __u16 ByteCount; 1091 __u16 ByteCount;
1092 /* read response data immediately follows */ 1092 __u8 Pad; /* BB check for whether padded to DWORD
1093 boundary and optimum performance here */
1094 char Data[1];
1093} __attribute__((packed)) READ_RSP; 1095} __attribute__((packed)) READ_RSP;
1094 1096
1095typedef struct locking_andx_range { 1097typedef struct locking_andx_range {
@@ -1911,10 +1913,6 @@ typedef struct whoami_rsp_data { /* Query level 0x202 */
1911 1913
1912/* SETFSInfo Levels */ 1914/* SETFSInfo Levels */
1913#define SMB_SET_CIFS_UNIX_INFO 0x200 1915#define SMB_SET_CIFS_UNIX_INFO 0x200
1914/* level 0x203 is defined above in list of QFS info levels */
1915/* #define SMB_REQUEST_TRANSPORT_ENCRYPTION 0x203 */
1916
1917/* Level 0x200 request structure follows */
1918typedef struct smb_com_transaction2_setfsi_req { 1916typedef struct smb_com_transaction2_setfsi_req {
1919 struct smb_hdr hdr; /* wct = 15 */ 1917 struct smb_hdr hdr; /* wct = 15 */
1920 __le16 TotalParameterCount; 1918 __le16 TotalParameterCount;
@@ -1942,39 +1940,13 @@ typedef struct smb_com_transaction2_setfsi_req {
1942 __le64 ClientUnixCap; /* Data end */ 1940 __le64 ClientUnixCap; /* Data end */
1943} __attribute__((packed)) TRANSACTION2_SETFSI_REQ; 1941} __attribute__((packed)) TRANSACTION2_SETFSI_REQ;
1944 1942
1945/* level 0x203 request structure follows */
1946typedef struct smb_com_transaction2_setfs_enc_req {
1947 struct smb_hdr hdr; /* wct = 15 */
1948 __le16 TotalParameterCount;
1949 __le16 TotalDataCount;
1950 __le16 MaxParameterCount;
1951 __le16 MaxDataCount;
1952 __u8 MaxSetupCount;
1953 __u8 Reserved;
1954 __le16 Flags;
1955 __le32 Timeout;
1956 __u16 Reserved2;
1957 __le16 ParameterCount; /* 4 */
1958 __le16 ParameterOffset;
1959 __le16 DataCount; /* 12 */
1960 __le16 DataOffset;
1961 __u8 SetupCount; /* one */
1962 __u8 Reserved3;
1963 __le16 SubCommand; /* TRANS2_SET_FS_INFORMATION */
1964 __le16 ByteCount;
1965 __u8 Pad;
1966 __u16 Reserved4; /* Parameters start. */
1967 __le16 InformationLevel;/* Parameters end. */
1968 /* NTLMSSP Blob, Data start. */
1969} __attribute__((packed)) TRANSACTION2_SETFSI_ENC_REQ;
1970
1971/* response for setfsinfo levels 0x200 and 0x203 */
1972typedef struct smb_com_transaction2_setfsi_rsp { 1943typedef struct smb_com_transaction2_setfsi_rsp {
1973 struct smb_hdr hdr; /* wct = 10 */ 1944 struct smb_hdr hdr; /* wct = 10 */
1974 struct trans2_resp t2; 1945 struct trans2_resp t2;
1975 __u16 ByteCount; 1946 __u16 ByteCount;
1976} __attribute__((packed)) TRANSACTION2_SETFSI_RSP; 1947} __attribute__((packed)) TRANSACTION2_SETFSI_RSP;
1977 1948
1949
1978typedef struct smb_com_transaction2_get_dfs_refer_req { 1950typedef struct smb_com_transaction2_get_dfs_refer_req {
1979 struct smb_hdr hdr; /* wct = 15 */ 1951 struct smb_hdr hdr; /* wct = 15 */
1980 __le16 TotalParameterCount; 1952 __le16 TotalParameterCount;
@@ -2126,13 +2098,13 @@ typedef struct {
2126#define CIFS_UNIX_PROXY_CAP 0x00000400 /* Proxy cap: 0xACE ioctl and 2098#define CIFS_UNIX_PROXY_CAP 0x00000400 /* Proxy cap: 0xACE ioctl and
2127 QFS PROXY call */ 2099 QFS PROXY call */
2128#ifdef CONFIG_CIFS_POSIX 2100#ifdef CONFIG_CIFS_POSIX
2129/* presumably don't need the 0x20 POSIX_PATH_OPS_CAP since we never send 2101/* Can not set pathnames cap yet until we send new posix create SMB since
2130 LockingX instead of posix locking call on unix sess (and we do not expect 2102 otherwise server can treat such handles opened with older ntcreatex
2131 LockingX to use different (ie Windows) semantics than posix locking on 2103 (by a new client which knows how to send posix path ops)
2132 the same session (if WINE needs to do this later, we can add this cap 2104 as non-posix handles (can affect write behavior with byte range locks.
2133 back in later */ 2105 We can add back in POSIX_PATH_OPS cap when Posix Create/Mkdir finished */
2134/* #define CIFS_UNIX_CAP_MASK 0x000000fb */ 2106/* #define CIFS_UNIX_CAP_MASK 0x000000fb */
2135#define CIFS_UNIX_CAP_MASK 0x000003db 2107#define CIFS_UNIX_CAP_MASK 0x000000db
2136#else 2108#else
2137#define CIFS_UNIX_CAP_MASK 0x00000013 2109#define CIFS_UNIX_CAP_MASK 0x00000013
2138#endif /* CONFIG_CIFS_POSIX */ 2110#endif /* CONFIG_CIFS_POSIX */
@@ -2210,7 +2182,7 @@ typedef struct { /* data block encoding of response to level 263 QPathInfo */
2210 __u8 DeletePending; 2182 __u8 DeletePending;
2211 __u8 Directory; 2183 __u8 Directory;
2212 __u16 Pad2; 2184 __u16 Pad2;
2213 __le64 IndexNumber; 2185 __u64 IndexNumber;
2214 __le32 EASize; 2186 __le32 EASize;
2215 __le32 AccessFlags; 2187 __le32 AccessFlags;
2216 __u64 IndexNumber1; 2188 __u64 IndexNumber1;
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 1988c1baa22..8df28e925e5 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -24,7 +24,6 @@
24 24
25struct statfs; 25struct statfs;
26struct smb_vol; 26struct smb_vol;
27struct smb_rqst;
28 27
29/* 28/*
30 ***************************************************************** 29 *****************************************************************
@@ -36,28 +35,27 @@ extern struct smb_hdr *cifs_buf_get(void);
36extern void cifs_buf_release(void *); 35extern void cifs_buf_release(void *);
37extern struct smb_hdr *cifs_small_buf_get(void); 36extern struct smb_hdr *cifs_small_buf_get(void);
38extern void cifs_small_buf_release(void *); 37extern void cifs_small_buf_release(void *);
39extern void cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx,
40 struct kvec *iov);
41extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, 38extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *,
42 unsigned int /* length */); 39 unsigned int /* length */);
43extern unsigned int _get_xid(void); 40extern unsigned int _GetXid(void);
44extern void _free_xid(unsigned int); 41extern void _FreeXid(unsigned int);
45#define get_xid() \ 42#define GetXid() \
46({ \ 43({ \
47 unsigned int __xid = _get_xid(); \ 44 int __xid = (int)_GetXid(); \
48 cFYI(1, "CIFS VFS: in %s as Xid: %u with uid: %d", \ 45 cFYI(1, "CIFS VFS: in %s as Xid: %d with uid: %d", \
49 __func__, __xid, current_fsuid()); \ 46 __func__, __xid, current_fsuid()); \
50 __xid; \ 47 __xid; \
51}) 48})
52 49
53#define free_xid(curr_xid) \ 50#define FreeXid(curr_xid) \
54do { \ 51do { \
55 _free_xid(curr_xid); \ 52 _FreeXid(curr_xid); \
56 cFYI(1, "CIFS VFS: leaving %s (xid = %u) rc = %d", \ 53 cFYI(1, "CIFS VFS: leaving %s (xid = %d) rc = %d", \
57 __func__, curr_xid, (int)rc); \ 54 __func__, curr_xid, (int)rc); \
58} while (0) 55} while (0)
59extern int init_cifs_idmap(void); 56extern int init_cifs_idmap(void);
60extern void exit_cifs_idmap(void); 57extern void exit_cifs_idmap(void);
58extern void cifs_destroy_idmaptrees(void);
61extern char *build_path_from_dentry(struct dentry *); 59extern char *build_path_from_dentry(struct dentry *);
62extern char *cifs_build_path_to_root(struct smb_vol *vol, 60extern char *cifs_build_path_to_root(struct smb_vol *vol,
63 struct cifs_sb_info *cifs_sb, 61 struct cifs_sb_info *cifs_sb,
@@ -70,22 +68,15 @@ extern char *cifs_compose_mount_options(const char *sb_mountdata,
70extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer, 68extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer,
71 struct TCP_Server_Info *server); 69 struct TCP_Server_Info *server);
72extern void DeleteMidQEntry(struct mid_q_entry *midEntry); 70extern void DeleteMidQEntry(struct mid_q_entry *midEntry);
73extern void cifs_delete_mid(struct mid_q_entry *mid); 71extern int cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
74extern void cifs_wake_up_task(struct mid_q_entry *mid); 72 unsigned int nvec, mid_callback_t *callback,
75extern int cifs_call_async(struct TCP_Server_Info *server, 73 void *cbdata, bool ignore_pend);
76 struct smb_rqst *rqst,
77 mid_receive_t *receive, mid_callback_t *callback,
78 void *cbdata, const int flags);
79extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, 74extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
80 struct smb_hdr * /* input */ , 75 struct smb_hdr * /* input */ ,
81 struct smb_hdr * /* out */ , 76 struct smb_hdr * /* out */ ,
82 int * /* bytes returned */ , const int); 77 int * /* bytes returned */ , const int long_op);
83extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, 78extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
84 char *in_buf, int flags); 79 struct smb_hdr *in_buf, int flags);
85extern struct mid_q_entry *cifs_setup_request(struct cifs_ses *,
86 struct smb_rqst *);
87extern struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *,
88 struct smb_rqst *);
89extern int cifs_check_receive(struct mid_q_entry *mid, 80extern int cifs_check_receive(struct mid_q_entry *mid,
90 struct TCP_Server_Info *server, bool log_error); 81 struct TCP_Server_Info *server, bool log_error);
91extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, 82extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *,
@@ -96,83 +87,70 @@ extern int SendReceiveBlockingLock(const unsigned int xid,
96 struct smb_hdr *in_buf , 87 struct smb_hdr *in_buf ,
97 struct smb_hdr *out_buf, 88 struct smb_hdr *out_buf,
98 int *bytes_returned); 89 int *bytes_returned);
99extern int cifs_reconnect(struct TCP_Server_Info *server); 90extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length);
100extern int checkSMB(char *buf, unsigned int length); 91extern bool is_valid_oplock_break(struct smb_hdr *smb,
101extern bool is_valid_oplock_break(char *, struct TCP_Server_Info *); 92 struct TCP_Server_Info *);
102extern bool backup_cred(struct cifs_sb_info *);
103extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); 93extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof);
104extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, 94extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
105 unsigned int bytes_written); 95 unsigned int bytes_written);
106extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); 96extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
107extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); 97extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
108extern unsigned int smbCalcSize(void *buf); 98extern unsigned int smbCalcSize(struct smb_hdr *ptr);
109extern int decode_negTokenInit(unsigned char *security_blob, int length, 99extern int decode_negTokenInit(unsigned char *security_blob, int length,
110 struct TCP_Server_Info *server); 100 struct TCP_Server_Info *server);
111extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); 101extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
112extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port); 102extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port);
113extern int map_smb_to_linux_error(char *buf, bool logErr); 103extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
104 const unsigned short int port);
105extern int map_smb_to_linux_error(struct smb_hdr *smb, bool logErr);
114extern void header_assemble(struct smb_hdr *, char /* command */ , 106extern void header_assemble(struct smb_hdr *, char /* command */ ,
115 const struct cifs_tcon *, int /* length of 107 const struct cifs_tcon *, int /* length of
116 fixed section (word count) in two byte units */); 108 fixed section (word count) in two byte units */);
117extern int small_smb_init_no_tc(const int smb_cmd, const int wct, 109extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
118 struct cifs_ses *ses, 110 struct cifs_ses *ses,
119 void **request_buf); 111 void **request_buf);
120extern int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, 112extern int CIFS_SessSetup(unsigned int xid, struct cifs_ses *ses,
121 const struct nls_table *nls_cp); 113 const struct nls_table *nls_cp);
114extern __u16 GetNextMid(struct TCP_Server_Info *server);
122extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601); 115extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
123extern u64 cifs_UnixTimeToNT(struct timespec); 116extern u64 cifs_UnixTimeToNT(struct timespec);
124extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, 117extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
125 int offset); 118 int offset);
126extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); 119extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock);
127extern int cifs_unlock_range(struct cifsFileInfo *cfile,
128 struct file_lock *flock, const unsigned int xid);
129extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile);
130 120
131extern struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, 121extern struct cifsFileInfo *cifs_new_fileinfo(__u16 fileHandle,
132 struct file *file, 122 struct file *file, struct tcon_link *tlink,
133 struct tcon_link *tlink, 123 __u32 oplock);
134 __u32 oplock); 124extern int cifs_posix_open(char *full_path, struct inode **pinode,
135extern int cifs_posix_open(char *full_path, struct inode **inode, 125 struct super_block *sb,
136 struct super_block *sb, int mode, 126 int mode, unsigned int f_flags,
137 unsigned int f_flags, __u32 *oplock, __u16 *netfid, 127 __u32 *poplock, __u16 *pnetfid, int xid);
138 unsigned int xid);
139void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr); 128void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr);
140extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, 129extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr,
141 FILE_UNIX_BASIC_INFO *info, 130 FILE_UNIX_BASIC_INFO *info,
142 struct cifs_sb_info *cifs_sb); 131 struct cifs_sb_info *cifs_sb);
143extern void cifs_dir_info_to_fattr(struct cifs_fattr *, FILE_DIRECTORY_INFO *,
144 struct cifs_sb_info *);
145extern void cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr); 132extern void cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr);
146extern struct inode *cifs_iget(struct super_block *sb, 133extern struct inode *cifs_iget(struct super_block *sb,
147 struct cifs_fattr *fattr); 134 struct cifs_fattr *fattr);
148 135
149extern int cifs_get_inode_info(struct inode **inode, const char *full_path, 136extern int cifs_get_file_info(struct file *filp);
150 FILE_ALL_INFO *data, struct super_block *sb, 137extern int cifs_get_inode_info(struct inode **pinode,
151 int xid, const __u16 *fid); 138 const unsigned char *search_path,
139 FILE_ALL_INFO *pfile_info,
140 struct super_block *sb, int xid, const __u16 *pfid);
141extern int cifs_get_file_info_unix(struct file *filp);
152extern int cifs_get_inode_info_unix(struct inode **pinode, 142extern int cifs_get_inode_info_unix(struct inode **pinode,
153 const unsigned char *search_path, 143 const unsigned char *search_path,
154 struct super_block *sb, unsigned int xid); 144 struct super_block *sb, int xid);
155extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs,
156 unsigned int xid, char *full_path, __u32 dosattr);
157extern int cifs_rename_pending_delete(const char *full_path,
158 struct dentry *dentry,
159 const unsigned int xid);
160extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, 145extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
161 struct cifs_fattr *fattr, struct inode *inode, 146 struct cifs_fattr *fattr, struct inode *inode,
162 const char *path, const __u16 *pfid); 147 const char *path, const __u16 *pfid);
163extern int id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64, 148extern int mode_to_cifs_acl(struct inode *inode, const char *path, __u64);
164 uid_t, gid_t);
165extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *, 149extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *,
166 const char *, u32 *); 150 const char *, u32 *);
167extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *, 151extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *,
168 const char *, int); 152 const char *);
169 153
170extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
171extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
172 unsigned int to_read);
173extern int cifs_readv_from_socket(struct TCP_Server_Info *server,
174 struct kvec *iov_orig, unsigned int nr_segs,
175 unsigned int to_read);
176extern void cifs_setup_cifs_sb(struct smb_vol *pvolume_info, 154extern void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
177 struct cifs_sb_info *cifs_sb); 155 struct cifs_sb_info *cifs_sb);
178extern int cifs_match_super(struct super_block *, void *); 156extern int cifs_match_super(struct super_block *, void *);
@@ -181,123 +159,102 @@ extern struct smb_vol *cifs_get_volume_info(char *mount_data,
181 const char *devname); 159 const char *devname);
182extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *); 160extern int cifs_mount(struct cifs_sb_info *, struct smb_vol *);
183extern void cifs_umount(struct cifs_sb_info *); 161extern void cifs_umount(struct cifs_sb_info *);
184extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon);
185extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
186 __u64 length, __u8 type,
187 struct cifsLockInfo **conf_lock,
188 int rw_check);
189extern void cifs_add_pending_open(struct cifs_fid *fid,
190 struct tcon_link *tlink,
191 struct cifs_pending_open *open);
192extern void cifs_add_pending_open_locked(struct cifs_fid *fid,
193 struct tcon_link *tlink,
194 struct cifs_pending_open *open);
195extern void cifs_del_pending_open(struct cifs_pending_open *open);
196
197#if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL)
198extern void cifs_dfs_release_automount_timer(void); 162extern void cifs_dfs_release_automount_timer(void);
199#else /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */
200#define cifs_dfs_release_automount_timer() do { } while (0)
201#endif /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */
202
203void cifs_proc_init(void); 163void cifs_proc_init(void);
204void cifs_proc_clean(void); 164void cifs_proc_clean(void);
205 165
206extern void cifs_move_llist(struct list_head *source, struct list_head *dest); 166extern int cifs_negotiate_protocol(unsigned int xid,
207extern void cifs_free_llist(struct list_head *llist); 167 struct cifs_ses *ses);
208extern void cifs_del_lock_waiters(struct cifsLockInfo *lock); 168extern int cifs_setup_session(unsigned int xid, struct cifs_ses *ses,
169 struct nls_table *nls_info);
170extern int CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses);
209 171
210extern int cifs_negotiate_protocol(const unsigned int xid, 172extern int CIFSTCon(unsigned int xid, struct cifs_ses *ses,
211 struct cifs_ses *ses); 173 const char *tree, struct cifs_tcon *tcon,
212extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, 174 const struct nls_table *);
213 struct nls_table *nls_info);
214extern int CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses);
215
216extern int CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
217 const char *tree, struct cifs_tcon *tcon,
218 const struct nls_table *);
219 175
220extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, 176extern int CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
221 const char *searchName, struct cifs_sb_info *cifs_sb, 177 const char *searchName, const struct nls_table *nls_codepage,
222 __u16 *searchHandle, __u16 search_flags, 178 __u16 *searchHandle, struct cifs_search_info *psrch_inf,
223 struct cifs_search_info *psrch_inf, 179 int map, const char dirsep);
224 bool msearch);
225 180
226extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, 181extern int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
227 __u16 searchHandle, __u16 search_flags, 182 __u16 searchHandle, struct cifs_search_info *psrch_inf);
228 struct cifs_search_info *psrch_inf);
229 183
230extern int CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, 184extern int CIFSFindClose(const int, struct cifs_tcon *tcon,
231 const __u16 search_handle); 185 const __u16 search_handle);
232 186
233extern int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 187extern int CIFSSMBQFileInfo(const int xid, struct cifs_tcon *tcon,
234 u16 netfid, FILE_ALL_INFO *pFindData); 188 u16 netfid, FILE_ALL_INFO *pFindData);
235extern int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 189extern int CIFSSMBQPathInfo(const int xid, struct cifs_tcon *tcon,
236 const char *search_Name, FILE_ALL_INFO *data, 190 const unsigned char *searchName,
237 int legacy /* whether to use old info level */, 191 FILE_ALL_INFO *findData,
238 const struct nls_table *nls_codepage, int remap); 192 int legacy /* whether to use old info level */,
239extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, 193 const struct nls_table *nls_codepage, int remap);
240 const char *search_name, FILE_ALL_INFO *data, 194extern int SMBQueryInformation(const int xid, struct cifs_tcon *tcon,
241 const struct nls_table *nls_codepage, int remap); 195 const unsigned char *searchName,
196 FILE_ALL_INFO *findData,
197 const struct nls_table *nls_codepage, int remap);
242 198
243extern int CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 199extern int CIFSSMBUnixQFileInfo(const int xid, struct cifs_tcon *tcon,
244 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData); 200 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData);
245extern int CIFSSMBUnixQPathInfo(const unsigned int xid, 201extern int CIFSSMBUnixQPathInfo(const int xid,
246 struct cifs_tcon *tcon, 202 struct cifs_tcon *tcon,
247 const unsigned char *searchName, 203 const unsigned char *searchName,
248 FILE_UNIX_BASIC_INFO *pFindData, 204 FILE_UNIX_BASIC_INFO *pFindData,
249 const struct nls_table *nls_codepage, int remap); 205 const struct nls_table *nls_codepage, int remap);
250 206
251extern int CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, 207extern int CIFSGetDFSRefer(const int xid, struct cifs_ses *ses,
252 const char *search_name, 208 const unsigned char *searchName,
253 struct dfs_info3_param **target_nodes, 209 struct dfs_info3_param **target_nodes,
254 unsigned int *num_of_nodes, 210 unsigned int *number_of_nodes_in_array,
255 const struct nls_table *nls_codepage, int remap); 211 const struct nls_table *nls_codepage, int remap);
256 212
257extern int get_dfs_path(const unsigned int xid, struct cifs_ses *ses, 213extern int get_dfs_path(int xid, struct cifs_ses *pSesInfo,
258 const char *old_path, 214 const char *old_path,
259 const struct nls_table *nls_codepage, 215 const struct nls_table *nls_codepage,
260 unsigned int *num_referrals, 216 unsigned int *pnum_referrals,
261 struct dfs_info3_param **referrals, int remap); 217 struct dfs_info3_param **preferrals,
262extern void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, 218 int remap);
219extern void reset_cifs_unix_caps(int xid, struct cifs_tcon *tcon,
263 struct cifs_sb_info *cifs_sb, 220 struct cifs_sb_info *cifs_sb,
264 struct smb_vol *vol); 221 struct smb_vol *vol);
265extern int CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 222extern int CIFSSMBQFSInfo(const int xid, struct cifs_tcon *tcon,
266 struct kstatfs *FSData); 223 struct kstatfs *FSData);
267extern int SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 224extern int SMBOldQFSInfo(const int xid, struct cifs_tcon *tcon,
268 struct kstatfs *FSData); 225 struct kstatfs *FSData);
269extern int CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, 226extern int CIFSSMBSetFSUnixInfo(const int xid, struct cifs_tcon *tcon,
270 __u64 cap); 227 __u64 cap);
271 228
272extern int CIFSSMBQFSAttributeInfo(const unsigned int xid, 229extern int CIFSSMBQFSAttributeInfo(const int xid,
273 struct cifs_tcon *tcon); 230 struct cifs_tcon *tcon);
274extern int CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon); 231extern int CIFSSMBQFSDeviceInfo(const int xid, struct cifs_tcon *tcon);
275extern int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon); 232extern int CIFSSMBQFSUnixInfo(const int xid, struct cifs_tcon *tcon);
276extern int CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, 233extern int CIFSSMBQFSPosixInfo(const int xid, struct cifs_tcon *tcon,
277 struct kstatfs *FSData); 234 struct kstatfs *FSData);
278 235
279extern int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 236extern int CIFSSMBSetPathInfo(const int xid, struct cifs_tcon *tcon,
280 const char *fileName, const FILE_BASIC_INFO *data, 237 const char *fileName, const FILE_BASIC_INFO *data,
281 const struct nls_table *nls_codepage, 238 const struct nls_table *nls_codepage,
282 int remap_special_chars); 239 int remap_special_chars);
283extern int CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 240extern int CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon,
284 const FILE_BASIC_INFO *data, __u16 fid, 241 const FILE_BASIC_INFO *data, __u16 fid,
285 __u32 pid_of_opener); 242 __u32 pid_of_opener);
286extern int CIFSSMBSetFileDisposition(const unsigned int xid, 243extern int CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon,
287 struct cifs_tcon *tcon, 244 bool delete_file, __u16 fid, __u32 pid_of_opener);
288 bool delete_file, __u16 fid,
289 __u32 pid_of_opener);
290#if 0 245#if 0
291extern int CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, 246extern int CIFSSMBSetAttrLegacy(int xid, struct cifs_tcon *tcon,
292 char *fileName, __u16 dos_attributes, 247 char *fileName, __u16 dos_attributes,
293 const struct nls_table *nls_codepage); 248 const struct nls_table *nls_codepage);
294#endif /* possibly unneeded function */ 249#endif /* possibly unneeded function */
295extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, 250extern int CIFSSMBSetEOF(const int xid, struct cifs_tcon *tcon,
296 const char *file_name, __u64 size, 251 const char *fileName, __u64 size,
297 struct cifs_sb_info *cifs_sb, bool set_allocation); 252 bool setAllocationSizeFlag,
298extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, 253 const struct nls_table *nls_codepage,
299 struct cifsFileInfo *cfile, __u64 size, 254 int remap_special_chars);
300 bool set_allocation); 255extern int CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon,
256 __u64 size, __u16 fileHandle, __u32 opener_pid,
257 bool AllocSizeFlag);
301 258
302struct cifs_unix_set_info_args { 259struct cifs_unix_set_info_args {
303 __u64 ctime; 260 __u64 ctime;
@@ -309,125 +266,125 @@ struct cifs_unix_set_info_args {
309 dev_t device; 266 dev_t device;
310}; 267};
311 268
312extern int CIFSSMBUnixSetFileInfo(const unsigned int xid, 269extern int CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon,
313 struct cifs_tcon *tcon,
314 const struct cifs_unix_set_info_args *args, 270 const struct cifs_unix_set_info_args *args,
315 u16 fid, u32 pid_of_opener); 271 u16 fid, u32 pid_of_opener);
316 272
317extern int CIFSSMBUnixSetPathInfo(const unsigned int xid, 273extern int CIFSSMBUnixSetPathInfo(const int xid, struct cifs_tcon *pTcon,
318 struct cifs_tcon *tcon, const char *file_name, 274 char *fileName,
319 const struct cifs_unix_set_info_args *args, 275 const struct cifs_unix_set_info_args *args,
320 const struct nls_table *nls_codepage, 276 const struct nls_table *nls_codepage,
321 int remap); 277 int remap_special_chars);
322 278
323extern int CIFSSMBMkDir(const unsigned int xid, struct cifs_tcon *tcon, 279extern int CIFSSMBMkDir(const int xid, struct cifs_tcon *tcon,
324 const char *name, struct cifs_sb_info *cifs_sb); 280 const char *newName,
325extern int CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, 281 const struct nls_table *nls_codepage,
326 const char *name, struct cifs_sb_info *cifs_sb); 282 int remap_special_chars);
327extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, 283extern int CIFSSMBRmDir(const int xid, struct cifs_tcon *tcon,
284 const char *name, const struct nls_table *nls_codepage,
285 int remap_special_chars);
286extern int CIFSPOSIXDelFile(const int xid, struct cifs_tcon *tcon,
328 const char *name, __u16 type, 287 const char *name, __u16 type,
329 const struct nls_table *nls_codepage, 288 const struct nls_table *nls_codepage,
330 int remap_special_chars); 289 int remap_special_chars);
331extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, 290extern int CIFSSMBDelFile(const int xid, struct cifs_tcon *tcon,
332 const char *name, struct cifs_sb_info *cifs_sb); 291 const char *name,
333extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, 292 const struct nls_table *nls_codepage,
334 const char *from_name, const char *to_name, 293 int remap_special_chars);
335 struct cifs_sb_info *cifs_sb); 294extern int CIFSSMBRename(const int xid, struct cifs_tcon *tcon,
336extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, 295 const char *fromName, const char *toName,
337 int netfid, const char *target_name, 296 const struct nls_table *nls_codepage,
338 const struct nls_table *nls_codepage, 297 int remap_special_chars);
339 int remap_special_chars); 298extern int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon,
340extern int CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, 299 int netfid, const char *target_name,
341 const char *from_name, const char *to_name, 300 const struct nls_table *nls_codepage,
342 struct cifs_sb_info *cifs_sb); 301 int remap_special_chars);
343extern int CIFSUnixCreateHardLink(const unsigned int xid, 302extern int CIFSCreateHardLink(const int xid,
303 struct cifs_tcon *tcon,
304 const char *fromName, const char *toName,
305 const struct nls_table *nls_codepage,
306 int remap_special_chars);
307extern int CIFSUnixCreateHardLink(const int xid,
344 struct cifs_tcon *tcon, 308 struct cifs_tcon *tcon,
345 const char *fromName, const char *toName, 309 const char *fromName, const char *toName,
346 const struct nls_table *nls_codepage, 310 const struct nls_table *nls_codepage,
347 int remap_special_chars); 311 int remap_special_chars);
348extern int CIFSUnixCreateSymLink(const unsigned int xid, 312extern int CIFSUnixCreateSymLink(const int xid,
349 struct cifs_tcon *tcon, 313 struct cifs_tcon *tcon,
350 const char *fromName, const char *toName, 314 const char *fromName, const char *toName,
351 const struct nls_table *nls_codepage); 315 const struct nls_table *nls_codepage);
352extern int CIFSSMBUnixQuerySymLink(const unsigned int xid, 316extern int CIFSSMBUnixQuerySymLink(const int xid,
353 struct cifs_tcon *tcon, 317 struct cifs_tcon *tcon,
354 const unsigned char *searchName, char **syminfo, 318 const unsigned char *searchName, char **syminfo,
355 const struct nls_table *nls_codepage); 319 const struct nls_table *nls_codepage);
356#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL 320#ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL
357extern int CIFSSMBQueryReparseLinkInfo(const unsigned int xid, 321extern int CIFSSMBQueryReparseLinkInfo(const int xid,
358 struct cifs_tcon *tcon, 322 struct cifs_tcon *tcon,
359 const unsigned char *searchName, 323 const unsigned char *searchName,
360 char *symlinkinfo, const int buflen, __u16 fid, 324 char *symlinkinfo, const int buflen, __u16 fid,
361 const struct nls_table *nls_codepage); 325 const struct nls_table *nls_codepage);
362#endif /* temporarily unused until cifs_symlink fixed */ 326#endif /* temporarily unused until cifs_symlink fixed */
363extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, 327extern int CIFSSMBOpen(const int xid, struct cifs_tcon *tcon,
364 const char *fileName, const int disposition, 328 const char *fileName, const int disposition,
365 const int access_flags, const int omode, 329 const int access_flags, const int omode,
366 __u16 *netfid, int *pOplock, FILE_ALL_INFO *, 330 __u16 *netfid, int *pOplock, FILE_ALL_INFO *,
367 const struct nls_table *nls_codepage, int remap); 331 const struct nls_table *nls_codepage, int remap);
368extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, 332extern int SMBLegacyOpen(const int xid, struct cifs_tcon *tcon,
369 const char *fileName, const int disposition, 333 const char *fileName, const int disposition,
370 const int access_flags, const int omode, 334 const int access_flags, const int omode,
371 __u16 *netfid, int *pOplock, FILE_ALL_INFO *, 335 __u16 *netfid, int *pOplock, FILE_ALL_INFO *,
372 const struct nls_table *nls_codepage, int remap); 336 const struct nls_table *nls_codepage, int remap);
373extern int CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, 337extern int CIFSPOSIXCreate(const int xid, struct cifs_tcon *tcon,
374 u32 posix_flags, __u64 mode, __u16 *netfid, 338 u32 posix_flags, __u64 mode, __u16 *netfid,
375 FILE_UNIX_BASIC_INFO *pRetData, 339 FILE_UNIX_BASIC_INFO *pRetData,
376 __u32 *pOplock, const char *name, 340 __u32 *pOplock, const char *name,
377 const struct nls_table *nls_codepage, int remap); 341 const struct nls_table *nls_codepage, int remap);
378extern int CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, 342extern int CIFSSMBClose(const int xid, struct cifs_tcon *tcon,
379 const int smb_file_id); 343 const int smb_file_id);
380 344
381extern int CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, 345extern int CIFSSMBFlush(const int xid, struct cifs_tcon *tcon,
382 const int smb_file_id); 346 const int smb_file_id);
383 347
384extern int CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, 348extern int CIFSSMBRead(const int xid, struct cifs_io_parms *io_parms,
385 unsigned int *nbytes, char **buf, 349 unsigned int *nbytes, char **buf,
386 int *return_buf_type); 350 int *return_buf_type);
387extern int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, 351extern int CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms,
388 unsigned int *nbytes, const char *buf, 352 unsigned int *nbytes, const char *buf,
389 const char __user *ubuf, const int long_op); 353 const char __user *ubuf, const int long_op);
390extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, 354extern int CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms,
391 unsigned int *nbytes, struct kvec *iov, const int nvec); 355 unsigned int *nbytes, struct kvec *iov, const int nvec,
392extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, 356 const int long_op);
393 const char *search_name, __u64 *inode_number, 357extern int CIFSGetSrvInodeNumber(const int xid, struct cifs_tcon *tcon,
394 const struct nls_table *nls_codepage, 358 const unsigned char *searchName, __u64 *inode_number,
395 int remap); 359 const struct nls_table *nls_codepage,
360 int remap_special_chars);
396 361
397extern int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, 362extern int CIFSSMBLock(const int xid, struct cifs_tcon *tcon,
398 const __u16 netfid, const __u8 lock_type, 363 const __u16 netfid, const __u64 len,
399 const __u32 num_unlock, const __u32 num_lock,
400 LOCKING_ANDX_RANGE *buf);
401extern int CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
402 const __u16 netfid, const __u32 netpid, const __u64 len,
403 const __u64 offset, const __u32 numUnlock, 364 const __u64 offset, const __u32 numUnlock,
404 const __u32 numLock, const __u8 lockType, 365 const __u32 numLock, const __u8 lockType,
405 const bool waitFlag, const __u8 oplock_level); 366 const bool waitFlag, const __u8 oplock_level);
406extern int CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, 367extern int CIFSSMBPosixLock(const int xid, struct cifs_tcon *tcon,
407 const __u16 smb_file_id, const __u32 netpid, 368 const __u16 smb_file_id, const int get_flag,
408 const loff_t start_offset, const __u64 len, 369 const __u64 len, struct file_lock *,
409 struct file_lock *, const __u16 lock_type, 370 const __u16 lock_type, const bool waitFlag);
410 const bool waitFlag); 371extern int CIFSSMBTDis(const int xid, struct cifs_tcon *tcon);
411extern int CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon);
412extern int CIFSSMBEcho(struct TCP_Server_Info *server); 372extern int CIFSSMBEcho(struct TCP_Server_Info *server);
413extern int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses); 373extern int CIFSSMBLogoff(const int xid, struct cifs_ses *ses);
414 374
415extern struct cifs_ses *sesInfoAlloc(void); 375extern struct cifs_ses *sesInfoAlloc(void);
416extern void sesInfoFree(struct cifs_ses *); 376extern void sesInfoFree(struct cifs_ses *);
417extern struct cifs_tcon *tconInfoAlloc(void); 377extern struct cifs_tcon *tconInfoAlloc(void);
418extern void tconInfoFree(struct cifs_tcon *); 378extern void tconInfoFree(struct cifs_tcon *);
419 379
420extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
421 __u32 *pexpected_response_sequence_number);
422extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
423 __u32 *);
424extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); 380extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *);
425extern int cifs_verify_signature(struct smb_rqst *rqst, 381extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
382 __u32 *);
383extern int cifs_verify_signature(struct smb_hdr *,
426 struct TCP_Server_Info *server, 384 struct TCP_Server_Info *server,
427 __u32 expected_sequence_number); 385 __u32 expected_sequence_number);
428extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *, 386extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *);
429 const struct nls_table *); 387extern int setup_ntlm_response(struct cifs_ses *);
430extern int setup_ntlm_response(struct cifs_ses *, const struct nls_table *);
431extern int setup_ntlmv2_rsp(struct cifs_ses *, const struct nls_table *); 388extern int setup_ntlmv2_rsp(struct cifs_ses *, const struct nls_table *);
432extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *); 389extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *);
433extern void cifs_crypto_shash_release(struct TCP_Server_Info *); 390extern void cifs_crypto_shash_release(struct TCP_Server_Info *);
@@ -438,60 +395,66 @@ extern int calc_lanman_hash(const char *password, const char *cryptkey,
438 bool encrypt, char *lnm_session_key); 395 bool encrypt, char *lnm_session_key);
439#endif /* CIFS_WEAK_PW_HASH */ 396#endif /* CIFS_WEAK_PW_HASH */
440#ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */ 397#ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
441extern int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon, 398extern int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon,
442 const int notify_subdirs, const __u16 netfid, 399 const int notify_subdirs, const __u16 netfid,
443 __u32 filter, struct file *file, int multishot, 400 __u32 filter, struct file *file, int multishot,
444 const struct nls_table *nls_codepage); 401 const struct nls_table *nls_codepage);
445#endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ 402#endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
446extern int CIFSSMBCopy(unsigned int xid, 403extern int CIFSSMBCopy(int xid,
447 struct cifs_tcon *source_tcon, 404 struct cifs_tcon *source_tcon,
448 const char *fromName, 405 const char *fromName,
449 const __u16 target_tid, 406 const __u16 target_tid,
450 const char *toName, const int flags, 407 const char *toName, const int flags,
451 const struct nls_table *nls_codepage, 408 const struct nls_table *nls_codepage,
452 int remap_special_chars); 409 int remap_special_chars);
453extern ssize_t CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, 410extern ssize_t CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon,
454 const unsigned char *searchName, 411 const unsigned char *searchName,
455 const unsigned char *ea_name, char *EAData, 412 const unsigned char *ea_name, char *EAData,
456 size_t bufsize, const struct nls_table *nls_codepage, 413 size_t bufsize, const struct nls_table *nls_codepage,
457 int remap_special_chars); 414 int remap_special_chars);
458extern int CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, 415extern int CIFSSMBSetEA(const int xid, struct cifs_tcon *tcon,
459 const char *fileName, const char *ea_name, 416 const char *fileName, const char *ea_name,
460 const void *ea_value, const __u16 ea_value_len, 417 const void *ea_value, const __u16 ea_value_len,
461 const struct nls_table *nls_codepage, int remap_special_chars); 418 const struct nls_table *nls_codepage, int remap_special_chars);
462extern int CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, 419extern int CIFSSMBGetCIFSACL(const int xid, struct cifs_tcon *tcon,
463 __u16 fid, struct cifs_ntsd **acl_inf, __u32 *buflen); 420 __u16 fid, struct cifs_ntsd **acl_inf, __u32 *buflen);
464extern int CIFSSMBSetCIFSACL(const unsigned int, struct cifs_tcon *, __u16, 421extern int CIFSSMBSetCIFSACL(const int, struct cifs_tcon *, __u16,
465 struct cifs_ntsd *, __u32, int); 422 struct cifs_ntsd *, __u32);
466extern int CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, 423extern int CIFSSMBGetPosixACL(const int xid, struct cifs_tcon *tcon,
467 const unsigned char *searchName, 424 const unsigned char *searchName,
468 char *acl_inf, const int buflen, const int acl_type, 425 char *acl_inf, const int buflen, const int acl_type,
469 const struct nls_table *nls_codepage, int remap_special_chars); 426 const struct nls_table *nls_codepage, int remap_special_chars);
470extern int CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, 427extern int CIFSSMBSetPosixACL(const int xid, struct cifs_tcon *tcon,
471 const unsigned char *fileName, 428 const unsigned char *fileName,
472 const char *local_acl, const int buflen, const int acl_type, 429 const char *local_acl, const int buflen, const int acl_type,
473 const struct nls_table *nls_codepage, int remap_special_chars); 430 const struct nls_table *nls_codepage, int remap_special_chars);
474extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, 431extern int CIFSGetExtAttr(const int xid, struct cifs_tcon *tcon,
475 const int netfid, __u64 *pExtAttrBits, __u64 *pMask); 432 const int netfid, __u64 *pExtAttrBits, __u64 *pMask);
476extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb); 433extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb);
477extern bool CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr); 434extern bool CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr);
478extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr, 435extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr,
479 const unsigned char *path, 436 const unsigned char *path,
480 struct cifs_sb_info *cifs_sb, unsigned int xid); 437 struct cifs_sb_info *cifs_sb, int xid);
481extern int mdfour(unsigned char *, unsigned char *, int); 438extern int mdfour(unsigned char *, unsigned char *, int);
482extern int E_md4hash(const unsigned char *passwd, unsigned char *p16, 439extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);
483 const struct nls_table *codepage);
484extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8, 440extern int SMBencrypt(unsigned char *passwd, const unsigned char *c8,
485 unsigned char *p24); 441 unsigned char *p24);
486 442
487void cifs_readdata_release(struct kref *refcount); 443/* asynchronous write support */
488int cifs_async_readv(struct cifs_readdata *rdata); 444struct cifs_writedata {
489int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid); 445 struct kref refcount;
446 enum writeback_sync_modes sync_mode;
447 struct work_struct work;
448 struct cifsFileInfo *cfile;
449 __u64 offset;
450 unsigned int bytes;
451 int result;
452 unsigned int nr_pages;
453 struct page *pages[1];
454};
490 455
491int cifs_async_writev(struct cifs_writedata *wdata); 456int cifs_async_writev(struct cifs_writedata *wdata);
492void cifs_writev_complete(struct work_struct *work); 457struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages);
493struct cifs_writedata *cifs_writedata_alloc(unsigned int nr_pages,
494 work_func_t complete);
495void cifs_writedata_release(struct kref *refcount); 458void cifs_writedata_release(struct kref *refcount);
496 459
497#endif /* _CIFSPROTO_H */ 460#endif /* _CIFSPROTO_H */
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 76d0d299885..a80f7bd97b9 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -33,8 +33,6 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/posix_acl_xattr.h> 34#include <linux/posix_acl_xattr.h>
35#include <linux/pagemap.h> 35#include <linux/pagemap.h>
36#include <linux/swap.h>
37#include <linux/task_io_accounting_ops.h>
38#include <asm/uaccess.h> 36#include <asm/uaccess.h>
39#include "cifspdu.h" 37#include "cifspdu.h"
40#include "cifsglob.h" 38#include "cifsglob.h"
@@ -42,7 +40,6 @@
42#include "cifsproto.h" 40#include "cifsproto.h"
43#include "cifs_unicode.h" 41#include "cifs_unicode.h"
44#include "cifs_debug.h" 42#include "cifs_debug.h"
45#include "fscache.h"
46 43
47#ifdef CONFIG_CIFS_POSIX 44#ifdef CONFIG_CIFS_POSIX
48static struct { 45static struct {
@@ -86,29 +83,24 @@ static struct {
86#endif /* CONFIG_CIFS_WEAK_PW_HASH */ 83#endif /* CONFIG_CIFS_WEAK_PW_HASH */
87#endif /* CIFS_POSIX */ 84#endif /* CIFS_POSIX */
88 85
89/* 86/* Mark as invalid, all open files on tree connections since they
90 * Mark as invalid, all open files on tree connections since they 87 were closed when session to server was lost */
91 * were closed when session to server was lost. 88static void mark_open_files_invalid(struct cifs_tcon *pTcon)
92 */
93void
94cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
95{ 89{
96 struct cifsFileInfo *open_file = NULL; 90 struct cifsFileInfo *open_file = NULL;
97 struct list_head *tmp; 91 struct list_head *tmp;
98 struct list_head *tmp1; 92 struct list_head *tmp1;
99 93
100 /* list all files open on tree connection and mark them invalid */ 94/* list all files open on tree connection and mark them invalid */
101 spin_lock(&cifs_file_list_lock); 95 spin_lock(&cifs_file_list_lock);
102 list_for_each_safe(tmp, tmp1, &tcon->openFileList) { 96 list_for_each_safe(tmp, tmp1, &pTcon->openFileList) {
103 open_file = list_entry(tmp, struct cifsFileInfo, tlist); 97 open_file = list_entry(tmp, struct cifsFileInfo, tlist);
104 open_file->invalidHandle = true; 98 open_file->invalidHandle = true;
105 open_file->oplock_break_cancelled = true; 99 open_file->oplock_break_cancelled = true;
106 } 100 }
107 spin_unlock(&cifs_file_list_lock); 101 spin_unlock(&cifs_file_list_lock);
108 /* 102 /* BB Add call to invalidate_inodes(sb) for all superblocks mounted
109 * BB Add call to invalidate_inodes(sb) for all superblocks mounted 103 to this tcon */
110 * to this tcon.
111 */
112} 104}
113 105
114/* reconnect the socket, tcon, and smb session if needed */ 106/* reconnect the socket, tcon, and smb session if needed */
@@ -188,7 +180,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
188 goto out; 180 goto out;
189 } 181 }
190 182
191 cifs_mark_open_files_invalid(tcon); 183 mark_open_files_invalid(tcon);
192 rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); 184 rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage);
193 mutex_unlock(&ses->session_mutex); 185 mutex_unlock(&ses->session_mutex);
194 cFYI(1, "reconnect tcon rc = %d", rc); 186 cFYI(1, "reconnect tcon rc = %d", rc);
@@ -271,7 +263,7 @@ small_smb_init_no_tc(const int smb_command, const int wct,
271 return rc; 263 return rc;
272 264
273 buffer = (struct smb_hdr *)*request_buf; 265 buffer = (struct smb_hdr *)*request_buf;
274 buffer->Mid = get_next_mid(ses->server); 266 buffer->Mid = GetNextMid(ses->server);
275 if (ses->capabilities & CAP_UNICODE) 267 if (ses->capabilities & CAP_UNICODE)
276 buffer->Flags2 |= SMBFLG2_UNICODE; 268 buffer->Flags2 |= SMBFLG2_UNICODE;
277 if (ses->capabilities & CAP_STATUS32) 269 if (ses->capabilities & CAP_STATUS32)
@@ -367,8 +359,15 @@ vt2_err:
367 return -EINVAL; 359 return -EINVAL;
368} 360}
369 361
362static inline void inc_rfc1001_len(void *pSMB, int count)
363{
364 struct smb_hdr *hdr = (struct smb_hdr *)pSMB;
365
366 be32_add_cpu(&hdr->smb_buf_length, count);
367}
368
370int 369int
371CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses) 370CIFSSMBNegotiate(unsigned int xid, struct cifs_ses *ses)
372{ 371{
373 NEGOTIATE_REQ *pSMB; 372 NEGOTIATE_REQ *pSMB;
374 NEGOTIATE_RSP *pSMBr; 373 NEGOTIATE_RSP *pSMBr;
@@ -398,7 +397,7 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses)
398 397
399 cFYI(1, "secFlags 0x%x", secFlags); 398 cFYI(1, "secFlags 0x%x", secFlags);
400 399
401 pSMB->hdr.Mid = get_next_mid(server); 400 pSMB->hdr.Mid = GetNextMid(server);
402 pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); 401 pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS);
403 402
404 if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) 403 if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
@@ -452,12 +451,10 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses)
452 rc = -EOPNOTSUPP; 451 rc = -EOPNOTSUPP;
453 goto neg_err_exit; 452 goto neg_err_exit;
454 } 453 }
455 server->sec_mode = le16_to_cpu(rsp->SecurityMode); 454 server->sec_mode = (__u8)le16_to_cpu(rsp->SecurityMode);
456 server->maxReq = min_t(unsigned int, 455 server->maxReq = le16_to_cpu(rsp->MaxMpxCount);
457 le16_to_cpu(rsp->MaxMpxCount), 456 server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize),
458 cifs_max_pending); 457 (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
459 set_credits(server, server->maxReq);
460 server->maxBuf = le16_to_cpu(rsp->MaxBufSize);
461 server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); 458 server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs);
462 /* even though we do not use raw we might as well set this 459 /* even though we do not use raw we might as well set this
463 accurately, in case we ever find a need for it */ 460 accurately, in case we ever find a need for it */
@@ -562,11 +559,10 @@ CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses)
562 559
563 /* one byte, so no need to convert this or EncryptionKeyLen from 560 /* one byte, so no need to convert this or EncryptionKeyLen from
564 little endian */ 561 little endian */
565 server->maxReq = min_t(unsigned int, le16_to_cpu(pSMBr->MaxMpxCount), 562 server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount);
566 cifs_max_pending);
567 set_credits(server, server->maxReq);
568 /* probably no need to store and check maxvcs */ 563 /* probably no need to store and check maxvcs */
569 server->maxBuf = le32_to_cpu(pSMBr->MaxBufferSize); 564 server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize),
565 (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
570 server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); 566 server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
571 cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); 567 cFYI(DBG2, "Max buf = %d", ses->server->maxBuf);
572 server->capabilities = le32_to_cpu(pSMBr->Capabilities); 568 server->capabilities = le32_to_cpu(pSMBr->Capabilities);
@@ -666,7 +662,7 @@ neg_err_exit:
666} 662}
667 663
668int 664int
669CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon) 665CIFSSMBTDis(const int xid, struct cifs_tcon *tcon)
670{ 666{
671 struct smb_hdr *smb_buffer; 667 struct smb_hdr *smb_buffer;
672 int rc = 0; 668 int rc = 0;
@@ -691,7 +687,7 @@ CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon)
691 if (rc) 687 if (rc)
692 return rc; 688 return rc;
693 689
694 rc = SendReceiveNoRsp(xid, tcon->ses, (char *)smb_buffer, 0); 690 rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0);
695 if (rc) 691 if (rc)
696 cFYI(1, "Tree disconnect failed %d", rc); 692 cFYI(1, "Tree disconnect failed %d", rc);
697 693
@@ -716,7 +712,8 @@ cifs_echo_callback(struct mid_q_entry *mid)
716 struct TCP_Server_Info *server = mid->callback_data; 712 struct TCP_Server_Info *server = mid->callback_data;
717 713
718 DeleteMidQEntry(mid); 714 DeleteMidQEntry(mid);
719 add_credits(server, 1, CIFS_ECHO_OP); 715 atomic_dec(&server->inFlight);
716 wake_up(&server->request_q);
720} 717}
721 718
722int 719int
@@ -725,8 +722,6 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
725 ECHO_REQ *smb; 722 ECHO_REQ *smb;
726 int rc = 0; 723 int rc = 0;
727 struct kvec iov; 724 struct kvec iov;
728 struct smb_rqst rqst = { .rq_iov = &iov,
729 .rq_nvec = 1 };
730 725
731 cFYI(1, "In echo request"); 726 cFYI(1, "In echo request");
732 727
@@ -744,8 +739,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
744 iov.iov_base = smb; 739 iov.iov_base = smb;
745 iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; 740 iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4;
746 741
747 rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, 742 rc = cifs_call_async(server, &iov, 1, cifs_echo_callback, server, true);
748 server, CIFS_ASYNC_OP | CIFS_ECHO_OP);
749 if (rc) 743 if (rc)
750 cFYI(1, "Echo request failed: %d", rc); 744 cFYI(1, "Echo request failed: %d", rc);
751 745
@@ -755,7 +749,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
755} 749}
756 750
757int 751int
758CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses) 752CIFSSMBLogoff(const int xid, struct cifs_ses *ses)
759{ 753{
760 LOGOFF_ANDX_REQ *pSMB; 754 LOGOFF_ANDX_REQ *pSMB;
761 int rc = 0; 755 int rc = 0;
@@ -780,7 +774,7 @@ CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses)
780 return rc; 774 return rc;
781 } 775 }
782 776
783 pSMB->hdr.Mid = get_next_mid(ses->server); 777 pSMB->hdr.Mid = GetNextMid(ses->server);
784 778
785 if (ses->server->sec_mode & 779 if (ses->server->sec_mode &
786 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) 780 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
@@ -789,7 +783,7 @@ CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses)
789 pSMB->hdr.Uid = ses->Suid; 783 pSMB->hdr.Uid = ses->Suid;
790 784
791 pSMB->AndXCommand = 0xFF; 785 pSMB->AndXCommand = 0xFF;
792 rc = SendReceiveNoRsp(xid, ses, (char *) pSMB, 0); 786 rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0);
793session_already_dead: 787session_already_dead:
794 mutex_unlock(&ses->session_mutex); 788 mutex_unlock(&ses->session_mutex);
795 789
@@ -802,9 +796,8 @@ session_already_dead:
802} 796}
803 797
804int 798int
805CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, 799CIFSPOSIXDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName,
806 const char *fileName, __u16 type, 800 __u16 type, const struct nls_table *nls_codepage, int remap)
807 const struct nls_table *nls_codepage, int remap)
808{ 801{
809 TRANSACTION2_SPI_REQ *pSMB = NULL; 802 TRANSACTION2_SPI_REQ *pSMB = NULL;
810 TRANSACTION2_SPI_RSP *pSMBr = NULL; 803 TRANSACTION2_SPI_RSP *pSMBr = NULL;
@@ -823,8 +816,8 @@ PsxDelete:
823 816
824 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 817 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
825 name_len = 818 name_len =
826 cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, 819 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
827 PATH_MAX, nls_codepage, remap); 820 PATH_MAX, nls_codepage, remap);
828 name_len++; /* trailing null */ 821 name_len++; /* trailing null */
829 name_len *= 2; 822 name_len *= 2;
830 } else { /* BB add path length overrun check */ 823 } else { /* BB add path length overrun check */
@@ -869,7 +862,7 @@ PsxDelete:
869 cFYI(1, "Posix delete returned %d", rc); 862 cFYI(1, "Posix delete returned %d", rc);
870 cifs_buf_release(pSMB); 863 cifs_buf_release(pSMB);
871 864
872 cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); 865 cifs_stats_inc(&tcon->num_deletes);
873 866
874 if (rc == -EAGAIN) 867 if (rc == -EAGAIN)
875 goto PsxDelete; 868 goto PsxDelete;
@@ -878,15 +871,14 @@ PsxDelete:
878} 871}
879 872
880int 873int
881CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, const char *name, 874CIFSSMBDelFile(const int xid, struct cifs_tcon *tcon, const char *fileName,
882 struct cifs_sb_info *cifs_sb) 875 const struct nls_table *nls_codepage, int remap)
883{ 876{
884 DELETE_FILE_REQ *pSMB = NULL; 877 DELETE_FILE_REQ *pSMB = NULL;
885 DELETE_FILE_RSP *pSMBr = NULL; 878 DELETE_FILE_RSP *pSMBr = NULL;
886 int rc = 0; 879 int rc = 0;
887 int bytes_returned; 880 int bytes_returned;
888 int name_len; 881 int name_len;
889 int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
890 882
891DelFileRetry: 883DelFileRetry:
892 rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, 884 rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB,
@@ -895,15 +887,15 @@ DelFileRetry:
895 return rc; 887 return rc;
896 888
897 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 889 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
898 name_len = cifsConvertToUTF16((__le16 *) pSMB->fileName, name, 890 name_len =
899 PATH_MAX, cifs_sb->local_nls, 891 cifsConvertToUCS((__le16 *) pSMB->fileName, fileName,
900 remap); 892 PATH_MAX, nls_codepage, remap);
901 name_len++; /* trailing null */ 893 name_len++; /* trailing null */
902 name_len *= 2; 894 name_len *= 2;
903 } else { /* BB improve check for buffer overruns BB */ 895 } else { /* BB improve check for buffer overruns BB */
904 name_len = strnlen(name, PATH_MAX); 896 name_len = strnlen(fileName, PATH_MAX);
905 name_len++; /* trailing null */ 897 name_len++; /* trailing null */
906 strncpy(pSMB->fileName, name, name_len); 898 strncpy(pSMB->fileName, fileName, name_len);
907 } 899 }
908 pSMB->SearchAttributes = 900 pSMB->SearchAttributes =
909 cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); 901 cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM);
@@ -912,7 +904,7 @@ DelFileRetry:
912 pSMB->ByteCount = cpu_to_le16(name_len + 1); 904 pSMB->ByteCount = cpu_to_le16(name_len + 1);
913 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 905 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
914 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 906 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
915 cifs_stats_inc(&tcon->stats.cifs_stats.num_deletes); 907 cifs_stats_inc(&tcon->num_deletes);
916 if (rc) 908 if (rc)
917 cFYI(1, "Error in RMFile = %d", rc); 909 cFYI(1, "Error in RMFile = %d", rc);
918 910
@@ -924,15 +916,14 @@ DelFileRetry:
924} 916}
925 917
926int 918int
927CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, 919CIFSSMBRmDir(const int xid, struct cifs_tcon *tcon, const char *dirName,
928 struct cifs_sb_info *cifs_sb) 920 const struct nls_table *nls_codepage, int remap)
929{ 921{
930 DELETE_DIRECTORY_REQ *pSMB = NULL; 922 DELETE_DIRECTORY_REQ *pSMB = NULL;
931 DELETE_DIRECTORY_RSP *pSMBr = NULL; 923 DELETE_DIRECTORY_RSP *pSMBr = NULL;
932 int rc = 0; 924 int rc = 0;
933 int bytes_returned; 925 int bytes_returned;
934 int name_len; 926 int name_len;
935 int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
936 927
937 cFYI(1, "In CIFSSMBRmDir"); 928 cFYI(1, "In CIFSSMBRmDir");
938RmDirRetry: 929RmDirRetry:
@@ -942,15 +933,14 @@ RmDirRetry:
942 return rc; 933 return rc;
943 934
944 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 935 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
945 name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, 936 name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName,
946 PATH_MAX, cifs_sb->local_nls, 937 PATH_MAX, nls_codepage, remap);
947 remap);
948 name_len++; /* trailing null */ 938 name_len++; /* trailing null */
949 name_len *= 2; 939 name_len *= 2;
950 } else { /* BB improve check for buffer overruns BB */ 940 } else { /* BB improve check for buffer overruns BB */
951 name_len = strnlen(name, PATH_MAX); 941 name_len = strnlen(dirName, PATH_MAX);
952 name_len++; /* trailing null */ 942 name_len++; /* trailing null */
953 strncpy(pSMB->DirName, name, name_len); 943 strncpy(pSMB->DirName, dirName, name_len);
954 } 944 }
955 945
956 pSMB->BufferFormat = 0x04; 946 pSMB->BufferFormat = 0x04;
@@ -958,7 +948,7 @@ RmDirRetry:
958 pSMB->ByteCount = cpu_to_le16(name_len + 1); 948 pSMB->ByteCount = cpu_to_le16(name_len + 1);
959 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 949 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
960 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 950 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
961 cifs_stats_inc(&tcon->stats.cifs_stats.num_rmdirs); 951 cifs_stats_inc(&tcon->num_rmdirs);
962 if (rc) 952 if (rc)
963 cFYI(1, "Error in RMDir = %d", rc); 953 cFYI(1, "Error in RMDir = %d", rc);
964 954
@@ -969,15 +959,14 @@ RmDirRetry:
969} 959}
970 960
971int 961int
972CIFSSMBMkDir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, 962CIFSSMBMkDir(const int xid, struct cifs_tcon *tcon,
973 struct cifs_sb_info *cifs_sb) 963 const char *name, const struct nls_table *nls_codepage, int remap)
974{ 964{
975 int rc = 0; 965 int rc = 0;
976 CREATE_DIRECTORY_REQ *pSMB = NULL; 966 CREATE_DIRECTORY_REQ *pSMB = NULL;
977 CREATE_DIRECTORY_RSP *pSMBr = NULL; 967 CREATE_DIRECTORY_RSP *pSMBr = NULL;
978 int bytes_returned; 968 int bytes_returned;
979 int name_len; 969 int name_len;
980 int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
981 970
982 cFYI(1, "In CIFSSMBMkDir"); 971 cFYI(1, "In CIFSSMBMkDir");
983MkDirRetry: 972MkDirRetry:
@@ -987,9 +976,8 @@ MkDirRetry:
987 return rc; 976 return rc;
988 977
989 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 978 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
990 name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name, 979 name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name,
991 PATH_MAX, cifs_sb->local_nls, 980 PATH_MAX, nls_codepage, remap);
992 remap);
993 name_len++; /* trailing null */ 981 name_len++; /* trailing null */
994 name_len *= 2; 982 name_len *= 2;
995 } else { /* BB improve check for buffer overruns BB */ 983 } else { /* BB improve check for buffer overruns BB */
@@ -1003,7 +991,7 @@ MkDirRetry:
1003 pSMB->ByteCount = cpu_to_le16(name_len + 1); 991 pSMB->ByteCount = cpu_to_le16(name_len + 1);
1004 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 992 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1005 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 993 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
1006 cifs_stats_inc(&tcon->stats.cifs_stats.num_mkdirs); 994 cifs_stats_inc(&tcon->num_mkdirs);
1007 if (rc) 995 if (rc)
1008 cFYI(1, "Error in Mkdir = %d", rc); 996 cFYI(1, "Error in Mkdir = %d", rc);
1009 997
@@ -1014,11 +1002,10 @@ MkDirRetry:
1014} 1002}
1015 1003
1016int 1004int
1017CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, 1005CIFSPOSIXCreate(const int xid, struct cifs_tcon *tcon, __u32 posix_flags,
1018 __u32 posix_flags, __u64 mode, __u16 *netfid, 1006 __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData,
1019 FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock, 1007 __u32 *pOplock, const char *name,
1020 const char *name, const struct nls_table *nls_codepage, 1008 const struct nls_table *nls_codepage, int remap)
1021 int remap)
1022{ 1009{
1023 TRANSACTION2_SPI_REQ *pSMB = NULL; 1010 TRANSACTION2_SPI_REQ *pSMB = NULL;
1024 TRANSACTION2_SPI_RSP *pSMBr = NULL; 1011 TRANSACTION2_SPI_RSP *pSMBr = NULL;
@@ -1038,8 +1025,8 @@ PsxCreat:
1038 1025
1039 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 1026 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
1040 name_len = 1027 name_len =
1041 cifsConvertToUTF16((__le16 *) pSMB->FileName, name, 1028 cifsConvertToUCS((__le16 *) pSMB->FileName, name,
1042 PATH_MAX, nls_codepage, remap); 1029 PATH_MAX, nls_codepage, remap);
1043 name_len++; /* trailing null */ 1030 name_len++; /* trailing null */
1044 name_len *= 2; 1031 name_len *= 2;
1045 } else { /* BB improve the check for buffer overruns BB */ 1032 } else { /* BB improve the check for buffer overruns BB */
@@ -1126,9 +1113,9 @@ psx_create_err:
1126 cifs_buf_release(pSMB); 1113 cifs_buf_release(pSMB);
1127 1114
1128 if (posix_flags & SMB_O_DIRECTORY) 1115 if (posix_flags & SMB_O_DIRECTORY)
1129 cifs_stats_inc(&tcon->stats.cifs_stats.num_posixmkdirs); 1116 cifs_stats_inc(&tcon->num_posixmkdirs);
1130 else 1117 else
1131 cifs_stats_inc(&tcon->stats.cifs_stats.num_posixopens); 1118 cifs_stats_inc(&tcon->num_posixopens);
1132 1119
1133 if (rc == -EAGAIN) 1120 if (rc == -EAGAIN)
1134 goto PsxCreat; 1121 goto PsxCreat;
@@ -1181,7 +1168,7 @@ access_flags_to_smbopen_mode(const int access_flags)
1181} 1168}
1182 1169
1183int 1170int
1184SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, 1171SMBLegacyOpen(const int xid, struct cifs_tcon *tcon,
1185 const char *fileName, const int openDisposition, 1172 const char *fileName, const int openDisposition,
1186 const int access_flags, const int create_options, __u16 *netfid, 1173 const int access_flags, const int create_options, __u16 *netfid,
1187 int *pOplock, FILE_ALL_INFO *pfile_info, 1174 int *pOplock, FILE_ALL_INFO *pfile_info,
@@ -1205,8 +1192,8 @@ OldOpenRetry:
1205 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 1192 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
1206 count = 1; /* account for one byte pad to word boundary */ 1193 count = 1; /* account for one byte pad to word boundary */
1207 name_len = 1194 name_len =
1208 cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), 1195 cifsConvertToUCS((__le16 *) (pSMB->fileName + 1),
1209 fileName, PATH_MAX, nls_codepage, remap); 1196 fileName, PATH_MAX, nls_codepage, remap);
1210 name_len++; /* trailing null */ 1197 name_len++; /* trailing null */
1211 name_len *= 2; 1198 name_len *= 2;
1212 } else { /* BB improve check for buffer overruns BB */ 1199 } else { /* BB improve check for buffer overruns BB */
@@ -1249,7 +1236,7 @@ OldOpenRetry:
1249 /* long_op set to 1 to allow for oplock break timeouts */ 1236 /* long_op set to 1 to allow for oplock break timeouts */
1250 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 1237 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1251 (struct smb_hdr *)pSMBr, &bytes_returned, 0); 1238 (struct smb_hdr *)pSMBr, &bytes_returned, 0);
1252 cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); 1239 cifs_stats_inc(&tcon->num_opens);
1253 if (rc) { 1240 if (rc) {
1254 cFYI(1, "Error in Open = %d", rc); 1241 cFYI(1, "Error in Open = %d", rc);
1255 } else { 1242 } else {
@@ -1288,7 +1275,7 @@ OldOpenRetry:
1288} 1275}
1289 1276
1290int 1277int
1291CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, 1278CIFSSMBOpen(const int xid, struct cifs_tcon *tcon,
1292 const char *fileName, const int openDisposition, 1279 const char *fileName, const int openDisposition,
1293 const int access_flags, const int create_options, __u16 *netfid, 1280 const int access_flags, const int create_options, __u16 *netfid,
1294 int *pOplock, FILE_ALL_INFO *pfile_info, 1281 int *pOplock, FILE_ALL_INFO *pfile_info,
@@ -1312,8 +1299,8 @@ openRetry:
1312 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 1299 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
1313 count = 1; /* account for one byte pad to word boundary */ 1300 count = 1; /* account for one byte pad to word boundary */
1314 name_len = 1301 name_len =
1315 cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), 1302 cifsConvertToUCS((__le16 *) (pSMB->fileName + 1),
1316 fileName, PATH_MAX, nls_codepage, remap); 1303 fileName, PATH_MAX, nls_codepage, remap);
1317 name_len++; /* trailing null */ 1304 name_len++; /* trailing null */
1318 name_len *= 2; 1305 name_len *= 2;
1319 pSMB->NameLength = cpu_to_le16(name_len); 1306 pSMB->NameLength = cpu_to_le16(name_len);
@@ -1362,7 +1349,7 @@ openRetry:
1362 /* long_op set to 1 to allow for oplock break timeouts */ 1349 /* long_op set to 1 to allow for oplock break timeouts */
1363 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 1350 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1364 (struct smb_hdr *)pSMBr, &bytes_returned, 0); 1351 (struct smb_hdr *)pSMBr, &bytes_returned, 0);
1365 cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); 1352 cifs_stats_inc(&tcon->num_opens);
1366 if (rc) { 1353 if (rc) {
1367 cFYI(1, "Error in Open = %d", rc); 1354 cFYI(1, "Error in Open = %d", rc);
1368 } else { 1355 } else {
@@ -1389,256 +1376,9 @@ openRetry:
1389 return rc; 1376 return rc;
1390} 1377}
1391 1378
1392/*
1393 * Discard any remaining data in the current SMB. To do this, we borrow the
1394 * current bigbuf.
1395 */
1396static int
1397cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1398{
1399 unsigned int rfclen = get_rfc1002_length(server->smallbuf);
1400 int remaining = rfclen + 4 - server->total_read;
1401 struct cifs_readdata *rdata = mid->callback_data;
1402
1403 while (remaining > 0) {
1404 int length;
1405
1406 length = cifs_read_from_socket(server, server->bigbuf,
1407 min_t(unsigned int, remaining,
1408 CIFSMaxBufSize + MAX_HEADER_SIZE(server)));
1409 if (length < 0)
1410 return length;
1411 server->total_read += length;
1412 remaining -= length;
1413 }
1414
1415 dequeue_mid(mid, rdata->result);
1416 return 0;
1417}
1418
1419int
1420cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
1421{
1422 int length, len;
1423 unsigned int data_offset, data_len;
1424 struct cifs_readdata *rdata = mid->callback_data;
1425 char *buf = server->smallbuf;
1426 unsigned int buflen = get_rfc1002_length(buf) + 4;
1427
1428 cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__,
1429 mid->mid, rdata->offset, rdata->bytes);
1430
1431 /*
1432 * read the rest of READ_RSP header (sans Data array), or whatever we
1433 * can if there's not enough data. At this point, we've read down to
1434 * the Mid.
1435 */
1436 len = min_t(unsigned int, buflen, server->vals->read_rsp_size) -
1437 HEADER_SIZE(server) + 1;
1438
1439 rdata->iov.iov_base = buf + HEADER_SIZE(server) - 1;
1440 rdata->iov.iov_len = len;
1441
1442 length = cifs_readv_from_socket(server, &rdata->iov, 1, len);
1443 if (length < 0)
1444 return length;
1445 server->total_read += length;
1446
1447 /* Was the SMB read successful? */
1448 rdata->result = server->ops->map_error(buf, false);
1449 if (rdata->result != 0) {
1450 cFYI(1, "%s: server returned error %d", __func__,
1451 rdata->result);
1452 return cifs_readv_discard(server, mid);
1453 }
1454
1455 /* Is there enough to get to the rest of the READ_RSP header? */
1456 if (server->total_read < server->vals->read_rsp_size) {
1457 cFYI(1, "%s: server returned short header. got=%u expected=%zu",
1458 __func__, server->total_read,
1459 server->vals->read_rsp_size);
1460 rdata->result = -EIO;
1461 return cifs_readv_discard(server, mid);
1462 }
1463
1464 data_offset = server->ops->read_data_offset(buf) + 4;
1465 if (data_offset < server->total_read) {
1466 /*
1467 * win2k8 sometimes sends an offset of 0 when the read
1468 * is beyond the EOF. Treat it as if the data starts just after
1469 * the header.
1470 */
1471 cFYI(1, "%s: data offset (%u) inside read response header",
1472 __func__, data_offset);
1473 data_offset = server->total_read;
1474 } else if (data_offset > MAX_CIFS_SMALL_BUFFER_SIZE) {
1475 /* data_offset is beyond the end of smallbuf */
1476 cFYI(1, "%s: data offset (%u) beyond end of smallbuf",
1477 __func__, data_offset);
1478 rdata->result = -EIO;
1479 return cifs_readv_discard(server, mid);
1480 }
1481
1482 cFYI(1, "%s: total_read=%u data_offset=%u", __func__,
1483 server->total_read, data_offset);
1484
1485 len = data_offset - server->total_read;
1486 if (len > 0) {
1487 /* read any junk before data into the rest of smallbuf */
1488 rdata->iov.iov_base = buf + server->total_read;
1489 rdata->iov.iov_len = len;
1490 length = cifs_readv_from_socket(server, &rdata->iov, 1, len);
1491 if (length < 0)
1492 return length;
1493 server->total_read += length;
1494 }
1495
1496 /* set up first iov for signature check */
1497 rdata->iov.iov_base = buf;
1498 rdata->iov.iov_len = server->total_read;
1499 cFYI(1, "0: iov_base=%p iov_len=%zu",
1500 rdata->iov.iov_base, rdata->iov.iov_len);
1501
1502 /* how much data is in the response? */
1503 data_len = server->ops->read_data_length(buf);
1504 if (data_offset + data_len > buflen) {
1505 /* data_len is corrupt -- discard frame */
1506 rdata->result = -EIO;
1507 return cifs_readv_discard(server, mid);
1508 }
1509
1510 length = rdata->read_into_pages(server, rdata, data_len);
1511 if (length < 0)
1512 return length;
1513
1514 server->total_read += length;
1515 rdata->bytes = length;
1516
1517 cFYI(1, "total_read=%u buflen=%u remaining=%u", server->total_read,
1518 buflen, data_len);
1519
1520 /* discard anything left over */
1521 if (server->total_read < buflen)
1522 return cifs_readv_discard(server, mid);
1523
1524 dequeue_mid(mid, false);
1525 return length;
1526}
1527
1528static void
1529cifs_readv_callback(struct mid_q_entry *mid)
1530{
1531 struct cifs_readdata *rdata = mid->callback_data;
1532 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
1533 struct TCP_Server_Info *server = tcon->ses->server;
1534 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
1535 .rq_nvec = 1,
1536 .rq_pages = rdata->pages,
1537 .rq_npages = rdata->nr_pages,
1538 .rq_pagesz = rdata->pagesz,
1539 .rq_tailsz = rdata->tailsz };
1540
1541 cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__,
1542 mid->mid, mid->mid_state, rdata->result, rdata->bytes);
1543
1544 switch (mid->mid_state) {
1545 case MID_RESPONSE_RECEIVED:
1546 /* result already set, check signature */
1547 if (server->sec_mode &
1548 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
1549 int rc = 0;
1550
1551 rc = cifs_verify_signature(&rqst, server,
1552 mid->sequence_number + 1);
1553 if (rc)
1554 cERROR(1, "SMB signature verification returned "
1555 "error = %d", rc);
1556 }
1557 /* FIXME: should this be counted toward the initiating task? */
1558 task_io_account_read(rdata->bytes);
1559 cifs_stats_bytes_read(tcon, rdata->bytes);
1560 break;
1561 case MID_REQUEST_SUBMITTED:
1562 case MID_RETRY_NEEDED:
1563 rdata->result = -EAGAIN;
1564 break;
1565 default:
1566 rdata->result = -EIO;
1567 }
1568
1569 queue_work(cifsiod_wq, &rdata->work);
1570 DeleteMidQEntry(mid);
1571 add_credits(server, 1, 0);
1572}
1573
1574/* cifs_async_readv - send an async write, and set up mid to handle result */
1575int 1379int
1576cifs_async_readv(struct cifs_readdata *rdata) 1380CIFSSMBRead(const int xid, struct cifs_io_parms *io_parms, unsigned int *nbytes,
1577{ 1381 char **buf, int *pbuf_type)
1578 int rc;
1579 READ_REQ *smb = NULL;
1580 int wct;
1581 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
1582 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
1583 .rq_nvec = 1 };
1584
1585 cFYI(1, "%s: offset=%llu bytes=%u", __func__,
1586 rdata->offset, rdata->bytes);
1587
1588 if (tcon->ses->capabilities & CAP_LARGE_FILES)
1589 wct = 12;
1590 else {
1591 wct = 10; /* old style read */
1592 if ((rdata->offset >> 32) > 0) {
1593 /* can not handle this big offset for old */
1594 return -EIO;
1595 }
1596 }
1597
1598 rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **)&smb);
1599 if (rc)
1600 return rc;
1601
1602 smb->hdr.Pid = cpu_to_le16((__u16)rdata->pid);
1603 smb->hdr.PidHigh = cpu_to_le16((__u16)(rdata->pid >> 16));
1604
1605 smb->AndXCommand = 0xFF; /* none */
1606 smb->Fid = rdata->cfile->fid.netfid;
1607 smb->OffsetLow = cpu_to_le32(rdata->offset & 0xFFFFFFFF);
1608 if (wct == 12)
1609 smb->OffsetHigh = cpu_to_le32(rdata->offset >> 32);
1610 smb->Remaining = 0;
1611 smb->MaxCount = cpu_to_le16(rdata->bytes & 0xFFFF);
1612 smb->MaxCountHigh = cpu_to_le32(rdata->bytes >> 16);
1613 if (wct == 12)
1614 smb->ByteCount = 0;
1615 else {
1616 /* old style read */
1617 struct smb_com_readx_req *smbr =
1618 (struct smb_com_readx_req *)smb;
1619 smbr->ByteCount = 0;
1620 }
1621
1622 /* 4 for RFC1001 length + 1 for BCC */
1623 rdata->iov.iov_base = smb;
1624 rdata->iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4;
1625
1626 kref_get(&rdata->refcount);
1627 rc = cifs_call_async(tcon->ses->server, &rqst, cifs_readv_receive,
1628 cifs_readv_callback, rdata, 0);
1629
1630 if (rc == 0)
1631 cifs_stats_inc(&tcon->stats.cifs_stats.num_reads);
1632 else
1633 kref_put(&rdata->refcount, cifs_readdata_release);
1634
1635 cifs_small_buf_release(smb);
1636 return rc;
1637}
1638
1639int
1640CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
1641 unsigned int *nbytes, char **buf, int *pbuf_type)
1642{ 1382{
1643 int rc = -EACCES; 1383 int rc = -EACCES;
1644 READ_REQ *pSMB = NULL; 1384 READ_REQ *pSMB = NULL;
@@ -1698,7 +1438,7 @@ CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
1698 iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; 1438 iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4;
1699 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, 1439 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */,
1700 &resp_buf_type, CIFS_LOG_ERROR); 1440 &resp_buf_type, CIFS_LOG_ERROR);
1701 cifs_stats_inc(&tcon->stats.cifs_stats.num_reads); 1441 cifs_stats_inc(&tcon->num_reads);
1702 pSMBr = (READ_RSP *)iov[0].iov_base; 1442 pSMBr = (READ_RSP *)iov[0].iov_base;
1703 if (rc) { 1443 if (rc) {
1704 cERROR(1, "Send error in read = %d", rc); 1444 cERROR(1, "Send error in read = %d", rc);
@@ -1749,7 +1489,7 @@ CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
1749 1489
1750 1490
1751int 1491int
1752CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, 1492CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms,
1753 unsigned int *nbytes, const char *buf, 1493 unsigned int *nbytes, const char *buf,
1754 const char __user *ubuf, const int long_op) 1494 const char __user *ubuf, const int long_op)
1755{ 1495{
@@ -1850,7 +1590,7 @@ CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
1850 1590
1851 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 1591 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1852 (struct smb_hdr *) pSMBr, &bytes_returned, long_op); 1592 (struct smb_hdr *) pSMBr, &bytes_returned, long_op);
1853 cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); 1593 cifs_stats_inc(&tcon->num_writes);
1854 if (rc) { 1594 if (rc) {
1855 cFYI(1, "Send error in write = %d", rc); 1595 cFYI(1, "Send error in write = %d", rc);
1856 } else { 1596 } else {
@@ -1896,7 +1636,6 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
1896{ 1636{
1897 int i, rc; 1637 int i, rc;
1898 struct inode *inode = wdata->cfile->dentry->d_inode; 1638 struct inode *inode = wdata->cfile->dentry->d_inode;
1899 struct TCP_Server_Info *server;
1900 1639
1901 for (i = 0; i < wdata->nr_pages; i++) { 1640 for (i = 0; i < wdata->nr_pages; i++) {
1902 lock_page(wdata->pages[i]); 1641 lock_page(wdata->pages[i]);
@@ -1904,8 +1643,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
1904 } 1643 }
1905 1644
1906 do { 1645 do {
1907 server = tlink_tcon(wdata->cfile->tlink)->ses->server; 1646 rc = cifs_async_writev(wdata);
1908 rc = server->ops->async_writev(wdata);
1909 } while (rc == -EAGAIN); 1647 } while (rc == -EAGAIN);
1910 1648
1911 for (i = 0; i < wdata->nr_pages; i++) { 1649 for (i = 0; i < wdata->nr_pages; i++) {
@@ -1918,7 +1656,7 @@ cifs_writev_requeue(struct cifs_writedata *wdata)
1918 kref_put(&wdata->refcount, cifs_writedata_release); 1656 kref_put(&wdata->refcount, cifs_writedata_release);
1919} 1657}
1920 1658
1921void 1659static void
1922cifs_writev_complete(struct work_struct *work) 1660cifs_writev_complete(struct work_struct *work)
1923{ 1661{
1924 struct cifs_writedata *wdata = container_of(work, 1662 struct cifs_writedata *wdata = container_of(work,
@@ -1927,9 +1665,7 @@ cifs_writev_complete(struct work_struct *work)
1927 int i = 0; 1665 int i = 0;
1928 1666
1929 if (wdata->result == 0) { 1667 if (wdata->result == 0) {
1930 spin_lock(&inode->i_lock);
1931 cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes); 1668 cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
1932 spin_unlock(&inode->i_lock);
1933 cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink), 1669 cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
1934 wdata->bytes); 1670 wdata->bytes);
1935 } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN) 1671 } else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
@@ -1950,7 +1686,7 @@ cifs_writev_complete(struct work_struct *work)
1950} 1686}
1951 1687
1952struct cifs_writedata * 1688struct cifs_writedata *
1953cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete) 1689cifs_writedata_alloc(unsigned int nr_pages)
1954{ 1690{
1955 struct cifs_writedata *wdata; 1691 struct cifs_writedata *wdata;
1956 1692
@@ -1964,16 +1700,14 @@ cifs_writedata_alloc(unsigned int nr_pages, work_func_t complete)
1964 wdata = kzalloc(sizeof(*wdata) + 1700 wdata = kzalloc(sizeof(*wdata) +
1965 sizeof(struct page *) * (nr_pages - 1), GFP_NOFS); 1701 sizeof(struct page *) * (nr_pages - 1), GFP_NOFS);
1966 if (wdata != NULL) { 1702 if (wdata != NULL) {
1703 INIT_WORK(&wdata->work, cifs_writev_complete);
1967 kref_init(&wdata->refcount); 1704 kref_init(&wdata->refcount);
1968 INIT_LIST_HEAD(&wdata->list);
1969 init_completion(&wdata->done);
1970 INIT_WORK(&wdata->work, complete);
1971 } 1705 }
1972 return wdata; 1706 return wdata;
1973} 1707}
1974 1708
1975/* 1709/*
1976 * Check the mid_state and signature on received buffer (if any), and queue the 1710 * Check the midState and signature on received buffer (if any), and queue the
1977 * workqueue completion task. 1711 * workqueue completion task.
1978 */ 1712 */
1979static void 1713static void
@@ -1984,7 +1718,7 @@ cifs_writev_callback(struct mid_q_entry *mid)
1984 unsigned int written; 1718 unsigned int written;
1985 WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf; 1719 WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf;
1986 1720
1987 switch (mid->mid_state) { 1721 switch (mid->midState) {
1988 case MID_RESPONSE_RECEIVED: 1722 case MID_RESPONSE_RECEIVED:
1989 wdata->result = cifs_check_receive(mid, tcon->ses->server, 0); 1723 wdata->result = cifs_check_receive(mid, tcon->ses->server, 0);
1990 if (wdata->result != 0) 1724 if (wdata->result != 0)
@@ -2016,21 +1750,22 @@ cifs_writev_callback(struct mid_q_entry *mid)
2016 break; 1750 break;
2017 } 1751 }
2018 1752
2019 queue_work(cifsiod_wq, &wdata->work); 1753 queue_work(system_nrt_wq, &wdata->work);
2020 DeleteMidQEntry(mid); 1754 DeleteMidQEntry(mid);
2021 add_credits(tcon->ses->server, 1, 0); 1755 atomic_dec(&tcon->ses->server->inFlight);
1756 wake_up(&tcon->ses->server->request_q);
2022} 1757}
2023 1758
2024/* cifs_async_writev - send an async write, and set up mid to handle result */ 1759/* cifs_async_writev - send an async write, and set up mid to handle result */
2025int 1760int
2026cifs_async_writev(struct cifs_writedata *wdata) 1761cifs_async_writev(struct cifs_writedata *wdata)
2027{ 1762{
2028 int rc = -EACCES; 1763 int i, rc = -EACCES;
2029 WRITE_REQ *smb = NULL; 1764 WRITE_REQ *smb = NULL;
2030 int wct; 1765 int wct;
2031 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); 1766 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2032 struct kvec iov; 1767 struct inode *inode = wdata->cfile->dentry->d_inode;
2033 struct smb_rqst rqst = { }; 1768 struct kvec *iov = NULL;
2034 1769
2035 if (tcon->ses->capabilities & CAP_LARGE_FILES) { 1770 if (tcon->ses->capabilities & CAP_LARGE_FILES) {
2036 wct = 14; 1771 wct = 14;
@@ -2046,11 +1781,18 @@ cifs_async_writev(struct cifs_writedata *wdata)
2046 if (rc) 1781 if (rc)
2047 goto async_writev_out; 1782 goto async_writev_out;
2048 1783
2049 smb->hdr.Pid = cpu_to_le16((__u16)wdata->pid); 1784 /* 1 iov per page + 1 for header */
2050 smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->pid >> 16)); 1785 iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS);
1786 if (iov == NULL) {
1787 rc = -ENOMEM;
1788 goto async_writev_out;
1789 }
1790
1791 smb->hdr.Pid = cpu_to_le16((__u16)wdata->cfile->pid);
1792 smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->cfile->pid >> 16));
2051 1793
2052 smb->AndXCommand = 0xFF; /* none */ 1794 smb->AndXCommand = 0xFF; /* none */
2053 smb->Fid = wdata->cfile->fid.netfid; 1795 smb->Fid = wdata->cfile->netfid;
2054 smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF); 1796 smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF);
2055 if (wct == 14) 1797 if (wct == 14)
2056 smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32); 1798 smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32);
@@ -2062,15 +1804,18 @@ cifs_async_writev(struct cifs_writedata *wdata)
2062 cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); 1804 cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4);
2063 1805
2064 /* 4 for RFC1001 length + 1 for BCC */ 1806 /* 4 for RFC1001 length + 1 for BCC */
2065 iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1; 1807 iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1;
2066 iov.iov_base = smb; 1808 iov[0].iov_base = smb;
2067 1809
2068 rqst.rq_iov = &iov; 1810 /* marshal up the pages into iov array */
2069 rqst.rq_nvec = 1; 1811 wdata->bytes = 0;
2070 rqst.rq_pages = wdata->pages; 1812 for (i = 0; i < wdata->nr_pages; i++) {
2071 rqst.rq_npages = wdata->nr_pages; 1813 iov[i + 1].iov_len = min(inode->i_size -
2072 rqst.rq_pagesz = wdata->pagesz; 1814 page_offset(wdata->pages[i]),
2073 rqst.rq_tailsz = wdata->tailsz; 1815 (loff_t)PAGE_CACHE_SIZE);
1816 iov[i + 1].iov_base = kmap(wdata->pages[i]);
1817 wdata->bytes += iov[i + 1].iov_len;
1818 }
2074 1819
2075 cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes); 1820 cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes);
2076 1821
@@ -2086,26 +1831,32 @@ cifs_async_writev(struct cifs_writedata *wdata)
2086 (struct smb_com_writex_req *)smb; 1831 (struct smb_com_writex_req *)smb;
2087 inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5); 1832 inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5);
2088 put_bcc(wdata->bytes + 5, &smbw->hdr); 1833 put_bcc(wdata->bytes + 5, &smbw->hdr);
2089 iov.iov_len += 4; /* pad bigger by four bytes */ 1834 iov[0].iov_len += 4; /* pad bigger by four bytes */
2090 } 1835 }
2091 1836
2092 kref_get(&wdata->refcount); 1837 kref_get(&wdata->refcount);
2093 rc = cifs_call_async(tcon->ses->server, &rqst, NULL, 1838 rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1,
2094 cifs_writev_callback, wdata, 0); 1839 cifs_writev_callback, wdata, false);
2095 1840
2096 if (rc == 0) 1841 if (rc == 0)
2097 cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); 1842 cifs_stats_inc(&tcon->num_writes);
2098 else 1843 else
2099 kref_put(&wdata->refcount, cifs_writedata_release); 1844 kref_put(&wdata->refcount, cifs_writedata_release);
2100 1845
1846 /* send is done, unmap pages */
1847 for (i = 0; i < wdata->nr_pages; i++)
1848 kunmap(wdata->pages[i]);
1849
2101async_writev_out: 1850async_writev_out:
2102 cifs_small_buf_release(smb); 1851 cifs_small_buf_release(smb);
1852 kfree(iov);
2103 return rc; 1853 return rc;
2104} 1854}
2105 1855
2106int 1856int
2107CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, 1857CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms,
2108 unsigned int *nbytes, struct kvec *iov, int n_vec) 1858 unsigned int *nbytes, struct kvec *iov, int n_vec,
1859 const int long_op)
2109{ 1860{
2110 int rc = -EACCES; 1861 int rc = -EACCES;
2111 WRITE_REQ *pSMB = NULL; 1862 WRITE_REQ *pSMB = NULL;
@@ -2176,8 +1927,9 @@ CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms,
2176 iov[0].iov_len = smb_hdr_len + 8; 1927 iov[0].iov_len = smb_hdr_len + 8;
2177 1928
2178 1929
2179 rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 0); 1930 rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type,
2180 cifs_stats_inc(&tcon->stats.cifs_stats.num_writes); 1931 long_op);
1932 cifs_stats_inc(&tcon->num_writes);
2181 if (rc) { 1933 if (rc) {
2182 cFYI(1, "Send error Write2 = %d", rc); 1934 cFYI(1, "Send error Write2 = %d", rc);
2183 } else if (resp_buf_type == 0) { 1935 } else if (resp_buf_type == 0) {
@@ -2210,50 +1962,10 @@ CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms,
2210 return rc; 1962 return rc;
2211} 1963}
2212 1964
2213int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon,
2214 const __u16 netfid, const __u8 lock_type, const __u32 num_unlock,
2215 const __u32 num_lock, LOCKING_ANDX_RANGE *buf)
2216{
2217 int rc = 0;
2218 LOCK_REQ *pSMB = NULL;
2219 struct kvec iov[2];
2220 int resp_buf_type;
2221 __u16 count;
2222
2223 cFYI(1, "cifs_lockv num lock %d num unlock %d", num_lock, num_unlock);
2224
2225 rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB);
2226 if (rc)
2227 return rc;
2228
2229 pSMB->Timeout = 0;
2230 pSMB->NumberOfLocks = cpu_to_le16(num_lock);
2231 pSMB->NumberOfUnlocks = cpu_to_le16(num_unlock);
2232 pSMB->LockType = lock_type;
2233 pSMB->AndXCommand = 0xFF; /* none */
2234 pSMB->Fid = netfid; /* netfid stays le */
2235
2236 count = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE);
2237 inc_rfc1001_len(pSMB, count);
2238 pSMB->ByteCount = cpu_to_le16(count);
2239
2240 iov[0].iov_base = (char *)pSMB;
2241 iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4 -
2242 (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE);
2243 iov[1].iov_base = (char *)buf;
2244 iov[1].iov_len = (num_unlock + num_lock) * sizeof(LOCKING_ANDX_RANGE);
2245
2246 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks);
2247 rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP);
2248 if (rc)
2249 cFYI(1, "Send error in cifs_lockv = %d", rc);
2250
2251 return rc;
2252}
2253 1965
2254int 1966int
2255CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, 1967CIFSSMBLock(const int xid, struct cifs_tcon *tcon,
2256 const __u16 smb_file_id, const __u32 netpid, const __u64 len, 1968 const __u16 smb_file_id, const __u64 len,
2257 const __u64 offset, const __u32 numUnlock, 1969 const __u64 offset, const __u32 numUnlock,
2258 const __u32 numLock, const __u8 lockType, 1970 const __u32 numLock, const __u8 lockType,
2259 const bool waitFlag, const __u8 oplock_level) 1971 const bool waitFlag, const __u8 oplock_level)
@@ -2262,7 +1974,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
2262 LOCK_REQ *pSMB = NULL; 1974 LOCK_REQ *pSMB = NULL;
2263/* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ 1975/* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
2264 int bytes_returned; 1976 int bytes_returned;
2265 int flags = 0; 1977 int timeout = 0;
2266 __u16 count; 1978 __u16 count;
2267 1979
2268 cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); 1980 cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock);
@@ -2272,11 +1984,10 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
2272 return rc; 1984 return rc;
2273 1985
2274 if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { 1986 if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) {
2275 /* no response expected */ 1987 timeout = CIFS_ASYNC_OP; /* no response expected */
2276 flags = CIFS_ASYNC_OP | CIFS_OBREAK_OP;
2277 pSMB->Timeout = 0; 1988 pSMB->Timeout = 0;
2278 } else if (waitFlag) { 1989 } else if (waitFlag) {
2279 flags = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ 1990 timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */
2280 pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ 1991 pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */
2281 } else { 1992 } else {
2282 pSMB->Timeout = 0; 1993 pSMB->Timeout = 0;
@@ -2290,7 +2001,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
2290 pSMB->Fid = smb_file_id; /* netfid stays le */ 2001 pSMB->Fid = smb_file_id; /* netfid stays le */
2291 2002
2292 if ((numLock != 0) || (numUnlock != 0)) { 2003 if ((numLock != 0) || (numUnlock != 0)) {
2293 pSMB->Locks[0].Pid = cpu_to_le16(netpid); 2004 pSMB->Locks[0].Pid = cpu_to_le16(current->tgid);
2294 /* BB where to store pid high? */ 2005 /* BB where to store pid high? */
2295 pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); 2006 pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len);
2296 pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); 2007 pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32));
@@ -2309,10 +2020,11 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
2309 (struct smb_hdr *) pSMB, &bytes_returned); 2020 (struct smb_hdr *) pSMB, &bytes_returned);
2310 cifs_small_buf_release(pSMB); 2021 cifs_small_buf_release(pSMB);
2311 } else { 2022 } else {
2312 rc = SendReceiveNoRsp(xid, tcon->ses, (char *)pSMB, flags); 2023 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB,
2024 timeout);
2313 /* SMB buffer freed by function above */ 2025 /* SMB buffer freed by function above */
2314 } 2026 }
2315 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks); 2027 cifs_stats_inc(&tcon->num_locks);
2316 if (rc) 2028 if (rc)
2317 cFYI(1, "Send error in Lock = %d", rc); 2029 cFYI(1, "Send error in Lock = %d", rc);
2318 2030
@@ -2322,9 +2034,8 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
2322} 2034}
2323 2035
2324int 2036int
2325CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, 2037CIFSSMBPosixLock(const int xid, struct cifs_tcon *tcon,
2326 const __u16 smb_file_id, const __u32 netpid, 2038 const __u16 smb_file_id, const int get_flag, const __u64 len,
2327 const loff_t start_offset, const __u64 len,
2328 struct file_lock *pLockData, const __u16 lock_type, 2039 struct file_lock *pLockData, const __u16 lock_type,
2329 const bool waitFlag) 2040 const bool waitFlag)
2330{ 2041{
@@ -2340,6 +2051,9 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
2340 2051
2341 cFYI(1, "Posix Lock"); 2052 cFYI(1, "Posix Lock");
2342 2053
2054 if (pLockData == NULL)
2055 return -EINVAL;
2056
2343 rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); 2057 rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB);
2344 2058
2345 if (rc) 2059 if (rc)
@@ -2360,7 +2074,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
2360 pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ 2074 pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */
2361 pSMB->SetupCount = 1; 2075 pSMB->SetupCount = 1;
2362 pSMB->Reserved3 = 0; 2076 pSMB->Reserved3 = 0;
2363 if (pLockData) 2077 if (get_flag)
2364 pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); 2078 pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION);
2365 else 2079 else
2366 pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); 2080 pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION);
@@ -2381,8 +2095,8 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
2381 } else 2095 } else
2382 pSMB->Timeout = 0; 2096 pSMB->Timeout = 0;
2383 2097
2384 parm_data->pid = cpu_to_le32(netpid); 2098 parm_data->pid = cpu_to_le32(current->tgid);
2385 parm_data->start = cpu_to_le64(start_offset); 2099 parm_data->start = cpu_to_le64(pLockData->fl_start);
2386 parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ 2100 parm_data->length = cpu_to_le64(len); /* normalize negative numbers */
2387 2101
2388 pSMB->DataOffset = cpu_to_le16(offset); 2102 pSMB->DataOffset = cpu_to_le16(offset);
@@ -2406,7 +2120,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
2406 2120
2407 if (rc) { 2121 if (rc) {
2408 cFYI(1, "Send error in Posix Lock = %d", rc); 2122 cFYI(1, "Send error in Posix Lock = %d", rc);
2409 } else if (pLockData) { 2123 } else if (get_flag) {
2410 /* lock structure can be returned on get */ 2124 /* lock structure can be returned on get */
2411 __u16 data_offset; 2125 __u16 data_offset;
2412 __u16 data_count; 2126 __u16 data_count;
@@ -2458,7 +2172,7 @@ plk_err_exit:
2458 2172
2459 2173
2460int 2174int
2461CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id) 2175CIFSSMBClose(const int xid, struct cifs_tcon *tcon, int smb_file_id)
2462{ 2176{
2463 int rc = 0; 2177 int rc = 0;
2464 CLOSE_REQ *pSMB = NULL; 2178 CLOSE_REQ *pSMB = NULL;
@@ -2474,8 +2188,8 @@ CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id)
2474 pSMB->FileID = (__u16) smb_file_id; 2188 pSMB->FileID = (__u16) smb_file_id;
2475 pSMB->LastWriteTime = 0xFFFFFFFF; 2189 pSMB->LastWriteTime = 0xFFFFFFFF;
2476 pSMB->ByteCount = 0; 2190 pSMB->ByteCount = 0;
2477 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 2191 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
2478 cifs_stats_inc(&tcon->stats.cifs_stats.num_closes); 2192 cifs_stats_inc(&tcon->num_closes);
2479 if (rc) { 2193 if (rc) {
2480 if (rc != -EINTR) { 2194 if (rc != -EINTR) {
2481 /* EINTR is expected when user ctl-c to kill app */ 2195 /* EINTR is expected when user ctl-c to kill app */
@@ -2491,7 +2205,7 @@ CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id)
2491} 2205}
2492 2206
2493int 2207int
2494CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id) 2208CIFSSMBFlush(const int xid, struct cifs_tcon *tcon, int smb_file_id)
2495{ 2209{
2496 int rc = 0; 2210 int rc = 0;
2497 FLUSH_REQ *pSMB = NULL; 2211 FLUSH_REQ *pSMB = NULL;
@@ -2503,8 +2217,8 @@ CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id)
2503 2217
2504 pSMB->FileID = (__u16) smb_file_id; 2218 pSMB->FileID = (__u16) smb_file_id;
2505 pSMB->ByteCount = 0; 2219 pSMB->ByteCount = 0;
2506 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 2220 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
2507 cifs_stats_inc(&tcon->stats.cifs_stats.num_flushes); 2221 cifs_stats_inc(&tcon->num_flushes);
2508 if (rc) 2222 if (rc)
2509 cERROR(1, "Send error in Flush = %d", rc); 2223 cERROR(1, "Send error in Flush = %d", rc);
2510 2224
@@ -2512,9 +2226,9 @@ CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, int smb_file_id)
2512} 2226}
2513 2227
2514int 2228int
2515CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, 2229CIFSSMBRename(const int xid, struct cifs_tcon *tcon,
2516 const char *from_name, const char *to_name, 2230 const char *fromName, const char *toName,
2517 struct cifs_sb_info *cifs_sb) 2231 const struct nls_table *nls_codepage, int remap)
2518{ 2232{
2519 int rc = 0; 2233 int rc = 0;
2520 RENAME_REQ *pSMB = NULL; 2234 RENAME_REQ *pSMB = NULL;
@@ -2522,7 +2236,6 @@ CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon,
2522 int bytes_returned; 2236 int bytes_returned;
2523 int name_len, name_len2; 2237 int name_len, name_len2;
2524 __u16 count; 2238 __u16 count;
2525 int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
2526 2239
2527 cFYI(1, "In CIFSSMBRename"); 2240 cFYI(1, "In CIFSSMBRename");
2528renameRetry: 2241renameRetry:
@@ -2537,28 +2250,27 @@ renameRetry:
2537 ATTR_DIRECTORY); 2250 ATTR_DIRECTORY);
2538 2251
2539 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2252 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2540 name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, 2253 name_len =
2541 from_name, PATH_MAX, 2254 cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName,
2542 cifs_sb->local_nls, remap); 2255 PATH_MAX, nls_codepage, remap);
2543 name_len++; /* trailing null */ 2256 name_len++; /* trailing null */
2544 name_len *= 2; 2257 name_len *= 2;
2545 pSMB->OldFileName[name_len] = 0x04; /* pad */ 2258 pSMB->OldFileName[name_len] = 0x04; /* pad */
2546 /* protocol requires ASCII signature byte on Unicode string */ 2259 /* protocol requires ASCII signature byte on Unicode string */
2547 pSMB->OldFileName[name_len + 1] = 0x00; 2260 pSMB->OldFileName[name_len + 1] = 0x00;
2548 name_len2 = 2261 name_len2 =
2549 cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], 2262 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
2550 to_name, PATH_MAX, cifs_sb->local_nls, 2263 toName, PATH_MAX, nls_codepage, remap);
2551 remap);
2552 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; 2264 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
2553 name_len2 *= 2; /* convert to bytes */ 2265 name_len2 *= 2; /* convert to bytes */
2554 } else { /* BB improve the check for buffer overruns BB */ 2266 } else { /* BB improve the check for buffer overruns BB */
2555 name_len = strnlen(from_name, PATH_MAX); 2267 name_len = strnlen(fromName, PATH_MAX);
2556 name_len++; /* trailing null */ 2268 name_len++; /* trailing null */
2557 strncpy(pSMB->OldFileName, from_name, name_len); 2269 strncpy(pSMB->OldFileName, fromName, name_len);
2558 name_len2 = strnlen(to_name, PATH_MAX); 2270 name_len2 = strnlen(toName, PATH_MAX);
2559 name_len2++; /* trailing null */ 2271 name_len2++; /* trailing null */
2560 pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ 2272 pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */
2561 strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); 2273 strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2);
2562 name_len2++; /* trailing null */ 2274 name_len2++; /* trailing null */
2563 name_len2++; /* signature byte */ 2275 name_len2++; /* signature byte */
2564 } 2276 }
@@ -2569,7 +2281,7 @@ renameRetry:
2569 2281
2570 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 2282 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
2571 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 2283 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
2572 cifs_stats_inc(&tcon->stats.cifs_stats.num_renames); 2284 cifs_stats_inc(&tcon->num_renames);
2573 if (rc) 2285 if (rc)
2574 cFYI(1, "Send error in rename = %d", rc); 2286 cFYI(1, "Send error in rename = %d", rc);
2575 2287
@@ -2581,7 +2293,7 @@ renameRetry:
2581 return rc; 2293 return rc;
2582} 2294}
2583 2295
2584int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon, 2296int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon,
2585 int netfid, const char *target_name, 2297 int netfid, const char *target_name,
2586 const struct nls_table *nls_codepage, int remap) 2298 const struct nls_table *nls_codepage, int remap)
2587{ 2299{
@@ -2628,12 +2340,10 @@ int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon,
2628 /* unicode only call */ 2340 /* unicode only call */
2629 if (target_name == NULL) { 2341 if (target_name == NULL) {
2630 sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); 2342 sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid);
2631 len_of_str = 2343 len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,
2632 cifsConvertToUTF16((__le16 *)rename_info->target_name,
2633 dummy_string, 24, nls_codepage, remap); 2344 dummy_string, 24, nls_codepage, remap);
2634 } else { 2345 } else {
2635 len_of_str = 2346 len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,
2636 cifsConvertToUTF16((__le16 *)rename_info->target_name,
2637 target_name, PATH_MAX, nls_codepage, 2347 target_name, PATH_MAX, nls_codepage,
2638 remap); 2348 remap);
2639 } 2349 }
@@ -2650,7 +2360,7 @@ int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon,
2650 pSMB->ByteCount = cpu_to_le16(byte_count); 2360 pSMB->ByteCount = cpu_to_le16(byte_count);
2651 rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, 2361 rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB,
2652 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 2362 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
2653 cifs_stats_inc(&pTcon->stats.cifs_stats.num_t2renames); 2363 cifs_stats_inc(&pTcon->num_t2renames);
2654 if (rc) 2364 if (rc)
2655 cFYI(1, "Send error in Rename (by file handle) = %d", rc); 2365 cFYI(1, "Send error in Rename (by file handle) = %d", rc);
2656 2366
@@ -2663,9 +2373,9 @@ int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon,
2663} 2373}
2664 2374
2665int 2375int
2666CIFSSMBCopy(const unsigned int xid, struct cifs_tcon *tcon, 2376CIFSSMBCopy(const int xid, struct cifs_tcon *tcon, const char *fromName,
2667 const char *fromName, const __u16 target_tid, const char *toName, 2377 const __u16 target_tid, const char *toName, const int flags,
2668 const int flags, const struct nls_table *nls_codepage, int remap) 2378 const struct nls_table *nls_codepage, int remap)
2669{ 2379{
2670 int rc = 0; 2380 int rc = 0;
2671 COPY_REQ *pSMB = NULL; 2381 COPY_REQ *pSMB = NULL;
@@ -2687,17 +2397,17 @@ copyRetry:
2687 pSMB->Flags = cpu_to_le16(flags & COPY_TREE); 2397 pSMB->Flags = cpu_to_le16(flags & COPY_TREE);
2688 2398
2689 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2399 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2690 name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName, 2400 name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName,
2691 fromName, PATH_MAX, nls_codepage, 2401 fromName, PATH_MAX, nls_codepage,
2692 remap); 2402 remap);
2693 name_len++; /* trailing null */ 2403 name_len++; /* trailing null */
2694 name_len *= 2; 2404 name_len *= 2;
2695 pSMB->OldFileName[name_len] = 0x04; /* pad */ 2405 pSMB->OldFileName[name_len] = 0x04; /* pad */
2696 /* protocol requires ASCII signature byte on Unicode string */ 2406 /* protocol requires ASCII signature byte on Unicode string */
2697 pSMB->OldFileName[name_len + 1] = 0x00; 2407 pSMB->OldFileName[name_len + 1] = 0x00;
2698 name_len2 = 2408 name_len2 =
2699 cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], 2409 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
2700 toName, PATH_MAX, nls_codepage, remap); 2410 toName, PATH_MAX, nls_codepage, remap);
2701 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; 2411 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
2702 name_len2 *= 2; /* convert to bytes */ 2412 name_len2 *= 2; /* convert to bytes */
2703 } else { /* BB improve the check for buffer overruns BB */ 2413 } else { /* BB improve the check for buffer overruns BB */
@@ -2731,7 +2441,7 @@ copyRetry:
2731} 2441}
2732 2442
2733int 2443int
2734CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon, 2444CIFSUnixCreateSymLink(const int xid, struct cifs_tcon *tcon,
2735 const char *fromName, const char *toName, 2445 const char *fromName, const char *toName,
2736 const struct nls_table *nls_codepage) 2446 const struct nls_table *nls_codepage)
2737{ 2447{
@@ -2753,9 +2463,9 @@ createSymLinkRetry:
2753 2463
2754 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2464 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2755 name_len = 2465 name_len =
2756 cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName, 2466 cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX
2757 /* find define for this maxpathcomponent */ 2467 /* find define for this maxpathcomponent */
2758 PATH_MAX, nls_codepage); 2468 , nls_codepage);
2759 name_len++; /* trailing null */ 2469 name_len++; /* trailing null */
2760 name_len *= 2; 2470 name_len *= 2;
2761 2471
@@ -2777,9 +2487,9 @@ createSymLinkRetry:
2777 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 2487 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
2778 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2488 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2779 name_len_target = 2489 name_len_target =
2780 cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX 2490 cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX
2781 /* find define for this maxpathcomponent */ 2491 /* find define for this maxpathcomponent */
2782 , nls_codepage); 2492 , nls_codepage);
2783 name_len_target++; /* trailing null */ 2493 name_len_target++; /* trailing null */
2784 name_len_target *= 2; 2494 name_len_target *= 2;
2785 } else { /* BB improve the check for buffer overruns BB */ 2495 } else { /* BB improve the check for buffer overruns BB */
@@ -2807,7 +2517,7 @@ createSymLinkRetry:
2807 pSMB->ByteCount = cpu_to_le16(byte_count); 2517 pSMB->ByteCount = cpu_to_le16(byte_count);
2808 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 2518 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
2809 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 2519 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
2810 cifs_stats_inc(&tcon->stats.cifs_stats.num_symlinks); 2520 cifs_stats_inc(&tcon->num_symlinks);
2811 if (rc) 2521 if (rc)
2812 cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); 2522 cFYI(1, "Send error in SetPathInfo create symlink = %d", rc);
2813 2523
@@ -2820,7 +2530,7 @@ createSymLinkRetry:
2820} 2530}
2821 2531
2822int 2532int
2823CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, 2533CIFSUnixCreateHardLink(const int xid, struct cifs_tcon *tcon,
2824 const char *fromName, const char *toName, 2534 const char *fromName, const char *toName,
2825 const struct nls_table *nls_codepage, int remap) 2535 const struct nls_table *nls_codepage, int remap)
2826{ 2536{
@@ -2841,8 +2551,8 @@ createHardLinkRetry:
2841 return rc; 2551 return rc;
2842 2552
2843 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2553 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2844 name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName, 2554 name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName,
2845 PATH_MAX, nls_codepage, remap); 2555 PATH_MAX, nls_codepage, remap);
2846 name_len++; /* trailing null */ 2556 name_len++; /* trailing null */
2847 name_len *= 2; 2557 name_len *= 2;
2848 2558
@@ -2864,8 +2574,8 @@ createHardLinkRetry:
2864 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 2574 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
2865 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2575 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2866 name_len_target = 2576 name_len_target =
2867 cifsConvertToUTF16((__le16 *) data_offset, fromName, 2577 cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX,
2868 PATH_MAX, nls_codepage, remap); 2578 nls_codepage, remap);
2869 name_len_target++; /* trailing null */ 2579 name_len_target++; /* trailing null */
2870 name_len_target *= 2; 2580 name_len_target *= 2;
2871 } else { /* BB improve the check for buffer overruns BB */ 2581 } else { /* BB improve the check for buffer overruns BB */
@@ -2893,7 +2603,7 @@ createHardLinkRetry:
2893 pSMB->ByteCount = cpu_to_le16(byte_count); 2603 pSMB->ByteCount = cpu_to_le16(byte_count);
2894 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 2604 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
2895 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 2605 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
2896 cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); 2606 cifs_stats_inc(&tcon->num_hardlinks);
2897 if (rc) 2607 if (rc)
2898 cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); 2608 cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc);
2899 2609
@@ -2905,9 +2615,9 @@ createHardLinkRetry:
2905} 2615}
2906 2616
2907int 2617int
2908CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, 2618CIFSCreateHardLink(const int xid, struct cifs_tcon *tcon,
2909 const char *from_name, const char *to_name, 2619 const char *fromName, const char *toName,
2910 struct cifs_sb_info *cifs_sb) 2620 const struct nls_table *nls_codepage, int remap)
2911{ 2621{
2912 int rc = 0; 2622 int rc = 0;
2913 NT_RENAME_REQ *pSMB = NULL; 2623 NT_RENAME_REQ *pSMB = NULL;
@@ -2915,7 +2625,6 @@ CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon,
2915 int bytes_returned; 2625 int bytes_returned;
2916 int name_len, name_len2; 2626 int name_len, name_len2;
2917 __u16 count; 2627 __u16 count;
2918 int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
2919 2628
2920 cFYI(1, "In CIFSCreateHardLink"); 2629 cFYI(1, "In CIFSCreateHardLink");
2921winCreateHardLinkRetry: 2630winCreateHardLinkRetry:
@@ -2935,8 +2644,8 @@ winCreateHardLinkRetry:
2935 2644
2936 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2645 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2937 name_len = 2646 name_len =
2938 cifsConvertToUTF16((__le16 *) pSMB->OldFileName, from_name, 2647 cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName,
2939 PATH_MAX, cifs_sb->local_nls, remap); 2648 PATH_MAX, nls_codepage, remap);
2940 name_len++; /* trailing null */ 2649 name_len++; /* trailing null */
2941 name_len *= 2; 2650 name_len *= 2;
2942 2651
@@ -2944,19 +2653,18 @@ winCreateHardLinkRetry:
2944 pSMB->OldFileName[name_len] = 0x04; 2653 pSMB->OldFileName[name_len] = 0x04;
2945 pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ 2654 pSMB->OldFileName[name_len + 1] = 0x00; /* pad */
2946 name_len2 = 2655 name_len2 =
2947 cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2], 2656 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
2948 to_name, PATH_MAX, cifs_sb->local_nls, 2657 toName, PATH_MAX, nls_codepage, remap);
2949 remap);
2950 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; 2658 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
2951 name_len2 *= 2; /* convert to bytes */ 2659 name_len2 *= 2; /* convert to bytes */
2952 } else { /* BB improve the check for buffer overruns BB */ 2660 } else { /* BB improve the check for buffer overruns BB */
2953 name_len = strnlen(from_name, PATH_MAX); 2661 name_len = strnlen(fromName, PATH_MAX);
2954 name_len++; /* trailing null */ 2662 name_len++; /* trailing null */
2955 strncpy(pSMB->OldFileName, from_name, name_len); 2663 strncpy(pSMB->OldFileName, fromName, name_len);
2956 name_len2 = strnlen(to_name, PATH_MAX); 2664 name_len2 = strnlen(toName, PATH_MAX);
2957 name_len2++; /* trailing null */ 2665 name_len2++; /* trailing null */
2958 pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ 2666 pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */
2959 strncpy(&pSMB->OldFileName[name_len + 1], to_name, name_len2); 2667 strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2);
2960 name_len2++; /* trailing null */ 2668 name_len2++; /* trailing null */
2961 name_len2++; /* signature byte */ 2669 name_len2++; /* signature byte */
2962 } 2670 }
@@ -2967,7 +2675,7 @@ winCreateHardLinkRetry:
2967 2675
2968 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 2676 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
2969 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 2677 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
2970 cifs_stats_inc(&tcon->stats.cifs_stats.num_hardlinks); 2678 cifs_stats_inc(&tcon->num_hardlinks);
2971 if (rc) 2679 if (rc)
2972 cFYI(1, "Send error in hard link (NT rename) = %d", rc); 2680 cFYI(1, "Send error in hard link (NT rename) = %d", rc);
2973 2681
@@ -2979,7 +2687,7 @@ winCreateHardLinkRetry:
2979} 2687}
2980 2688
2981int 2689int
2982CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, 2690CIFSSMBUnixQuerySymLink(const int xid, struct cifs_tcon *tcon,
2983 const unsigned char *searchName, char **symlinkinfo, 2691 const unsigned char *searchName, char **symlinkinfo,
2984 const struct nls_table *nls_codepage) 2692 const struct nls_table *nls_codepage)
2985{ 2693{
@@ -3002,8 +2710,8 @@ querySymLinkRetry:
3002 2710
3003 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2711 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3004 name_len = 2712 name_len =
3005 cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName, 2713 cifs_strtoUCS((__le16 *) pSMB->FileName, searchName,
3006 PATH_MAX, nls_codepage); 2714 PATH_MAX, nls_codepage);
3007 name_len++; /* trailing null */ 2715 name_len++; /* trailing null */
3008 name_len *= 2; 2716 name_len *= 2;
3009 } else { /* BB improve the check for buffer overruns BB */ 2717 } else { /* BB improve the check for buffer overruns BB */
@@ -3060,8 +2768,8 @@ querySymLinkRetry:
3060 is_unicode = false; 2768 is_unicode = false;
3061 2769
3062 /* BB FIXME investigate remapping reserved chars here */ 2770 /* BB FIXME investigate remapping reserved chars here */
3063 *symlinkinfo = cifs_strndup_from_utf16(data_start, 2771 *symlinkinfo = cifs_strndup_from_ucs(data_start, count,
3064 count, is_unicode, nls_codepage); 2772 is_unicode, nls_codepage);
3065 if (!*symlinkinfo) 2773 if (!*symlinkinfo)
3066 rc = -ENOMEM; 2774 rc = -ENOMEM;
3067 } 2775 }
@@ -3084,7 +2792,7 @@ querySymLinkRetry:
3084 * it is not compiled in by default until callers fixed up and more tested. 2792 * it is not compiled in by default until callers fixed up and more tested.
3085 */ 2793 */
3086int 2794int
3087CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon, 2795CIFSSMBQueryReparseLinkInfo(const int xid, struct cifs_tcon *tcon,
3088 const unsigned char *searchName, 2796 const unsigned char *searchName,
3089 char *symlinkinfo, const int buflen, __u16 fid, 2797 char *symlinkinfo, const int buflen, __u16 fid,
3090 const struct nls_table *nls_codepage) 2798 const struct nls_table *nls_codepage)
@@ -3104,7 +2812,8 @@ CIFSSMBQueryReparseLinkInfo(const unsigned int xid, struct cifs_tcon *tcon,
3104 pSMB->TotalDataCount = 0; 2812 pSMB->TotalDataCount = 0;
3105 pSMB->MaxParameterCount = cpu_to_le32(2); 2813 pSMB->MaxParameterCount = cpu_to_le32(2);
3106 /* BB find exact data count max from sess structure BB */ 2814 /* BB find exact data count max from sess structure BB */
3107 pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); 2815 pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
2816 MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
3108 pSMB->MaxSetupCount = 4; 2817 pSMB->MaxSetupCount = 4;
3109 pSMB->Reserved = 0; 2818 pSMB->Reserved = 0;
3110 pSMB->ParameterOffset = 0; 2819 pSMB->ParameterOffset = 0;
@@ -3321,7 +3030,7 @@ static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL,
3321} 3030}
3322 3031
3323int 3032int
3324CIFSSMBGetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, 3033CIFSSMBGetPosixACL(const int xid, struct cifs_tcon *tcon,
3325 const unsigned char *searchName, 3034 const unsigned char *searchName,
3326 char *acl_inf, const int buflen, const int acl_type, 3035 char *acl_inf, const int buflen, const int acl_type,
3327 const struct nls_table *nls_codepage, int remap) 3036 const struct nls_table *nls_codepage, int remap)
@@ -3344,9 +3053,8 @@ queryAclRetry:
3344 3053
3345 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3054 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3346 name_len = 3055 name_len =
3347 cifsConvertToUTF16((__le16 *) pSMB->FileName, 3056 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3348 searchName, PATH_MAX, nls_codepage, 3057 PATH_MAX, nls_codepage, remap);
3349 remap);
3350 name_len++; /* trailing null */ 3058 name_len++; /* trailing null */
3351 name_len *= 2; 3059 name_len *= 2;
3352 pSMB->FileName[name_len] = 0; 3060 pSMB->FileName[name_len] = 0;
@@ -3385,7 +3093,7 @@ queryAclRetry:
3385 3093
3386 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 3094 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
3387 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 3095 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
3388 cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); 3096 cifs_stats_inc(&tcon->num_acl_get);
3389 if (rc) { 3097 if (rc) {
3390 cFYI(1, "Send error in Query POSIX ACL = %d", rc); 3098 cFYI(1, "Send error in Query POSIX ACL = %d", rc);
3391 } else { 3099 } else {
@@ -3410,7 +3118,7 @@ queryAclRetry:
3410} 3118}
3411 3119
3412int 3120int
3413CIFSSMBSetPosixACL(const unsigned int xid, struct cifs_tcon *tcon, 3121CIFSSMBSetPosixACL(const int xid, struct cifs_tcon *tcon,
3414 const unsigned char *fileName, 3122 const unsigned char *fileName,
3415 const char *local_acl, const int buflen, 3123 const char *local_acl, const int buflen,
3416 const int acl_type, 3124 const int acl_type,
@@ -3432,8 +3140,8 @@ setAclRetry:
3432 return rc; 3140 return rc;
3433 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3141 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3434 name_len = 3142 name_len =
3435 cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, 3143 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
3436 PATH_MAX, nls_codepage, remap); 3144 PATH_MAX, nls_codepage, remap);
3437 name_len++; /* trailing null */ 3145 name_len++; /* trailing null */
3438 name_len *= 2; 3146 name_len *= 2;
3439 } else { /* BB improve the check for buffer overruns BB */ 3147 } else { /* BB improve the check for buffer overruns BB */
@@ -3490,7 +3198,7 @@ setACLerrorExit:
3490 3198
3491/* BB fix tabs in this function FIXME BB */ 3199/* BB fix tabs in this function FIXME BB */
3492int 3200int
3493CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, 3201CIFSGetExtAttr(const int xid, struct cifs_tcon *tcon,
3494 const int netfid, __u64 *pExtAttrBits, __u64 *pMask) 3202 const int netfid, __u64 *pExtAttrBits, __u64 *pMask)
3495{ 3203{
3496 int rc = 0; 3204 int rc = 0;
@@ -3598,7 +3306,8 @@ smb_init_nttransact(const __u16 sub_command, const int setup_count,
3598 pSMB->Reserved = 0; 3306 pSMB->Reserved = 0;
3599 pSMB->TotalParameterCount = cpu_to_le32(parm_len); 3307 pSMB->TotalParameterCount = cpu_to_le32(parm_len);
3600 pSMB->TotalDataCount = 0; 3308 pSMB->TotalDataCount = 0;
3601 pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); 3309 pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
3310 MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
3602 pSMB->ParameterCount = pSMB->TotalParameterCount; 3311 pSMB->ParameterCount = pSMB->TotalParameterCount;
3603 pSMB->DataCount = pSMB->TotalDataCount; 3312 pSMB->DataCount = pSMB->TotalDataCount;
3604 temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + 3313 temp_offset = offsetof(struct smb_com_ntransact_req, Parms) +
@@ -3665,7 +3374,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
3665 3374
3666/* Get Security Descriptor (by handle) from remote server for a file or dir */ 3375/* Get Security Descriptor (by handle) from remote server for a file or dir */
3667int 3376int
3668CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, 3377CIFSSMBGetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid,
3669 struct cifs_ntsd **acl_inf, __u32 *pbuflen) 3378 struct cifs_ntsd **acl_inf, __u32 *pbuflen)
3670{ 3379{
3671 int rc = 0; 3380 int rc = 0;
@@ -3696,7 +3405,7 @@ CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid,
3696 3405
3697 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, 3406 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type,
3698 0); 3407 0);
3699 cifs_stats_inc(&tcon->stats.cifs_stats.num_acl_get); 3408 cifs_stats_inc(&tcon->num_acl_get);
3700 if (rc) { 3409 if (rc) {
3701 cFYI(1, "Send error in QuerySecDesc = %d", rc); 3410 cFYI(1, "Send error in QuerySecDesc = %d", rc);
3702 } else { /* decode response */ 3411 } else { /* decode response */
@@ -3757,19 +3466,20 @@ qsec_out:
3757} 3466}
3758 3467
3759int 3468int
3760CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, __u16 fid, 3469CIFSSMBSetCIFSACL(const int xid, struct cifs_tcon *tcon, __u16 fid,
3761 struct cifs_ntsd *pntsd, __u32 acllen, int aclflag) 3470 struct cifs_ntsd *pntsd, __u32 acllen)
3762{ 3471{
3763 __u16 byte_count, param_count, data_count, param_offset, data_offset; 3472 __u16 byte_count, param_count, data_count, param_offset, data_offset;
3764 int rc = 0; 3473 int rc = 0;
3765 int bytes_returned = 0; 3474 int bytes_returned = 0;
3766 SET_SEC_DESC_REQ *pSMB = NULL; 3475 SET_SEC_DESC_REQ *pSMB = NULL;
3767 void *pSMBr; 3476 NTRANSACT_RSP *pSMBr = NULL;
3768 3477
3769setCifsAclRetry: 3478setCifsAclRetry:
3770 rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, &pSMBr); 3479 rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB,
3480 (void **) &pSMBr);
3771 if (rc) 3481 if (rc)
3772 return rc; 3482 return (rc);
3773 3483
3774 pSMB->MaxSetupCount = 0; 3484 pSMB->MaxSetupCount = 0;
3775 pSMB->Reserved = 0; 3485 pSMB->Reserved = 0;
@@ -3794,11 +3504,12 @@ setCifsAclRetry:
3794 3504
3795 pSMB->Fid = fid; /* file handle always le */ 3505 pSMB->Fid = fid; /* file handle always le */
3796 pSMB->Reserved2 = 0; 3506 pSMB->Reserved2 = 0;
3797 pSMB->AclFlags = cpu_to_le32(aclflag); 3507 pSMB->AclFlags = cpu_to_le32(CIFS_ACL_DACL);
3798 3508
3799 if (pntsd && acllen) { 3509 if (pntsd && acllen) {
3800 memcpy((char *)pSMBr + offsetof(struct smb_hdr, Protocol) + 3510 memcpy((char *) &pSMBr->hdr.Protocol + data_offset,
3801 data_offset, pntsd, acllen); 3511 (char *) pntsd,
3512 acllen);
3802 inc_rfc1001_len(pSMB, byte_count + data_count); 3513 inc_rfc1001_len(pSMB, byte_count + data_count);
3803 } else 3514 } else
3804 inc_rfc1001_len(pSMB, byte_count); 3515 inc_rfc1001_len(pSMB, byte_count);
@@ -3821,10 +3532,10 @@ setCifsAclRetry:
3821 3532
3822/* Legacy Query Path Information call for lookup to old servers such 3533/* Legacy Query Path Information call for lookup to old servers such
3823 as Win9x/WinME */ 3534 as Win9x/WinME */
3824int 3535int SMBQueryInformation(const int xid, struct cifs_tcon *tcon,
3825SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, 3536 const unsigned char *searchName,
3826 const char *search_name, FILE_ALL_INFO *data, 3537 FILE_ALL_INFO *pFinfo,
3827 const struct nls_table *nls_codepage, int remap) 3538 const struct nls_table *nls_codepage, int remap)
3828{ 3539{
3829 QUERY_INFORMATION_REQ *pSMB; 3540 QUERY_INFORMATION_REQ *pSMB;
3830 QUERY_INFORMATION_RSP *pSMBr; 3541 QUERY_INFORMATION_RSP *pSMBr;
@@ -3832,7 +3543,7 @@ SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon,
3832 int bytes_returned; 3543 int bytes_returned;
3833 int name_len; 3544 int name_len;
3834 3545
3835 cFYI(1, "In SMBQPath path %s", search_name); 3546 cFYI(1, "In SMBQPath path %s", searchName);
3836QInfRetry: 3547QInfRetry:
3837 rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, 3548 rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB,
3838 (void **) &pSMBr); 3549 (void **) &pSMBr);
@@ -3841,15 +3552,14 @@ QInfRetry:
3841 3552
3842 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3553 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3843 name_len = 3554 name_len =
3844 cifsConvertToUTF16((__le16 *) pSMB->FileName, 3555 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3845 search_name, PATH_MAX, nls_codepage, 3556 PATH_MAX, nls_codepage, remap);
3846 remap);
3847 name_len++; /* trailing null */ 3557 name_len++; /* trailing null */
3848 name_len *= 2; 3558 name_len *= 2;
3849 } else { 3559 } else {
3850 name_len = strnlen(search_name, PATH_MAX); 3560 name_len = strnlen(searchName, PATH_MAX);
3851 name_len++; /* trailing null */ 3561 name_len++; /* trailing null */
3852 strncpy(pSMB->FileName, search_name, name_len); 3562 strncpy(pSMB->FileName, searchName, name_len);
3853 } 3563 }
3854 pSMB->BufferFormat = 0x04; 3564 pSMB->BufferFormat = 0x04;
3855 name_len++; /* account for buffer type byte */ 3565 name_len++; /* account for buffer type byte */
@@ -3860,23 +3570,23 @@ QInfRetry:
3860 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 3570 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
3861 if (rc) { 3571 if (rc) {
3862 cFYI(1, "Send error in QueryInfo = %d", rc); 3572 cFYI(1, "Send error in QueryInfo = %d", rc);
3863 } else if (data) { 3573 } else if (pFinfo) {
3864 struct timespec ts; 3574 struct timespec ts;
3865 __u32 time = le32_to_cpu(pSMBr->last_write_time); 3575 __u32 time = le32_to_cpu(pSMBr->last_write_time);
3866 3576
3867 /* decode response */ 3577 /* decode response */
3868 /* BB FIXME - add time zone adjustment BB */ 3578 /* BB FIXME - add time zone adjustment BB */
3869 memset(data, 0, sizeof(FILE_ALL_INFO)); 3579 memset(pFinfo, 0, sizeof(FILE_ALL_INFO));
3870 ts.tv_nsec = 0; 3580 ts.tv_nsec = 0;
3871 ts.tv_sec = time; 3581 ts.tv_sec = time;
3872 /* decode time fields */ 3582 /* decode time fields */
3873 data->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); 3583 pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts));
3874 data->LastWriteTime = data->ChangeTime; 3584 pFinfo->LastWriteTime = pFinfo->ChangeTime;
3875 data->LastAccessTime = 0; 3585 pFinfo->LastAccessTime = 0;
3876 data->AllocationSize = 3586 pFinfo->AllocationSize =
3877 cpu_to_le64(le32_to_cpu(pSMBr->size)); 3587 cpu_to_le64(le32_to_cpu(pSMBr->size));
3878 data->EndOfFile = data->AllocationSize; 3588 pFinfo->EndOfFile = pFinfo->AllocationSize;
3879 data->Attributes = 3589 pFinfo->Attributes =
3880 cpu_to_le32(le16_to_cpu(pSMBr->attr)); 3590 cpu_to_le32(le16_to_cpu(pSMBr->attr));
3881 } else 3591 } else
3882 rc = -EIO; /* bad buffer passed in */ 3592 rc = -EIO; /* bad buffer passed in */
@@ -3890,7 +3600,7 @@ QInfRetry:
3890} 3600}
3891 3601
3892int 3602int
3893CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 3603CIFSSMBQFileInfo(const int xid, struct cifs_tcon *tcon,
3894 u16 netfid, FILE_ALL_INFO *pFindData) 3604 u16 netfid, FILE_ALL_INFO *pFindData)
3895{ 3605{
3896 struct smb_t2_qfi_req *pSMB = NULL; 3606 struct smb_t2_qfi_req *pSMB = NULL;
@@ -3957,12 +3667,13 @@ QFileInfoRetry:
3957} 3667}
3958 3668
3959int 3669int
3960CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 3670CIFSSMBQPathInfo(const int xid, struct cifs_tcon *tcon,
3961 const char *search_name, FILE_ALL_INFO *data, 3671 const unsigned char *searchName,
3672 FILE_ALL_INFO *pFindData,
3962 int legacy /* old style infolevel */, 3673 int legacy /* old style infolevel */,
3963 const struct nls_table *nls_codepage, int remap) 3674 const struct nls_table *nls_codepage, int remap)
3964{ 3675{
3965 /* level 263 SMB_QUERY_FILE_ALL_INFO */ 3676/* level 263 SMB_QUERY_FILE_ALL_INFO */
3966 TRANSACTION2_QPI_REQ *pSMB = NULL; 3677 TRANSACTION2_QPI_REQ *pSMB = NULL;
3967 TRANSACTION2_QPI_RSP *pSMBr = NULL; 3678 TRANSACTION2_QPI_RSP *pSMBr = NULL;
3968 int rc = 0; 3679 int rc = 0;
@@ -3970,7 +3681,7 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
3970 int name_len; 3681 int name_len;
3971 __u16 params, byte_count; 3682 __u16 params, byte_count;
3972 3683
3973 /* cFYI(1, "In QPathInfo path %s", search_name); */ 3684/* cFYI(1, "In QPathInfo path %s", searchName); */
3974QPathInfoRetry: 3685QPathInfoRetry:
3975 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, 3686 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
3976 (void **) &pSMBr); 3687 (void **) &pSMBr);
@@ -3979,14 +3690,14 @@ QPathInfoRetry:
3979 3690
3980 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3691 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3981 name_len = 3692 name_len =
3982 cifsConvertToUTF16((__le16 *) pSMB->FileName, search_name, 3693 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3983 PATH_MAX, nls_codepage, remap); 3694 PATH_MAX, nls_codepage, remap);
3984 name_len++; /* trailing null */ 3695 name_len++; /* trailing null */
3985 name_len *= 2; 3696 name_len *= 2;
3986 } else { /* BB improve the check for buffer overruns BB */ 3697 } else { /* BB improve the check for buffer overruns BB */
3987 name_len = strnlen(search_name, PATH_MAX); 3698 name_len = strnlen(searchName, PATH_MAX);
3988 name_len++; /* trailing null */ 3699 name_len++; /* trailing null */
3989 strncpy(pSMB->FileName, search_name, name_len); 3700 strncpy(pSMB->FileName, searchName, name_len);
3990 } 3701 }
3991 3702
3992 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; 3703 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */;
@@ -4031,21 +3742,20 @@ QPathInfoRetry:
4031 else if (legacy && get_bcc(&pSMBr->hdr) < 24) 3742 else if (legacy && get_bcc(&pSMBr->hdr) < 24)
4032 rc = -EIO; /* 24 or 26 expected but we do not read 3743 rc = -EIO; /* 24 or 26 expected but we do not read
4033 last field */ 3744 last field */
4034 else if (data) { 3745 else if (pFindData) {
4035 int size; 3746 int size;
4036 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 3747 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
4037 3748
4038 /* 3749 /* On legacy responses we do not read the last field,
4039 * On legacy responses we do not read the last field, 3750 EAsize, fortunately since it varies by subdialect and
4040 * EAsize, fortunately since it varies by subdialect and 3751 also note it differs on Set vs. Get, ie two bytes or 4
4041 * also note it differs on Set vs Get, ie two bytes or 4 3752 bytes depending but we don't care here */
4042 * bytes depending but we don't care here.
4043 */
4044 if (legacy) 3753 if (legacy)
4045 size = sizeof(FILE_INFO_STANDARD); 3754 size = sizeof(FILE_INFO_STANDARD);
4046 else 3755 else
4047 size = sizeof(FILE_ALL_INFO); 3756 size = sizeof(FILE_ALL_INFO);
4048 memcpy((char *) data, (char *) &pSMBr->hdr.Protocol + 3757 memcpy((char *) pFindData,
3758 (char *) &pSMBr->hdr.Protocol +
4049 data_offset, size); 3759 data_offset, size);
4050 } else 3760 } else
4051 rc = -ENOMEM; 3761 rc = -ENOMEM;
@@ -4058,7 +3768,7 @@ QPathInfoRetry:
4058} 3768}
4059 3769
4060int 3770int
4061CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 3771CIFSSMBUnixQFileInfo(const int xid, struct cifs_tcon *tcon,
4062 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) 3772 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData)
4063{ 3773{
4064 struct smb_t2_qfi_req *pSMB = NULL; 3774 struct smb_t2_qfi_req *pSMB = NULL;
@@ -4106,7 +3816,7 @@ UnixQFileInfoRetry:
4106 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 3816 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4107 3817
4108 if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { 3818 if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) {
4109 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response. " 3819 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
4110 "Unix Extensions can be disabled on mount " 3820 "Unix Extensions can be disabled on mount "
4111 "by specifying the nosfu mount option."); 3821 "by specifying the nosfu mount option.");
4112 rc = -EIO; /* bad smb */ 3822 rc = -EIO; /* bad smb */
@@ -4127,7 +3837,7 @@ UnixQFileInfoRetry:
4127} 3837}
4128 3838
4129int 3839int
4130CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 3840CIFSSMBUnixQPathInfo(const int xid, struct cifs_tcon *tcon,
4131 const unsigned char *searchName, 3841 const unsigned char *searchName,
4132 FILE_UNIX_BASIC_INFO *pFindData, 3842 FILE_UNIX_BASIC_INFO *pFindData,
4133 const struct nls_table *nls_codepage, int remap) 3843 const struct nls_table *nls_codepage, int remap)
@@ -4149,8 +3859,8 @@ UnixQPathInfoRetry:
4149 3859
4150 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3860 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
4151 name_len = 3861 name_len =
4152 cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, 3862 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
4153 PATH_MAX, nls_codepage, remap); 3863 PATH_MAX, nls_codepage, remap);
4154 name_len++; /* trailing null */ 3864 name_len++; /* trailing null */
4155 name_len *= 2; 3865 name_len *= 2;
4156 } else { /* BB improve the check for buffer overruns BB */ 3866 } else { /* BB improve the check for buffer overruns BB */
@@ -4192,7 +3902,7 @@ UnixQPathInfoRetry:
4192 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 3902 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4193 3903
4194 if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { 3904 if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) {
4195 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response. " 3905 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
4196 "Unix Extensions can be disabled on mount " 3906 "Unix Extensions can be disabled on mount "
4197 "by specifying the nosfu mount option."); 3907 "by specifying the nosfu mount option.");
4198 rc = -EIO; /* bad smb */ 3908 rc = -EIO; /* bad smb */
@@ -4213,10 +3923,11 @@ UnixQPathInfoRetry:
4213 3923
4214/* xid, tcon, searchName and codepage are input parms, rest are returned */ 3924/* xid, tcon, searchName and codepage are input parms, rest are returned */
4215int 3925int
4216CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, 3926CIFSFindFirst(const int xid, struct cifs_tcon *tcon,
4217 const char *searchName, struct cifs_sb_info *cifs_sb, 3927 const char *searchName,
4218 __u16 *pnetfid, __u16 search_flags, 3928 const struct nls_table *nls_codepage,
4219 struct cifs_search_info *psrch_inf, bool msearch) 3929 __u16 *pnetfid,
3930 struct cifs_search_info *psrch_inf, int remap, const char dirsep)
4220{ 3931{
4221/* level 257 SMB_ */ 3932/* level 257 SMB_ */
4222 TRANSACTION2_FFIRST_REQ *pSMB = NULL; 3933 TRANSACTION2_FFIRST_REQ *pSMB = NULL;
@@ -4224,9 +3935,8 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon,
4224 T2_FFIRST_RSP_PARMS *parms; 3935 T2_FFIRST_RSP_PARMS *parms;
4225 int rc = 0; 3936 int rc = 0;
4226 int bytes_returned = 0; 3937 int bytes_returned = 0;
4227 int name_len, remap; 3938 int name_len;
4228 __u16 params, byte_count; 3939 __u16 params, byte_count;
4229 struct nls_table *nls_codepage;
4230 3940
4231 cFYI(1, "In FindFirst for %s", searchName); 3941 cFYI(1, "In FindFirst for %s", searchName);
4232 3942
@@ -4236,46 +3946,39 @@ findFirstRetry:
4236 if (rc) 3946 if (rc)
4237 return rc; 3947 return rc;
4238 3948
4239 nls_codepage = cifs_sb->local_nls;
4240 remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
4241
4242 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3949 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
4243 name_len = 3950 name_len =
4244 cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, 3951 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
4245 PATH_MAX, nls_codepage, remap); 3952 PATH_MAX, nls_codepage, remap);
4246 /* We can not add the asterik earlier in case 3953 /* We can not add the asterik earlier in case
4247 it got remapped to 0xF03A as if it were part of the 3954 it got remapped to 0xF03A as if it were part of the
4248 directory name instead of a wildcard */ 3955 directory name instead of a wildcard */
4249 name_len *= 2; 3956 name_len *= 2;
4250 if (msearch) { 3957 pSMB->FileName[name_len] = dirsep;
4251 pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); 3958 pSMB->FileName[name_len+1] = 0;
4252 pSMB->FileName[name_len+1] = 0; 3959 pSMB->FileName[name_len+2] = '*';
4253 pSMB->FileName[name_len+2] = '*'; 3960 pSMB->FileName[name_len+3] = 0;
4254 pSMB->FileName[name_len+3] = 0; 3961 name_len += 4; /* now the trailing null */
4255 name_len += 4; /* now the trailing null */ 3962 pSMB->FileName[name_len] = 0; /* null terminate just in case */
4256 /* null terminate just in case */ 3963 pSMB->FileName[name_len+1] = 0;
4257 pSMB->FileName[name_len] = 0; 3964 name_len += 2;
4258 pSMB->FileName[name_len+1] = 0;
4259 name_len += 2;
4260 }
4261 } else { /* BB add check for overrun of SMB buf BB */ 3965 } else { /* BB add check for overrun of SMB buf BB */
4262 name_len = strnlen(searchName, PATH_MAX); 3966 name_len = strnlen(searchName, PATH_MAX);
4263/* BB fix here and in unicode clause above ie 3967/* BB fix here and in unicode clause above ie
4264 if (name_len > buffersize-header) 3968 if (name_len > buffersize-header)
4265 free buffer exit; BB */ 3969 free buffer exit; BB */
4266 strncpy(pSMB->FileName, searchName, name_len); 3970 strncpy(pSMB->FileName, searchName, name_len);
4267 if (msearch) { 3971 pSMB->FileName[name_len] = dirsep;
4268 pSMB->FileName[name_len] = CIFS_DIR_SEP(cifs_sb); 3972 pSMB->FileName[name_len+1] = '*';
4269 pSMB->FileName[name_len+1] = '*'; 3973 pSMB->FileName[name_len+2] = 0;
4270 pSMB->FileName[name_len+2] = 0; 3974 name_len += 3;
4271 name_len += 3;
4272 }
4273 } 3975 }
4274 3976
4275 params = 12 + name_len /* includes null */ ; 3977 params = 12 + name_len /* includes null */ ;
4276 pSMB->TotalDataCount = 0; /* no EAs */ 3978 pSMB->TotalDataCount = 0; /* no EAs */
4277 pSMB->MaxParameterCount = cpu_to_le16(10); 3979 pSMB->MaxParameterCount = cpu_to_le16(10);
4278 pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); 3980 pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf -
3981 MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
4279 pSMB->MaxSetupCount = 0; 3982 pSMB->MaxSetupCount = 0;
4280 pSMB->Reserved = 0; 3983 pSMB->Reserved = 0;
4281 pSMB->Flags = 0; 3984 pSMB->Flags = 0;
@@ -4296,7 +3999,8 @@ findFirstRetry:
4296 cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | 3999 cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
4297 ATTR_DIRECTORY); 4000 ATTR_DIRECTORY);
4298 pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); 4001 pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO));
4299 pSMB->SearchFlags = cpu_to_le16(search_flags); 4002 pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END |
4003 CIFS_SEARCH_RETURN_RESUME);
4300 pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); 4004 pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level);
4301 4005
4302 /* BB what should we set StorageType to? Does it matter? BB */ 4006 /* BB what should we set StorageType to? Does it matter? BB */
@@ -4306,7 +4010,7 @@ findFirstRetry:
4306 4010
4307 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 4011 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
4308 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 4012 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
4309 cifs_stats_inc(&tcon->stats.cifs_stats.num_ffirst); 4013 cifs_stats_inc(&tcon->num_ffirst);
4310 4014
4311 if (rc) {/* BB add logic to retry regular search if Unix search 4015 if (rc) {/* BB add logic to retry regular search if Unix search
4312 rejected unexpectedly by server */ 4016 rejected unexpectedly by server */
@@ -4348,7 +4052,8 @@ findFirstRetry:
4348 psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + 4052 psrch_inf->index_of_last_entry = 2 /* skip . and .. */ +
4349 psrch_inf->entries_in_buffer; 4053 psrch_inf->entries_in_buffer;
4350 lnoff = le16_to_cpu(parms->LastNameOffset); 4054 lnoff = le16_to_cpu(parms->LastNameOffset);
4351 if (CIFSMaxBufSize < lnoff) { 4055 if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE <
4056 lnoff) {
4352 cERROR(1, "ignoring corrupt resume name"); 4057 cERROR(1, "ignoring corrupt resume name");
4353 psrch_inf->last_entry = NULL; 4058 psrch_inf->last_entry = NULL;
4354 return rc; 4059 return rc;
@@ -4357,8 +4062,7 @@ findFirstRetry:
4357 psrch_inf->last_entry = psrch_inf->srch_entries_start + 4062 psrch_inf->last_entry = psrch_inf->srch_entries_start +
4358 lnoff; 4063 lnoff;
4359 4064
4360 if (pnetfid) 4065 *pnetfid = parms->SearchHandle;
4361 *pnetfid = parms->SearchHandle;
4362 } else { 4066 } else {
4363 cifs_buf_release(pSMB); 4067 cifs_buf_release(pSMB);
4364 } 4068 }
@@ -4367,9 +4071,8 @@ findFirstRetry:
4367 return rc; 4071 return rc;
4368} 4072}
4369 4073
4370int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, 4074int CIFSFindNext(const int xid, struct cifs_tcon *tcon,
4371 __u16 searchHandle, __u16 search_flags, 4075 __u16 searchHandle, struct cifs_search_info *psrch_inf)
4372 struct cifs_search_info *psrch_inf)
4373{ 4076{
4374 TRANSACTION2_FNEXT_REQ *pSMB = NULL; 4077 TRANSACTION2_FNEXT_REQ *pSMB = NULL;
4375 TRANSACTION2_FNEXT_RSP *pSMBr = NULL; 4078 TRANSACTION2_FNEXT_RSP *pSMBr = NULL;
@@ -4394,7 +4097,9 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
4394 byte_count = 0; 4097 byte_count = 0;
4395 pSMB->TotalDataCount = 0; /* no EAs */ 4098 pSMB->TotalDataCount = 0; /* no EAs */
4396 pSMB->MaxParameterCount = cpu_to_le16(8); 4099 pSMB->MaxParameterCount = cpu_to_le16(8);
4397 pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize & 0xFFFFFF00); 4100 pSMB->MaxDataCount =
4101 cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) &
4102 0xFFFFFF00);
4398 pSMB->MaxSetupCount = 0; 4103 pSMB->MaxSetupCount = 0;
4399 pSMB->Reserved = 0; 4104 pSMB->Reserved = 0;
4400 pSMB->Flags = 0; 4105 pSMB->Flags = 0;
@@ -4412,7 +4117,8 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
4412 cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); 4117 cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO));
4413 pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); 4118 pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level);
4414 pSMB->ResumeKey = psrch_inf->resume_key; 4119 pSMB->ResumeKey = psrch_inf->resume_key;
4415 pSMB->SearchFlags = cpu_to_le16(search_flags); 4120 pSMB->SearchFlags =
4121 cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME);
4416 4122
4417 name_len = psrch_inf->resume_name_len; 4123 name_len = psrch_inf->resume_name_len;
4418 params += name_len; 4124 params += name_len;
@@ -4434,7 +4140,7 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
4434 4140
4435 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 4141 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
4436 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 4142 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
4437 cifs_stats_inc(&tcon->stats.cifs_stats.num_fnext); 4143 cifs_stats_inc(&tcon->num_fnext);
4438 if (rc) { 4144 if (rc) {
4439 if (rc == -EBADF) { 4145 if (rc == -EBADF) {
4440 psrch_inf->endOfSearch = true; 4146 psrch_inf->endOfSearch = true;
@@ -4475,7 +4181,8 @@ int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
4475 psrch_inf->index_of_last_entry += 4181 psrch_inf->index_of_last_entry +=
4476 psrch_inf->entries_in_buffer; 4182 psrch_inf->entries_in_buffer;
4477 lnoff = le16_to_cpu(parms->LastNameOffset); 4183 lnoff = le16_to_cpu(parms->LastNameOffset);
4478 if (CIFSMaxBufSize < lnoff) { 4184 if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE <
4185 lnoff) {
4479 cERROR(1, "ignoring corrupt resume name"); 4186 cERROR(1, "ignoring corrupt resume name");
4480 psrch_inf->last_entry = NULL; 4187 psrch_inf->last_entry = NULL;
4481 return rc; 4188 return rc;
@@ -4503,7 +4210,7 @@ FNext2_err_exit:
4503} 4210}
4504 4211
4505int 4212int
4506CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, 4213CIFSFindClose(const int xid, struct cifs_tcon *tcon,
4507 const __u16 searchHandle) 4214 const __u16 searchHandle)
4508{ 4215{
4509 int rc = 0; 4216 int rc = 0;
@@ -4521,11 +4228,11 @@ CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon,
4521 4228
4522 pSMB->FileID = searchHandle; 4229 pSMB->FileID = searchHandle;
4523 pSMB->ByteCount = 0; 4230 pSMB->ByteCount = 0;
4524 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 4231 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
4525 if (rc) 4232 if (rc)
4526 cERROR(1, "Send error in FindClose = %d", rc); 4233 cERROR(1, "Send error in FindClose = %d", rc);
4527 4234
4528 cifs_stats_inc(&tcon->stats.cifs_stats.num_fclose); 4235 cifs_stats_inc(&tcon->num_fclose);
4529 4236
4530 /* Since session is dead, search handle closed on server already */ 4237 /* Since session is dead, search handle closed on server already */
4531 if (rc == -EAGAIN) 4238 if (rc == -EAGAIN)
@@ -4535,8 +4242,9 @@ CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon,
4535} 4242}
4536 4243
4537int 4244int
4538CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, 4245CIFSGetSrvInodeNumber(const int xid, struct cifs_tcon *tcon,
4539 const char *search_name, __u64 *inode_number, 4246 const unsigned char *searchName,
4247 __u64 *inode_number,
4540 const struct nls_table *nls_codepage, int remap) 4248 const struct nls_table *nls_codepage, int remap)
4541{ 4249{
4542 int rc = 0; 4250 int rc = 0;
@@ -4545,7 +4253,7 @@ CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon,
4545 int name_len, bytes_returned; 4253 int name_len, bytes_returned;
4546 __u16 params, byte_count; 4254 __u16 params, byte_count;
4547 4255
4548 cFYI(1, "In GetSrvInodeNum for %s", search_name); 4256 cFYI(1, "In GetSrvInodeNum for %s", searchName);
4549 if (tcon == NULL) 4257 if (tcon == NULL)
4550 return -ENODEV; 4258 return -ENODEV;
4551 4259
@@ -4557,15 +4265,14 @@ GetInodeNumberRetry:
4557 4265
4558 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 4266 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
4559 name_len = 4267 name_len =
4560 cifsConvertToUTF16((__le16 *) pSMB->FileName, 4268 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
4561 search_name, PATH_MAX, nls_codepage, 4269 PATH_MAX, nls_codepage, remap);
4562 remap);
4563 name_len++; /* trailing null */ 4270 name_len++; /* trailing null */
4564 name_len *= 2; 4271 name_len *= 2;
4565 } else { /* BB improve the check for buffer overruns BB */ 4272 } else { /* BB improve the check for buffer overruns BB */
4566 name_len = strnlen(search_name, PATH_MAX); 4273 name_len = strnlen(searchName, PATH_MAX);
4567 name_len++; /* trailing null */ 4274 name_len++; /* trailing null */
4568 strncpy(pSMB->FileName, search_name, name_len); 4275 strncpy(pSMB->FileName, searchName, name_len);
4569 } 4276 }
4570 4277
4571 params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; 4278 params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ;
@@ -4653,7 +4360,7 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4653 4360
4654 if (*num_of_nodes < 1) { 4361 if (*num_of_nodes < 1) {
4655 cERROR(1, "num_referrals: must be at least > 0," 4362 cERROR(1, "num_referrals: must be at least > 0,"
4656 "but we get num_referrals = %d", *num_of_nodes); 4363 "but we get num_referrals = %d\n", *num_of_nodes);
4657 rc = -EINVAL; 4364 rc = -EINVAL;
4658 goto parse_DFS_referrals_exit; 4365 goto parse_DFS_referrals_exit;
4659 } 4366 }
@@ -4670,14 +4377,14 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4670 data_end = (char *)(&(pSMBr->PathConsumed)) + 4377 data_end = (char *)(&(pSMBr->PathConsumed)) +
4671 le16_to_cpu(pSMBr->t2.DataCount); 4378 le16_to_cpu(pSMBr->t2.DataCount);
4672 4379
4673 cFYI(1, "num_referrals: %d dfs flags: 0x%x ...", 4380 cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n",
4674 *num_of_nodes, 4381 *num_of_nodes,
4675 le32_to_cpu(pSMBr->DFSFlags)); 4382 le32_to_cpu(pSMBr->DFSFlags));
4676 4383
4677 *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * 4384 *target_nodes = kzalloc(sizeof(struct dfs_info3_param) *
4678 *num_of_nodes, GFP_KERNEL); 4385 *num_of_nodes, GFP_KERNEL);
4679 if (*target_nodes == NULL) { 4386 if (*target_nodes == NULL) {
4680 cERROR(1, "Failed to allocate buffer for target_nodes"); 4387 cERROR(1, "Failed to allocate buffer for target_nodes\n");
4681 rc = -ENOMEM; 4388 rc = -ENOMEM;
4682 goto parse_DFS_referrals_exit; 4389 goto parse_DFS_referrals_exit;
4683 } 4390 }
@@ -4696,9 +4403,9 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4696 rc = -ENOMEM; 4403 rc = -ENOMEM;
4697 goto parse_DFS_referrals_exit; 4404 goto parse_DFS_referrals_exit;
4698 } 4405 }
4699 cifsConvertToUTF16((__le16 *) tmp, searchName, 4406 cifsConvertToUCS((__le16 *) tmp, searchName,
4700 PATH_MAX, nls_codepage, remap); 4407 PATH_MAX, nls_codepage, remap);
4701 node->path_consumed = cifs_utf16_bytes(tmp, 4408 node->path_consumed = cifs_ucs2_bytes(tmp,
4702 le16_to_cpu(pSMBr->PathConsumed), 4409 le16_to_cpu(pSMBr->PathConsumed),
4703 nls_codepage); 4410 nls_codepage);
4704 kfree(tmp); 4411 kfree(tmp);
@@ -4711,8 +4418,8 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4711 /* copy DfsPath */ 4418 /* copy DfsPath */
4712 temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); 4419 temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset);
4713 max_len = data_end - temp; 4420 max_len = data_end - temp;
4714 node->path_name = cifs_strndup_from_utf16(temp, max_len, 4421 node->path_name = cifs_strndup_from_ucs(temp, max_len,
4715 is_unicode, nls_codepage); 4422 is_unicode, nls_codepage);
4716 if (!node->path_name) { 4423 if (!node->path_name) {
4717 rc = -ENOMEM; 4424 rc = -ENOMEM;
4718 goto parse_DFS_referrals_exit; 4425 goto parse_DFS_referrals_exit;
@@ -4721,14 +4428,10 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4721 /* copy link target UNC */ 4428 /* copy link target UNC */
4722 temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); 4429 temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset);
4723 max_len = data_end - temp; 4430 max_len = data_end - temp;
4724 node->node_name = cifs_strndup_from_utf16(temp, max_len, 4431 node->node_name = cifs_strndup_from_ucs(temp, max_len,
4725 is_unicode, nls_codepage); 4432 is_unicode, nls_codepage);
4726 if (!node->node_name) { 4433 if (!node->node_name)
4727 rc = -ENOMEM; 4434 rc = -ENOMEM;
4728 goto parse_DFS_referrals_exit;
4729 }
4730
4731 ref++;
4732 } 4435 }
4733 4436
4734parse_DFS_referrals_exit: 4437parse_DFS_referrals_exit:
@@ -4741,8 +4444,9 @@ parse_DFS_referrals_exit:
4741} 4444}
4742 4445
4743int 4446int
4744CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, 4447CIFSGetDFSRefer(const int xid, struct cifs_ses *ses,
4745 const char *search_name, struct dfs_info3_param **target_nodes, 4448 const unsigned char *searchName,
4449 struct dfs_info3_param **target_nodes,
4746 unsigned int *num_of_nodes, 4450 unsigned int *num_of_nodes,
4747 const struct nls_table *nls_codepage, int remap) 4451 const struct nls_table *nls_codepage, int remap)
4748{ 4452{
@@ -4756,7 +4460,7 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,
4756 *num_of_nodes = 0; 4460 *num_of_nodes = 0;
4757 *target_nodes = NULL; 4461 *target_nodes = NULL;
4758 4462
4759 cFYI(1, "In GetDFSRefer the path %s", search_name); 4463 cFYI(1, "In GetDFSRefer the path %s", searchName);
4760 if (ses == NULL) 4464 if (ses == NULL)
4761 return -ENODEV; 4465 return -ENODEV;
4762getDFSRetry: 4466getDFSRetry:
@@ -4767,7 +4471,7 @@ getDFSRetry:
4767 4471
4768 /* server pointer checked in called function, 4472 /* server pointer checked in called function,
4769 but should never be null here anyway */ 4473 but should never be null here anyway */
4770 pSMB->hdr.Mid = get_next_mid(ses->server); 4474 pSMB->hdr.Mid = GetNextMid(ses->server);
4771 pSMB->hdr.Tid = ses->ipc_tid; 4475 pSMB->hdr.Tid = ses->ipc_tid;
4772 pSMB->hdr.Uid = ses->Suid; 4476 pSMB->hdr.Uid = ses->Suid;
4773 if (ses->capabilities & CAP_STATUS32) 4477 if (ses->capabilities & CAP_STATUS32)
@@ -4778,15 +4482,14 @@ getDFSRetry:
4778 if (ses->capabilities & CAP_UNICODE) { 4482 if (ses->capabilities & CAP_UNICODE) {
4779 pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; 4483 pSMB->hdr.Flags2 |= SMBFLG2_UNICODE;
4780 name_len = 4484 name_len =
4781 cifsConvertToUTF16((__le16 *) pSMB->RequestFileName, 4485 cifsConvertToUCS((__le16 *) pSMB->RequestFileName,
4782 search_name, PATH_MAX, nls_codepage, 4486 searchName, PATH_MAX, nls_codepage, remap);
4783 remap);
4784 name_len++; /* trailing null */ 4487 name_len++; /* trailing null */
4785 name_len *= 2; 4488 name_len *= 2;
4786 } else { /* BB improve the check for buffer overruns BB */ 4489 } else { /* BB improve the check for buffer overruns BB */
4787 name_len = strnlen(search_name, PATH_MAX); 4490 name_len = strnlen(searchName, PATH_MAX);
4788 name_len++; /* trailing null */ 4491 name_len++; /* trailing null */
4789 strncpy(pSMB->RequestFileName, search_name, name_len); 4492 strncpy(pSMB->RequestFileName, searchName, name_len);
4790 } 4493 }
4791 4494
4792 if (ses->server) { 4495 if (ses->server) {
@@ -4842,7 +4545,7 @@ getDFSRetry:
4842 /* parse returned result into more usable form */ 4545 /* parse returned result into more usable form */
4843 rc = parse_DFS_referrals(pSMBr, num_of_nodes, 4546 rc = parse_DFS_referrals(pSMBr, num_of_nodes,
4844 target_nodes, nls_codepage, remap, 4547 target_nodes, nls_codepage, remap,
4845 search_name); 4548 searchName);
4846 4549
4847GetDFSRefExit: 4550GetDFSRefExit:
4848 cifs_buf_release(pSMB); 4551 cifs_buf_release(pSMB);
@@ -4855,8 +4558,7 @@ GetDFSRefExit:
4855 4558
4856/* Query File System Info such as free space to old servers such as Win 9x */ 4559/* Query File System Info such as free space to old servers such as Win 9x */
4857int 4560int
4858SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 4561SMBOldQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData)
4859 struct kstatfs *FSData)
4860{ 4562{
4861/* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ 4563/* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
4862 TRANSACTION2_QFSI_REQ *pSMB = NULL; 4564 TRANSACTION2_QFSI_REQ *pSMB = NULL;
@@ -4935,8 +4637,7 @@ oldQFSInfoRetry:
4935} 4637}
4936 4638
4937int 4639int
4938CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 4640CIFSSMBQFSInfo(const int xid, struct cifs_tcon *tcon, struct kstatfs *FSData)
4939 struct kstatfs *FSData)
4940{ 4641{
4941/* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ 4642/* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
4942 TRANSACTION2_QFSI_REQ *pSMB = NULL; 4643 TRANSACTION2_QFSI_REQ *pSMB = NULL;
@@ -5015,7 +4716,7 @@ QFSInfoRetry:
5015} 4716}
5016 4717
5017int 4718int
5018CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon) 4719CIFSSMBQFSAttributeInfo(const int xid, struct cifs_tcon *tcon)
5019{ 4720{
5020/* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ 4721/* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
5021 TRANSACTION2_QFSI_REQ *pSMB = NULL; 4722 TRANSACTION2_QFSI_REQ *pSMB = NULL;
@@ -5085,7 +4786,7 @@ QFSAttributeRetry:
5085} 4786}
5086 4787
5087int 4788int
5088CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon) 4789CIFSSMBQFSDeviceInfo(const int xid, struct cifs_tcon *tcon)
5089{ 4790{
5090/* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ 4791/* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
5091 TRANSACTION2_QFSI_REQ *pSMB = NULL; 4792 TRANSACTION2_QFSI_REQ *pSMB = NULL;
@@ -5156,7 +4857,7 @@ QFSDeviceRetry:
5156} 4857}
5157 4858
5158int 4859int
5159CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon) 4860CIFSSMBQFSUnixInfo(const int xid, struct cifs_tcon *tcon)
5160{ 4861{
5161/* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ 4862/* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
5162 TRANSACTION2_QFSI_REQ *pSMB = NULL; 4863 TRANSACTION2_QFSI_REQ *pSMB = NULL;
@@ -5226,7 +4927,7 @@ QFSUnixRetry:
5226} 4927}
5227 4928
5228int 4929int
5229CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, __u64 cap) 4930CIFSSMBSetFSUnixInfo(const int xid, struct cifs_tcon *tcon, __u64 cap)
5230{ 4931{
5231/* level 0x200 SMB_SET_CIFS_UNIX_INFO */ 4932/* level 0x200 SMB_SET_CIFS_UNIX_INFO */
5232 TRANSACTION2_SETFSI_REQ *pSMB = NULL; 4933 TRANSACTION2_SETFSI_REQ *pSMB = NULL;
@@ -5300,7 +5001,7 @@ SETFSUnixRetry:
5300 5001
5301 5002
5302int 5003int
5303CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, 5004CIFSSMBQFSPosixInfo(const int xid, struct cifs_tcon *tcon,
5304 struct kstatfs *FSData) 5005 struct kstatfs *FSData)
5305{ 5006{
5306/* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ 5007/* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
@@ -5386,16 +5087,16 @@ QFSPosixRetry:
5386} 5087}
5387 5088
5388 5089
5389/* 5090/* We can not use write of zero bytes trick to
5390 * We can not use write of zero bytes trick to set file size due to need for 5091 set file size due to need for large file support. Also note that
5391 * large file support. Also note that this SetPathInfo is preferred to 5092 this SetPathInfo is preferred to SetFileInfo based method in next
5392 * SetFileInfo based method in next routine which is only needed to work around 5093 routine which is only needed to work around a sharing violation bug
5393 * a sharing violation bugin Samba which this routine can run into. 5094 in Samba which this routine can run into */
5394 */ 5095
5395int 5096int
5396CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, 5097CIFSSMBSetEOF(const int xid, struct cifs_tcon *tcon, const char *fileName,
5397 const char *file_name, __u64 size, struct cifs_sb_info *cifs_sb, 5098 __u64 size, bool SetAllocation,
5398 bool set_allocation) 5099 const struct nls_table *nls_codepage, int remap)
5399{ 5100{
5400 struct smb_com_transaction2_spi_req *pSMB = NULL; 5101 struct smb_com_transaction2_spi_req *pSMB = NULL;
5401 struct smb_com_transaction2_spi_rsp *pSMBr = NULL; 5102 struct smb_com_transaction2_spi_rsp *pSMBr = NULL;
@@ -5403,8 +5104,6 @@ CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon,
5403 int name_len; 5104 int name_len;
5404 int rc = 0; 5105 int rc = 0;
5405 int bytes_returned = 0; 5106 int bytes_returned = 0;
5406 int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
5407
5408 __u16 params, byte_count, data_count, param_offset, offset; 5107 __u16 params, byte_count, data_count, param_offset, offset;
5409 5108
5410 cFYI(1, "In SetEOF"); 5109 cFYI(1, "In SetEOF");
@@ -5416,14 +5115,14 @@ SetEOFRetry:
5416 5115
5417 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5116 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5418 name_len = 5117 name_len =
5419 cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, 5118 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
5420 PATH_MAX, cifs_sb->local_nls, remap); 5119 PATH_MAX, nls_codepage, remap);
5421 name_len++; /* trailing null */ 5120 name_len++; /* trailing null */
5422 name_len *= 2; 5121 name_len *= 2;
5423 } else { /* BB improve the check for buffer overruns BB */ 5122 } else { /* BB improve the check for buffer overruns BB */
5424 name_len = strnlen(file_name, PATH_MAX); 5123 name_len = strnlen(fileName, PATH_MAX);
5425 name_len++; /* trailing null */ 5124 name_len++; /* trailing null */
5426 strncpy(pSMB->FileName, file_name, name_len); 5125 strncpy(pSMB->FileName, fileName, name_len);
5427 } 5126 }
5428 params = 6 + name_len; 5127 params = 6 + name_len;
5429 data_count = sizeof(struct file_end_of_file_info); 5128 data_count = sizeof(struct file_end_of_file_info);
@@ -5437,7 +5136,7 @@ SetEOFRetry:
5437 param_offset = offsetof(struct smb_com_transaction2_spi_req, 5136 param_offset = offsetof(struct smb_com_transaction2_spi_req,
5438 InformationLevel) - 4; 5137 InformationLevel) - 4;
5439 offset = param_offset + params; 5138 offset = param_offset + params;
5440 if (set_allocation) { 5139 if (SetAllocation) {
5441 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) 5140 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
5442 pSMB->InformationLevel = 5141 pSMB->InformationLevel =
5443 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); 5142 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2);
@@ -5484,8 +5183,8 @@ SetEOFRetry:
5484} 5183}
5485 5184
5486int 5185int
5487CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, 5186CIFSSMBSetFileSize(const int xid, struct cifs_tcon *tcon, __u64 size,
5488 struct cifsFileInfo *cfile, __u64 size, bool set_allocation) 5187 __u16 fid, __u32 pid_of_opener, bool SetAllocation)
5489{ 5188{
5490 struct smb_com_transaction2_sfi_req *pSMB = NULL; 5189 struct smb_com_transaction2_sfi_req *pSMB = NULL;
5491 struct file_end_of_file_info *parm_data; 5190 struct file_end_of_file_info *parm_data;
@@ -5499,8 +5198,8 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon,
5499 if (rc) 5198 if (rc)
5500 return rc; 5199 return rc;
5501 5200
5502 pSMB->hdr.Pid = cpu_to_le16((__u16)cfile->pid); 5201 pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener);
5503 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(cfile->pid >> 16)); 5202 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));
5504 5203
5505 params = 6; 5204 params = 6;
5506 pSMB->MaxSetupCount = 0; 5205 pSMB->MaxSetupCount = 0;
@@ -5529,8 +5228,8 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon,
5529 + offset); 5228 + offset);
5530 pSMB->DataOffset = cpu_to_le16(offset); 5229 pSMB->DataOffset = cpu_to_le16(offset);
5531 parm_data->FileSize = cpu_to_le64(size); 5230 parm_data->FileSize = cpu_to_le64(size);
5532 pSMB->Fid = cfile->fid.netfid; 5231 pSMB->Fid = fid;
5533 if (set_allocation) { 5232 if (SetAllocation) {
5534 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) 5233 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
5535 pSMB->InformationLevel = 5234 pSMB->InformationLevel =
5536 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); 5235 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2);
@@ -5548,7 +5247,7 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon,
5548 pSMB->Reserved4 = 0; 5247 pSMB->Reserved4 = 0;
5549 inc_rfc1001_len(pSMB, byte_count); 5248 inc_rfc1001_len(pSMB, byte_count);
5550 pSMB->ByteCount = cpu_to_le16(byte_count); 5249 pSMB->ByteCount = cpu_to_le16(byte_count);
5551 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 5250 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
5552 if (rc) { 5251 if (rc) {
5553 cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); 5252 cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc);
5554 } 5253 }
@@ -5566,7 +5265,7 @@ CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon,
5566 time and resort to the original setpathinfo level which takes the ancient 5265 time and resort to the original setpathinfo level which takes the ancient
5567 DOS time format with 2 second granularity */ 5266 DOS time format with 2 second granularity */
5568int 5267int
5569CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 5268CIFSSMBSetFileInfo(const int xid, struct cifs_tcon *tcon,
5570 const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) 5269 const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener)
5571{ 5270{
5572 struct smb_com_transaction2_sfi_req *pSMB = NULL; 5271 struct smb_com_transaction2_sfi_req *pSMB = NULL;
@@ -5592,8 +5291,7 @@ CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
5592 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 5291 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
5593 offset = param_offset + params; 5292 offset = param_offset + params;
5594 5293
5595 data_offset = (char *)pSMB + 5294 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
5596 offsetof(struct smb_hdr, Protocol) + offset;
5597 5295
5598 count = sizeof(FILE_BASIC_INFO); 5296 count = sizeof(FILE_BASIC_INFO);
5599 pSMB->MaxParameterCount = cpu_to_le16(2); 5297 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -5618,7 +5316,7 @@ CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
5618 inc_rfc1001_len(pSMB, byte_count); 5316 inc_rfc1001_len(pSMB, byte_count);
5619 pSMB->ByteCount = cpu_to_le16(byte_count); 5317 pSMB->ByteCount = cpu_to_le16(byte_count);
5620 memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); 5318 memcpy(data_offset, data, sizeof(FILE_BASIC_INFO));
5621 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 5319 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
5622 if (rc) 5320 if (rc)
5623 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); 5321 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc);
5624 5322
@@ -5629,7 +5327,7 @@ CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
5629} 5327}
5630 5328
5631int 5329int
5632CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon, 5330CIFSSMBSetFileDisposition(const int xid, struct cifs_tcon *tcon,
5633 bool delete_file, __u16 fid, __u32 pid_of_opener) 5331 bool delete_file, __u16 fid, __u32 pid_of_opener)
5634{ 5332{
5635 struct smb_com_transaction2_sfi_req *pSMB = NULL; 5333 struct smb_com_transaction2_sfi_req *pSMB = NULL;
@@ -5677,7 +5375,7 @@ CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon,
5677 inc_rfc1001_len(pSMB, byte_count); 5375 inc_rfc1001_len(pSMB, byte_count);
5678 pSMB->ByteCount = cpu_to_le16(byte_count); 5376 pSMB->ByteCount = cpu_to_le16(byte_count);
5679 *data_offset = delete_file ? 1 : 0; 5377 *data_offset = delete_file ? 1 : 0;
5680 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 5378 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
5681 if (rc) 5379 if (rc)
5682 cFYI(1, "Send error in SetFileDisposition = %d", rc); 5380 cFYI(1, "Send error in SetFileDisposition = %d", rc);
5683 5381
@@ -5685,7 +5383,7 @@ CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon,
5685} 5383}
5686 5384
5687int 5385int
5688CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 5386CIFSSMBSetPathInfo(const int xid, struct cifs_tcon *tcon,
5689 const char *fileName, const FILE_BASIC_INFO *data, 5387 const char *fileName, const FILE_BASIC_INFO *data,
5690 const struct nls_table *nls_codepage, int remap) 5388 const struct nls_table *nls_codepage, int remap)
5691{ 5389{
@@ -5707,8 +5405,8 @@ SetTimesRetry:
5707 5405
5708 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5406 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5709 name_len = 5407 name_len =
5710 cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, 5408 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
5711 PATH_MAX, nls_codepage, remap); 5409 PATH_MAX, nls_codepage, remap);
5712 name_len++; /* trailing null */ 5410 name_len++; /* trailing null */
5713 name_len *= 2; 5411 name_len *= 2;
5714 } else { /* BB improve the check for buffer overruns BB */ 5412 } else { /* BB improve the check for buffer overruns BB */
@@ -5769,7 +5467,7 @@ SetTimesRetry:
5769 handling it anyway and NT4 was what we thought it would be needed for 5467 handling it anyway and NT4 was what we thought it would be needed for
5770 Do not delete it until we prove whether needed for Win9x though */ 5468 Do not delete it until we prove whether needed for Win9x though */
5771int 5469int
5772CIFSSMBSetAttrLegacy(unsigned int xid, struct cifs_tcon *tcon, char *fileName, 5470CIFSSMBSetAttrLegacy(int xid, struct cifs_tcon *tcon, char *fileName,
5773 __u16 dos_attrs, const struct nls_table *nls_codepage) 5471 __u16 dos_attrs, const struct nls_table *nls_codepage)
5774{ 5472{
5775 SETATTR_REQ *pSMB = NULL; 5473 SETATTR_REQ *pSMB = NULL;
@@ -5788,8 +5486,8 @@ SetAttrLgcyRetry:
5788 5486
5789 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5487 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5790 name_len = 5488 name_len =
5791 ConvertToUTF16((__le16 *) pSMB->fileName, fileName, 5489 ConvertToUCS((__le16 *) pSMB->fileName, fileName,
5792 PATH_MAX, nls_codepage); 5490 PATH_MAX, nls_codepage);
5793 name_len++; /* trailing null */ 5491 name_len++; /* trailing null */
5794 name_len *= 2; 5492 name_len *= 2;
5795 } else { /* BB improve the check for buffer overruns BB */ 5493 } else { /* BB improve the check for buffer overruns BB */
@@ -5857,12 +5555,12 @@ cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset,
5857} 5555}
5858 5556
5859int 5557int
5860CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 5558CIFSSMBUnixSetFileInfo(const int xid, struct cifs_tcon *tcon,
5861 const struct cifs_unix_set_info_args *args, 5559 const struct cifs_unix_set_info_args *args,
5862 u16 fid, u32 pid_of_opener) 5560 u16 fid, u32 pid_of_opener)
5863{ 5561{
5864 struct smb_com_transaction2_sfi_req *pSMB = NULL; 5562 struct smb_com_transaction2_sfi_req *pSMB = NULL;
5865 char *data_offset; 5563 FILE_UNIX_BASIC_INFO *data_offset;
5866 int rc = 0; 5564 int rc = 0;
5867 u16 params, param_offset, offset, byte_count, count; 5565 u16 params, param_offset, offset, byte_count, count;
5868 5566
@@ -5884,9 +5582,8 @@ CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
5884 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 5582 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
5885 offset = param_offset + params; 5583 offset = param_offset + params;
5886 5584
5887 data_offset = (char *)pSMB + 5585 data_offset = (FILE_UNIX_BASIC_INFO *)
5888 offsetof(struct smb_hdr, Protocol) + offset; 5586 ((char *)(&pSMB->hdr.Protocol) + offset);
5889
5890 count = sizeof(FILE_UNIX_BASIC_INFO); 5587 count = sizeof(FILE_UNIX_BASIC_INFO);
5891 5588
5892 pSMB->MaxParameterCount = cpu_to_le16(2); 5589 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -5908,9 +5605,9 @@ CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
5908 inc_rfc1001_len(pSMB, byte_count); 5605 inc_rfc1001_len(pSMB, byte_count);
5909 pSMB->ByteCount = cpu_to_le16(byte_count); 5606 pSMB->ByteCount = cpu_to_le16(byte_count);
5910 5607
5911 cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO *)data_offset, args); 5608 cifs_fill_unix_set_info(data_offset, args);
5912 5609
5913 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) pSMB, 0); 5610 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
5914 if (rc) 5611 if (rc)
5915 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); 5612 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc);
5916 5613
@@ -5921,8 +5618,7 @@ CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
5921} 5618}
5922 5619
5923int 5620int
5924CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 5621CIFSSMBUnixSetPathInfo(const int xid, struct cifs_tcon *tcon, char *fileName,
5925 const char *file_name,
5926 const struct cifs_unix_set_info_args *args, 5622 const struct cifs_unix_set_info_args *args,
5927 const struct nls_table *nls_codepage, int remap) 5623 const struct nls_table *nls_codepage, int remap)
5928{ 5624{
@@ -5943,14 +5639,14 @@ setPermsRetry:
5943 5639
5944 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5640 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5945 name_len = 5641 name_len =
5946 cifsConvertToUTF16((__le16 *) pSMB->FileName, file_name, 5642 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
5947 PATH_MAX, nls_codepage, remap); 5643 PATH_MAX, nls_codepage, remap);
5948 name_len++; /* trailing null */ 5644 name_len++; /* trailing null */
5949 name_len *= 2; 5645 name_len *= 2;
5950 } else { /* BB improve the check for buffer overruns BB */ 5646 } else { /* BB improve the check for buffer overruns BB */
5951 name_len = strnlen(file_name, PATH_MAX); 5647 name_len = strnlen(fileName, PATH_MAX);
5952 name_len++; /* trailing null */ 5648 name_len++; /* trailing null */
5953 strncpy(pSMB->FileName, file_name, name_len); 5649 strncpy(pSMB->FileName, fileName, name_len);
5954 } 5650 }
5955 5651
5956 params = 6 + name_len; 5652 params = 6 + name_len;
@@ -6009,7 +5705,7 @@ setPermsRetry:
6009 * the data isn't copied to it, but the length is returned. 5705 * the data isn't copied to it, but the length is returned.
6010 */ 5706 */
6011ssize_t 5707ssize_t
6012CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, 5708CIFSSMBQAllEAs(const int xid, struct cifs_tcon *tcon,
6013 const unsigned char *searchName, const unsigned char *ea_name, 5709 const unsigned char *searchName, const unsigned char *ea_name,
6014 char *EAData, size_t buf_size, 5710 char *EAData, size_t buf_size,
6015 const struct nls_table *nls_codepage, int remap) 5711 const struct nls_table *nls_codepage, int remap)
@@ -6036,8 +5732,8 @@ QAllEAsRetry:
6036 5732
6037 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5733 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
6038 list_len = 5734 list_len =
6039 cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName, 5735 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
6040 PATH_MAX, nls_codepage, remap); 5736 PATH_MAX, nls_codepage, remap);
6041 list_len++; /* trailing null */ 5737 list_len++; /* trailing null */
6042 list_len *= 2; 5738 list_len *= 2;
6043 } else { /* BB improve the check for buffer overruns BB */ 5739 } else { /* BB improve the check for buffer overruns BB */
@@ -6144,7 +5840,7 @@ QAllEAsRetry:
6144 5840
6145 if (ea_name) { 5841 if (ea_name) {
6146 if (ea_name_len == name_len && 5842 if (ea_name_len == name_len &&
6147 memcmp(ea_name, temp_ptr, name_len) == 0) { 5843 strncmp(ea_name, temp_ptr, name_len) == 0) {
6148 temp_ptr += name_len + 1; 5844 temp_ptr += name_len + 1;
6149 rc = value_len; 5845 rc = value_len;
6150 if (buf_size == 0) 5846 if (buf_size == 0)
@@ -6192,8 +5888,8 @@ QAllEAsOut:
6192} 5888}
6193 5889
6194int 5890int
6195CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, 5891CIFSSMBSetEA(const int xid, struct cifs_tcon *tcon, const char *fileName,
6196 const char *fileName, const char *ea_name, const void *ea_value, 5892 const char *ea_name, const void *ea_value,
6197 const __u16 ea_value_len, const struct nls_table *nls_codepage, 5893 const __u16 ea_value_len, const struct nls_table *nls_codepage,
6198 int remap) 5894 int remap)
6199{ 5895{
@@ -6214,8 +5910,8 @@ SetEARetry:
6214 5910
6215 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5911 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
6216 name_len = 5912 name_len =
6217 cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName, 5913 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
6218 PATH_MAX, nls_codepage, remap); 5914 PATH_MAX, nls_codepage, remap);
6219 name_len++; /* trailing null */ 5915 name_len++; /* trailing null */
6220 name_len *= 2; 5916 name_len *= 2;
6221 } else { /* BB improve the check for buffer overruns BB */ 5917 } else { /* BB improve the check for buffer overruns BB */
@@ -6319,7 +6015,7 @@ SetEARetry:
6319 * incompatible for network fs clients, we could instead simply 6015 * incompatible for network fs clients, we could instead simply
6320 * expose this config flag by adding a future cifs (and smb2) notify ioctl. 6016 * expose this config flag by adding a future cifs (and smb2) notify ioctl.
6321 */ 6017 */
6322int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon, 6018int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon,
6323 const int notify_subdirs, const __u16 netfid, 6019 const int notify_subdirs, const __u16 netfid,
6324 __u32 filter, struct file *pfile, int multishot, 6020 __u32 filter, struct file *pfile, int multishot,
6325 const struct nls_table *nls_codepage) 6021 const struct nls_table *nls_codepage)
@@ -6339,7 +6035,12 @@ int CIFSSMBNotify(const unsigned int xid, struct cifs_tcon *tcon,
6339 pSMB->TotalParameterCount = 0 ; 6035 pSMB->TotalParameterCount = 0 ;
6340 pSMB->TotalDataCount = 0; 6036 pSMB->TotalDataCount = 0;
6341 pSMB->MaxParameterCount = cpu_to_le32(2); 6037 pSMB->MaxParameterCount = cpu_to_le32(2);
6342 pSMB->MaxDataCount = cpu_to_le32(CIFSMaxBufSize & 0xFFFFFF00); 6038 /* BB find exact data count max from sess structure BB */
6039 pSMB->MaxDataCount = 0; /* same in little endian or be */
6040/* BB VERIFY verify which is correct for above BB */
6041 pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
6042 MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
6043
6343 pSMB->MaxSetupCount = 4; 6044 pSMB->MaxSetupCount = 4;
6344 pSMB->Reserved = 0; 6045 pSMB->Reserved = 0;
6345 pSMB->ParameterOffset = 0; 6046 pSMB->ParameterOffset = 0;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 17c3643e595..28bba5791d9 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * fs/cifs/connect.c 2 * fs/cifs/connect.c
3 * 3 *
4 * Copyright (C) International Business Machines Corp., 2002,2011 4 * Copyright (C) International Business Machines Corp., 2002,2009
5 * Author(s): Steve French (sfrench@us.ibm.com) 5 * Author(s): Steve French (sfrench@us.ibm.com)
6 * 6 *
7 * This library is free software; you can redistribute it and/or modify 7 * This library is free software; you can redistribute it and/or modify
@@ -37,11 +37,7 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38#include <asm/processor.h> 38#include <asm/processor.h>
39#include <linux/inet.h> 39#include <linux/inet.h>
40#include <linux/module.h>
41#include <keys/user-type.h>
42#include <net/ipv6.h> 40#include <net/ipv6.h>
43#include <linux/parser.h>
44
45#include "cifspdu.h" 41#include "cifspdu.h"
46#include "cifsglob.h" 42#include "cifsglob.h"
47#include "cifsproto.h" 43#include "cifsproto.h"
@@ -56,230 +52,15 @@
56#define CIFS_PORT 445 52#define CIFS_PORT 445
57#define RFC1001_PORT 139 53#define RFC1001_PORT 139
58 54
55/* SMB echo "timeout" -- FIXME: tunable? */
56#define SMB_ECHO_INTERVAL (60 * HZ)
57
59extern mempool_t *cifs_req_poolp; 58extern mempool_t *cifs_req_poolp;
60 59
61/* FIXME: should these be tunable? */ 60/* FIXME: should these be tunable? */
62#define TLINK_ERROR_EXPIRE (1 * HZ) 61#define TLINK_ERROR_EXPIRE (1 * HZ)
63#define TLINK_IDLE_EXPIRE (600 * HZ) 62#define TLINK_IDLE_EXPIRE (600 * HZ)
64 63
65enum {
66
67 /* Mount options that take no arguments */
68 Opt_user_xattr, Opt_nouser_xattr,
69 Opt_forceuid, Opt_noforceuid,
70 Opt_forcegid, Opt_noforcegid,
71 Opt_noblocksend, Opt_noautotune,
72 Opt_hard, Opt_soft, Opt_perm, Opt_noperm,
73 Opt_mapchars, Opt_nomapchars, Opt_sfu,
74 Opt_nosfu, Opt_nodfs, Opt_posixpaths,
75 Opt_noposixpaths, Opt_nounix,
76 Opt_nocase,
77 Opt_brl, Opt_nobrl,
78 Opt_forcemandatorylock, Opt_setuids,
79 Opt_nosetuids, Opt_dynperm, Opt_nodynperm,
80 Opt_nohard, Opt_nosoft,
81 Opt_nointr, Opt_intr,
82 Opt_nostrictsync, Opt_strictsync,
83 Opt_serverino, Opt_noserverino,
84 Opt_rwpidforward, Opt_cifsacl, Opt_nocifsacl,
85 Opt_acl, Opt_noacl, Opt_locallease,
86 Opt_sign, Opt_seal, Opt_noac,
87 Opt_fsc, Opt_mfsymlinks,
88 Opt_multiuser, Opt_sloppy,
89
90 /* Mount options which take numeric value */
91 Opt_backupuid, Opt_backupgid, Opt_uid,
92 Opt_cruid, Opt_gid, Opt_file_mode,
93 Opt_dirmode, Opt_port,
94 Opt_rsize, Opt_wsize, Opt_actimeo,
95
96 /* Mount options which take string value */
97 Opt_user, Opt_pass, Opt_ip,
98 Opt_unc, Opt_domain,
99 Opt_srcaddr, Opt_prefixpath,
100 Opt_iocharset, Opt_sockopt,
101 Opt_netbiosname, Opt_servern,
102 Opt_ver, Opt_vers, Opt_sec, Opt_cache,
103
104 /* Mount options to be ignored */
105 Opt_ignore,
106
107 /* Options which could be blank */
108 Opt_blank_pass,
109 Opt_blank_user,
110 Opt_blank_ip,
111
112 Opt_err
113};
114
115static const match_table_t cifs_mount_option_tokens = {
116
117 { Opt_user_xattr, "user_xattr" },
118 { Opt_nouser_xattr, "nouser_xattr" },
119 { Opt_forceuid, "forceuid" },
120 { Opt_noforceuid, "noforceuid" },
121 { Opt_forcegid, "forcegid" },
122 { Opt_noforcegid, "noforcegid" },
123 { Opt_noblocksend, "noblocksend" },
124 { Opt_noautotune, "noautotune" },
125 { Opt_hard, "hard" },
126 { Opt_soft, "soft" },
127 { Opt_perm, "perm" },
128 { Opt_noperm, "noperm" },
129 { Opt_mapchars, "mapchars" },
130 { Opt_nomapchars, "nomapchars" },
131 { Opt_sfu, "sfu" },
132 { Opt_nosfu, "nosfu" },
133 { Opt_nodfs, "nodfs" },
134 { Opt_posixpaths, "posixpaths" },
135 { Opt_noposixpaths, "noposixpaths" },
136 { Opt_nounix, "nounix" },
137 { Opt_nounix, "nolinux" },
138 { Opt_nocase, "nocase" },
139 { Opt_nocase, "ignorecase" },
140 { Opt_brl, "brl" },
141 { Opt_nobrl, "nobrl" },
142 { Opt_nobrl, "nolock" },
143 { Opt_forcemandatorylock, "forcemandatorylock" },
144 { Opt_forcemandatorylock, "forcemand" },
145 { Opt_setuids, "setuids" },
146 { Opt_nosetuids, "nosetuids" },
147 { Opt_dynperm, "dynperm" },
148 { Opt_nodynperm, "nodynperm" },
149 { Opt_nohard, "nohard" },
150 { Opt_nosoft, "nosoft" },
151 { Opt_nointr, "nointr" },
152 { Opt_intr, "intr" },
153 { Opt_nostrictsync, "nostrictsync" },
154 { Opt_strictsync, "strictsync" },
155 { Opt_serverino, "serverino" },
156 { Opt_noserverino, "noserverino" },
157 { Opt_rwpidforward, "rwpidforward" },
158 { Opt_cifsacl, "cifsacl" },
159 { Opt_nocifsacl, "nocifsacl" },
160 { Opt_acl, "acl" },
161 { Opt_noacl, "noacl" },
162 { Opt_locallease, "locallease" },
163 { Opt_sign, "sign" },
164 { Opt_seal, "seal" },
165 { Opt_noac, "noac" },
166 { Opt_fsc, "fsc" },
167 { Opt_mfsymlinks, "mfsymlinks" },
168 { Opt_multiuser, "multiuser" },
169 { Opt_sloppy, "sloppy" },
170
171 { Opt_backupuid, "backupuid=%s" },
172 { Opt_backupgid, "backupgid=%s" },
173 { Opt_uid, "uid=%s" },
174 { Opt_cruid, "cruid=%s" },
175 { Opt_gid, "gid=%s" },
176 { Opt_file_mode, "file_mode=%s" },
177 { Opt_dirmode, "dirmode=%s" },
178 { Opt_dirmode, "dir_mode=%s" },
179 { Opt_port, "port=%s" },
180 { Opt_rsize, "rsize=%s" },
181 { Opt_wsize, "wsize=%s" },
182 { Opt_actimeo, "actimeo=%s" },
183
184 { Opt_blank_user, "user=" },
185 { Opt_blank_user, "username=" },
186 { Opt_user, "user=%s" },
187 { Opt_user, "username=%s" },
188 { Opt_blank_pass, "pass=" },
189 { Opt_blank_pass, "password=" },
190 { Opt_pass, "pass=%s" },
191 { Opt_pass, "password=%s" },
192 { Opt_blank_ip, "ip=" },
193 { Opt_blank_ip, "addr=" },
194 { Opt_ip, "ip=%s" },
195 { Opt_ip, "addr=%s" },
196 { Opt_unc, "unc=%s" },
197 { Opt_unc, "target=%s" },
198 { Opt_unc, "path=%s" },
199 { Opt_domain, "dom=%s" },
200 { Opt_domain, "domain=%s" },
201 { Opt_domain, "workgroup=%s" },
202 { Opt_srcaddr, "srcaddr=%s" },
203 { Opt_prefixpath, "prefixpath=%s" },
204 { Opt_iocharset, "iocharset=%s" },
205 { Opt_sockopt, "sockopt=%s" },
206 { Opt_netbiosname, "netbiosname=%s" },
207 { Opt_servern, "servern=%s" },
208 { Opt_ver, "ver=%s" },
209 { Opt_vers, "vers=%s" },
210 { Opt_sec, "sec=%s" },
211 { Opt_cache, "cache=%s" },
212
213 { Opt_ignore, "cred" },
214 { Opt_ignore, "credentials" },
215 { Opt_ignore, "cred=%s" },
216 { Opt_ignore, "credentials=%s" },
217 { Opt_ignore, "guest" },
218 { Opt_ignore, "rw" },
219 { Opt_ignore, "ro" },
220 { Opt_ignore, "suid" },
221 { Opt_ignore, "nosuid" },
222 { Opt_ignore, "exec" },
223 { Opt_ignore, "noexec" },
224 { Opt_ignore, "nodev" },
225 { Opt_ignore, "noauto" },
226 { Opt_ignore, "dev" },
227 { Opt_ignore, "mand" },
228 { Opt_ignore, "nomand" },
229 { Opt_ignore, "_netdev" },
230
231 { Opt_err, NULL }
232};
233
234enum {
235 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
236 Opt_sec_ntlmsspi, Opt_sec_ntlmssp,
237 Opt_ntlm, Opt_sec_ntlmi, Opt_sec_ntlmv2,
238 Opt_sec_ntlmv2i, Opt_sec_lanman,
239 Opt_sec_none,
240
241 Opt_sec_err
242};
243
244static const match_table_t cifs_secflavor_tokens = {
245 { Opt_sec_krb5, "krb5" },
246 { Opt_sec_krb5i, "krb5i" },
247 { Opt_sec_krb5p, "krb5p" },
248 { Opt_sec_ntlmsspi, "ntlmsspi" },
249 { Opt_sec_ntlmssp, "ntlmssp" },
250 { Opt_ntlm, "ntlm" },
251 { Opt_sec_ntlmi, "ntlmi" },
252 { Opt_sec_ntlmv2, "nontlm" },
253 { Opt_sec_ntlmv2, "ntlmv2" },
254 { Opt_sec_ntlmv2i, "ntlmv2i" },
255 { Opt_sec_lanman, "lanman" },
256 { Opt_sec_none, "none" },
257
258 { Opt_sec_err, NULL }
259};
260
261/* cache flavors */
262enum {
263 Opt_cache_loose,
264 Opt_cache_strict,
265 Opt_cache_none,
266 Opt_cache_err
267};
268
269static const match_table_t cifs_cacheflavor_tokens = {
270 { Opt_cache_loose, "loose" },
271 { Opt_cache_strict, "strict" },
272 { Opt_cache_none, "none" },
273 { Opt_cache_err, NULL }
274};
275
276static const match_table_t cifs_smb_version_tokens = {
277 { Smb_1, SMB1_VERSION_STRING },
278 { Smb_20, SMB20_VERSION_STRING},
279 { Smb_21, SMB21_VERSION_STRING },
280 { Smb_30, SMB30_VERSION_STRING },
281};
282
283static int ip_connect(struct TCP_Server_Info *server); 64static int ip_connect(struct TCP_Server_Info *server);
284static int generic_ip_connect(struct TCP_Server_Info *server); 65static int generic_ip_connect(struct TCP_Server_Info *server);
285static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink); 66static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
@@ -295,7 +76,7 @@ static int cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
295 * reconnect tcp session 76 * reconnect tcp session
296 * wake up waiters on reconnection? - (not needed currently) 77 * wake up waiters on reconnection? - (not needed currently)
297 */ 78 */
298int 79static int
299cifs_reconnect(struct TCP_Server_Info *server) 80cifs_reconnect(struct TCP_Server_Info *server)
300{ 81{
301 int rc = 0; 82 int rc = 0;
@@ -315,9 +96,6 @@ cifs_reconnect(struct TCP_Server_Info *server)
315 server->tcpStatus = CifsNeedReconnect; 96 server->tcpStatus = CifsNeedReconnect;
316 spin_unlock(&GlobalMid_Lock); 97 spin_unlock(&GlobalMid_Lock);
317 server->maxBuf = 0; 98 server->maxBuf = 0;
318#ifdef CONFIG_CIFS_SMB2
319 server->max_read = 0;
320#endif
321 99
322 cFYI(1, "Reconnecting tcp session"); 100 cFYI(1, "Reconnecting tcp session");
323 101
@@ -363,8 +141,8 @@ cifs_reconnect(struct TCP_Server_Info *server)
363 spin_lock(&GlobalMid_Lock); 141 spin_lock(&GlobalMid_Lock);
364 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { 142 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
365 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 143 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
366 if (mid_entry->mid_state == MID_REQUEST_SUBMITTED) 144 if (mid_entry->midState == MID_REQUEST_SUBMITTED)
367 mid_entry->mid_state = MID_RETRY_NEEDED; 145 mid_entry->midState = MID_RETRY_NEEDED;
368 list_move(&mid_entry->qhead, &retry_list); 146 list_move(&mid_entry->qhead, &retry_list);
369 } 147 }
370 spin_unlock(&GlobalMid_Lock); 148 spin_unlock(&GlobalMid_Lock);
@@ -396,6 +174,126 @@ cifs_reconnect(struct TCP_Server_Info *server)
396 return rc; 174 return rc;
397} 175}
398 176
177/*
178 return codes:
179 0 not a transact2, or all data present
180 >0 transact2 with that much data missing
181 -EINVAL = invalid transact2
182
183 */
184static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize)
185{
186 struct smb_t2_rsp *pSMBt;
187 int remaining;
188 __u16 total_data_size, data_in_this_rsp;
189
190 if (pSMB->Command != SMB_COM_TRANSACTION2)
191 return 0;
192
193 /* check for plausible wct, bcc and t2 data and parm sizes */
194 /* check for parm and data offset going beyond end of smb */
195 if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */
196 cFYI(1, "invalid transact2 word count");
197 return -EINVAL;
198 }
199
200 pSMBt = (struct smb_t2_rsp *)pSMB;
201
202 total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
203 data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
204
205 if (total_data_size == data_in_this_rsp)
206 return 0;
207 else if (total_data_size < data_in_this_rsp) {
208 cFYI(1, "total data %d smaller than data in frame %d",
209 total_data_size, data_in_this_rsp);
210 return -EINVAL;
211 }
212
213 remaining = total_data_size - data_in_this_rsp;
214
215 cFYI(1, "missing %d bytes from transact2, check next response",
216 remaining);
217 if (total_data_size > maxBufSize) {
218 cERROR(1, "TotalDataSize %d is over maximum buffer %d",
219 total_data_size, maxBufSize);
220 return -EINVAL;
221 }
222 return remaining;
223}
224
225static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
226{
227 struct smb_t2_rsp *pSMB2 = (struct smb_t2_rsp *)psecond;
228 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)pTargetSMB;
229 char *data_area_of_target;
230 char *data_area_of_buf2;
231 int remaining;
232 unsigned int byte_count, total_in_buf;
233 __u16 total_data_size, total_in_buf2;
234
235 total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
236
237 if (total_data_size !=
238 get_unaligned_le16(&pSMB2->t2_rsp.TotalDataCount))
239 cFYI(1, "total data size of primary and secondary t2 differ");
240
241 total_in_buf = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
242
243 remaining = total_data_size - total_in_buf;
244
245 if (remaining < 0)
246 return -EPROTO;
247
248 if (remaining == 0) /* nothing to do, ignore */
249 return 0;
250
251 total_in_buf2 = get_unaligned_le16(&pSMB2->t2_rsp.DataCount);
252 if (remaining < total_in_buf2) {
253 cFYI(1, "transact2 2nd response contains too much data");
254 }
255
256 /* find end of first SMB data area */
257 data_area_of_target = (char *)&pSMBt->hdr.Protocol +
258 get_unaligned_le16(&pSMBt->t2_rsp.DataOffset);
259 /* validate target area */
260
261 data_area_of_buf2 = (char *)&pSMB2->hdr.Protocol +
262 get_unaligned_le16(&pSMB2->t2_rsp.DataOffset);
263
264 data_area_of_target += total_in_buf;
265
266 /* copy second buffer into end of first buffer */
267 total_in_buf += total_in_buf2;
268 /* is the result too big for the field? */
269 if (total_in_buf > USHRT_MAX)
270 return -EPROTO;
271 put_unaligned_le16(total_in_buf, &pSMBt->t2_rsp.DataCount);
272
273 /* fix up the BCC */
274 byte_count = get_bcc(pTargetSMB);
275 byte_count += total_in_buf2;
276 /* is the result too big for the field? */
277 if (byte_count > USHRT_MAX)
278 return -EPROTO;
279 put_bcc(byte_count, pTargetSMB);
280
281 byte_count = be32_to_cpu(pTargetSMB->smb_buf_length);
282 byte_count += total_in_buf2;
283 /* don't allow buffer to overflow */
284 if (byte_count > CIFSMaxBufSize)
285 return -ENOBUFS;
286 pTargetSMB->smb_buf_length = cpu_to_be32(byte_count);
287
288 memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
289
290 if (remaining == total_in_buf2) {
291 cFYI(1, "found the last secondary response");
292 return 0; /* we are done */
293 } else /* more responses to go */
294 return 1;
295}
296
399static void 297static void
400cifs_echo_request(struct work_struct *work) 298cifs_echo_request(struct work_struct *work)
401{ 299{
@@ -404,44 +302,45 @@ cifs_echo_request(struct work_struct *work)
404 struct TCP_Server_Info, echo.work); 302 struct TCP_Server_Info, echo.work);
405 303
406 /* 304 /*
407 * We cannot send an echo if it is disabled or until the 305 * We cannot send an echo until the NEGOTIATE_PROTOCOL request is
408 * NEGOTIATE_PROTOCOL request is done, which is indicated by 306 * done, which is indicated by maxBuf != 0. Also, no need to ping if
409 * server->ops->need_neg() == true. Also, no need to ping if 307 * we got a response recently
410 * we got a response recently.
411 */ 308 */
412 if (!server->ops->need_neg || server->ops->need_neg(server) || 309 if (server->maxBuf == 0 ||
413 (server->ops->can_echo && !server->ops->can_echo(server)) ||
414 time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ)) 310 time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ))
415 goto requeue_echo; 311 goto requeue_echo;
416 312
417 rc = server->ops->echo ? server->ops->echo(server) : -ENOSYS; 313 rc = CIFSSMBEcho(server);
418 if (rc) 314 if (rc)
419 cFYI(1, "Unable to send echo request to server: %s", 315 cFYI(1, "Unable to send echo request to server: %s",
420 server->hostname); 316 server->hostname);
421 317
422requeue_echo: 318requeue_echo:
423 queue_delayed_work(cifsiod_wq, &server->echo, SMB_ECHO_INTERVAL); 319 queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL);
424} 320}
425 321
426static bool 322static bool
427allocate_buffers(struct TCP_Server_Info *server) 323allocate_buffers(char **bigbuf, char **smallbuf, unsigned int size,
324 bool is_large_buf)
428{ 325{
429 if (!server->bigbuf) { 326 char *bbuf = *bigbuf, *sbuf = *smallbuf;
430 server->bigbuf = (char *)cifs_buf_get(); 327
431 if (!server->bigbuf) { 328 if (bbuf == NULL) {
329 bbuf = (char *)cifs_buf_get();
330 if (!bbuf) {
432 cERROR(1, "No memory for large SMB response"); 331 cERROR(1, "No memory for large SMB response");
433 msleep(3000); 332 msleep(3000);
434 /* retry will check if exiting */ 333 /* retry will check if exiting */
435 return false; 334 return false;
436 } 335 }
437 } else if (server->large_buf) { 336 } else if (is_large_buf) {
438 /* we are reusing a dirty large buf, clear its start */ 337 /* we are reusing a dirty large buf, clear its start */
439 memset(server->bigbuf, 0, HEADER_SIZE(server)); 338 memset(bbuf, 0, size);
440 } 339 }
441 340
442 if (!server->smallbuf) { 341 if (sbuf == NULL) {
443 server->smallbuf = (char *)cifs_small_buf_get(); 342 sbuf = (char *)cifs_small_buf_get();
444 if (!server->smallbuf) { 343 if (!sbuf) {
445 cERROR(1, "No memory for SMB response"); 344 cERROR(1, "No memory for SMB response");
446 msleep(1000); 345 msleep(1000);
447 /* retry will check if exiting */ 346 /* retry will check if exiting */
@@ -450,128 +349,36 @@ allocate_buffers(struct TCP_Server_Info *server)
450 /* beginning of smb buffer is cleared in our buf_get */ 349 /* beginning of smb buffer is cleared in our buf_get */
451 } else { 350 } else {
452 /* if existing small buf clear beginning */ 351 /* if existing small buf clear beginning */
453 memset(server->smallbuf, 0, HEADER_SIZE(server)); 352 memset(sbuf, 0, size);
454 }
455
456 return true;
457}
458
459static bool
460server_unresponsive(struct TCP_Server_Info *server)
461{
462 /*
463 * We need to wait 2 echo intervals to make sure we handle such
464 * situations right:
465 * 1s client sends a normal SMB request
466 * 2s client gets a response
467 * 30s echo workqueue job pops, and decides we got a response recently
468 * and don't need to send another
469 * ...
470 * 65s kernel_recvmsg times out, and we see that we haven't gotten
471 * a response in >60s.
472 */
473 if (server->tcpStatus == CifsGood &&
474 time_after(jiffies, server->lstrp + 2 * SMB_ECHO_INTERVAL)) {
475 cERROR(1, "Server %s has not responded in %d seconds. "
476 "Reconnecting...", server->hostname,
477 (2 * SMB_ECHO_INTERVAL) / HZ);
478 cifs_reconnect(server);
479 wake_up(&server->response_q);
480 return true;
481 } 353 }
482 354
483 return false; 355 *bigbuf = bbuf;
484} 356 *smallbuf = sbuf;
485
486/*
487 * kvec_array_init - clone a kvec array, and advance into it
488 * @new: pointer to memory for cloned array
489 * @iov: pointer to original array
490 * @nr_segs: number of members in original array
491 * @bytes: number of bytes to advance into the cloned array
492 *
493 * This function will copy the array provided in iov to a section of memory
494 * and advance the specified number of bytes into the new array. It returns
495 * the number of segments in the new array. "new" must be at least as big as
496 * the original iov array.
497 */
498static unsigned int
499kvec_array_init(struct kvec *new, struct kvec *iov, unsigned int nr_segs,
500 size_t bytes)
501{
502 size_t base = 0;
503 357
504 while (bytes || !iov->iov_len) { 358 return true;
505 int copy = min(bytes, iov->iov_len);
506
507 bytes -= copy;
508 base += copy;
509 if (iov->iov_len == base) {
510 iov++;
511 nr_segs--;
512 base = 0;
513 }
514 }
515 memcpy(new, iov, sizeof(*iov) * nr_segs);
516 new->iov_base += base;
517 new->iov_len -= base;
518 return nr_segs;
519}
520
521static struct kvec *
522get_server_iovec(struct TCP_Server_Info *server, unsigned int nr_segs)
523{
524 struct kvec *new_iov;
525
526 if (server->iov && nr_segs <= server->nr_iov)
527 return server->iov;
528
529 /* not big enough -- allocate a new one and release the old */
530 new_iov = kmalloc(sizeof(*new_iov) * nr_segs, GFP_NOFS);
531 if (new_iov) {
532 kfree(server->iov);
533 server->iov = new_iov;
534 server->nr_iov = nr_segs;
535 }
536 return new_iov;
537} 359}
538 360
539int 361static int
540cifs_readv_from_socket(struct TCP_Server_Info *server, struct kvec *iov_orig, 362read_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg,
541 unsigned int nr_segs, unsigned int to_read) 363 struct kvec *iov, unsigned int to_read,
364 unsigned int *ptotal_read, bool is_header_read)
542{ 365{
543 int length = 0; 366 int length, rc = 0;
544 int total_read; 367 unsigned int total_read;
545 unsigned int segs; 368 char *buf = iov->iov_base;
546 struct msghdr smb_msg;
547 struct kvec *iov;
548
549 iov = get_server_iovec(server, nr_segs);
550 if (!iov)
551 return -ENOMEM;
552
553 smb_msg.msg_control = NULL;
554 smb_msg.msg_controllen = 0;
555
556 for (total_read = 0; to_read; total_read += length, to_read -= length) {
557 try_to_freeze();
558
559 if (server_unresponsive(server)) {
560 total_read = -EAGAIN;
561 break;
562 }
563
564 segs = kvec_array_init(iov, iov_orig, nr_segs, total_read);
565
566 length = kernel_recvmsg(server->ssocket, &smb_msg,
567 iov, segs, to_read, 0);
568 369
370 for (total_read = 0; total_read < to_read; total_read += length) {
371 length = kernel_recvmsg(server->ssocket, smb_msg, iov, 1,
372 to_read - total_read, 0);
569 if (server->tcpStatus == CifsExiting) { 373 if (server->tcpStatus == CifsExiting) {
570 total_read = -ESHUTDOWN; 374 /* then will exit */
375 rc = 2;
571 break; 376 break;
572 } else if (server->tcpStatus == CifsNeedReconnect) { 377 } else if (server->tcpStatus == CifsNeedReconnect) {
573 cifs_reconnect(server); 378 cifs_reconnect(server);
574 total_read = -EAGAIN; 379 /* Reconnect wakes up rspns q */
380 /* Now we will reread sock */
381 rc = 1;
575 break; 382 break;
576 } else if (length == -ERESTARTSYS || 383 } else if (length == -ERESTARTSYS ||
577 length == -EAGAIN || 384 length == -EAGAIN ||
@@ -583,54 +390,56 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct kvec *iov_orig,
583 */ 390 */
584 usleep_range(1000, 2000); 391 usleep_range(1000, 2000);
585 length = 0; 392 length = 0;
586 continue; 393 if (!is_header_read)
394 continue;
395 /* Special handling for header read */
396 if (total_read) {
397 iov->iov_base = (to_read - total_read) +
398 buf;
399 iov->iov_len = to_read - total_read;
400 smb_msg->msg_control = NULL;
401 smb_msg->msg_controllen = 0;
402 rc = 3;
403 } else
404 rc = 1;
405 break;
587 } else if (length <= 0) { 406 } else if (length <= 0) {
588 cFYI(1, "Received no data or error: expecting %d " 407 cERROR(1, "Received no data, expecting %d",
589 "got %d", to_read, length); 408 to_read - total_read);
590 cifs_reconnect(server); 409 cifs_reconnect(server);
591 total_read = -EAGAIN; 410 rc = 1;
592 break; 411 break;
593 } 412 }
594 } 413 }
595 return total_read;
596}
597 414
598int 415 *ptotal_read = total_read;
599cifs_read_from_socket(struct TCP_Server_Info *server, char *buf, 416 return rc;
600 unsigned int to_read)
601{
602 struct kvec iov;
603
604 iov.iov_base = buf;
605 iov.iov_len = to_read;
606
607 return cifs_readv_from_socket(server, &iov, 1, to_read);
608} 417}
609 418
610static bool 419static bool
611is_smb_response(struct TCP_Server_Info *server, unsigned char type) 420check_rfc1002_header(struct TCP_Server_Info *server, char *buf)
612{ 421{
422 char temp = *buf;
423 unsigned int pdu_length = be32_to_cpu(
424 ((struct smb_hdr *)buf)->smb_buf_length);
425
613 /* 426 /*
614 * The first byte big endian of the length field, 427 * The first byte big endian of the length field,
615 * is actually not part of the length but the type 428 * is actually not part of the length but the type
616 * with the most common, zero, as regular data. 429 * with the most common, zero, as regular data.
617 */ 430 */
618 switch (type) { 431 if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) {
619 case RFC1002_SESSION_MESSAGE: 432 return false;
620 /* Regular SMB response */ 433 } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) {
621 return true; 434 cFYI(1, "Good RFC 1002 session rsp");
622 case RFC1002_SESSION_KEEP_ALIVE: 435 return false;
623 cFYI(1, "RFC 1002 session keep alive"); 436 } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
624 break;
625 case RFC1002_POSITIVE_SESSION_RESPONSE:
626 cFYI(1, "RFC 1002 positive session response");
627 break;
628 case RFC1002_NEGATIVE_SESSION_RESPONSE:
629 /* 437 /*
630 * We get this from Windows 98 instead of an error on 438 * We get this from Windows 98 instead of an error on
631 * SMB negprot response. 439 * SMB negprot response.
632 */ 440 */
633 cFYI(1, "RFC 1002 negative session response"); 441 cFYI(1, "Negative RFC1002 Session Response Error 0x%x)",
442 pdu_length);
634 /* give server a second to clean up */ 443 /* give server a second to clean up */
635 msleep(1000); 444 msleep(1000);
636 /* 445 /*
@@ -639,51 +448,87 @@ is_smb_response(struct TCP_Server_Info *server, unsigned char type)
639 * is since we do not begin with RFC1001 session 448 * is since we do not begin with RFC1001 session
640 * initialize frame). 449 * initialize frame).
641 */ 450 */
642 cifs_set_port((struct sockaddr *)&server->dstaddr, CIFS_PORT); 451 cifs_set_port((struct sockaddr *)
452 &server->dstaddr, CIFS_PORT);
643 cifs_reconnect(server); 453 cifs_reconnect(server);
644 wake_up(&server->response_q); 454 wake_up(&server->response_q);
645 break; 455 return false;
646 default: 456 } else if (temp != (char) 0) {
647 cERROR(1, "RFC 1002 unknown response type 0x%x", type); 457 cERROR(1, "Unknown RFC 1002 frame");
458 cifs_dump_mem(" Received Data: ", buf, 4);
648 cifs_reconnect(server); 459 cifs_reconnect(server);
460 return false;
649 } 461 }
650 462
651 return false; 463 /* else we have an SMB response */
464 if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) ||
465 (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) {
466 cERROR(1, "Invalid size SMB length %d pdu_length %d",
467 4, pdu_length+4);
468 cifs_reconnect(server);
469 wake_up(&server->response_q);
470 return false;
471 }
472
473 return true;
652} 474}
653 475
654void 476static struct mid_q_entry *
655dequeue_mid(struct mid_q_entry *mid, bool malformed) 477find_cifs_mid(struct TCP_Server_Info *server, struct smb_hdr *buf,
478 int *length, bool is_large_buf, bool *is_multi_rsp, char **bigbuf)
656{ 479{
657#ifdef CONFIG_CIFS_STATS2 480 struct mid_q_entry *mid = NULL, *tmp_mid, *ret = NULL;
658 mid->when_received = jiffies; 481
659#endif
660 spin_lock(&GlobalMid_Lock); 482 spin_lock(&GlobalMid_Lock);
661 if (!malformed) 483 list_for_each_entry_safe(mid, tmp_mid, &server->pending_mid_q, qhead) {
662 mid->mid_state = MID_RESPONSE_RECEIVED; 484 if (mid->mid != buf->Mid ||
663 else 485 mid->midState != MID_REQUEST_SUBMITTED ||
664 mid->mid_state = MID_RESPONSE_MALFORMED; 486 mid->command != buf->Command)
665 list_del_init(&mid->qhead); 487 continue;
666 spin_unlock(&GlobalMid_Lock);
667}
668 488
669static void 489 if (*length == 0 && check2ndT2(buf, server->maxBuf) > 0) {
670handle_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server, 490 /* We have a multipart transact2 resp */
671 char *buf, int malformed) 491 *is_multi_rsp = true;
672{ 492 if (mid->resp_buf) {
673 if (server->ops->check_trans2 && 493 /* merge response - fix up 1st*/
674 server->ops->check_trans2(mid, server, buf, malformed)) 494 *length = coalesce_t2(buf, mid->resp_buf);
675 return; 495 if (*length > 0) {
676 mid->resp_buf = buf; 496 *length = 0;
677 mid->large_buf = server->large_buf; 497 mid->multiRsp = true;
678 /* Was previous buf put in mpx struct for multi-rsp? */ 498 break;
679 if (!mid->multiRsp) { 499 }
680 /* smb buffer will be freed by user thread */ 500 /* All parts received or packet is malformed. */
681 if (server->large_buf) 501 mid->multiEnd = true;
682 server->bigbuf = NULL; 502 goto multi_t2_fnd;
503 }
504 if (!is_large_buf) {
505 /*FIXME: switch to already allocated largebuf?*/
506 cERROR(1, "1st trans2 resp needs bigbuf");
507 } else {
508 /* Have first buffer */
509 mid->resp_buf = buf;
510 mid->largeBuf = true;
511 *bigbuf = NULL;
512 }
513 break;
514 }
515 mid->resp_buf = buf;
516 mid->largeBuf = is_large_buf;
517multi_t2_fnd:
518 if (*length == 0)
519 mid->midState = MID_RESPONSE_RECEIVED;
683 else 520 else
684 server->smallbuf = NULL; 521 mid->midState = MID_RESPONSE_MALFORMED;
522#ifdef CONFIG_CIFS_STATS2
523 mid->when_received = jiffies;
524#endif
525 list_del_init(&mid->qhead);
526 ret = mid;
527 break;
685 } 528 }
686 dequeue_mid(mid, malformed); 529 spin_unlock(&GlobalMid_Lock);
530
531 return ret;
687} 532}
688 533
689static void clean_demultiplex_info(struct TCP_Server_Info *server) 534static void clean_demultiplex_info(struct TCP_Server_Info *server)
@@ -700,11 +545,19 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
700 spin_unlock(&GlobalMid_Lock); 545 spin_unlock(&GlobalMid_Lock);
701 wake_up_all(&server->response_q); 546 wake_up_all(&server->response_q);
702 547
703 /* check if we have blocked requests that need to free */ 548 /*
704 spin_lock(&server->req_lock); 549 * Check if we have blocked requests that need to free. Note that
705 if (server->credits <= 0) 550 * cifs_max_pending is normally 50, but can be set at module install
706 server->credits = 1; 551 * time to as little as two.
707 spin_unlock(&server->req_lock); 552 */
553 spin_lock(&GlobalMid_Lock);
554 if (atomic_read(&server->inFlight) >= cifs_max_pending)
555 atomic_set(&server->inFlight, cifs_max_pending - 1);
556 /*
557 * We do not want to set the max_pending too low or we could end up
558 * with the counter going negative.
559 */
560 spin_unlock(&GlobalMid_Lock);
708 /* 561 /*
709 * Although there should not be any requests blocked on this queue it 562 * Although there should not be any requests blocked on this queue it
710 * can not hurt to be paranoid and try to wake up requests that may 563 * can not hurt to be paranoid and try to wake up requests that may
@@ -730,8 +583,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
730 spin_lock(&GlobalMid_Lock); 583 spin_lock(&GlobalMid_Lock);
731 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) { 584 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
732 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 585 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
733 cFYI(1, "Clearing mid 0x%llx", mid_entry->mid); 586 cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
734 mid_entry->mid_state = MID_SHUTDOWN; 587 mid_entry->midState = MID_SHUTDOWN;
735 list_move(&mid_entry->qhead, &dispose_list); 588 list_move(&mid_entry->qhead, &dispose_list);
736 } 589 }
737 spin_unlock(&GlobalMid_Lock); 590 spin_unlock(&GlobalMid_Lock);
@@ -739,7 +592,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
739 /* now walk dispose list and issue callbacks */ 592 /* now walk dispose list and issue callbacks */
740 list_for_each_safe(tmp, tmp2, &dispose_list) { 593 list_for_each_safe(tmp, tmp2, &dispose_list) {
741 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 594 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
742 cFYI(1, "Callback mid 0x%llx", mid_entry->mid); 595 cFYI(1, "Callback mid 0x%x", mid_entry->mid);
743 list_del_init(&mid_entry->qhead); 596 list_del_init(&mid_entry->qhead);
744 mid_entry->callback(mid_entry); 597 mid_entry->callback(mid_entry);
745 } 598 }
@@ -765,7 +618,6 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
765 } 618 }
766 619
767 kfree(server->hostname); 620 kfree(server->hostname);
768 kfree(server->iov);
769 kfree(server); 621 kfree(server);
770 622
771 length = atomic_dec_return(&tcpSesAllocCount); 623 length = atomic_dec_return(&tcpSesAllocCount);
@@ -775,71 +627,20 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
775} 627}
776 628
777static int 629static int
778standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
779{
780 int length;
781 char *buf = server->smallbuf;
782 unsigned int pdu_length = get_rfc1002_length(buf);
783
784 /* make sure this will fit in a large buffer */
785 if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server) - 4) {
786 cERROR(1, "SMB response too long (%u bytes)",
787 pdu_length);
788 cifs_reconnect(server);
789 wake_up(&server->response_q);
790 return -EAGAIN;
791 }
792
793 /* switch to large buffer if too big for a small one */
794 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) {
795 server->large_buf = true;
796 memcpy(server->bigbuf, buf, server->total_read);
797 buf = server->bigbuf;
798 }
799
800 /* now read the rest */
801 length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
802 pdu_length - HEADER_SIZE(server) + 1 + 4);
803 if (length < 0)
804 return length;
805 server->total_read += length;
806
807 dump_smb(buf, server->total_read);
808
809 /*
810 * We know that we received enough to get to the MID as we
811 * checked the pdu_length earlier. Now check to see
812 * if the rest of the header is OK. We borrow the length
813 * var for the rest of the loop to avoid a new stack var.
814 *
815 * 48 bytes is enough to display the header and a little bit
816 * into the payload for debugging purposes.
817 */
818 length = server->ops->check_message(buf, server->total_read);
819 if (length != 0)
820 cifs_dump_mem("Bad SMB: ", buf,
821 min_t(unsigned int, server->total_read, 48));
822
823 if (server->ops->is_status_pending &&
824 server->ops->is_status_pending(buf, server, length))
825 return -1;
826
827 if (!mid)
828 return length;
829
830 handle_mid(mid, server, buf, length);
831 return 0;
832}
833
834static int
835cifs_demultiplex_thread(void *p) 630cifs_demultiplex_thread(void *p)
836{ 631{
837 int length; 632 int length;
838 struct TCP_Server_Info *server = p; 633 struct TCP_Server_Info *server = p;
839 unsigned int pdu_length; 634 unsigned int pdu_length, total_read;
840 char *buf = NULL; 635 char *buf = NULL, *bigbuf = NULL, *smallbuf = NULL;
636 struct smb_hdr *smb_buffer = NULL;
637 struct msghdr smb_msg;
638 struct kvec iov;
841 struct task_struct *task_to_wake = NULL; 639 struct task_struct *task_to_wake = NULL;
842 struct mid_q_entry *mid_entry; 640 struct mid_q_entry *mid_entry;
641 bool isLargeBuf = false;
642 bool isMultiRsp = false;
643 int rc;
843 644
844 current->flags |= PF_MEMALLOC; 645 current->flags |= PF_MEMALLOC;
845 cFYI(1, "Demultiplex PID: %d", task_pid_nr(current)); 646 cFYI(1, "Demultiplex PID: %d", task_pid_nr(current));
@@ -854,70 +655,117 @@ cifs_demultiplex_thread(void *p)
854 if (try_to_freeze()) 655 if (try_to_freeze())
855 continue; 656 continue;
856 657
857 if (!allocate_buffers(server)) 658 if (!allocate_buffers(&bigbuf, &smallbuf,
659 sizeof(struct smb_hdr), isLargeBuf))
858 continue; 660 continue;
859 661
860 server->large_buf = false; 662 isLargeBuf = false;
861 buf = server->smallbuf; 663 isMultiRsp = false;
664 smb_buffer = (struct smb_hdr *)smallbuf;
665 buf = smallbuf;
666 iov.iov_base = buf;
667 iov.iov_len = 4;
668 smb_msg.msg_control = NULL;
669 smb_msg.msg_controllen = 0;
862 pdu_length = 4; /* enough to get RFC1001 header */ 670 pdu_length = 4; /* enough to get RFC1001 header */
863 671
864 length = cifs_read_from_socket(server, buf, pdu_length); 672incomplete_rcv:
865 if (length < 0) 673 if (echo_retries > 0 && server->tcpStatus == CifsGood &&
674 time_after(jiffies, server->lstrp +
675 (echo_retries * SMB_ECHO_INTERVAL))) {
676 cERROR(1, "Server %s has not responded in %d seconds. "
677 "Reconnecting...", server->hostname,
678 (echo_retries * SMB_ECHO_INTERVAL / HZ));
679 cifs_reconnect(server);
680 wake_up(&server->response_q);
681 continue;
682 }
683
684 rc = read_from_socket(server, &smb_msg, &iov, pdu_length,
685 &total_read, true /* header read */);
686 if (rc == 3)
687 goto incomplete_rcv;
688 else if (rc == 2)
689 break;
690 else if (rc == 1)
866 continue; 691 continue;
867 server->total_read = length;
868 692
869 /* 693 /*
870 * The right amount was read from socket - 4 bytes, 694 * The right amount was read from socket - 4 bytes,
871 * so we can now interpret the length field. 695 * so we can now interpret the length field.
872 */ 696 */
873 pdu_length = get_rfc1002_length(buf);
874 697
875 cFYI(1, "RFC1002 header 0x%x", pdu_length); 698 /*
876 if (!is_smb_response(server, buf[0])) 699 * Note that RFC 1001 length is big endian on the wire,
877 continue; 700 * but we convert it here so it is always manipulated
701 * as host byte order.
702 */
703 pdu_length = be32_to_cpu(smb_buffer->smb_buf_length);
878 704
879 /* make sure we have enough to get to the MID */ 705 cFYI(1, "rfc1002 length 0x%x", pdu_length+4);
880 if (pdu_length < HEADER_SIZE(server) - 1 - 4) { 706 if (!check_rfc1002_header(server, buf))
881 cERROR(1, "SMB response too short (%u bytes)",
882 pdu_length);
883 cifs_reconnect(server);
884 wake_up(&server->response_q);
885 continue; 707 continue;
708
709 /* else length ok */
710 if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) {
711 isLargeBuf = true;
712 memcpy(bigbuf, smallbuf, 4);
713 smb_buffer = (struct smb_hdr *)bigbuf;
714 buf = bigbuf;
886 } 715 }
887 716
888 /* read down to the MID */ 717 iov.iov_base = 4 + buf;
889 length = cifs_read_from_socket(server, buf + 4, 718 iov.iov_len = pdu_length;
890 HEADER_SIZE(server) - 1 - 4); 719 rc = read_from_socket(server, &smb_msg, &iov, pdu_length,
891 if (length < 0) 720 &total_read, false);
721 if (rc == 2)
722 break;
723 else if (rc == 1)
892 continue; 724 continue;
893 server->total_read += length;
894 725
895 mid_entry = server->ops->find_mid(server, buf); 726 total_read += 4; /* account for rfc1002 hdr */
896 727
897 if (!mid_entry || !mid_entry->receive) 728 dump_smb(smb_buffer, total_read);
898 length = standard_receive3(server, mid_entry);
899 else
900 length = mid_entry->receive(server, mid_entry);
901 729
902 if (length < 0) 730 /*
903 continue; 731 * We know that we received enough to get to the MID as we
904 732 * checked the pdu_length earlier. Now check to see
905 if (server->large_buf) 733 * if the rest of the header is OK. We borrow the length
906 buf = server->bigbuf; 734 * var for the rest of the loop to avoid a new stack var.
735 *
736 * 48 bytes is enough to display the header and a little bit
737 * into the payload for debugging purposes.
738 */
739 length = checkSMB(smb_buffer, smb_buffer->Mid, total_read);
740 if (length != 0)
741 cifs_dump_mem("Bad SMB: ", buf,
742 min_t(unsigned int, total_read, 48));
907 743
908 server->lstrp = jiffies; 744 server->lstrp = jiffies;
745
746 mid_entry = find_cifs_mid(server, smb_buffer, &length,
747 isLargeBuf, &isMultiRsp, &bigbuf);
909 if (mid_entry != NULL) { 748 if (mid_entry != NULL) {
910 if (!mid_entry->multiRsp || mid_entry->multiEnd) 749 mid_entry->callback(mid_entry);
911 mid_entry->callback(mid_entry); 750 /* Was previous buf put in mpx struct for multi-rsp? */
912 } else if (!server->ops->is_oplock_break || 751 if (!isMultiRsp) {
913 !server->ops->is_oplock_break(buf, server)) { 752 /* smb buffer will be freed by user thread */
753 if (isLargeBuf)
754 bigbuf = NULL;
755 else
756 smallbuf = NULL;
757 }
758 } else if (length != 0) {
759 /* response sanity checks failed */
760 continue;
761 } else if (!is_valid_oplock_break(smb_buffer, server) &&
762 !isMultiRsp) {
914 cERROR(1, "No task to wake, unknown frame received! " 763 cERROR(1, "No task to wake, unknown frame received! "
915 "NumMids %d", atomic_read(&midCount)); 764 "NumMids %d", atomic_read(&midCount));
916 cifs_dump_mem("Received Data is: ", buf, 765 cifs_dump_mem("Received Data is: ", buf,
917 HEADER_SIZE(server)); 766 sizeof(struct smb_hdr));
918#ifdef CONFIG_CIFS_DEBUG2 767#ifdef CONFIG_CIFS_DEBUG2
919 if (server->ops->dump_detail) 768 cifs_dump_detail(smb_buffer);
920 server->ops->dump_detail(buf);
921 cifs_dump_mids(server); 769 cifs_dump_mids(server);
922#endif /* CIFS_DEBUG2 */ 770#endif /* CIFS_DEBUG2 */
923 771
@@ -925,9 +773,9 @@ cifs_demultiplex_thread(void *p)
925 } /* end while !EXITING */ 773 } /* end while !EXITING */
926 774
927 /* buffer usually freed in free_mid - need to free it here on exit */ 775 /* buffer usually freed in free_mid - need to free it here on exit */
928 cifs_buf_release(server->bigbuf); 776 cifs_buf_release(bigbuf);
929 if (server->smallbuf) /* no sense logging a debug message if NULL */ 777 if (smallbuf) /* no sense logging a debug message if NULL */
930 cifs_small_buf_release(server->smallbuf); 778 cifs_small_buf_release(smallbuf);
931 779
932 task_to_wake = xchg(&server->tsk, NULL); 780 task_to_wake = xchg(&server->tsk, NULL);
933 clean_demultiplex_info(server); 781 clean_demultiplex_info(server);
@@ -973,180 +821,11 @@ extract_hostname(const char *unc)
973 return dst; 821 return dst;
974} 822}
975 823
976static int get_option_ul(substring_t args[], unsigned long *option)
977{
978 int rc;
979 char *string;
980
981 string = match_strdup(args);
982 if (string == NULL)
983 return -ENOMEM;
984 rc = kstrtoul(string, 0, option);
985 kfree(string);
986
987 return rc;
988}
989
990
991static int cifs_parse_security_flavors(char *value,
992 struct smb_vol *vol)
993{
994
995 substring_t args[MAX_OPT_ARGS];
996
997 switch (match_token(value, cifs_secflavor_tokens, args)) {
998 case Opt_sec_krb5:
999 vol->secFlg |= CIFSSEC_MAY_KRB5;
1000 break;
1001 case Opt_sec_krb5i:
1002 vol->secFlg |= CIFSSEC_MAY_KRB5 | CIFSSEC_MUST_SIGN;
1003 break;
1004 case Opt_sec_krb5p:
1005 /* vol->secFlg |= CIFSSEC_MUST_SEAL | CIFSSEC_MAY_KRB5; */
1006 cERROR(1, "Krb5 cifs privacy not supported");
1007 break;
1008 case Opt_sec_ntlmssp:
1009 vol->secFlg |= CIFSSEC_MAY_NTLMSSP;
1010 break;
1011 case Opt_sec_ntlmsspi:
1012 vol->secFlg |= CIFSSEC_MAY_NTLMSSP | CIFSSEC_MUST_SIGN;
1013 break;
1014 case Opt_ntlm:
1015 /* ntlm is default so can be turned off too */
1016 vol->secFlg |= CIFSSEC_MAY_NTLM;
1017 break;
1018 case Opt_sec_ntlmi:
1019 vol->secFlg |= CIFSSEC_MAY_NTLM | CIFSSEC_MUST_SIGN;
1020 break;
1021 case Opt_sec_ntlmv2:
1022 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
1023 break;
1024 case Opt_sec_ntlmv2i:
1025 vol->secFlg |= CIFSSEC_MAY_NTLMV2 | CIFSSEC_MUST_SIGN;
1026 break;
1027#ifdef CONFIG_CIFS_WEAK_PW_HASH
1028 case Opt_sec_lanman:
1029 vol->secFlg |= CIFSSEC_MAY_LANMAN;
1030 break;
1031#endif
1032 case Opt_sec_none:
1033 vol->nullauth = 1;
1034 break;
1035 default:
1036 cERROR(1, "bad security option: %s", value);
1037 return 1;
1038 }
1039
1040 return 0;
1041}
1042
1043static int
1044cifs_parse_cache_flavor(char *value, struct smb_vol *vol)
1045{
1046 substring_t args[MAX_OPT_ARGS];
1047
1048 switch (match_token(value, cifs_cacheflavor_tokens, args)) {
1049 case Opt_cache_loose:
1050 vol->direct_io = false;
1051 vol->strict_io = false;
1052 break;
1053 case Opt_cache_strict:
1054 vol->direct_io = false;
1055 vol->strict_io = true;
1056 break;
1057 case Opt_cache_none:
1058 vol->direct_io = true;
1059 vol->strict_io = false;
1060 break;
1061 default:
1062 cERROR(1, "bad cache= option: %s", value);
1063 return 1;
1064 }
1065 return 0;
1066}
1067
1068static int
1069cifs_parse_smb_version(char *value, struct smb_vol *vol)
1070{
1071 substring_t args[MAX_OPT_ARGS];
1072
1073 switch (match_token(value, cifs_smb_version_tokens, args)) {
1074 case Smb_1:
1075 vol->ops = &smb1_operations;
1076 vol->vals = &smb1_values;
1077 break;
1078#ifdef CONFIG_CIFS_SMB2
1079 case Smb_20:
1080 vol->ops = &smb21_operations; /* currently identical with 2.1 */
1081 vol->vals = &smb20_values;
1082 break;
1083 case Smb_21:
1084 vol->ops = &smb21_operations;
1085 vol->vals = &smb21_values;
1086 break;
1087 case Smb_30:
1088 vol->ops = &smb30_operations;
1089 vol->vals = &smb30_values;
1090 break;
1091#endif
1092 default:
1093 cERROR(1, "Unknown vers= option specified: %s", value);
1094 return 1;
1095 }
1096 return 0;
1097}
1098
1099/*
1100 * Parse a devname into substrings and populate the vol->UNC and vol->prepath
1101 * fields with the result. Returns 0 on success and an error otherwise.
1102 */
1103static int
1104cifs_parse_devname(const char *devname, struct smb_vol *vol)
1105{
1106 char *pos;
1107 const char *delims = "/\\";
1108 size_t len;
1109
1110 /* make sure we have a valid UNC double delimiter prefix */
1111 len = strspn(devname, delims);
1112 if (len != 2)
1113 return -EINVAL;
1114
1115 /* find delimiter between host and sharename */
1116 pos = strpbrk(devname + 2, delims);
1117 if (!pos)
1118 return -EINVAL;
1119
1120 /* skip past delimiter */
1121 ++pos;
1122
1123 /* now go until next delimiter or end of string */
1124 len = strcspn(pos, delims);
1125
1126 /* move "pos" up to delimiter or NULL */
1127 pos += len;
1128 vol->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
1129 if (!vol->UNC)
1130 return -ENOMEM;
1131
1132 convert_delimiter(vol->UNC, '\\');
1133
1134 /* If pos is NULL, or is a bogus trailing delimiter then no prepath */
1135 if (!*pos++ || !*pos)
1136 return 0;
1137
1138 vol->prepath = kstrdup(pos, GFP_KERNEL);
1139 if (!vol->prepath)
1140 return -ENOMEM;
1141
1142 return 0;
1143}
1144
1145static int 824static int
1146cifs_parse_mount_options(const char *mountdata, const char *devname, 825cifs_parse_mount_options(const char *mountdata, const char *devname,
1147 struct smb_vol *vol) 826 struct smb_vol *vol)
1148{ 827{
1149 char *data, *end; 828 char *value, *data, *end;
1150 char *mountdata_copy = NULL, *options; 829 char *mountdata_copy = NULL, *options;
1151 unsigned int temp_len, i, j; 830 unsigned int temp_len, i, j;
1152 char separator[2]; 831 char separator[2];
@@ -1154,22 +833,10 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1154 short int override_gid = -1; 833 short int override_gid = -1;
1155 bool uid_specified = false; 834 bool uid_specified = false;
1156 bool gid_specified = false; 835 bool gid_specified = false;
1157 bool sloppy = false;
1158 char *invalid = NULL;
1159 char *nodename = utsname()->nodename; 836 char *nodename = utsname()->nodename;
1160 char *string = NULL;
1161 char *tmp_end, *value;
1162 char delim;
1163 bool got_ip = false;
1164 unsigned short port = 0;
1165 struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
1166 837
1167 separator[0] = ','; 838 separator[0] = ',';
1168 separator[1] = 0; 839 separator[1] = 0;
1169 delim = separator[0];
1170
1171 /* ensure we always start with zeroed-out smb_vol */
1172 memset(vol, 0, sizeof(*vol));
1173 840
1174 /* 841 /*
1175 * does not have to be perfect mapping since field is 842 * does not have to be perfect mapping since field is
@@ -1197,15 +864,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1197 /* default to using server inode numbers where available */ 864 /* default to using server inode numbers where available */
1198 vol->server_ino = 1; 865 vol->server_ino = 1;
1199 866
1200 /* default is to use strict cifs caching semantics */
1201 vol->strict_io = true;
1202
1203 vol->actimeo = CIFS_DEF_ACTIMEO; 867 vol->actimeo = CIFS_DEF_ACTIMEO;
1204 868
1205 /* FIXME: add autonegotiation -- for now, SMB1 is default */
1206 vol->ops = &smb1_operations;
1207 vol->vals = &smb1_values;
1208
1209 if (!mountdata) 869 if (!mountdata)
1210 goto cifs_parse_mount_err; 870 goto cifs_parse_mount_err;
1211 871
@@ -1215,7 +875,6 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1215 875
1216 options = mountdata_copy; 876 options = mountdata_copy;
1217 end = options + strlen(options); 877 end = options + strlen(options);
1218
1219 if (strncmp(options, "sep=", 4) == 0) { 878 if (strncmp(options, "sep=", 4) == 0) {
1220 if (options[4] != 0) { 879 if (options[4] != 0) {
1221 separator[0] = options[4]; 880 separator[0] = options[4];
@@ -1224,658 +883,605 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1224 cFYI(1, "Null separator not allowed"); 883 cFYI(1, "Null separator not allowed");
1225 } 884 }
1226 } 885 }
1227 vol->backupuid_specified = false; /* no backup intent for a user */
1228 vol->backupgid_specified = false; /* no backup intent for a group */
1229
1230 /*
1231 * For now, we ignore -EINVAL errors under the assumption that the
1232 * unc= and prefixpath= options will be usable.
1233 */
1234 if (cifs_parse_devname(devname, vol) == -ENOMEM) {
1235 printk(KERN_ERR "CIFS: Unable to allocate memory to parse "
1236 "device string.\n");
1237 goto out_nomem;
1238 }
1239 886
1240 while ((data = strsep(&options, separator)) != NULL) { 887 while ((data = strsep(&options, separator)) != NULL) {
1241 substring_t args[MAX_OPT_ARGS];
1242 unsigned long option;
1243 int token;
1244
1245 if (!*data) 888 if (!*data)
1246 continue; 889 continue;
890 if ((value = strchr(data, '=')) != NULL)
891 *value++ = '\0';
1247 892
1248 token = match_token(data, cifs_mount_option_tokens, args); 893 /* Have to parse this before we parse for "user" */
1249 894 if (strnicmp(data, "user_xattr", 10) == 0) {
1250 switch (token) {
1251
1252 /* Ingnore the following */
1253 case Opt_ignore:
1254 break;
1255
1256 /* Boolean values */
1257 case Opt_user_xattr:
1258 vol->no_xattr = 0; 895 vol->no_xattr = 0;
1259 break; 896 } else if (strnicmp(data, "nouser_xattr", 12) == 0) {
1260 case Opt_nouser_xattr:
1261 vol->no_xattr = 1; 897 vol->no_xattr = 1;
1262 break; 898 } else if (strnicmp(data, "user", 4) == 0) {
1263 case Opt_forceuid: 899 if (!value) {
900 printk(KERN_WARNING
901 "CIFS: invalid or missing username\n");
902 goto cifs_parse_mount_err;
903 } else if (!*value) {
904 /* null user, ie anonymous, authentication */
905 vol->nullauth = 1;
906 }
907 if (strnlen(value, MAX_USERNAME_SIZE) <
908 MAX_USERNAME_SIZE) {
909 vol->username = kstrdup(value, GFP_KERNEL);
910 if (!vol->username) {
911 printk(KERN_WARNING "CIFS: no memory "
912 "for username\n");
913 goto cifs_parse_mount_err;
914 }
915 } else {
916 printk(KERN_WARNING "CIFS: username too long\n");
917 goto cifs_parse_mount_err;
918 }
919 } else if (strnicmp(data, "pass", 4) == 0) {
920 if (!value) {
921 vol->password = NULL;
922 continue;
923 } else if (value[0] == 0) {
924 /* check if string begins with double comma
925 since that would mean the password really
926 does start with a comma, and would not
927 indicate an empty string */
928 if (value[1] != separator[0]) {
929 vol->password = NULL;
930 continue;
931 }
932 }
933 temp_len = strlen(value);
934 /* removed password length check, NTLM passwords
935 can be arbitrarily long */
936
937 /* if comma in password, the string will be
938 prematurely null terminated. Commas in password are
939 specified across the cifs mount interface by a double
940 comma ie ,, and a comma used as in other cases ie ','
941 as a parameter delimiter/separator is single and due
942 to the strsep above is temporarily zeroed. */
943
944 /* NB: password legally can have multiple commas and
945 the only illegal character in a password is null */
946
947 if ((value[temp_len] == 0) &&
948 (value + temp_len < end) &&
949 (value[temp_len+1] == separator[0])) {
950 /* reinsert comma */
951 value[temp_len] = separator[0];
952 temp_len += 2; /* move after second comma */
953 while (value[temp_len] != 0) {
954 if (value[temp_len] == separator[0]) {
955 if (value[temp_len+1] ==
956 separator[0]) {
957 /* skip second comma */
958 temp_len++;
959 } else {
960 /* single comma indicating start
961 of next parm */
962 break;
963 }
964 }
965 temp_len++;
966 }
967 if (value[temp_len] == 0) {
968 options = NULL;
969 } else {
970 value[temp_len] = 0;
971 /* point option to start of next parm */
972 options = value + temp_len + 1;
973 }
974 /* go from value to value + temp_len condensing
975 double commas to singles. Note that this ends up
976 allocating a few bytes too many, which is ok */
977 vol->password = kzalloc(temp_len, GFP_KERNEL);
978 if (vol->password == NULL) {
979 printk(KERN_WARNING "CIFS: no memory "
980 "for password\n");
981 goto cifs_parse_mount_err;
982 }
983 for (i = 0, j = 0; i < temp_len; i++, j++) {
984 vol->password[j] = value[i];
985 if (value[i] == separator[0]
986 && value[i+1] == separator[0]) {
987 /* skip second comma */
988 i++;
989 }
990 }
991 vol->password[j] = 0;
992 } else {
993 vol->password = kzalloc(temp_len+1, GFP_KERNEL);
994 if (vol->password == NULL) {
995 printk(KERN_WARNING "CIFS: no memory "
996 "for password\n");
997 goto cifs_parse_mount_err;
998 }
999 strcpy(vol->password, value);
1000 }
1001 } else if (!strnicmp(data, "ip", 2) ||
1002 !strnicmp(data, "addr", 4)) {
1003 if (!value || !*value) {
1004 vol->UNCip = NULL;
1005 } else if (strnlen(value, INET6_ADDRSTRLEN) <
1006 INET6_ADDRSTRLEN) {
1007 vol->UNCip = kstrdup(value, GFP_KERNEL);
1008 if (!vol->UNCip) {
1009 printk(KERN_WARNING "CIFS: no memory "
1010 "for UNC IP\n");
1011 goto cifs_parse_mount_err;
1012 }
1013 } else {
1014 printk(KERN_WARNING "CIFS: ip address "
1015 "too long\n");
1016 goto cifs_parse_mount_err;
1017 }
1018 } else if (strnicmp(data, "sec", 3) == 0) {
1019 if (!value || !*value) {
1020 cERROR(1, "no security value specified");
1021 continue;
1022 } else if (strnicmp(value, "krb5i", 5) == 0) {
1023 vol->secFlg |= CIFSSEC_MAY_KRB5 |
1024 CIFSSEC_MUST_SIGN;
1025 } else if (strnicmp(value, "krb5p", 5) == 0) {
1026 /* vol->secFlg |= CIFSSEC_MUST_SEAL |
1027 CIFSSEC_MAY_KRB5; */
1028 cERROR(1, "Krb5 cifs privacy not supported");
1029 goto cifs_parse_mount_err;
1030 } else if (strnicmp(value, "krb5", 4) == 0) {
1031 vol->secFlg |= CIFSSEC_MAY_KRB5;
1032 } else if (strnicmp(value, "ntlmsspi", 8) == 0) {
1033 vol->secFlg |= CIFSSEC_MAY_NTLMSSP |
1034 CIFSSEC_MUST_SIGN;
1035 } else if (strnicmp(value, "ntlmssp", 7) == 0) {
1036 vol->secFlg |= CIFSSEC_MAY_NTLMSSP;
1037 } else if (strnicmp(value, "ntlmv2i", 7) == 0) {
1038 vol->secFlg |= CIFSSEC_MAY_NTLMV2 |
1039 CIFSSEC_MUST_SIGN;
1040 } else if (strnicmp(value, "ntlmv2", 6) == 0) {
1041 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
1042 } else if (strnicmp(value, "ntlmi", 5) == 0) {
1043 vol->secFlg |= CIFSSEC_MAY_NTLM |
1044 CIFSSEC_MUST_SIGN;
1045 } else if (strnicmp(value, "ntlm", 4) == 0) {
1046 /* ntlm is default so can be turned off too */
1047 vol->secFlg |= CIFSSEC_MAY_NTLM;
1048 } else if (strnicmp(value, "nontlm", 6) == 0) {
1049 /* BB is there a better way to do this? */
1050 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
1051#ifdef CONFIG_CIFS_WEAK_PW_HASH
1052 } else if (strnicmp(value, "lanman", 6) == 0) {
1053 vol->secFlg |= CIFSSEC_MAY_LANMAN;
1054#endif
1055 } else if (strnicmp(value, "none", 4) == 0) {
1056 vol->nullauth = 1;
1057 } else {
1058 cERROR(1, "bad security option: %s", value);
1059 goto cifs_parse_mount_err;
1060 }
1061 } else if (strnicmp(data, "vers", 3) == 0) {
1062 if (!value || !*value) {
1063 cERROR(1, "no protocol version specified"
1064 " after vers= mount option");
1065 } else if ((strnicmp(value, "cifs", 4) == 0) ||
1066 (strnicmp(value, "1", 1) == 0)) {
1067 /* this is the default */
1068 continue;
1069 }
1070 } else if ((strnicmp(data, "unc", 3) == 0)
1071 || (strnicmp(data, "target", 6) == 0)
1072 || (strnicmp(data, "path", 4) == 0)) {
1073 if (!value || !*value) {
1074 printk(KERN_WARNING "CIFS: invalid path to "
1075 "network resource\n");
1076 goto cifs_parse_mount_err;
1077 }
1078 if ((temp_len = strnlen(value, 300)) < 300) {
1079 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1080 if (vol->UNC == NULL)
1081 goto cifs_parse_mount_err;
1082 strcpy(vol->UNC, value);
1083 if (strncmp(vol->UNC, "//", 2) == 0) {
1084 vol->UNC[0] = '\\';
1085 vol->UNC[1] = '\\';
1086 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
1087 printk(KERN_WARNING
1088 "CIFS: UNC Path does not begin "
1089 "with // or \\\\ \n");
1090 goto cifs_parse_mount_err;
1091 }
1092 } else {
1093 printk(KERN_WARNING "CIFS: UNC name too long\n");
1094 goto cifs_parse_mount_err;
1095 }
1096 } else if ((strnicmp(data, "domain", 3) == 0)
1097 || (strnicmp(data, "workgroup", 5) == 0)) {
1098 if (!value || !*value) {
1099 printk(KERN_WARNING "CIFS: invalid domain name\n");
1100 goto cifs_parse_mount_err;
1101 }
1102 /* BB are there cases in which a comma can be valid in
1103 a domain name and need special handling? */
1104 if (strnlen(value, 256) < 256) {
1105 vol->domainname = kstrdup(value, GFP_KERNEL);
1106 if (!vol->domainname) {
1107 printk(KERN_WARNING "CIFS: no memory "
1108 "for domainname\n");
1109 goto cifs_parse_mount_err;
1110 }
1111 cFYI(1, "Domain name set");
1112 } else {
1113 printk(KERN_WARNING "CIFS: domain name too "
1114 "long\n");
1115 goto cifs_parse_mount_err;
1116 }
1117 } else if (strnicmp(data, "srcaddr", 7) == 0) {
1118 vol->srcaddr.ss_family = AF_UNSPEC;
1119
1120 if (!value || !*value) {
1121 printk(KERN_WARNING "CIFS: srcaddr value"
1122 " not specified.\n");
1123 goto cifs_parse_mount_err;
1124 }
1125 i = cifs_convert_address((struct sockaddr *)&vol->srcaddr,
1126 value, strlen(value));
1127 if (i == 0) {
1128 printk(KERN_WARNING "CIFS: Could not parse"
1129 " srcaddr: %s\n",
1130 value);
1131 goto cifs_parse_mount_err;
1132 }
1133 } else if (strnicmp(data, "prefixpath", 10) == 0) {
1134 if (!value || !*value) {
1135 printk(KERN_WARNING
1136 "CIFS: invalid path prefix\n");
1137 goto cifs_parse_mount_err;
1138 }
1139 if ((temp_len = strnlen(value, 1024)) < 1024) {
1140 if (value[0] != '/')
1141 temp_len++; /* missing leading slash */
1142 vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
1143 if (vol->prepath == NULL)
1144 goto cifs_parse_mount_err;
1145 if (value[0] != '/') {
1146 vol->prepath[0] = '/';
1147 strcpy(vol->prepath+1, value);
1148 } else
1149 strcpy(vol->prepath, value);
1150 cFYI(1, "prefix path %s", vol->prepath);
1151 } else {
1152 printk(KERN_WARNING "CIFS: prefix too long\n");
1153 goto cifs_parse_mount_err;
1154 }
1155 } else if (strnicmp(data, "iocharset", 9) == 0) {
1156 if (!value || !*value) {
1157 printk(KERN_WARNING "CIFS: invalid iocharset "
1158 "specified\n");
1159 goto cifs_parse_mount_err;
1160 }
1161 if (strnlen(value, 65) < 65) {
1162 if (strnicmp(value, "default", 7)) {
1163 vol->iocharset = kstrdup(value,
1164 GFP_KERNEL);
1165
1166 if (!vol->iocharset) {
1167 printk(KERN_WARNING "CIFS: no "
1168 "memory for"
1169 "charset\n");
1170 goto cifs_parse_mount_err;
1171 }
1172 }
1173 /* if iocharset not set then load_nls_default
1174 is used by caller */
1175 cFYI(1, "iocharset set to %s", value);
1176 } else {
1177 printk(KERN_WARNING "CIFS: iocharset name "
1178 "too long.\n");
1179 goto cifs_parse_mount_err;
1180 }
1181 } else if (!strnicmp(data, "uid", 3) && value && *value) {
1182 vol->linux_uid = simple_strtoul(value, &value, 0);
1183 uid_specified = true;
1184 } else if (!strnicmp(data, "cruid", 5) && value && *value) {
1185 vol->cred_uid = simple_strtoul(value, &value, 0);
1186 } else if (!strnicmp(data, "forceuid", 8)) {
1264 override_uid = 1; 1187 override_uid = 1;
1265 break; 1188 } else if (!strnicmp(data, "noforceuid", 10)) {
1266 case Opt_noforceuid:
1267 override_uid = 0; 1189 override_uid = 0;
1268 break; 1190 } else if (!strnicmp(data, "gid", 3) && value && *value) {
1269 case Opt_forcegid: 1191 vol->linux_gid = simple_strtoul(value, &value, 0);
1192 gid_specified = true;
1193 } else if (!strnicmp(data, "forcegid", 8)) {
1270 override_gid = 1; 1194 override_gid = 1;
1271 break; 1195 } else if (!strnicmp(data, "noforcegid", 10)) {
1272 case Opt_noforcegid:
1273 override_gid = 0; 1196 override_gid = 0;
1274 break; 1197 } else if (strnicmp(data, "file_mode", 4) == 0) {
1275 case Opt_noblocksend: 1198 if (value && *value) {
1199 vol->file_mode =
1200 simple_strtoul(value, &value, 0);
1201 }
1202 } else if (strnicmp(data, "dir_mode", 4) == 0) {
1203 if (value && *value) {
1204 vol->dir_mode =
1205 simple_strtoul(value, &value, 0);
1206 }
1207 } else if (strnicmp(data, "dirmode", 4) == 0) {
1208 if (value && *value) {
1209 vol->dir_mode =
1210 simple_strtoul(value, &value, 0);
1211 }
1212 } else if (strnicmp(data, "port", 4) == 0) {
1213 if (value && *value) {
1214 vol->port =
1215 simple_strtoul(value, &value, 0);
1216 }
1217 } else if (strnicmp(data, "rsize", 5) == 0) {
1218 if (value && *value) {
1219 vol->rsize =
1220 simple_strtoul(value, &value, 0);
1221 }
1222 } else if (strnicmp(data, "wsize", 5) == 0) {
1223 if (value && *value) {
1224 vol->wsize =
1225 simple_strtoul(value, &value, 0);
1226 }
1227 } else if (strnicmp(data, "sockopt", 5) == 0) {
1228 if (!value || !*value) {
1229 cERROR(1, "no socket option specified");
1230 continue;
1231 } else if (strnicmp(value, "TCP_NODELAY", 11) == 0) {
1232 vol->sockopt_tcp_nodelay = 1;
1233 }
1234 } else if (strnicmp(data, "netbiosname", 4) == 0) {
1235 if (!value || !*value || (*value == ' ')) {
1236 cFYI(1, "invalid (empty) netbiosname");
1237 } else {
1238 memset(vol->source_rfc1001_name, 0x20,
1239 RFC1001_NAME_LEN);
1240 /*
1241 * FIXME: are there cases in which a comma can
1242 * be valid in workstation netbios name (and
1243 * need special handling)?
1244 */
1245 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1246 /* don't ucase netbiosname for user */
1247 if (value[i] == 0)
1248 break;
1249 vol->source_rfc1001_name[i] = value[i];
1250 }
1251 /* The string has 16th byte zero still from
1252 set at top of the function */
1253 if (i == RFC1001_NAME_LEN && value[i] != 0)
1254 printk(KERN_WARNING "CIFS: netbiosname"
1255 " longer than 15 truncated.\n");
1256 }
1257 } else if (strnicmp(data, "servern", 7) == 0) {
1258 /* servernetbiosname specified override *SMBSERVER */
1259 if (!value || !*value || (*value == ' ')) {
1260 cFYI(1, "empty server netbiosname specified");
1261 } else {
1262 /* last byte, type, is 0x20 for servr type */
1263 memset(vol->target_rfc1001_name, 0x20,
1264 RFC1001_NAME_LEN_WITH_NULL);
1265
1266 for (i = 0; i < 15; i++) {
1267 /* BB are there cases in which a comma can be
1268 valid in this workstation netbios name
1269 (and need special handling)? */
1270
1271 /* user or mount helper must uppercase
1272 the netbiosname */
1273 if (value[i] == 0)
1274 break;
1275 else
1276 vol->target_rfc1001_name[i] =
1277 value[i];
1278 }
1279 /* The string has 16th byte zero still from
1280 set at top of the function */
1281 if (i == RFC1001_NAME_LEN && value[i] != 0)
1282 printk(KERN_WARNING "CIFS: server net"
1283 "biosname longer than 15 truncated.\n");
1284 }
1285 } else if (strnicmp(data, "actimeo", 7) == 0) {
1286 if (value && *value) {
1287 vol->actimeo = HZ * simple_strtoul(value,
1288 &value, 0);
1289 if (vol->actimeo > CIFS_MAX_ACTIMEO) {
1290 cERROR(1, "CIFS: attribute cache"
1291 "timeout too large");
1292 goto cifs_parse_mount_err;
1293 }
1294 }
1295 } else if (strnicmp(data, "credentials", 4) == 0) {
1296 /* ignore */
1297 } else if (strnicmp(data, "version", 3) == 0) {
1298 /* ignore */
1299 } else if (strnicmp(data, "guest", 5) == 0) {
1300 /* ignore */
1301 } else if (strnicmp(data, "rw", 2) == 0 && strlen(data) == 2) {
1302 /* ignore */
1303 } else if (strnicmp(data, "ro", 2) == 0) {
1304 /* ignore */
1305 } else if (strnicmp(data, "noblocksend", 11) == 0) {
1276 vol->noblocksnd = 1; 1306 vol->noblocksnd = 1;
1277 break; 1307 } else if (strnicmp(data, "noautotune", 10) == 0) {
1278 case Opt_noautotune:
1279 vol->noautotune = 1; 1308 vol->noautotune = 1;
1280 break; 1309 } else if ((strnicmp(data, "suid", 4) == 0) ||
1281 case Opt_hard: 1310 (strnicmp(data, "nosuid", 6) == 0) ||
1311 (strnicmp(data, "exec", 4) == 0) ||
1312 (strnicmp(data, "noexec", 6) == 0) ||
1313 (strnicmp(data, "nodev", 5) == 0) ||
1314 (strnicmp(data, "noauto", 6) == 0) ||
1315 (strnicmp(data, "dev", 3) == 0)) {
1316 /* The mount tool or mount.cifs helper (if present)
1317 uses these opts to set flags, and the flags are read
1318 by the kernel vfs layer before we get here (ie
1319 before read super) so there is no point trying to
1320 parse these options again and set anything and it
1321 is ok to just ignore them */
1322 continue;
1323 } else if (strnicmp(data, "hard", 4) == 0) {
1282 vol->retry = 1; 1324 vol->retry = 1;
1283 break; 1325 } else if (strnicmp(data, "soft", 4) == 0) {
1284 case Opt_soft:
1285 vol->retry = 0; 1326 vol->retry = 0;
1286 break; 1327 } else if (strnicmp(data, "perm", 4) == 0) {
1287 case Opt_perm:
1288 vol->noperm = 0; 1328 vol->noperm = 0;
1289 break; 1329 } else if (strnicmp(data, "noperm", 6) == 0) {
1290 case Opt_noperm:
1291 vol->noperm = 1; 1330 vol->noperm = 1;
1292 break; 1331 } else if (strnicmp(data, "mapchars", 8) == 0) {
1293 case Opt_mapchars:
1294 vol->remap = 1; 1332 vol->remap = 1;
1295 break; 1333 } else if (strnicmp(data, "nomapchars", 10) == 0) {
1296 case Opt_nomapchars:
1297 vol->remap = 0; 1334 vol->remap = 0;
1298 break; 1335 } else if (strnicmp(data, "sfu", 3) == 0) {
1299 case Opt_sfu:
1300 vol->sfu_emul = 1; 1336 vol->sfu_emul = 1;
1301 break; 1337 } else if (strnicmp(data, "nosfu", 5) == 0) {
1302 case Opt_nosfu:
1303 vol->sfu_emul = 0; 1338 vol->sfu_emul = 0;
1304 break; 1339 } else if (strnicmp(data, "nodfs", 5) == 0) {
1305 case Opt_nodfs:
1306 vol->nodfs = 1; 1340 vol->nodfs = 1;
1307 break; 1341 } else if (strnicmp(data, "posixpaths", 10) == 0) {
1308 case Opt_posixpaths:
1309 vol->posix_paths = 1; 1342 vol->posix_paths = 1;
1310 break; 1343 } else if (strnicmp(data, "noposixpaths", 12) == 0) {
1311 case Opt_noposixpaths:
1312 vol->posix_paths = 0; 1344 vol->posix_paths = 0;
1313 break; 1345 } else if (strnicmp(data, "nounix", 6) == 0) {
1314 case Opt_nounix:
1315 vol->no_linux_ext = 1; 1346 vol->no_linux_ext = 1;
1316 break; 1347 } else if (strnicmp(data, "nolinux", 7) == 0) {
1317 case Opt_nocase: 1348 vol->no_linux_ext = 1;
1349 } else if ((strnicmp(data, "nocase", 6) == 0) ||
1350 (strnicmp(data, "ignorecase", 10) == 0)) {
1318 vol->nocase = 1; 1351 vol->nocase = 1;
1319 break; 1352 } else if (strnicmp(data, "mand", 4) == 0) {
1320 case Opt_brl: 1353 /* ignore */
1354 } else if (strnicmp(data, "nomand", 6) == 0) {
1355 /* ignore */
1356 } else if (strnicmp(data, "_netdev", 7) == 0) {
1357 /* ignore */
1358 } else if (strnicmp(data, "brl", 3) == 0) {
1321 vol->nobrl = 0; 1359 vol->nobrl = 0;
1322 break; 1360 } else if ((strnicmp(data, "nobrl", 5) == 0) ||
1323 case Opt_nobrl: 1361 (strnicmp(data, "nolock", 6) == 0)) {
1324 vol->nobrl = 1; 1362 vol->nobrl = 1;
1325 /* 1363 /* turn off mandatory locking in mode
1326 * turn off mandatory locking in mode 1364 if remote locking is turned off since the
1327 * if remote locking is turned off since the 1365 local vfs will do advisory */
1328 * local vfs will do advisory
1329 */
1330 if (vol->file_mode == 1366 if (vol->file_mode ==
1331 (S_IALLUGO & ~(S_ISUID | S_IXGRP))) 1367 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1332 vol->file_mode = S_IALLUGO; 1368 vol->file_mode = S_IALLUGO;
1333 break; 1369 } else if (strnicmp(data, "forcemandatorylock", 9) == 0) {
1334 case Opt_forcemandatorylock: 1370 /* will take the shorter form "forcemand" as well */
1371 /* This mount option will force use of mandatory
1372 (DOS/Windows style) byte range locks, instead of
1373 using posix advisory byte range locks, even if the
1374 Unix extensions are available and posix locks would
1375 be supported otherwise. If Unix extensions are not
1376 negotiated this has no effect since mandatory locks
1377 would be used (mandatory locks is all that those
1378 those servers support) */
1335 vol->mand_lock = 1; 1379 vol->mand_lock = 1;
1336 break; 1380 } else if (strnicmp(data, "setuids", 7) == 0) {
1337 case Opt_setuids:
1338 vol->setuids = 1; 1381 vol->setuids = 1;
1339 break; 1382 } else if (strnicmp(data, "nosetuids", 9) == 0) {
1340 case Opt_nosetuids:
1341 vol->setuids = 0; 1383 vol->setuids = 0;
1342 break; 1384 } else if (strnicmp(data, "dynperm", 7) == 0) {
1343 case Opt_dynperm:
1344 vol->dynperm = true; 1385 vol->dynperm = true;
1345 break; 1386 } else if (strnicmp(data, "nodynperm", 9) == 0) {
1346 case Opt_nodynperm:
1347 vol->dynperm = false; 1387 vol->dynperm = false;
1348 break; 1388 } else if (strnicmp(data, "nohard", 6) == 0) {
1349 case Opt_nohard:
1350 vol->retry = 0; 1389 vol->retry = 0;
1351 break; 1390 } else if (strnicmp(data, "nosoft", 6) == 0) {
1352 case Opt_nosoft:
1353 vol->retry = 1; 1391 vol->retry = 1;
1354 break; 1392 } else if (strnicmp(data, "nointr", 6) == 0) {
1355 case Opt_nointr:
1356 vol->intr = 0; 1393 vol->intr = 0;
1357 break; 1394 } else if (strnicmp(data, "intr", 4) == 0) {
1358 case Opt_intr:
1359 vol->intr = 1; 1395 vol->intr = 1;
1360 break; 1396 } else if (strnicmp(data, "nostrictsync", 12) == 0) {
1361 case Opt_nostrictsync:
1362 vol->nostrictsync = 1; 1397 vol->nostrictsync = 1;
1363 break; 1398 } else if (strnicmp(data, "strictsync", 10) == 0) {
1364 case Opt_strictsync:
1365 vol->nostrictsync = 0; 1399 vol->nostrictsync = 0;
1366 break; 1400 } else if (strnicmp(data, "serverino", 7) == 0) {
1367 case Opt_serverino:
1368 vol->server_ino = 1; 1401 vol->server_ino = 1;
1369 break; 1402 } else if (strnicmp(data, "noserverino", 9) == 0) {
1370 case Opt_noserverino:
1371 vol->server_ino = 0; 1403 vol->server_ino = 0;
1372 break; 1404 } else if (strnicmp(data, "rwpidforward", 12) == 0) {
1373 case Opt_rwpidforward:
1374 vol->rwpidforward = 1; 1405 vol->rwpidforward = 1;
1375 break; 1406 } else if (strnicmp(data, "cifsacl", 7) == 0) {
1376 case Opt_cifsacl:
1377 vol->cifs_acl = 1; 1407 vol->cifs_acl = 1;
1378 break; 1408 } else if (strnicmp(data, "nocifsacl", 9) == 0) {
1379 case Opt_nocifsacl:
1380 vol->cifs_acl = 0; 1409 vol->cifs_acl = 0;
1381 break; 1410 } else if (strnicmp(data, "acl", 3) == 0) {
1382 case Opt_acl:
1383 vol->no_psx_acl = 0; 1411 vol->no_psx_acl = 0;
1384 break; 1412 } else if (strnicmp(data, "noacl", 5) == 0) {
1385 case Opt_noacl:
1386 vol->no_psx_acl = 1; 1413 vol->no_psx_acl = 1;
1387 break; 1414 } else if (strnicmp(data, "locallease", 6) == 0) {
1388 case Opt_locallease:
1389 vol->local_lease = 1; 1415 vol->local_lease = 1;
1390 break; 1416 } else if (strnicmp(data, "sign", 4) == 0) {
1391 case Opt_sign:
1392 vol->secFlg |= CIFSSEC_MUST_SIGN; 1417 vol->secFlg |= CIFSSEC_MUST_SIGN;
1393 break; 1418 } else if (strnicmp(data, "seal", 4) == 0) {
1394 case Opt_seal:
1395 /* we do not do the following in secFlags because seal 1419 /* we do not do the following in secFlags because seal
1396 * is a per tree connection (mount) not a per socket 1420 is a per tree connection (mount) not a per socket
1397 * or per-smb connection option in the protocol 1421 or per-smb connection option in the protocol */
1398 * vol->secFlg |= CIFSSEC_MUST_SEAL; 1422 /* vol->secFlg |= CIFSSEC_MUST_SEAL; */
1399 */
1400 vol->seal = 1; 1423 vol->seal = 1;
1401 break; 1424 } else if (strnicmp(data, "direct", 6) == 0) {
1402 case Opt_noac: 1425 vol->direct_io = 1;
1426 } else if (strnicmp(data, "forcedirectio", 13) == 0) {
1427 vol->direct_io = 1;
1428 } else if (strnicmp(data, "strictcache", 11) == 0) {
1429 vol->strict_io = 1;
1430 } else if (strnicmp(data, "noac", 4) == 0) {
1403 printk(KERN_WARNING "CIFS: Mount option noac not " 1431 printk(KERN_WARNING "CIFS: Mount option noac not "
1404 "supported. Instead set " 1432 "supported. Instead set "
1405 "/proc/fs/cifs/LookupCacheEnabled to 0\n"); 1433 "/proc/fs/cifs/LookupCacheEnabled to 0\n");
1406 break; 1434 } else if (strnicmp(data, "fsc", 3) == 0) {
1407 case Opt_fsc:
1408#ifndef CONFIG_CIFS_FSCACHE 1435#ifndef CONFIG_CIFS_FSCACHE
1409 cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE " 1436 cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE "
1410 "kernel config option set"); 1437 "kernel config option set");
1411 goto cifs_parse_mount_err; 1438 goto cifs_parse_mount_err;
1412#endif 1439#endif
1413 vol->fsc = true; 1440 vol->fsc = true;
1414 break; 1441 } else if (strnicmp(data, "mfsymlinks", 10) == 0) {
1415 case Opt_mfsymlinks:
1416 vol->mfsymlinks = true; 1442 vol->mfsymlinks = true;
1417 break; 1443 } else if (strnicmp(data, "multiuser", 8) == 0) {
1418 case Opt_multiuser:
1419 vol->multiuser = true; 1444 vol->multiuser = true;
1420 break; 1445 } else
1421 case Opt_sloppy: 1446 printk(KERN_WARNING "CIFS: Unknown mount option %s\n",
1422 sloppy = true; 1447 data);
1423 break; 1448 }
1424 1449 if (vol->UNC == NULL) {
1425 /* Numeric Values */ 1450 if (devname == NULL) {
1426 case Opt_backupuid: 1451 printk(KERN_WARNING "CIFS: Missing UNC name for mount "
1427 if (get_option_ul(args, &option)) { 1452 "target\n");
1428 cERROR(1, "%s: Invalid backupuid value", 1453 goto cifs_parse_mount_err;
1429 __func__); 1454 }
1430 goto cifs_parse_mount_err; 1455 if ((temp_len = strnlen(devname, 300)) < 300) {
1431 } 1456 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1432 vol->backupuid = option;
1433 vol->backupuid_specified = true;
1434 break;
1435 case Opt_backupgid:
1436 if (get_option_ul(args, &option)) {
1437 cERROR(1, "%s: Invalid backupgid value",
1438 __func__);
1439 goto cifs_parse_mount_err;
1440 }
1441 vol->backupgid = option;
1442 vol->backupgid_specified = true;
1443 break;
1444 case Opt_uid:
1445 if (get_option_ul(args, &option)) {
1446 cERROR(1, "%s: Invalid uid value",
1447 __func__);
1448 goto cifs_parse_mount_err;
1449 }
1450 vol->linux_uid = option;
1451 uid_specified = true;
1452 break;
1453 case Opt_cruid:
1454 if (get_option_ul(args, &option)) {
1455 cERROR(1, "%s: Invalid cruid value",
1456 __func__);
1457 goto cifs_parse_mount_err;
1458 }
1459 vol->cred_uid = option;
1460 break;
1461 case Opt_gid:
1462 if (get_option_ul(args, &option)) {
1463 cERROR(1, "%s: Invalid gid value",
1464 __func__);
1465 goto cifs_parse_mount_err;
1466 }
1467 vol->linux_gid = option;
1468 gid_specified = true;
1469 break;
1470 case Opt_file_mode:
1471 if (get_option_ul(args, &option)) {
1472 cERROR(1, "%s: Invalid file_mode value",
1473 __func__);
1474 goto cifs_parse_mount_err;
1475 }
1476 vol->file_mode = option;
1477 break;
1478 case Opt_dirmode:
1479 if (get_option_ul(args, &option)) {
1480 cERROR(1, "%s: Invalid dir_mode value",
1481 __func__);
1482 goto cifs_parse_mount_err;
1483 }
1484 vol->dir_mode = option;
1485 break;
1486 case Opt_port:
1487 if (get_option_ul(args, &option) ||
1488 option > USHRT_MAX) {
1489 cERROR(1, "%s: Invalid port value", __func__);
1490 goto cifs_parse_mount_err;
1491 }
1492 port = (unsigned short)option;
1493 break;
1494 case Opt_rsize:
1495 if (get_option_ul(args, &option)) {
1496 cERROR(1, "%s: Invalid rsize value",
1497 __func__);
1498 goto cifs_parse_mount_err;
1499 }
1500 vol->rsize = option;
1501 break;
1502 case Opt_wsize:
1503 if (get_option_ul(args, &option)) {
1504 cERROR(1, "%s: Invalid wsize value",
1505 __func__);
1506 goto cifs_parse_mount_err;
1507 }
1508 vol->wsize = option;
1509 break;
1510 case Opt_actimeo:
1511 if (get_option_ul(args, &option)) {
1512 cERROR(1, "%s: Invalid actimeo value",
1513 __func__);
1514 goto cifs_parse_mount_err;
1515 }
1516 vol->actimeo = HZ * option;
1517 if (vol->actimeo > CIFS_MAX_ACTIMEO) {
1518 cERROR(1, "CIFS: attribute cache"
1519 "timeout too large");
1520 goto cifs_parse_mount_err;
1521 }
1522 break;
1523
1524 /* String Arguments */
1525
1526 case Opt_blank_user:
1527 /* null user, ie. anonymous authentication */
1528 vol->nullauth = 1;
1529 vol->username = NULL;
1530 break;
1531 case Opt_user:
1532 string = match_strdup(args);
1533 if (string == NULL)
1534 goto out_nomem;
1535
1536 if (strnlen(string, MAX_USERNAME_SIZE) >
1537 MAX_USERNAME_SIZE) {
1538 printk(KERN_WARNING "CIFS: username too long\n");
1539 goto cifs_parse_mount_err;
1540 }
1541 vol->username = kstrdup(string, GFP_KERNEL);
1542 if (!vol->username) {
1543 printk(KERN_WARNING "CIFS: no memory "
1544 "for username\n");
1545 goto cifs_parse_mount_err;
1546 }
1547 break;
1548 case Opt_blank_pass:
1549 vol->password = NULL;
1550 break;
1551 case Opt_pass:
1552 /* passwords have to be handled differently
1553 * to allow the character used for deliminator
1554 * to be passed within them
1555 */
1556
1557 /* Obtain the value string */
1558 value = strchr(data, '=');
1559 value++;
1560
1561 /* Set tmp_end to end of the string */
1562 tmp_end = (char *) value + strlen(value);
1563
1564 /* Check if following character is the deliminator
1565 * If yes, we have encountered a double deliminator
1566 * reset the NULL character to the deliminator
1567 */
1568 if (tmp_end < end && tmp_end[1] == delim) {
1569 tmp_end[0] = delim;
1570
1571 /* Keep iterating until we get to a single
1572 * deliminator OR the end
1573 */
1574 while ((tmp_end = strchr(tmp_end, delim))
1575 != NULL && (tmp_end[1] == delim)) {
1576 tmp_end = (char *) &tmp_end[2];
1577 }
1578
1579 /* Reset var options to point to next element */
1580 if (tmp_end) {
1581 tmp_end[0] = '\0';
1582 options = (char *) &tmp_end[1];
1583 } else
1584 /* Reached the end of the mount option
1585 * string */
1586 options = end;
1587 }
1588
1589 /* Now build new password string */
1590 temp_len = strlen(value);
1591 vol->password = kzalloc(temp_len+1, GFP_KERNEL);
1592 if (vol->password == NULL) {
1593 printk(KERN_WARNING "CIFS: no memory "
1594 "for password\n");
1595 goto cifs_parse_mount_err;
1596 }
1597
1598 for (i = 0, j = 0; i < temp_len; i++, j++) {
1599 vol->password[j] = value[i];
1600 if ((value[i] == delim) &&
1601 value[i+1] == delim)
1602 /* skip the second deliminator */
1603 i++;
1604 }
1605 vol->password[j] = '\0';
1606 break;
1607 case Opt_blank_ip:
1608 /* FIXME: should this be an error instead? */
1609 got_ip = false;
1610 break;
1611 case Opt_ip:
1612 string = match_strdup(args);
1613 if (string == NULL)
1614 goto out_nomem;
1615
1616 if (!cifs_convert_address(dstaddr, string,
1617 strlen(string))) {
1618 printk(KERN_ERR "CIFS: bad ip= option (%s).\n",
1619 string);
1620 goto cifs_parse_mount_err;
1621 }
1622 got_ip = true;
1623 break;
1624 case Opt_unc:
1625 string = vol->UNC;
1626 vol->UNC = match_strdup(args);
1627 if (vol->UNC == NULL) 1457 if (vol->UNC == NULL)
1628 goto out_nomem;
1629
1630 convert_delimiter(vol->UNC, '\\');
1631 if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') {
1632 printk(KERN_ERR "CIFS: UNC Path does not "
1633 "begin with // or \\\\\n");
1634 goto cifs_parse_mount_err;
1635 }
1636
1637 /* Compare old unc= option to new one */
1638 if (!string || strcmp(string, vol->UNC))
1639 printk(KERN_WARNING "CIFS: the value of the "
1640 "unc= mount option does not match the "
1641 "device string. Using the unc= option "
1642 "for now. In 3.10, that option will "
1643 "be ignored and the contents of the "
1644 "device string will be used "
1645 "instead. (%s != %s)\n", string,
1646 vol->UNC);
1647 break;
1648 case Opt_domain:
1649 string = match_strdup(args);
1650 if (string == NULL)
1651 goto out_nomem;
1652
1653 if (strnlen(string, 256) == 256) {
1654 printk(KERN_WARNING "CIFS: domain name too"
1655 " long\n");
1656 goto cifs_parse_mount_err;
1657 }
1658
1659 vol->domainname = kstrdup(string, GFP_KERNEL);
1660 if (!vol->domainname) {
1661 printk(KERN_WARNING "CIFS: no memory "
1662 "for domainname\n");
1663 goto cifs_parse_mount_err; 1458 goto cifs_parse_mount_err;
1664 } 1459 strcpy(vol->UNC, devname);
1665 cFYI(1, "Domain name set"); 1460 if (strncmp(vol->UNC, "//", 2) == 0) {
1666 break; 1461 vol->UNC[0] = '\\';
1667 case Opt_srcaddr: 1462 vol->UNC[1] = '\\';
1668 string = match_strdup(args); 1463 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
1669 if (string == NULL) 1464 printk(KERN_WARNING "CIFS: UNC Path does not "
1670 goto out_nomem; 1465 "begin with // or \\\\ \n");
1671
1672 if (!cifs_convert_address(
1673 (struct sockaddr *)&vol->srcaddr,
1674 string, strlen(string))) {
1675 printk(KERN_WARNING "CIFS: Could not parse"
1676 " srcaddr: %s\n", string);
1677 goto cifs_parse_mount_err; 1466 goto cifs_parse_mount_err;
1678 } 1467 }
1679 break; 1468 value = strpbrk(vol->UNC+2, "/\\");
1680 case Opt_prefixpath: 1469 if (value)
1681 /* skip over any leading delimiter */ 1470 *value = '\\';
1682 if (*args[0].from == '/' || *args[0].from == '\\') 1471 } else {
1683 args[0].from++; 1472 printk(KERN_WARNING "CIFS: UNC name too long\n");
1684
1685 string = vol->prepath;
1686 vol->prepath = match_strdup(args);
1687 if (vol->prepath == NULL)
1688 goto out_nomem;
1689 /* Compare old prefixpath= option to new one */
1690 if (!string || strcmp(string, vol->prepath))
1691 printk(KERN_WARNING "CIFS: the value of the "
1692 "prefixpath= mount option does not "
1693 "match the device string. Using the "
1694 "prefixpath= option for now. In 3.10, "
1695 "that option will be ignored and the "
1696 "contents of the device string will be "
1697 "used instead.(%s != %s)\n", string,
1698 vol->prepath);
1699 break;
1700 case Opt_iocharset:
1701 string = match_strdup(args);
1702 if (string == NULL)
1703 goto out_nomem;
1704
1705 if (strnlen(string, 1024) >= 65) {
1706 printk(KERN_WARNING "CIFS: iocharset name "
1707 "too long.\n");
1708 goto cifs_parse_mount_err;
1709 }
1710
1711 if (strnicmp(string, "default", 7) != 0) {
1712 vol->iocharset = kstrdup(string,
1713 GFP_KERNEL);
1714 if (!vol->iocharset) {
1715 printk(KERN_WARNING "CIFS: no memory"
1716 "for charset\n");
1717 goto cifs_parse_mount_err;
1718 }
1719 }
1720 /* if iocharset not set then load_nls_default
1721 * is used by caller
1722 */
1723 cFYI(1, "iocharset set to %s", string);
1724 break;
1725 case Opt_sockopt:
1726 string = match_strdup(args);
1727 if (string == NULL)
1728 goto out_nomem;
1729
1730 if (strnicmp(string, "TCP_NODELAY", 11) == 0) {
1731 printk(KERN_WARNING "CIFS: the "
1732 "sockopt=TCP_NODELAY option has been "
1733 "deprecated and will be removed "
1734 "in 3.9\n");
1735 vol->sockopt_tcp_nodelay = 1;
1736 }
1737 break;
1738 case Opt_netbiosname:
1739 string = match_strdup(args);
1740 if (string == NULL)
1741 goto out_nomem;
1742
1743 memset(vol->source_rfc1001_name, 0x20,
1744 RFC1001_NAME_LEN);
1745 /*
1746 * FIXME: are there cases in which a comma can
1747 * be valid in workstation netbios name (and
1748 * need special handling)?
1749 */
1750 for (i = 0; i < RFC1001_NAME_LEN; i++) {
1751 /* don't ucase netbiosname for user */
1752 if (string[i] == 0)
1753 break;
1754 vol->source_rfc1001_name[i] = string[i];
1755 }
1756 /* The string has 16th byte zero still from
1757 * set at top of the function
1758 */
1759 if (i == RFC1001_NAME_LEN && string[i] != 0)
1760 printk(KERN_WARNING "CIFS: netbiosname"
1761 " longer than 15 truncated.\n");
1762
1763 break;
1764 case Opt_servern:
1765 /* servernetbiosname specified override *SMBSERVER */
1766 string = match_strdup(args);
1767 if (string == NULL)
1768 goto out_nomem;
1769
1770 /* last byte, type, is 0x20 for servr type */
1771 memset(vol->target_rfc1001_name, 0x20,
1772 RFC1001_NAME_LEN_WITH_NULL);
1773
1774 /* BB are there cases in which a comma can be
1775 valid in this workstation netbios name
1776 (and need special handling)? */
1777
1778 /* user or mount helper must uppercase the
1779 netbios name */
1780 for (i = 0; i < 15; i++) {
1781 if (string[i] == 0)
1782 break;
1783 vol->target_rfc1001_name[i] = string[i];
1784 }
1785 /* The string has 16th byte zero still from
1786 set at top of the function */
1787 if (i == RFC1001_NAME_LEN && string[i] != 0)
1788 printk(KERN_WARNING "CIFS: server net"
1789 "biosname longer than 15 truncated.\n");
1790 break;
1791 case Opt_ver:
1792 string = match_strdup(args);
1793 if (string == NULL)
1794 goto out_nomem;
1795
1796 if (strnicmp(string, "1", 1) == 0) {
1797 /* This is the default */
1798 break;
1799 }
1800 /* For all other value, error */
1801 printk(KERN_WARNING "CIFS: Invalid version"
1802 " specified\n");
1803 goto cifs_parse_mount_err; 1473 goto cifs_parse_mount_err;
1804 case Opt_vers:
1805 string = match_strdup(args);
1806 if (string == NULL)
1807 goto out_nomem;
1808
1809 if (cifs_parse_smb_version(string, vol) != 0)
1810 goto cifs_parse_mount_err;
1811 break;
1812 case Opt_sec:
1813 string = match_strdup(args);
1814 if (string == NULL)
1815 goto out_nomem;
1816
1817 if (cifs_parse_security_flavors(string, vol) != 0)
1818 goto cifs_parse_mount_err;
1819 break;
1820 case Opt_cache:
1821 string = match_strdup(args);
1822 if (string == NULL)
1823 goto out_nomem;
1824
1825 if (cifs_parse_cache_flavor(string, vol) != 0)
1826 goto cifs_parse_mount_err;
1827 break;
1828 default:
1829 /*
1830 * An option we don't recognize. Save it off for later
1831 * if we haven't already found one
1832 */
1833 if (!invalid)
1834 invalid = data;
1835 break;
1836 } 1474 }
1837 /* Free up any allocated string */
1838 kfree(string);
1839 string = NULL;
1840 }
1841
1842 if (!sloppy && invalid) {
1843 printk(KERN_ERR "CIFS: Unknown mount option \"%s\"\n", invalid);
1844 goto cifs_parse_mount_err;
1845 }
1846
1847#ifndef CONFIG_KEYS
1848 /* Muliuser mounts require CONFIG_KEYS support */
1849 if (vol->multiuser) {
1850 cERROR(1, "Multiuser mounts require kernels with "
1851 "CONFIG_KEYS enabled.");
1852 goto cifs_parse_mount_err;
1853 }
1854#endif
1855 if (!vol->UNC) {
1856 cERROR(1, "CIFS mount error: No usable UNC path provided in "
1857 "device string or in unc= option!");
1858 goto cifs_parse_mount_err;
1859 } 1475 }
1860 1476
1861 /* make sure UNC has a share name */ 1477 if (vol->multiuser && !(vol->secFlg & CIFSSEC_MAY_KRB5)) {
1862 if (!strchr(vol->UNC + 3, '\\')) { 1478 cERROR(1, "Multiuser mounts currently require krb5 "
1863 cERROR(1, "Malformed UNC. Unable to find share name."); 1479 "authentication!");
1864 goto cifs_parse_mount_err; 1480 goto cifs_parse_mount_err;
1865 } 1481 }
1866 1482
1867 if (!got_ip) { 1483 if (vol->UNCip == NULL)
1868 /* No ip= option specified? Try to get it from UNC */ 1484 vol->UNCip = &vol->UNC[2];
1869 if (!cifs_convert_address(dstaddr, &vol->UNC[2],
1870 strlen(&vol->UNC[2]))) {
1871 printk(KERN_ERR "Unable to determine destination "
1872 "address.\n");
1873 goto cifs_parse_mount_err;
1874 }
1875 }
1876
1877 /* set the port that we got earlier */
1878 cifs_set_port(dstaddr, port);
1879 1485
1880 if (uid_specified) 1486 if (uid_specified)
1881 vol->override_uid = override_uid; 1487 vol->override_uid = override_uid;
@@ -1892,10 +1498,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1892 kfree(mountdata_copy); 1498 kfree(mountdata_copy);
1893 return 0; 1499 return 0;
1894 1500
1895out_nomem:
1896 printk(KERN_WARNING "Could not allocate temporary buffer\n");
1897cifs_parse_mount_err: 1501cifs_parse_mount_err:
1898 kfree(string);
1899 kfree(mountdata_copy); 1502 kfree(mountdata_copy);
1900 return 1; 1503 return 1;
1901} 1504}
@@ -2046,13 +1649,9 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
2046 return true; 1649 return true;
2047} 1650}
2048 1651
2049static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol) 1652static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
1653 struct smb_vol *vol)
2050{ 1654{
2051 struct sockaddr *addr = (struct sockaddr *)&vol->dstaddr;
2052
2053 if ((server->vals != vol->vals) || (server->ops != vol->ops))
2054 return 0;
2055
2056 if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) 1655 if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
2057 return 0; 1656 return 0;
2058 1657
@@ -2070,13 +1669,13 @@ static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol)
2070} 1669}
2071 1670
2072static struct TCP_Server_Info * 1671static struct TCP_Server_Info *
2073cifs_find_tcp_session(struct smb_vol *vol) 1672cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol)
2074{ 1673{
2075 struct TCP_Server_Info *server; 1674 struct TCP_Server_Info *server;
2076 1675
2077 spin_lock(&cifs_tcp_ses_lock); 1676 spin_lock(&cifs_tcp_ses_lock);
2078 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { 1677 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
2079 if (!match_server(server, vol)) 1678 if (!match_server(server, addr, vol))
2080 continue; 1679 continue;
2081 1680
2082 ++server->srv_count; 1681 ++server->srv_count;
@@ -2126,12 +1725,40 @@ static struct TCP_Server_Info *
2126cifs_get_tcp_session(struct smb_vol *volume_info) 1725cifs_get_tcp_session(struct smb_vol *volume_info)
2127{ 1726{
2128 struct TCP_Server_Info *tcp_ses = NULL; 1727 struct TCP_Server_Info *tcp_ses = NULL;
1728 struct sockaddr_storage addr;
1729 struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr;
1730 struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr;
2129 int rc; 1731 int rc;
2130 1732
2131 cFYI(1, "UNC: %s", volume_info->UNC); 1733 memset(&addr, 0, sizeof(struct sockaddr_storage));
1734
1735 cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip);
1736
1737 if (volume_info->UNCip && volume_info->UNC) {
1738 rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
1739 volume_info->UNCip,
1740 strlen(volume_info->UNCip),
1741 volume_info->port);
1742 if (!rc) {
1743 /* we failed translating address */
1744 rc = -EINVAL;
1745 goto out_err;
1746 }
1747 } else if (volume_info->UNCip) {
1748 /* BB using ip addr as tcp_ses name to connect to the
1749 DFS root below */
1750 cERROR(1, "Connecting to DFS root not implemented yet");
1751 rc = -EINVAL;
1752 goto out_err;
1753 } else /* which tcp_sess DFS root would we conect to */ {
1754 cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
1755 "unc=//192.168.1.100/public) specified");
1756 rc = -EINVAL;
1757 goto out_err;
1758 }
2132 1759
2133 /* see if we already have a matching tcp_ses */ 1760 /* see if we already have a matching tcp_ses */
2134 tcp_ses = cifs_find_tcp_session(volume_info); 1761 tcp_ses = cifs_find_tcp_session((struct sockaddr *)&addr, volume_info);
2135 if (tcp_ses) 1762 if (tcp_ses)
2136 return tcp_ses; 1763 return tcp_ses;
2137 1764
@@ -2147,8 +1774,6 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
2147 goto out_err; 1774 goto out_err;
2148 } 1775 }
2149 1776
2150 tcp_ses->ops = volume_info->ops;
2151 tcp_ses->vals = volume_info->vals;
2152 cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); 1777 cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
2153 tcp_ses->hostname = extract_hostname(volume_info->UNC); 1778 tcp_ses->hostname = extract_hostname(volume_info->UNC);
2154 if (IS_ERR(tcp_ses->hostname)) { 1779 if (IS_ERR(tcp_ses->hostname)) {
@@ -2159,8 +1784,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
2159 tcp_ses->noblocksnd = volume_info->noblocksnd; 1784 tcp_ses->noblocksnd = volume_info->noblocksnd;
2160 tcp_ses->noautotune = volume_info->noautotune; 1785 tcp_ses->noautotune = volume_info->noautotune;
2161 tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay; 1786 tcp_ses->tcp_nodelay = volume_info->sockopt_tcp_nodelay;
2162 tcp_ses->in_flight = 0; 1787 atomic_set(&tcp_ses->inFlight, 0);
2163 tcp_ses->credits = 1;
2164 init_waitqueue_head(&tcp_ses->response_q); 1788 init_waitqueue_head(&tcp_ses->response_q);
2165 init_waitqueue_head(&tcp_ses->request_q); 1789 init_waitqueue_head(&tcp_ses->request_q);
2166 INIT_LIST_HEAD(&tcp_ses->pending_mid_q); 1790 INIT_LIST_HEAD(&tcp_ses->pending_mid_q);
@@ -2172,22 +1796,30 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
2172 tcp_ses->session_estab = false; 1796 tcp_ses->session_estab = false;
2173 tcp_ses->sequence_number = 0; 1797 tcp_ses->sequence_number = 0;
2174 tcp_ses->lstrp = jiffies; 1798 tcp_ses->lstrp = jiffies;
2175 spin_lock_init(&tcp_ses->req_lock);
2176 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); 1799 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
2177 INIT_LIST_HEAD(&tcp_ses->smb_ses_list); 1800 INIT_LIST_HEAD(&tcp_ses->smb_ses_list);
2178 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); 1801 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request);
2179 memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr, 1802
2180 sizeof(tcp_ses->srcaddr));
2181 memcpy(&tcp_ses->dstaddr, &volume_info->dstaddr,
2182 sizeof(tcp_ses->dstaddr));
2183 /* 1803 /*
2184 * at this point we are the only ones with the pointer 1804 * at this point we are the only ones with the pointer
2185 * to the struct since the kernel thread not created yet 1805 * to the struct since the kernel thread not created yet
2186 * no need to spinlock this init of tcpStatus or srv_count 1806 * no need to spinlock this init of tcpStatus or srv_count
2187 */ 1807 */
2188 tcp_ses->tcpStatus = CifsNew; 1808 tcp_ses->tcpStatus = CifsNew;
1809 memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr,
1810 sizeof(tcp_ses->srcaddr));
2189 ++tcp_ses->srv_count; 1811 ++tcp_ses->srv_count;
2190 1812
1813 if (addr.ss_family == AF_INET6) {
1814 cFYI(1, "attempting ipv6 connect");
1815 /* BB should we allow ipv6 on port 139? */
1816 /* other OS never observed in Wild doing 139 with v6 */
1817 memcpy(&tcp_ses->dstaddr, sin_server6,
1818 sizeof(struct sockaddr_in6));
1819 } else
1820 memcpy(&tcp_ses->dstaddr, sin_server,
1821 sizeof(struct sockaddr_in));
1822
2191 rc = ip_connect(tcp_ses); 1823 rc = ip_connect(tcp_ses);
2192 if (rc < 0) { 1824 if (rc < 0) {
2193 cERROR(1, "Error connecting to socket. Aborting operation"); 1825 cERROR(1, "Error connecting to socket. Aborting operation");
@@ -2217,7 +1849,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
2217 cifs_fscache_get_client_cookie(tcp_ses); 1849 cifs_fscache_get_client_cookie(tcp_ses);
2218 1850
2219 /* queue echo request delayed work */ 1851 /* queue echo request delayed work */
2220 queue_delayed_work(cifsiod_wq, &tcp_ses->echo, SMB_ECHO_INTERVAL); 1852 queue_delayed_work(system_nrt_wq, &tcp_ses->echo, SMB_ECHO_INTERVAL);
2221 1853
2222 return tcp_ses; 1854 return tcp_ses;
2223 1855
@@ -2245,16 +1877,10 @@ static int match_session(struct cifs_ses *ses, struct smb_vol *vol)
2245 return 0; 1877 return 0;
2246 break; 1878 break;
2247 default: 1879 default:
2248 /* NULL username means anonymous session */
2249 if (ses->user_name == NULL) {
2250 if (!vol->nullauth)
2251 return 0;
2252 break;
2253 }
2254
2255 /* anything else takes username/password */ 1880 /* anything else takes username/password */
2256 if (strncmp(ses->user_name, 1881 if (ses->user_name == NULL)
2257 vol->username ? vol->username : "", 1882 return 0;
1883 if (strncmp(ses->user_name, vol->username,
2258 MAX_USERNAME_SIZE)) 1884 MAX_USERNAME_SIZE))
2259 return 0; 1885 return 0;
2260 if (strlen(vol->username) != 0 && 1886 if (strlen(vol->username) != 0 &&
@@ -2287,10 +1913,10 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
2287static void 1913static void
2288cifs_put_smb_ses(struct cifs_ses *ses) 1914cifs_put_smb_ses(struct cifs_ses *ses)
2289{ 1915{
2290 unsigned int xid; 1916 int xid;
2291 struct TCP_Server_Info *server = ses->server; 1917 struct TCP_Server_Info *server = ses->server;
2292 1918
2293 cFYI(1, "%s: ses_count=%d", __func__, ses->ses_count); 1919 cFYI(1, "%s: ses_count=%d\n", __func__, ses->ses_count);
2294 spin_lock(&cifs_tcp_ses_lock); 1920 spin_lock(&cifs_tcp_ses_lock);
2295 if (--ses->ses_count > 0) { 1921 if (--ses->ses_count > 0) {
2296 spin_unlock(&cifs_tcp_ses_lock); 1922 spin_unlock(&cifs_tcp_ses_lock);
@@ -2300,151 +1926,26 @@ cifs_put_smb_ses(struct cifs_ses *ses)
2300 list_del_init(&ses->smb_ses_list); 1926 list_del_init(&ses->smb_ses_list);
2301 spin_unlock(&cifs_tcp_ses_lock); 1927 spin_unlock(&cifs_tcp_ses_lock);
2302 1928
2303 if (ses->status == CifsGood && server->ops->logoff) { 1929 if (ses->status == CifsGood) {
2304 xid = get_xid(); 1930 xid = GetXid();
2305 server->ops->logoff(xid, ses); 1931 CIFSSMBLogoff(xid, ses);
2306 _free_xid(xid); 1932 _FreeXid(xid);
2307 } 1933 }
2308 sesInfoFree(ses); 1934 sesInfoFree(ses);
2309 cifs_put_tcp_session(server); 1935 cifs_put_tcp_session(server);
2310} 1936}
2311 1937
2312#ifdef CONFIG_KEYS 1938static bool warned_on_ntlm; /* globals init to false automatically */
2313
2314/* strlen("cifs:a:") + INET6_ADDRSTRLEN + 1 */
2315#define CIFSCREDS_DESC_SIZE (7 + INET6_ADDRSTRLEN + 1)
2316
2317/* Populate username and pw fields from keyring if possible */
2318static int
2319cifs_set_cifscreds(struct smb_vol *vol, struct cifs_ses *ses)
2320{
2321 int rc = 0;
2322 char *desc, *delim, *payload;
2323 ssize_t len;
2324 struct key *key;
2325 struct TCP_Server_Info *server = ses->server;
2326 struct sockaddr_in *sa;
2327 struct sockaddr_in6 *sa6;
2328 struct user_key_payload *upayload;
2329
2330 desc = kmalloc(CIFSCREDS_DESC_SIZE, GFP_KERNEL);
2331 if (!desc)
2332 return -ENOMEM;
2333
2334 /* try to find an address key first */
2335 switch (server->dstaddr.ss_family) {
2336 case AF_INET:
2337 sa = (struct sockaddr_in *)&server->dstaddr;
2338 sprintf(desc, "cifs:a:%pI4", &sa->sin_addr.s_addr);
2339 break;
2340 case AF_INET6:
2341 sa6 = (struct sockaddr_in6 *)&server->dstaddr;
2342 sprintf(desc, "cifs:a:%pI6c", &sa6->sin6_addr.s6_addr);
2343 break;
2344 default:
2345 cFYI(1, "Bad ss_family (%hu)", server->dstaddr.ss_family);
2346 rc = -EINVAL;
2347 goto out_err;
2348 }
2349
2350 cFYI(1, "%s: desc=%s", __func__, desc);
2351 key = request_key(&key_type_logon, desc, "");
2352 if (IS_ERR(key)) {
2353 if (!ses->domainName) {
2354 cFYI(1, "domainName is NULL");
2355 rc = PTR_ERR(key);
2356 goto out_err;
2357 }
2358
2359 /* didn't work, try to find a domain key */
2360 sprintf(desc, "cifs:d:%s", ses->domainName);
2361 cFYI(1, "%s: desc=%s", __func__, desc);
2362 key = request_key(&key_type_logon, desc, "");
2363 if (IS_ERR(key)) {
2364 rc = PTR_ERR(key);
2365 goto out_err;
2366 }
2367 }
2368
2369 down_read(&key->sem);
2370 upayload = key->payload.data;
2371 if (IS_ERR_OR_NULL(upayload)) {
2372 rc = upayload ? PTR_ERR(upayload) : -EINVAL;
2373 goto out_key_put;
2374 }
2375
2376 /* find first : in payload */
2377 payload = (char *)upayload->data;
2378 delim = strnchr(payload, upayload->datalen, ':');
2379 cFYI(1, "payload=%s", payload);
2380 if (!delim) {
2381 cFYI(1, "Unable to find ':' in payload (datalen=%d)",
2382 upayload->datalen);
2383 rc = -EINVAL;
2384 goto out_key_put;
2385 }
2386
2387 len = delim - payload;
2388 if (len > MAX_USERNAME_SIZE || len <= 0) {
2389 cFYI(1, "Bad value from username search (len=%zd)", len);
2390 rc = -EINVAL;
2391 goto out_key_put;
2392 }
2393
2394 vol->username = kstrndup(payload, len, GFP_KERNEL);
2395 if (!vol->username) {
2396 cFYI(1, "Unable to allocate %zd bytes for username", len);
2397 rc = -ENOMEM;
2398 goto out_key_put;
2399 }
2400 cFYI(1, "%s: username=%s", __func__, vol->username);
2401
2402 len = key->datalen - (len + 1);
2403 if (len > MAX_PASSWORD_SIZE || len <= 0) {
2404 cFYI(1, "Bad len for password search (len=%zd)", len);
2405 rc = -EINVAL;
2406 kfree(vol->username);
2407 vol->username = NULL;
2408 goto out_key_put;
2409 }
2410
2411 ++delim;
2412 vol->password = kstrndup(delim, len, GFP_KERNEL);
2413 if (!vol->password) {
2414 cFYI(1, "Unable to allocate %zd bytes for password", len);
2415 rc = -ENOMEM;
2416 kfree(vol->username);
2417 vol->username = NULL;
2418 goto out_key_put;
2419 }
2420
2421out_key_put:
2422 up_read(&key->sem);
2423 key_put(key);
2424out_err:
2425 kfree(desc);
2426 cFYI(1, "%s: returning %d", __func__, rc);
2427 return rc;
2428}
2429#else /* ! CONFIG_KEYS */
2430static inline int
2431cifs_set_cifscreds(struct smb_vol *vol __attribute__((unused)),
2432 struct cifs_ses *ses __attribute__((unused)))
2433{
2434 return -ENOSYS;
2435}
2436#endif /* CONFIG_KEYS */
2437 1939
2438static struct cifs_ses * 1940static struct cifs_ses *
2439cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) 1941cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
2440{ 1942{
2441 int rc = -ENOMEM; 1943 int rc = -ENOMEM, xid;
2442 unsigned int xid;
2443 struct cifs_ses *ses; 1944 struct cifs_ses *ses;
2444 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; 1945 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
2445 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; 1946 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr;
2446 1947
2447 xid = get_xid(); 1948 xid = GetXid();
2448 1949
2449 ses = cifs_find_smb_ses(server, volume_info); 1950 ses = cifs_find_smb_ses(server, volume_info);
2450 if (ses) { 1951 if (ses) {
@@ -2456,7 +1957,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
2456 mutex_unlock(&ses->session_mutex); 1957 mutex_unlock(&ses->session_mutex);
2457 /* problem -- put our ses reference */ 1958 /* problem -- put our ses reference */
2458 cifs_put_smb_ses(ses); 1959 cifs_put_smb_ses(ses);
2459 free_xid(xid); 1960 FreeXid(xid);
2460 return ERR_PTR(rc); 1961 return ERR_PTR(rc);
2461 } 1962 }
2462 if (ses->need_reconnect) { 1963 if (ses->need_reconnect) {
@@ -2467,7 +1968,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
2467 mutex_unlock(&ses->session_mutex); 1968 mutex_unlock(&ses->session_mutex);
2468 /* problem -- put our reference */ 1969 /* problem -- put our reference */
2469 cifs_put_smb_ses(ses); 1970 cifs_put_smb_ses(ses);
2470 free_xid(xid); 1971 FreeXid(xid);
2471 return ERR_PTR(rc); 1972 return ERR_PTR(rc);
2472 } 1973 }
2473 } 1974 }
@@ -2475,7 +1976,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
2475 1976
2476 /* existing SMB ses has a server reference already */ 1977 /* existing SMB ses has a server reference already */
2477 cifs_put_tcp_session(server); 1978 cifs_put_tcp_session(server);
2478 free_xid(xid); 1979 FreeXid(xid);
2479 return ses; 1980 return ses;
2480 } 1981 }
2481 1982
@@ -2511,6 +2012,14 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
2511 ses->cred_uid = volume_info->cred_uid; 2012 ses->cred_uid = volume_info->cred_uid;
2512 ses->linux_uid = volume_info->linux_uid; 2013 ses->linux_uid = volume_info->linux_uid;
2513 2014
2015 /* ntlmv2 is much stronger than ntlm security, and has been broadly
2016 supported for many years, time to update default security mechanism */
2017 if ((volume_info->secFlg == 0) && warned_on_ntlm == false) {
2018 warned_on_ntlm = true;
2019 cERROR(1, "default security mechanism requested. The default "
2020 "security mechanism will be upgraded from ntlm to "
2021 "ntlmv2 in kernel release 3.2");
2022 }
2514 ses->overrideSecFlg = volume_info->secFlg; 2023 ses->overrideSecFlg = volume_info->secFlg;
2515 2024
2516 mutex_lock(&ses->session_mutex); 2025 mutex_lock(&ses->session_mutex);
@@ -2526,12 +2035,12 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
2526 list_add(&ses->smb_ses_list, &server->smb_ses_list); 2035 list_add(&ses->smb_ses_list, &server->smb_ses_list);
2527 spin_unlock(&cifs_tcp_ses_lock); 2036 spin_unlock(&cifs_tcp_ses_lock);
2528 2037
2529 free_xid(xid); 2038 FreeXid(xid);
2530 return ses; 2039 return ses;
2531 2040
2532get_ses_fail: 2041get_ses_fail:
2533 sesInfoFree(ses); 2042 sesInfoFree(ses);
2534 free_xid(xid); 2043 FreeXid(xid);
2535 return ERR_PTR(rc); 2044 return ERR_PTR(rc);
2536} 2045}
2537 2046
@@ -2566,10 +2075,10 @@ cifs_find_tcon(struct cifs_ses *ses, const char *unc)
2566static void 2075static void
2567cifs_put_tcon(struct cifs_tcon *tcon) 2076cifs_put_tcon(struct cifs_tcon *tcon)
2568{ 2077{
2569 unsigned int xid; 2078 int xid;
2570 struct cifs_ses *ses = tcon->ses; 2079 struct cifs_ses *ses = tcon->ses;
2571 2080
2572 cFYI(1, "%s: tc_count=%d", __func__, tcon->tc_count); 2081 cFYI(1, "%s: tc_count=%d\n", __func__, tcon->tc_count);
2573 spin_lock(&cifs_tcp_ses_lock); 2082 spin_lock(&cifs_tcp_ses_lock);
2574 if (--tcon->tc_count > 0) { 2083 if (--tcon->tc_count > 0) {
2575 spin_unlock(&cifs_tcp_ses_lock); 2084 spin_unlock(&cifs_tcp_ses_lock);
@@ -2579,10 +2088,9 @@ cifs_put_tcon(struct cifs_tcon *tcon)
2579 list_del_init(&tcon->tcon_list); 2088 list_del_init(&tcon->tcon_list);
2580 spin_unlock(&cifs_tcp_ses_lock); 2089 spin_unlock(&cifs_tcp_ses_lock);
2581 2090
2582 xid = get_xid(); 2091 xid = GetXid();
2583 if (ses->server->ops->tree_disconnect) 2092 CIFSSMBTDis(xid, tcon);
2584 ses->server->ops->tree_disconnect(xid, tcon); 2093 _FreeXid(xid);
2585 _free_xid(xid);
2586 2094
2587 cifs_fscache_release_super_cookie(tcon); 2095 cifs_fscache_release_super_cookie(tcon);
2588 tconInfoFree(tcon); 2096 tconInfoFree(tcon);
@@ -2606,11 +2114,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
2606 return tcon; 2114 return tcon;
2607 } 2115 }
2608 2116
2609 if (!ses->server->ops->tree_connect) {
2610 rc = -ENOSYS;
2611 goto out_fail;
2612 }
2613
2614 tcon = tconInfoAlloc(); 2117 tcon = tconInfoAlloc();
2615 if (tcon == NULL) { 2118 if (tcon == NULL) {
2616 rc = -ENOMEM; 2119 rc = -ENOMEM;
@@ -2626,15 +2129,20 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
2626 } 2129 }
2627 } 2130 }
2628 2131
2629 /* 2132 if (strchr(volume_info->UNC + 3, '\\') == NULL
2630 * BB Do we need to wrap session_mutex around this TCon call and Unix 2133 && strchr(volume_info->UNC + 3, '/') == NULL) {
2631 * SetFS as we do on SessSetup and reconnect? 2134 cERROR(1, "Missing share name");
2632 */ 2135 rc = -ENODEV;
2633 xid = get_xid(); 2136 goto out_fail;
2634 rc = ses->server->ops->tree_connect(xid, ses, volume_info->UNC, tcon, 2137 }
2635 volume_info->local_nls); 2138
2636 free_xid(xid); 2139 /* BB Do we need to wrap session_mutex around
2637 cFYI(1, "Tcon rc = %d", rc); 2140 * this TCon call and Unix SetFS as
2141 * we do on SessSetup and reconnect? */
2142 xid = GetXid();
2143 rc = CIFSTCon(xid, ses, volume_info->UNC, tcon, volume_info->local_nls);
2144 FreeXid(xid);
2145 cFYI(1, "CIFS Tcon rc = %d", rc);
2638 if (rc) 2146 if (rc)
2639 goto out_fail; 2147 goto out_fail;
2640 2148
@@ -2643,15 +2151,13 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
2643 cFYI(1, "DFS disabled (%d)", tcon->Flags); 2151 cFYI(1, "DFS disabled (%d)", tcon->Flags);
2644 } 2152 }
2645 tcon->seal = volume_info->seal; 2153 tcon->seal = volume_info->seal;
2646 /* 2154 /* we can have only one retry value for a connection
2647 * We can have only one retry value for a connection to a share so for 2155 to a share so for resources mounted more than once
2648 * resources mounted more than once to the same server share the last 2156 to the same server share the last value passed in
2649 * value passed in for the retry flag is used. 2157 for the retry flag is used */
2650 */
2651 tcon->retry = volume_info->retry; 2158 tcon->retry = volume_info->retry;
2652 tcon->nocase = volume_info->nocase; 2159 tcon->nocase = volume_info->nocase;
2653 tcon->local_lease = volume_info->local_lease; 2160 tcon->local_lease = volume_info->local_lease;
2654 INIT_LIST_HEAD(&tcon->pending_opens);
2655 2161
2656 spin_lock(&cifs_tcp_ses_lock); 2162 spin_lock(&cifs_tcp_ses_lock);
2657 list_add(&tcon->tcon_list, &ses->tcon_list); 2163 list_add(&tcon->tcon_list, &ses->tcon_list);
@@ -2703,16 +2209,16 @@ compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data)
2703 (new->mnt_cifs_flags & CIFS_MOUNT_MASK)) 2209 (new->mnt_cifs_flags & CIFS_MOUNT_MASK))
2704 return 0; 2210 return 0;
2705 2211
2212 if (old->rsize != new->rsize)
2213 return 0;
2214
2706 /* 2215 /*
2707 * We want to share sb only if we don't specify an r/wsize or 2216 * We want to share sb only if we don't specify wsize or specified wsize
2708 * specified r/wsize is greater than or equal to existing one. 2217 * is greater or equal than existing one.
2709 */ 2218 */
2710 if (new->wsize && new->wsize < old->wsize) 2219 if (new->wsize && new->wsize < old->wsize)
2711 return 0; 2220 return 0;
2712 2221
2713 if (new->rsize && new->rsize < old->rsize)
2714 return 0;
2715
2716 if (old->mnt_uid != new->mnt_uid || old->mnt_gid != new->mnt_gid) 2222 if (old->mnt_uid != new->mnt_uid || old->mnt_gid != new->mnt_gid)
2717 return 0; 2223 return 0;
2718 2224
@@ -2739,8 +2245,11 @@ cifs_match_super(struct super_block *sb, void *data)
2739 struct cifs_ses *ses; 2245 struct cifs_ses *ses;
2740 struct cifs_tcon *tcon; 2246 struct cifs_tcon *tcon;
2741 struct tcon_link *tlink; 2247 struct tcon_link *tlink;
2248 struct sockaddr_storage addr;
2742 int rc = 0; 2249 int rc = 0;
2743 2250
2251 memset(&addr, 0, sizeof(struct sockaddr_storage));
2252
2744 spin_lock(&cifs_tcp_ses_lock); 2253 spin_lock(&cifs_tcp_ses_lock);
2745 cifs_sb = CIFS_SB(sb); 2254 cifs_sb = CIFS_SB(sb);
2746 tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb)); 2255 tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
@@ -2754,7 +2263,17 @@ cifs_match_super(struct super_block *sb, void *data)
2754 2263
2755 volume_info = mnt_data->vol; 2264 volume_info = mnt_data->vol;
2756 2265
2757 if (!match_server(tcp_srv, volume_info) || 2266 if (!volume_info->UNCip || !volume_info->UNC)
2267 goto out;
2268
2269 rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
2270 volume_info->UNCip,
2271 strlen(volume_info->UNCip),
2272 volume_info->port);
2273 if (!rc)
2274 goto out;
2275
2276 if (!match_server(tcp_srv, (struct sockaddr *)&addr, volume_info) ||
2758 !match_session(ses, volume_info) || 2277 !match_session(ses, volume_info) ||
2759 !match_tcon(tcon, volume_info->UNC)) { 2278 !match_tcon(tcon, volume_info->UNC)) {
2760 rc = 0; 2279 rc = 0;
@@ -2769,42 +2288,37 @@ out:
2769} 2288}
2770 2289
2771int 2290int
2772get_dfs_path(const unsigned int xid, struct cifs_ses *ses, const char *old_path, 2291get_dfs_path(int xid, struct cifs_ses *pSesInfo, const char *old_path,
2773 const struct nls_table *nls_codepage, unsigned int *num_referrals, 2292 const struct nls_table *nls_codepage, unsigned int *pnum_referrals,
2774 struct dfs_info3_param **referrals, int remap) 2293 struct dfs_info3_param **preferrals, int remap)
2775{ 2294{
2776 char *temp_unc; 2295 char *temp_unc;
2777 int rc = 0; 2296 int rc = 0;
2778 2297
2779 if (!ses->server->ops->tree_connect || !ses->server->ops->get_dfs_refer) 2298 *pnum_referrals = 0;
2780 return -ENOSYS; 2299 *preferrals = NULL;
2781
2782 *num_referrals = 0;
2783 *referrals = NULL;
2784 2300
2785 if (ses->ipc_tid == 0) { 2301 if (pSesInfo->ipc_tid == 0) {
2786 temp_unc = kmalloc(2 /* for slashes */ + 2302 temp_unc = kmalloc(2 /* for slashes */ +
2787 strnlen(ses->serverName, SERVER_NAME_LEN_WITH_NULL * 2) 2303 strnlen(pSesInfo->serverName,
2788 + 1 + 4 /* slash IPC$ */ + 2, GFP_KERNEL); 2304 SERVER_NAME_LEN_WITH_NULL * 2)
2305 + 1 + 4 /* slash IPC$ */ + 2,
2306 GFP_KERNEL);
2789 if (temp_unc == NULL) 2307 if (temp_unc == NULL)
2790 return -ENOMEM; 2308 return -ENOMEM;
2791 temp_unc[0] = '\\'; 2309 temp_unc[0] = '\\';
2792 temp_unc[1] = '\\'; 2310 temp_unc[1] = '\\';
2793 strcpy(temp_unc + 2, ses->serverName); 2311 strcpy(temp_unc + 2, pSesInfo->serverName);
2794 strcpy(temp_unc + 2 + strlen(ses->serverName), "\\IPC$"); 2312 strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$");
2795 rc = ses->server->ops->tree_connect(xid, ses, temp_unc, NULL, 2313 rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage);
2796 nls_codepage); 2314 cFYI(1, "CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid);
2797 cFYI(1, "Tcon rc = %d ipc_tid = %d", rc, ses->ipc_tid);
2798 kfree(temp_unc); 2315 kfree(temp_unc);
2799 } 2316 }
2800 if (rc == 0) 2317 if (rc == 0)
2801 rc = ses->server->ops->get_dfs_refer(xid, ses, old_path, 2318 rc = CIFSGetDFSRefer(xid, pSesInfo, old_path, preferrals,
2802 referrals, num_referrals, 2319 pnum_referrals, nls_codepage, remap);
2803 nls_codepage, remap); 2320 /* BB map targetUNCs to dfs_info3 structures, here or
2804 /* 2321 in CIFSGetDFSRefer BB */
2805 * BB - map targetUNCs to dfs_info3 structures, here or in
2806 * ses->server->ops->get_dfs_refer.
2807 */
2808 2322
2809 return rc; 2323 return rc;
2810} 2324}
@@ -2873,11 +2387,11 @@ bind_socket(struct TCP_Server_Info *server)
2873 saddr6 = (struct sockaddr_in6 *)&server->srcaddr; 2387 saddr6 = (struct sockaddr_in6 *)&server->srcaddr;
2874 if (saddr6->sin6_family == AF_INET6) 2388 if (saddr6->sin6_family == AF_INET6)
2875 cERROR(1, "cifs: " 2389 cERROR(1, "cifs: "
2876 "Failed to bind to: %pI6c, error: %d", 2390 "Failed to bind to: %pI6c, error: %d\n",
2877 &saddr6->sin6_addr, rc); 2391 &saddr6->sin6_addr, rc);
2878 else 2392 else
2879 cERROR(1, "cifs: " 2393 cERROR(1, "cifs: "
2880 "Failed to bind to: %pI4, error: %d", 2394 "Failed to bind to: %pI4, error: %d\n",
2881 &saddr4->sin_addr.s_addr, rc); 2395 &saddr4->sin_addr.s_addr, rc);
2882 } 2396 }
2883 } 2397 }
@@ -3073,7 +2587,7 @@ ip_connect(struct TCP_Server_Info *server)
3073 return generic_ip_connect(server); 2587 return generic_ip_connect(server);
3074} 2588}
3075 2589
3076void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, 2590void reset_cifs_unix_caps(int xid, struct cifs_tcon *tcon,
3077 struct cifs_sb_info *cifs_sb, struct smb_vol *vol_info) 2591 struct cifs_sb_info *cifs_sb, struct smb_vol *vol_info)
3078{ 2592{
3079 /* if we are reconnecting then should we check to see if 2593 /* if we are reconnecting then should we check to see if
@@ -3142,6 +2656,14 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
3142 CIFS_MOUNT_POSIX_PATHS; 2656 CIFS_MOUNT_POSIX_PATHS;
3143 } 2657 }
3144 2658
2659 if (cifs_sb && (cifs_sb->rsize > 127 * 1024)) {
2660 if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) {
2661 cifs_sb->rsize = 127 * 1024;
2662 cFYI(DBG2, "larger reads not supported by srv");
2663 }
2664 }
2665
2666
3145 cFYI(1, "Negotiate caps 0x%x", (int)cap); 2667 cFYI(1, "Negotiate caps 0x%x", (int)cap);
3146#ifdef CONFIG_CIFS_DEBUG2 2668#ifdef CONFIG_CIFS_DEBUG2
3147 if (cap & CIFS_UNIX_FCNTL_CAP) 2669 if (cap & CIFS_UNIX_FCNTL_CAP)
@@ -3168,9 +2690,9 @@ void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
3168 cFYI(1, "resetting capabilities failed"); 2690 cFYI(1, "resetting capabilities failed");
3169 } else 2691 } else
3170 cERROR(1, "Negotiating Unix capabilities " 2692 cERROR(1, "Negotiating Unix capabilities "
3171 "with the server failed. Consider " 2693 "with the server failed. Consider "
3172 "mounting with the Unix Extensions " 2694 "mounting with the Unix Extensions\n"
3173 "disabled if problems are found " 2695 "disabled, if problems are found, "
3174 "by specifying the nounix mount " 2696 "by specifying the nounix mount "
3175 "option."); 2697 "option.");
3176 2698
@@ -3186,18 +2708,34 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
3186 spin_lock_init(&cifs_sb->tlink_tree_lock); 2708 spin_lock_init(&cifs_sb->tlink_tree_lock);
3187 cifs_sb->tlink_tree = RB_ROOT; 2709 cifs_sb->tlink_tree = RB_ROOT;
3188 2710
2711 if (pvolume_info->rsize > CIFSMaxBufSize) {
2712 cERROR(1, "rsize %d too large, using MaxBufSize",
2713 pvolume_info->rsize);
2714 cifs_sb->rsize = CIFSMaxBufSize;
2715 } else if ((pvolume_info->rsize) &&
2716 (pvolume_info->rsize <= CIFSMaxBufSize))
2717 cifs_sb->rsize = pvolume_info->rsize;
2718 else /* default */
2719 cifs_sb->rsize = CIFSMaxBufSize;
2720
2721 if (cifs_sb->rsize < 2048) {
2722 cifs_sb->rsize = 2048;
2723 /* Windows ME may prefer this */
2724 cFYI(1, "readsize set to minimum: 2048");
2725 }
2726
3189 /* 2727 /*
3190 * Temporarily set r/wsize for matching superblock. If we end up using 2728 * Temporarily set wsize for matching superblock. If we end up using
3191 * new sb then client will later negotiate it downward if needed. 2729 * new sb then cifs_negotiate_wsize will later negotiate it downward
2730 * if needed.
3192 */ 2731 */
3193 cifs_sb->rsize = pvolume_info->rsize;
3194 cifs_sb->wsize = pvolume_info->wsize; 2732 cifs_sb->wsize = pvolume_info->wsize;
3195 2733
3196 cifs_sb->mnt_uid = pvolume_info->linux_uid; 2734 cifs_sb->mnt_uid = pvolume_info->linux_uid;
3197 cifs_sb->mnt_gid = pvolume_info->linux_gid; 2735 cifs_sb->mnt_gid = pvolume_info->linux_gid;
3198 cifs_sb->mnt_file_mode = pvolume_info->file_mode; 2736 cifs_sb->mnt_file_mode = pvolume_info->file_mode;
3199 cifs_sb->mnt_dir_mode = pvolume_info->dir_mode; 2737 cifs_sb->mnt_dir_mode = pvolume_info->dir_mode;
3200 cFYI(1, "file mode: 0x%hx dir mode: 0x%hx", 2738 cFYI(1, "file mode: 0x%x dir mode: 0x%x",
3201 cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode); 2739 cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode);
3202 2740
3203 cifs_sb->actimeo = pvolume_info->actimeo; 2741 cifs_sb->actimeo = pvolume_info->actimeo;
@@ -3225,14 +2763,6 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
3225 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD; 2763 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
3226 if (pvolume_info->cifs_acl) 2764 if (pvolume_info->cifs_acl)
3227 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL; 2765 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
3228 if (pvolume_info->backupuid_specified) {
3229 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPUID;
3230 cifs_sb->mnt_backupuid = pvolume_info->backupuid;
3231 }
3232 if (pvolume_info->backupgid_specified) {
3233 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_BACKUPGID;
3234 cifs_sb->mnt_backupgid = pvolume_info->backupgid;
3235 }
3236 if (pvolume_info->override_uid) 2766 if (pvolume_info->override_uid)
3237 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID; 2767 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID;
3238 if (pvolume_info->override_gid) 2768 if (pvolume_info->override_gid)
@@ -3264,12 +2794,92 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
3264 "mount option supported"); 2794 "mount option supported");
3265} 2795}
3266 2796
2797/*
2798 * When the server supports very large writes via POSIX extensions, we can
2799 * allow up to 2^24-1, minus the size of a WRITE_AND_X header, not including
2800 * the RFC1001 length.
2801 *
2802 * Note that this might make for "interesting" allocation problems during
2803 * writeback however as we have to allocate an array of pointers for the
2804 * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096.
2805 */
2806#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4)
2807
2808/*
2809 * When the server doesn't allow large posix writes, only allow a wsize of
2810 * 2^17-1 minus the size of the WRITE_AND_X header. That allows for a write up
2811 * to the maximum size described by RFC1002.
2812 */
2813#define CIFS_MAX_RFC1002_WSIZE ((1<<17) - 1 - sizeof(WRITE_REQ) + 4)
2814
2815/*
2816 * The default wsize is 1M. find_get_pages seems to return a maximum of 256
2817 * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill
2818 * a single wsize request with a single call.
2819 */
2820#define CIFS_DEFAULT_WSIZE (1024 * 1024)
2821
2822static unsigned int
2823cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)
2824{
2825 __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
2826 struct TCP_Server_Info *server = tcon->ses->server;
2827 unsigned int wsize = pvolume_info->wsize ? pvolume_info->wsize :
2828 CIFS_DEFAULT_WSIZE;
2829
2830 /* can server support 24-bit write sizes? (via UNIX extensions) */
2831 if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
2832 wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE);
2833
2834 /*
2835 * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set?
2836 * Limit it to max buffer offered by the server, minus the size of the
2837 * WRITEX header, not including the 4 byte RFC1001 length.
2838 */
2839 if (!(server->capabilities & CAP_LARGE_WRITE_X) ||
2840 (!(server->capabilities & CAP_UNIX) &&
2841 (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED))))
2842 wsize = min_t(unsigned int, wsize,
2843 server->maxBuf - sizeof(WRITE_REQ) + 4);
2844
2845 /* hard limit of CIFS_MAX_WSIZE */
2846 wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
2847
2848 return wsize;
2849}
2850
2851static int
2852is_path_accessible(int xid, struct cifs_tcon *tcon,
2853 struct cifs_sb_info *cifs_sb, const char *full_path)
2854{
2855 int rc;
2856 FILE_ALL_INFO *pfile_info;
2857
2858 pfile_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
2859 if (pfile_info == NULL)
2860 return -ENOMEM;
2861
2862 rc = CIFSSMBQPathInfo(xid, tcon, full_path, pfile_info,
2863 0 /* not legacy */, cifs_sb->local_nls,
2864 cifs_sb->mnt_cifs_flags &
2865 CIFS_MOUNT_MAP_SPECIAL_CHR);
2866
2867 if (rc == -EOPNOTSUPP || rc == -EINVAL)
2868 rc = SMBQueryInformation(xid, tcon, full_path, pfile_info,
2869 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
2870 CIFS_MOUNT_MAP_SPECIAL_CHR);
2871 kfree(pfile_info);
2872 return rc;
2873}
2874
3267static void 2875static void
3268cleanup_volume_info_contents(struct smb_vol *volume_info) 2876cleanup_volume_info_contents(struct smb_vol *volume_info)
3269{ 2877{
3270 kfree(volume_info->username); 2878 kfree(volume_info->username);
3271 kzfree(volume_info->password); 2879 kzfree(volume_info->password);
3272 kfree(volume_info->UNC); 2880 kfree(volume_info->UNC);
2881 if (volume_info->UNCip != volume_info->UNC + 2)
2882 kfree(volume_info->UNCip);
3273 kfree(volume_info->domainname); 2883 kfree(volume_info->domainname);
3274 kfree(volume_info->iocharset); 2884 kfree(volume_info->iocharset);
3275 kfree(volume_info->prepath); 2885 kfree(volume_info->prepath);
@@ -3286,16 +2896,14 @@ cifs_cleanup_volume_info(struct smb_vol *volume_info)
3286 2896
3287 2897
3288#ifdef CONFIG_CIFS_DFS_UPCALL 2898#ifdef CONFIG_CIFS_DFS_UPCALL
3289/* 2899/* build_path_to_root returns full path to root when
3290 * cifs_build_path_to_root returns full path to root when we do not have an 2900 * we do not have an exiting connection (tcon) */
3291 * exiting connection (tcon)
3292 */
3293static char * 2901static char *
3294build_unc_path_to_root(const struct smb_vol *vol, 2902build_unc_path_to_root(const struct smb_vol *vol,
3295 const struct cifs_sb_info *cifs_sb) 2903 const struct cifs_sb_info *cifs_sb)
3296{ 2904{
3297 char *full_path, *pos; 2905 char *full_path, *pos;
3298 unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0; 2906 unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
3299 unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1); 2907 unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
3300 2908
3301 full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL); 2909 full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
@@ -3306,7 +2914,6 @@ build_unc_path_to_root(const struct smb_vol *vol,
3306 pos = full_path + unc_len; 2914 pos = full_path + unc_len;
3307 2915
3308 if (pplen) { 2916 if (pplen) {
3309 *pos++ = CIFS_DIR_SEP(cifs_sb);
3310 strncpy(pos, vol->prepath, pplen); 2917 strncpy(pos, vol->prepath, pplen);
3311 pos += pplen; 2918 pos += pplen;
3312 } 2919 }
@@ -3328,7 +2935,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
3328 * determine whether there were referrals. 2935 * determine whether there were referrals.
3329 */ 2936 */
3330static int 2937static int
3331expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses, 2938expand_dfs_referral(int xid, struct cifs_ses *pSesInfo,
3332 struct smb_vol *volume_info, struct cifs_sb_info *cifs_sb, 2939 struct smb_vol *volume_info, struct cifs_sb_info *cifs_sb,
3333 int check_prefix) 2940 int check_prefix)
3334{ 2941{
@@ -3344,7 +2951,7 @@ expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses,
3344 /* For DFS paths, skip the first '\' of the UNC */ 2951 /* For DFS paths, skip the first '\' of the UNC */
3345 ref_path = check_prefix ? full_path + 1 : volume_info->UNC + 1; 2952 ref_path = check_prefix ? full_path + 1 : volume_info->UNC + 1;
3346 2953
3347 rc = get_dfs_path(xid, ses, ref_path, cifs_sb->local_nls, 2954 rc = get_dfs_path(xid, pSesInfo , ref_path, cifs_sb->local_nls,
3348 &num_referrals, &referrals, 2955 &num_referrals, &referrals,
3349 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 2956 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
3350 2957
@@ -3362,6 +2969,7 @@ expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses,
3362 mdata = NULL; 2969 mdata = NULL;
3363 } else { 2970 } else {
3364 cleanup_volume_info_contents(volume_info); 2971 cleanup_volume_info_contents(volume_info);
2972 memset(volume_info, '\0', sizeof(*volume_info));
3365 rc = cifs_setup_volume_info(volume_info, mdata, 2973 rc = cifs_setup_volume_info(volume_info, mdata,
3366 fake_devname); 2974 fake_devname);
3367 } 2975 }
@@ -3384,9 +2992,10 @@ cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
3384 return -EINVAL; 2992 return -EINVAL;
3385 2993
3386 if (volume_info->nullauth) { 2994 if (volume_info->nullauth) {
3387 cFYI(1, "Anonymous login"); 2995 cFYI(1, "null user");
3388 kfree(volume_info->username); 2996 volume_info->username = kzalloc(1, GFP_KERNEL);
3389 volume_info->username = NULL; 2997 if (volume_info->username == NULL)
2998 return -ENOMEM;
3390 } else if (volume_info->username) { 2999 } else if (volume_info->username) {
3391 /* BB fixme parse for domain name here */ 3000 /* BB fixme parse for domain name here */
3392 cFYI(1, "Username: %s", volume_info->username); 3001 cFYI(1, "Username: %s", volume_info->username);
@@ -3419,7 +3028,7 @@ cifs_get_volume_info(char *mount_data, const char *devname)
3419 int rc; 3028 int rc;
3420 struct smb_vol *volume_info; 3029 struct smb_vol *volume_info;
3421 3030
3422 volume_info = kmalloc(sizeof(struct smb_vol), GFP_KERNEL); 3031 volume_info = kzalloc(sizeof(struct smb_vol), GFP_KERNEL);
3423 if (!volume_info) 3032 if (!volume_info)
3424 return ERR_PTR(-ENOMEM); 3033 return ERR_PTR(-ENOMEM);
3425 3034
@@ -3435,11 +3044,11 @@ cifs_get_volume_info(char *mount_data, const char *devname)
3435int 3044int
3436cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info) 3045cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
3437{ 3046{
3438 int rc; 3047 int rc = 0;
3439 unsigned int xid; 3048 int xid;
3440 struct cifs_ses *ses; 3049 struct cifs_ses *pSesInfo;
3441 struct cifs_tcon *tcon; 3050 struct cifs_tcon *tcon;
3442 struct TCP_Server_Info *server; 3051 struct TCP_Server_Info *srvTcp;
3443 char *full_path; 3052 char *full_path;
3444 struct tcon_link *tlink; 3053 struct tcon_link *tlink;
3445#ifdef CONFIG_CIFS_DFS_UPCALL 3054#ifdef CONFIG_CIFS_DFS_UPCALL
@@ -3450,45 +3059,46 @@ cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
3450 if (rc) 3059 if (rc)
3451 return rc; 3060 return rc;
3452 3061
3062 cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages;
3063
3453#ifdef CONFIG_CIFS_DFS_UPCALL 3064#ifdef CONFIG_CIFS_DFS_UPCALL
3454try_mount_again: 3065try_mount_again:
3455 /* cleanup activities if we're chasing a referral */ 3066 /* cleanup activities if we're chasing a referral */
3456 if (referral_walks_count) { 3067 if (referral_walks_count) {
3457 if (tcon) 3068 if (tcon)
3458 cifs_put_tcon(tcon); 3069 cifs_put_tcon(tcon);
3459 else if (ses) 3070 else if (pSesInfo)
3460 cifs_put_smb_ses(ses); 3071 cifs_put_smb_ses(pSesInfo);
3461 3072
3462 free_xid(xid); 3073 FreeXid(xid);
3463 } 3074 }
3464#endif 3075#endif
3465 rc = 0;
3466 tcon = NULL; 3076 tcon = NULL;
3467 ses = NULL; 3077 pSesInfo = NULL;
3468 server = NULL; 3078 srvTcp = NULL;
3469 full_path = NULL; 3079 full_path = NULL;
3470 tlink = NULL; 3080 tlink = NULL;
3471 3081
3472 xid = get_xid(); 3082 xid = GetXid();
3473 3083
3474 /* get a reference to a tcp session */ 3084 /* get a reference to a tcp session */
3475 server = cifs_get_tcp_session(volume_info); 3085 srvTcp = cifs_get_tcp_session(volume_info);
3476 if (IS_ERR(server)) { 3086 if (IS_ERR(srvTcp)) {
3477 rc = PTR_ERR(server); 3087 rc = PTR_ERR(srvTcp);
3478 bdi_destroy(&cifs_sb->bdi); 3088 bdi_destroy(&cifs_sb->bdi);
3479 goto out; 3089 goto out;
3480 } 3090 }
3481 3091
3482 /* get a reference to a SMB session */ 3092 /* get a reference to a SMB session */
3483 ses = cifs_get_smb_ses(server, volume_info); 3093 pSesInfo = cifs_get_smb_ses(srvTcp, volume_info);
3484 if (IS_ERR(ses)) { 3094 if (IS_ERR(pSesInfo)) {
3485 rc = PTR_ERR(ses); 3095 rc = PTR_ERR(pSesInfo);
3486 ses = NULL; 3096 pSesInfo = NULL;
3487 goto mount_fail_check; 3097 goto mount_fail_check;
3488 } 3098 }
3489 3099
3490 /* search for existing tcon to this server share */ 3100 /* search for existing tcon to this server share */
3491 tcon = cifs_get_tcon(ses, volume_info); 3101 tcon = cifs_get_tcon(pSesInfo, volume_info);
3492 if (IS_ERR(tcon)) { 3102 if (IS_ERR(tcon)) {
3493 rc = PTR_ERR(tcon); 3103 rc = PTR_ERR(tcon);
3494 tcon = NULL; 3104 tcon = NULL;
@@ -3496,7 +3106,7 @@ try_mount_again:
3496 } 3106 }
3497 3107
3498 /* tell server which Unix caps we support */ 3108 /* tell server which Unix caps we support */
3499 if (cap_unix(tcon->ses)) { 3109 if (tcon->ses->capabilities & CAP_UNIX) {
3500 /* reset of caps checks mount to see if unix extensions 3110 /* reset of caps checks mount to see if unix extensions
3501 disabled for just this mount */ 3111 disabled for just this mount */
3502 reset_cifs_unix_caps(xid, tcon, cifs_sb, volume_info); 3112 reset_cifs_unix_caps(xid, tcon, cifs_sb, volume_info);
@@ -3509,15 +3119,21 @@ try_mount_again:
3509 } else 3119 } else
3510 tcon->unix_ext = 0; /* server does not support them */ 3120 tcon->unix_ext = 0; /* server does not support them */
3511 3121
3512 /* do not care if a following call succeed - informational */ 3122 /* do not care if following two calls succeed - informational */
3513 if (!tcon->ipc && server->ops->qfs_tcon) 3123 if (!tcon->ipc) {
3514 server->ops->qfs_tcon(xid, tcon); 3124 CIFSSMBQFSDeviceInfo(xid, tcon);
3125 CIFSSMBQFSAttributeInfo(xid, tcon);
3126 }
3515 3127
3516 cifs_sb->wsize = server->ops->negotiate_wsize(tcon, volume_info); 3128 if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) {
3517 cifs_sb->rsize = server->ops->negotiate_rsize(tcon, volume_info); 3129 cifs_sb->rsize = 1024 * 127;
3130 cFYI(DBG2, "no very large read support, rsize now 127K");
3131 }
3132 if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
3133 cifs_sb->rsize = min(cifs_sb->rsize,
3134 (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
3518 3135
3519 /* tune readahead according to rsize */ 3136 cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info);
3520 cifs_sb->bdi.ra_pages = cifs_sb->rsize / PAGE_CACHE_SIZE;
3521 3137
3522remote_path_check: 3138remote_path_check:
3523#ifdef CONFIG_CIFS_DFS_UPCALL 3139#ifdef CONFIG_CIFS_DFS_UPCALL
@@ -3529,8 +3145,8 @@ remote_path_check:
3529 * Chase the referral if found, otherwise continue normally. 3145 * Chase the referral if found, otherwise continue normally.
3530 */ 3146 */
3531 if (referral_walks_count == 0) { 3147 if (referral_walks_count == 0) {
3532 int refrc = expand_dfs_referral(xid, ses, volume_info, cifs_sb, 3148 int refrc = expand_dfs_referral(xid, pSesInfo, volume_info,
3533 false); 3149 cifs_sb, false);
3534 if (!refrc) { 3150 if (!refrc) {
3535 referral_walks_count++; 3151 referral_walks_count++;
3536 goto try_mount_again; 3152 goto try_mount_again;
@@ -3540,20 +3156,13 @@ remote_path_check:
3540 3156
3541 /* check if a whole path is not remote */ 3157 /* check if a whole path is not remote */
3542 if (!rc && tcon) { 3158 if (!rc && tcon) {
3543 if (!server->ops->is_path_accessible) { 3159 /* build_path_to_root works only when we have a valid tcon */
3544 rc = -ENOSYS;
3545 goto mount_fail_check;
3546 }
3547 /*
3548 * cifs_build_path_to_root works only when we have a valid tcon
3549 */
3550 full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon); 3160 full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
3551 if (full_path == NULL) { 3161 if (full_path == NULL) {
3552 rc = -ENOMEM; 3162 rc = -ENOMEM;
3553 goto mount_fail_check; 3163 goto mount_fail_check;
3554 } 3164 }
3555 rc = server->ops->is_path_accessible(xid, tcon, cifs_sb, 3165 rc = is_path_accessible(xid, tcon, cifs_sb, full_path);
3556 full_path);
3557 if (rc != 0 && rc != -EREMOTE) { 3166 if (rc != 0 && rc != -EREMOTE) {
3558 kfree(full_path); 3167 kfree(full_path);
3559 goto mount_fail_check; 3168 goto mount_fail_check;
@@ -3575,7 +3184,8 @@ remote_path_check:
3575 goto mount_fail_check; 3184 goto mount_fail_check;
3576 } 3185 }
3577 3186
3578 rc = expand_dfs_referral(xid, ses, volume_info, cifs_sb, true); 3187 rc = expand_dfs_referral(xid, pSesInfo, volume_info, cifs_sb,
3188 true);
3579 3189
3580 if (!rc) { 3190 if (!rc) {
3581 referral_walks_count++; 3191 referral_walks_count++;
@@ -3597,7 +3207,7 @@ remote_path_check:
3597 goto mount_fail_check; 3207 goto mount_fail_check;
3598 } 3208 }
3599 3209
3600 tlink->tl_uid = ses->linux_uid; 3210 tlink->tl_uid = pSesInfo->linux_uid;
3601 tlink->tl_tcon = tcon; 3211 tlink->tl_tcon = tcon;
3602 tlink->tl_time = jiffies; 3212 tlink->tl_time = jiffies;
3603 set_bit(TCON_LINK_MASTER, &tlink->tl_flags); 3213 set_bit(TCON_LINK_MASTER, &tlink->tl_flags);
@@ -3608,7 +3218,7 @@ remote_path_check:
3608 tlink_rb_insert(&cifs_sb->tlink_tree, tlink); 3218 tlink_rb_insert(&cifs_sb->tlink_tree, tlink);
3609 spin_unlock(&cifs_sb->tlink_tree_lock); 3219 spin_unlock(&cifs_sb->tlink_tree_lock);
3610 3220
3611 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, 3221 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
3612 TLINK_IDLE_EXPIRE); 3222 TLINK_IDLE_EXPIRE);
3613 3223
3614mount_fail_check: 3224mount_fail_check:
@@ -3618,15 +3228,15 @@ mount_fail_check:
3618 /* up accidentally freeing someone elses tcon struct */ 3228 /* up accidentally freeing someone elses tcon struct */
3619 if (tcon) 3229 if (tcon)
3620 cifs_put_tcon(tcon); 3230 cifs_put_tcon(tcon);
3621 else if (ses) 3231 else if (pSesInfo)
3622 cifs_put_smb_ses(ses); 3232 cifs_put_smb_ses(pSesInfo);
3623 else 3233 else
3624 cifs_put_tcp_session(server); 3234 cifs_put_tcp_session(srvTcp);
3625 bdi_destroy(&cifs_sb->bdi); 3235 bdi_destroy(&cifs_sb->bdi);
3626 } 3236 }
3627 3237
3628out: 3238out:
3629 free_xid(xid); 3239 FreeXid(xid);
3630 return rc; 3240 return rc;
3631} 3241}
3632 3242
@@ -3635,7 +3245,7 @@ out:
3635 * pointer may be NULL. 3245 * pointer may be NULL.
3636 */ 3246 */
3637int 3247int
3638CIFSTCon(const unsigned int xid, struct cifs_ses *ses, 3248CIFSTCon(unsigned int xid, struct cifs_ses *ses,
3639 const char *tree, struct cifs_tcon *tcon, 3249 const char *tree, struct cifs_tcon *tcon,
3640 const struct nls_table *nls_codepage) 3250 const struct nls_table *nls_codepage)
3641{ 3251{
@@ -3660,7 +3270,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
3660 header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX, 3270 header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX,
3661 NULL /*no tid */ , 4 /*wct */ ); 3271 NULL /*no tid */ , 4 /*wct */ );
3662 3272
3663 smb_buffer->Mid = get_next_mid(ses->server); 3273 smb_buffer->Mid = GetNextMid(ses->server);
3664 smb_buffer->Uid = ses->Suid; 3274 smb_buffer->Uid = ses->Suid;
3665 pSMB = (TCONX_REQ *) smb_buffer; 3275 pSMB = (TCONX_REQ *) smb_buffer;
3666 pSMBr = (TCONX_RSP *) smb_buffer_response; 3276 pSMBr = (TCONX_RSP *) smb_buffer_response;
@@ -3691,7 +3301,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
3691 else 3301 else
3692#endif /* CIFS_WEAK_PW_HASH */ 3302#endif /* CIFS_WEAK_PW_HASH */
3693 rc = SMBNTencrypt(tcon->password, ses->server->cryptkey, 3303 rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
3694 bcc_ptr, nls_codepage); 3304 bcc_ptr);
3695 3305
3696 bcc_ptr += CIFS_AUTH_RESP_SIZE; 3306 bcc_ptr += CIFS_AUTH_RESP_SIZE;
3697 if (ses->capabilities & CAP_UNICODE) { 3307 if (ses->capabilities & CAP_UNICODE) {
@@ -3714,7 +3324,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
3714 if (ses->capabilities & CAP_UNICODE) { 3324 if (ses->capabilities & CAP_UNICODE) {
3715 smb_buffer->Flags2 |= SMBFLG2_UNICODE; 3325 smb_buffer->Flags2 |= SMBFLG2_UNICODE;
3716 length = 3326 length =
3717 cifs_strtoUTF16((__le16 *) bcc_ptr, tree, 3327 cifs_strtoUCS((__le16 *) bcc_ptr, tree,
3718 6 /* max utf8 char length in bytes */ * 3328 6 /* max utf8 char length in bytes */ *
3719 (/* server len*/ + 256 /* share len */), nls_codepage); 3329 (/* server len*/ + 256 /* share len */), nls_codepage);
3720 bcc_ptr += 2 * length; /* convert num 16 bit words to bytes */ 3330 bcc_ptr += 2 * length; /* convert num 16 bit words to bytes */
@@ -3769,7 +3379,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
3769 3379
3770 /* mostly informational -- no need to fail on error here */ 3380 /* mostly informational -- no need to fail on error here */
3771 kfree(tcon->nativeFileSystem); 3381 kfree(tcon->nativeFileSystem);
3772 tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr, 3382 tcon->nativeFileSystem = cifs_strndup_from_ucs(bcc_ptr,
3773 bytes_left, is_unicode, 3383 bytes_left, is_unicode,
3774 nls_codepage); 3384 nls_codepage);
3775 3385
@@ -3819,22 +3429,22 @@ cifs_umount(struct cifs_sb_info *cifs_sb)
3819 kfree(cifs_sb); 3429 kfree(cifs_sb);
3820} 3430}
3821 3431
3822int 3432int cifs_negotiate_protocol(unsigned int xid, struct cifs_ses *ses)
3823cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses)
3824{ 3433{
3825 int rc = 0; 3434 int rc = 0;
3826 struct TCP_Server_Info *server = ses->server; 3435 struct TCP_Server_Info *server = ses->server;
3827 3436
3828 if (!server->ops->need_neg || !server->ops->negotiate)
3829 return -ENOSYS;
3830
3831 /* only send once per connect */ 3437 /* only send once per connect */
3832 if (!server->ops->need_neg(server)) 3438 if (server->maxBuf != 0)
3833 return 0; 3439 return 0;
3834 3440
3835 set_credits(server, 1); 3441 rc = CIFSSMBNegotiate(xid, ses);
3836 3442 if (rc == -EAGAIN) {
3837 rc = server->ops->negotiate(xid, ses); 3443 /* retry only once on 1st time connection */
3444 rc = CIFSSMBNegotiate(xid, ses);
3445 if (rc == -EAGAIN)
3446 rc = -EHOSTDOWN;
3447 }
3838 if (rc == 0) { 3448 if (rc == 0) {
3839 spin_lock(&GlobalMid_Lock); 3449 spin_lock(&GlobalMid_Lock);
3840 if (server->tcpStatus == CifsNeedNegotiate) 3450 if (server->tcpStatus == CifsNeedNegotiate)
@@ -3842,29 +3452,28 @@ cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses)
3842 else 3452 else
3843 rc = -EHOSTDOWN; 3453 rc = -EHOSTDOWN;
3844 spin_unlock(&GlobalMid_Lock); 3454 spin_unlock(&GlobalMid_Lock);
3455
3845 } 3456 }
3846 3457
3847 return rc; 3458 return rc;
3848} 3459}
3849 3460
3850int 3461
3851cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, 3462int cifs_setup_session(unsigned int xid, struct cifs_ses *ses,
3852 struct nls_table *nls_info) 3463 struct nls_table *nls_info)
3853{ 3464{
3854 int rc = -ENOSYS; 3465 int rc = 0;
3855 struct TCP_Server_Info *server = ses->server; 3466 struct TCP_Server_Info *server = ses->server;
3856 3467
3857 ses->flags = 0; 3468 ses->flags = 0;
3858 ses->capabilities = server->capabilities; 3469 ses->capabilities = server->capabilities;
3859 if (linuxExtEnabled == 0) 3470 if (linuxExtEnabled == 0)
3860 ses->capabilities &= (~server->vals->cap_unix); 3471 ses->capabilities &= (~CAP_UNIX);
3861 3472
3862 cFYI(1, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d", 3473 cFYI(1, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d",
3863 server->sec_mode, server->capabilities, server->timeAdj); 3474 server->sec_mode, server->capabilities, server->timeAdj);
3864 3475
3865 if (server->ops->sess_setup) 3476 rc = CIFS_SessSetup(xid, ses, nls_info);
3866 rc = server->ops->sess_setup(xid, ses, nls_info);
3867
3868 if (rc) { 3477 if (rc) {
3869 cERROR(1, "Send error in SessSetup = %d", rc); 3478 cERROR(1, "Send error in SessSetup = %d", rc);
3870 } else { 3479 } else {
@@ -3894,43 +3503,25 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
3894 return rc; 3503 return rc;
3895} 3504}
3896 3505
3897static int
3898cifs_set_vol_auth(struct smb_vol *vol, struct cifs_ses *ses)
3899{
3900 switch (ses->server->secType) {
3901 case Kerberos:
3902 vol->secFlg = CIFSSEC_MUST_KRB5;
3903 return 0;
3904 case NTLMv2:
3905 vol->secFlg = CIFSSEC_MUST_NTLMV2;
3906 break;
3907 case NTLM:
3908 vol->secFlg = CIFSSEC_MUST_NTLM;
3909 break;
3910 case RawNTLMSSP:
3911 vol->secFlg = CIFSSEC_MUST_NTLMSSP;
3912 break;
3913 case LANMAN:
3914 vol->secFlg = CIFSSEC_MUST_LANMAN;
3915 break;
3916 }
3917
3918 return cifs_set_cifscreds(vol, ses);
3919}
3920
3921static struct cifs_tcon * 3506static struct cifs_tcon *
3922cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid) 3507cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
3923{ 3508{
3924 int rc;
3925 struct cifs_tcon *master_tcon = cifs_sb_master_tcon(cifs_sb); 3509 struct cifs_tcon *master_tcon = cifs_sb_master_tcon(cifs_sb);
3926 struct cifs_ses *ses; 3510 struct cifs_ses *ses;
3927 struct cifs_tcon *tcon = NULL; 3511 struct cifs_tcon *tcon = NULL;
3928 struct smb_vol *vol_info; 3512 struct smb_vol *vol_info;
3513 char username[28]; /* big enough for "krb50x" + hex of ULONG_MAX 6+16 */
3514 /* We used to have this as MAX_USERNAME which is */
3515 /* way too big now (256 instead of 32) */
3929 3516
3930 vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL); 3517 vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL);
3931 if (vol_info == NULL) 3518 if (vol_info == NULL) {
3932 return ERR_PTR(-ENOMEM); 3519 tcon = ERR_PTR(-ENOMEM);
3520 goto out;
3521 }
3933 3522
3523 snprintf(username, sizeof(username), "krb50x%x", fsuid);
3524 vol_info->username = username;
3934 vol_info->local_nls = cifs_sb->local_nls; 3525 vol_info->local_nls = cifs_sb->local_nls;
3935 vol_info->linux_uid = fsuid; 3526 vol_info->linux_uid = fsuid;
3936 vol_info->cred_uid = fsuid; 3527 vol_info->cred_uid = fsuid;
@@ -3940,11 +3531,8 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
3940 vol_info->local_lease = master_tcon->local_lease; 3531 vol_info->local_lease = master_tcon->local_lease;
3941 vol_info->no_linux_ext = !master_tcon->unix_ext; 3532 vol_info->no_linux_ext = !master_tcon->unix_ext;
3942 3533
3943 rc = cifs_set_vol_auth(vol_info, master_tcon->ses); 3534 /* FIXME: allow for other secFlg settings */
3944 if (rc) { 3535 vol_info->secFlg = CIFSSEC_MUST_KRB5;
3945 tcon = ERR_PTR(rc);
3946 goto out;
3947 }
3948 3536
3949 /* get a reference for the same TCP session */ 3537 /* get a reference for the same TCP session */
3950 spin_lock(&cifs_tcp_ses_lock); 3538 spin_lock(&cifs_tcp_ses_lock);
@@ -3964,11 +3552,9 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
3964 goto out; 3552 goto out;
3965 } 3553 }
3966 3554
3967 if (cap_unix(ses)) 3555 if (ses->capabilities & CAP_UNIX)
3968 reset_cifs_unix_caps(0, tcon, NULL, vol_info); 3556 reset_cifs_unix_caps(0, tcon, NULL, vol_info);
3969out: 3557out:
3970 kfree(vol_info->username);
3971 kfree(vol_info->password);
3972 kfree(vol_info); 3558 kfree(vol_info);
3973 3559
3974 return tcon; 3560 return tcon;
@@ -4161,6 +3747,6 @@ cifs_prune_tlinks(struct work_struct *work)
4161 } 3747 }
4162 spin_unlock(&cifs_sb->tlink_tree_lock); 3748 spin_unlock(&cifs_sb->tlink_tree_lock);
4163 3749
4164 queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks, 3750 queue_delayed_work(system_nrt_wq, &cifs_sb->prune_tlinks,
4165 TLINK_IDLE_EXPIRE); 3751 TLINK_IDLE_EXPIRE);
4166} 3752}
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 8719bbe0dcc..72d448bf96c 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -44,38 +44,6 @@ renew_parental_timestamps(struct dentry *direntry)
44 } while (!IS_ROOT(direntry)); 44 } while (!IS_ROOT(direntry));
45} 45}
46 46
47char *
48cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
49 struct cifs_tcon *tcon)
50{
51 int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
52 int dfsplen;
53 char *full_path = NULL;
54
55 /* if no prefix path, simply set path to the root of share to "" */
56 if (pplen == 0) {
57 full_path = kzalloc(1, GFP_KERNEL);
58 return full_path;
59 }
60
61 if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
62 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
63 else
64 dfsplen = 0;
65
66 full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
67 if (full_path == NULL)
68 return full_path;
69
70 if (dfsplen)
71 strncpy(full_path, tcon->treeName, dfsplen);
72 full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
73 strncpy(full_path + dfsplen + 1, vol->prepath, pplen);
74 convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
75 full_path[dfsplen + pplen] = 0; /* add trailing null */
76 return full_path;
77}
78
79/* Note: caller must free return buffer */ 47/* Note: caller must free return buffer */
80char * 48char *
81build_path_from_dentry(struct dentry *direntry) 49build_path_from_dentry(struct dentry *direntry)
@@ -165,148 +133,108 @@ cifs_bp_rename_retry:
165 return full_path; 133 return full_path;
166} 134}
167 135
168/*
169 * Don't allow the separator character in a path component.
170 * The VFS will not allow "/", but "\" is allowed by posix.
171 */
172static int
173check_name(struct dentry *direntry)
174{
175 struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
176 int i;
177
178 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
179 for (i = 0; i < direntry->d_name.len; i++) {
180 if (direntry->d_name.name[i] == '\\') {
181 cFYI(1, "Invalid file name");
182 return -EINVAL;
183 }
184 }
185 }
186 return 0;
187}
188
189
190/* Inode operations in similar order to how they appear in Linux file fs.h */ 136/* Inode operations in similar order to how they appear in Linux file fs.h */
191 137
192static int 138int
193cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid, 139cifs_create(struct inode *inode, struct dentry *direntry, int mode,
194 struct tcon_link *tlink, unsigned oflags, umode_t mode, 140 struct nameidata *nd)
195 __u32 *oplock, struct cifs_fid *fid, int *created)
196{ 141{
197 int rc = -ENOENT; 142 int rc = -ENOENT;
143 int xid;
198 int create_options = CREATE_NOT_DIR; 144 int create_options = CREATE_NOT_DIR;
199 int desired_access; 145 __u32 oplock = 0;
200 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 146 int oflags;
201 struct cifs_tcon *tcon = tlink_tcon(tlink); 147 /*
148 * BB below access is probably too much for mknod to request
149 * but we have to do query and setpathinfo so requesting
150 * less could fail (unless we want to request getatr and setatr
151 * permissions (only). At least for POSIX we do not have to
152 * request so much.
153 */
154 int desiredAccess = GENERIC_READ | GENERIC_WRITE;
155 __u16 fileHandle;
156 struct cifs_sb_info *cifs_sb;
157 struct tcon_link *tlink;
158 struct cifs_tcon *tcon;
202 char *full_path = NULL; 159 char *full_path = NULL;
203 FILE_ALL_INFO *buf = NULL; 160 FILE_ALL_INFO *buf = NULL;
204 struct inode *newinode = NULL; 161 struct inode *newinode = NULL;
205 int disposition; 162 int disposition = FILE_OVERWRITE_IF;
206 struct TCP_Server_Info *server = tcon->ses->server; 163
164 xid = GetXid();
165
166 cifs_sb = CIFS_SB(inode->i_sb);
167 tlink = cifs_sb_tlink(cifs_sb);
168 if (IS_ERR(tlink)) {
169 FreeXid(xid);
170 return PTR_ERR(tlink);
171 }
172 tcon = tlink_tcon(tlink);
207 173
208 *oplock = 0; 174 if (oplockEnabled)
209 if (tcon->ses->server->oplocks) 175 oplock = REQ_OPLOCK;
210 *oplock = REQ_OPLOCK; 176
177 if (nd)
178 oflags = nd->intent.open.file->f_flags;
179 else
180 oflags = O_RDONLY | O_CREAT;
211 181
212 full_path = build_path_from_dentry(direntry); 182 full_path = build_path_from_dentry(direntry);
213 if (full_path == NULL) { 183 if (full_path == NULL) {
214 rc = -ENOMEM; 184 rc = -ENOMEM;
215 goto out; 185 goto cifs_create_out;
216 } 186 }
217 187
218 if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open && 188 if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) &&
219 (CIFS_UNIX_POSIX_PATH_OPS_CAP & 189 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
220 le64_to_cpu(tcon->fsUnixInfo.Capability))) { 190 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
221 rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode, 191 rc = cifs_posix_open(full_path, &newinode,
222 oflags, oplock, &fid->netfid, xid); 192 inode->i_sb, mode, oflags, &oplock, &fileHandle, xid);
223 switch (rc) { 193 /* EIO could indicate that (posix open) operation is not
224 case 0: 194 supported, despite what server claimed in capability
225 if (newinode == NULL) { 195 negotiation. EREMOTE indicates DFS junction, which is not
226 /* query inode info */ 196 handled in posix open */
227 goto cifs_create_get_file_info; 197
228 } 198 if (rc == 0) {
229 199 if (newinode == NULL) /* query inode info */
230 if (!S_ISREG(newinode->i_mode)) {
231 /*
232 * The server may allow us to open things like
233 * FIFOs, but the client isn't set up to deal
234 * with that. If it's not a regular file, just
235 * close it and proceed as if it were a normal
236 * lookup.
237 */
238 CIFSSMBClose(xid, tcon, fid->netfid);
239 goto cifs_create_get_file_info; 200 goto cifs_create_get_file_info;
240 } 201 else /* success, no need to query */
241 /* success, no need to query */ 202 goto cifs_create_set_dentry;
242 goto cifs_create_set_dentry; 203 } else if ((rc != -EIO) && (rc != -EREMOTE) &&
243 204 (rc != -EOPNOTSUPP) && (rc != -EINVAL))
244 case -ENOENT: 205 goto cifs_create_out;
245 goto cifs_create_get_file_info; 206 /* else fallthrough to retry, using older open call, this is
246 207 case where server does not support this SMB level, and
247 case -EIO: 208 falsely claims capability (also get here for DFS case
248 case -EINVAL: 209 which should be rare for path not covered on files) */
249 /*
250 * EIO could indicate that (posix open) operation is not
251 * supported, despite what server claimed in capability
252 * negotiation.
253 *
254 * POSIX open in samba versions 3.3.1 and earlier could
255 * incorrectly fail with invalid parameter.
256 */
257 tcon->broken_posix_open = true;
258 break;
259
260 case -EREMOTE:
261 case -EOPNOTSUPP:
262 /*
263 * EREMOTE indicates DFS junction, which is not handled
264 * in posix open. If either that or op not supported
265 * returned, follow the normal lookup.
266 */
267 break;
268
269 default:
270 goto out;
271 }
272 /*
273 * fallthrough to retry, using older open call, this is case
274 * where server does not support this SMB level, and falsely
275 * claims capability (also get here for DFS case which should be
276 * rare for path not covered on files)
277 */
278 } 210 }
279 211
280 desired_access = 0; 212 if (nd) {
281 if (OPEN_FMODE(oflags) & FMODE_READ) 213 /* if the file is going to stay open, then we
282 desired_access |= GENERIC_READ; /* is this too little? */ 214 need to set the desired access properly */
283 if (OPEN_FMODE(oflags) & FMODE_WRITE) 215 desiredAccess = 0;
284 desired_access |= GENERIC_WRITE; 216 if (OPEN_FMODE(oflags) & FMODE_READ)
285 217 desiredAccess |= GENERIC_READ; /* is this too little? */
286 disposition = FILE_OVERWRITE_IF; 218 if (OPEN_FMODE(oflags) & FMODE_WRITE)
287 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) 219 desiredAccess |= GENERIC_WRITE;
288 disposition = FILE_CREATE; 220
289 else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC)) 221 if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
290 disposition = FILE_OVERWRITE_IF; 222 disposition = FILE_CREATE;
291 else if ((oflags & O_CREAT) == O_CREAT) 223 else if ((oflags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
292 disposition = FILE_OPEN_IF; 224 disposition = FILE_OVERWRITE_IF;
293 else 225 else if ((oflags & O_CREAT) == O_CREAT)
294 cFYI(1, "Create flag not set in create function"); 226 disposition = FILE_OPEN_IF;
295 227 else
296 /* 228 cFYI(1, "Create flag not set in create function");
297 * BB add processing to set equivalent of mode - e.g. via CreateX with
298 * ACLs
299 */
300
301 if (!server->ops->open) {
302 rc = -ENOSYS;
303 goto out;
304 } 229 }
305 230
231 /* BB add processing to set equivalent of mode - e.g. via CreateX with
232 ACLs */
233
306 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); 234 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
307 if (buf == NULL) { 235 if (buf == NULL) {
308 rc = -ENOMEM; 236 rc = -ENOMEM;
309 goto out; 237 goto cifs_create_out;
310 } 238 }
311 239
312 /* 240 /*
@@ -316,22 +244,29 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
316 if (!tcon->unix_ext && (mode & S_IWUGO) == 0) 244 if (!tcon->unix_ext && (mode & S_IWUGO) == 0)
317 create_options |= CREATE_OPTION_READONLY; 245 create_options |= CREATE_OPTION_READONLY;
318 246
319 if (backup_cred(cifs_sb)) 247 if (tcon->ses->capabilities & CAP_NT_SMBS)
320 create_options |= CREATE_OPEN_BACKUP_INTENT; 248 rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
321 249 desiredAccess, create_options,
322 rc = server->ops->open(xid, tcon, full_path, disposition, 250 &fileHandle, &oplock, buf, cifs_sb->local_nls,
323 desired_access, create_options, fid, oplock, 251 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
324 buf, cifs_sb); 252 else
253 rc = -EIO; /* no NT SMB support fall into legacy open below */
254
255 if (rc == -EIO) {
256 /* old server, retry the open legacy style */
257 rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
258 desiredAccess, create_options,
259 &fileHandle, &oplock, buf, cifs_sb->local_nls,
260 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
261 }
325 if (rc) { 262 if (rc) {
326 cFYI(1, "cifs_create returned 0x%x", rc); 263 cFYI(1, "cifs_create returned 0x%x", rc);
327 goto out; 264 goto cifs_create_out;
328 } 265 }
329 266
330 /* 267 /* If Open reported that we actually created a file
331 * If Open reported that we actually created a file then we now have to 268 then we now have to set the mode if possible */
332 * set the mode if possible. 269 if ((tcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) {
333 */
334 if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) {
335 struct cifs_unix_set_info_args args = { 270 struct cifs_unix_set_info_args args = {
336 .mode = mode, 271 .mode = mode,
337 .ctime = NO_CHANGE_64, 272 .ctime = NO_CHANGE_64,
@@ -340,7 +275,6 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
340 .device = 0, 275 .device = 0,
341 }; 276 };
342 277
343 *created |= FILE_CREATED;
344 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) { 278 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
345 args.uid = (__u64) current_fsuid(); 279 args.uid = (__u64) current_fsuid();
346 if (inode->i_mode & S_ISGID) 280 if (inode->i_mode & S_ISGID)
@@ -351,13 +285,11 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
351 args.uid = NO_CHANGE_64; 285 args.uid = NO_CHANGE_64;
352 args.gid = NO_CHANGE_64; 286 args.gid = NO_CHANGE_64;
353 } 287 }
354 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid, 288 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fileHandle,
355 current->tgid); 289 current->tgid);
356 } else { 290 } else {
357 /* 291 /* BB implement mode setting via Windows security
358 * BB implement mode setting via Windows security 292 descriptors e.g. */
359 * descriptors e.g.
360 */
361 /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ 293 /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/
362 294
363 /* Could set r/o dos attribute if mode & 0222 == 0 */ 295 /* Could set r/o dos attribute if mode & 0222 == 0 */
@@ -366,17 +298,15 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
366cifs_create_get_file_info: 298cifs_create_get_file_info:
367 /* server might mask mode so we have to query for it */ 299 /* server might mask mode so we have to query for it */
368 if (tcon->unix_ext) 300 if (tcon->unix_ext)
369 rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb, 301 rc = cifs_get_inode_info_unix(&newinode, full_path,
370 xid); 302 inode->i_sb, xid);
371 else { 303 else {
372 rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb, 304 rc = cifs_get_inode_info(&newinode, full_path, buf,
373 xid, &fid->netfid); 305 inode->i_sb, xid, &fileHandle);
374 if (newinode) { 306 if (newinode) {
375 if (server->ops->set_lease_key)
376 server->ops->set_lease_key(newinode, fid);
377 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) 307 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
378 newinode->i_mode = mode; 308 newinode->i_mode = mode;
379 if ((*oplock & CIFS_CREATE_ACTION) && 309 if ((oplock & CIFS_CREATE_ACTION) &&
380 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) { 310 (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) {
381 newinode->i_uid = current_fsuid(); 311 newinode->i_uid = current_fsuid();
382 if (inode->i_mode & S_ISGID) 312 if (inode->i_mode & S_ISGID)
@@ -388,167 +318,45 @@ cifs_create_get_file_info:
388 } 318 }
389 319
390cifs_create_set_dentry: 320cifs_create_set_dentry:
391 if (rc != 0) { 321 if (rc == 0)
322 d_instantiate(direntry, newinode);
323 else
392 cFYI(1, "Create worked, get_inode_info failed rc = %d", rc); 324 cFYI(1, "Create worked, get_inode_info failed rc = %d", rc);
393 if (server->ops->close)
394 server->ops->close(xid, tcon, fid);
395 goto out;
396 }
397 d_drop(direntry);
398 d_add(direntry, newinode);
399 325
400out: 326 if (newinode && nd) {
401 kfree(buf); 327 struct cifsFileInfo *pfile_info;
402 kfree(full_path); 328 struct file *filp;
403 return rc;
404}
405
406int
407cifs_atomic_open(struct inode *inode, struct dentry *direntry,
408 struct file *file, unsigned oflags, umode_t mode,
409 int *opened)
410{
411 int rc;
412 unsigned int xid;
413 struct tcon_link *tlink;
414 struct cifs_tcon *tcon;
415 struct TCP_Server_Info *server;
416 struct cifs_fid fid;
417 struct cifs_pending_open open;
418 __u32 oplock;
419 struct cifsFileInfo *file_info;
420
421 /*
422 * Posix open is only called (at lookup time) for file create now. For
423 * opens (rather than creates), because we do not know if it is a file
424 * or directory yet, and current Samba no longer allows us to do posix
425 * open on dirs, we could end up wasting an open call on what turns out
426 * to be a dir. For file opens, we wait to call posix open till
427 * cifs_open. It could be added to atomic_open in the future but the
428 * performance tradeoff of the extra network request when EISDIR or
429 * EACCES is returned would have to be weighed against the 50% reduction
430 * in network traffic in the other paths.
431 */
432 if (!(oflags & O_CREAT)) {
433 struct dentry *res;
434
435 /*
436 * Check for hashed negative dentry. We have already revalidated
437 * the dentry and it is fine. No need to perform another lookup.
438 */
439 if (!d_unhashed(direntry))
440 return -ENOENT;
441
442 res = cifs_lookup(inode, direntry, 0);
443 if (IS_ERR(res))
444 return PTR_ERR(res);
445
446 return finish_no_open(file, res);
447 }
448
449 rc = check_name(direntry);
450 if (rc)
451 return rc;
452
453 xid = get_xid();
454
455 cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p",
456 inode, direntry->d_name.name, direntry);
457
458 tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
459 if (IS_ERR(tlink))
460 goto out_free_xid;
461
462 tcon = tlink_tcon(tlink);
463 server = tcon->ses->server;
464
465 if (server->ops->new_lease_key)
466 server->ops->new_lease_key(&fid);
467
468 cifs_add_pending_open(&fid, tlink, &open);
469
470 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
471 &oplock, &fid, opened);
472 329
473 if (rc) { 330 filp = lookup_instantiate_filp(nd, direntry, generic_file_open);
474 cifs_del_pending_open(&open); 331 if (IS_ERR(filp)) {
475 goto out; 332 rc = PTR_ERR(filp);
476 } 333 CIFSSMBClose(xid, tcon, fileHandle);
477 334 goto cifs_create_out;
478 rc = finish_open(file, direntry, generic_file_open, opened); 335 }
479 if (rc) {
480 if (server->ops->close)
481 server->ops->close(xid, tcon, &fid);
482 cifs_del_pending_open(&open);
483 goto out;
484 }
485 336
486 file_info = cifs_new_fileinfo(&fid, file, tlink, oplock); 337 pfile_info = cifs_new_fileinfo(fileHandle, filp, tlink, oplock);
487 if (file_info == NULL) { 338 if (pfile_info == NULL) {
488 if (server->ops->close) 339 fput(filp);
489 server->ops->close(xid, tcon, &fid); 340 CIFSSMBClose(xid, tcon, fileHandle);
490 cifs_del_pending_open(&open); 341 rc = -ENOMEM;
491 rc = -ENOMEM; 342 }
343 } else {
344 CIFSSMBClose(xid, tcon, fileHandle);
492 } 345 }
493 346
494out: 347cifs_create_out:
495 cifs_put_tlink(tlink); 348 kfree(buf);
496out_free_xid: 349 kfree(full_path);
497 free_xid(xid);
498 return rc;
499}
500
501int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,
502 bool excl)
503{
504 int rc;
505 unsigned int xid = get_xid();
506 /*
507 * BB below access is probably too much for mknod to request
508 * but we have to do query and setpathinfo so requesting
509 * less could fail (unless we want to request getatr and setatr
510 * permissions (only). At least for POSIX we do not have to
511 * request so much.
512 */
513 unsigned oflags = O_EXCL | O_CREAT | O_RDWR;
514 struct tcon_link *tlink;
515 struct cifs_tcon *tcon;
516 struct TCP_Server_Info *server;
517 struct cifs_fid fid;
518 __u32 oplock;
519 int created = FILE_CREATED;
520
521 cFYI(1, "cifs_create parent inode = 0x%p name is: %s and dentry = 0x%p",
522 inode, direntry->d_name.name, direntry);
523
524 tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
525 rc = PTR_ERR(tlink);
526 if (IS_ERR(tlink))
527 goto out_free_xid;
528
529 tcon = tlink_tcon(tlink);
530 server = tcon->ses->server;
531
532 if (server->ops->new_lease_key)
533 server->ops->new_lease_key(&fid);
534
535 rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
536 &oplock, &fid, &created);
537 if (!rc && server->ops->close)
538 server->ops->close(xid, tcon, &fid);
539
540 cifs_put_tlink(tlink); 350 cifs_put_tlink(tlink);
541out_free_xid: 351 FreeXid(xid);
542 free_xid(xid);
543 return rc; 352 return rc;
544} 353}
545 354
546int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode, 355int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
547 dev_t device_number) 356 dev_t device_number)
548{ 357{
549 int rc = -EPERM; 358 int rc = -EPERM;
550 unsigned int xid; 359 int xid;
551 int create_options = CREATE_NOT_DIR | CREATE_OPTION_SPECIAL;
552 struct cifs_sb_info *cifs_sb; 360 struct cifs_sb_info *cifs_sb;
553 struct tcon_link *tlink; 361 struct tcon_link *tlink;
554 struct cifs_tcon *pTcon; 362 struct cifs_tcon *pTcon;
@@ -571,7 +379,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
571 379
572 pTcon = tlink_tcon(tlink); 380 pTcon = tlink_tcon(tlink);
573 381
574 xid = get_xid(); 382 xid = GetXid();
575 383
576 full_path = build_path_from_dentry(direntry); 384 full_path = build_path_from_dentry(direntry);
577 if (full_path == NULL) { 385 if (full_path == NULL) {
@@ -619,15 +427,13 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
619 if (buf == NULL) { 427 if (buf == NULL) {
620 kfree(full_path); 428 kfree(full_path);
621 rc = -ENOMEM; 429 rc = -ENOMEM;
622 free_xid(xid); 430 FreeXid(xid);
623 return rc; 431 return rc;
624 } 432 }
625 433
626 if (backup_cred(cifs_sb)) 434 /* FIXME: would WRITE_OWNER | WRITE_DAC be better? */
627 create_options |= CREATE_OPEN_BACKUP_INTENT;
628
629 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_CREATE, 435 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_CREATE,
630 GENERIC_WRITE, create_options, 436 GENERIC_WRITE, CREATE_NOT_DIR | CREATE_OPTION_SPECIAL,
631 &fileHandle, &oplock, buf, cifs_sb->local_nls, 437 &fileHandle, &oplock, buf, cifs_sb->local_nls,
632 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 438 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
633 if (rc) 439 if (rc)
@@ -669,24 +475,29 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
669mknod_out: 475mknod_out:
670 kfree(full_path); 476 kfree(full_path);
671 kfree(buf); 477 kfree(buf);
672 free_xid(xid); 478 FreeXid(xid);
673 cifs_put_tlink(tlink); 479 cifs_put_tlink(tlink);
674 return rc; 480 return rc;
675} 481}
676 482
677struct dentry * 483struct dentry *
678cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry, 484cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
679 unsigned int flags) 485 struct nameidata *nd)
680{ 486{
681 unsigned int xid; 487 int xid;
682 int rc = 0; /* to get around spurious gcc warning, set to zero here */ 488 int rc = 0; /* to get around spurious gcc warning, set to zero here */
489 __u32 oplock = 0;
490 __u16 fileHandle = 0;
491 bool posix_open = false;
683 struct cifs_sb_info *cifs_sb; 492 struct cifs_sb_info *cifs_sb;
684 struct tcon_link *tlink; 493 struct tcon_link *tlink;
685 struct cifs_tcon *pTcon; 494 struct cifs_tcon *pTcon;
495 struct cifsFileInfo *cfile;
686 struct inode *newInode = NULL; 496 struct inode *newInode = NULL;
687 char *full_path = NULL; 497 char *full_path = NULL;
498 struct file *filp;
688 499
689 xid = get_xid(); 500 xid = GetXid();
690 501
691 cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p", 502 cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p",
692 parent_dir_inode, direntry->d_name.name, direntry); 503 parent_dir_inode, direntry->d_name.name, direntry);
@@ -696,14 +507,34 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
696 cifs_sb = CIFS_SB(parent_dir_inode->i_sb); 507 cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
697 tlink = cifs_sb_tlink(cifs_sb); 508 tlink = cifs_sb_tlink(cifs_sb);
698 if (IS_ERR(tlink)) { 509 if (IS_ERR(tlink)) {
699 free_xid(xid); 510 FreeXid(xid);
700 return (struct dentry *)tlink; 511 return (struct dentry *)tlink;
701 } 512 }
702 pTcon = tlink_tcon(tlink); 513 pTcon = tlink_tcon(tlink);
703 514
704 rc = check_name(direntry); 515 /*
705 if (rc) 516 * Don't allow the separator character in a path component.
517 * The VFS will not allow "/", but "\" is allowed by posix.
518 */
519 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)) {
520 int i;
521 for (i = 0; i < direntry->d_name.len; i++)
522 if (direntry->d_name.name[i] == '\\') {
523 cFYI(1, "Invalid file name");
524 rc = -EINVAL;
525 goto lookup_out;
526 }
527 }
528
529 /*
530 * O_EXCL: optimize away the lookup, but don't hash the dentry. Let
531 * the VFS handle the create.
532 */
533 if (nd && (nd->flags & LOOKUP_EXCL)) {
534 d_instantiate(direntry, NULL);
535 rc = 0;
706 goto lookup_out; 536 goto lookup_out;
537 }
707 538
708 /* can not grab the rename sem here since it would 539 /* can not grab the rename sem here since it would
709 deadlock in the cases (beginning of sys_rename itself) 540 deadlock in the cases (beginning of sys_rename itself)
@@ -721,16 +552,64 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
721 } 552 }
722 cFYI(1, "Full path: %s inode = 0x%p", full_path, direntry->d_inode); 553 cFYI(1, "Full path: %s inode = 0x%p", full_path, direntry->d_inode);
723 554
555 /* Posix open is only called (at lookup time) for file create now.
556 * For opens (rather than creates), because we do not know if it
557 * is a file or directory yet, and current Samba no longer allows
558 * us to do posix open on dirs, we could end up wasting an open call
559 * on what turns out to be a dir. For file opens, we wait to call posix
560 * open till cifs_open. It could be added here (lookup) in the future
561 * but the performance tradeoff of the extra network request when EISDIR
562 * or EACCES is returned would have to be weighed against the 50%
563 * reduction in network traffic in the other paths.
564 */
724 if (pTcon->unix_ext) { 565 if (pTcon->unix_ext) {
725 rc = cifs_get_inode_info_unix(&newInode, full_path, 566 if (nd && !(nd->flags & LOOKUP_DIRECTORY) &&
726 parent_dir_inode->i_sb, xid); 567 (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open &&
727 } else { 568 (nd->intent.open.file->f_flags & O_CREAT)) {
569 rc = cifs_posix_open(full_path, &newInode,
570 parent_dir_inode->i_sb,
571 nd->intent.open.create_mode,
572 nd->intent.open.file->f_flags, &oplock,
573 &fileHandle, xid);
574 /*
575 * The check below works around a bug in POSIX
576 * open in samba versions 3.3.1 and earlier where
577 * open could incorrectly fail with invalid parameter.
578 * If either that or op not supported returned, follow
579 * the normal lookup.
580 */
581 if ((rc == 0) || (rc == -ENOENT))
582 posix_open = true;
583 else if ((rc == -EINVAL) || (rc != -EOPNOTSUPP))
584 pTcon->broken_posix_open = true;
585 }
586 if (!posix_open)
587 rc = cifs_get_inode_info_unix(&newInode, full_path,
588 parent_dir_inode->i_sb, xid);
589 } else
728 rc = cifs_get_inode_info(&newInode, full_path, NULL, 590 rc = cifs_get_inode_info(&newInode, full_path, NULL,
729 parent_dir_inode->i_sb, xid, NULL); 591 parent_dir_inode->i_sb, xid, NULL);
730 }
731 592
732 if ((rc == 0) && (newInode != NULL)) { 593 if ((rc == 0) && (newInode != NULL)) {
733 d_add(direntry, newInode); 594 d_add(direntry, newInode);
595 if (posix_open) {
596 filp = lookup_instantiate_filp(nd, direntry,
597 generic_file_open);
598 if (IS_ERR(filp)) {
599 rc = PTR_ERR(filp);
600 CIFSSMBClose(xid, pTcon, fileHandle);
601 goto lookup_out;
602 }
603
604 cfile = cifs_new_fileinfo(fileHandle, filp, tlink,
605 oplock);
606 if (cfile == NULL) {
607 fput(filp);
608 CIFSSMBClose(xid, pTcon, fileHandle);
609 rc = -ENOMEM;
610 goto lookup_out;
611 }
612 }
734 /* since paths are not looked up by component - the parent 613 /* since paths are not looked up by component - the parent
735 directories are presumed to be good here */ 614 directories are presumed to be good here */
736 renew_parental_timestamps(direntry); 615 renew_parental_timestamps(direntry);
@@ -750,43 +629,28 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
750lookup_out: 629lookup_out:
751 kfree(full_path); 630 kfree(full_path);
752 cifs_put_tlink(tlink); 631 cifs_put_tlink(tlink);
753 free_xid(xid); 632 FreeXid(xid);
754 return ERR_PTR(rc); 633 return ERR_PTR(rc);
755} 634}
756 635
757static int 636static int
758cifs_d_revalidate(struct dentry *direntry, unsigned int flags) 637cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
759{ 638{
760 if (flags & LOOKUP_RCU) 639 if (nd && (nd->flags & LOOKUP_RCU))
761 return -ECHILD; 640 return -ECHILD;
762 641
763 if (direntry->d_inode) { 642 if (direntry->d_inode) {
764 if (cifs_revalidate_dentry(direntry)) 643 if (cifs_revalidate_dentry(direntry))
765 return 0; 644 return 0;
766 else { 645 else
767 /*
768 * If the inode wasn't known to be a dfs entry when
769 * the dentry was instantiated, such as when created
770 * via ->readdir(), it needs to be set now since the
771 * attributes will have been updated by
772 * cifs_revalidate_dentry().
773 */
774 if (IS_AUTOMOUNT(direntry->d_inode) &&
775 !(direntry->d_flags & DCACHE_NEED_AUTOMOUNT)) {
776 spin_lock(&direntry->d_lock);
777 direntry->d_flags |= DCACHE_NEED_AUTOMOUNT;
778 spin_unlock(&direntry->d_lock);
779 }
780
781 return 1; 646 return 1;
782 }
783 } 647 }
784 648
785 /* 649 /*
786 * This may be nfsd (or something), anyway, we can't see the 650 * This may be nfsd (or something), anyway, we can't see the
787 * intent of this. So, since this can be for creation, drop it. 651 * intent of this. So, since this can be for creation, drop it.
788 */ 652 */
789 if (!flags) 653 if (!nd)
790 return 0; 654 return 0;
791 655
792 /* 656 /*
@@ -794,7 +658,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
794 * case sensitive name which is specified by user if this is 658 * case sensitive name which is specified by user if this is
795 * for creation. 659 * for creation.
796 */ 660 */
797 if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) 661 if (nd->flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
798 return 0; 662 return 0;
799 663
800 if (time_after(jiffies, direntry->d_time + HZ) || !lookupCacheEnabled) 664 if (time_after(jiffies, direntry->d_time + HZ) || !lookupCacheEnabled)
diff --git a/fs/cifs/export.c b/fs/cifs/export.c
index 9c7ecdccf2f..55d87ac5200 100644
--- a/fs/cifs/export.c
+++ b/fs/cifs/export.c
@@ -45,7 +45,7 @@
45#include "cifs_debug.h" 45#include "cifs_debug.h"
46#include "cifsfs.h" 46#include "cifsfs.h"
47 47
48#ifdef CONFIG_CIFS_NFSD_EXPORT 48#ifdef CIFS_NFSD_EXPORT
49static struct dentry *cifs_get_parent(struct dentry *dentry) 49static struct dentry *cifs_get_parent(struct dentry *dentry)
50{ 50{
51 /* BB need to add code here eventually to enable export via NFSD */ 51 /* BB need to add code here eventually to enable export via NFSD */
@@ -63,5 +63,5 @@ const struct export_operations cifs_export_ops = {
63 .encode_fs = */ 63 .encode_fs = */
64}; 64};
65 65
66#endif /* CONFIG_CIFS_NFSD_EXPORT */ 66#endif /* CIFS_NFSD_EXPORT */
67 67
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 8ea6ca50a66..9f41a10523a 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -32,7 +32,6 @@
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/mount.h> 33#include <linux/mount.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/swap.h>
36#include <asm/div64.h> 35#include <asm/div64.h>
37#include "cifsfs.h" 36#include "cifsfs.h"
38#include "cifspdu.h" 37#include "cifspdu.h"
@@ -107,7 +106,7 @@ static inline int cifs_get_disposition(unsigned int flags)
107 106
108int cifs_posix_open(char *full_path, struct inode **pinode, 107int cifs_posix_open(char *full_path, struct inode **pinode,
109 struct super_block *sb, int mode, unsigned int f_flags, 108 struct super_block *sb, int mode, unsigned int f_flags,
110 __u32 *poplock, __u16 *pnetfid, unsigned int xid) 109 __u32 *poplock, __u16 *pnetfid, int xid)
111{ 110{
112 int rc; 111 int rc;
113 FILE_UNIX_BASIC_INFO *presp_data; 112 FILE_UNIX_BASIC_INFO *presp_data;
@@ -169,20 +168,15 @@ posix_open_ret:
169 168
170static int 169static int
171cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb, 170cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
172 struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock, 171 struct cifs_tcon *tcon, unsigned int f_flags, __u32 *poplock,
173 struct cifs_fid *fid, unsigned int xid) 172 __u16 *pnetfid, int xid)
174{ 173{
175 int rc; 174 int rc;
176 int desired_access; 175 int desiredAccess;
177 int disposition; 176 int disposition;
178 int create_options = CREATE_NOT_DIR;
179 FILE_ALL_INFO *buf; 177 FILE_ALL_INFO *buf;
180 struct TCP_Server_Info *server = tcon->ses->server;
181 178
182 if (!server->ops->open) 179 desiredAccess = cifs_convert_flags(f_flags);
183 return -ENOSYS;
184
185 desired_access = cifs_convert_flags(f_flags);
186 180
187/********************************************************************* 181/*********************************************************************
188 * open flag mapping table: 182 * open flag mapping table:
@@ -216,12 +210,16 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
216 if (!buf) 210 if (!buf)
217 return -ENOMEM; 211 return -ENOMEM;
218 212
219 if (backup_cred(cifs_sb)) 213 if (tcon->ses->capabilities & CAP_NT_SMBS)
220 create_options |= CREATE_OPEN_BACKUP_INTENT; 214 rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
221 215 desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
222 rc = server->ops->open(xid, tcon, full_path, disposition, 216 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
223 desired_access, create_options, fid, oplock, buf, 217 & CIFS_MOUNT_MAP_SPECIAL_CHR);
224 cifs_sb); 218 else
219 rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
220 desiredAccess, CREATE_NOT_DIR, pnetfid, poplock, buf,
221 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
222 & CIFS_MOUNT_MAP_SPECIAL_CHR);
225 223
226 if (rc) 224 if (rc)
227 goto out; 225 goto out;
@@ -231,105 +229,52 @@ cifs_nt_open(char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
231 xid); 229 xid);
232 else 230 else
233 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb, 231 rc = cifs_get_inode_info(&inode, full_path, buf, inode->i_sb,
234 xid, &fid->netfid); 232 xid, pnetfid);
235 233
236out: 234out:
237 kfree(buf); 235 kfree(buf);
238 return rc; 236 return rc;
239} 237}
240 238
241static bool
242cifs_has_mand_locks(struct cifsInodeInfo *cinode)
243{
244 struct cifs_fid_locks *cur;
245 bool has_locks = false;
246
247 down_read(&cinode->lock_sem);
248 list_for_each_entry(cur, &cinode->llist, llist) {
249 if (!list_empty(&cur->locks)) {
250 has_locks = true;
251 break;
252 }
253 }
254 up_read(&cinode->lock_sem);
255 return has_locks;
256}
257
258struct cifsFileInfo * 239struct cifsFileInfo *
259cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, 240cifs_new_fileinfo(__u16 fileHandle, struct file *file,
260 struct tcon_link *tlink, __u32 oplock) 241 struct tcon_link *tlink, __u32 oplock)
261{ 242{
262 struct dentry *dentry = file->f_path.dentry; 243 struct dentry *dentry = file->f_path.dentry;
263 struct inode *inode = dentry->d_inode; 244 struct inode *inode = dentry->d_inode;
264 struct cifsInodeInfo *cinode = CIFS_I(inode); 245 struct cifsInodeInfo *pCifsInode = CIFS_I(inode);
265 struct cifsFileInfo *cfile; 246 struct cifsFileInfo *pCifsFile;
266 struct cifs_fid_locks *fdlocks; 247
267 struct cifs_tcon *tcon = tlink_tcon(tlink); 248 pCifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
268 struct TCP_Server_Info *server = tcon->ses->server; 249 if (pCifsFile == NULL)
269 250 return pCifsFile;
270 cfile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); 251
271 if (cfile == NULL) 252 pCifsFile->count = 1;
272 return cfile; 253 pCifsFile->netfid = fileHandle;
273 254 pCifsFile->pid = current->tgid;
274 fdlocks = kzalloc(sizeof(struct cifs_fid_locks), GFP_KERNEL); 255 pCifsFile->uid = current_fsuid();
275 if (!fdlocks) { 256 pCifsFile->dentry = dget(dentry);
276 kfree(cfile); 257 pCifsFile->f_flags = file->f_flags;
277 return NULL; 258 pCifsFile->invalidHandle = false;
278 } 259 pCifsFile->tlink = cifs_get_tlink(tlink);
279 260 mutex_init(&pCifsFile->fh_mutex);
280 INIT_LIST_HEAD(&fdlocks->locks); 261 mutex_init(&pCifsFile->lock_mutex);
281 fdlocks->cfile = cfile; 262 INIT_LIST_HEAD(&pCifsFile->llist);
282 cfile->llist = fdlocks; 263 INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break);
283 down_write(&cinode->lock_sem);
284 list_add(&fdlocks->llist, &cinode->llist);
285 up_write(&cinode->lock_sem);
286
287 cfile->count = 1;
288 cfile->pid = current->tgid;
289 cfile->uid = current_fsuid();
290 cfile->dentry = dget(dentry);
291 cfile->f_flags = file->f_flags;
292 cfile->invalidHandle = false;
293 cfile->tlink = cifs_get_tlink(tlink);
294 INIT_WORK(&cfile->oplock_break, cifs_oplock_break);
295 mutex_init(&cfile->fh_mutex);
296
297 /*
298 * If the server returned a read oplock and we have mandatory brlocks,
299 * set oplock level to None.
300 */
301 if (oplock == server->vals->oplock_read &&
302 cifs_has_mand_locks(cinode)) {
303 cFYI(1, "Reset oplock val from read to None due to mand locks");
304 oplock = 0;
305 }
306 264
307 spin_lock(&cifs_file_list_lock); 265 spin_lock(&cifs_file_list_lock);
308 if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock) 266 list_add(&pCifsFile->tlist, &(tlink_tcon(tlink)->openFileList));
309 oplock = fid->pending_open->oplock;
310 list_del(&fid->pending_open->olist);
311
312 server->ops->set_fid(cfile, fid, oplock);
313
314 list_add(&cfile->tlist, &tcon->openFileList);
315 /* if readable file instance put first in list*/ 267 /* if readable file instance put first in list*/
316 if (file->f_mode & FMODE_READ) 268 if (file->f_mode & FMODE_READ)
317 list_add(&cfile->flist, &cinode->openFileList); 269 list_add(&pCifsFile->flist, &pCifsInode->openFileList);
318 else 270 else
319 list_add_tail(&cfile->flist, &cinode->openFileList); 271 list_add_tail(&pCifsFile->flist, &pCifsInode->openFileList);
320 spin_unlock(&cifs_file_list_lock); 272 spin_unlock(&cifs_file_list_lock);
321 273
322 file->private_data = cfile; 274 cifs_set_oplock_level(pCifsInode, oplock);
323 return cfile;
324}
325 275
326struct cifsFileInfo * 276 file->private_data = pCifsFile;
327cifsFileInfo_get(struct cifsFileInfo *cifs_file) 277 return pCifsFile;
328{
329 spin_lock(&cifs_file_list_lock);
330 cifsFileInfo_get_locked(cifs_file);
331 spin_unlock(&cifs_file_list_lock);
332 return cifs_file;
333} 278}
334 279
335/* 280/*
@@ -341,12 +286,9 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
341{ 286{
342 struct inode *inode = cifs_file->dentry->d_inode; 287 struct inode *inode = cifs_file->dentry->d_inode;
343 struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink); 288 struct cifs_tcon *tcon = tlink_tcon(cifs_file->tlink);
344 struct TCP_Server_Info *server = tcon->ses->server;
345 struct cifsInodeInfo *cifsi = CIFS_I(inode); 289 struct cifsInodeInfo *cifsi = CIFS_I(inode);
346 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 290 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
347 struct cifsLockInfo *li, *tmp; 291 struct cifsLockInfo *li, *tmp;
348 struct cifs_fid fid;
349 struct cifs_pending_open open;
350 292
351 spin_lock(&cifs_file_list_lock); 293 spin_lock(&cifs_file_list_lock);
352 if (--cifs_file->count > 0) { 294 if (--cifs_file->count > 0) {
@@ -354,12 +296,6 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
354 return; 296 return;
355 } 297 }
356 298
357 if (server->ops->get_lease_key)
358 server->ops->get_lease_key(inode, &fid);
359
360 /* store open in pending opens to make sure we don't miss lease break */
361 cifs_add_pending_open_locked(&fid, cifs_file->tlink, &open);
362
363 /* remove it from the lists */ 299 /* remove it from the lists */
364 list_del(&cifs_file->flist); 300 list_del(&cifs_file->flist);
365 list_del(&cifs_file->tlist); 301 list_del(&cifs_file->tlist);
@@ -367,13 +303,13 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
367 if (list_empty(&cifsi->openFileList)) { 303 if (list_empty(&cifsi->openFileList)) {
368 cFYI(1, "closing last open instance for inode %p", 304 cFYI(1, "closing last open instance for inode %p",
369 cifs_file->dentry->d_inode); 305 cifs_file->dentry->d_inode);
370 /* 306
371 * In strict cache mode we need invalidate mapping on the last 307 /* in strict cache mode we need invalidate mapping on the last
372 * close because it may cause a error when we open this file 308 close because it may cause a error when we open this file
373 * again and get at least level II oplock. 309 again and get at least level II oplock */
374 */
375 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) 310 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
376 CIFS_I(inode)->invalid_mapping = true; 311 CIFS_I(inode)->invalid_mapping = true;
312
377 cifs_set_oplock_level(cifsi, 0); 313 cifs_set_oplock_level(cifsi, 0);
378 } 314 }
379 spin_unlock(&cifs_file_list_lock); 315 spin_unlock(&cifs_file_list_lock);
@@ -381,30 +317,22 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
381 cancel_work_sync(&cifs_file->oplock_break); 317 cancel_work_sync(&cifs_file->oplock_break);
382 318
383 if (!tcon->need_reconnect && !cifs_file->invalidHandle) { 319 if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
384 struct TCP_Server_Info *server = tcon->ses->server; 320 int xid, rc;
385 unsigned int xid;
386 321
387 xid = get_xid(); 322 xid = GetXid();
388 if (server->ops->close) 323 rc = CIFSSMBClose(xid, tcon, cifs_file->netfid);
389 server->ops->close(xid, tcon, &cifs_file->fid); 324 FreeXid(xid);
390 _free_xid(xid);
391 } 325 }
392 326
393 cifs_del_pending_open(&open); 327 /* Delete any outstanding lock records. We'll lose them when the file
394
395 /*
396 * Delete any outstanding lock records. We'll lose them when the file
397 * is closed anyway. 328 * is closed anyway.
398 */ 329 */
399 down_write(&cifsi->lock_sem); 330 mutex_lock(&cifs_file->lock_mutex);
400 list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) { 331 list_for_each_entry_safe(li, tmp, &cifs_file->llist, llist) {
401 list_del(&li->llist); 332 list_del(&li->llist);
402 cifs_del_lock_waiters(li);
403 kfree(li); 333 kfree(li);
404 } 334 }
405 list_del(&cifs_file->llist->llist); 335 mutex_unlock(&cifs_file->lock_mutex);
406 kfree(cifs_file->llist);
407 up_write(&cifsi->lock_sem);
408 336
409 cifs_put_tlink(cifs_file->tlink); 337 cifs_put_tlink(cifs_file->tlink);
410 dput(cifs_file->dentry); 338 dput(cifs_file->dentry);
@@ -412,31 +340,27 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
412} 340}
413 341
414int cifs_open(struct inode *inode, struct file *file) 342int cifs_open(struct inode *inode, struct file *file)
415
416{ 343{
417 int rc = -EACCES; 344 int rc = -EACCES;
418 unsigned int xid; 345 int xid;
419 __u32 oplock; 346 __u32 oplock;
420 struct cifs_sb_info *cifs_sb; 347 struct cifs_sb_info *cifs_sb;
421 struct TCP_Server_Info *server;
422 struct cifs_tcon *tcon; 348 struct cifs_tcon *tcon;
423 struct tcon_link *tlink; 349 struct tcon_link *tlink;
424 struct cifsFileInfo *cfile = NULL; 350 struct cifsFileInfo *pCifsFile = NULL;
425 char *full_path = NULL; 351 char *full_path = NULL;
426 bool posix_open_ok = false; 352 bool posix_open_ok = false;
427 struct cifs_fid fid; 353 __u16 netfid;
428 struct cifs_pending_open open;
429 354
430 xid = get_xid(); 355 xid = GetXid();
431 356
432 cifs_sb = CIFS_SB(inode->i_sb); 357 cifs_sb = CIFS_SB(inode->i_sb);
433 tlink = cifs_sb_tlink(cifs_sb); 358 tlink = cifs_sb_tlink(cifs_sb);
434 if (IS_ERR(tlink)) { 359 if (IS_ERR(tlink)) {
435 free_xid(xid); 360 FreeXid(xid);
436 return PTR_ERR(tlink); 361 return PTR_ERR(tlink);
437 } 362 }
438 tcon = tlink_tcon(tlink); 363 tcon = tlink_tcon(tlink);
439 server = tcon->ses->server;
440 364
441 full_path = build_path_from_dentry(file->f_path.dentry); 365 full_path = build_path_from_dentry(file->f_path.dentry);
442 if (full_path == NULL) { 366 if (full_path == NULL) {
@@ -447,18 +371,19 @@ int cifs_open(struct inode *inode, struct file *file)
447 cFYI(1, "inode = 0x%p file flags are 0x%x for %s", 371 cFYI(1, "inode = 0x%p file flags are 0x%x for %s",
448 inode, file->f_flags, full_path); 372 inode, file->f_flags, full_path);
449 373
450 if (server->oplocks) 374 if (oplockEnabled)
451 oplock = REQ_OPLOCK; 375 oplock = REQ_OPLOCK;
452 else 376 else
453 oplock = 0; 377 oplock = 0;
454 378
455 if (!tcon->broken_posix_open && tcon->unix_ext && 379 if (!tcon->broken_posix_open && tcon->unix_ext &&
456 cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & 380 (tcon->ses->capabilities & CAP_UNIX) &&
457 le64_to_cpu(tcon->fsUnixInfo.Capability))) { 381 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
382 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
458 /* can not refresh inode info since size could be stale */ 383 /* can not refresh inode info since size could be stale */
459 rc = cifs_posix_open(full_path, &inode, inode->i_sb, 384 rc = cifs_posix_open(full_path, &inode, inode->i_sb,
460 cifs_sb->mnt_file_mode /* ignored */, 385 cifs_sb->mnt_file_mode /* ignored */,
461 file->f_flags, &oplock, &fid.netfid, xid); 386 file->f_flags, &oplock, &netfid, xid);
462 if (rc == 0) { 387 if (rc == 0) {
463 cFYI(1, "posix open succeeded"); 388 cFYI(1, "posix open succeeded");
464 posix_open_ok = true; 389 posix_open_ok = true;
@@ -474,34 +399,20 @@ int cifs_open(struct inode *inode, struct file *file)
474 } else if ((rc != -EIO) && (rc != -EREMOTE) && 399 } else if ((rc != -EIO) && (rc != -EREMOTE) &&
475 (rc != -EOPNOTSUPP)) /* path not found or net err */ 400 (rc != -EOPNOTSUPP)) /* path not found or net err */
476 goto out; 401 goto out;
477 /* 402 /* else fallthrough to retry open the old way on network i/o
478 * Else fallthrough to retry open the old way on network i/o 403 or DFS errors */
479 * or DFS errors.
480 */
481 } 404 }
482 405
483 if (server->ops->get_lease_key)
484 server->ops->get_lease_key(inode, &fid);
485
486 cifs_add_pending_open(&fid, tlink, &open);
487
488 if (!posix_open_ok) { 406 if (!posix_open_ok) {
489 if (server->ops->get_lease_key)
490 server->ops->get_lease_key(inode, &fid);
491
492 rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, 407 rc = cifs_nt_open(full_path, inode, cifs_sb, tcon,
493 file->f_flags, &oplock, &fid, xid); 408 file->f_flags, &oplock, &netfid, xid);
494 if (rc) { 409 if (rc)
495 cifs_del_pending_open(&open);
496 goto out; 410 goto out;
497 }
498 } 411 }
499 412
500 cfile = cifs_new_fileinfo(&fid, file, tlink, oplock); 413 pCifsFile = cifs_new_fileinfo(netfid, file, tlink, oplock);
501 if (cfile == NULL) { 414 if (pCifsFile == NULL) {
502 if (server->ops->close) 415 CIFSSMBClose(xid, tcon, netfid);
503 server->ops->close(xid, tcon, &fid);
504 cifs_del_pending_open(&open);
505 rc = -ENOMEM; 416 rc = -ENOMEM;
506 goto out; 417 goto out;
507 } 418 }
@@ -509,10 +420,8 @@ int cifs_open(struct inode *inode, struct file *file)
509 cifs_fscache_set_inode_cookie(inode, file); 420 cifs_fscache_set_inode_cookie(inode, file);
510 421
511 if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { 422 if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) {
512 /* 423 /* time to set mode which we can not set earlier due to
513 * Time to set mode which we can not set earlier due to 424 problems creating new read-only files */
514 * problems creating new read-only files.
515 */
516 struct cifs_unix_set_info_args args = { 425 struct cifs_unix_set_info_args args = {
517 .mode = inode->i_mode, 426 .mode = inode->i_mode,
518 .uid = NO_CHANGE_64, 427 .uid = NO_CHANGE_64,
@@ -522,180 +431,147 @@ int cifs_open(struct inode *inode, struct file *file)
522 .mtime = NO_CHANGE_64, 431 .mtime = NO_CHANGE_64,
523 .device = 0, 432 .device = 0,
524 }; 433 };
525 CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid.netfid, 434 CIFSSMBUnixSetFileInfo(xid, tcon, &args, netfid,
526 cfile->pid); 435 pCifsFile->pid);
527 } 436 }
528 437
529out: 438out:
530 kfree(full_path); 439 kfree(full_path);
531 free_xid(xid); 440 FreeXid(xid);
532 cifs_put_tlink(tlink); 441 cifs_put_tlink(tlink);
533 return rc; 442 return rc;
534} 443}
535 444
536static int cifs_push_posix_locks(struct cifsFileInfo *cfile); 445/* Try to reacquire byte range locks that were released when session */
537 446/* to server was lost */
538/* 447static int cifs_relock_file(struct cifsFileInfo *cifsFile)
539 * Try to reacquire byte range locks that were released when session
540 * to server was lost.
541 */
542static int
543cifs_relock_file(struct cifsFileInfo *cfile)
544{ 448{
545 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
546 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
547 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
548 int rc = 0; 449 int rc = 0;
549 450
550 /* we are going to update can_cache_brlcks here - need a write access */ 451/* BB list all locks open on this file and relock */
551 down_write(&cinode->lock_sem);
552 if (cinode->can_cache_brlcks) {
553 /* can cache locks - no need to push them */
554 up_write(&cinode->lock_sem);
555 return rc;
556 }
557
558 if (cap_unix(tcon->ses) &&
559 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
560 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
561 rc = cifs_push_posix_locks(cfile);
562 else
563 rc = tcon->ses->server->ops->push_mand_locks(cfile);
564 452
565 up_write(&cinode->lock_sem);
566 return rc; 453 return rc;
567} 454}
568 455
569static int 456static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush)
570cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
571{ 457{
572 int rc = -EACCES; 458 int rc = -EACCES;
573 unsigned int xid; 459 int xid;
574 __u32 oplock; 460 __u32 oplock;
575 struct cifs_sb_info *cifs_sb; 461 struct cifs_sb_info *cifs_sb;
576 struct cifs_tcon *tcon; 462 struct cifs_tcon *tcon;
577 struct TCP_Server_Info *server; 463 struct cifsInodeInfo *pCifsInode;
578 struct cifsInodeInfo *cinode;
579 struct inode *inode; 464 struct inode *inode;
580 char *full_path = NULL; 465 char *full_path = NULL;
581 int desired_access; 466 int desiredAccess;
582 int disposition = FILE_OPEN; 467 int disposition = FILE_OPEN;
583 int create_options = CREATE_NOT_DIR; 468 __u16 netfid;
584 struct cifs_fid fid;
585 469
586 xid = get_xid(); 470 xid = GetXid();
587 mutex_lock(&cfile->fh_mutex); 471 mutex_lock(&pCifsFile->fh_mutex);
588 if (!cfile->invalidHandle) { 472 if (!pCifsFile->invalidHandle) {
589 mutex_unlock(&cfile->fh_mutex); 473 mutex_unlock(&pCifsFile->fh_mutex);
590 rc = 0; 474 rc = 0;
591 free_xid(xid); 475 FreeXid(xid);
592 return rc; 476 return rc;
593 } 477 }
594 478
595 inode = cfile->dentry->d_inode; 479 inode = pCifsFile->dentry->d_inode;
596 cifs_sb = CIFS_SB(inode->i_sb); 480 cifs_sb = CIFS_SB(inode->i_sb);
597 tcon = tlink_tcon(cfile->tlink); 481 tcon = tlink_tcon(pCifsFile->tlink);
598 server = tcon->ses->server;
599 482
600 /* 483/* can not grab rename sem here because various ops, including
601 * Can not grab rename sem here because various ops, including those 484 those that already have the rename sem can end up causing writepage
602 * that already have the rename sem can end up causing writepage to get 485 to get called and if the server was down that means we end up here,
603 * called and if the server was down that means we end up here, and we 486 and we can never tell if the caller already has the rename_sem */
604 * can never tell if the caller already has the rename_sem. 487 full_path = build_path_from_dentry(pCifsFile->dentry);
605 */
606 full_path = build_path_from_dentry(cfile->dentry);
607 if (full_path == NULL) { 488 if (full_path == NULL) {
608 rc = -ENOMEM; 489 rc = -ENOMEM;
609 mutex_unlock(&cfile->fh_mutex); 490 mutex_unlock(&pCifsFile->fh_mutex);
610 free_xid(xid); 491 FreeXid(xid);
611 return rc; 492 return rc;
612 } 493 }
613 494
614 cFYI(1, "inode = 0x%p file flags 0x%x for %s", inode, cfile->f_flags, 495 cFYI(1, "inode = 0x%p file flags 0x%x for %s",
615 full_path); 496 inode, pCifsFile->f_flags, full_path);
616 497
617 if (tcon->ses->server->oplocks) 498 if (oplockEnabled)
618 oplock = REQ_OPLOCK; 499 oplock = REQ_OPLOCK;
619 else 500 else
620 oplock = 0; 501 oplock = 0;
621 502
622 if (tcon->unix_ext && cap_unix(tcon->ses) && 503 if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) &&
623 (CIFS_UNIX_POSIX_PATH_OPS_CAP & 504 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
624 le64_to_cpu(tcon->fsUnixInfo.Capability))) { 505 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
506
625 /* 507 /*
626 * O_CREAT, O_EXCL and O_TRUNC already had their effect on the 508 * O_CREAT, O_EXCL and O_TRUNC already had their effect on the
627 * original open. Must mask them off for a reopen. 509 * original open. Must mask them off for a reopen.
628 */ 510 */
629 unsigned int oflags = cfile->f_flags & 511 unsigned int oflags = pCifsFile->f_flags &
630 ~(O_CREAT | O_EXCL | O_TRUNC); 512 ~(O_CREAT | O_EXCL | O_TRUNC);
631 513
632 rc = cifs_posix_open(full_path, NULL, inode->i_sb, 514 rc = cifs_posix_open(full_path, NULL, inode->i_sb,
633 cifs_sb->mnt_file_mode /* ignored */, 515 cifs_sb->mnt_file_mode /* ignored */,
634 oflags, &oplock, &fid.netfid, xid); 516 oflags, &oplock, &netfid, xid);
635 if (rc == 0) { 517 if (rc == 0) {
636 cFYI(1, "posix reopen succeeded"); 518 cFYI(1, "posix reopen succeeded");
637 goto reopen_success; 519 goto reopen_success;
638 } 520 }
639 /* 521 /* fallthrough to retry open the old way on errors, especially
640 * fallthrough to retry open the old way on errors, especially 522 in the reconnect path it is important to retry hard */
641 * in the reconnect path it is important to retry hard
642 */
643 } 523 }
644 524
645 desired_access = cifs_convert_flags(cfile->f_flags); 525 desiredAccess = cifs_convert_flags(pCifsFile->f_flags);
646
647 if (backup_cred(cifs_sb))
648 create_options |= CREATE_OPEN_BACKUP_INTENT;
649 526
650 if (server->ops->get_lease_key) 527 /* Can not refresh inode by passing in file_info buf to be returned
651 server->ops->get_lease_key(inode, &fid); 528 by SMBOpen and then calling get_inode_info with returned buf
529 since file might have write behind data that needs to be flushed
530 and server version of file size can be stale. If we knew for sure
531 that inode was not dirty locally we could do this */
652 532
653 /* 533 rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desiredAccess,
654 * Can not refresh inode by passing in file_info buf to be returned by 534 CREATE_NOT_DIR, &netfid, &oplock, NULL,
655 * CIFSSMBOpen and then calling get_inode_info with returned buf since 535 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
656 * file might have write behind data that needs to be flushed and server 536 CIFS_MOUNT_MAP_SPECIAL_CHR);
657 * version of file size can be stale. If we knew for sure that inode was
658 * not dirty locally we could do this.
659 */
660 rc = server->ops->open(xid, tcon, full_path, disposition,
661 desired_access, create_options, &fid, &oplock,
662 NULL, cifs_sb);
663 if (rc) { 537 if (rc) {
664 mutex_unlock(&cfile->fh_mutex); 538 mutex_unlock(&pCifsFile->fh_mutex);
665 cFYI(1, "cifs_reopen returned 0x%x", rc); 539 cFYI(1, "cifs_open returned 0x%x", rc);
666 cFYI(1, "oplock: %d", oplock); 540 cFYI(1, "oplock: %d", oplock);
667 goto reopen_error_exit; 541 goto reopen_error_exit;
668 } 542 }
669 543
670reopen_success: 544reopen_success:
671 cfile->invalidHandle = false; 545 pCifsFile->netfid = netfid;
672 mutex_unlock(&cfile->fh_mutex); 546 pCifsFile->invalidHandle = false;
673 cinode = CIFS_I(inode); 547 mutex_unlock(&pCifsFile->fh_mutex);
548 pCifsInode = CIFS_I(inode);
674 549
675 if (can_flush) { 550 if (can_flush) {
676 rc = filemap_write_and_wait(inode->i_mapping); 551 rc = filemap_write_and_wait(inode->i_mapping);
677 mapping_set_error(inode->i_mapping, rc); 552 mapping_set_error(inode->i_mapping, rc);
678 553
679 if (tcon->unix_ext) 554 if (tcon->unix_ext)
680 rc = cifs_get_inode_info_unix(&inode, full_path, 555 rc = cifs_get_inode_info_unix(&inode,
681 inode->i_sb, xid); 556 full_path, inode->i_sb, xid);
682 else 557 else
683 rc = cifs_get_inode_info(&inode, full_path, NULL, 558 rc = cifs_get_inode_info(&inode,
684 inode->i_sb, xid, NULL); 559 full_path, NULL, inode->i_sb,
685 } 560 xid, NULL);
686 /* 561 } /* else we are writing out data to server already
687 * Else we are writing out data to server already and could deadlock if 562 and could deadlock if we tried to flush data, and
688 * we tried to flush data, and since we do not know if we have data that 563 since we do not know if we have data that would
689 * would invalidate the current end of file on the server we can not go 564 invalidate the current end of file on the server
690 * to the server to get the new inode info. 565 we can not go to the server to get the new inod
691 */ 566 info */
567
568 cifs_set_oplock_level(pCifsInode, oplock);
692 569
693 server->ops->set_fid(cfile, &fid, oplock); 570 cifs_relock_file(pCifsFile);
694 cifs_relock_file(cfile);
695 571
696reopen_error_exit: 572reopen_error_exit:
697 kfree(full_path); 573 kfree(full_path);
698 free_xid(xid); 574 FreeXid(xid);
699 return rc; 575 return rc;
700} 576}
701 577
@@ -713,876 +589,266 @@ int cifs_close(struct inode *inode, struct file *file)
713int cifs_closedir(struct inode *inode, struct file *file) 589int cifs_closedir(struct inode *inode, struct file *file)
714{ 590{
715 int rc = 0; 591 int rc = 0;
716 unsigned int xid; 592 int xid;
717 struct cifsFileInfo *cfile = file->private_data; 593 struct cifsFileInfo *pCFileStruct = file->private_data;
718 struct cifs_tcon *tcon; 594 char *ptmp;
719 struct TCP_Server_Info *server;
720 char *buf;
721 595
722 cFYI(1, "Closedir inode = 0x%p", inode); 596 cFYI(1, "Closedir inode = 0x%p", inode);
723 597
724 if (cfile == NULL) 598 xid = GetXid();
725 return rc;
726
727 xid = get_xid();
728 tcon = tlink_tcon(cfile->tlink);
729 server = tcon->ses->server;
730 599
731 cFYI(1, "Freeing private data in close dir"); 600 if (pCFileStruct) {
732 spin_lock(&cifs_file_list_lock); 601 struct cifs_tcon *pTcon = tlink_tcon(pCFileStruct->tlink);
733 if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) {
734 cfile->invalidHandle = true;
735 spin_unlock(&cifs_file_list_lock);
736 if (server->ops->close_dir)
737 rc = server->ops->close_dir(xid, tcon, &cfile->fid);
738 else
739 rc = -ENOSYS;
740 cFYI(1, "Closing uncompleted readdir with rc %d", rc);
741 /* not much we can do if it fails anyway, ignore rc */
742 rc = 0;
743 } else
744 spin_unlock(&cifs_file_list_lock);
745 602
746 buf = cfile->srch_inf.ntwrk_buf_start; 603 cFYI(1, "Freeing private data in close dir");
747 if (buf) { 604 spin_lock(&cifs_file_list_lock);
748 cFYI(1, "closedir free smb buf in srch struct"); 605 if (!pCFileStruct->srch_inf.endOfSearch &&
749 cfile->srch_inf.ntwrk_buf_start = NULL; 606 !pCFileStruct->invalidHandle) {
750 if (cfile->srch_inf.smallBuf) 607 pCFileStruct->invalidHandle = true;
751 cifs_small_buf_release(buf); 608 spin_unlock(&cifs_file_list_lock);
752 else 609 rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid);
753 cifs_buf_release(buf); 610 cFYI(1, "Closing uncompleted readdir with rc %d",
611 rc);
612 /* not much we can do if it fails anyway, ignore rc */
613 rc = 0;
614 } else
615 spin_unlock(&cifs_file_list_lock);
616 ptmp = pCFileStruct->srch_inf.ntwrk_buf_start;
617 if (ptmp) {
618 cFYI(1, "closedir free smb buf in srch struct");
619 pCFileStruct->srch_inf.ntwrk_buf_start = NULL;
620 if (pCFileStruct->srch_inf.smallBuf)
621 cifs_small_buf_release(ptmp);
622 else
623 cifs_buf_release(ptmp);
624 }
625 cifs_put_tlink(pCFileStruct->tlink);
626 kfree(file->private_data);
627 file->private_data = NULL;
754 } 628 }
755
756 cifs_put_tlink(cfile->tlink);
757 kfree(file->private_data);
758 file->private_data = NULL;
759 /* BB can we lock the filestruct while this is going on? */ 629 /* BB can we lock the filestruct while this is going on? */
760 free_xid(xid); 630 FreeXid(xid);
761 return rc; 631 return rc;
762} 632}
763 633
764static struct cifsLockInfo * 634static int store_file_lock(struct cifsFileInfo *fid, __u64 len,
765cifs_lock_init(__u64 offset, __u64 length, __u8 type) 635 __u64 offset, __u8 lockType)
766{ 636{
767 struct cifsLockInfo *lock = 637 struct cifsLockInfo *li =
768 kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL); 638 kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL);
769 if (!lock) 639 if (li == NULL)
770 return lock;
771 lock->offset = offset;
772 lock->length = length;
773 lock->type = type;
774 lock->pid = current->tgid;
775 INIT_LIST_HEAD(&lock->blist);
776 init_waitqueue_head(&lock->block_q);
777 return lock;
778}
779
780void
781cifs_del_lock_waiters(struct cifsLockInfo *lock)
782{
783 struct cifsLockInfo *li, *tmp;
784 list_for_each_entry_safe(li, tmp, &lock->blist, blist) {
785 list_del_init(&li->blist);
786 wake_up(&li->block_q);
787 }
788}
789
790#define CIFS_LOCK_OP 0
791#define CIFS_READ_OP 1
792#define CIFS_WRITE_OP 2
793
794/* @rw_check : 0 - no op, 1 - read, 2 - write */
795static bool
796cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
797 __u64 length, __u8 type, struct cifsFileInfo *cfile,
798 struct cifsLockInfo **conf_lock, int rw_check)
799{
800 struct cifsLockInfo *li;
801 struct cifsFileInfo *cur_cfile = fdlocks->cfile;
802 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
803
804 list_for_each_entry(li, &fdlocks->locks, llist) {
805 if (offset + length <= li->offset ||
806 offset >= li->offset + li->length)
807 continue;
808 if (rw_check != CIFS_LOCK_OP && current->tgid == li->pid &&
809 server->ops->compare_fids(cfile, cur_cfile)) {
810 /* shared lock prevents write op through the same fid */
811 if (!(li->type & server->vals->shared_lock_type) ||
812 rw_check != CIFS_WRITE_OP)
813 continue;
814 }
815 if ((type & server->vals->shared_lock_type) &&
816 ((server->ops->compare_fids(cfile, cur_cfile) &&
817 current->tgid == li->pid) || type == li->type))
818 continue;
819 if (conf_lock)
820 *conf_lock = li;
821 return true;
822 }
823 return false;
824}
825
826bool
827cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
828 __u8 type, struct cifsLockInfo **conf_lock,
829 int rw_check)
830{
831 bool rc = false;
832 struct cifs_fid_locks *cur;
833 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
834
835 list_for_each_entry(cur, &cinode->llist, llist) {
836 rc = cifs_find_fid_lock_conflict(cur, offset, length, type,
837 cfile, conf_lock, rw_check);
838 if (rc)
839 break;
840 }
841
842 return rc;
843}
844
845/*
846 * Check if there is another lock that prevents us to set the lock (mandatory
847 * style). If such a lock exists, update the flock structure with its
848 * properties. Otherwise, set the flock type to F_UNLCK if we can cache brlocks
849 * or leave it the same if we can't. Returns 0 if we don't need to request to
850 * the server or 1 otherwise.
851 */
852static int
853cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
854 __u8 type, struct file_lock *flock)
855{
856 int rc = 0;
857 struct cifsLockInfo *conf_lock;
858 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
859 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
860 bool exist;
861
862 down_read(&cinode->lock_sem);
863
864 exist = cifs_find_lock_conflict(cfile, offset, length, type,
865 &conf_lock, CIFS_LOCK_OP);
866 if (exist) {
867 flock->fl_start = conf_lock->offset;
868 flock->fl_end = conf_lock->offset + conf_lock->length - 1;
869 flock->fl_pid = conf_lock->pid;
870 if (conf_lock->type & server->vals->shared_lock_type)
871 flock->fl_type = F_RDLCK;
872 else
873 flock->fl_type = F_WRLCK;
874 } else if (!cinode->can_cache_brlcks)
875 rc = 1;
876 else
877 flock->fl_type = F_UNLCK;
878
879 up_read(&cinode->lock_sem);
880 return rc;
881}
882
883static void
884cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
885{
886 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
887 down_write(&cinode->lock_sem);
888 list_add_tail(&lock->llist, &cfile->llist->locks);
889 up_write(&cinode->lock_sem);
890}
891
892/*
893 * Set the byte-range lock (mandatory style). Returns:
894 * 1) 0, if we set the lock and don't need to request to the server;
895 * 2) 1, if no locks prevent us but we need to request to the server;
896 * 3) -EACCESS, if there is a lock that prevents us and wait is false.
897 */
898static int
899cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
900 bool wait)
901{
902 struct cifsLockInfo *conf_lock;
903 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
904 bool exist;
905 int rc = 0;
906
907try_again:
908 exist = false;
909 down_write(&cinode->lock_sem);
910
911 exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length,
912 lock->type, &conf_lock, CIFS_LOCK_OP);
913 if (!exist && cinode->can_cache_brlcks) {
914 list_add_tail(&lock->llist, &cfile->llist->locks);
915 up_write(&cinode->lock_sem);
916 return rc;
917 }
918
919 if (!exist)
920 rc = 1;
921 else if (!wait)
922 rc = -EACCES;
923 else {
924 list_add_tail(&lock->blist, &conf_lock->blist);
925 up_write(&cinode->lock_sem);
926 rc = wait_event_interruptible(lock->block_q,
927 (lock->blist.prev == &lock->blist) &&
928 (lock->blist.next == &lock->blist));
929 if (!rc)
930 goto try_again;
931 down_write(&cinode->lock_sem);
932 list_del_init(&lock->blist);
933 }
934
935 up_write(&cinode->lock_sem);
936 return rc;
937}
938
939/*
940 * Check if there is another lock that prevents us to set the lock (posix
941 * style). If such a lock exists, update the flock structure with its
942 * properties. Otherwise, set the flock type to F_UNLCK if we can cache brlocks
943 * or leave it the same if we can't. Returns 0 if we don't need to request to
944 * the server or 1 otherwise.
945 */
946static int
947cifs_posix_lock_test(struct file *file, struct file_lock *flock)
948{
949 int rc = 0;
950 struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode);
951 unsigned char saved_type = flock->fl_type;
952
953 if ((flock->fl_flags & FL_POSIX) == 0)
954 return 1;
955
956 down_read(&cinode->lock_sem);
957 posix_test_lock(file, flock);
958
959 if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) {
960 flock->fl_type = saved_type;
961 rc = 1;
962 }
963
964 up_read(&cinode->lock_sem);
965 return rc;
966}
967
968/*
969 * Set the byte-range lock (posix style). Returns:
970 * 1) 0, if we set the lock and don't need to request to the server;
971 * 2) 1, if we need to request to the server;
972 * 3) <0, if the error occurs while setting the lock.
973 */
974static int
975cifs_posix_lock_set(struct file *file, struct file_lock *flock)
976{
977 struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode);
978 int rc = 1;
979
980 if ((flock->fl_flags & FL_POSIX) == 0)
981 return rc;
982
983try_again:
984 down_write(&cinode->lock_sem);
985 if (!cinode->can_cache_brlcks) {
986 up_write(&cinode->lock_sem);
987 return rc;
988 }
989
990 rc = posix_lock_file(file, flock, NULL);
991 up_write(&cinode->lock_sem);
992 if (rc == FILE_LOCK_DEFERRED) {
993 rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next);
994 if (!rc)
995 goto try_again;
996 locks_delete_block(flock);
997 }
998 return rc;
999}
1000
1001int
1002cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
1003{
1004 unsigned int xid;
1005 int rc = 0, stored_rc;
1006 struct cifsLockInfo *li, *tmp;
1007 struct cifs_tcon *tcon;
1008 unsigned int num, max_num, max_buf;
1009 LOCKING_ANDX_RANGE *buf, *cur;
1010 int types[] = {LOCKING_ANDX_LARGE_FILES,
1011 LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES};
1012 int i;
1013
1014 xid = get_xid();
1015 tcon = tlink_tcon(cfile->tlink);
1016
1017 /*
1018 * Accessing maxBuf is racy with cifs_reconnect - need to store value
1019 * and check it for zero before using.
1020 */
1021 max_buf = tcon->ses->server->maxBuf;
1022 if (!max_buf) {
1023 free_xid(xid);
1024 return -EINVAL;
1025 }
1026
1027 max_num = (max_buf - sizeof(struct smb_hdr)) /
1028 sizeof(LOCKING_ANDX_RANGE);
1029 buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL);
1030 if (!buf) {
1031 free_xid(xid);
1032 return -ENOMEM; 640 return -ENOMEM;
1033 } 641 li->offset = offset;
1034 642 li->length = len;
1035 for (i = 0; i < 2; i++) { 643 li->type = lockType;
1036 cur = buf; 644 mutex_lock(&fid->lock_mutex);
1037 num = 0; 645 list_add(&li->llist, &fid->llist);
1038 list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { 646 mutex_unlock(&fid->lock_mutex);
1039 if (li->type != types[i]) 647 return 0;
1040 continue;
1041 cur->Pid = cpu_to_le16(li->pid);
1042 cur->LengthLow = cpu_to_le32((u32)li->length);
1043 cur->LengthHigh = cpu_to_le32((u32)(li->length>>32));
1044 cur->OffsetLow = cpu_to_le32((u32)li->offset);
1045 cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32));
1046 if (++num == max_num) {
1047 stored_rc = cifs_lockv(xid, tcon,
1048 cfile->fid.netfid,
1049 (__u8)li->type, 0, num,
1050 buf);
1051 if (stored_rc)
1052 rc = stored_rc;
1053 cur = buf;
1054 num = 0;
1055 } else
1056 cur++;
1057 }
1058
1059 if (num) {
1060 stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid,
1061 (__u8)types[i], 0, num, buf);
1062 if (stored_rc)
1063 rc = stored_rc;
1064 }
1065 }
1066
1067 kfree(buf);
1068 free_xid(xid);
1069 return rc;
1070} 648}
1071 649
1072/* copied from fs/locks.c with a name change */ 650int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
1073#define cifs_for_each_lock(inode, lockp) \
1074 for (lockp = &inode->i_flock; *lockp != NULL; \
1075 lockp = &(*lockp)->fl_next)
1076
1077struct lock_to_push {
1078 struct list_head llist;
1079 __u64 offset;
1080 __u64 length;
1081 __u32 pid;
1082 __u16 netfid;
1083 __u8 type;
1084};
1085
1086static int
1087cifs_push_posix_locks(struct cifsFileInfo *cfile)
1088{ 651{
1089 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 652 int rc, xid;
1090 struct file_lock *flock, **before; 653 __u32 numLock = 0;
1091 unsigned int count = 0, i = 0; 654 __u32 numUnlock = 0;
1092 int rc = 0, xid, type;
1093 struct list_head locks_to_send, *el;
1094 struct lock_to_push *lck, *tmp;
1095 __u64 length; 655 __u64 length;
656 bool wait_flag = false;
657 struct cifs_sb_info *cifs_sb;
658 struct cifs_tcon *tcon;
659 __u16 netfid;
660 __u8 lockType = LOCKING_ANDX_LARGE_FILES;
661 bool posix_locking = 0;
1096 662
1097 xid = get_xid(); 663 length = 1 + pfLock->fl_end - pfLock->fl_start;
1098 664 rc = -EACCES;
1099 lock_flocks(); 665 xid = GetXid();
1100 cifs_for_each_lock(cfile->dentry->d_inode, before) {
1101 if ((*before)->fl_flags & FL_POSIX)
1102 count++;
1103 }
1104 unlock_flocks();
1105
1106 INIT_LIST_HEAD(&locks_to_send);
1107
1108 /*
1109 * Allocating count locks is enough because no FL_POSIX locks can be
1110 * added to the list while we are holding cinode->lock_sem that
1111 * protects locking operations of this inode.
1112 */
1113 for (; i < count; i++) {
1114 lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
1115 if (!lck) {
1116 rc = -ENOMEM;
1117 goto err_out;
1118 }
1119 list_add_tail(&lck->llist, &locks_to_send);
1120 }
1121
1122 el = locks_to_send.next;
1123 lock_flocks();
1124 cifs_for_each_lock(cfile->dentry->d_inode, before) {
1125 flock = *before;
1126 if ((flock->fl_flags & FL_POSIX) == 0)
1127 continue;
1128 if (el == &locks_to_send) {
1129 /*
1130 * The list ended. We don't have enough allocated
1131 * structures - something is really wrong.
1132 */
1133 cERROR(1, "Can't push all brlocks!");
1134 break;
1135 }
1136 length = 1 + flock->fl_end - flock->fl_start;
1137 if (flock->fl_type == F_RDLCK || flock->fl_type == F_SHLCK)
1138 type = CIFS_RDLCK;
1139 else
1140 type = CIFS_WRLCK;
1141 lck = list_entry(el, struct lock_to_push, llist);
1142 lck->pid = flock->fl_pid;
1143 lck->netfid = cfile->fid.netfid;
1144 lck->length = length;
1145 lck->type = type;
1146 lck->offset = flock->fl_start;
1147 el = el->next;
1148 }
1149 unlock_flocks();
1150
1151 list_for_each_entry_safe(lck, tmp, &locks_to_send, llist) {
1152 int stored_rc;
1153
1154 stored_rc = CIFSSMBPosixLock(xid, tcon, lck->netfid, lck->pid,
1155 lck->offset, lck->length, NULL,
1156 lck->type, 0);
1157 if (stored_rc)
1158 rc = stored_rc;
1159 list_del(&lck->llist);
1160 kfree(lck);
1161 }
1162
1163out:
1164 free_xid(xid);
1165 return rc;
1166err_out:
1167 list_for_each_entry_safe(lck, tmp, &locks_to_send, llist) {
1168 list_del(&lck->llist);
1169 kfree(lck);
1170 }
1171 goto out;
1172}
1173
1174static int
1175cifs_push_locks(struct cifsFileInfo *cfile)
1176{
1177 struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
1178 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
1179 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1180 int rc = 0;
1181
1182 /* we are going to update can_cache_brlcks here - need a write access */
1183 down_write(&cinode->lock_sem);
1184 if (!cinode->can_cache_brlcks) {
1185 up_write(&cinode->lock_sem);
1186 return rc;
1187 }
1188
1189 if (cap_unix(tcon->ses) &&
1190 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
1191 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
1192 rc = cifs_push_posix_locks(cfile);
1193 else
1194 rc = tcon->ses->server->ops->push_mand_locks(cfile);
1195 666
1196 cinode->can_cache_brlcks = false; 667 cFYI(1, "Lock parm: 0x%x flockflags: "
1197 up_write(&cinode->lock_sem); 668 "0x%x flocktype: 0x%x start: %lld end: %lld",
1198 return rc; 669 cmd, pfLock->fl_flags, pfLock->fl_type, pfLock->fl_start,
1199} 670 pfLock->fl_end);
1200 671
1201static void 672 if (pfLock->fl_flags & FL_POSIX)
1202cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
1203 bool *wait_flag, struct TCP_Server_Info *server)
1204{
1205 if (flock->fl_flags & FL_POSIX)
1206 cFYI(1, "Posix"); 673 cFYI(1, "Posix");
1207 if (flock->fl_flags & FL_FLOCK) 674 if (pfLock->fl_flags & FL_FLOCK)
1208 cFYI(1, "Flock"); 675 cFYI(1, "Flock");
1209 if (flock->fl_flags & FL_SLEEP) { 676 if (pfLock->fl_flags & FL_SLEEP) {
1210 cFYI(1, "Blocking lock"); 677 cFYI(1, "Blocking lock");
1211 *wait_flag = true; 678 wait_flag = true;
1212 } 679 }
1213 if (flock->fl_flags & FL_ACCESS) 680 if (pfLock->fl_flags & FL_ACCESS)
1214 cFYI(1, "Process suspended by mandatory locking - " 681 cFYI(1, "Process suspended by mandatory locking - "
1215 "not implemented yet"); 682 "not implemented yet");
1216 if (flock->fl_flags & FL_LEASE) 683 if (pfLock->fl_flags & FL_LEASE)
1217 cFYI(1, "Lease on file - not implemented yet"); 684 cFYI(1, "Lease on file - not implemented yet");
1218 if (flock->fl_flags & 685 if (pfLock->fl_flags &
1219 (~(FL_POSIX | FL_FLOCK | FL_SLEEP | 686 (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE)))
1220 FL_ACCESS | FL_LEASE | FL_CLOSE))) 687 cFYI(1, "Unknown lock flags 0x%x", pfLock->fl_flags);
1221 cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags);
1222 688
1223 *type = server->vals->large_lock_type; 689 if (pfLock->fl_type == F_WRLCK) {
1224 if (flock->fl_type == F_WRLCK) {
1225 cFYI(1, "F_WRLCK "); 690 cFYI(1, "F_WRLCK ");
1226 *type |= server->vals->exclusive_lock_type; 691 numLock = 1;
1227 *lock = 1; 692 } else if (pfLock->fl_type == F_UNLCK) {
1228 } else if (flock->fl_type == F_UNLCK) {
1229 cFYI(1, "F_UNLCK"); 693 cFYI(1, "F_UNLCK");
1230 *type |= server->vals->unlock_lock_type; 694 numUnlock = 1;
1231 *unlock = 1; 695 /* Check if unlock includes more than
1232 /* Check if unlock includes more than one lock range */ 696 one lock range */
1233 } else if (flock->fl_type == F_RDLCK) { 697 } else if (pfLock->fl_type == F_RDLCK) {
1234 cFYI(1, "F_RDLCK"); 698 cFYI(1, "F_RDLCK");
1235 *type |= server->vals->shared_lock_type; 699 lockType |= LOCKING_ANDX_SHARED_LOCK;
1236 *lock = 1; 700 numLock = 1;
1237 } else if (flock->fl_type == F_EXLCK) { 701 } else if (pfLock->fl_type == F_EXLCK) {
1238 cFYI(1, "F_EXLCK"); 702 cFYI(1, "F_EXLCK");
1239 *type |= server->vals->exclusive_lock_type; 703 numLock = 1;
1240 *lock = 1; 704 } else if (pfLock->fl_type == F_SHLCK) {
1241 } else if (flock->fl_type == F_SHLCK) {
1242 cFYI(1, "F_SHLCK"); 705 cFYI(1, "F_SHLCK");
1243 *type |= server->vals->shared_lock_type; 706 lockType |= LOCKING_ANDX_SHARED_LOCK;
1244 *lock = 1; 707 numLock = 1;
1245 } else 708 } else
1246 cFYI(1, "Unknown type of lock"); 709 cFYI(1, "Unknown type of lock");
1247}
1248 710
1249static int 711 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1250cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, 712 tcon = tlink_tcon(((struct cifsFileInfo *)file->private_data)->tlink);
1251 bool wait_flag, bool posix_lck, unsigned int xid) 713 netfid = ((struct cifsFileInfo *)file->private_data)->netfid;
1252{
1253 int rc = 0;
1254 __u64 length = 1 + flock->fl_end - flock->fl_start;
1255 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
1256 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1257 struct TCP_Server_Info *server = tcon->ses->server;
1258 __u16 netfid = cfile->fid.netfid;
1259
1260 if (posix_lck) {
1261 int posix_lock_type;
1262 714
1263 rc = cifs_posix_lock_test(file, flock); 715 if ((tcon->ses->capabilities & CAP_UNIX) &&
1264 if (!rc) 716 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
717 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
718 posix_locking = 1;
719 /* BB add code here to normalize offset and length to
720 account for negative length which we can not accept over the
721 wire */
722 if (IS_GETLK(cmd)) {
723 if (posix_locking) {
724 int posix_lock_type;
725 if (lockType & LOCKING_ANDX_SHARED_LOCK)
726 posix_lock_type = CIFS_RDLCK;
727 else
728 posix_lock_type = CIFS_WRLCK;
729 rc = CIFSSMBPosixLock(xid, tcon, netfid, 1 /* get */,
730 length, pfLock, posix_lock_type,
731 wait_flag);
732 FreeXid(xid);
1265 return rc; 733 return rc;
734 }
1266 735
1267 if (type & server->vals->shared_lock_type) 736 /* BB we could chain these into one lock request BB */
1268 posix_lock_type = CIFS_RDLCK; 737 rc = CIFSSMBLock(xid, tcon, netfid, length, pfLock->fl_start,
1269 else 738 0, 1, lockType, 0 /* wait flag */, 0);
1270 posix_lock_type = CIFS_WRLCK; 739 if (rc == 0) {
1271 rc = CIFSSMBPosixLock(xid, tcon, netfid, current->tgid, 740 rc = CIFSSMBLock(xid, tcon, netfid, length,
1272 flock->fl_start, length, flock, 741 pfLock->fl_start, 1 /* numUnlock */ ,
1273 posix_lock_type, wait_flag); 742 0 /* numLock */ , lockType,
1274 return rc; 743 0 /* wait flag */, 0);
1275 } 744 pfLock->fl_type = F_UNLCK;
1276 745 if (rc != 0)
1277 rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock); 746 cERROR(1, "Error unlocking previously locked "
1278 if (!rc) 747 "range %d during test of lock", rc);
1279 return rc; 748 rc = 0;
1280
1281 /* BB we could chain these into one lock request BB */
1282 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type,
1283 1, 0, false);
1284 if (rc == 0) {
1285 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
1286 type, 0, 1, false);
1287 flock->fl_type = F_UNLCK;
1288 if (rc != 0)
1289 cERROR(1, "Error unlocking previously locked "
1290 "range %d during test of lock", rc);
1291 return 0;
1292 }
1293
1294 if (type & server->vals->shared_lock_type) {
1295 flock->fl_type = F_WRLCK;
1296 return 0;
1297 }
1298
1299 type &= ~server->vals->exclusive_lock_type;
1300
1301 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
1302 type | server->vals->shared_lock_type,
1303 1, 0, false);
1304 if (rc == 0) {
1305 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
1306 type | server->vals->shared_lock_type, 0, 1, false);
1307 flock->fl_type = F_RDLCK;
1308 if (rc != 0)
1309 cERROR(1, "Error unlocking previously locked "
1310 "range %d during test of lock", rc);
1311 } else
1312 flock->fl_type = F_WRLCK;
1313
1314 return 0;
1315}
1316
1317void
1318cifs_move_llist(struct list_head *source, struct list_head *dest)
1319{
1320 struct list_head *li, *tmp;
1321 list_for_each_safe(li, tmp, source)
1322 list_move(li, dest);
1323}
1324
1325void
1326cifs_free_llist(struct list_head *llist)
1327{
1328 struct cifsLockInfo *li, *tmp;
1329 list_for_each_entry_safe(li, tmp, llist, llist) {
1330 cifs_del_lock_waiters(li);
1331 list_del(&li->llist);
1332 kfree(li);
1333 }
1334}
1335
1336int
1337cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
1338 unsigned int xid)
1339{
1340 int rc = 0, stored_rc;
1341 int types[] = {LOCKING_ANDX_LARGE_FILES,
1342 LOCKING_ANDX_SHARED_LOCK | LOCKING_ANDX_LARGE_FILES};
1343 unsigned int i;
1344 unsigned int max_num, num, max_buf;
1345 LOCKING_ANDX_RANGE *buf, *cur;
1346 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1347 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
1348 struct cifsLockInfo *li, *tmp;
1349 __u64 length = 1 + flock->fl_end - flock->fl_start;
1350 struct list_head tmp_llist;
1351
1352 INIT_LIST_HEAD(&tmp_llist);
1353
1354 /*
1355 * Accessing maxBuf is racy with cifs_reconnect - need to store value
1356 * and check it for zero before using.
1357 */
1358 max_buf = tcon->ses->server->maxBuf;
1359 if (!max_buf)
1360 return -EINVAL;
1361 749
1362 max_num = (max_buf - sizeof(struct smb_hdr)) / 750 } else {
1363 sizeof(LOCKING_ANDX_RANGE); 751 /* if rc == ERR_SHARING_VIOLATION ? */
1364 buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); 752 rc = 0;
1365 if (!buf)
1366 return -ENOMEM;
1367 753
1368 down_write(&cinode->lock_sem); 754 if (lockType & LOCKING_ANDX_SHARED_LOCK) {
1369 for (i = 0; i < 2; i++) { 755 pfLock->fl_type = F_WRLCK;
1370 cur = buf; 756 } else {
1371 num = 0; 757 rc = CIFSSMBLock(xid, tcon, netfid, length,
1372 list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { 758 pfLock->fl_start, 0, 1,
1373 if (flock->fl_start > li->offset || 759 lockType | LOCKING_ANDX_SHARED_LOCK,
1374 (flock->fl_start + length) < 760 0 /* wait flag */, 0);
1375 (li->offset + li->length)) 761 if (rc == 0) {
1376 continue; 762 rc = CIFSSMBLock(xid, tcon, netfid,
1377 if (current->tgid != li->pid) 763 length, pfLock->fl_start, 1, 0,
1378 continue; 764 lockType |
1379 if (types[i] != li->type) 765 LOCKING_ANDX_SHARED_LOCK,
1380 continue; 766 0 /* wait flag */, 0);
1381 if (cinode->can_cache_brlcks) { 767 pfLock->fl_type = F_RDLCK;
1382 /* 768 if (rc != 0)
1383 * We can cache brlock requests - simply remove 769 cERROR(1, "Error unlocking "
1384 * a lock from the file's list. 770 "previously locked range %d "
1385 */ 771 "during test of lock", rc);
1386 list_del(&li->llist); 772 rc = 0;
1387 cifs_del_lock_waiters(li); 773 } else {
1388 kfree(li); 774 pfLock->fl_type = F_WRLCK;
1389 continue; 775 rc = 0;
776 }
1390 } 777 }
1391 cur->Pid = cpu_to_le16(li->pid);
1392 cur->LengthLow = cpu_to_le32((u32)li->length);
1393 cur->LengthHigh = cpu_to_le32((u32)(li->length>>32));
1394 cur->OffsetLow = cpu_to_le32((u32)li->offset);
1395 cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32));
1396 /*
1397 * We need to save a lock here to let us add it again to
1398 * the file's list if the unlock range request fails on
1399 * the server.
1400 */
1401 list_move(&li->llist, &tmp_llist);
1402 if (++num == max_num) {
1403 stored_rc = cifs_lockv(xid, tcon,
1404 cfile->fid.netfid,
1405 li->type, num, 0, buf);
1406 if (stored_rc) {
1407 /*
1408 * We failed on the unlock range
1409 * request - add all locks from the tmp
1410 * list to the head of the file's list.
1411 */
1412 cifs_move_llist(&tmp_llist,
1413 &cfile->llist->locks);
1414 rc = stored_rc;
1415 } else
1416 /*
1417 * The unlock range request succeed -
1418 * free the tmp list.
1419 */
1420 cifs_free_llist(&tmp_llist);
1421 cur = buf;
1422 num = 0;
1423 } else
1424 cur++;
1425 } 778 }
1426 if (num) {
1427 stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid,
1428 types[i], num, 0, buf);
1429 if (stored_rc) {
1430 cifs_move_llist(&tmp_llist,
1431 &cfile->llist->locks);
1432 rc = stored_rc;
1433 } else
1434 cifs_free_llist(&tmp_llist);
1435 }
1436 }
1437 779
1438 up_write(&cinode->lock_sem); 780 FreeXid(xid);
1439 kfree(buf); 781 return rc;
1440 return rc; 782 }
1441}
1442 783
1443static int 784 if (!numLock && !numUnlock) {
1444cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, 785 /* if no lock or unlock then nothing
1445 bool wait_flag, bool posix_lck, int lock, int unlock, 786 to do since we do not know what it is */
1446 unsigned int xid) 787 FreeXid(xid);
1447{ 788 return -EOPNOTSUPP;
1448 int rc = 0; 789 }
1449 __u64 length = 1 + flock->fl_end - flock->fl_start;
1450 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
1451 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1452 struct TCP_Server_Info *server = tcon->ses->server;
1453 struct inode *inode = cfile->dentry->d_inode;
1454 790
1455 if (posix_lck) { 791 if (posix_locking) {
1456 int posix_lock_type; 792 int posix_lock_type;
1457 793 if (lockType & LOCKING_ANDX_SHARED_LOCK)
1458 rc = cifs_posix_lock_set(file, flock);
1459 if (!rc || rc < 0)
1460 return rc;
1461
1462 if (type & server->vals->shared_lock_type)
1463 posix_lock_type = CIFS_RDLCK; 794 posix_lock_type = CIFS_RDLCK;
1464 else 795 else
1465 posix_lock_type = CIFS_WRLCK; 796 posix_lock_type = CIFS_WRLCK;
1466 797
1467 if (unlock == 1) 798 if (numUnlock == 1)
1468 posix_lock_type = CIFS_UNLCK; 799 posix_lock_type = CIFS_UNLCK;
1469 800
1470 rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid, 801 rc = CIFSSMBPosixLock(xid, tcon, netfid, 0 /* set */,
1471 current->tgid, flock->fl_start, length, 802 length, pfLock, posix_lock_type,
1472 NULL, posix_lock_type, wait_flag); 803 wait_flag);
1473 goto out; 804 } else {
1474 } 805 struct cifsFileInfo *fid = file->private_data;
1475
1476 if (lock) {
1477 struct cifsLockInfo *lock;
1478 806
1479 lock = cifs_lock_init(flock->fl_start, length, type); 807 if (numLock) {
1480 if (!lock) 808 rc = CIFSSMBLock(xid, tcon, netfid, length,
1481 return -ENOMEM; 809 pfLock->fl_start, 0, numLock, lockType,
810 wait_flag, 0);
1482 811
1483 rc = cifs_lock_add_if(cfile, lock, wait_flag); 812 if (rc == 0) {
1484 if (rc < 0) { 813 /* For Windows locks we must store them. */
1485 kfree(lock); 814 rc = store_file_lock(fid, length,
1486 return rc; 815 pfLock->fl_start, lockType);
1487 } 816 }
1488 if (!rc) 817 } else if (numUnlock) {
1489 goto out; 818 /* For each stored lock that this unlock overlaps
1490 819 completely, unlock it. */
1491 /* 820 int stored_rc = 0;
1492 * Windows 7 server can delay breaking lease from read to None 821 struct cifsLockInfo *li, *tmp;
1493 * if we set a byte-range lock on a file - break it explicitly
1494 * before sending the lock to the server to be sure the next
1495 * read won't conflict with non-overlapted locks due to
1496 * pagereading.
1497 */
1498 if (!CIFS_I(inode)->clientCanCacheAll &&
1499 CIFS_I(inode)->clientCanCacheRead) {
1500 cifs_invalidate_mapping(inode);
1501 cFYI(1, "Set no oplock for inode=%p due to mand locks",
1502 inode);
1503 CIFS_I(inode)->clientCanCacheRead = false;
1504 }
1505 822
1506 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, 823 rc = 0;
1507 type, 1, 0, wait_flag); 824 mutex_lock(&fid->lock_mutex);
1508 if (rc) { 825 list_for_each_entry_safe(li, tmp, &fid->llist, llist) {
1509 kfree(lock); 826 if (pfLock->fl_start <= li->offset &&
1510 return rc; 827 (pfLock->fl_start + length) >=
828 (li->offset + li->length)) {
829 stored_rc = CIFSSMBLock(xid, tcon,
830 netfid, li->length,
831 li->offset, 1, 0,
832 li->type, false, 0);
833 if (stored_rc)
834 rc = stored_rc;
835 else {
836 list_del(&li->llist);
837 kfree(li);
838 }
839 }
840 }
841 mutex_unlock(&fid->lock_mutex);
1511 } 842 }
1512
1513 cifs_lock_add(cfile, lock);
1514 } else if (unlock)
1515 rc = server->ops->mand_unlock_range(cfile, flock, xid);
1516
1517out:
1518 if (flock->fl_flags & FL_POSIX)
1519 posix_lock_file_wait(file, flock);
1520 return rc;
1521}
1522
1523int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
1524{
1525 int rc, xid;
1526 int lock = 0, unlock = 0;
1527 bool wait_flag = false;
1528 bool posix_lck = false;
1529 struct cifs_sb_info *cifs_sb;
1530 struct cifs_tcon *tcon;
1531 struct cifsInodeInfo *cinode;
1532 struct cifsFileInfo *cfile;
1533 __u16 netfid;
1534 __u32 type;
1535
1536 rc = -EACCES;
1537 xid = get_xid();
1538
1539 cFYI(1, "Lock parm: 0x%x flockflags: 0x%x flocktype: 0x%x start: %lld "
1540 "end: %lld", cmd, flock->fl_flags, flock->fl_type,
1541 flock->fl_start, flock->fl_end);
1542
1543 cfile = (struct cifsFileInfo *)file->private_data;
1544 tcon = tlink_tcon(cfile->tlink);
1545
1546 cifs_read_flock(flock, &type, &lock, &unlock, &wait_flag,
1547 tcon->ses->server);
1548
1549 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1550 netfid = cfile->fid.netfid;
1551 cinode = CIFS_I(file->f_path.dentry->d_inode);
1552
1553 if (cap_unix(tcon->ses) &&
1554 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
1555 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
1556 posix_lck = true;
1557 /*
1558 * BB add code here to normalize offset and length to account for
1559 * negative length which we can not accept over the wire.
1560 */
1561 if (IS_GETLK(cmd)) {
1562 rc = cifs_getlk(file, flock, type, wait_flag, posix_lck, xid);
1563 free_xid(xid);
1564 return rc;
1565 }
1566
1567 if (!lock && !unlock) {
1568 /*
1569 * if no lock or unlock then nothing to do since we do not
1570 * know what it is
1571 */
1572 free_xid(xid);
1573 return -EOPNOTSUPP;
1574 } 843 }
1575 844
1576 rc = cifs_setlk(file, flock, type, wait_flag, posix_lck, lock, unlock, 845 if (pfLock->fl_flags & FL_POSIX)
1577 xid); 846 posix_lock_file_wait(file, pfLock);
1578 free_xid(xid); 847 FreeXid(xid);
1579 return rc; 848 return rc;
1580} 849}
1581 850
1582/* 851/* update the file size (if needed) after a write */
1583 * update the file size (if needed) after a write. Should be called with
1584 * the inode->i_lock held
1585 */
1586void 852void
1587cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, 853cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
1588 unsigned int bytes_written) 854 unsigned int bytes_written)
@@ -1593,17 +859,16 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
1593 cifsi->server_eof = end_of_write; 859 cifsi->server_eof = end_of_write;
1594} 860}
1595 861
1596static ssize_t 862static ssize_t cifs_write(struct cifsFileInfo *open_file, __u32 pid,
1597cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data, 863 const char *write_data, size_t write_size,
1598 size_t write_size, loff_t *offset) 864 loff_t *poffset)
1599{ 865{
1600 int rc = 0; 866 int rc = 0;
1601 unsigned int bytes_written = 0; 867 unsigned int bytes_written = 0;
1602 unsigned int total_written; 868 unsigned int total_written;
1603 struct cifs_sb_info *cifs_sb; 869 struct cifs_sb_info *cifs_sb;
1604 struct cifs_tcon *tcon; 870 struct cifs_tcon *pTcon;
1605 struct TCP_Server_Info *server; 871 int xid;
1606 unsigned int xid;
1607 struct dentry *dentry = open_file->dentry; 872 struct dentry *dentry = open_file->dentry;
1608 struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); 873 struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode);
1609 struct cifs_io_parms io_parms; 874 struct cifs_io_parms io_parms;
@@ -1611,15 +876,11 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
1611 cifs_sb = CIFS_SB(dentry->d_sb); 876 cifs_sb = CIFS_SB(dentry->d_sb);
1612 877
1613 cFYI(1, "write %zd bytes to offset %lld of %s", write_size, 878 cFYI(1, "write %zd bytes to offset %lld of %s", write_size,
1614 *offset, dentry->d_name.name); 879 *poffset, dentry->d_name.name);
1615
1616 tcon = tlink_tcon(open_file->tlink);
1617 server = tcon->ses->server;
1618 880
1619 if (!server->ops->sync_write) 881 pTcon = tlink_tcon(open_file->tlink);
1620 return -ENOSYS;
1621 882
1622 xid = get_xid(); 883 xid = GetXid();
1623 884
1624 for (total_written = 0; write_size > total_written; 885 for (total_written = 0; write_size > total_written;
1625 total_written += bytes_written) { 886 total_written += bytes_written) {
@@ -1643,38 +904,37 @@ cifs_write(struct cifsFileInfo *open_file, __u32 pid, const char *write_data,
1643 /* iov[0] is reserved for smb header */ 904 /* iov[0] is reserved for smb header */
1644 iov[1].iov_base = (char *)write_data + total_written; 905 iov[1].iov_base = (char *)write_data + total_written;
1645 iov[1].iov_len = len; 906 iov[1].iov_len = len;
907 io_parms.netfid = open_file->netfid;
1646 io_parms.pid = pid; 908 io_parms.pid = pid;
1647 io_parms.tcon = tcon; 909 io_parms.tcon = pTcon;
1648 io_parms.offset = *offset; 910 io_parms.offset = *poffset;
1649 io_parms.length = len; 911 io_parms.length = len;
1650 rc = server->ops->sync_write(xid, open_file, &io_parms, 912 rc = CIFSSMBWrite2(xid, &io_parms, &bytes_written, iov,
1651 &bytes_written, iov, 1); 913 1, 0);
1652 } 914 }
1653 if (rc || (bytes_written == 0)) { 915 if (rc || (bytes_written == 0)) {
1654 if (total_written) 916 if (total_written)
1655 break; 917 break;
1656 else { 918 else {
1657 free_xid(xid); 919 FreeXid(xid);
1658 return rc; 920 return rc;
1659 } 921 }
1660 } else { 922 } else {
1661 spin_lock(&dentry->d_inode->i_lock); 923 cifs_update_eof(cifsi, *poffset, bytes_written);
1662 cifs_update_eof(cifsi, *offset, bytes_written); 924 *poffset += bytes_written;
1663 spin_unlock(&dentry->d_inode->i_lock);
1664 *offset += bytes_written;
1665 } 925 }
1666 } 926 }
1667 927
1668 cifs_stats_bytes_written(tcon, total_written); 928 cifs_stats_bytes_written(pTcon, total_written);
1669 929
1670 if (total_written > 0) { 930 if (total_written > 0) {
1671 spin_lock(&dentry->d_inode->i_lock); 931 spin_lock(&dentry->d_inode->i_lock);
1672 if (*offset > dentry->d_inode->i_size) 932 if (*poffset > dentry->d_inode->i_size)
1673 i_size_write(dentry->d_inode, *offset); 933 i_size_write(dentry->d_inode, *poffset);
1674 spin_unlock(&dentry->d_inode->i_lock); 934 spin_unlock(&dentry->d_inode->i_lock);
1675 } 935 }
1676 mark_inode_dirty_sync(dentry->d_inode); 936 mark_inode_dirty_sync(dentry->d_inode);
1677 free_xid(xid); 937 FreeXid(xid);
1678 return total_written; 938 return total_written;
1679} 939}
1680 940
@@ -1699,7 +959,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1699 if (!open_file->invalidHandle) { 959 if (!open_file->invalidHandle) {
1700 /* found a good file */ 960 /* found a good file */
1701 /* lock it so it will not be closed on us */ 961 /* lock it so it will not be closed on us */
1702 cifsFileInfo_get_locked(open_file); 962 cifsFileInfo_get(open_file);
1703 spin_unlock(&cifs_file_list_lock); 963 spin_unlock(&cifs_file_list_lock);
1704 return open_file; 964 return open_file;
1705 } /* else might as well continue, and look for 965 } /* else might as well continue, and look for
@@ -1715,11 +975,10 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,
1715struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, 975struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode,
1716 bool fsuid_only) 976 bool fsuid_only)
1717{ 977{
1718 struct cifsFileInfo *open_file, *inv_file = NULL; 978 struct cifsFileInfo *open_file;
1719 struct cifs_sb_info *cifs_sb; 979 struct cifs_sb_info *cifs_sb;
1720 bool any_available = false; 980 bool any_available = false;
1721 int rc; 981 int rc;
1722 unsigned int refind = 0;
1723 982
1724 /* Having a null inode here (because mapping->host was set to zero by 983 /* Having a null inode here (because mapping->host was set to zero by
1725 the VFS or MM) should not happen but we had reports of on oops (due to 984 the VFS or MM) should not happen but we had reports of on oops (due to
@@ -1739,25 +998,40 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode,
1739 998
1740 spin_lock(&cifs_file_list_lock); 999 spin_lock(&cifs_file_list_lock);
1741refind_writable: 1000refind_writable:
1742 if (refind > MAX_REOPEN_ATT) {
1743 spin_unlock(&cifs_file_list_lock);
1744 return NULL;
1745 }
1746 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) { 1001 list_for_each_entry(open_file, &cifs_inode->openFileList, flist) {
1747 if (!any_available && open_file->pid != current->tgid) 1002 if (!any_available && open_file->pid != current->tgid)
1748 continue; 1003 continue;
1749 if (fsuid_only && open_file->uid != current_fsuid()) 1004 if (fsuid_only && open_file->uid != current_fsuid())
1750 continue; 1005 continue;
1751 if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { 1006 if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) {
1007 cifsFileInfo_get(open_file);
1008
1752 if (!open_file->invalidHandle) { 1009 if (!open_file->invalidHandle) {
1753 /* found a good writable file */ 1010 /* found a good writable file */
1754 cifsFileInfo_get_locked(open_file);
1755 spin_unlock(&cifs_file_list_lock); 1011 spin_unlock(&cifs_file_list_lock);
1756 return open_file; 1012 return open_file;
1757 } else {
1758 if (!inv_file)
1759 inv_file = open_file;
1760 } 1013 }
1014
1015 spin_unlock(&cifs_file_list_lock);
1016
1017 /* Had to unlock since following call can block */
1018 rc = cifs_reopen_file(open_file, false);
1019 if (!rc)
1020 return open_file;
1021
1022 /* if it fails, try another handle if possible */
1023 cFYI(1, "wp failed on reopen file");
1024 cifsFileInfo_put(open_file);
1025
1026 spin_lock(&cifs_file_list_lock);
1027
1028 /* else we simply continue to the next entry. Thus
1029 we do not loop on reopen errors. If we
1030 can not reopen the file, for example if we
1031 reconnected to a server with another client
1032 racing to delete or lock the file we would not
1033 make progress if we restarted before the beginning
1034 of the loop here. */
1761 } 1035 }
1762 } 1036 }
1763 /* couldn't find useable FH with same pid, try any available */ 1037 /* couldn't find useable FH with same pid, try any available */
@@ -1765,30 +1039,7 @@ refind_writable:
1765 any_available = true; 1039 any_available = true;
1766 goto refind_writable; 1040 goto refind_writable;
1767 } 1041 }
1768
1769 if (inv_file) {
1770 any_available = false;
1771 cifsFileInfo_get_locked(inv_file);
1772 }
1773
1774 spin_unlock(&cifs_file_list_lock); 1042 spin_unlock(&cifs_file_list_lock);
1775
1776 if (inv_file) {
1777 rc = cifs_reopen_file(inv_file, false);
1778 if (!rc)
1779 return inv_file;
1780 else {
1781 spin_lock(&cifs_file_list_lock);
1782 list_move_tail(&inv_file->flist,
1783 &cifs_inode->openFileList);
1784 spin_unlock(&cifs_file_list_lock);
1785 cifsFileInfo_put(inv_file);
1786 spin_lock(&cifs_file_list_lock);
1787 ++refind;
1788 goto refind_writable;
1789 }
1790 }
1791
1792 return NULL; 1043 return NULL;
1793} 1044}
1794 1045
@@ -1853,7 +1104,6 @@ static int cifs_writepages(struct address_space *mapping,
1853 bool done = false, scanned = false, range_whole = false; 1104 bool done = false, scanned = false, range_whole = false;
1854 pgoff_t end, index; 1105 pgoff_t end, index;
1855 struct cifs_writedata *wdata; 1106 struct cifs_writedata *wdata;
1856 struct TCP_Server_Info *server;
1857 struct page *page; 1107 struct page *page;
1858 int rc = 0; 1108 int rc = 0;
1859 1109
@@ -1883,8 +1133,7 @@ retry:
1883 tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1, 1133 tofind = min((cifs_sb->wsize / PAGE_CACHE_SIZE) - 1,
1884 end - index) + 1; 1134 end - index) + 1;
1885 1135
1886 wdata = cifs_writedata_alloc((unsigned int)tofind, 1136 wdata = cifs_writedata_alloc((unsigned int)tofind);
1887 cifs_writev_complete);
1888 if (!wdata) { 1137 if (!wdata) {
1889 rc = -ENOMEM; 1138 rc = -ENOMEM;
1890 break; 1139 break;
@@ -1960,7 +1209,7 @@ retry:
1960 */ 1209 */
1961 set_page_writeback(page); 1210 set_page_writeback(page);
1962 1211
1963 if (page_offset(page) >= i_size_read(mapping->host)) { 1212 if (page_offset(page) >= mapping->host->i_size) {
1964 done = true; 1213 done = true;
1965 unlock_page(page); 1214 unlock_page(page);
1966 end_page_writeback(page); 1215 end_page_writeback(page);
@@ -1991,13 +1240,6 @@ retry:
1991 wdata->sync_mode = wbc->sync_mode; 1240 wdata->sync_mode = wbc->sync_mode;
1992 wdata->nr_pages = nr_pages; 1241 wdata->nr_pages = nr_pages;
1993 wdata->offset = page_offset(wdata->pages[0]); 1242 wdata->offset = page_offset(wdata->pages[0]);
1994 wdata->pagesz = PAGE_CACHE_SIZE;
1995 wdata->tailsz =
1996 min(i_size_read(mapping->host) -
1997 page_offset(wdata->pages[nr_pages - 1]),
1998 (loff_t)PAGE_CACHE_SIZE);
1999 wdata->bytes = ((nr_pages - 1) * PAGE_CACHE_SIZE) +
2000 wdata->tailsz;
2001 1243
2002 do { 1244 do {
2003 if (wdata->cfile != NULL) 1245 if (wdata->cfile != NULL)
@@ -2009,9 +1251,7 @@ retry:
2009 rc = -EBADF; 1251 rc = -EBADF;
2010 break; 1252 break;
2011 } 1253 }
2012 wdata->pid = wdata->cfile->pid; 1254 rc = cifs_async_writev(wdata);
2013 server = tlink_tcon(wdata->cfile->tlink)->ses->server;
2014 rc = server->ops->async_writev(wdata);
2015 } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN); 1255 } while (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN);
2016 1256
2017 for (i = 0; i < nr_pages; ++i) 1257 for (i = 0; i < nr_pages; ++i)
@@ -2060,9 +1300,9 @@ static int
2060cifs_writepage_locked(struct page *page, struct writeback_control *wbc) 1300cifs_writepage_locked(struct page *page, struct writeback_control *wbc)
2061{ 1301{
2062 int rc; 1302 int rc;
2063 unsigned int xid; 1303 int xid;
2064 1304
2065 xid = get_xid(); 1305 xid = GetXid();
2066/* BB add check for wbc flags */ 1306/* BB add check for wbc flags */
2067 page_cache_get(page); 1307 page_cache_get(page);
2068 if (!PageUptodate(page)) 1308 if (!PageUptodate(page))
@@ -2091,7 +1331,7 @@ retry_write:
2091 SetPageUptodate(page); 1331 SetPageUptodate(page);
2092 end_page_writeback(page); 1332 end_page_writeback(page);
2093 page_cache_release(page); 1333 page_cache_release(page);
2094 free_xid(xid); 1334 FreeXid(xid);
2095 return rc; 1335 return rc;
2096} 1336}
2097 1337
@@ -2130,9 +1370,9 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
2130 if (!PageUptodate(page)) { 1370 if (!PageUptodate(page)) {
2131 char *page_data; 1371 char *page_data;
2132 unsigned offset = pos & (PAGE_CACHE_SIZE - 1); 1372 unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
2133 unsigned int xid; 1373 int xid;
2134 1374
2135 xid = get_xid(); 1375 xid = GetXid();
2136 /* this is probably better than directly calling 1376 /* this is probably better than directly calling
2137 partialpage_write since in this function the file handle is 1377 partialpage_write since in this function the file handle is
2138 known which we might as well leverage */ 1378 known which we might as well leverage */
@@ -2143,7 +1383,7 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
2143 /* if (rc < 0) should we set writebehind rc? */ 1383 /* if (rc < 0) should we set writebehind rc? */
2144 kunmap(page); 1384 kunmap(page);
2145 1385
2146 free_xid(xid); 1386 FreeXid(xid);
2147 } else { 1387 } else {
2148 rc = copied; 1388 rc = copied;
2149 pos += copied; 1389 pos += copied;
@@ -2166,10 +1406,9 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
2166int cifs_strict_fsync(struct file *file, loff_t start, loff_t end, 1406int cifs_strict_fsync(struct file *file, loff_t start, loff_t end,
2167 int datasync) 1407 int datasync)
2168{ 1408{
2169 unsigned int xid; 1409 int xid;
2170 int rc = 0; 1410 int rc = 0;
2171 struct cifs_tcon *tcon; 1411 struct cifs_tcon *tcon;
2172 struct TCP_Server_Info *server;
2173 struct cifsFileInfo *smbfile = file->private_data; 1412 struct cifsFileInfo *smbfile = file->private_data;
2174 struct inode *inode = file->f_path.dentry->d_inode; 1413 struct inode *inode = file->f_path.dentry->d_inode;
2175 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 1414 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
@@ -2179,7 +1418,7 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end,
2179 return rc; 1418 return rc;
2180 mutex_lock(&inode->i_mutex); 1419 mutex_lock(&inode->i_mutex);
2181 1420
2182 xid = get_xid(); 1421 xid = GetXid();
2183 1422
2184 cFYI(1, "Sync file - name: %s datasync: 0x%x", 1423 cFYI(1, "Sync file - name: %s datasync: 0x%x",
2185 file->f_path.dentry->d_name.name, datasync); 1424 file->f_path.dentry->d_name.name, datasync);
@@ -2193,25 +1432,19 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end,
2193 } 1432 }
2194 1433
2195 tcon = tlink_tcon(smbfile->tlink); 1434 tcon = tlink_tcon(smbfile->tlink);
2196 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { 1435 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
2197 server = tcon->ses->server; 1436 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
2198 if (server->ops->flush)
2199 rc = server->ops->flush(xid, tcon, &smbfile->fid);
2200 else
2201 rc = -ENOSYS;
2202 }
2203 1437
2204 free_xid(xid); 1438 FreeXid(xid);
2205 mutex_unlock(&inode->i_mutex); 1439 mutex_unlock(&inode->i_mutex);
2206 return rc; 1440 return rc;
2207} 1441}
2208 1442
2209int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync) 1443int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
2210{ 1444{
2211 unsigned int xid; 1445 int xid;
2212 int rc = 0; 1446 int rc = 0;
2213 struct cifs_tcon *tcon; 1447 struct cifs_tcon *tcon;
2214 struct TCP_Server_Info *server;
2215 struct cifsFileInfo *smbfile = file->private_data; 1448 struct cifsFileInfo *smbfile = file->private_data;
2216 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 1449 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2217 struct inode *inode = file->f_mapping->host; 1450 struct inode *inode = file->f_mapping->host;
@@ -2221,21 +1454,16 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
2221 return rc; 1454 return rc;
2222 mutex_lock(&inode->i_mutex); 1455 mutex_lock(&inode->i_mutex);
2223 1456
2224 xid = get_xid(); 1457 xid = GetXid();
2225 1458
2226 cFYI(1, "Sync file - name: %s datasync: 0x%x", 1459 cFYI(1, "Sync file - name: %s datasync: 0x%x",
2227 file->f_path.dentry->d_name.name, datasync); 1460 file->f_path.dentry->d_name.name, datasync);
2228 1461
2229 tcon = tlink_tcon(smbfile->tlink); 1462 tcon = tlink_tcon(smbfile->tlink);
2230 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) { 1463 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
2231 server = tcon->ses->server; 1464 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
2232 if (server->ops->flush)
2233 rc = server->ops->flush(xid, tcon, &smbfile->fid);
2234 else
2235 rc = -ENOSYS;
2236 }
2237 1465
2238 free_xid(xid); 1466 FreeXid(xid);
2239 mutex_unlock(&inode->i_mutex); 1467 mutex_unlock(&inode->i_mutex);
2240 return rc; 1468 return rc;
2241} 1469}
@@ -2264,7 +1492,7 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
2264 unsigned long i; 1492 unsigned long i;
2265 1493
2266 for (i = 0; i < num_pages; i++) { 1494 for (i = 0; i < num_pages; i++) {
2267 pages[i] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM); 1495 pages[i] = alloc_page(__GFP_HIGHMEM);
2268 if (!pages[i]) { 1496 if (!pages[i]) {
2269 /* 1497 /*
2270 * save number of pages we have already allocated and 1498 * save number of pages we have already allocated and
@@ -2272,14 +1500,15 @@ cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
2272 */ 1500 */
2273 num_pages = i; 1501 num_pages = i;
2274 rc = -ENOMEM; 1502 rc = -ENOMEM;
2275 break; 1503 goto error;
2276 } 1504 }
2277 } 1505 }
2278 1506
2279 if (rc) { 1507 return rc;
2280 for (i = 0; i < num_pages; i++) 1508
2281 put_page(pages[i]); 1509error:
2282 } 1510 for (i = 0; i < num_pages; i++)
1511 put_page(pages[i]);
2283 return rc; 1512 return rc;
2284} 1513}
2285 1514
@@ -2290,7 +1519,9 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
2290 size_t clen; 1519 size_t clen;
2291 1520
2292 clen = min_t(const size_t, len, wsize); 1521 clen = min_t(const size_t, len, wsize);
2293 num_pages = DIV_ROUND_UP(clen, PAGE_SIZE); 1522 num_pages = clen / PAGE_CACHE_SIZE;
1523 if (clen % PAGE_CACHE_SIZE)
1524 num_pages++;
2294 1525
2295 if (cur_len) 1526 if (cur_len)
2296 *cur_len = clen; 1527 *cur_len = clen;
@@ -2298,68 +1529,24 @@ size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
2298 return num_pages; 1529 return num_pages;
2299} 1530}
2300 1531
2301static void
2302cifs_uncached_writev_complete(struct work_struct *work)
2303{
2304 int i;
2305 struct cifs_writedata *wdata = container_of(work,
2306 struct cifs_writedata, work);
2307 struct inode *inode = wdata->cfile->dentry->d_inode;
2308 struct cifsInodeInfo *cifsi = CIFS_I(inode);
2309
2310 spin_lock(&inode->i_lock);
2311 cifs_update_eof(cifsi, wdata->offset, wdata->bytes);
2312 if (cifsi->server_eof > inode->i_size)
2313 i_size_write(inode, cifsi->server_eof);
2314 spin_unlock(&inode->i_lock);
2315
2316 complete(&wdata->done);
2317
2318 if (wdata->result != -EAGAIN) {
2319 for (i = 0; i < wdata->nr_pages; i++)
2320 put_page(wdata->pages[i]);
2321 }
2322
2323 kref_put(&wdata->refcount, cifs_writedata_release);
2324}
2325
2326/* attempt to send write to server, retry on any -EAGAIN errors */
2327static int
2328cifs_uncached_retry_writev(struct cifs_writedata *wdata)
2329{
2330 int rc;
2331 struct TCP_Server_Info *server;
2332
2333 server = tlink_tcon(wdata->cfile->tlink)->ses->server;
2334
2335 do {
2336 if (wdata->cfile->invalidHandle) {
2337 rc = cifs_reopen_file(wdata->cfile, false);
2338 if (rc != 0)
2339 continue;
2340 }
2341 rc = server->ops->async_writev(wdata);
2342 } while (rc == -EAGAIN);
2343
2344 return rc;
2345}
2346
2347static ssize_t 1532static ssize_t
2348cifs_iovec_write(struct file *file, const struct iovec *iov, 1533cifs_iovec_write(struct file *file, const struct iovec *iov,
2349 unsigned long nr_segs, loff_t *poffset) 1534 unsigned long nr_segs, loff_t *poffset)
2350{ 1535{
2351 unsigned long nr_pages, i; 1536 unsigned int written;
1537 unsigned long num_pages, npages, i;
2352 size_t copied, len, cur_len; 1538 size_t copied, len, cur_len;
2353 ssize_t total_written = 0; 1539 ssize_t total_written = 0;
2354 loff_t offset; 1540 struct kvec *to_send;
1541 struct page **pages;
2355 struct iov_iter it; 1542 struct iov_iter it;
1543 struct inode *inode;
2356 struct cifsFileInfo *open_file; 1544 struct cifsFileInfo *open_file;
2357 struct cifs_tcon *tcon; 1545 struct cifs_tcon *pTcon;
2358 struct cifs_sb_info *cifs_sb; 1546 struct cifs_sb_info *cifs_sb;
2359 struct cifs_writedata *wdata, *tmp; 1547 struct cifs_io_parms io_parms;
2360 struct list_head wdata_list; 1548 int xid, rc;
2361 int rc; 1549 __u32 pid;
2362 pid_t pid;
2363 1550
2364 len = iov_length(iov, nr_segs); 1551 len = iov_length(iov, nr_segs);
2365 if (!len) 1552 if (!len)
@@ -2369,109 +1556,103 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
2369 if (rc) 1556 if (rc)
2370 return rc; 1557 return rc;
2371 1558
2372 INIT_LIST_HEAD(&wdata_list);
2373 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 1559 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2374 open_file = file->private_data; 1560 num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
2375 tcon = tlink_tcon(open_file->tlink); 1561
1562 pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
1563 if (!pages)
1564 return -ENOMEM;
2376 1565
2377 if (!tcon->ses->server->ops->async_writev) 1566 to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
2378 return -ENOSYS; 1567 if (!to_send) {
1568 kfree(pages);
1569 return -ENOMEM;
1570 }
2379 1571
2380 offset = *poffset; 1572 rc = cifs_write_allocate_pages(pages, num_pages);
1573 if (rc) {
1574 kfree(pages);
1575 kfree(to_send);
1576 return rc;
1577 }
1578
1579 xid = GetXid();
1580 open_file = file->private_data;
2381 1581
2382 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 1582 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
2383 pid = open_file->pid; 1583 pid = open_file->pid;
2384 else 1584 else
2385 pid = current->tgid; 1585 pid = current->tgid;
2386 1586
2387 iov_iter_init(&it, iov, nr_segs, len, 0); 1587 pTcon = tlink_tcon(open_file->tlink);
2388 do { 1588 inode = file->f_path.dentry->d_inode;
2389 size_t save_len;
2390
2391 nr_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
2392 wdata = cifs_writedata_alloc(nr_pages,
2393 cifs_uncached_writev_complete);
2394 if (!wdata) {
2395 rc = -ENOMEM;
2396 break;
2397 }
2398 1589
2399 rc = cifs_write_allocate_pages(wdata->pages, nr_pages); 1590 iov_iter_init(&it, iov, nr_segs, len, 0);
2400 if (rc) { 1591 npages = num_pages;
2401 kfree(wdata);
2402 break;
2403 }
2404 1592
2405 save_len = cur_len; 1593 do {
2406 for (i = 0; i < nr_pages; i++) { 1594 size_t save_len = cur_len;
2407 copied = min_t(const size_t, cur_len, PAGE_SIZE); 1595 for (i = 0; i < npages; i++) {
2408 copied = iov_iter_copy_from_user(wdata->pages[i], &it, 1596 copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE);
2409 0, copied); 1597 copied = iov_iter_copy_from_user(pages[i], &it, 0,
1598 copied);
2410 cur_len -= copied; 1599 cur_len -= copied;
2411 iov_iter_advance(&it, copied); 1600 iov_iter_advance(&it, copied);
1601 to_send[i+1].iov_base = kmap(pages[i]);
1602 to_send[i+1].iov_len = copied;
2412 } 1603 }
1604
2413 cur_len = save_len - cur_len; 1605 cur_len = save_len - cur_len;
2414 1606
2415 wdata->sync_mode = WB_SYNC_ALL; 1607 do {
2416 wdata->nr_pages = nr_pages; 1608 if (open_file->invalidHandle) {
2417 wdata->offset = (__u64)offset; 1609 rc = cifs_reopen_file(open_file, false);
2418 wdata->cfile = cifsFileInfo_get(open_file); 1610 if (rc != 0)
2419 wdata->pid = pid; 1611 break;
2420 wdata->bytes = cur_len; 1612 }
2421 wdata->pagesz = PAGE_SIZE; 1613 io_parms.netfid = open_file->netfid;
2422 wdata->tailsz = cur_len - ((nr_pages - 1) * PAGE_SIZE); 1614 io_parms.pid = pid;
2423 rc = cifs_uncached_retry_writev(wdata); 1615 io_parms.tcon = pTcon;
2424 if (rc) { 1616 io_parms.offset = *poffset;
2425 kref_put(&wdata->refcount, cifs_writedata_release); 1617 io_parms.length = cur_len;
1618 rc = CIFSSMBWrite2(xid, &io_parms, &written, to_send,
1619 npages, 0);
1620 } while (rc == -EAGAIN);
1621
1622 for (i = 0; i < npages; i++)
1623 kunmap(pages[i]);
1624
1625 if (written) {
1626 len -= written;
1627 total_written += written;
1628 cifs_update_eof(CIFS_I(inode), *poffset, written);
1629 *poffset += written;
1630 } else if (rc < 0) {
1631 if (!total_written)
1632 total_written = rc;
2426 break; 1633 break;
2427 } 1634 }
2428 1635
2429 list_add_tail(&wdata->list, &wdata_list); 1636 /* get length and number of kvecs of the next write */
2430 offset += cur_len; 1637 npages = get_numpages(cifs_sb->wsize, len, &cur_len);
2431 len -= cur_len;
2432 } while (len > 0); 1638 } while (len > 0);
2433 1639
2434 /* 1640 if (total_written > 0) {
2435 * If at least one write was successfully sent, then discard any rc 1641 spin_lock(&inode->i_lock);
2436 * value from the later writes. If the other write succeeds, then 1642 if (*poffset > inode->i_size)
2437 * we'll end up returning whatever was written. If it fails, then 1643 i_size_write(inode, *poffset);
2438 * we'll get a new rc value from that. 1644 spin_unlock(&inode->i_lock);
2439 */
2440 if (!list_empty(&wdata_list))
2441 rc = 0;
2442
2443 /*
2444 * Wait for and collect replies for any successful sends in order of
2445 * increasing offset. Once an error is hit or we get a fatal signal
2446 * while waiting, then return without waiting for any more replies.
2447 */
2448restart_loop:
2449 list_for_each_entry_safe(wdata, tmp, &wdata_list, list) {
2450 if (!rc) {
2451 /* FIXME: freezable too? */
2452 rc = wait_for_completion_killable(&wdata->done);
2453 if (rc)
2454 rc = -EINTR;
2455 else if (wdata->result)
2456 rc = wdata->result;
2457 else
2458 total_written += wdata->bytes;
2459
2460 /* resend call if it's a retryable error */
2461 if (rc == -EAGAIN) {
2462 rc = cifs_uncached_retry_writev(wdata);
2463 goto restart_loop;
2464 }
2465 }
2466 list_del_init(&wdata->list);
2467 kref_put(&wdata->refcount, cifs_writedata_release);
2468 } 1645 }
2469 1646
2470 if (total_written > 0) 1647 cifs_stats_bytes_written(pTcon, total_written);
2471 *poffset += total_written; 1648 mark_inode_dirty_sync(inode);
2472 1649
2473 cifs_stats_bytes_written(tcon, total_written); 1650 for (i = 0; i < num_pages; i++)
2474 return total_written ? total_written : (ssize_t)rc; 1651 put_page(pages[i]);
1652 kfree(to_send);
1653 kfree(pages);
1654 FreeXid(xid);
1655 return total_written;
2475} 1656}
2476 1657
2477ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, 1658ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov,
@@ -2497,304 +1678,43 @@ ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov,
2497 return written; 1678 return written;
2498} 1679}
2499 1680
2500static ssize_t 1681ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov,
2501cifs_writev(struct kiocb *iocb, const struct iovec *iov, 1682 unsigned long nr_segs, loff_t pos)
2502 unsigned long nr_segs, loff_t pos)
2503{ 1683{
2504 struct file *file = iocb->ki_filp; 1684 struct inode *inode;
2505 struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
2506 struct inode *inode = file->f_mapping->host;
2507 struct cifsInodeInfo *cinode = CIFS_I(inode);
2508 struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
2509 ssize_t rc = -EACCES;
2510
2511 BUG_ON(iocb->ki_pos != pos);
2512
2513 sb_start_write(inode->i_sb);
2514
2515 /*
2516 * We need to hold the sem to be sure nobody modifies lock list
2517 * with a brlock that prevents writing.
2518 */
2519 down_read(&cinode->lock_sem);
2520 if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs),
2521 server->vals->exclusive_lock_type, NULL,
2522 CIFS_WRITE_OP)) {
2523 mutex_lock(&inode->i_mutex);
2524 rc = __generic_file_aio_write(iocb, iov, nr_segs,
2525 &iocb->ki_pos);
2526 mutex_unlock(&inode->i_mutex);
2527 }
2528
2529 if (rc > 0 || rc == -EIOCBQUEUED) {
2530 ssize_t err;
2531 1685
2532 err = generic_write_sync(file, pos, rc); 1686 inode = iocb->ki_filp->f_path.dentry->d_inode;
2533 if (err < 0 && rc > 0)
2534 rc = err;
2535 }
2536 1687
2537 up_read(&cinode->lock_sem); 1688 if (CIFS_I(inode)->clientCanCacheAll)
2538 sb_end_write(inode->i_sb); 1689 return generic_file_aio_write(iocb, iov, nr_segs, pos);
2539 return rc;
2540}
2541 1690
2542ssize_t
2543cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov,
2544 unsigned long nr_segs, loff_t pos)
2545{
2546 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
2547 struct cifsInodeInfo *cinode = CIFS_I(inode);
2548 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2549 struct cifsFileInfo *cfile = (struct cifsFileInfo *)
2550 iocb->ki_filp->private_data;
2551 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
2552 ssize_t written;
2553
2554 if (cinode->clientCanCacheAll) {
2555 if (cap_unix(tcon->ses) &&
2556 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability))
2557 && ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
2558 return generic_file_aio_write(iocb, iov, nr_segs, pos);
2559 return cifs_writev(iocb, iov, nr_segs, pos);
2560 }
2561 /* 1691 /*
2562 * For non-oplocked files in strict cache mode we need to write the data 1692 * In strict cache mode we need to write the data to the server exactly
2563 * to the server exactly from the pos to pos+len-1 rather than flush all 1693 * from the pos to pos+len-1 rather than flush all affected pages
2564 * affected pages because it may cause a error with mandatory locks on 1694 * because it may cause a error with mandatory locks on these pages but
2565 * these pages but not on the region from pos to ppos+len-1. 1695 * not on the region from pos to ppos+len-1.
2566 */ 1696 */
2567 written = cifs_user_writev(iocb, iov, nr_segs, pos);
2568 if (written > 0 && cinode->clientCanCacheRead) {
2569 /*
2570 * Windows 7 server can delay breaking level2 oplock if a write
2571 * request comes - break it on the client to prevent reading
2572 * an old data.
2573 */
2574 cifs_invalidate_mapping(inode);
2575 cFYI(1, "Set no oplock for inode=%p after a write operation",
2576 inode);
2577 cinode->clientCanCacheRead = false;
2578 }
2579 return written;
2580}
2581 1697
2582static struct cifs_readdata * 1698 return cifs_user_writev(iocb, iov, nr_segs, pos);
2583cifs_readdata_alloc(unsigned int nr_pages, work_func_t complete)
2584{
2585 struct cifs_readdata *rdata;
2586
2587 rdata = kzalloc(sizeof(*rdata) + (sizeof(struct page *) * nr_pages),
2588 GFP_KERNEL);
2589 if (rdata != NULL) {
2590 kref_init(&rdata->refcount);
2591 INIT_LIST_HEAD(&rdata->list);
2592 init_completion(&rdata->done);
2593 INIT_WORK(&rdata->work, complete);
2594 }
2595
2596 return rdata;
2597}
2598
2599void
2600cifs_readdata_release(struct kref *refcount)
2601{
2602 struct cifs_readdata *rdata = container_of(refcount,
2603 struct cifs_readdata, refcount);
2604
2605 if (rdata->cfile)
2606 cifsFileInfo_put(rdata->cfile);
2607
2608 kfree(rdata);
2609}
2610
2611static int
2612cifs_read_allocate_pages(struct cifs_readdata *rdata, unsigned int nr_pages)
2613{
2614 int rc = 0;
2615 struct page *page;
2616 unsigned int i;
2617
2618 for (i = 0; i < nr_pages; i++) {
2619 page = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
2620 if (!page) {
2621 rc = -ENOMEM;
2622 break;
2623 }
2624 rdata->pages[i] = page;
2625 }
2626
2627 if (rc) {
2628 for (i = 0; i < nr_pages; i++) {
2629 put_page(rdata->pages[i]);
2630 rdata->pages[i] = NULL;
2631 }
2632 }
2633 return rc;
2634}
2635
2636static void
2637cifs_uncached_readdata_release(struct kref *refcount)
2638{
2639 struct cifs_readdata *rdata = container_of(refcount,
2640 struct cifs_readdata, refcount);
2641 unsigned int i;
2642
2643 for (i = 0; i < rdata->nr_pages; i++) {
2644 put_page(rdata->pages[i]);
2645 rdata->pages[i] = NULL;
2646 }
2647 cifs_readdata_release(refcount);
2648}
2649
2650static int
2651cifs_retry_async_readv(struct cifs_readdata *rdata)
2652{
2653 int rc;
2654 struct TCP_Server_Info *server;
2655
2656 server = tlink_tcon(rdata->cfile->tlink)->ses->server;
2657
2658 do {
2659 if (rdata->cfile->invalidHandle) {
2660 rc = cifs_reopen_file(rdata->cfile, true);
2661 if (rc != 0)
2662 continue;
2663 }
2664 rc = server->ops->async_readv(rdata);
2665 } while (rc == -EAGAIN);
2666
2667 return rc;
2668}
2669
2670/**
2671 * cifs_readdata_to_iov - copy data from pages in response to an iovec
2672 * @rdata: the readdata response with list of pages holding data
2673 * @iov: vector in which we should copy the data
2674 * @nr_segs: number of segments in vector
2675 * @offset: offset into file of the first iovec
2676 * @copied: used to return the amount of data copied to the iov
2677 *
2678 * This function copies data from a list of pages in a readdata response into
2679 * an array of iovecs. It will first calculate where the data should go
2680 * based on the info in the readdata and then copy the data into that spot.
2681 */
2682static ssize_t
2683cifs_readdata_to_iov(struct cifs_readdata *rdata, const struct iovec *iov,
2684 unsigned long nr_segs, loff_t offset, ssize_t *copied)
2685{
2686 int rc = 0;
2687 struct iov_iter ii;
2688 size_t pos = rdata->offset - offset;
2689 ssize_t remaining = rdata->bytes;
2690 unsigned char *pdata;
2691 unsigned int i;
2692
2693 /* set up iov_iter and advance to the correct offset */
2694 iov_iter_init(&ii, iov, nr_segs, iov_length(iov, nr_segs), 0);
2695 iov_iter_advance(&ii, pos);
2696
2697 *copied = 0;
2698 for (i = 0; i < rdata->nr_pages; i++) {
2699 ssize_t copy;
2700 struct page *page = rdata->pages[i];
2701
2702 /* copy a whole page or whatever's left */
2703 copy = min_t(ssize_t, remaining, PAGE_SIZE);
2704
2705 /* ...but limit it to whatever space is left in the iov */
2706 copy = min_t(ssize_t, copy, iov_iter_count(&ii));
2707
2708 /* go while there's data to be copied and no errors */
2709 if (copy && !rc) {
2710 pdata = kmap(page);
2711 rc = memcpy_toiovecend(ii.iov, pdata, ii.iov_offset,
2712 (int)copy);
2713 kunmap(page);
2714 if (!rc) {
2715 *copied += copy;
2716 remaining -= copy;
2717 iov_iter_advance(&ii, copy);
2718 }
2719 }
2720 }
2721
2722 return rc;
2723}
2724
2725static void
2726cifs_uncached_readv_complete(struct work_struct *work)
2727{
2728 struct cifs_readdata *rdata = container_of(work,
2729 struct cifs_readdata, work);
2730
2731 complete(&rdata->done);
2732 kref_put(&rdata->refcount, cifs_uncached_readdata_release);
2733}
2734
2735static int
2736cifs_uncached_read_into_pages(struct TCP_Server_Info *server,
2737 struct cifs_readdata *rdata, unsigned int len)
2738{
2739 int total_read = 0, result = 0;
2740 unsigned int i;
2741 unsigned int nr_pages = rdata->nr_pages;
2742 struct kvec iov;
2743
2744 rdata->tailsz = PAGE_SIZE;
2745 for (i = 0; i < nr_pages; i++) {
2746 struct page *page = rdata->pages[i];
2747
2748 if (len >= PAGE_SIZE) {
2749 /* enough data to fill the page */
2750 iov.iov_base = kmap(page);
2751 iov.iov_len = PAGE_SIZE;
2752 cFYI(1, "%u: iov_base=%p iov_len=%zu",
2753 i, iov.iov_base, iov.iov_len);
2754 len -= PAGE_SIZE;
2755 } else if (len > 0) {
2756 /* enough for partial page, fill and zero the rest */
2757 iov.iov_base = kmap(page);
2758 iov.iov_len = len;
2759 cFYI(1, "%u: iov_base=%p iov_len=%zu",
2760 i, iov.iov_base, iov.iov_len);
2761 memset(iov.iov_base + len, '\0', PAGE_SIZE - len);
2762 rdata->tailsz = len;
2763 len = 0;
2764 } else {
2765 /* no need to hold page hostage */
2766 rdata->pages[i] = NULL;
2767 rdata->nr_pages--;
2768 put_page(page);
2769 continue;
2770 }
2771
2772 result = cifs_readv_from_socket(server, &iov, 1, iov.iov_len);
2773 kunmap(page);
2774 if (result < 0)
2775 break;
2776
2777 total_read += result;
2778 }
2779
2780 return total_read > 0 ? total_read : result;
2781} 1699}
2782 1700
2783static ssize_t 1701static ssize_t
2784cifs_iovec_read(struct file *file, const struct iovec *iov, 1702cifs_iovec_read(struct file *file, const struct iovec *iov,
2785 unsigned long nr_segs, loff_t *poffset) 1703 unsigned long nr_segs, loff_t *poffset)
2786{ 1704{
2787 ssize_t rc; 1705 int rc;
1706 int xid;
1707 ssize_t total_read;
1708 unsigned int bytes_read = 0;
2788 size_t len, cur_len; 1709 size_t len, cur_len;
2789 ssize_t total_read = 0; 1710 int iov_offset = 0;
2790 loff_t offset = *poffset;
2791 unsigned int npages;
2792 struct cifs_sb_info *cifs_sb; 1711 struct cifs_sb_info *cifs_sb;
2793 struct cifs_tcon *tcon; 1712 struct cifs_tcon *pTcon;
2794 struct cifsFileInfo *open_file; 1713 struct cifsFileInfo *open_file;
2795 struct cifs_readdata *rdata, *tmp; 1714 struct smb_com_read_rsp *pSMBr;
2796 struct list_head rdata_list; 1715 struct cifs_io_parms io_parms;
2797 pid_t pid; 1716 char *read_data;
1717 __u32 pid;
2798 1718
2799 if (!nr_segs) 1719 if (!nr_segs)
2800 return 0; 1720 return 0;
@@ -2803,13 +1723,11 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,
2803 if (!len) 1723 if (!len)
2804 return 0; 1724 return 0;
2805 1725
2806 INIT_LIST_HEAD(&rdata_list); 1726 xid = GetXid();
2807 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 1727 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2808 open_file = file->private_data;
2809 tcon = tlink_tcon(open_file->tlink);
2810 1728
2811 if (!tcon->ses->server->ops->async_readv) 1729 open_file = file->private_data;
2812 return -ENOSYS; 1730 pTcon = tlink_tcon(open_file->tlink);
2813 1731
2814 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 1732 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
2815 pid = open_file->pid; 1733 pid = open_file->pid;
@@ -2819,84 +1737,56 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,
2819 if ((file->f_flags & O_ACCMODE) == O_WRONLY) 1737 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
2820 cFYI(1, "attempting read on write only file instance"); 1738 cFYI(1, "attempting read on write only file instance");
2821 1739
2822 do { 1740 for (total_read = 0; total_read < len; total_read += bytes_read) {
2823 cur_len = min_t(const size_t, len - total_read, cifs_sb->rsize); 1741 cur_len = min_t(const size_t, len - total_read, cifs_sb->rsize);
2824 npages = DIV_ROUND_UP(cur_len, PAGE_SIZE); 1742 rc = -EAGAIN;
2825 1743 read_data = NULL;
2826 /* allocate a readdata struct */
2827 rdata = cifs_readdata_alloc(npages,
2828 cifs_uncached_readv_complete);
2829 if (!rdata) {
2830 rc = -ENOMEM;
2831 goto error;
2832 }
2833
2834 rc = cifs_read_allocate_pages(rdata, npages);
2835 if (rc)
2836 goto error;
2837
2838 rdata->cfile = cifsFileInfo_get(open_file);
2839 rdata->nr_pages = npages;
2840 rdata->offset = offset;
2841 rdata->bytes = cur_len;
2842 rdata->pid = pid;
2843 rdata->pagesz = PAGE_SIZE;
2844 rdata->read_into_pages = cifs_uncached_read_into_pages;
2845
2846 rc = cifs_retry_async_readv(rdata);
2847error:
2848 if (rc) {
2849 kref_put(&rdata->refcount,
2850 cifs_uncached_readdata_release);
2851 break;
2852 }
2853
2854 list_add_tail(&rdata->list, &rdata_list);
2855 offset += cur_len;
2856 len -= cur_len;
2857 } while (len > 0);
2858
2859 /* if at least one read request send succeeded, then reset rc */
2860 if (!list_empty(&rdata_list))
2861 rc = 0;
2862 1744
2863 /* the loop below should proceed in the order of increasing offsets */ 1745 while (rc == -EAGAIN) {
2864restart_loop: 1746 int buf_type = CIFS_NO_BUFFER;
2865 list_for_each_entry_safe(rdata, tmp, &rdata_list, list) { 1747 if (open_file->invalidHandle) {
2866 if (!rc) { 1748 rc = cifs_reopen_file(open_file, true);
2867 ssize_t copied; 1749 if (rc != 0)
2868 1750 break;
2869 /* FIXME: freezable sleep too? */ 1751 }
2870 rc = wait_for_completion_killable(&rdata->done); 1752 io_parms.netfid = open_file->netfid;
2871 if (rc) 1753 io_parms.pid = pid;
2872 rc = -EINTR; 1754 io_parms.tcon = pTcon;
2873 else if (rdata->result) 1755 io_parms.offset = *poffset;
2874 rc = rdata->result; 1756 io_parms.length = cur_len;
2875 else { 1757 rc = CIFSSMBRead(xid, &io_parms, &bytes_read,
2876 rc = cifs_readdata_to_iov(rdata, iov, 1758 &read_data, &buf_type);
2877 nr_segs, *poffset, 1759 pSMBr = (struct smb_com_read_rsp *)read_data;
2878 &copied); 1760 if (read_data) {
2879 total_read += copied; 1761 char *data_offset = read_data + 4 +
1762 le16_to_cpu(pSMBr->DataOffset);
1763 if (memcpy_toiovecend(iov, data_offset,
1764 iov_offset, bytes_read))
1765 rc = -EFAULT;
1766 if (buf_type == CIFS_SMALL_BUFFER)
1767 cifs_small_buf_release(read_data);
1768 else if (buf_type == CIFS_LARGE_BUFFER)
1769 cifs_buf_release(read_data);
1770 read_data = NULL;
1771 iov_offset += bytes_read;
2880 } 1772 }
1773 }
2881 1774
2882 /* resend call if it's a retryable error */ 1775 if (rc || (bytes_read == 0)) {
2883 if (rc == -EAGAIN) { 1776 if (total_read) {
2884 rc = cifs_retry_async_readv(rdata); 1777 break;
2885 goto restart_loop; 1778 } else {
1779 FreeXid(xid);
1780 return rc;
2886 } 1781 }
1782 } else {
1783 cifs_stats_bytes_read(pTcon, bytes_read);
1784 *poffset += bytes_read;
2887 } 1785 }
2888 list_del_init(&rdata->list);
2889 kref_put(&rdata->refcount, cifs_uncached_readdata_release);
2890 } 1786 }
2891 1787
2892 cifs_stats_bytes_read(tcon, total_read); 1788 FreeXid(xid);
2893 *poffset += total_read; 1789 return total_read;
2894
2895 /* mask nodata case */
2896 if (rc == -ENODATA)
2897 rc = 0;
2898
2899 return total_read ? total_read : rc;
2900} 1790}
2901 1791
2902ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov, 1792ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov,
@@ -2911,17 +1801,15 @@ ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov,
2911 return read; 1801 return read;
2912} 1802}
2913 1803
2914ssize_t 1804ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov,
2915cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, 1805 unsigned long nr_segs, loff_t pos)
2916 unsigned long nr_segs, loff_t pos)
2917{ 1806{
2918 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; 1807 struct inode *inode;
2919 struct cifsInodeInfo *cinode = CIFS_I(inode); 1808
2920 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 1809 inode = iocb->ki_filp->f_path.dentry->d_inode;
2921 struct cifsFileInfo *cfile = (struct cifsFileInfo *) 1810
2922 iocb->ki_filp->private_data; 1811 if (CIFS_I(inode)->clientCanCacheRead)
2923 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 1812 return generic_file_aio_read(iocb, iov, nr_segs, pos);
2924 int rc = -EACCES;
2925 1813
2926 /* 1814 /*
2927 * In strict cache mode we need to read from the server all the time 1815 * In strict cache mode we need to read from the server all the time
@@ -2931,64 +1819,36 @@ cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov,
2931 * on pages affected by this read but not on the region from pos to 1819 * on pages affected by this read but not on the region from pos to
2932 * pos+len-1. 1820 * pos+len-1.
2933 */ 1821 */
2934 if (!cinode->clientCanCacheRead)
2935 return cifs_user_readv(iocb, iov, nr_segs, pos);
2936 1822
2937 if (cap_unix(tcon->ses) && 1823 return cifs_user_readv(iocb, iov, nr_segs, pos);
2938 (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
2939 ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
2940 return generic_file_aio_read(iocb, iov, nr_segs, pos);
2941
2942 /*
2943 * We need to hold the sem to be sure nobody modifies lock list
2944 * with a brlock that prevents reading.
2945 */
2946 down_read(&cinode->lock_sem);
2947 if (!cifs_find_lock_conflict(cfile, pos, iov_length(iov, nr_segs),
2948 tcon->ses->server->vals->shared_lock_type,
2949 NULL, CIFS_READ_OP))
2950 rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
2951 up_read(&cinode->lock_sem);
2952 return rc;
2953} 1824}
2954 1825
2955static ssize_t 1826static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
2956cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset) 1827 loff_t *poffset)
2957{ 1828{
2958 int rc = -EACCES; 1829 int rc = -EACCES;
2959 unsigned int bytes_read = 0; 1830 unsigned int bytes_read = 0;
2960 unsigned int total_read; 1831 unsigned int total_read;
2961 unsigned int current_read_size; 1832 unsigned int current_read_size;
2962 unsigned int rsize;
2963 struct cifs_sb_info *cifs_sb; 1833 struct cifs_sb_info *cifs_sb;
2964 struct cifs_tcon *tcon; 1834 struct cifs_tcon *pTcon;
2965 struct TCP_Server_Info *server; 1835 int xid;
2966 unsigned int xid; 1836 char *current_offset;
2967 char *cur_offset;
2968 struct cifsFileInfo *open_file; 1837 struct cifsFileInfo *open_file;
2969 struct cifs_io_parms io_parms; 1838 struct cifs_io_parms io_parms;
2970 int buf_type = CIFS_NO_BUFFER; 1839 int buf_type = CIFS_NO_BUFFER;
2971 __u32 pid; 1840 __u32 pid;
2972 1841
2973 xid = get_xid(); 1842 xid = GetXid();
2974 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 1843 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2975 1844
2976 /* FIXME: set up handlers for larger reads and/or convert to async */
2977 rsize = min_t(unsigned int, cifs_sb->rsize, CIFSMaxBufSize);
2978
2979 if (file->private_data == NULL) { 1845 if (file->private_data == NULL) {
2980 rc = -EBADF; 1846 rc = -EBADF;
2981 free_xid(xid); 1847 FreeXid(xid);
2982 return rc; 1848 return rc;
2983 } 1849 }
2984 open_file = file->private_data; 1850 open_file = file->private_data;
2985 tcon = tlink_tcon(open_file->tlink); 1851 pTcon = tlink_tcon(open_file->tlink);
2986 server = tcon->ses->server;
2987
2988 if (!server->ops->sync_read) {
2989 free_xid(xid);
2990 return -ENOSYS;
2991 }
2992 1852
2993 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 1853 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
2994 pid = open_file->pid; 1854 pid = open_file->pid;
@@ -2998,17 +1858,17 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset)
2998 if ((file->f_flags & O_ACCMODE) == O_WRONLY) 1858 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
2999 cFYI(1, "attempting read on write only file instance"); 1859 cFYI(1, "attempting read on write only file instance");
3000 1860
3001 for (total_read = 0, cur_offset = read_data; read_size > total_read; 1861 for (total_read = 0, current_offset = read_data;
3002 total_read += bytes_read, cur_offset += bytes_read) { 1862 read_size > total_read;
3003 current_read_size = min_t(uint, read_size - total_read, rsize); 1863 total_read += bytes_read, current_offset += bytes_read) {
3004 /* 1864 current_read_size = min_t(const int, read_size - total_read,
3005 * For windows me and 9x we do not want to request more than it 1865 cifs_sb->rsize);
3006 * negotiated since it will refuse the read then. 1866 /* For windows me and 9x we do not want to request more
3007 */ 1867 than it negotiated since it will refuse the read then */
3008 if ((tcon->ses) && !(tcon->ses->capabilities & 1868 if ((pTcon->ses) &&
3009 tcon->ses->server->vals->cap_large_files)) { 1869 !(pTcon->ses->capabilities & CAP_LARGE_FILES)) {
3010 current_read_size = min_t(uint, current_read_size, 1870 current_read_size = min_t(const int, current_read_size,
3011 CIFSMaxBufSize); 1871 pTcon->ses->server->maxBuf - 128);
3012 } 1872 }
3013 rc = -EAGAIN; 1873 rc = -EAGAIN;
3014 while (rc == -EAGAIN) { 1874 while (rc == -EAGAIN) {
@@ -3017,27 +1877,27 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset)
3017 if (rc != 0) 1877 if (rc != 0)
3018 break; 1878 break;
3019 } 1879 }
1880 io_parms.netfid = open_file->netfid;
3020 io_parms.pid = pid; 1881 io_parms.pid = pid;
3021 io_parms.tcon = tcon; 1882 io_parms.tcon = pTcon;
3022 io_parms.offset = *offset; 1883 io_parms.offset = *poffset;
3023 io_parms.length = current_read_size; 1884 io_parms.length = current_read_size;
3024 rc = server->ops->sync_read(xid, open_file, &io_parms, 1885 rc = CIFSSMBRead(xid, &io_parms, &bytes_read,
3025 &bytes_read, &cur_offset, 1886 &current_offset, &buf_type);
3026 &buf_type);
3027 } 1887 }
3028 if (rc || (bytes_read == 0)) { 1888 if (rc || (bytes_read == 0)) {
3029 if (total_read) { 1889 if (total_read) {
3030 break; 1890 break;
3031 } else { 1891 } else {
3032 free_xid(xid); 1892 FreeXid(xid);
3033 return rc; 1893 return rc;
3034 } 1894 }
3035 } else { 1895 } else {
3036 cifs_stats_bytes_read(tcon, total_read); 1896 cifs_stats_bytes_read(pTcon, total_read);
3037 *offset += bytes_read; 1897 *poffset += bytes_read;
3038 } 1898 }
3039 } 1899 }
3040 free_xid(xid); 1900 FreeXid(xid);
3041 return total_read; 1901 return total_read;
3042} 1902}
3043 1903
@@ -3057,7 +1917,6 @@ cifs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
3057static struct vm_operations_struct cifs_file_vm_ops = { 1917static struct vm_operations_struct cifs_file_vm_ops = {
3058 .fault = filemap_fault, 1918 .fault = filemap_fault,
3059 .page_mkwrite = cifs_page_mkwrite, 1919 .page_mkwrite = cifs_page_mkwrite,
3060 .remap_pages = generic_file_remap_pages,
3061}; 1920};
3062 1921
3063int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) 1922int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
@@ -3065,7 +1924,7 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
3065 int rc, xid; 1924 int rc, xid;
3066 struct inode *inode = file->f_path.dentry->d_inode; 1925 struct inode *inode = file->f_path.dentry->d_inode;
3067 1926
3068 xid = get_xid(); 1927 xid = GetXid();
3069 1928
3070 if (!CIFS_I(inode)->clientCanCacheRead) { 1929 if (!CIFS_I(inode)->clientCanCacheRead) {
3071 rc = cifs_invalidate_mapping(inode); 1930 rc = cifs_invalidate_mapping(inode);
@@ -3076,7 +1935,7 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
3076 rc = generic_file_mmap(file, vma); 1935 rc = generic_file_mmap(file, vma);
3077 if (rc == 0) 1936 if (rc == 0)
3078 vma->vm_ops = &cifs_file_vm_ops; 1937 vma->vm_ops = &cifs_file_vm_ops;
3079 free_xid(xid); 1938 FreeXid(xid);
3080 return rc; 1939 return rc;
3081} 1940}
3082 1941
@@ -3084,142 +1943,96 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
3084{ 1943{
3085 int rc, xid; 1944 int rc, xid;
3086 1945
3087 xid = get_xid(); 1946 xid = GetXid();
3088 rc = cifs_revalidate_file(file); 1947 rc = cifs_revalidate_file(file);
3089 if (rc) { 1948 if (rc) {
3090 cFYI(1, "Validation prior to mmap failed, error=%d", rc); 1949 cFYI(1, "Validation prior to mmap failed, error=%d", rc);
3091 free_xid(xid); 1950 FreeXid(xid);
3092 return rc; 1951 return rc;
3093 } 1952 }
3094 rc = generic_file_mmap(file, vma); 1953 rc = generic_file_mmap(file, vma);
3095 if (rc == 0) 1954 if (rc == 0)
3096 vma->vm_ops = &cifs_file_vm_ops; 1955 vma->vm_ops = &cifs_file_vm_ops;
3097 free_xid(xid); 1956 FreeXid(xid);
3098 return rc; 1957 return rc;
3099} 1958}
3100 1959
3101static void 1960
3102cifs_readv_complete(struct work_struct *work) 1961static void cifs_copy_cache_pages(struct address_space *mapping,
1962 struct list_head *pages, int bytes_read, char *data)
3103{ 1963{
3104 unsigned int i; 1964 struct page *page;
3105 struct cifs_readdata *rdata = container_of(work, 1965 char *target;
3106 struct cifs_readdata, work);
3107 1966
3108 for (i = 0; i < rdata->nr_pages; i++) { 1967 while (bytes_read > 0) {
3109 struct page *page = rdata->pages[i]; 1968 if (list_empty(pages))
1969 break;
3110 1970
3111 lru_cache_add_file(page); 1971 page = list_entry(pages->prev, struct page, lru);
1972 list_del(&page->lru);
3112 1973
3113 if (rdata->result == 0) { 1974 if (add_to_page_cache_lru(page, mapping, page->index,
3114 flush_dcache_page(page); 1975 GFP_KERNEL)) {
3115 SetPageUptodate(page); 1976 page_cache_release(page);
1977 cFYI(1, "Add page cache failed");
1978 data += PAGE_CACHE_SIZE;
1979 bytes_read -= PAGE_CACHE_SIZE;
1980 continue;
3116 } 1981 }
3117
3118 unlock_page(page);
3119
3120 if (rdata->result == 0)
3121 cifs_readpage_to_fscache(rdata->mapping->host, page);
3122
3123 page_cache_release(page); 1982 page_cache_release(page);
3124 rdata->pages[i] = NULL;
3125 }
3126 kref_put(&rdata->refcount, cifs_readdata_release);
3127}
3128 1983
3129static int 1984 target = kmap_atomic(page, KM_USER0);
3130cifs_readpages_read_into_pages(struct TCP_Server_Info *server, 1985
3131 struct cifs_readdata *rdata, unsigned int len) 1986 if (PAGE_CACHE_SIZE > bytes_read) {
3132{ 1987 memcpy(target, data, bytes_read);
3133 int total_read = 0, result = 0; 1988 /* zero the tail end of this partial page */
3134 unsigned int i; 1989 memset(target + bytes_read, 0,
3135 u64 eof; 1990 PAGE_CACHE_SIZE - bytes_read);
3136 pgoff_t eof_index; 1991 bytes_read = 0;
3137 unsigned int nr_pages = rdata->nr_pages;
3138 struct kvec iov;
3139
3140 /* determine the eof that the server (probably) has */
3141 eof = CIFS_I(rdata->mapping->host)->server_eof;
3142 eof_index = eof ? (eof - 1) >> PAGE_CACHE_SHIFT : 0;
3143 cFYI(1, "eof=%llu eof_index=%lu", eof, eof_index);
3144
3145 rdata->tailsz = PAGE_CACHE_SIZE;
3146 for (i = 0; i < nr_pages; i++) {
3147 struct page *page = rdata->pages[i];
3148
3149 if (len >= PAGE_CACHE_SIZE) {
3150 /* enough data to fill the page */
3151 iov.iov_base = kmap(page);
3152 iov.iov_len = PAGE_CACHE_SIZE;
3153 cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu",
3154 i, page->index, iov.iov_base, iov.iov_len);
3155 len -= PAGE_CACHE_SIZE;
3156 } else if (len > 0) {
3157 /* enough for partial page, fill and zero the rest */
3158 iov.iov_base = kmap(page);
3159 iov.iov_len = len;
3160 cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu",
3161 i, page->index, iov.iov_base, iov.iov_len);
3162 memset(iov.iov_base + len,
3163 '\0', PAGE_CACHE_SIZE - len);
3164 rdata->tailsz = len;
3165 len = 0;
3166 } else if (page->index > eof_index) {
3167 /*
3168 * The VFS will not try to do readahead past the
3169 * i_size, but it's possible that we have outstanding
3170 * writes with gaps in the middle and the i_size hasn't
3171 * caught up yet. Populate those with zeroed out pages
3172 * to prevent the VFS from repeatedly attempting to
3173 * fill them until the writes are flushed.
3174 */
3175 zero_user(page, 0, PAGE_CACHE_SIZE);
3176 lru_cache_add_file(page);
3177 flush_dcache_page(page);
3178 SetPageUptodate(page);
3179 unlock_page(page);
3180 page_cache_release(page);
3181 rdata->pages[i] = NULL;
3182 rdata->nr_pages--;
3183 continue;
3184 } else { 1992 } else {
3185 /* no need to hold page hostage */ 1993 memcpy(target, data, PAGE_CACHE_SIZE);
3186 lru_cache_add_file(page); 1994 bytes_read -= PAGE_CACHE_SIZE;
3187 unlock_page(page);
3188 page_cache_release(page);
3189 rdata->pages[i] = NULL;
3190 rdata->nr_pages--;
3191 continue;
3192 } 1995 }
1996 kunmap_atomic(target, KM_USER0);
3193 1997
3194 result = cifs_readv_from_socket(server, &iov, 1, iov.iov_len); 1998 flush_dcache_page(page);
3195 kunmap(page); 1999 SetPageUptodate(page);
3196 if (result < 0) 2000 unlock_page(page);
3197 break; 2001 data += PAGE_CACHE_SIZE;
3198 2002
3199 total_read += result; 2003 /* add page to FS-Cache */
2004 cifs_readpage_to_fscache(mapping->host, page);
3200 } 2005 }
3201 2006 return;
3202 return total_read > 0 ? total_read : result;
3203} 2007}
3204 2008
3205static int cifs_readpages(struct file *file, struct address_space *mapping, 2009static int cifs_readpages(struct file *file, struct address_space *mapping,
3206 struct list_head *page_list, unsigned num_pages) 2010 struct list_head *page_list, unsigned num_pages)
3207{ 2011{
3208 int rc; 2012 int rc = -EACCES;
3209 struct list_head tmplist; 2013 int xid;
3210 struct cifsFileInfo *open_file = file->private_data; 2014 loff_t offset;
3211 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 2015 struct page *page;
3212 unsigned int rsize = cifs_sb->rsize; 2016 struct cifs_sb_info *cifs_sb;
3213 pid_t pid; 2017 struct cifs_tcon *pTcon;
2018 unsigned int bytes_read = 0;
2019 unsigned int read_size, i;
2020 char *smb_read_data = NULL;
2021 struct smb_com_read_rsp *pSMBr;
2022 struct cifsFileInfo *open_file;
2023 struct cifs_io_parms io_parms;
2024 int buf_type = CIFS_NO_BUFFER;
2025 __u32 pid;
3214 2026
3215 /* 2027 xid = GetXid();
3216 * Give up immediately if rsize is too small to read an entire page. 2028 if (file->private_data == NULL) {
3217 * The VFS will fall back to readpage. We should never reach this 2029 rc = -EBADF;
3218 * point however since we set ra_pages to 0 when the rsize is smaller 2030 FreeXid(xid);
3219 * than a cache page. 2031 return rc;
3220 */ 2032 }
3221 if (unlikely(rsize < PAGE_CACHE_SIZE)) 2033 open_file = file->private_data;
3222 return 0; 2034 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
2035 pTcon = tlink_tcon(open_file->tlink);
3223 2036
3224 /* 2037 /*
3225 * Reads as many pages as possible from fscache. Returns -ENOBUFS 2038 * Reads as many pages as possible from fscache. Returns -ENOBUFS
@@ -3228,124 +2041,125 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
3228 rc = cifs_readpages_from_fscache(mapping->host, mapping, page_list, 2041 rc = cifs_readpages_from_fscache(mapping->host, mapping, page_list,
3229 &num_pages); 2042 &num_pages);
3230 if (rc == 0) 2043 if (rc == 0)
3231 return rc; 2044 goto read_complete;
3232 2045
2046 cFYI(DBG2, "rpages: num pages %d", num_pages);
3233 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD) 2047 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
3234 pid = open_file->pid; 2048 pid = open_file->pid;
3235 else 2049 else
3236 pid = current->tgid; 2050 pid = current->tgid;
3237 2051
3238 rc = 0; 2052 for (i = 0; i < num_pages; ) {
3239 INIT_LIST_HEAD(&tmplist); 2053 unsigned contig_pages;
2054 struct page *tmp_page;
2055 unsigned long expected_index;
3240 2056
3241 cFYI(1, "%s: file=%p mapping=%p num_pages=%u", __func__, file, 2057 if (list_empty(page_list))
3242 mapping, num_pages);
3243
3244 /*
3245 * Start with the page at end of list and move it to private
3246 * list. Do the same with any following pages until we hit
3247 * the rsize limit, hit an index discontinuity, or run out of
3248 * pages. Issue the async read and then start the loop again
3249 * until the list is empty.
3250 *
3251 * Note that list order is important. The page_list is in
3252 * the order of declining indexes. When we put the pages in
3253 * the rdata->pages, then we want them in increasing order.
3254 */
3255 while (!list_empty(page_list)) {
3256 unsigned int i;
3257 unsigned int bytes = PAGE_CACHE_SIZE;
3258 unsigned int expected_index;
3259 unsigned int nr_pages = 1;
3260 loff_t offset;
3261 struct page *page, *tpage;
3262 struct cifs_readdata *rdata;
3263
3264 page = list_entry(page_list->prev, struct page, lru);
3265
3266 /*
3267 * Lock the page and put it in the cache. Since no one else
3268 * should have access to this page, we're safe to simply set
3269 * PG_locked without checking it first.
3270 */
3271 __set_page_locked(page);
3272 rc = add_to_page_cache_locked(page, mapping,
3273 page->index, GFP_KERNEL);
3274
3275 /* give up if we can't stick it in the cache */
3276 if (rc) {
3277 __clear_page_locked(page);
3278 break; 2058 break;
3279 }
3280 2059
3281 /* move first page to the tmplist */ 2060 page = list_entry(page_list->prev, struct page, lru);
3282 offset = (loff_t)page->index << PAGE_CACHE_SHIFT; 2061 offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
3283 list_move_tail(&page->lru, &tmplist);
3284
3285 /* now try and add more pages onto the request */
3286 expected_index = page->index + 1;
3287 list_for_each_entry_safe_reverse(page, tpage, page_list, lru) {
3288 /* discontinuity ? */
3289 if (page->index != expected_index)
3290 break;
3291 2062
3292 /* would this page push the read over the rsize? */ 2063 /* count adjacent pages that we will read into */
3293 if (bytes + PAGE_CACHE_SIZE > rsize) 2064 contig_pages = 0;
3294 break; 2065 expected_index =
3295 2066 list_entry(page_list->prev, struct page, lru)->index;
3296 __set_page_locked(page); 2067 list_for_each_entry_reverse(tmp_page, page_list, lru) {
3297 if (add_to_page_cache_locked(page, mapping, 2068 if (tmp_page->index == expected_index) {
3298 page->index, GFP_KERNEL)) { 2069 contig_pages++;
3299 __clear_page_locked(page); 2070 expected_index++;
2071 } else
3300 break; 2072 break;
3301 }
3302 list_move_tail(&page->lru, &tmplist);
3303 bytes += PAGE_CACHE_SIZE;
3304 expected_index++;
3305 nr_pages++;
3306 } 2073 }
3307 2074 if (contig_pages + i > num_pages)
3308 rdata = cifs_readdata_alloc(nr_pages, cifs_readv_complete); 2075 contig_pages = num_pages - i;
3309 if (!rdata) { 2076
3310 /* best to give up if we're out of mem */ 2077 /* for reads over a certain size could initiate async
3311 list_for_each_entry_safe(page, tpage, &tmplist, lru) { 2078 read ahead */
3312 list_del(&page->lru); 2079
3313 lru_cache_add_file(page); 2080 read_size = contig_pages * PAGE_CACHE_SIZE;
3314 unlock_page(page); 2081 /* Read size needs to be in multiples of one page */
3315 page_cache_release(page); 2082 read_size = min_t(const unsigned int, read_size,
2083 cifs_sb->rsize & PAGE_CACHE_MASK);
2084 cFYI(DBG2, "rpages: read size 0x%x contiguous pages %d",
2085 read_size, contig_pages);
2086 rc = -EAGAIN;
2087 while (rc == -EAGAIN) {
2088 if (open_file->invalidHandle) {
2089 rc = cifs_reopen_file(open_file, true);
2090 if (rc != 0)
2091 break;
2092 }
2093 io_parms.netfid = open_file->netfid;
2094 io_parms.pid = pid;
2095 io_parms.tcon = pTcon;
2096 io_parms.offset = offset;
2097 io_parms.length = read_size;
2098 rc = CIFSSMBRead(xid, &io_parms, &bytes_read,
2099 &smb_read_data, &buf_type);
2100 /* BB more RC checks ? */
2101 if (rc == -EAGAIN) {
2102 if (smb_read_data) {
2103 if (buf_type == CIFS_SMALL_BUFFER)
2104 cifs_small_buf_release(smb_read_data);
2105 else if (buf_type == CIFS_LARGE_BUFFER)
2106 cifs_buf_release(smb_read_data);
2107 smb_read_data = NULL;
2108 }
3316 } 2109 }
3317 rc = -ENOMEM;
3318 break;
3319 }
3320
3321 rdata->cfile = cifsFileInfo_get(open_file);
3322 rdata->mapping = mapping;
3323 rdata->offset = offset;
3324 rdata->bytes = bytes;
3325 rdata->pid = pid;
3326 rdata->pagesz = PAGE_CACHE_SIZE;
3327 rdata->read_into_pages = cifs_readpages_read_into_pages;
3328
3329 list_for_each_entry_safe(page, tpage, &tmplist, lru) {
3330 list_del(&page->lru);
3331 rdata->pages[rdata->nr_pages++] = page;
3332 } 2110 }
3333 2111 if ((rc < 0) || (smb_read_data == NULL)) {
3334 rc = cifs_retry_async_readv(rdata); 2112 cFYI(1, "Read error in readpages: %d", rc);
3335 if (rc != 0) { 2113 break;
3336 for (i = 0; i < rdata->nr_pages; i++) { 2114 } else if (bytes_read > 0) {
3337 page = rdata->pages[i]; 2115 task_io_account_read(bytes_read);
3338 lru_cache_add_file(page); 2116 pSMBr = (struct smb_com_read_rsp *)smb_read_data;
3339 unlock_page(page); 2117 cifs_copy_cache_pages(mapping, page_list, bytes_read,
3340 page_cache_release(page); 2118 smb_read_data + 4 /* RFC1001 hdr */ +
2119 le16_to_cpu(pSMBr->DataOffset));
2120
2121 i += bytes_read >> PAGE_CACHE_SHIFT;
2122 cifs_stats_bytes_read(pTcon, bytes_read);
2123 if ((bytes_read & PAGE_CACHE_MASK) != bytes_read) {
2124 i++; /* account for partial page */
2125
2126 /* server copy of file can have smaller size
2127 than client */
2128 /* BB do we need to verify this common case ?
2129 this case is ok - if we are at server EOF
2130 we will hit it on next read */
2131
2132 /* break; */
3341 } 2133 }
3342 kref_put(&rdata->refcount, cifs_readdata_release); 2134 } else {
2135 cFYI(1, "No bytes read (%d) at offset %lld . "
2136 "Cleaning remaining pages from readahead list",
2137 bytes_read, offset);
2138 /* BB turn off caching and do new lookup on
2139 file size at server? */
3343 break; 2140 break;
3344 } 2141 }
2142 if (smb_read_data) {
2143 if (buf_type == CIFS_SMALL_BUFFER)
2144 cifs_small_buf_release(smb_read_data);
2145 else if (buf_type == CIFS_LARGE_BUFFER)
2146 cifs_buf_release(smb_read_data);
2147 smb_read_data = NULL;
2148 }
2149 bytes_read = 0;
2150 }
3345 2151
3346 kref_put(&rdata->refcount, cifs_readdata_release); 2152/* need to free smb_read_data buf before exit */
2153 if (smb_read_data) {
2154 if (buf_type == CIFS_SMALL_BUFFER)
2155 cifs_small_buf_release(smb_read_data);
2156 else if (buf_type == CIFS_LARGE_BUFFER)
2157 cifs_buf_release(smb_read_data);
2158 smb_read_data = NULL;
3347 } 2159 }
3348 2160
2161read_complete:
2162 FreeXid(xid);
3349 return rc; 2163 return rc;
3350} 2164}
3351 2165
@@ -3397,24 +2211,24 @@ static int cifs_readpage(struct file *file, struct page *page)
3397{ 2211{
3398 loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT; 2212 loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
3399 int rc = -EACCES; 2213 int rc = -EACCES;
3400 unsigned int xid; 2214 int xid;
3401 2215
3402 xid = get_xid(); 2216 xid = GetXid();
3403 2217
3404 if (file->private_data == NULL) { 2218 if (file->private_data == NULL) {
3405 rc = -EBADF; 2219 rc = -EBADF;
3406 free_xid(xid); 2220 FreeXid(xid);
3407 return rc; 2221 return rc;
3408 } 2222 }
3409 2223
3410 cFYI(1, "readpage %p at offset %d 0x%x", 2224 cFYI(1, "readpage %p at offset %d 0x%x\n",
3411 page, (int)offset, (int)offset); 2225 page, (int)offset, (int)offset);
3412 2226
3413 rc = cifs_readpage_worker(file, page, &offset); 2227 rc = cifs_readpage_worker(file, page, &offset);
3414 2228
3415 unlock_page(page); 2229 unlock_page(page);
3416 2230
3417 free_xid(xid); 2231 FreeXid(xid);
3418 return rc; 2232 return rc;
3419} 2233}
3420 2234
@@ -3578,16 +2392,8 @@ void cifs_oplock_break(struct work_struct *work)
3578 oplock_break); 2392 oplock_break);
3579 struct inode *inode = cfile->dentry->d_inode; 2393 struct inode *inode = cfile->dentry->d_inode;
3580 struct cifsInodeInfo *cinode = CIFS_I(inode); 2394 struct cifsInodeInfo *cinode = CIFS_I(inode);
3581 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
3582 int rc = 0; 2395 int rc = 0;
3583 2396
3584 if (!cinode->clientCanCacheAll && cinode->clientCanCacheRead &&
3585 cifs_has_mand_locks(cinode)) {
3586 cFYI(1, "Reset oplock to None for inode=%p due to mand locks",
3587 inode);
3588 cinode->clientCanCacheRead = false;
3589 }
3590
3591 if (inode && S_ISREG(inode->i_mode)) { 2397 if (inode && S_ISREG(inode->i_mode)) {
3592 if (cinode->clientCanCacheRead) 2398 if (cinode->clientCanCacheRead)
3593 break_lease(inode, O_RDONLY); 2399 break_lease(inode, O_RDONLY);
@@ -3597,15 +2403,11 @@ void cifs_oplock_break(struct work_struct *work)
3597 if (cinode->clientCanCacheRead == 0) { 2403 if (cinode->clientCanCacheRead == 0) {
3598 rc = filemap_fdatawait(inode->i_mapping); 2404 rc = filemap_fdatawait(inode->i_mapping);
3599 mapping_set_error(inode->i_mapping, rc); 2405 mapping_set_error(inode->i_mapping, rc);
3600 cifs_invalidate_mapping(inode); 2406 invalidate_remote_inode(inode);
3601 } 2407 }
3602 cFYI(1, "Oplock flush inode %p rc %d", inode, rc); 2408 cFYI(1, "Oplock flush inode %p rc %d", inode, rc);
3603 } 2409 }
3604 2410
3605 rc = cifs_push_locks(cfile);
3606 if (rc)
3607 cERROR(1, "Push locks rc = %d", rc);
3608
3609 /* 2411 /*
3610 * releasing stale oplock after recent reconnect of smb session using 2412 * releasing stale oplock after recent reconnect of smb session using
3611 * a now incorrect file handle is not a data integrity issue but do 2413 * a now incorrect file handle is not a data integrity issue but do
@@ -3613,8 +2415,9 @@ void cifs_oplock_break(struct work_struct *work)
3613 * disconnected since oplock already released by the server 2415 * disconnected since oplock already released by the server
3614 */ 2416 */
3615 if (!cfile->oplock_break_cancelled) { 2417 if (!cfile->oplock_break_cancelled) {
3616 rc = tcon->ses->server->ops->oplock_response(tcon, &cfile->fid, 2418 rc = CIFSSMBLock(0, tlink_tcon(cfile->tlink), cfile->netfid, 0,
3617 cinode); 2419 0, 0, 0, LOCKING_ANDX_OPLOCK_RELEASE, false,
2420 cinode->clientCanCacheRead ? 1 : 0);
3618 cFYI(1, "Oplock release rc = %d", rc); 2421 cFYI(1, "Oplock release rc = %d", rc);
3619 } 2422 }
3620} 2423}
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index ed6208ff85a..745e5cdca8f 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -124,15 +124,15 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
124{ 124{
125 struct cifsInodeInfo *cifs_i = CIFS_I(inode); 125 struct cifsInodeInfo *cifs_i = CIFS_I(inode);
126 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 126 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
127 unsigned long oldtime = cifs_i->time;
127 128
128 cifs_revalidate_cache(inode, fattr); 129 cifs_revalidate_cache(inode, fattr);
129 130
130 spin_lock(&inode->i_lock);
131 inode->i_atime = fattr->cf_atime; 131 inode->i_atime = fattr->cf_atime;
132 inode->i_mtime = fattr->cf_mtime; 132 inode->i_mtime = fattr->cf_mtime;
133 inode->i_ctime = fattr->cf_ctime; 133 inode->i_ctime = fattr->cf_ctime;
134 inode->i_rdev = fattr->cf_rdev; 134 inode->i_rdev = fattr->cf_rdev;
135 set_nlink(inode, fattr->cf_nlink); 135 inode->i_nlink = fattr->cf_nlink;
136 inode->i_uid = fattr->cf_uid; 136 inode->i_uid = fattr->cf_uid;
137 inode->i_gid = fattr->cf_gid; 137 inode->i_gid = fattr->cf_gid;
138 138
@@ -148,6 +148,9 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
148 else 148 else
149 cifs_i->time = jiffies; 149 cifs_i->time = jiffies;
150 150
151 cFYI(1, "inode 0x%p old_time=%ld new_time=%ld", inode,
152 oldtime, cifs_i->time);
153
151 cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING; 154 cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING;
152 155
153 cifs_i->server_eof = fattr->cf_eof; 156 cifs_i->server_eof = fattr->cf_eof;
@@ -155,6 +158,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
155 * Can't safely change the file size here if the client is writing to 158 * Can't safely change the file size here if the client is writing to
156 * it due to potential races. 159 * it due to potential races.
157 */ 160 */
161 spin_lock(&inode->i_lock);
158 if (is_size_safe_to_change(cifs_i, fattr->cf_eof)) { 162 if (is_size_safe_to_change(cifs_i, fattr->cf_eof)) {
159 i_size_write(inode, fattr->cf_eof); 163 i_size_write(inode, fattr->cf_eof);
160 164
@@ -282,11 +286,10 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb)
282 fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL; 286 fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL;
283} 287}
284 288
285static int 289int cifs_get_file_info_unix(struct file *filp)
286cifs_get_file_info_unix(struct file *filp)
287{ 290{
288 int rc; 291 int rc;
289 unsigned int xid; 292 int xid;
290 FILE_UNIX_BASIC_INFO find_data; 293 FILE_UNIX_BASIC_INFO find_data;
291 struct cifs_fattr fattr; 294 struct cifs_fattr fattr;
292 struct inode *inode = filp->f_path.dentry->d_inode; 295 struct inode *inode = filp->f_path.dentry->d_inode;
@@ -294,8 +297,8 @@ cifs_get_file_info_unix(struct file *filp)
294 struct cifsFileInfo *cfile = filp->private_data; 297 struct cifsFileInfo *cfile = filp->private_data;
295 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 298 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
296 299
297 xid = get_xid(); 300 xid = GetXid();
298 rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->fid.netfid, &find_data); 301 rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->netfid, &find_data);
299 if (!rc) { 302 if (!rc) {
300 cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb); 303 cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb);
301 } else if (rc == -EREMOTE) { 304 } else if (rc == -EREMOTE) {
@@ -304,13 +307,13 @@ cifs_get_file_info_unix(struct file *filp)
304 } 307 }
305 308
306 cifs_fattr_to_inode(inode, &fattr); 309 cifs_fattr_to_inode(inode, &fattr);
307 free_xid(xid); 310 FreeXid(xid);
308 return rc; 311 return rc;
309} 312}
310 313
311int cifs_get_inode_info_unix(struct inode **pinode, 314int cifs_get_inode_info_unix(struct inode **pinode,
312 const unsigned char *full_path, 315 const unsigned char *full_path,
313 struct super_block *sb, unsigned int xid) 316 struct super_block *sb, int xid)
314{ 317{
315 int rc; 318 int rc;
316 FILE_UNIX_BASIC_INFO find_data; 319 FILE_UNIX_BASIC_INFO find_data;
@@ -364,7 +367,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
364 367
365static int 368static int
366cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path, 369cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
367 struct cifs_sb_info *cifs_sb, unsigned int xid) 370 struct cifs_sb_info *cifs_sb, int xid)
368{ 371{
369 int rc; 372 int rc;
370 int oplock = 0; 373 int oplock = 0;
@@ -463,7 +466,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
463 * FIXME: Doesn't this clobber the type bit we got from cifs_sfu_type ? 466 * FIXME: Doesn't this clobber the type bit we got from cifs_sfu_type ?
464 */ 467 */
465static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path, 468static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
466 struct cifs_sb_info *cifs_sb, unsigned int xid) 469 struct cifs_sb_info *cifs_sb, int xid)
467{ 470{
468#ifdef CONFIG_CIFS_XATTR 471#ifdef CONFIG_CIFS_XATTR
469 ssize_t rc; 472 ssize_t rc;
@@ -531,11 +534,6 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
531 if (fattr->cf_cifsattrs & ATTR_DIRECTORY) { 534 if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
532 fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode; 535 fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
533 fattr->cf_dtype = DT_DIR; 536 fattr->cf_dtype = DT_DIR;
534 /*
535 * Server can return wrong NumberOfLinks value for directories
536 * when Unix extensions are disabled - fake it.
537 */
538 fattr->cf_nlink = 2;
539 } else { 537 } else {
540 fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode; 538 fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
541 fattr->cf_dtype = DT_REG; 539 fattr->cf_dtype = DT_REG;
@@ -543,32 +541,27 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
543 /* clear write bits if ATTR_READONLY is set */ 541 /* clear write bits if ATTR_READONLY is set */
544 if (fattr->cf_cifsattrs & ATTR_READONLY) 542 if (fattr->cf_cifsattrs & ATTR_READONLY)
545 fattr->cf_mode &= ~(S_IWUGO); 543 fattr->cf_mode &= ~(S_IWUGO);
546
547 fattr->cf_nlink = le32_to_cpu(info->NumberOfLinks);
548 } 544 }
549 545
546 fattr->cf_nlink = le32_to_cpu(info->NumberOfLinks);
547
550 fattr->cf_uid = cifs_sb->mnt_uid; 548 fattr->cf_uid = cifs_sb->mnt_uid;
551 fattr->cf_gid = cifs_sb->mnt_gid; 549 fattr->cf_gid = cifs_sb->mnt_gid;
552} 550}
553 551
554static int 552int cifs_get_file_info(struct file *filp)
555cifs_get_file_info(struct file *filp)
556{ 553{
557 int rc; 554 int rc;
558 unsigned int xid; 555 int xid;
559 FILE_ALL_INFO find_data; 556 FILE_ALL_INFO find_data;
560 struct cifs_fattr fattr; 557 struct cifs_fattr fattr;
561 struct inode *inode = filp->f_path.dentry->d_inode; 558 struct inode *inode = filp->f_path.dentry->d_inode;
562 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 559 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
563 struct cifsFileInfo *cfile = filp->private_data; 560 struct cifsFileInfo *cfile = filp->private_data;
564 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); 561 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
565 struct TCP_Server_Info *server = tcon->ses->server;
566 562
567 if (!server->ops->query_file_info) 563 xid = GetXid();
568 return -ENOSYS; 564 rc = CIFSSMBQFileInfo(xid, tcon, cfile->netfid, &find_data);
569
570 xid = get_xid();
571 rc = server->ops->query_file_info(xid, tcon, &cfile->fid, &find_data);
572 switch (rc) { 565 switch (rc) {
573 case 0: 566 case 0:
574 cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false); 567 cifs_all_info_to_fattr(&fattr, &find_data, cifs_sb, false);
@@ -598,96 +591,71 @@ cifs_get_file_info(struct file *filp)
598 fattr.cf_flags |= CIFS_FATTR_NEED_REVAL; 591 fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
599 cifs_fattr_to_inode(inode, &fattr); 592 cifs_fattr_to_inode(inode, &fattr);
600cgfi_exit: 593cgfi_exit:
601 free_xid(xid); 594 FreeXid(xid);
602 return rc; 595 return rc;
603} 596}
604 597
605int 598int cifs_get_inode_info(struct inode **pinode,
606cifs_get_inode_info(struct inode **inode, const char *full_path, 599 const unsigned char *full_path, FILE_ALL_INFO *pfindData,
607 FILE_ALL_INFO *data, struct super_block *sb, int xid, 600 struct super_block *sb, int xid, const __u16 *pfid)
608 const __u16 *fid)
609{ 601{
610 bool validinum = false; 602 int rc = 0, tmprc;
611 __u16 srchflgs; 603 struct cifs_tcon *pTcon;
612 int rc = 0, tmprc = ENOSYS;
613 struct cifs_tcon *tcon;
614 struct TCP_Server_Info *server;
615 struct tcon_link *tlink; 604 struct tcon_link *tlink;
616 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 605 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
617 char *buf = NULL; 606 char *buf = NULL;
618 bool adjust_tz = false; 607 bool adjustTZ = false;
619 struct cifs_fattr fattr; 608 struct cifs_fattr fattr;
620 struct cifs_search_info *srchinf = NULL;
621 609
622 tlink = cifs_sb_tlink(cifs_sb); 610 tlink = cifs_sb_tlink(cifs_sb);
623 if (IS_ERR(tlink)) 611 if (IS_ERR(tlink))
624 return PTR_ERR(tlink); 612 return PTR_ERR(tlink);
625 tcon = tlink_tcon(tlink); 613 pTcon = tlink_tcon(tlink);
626 server = tcon->ses->server;
627 614
628 cFYI(1, "Getting info on %s", full_path); 615 cFYI(1, "Getting info on %s", full_path);
629 616
630 if ((data == NULL) && (*inode != NULL)) { 617 if ((pfindData == NULL) && (*pinode != NULL)) {
631 if (CIFS_I(*inode)->clientCanCacheRead) { 618 if (CIFS_I(*pinode)->clientCanCacheRead) {
632 cFYI(1, "No need to revalidate cached inode sizes"); 619 cFYI(1, "No need to revalidate cached inode sizes");
633 goto cgii_exit; 620 goto cgii_exit;
634 } 621 }
635 } 622 }
636 623
637 /* if inode info is not passed, get it from server */ 624 /* if file info not passed in then get it from server */
638 if (data == NULL) { 625 if (pfindData == NULL) {
639 if (!server->ops->query_path_info) {
640 rc = -ENOSYS;
641 goto cgii_exit;
642 }
643 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); 626 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
644 if (buf == NULL) { 627 if (buf == NULL) {
645 rc = -ENOMEM; 628 rc = -ENOMEM;
646 goto cgii_exit; 629 goto cgii_exit;
647 } 630 }
648 data = (FILE_ALL_INFO *)buf; 631 pfindData = (FILE_ALL_INFO *)buf;
649 rc = server->ops->query_path_info(xid, tcon, cifs_sb, full_path, 632
650 data, &adjust_tz); 633 /* could do find first instead but this returns more info */
634 rc = CIFSSMBQPathInfo(xid, pTcon, full_path, pfindData,
635 0 /* not legacy */,
636 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
637 CIFS_MOUNT_MAP_SPECIAL_CHR);
638 /* BB optimize code so we do not make the above call
639 when server claims no NT SMB support and the above call
640 failed at least once - set flag in tcon or mount */
641 if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
642 rc = SMBQueryInformation(xid, pTcon, full_path,
643 pfindData, cifs_sb->local_nls,
644 cifs_sb->mnt_cifs_flags &
645 CIFS_MOUNT_MAP_SPECIAL_CHR);
646 adjustTZ = true;
647 }
651 } 648 }
652 649
653 if (!rc) { 650 if (!rc) {
654 cifs_all_info_to_fattr(&fattr, (FILE_ALL_INFO *)data, cifs_sb, 651 cifs_all_info_to_fattr(&fattr, (FILE_ALL_INFO *) pfindData,
655 adjust_tz); 652 cifs_sb, adjustTZ);
656 } else if (rc == -EREMOTE) { 653 } else if (rc == -EREMOTE) {
657 cifs_create_dfs_fattr(&fattr, sb); 654 cifs_create_dfs_fattr(&fattr, sb);
658 rc = 0; 655 rc = 0;
659 } else if (rc == -EACCES && backup_cred(cifs_sb)) { 656 } else {
660 srchinf = kzalloc(sizeof(struct cifs_search_info),
661 GFP_KERNEL);
662 if (srchinf == NULL) {
663 rc = -ENOMEM;
664 goto cgii_exit;
665 }
666
667 srchinf->endOfSearch = false;
668 srchinf->info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
669
670 srchflgs = CIFS_SEARCH_CLOSE_ALWAYS |
671 CIFS_SEARCH_CLOSE_AT_END |
672 CIFS_SEARCH_BACKUP_SEARCH;
673
674 rc = CIFSFindFirst(xid, tcon, full_path,
675 cifs_sb, NULL, srchflgs, srchinf, false);
676 if (!rc) {
677 data =
678 (FILE_ALL_INFO *)srchinf->srch_entries_start;
679
680 cifs_dir_info_to_fattr(&fattr,
681 (FILE_DIRECTORY_INFO *)data, cifs_sb);
682 fattr.cf_uniqueid = le64_to_cpu(
683 ((SEARCH_ID_FULL_DIR_INFO *)data)->UniqueId);
684 validinum = true;
685
686 cifs_buf_release(srchinf->ntwrk_buf_start);
687 }
688 kfree(srchinf);
689 } else
690 goto cgii_exit; 657 goto cgii_exit;
658 }
691 659
692 /* 660 /*
693 * If an inode wasn't passed in, then get the inode number 661 * If an inode wasn't passed in, then get the inode number
@@ -695,24 +663,37 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
695 * Is an i_ino of zero legal? Can we use that to check if the server 663 * Is an i_ino of zero legal? Can we use that to check if the server
696 * supports returning inode numbers? Are there other sanity checks we 664 * supports returning inode numbers? Are there other sanity checks we
697 * can use to ensure that the server is really filling in that field? 665 * can use to ensure that the server is really filling in that field?
666 *
667 * We can not use the IndexNumber field by default from Windows or
668 * Samba (in ALL_INFO buf) but we can request it explicitly. The SNIA
669 * CIFS spec claims that this value is unique within the scope of a
670 * share, and the windows docs hint that it's actually unique
671 * per-machine.
672 *
673 * There may be higher info levels that work but are there Windows
674 * server or network appliances for which IndexNumber field is not
675 * guaranteed unique?
698 */ 676 */
699 if (*inode == NULL) { 677 if (*pinode == NULL) {
700 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { 678 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
701 if (validinum == false) { 679 int rc1 = 0;
702 if (server->ops->get_srv_inum) 680
703 tmprc = server->ops->get_srv_inum(xid, 681 rc1 = CIFSGetSrvInodeNumber(xid, pTcon,
704 tcon, cifs_sb, full_path, 682 full_path, &fattr.cf_uniqueid,
705 &fattr.cf_uniqueid, data); 683 cifs_sb->local_nls,
706 if (tmprc) { 684 cifs_sb->mnt_cifs_flags &
707 cFYI(1, "GetSrvInodeNum rc %d", tmprc); 685 CIFS_MOUNT_MAP_SPECIAL_CHR);
708 fattr.cf_uniqueid = iunique(sb, ROOT_I); 686 if (rc1 || !fattr.cf_uniqueid) {
709 cifs_autodisable_serverino(cifs_sb); 687 cFYI(1, "GetSrvInodeNum rc %d", rc1);
710 } 688 fattr.cf_uniqueid = iunique(sb, ROOT_I);
689 cifs_autodisable_serverino(cifs_sb);
711 } 690 }
712 } else 691 } else {
713 fattr.cf_uniqueid = iunique(sb, ROOT_I); 692 fattr.cf_uniqueid = iunique(sb, ROOT_I);
714 } else 693 }
715 fattr.cf_uniqueid = CIFS_I(*inode)->uniqueid; 694 } else {
695 fattr.cf_uniqueid = CIFS_I(*pinode)->uniqueid;
696 }
716 697
717 /* query for SFU type info if supported and needed */ 698 /* query for SFU type info if supported and needed */
718 if (fattr.cf_cifsattrs & ATTR_SYSTEM && 699 if (fattr.cf_cifsattrs & ATTR_SYSTEM &&
@@ -725,7 +706,8 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
725#ifdef CONFIG_CIFS_ACL 706#ifdef CONFIG_CIFS_ACL
726 /* fill in 0777 bits from ACL */ 707 /* fill in 0777 bits from ACL */
727 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { 708 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
728 rc = cifs_acl_to_fattr(cifs_sb, &fattr, *inode, full_path, fid); 709 rc = cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path,
710 pfid);
729 if (rc) { 711 if (rc) {
730 cFYI(1, "%s: Getting ACL failed with error: %d", 712 cFYI(1, "%s: Getting ACL failed with error: %d",
731 __func__, rc); 713 __func__, rc);
@@ -745,12 +727,12 @@ cifs_get_inode_info(struct inode **inode, const char *full_path,
745 cFYI(1, "CIFSCheckMFSymlink: %d", tmprc); 727 cFYI(1, "CIFSCheckMFSymlink: %d", tmprc);
746 } 728 }
747 729
748 if (!*inode) { 730 if (!*pinode) {
749 *inode = cifs_iget(sb, &fattr); 731 *pinode = cifs_iget(sb, &fattr);
750 if (!*inode) 732 if (!*pinode)
751 rc = -ENOMEM; 733 rc = -ENOMEM;
752 } else { 734 } else {
753 cifs_fattr_to_inode(*inode, &fattr); 735 cifs_fattr_to_inode(*pinode, &fattr);
754 } 736 }
755 737
756cgii_exit: 738cgii_exit:
@@ -763,6 +745,38 @@ static const struct inode_operations cifs_ipc_inode_ops = {
763 .lookup = cifs_lookup, 745 .lookup = cifs_lookup,
764}; 746};
765 747
748char *cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
749 struct cifs_tcon *tcon)
750{
751 int pplen = vol->prepath ? strlen(vol->prepath) : 0;
752 int dfsplen;
753 char *full_path = NULL;
754
755 /* if no prefix path, simply set path to the root of share to "" */
756 if (pplen == 0) {
757 full_path = kmalloc(1, GFP_KERNEL);
758 if (full_path)
759 full_path[0] = 0;
760 return full_path;
761 }
762
763 if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
764 dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
765 else
766 dfsplen = 0;
767
768 full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
769 if (full_path == NULL)
770 return full_path;
771
772 if (dfsplen)
773 strncpy(full_path, tcon->treeName, dfsplen);
774 strncpy(full_path + dfsplen, vol->prepath, pplen);
775 convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
776 full_path[dfsplen + pplen] = 0; /* add trailing null */
777 return full_path;
778}
779
766static int 780static int
767cifs_find_inode(struct inode *inode, void *opaque) 781cifs_find_inode(struct inode *inode, void *opaque)
768{ 782{
@@ -781,7 +795,7 @@ cifs_find_inode(struct inode *inode, void *opaque)
781 return 0; 795 return 0;
782 796
783 /* if it's not a directory or has no dentries, then flag it */ 797 /* if it's not a directory or has no dentries, then flag it */
784 if (S_ISDIR(inode->i_mode) && !hlist_empty(&inode->i_dentry)) 798 if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry))
785 fattr->cf_flags |= CIFS_FATTR_INO_COLLISION; 799 fattr->cf_flags |= CIFS_FATTR_INO_COLLISION;
786 800
787 return 1; 801 return 1;
@@ -806,10 +820,9 @@ static bool
806inode_has_hashed_dentries(struct inode *inode) 820inode_has_hashed_dentries(struct inode *inode)
807{ 821{
808 struct dentry *dentry; 822 struct dentry *dentry;
809 struct hlist_node *p;
810 823
811 spin_lock(&inode->i_lock); 824 spin_lock(&inode->i_lock);
812 hlist_for_each_entry(dentry, p, &inode->i_dentry, d_alias) { 825 list_for_each_entry(dentry, &inode->i_dentry, d_alias) {
813 if (!d_unhashed(dentry) || IS_ROOT(dentry)) { 826 if (!d_unhashed(dentry) || IS_ROOT(dentry)) {
814 spin_unlock(&inode->i_lock); 827 spin_unlock(&inode->i_lock);
815 return true; 828 return true;
@@ -867,13 +880,13 @@ retry_iget5_locked:
867/* gets root inode */ 880/* gets root inode */
868struct inode *cifs_root_iget(struct super_block *sb) 881struct inode *cifs_root_iget(struct super_block *sb)
869{ 882{
870 unsigned int xid; 883 int xid;
871 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 884 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
872 struct inode *inode = NULL; 885 struct inode *inode = NULL;
873 long rc; 886 long rc;
874 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); 887 struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
875 888
876 xid = get_xid(); 889 xid = GetXid();
877 if (tcon->unix_ext) 890 if (tcon->unix_ext)
878 rc = cifs_get_inode_info_unix(&inode, "", sb, xid); 891 rc = cifs_get_inode_info_unix(&inode, "", sb, xid);
879 else 892 else
@@ -891,43 +904,44 @@ struct inode *cifs_root_iget(struct super_block *sb)
891 904
892 if (rc && tcon->ipc) { 905 if (rc && tcon->ipc) {
893 cFYI(1, "ipc connection - fake read inode"); 906 cFYI(1, "ipc connection - fake read inode");
894 spin_lock(&inode->i_lock);
895 inode->i_mode |= S_IFDIR; 907 inode->i_mode |= S_IFDIR;
896 set_nlink(inode, 2); 908 inode->i_nlink = 2;
897 inode->i_op = &cifs_ipc_inode_ops; 909 inode->i_op = &cifs_ipc_inode_ops;
898 inode->i_fop = &simple_dir_operations; 910 inode->i_fop = &simple_dir_operations;
899 inode->i_uid = cifs_sb->mnt_uid; 911 inode->i_uid = cifs_sb->mnt_uid;
900 inode->i_gid = cifs_sb->mnt_gid; 912 inode->i_gid = cifs_sb->mnt_gid;
901 spin_unlock(&inode->i_lock);
902 } else if (rc) { 913 } else if (rc) {
903 iget_failed(inode); 914 iget_failed(inode);
904 inode = ERR_PTR(rc); 915 inode = ERR_PTR(rc);
905 } 916 }
906 917
907out: 918out:
908 /* can not call macro free_xid here since in a void func 919 /* can not call macro FreeXid here since in a void func
909 * TODO: This is no longer true 920 * TODO: This is no longer true
910 */ 921 */
911 _free_xid(xid); 922 _FreeXid(xid);
912 return inode; 923 return inode;
913} 924}
914 925
915int 926static int
916cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid, 927cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid,
917 char *full_path, __u32 dosattr) 928 char *full_path, __u32 dosattr)
918{ 929{
930 int rc;
931 int oplock = 0;
932 __u16 netfid;
933 __u32 netpid;
919 bool set_time = false; 934 bool set_time = false;
935 struct cifsFileInfo *open_file;
936 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
920 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 937 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
921 struct TCP_Server_Info *server; 938 struct tcon_link *tlink = NULL;
939 struct cifs_tcon *pTcon;
922 FILE_BASIC_INFO info_buf; 940 FILE_BASIC_INFO info_buf;
923 941
924 if (attrs == NULL) 942 if (attrs == NULL)
925 return -EINVAL; 943 return -EINVAL;
926 944
927 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
928 if (!server->ops->set_file_info)
929 return -ENOSYS;
930
931 if (attrs->ia_valid & ATTR_ATIME) { 945 if (attrs->ia_valid & ATTR_ATIME) {
932 set_time = true; 946 set_time = true;
933 info_buf.LastAccessTime = 947 info_buf.LastAccessTime =
@@ -958,17 +972,80 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid,
958 info_buf.CreationTime = 0; /* don't change */ 972 info_buf.CreationTime = 0; /* don't change */
959 info_buf.Attributes = cpu_to_le32(dosattr); 973 info_buf.Attributes = cpu_to_le32(dosattr);
960 974
961 return server->ops->set_file_info(inode, full_path, &info_buf, xid); 975 /*
976 * If the file is already open for write, just use that fileid
977 */
978 open_file = find_writable_file(cifsInode, true);
979 if (open_file) {
980 netfid = open_file->netfid;
981 netpid = open_file->pid;
982 pTcon = tlink_tcon(open_file->tlink);
983 goto set_via_filehandle;
984 }
985
986 tlink = cifs_sb_tlink(cifs_sb);
987 if (IS_ERR(tlink)) {
988 rc = PTR_ERR(tlink);
989 tlink = NULL;
990 goto out;
991 }
992 pTcon = tlink_tcon(tlink);
993
994 /*
995 * NT4 apparently returns success on this call, but it doesn't
996 * really work.
997 */
998 if (!(pTcon->ses->flags & CIFS_SES_NT4)) {
999 rc = CIFSSMBSetPathInfo(xid, pTcon, full_path,
1000 &info_buf, cifs_sb->local_nls,
1001 cifs_sb->mnt_cifs_flags &
1002 CIFS_MOUNT_MAP_SPECIAL_CHR);
1003 if (rc == 0) {
1004 cifsInode->cifsAttrs = dosattr;
1005 goto out;
1006 } else if (rc != -EOPNOTSUPP && rc != -EINVAL)
1007 goto out;
1008 }
1009
1010 cFYI(1, "calling SetFileInfo since SetPathInfo for "
1011 "times not supported by this server");
1012 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
1013 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
1014 CREATE_NOT_DIR, &netfid, &oplock,
1015 NULL, cifs_sb->local_nls,
1016 cifs_sb->mnt_cifs_flags &
1017 CIFS_MOUNT_MAP_SPECIAL_CHR);
1018
1019 if (rc != 0) {
1020 if (rc == -EIO)
1021 rc = -EINVAL;
1022 goto out;
1023 }
1024
1025 netpid = current->tgid;
1026
1027set_via_filehandle:
1028 rc = CIFSSMBSetFileInfo(xid, pTcon, &info_buf, netfid, netpid);
1029 if (!rc)
1030 cifsInode->cifsAttrs = dosattr;
1031
1032 if (open_file == NULL)
1033 CIFSSMBClose(xid, pTcon, netfid);
1034 else
1035 cifsFileInfo_put(open_file);
1036out:
1037 if (tlink != NULL)
1038 cifs_put_tlink(tlink);
1039 return rc;
962} 1040}
963 1041
964/* 1042/*
965 * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit 1043 * open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
966 * and rename it to a random name that hopefully won't conflict with 1044 * and rename it to a random name that hopefully won't conflict with
967 * anything else. 1045 * anything else.
968 */ 1046 */
969int 1047static int
970cifs_rename_pending_delete(const char *full_path, struct dentry *dentry, 1048cifs_rename_pending_delete(char *full_path, struct dentry *dentry, int xid)
971 const unsigned int xid)
972{ 1049{
973 int oplock = 0; 1050 int oplock = 0;
974 int rc; 1051 int rc;
@@ -1077,15 +1154,6 @@ undo_setattr:
1077 goto out_close; 1154 goto out_close;
1078} 1155}
1079 1156
1080/* copied from fs/nfs/dir.c with small changes */
1081static void
1082cifs_drop_nlink(struct inode *inode)
1083{
1084 spin_lock(&inode->i_lock);
1085 if (inode->i_nlink > 0)
1086 drop_nlink(inode);
1087 spin_unlock(&inode->i_lock);
1088}
1089 1157
1090/* 1158/*
1091 * If dentry->d_inode is null (usually meaning the cached dentry 1159 * If dentry->d_inode is null (usually meaning the cached dentry
@@ -1097,7 +1165,7 @@ cifs_drop_nlink(struct inode *inode)
1097int cifs_unlink(struct inode *dir, struct dentry *dentry) 1165int cifs_unlink(struct inode *dir, struct dentry *dentry)
1098{ 1166{
1099 int rc = 0; 1167 int rc = 0;
1100 unsigned int xid; 1168 int xid;
1101 char *full_path = NULL; 1169 char *full_path = NULL;
1102 struct inode *inode = dentry->d_inode; 1170 struct inode *inode = dentry->d_inode;
1103 struct cifsInodeInfo *cifs_inode; 1171 struct cifsInodeInfo *cifs_inode;
@@ -1105,7 +1173,6 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
1105 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 1173 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
1106 struct tcon_link *tlink; 1174 struct tcon_link *tlink;
1107 struct cifs_tcon *tcon; 1175 struct cifs_tcon *tcon;
1108 struct TCP_Server_Info *server;
1109 struct iattr *attrs = NULL; 1176 struct iattr *attrs = NULL;
1110 __u32 dosattr = 0, origattr = 0; 1177 __u32 dosattr = 0, origattr = 0;
1111 1178
@@ -1115,9 +1182,8 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
1115 if (IS_ERR(tlink)) 1182 if (IS_ERR(tlink))
1116 return PTR_ERR(tlink); 1183 return PTR_ERR(tlink);
1117 tcon = tlink_tcon(tlink); 1184 tcon = tlink_tcon(tlink);
1118 server = tcon->ses->server;
1119 1185
1120 xid = get_xid(); 1186 xid = GetXid();
1121 1187
1122 /* Unlink can be called from rename so we can not take the 1188 /* Unlink can be called from rename so we can not take the
1123 * sb->s_vfs_rename_mutex here */ 1189 * sb->s_vfs_rename_mutex here */
@@ -1127,8 +1193,9 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
1127 goto unlink_out; 1193 goto unlink_out;
1128 } 1194 }
1129 1195
1130 if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & 1196 if ((tcon->ses->capabilities & CAP_UNIX) &&
1131 le64_to_cpu(tcon->fsUnixInfo.Capability))) { 1197 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
1198 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
1132 rc = CIFSPOSIXDelFile(xid, tcon, full_path, 1199 rc = CIFSPOSIXDelFile(xid, tcon, full_path,
1133 SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls, 1200 SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls,
1134 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 1201 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -1138,28 +1205,19 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
1138 } 1205 }
1139 1206
1140retry_std_delete: 1207retry_std_delete:
1141 if (!server->ops->unlink) { 1208 rc = CIFSSMBDelFile(xid, tcon, full_path, cifs_sb->local_nls,
1142 rc = -ENOSYS; 1209 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
1143 goto psx_del_no_retry;
1144 }
1145
1146 rc = server->ops->unlink(xid, tcon, full_path, cifs_sb);
1147 1210
1148psx_del_no_retry: 1211psx_del_no_retry:
1149 if (!rc) { 1212 if (!rc) {
1150 if (inode) 1213 if (inode)
1151 cifs_drop_nlink(inode); 1214 drop_nlink(inode);
1152 } else if (rc == -ENOENT) { 1215 } else if (rc == -ENOENT) {
1153 d_drop(dentry); 1216 d_drop(dentry);
1154 } else if (rc == -ETXTBSY) { 1217 } else if (rc == -ETXTBSY) {
1155 if (server->ops->rename_pending_delete) { 1218 rc = cifs_rename_pending_delete(full_path, dentry, xid);
1156 rc = server->ops->rename_pending_delete(full_path, 1219 if (rc == 0)
1157 dentry, xid); 1220 drop_nlink(inode);
1158 if (rc == 0)
1159 cifs_drop_nlink(inode);
1160 }
1161 if (rc == -ETXTBSY)
1162 rc = -EBUSY;
1163 } else if ((rc == -EACCES) && (dosattr == 0) && inode) { 1221 } else if ((rc == -EACCES) && (dosattr == 0) && inode) {
1164 attrs = kzalloc(sizeof(*attrs), GFP_KERNEL); 1222 attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
1165 if (attrs == NULL) { 1223 if (attrs == NULL) {
@@ -1201,166 +1259,31 @@ out_reval:
1201unlink_out: 1259unlink_out:
1202 kfree(full_path); 1260 kfree(full_path);
1203 kfree(attrs); 1261 kfree(attrs);
1204 free_xid(xid); 1262 FreeXid(xid);
1205 cifs_put_tlink(tlink); 1263 cifs_put_tlink(tlink);
1206 return rc; 1264 return rc;
1207} 1265}
1208 1266
1209static int 1267int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
1210cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
1211 const char *full_path, struct cifs_sb_info *cifs_sb,
1212 struct cifs_tcon *tcon, const unsigned int xid)
1213{ 1268{
1214 int rc = 0; 1269 int rc = 0, tmprc;
1215 struct inode *inode = NULL; 1270 int xid;
1216
1217 if (tcon->unix_ext)
1218 rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb,
1219 xid);
1220 else
1221 rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb,
1222 xid, NULL);
1223
1224 if (rc)
1225 return rc;
1226
1227 /*
1228 * setting nlink not necessary except in cases where we failed to get it
1229 * from the server or was set bogus. Also, since this is a brand new
1230 * inode, no need to grab the i_lock before setting the i_nlink.
1231 */
1232 if (inode->i_nlink < 2)
1233 set_nlink(inode, 2);
1234 mode &= ~current_umask();
1235 /* must turn on setgid bit if parent dir has it */
1236 if (parent->i_mode & S_ISGID)
1237 mode |= S_ISGID;
1238
1239 if (tcon->unix_ext) {
1240 struct cifs_unix_set_info_args args = {
1241 .mode = mode,
1242 .ctime = NO_CHANGE_64,
1243 .atime = NO_CHANGE_64,
1244 .mtime = NO_CHANGE_64,
1245 .device = 0,
1246 };
1247 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
1248 args.uid = (__u64)current_fsuid();
1249 if (parent->i_mode & S_ISGID)
1250 args.gid = (__u64)parent->i_gid;
1251 else
1252 args.gid = (__u64)current_fsgid();
1253 } else {
1254 args.uid = NO_CHANGE_64;
1255 args.gid = NO_CHANGE_64;
1256 }
1257 CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
1258 cifs_sb->local_nls,
1259 cifs_sb->mnt_cifs_flags &
1260 CIFS_MOUNT_MAP_SPECIAL_CHR);
1261 } else {
1262 struct TCP_Server_Info *server = tcon->ses->server;
1263 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
1264 (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo)
1265 server->ops->mkdir_setinfo(inode, full_path, cifs_sb,
1266 tcon, xid);
1267 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
1268 inode->i_mode = (mode | S_IFDIR);
1269
1270 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
1271 inode->i_uid = current_fsuid();
1272 if (inode->i_mode & S_ISGID)
1273 inode->i_gid = parent->i_gid;
1274 else
1275 inode->i_gid = current_fsgid();
1276 }
1277 }
1278 d_instantiate(dentry, inode);
1279 return rc;
1280}
1281
1282static int
1283cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode,
1284 const char *full_path, struct cifs_sb_info *cifs_sb,
1285 struct cifs_tcon *tcon, const unsigned int xid)
1286{
1287 int rc = 0;
1288 u32 oplock = 0;
1289 FILE_UNIX_BASIC_INFO *info = NULL;
1290 struct inode *newinode = NULL;
1291 struct cifs_fattr fattr;
1292
1293 info = kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
1294 if (info == NULL) {
1295 rc = -ENOMEM;
1296 goto posix_mkdir_out;
1297 }
1298
1299 mode &= ~current_umask();
1300 rc = CIFSPOSIXCreate(xid, tcon, SMB_O_DIRECTORY | SMB_O_CREAT, mode,
1301 NULL /* netfid */, info, &oplock, full_path,
1302 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
1303 CIFS_MOUNT_MAP_SPECIAL_CHR);
1304 if (rc == -EOPNOTSUPP)
1305 goto posix_mkdir_out;
1306 else if (rc) {
1307 cFYI(1, "posix mkdir returned 0x%x", rc);
1308 d_drop(dentry);
1309 goto posix_mkdir_out;
1310 }
1311
1312 if (info->Type == cpu_to_le32(-1))
1313 /* no return info, go query for it */
1314 goto posix_mkdir_get_info;
1315 /*
1316 * BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if
1317 * need to set uid/gid.
1318 */
1319
1320 cifs_unix_basic_to_fattr(&fattr, info, cifs_sb);
1321 cifs_fill_uniqueid(inode->i_sb, &fattr);
1322 newinode = cifs_iget(inode->i_sb, &fattr);
1323 if (!newinode)
1324 goto posix_mkdir_get_info;
1325
1326 d_instantiate(dentry, newinode);
1327
1328#ifdef CONFIG_CIFS_DEBUG2
1329 cFYI(1, "instantiated dentry %p %s to inode %p", dentry,
1330 dentry->d_name.name, newinode);
1331
1332 if (newinode->i_nlink != 2)
1333 cFYI(1, "unexpected number of links %d", newinode->i_nlink);
1334#endif
1335
1336posix_mkdir_out:
1337 kfree(info);
1338 return rc;
1339posix_mkdir_get_info:
1340 rc = cifs_mkdir_qinfo(inode, dentry, mode, full_path, cifs_sb, tcon,
1341 xid);
1342 goto posix_mkdir_out;
1343}
1344
1345int cifs_mkdir(struct inode *inode, struct dentry *direntry, umode_t mode)
1346{
1347 int rc = 0;
1348 unsigned int xid;
1349 struct cifs_sb_info *cifs_sb; 1271 struct cifs_sb_info *cifs_sb;
1350 struct tcon_link *tlink; 1272 struct tcon_link *tlink;
1351 struct cifs_tcon *tcon; 1273 struct cifs_tcon *pTcon;
1352 struct TCP_Server_Info *server; 1274 char *full_path = NULL;
1353 char *full_path; 1275 struct inode *newinode = NULL;
1276 struct cifs_fattr fattr;
1354 1277
1355 cFYI(1, "In cifs_mkdir, mode = 0x%hx inode = 0x%p", mode, inode); 1278 cFYI(1, "In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode);
1356 1279
1357 cifs_sb = CIFS_SB(inode->i_sb); 1280 cifs_sb = CIFS_SB(inode->i_sb);
1358 tlink = cifs_sb_tlink(cifs_sb); 1281 tlink = cifs_sb_tlink(cifs_sb);
1359 if (IS_ERR(tlink)) 1282 if (IS_ERR(tlink))
1360 return PTR_ERR(tlink); 1283 return PTR_ERR(tlink);
1361 tcon = tlink_tcon(tlink); 1284 pTcon = tlink_tcon(tlink);
1362 1285
1363 xid = get_xid(); 1286 xid = GetXid();
1364 1287
1365 full_path = build_path_from_dentry(direntry); 1288 full_path = build_path_from_dentry(direntry);
1366 if (full_path == NULL) { 1289 if (full_path == NULL) {
@@ -1368,39 +1291,153 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, umode_t mode)
1368 goto mkdir_out; 1291 goto mkdir_out;
1369 } 1292 }
1370 1293
1371 if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP & 1294 if ((pTcon->ses->capabilities & CAP_UNIX) &&
1372 le64_to_cpu(tcon->fsUnixInfo.Capability))) { 1295 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
1373 rc = cifs_posix_mkdir(inode, direntry, mode, full_path, cifs_sb, 1296 le64_to_cpu(pTcon->fsUnixInfo.Capability))) {
1374 tcon, xid); 1297 u32 oplock = 0;
1375 if (rc != -EOPNOTSUPP) 1298 FILE_UNIX_BASIC_INFO *pInfo =
1299 kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
1300 if (pInfo == NULL) {
1301 rc = -ENOMEM;
1376 goto mkdir_out; 1302 goto mkdir_out;
1377 } 1303 }
1304
1305 mode &= ~current_umask();
1306 rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT,
1307 mode, NULL /* netfid */, pInfo, &oplock,
1308 full_path, cifs_sb->local_nls,
1309 cifs_sb->mnt_cifs_flags &
1310 CIFS_MOUNT_MAP_SPECIAL_CHR);
1311 if (rc == -EOPNOTSUPP) {
1312 kfree(pInfo);
1313 goto mkdir_retry_old;
1314 } else if (rc) {
1315 cFYI(1, "posix mkdir returned 0x%x", rc);
1316 d_drop(direntry);
1317 } else {
1318 if (pInfo->Type == cpu_to_le32(-1)) {
1319 /* no return info, go query for it */
1320 kfree(pInfo);
1321 goto mkdir_get_info;
1322 }
1323/*BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if need
1324 to set uid/gid */
1325 inc_nlink(inode);
1326
1327 cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb);
1328 cifs_fill_uniqueid(inode->i_sb, &fattr);
1329 newinode = cifs_iget(inode->i_sb, &fattr);
1330 if (!newinode) {
1331 kfree(pInfo);
1332 goto mkdir_get_info;
1333 }
1334
1335 d_instantiate(direntry, newinode);
1378 1336
1379 server = tcon->ses->server; 1337#ifdef CONFIG_CIFS_DEBUG2
1338 cFYI(1, "instantiated dentry %p %s to inode %p",
1339 direntry, direntry->d_name.name, newinode);
1380 1340
1381 if (!server->ops->mkdir) { 1341 if (newinode->i_nlink != 2)
1382 rc = -ENOSYS; 1342 cFYI(1, "unexpected number of links %d",
1343 newinode->i_nlink);
1344#endif
1345 }
1346 kfree(pInfo);
1383 goto mkdir_out; 1347 goto mkdir_out;
1384 } 1348 }
1385 1349mkdir_retry_old:
1386 /* BB add setting the equivalent of mode via CreateX w/ACLs */ 1350 /* BB add setting the equivalent of mode via CreateX w/ACLs */
1387 rc = server->ops->mkdir(xid, tcon, full_path, cifs_sb); 1351 rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
1352 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
1388 if (rc) { 1353 if (rc) {
1389 cFYI(1, "cifs_mkdir returned 0x%x", rc); 1354 cFYI(1, "cifs_mkdir returned 0x%x", rc);
1390 d_drop(direntry); 1355 d_drop(direntry);
1391 goto mkdir_out; 1356 } else {
1357mkdir_get_info:
1358 inc_nlink(inode);
1359 if (pTcon->unix_ext)
1360 rc = cifs_get_inode_info_unix(&newinode, full_path,
1361 inode->i_sb, xid);
1362 else
1363 rc = cifs_get_inode_info(&newinode, full_path, NULL,
1364 inode->i_sb, xid, NULL);
1365
1366 d_instantiate(direntry, newinode);
1367 /* setting nlink not necessary except in cases where we
1368 * failed to get it from the server or was set bogus */
1369 if ((direntry->d_inode) && (direntry->d_inode->i_nlink < 2))
1370 direntry->d_inode->i_nlink = 2;
1371
1372 mode &= ~current_umask();
1373 /* must turn on setgid bit if parent dir has it */
1374 if (inode->i_mode & S_ISGID)
1375 mode |= S_ISGID;
1376
1377 if (pTcon->unix_ext) {
1378 struct cifs_unix_set_info_args args = {
1379 .mode = mode,
1380 .ctime = NO_CHANGE_64,
1381 .atime = NO_CHANGE_64,
1382 .mtime = NO_CHANGE_64,
1383 .device = 0,
1384 };
1385 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
1386 args.uid = (__u64)current_fsuid();
1387 if (inode->i_mode & S_ISGID)
1388 args.gid = (__u64)inode->i_gid;
1389 else
1390 args.gid = (__u64)current_fsgid();
1391 } else {
1392 args.uid = NO_CHANGE_64;
1393 args.gid = NO_CHANGE_64;
1394 }
1395 CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, &args,
1396 cifs_sb->local_nls,
1397 cifs_sb->mnt_cifs_flags &
1398 CIFS_MOUNT_MAP_SPECIAL_CHR);
1399 } else {
1400 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
1401 (mode & S_IWUGO) == 0) {
1402 FILE_BASIC_INFO pInfo;
1403 struct cifsInodeInfo *cifsInode;
1404 u32 dosattrs;
1405
1406 memset(&pInfo, 0, sizeof(pInfo));
1407 cifsInode = CIFS_I(newinode);
1408 dosattrs = cifsInode->cifsAttrs|ATTR_READONLY;
1409 pInfo.Attributes = cpu_to_le32(dosattrs);
1410 tmprc = CIFSSMBSetPathInfo(xid, pTcon,
1411 full_path, &pInfo,
1412 cifs_sb->local_nls,
1413 cifs_sb->mnt_cifs_flags &
1414 CIFS_MOUNT_MAP_SPECIAL_CHR);
1415 if (tmprc == 0)
1416 cifsInode->cifsAttrs = dosattrs;
1417 }
1418 if (direntry->d_inode) {
1419 if (cifs_sb->mnt_cifs_flags &
1420 CIFS_MOUNT_DYNPERM)
1421 direntry->d_inode->i_mode =
1422 (mode | S_IFDIR);
1423
1424 if (cifs_sb->mnt_cifs_flags &
1425 CIFS_MOUNT_SET_UID) {
1426 direntry->d_inode->i_uid =
1427 current_fsuid();
1428 if (inode->i_mode & S_ISGID)
1429 direntry->d_inode->i_gid =
1430 inode->i_gid;
1431 else
1432 direntry->d_inode->i_gid =
1433 current_fsgid();
1434 }
1435 }
1436 }
1392 } 1437 }
1393
1394 rc = cifs_mkdir_qinfo(inode, direntry, mode, full_path, cifs_sb, tcon,
1395 xid);
1396mkdir_out: 1438mkdir_out:
1397 /*
1398 * Force revalidate to get parent dir info when needed since cached
1399 * attributes are invalid now.
1400 */
1401 CIFS_I(inode)->time = 0;
1402 kfree(full_path); 1439 kfree(full_path);
1403 free_xid(xid); 1440 FreeXid(xid);
1404 cifs_put_tlink(tlink); 1441 cifs_put_tlink(tlink);
1405 return rc; 1442 return rc;
1406} 1443}
@@ -1408,17 +1445,16 @@ mkdir_out:
1408int cifs_rmdir(struct inode *inode, struct dentry *direntry) 1445int cifs_rmdir(struct inode *inode, struct dentry *direntry)
1409{ 1446{
1410 int rc = 0; 1447 int rc = 0;
1411 unsigned int xid; 1448 int xid;
1412 struct cifs_sb_info *cifs_sb; 1449 struct cifs_sb_info *cifs_sb;
1413 struct tcon_link *tlink; 1450 struct tcon_link *tlink;
1414 struct cifs_tcon *tcon; 1451 struct cifs_tcon *pTcon;
1415 struct TCP_Server_Info *server;
1416 char *full_path = NULL; 1452 char *full_path = NULL;
1417 struct cifsInodeInfo *cifsInode; 1453 struct cifsInodeInfo *cifsInode;
1418 1454
1419 cFYI(1, "cifs_rmdir, inode = 0x%p", inode); 1455 cFYI(1, "cifs_rmdir, inode = 0x%p", inode);
1420 1456
1421 xid = get_xid(); 1457 xid = GetXid();
1422 1458
1423 full_path = build_path_from_dentry(direntry); 1459 full_path = build_path_from_dentry(direntry);
1424 if (full_path == NULL) { 1460 if (full_path == NULL) {
@@ -1432,19 +1468,14 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry)
1432 rc = PTR_ERR(tlink); 1468 rc = PTR_ERR(tlink);
1433 goto rmdir_exit; 1469 goto rmdir_exit;
1434 } 1470 }
1435 tcon = tlink_tcon(tlink); 1471 pTcon = tlink_tcon(tlink);
1436 server = tcon->ses->server;
1437
1438 if (!server->ops->rmdir) {
1439 rc = -ENOSYS;
1440 cifs_put_tlink(tlink);
1441 goto rmdir_exit;
1442 }
1443 1472
1444 rc = server->ops->rmdir(xid, tcon, full_path, cifs_sb); 1473 rc = CIFSSMBRmDir(xid, pTcon, full_path, cifs_sb->local_nls,
1474 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
1445 cifs_put_tlink(tlink); 1475 cifs_put_tlink(tlink);
1446 1476
1447 if (!rc) { 1477 if (!rc) {
1478 drop_nlink(inode);
1448 spin_lock(&direntry->d_inode->i_lock); 1479 spin_lock(&direntry->d_inode->i_lock);
1449 i_size_write(direntry->d_inode, 0); 1480 i_size_write(direntry->d_inode, 0);
1450 clear_nlink(direntry->d_inode); 1481 clear_nlink(direntry->d_inode);
@@ -1452,52 +1483,45 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry)
1452 } 1483 }
1453 1484
1454 cifsInode = CIFS_I(direntry->d_inode); 1485 cifsInode = CIFS_I(direntry->d_inode);
1455 /* force revalidate to go get info when needed */ 1486 cifsInode->time = 0; /* force revalidate to go get info when
1456 cifsInode->time = 0; 1487 needed */
1457 1488
1458 cifsInode = CIFS_I(inode); 1489 cifsInode = CIFS_I(inode);
1459 /* 1490 cifsInode->time = 0; /* force revalidate to get parent dir info
1460 * Force revalidate to get parent dir info when needed since cached 1491 since cached search results now invalid */
1461 * attributes are invalid now.
1462 */
1463 cifsInode->time = 0;
1464 1492
1465 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = 1493 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime =
1466 current_fs_time(inode->i_sb); 1494 current_fs_time(inode->i_sb);
1467 1495
1468rmdir_exit: 1496rmdir_exit:
1469 kfree(full_path); 1497 kfree(full_path);
1470 free_xid(xid); 1498 FreeXid(xid);
1471 return rc; 1499 return rc;
1472} 1500}
1473 1501
1474static int 1502static int
1475cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, 1503cifs_do_rename(int xid, struct dentry *from_dentry, const char *fromPath,
1476 const char *from_path, struct dentry *to_dentry, 1504 struct dentry *to_dentry, const char *toPath)
1477 const char *to_path)
1478{ 1505{
1479 struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb); 1506 struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb);
1480 struct tcon_link *tlink; 1507 struct tcon_link *tlink;
1481 struct cifs_tcon *tcon; 1508 struct cifs_tcon *pTcon;
1482 struct TCP_Server_Info *server;
1483 __u16 srcfid; 1509 __u16 srcfid;
1484 int oplock, rc; 1510 int oplock, rc;
1485 1511
1486 tlink = cifs_sb_tlink(cifs_sb); 1512 tlink = cifs_sb_tlink(cifs_sb);
1487 if (IS_ERR(tlink)) 1513 if (IS_ERR(tlink))
1488 return PTR_ERR(tlink); 1514 return PTR_ERR(tlink);
1489 tcon = tlink_tcon(tlink); 1515 pTcon = tlink_tcon(tlink);
1490 server = tcon->ses->server;
1491
1492 if (!server->ops->rename)
1493 return -ENOSYS;
1494 1516
1495 /* try path-based rename first */ 1517 /* try path-based rename first */
1496 rc = server->ops->rename(xid, tcon, from_path, to_path, cifs_sb); 1518 rc = CIFSSMBRename(xid, pTcon, fromPath, toPath, cifs_sb->local_nls,
1519 cifs_sb->mnt_cifs_flags &
1520 CIFS_MOUNT_MAP_SPECIAL_CHR);
1497 1521
1498 /* 1522 /*
1499 * Don't bother with rename by filehandle unless file is busy and 1523 * don't bother with rename by filehandle unless file is busy and
1500 * source. Note that cross directory moves do not work with 1524 * source Note that cross directory moves do not work with
1501 * rename by filehandle to various Windows servers. 1525 * rename by filehandle to various Windows servers.
1502 */ 1526 */
1503 if (rc == 0 || rc != -ETXTBSY) 1527 if (rc == 0 || rc != -ETXTBSY)
@@ -1508,35 +1532,35 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
1508 goto do_rename_exit; 1532 goto do_rename_exit;
1509 1533
1510 /* open the file to be renamed -- we need DELETE perms */ 1534 /* open the file to be renamed -- we need DELETE perms */
1511 rc = CIFSSMBOpen(xid, tcon, from_path, FILE_OPEN, DELETE, 1535 rc = CIFSSMBOpen(xid, pTcon, fromPath, FILE_OPEN, DELETE,
1512 CREATE_NOT_DIR, &srcfid, &oplock, NULL, 1536 CREATE_NOT_DIR, &srcfid, &oplock, NULL,
1513 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 1537 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
1514 CIFS_MOUNT_MAP_SPECIAL_CHR); 1538 CIFS_MOUNT_MAP_SPECIAL_CHR);
1539
1515 if (rc == 0) { 1540 if (rc == 0) {
1516 rc = CIFSSMBRenameOpenFile(xid, tcon, srcfid, 1541 rc = CIFSSMBRenameOpenFile(xid, pTcon, srcfid,
1517 (const char *) to_dentry->d_name.name, 1542 (const char *) to_dentry->d_name.name,
1518 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 1543 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
1519 CIFS_MOUNT_MAP_SPECIAL_CHR); 1544 CIFS_MOUNT_MAP_SPECIAL_CHR);
1520 CIFSSMBClose(xid, tcon, srcfid); 1545
1546 CIFSSMBClose(xid, pTcon, srcfid);
1521 } 1547 }
1522do_rename_exit: 1548do_rename_exit:
1523 cifs_put_tlink(tlink); 1549 cifs_put_tlink(tlink);
1524 return rc; 1550 return rc;
1525} 1551}
1526 1552
1527int 1553int cifs_rename(struct inode *source_dir, struct dentry *source_dentry,
1528cifs_rename(struct inode *source_dir, struct dentry *source_dentry, 1554 struct inode *target_dir, struct dentry *target_dentry)
1529 struct inode *target_dir, struct dentry *target_dentry)
1530{ 1555{
1531 char *from_name = NULL; 1556 char *fromName = NULL;
1532 char *to_name = NULL; 1557 char *toName = NULL;
1533 struct cifs_sb_info *cifs_sb; 1558 struct cifs_sb_info *cifs_sb;
1534 struct tcon_link *tlink; 1559 struct tcon_link *tlink;
1535 struct cifs_tcon *tcon; 1560 struct cifs_tcon *tcon;
1536 FILE_UNIX_BASIC_INFO *info_buf_source = NULL; 1561 FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
1537 FILE_UNIX_BASIC_INFO *info_buf_target; 1562 FILE_UNIX_BASIC_INFO *info_buf_target;
1538 unsigned int xid; 1563 int xid, rc, tmprc;
1539 int rc, tmprc;
1540 1564
1541 cifs_sb = CIFS_SB(source_dir->i_sb); 1565 cifs_sb = CIFS_SB(source_dir->i_sb);
1542 tlink = cifs_sb_tlink(cifs_sb); 1566 tlink = cifs_sb_tlink(cifs_sb);
@@ -1544,31 +1568,31 @@ cifs_rename(struct inode *source_dir, struct dentry *source_dentry,
1544 return PTR_ERR(tlink); 1568 return PTR_ERR(tlink);
1545 tcon = tlink_tcon(tlink); 1569 tcon = tlink_tcon(tlink);
1546 1570
1547 xid = get_xid(); 1571 xid = GetXid();
1548 1572
1549 /* 1573 /*
1550 * we already have the rename sem so we do not need to 1574 * we already have the rename sem so we do not need to
1551 * grab it again here to protect the path integrity 1575 * grab it again here to protect the path integrity
1552 */ 1576 */
1553 from_name = build_path_from_dentry(source_dentry); 1577 fromName = build_path_from_dentry(source_dentry);
1554 if (from_name == NULL) { 1578 if (fromName == NULL) {
1555 rc = -ENOMEM; 1579 rc = -ENOMEM;
1556 goto cifs_rename_exit; 1580 goto cifs_rename_exit;
1557 } 1581 }
1558 1582
1559 to_name = build_path_from_dentry(target_dentry); 1583 toName = build_path_from_dentry(target_dentry);
1560 if (to_name == NULL) { 1584 if (toName == NULL) {
1561 rc = -ENOMEM; 1585 rc = -ENOMEM;
1562 goto cifs_rename_exit; 1586 goto cifs_rename_exit;
1563 } 1587 }
1564 1588
1565 rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry, 1589 rc = cifs_do_rename(xid, source_dentry, fromName,
1566 to_name); 1590 target_dentry, toName);
1567 1591
1568 if (rc == -EEXIST && tcon->unix_ext) { 1592 if (rc == -EEXIST && tcon->unix_ext) {
1569 /* 1593 /*
1570 * Are src and dst hardlinks of same inode? We can only tell 1594 * Are src and dst hardlinks of same inode? We can
1571 * with unix extensions enabled. 1595 * only tell with unix extensions enabled
1572 */ 1596 */
1573 info_buf_source = 1597 info_buf_source =
1574 kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO), 1598 kmalloc(2 * sizeof(FILE_UNIX_BASIC_INFO),
@@ -1579,19 +1603,19 @@ cifs_rename(struct inode *source_dir, struct dentry *source_dentry,
1579 } 1603 }
1580 1604
1581 info_buf_target = info_buf_source + 1; 1605 info_buf_target = info_buf_source + 1;
1582 tmprc = CIFSSMBUnixQPathInfo(xid, tcon, from_name, 1606 tmprc = CIFSSMBUnixQPathInfo(xid, tcon, fromName,
1583 info_buf_source, 1607 info_buf_source,
1584 cifs_sb->local_nls, 1608 cifs_sb->local_nls,
1585 cifs_sb->mnt_cifs_flags & 1609 cifs_sb->mnt_cifs_flags &
1586 CIFS_MOUNT_MAP_SPECIAL_CHR); 1610 CIFS_MOUNT_MAP_SPECIAL_CHR);
1587 if (tmprc != 0) 1611 if (tmprc != 0)
1588 goto unlink_target; 1612 goto unlink_target;
1589 1613
1590 tmprc = CIFSSMBUnixQPathInfo(xid, tcon, to_name, 1614 tmprc = CIFSSMBUnixQPathInfo(xid, tcon, toName,
1591 info_buf_target, 1615 info_buf_target,
1592 cifs_sb->local_nls, 1616 cifs_sb->local_nls,
1593 cifs_sb->mnt_cifs_flags & 1617 cifs_sb->mnt_cifs_flags &
1594 CIFS_MOUNT_MAP_SPECIAL_CHR); 1618 CIFS_MOUNT_MAP_SPECIAL_CHR);
1595 1619
1596 if (tmprc == 0 && (info_buf_source->UniqueId == 1620 if (tmprc == 0 && (info_buf_source->UniqueId ==
1597 info_buf_target->UniqueId)) { 1621 info_buf_target->UniqueId)) {
@@ -1599,11 +1623,8 @@ cifs_rename(struct inode *source_dir, struct dentry *source_dentry,
1599 rc = 0; 1623 rc = 0;
1600 goto cifs_rename_exit; 1624 goto cifs_rename_exit;
1601 } 1625 }
1602 } 1626 } /* else ... BB we could add the same check for Windows by
1603 /* 1627 checking the UniqueId via FILE_INTERNAL_INFO */
1604 * else ... BB we could add the same check for Windows by
1605 * checking the UniqueId via FILE_INTERNAL_INFO
1606 */
1607 1628
1608unlink_target: 1629unlink_target:
1609 /* Try unlinking the target dentry if it's not negative */ 1630 /* Try unlinking the target dentry if it's not negative */
@@ -1611,15 +1632,16 @@ unlink_target:
1611 tmprc = cifs_unlink(target_dir, target_dentry); 1632 tmprc = cifs_unlink(target_dir, target_dentry);
1612 if (tmprc) 1633 if (tmprc)
1613 goto cifs_rename_exit; 1634 goto cifs_rename_exit;
1614 rc = cifs_do_rename(xid, source_dentry, from_name, 1635
1615 target_dentry, to_name); 1636 rc = cifs_do_rename(xid, source_dentry, fromName,
1637 target_dentry, toName);
1616 } 1638 }
1617 1639
1618cifs_rename_exit: 1640cifs_rename_exit:
1619 kfree(info_buf_source); 1641 kfree(info_buf_source);
1620 kfree(from_name); 1642 kfree(fromName);
1621 kfree(to_name); 1643 kfree(toName);
1622 free_xid(xid); 1644 FreeXid(xid);
1623 cifs_put_tlink(tlink); 1645 cifs_put_tlink(tlink);
1624 return rc; 1646 return rc;
1625} 1647}
@@ -1694,7 +1716,7 @@ int cifs_revalidate_file_attr(struct file *filp)
1694 1716
1695int cifs_revalidate_dentry_attr(struct dentry *dentry) 1717int cifs_revalidate_dentry_attr(struct dentry *dentry)
1696{ 1718{
1697 unsigned int xid; 1719 int xid;
1698 int rc = 0; 1720 int rc = 0;
1699 struct inode *inode = dentry->d_inode; 1721 struct inode *inode = dentry->d_inode;
1700 struct super_block *sb = dentry->d_sb; 1722 struct super_block *sb = dentry->d_sb;
@@ -1706,7 +1728,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
1706 if (!cifs_inode_needs_reval(inode)) 1728 if (!cifs_inode_needs_reval(inode))
1707 return rc; 1729 return rc;
1708 1730
1709 xid = get_xid(); 1731 xid = GetXid();
1710 1732
1711 /* can not safely grab the rename sem here if rename calls revalidate 1733 /* can not safely grab the rename sem here if rename calls revalidate
1712 since that would deadlock */ 1734 since that would deadlock */
@@ -1728,7 +1750,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
1728 1750
1729out: 1751out:
1730 kfree(full_path); 1752 kfree(full_path);
1731 free_xid(xid); 1753 FreeXid(xid);
1732 return rc; 1754 return rc;
1733} 1755}
1734 1756
@@ -1791,12 +1813,11 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1791 stat->ino = CIFS_I(inode)->uniqueid; 1813 stat->ino = CIFS_I(inode)->uniqueid;
1792 1814
1793 /* 1815 /*
1794 * If on a multiuser mount without unix extensions or cifsacl being 1816 * If on a multiuser mount without unix extensions, and the admin hasn't
1795 * enabled, and the admin hasn't overridden them, set the ownership 1817 * overridden them, set the ownership to the fsuid/fsgid of the current
1796 * to the fsuid/fsgid of the current process. 1818 * process.
1797 */ 1819 */
1798 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) && 1820 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) &&
1799 !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
1800 !tcon->unix_ext) { 1821 !tcon->unix_ext) {
1801 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)) 1822 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID))
1802 stat->uid = current_fsuid(); 1823 stat->uid = current_fsuid();
@@ -1837,15 +1858,14 @@ static void cifs_setsize(struct inode *inode, loff_t offset)
1837 1858
1838static int 1859static int
1839cifs_set_file_size(struct inode *inode, struct iattr *attrs, 1860cifs_set_file_size(struct inode *inode, struct iattr *attrs,
1840 unsigned int xid, char *full_path) 1861 int xid, char *full_path)
1841{ 1862{
1842 int rc; 1863 int rc;
1843 struct cifsFileInfo *open_file; 1864 struct cifsFileInfo *open_file;
1844 struct cifsInodeInfo *cifsInode = CIFS_I(inode); 1865 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
1845 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 1866 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1846 struct tcon_link *tlink = NULL; 1867 struct tcon_link *tlink = NULL;
1847 struct cifs_tcon *tcon = NULL; 1868 struct cifs_tcon *pTcon = NULL;
1848 struct TCP_Server_Info *server;
1849 struct cifs_io_parms io_parms; 1869 struct cifs_io_parms io_parms;
1850 1870
1851 /* 1871 /*
@@ -1859,21 +1879,19 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
1859 */ 1879 */
1860 open_file = find_writable_file(cifsInode, true); 1880 open_file = find_writable_file(cifsInode, true);
1861 if (open_file) { 1881 if (open_file) {
1862 tcon = tlink_tcon(open_file->tlink); 1882 __u16 nfid = open_file->netfid;
1863 server = tcon->ses->server; 1883 __u32 npid = open_file->pid;
1864 if (server->ops->set_file_size) 1884 pTcon = tlink_tcon(open_file->tlink);
1865 rc = server->ops->set_file_size(xid, tcon, open_file, 1885 rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid,
1866 attrs->ia_size, false); 1886 npid, false);
1867 else
1868 rc = -ENOSYS;
1869 cifsFileInfo_put(open_file); 1887 cifsFileInfo_put(open_file);
1870 cFYI(1, "SetFSize for attrs rc = %d", rc); 1888 cFYI(1, "SetFSize for attrs rc = %d", rc);
1871 if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) { 1889 if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
1872 unsigned int bytes_written; 1890 unsigned int bytes_written;
1873 1891
1874 io_parms.netfid = open_file->fid.netfid; 1892 io_parms.netfid = nfid;
1875 io_parms.pid = open_file->pid; 1893 io_parms.pid = npid;
1876 io_parms.tcon = tcon; 1894 io_parms.tcon = pTcon;
1877 io_parms.offset = 0; 1895 io_parms.offset = 0;
1878 io_parms.length = attrs->ia_size; 1896 io_parms.length = attrs->ia_size;
1879 rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, 1897 rc = CIFSSMBWrite(xid, &io_parms, &bytes_written,
@@ -1883,55 +1901,52 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
1883 } else 1901 } else
1884 rc = -EINVAL; 1902 rc = -EINVAL;
1885 1903
1886 if (!rc) 1904 if (rc != 0) {
1887 goto set_size_out; 1905 if (pTcon == NULL) {
1888 1906 tlink = cifs_sb_tlink(cifs_sb);
1889 if (tcon == NULL) { 1907 if (IS_ERR(tlink))
1890 tlink = cifs_sb_tlink(cifs_sb); 1908 return PTR_ERR(tlink);
1891 if (IS_ERR(tlink)) 1909 pTcon = tlink_tcon(tlink);
1892 return PTR_ERR(tlink); 1910 }
1893 tcon = tlink_tcon(tlink);
1894 server = tcon->ses->server;
1895 }
1896 1911
1897 /* 1912 /* Set file size by pathname rather than by handle
1898 * Set file size by pathname rather than by handle either because no 1913 either because no valid, writeable file handle for
1899 * valid, writeable file handle for it was found or because there was 1914 it was found or because there was an error setting
1900 * an error setting it by handle. 1915 it by handle */
1901 */ 1916 rc = CIFSSMBSetEOF(xid, pTcon, full_path, attrs->ia_size,
1902 if (server->ops->set_path_size) 1917 false, cifs_sb->local_nls,
1903 rc = server->ops->set_path_size(xid, tcon, full_path,
1904 attrs->ia_size, cifs_sb, false);
1905 else
1906 rc = -ENOSYS;
1907 cFYI(1, "SetEOF by path (setattrs) rc = %d", rc);
1908 if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
1909 __u16 netfid;
1910 int oplock = 0;
1911
1912 rc = SMBLegacyOpen(xid, tcon, full_path, FILE_OPEN,
1913 GENERIC_WRITE, CREATE_NOT_DIR, &netfid,
1914 &oplock, NULL, cifs_sb->local_nls,
1915 cifs_sb->mnt_cifs_flags & 1918 cifs_sb->mnt_cifs_flags &
1916 CIFS_MOUNT_MAP_SPECIAL_CHR); 1919 CIFS_MOUNT_MAP_SPECIAL_CHR);
1917 if (rc == 0) { 1920 cFYI(1, "SetEOF by path (setattrs) rc = %d", rc);
1918 unsigned int bytes_written; 1921 if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
1919 1922 __u16 netfid;
1920 io_parms.netfid = netfid; 1923 int oplock = 0;
1921 io_parms.pid = current->tgid; 1924
1922 io_parms.tcon = tcon; 1925 rc = SMBLegacyOpen(xid, pTcon, full_path,
1923 io_parms.offset = 0; 1926 FILE_OPEN, GENERIC_WRITE,
1924 io_parms.length = attrs->ia_size; 1927 CREATE_NOT_DIR, &netfid, &oplock, NULL,
1925 rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, NULL, 1928 cifs_sb->local_nls,
1926 NULL, 1); 1929 cifs_sb->mnt_cifs_flags &
1927 cFYI(1, "wrt seteof rc %d", rc); 1930 CIFS_MOUNT_MAP_SPECIAL_CHR);
1928 CIFSSMBClose(xid, tcon, netfid); 1931 if (rc == 0) {
1932 unsigned int bytes_written;
1933
1934 io_parms.netfid = netfid;
1935 io_parms.pid = current->tgid;
1936 io_parms.tcon = pTcon;
1937 io_parms.offset = 0;
1938 io_parms.length = attrs->ia_size;
1939 rc = CIFSSMBWrite(xid, &io_parms,
1940 &bytes_written,
1941 NULL, NULL, 1);
1942 cFYI(1, "wrt seteof rc %d", rc);
1943 CIFSSMBClose(xid, pTcon, netfid);
1944 }
1929 } 1945 }
1946 if (tlink)
1947 cifs_put_tlink(tlink);
1930 } 1948 }
1931 if (tlink)
1932 cifs_put_tlink(tlink);
1933 1949
1934set_size_out:
1935 if (rc == 0) { 1950 if (rc == 0) {
1936 cifsInode->server_eof = attrs->ia_size; 1951 cifsInode->server_eof = attrs->ia_size;
1937 cifs_setsize(inode, attrs->ia_size); 1952 cifs_setsize(inode, attrs->ia_size);
@@ -1945,7 +1960,7 @@ static int
1945cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) 1960cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
1946{ 1961{
1947 int rc; 1962 int rc;
1948 unsigned int xid; 1963 int xid;
1949 char *full_path = NULL; 1964 char *full_path = NULL;
1950 struct inode *inode = direntry->d_inode; 1965 struct inode *inode = direntry->d_inode;
1951 struct cifsInodeInfo *cifsInode = CIFS_I(inode); 1966 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
@@ -1958,7 +1973,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
1958 cFYI(1, "setattr_unix on file %s attrs->ia_valid=0x%x", 1973 cFYI(1, "setattr_unix on file %s attrs->ia_valid=0x%x",
1959 direntry->d_name.name, attrs->ia_valid); 1974 direntry->d_name.name, attrs->ia_valid);
1960 1975
1961 xid = get_xid(); 1976 xid = GetXid();
1962 1977
1963 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) 1978 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
1964 attrs->ia_valid |= ATTR_FORCE; 1979 attrs->ia_valid |= ATTR_FORCE;
@@ -2038,7 +2053,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
2038 args->device = 0; 2053 args->device = 0;
2039 open_file = find_writable_file(cifsInode, true); 2054 open_file = find_writable_file(cifsInode, true);
2040 if (open_file) { 2055 if (open_file) {
2041 u16 nfid = open_file->fid.netfid; 2056 u16 nfid = open_file->netfid;
2042 u32 npid = open_file->pid; 2057 u32 npid = open_file->pid;
2043 pTcon = tlink_tcon(open_file->tlink); 2058 pTcon = tlink_tcon(open_file->tlink);
2044 rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid); 2059 rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid);
@@ -2078,16 +2093,14 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
2078out: 2093out:
2079 kfree(args); 2094 kfree(args);
2080 kfree(full_path); 2095 kfree(full_path);
2081 free_xid(xid); 2096 FreeXid(xid);
2082 return rc; 2097 return rc;
2083} 2098}
2084 2099
2085static int 2100static int
2086cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) 2101cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2087{ 2102{
2088 unsigned int xid; 2103 int xid;
2089 uid_t uid = NO_CHANGE_32;
2090 gid_t gid = NO_CHANGE_32;
2091 struct inode *inode = direntry->d_inode; 2104 struct inode *inode = direntry->d_inode;
2092 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 2105 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
2093 struct cifsInodeInfo *cifsInode = CIFS_I(inode); 2106 struct cifsInodeInfo *cifsInode = CIFS_I(inode);
@@ -2096,7 +2109,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2096 __u32 dosattr = 0; 2109 __u32 dosattr = 0;
2097 __u64 mode = NO_CHANGE_64; 2110 __u64 mode = NO_CHANGE_64;
2098 2111
2099 xid = get_xid(); 2112 xid = GetXid();
2100 2113
2101 cFYI(1, "setattr on file %s attrs->iavalid 0x%x", 2114 cFYI(1, "setattr on file %s attrs->iavalid 0x%x",
2102 direntry->d_name.name, attrs->ia_valid); 2115 direntry->d_name.name, attrs->ia_valid);
@@ -2106,14 +2119,14 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2106 2119
2107 rc = inode_change_ok(inode, attrs); 2120 rc = inode_change_ok(inode, attrs);
2108 if (rc < 0) { 2121 if (rc < 0) {
2109 free_xid(xid); 2122 FreeXid(xid);
2110 return rc; 2123 return rc;
2111 } 2124 }
2112 2125
2113 full_path = build_path_from_dentry(direntry); 2126 full_path = build_path_from_dentry(direntry);
2114 if (full_path == NULL) { 2127 if (full_path == NULL) {
2115 rc = -ENOMEM; 2128 rc = -ENOMEM;
2116 free_xid(xid); 2129 FreeXid(xid);
2117 return rc; 2130 return rc;
2118 } 2131 }
2119 2132
@@ -2138,25 +2151,13 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2138 goto cifs_setattr_exit; 2151 goto cifs_setattr_exit;
2139 } 2152 }
2140 2153
2141 if (attrs->ia_valid & ATTR_UID) 2154 /*
2142 uid = attrs->ia_uid; 2155 * Without unix extensions we can't send ownership changes to the
2143 2156 * server, so silently ignore them. This is consistent with how
2144 if (attrs->ia_valid & ATTR_GID) 2157 * local DOS/Windows filesystems behave (VFAT, NTFS, etc). With
2145 gid = attrs->ia_gid; 2158 * CIFSACL support + proper Windows to Unix idmapping, we may be
2146 2159 * able to support this in the future.
2147#ifdef CONFIG_CIFS_ACL 2160 */
2148 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
2149 if (uid != NO_CHANGE_32 || gid != NO_CHANGE_32) {
2150 rc = id_mode_to_cifs_acl(inode, full_path, NO_CHANGE_64,
2151 uid, gid);
2152 if (rc) {
2153 cFYI(1, "%s: Setting id failed with error: %d",
2154 __func__, rc);
2155 goto cifs_setattr_exit;
2156 }
2157 }
2158 } else
2159#endif /* CONFIG_CIFS_ACL */
2160 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)) 2161 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID))
2161 attrs->ia_valid &= ~(ATTR_UID | ATTR_GID); 2162 attrs->ia_valid &= ~(ATTR_UID | ATTR_GID);
2162 2163
@@ -2165,12 +2166,15 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2165 attrs->ia_valid &= ~ATTR_MODE; 2166 attrs->ia_valid &= ~ATTR_MODE;
2166 2167
2167 if (attrs->ia_valid & ATTR_MODE) { 2168 if (attrs->ia_valid & ATTR_MODE) {
2169 cFYI(1, "Mode changed to 0%o", attrs->ia_mode);
2168 mode = attrs->ia_mode; 2170 mode = attrs->ia_mode;
2171 }
2172
2173 if (attrs->ia_valid & ATTR_MODE) {
2169 rc = 0; 2174 rc = 0;
2170#ifdef CONFIG_CIFS_ACL 2175#ifdef CONFIG_CIFS_ACL
2171 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { 2176 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
2172 rc = id_mode_to_cifs_acl(inode, full_path, mode, 2177 rc = mode_to_cifs_acl(inode, full_path, mode);
2173 NO_CHANGE_32, NO_CHANGE_32);
2174 if (rc) { 2178 if (rc) {
2175 cFYI(1, "%s: Setting ACL failed with error: %d", 2179 cFYI(1, "%s: Setting ACL failed with error: %d",
2176 __func__, rc); 2180 __func__, rc);
@@ -2239,7 +2243,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
2239 2243
2240cifs_setattr_exit: 2244cifs_setattr_exit:
2241 kfree(full_path); 2245 kfree(full_path);
2242 free_xid(xid); 2246 FreeXid(xid);
2243 return rc; 2247 return rc;
2244} 2248}
2245 2249
diff --git a/fs/cifs/ioctl.c b/fs/cifs/ioctl.c
index fd5009d56f9..4221b5e48a4 100644
--- a/fs/cifs/ioctl.c
+++ b/fs/cifs/ioctl.c
@@ -28,11 +28,13 @@
28#include "cifs_debug.h" 28#include "cifs_debug.h"
29#include "cifsfs.h" 29#include "cifsfs.h"
30 30
31#define CIFS_IOC_CHECKUMOUNT _IO(0xCF, 2)
32
31long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) 33long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
32{ 34{
33 struct inode *inode = filep->f_dentry->d_inode; 35 struct inode *inode = filep->f_dentry->d_inode;
34 int rc = -ENOTTY; /* strange error - but the precedent */ 36 int rc = -ENOTTY; /* strange error - but the precedent */
35 unsigned int xid; 37 int xid;
36 struct cifs_sb_info *cifs_sb; 38 struct cifs_sb_info *cifs_sb;
37#ifdef CONFIG_CIFS_POSIX 39#ifdef CONFIG_CIFS_POSIX
38 struct cifsFileInfo *pSMBFile = filep->private_data; 40 struct cifsFileInfo *pSMBFile = filep->private_data;
@@ -42,13 +44,22 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
42 __u64 caps; 44 __u64 caps;
43#endif /* CONFIG_CIFS_POSIX */ 45#endif /* CONFIG_CIFS_POSIX */
44 46
45 xid = get_xid(); 47 xid = GetXid();
46 48
47 cFYI(1, "ioctl file %p cmd %u arg %lu", filep, command, arg); 49 cFYI(1, "ioctl file %p cmd %u arg %lu", filep, command, arg);
48 50
49 cifs_sb = CIFS_SB(inode->i_sb); 51 cifs_sb = CIFS_SB(inode->i_sb);
50 52
51 switch (command) { 53 switch (command) {
54 case CIFS_IOC_CHECKUMOUNT:
55 cFYI(1, "User unmount attempted");
56 if (cifs_sb->mnt_uid == current_uid())
57 rc = 0;
58 else {
59 rc = -EACCES;
60 cFYI(1, "uids do not match");
61 }
62 break;
52#ifdef CONFIG_CIFS_POSIX 63#ifdef CONFIG_CIFS_POSIX
53 case FS_IOC_GETFLAGS: 64 case FS_IOC_GETFLAGS:
54 if (pSMBFile == NULL) 65 if (pSMBFile == NULL)
@@ -56,9 +67,8 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
56 tcon = tlink_tcon(pSMBFile->tlink); 67 tcon = tlink_tcon(pSMBFile->tlink);
57 caps = le64_to_cpu(tcon->fsUnixInfo.Capability); 68 caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
58 if (CIFS_UNIX_EXTATTR_CAP & caps) { 69 if (CIFS_UNIX_EXTATTR_CAP & caps) {
59 rc = CIFSGetExtAttr(xid, tcon, 70 rc = CIFSGetExtAttr(xid, tcon, pSMBFile->netfid,
60 pSMBFile->fid.netfid, 71 &ExtAttrBits, &ExtAttrMask);
61 &ExtAttrBits, &ExtAttrMask);
62 if (rc == 0) 72 if (rc == 0)
63 rc = put_user(ExtAttrBits & 73 rc = put_user(ExtAttrBits &
64 FS_FL_USER_VISIBLE, 74 FS_FL_USER_VISIBLE,
@@ -76,12 +86,8 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
76 rc = -EFAULT; 86 rc = -EFAULT;
77 break; 87 break;
78 } 88 }
79 /* 89 /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid,
80 * rc = CIFSGetExtAttr(xid, tcon, 90 extAttrBits, &ExtAttrMask);*/
81 * pSMBFile->fid.netfid,
82 * extAttrBits,
83 * &ExtAttrMask);
84 */
85 } 91 }
86 cFYI(1, "set flags not implemented yet"); 92 cFYI(1, "set flags not implemented yet");
87 break; 93 break;
@@ -91,6 +97,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
91 break; 97 break;
92 } 98 }
93 99
94 free_xid(xid); 100 FreeXid(xid);
95 return rc; 101 return rc;
96} 102}
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 51dc2fb6e85..db3f18cdf02 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -56,14 +56,14 @@ symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
56 md5 = crypto_alloc_shash("md5", 0, 0); 56 md5 = crypto_alloc_shash("md5", 0, 0);
57 if (IS_ERR(md5)) { 57 if (IS_ERR(md5)) {
58 rc = PTR_ERR(md5); 58 rc = PTR_ERR(md5);
59 cERROR(1, "%s: Crypto md5 allocation error %d", __func__, rc); 59 cERROR(1, "%s: Crypto md5 allocation error %d\n", __func__, rc);
60 return rc; 60 return rc;
61 } 61 }
62 size = sizeof(struct shash_desc) + crypto_shash_descsize(md5); 62 size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
63 sdescmd5 = kmalloc(size, GFP_KERNEL); 63 sdescmd5 = kmalloc(size, GFP_KERNEL);
64 if (!sdescmd5) { 64 if (!sdescmd5) {
65 rc = -ENOMEM; 65 rc = -ENOMEM;
66 cERROR(1, "%s: Memory allocation failure", __func__); 66 cERROR(1, "%s: Memory allocation failure\n", __func__);
67 goto symlink_hash_err; 67 goto symlink_hash_err;
68 } 68 }
69 sdescmd5->shash.tfm = md5; 69 sdescmd5->shash.tfm = md5;
@@ -71,17 +71,17 @@ symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
71 71
72 rc = crypto_shash_init(&sdescmd5->shash); 72 rc = crypto_shash_init(&sdescmd5->shash);
73 if (rc) { 73 if (rc) {
74 cERROR(1, "%s: Could not init md5 shash", __func__); 74 cERROR(1, "%s: Could not init md5 shash\n", __func__);
75 goto symlink_hash_err; 75 goto symlink_hash_err;
76 } 76 }
77 rc = crypto_shash_update(&sdescmd5->shash, link_str, link_len); 77 rc = crypto_shash_update(&sdescmd5->shash, link_str, link_len);
78 if (rc) { 78 if (rc) {
79 cERROR(1, "%s: Could not update iwth link_str", __func__); 79 cERROR(1, "%s: Could not update iwth link_str\n", __func__);
80 goto symlink_hash_err; 80 goto symlink_hash_err;
81 } 81 }
82 rc = crypto_shash_final(&sdescmd5->shash, md5_hash); 82 rc = crypto_shash_final(&sdescmd5->shash, md5_hash);
83 if (rc) 83 if (rc)
84 cERROR(1, "%s: Could not generate md5 hash", __func__); 84 cERROR(1, "%s: Could not generate md5 hash\n", __func__);
85 85
86symlink_hash_err: 86symlink_hash_err:
87 crypto_free_shash(md5); 87 crypto_free_shash(md5);
@@ -115,7 +115,7 @@ CIFSParseMFSymlink(const u8 *buf,
115 115
116 rc = symlink_hash(link_len, link_str, md5_hash); 116 rc = symlink_hash(link_len, link_str, md5_hash);
117 if (rc) { 117 if (rc) {
118 cFYI(1, "%s: MD5 hash failure: %d", __func__, rc); 118 cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc);
119 return rc; 119 return rc;
120 } 120 }
121 121
@@ -154,7 +154,7 @@ CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str)
154 154
155 rc = symlink_hash(link_len, link_str, md5_hash); 155 rc = symlink_hash(link_len, link_str, md5_hash);
156 if (rc) { 156 if (rc) {
157 cFYI(1, "%s: MD5 hash failure: %d", __func__, rc); 157 cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc);
158 return rc; 158 return rc;
159 } 159 }
160 160
@@ -181,22 +181,16 @@ CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str)
181} 181}
182 182
183static int 183static int
184CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon, 184CIFSCreateMFSymLink(const int xid, struct cifs_tcon *tcon,
185 const char *fromName, const char *toName, 185 const char *fromName, const char *toName,
186 struct cifs_sb_info *cifs_sb) 186 const struct nls_table *nls_codepage, int remap)
187{ 187{
188 int rc; 188 int rc;
189 int oplock = 0; 189 int oplock = 0;
190 int remap;
191 int create_options = CREATE_NOT_DIR;
192 __u16 netfid = 0; 190 __u16 netfid = 0;
193 u8 *buf; 191 u8 *buf;
194 unsigned int bytes_written = 0; 192 unsigned int bytes_written = 0;
195 struct cifs_io_parms io_parms; 193 struct cifs_io_parms io_parms;
196 struct nls_table *nls_codepage;
197
198 nls_codepage = cifs_sb->local_nls;
199 remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
200 194
201 buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL); 195 buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
202 if (!buf) 196 if (!buf)
@@ -208,11 +202,8 @@ CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon,
208 return rc; 202 return rc;
209 } 203 }
210 204
211 if (backup_cred(cifs_sb))
212 create_options |= CREATE_OPEN_BACKUP_INTENT;
213
214 rc = CIFSSMBOpen(xid, tcon, fromName, FILE_CREATE, GENERIC_WRITE, 205 rc = CIFSSMBOpen(xid, tcon, fromName, FILE_CREATE, GENERIC_WRITE,
215 create_options, &netfid, &oplock, NULL, 206 CREATE_NOT_DIR, &netfid, &oplock, NULL,
216 nls_codepage, remap); 207 nls_codepage, remap);
217 if (rc != 0) { 208 if (rc != 0) {
218 kfree(buf); 209 kfree(buf);
@@ -238,7 +229,7 @@ CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon,
238} 229}
239 230
240static int 231static int
241CIFSQueryMFSymLink(const unsigned int xid, struct cifs_tcon *tcon, 232CIFSQueryMFSymLink(const int xid, struct cifs_tcon *tcon,
242 const unsigned char *searchName, char **symlinkinfo, 233 const unsigned char *searchName, char **symlinkinfo,
243 const struct nls_table *nls_codepage, int remap) 234 const struct nls_table *nls_codepage, int remap)
244{ 235{
@@ -307,7 +298,7 @@ CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr)
307int 298int
308CIFSCheckMFSymlink(struct cifs_fattr *fattr, 299CIFSCheckMFSymlink(struct cifs_fattr *fattr,
309 const unsigned char *path, 300 const unsigned char *path,
310 struct cifs_sb_info *cifs_sb, unsigned int xid) 301 struct cifs_sb_info *cifs_sb, int xid)
311{ 302{
312 int rc; 303 int rc;
313 int oplock = 0; 304 int oplock = 0;
@@ -390,88 +381,72 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
390 struct dentry *direntry) 381 struct dentry *direntry)
391{ 382{
392 int rc = -EACCES; 383 int rc = -EACCES;
393 unsigned int xid; 384 int xid;
394 char *from_name = NULL; 385 char *fromName = NULL;
395 char *to_name = NULL; 386 char *toName = NULL;
396 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 387 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
397 struct tcon_link *tlink; 388 struct tcon_link *tlink;
398 struct cifs_tcon *tcon; 389 struct cifs_tcon *pTcon;
399 struct TCP_Server_Info *server;
400 struct cifsInodeInfo *cifsInode; 390 struct cifsInodeInfo *cifsInode;
401 391
402 tlink = cifs_sb_tlink(cifs_sb); 392 tlink = cifs_sb_tlink(cifs_sb);
403 if (IS_ERR(tlink)) 393 if (IS_ERR(tlink))
404 return PTR_ERR(tlink); 394 return PTR_ERR(tlink);
405 tcon = tlink_tcon(tlink); 395 pTcon = tlink_tcon(tlink);
406 396
407 xid = get_xid(); 397 xid = GetXid();
408 398
409 from_name = build_path_from_dentry(old_file); 399 fromName = build_path_from_dentry(old_file);
410 to_name = build_path_from_dentry(direntry); 400 toName = build_path_from_dentry(direntry);
411 if ((from_name == NULL) || (to_name == NULL)) { 401 if ((fromName == NULL) || (toName == NULL)) {
412 rc = -ENOMEM; 402 rc = -ENOMEM;
413 goto cifs_hl_exit; 403 goto cifs_hl_exit;
414 } 404 }
415 405
416 if (tcon->unix_ext) 406 if (pTcon->unix_ext)
417 rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name, 407 rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName,
418 cifs_sb->local_nls, 408 cifs_sb->local_nls,
419 cifs_sb->mnt_cifs_flags & 409 cifs_sb->mnt_cifs_flags &
420 CIFS_MOUNT_MAP_SPECIAL_CHR); 410 CIFS_MOUNT_MAP_SPECIAL_CHR);
421 else { 411 else {
422 server = tcon->ses->server; 412 rc = CIFSCreateHardLink(xid, pTcon, fromName, toName,
423 if (!server->ops->create_hardlink) 413 cifs_sb->local_nls,
424 return -ENOSYS; 414 cifs_sb->mnt_cifs_flags &
425 rc = server->ops->create_hardlink(xid, tcon, from_name, to_name, 415 CIFS_MOUNT_MAP_SPECIAL_CHR);
426 cifs_sb);
427 if ((rc == -EIO) || (rc == -EINVAL)) 416 if ((rc == -EIO) || (rc == -EINVAL))
428 rc = -EOPNOTSUPP; 417 rc = -EOPNOTSUPP;
429 } 418 }
430 419
431 d_drop(direntry); /* force new lookup from server of target */ 420 d_drop(direntry); /* force new lookup from server of target */
432 421
433 /* 422 /* if source file is cached (oplocked) revalidate will not go to server
434 * if source file is cached (oplocked) revalidate will not go to server 423 until the file is closed or oplock broken so update nlinks locally */
435 * until the file is closed or oplock broken so update nlinks locally
436 */
437 if (old_file->d_inode) { 424 if (old_file->d_inode) {
438 cifsInode = CIFS_I(old_file->d_inode); 425 cifsInode = CIFS_I(old_file->d_inode);
439 if (rc == 0) { 426 if (rc == 0) {
440 spin_lock(&old_file->d_inode->i_lock); 427 old_file->d_inode->i_nlink++;
441 inc_nlink(old_file->d_inode); 428/* BB should we make this contingent on superblock flag NOATIME? */
442 spin_unlock(&old_file->d_inode->i_lock); 429/* old_file->d_inode->i_ctime = CURRENT_TIME;*/
443 /* 430 /* parent dir timestamps will update from srv
444 * BB should we make this contingent on superblock flag 431 within a second, would it really be worth it
445 * NOATIME? 432 to set the parent dir cifs inode time to zero
446 */ 433 to force revalidate (faster) for it too? */
447 /* old_file->d_inode->i_ctime = CURRENT_TIME; */
448 /*
449 * parent dir timestamps will update from srv within a
450 * second, would it really be worth it to set the parent
451 * dir cifs inode time to zero to force revalidate
452 * (faster) for it too?
453 */
454 } 434 }
455 /* 435 /* if not oplocked will force revalidate to get info
456 * if not oplocked will force revalidate to get info on source 436 on source file from srv */
457 * file from srv
458 */
459 cifsInode->time = 0; 437 cifsInode->time = 0;
460 438
461 /* 439 /* Will update parent dir timestamps from srv within a second.
462 * Will update parent dir timestamps from srv within a second. 440 Would it really be worth it to set the parent dir (cifs
463 * Would it really be worth it to set the parent dir (cifs 441 inode) time field to zero to force revalidate on parent
464 * inode) time field to zero to force revalidate on parent 442 directory faster ie
465 * directory faster ie 443 CIFS_I(inode)->time = 0; */
466 *
467 * CIFS_I(inode)->time = 0;
468 */
469 } 444 }
470 445
471cifs_hl_exit: 446cifs_hl_exit:
472 kfree(from_name); 447 kfree(fromName);
473 kfree(to_name); 448 kfree(toName);
474 free_xid(xid); 449 FreeXid(xid);
475 cifs_put_tlink(tlink); 450 cifs_put_tlink(tlink);
476 return rc; 451 return rc;
477} 452}
@@ -481,14 +456,14 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
481{ 456{
482 struct inode *inode = direntry->d_inode; 457 struct inode *inode = direntry->d_inode;
483 int rc = -ENOMEM; 458 int rc = -ENOMEM;
484 unsigned int xid; 459 int xid;
485 char *full_path = NULL; 460 char *full_path = NULL;
486 char *target_path = NULL; 461 char *target_path = NULL;
487 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 462 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
488 struct tcon_link *tlink = NULL; 463 struct tcon_link *tlink = NULL;
489 struct cifs_tcon *tcon; 464 struct cifs_tcon *tcon;
490 465
491 xid = get_xid(); 466 xid = GetXid();
492 467
493 tlink = cifs_sb_tlink(cifs_sb); 468 tlink = cifs_sb_tlink(cifs_sb);
494 if (IS_ERR(tlink)) { 469 if (IS_ERR(tlink)) {
@@ -511,8 +486,8 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
511 * but there doesn't seem to be any harm in allowing the client to 486 * but there doesn't seem to be any harm in allowing the client to
512 * read them. 487 * read them.
513 */ 488 */
514 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) && 489 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
515 !cap_unix(tcon->ses)) { 490 && !(tcon->ses->capabilities & CAP_UNIX)) {
516 rc = -EACCES; 491 rc = -EACCES;
517 goto out; 492 goto out;
518 } 493 }
@@ -534,7 +509,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
534 cifs_sb->mnt_cifs_flags & 509 cifs_sb->mnt_cifs_flags &
535 CIFS_MOUNT_MAP_SPECIAL_CHR); 510 CIFS_MOUNT_MAP_SPECIAL_CHR);
536 511
537 if ((rc != 0) && cap_unix(tcon->ses)) 512 if ((rc != 0) && (tcon->ses->capabilities & CAP_UNIX))
538 rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path, 513 rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path,
539 cifs_sb->local_nls); 514 cifs_sb->local_nls);
540 515
@@ -545,7 +520,7 @@ out:
545 target_path = ERR_PTR(rc); 520 target_path = ERR_PTR(rc);
546 } 521 }
547 522
548 free_xid(xid); 523 FreeXid(xid);
549 if (tlink) 524 if (tlink)
550 cifs_put_tlink(tlink); 525 cifs_put_tlink(tlink);
551 nd_set_link(nd, target_path); 526 nd_set_link(nd, target_path);
@@ -556,14 +531,14 @@ int
556cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname) 531cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
557{ 532{
558 int rc = -EOPNOTSUPP; 533 int rc = -EOPNOTSUPP;
559 unsigned int xid; 534 int xid;
560 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 535 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
561 struct tcon_link *tlink; 536 struct tcon_link *tlink;
562 struct cifs_tcon *pTcon; 537 struct cifs_tcon *pTcon;
563 char *full_path = NULL; 538 char *full_path = NULL;
564 struct inode *newinode = NULL; 539 struct inode *newinode = NULL;
565 540
566 xid = get_xid(); 541 xid = GetXid();
567 542
568 tlink = cifs_sb_tlink(cifs_sb); 543 tlink = cifs_sb_tlink(cifs_sb);
569 if (IS_ERR(tlink)) { 544 if (IS_ERR(tlink)) {
@@ -584,7 +559,9 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
584 /* BB what if DFS and this volume is on different share? BB */ 559 /* BB what if DFS and this volume is on different share? BB */
585 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) 560 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
586 rc = CIFSCreateMFSymLink(xid, pTcon, full_path, symname, 561 rc = CIFSCreateMFSymLink(xid, pTcon, full_path, symname,
587 cifs_sb); 562 cifs_sb->local_nls,
563 cifs_sb->mnt_cifs_flags &
564 CIFS_MOUNT_MAP_SPECIAL_CHR);
588 else if (pTcon->unix_ext) 565 else if (pTcon->unix_ext)
589 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname, 566 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
590 cifs_sb->local_nls); 567 cifs_sb->local_nls);
@@ -610,7 +587,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
610symlink_exit: 587symlink_exit:
611 kfree(full_path); 588 kfree(full_path);
612 cifs_put_tlink(tlink); 589 cifs_put_tlink(tlink);
613 free_xid(xid); 590 FreeXid(xid);
614 return rc; 591 return rc;
615} 592}
616 593
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 3a00c0d0cea..7c169339259 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -29,9 +29,6 @@
29#include "smberr.h" 29#include "smberr.h"
30#include "nterr.h" 30#include "nterr.h"
31#include "cifs_unicode.h" 31#include "cifs_unicode.h"
32#ifdef CONFIG_CIFS_SMB2
33#include "smb2pdu.h"
34#endif
35 32
36extern mempool_t *cifs_sm_req_poolp; 33extern mempool_t *cifs_sm_req_poolp;
37extern mempool_t *cifs_req_poolp; 34extern mempool_t *cifs_req_poolp;
@@ -43,7 +40,7 @@ extern mempool_t *cifs_req_poolp;
43 since the cifs fs was mounted */ 40 since the cifs fs was mounted */
44 41
45unsigned int 42unsigned int
46_get_xid(void) 43_GetXid(void)
47{ 44{
48 unsigned int xid; 45 unsigned int xid;
49 46
@@ -61,7 +58,7 @@ _get_xid(void)
61} 58}
62 59
63void 60void
64_free_xid(unsigned int xid) 61_FreeXid(unsigned int xid)
65{ 62{
66 spin_lock(&GlobalMid_Lock); 63 spin_lock(&GlobalMid_Lock);
67 /* if (GlobalTotalActiveXid == 0) 64 /* if (GlobalTotalActiveXid == 0)
@@ -146,27 +143,17 @@ struct smb_hdr *
146cifs_buf_get(void) 143cifs_buf_get(void)
147{ 144{
148 struct smb_hdr *ret_buf = NULL; 145 struct smb_hdr *ret_buf = NULL;
149 size_t buf_size = sizeof(struct smb_hdr); 146
150 147/* We could use negotiated size instead of max_msgsize -
151#ifdef CONFIG_CIFS_SMB2 148 but it may be more efficient to always alloc same size
152 /* 149 albeit slightly larger than necessary and maxbuffersize
153 * SMB2 header is bigger than CIFS one - no problems to clean some 150 defaults to this and can not be bigger */
154 * more bytes for CIFS.
155 */
156 buf_size = sizeof(struct smb2_hdr);
157#endif
158 /*
159 * We could use negotiated size instead of max_msgsize -
160 * but it may be more efficient to always alloc same size
161 * albeit slightly larger than necessary and maxbuffersize
162 * defaults to this and can not be bigger.
163 */
164 ret_buf = mempool_alloc(cifs_req_poolp, GFP_NOFS); 151 ret_buf = mempool_alloc(cifs_req_poolp, GFP_NOFS);
165 152
166 /* clear the first few header bytes */ 153 /* clear the first few header bytes */
167 /* for most paths, more is cleared in header_assemble */ 154 /* for most paths, more is cleared in header_assemble */
168 if (ret_buf) { 155 if (ret_buf) {
169 memset(ret_buf, 0, buf_size + 3); 156 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
170 atomic_inc(&bufAllocCount); 157 atomic_inc(&bufAllocCount);
171#ifdef CONFIG_CIFS_STATS2 158#ifdef CONFIG_CIFS_STATS2
172 atomic_inc(&totBufAllocCount); 159 atomic_inc(&totBufAllocCount);
@@ -225,6 +212,85 @@ cifs_small_buf_release(void *buf_to_free)
225 return; 212 return;
226} 213}
227 214
215/*
216 Find a free multiplex id (SMB mid). Otherwise there could be
217 mid collisions which might cause problems, demultiplexing the
218 wrong response to this request. Multiplex ids could collide if
219 one of a series requests takes much longer than the others, or
220 if a very large number of long lived requests (byte range
221 locks or FindNotify requests) are pending. No more than
222 64K-1 requests can be outstanding at one time. If no
223 mids are available, return zero. A future optimization
224 could make the combination of mids and uid the key we use
225 to demultiplex on (rather than mid alone).
226 In addition to the above check, the cifs demultiplex
227 code already used the command code as a secondary
228 check of the frame and if signing is negotiated the
229 response would be discarded if the mid were the same
230 but the signature was wrong. Since the mid is not put in the
231 pending queue until later (when it is about to be dispatched)
232 we do have to limit the number of outstanding requests
233 to somewhat less than 64K-1 although it is hard to imagine
234 so many threads being in the vfs at one time.
235*/
236__u16 GetNextMid(struct TCP_Server_Info *server)
237{
238 __u16 mid = 0;
239 __u16 last_mid;
240 bool collision;
241
242 spin_lock(&GlobalMid_Lock);
243 last_mid = server->CurrentMid; /* we do not want to loop forever */
244 server->CurrentMid++;
245 /* This nested loop looks more expensive than it is.
246 In practice the list of pending requests is short,
247 fewer than 50, and the mids are likely to be unique
248 on the first pass through the loop unless some request
249 takes longer than the 64 thousand requests before it
250 (and it would also have to have been a request that
251 did not time out) */
252 while (server->CurrentMid != last_mid) {
253 struct mid_q_entry *mid_entry;
254 unsigned int num_mids;
255
256 collision = false;
257 if (server->CurrentMid == 0)
258 server->CurrentMid++;
259
260 num_mids = 0;
261 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
262 ++num_mids;
263 if (mid_entry->mid == server->CurrentMid &&
264 mid_entry->midState == MID_REQUEST_SUBMITTED) {
265 /* This mid is in use, try a different one */
266 collision = true;
267 break;
268 }
269 }
270
271 /*
272 * if we have more than 32k mids in the list, then something
273 * is very wrong. Possibly a local user is trying to DoS the
274 * box by issuing long-running calls and SIGKILL'ing them. If
275 * we get to 2^16 mids then we're in big trouble as this
276 * function could loop forever.
277 *
278 * Go ahead and assign out the mid in this situation, but force
279 * an eventual reconnect to clean out the pending_mid_q.
280 */
281 if (num_mids > 32768)
282 server->tcpStatus = CifsNeedReconnect;
283
284 if (!collision) {
285 mid = server->CurrentMid;
286 break;
287 }
288 server->CurrentMid++;
289 }
290 spin_unlock(&GlobalMid_Lock);
291 return mid;
292}
293
228/* NB: MID can not be set if treeCon not passed in, in that 294/* NB: MID can not be set if treeCon not passed in, in that
229 case it is responsbility of caller to set the mid */ 295 case it is responsbility of caller to set the mid */
230void 296void
@@ -232,6 +298,8 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
232 const struct cifs_tcon *treeCon, int word_count 298 const struct cifs_tcon *treeCon, int word_count
233 /* length of fixed section (word count) in two byte units */) 299 /* length of fixed section (word count) in two byte units */)
234{ 300{
301 struct list_head *temp_item;
302 struct cifs_ses *ses;
235 char *temp = (char *) buffer; 303 char *temp = (char *) buffer;
236 304
237 memset(temp, 0, 256); /* bigger than MAX_CIFS_HDR_SIZE */ 305 memset(temp, 0, 256); /* bigger than MAX_CIFS_HDR_SIZE */
@@ -260,7 +328,52 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
260 328
261 /* Uid is not converted */ 329 /* Uid is not converted */
262 buffer->Uid = treeCon->ses->Suid; 330 buffer->Uid = treeCon->ses->Suid;
263 buffer->Mid = get_next_mid(treeCon->ses->server); 331 buffer->Mid = GetNextMid(treeCon->ses->server);
332 if (multiuser_mount != 0) {
333 /* For the multiuser case, there are few obvious technically */
334 /* possible mechanisms to match the local linux user (uid) */
335 /* to a valid remote smb user (smb_uid): */
336 /* 1) Query Winbind (or other local pam/nss daemon */
337 /* for userid/password/logon_domain or credential */
338 /* 2) Query Winbind for uid to sid to username mapping */
339 /* and see if we have a matching password for existing*/
340 /* session for that user perhas getting password by */
341 /* adding a new pam_cifs module that stores passwords */
342 /* so that the cifs vfs can get at that for all logged*/
343 /* on users */
344 /* 3) (Which is the mechanism we have chosen) */
345 /* Search through sessions to the same server for a */
346 /* a match on the uid that was passed in on mount */
347 /* with the current processes uid (or euid?) and use */
348 /* that smb uid. If no existing smb session for */
349 /* that uid found, use the default smb session ie */
350 /* the smb session for the volume mounted which is */
351 /* the same as would be used if the multiuser mount */
352 /* flag were disabled. */
353
354 /* BB Add support for establishing new tCon and SMB Session */
355 /* with userid/password pairs found on the smb session */
356 /* for other target tcp/ip addresses BB */
357 if (current_fsuid() != treeCon->ses->linux_uid) {
358 cFYI(1, "Multiuser mode and UID "
359 "did not match tcon uid");
360 spin_lock(&cifs_tcp_ses_lock);
361 list_for_each(temp_item, &treeCon->ses->server->smb_ses_list) {
362 ses = list_entry(temp_item, struct cifs_ses, smb_ses_list);
363 if (ses->linux_uid == current_fsuid()) {
364 if (ses->server == treeCon->ses->server) {
365 cFYI(1, "found matching uid substitute right smb_uid");
366 buffer->Uid = ses->Suid;
367 break;
368 } else {
369 /* BB eventually call cifs_setup_session here */
370 cFYI(1, "local UID found but no smb sess with this server exists");
371 }
372 }
373 }
374 spin_unlock(&cifs_tcp_ses_lock);
375 }
376 }
264 } 377 }
265 if (treeCon->Flags & SMB_SHARE_IS_IN_DFS) 378 if (treeCon->Flags & SMB_SHARE_IS_IN_DFS)
266 buffer->Flags2 |= SMBFLG2_DFS; 379 buffer->Flags2 |= SMBFLG2_DFS;
@@ -307,24 +420,19 @@ check_smb_hdr(struct smb_hdr *smb, __u16 mid)
307} 420}
308 421
309int 422int
310checkSMB(char *buf, unsigned int total_read) 423checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
311{ 424{
312 struct smb_hdr *smb = (struct smb_hdr *)buf; 425 __u32 len = be32_to_cpu(smb->smb_buf_length);
313 __u16 mid = smb->Mid;
314 __u32 rfclen = be32_to_cpu(smb->smb_buf_length);
315 __u32 clc_len; /* calculated length */ 426 __u32 clc_len; /* calculated length */
316 cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", 427 cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len);
317 total_read, rfclen);
318 428
319 /* is this frame too small to even get to a BCC? */ 429 if (length < 2 + sizeof(struct smb_hdr)) {
320 if (total_read < 2 + sizeof(struct smb_hdr)) { 430 if ((length >= sizeof(struct smb_hdr) - 1)
321 if ((total_read >= sizeof(struct smb_hdr) - 1)
322 && (smb->Status.CifsError != 0)) { 431 && (smb->Status.CifsError != 0)) {
323 /* it's an error return */
324 smb->WordCount = 0; 432 smb->WordCount = 0;
325 /* some error cases do not return wct and bcc */ 433 /* some error cases do not return wct and bcc */
326 return 0; 434 return 0;
327 } else if ((total_read == sizeof(struct smb_hdr) + 1) && 435 } else if ((length == sizeof(struct smb_hdr) + 1) &&
328 (smb->WordCount == 0)) { 436 (smb->WordCount == 0)) {
329 char *tmp = (char *)smb; 437 char *tmp = (char *)smb;
330 /* Need to work around a bug in two servers here */ 438 /* Need to work around a bug in two servers here */
@@ -344,35 +452,39 @@ checkSMB(char *buf, unsigned int total_read)
344 } else { 452 } else {
345 cERROR(1, "Length less than smb header size"); 453 cERROR(1, "Length less than smb header size");
346 } 454 }
347 return -EIO; 455 return 1;
456 }
457 if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
458 cERROR(1, "smb length greater than MaxBufSize, mid=%d",
459 smb->Mid);
460 return 1;
348 } 461 }
349 462
350 /* otherwise, there is enough to get to the BCC */
351 if (check_smb_hdr(smb, mid)) 463 if (check_smb_hdr(smb, mid))
352 return -EIO; 464 return 1;
353 clc_len = smbCalcSize(smb); 465 clc_len = smbCalcSize(smb);
354 466
355 if (4 + rfclen != total_read) { 467 if (4 + len != length) {
356 cERROR(1, "Length read does not match RFC1001 length %d", 468 cERROR(1, "Length read does not match RFC1001 length %d",
357 rfclen); 469 len);
358 return -EIO; 470 return 1;
359 } 471 }
360 472
361 if (4 + rfclen != clc_len) { 473 if (4 + len != clc_len) {
362 /* check if bcc wrapped around for large read responses */ 474 /* check if bcc wrapped around for large read responses */
363 if ((rfclen > 64 * 1024) && (rfclen > clc_len)) { 475 if ((len > 64 * 1024) && (len > clc_len)) {
364 /* check if lengths match mod 64K */ 476 /* check if lengths match mod 64K */
365 if (((4 + rfclen) & 0xFFFF) == (clc_len & 0xFFFF)) 477 if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF))
366 return 0; /* bcc wrapped */ 478 return 0; /* bcc wrapped */
367 } 479 }
368 cFYI(1, "Calculated size %u vs length %u mismatch for mid=%u", 480 cFYI(1, "Calculated size %u vs length %u mismatch for mid=%u",
369 clc_len, 4 + rfclen, smb->Mid); 481 clc_len, 4 + len, smb->Mid);
370 482
371 if (4 + rfclen < clc_len) { 483 if (4 + len < clc_len) {
372 cERROR(1, "RFC1001 size %u smaller than SMB for mid=%u", 484 cERROR(1, "RFC1001 size %u smaller than SMB for mid=%u",
373 rfclen, smb->Mid); 485 len, smb->Mid);
374 return -EIO; 486 return 1;
375 } else if (rfclen > clc_len + 512) { 487 } else if (len > clc_len + 512) {
376 /* 488 /*
377 * Some servers (Windows XP in particular) send more 489 * Some servers (Windows XP in particular) send more
378 * data than the lengths in the SMB packet would 490 * data than the lengths in the SMB packet would
@@ -383,17 +495,16 @@ checkSMB(char *buf, unsigned int total_read)
383 * data to 512 bytes. 495 * data to 512 bytes.
384 */ 496 */
385 cERROR(1, "RFC1001 size %u more than 512 bytes larger " 497 cERROR(1, "RFC1001 size %u more than 512 bytes larger "
386 "than SMB for mid=%u", rfclen, smb->Mid); 498 "than SMB for mid=%u", len, smb->Mid);
387 return -EIO; 499 return 1;
388 } 500 }
389 } 501 }
390 return 0; 502 return 0;
391} 503}
392 504
393bool 505bool
394is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) 506is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
395{ 507{
396 struct smb_hdr *buf = (struct smb_hdr *)buffer;
397 struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf; 508 struct smb_com_lock_req *pSMB = (struct smb_com_lock_req *)buf;
398 struct list_head *tmp, *tmp1, *tmp2; 509 struct list_head *tmp, *tmp1, *tmp2;
399 struct cifs_ses *ses; 510 struct cifs_ses *ses;
@@ -461,12 +572,12 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
461 if (tcon->tid != buf->Tid) 572 if (tcon->tid != buf->Tid)
462 continue; 573 continue;
463 574
464 cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks); 575 cifs_stats_inc(&tcon->num_oplock_brks);
465 spin_lock(&cifs_file_list_lock); 576 spin_lock(&cifs_file_list_lock);
466 list_for_each(tmp2, &tcon->openFileList) { 577 list_for_each(tmp2, &tcon->openFileList) {
467 netfile = list_entry(tmp2, struct cifsFileInfo, 578 netfile = list_entry(tmp2, struct cifsFileInfo,
468 tlist); 579 tlist);
469 if (pSMB->Fid != netfile->fid.netfid) 580 if (pSMB->Fid != netfile->netfid)
470 continue; 581 continue;
471 582
472 cFYI(1, "file id match, oplock break"); 583 cFYI(1, "file id match, oplock break");
@@ -474,7 +585,7 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
474 585
475 cifs_set_oplock_level(pCifsInode, 586 cifs_set_oplock_level(pCifsInode,
476 pSMB->OplockLevel ? OPLOCK_READ : 0); 587 pSMB->OplockLevel ? OPLOCK_READ : 0);
477 queue_work(cifsiod_wq, 588 queue_work(system_nrt_wq,
478 &netfile->oplock_break); 589 &netfile->oplock_break);
479 netfile->oplock_break_cancelled = false; 590 netfile->oplock_break_cancelled = false;
480 591
@@ -494,15 +605,16 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)
494} 605}
495 606
496void 607void
497dump_smb(void *buf, int smb_buf_length) 608dump_smb(struct smb_hdr *smb_buf, int smb_buf_length)
498{ 609{
499 int i, j; 610 int i, j;
500 char debug_line[17]; 611 char debug_line[17];
501 unsigned char *buffer = buf; 612 unsigned char *buffer;
502 613
503 if (traceSMB == 0) 614 if (traceSMB == 0)
504 return; 615 return;
505 616
617 buffer = (unsigned char *) smb_buf;
506 for (i = 0, j = 0; i < smb_buf_length; i++, j++) { 618 for (i = 0, j = 0; i < smb_buf_length; i++, j++) {
507 if (i % 8 == 0) { 619 if (i % 8 == 0) {
508 /* have reached the beginning of line */ 620 /* have reached the beginning of line */
@@ -564,48 +676,3 @@ void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock)
564 cinode->clientCanCacheRead = false; 676 cinode->clientCanCacheRead = false;
565 } 677 }
566} 678}
567
568bool
569backup_cred(struct cifs_sb_info *cifs_sb)
570{
571 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID) {
572 if (cifs_sb->mnt_backupuid == current_fsuid())
573 return true;
574 }
575 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID) {
576 if (in_group_p(cifs_sb->mnt_backupgid))
577 return true;
578 }
579
580 return false;
581}
582
583void
584cifs_del_pending_open(struct cifs_pending_open *open)
585{
586 spin_lock(&cifs_file_list_lock);
587 list_del(&open->olist);
588 spin_unlock(&cifs_file_list_lock);
589}
590
591void
592cifs_add_pending_open_locked(struct cifs_fid *fid, struct tcon_link *tlink,
593 struct cifs_pending_open *open)
594{
595#ifdef CONFIG_CIFS_SMB2
596 memcpy(open->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
597#endif
598 open->oplock = CIFS_OPLOCK_NO_CHANGE;
599 open->tlink = tlink;
600 fid->pending_open = open;
601 list_add_tail(&open->olist, &tlink_tcon(tlink)->pending_opens);
602}
603
604void
605cifs_add_pending_open(struct cifs_fid *fid, struct tcon_link *tlink,
606 struct cifs_pending_open *open)
607{
608 spin_lock(&cifs_file_list_lock);
609 cifs_add_pending_open_locked(fid, tlink, open);
610 spin_unlock(&cifs_file_list_lock);
611}
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index a82bc51fdc8..73e47e84b61 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -110,7 +110,7 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
110 {ERRnoroom, -ENOSPC}, 110 {ERRnoroom, -ENOSPC},
111 {ERRrmuns, -EUSERS}, 111 {ERRrmuns, -EUSERS},
112 {ERRtimeout, -ETIME}, 112 {ERRtimeout, -ETIME},
113 {ERRnoresource, -EREMOTEIO}, 113 {ERRnoresource, -ENOBUFS},
114 {ERRtoomanyuids, -EUSERS}, 114 {ERRtoomanyuids, -EUSERS},
115 {ERRbaduid, -EACCES}, 115 {ERRbaduid, -EACCES},
116 {ERRusempx, -EIO}, 116 {ERRusempx, -EIO},
@@ -197,14 +197,15 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
197 memcpy(scope_id, pct + 1, slen); 197 memcpy(scope_id, pct + 1, slen);
198 scope_id[slen] = '\0'; 198 scope_id[slen] = '\0';
199 199
200 rc = kstrtouint(scope_id, 0, &s6->sin6_scope_id); 200 rc = strict_strtoul(scope_id, 0,
201 (unsigned long *)&s6->sin6_scope_id);
201 rc = (rc == 0) ? 1 : 0; 202 rc = (rc == 0) ? 1 : 0;
202 } 203 }
203 204
204 return rc; 205 return rc;
205} 206}
206 207
207void 208int
208cifs_set_port(struct sockaddr *addr, const unsigned short int port) 209cifs_set_port(struct sockaddr *addr, const unsigned short int port)
209{ 210{
210 switch (addr->sa_family) { 211 switch (addr->sa_family) {
@@ -214,7 +215,19 @@ cifs_set_port(struct sockaddr *addr, const unsigned short int port)
214 case AF_INET6: 215 case AF_INET6:
215 ((struct sockaddr_in6 *)addr)->sin6_port = htons(port); 216 ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
216 break; 217 break;
218 default:
219 return 0;
217 } 220 }
221 return 1;
222}
223
224int
225cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
226 const unsigned short int port)
227{
228 if (!cifs_convert_address(dst, src, len))
229 return 0;
230 return cifs_set_port(dst, port);
218} 231}
219 232
220/***************************************************************************** 233/*****************************************************************************
@@ -400,7 +413,7 @@ static const struct {
400 from NT_STATUS_INSUFFICIENT_RESOURCES to 413 from NT_STATUS_INSUFFICIENT_RESOURCES to
401 NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */ 414 NT_STATUS_INSUFF_SERVER_RESOURCES during the session setup } */
402 { 415 {
403 ERRDOS, ERRnoresource, NT_STATUS_INSUFFICIENT_RESOURCES}, { 416 ERRDOS, ERRnomem, NT_STATUS_INSUFFICIENT_RESOURCES}, {
404 ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, { 417 ERRDOS, ERRbadpath, NT_STATUS_DFS_EXIT_PATH_FOUND}, {
405 ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, { 418 ERRDOS, 23, NT_STATUS_DEVICE_DATA_ERROR}, {
406 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, { 419 ERRHRD, ERRgeneral, NT_STATUS_DEVICE_NOT_CONNECTED}, {
@@ -670,7 +683,7 @@ static const struct {
670 ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, { 683 ERRHRD, ERRgeneral, NT_STATUS_NO_USER_SESSION_KEY}, {
671 ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, { 684 ERRDOS, 59, NT_STATUS_USER_SESSION_DELETED}, {
672 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, { 685 ERRHRD, ERRgeneral, NT_STATUS_RESOURCE_LANG_NOT_FOUND}, {
673 ERRDOS, ERRnoresource, NT_STATUS_INSUFF_SERVER_RESOURCES}, { 686 ERRDOS, ERRnomem, NT_STATUS_INSUFF_SERVER_RESOURCES}, {
674 ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, { 687 ERRHRD, ERRgeneral, NT_STATUS_INVALID_BUFFER_SIZE}, {
675 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, { 688 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_COMPONENT}, {
676 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, { 689 ERRHRD, ERRgeneral, NT_STATUS_INVALID_ADDRESS_WILDCARD}, {
@@ -823,9 +836,8 @@ ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
823} 836}
824 837
825int 838int
826map_smb_to_linux_error(char *buf, bool logErr) 839map_smb_to_linux_error(struct smb_hdr *smb, bool logErr)
827{ 840{
828 struct smb_hdr *smb = (struct smb_hdr *)buf;
829 unsigned int i; 841 unsigned int i;
830 int rc = -EIO; /* if transport error smb error may not be set */ 842 int rc = -EIO; /* if transport error smb error may not be set */
831 __u8 smberrclass; 843 __u8 smberrclass;
@@ -901,9 +913,8 @@ map_smb_to_linux_error(char *buf, bool logErr)
901 * portion, the number of word parameters and the data portion of the message 913 * portion, the number of word parameters and the data portion of the message
902 */ 914 */
903unsigned int 915unsigned int
904smbCalcSize(void *buf) 916smbCalcSize(struct smb_hdr *ptr)
905{ 917{
906 struct smb_hdr *ptr = (struct smb_hdr *)buf;
907 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + 918 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
908 2 /* size of the bcc field */ + get_bcc(ptr)); 919 2 /* size of the bcc field */ + get_bcc(ptr));
909} 920}
diff --git a/fs/cifs/nterr.c b/fs/cifs/nterr.c
index b6023c64612..819fd994b12 100644
--- a/fs/cifs/nterr.c
+++ b/fs/cifs/nterr.c
@@ -31,7 +31,7 @@ const struct nt_err_code_struct nt_errs[] = {
31 {"NT_STATUS_INVALID_INFO_CLASS", NT_STATUS_INVALID_INFO_CLASS}, 31 {"NT_STATUS_INVALID_INFO_CLASS", NT_STATUS_INVALID_INFO_CLASS},
32 {"NT_STATUS_INFO_LENGTH_MISMATCH", NT_STATUS_INFO_LENGTH_MISMATCH}, 32 {"NT_STATUS_INFO_LENGTH_MISMATCH", NT_STATUS_INFO_LENGTH_MISMATCH},
33 {"NT_STATUS_ACCESS_VIOLATION", NT_STATUS_ACCESS_VIOLATION}, 33 {"NT_STATUS_ACCESS_VIOLATION", NT_STATUS_ACCESS_VIOLATION},
34 {"NT_STATUS_BUFFER_OVERFLOW", NT_STATUS_BUFFER_OVERFLOW}, 34 {"STATUS_BUFFER_OVERFLOW", STATUS_BUFFER_OVERFLOW},
35 {"NT_STATUS_IN_PAGE_ERROR", NT_STATUS_IN_PAGE_ERROR}, 35 {"NT_STATUS_IN_PAGE_ERROR", NT_STATUS_IN_PAGE_ERROR},
36 {"NT_STATUS_PAGEFILE_QUOTA", NT_STATUS_PAGEFILE_QUOTA}, 36 {"NT_STATUS_PAGEFILE_QUOTA", NT_STATUS_PAGEFILE_QUOTA},
37 {"NT_STATUS_INVALID_HANDLE", NT_STATUS_INVALID_HANDLE}, 37 {"NT_STATUS_INVALID_HANDLE", NT_STATUS_INVALID_HANDLE},
@@ -681,7 +681,7 @@ const struct nt_err_code_struct nt_errs[] = {
681 NT_STATUS_QUOTA_LIST_INCONSISTENT}, 681 NT_STATUS_QUOTA_LIST_INCONSISTENT},
682 {"NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE}, 682 {"NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE},
683 {"NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES}, 683 {"NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES},
684 {"NT_STATUS_MORE_ENTRIES", NT_STATUS_MORE_ENTRIES}, 684 {"STATUS_MORE_ENTRIES", STATUS_MORE_ENTRIES},
685 {"NT_STATUS_SOME_UNMAPPED", NT_STATUS_SOME_UNMAPPED}, 685 {"STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED},
686 {NULL, 0} 686 {NULL, 0}
687}; 687};
diff --git a/fs/cifs/nterr.h b/fs/cifs/nterr.h
index 7a0eae5ae7c..257267367d4 100644
--- a/fs/cifs/nterr.h
+++ b/fs/cifs/nterr.h
@@ -35,20 +35,18 @@ struct nt_err_code_struct {
35extern const struct nt_err_code_struct nt_errs[]; 35extern const struct nt_err_code_struct nt_errs[];
36 36
37/* Win32 Status codes. */ 37/* Win32 Status codes. */
38#define NT_STATUS_MORE_ENTRIES 0x0105 38#define STATUS_MORE_ENTRIES 0x0105
39#define NT_ERROR_INVALID_PARAMETER 0x0057 39#define ERROR_INVALID_PARAMETER 0x0057
40#define NT_ERROR_INSUFFICIENT_BUFFER 0x007a 40#define ERROR_INSUFFICIENT_BUFFER 0x007a
41#define NT_STATUS_1804 0x070c 41#define STATUS_1804 0x070c
42#define NT_STATUS_NOTIFY_ENUM_DIR 0x010c 42#define STATUS_NOTIFY_ENUM_DIR 0x010c
43 43
44/* 44/* Win32 Error codes extracted using a loop in smbclient then printing a
45 * Win32 Error codes extracted using a loop in smbclient then printing a netmon 45 netmon sniff to a file. */
46 * sniff to a file.
47 */
48 46
49#define NT_STATUS_OK 0x0000 47#define NT_STATUS_OK 0x0000
50#define NT_STATUS_SOME_UNMAPPED 0x0107 48#define STATUS_SOME_UNMAPPED 0x0107
51#define NT_STATUS_BUFFER_OVERFLOW 0x80000005 49#define STATUS_BUFFER_OVERFLOW 0x80000005
52#define NT_STATUS_NO_MORE_ENTRIES 0x8000001a 50#define NT_STATUS_NO_MORE_ENTRIES 0x8000001a
53#define NT_STATUS_MEDIA_CHANGED 0x8000001c 51#define NT_STATUS_MEDIA_CHANGED 0x8000001c
54#define NT_STATUS_END_OF_MEDIA 0x8000001e 52#define NT_STATUS_END_OF_MEDIA 0x8000001e
diff --git a/fs/cifs/ntlmssp.h b/fs/cifs/ntlmssp.h
index 848249fa120..5d52e4a3b1e 100644
--- a/fs/cifs/ntlmssp.h
+++ b/fs/cifs/ntlmssp.h
@@ -126,13 +126,3 @@ typedef struct _AUTHENTICATE_MESSAGE {
126 do not set the version is present flag */ 126 do not set the version is present flag */
127 char UserString[0]; 127 char UserString[0];
128} __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE; 128} __attribute__((packed)) AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
129
130/*
131 * Size of the session key (crypto key encrypted with the password
132 */
133
134int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, struct cifs_ses *ses);
135void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, struct cifs_ses *ses);
136int build_ntlmssp_auth_blob(unsigned char *pbuffer, u16 *buflen,
137 struct cifs_ses *ses,
138 const struct nls_table *nls_cp);
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index cdd6ff48246..a090bbe6ee2 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -66,21 +66,18 @@ static inline void dump_cifs_file_struct(struct file *file, char *label)
66#endif /* DEBUG2 */ 66#endif /* DEBUG2 */
67 67
68/* 68/*
69 * Attempt to preload the dcache with the results from the FIND_FIRST/NEXT
70 *
71 * Find the dentry that matches "name". If there isn't one, create one. If it's 69 * Find the dentry that matches "name". If there isn't one, create one. If it's
72 * a negative dentry or the uniqueid changed, then drop it and recreate it. 70 * a negative dentry or the uniqueid changed, then drop it and recreate it.
73 */ 71 */
74static void 72static struct dentry *
75cifs_prime_dcache(struct dentry *parent, struct qstr *name, 73cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
76 struct cifs_fattr *fattr) 74 struct cifs_fattr *fattr)
77{ 75{
78 struct dentry *dentry, *alias; 76 struct dentry *dentry, *alias;
79 struct inode *inode; 77 struct inode *inode;
80 struct super_block *sb = parent->d_inode->i_sb; 78 struct super_block *sb = parent->d_inode->i_sb;
81 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
82 79
83 cFYI(1, "%s: for %s", __func__, name->name); 80 cFYI(1, "For %s", name->name);
84 81
85 if (parent->d_op && parent->d_op->d_hash) 82 if (parent->d_op && parent->d_op->d_hash)
86 parent->d_op->d_hash(parent, parent->d_inode, name); 83 parent->d_op->d_hash(parent, parent->d_inode, name);
@@ -89,43 +86,32 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
89 86
90 dentry = d_lookup(parent, name); 87 dentry = d_lookup(parent, name);
91 if (dentry) { 88 if (dentry) {
92 int err; 89 /* FIXME: check for inode number changes? */
93 90 if (dentry->d_inode != NULL)
94 inode = dentry->d_inode; 91 return dentry;
95 if (inode) { 92 d_drop(dentry);
96 /*
97 * If we're generating inode numbers, then we don't
98 * want to clobber the existing one with the one that
99 * the readdir code created.
100 */
101 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM))
102 fattr->cf_uniqueid = CIFS_I(inode)->uniqueid;
103
104 /* update inode in place if i_ino didn't change */
105 if (CIFS_I(inode)->uniqueid == fattr->cf_uniqueid) {
106 cifs_fattr_to_inode(inode, fattr);
107 goto out;
108 }
109 }
110 err = d_invalidate(dentry);
111 dput(dentry); 93 dput(dentry);
112 if (err)
113 return;
114 } 94 }
115 95
116 dentry = d_alloc(parent, name); 96 dentry = d_alloc(parent, name);
117 if (!dentry) 97 if (dentry == NULL)
118 return; 98 return NULL;
119 99
120 inode = cifs_iget(sb, fattr); 100 inode = cifs_iget(sb, fattr);
121 if (!inode) 101 if (!inode) {
122 goto out; 102 dput(dentry);
103 return NULL;
104 }
123 105
124 alias = d_materialise_unique(dentry, inode); 106 alias = d_materialise_unique(dentry, inode);
125 if (alias && !IS_ERR(alias)) 107 if (alias != NULL) {
126 dput(alias); 108 dput(dentry);
127out: 109 if (IS_ERR(alias))
128 dput(dentry); 110 return NULL;
111 dentry = alias;
112 }
113
114 return dentry;
129} 115}
130 116
131static void 117static void
@@ -145,16 +131,6 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)
145 if (fattr->cf_cifsattrs & ATTR_READONLY) 131 if (fattr->cf_cifsattrs & ATTR_READONLY)
146 fattr->cf_mode &= ~S_IWUGO; 132 fattr->cf_mode &= ~S_IWUGO;
147 133
148 /*
149 * We of course don't get ACL info in FIND_FIRST/NEXT results, so
150 * mark it for revalidation so that "ls -l" will look right. It might
151 * be super-slow, but if we don't do this then the ownership of files
152 * may look wrong since the inodes may not have timed out by the time
153 * "ls" does a stat() call on them.
154 */
155 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
156 fattr->cf_flags |= CIFS_FATTR_NEED_REVAL;
157
158 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL && 134 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL &&
159 fattr->cf_cifsattrs & ATTR_SYSTEM) { 135 fattr->cf_cifsattrs & ATTR_SYSTEM) {
160 if (fattr->cf_eof == 0) { 136 if (fattr->cf_eof == 0) {
@@ -172,7 +148,7 @@ cifs_fill_common_info(struct cifs_fattr *fattr, struct cifs_sb_info *cifs_sb)
172 } 148 }
173} 149}
174 150
175void 151static void
176cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info, 152cifs_dir_info_to_fattr(struct cifs_fattr *fattr, FILE_DIRECTORY_INFO *info,
177 struct cifs_sb_info *cifs_sb) 153 struct cifs_sb_info *cifs_sb)
178{ 154{
@@ -214,7 +190,7 @@ cifs_std_info_to_fattr(struct cifs_fattr *fattr, FIND_FILE_STANDARD_INFO *info,
214 we try to do FindFirst on (NTFS) directory symlinks */ 190 we try to do FindFirst on (NTFS) directory symlinks */
215/* 191/*
216int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb, 192int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
217 unsigned int xid) 193 int xid)
218{ 194{
219 __u16 fid; 195 __u16 fid;
220 int len; 196 int len;
@@ -241,17 +217,14 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
241} 217}
242 */ 218 */
243 219
244static int 220static int initiate_cifs_search(const int xid, struct file *file)
245initiate_cifs_search(const unsigned int xid, struct file *file)
246{ 221{
247 __u16 search_flags;
248 int rc = 0; 222 int rc = 0;
249 char *full_path = NULL; 223 char *full_path = NULL;
250 struct cifsFileInfo *cifsFile; 224 struct cifsFileInfo *cifsFile;
251 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 225 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
252 struct tcon_link *tlink = NULL; 226 struct tcon_link *tlink = NULL;
253 struct cifs_tcon *tcon; 227 struct cifs_tcon *pTcon;
254 struct TCP_Server_Info *server;
255 228
256 if (file->private_data == NULL) { 229 if (file->private_data == NULL) {
257 tlink = cifs_sb_tlink(cifs_sb); 230 tlink = cifs_sb_tlink(cifs_sb);
@@ -265,17 +238,10 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
265 } 238 }
266 file->private_data = cifsFile; 239 file->private_data = cifsFile;
267 cifsFile->tlink = cifs_get_tlink(tlink); 240 cifsFile->tlink = cifs_get_tlink(tlink);
268 tcon = tlink_tcon(tlink); 241 pTcon = tlink_tcon(tlink);
269 } else { 242 } else {
270 cifsFile = file->private_data; 243 cifsFile = file->private_data;
271 tcon = tlink_tcon(cifsFile->tlink); 244 pTcon = tlink_tcon(cifsFile->tlink);
272 }
273
274 server = tcon->ses->server;
275
276 if (!server->ops->query_dir_first) {
277 rc = -ENOSYS;
278 goto error_exit;
279 } 245 }
280 246
281 cifsFile->invalidHandle = true; 247 cifsFile->invalidHandle = true;
@@ -292,11 +258,11 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
292ffirst_retry: 258ffirst_retry:
293 /* test for Unix extensions */ 259 /* test for Unix extensions */
294 /* but now check for them on the share/mount not on the SMB session */ 260 /* but now check for them on the share/mount not on the SMB session */
295 /* if (cap_unix(tcon->ses) { */ 261/* if (pTcon->ses->capabilities & CAP_UNIX) { */
296 if (tcon->unix_ext) 262 if (pTcon->unix_ext)
297 cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX; 263 cifsFile->srch_inf.info_level = SMB_FIND_FILE_UNIX;
298 else if ((tcon->ses->capabilities & 264 else if ((pTcon->ses->capabilities &
299 tcon->ses->server->vals->cap_nt_find) == 0) { 265 (CAP_NT_SMBS | CAP_NT_FIND)) == 0) {
300 cifsFile->srch_inf.info_level = SMB_FIND_FILE_INFO_STANDARD; 266 cifsFile->srch_inf.info_level = SMB_FIND_FILE_INFO_STANDARD;
301 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { 267 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
302 cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO; 268 cifsFile->srch_inf.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
@@ -304,14 +270,10 @@ ffirst_retry:
304 cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO; 270 cifsFile->srch_inf.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
305 } 271 }
306 272
307 search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; 273 rc = CIFSFindFirst(xid, pTcon, full_path, cifs_sb->local_nls,
308 if (backup_cred(cifs_sb)) 274 &cifsFile->netfid, &cifsFile->srch_inf,
309 search_flags |= CIFS_SEARCH_BACKUP_SEARCH; 275 cifs_sb->mnt_cifs_flags &
310 276 CIFS_MOUNT_MAP_SPECIAL_CHR, CIFS_DIR_SEP(cifs_sb));
311 rc = server->ops->query_dir_first(xid, tcon, full_path, cifs_sb,
312 &cifsFile->fid, search_flags,
313 &cifsFile->srch_inf);
314
315 if (rc == 0) 277 if (rc == 0)
316 cifsFile->invalidHandle = false; 278 cifsFile->invalidHandle = false;
317 /* BB add following call to handle readdir on new NTFS symlink errors 279 /* BB add following call to handle readdir on new NTFS symlink errors
@@ -531,67 +493,60 @@ static int cifs_save_resume_key(const char *current_entry,
531 return rc; 493 return rc;
532} 494}
533 495
534/* 496/* find the corresponding entry in the search */
535 * Find the corresponding entry in the search. Note that the SMB server returns 497/* Note that the SMB server returns search entries for . and .. which
536 * search entries for . and .. which complicates logic here if we choose to 498 complicates logic here if we choose to parse for them and we do not
537 * parse for them and we do not assume that they are located in the findfirst 499 assume that they are located in the findfirst return buffer.*/
538 * return buffer. We start counting in the buffer with entry 2 and increment for 500/* We start counting in the buffer with entry 2 and increment for every
539 * every entry (do not increment for . or .. entry). 501 entry (do not increment for . or .. entry) */
540 */ 502static int find_cifs_entry(const int xid, struct cifs_tcon *pTcon,
541static int 503 struct file *file, char **ppCurrentEntry, int *num_to_ret)
542find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon,
543 struct file *file, char **current_entry, int *num_to_ret)
544{ 504{
545 __u16 search_flags;
546 int rc = 0; 505 int rc = 0;
547 int pos_in_buf = 0; 506 int pos_in_buf = 0;
548 loff_t first_entry_in_buffer; 507 loff_t first_entry_in_buffer;
549 loff_t index_to_find = file->f_pos; 508 loff_t index_to_find = file->f_pos;
550 struct cifsFileInfo *cfile = file->private_data; 509 struct cifsFileInfo *cifsFile = file->private_data;
551 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
552 struct TCP_Server_Info *server = tcon->ses->server;
553 /* check if index in the buffer */ 510 /* check if index in the buffer */
554 511
555 if (!server->ops->query_dir_first || !server->ops->query_dir_next) 512 if ((cifsFile == NULL) || (ppCurrentEntry == NULL) ||
556 return -ENOSYS; 513 (num_to_ret == NULL))
557
558 if ((cfile == NULL) || (current_entry == NULL) || (num_to_ret == NULL))
559 return -ENOENT; 514 return -ENOENT;
560 515
561 *current_entry = NULL; 516 *ppCurrentEntry = NULL;
562 first_entry_in_buffer = cfile->srch_inf.index_of_last_entry - 517 first_entry_in_buffer =
563 cfile->srch_inf.entries_in_buffer; 518 cifsFile->srch_inf.index_of_last_entry -
519 cifsFile->srch_inf.entries_in_buffer;
564 520
565 /* 521 /* if first entry in buf is zero then is first buffer
566 * If first entry in buf is zero then is first buffer 522 in search response data which means it is likely . and ..
567 * in search response data which means it is likely . and .. 523 will be in this buffer, although some servers do not return
568 * will be in this buffer, although some servers do not return 524 . and .. for the root of a drive and for those we need
569 * . and .. for the root of a drive and for those we need 525 to start two entries earlier */
570 * to start two entries earlier.
571 */
572 526
573 dump_cifs_file_struct(file, "In fce "); 527 dump_cifs_file_struct(file, "In fce ");
574 if (((index_to_find < cfile->srch_inf.index_of_last_entry) && 528 if (((index_to_find < cifsFile->srch_inf.index_of_last_entry) &&
575 is_dir_changed(file)) || (index_to_find < first_entry_in_buffer)) { 529 is_dir_changed(file)) ||
530 (index_to_find < first_entry_in_buffer)) {
576 /* close and restart search */ 531 /* close and restart search */
577 cFYI(1, "search backing up - close and restart search"); 532 cFYI(1, "search backing up - close and restart search");
578 spin_lock(&cifs_file_list_lock); 533 spin_lock(&cifs_file_list_lock);
579 if (!cfile->srch_inf.endOfSearch && !cfile->invalidHandle) { 534 if (!cifsFile->srch_inf.endOfSearch &&
580 cfile->invalidHandle = true; 535 !cifsFile->invalidHandle) {
536 cifsFile->invalidHandle = true;
581 spin_unlock(&cifs_file_list_lock); 537 spin_unlock(&cifs_file_list_lock);
582 if (server->ops->close) 538 CIFSFindClose(xid, pTcon, cifsFile->netfid);
583 server->ops->close(xid, tcon, &cfile->fid);
584 } else 539 } else
585 spin_unlock(&cifs_file_list_lock); 540 spin_unlock(&cifs_file_list_lock);
586 if (cfile->srch_inf.ntwrk_buf_start) { 541 if (cifsFile->srch_inf.ntwrk_buf_start) {
587 cFYI(1, "freeing SMB ff cache buf on search rewind"); 542 cFYI(1, "freeing SMB ff cache buf on search rewind");
588 if (cfile->srch_inf.smallBuf) 543 if (cifsFile->srch_inf.smallBuf)
589 cifs_small_buf_release(cfile->srch_inf. 544 cifs_small_buf_release(cifsFile->srch_inf.
590 ntwrk_buf_start); 545 ntwrk_buf_start);
591 else 546 else
592 cifs_buf_release(cfile->srch_inf. 547 cifs_buf_release(cifsFile->srch_inf.
593 ntwrk_buf_start); 548 ntwrk_buf_start);
594 cfile->srch_inf.ntwrk_buf_start = NULL; 549 cifsFile->srch_inf.ntwrk_buf_start = NULL;
595 } 550 }
596 rc = initiate_cifs_search(xid, file); 551 rc = initiate_cifs_search(xid, file);
597 if (rc) { 552 if (rc) {
@@ -600,64 +555,61 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon,
600 return rc; 555 return rc;
601 } 556 }
602 /* FindFirst/Next set last_entry to NULL on malformed reply */ 557 /* FindFirst/Next set last_entry to NULL on malformed reply */
603 if (cfile->srch_inf.last_entry) 558 if (cifsFile->srch_inf.last_entry)
604 cifs_save_resume_key(cfile->srch_inf.last_entry, cfile); 559 cifs_save_resume_key(cifsFile->srch_inf.last_entry,
560 cifsFile);
605 } 561 }
606 562
607 search_flags = CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME; 563 while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
608 if (backup_cred(cifs_sb)) 564 (rc == 0) && !cifsFile->srch_inf.endOfSearch) {
609 search_flags |= CIFS_SEARCH_BACKUP_SEARCH;
610
611 while ((index_to_find >= cfile->srch_inf.index_of_last_entry) &&
612 (rc == 0) && !cfile->srch_inf.endOfSearch) {
613 cFYI(1, "calling findnext2"); 565 cFYI(1, "calling findnext2");
614 rc = server->ops->query_dir_next(xid, tcon, &cfile->fid, 566 rc = CIFSFindNext(xid, pTcon, cifsFile->netfid,
615 search_flags, 567 &cifsFile->srch_inf);
616 &cfile->srch_inf);
617 /* FindFirst/Next set last_entry to NULL on malformed reply */ 568 /* FindFirst/Next set last_entry to NULL on malformed reply */
618 if (cfile->srch_inf.last_entry) 569 if (cifsFile->srch_inf.last_entry)
619 cifs_save_resume_key(cfile->srch_inf.last_entry, cfile); 570 cifs_save_resume_key(cifsFile->srch_inf.last_entry,
571 cifsFile);
620 if (rc) 572 if (rc)
621 return -ENOENT; 573 return -ENOENT;
622 } 574 }
623 if (index_to_find < cfile->srch_inf.index_of_last_entry) { 575 if (index_to_find < cifsFile->srch_inf.index_of_last_entry) {
624 /* we found the buffer that contains the entry */ 576 /* we found the buffer that contains the entry */
625 /* scan and find it */ 577 /* scan and find it */
626 int i; 578 int i;
627 char *cur_ent; 579 char *current_entry;
628 char *end_of_smb = cfile->srch_inf.ntwrk_buf_start + 580 char *end_of_smb = cifsFile->srch_inf.ntwrk_buf_start +
629 server->ops->calc_smb_size( 581 smbCalcSize((struct smb_hdr *)
630 cfile->srch_inf.ntwrk_buf_start); 582 cifsFile->srch_inf.ntwrk_buf_start);
631 583
632 cur_ent = cfile->srch_inf.srch_entries_start; 584 current_entry = cifsFile->srch_inf.srch_entries_start;
633 first_entry_in_buffer = cfile->srch_inf.index_of_last_entry 585 first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry
634 - cfile->srch_inf.entries_in_buffer; 586 - cifsFile->srch_inf.entries_in_buffer;
635 pos_in_buf = index_to_find - first_entry_in_buffer; 587 pos_in_buf = index_to_find - first_entry_in_buffer;
636 cFYI(1, "found entry - pos_in_buf %d", pos_in_buf); 588 cFYI(1, "found entry - pos_in_buf %d", pos_in_buf);
637 589
638 for (i = 0; (i < (pos_in_buf)) && (cur_ent != NULL); i++) { 590 for (i = 0; (i < (pos_in_buf)) && (current_entry != NULL); i++) {
639 /* go entry by entry figuring out which is first */ 591 /* go entry by entry figuring out which is first */
640 cur_ent = nxt_dir_entry(cur_ent, end_of_smb, 592 current_entry = nxt_dir_entry(current_entry, end_of_smb,
641 cfile->srch_inf.info_level); 593 cifsFile->srch_inf.info_level);
642 } 594 }
643 if ((cur_ent == NULL) && (i < pos_in_buf)) { 595 if ((current_entry == NULL) && (i < pos_in_buf)) {
644 /* BB fixme - check if we should flag this error */ 596 /* BB fixme - check if we should flag this error */
645 cERROR(1, "reached end of buf searching for pos in buf" 597 cERROR(1, "reached end of buf searching for pos in buf"
646 " %d index to find %lld rc %d", pos_in_buf, 598 " %d index to find %lld rc %d",
647 index_to_find, rc); 599 pos_in_buf, index_to_find, rc);
648 } 600 }
649 rc = 0; 601 rc = 0;
650 *current_entry = cur_ent; 602 *ppCurrentEntry = current_entry;
651 } else { 603 } else {
652 cFYI(1, "index not in buffer - could not findnext into it"); 604 cFYI(1, "index not in buffer - could not findnext into it");
653 return 0; 605 return 0;
654 } 606 }
655 607
656 if (pos_in_buf >= cfile->srch_inf.entries_in_buffer) { 608 if (pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
657 cFYI(1, "can not return entries pos_in_buf beyond last"); 609 cFYI(1, "can not return entries pos_in_buf beyond last");
658 *num_to_ret = 0; 610 *num_to_ret = 0;
659 } else 611 } else
660 *num_to_ret = cfile->srch_inf.entries_in_buffer - pos_in_buf; 612 *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
661 613
662 return rc; 614 return rc;
663} 615}
@@ -670,6 +622,7 @@ static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
670 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 622 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
671 struct cifs_dirent de = { NULL, }; 623 struct cifs_dirent de = { NULL, };
672 struct cifs_fattr fattr; 624 struct cifs_fattr fattr;
625 struct dentry *dentry;
673 struct qstr name; 626 struct qstr name;
674 int rc = 0; 627 int rc = 0;
675 ino_t ino; 628 ino_t ino;
@@ -694,11 +647,10 @@ static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
694 647
695 name.name = scratch_buf; 648 name.name = scratch_buf;
696 name.len = 649 name.len =
697 cifs_from_utf16((char *)name.name, (__le16 *)de.name, 650 cifs_from_ucs2((char *)name.name, (__le16 *)de.name,
698 UNICODE_NAME_MAX, 651 UNICODE_NAME_MAX,
699 min_t(size_t, de.namelen, 652 min(de.namelen, (size_t)max_len), nlt,
700 (size_t)max_len), nlt, 653 cifs_sb->mnt_cifs_flags &
701 cifs_sb->mnt_cifs_flags &
702 CIFS_MOUNT_MAP_SPECIAL_CHR); 654 CIFS_MOUNT_MAP_SPECIAL_CHR);
703 name.len -= nls_nullsize(nlt); 655 name.len -= nls_nullsize(nlt);
704 } else { 656 } else {
@@ -740,11 +692,13 @@ static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
740 */ 692 */
741 fattr.cf_flags |= CIFS_FATTR_NEED_REVAL; 693 fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
742 694
743 cifs_prime_dcache(file->f_dentry, &name, &fattr);
744
745 ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid); 695 ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid);
696 dentry = cifs_readdir_lookup(file->f_dentry, &name, &fattr);
697
746 rc = filldir(dirent, name.name, name.len, file->f_pos, ino, 698 rc = filldir(dirent, name.name, name.len, file->f_pos, ino,
747 fattr.cf_dtype); 699 fattr.cf_dtype);
700
701 dput(dentry);
748 return rc; 702 return rc;
749} 703}
750 704
@@ -752,9 +706,8 @@ static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
752int cifs_readdir(struct file *file, void *direntry, filldir_t filldir) 706int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
753{ 707{
754 int rc = 0; 708 int rc = 0;
755 unsigned int xid; 709 int xid, i;
756 int i; 710 struct cifs_tcon *pTcon;
757 struct cifs_tcon *tcon;
758 struct cifsFileInfo *cifsFile = NULL; 711 struct cifsFileInfo *cifsFile = NULL;
759 char *current_entry; 712 char *current_entry;
760 int num_to_fill = 0; 713 int num_to_fill = 0;
@@ -762,7 +715,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
762 char *end_of_smb; 715 char *end_of_smb;
763 unsigned int max_len; 716 unsigned int max_len;
764 717
765 xid = get_xid(); 718 xid = GetXid();
766 719
767 /* 720 /*
768 * Ensure FindFirst doesn't fail before doing filldir() for '.' and 721 * Ensure FindFirst doesn't fail before doing filldir() for '.' and
@@ -800,7 +753,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
800 753
801 if (file->private_data == NULL) { 754 if (file->private_data == NULL) {
802 rc = -EINVAL; 755 rc = -EINVAL;
803 free_xid(xid); 756 FreeXid(xid);
804 return rc; 757 return rc;
805 } 758 }
806 cifsFile = file->private_data; 759 cifsFile = file->private_data;
@@ -812,12 +765,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
812 } 765 }
813 } /* else { 766 } /* else {
814 cifsFile->invalidHandle = true; 767 cifsFile->invalidHandle = true;
815 tcon->ses->server->close(xid, tcon, &cifsFile->fid); 768 CIFSFindClose(xid, pTcon, cifsFile->netfid);
816 } */ 769 } */
817 770
818 tcon = tlink_tcon(cifsFile->tlink); 771 pTcon = tlink_tcon(cifsFile->tlink);
819 rc = find_cifs_entry(xid, tcon, file, &current_entry, 772 rc = find_cifs_entry(xid, pTcon, file,
820 &num_to_fill); 773 &current_entry, &num_to_fill);
821 if (rc) { 774 if (rc) {
822 cFYI(1, "fce error %d", rc); 775 cFYI(1, "fce error %d", rc);
823 goto rddir2_exit; 776 goto rddir2_exit;
@@ -829,7 +782,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
829 } 782 }
830 cFYI(1, "loop through %d times filling dir for net buf %p", 783 cFYI(1, "loop through %d times filling dir for net buf %p",
831 num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); 784 num_to_fill, cifsFile->srch_inf.ntwrk_buf_start);
832 max_len = tcon->ses->server->ops->calc_smb_size( 785 max_len = smbCalcSize((struct smb_hdr *)
833 cifsFile->srch_inf.ntwrk_buf_start); 786 cifsFile->srch_inf.ntwrk_buf_start);
834 end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; 787 end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
835 788
@@ -846,12 +799,10 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
846 num_to_fill, i); 799 num_to_fill, i);
847 break; 800 break;
848 } 801 }
849 /* 802 /* if buggy server returns . and .. late do
850 * if buggy server returns . and .. late do we want to 803 we want to check for that here? */
851 * check for that here? 804 rc = cifs_filldir(current_entry, file,
852 */ 805 filldir, direntry, tmp_buf, max_len);
853 rc = cifs_filldir(current_entry, file, filldir,
854 direntry, tmp_buf, max_len);
855 if (rc == -EOVERFLOW) { 806 if (rc == -EOVERFLOW) {
856 rc = 0; 807 rc = 0;
857 break; 808 break;
@@ -874,6 +825,6 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
874 } /* end switch */ 825 } /* end switch */
875 826
876rddir2_exit: 827rddir2_exit:
877 free_xid(xid); 828 FreeXid(xid);
878 return rc; 829 return rc;
879} 830}
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index 76809f4d342..d3e619692ee 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -124,9 +124,7 @@ static __u32 cifs_ssetup_hdr(struct cifs_ses *ses, SESSION_SETUP_ANDX *pSMB)
124 /* that we use in next few lines */ 124 /* that we use in next few lines */
125 /* Note that header is initialized to zero in header_assemble */ 125 /* Note that header is initialized to zero in header_assemble */
126 pSMB->req.AndXCommand = 0xFF; 126 pSMB->req.AndXCommand = 0xFF;
127 pSMB->req.MaxBufferSize = cpu_to_le16(min_t(u32, 127 pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
128 CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4,
129 USHRT_MAX));
130 pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq); 128 pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
131 pSMB->req.VcNumber = get_next_vcnum(ses); 129 pSMB->req.VcNumber = get_next_vcnum(ses);
132 130
@@ -167,16 +165,16 @@ unicode_oslm_strings(char **pbcc_area, const struct nls_table *nls_cp)
167 int bytes_ret = 0; 165 int bytes_ret = 0;
168 166
169 /* Copy OS version */ 167 /* Copy OS version */
170 bytes_ret = cifs_strtoUTF16((__le16 *)bcc_ptr, "Linux version ", 32, 168 bytes_ret = cifs_strtoUCS((__le16 *)bcc_ptr, "Linux version ", 32,
171 nls_cp); 169 nls_cp);
172 bcc_ptr += 2 * bytes_ret; 170 bcc_ptr += 2 * bytes_ret;
173 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, init_utsname()->release, 171 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, init_utsname()->release,
174 32, nls_cp); 172 32, nls_cp);
175 bcc_ptr += 2 * bytes_ret; 173 bcc_ptr += 2 * bytes_ret;
176 bcc_ptr += 2; /* trailing null */ 174 bcc_ptr += 2; /* trailing null */
177 175
178 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS, 176 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS,
179 32, nls_cp); 177 32, nls_cp);
180 bcc_ptr += 2 * bytes_ret; 178 bcc_ptr += 2 * bytes_ret;
181 bcc_ptr += 2; /* trailing null */ 179 bcc_ptr += 2; /* trailing null */
182 180
@@ -197,8 +195,8 @@ static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses,
197 *(bcc_ptr+1) = 0; 195 *(bcc_ptr+1) = 0;
198 bytes_ret = 0; 196 bytes_ret = 0;
199 } else 197 } else
200 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->domainName, 198 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->domainName,
201 256, nls_cp); 199 256, nls_cp);
202 bcc_ptr += 2 * bytes_ret; 200 bcc_ptr += 2 * bytes_ret;
203 bcc_ptr += 2; /* account for null terminator */ 201 bcc_ptr += 2; /* account for null terminator */
204 202
@@ -226,8 +224,8 @@ static void unicode_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
226 *bcc_ptr = 0; 224 *bcc_ptr = 0;
227 *(bcc_ptr+1) = 0; 225 *(bcc_ptr+1) = 0;
228 } else { 226 } else {
229 bytes_ret = cifs_strtoUTF16((__le16 *) bcc_ptr, ses->user_name, 227 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->user_name,
230 MAX_USERNAME_SIZE, nls_cp); 228 MAX_USERNAME_SIZE, nls_cp);
231 } 229 }
232 bcc_ptr += 2 * bytes_ret; 230 bcc_ptr += 2 * bytes_ret;
233 bcc_ptr += 2; /* account for null termination */ 231 bcc_ptr += 2; /* account for null termination */
@@ -246,15 +244,16 @@ static void ascii_ssetup_strings(char **pbcc_area, struct cifs_ses *ses,
246 /* copy user */ 244 /* copy user */
247 /* BB what about null user mounts - check that we do this BB */ 245 /* BB what about null user mounts - check that we do this BB */
248 /* copy user */ 246 /* copy user */
249 if (ses->user_name != NULL) { 247 if (ses->user_name != NULL)
250 strncpy(bcc_ptr, ses->user_name, MAX_USERNAME_SIZE); 248 strncpy(bcc_ptr, ses->user_name, MAX_USERNAME_SIZE);
251 bcc_ptr += strnlen(ses->user_name, MAX_USERNAME_SIZE);
252 }
253 /* else null user mount */ 249 /* else null user mount */
250
251 bcc_ptr += strnlen(ses->user_name, MAX_USERNAME_SIZE);
254 *bcc_ptr = 0; 252 *bcc_ptr = 0;
255 bcc_ptr++; /* account for null termination */ 253 bcc_ptr++; /* account for null termination */
256 254
257 /* copy domain */ 255 /* copy domain */
256
258 if (ses->domainName != NULL) { 257 if (ses->domainName != NULL) {
259 strncpy(bcc_ptr, ses->domainName, 256); 258 strncpy(bcc_ptr, ses->domainName, 256);
260 bcc_ptr += strnlen(ses->domainName, 256); 259 bcc_ptr += strnlen(ses->domainName, 256);
@@ -286,7 +285,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifs_ses *ses,
286 cFYI(1, "bleft %d", bleft); 285 cFYI(1, "bleft %d", bleft);
287 286
288 kfree(ses->serverOS); 287 kfree(ses->serverOS);
289 ses->serverOS = cifs_strndup_from_utf16(data, bleft, true, nls_cp); 288 ses->serverOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
290 cFYI(1, "serverOS=%s", ses->serverOS); 289 cFYI(1, "serverOS=%s", ses->serverOS);
291 len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; 290 len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2;
292 data += len; 291 data += len;
@@ -295,7 +294,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifs_ses *ses,
295 return; 294 return;
296 295
297 kfree(ses->serverNOS); 296 kfree(ses->serverNOS);
298 ses->serverNOS = cifs_strndup_from_utf16(data, bleft, true, nls_cp); 297 ses->serverNOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
299 cFYI(1, "serverNOS=%s", ses->serverNOS); 298 cFYI(1, "serverNOS=%s", ses->serverNOS);
300 len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2; 299 len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2;
301 data += len; 300 data += len;
@@ -304,7 +303,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifs_ses *ses,
304 return; 303 return;
305 304
306 kfree(ses->serverDomain); 305 kfree(ses->serverDomain);
307 ses->serverDomain = cifs_strndup_from_utf16(data, bleft, true, nls_cp); 306 ses->serverDomain = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
308 cFYI(1, "serverDomain=%s", ses->serverDomain); 307 cFYI(1, "serverDomain=%s", ses->serverDomain);
309 308
310 return; 309 return;
@@ -364,7 +363,7 @@ static int decode_ascii_ssetup(char **pbcc_area, __u16 bleft,
364 return rc; 363 return rc;
365} 364}
366 365
367int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, 366static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
368 struct cifs_ses *ses) 367 struct cifs_ses *ses)
369{ 368{
370 unsigned int tioffset; /* challenge message target info area */ 369 unsigned int tioffset; /* challenge message target info area */
@@ -394,10 +393,6 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
394 ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags); 393 ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
395 tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset); 394 tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
396 tilen = le16_to_cpu(pblob->TargetInfoArray.Length); 395 tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
397 if (tioffset > blob_len || tioffset + tilen > blob_len) {
398 cERROR(1, "tioffset + tilen too high %u + %u", tioffset, tilen);
399 return -EINVAL;
400 }
401 if (tilen) { 396 if (tilen) {
402 ses->auth_key.response = kmalloc(tilen, GFP_KERNEL); 397 ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
403 if (!ses->auth_key.response) { 398 if (!ses->auth_key.response) {
@@ -415,7 +410,7 @@ int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
415 410
416/* We do not malloc the blob, it is passed in pbuffer, because 411/* We do not malloc the blob, it is passed in pbuffer, because
417 it is fixed size, and small, making this approach cleaner */ 412 it is fixed size, and small, making this approach cleaner */
418void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, 413static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
419 struct cifs_ses *ses) 414 struct cifs_ses *ses)
420{ 415{
421 NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer; 416 NEGOTIATE_MESSAGE *sec_blob = (NEGOTIATE_MESSAGE *)pbuffer;
@@ -451,7 +446,7 @@ void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
451/* We do not malloc the blob, it is passed in pbuffer, because its 446/* We do not malloc the blob, it is passed in pbuffer, because its
452 maximum possible size is fixed and small, making this approach cleaner. 447 maximum possible size is fixed and small, making this approach cleaner.
453 This function returns the length of the data in the blob */ 448 This function returns the length of the data in the blob */
454int build_ntlmssp_auth_blob(unsigned char *pbuffer, 449static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
455 u16 *buflen, 450 u16 *buflen,
456 struct cifs_ses *ses, 451 struct cifs_ses *ses,
457 const struct nls_table *nls_cp) 452 const struct nls_table *nls_cp)
@@ -505,8 +500,8 @@ int build_ntlmssp_auth_blob(unsigned char *pbuffer,
505 tmp += 2; 500 tmp += 2;
506 } else { 501 } else {
507 int len; 502 int len;
508 len = cifs_strtoUTF16((__le16 *)tmp, ses->domainName, 503 len = cifs_strtoUCS((__le16 *)tmp, ses->domainName,
509 MAX_USERNAME_SIZE, nls_cp); 504 MAX_USERNAME_SIZE, nls_cp);
510 len *= 2; /* unicode is 2 bytes each */ 505 len *= 2; /* unicode is 2 bytes each */
511 sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer); 506 sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer);
512 sec_blob->DomainName.Length = cpu_to_le16(len); 507 sec_blob->DomainName.Length = cpu_to_le16(len);
@@ -521,8 +516,8 @@ int build_ntlmssp_auth_blob(unsigned char *pbuffer,
521 tmp += 2; 516 tmp += 2;
522 } else { 517 } else {
523 int len; 518 int len;
524 len = cifs_strtoUTF16((__le16 *)tmp, ses->user_name, 519 len = cifs_strtoUCS((__le16 *)tmp, ses->user_name,
525 MAX_USERNAME_SIZE, nls_cp); 520 MAX_USERNAME_SIZE, nls_cp);
526 len *= 2; /* unicode is 2 bytes each */ 521 len *= 2; /* unicode is 2 bytes each */
527 sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); 522 sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer);
528 sec_blob->UserName.Length = cpu_to_le16(len); 523 sec_blob->UserName.Length = cpu_to_le16(len);
@@ -556,7 +551,7 @@ setup_ntlmv2_ret:
556} 551}
557 552
558int 553int
559CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, 554CIFS_SessSetup(unsigned int xid, struct cifs_ses *ses,
560 const struct nls_table *nls_cp) 555 const struct nls_table *nls_cp)
561{ 556{
562 int rc = 0; 557 int rc = 0;
@@ -686,7 +681,7 @@ ssetup_ntlmssp_authenticate:
686 cpu_to_le16(CIFS_AUTH_RESP_SIZE); 681 cpu_to_le16(CIFS_AUTH_RESP_SIZE);
687 682
688 /* calculate ntlm response and session key */ 683 /* calculate ntlm response and session key */
689 rc = setup_ntlm_response(ses, nls_cp); 684 rc = setup_ntlm_response(ses);
690 if (rc) { 685 if (rc) {
691 cERROR(1, "Error %d during NTLM authentication", rc); 686 cERROR(1, "Error %d during NTLM authentication", rc);
692 goto ssetup_exit; 687 goto ssetup_exit;
@@ -876,8 +871,7 @@ ssetup_ntlmssp_authenticate:
876 pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; 871 pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base;
877 smb_buf = (struct smb_hdr *)iov[0].iov_base; 872 smb_buf = (struct smb_hdr *)iov[0].iov_base;
878 873
879 if ((type == RawNTLMSSP) && (resp_buf_type != CIFS_NO_BUFFER) && 874 if ((type == RawNTLMSSP) && (smb_buf->Status.CifsError ==
880 (smb_buf->Status.CifsError ==
881 cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) { 875 cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) {
882 if (phase != NtLmNegotiate) { 876 if (phase != NtLmNegotiate) {
883 cERROR(1, "Unexpected more processing error"); 877 cERROR(1, "Unexpected more processing error");
@@ -899,7 +893,7 @@ ssetup_ntlmssp_authenticate:
899 if (action & GUEST_LOGIN) 893 if (action & GUEST_LOGIN)
900 cFYI(1, "Guest login"); /* BB mark SesInfo struct? */ 894 cFYI(1, "Guest login"); /* BB mark SesInfo struct? */
901 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */ 895 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
902 cFYI(1, "UID = %llu ", ses->Suid); 896 cFYI(1, "UID = %d ", ses->Suid);
903 /* response can have either 3 or 4 word count - Samba sends 3 */ 897 /* response can have either 3 or 4 word count - Samba sends 3 */
904 /* and lanman response is 3 */ 898 /* and lanman response is 3 */
905 bytes_remaining = get_bcc(smb_buf); 899 bytes_remaining = get_bcc(smb_buf);
@@ -939,7 +933,7 @@ ssetup_ntlmssp_authenticate:
939 933
940ssetup_exit: 934ssetup_exit:
941 if (spnego_key) { 935 if (spnego_key) {
942 key_invalidate(spnego_key); 936 key_revoke(spnego_key);
943 key_put(spnego_key); 937 key_put(spnego_key);
944 } 938 }
945 kfree(str_area); 939 kfree(str_area);
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
deleted file mode 100644
index 47bc5a87f94..00000000000
--- a/fs/cifs/smb1ops.c
+++ /dev/null
@@ -1,963 +0,0 @@
1/*
2 * SMB1 (CIFS) version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/pagemap.h>
21#include <linux/vfs.h>
22#include "cifsglob.h"
23#include "cifsproto.h"
24#include "cifs_debug.h"
25#include "cifspdu.h"
26
27/*
28 * An NT cancel request header looks just like the original request except:
29 *
30 * The Command is SMB_COM_NT_CANCEL
31 * The WordCount is zeroed out
32 * The ByteCount is zeroed out
33 *
34 * This function mangles an existing request buffer into a
35 * SMB_COM_NT_CANCEL request and then sends it.
36 */
37static int
38send_nt_cancel(struct TCP_Server_Info *server, void *buf,
39 struct mid_q_entry *mid)
40{
41 int rc = 0;
42 struct smb_hdr *in_buf = (struct smb_hdr *)buf;
43
44 /* -4 for RFC1001 length and +2 for BCC field */
45 in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2);
46 in_buf->Command = SMB_COM_NT_CANCEL;
47 in_buf->WordCount = 0;
48 put_bcc(0, in_buf);
49
50 mutex_lock(&server->srv_mutex);
51 rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
52 if (rc) {
53 mutex_unlock(&server->srv_mutex);
54 return rc;
55 }
56
57 /*
58 * The response to this call was already factored into the sequence
59 * number when the call went out, so we must adjust it back downward
60 * after signing here.
61 */
62 --server->sequence_number;
63 rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
64 mutex_unlock(&server->srv_mutex);
65
66 cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
67 in_buf->Mid, rc);
68
69 return rc;
70}
71
72static bool
73cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
74{
75 return ob1->fid.netfid == ob2->fid.netfid;
76}
77
78static unsigned int
79cifs_read_data_offset(char *buf)
80{
81 READ_RSP *rsp = (READ_RSP *)buf;
82 return le16_to_cpu(rsp->DataOffset);
83}
84
85static unsigned int
86cifs_read_data_length(char *buf)
87{
88 READ_RSP *rsp = (READ_RSP *)buf;
89 return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
90 le16_to_cpu(rsp->DataLength);
91}
92
93static struct mid_q_entry *
94cifs_find_mid(struct TCP_Server_Info *server, char *buffer)
95{
96 struct smb_hdr *buf = (struct smb_hdr *)buffer;
97 struct mid_q_entry *mid;
98
99 spin_lock(&GlobalMid_Lock);
100 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
101 if (mid->mid == buf->Mid &&
102 mid->mid_state == MID_REQUEST_SUBMITTED &&
103 le16_to_cpu(mid->command) == buf->Command) {
104 spin_unlock(&GlobalMid_Lock);
105 return mid;
106 }
107 }
108 spin_unlock(&GlobalMid_Lock);
109 return NULL;
110}
111
112static void
113cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add,
114 const int optype)
115{
116 spin_lock(&server->req_lock);
117 server->credits += add;
118 server->in_flight--;
119 spin_unlock(&server->req_lock);
120 wake_up(&server->request_q);
121}
122
123static void
124cifs_set_credits(struct TCP_Server_Info *server, const int val)
125{
126 spin_lock(&server->req_lock);
127 server->credits = val;
128 server->oplocks = val > 1 ? enable_oplocks : false;
129 spin_unlock(&server->req_lock);
130}
131
132static int *
133cifs_get_credits_field(struct TCP_Server_Info *server, const int optype)
134{
135 return &server->credits;
136}
137
138static unsigned int
139cifs_get_credits(struct mid_q_entry *mid)
140{
141 return 1;
142}
143
144/*
145 * Find a free multiplex id (SMB mid). Otherwise there could be
146 * mid collisions which might cause problems, demultiplexing the
147 * wrong response to this request. Multiplex ids could collide if
148 * one of a series requests takes much longer than the others, or
149 * if a very large number of long lived requests (byte range
150 * locks or FindNotify requests) are pending. No more than
151 * 64K-1 requests can be outstanding at one time. If no
152 * mids are available, return zero. A future optimization
153 * could make the combination of mids and uid the key we use
154 * to demultiplex on (rather than mid alone).
155 * In addition to the above check, the cifs demultiplex
156 * code already used the command code as a secondary
157 * check of the frame and if signing is negotiated the
158 * response would be discarded if the mid were the same
159 * but the signature was wrong. Since the mid is not put in the
160 * pending queue until later (when it is about to be dispatched)
161 * we do have to limit the number of outstanding requests
162 * to somewhat less than 64K-1 although it is hard to imagine
163 * so many threads being in the vfs at one time.
164 */
165static __u64
166cifs_get_next_mid(struct TCP_Server_Info *server)
167{
168 __u64 mid = 0;
169 __u16 last_mid, cur_mid;
170 bool collision;
171
172 spin_lock(&GlobalMid_Lock);
173
174 /* mid is 16 bit only for CIFS/SMB */
175 cur_mid = (__u16)((server->CurrentMid) & 0xffff);
176 /* we do not want to loop forever */
177 last_mid = cur_mid;
178 cur_mid++;
179
180 /*
181 * This nested loop looks more expensive than it is.
182 * In practice the list of pending requests is short,
183 * fewer than 50, and the mids are likely to be unique
184 * on the first pass through the loop unless some request
185 * takes longer than the 64 thousand requests before it
186 * (and it would also have to have been a request that
187 * did not time out).
188 */
189 while (cur_mid != last_mid) {
190 struct mid_q_entry *mid_entry;
191 unsigned int num_mids;
192
193 collision = false;
194 if (cur_mid == 0)
195 cur_mid++;
196
197 num_mids = 0;
198 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
199 ++num_mids;
200 if (mid_entry->mid == cur_mid &&
201 mid_entry->mid_state == MID_REQUEST_SUBMITTED) {
202 /* This mid is in use, try a different one */
203 collision = true;
204 break;
205 }
206 }
207
208 /*
209 * if we have more than 32k mids in the list, then something
210 * is very wrong. Possibly a local user is trying to DoS the
211 * box by issuing long-running calls and SIGKILL'ing them. If
212 * we get to 2^16 mids then we're in big trouble as this
213 * function could loop forever.
214 *
215 * Go ahead and assign out the mid in this situation, but force
216 * an eventual reconnect to clean out the pending_mid_q.
217 */
218 if (num_mids > 32768)
219 server->tcpStatus = CifsNeedReconnect;
220
221 if (!collision) {
222 mid = (__u64)cur_mid;
223 server->CurrentMid = mid;
224 break;
225 }
226 cur_mid++;
227 }
228 spin_unlock(&GlobalMid_Lock);
229 return mid;
230}
231
232/*
233 return codes:
234 0 not a transact2, or all data present
235 >0 transact2 with that much data missing
236 -EINVAL invalid transact2
237 */
238static int
239check2ndT2(char *buf)
240{
241 struct smb_hdr *pSMB = (struct smb_hdr *)buf;
242 struct smb_t2_rsp *pSMBt;
243 int remaining;
244 __u16 total_data_size, data_in_this_rsp;
245
246 if (pSMB->Command != SMB_COM_TRANSACTION2)
247 return 0;
248
249 /* check for plausible wct, bcc and t2 data and parm sizes */
250 /* check for parm and data offset going beyond end of smb */
251 if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */
252 cFYI(1, "invalid transact2 word count");
253 return -EINVAL;
254 }
255
256 pSMBt = (struct smb_t2_rsp *)pSMB;
257
258 total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
259 data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
260
261 if (total_data_size == data_in_this_rsp)
262 return 0;
263 else if (total_data_size < data_in_this_rsp) {
264 cFYI(1, "total data %d smaller than data in frame %d",
265 total_data_size, data_in_this_rsp);
266 return -EINVAL;
267 }
268
269 remaining = total_data_size - data_in_this_rsp;
270
271 cFYI(1, "missing %d bytes from transact2, check next response",
272 remaining);
273 if (total_data_size > CIFSMaxBufSize) {
274 cERROR(1, "TotalDataSize %d is over maximum buffer %d",
275 total_data_size, CIFSMaxBufSize);
276 return -EINVAL;
277 }
278 return remaining;
279}
280
281static int
282coalesce_t2(char *second_buf, struct smb_hdr *target_hdr)
283{
284 struct smb_t2_rsp *pSMBs = (struct smb_t2_rsp *)second_buf;
285 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)target_hdr;
286 char *data_area_of_tgt;
287 char *data_area_of_src;
288 int remaining;
289 unsigned int byte_count, total_in_tgt;
290 __u16 tgt_total_cnt, src_total_cnt, total_in_src;
291
292 src_total_cnt = get_unaligned_le16(&pSMBs->t2_rsp.TotalDataCount);
293 tgt_total_cnt = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
294
295 if (tgt_total_cnt != src_total_cnt)
296 cFYI(1, "total data count of primary and secondary t2 differ "
297 "source=%hu target=%hu", src_total_cnt, tgt_total_cnt);
298
299 total_in_tgt = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
300
301 remaining = tgt_total_cnt - total_in_tgt;
302
303 if (remaining < 0) {
304 cFYI(1, "Server sent too much data. tgt_total_cnt=%hu "
305 "total_in_tgt=%hu", tgt_total_cnt, total_in_tgt);
306 return -EPROTO;
307 }
308
309 if (remaining == 0) {
310 /* nothing to do, ignore */
311 cFYI(1, "no more data remains");
312 return 0;
313 }
314
315 total_in_src = get_unaligned_le16(&pSMBs->t2_rsp.DataCount);
316 if (remaining < total_in_src)
317 cFYI(1, "transact2 2nd response contains too much data");
318
319 /* find end of first SMB data area */
320 data_area_of_tgt = (char *)&pSMBt->hdr.Protocol +
321 get_unaligned_le16(&pSMBt->t2_rsp.DataOffset);
322
323 /* validate target area */
324 data_area_of_src = (char *)&pSMBs->hdr.Protocol +
325 get_unaligned_le16(&pSMBs->t2_rsp.DataOffset);
326
327 data_area_of_tgt += total_in_tgt;
328
329 total_in_tgt += total_in_src;
330 /* is the result too big for the field? */
331 if (total_in_tgt > USHRT_MAX) {
332 cFYI(1, "coalesced DataCount too large (%u)", total_in_tgt);
333 return -EPROTO;
334 }
335 put_unaligned_le16(total_in_tgt, &pSMBt->t2_rsp.DataCount);
336
337 /* fix up the BCC */
338 byte_count = get_bcc(target_hdr);
339 byte_count += total_in_src;
340 /* is the result too big for the field? */
341 if (byte_count > USHRT_MAX) {
342 cFYI(1, "coalesced BCC too large (%u)", byte_count);
343 return -EPROTO;
344 }
345 put_bcc(byte_count, target_hdr);
346
347 byte_count = be32_to_cpu(target_hdr->smb_buf_length);
348 byte_count += total_in_src;
349 /* don't allow buffer to overflow */
350 if (byte_count > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
351 cFYI(1, "coalesced BCC exceeds buffer size (%u)", byte_count);
352 return -ENOBUFS;
353 }
354 target_hdr->smb_buf_length = cpu_to_be32(byte_count);
355
356 /* copy second buffer into end of first buffer */
357 memcpy(data_area_of_tgt, data_area_of_src, total_in_src);
358
359 if (remaining != total_in_src) {
360 /* more responses to go */
361 cFYI(1, "waiting for more secondary responses");
362 return 1;
363 }
364
365 /* we are done */
366 cFYI(1, "found the last secondary response");
367 return 0;
368}
369
370static bool
371cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server,
372 char *buf, int malformed)
373{
374 if (malformed)
375 return false;
376 if (check2ndT2(buf) <= 0)
377 return false;
378 mid->multiRsp = true;
379 if (mid->resp_buf) {
380 /* merge response - fix up 1st*/
381 malformed = coalesce_t2(buf, mid->resp_buf);
382 if (malformed > 0)
383 return true;
384 /* All parts received or packet is malformed. */
385 mid->multiEnd = true;
386 dequeue_mid(mid, malformed);
387 return true;
388 }
389 if (!server->large_buf) {
390 /*FIXME: switch to already allocated largebuf?*/
391 cERROR(1, "1st trans2 resp needs bigbuf");
392 } else {
393 /* Have first buffer */
394 mid->resp_buf = buf;
395 mid->large_buf = true;
396 server->bigbuf = NULL;
397 }
398 return true;
399}
400
401static bool
402cifs_need_neg(struct TCP_Server_Info *server)
403{
404 return server->maxBuf == 0;
405}
406
407static int
408cifs_negotiate(const unsigned int xid, struct cifs_ses *ses)
409{
410 int rc;
411 rc = CIFSSMBNegotiate(xid, ses);
412 if (rc == -EAGAIN) {
413 /* retry only once on 1st time connection */
414 set_credits(ses->server, 1);
415 rc = CIFSSMBNegotiate(xid, ses);
416 if (rc == -EAGAIN)
417 rc = -EHOSTDOWN;
418 }
419 return rc;
420}
421
422static unsigned int
423cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
424{
425 __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
426 struct TCP_Server_Info *server = tcon->ses->server;
427 unsigned int wsize;
428
429 /* start with specified wsize, or default */
430 if (volume_info->wsize)
431 wsize = volume_info->wsize;
432 else if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
433 wsize = CIFS_DEFAULT_IOSIZE;
434 else
435 wsize = CIFS_DEFAULT_NON_POSIX_WSIZE;
436
437 /* can server support 24-bit write sizes? (via UNIX extensions) */
438 if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
439 wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE);
440
441 /*
442 * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set?
443 * Limit it to max buffer offered by the server, minus the size of the
444 * WRITEX header, not including the 4 byte RFC1001 length.
445 */
446 if (!(server->capabilities & CAP_LARGE_WRITE_X) ||
447 (!(server->capabilities & CAP_UNIX) &&
448 (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED))))
449 wsize = min_t(unsigned int, wsize,
450 server->maxBuf - sizeof(WRITE_REQ) + 4);
451
452 /* hard limit of CIFS_MAX_WSIZE */
453 wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
454
455 return wsize;
456}
457
458static unsigned int
459cifs_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
460{
461 __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
462 struct TCP_Server_Info *server = tcon->ses->server;
463 unsigned int rsize, defsize;
464
465 /*
466 * Set default value...
467 *
468 * HACK alert! Ancient servers have very small buffers. Even though
469 * MS-CIFS indicates that servers are only limited by the client's
470 * bufsize for reads, testing against win98se shows that it throws
471 * INVALID_PARAMETER errors if you try to request too large a read.
472 * OS/2 just sends back short reads.
473 *
474 * If the server doesn't advertise CAP_LARGE_READ_X, then assume that
475 * it can't handle a read request larger than its MaxBufferSize either.
476 */
477 if (tcon->unix_ext && (unix_cap & CIFS_UNIX_LARGE_READ_CAP))
478 defsize = CIFS_DEFAULT_IOSIZE;
479 else if (server->capabilities & CAP_LARGE_READ_X)
480 defsize = CIFS_DEFAULT_NON_POSIX_RSIZE;
481 else
482 defsize = server->maxBuf - sizeof(READ_RSP);
483
484 rsize = volume_info->rsize ? volume_info->rsize : defsize;
485
486 /*
487 * no CAP_LARGE_READ_X? Then MS-CIFS states that we must limit this to
488 * the client's MaxBufferSize.
489 */
490 if (!(server->capabilities & CAP_LARGE_READ_X))
491 rsize = min_t(unsigned int, CIFSMaxBufSize, rsize);
492
493 /* hard limit of CIFS_MAX_RSIZE */
494 rsize = min_t(unsigned int, rsize, CIFS_MAX_RSIZE);
495
496 return rsize;
497}
498
499static void
500cifs_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
501{
502 CIFSSMBQFSDeviceInfo(xid, tcon);
503 CIFSSMBQFSAttributeInfo(xid, tcon);
504}
505
506static int
507cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
508 struct cifs_sb_info *cifs_sb, const char *full_path)
509{
510 int rc;
511 FILE_ALL_INFO *file_info;
512
513 file_info = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
514 if (file_info == NULL)
515 return -ENOMEM;
516
517 rc = CIFSSMBQPathInfo(xid, tcon, full_path, file_info,
518 0 /* not legacy */, cifs_sb->local_nls,
519 cifs_sb->mnt_cifs_flags &
520 CIFS_MOUNT_MAP_SPECIAL_CHR);
521
522 if (rc == -EOPNOTSUPP || rc == -EINVAL)
523 rc = SMBQueryInformation(xid, tcon, full_path, file_info,
524 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
525 CIFS_MOUNT_MAP_SPECIAL_CHR);
526 kfree(file_info);
527 return rc;
528}
529
530static int
531cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
532 struct cifs_sb_info *cifs_sb, const char *full_path,
533 FILE_ALL_INFO *data, bool *adjustTZ)
534{
535 int rc;
536
537 /* could do find first instead but this returns more info */
538 rc = CIFSSMBQPathInfo(xid, tcon, full_path, data, 0 /* not legacy */,
539 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
540 CIFS_MOUNT_MAP_SPECIAL_CHR);
541 /*
542 * BB optimize code so we do not make the above call when server claims
543 * no NT SMB support and the above call failed at least once - set flag
544 * in tcon or mount.
545 */
546 if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
547 rc = SMBQueryInformation(xid, tcon, full_path, data,
548 cifs_sb->local_nls,
549 cifs_sb->mnt_cifs_flags &
550 CIFS_MOUNT_MAP_SPECIAL_CHR);
551 *adjustTZ = true;
552 }
553 return rc;
554}
555
556static int
557cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
558 struct cifs_sb_info *cifs_sb, const char *full_path,
559 u64 *uniqueid, FILE_ALL_INFO *data)
560{
561 /*
562 * We can not use the IndexNumber field by default from Windows or
563 * Samba (in ALL_INFO buf) but we can request it explicitly. The SNIA
564 * CIFS spec claims that this value is unique within the scope of a
565 * share, and the windows docs hint that it's actually unique
566 * per-machine.
567 *
568 * There may be higher info levels that work but are there Windows
569 * server or network appliances for which IndexNumber field is not
570 * guaranteed unique?
571 */
572 return CIFSGetSrvInodeNumber(xid, tcon, full_path, uniqueid,
573 cifs_sb->local_nls,
574 cifs_sb->mnt_cifs_flags &
575 CIFS_MOUNT_MAP_SPECIAL_CHR);
576}
577
578static int
579cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
580 struct cifs_fid *fid, FILE_ALL_INFO *data)
581{
582 return CIFSSMBQFileInfo(xid, tcon, fid->netfid, data);
583}
584
585static void
586cifs_clear_stats(struct cifs_tcon *tcon)
587{
588#ifdef CONFIG_CIFS_STATS
589 atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
590 atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
591 atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
592 atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
593 atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
594 atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
595 atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
596 atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
597 atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
598 atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
599 atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
600 atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
601 atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
602 atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
603 atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
604 atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
605 atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
606 atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
607 atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
608 atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
609 atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
610#endif
611}
612
613static void
614cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
615{
616#ifdef CONFIG_CIFS_STATS
617 seq_printf(m, " Oplocks breaks: %d",
618 atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
619 seq_printf(m, "\nReads: %d Bytes: %llu",
620 atomic_read(&tcon->stats.cifs_stats.num_reads),
621 (long long)(tcon->bytes_read));
622 seq_printf(m, "\nWrites: %d Bytes: %llu",
623 atomic_read(&tcon->stats.cifs_stats.num_writes),
624 (long long)(tcon->bytes_written));
625 seq_printf(m, "\nFlushes: %d",
626 atomic_read(&tcon->stats.cifs_stats.num_flushes));
627 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
628 atomic_read(&tcon->stats.cifs_stats.num_locks),
629 atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
630 atomic_read(&tcon->stats.cifs_stats.num_symlinks));
631 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
632 atomic_read(&tcon->stats.cifs_stats.num_opens),
633 atomic_read(&tcon->stats.cifs_stats.num_closes),
634 atomic_read(&tcon->stats.cifs_stats.num_deletes));
635 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
636 atomic_read(&tcon->stats.cifs_stats.num_posixopens),
637 atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
638 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
639 atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
640 atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
641 seq_printf(m, "\nRenames: %d T2 Renames %d",
642 atomic_read(&tcon->stats.cifs_stats.num_renames),
643 atomic_read(&tcon->stats.cifs_stats.num_t2renames));
644 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
645 atomic_read(&tcon->stats.cifs_stats.num_ffirst),
646 atomic_read(&tcon->stats.cifs_stats.num_fnext),
647 atomic_read(&tcon->stats.cifs_stats.num_fclose));
648#endif
649}
650
651static void
652cifs_mkdir_setinfo(struct inode *inode, const char *full_path,
653 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
654 const unsigned int xid)
655{
656 FILE_BASIC_INFO info;
657 struct cifsInodeInfo *cifsInode;
658 u32 dosattrs;
659 int rc;
660
661 memset(&info, 0, sizeof(info));
662 cifsInode = CIFS_I(inode);
663 dosattrs = cifsInode->cifsAttrs|ATTR_READONLY;
664 info.Attributes = cpu_to_le32(dosattrs);
665 rc = CIFSSMBSetPathInfo(xid, tcon, full_path, &info, cifs_sb->local_nls,
666 cifs_sb->mnt_cifs_flags &
667 CIFS_MOUNT_MAP_SPECIAL_CHR);
668 if (rc == 0)
669 cifsInode->cifsAttrs = dosattrs;
670}
671
672static int
673cifs_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path,
674 int disposition, int desired_access, int create_options,
675 struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf,
676 struct cifs_sb_info *cifs_sb)
677{
678 if (!(tcon->ses->capabilities & CAP_NT_SMBS))
679 return SMBLegacyOpen(xid, tcon, path, disposition,
680 desired_access, create_options,
681 &fid->netfid, oplock, buf,
682 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
683 & CIFS_MOUNT_MAP_SPECIAL_CHR);
684 return CIFSSMBOpen(xid, tcon, path, disposition, desired_access,
685 create_options, &fid->netfid, oplock, buf,
686 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
687 CIFS_MOUNT_MAP_SPECIAL_CHR);
688}
689
690static void
691cifs_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
692{
693 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
694 cfile->fid.netfid = fid->netfid;
695 cifs_set_oplock_level(cinode, oplock);
696 cinode->can_cache_brlcks = cinode->clientCanCacheAll;
697}
698
699static void
700cifs_close_file(const unsigned int xid, struct cifs_tcon *tcon,
701 struct cifs_fid *fid)
702{
703 CIFSSMBClose(xid, tcon, fid->netfid);
704}
705
706static int
707cifs_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
708 struct cifs_fid *fid)
709{
710 return CIFSSMBFlush(xid, tcon, fid->netfid);
711}
712
713static int
714cifs_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
715 struct cifs_io_parms *parms, unsigned int *bytes_read,
716 char **buf, int *buf_type)
717{
718 parms->netfid = cfile->fid.netfid;
719 return CIFSSMBRead(xid, parms, bytes_read, buf, buf_type);
720}
721
722static int
723cifs_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
724 struct cifs_io_parms *parms, unsigned int *written,
725 struct kvec *iov, unsigned long nr_segs)
726{
727
728 parms->netfid = cfile->fid.netfid;
729 return CIFSSMBWrite2(xid, parms, written, iov, nr_segs);
730}
731
732static int
733smb_set_file_info(struct inode *inode, const char *full_path,
734 FILE_BASIC_INFO *buf, const unsigned int xid)
735{
736 int oplock = 0;
737 int rc;
738 __u16 netfid;
739 __u32 netpid;
740 struct cifsFileInfo *open_file;
741 struct cifsInodeInfo *cinode = CIFS_I(inode);
742 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
743 struct tcon_link *tlink = NULL;
744 struct cifs_tcon *tcon;
745
746 /* if the file is already open for write, just use that fileid */
747 open_file = find_writable_file(cinode, true);
748 if (open_file) {
749 netfid = open_file->fid.netfid;
750 netpid = open_file->pid;
751 tcon = tlink_tcon(open_file->tlink);
752 goto set_via_filehandle;
753 }
754
755 tlink = cifs_sb_tlink(cifs_sb);
756 if (IS_ERR(tlink)) {
757 rc = PTR_ERR(tlink);
758 tlink = NULL;
759 goto out;
760 }
761 tcon = tlink_tcon(tlink);
762
763 /*
764 * NT4 apparently returns success on this call, but it doesn't really
765 * work.
766 */
767 if (!(tcon->ses->flags & CIFS_SES_NT4)) {
768 rc = CIFSSMBSetPathInfo(xid, tcon, full_path, buf,
769 cifs_sb->local_nls,
770 cifs_sb->mnt_cifs_flags &
771 CIFS_MOUNT_MAP_SPECIAL_CHR);
772 if (rc == 0) {
773 cinode->cifsAttrs = le32_to_cpu(buf->Attributes);
774 goto out;
775 } else if (rc != -EOPNOTSUPP && rc != -EINVAL)
776 goto out;
777 }
778
779 cFYI(1, "calling SetFileInfo since SetPathInfo for times not supported "
780 "by this server");
781 rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN,
782 SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR,
783 &netfid, &oplock, NULL, cifs_sb->local_nls,
784 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
785
786 if (rc != 0) {
787 if (rc == -EIO)
788 rc = -EINVAL;
789 goto out;
790 }
791
792 netpid = current->tgid;
793
794set_via_filehandle:
795 rc = CIFSSMBSetFileInfo(xid, tcon, buf, netfid, netpid);
796 if (!rc)
797 cinode->cifsAttrs = le32_to_cpu(buf->Attributes);
798
799 if (open_file == NULL)
800 CIFSSMBClose(xid, tcon, netfid);
801 else
802 cifsFileInfo_put(open_file);
803out:
804 if (tlink != NULL)
805 cifs_put_tlink(tlink);
806 return rc;
807}
808
809static int
810cifs_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
811 const char *path, struct cifs_sb_info *cifs_sb,
812 struct cifs_fid *fid, __u16 search_flags,
813 struct cifs_search_info *srch_inf)
814{
815 return CIFSFindFirst(xid, tcon, path, cifs_sb,
816 &fid->netfid, search_flags, srch_inf, true);
817}
818
819static int
820cifs_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
821 struct cifs_fid *fid, __u16 search_flags,
822 struct cifs_search_info *srch_inf)
823{
824 return CIFSFindNext(xid, tcon, fid->netfid, search_flags, srch_inf);
825}
826
827static int
828cifs_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
829 struct cifs_fid *fid)
830{
831 return CIFSFindClose(xid, tcon, fid->netfid);
832}
833
834static int
835cifs_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
836 struct cifsInodeInfo *cinode)
837{
838 return CIFSSMBLock(0, tcon, fid->netfid, current->tgid, 0, 0, 0, 0,
839 LOCKING_ANDX_OPLOCK_RELEASE, false,
840 cinode->clientCanCacheRead ? 1 : 0);
841}
842
843static int
844cifs_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
845 struct kstatfs *buf)
846{
847 int rc = -EOPNOTSUPP;
848
849 buf->f_type = CIFS_MAGIC_NUMBER;
850
851 /*
852 * We could add a second check for a QFS Unix capability bit
853 */
854 if ((tcon->ses->capabilities & CAP_UNIX) &&
855 (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
856 rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
857
858 /*
859 * Only need to call the old QFSInfo if failed on newer one,
860 * e.g. by OS/2.
861 **/
862 if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
863 rc = CIFSSMBQFSInfo(xid, tcon, buf);
864
865 /*
866 * Some old Windows servers also do not support level 103, retry with
867 * older level one if old server failed the previous call or we
868 * bypassed it because we detected that this was an older LANMAN sess
869 */
870 if (rc)
871 rc = SMBOldQFSInfo(xid, tcon, buf);
872 return rc;
873}
874
875static int
876cifs_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
877 __u64 length, __u32 type, int lock, int unlock, bool wait)
878{
879 return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->fid.netfid,
880 current->tgid, length, offset, unlock, lock,
881 (__u8)type, wait, 0);
882}
883
884struct smb_version_operations smb1_operations = {
885 .send_cancel = send_nt_cancel,
886 .compare_fids = cifs_compare_fids,
887 .setup_request = cifs_setup_request,
888 .setup_async_request = cifs_setup_async_request,
889 .check_receive = cifs_check_receive,
890 .add_credits = cifs_add_credits,
891 .set_credits = cifs_set_credits,
892 .get_credits_field = cifs_get_credits_field,
893 .get_credits = cifs_get_credits,
894 .get_next_mid = cifs_get_next_mid,
895 .read_data_offset = cifs_read_data_offset,
896 .read_data_length = cifs_read_data_length,
897 .map_error = map_smb_to_linux_error,
898 .find_mid = cifs_find_mid,
899 .check_message = checkSMB,
900 .dump_detail = cifs_dump_detail,
901 .clear_stats = cifs_clear_stats,
902 .print_stats = cifs_print_stats,
903 .is_oplock_break = is_valid_oplock_break,
904 .check_trans2 = cifs_check_trans2,
905 .need_neg = cifs_need_neg,
906 .negotiate = cifs_negotiate,
907 .negotiate_wsize = cifs_negotiate_wsize,
908 .negotiate_rsize = cifs_negotiate_rsize,
909 .sess_setup = CIFS_SessSetup,
910 .logoff = CIFSSMBLogoff,
911 .tree_connect = CIFSTCon,
912 .tree_disconnect = CIFSSMBTDis,
913 .get_dfs_refer = CIFSGetDFSRefer,
914 .qfs_tcon = cifs_qfs_tcon,
915 .is_path_accessible = cifs_is_path_accessible,
916 .query_path_info = cifs_query_path_info,
917 .query_file_info = cifs_query_file_info,
918 .get_srv_inum = cifs_get_srv_inum,
919 .set_path_size = CIFSSMBSetEOF,
920 .set_file_size = CIFSSMBSetFileSize,
921 .set_file_info = smb_set_file_info,
922 .echo = CIFSSMBEcho,
923 .mkdir = CIFSSMBMkDir,
924 .mkdir_setinfo = cifs_mkdir_setinfo,
925 .rmdir = CIFSSMBRmDir,
926 .unlink = CIFSSMBDelFile,
927 .rename_pending_delete = cifs_rename_pending_delete,
928 .rename = CIFSSMBRename,
929 .create_hardlink = CIFSCreateHardLink,
930 .open = cifs_open_file,
931 .set_fid = cifs_set_fid,
932 .close = cifs_close_file,
933 .flush = cifs_flush_file,
934 .async_readv = cifs_async_readv,
935 .async_writev = cifs_async_writev,
936 .sync_read = cifs_sync_read,
937 .sync_write = cifs_sync_write,
938 .query_dir_first = cifs_query_dir_first,
939 .query_dir_next = cifs_query_dir_next,
940 .close_dir = cifs_close_dir,
941 .calc_smb_size = smbCalcSize,
942 .oplock_response = cifs_oplock_response,
943 .queryfs = cifs_queryfs,
944 .mand_lock = cifs_mand_lock,
945 .mand_unlock_range = cifs_unlock_range,
946 .push_mand_locks = cifs_push_mandatory_locks,
947};
948
949struct smb_version_values smb1_values = {
950 .version_string = SMB1_VERSION_STRING,
951 .large_lock_type = LOCKING_ANDX_LARGE_FILES,
952 .exclusive_lock_type = 0,
953 .shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
954 .unlock_lock_type = 0,
955 .header_size = sizeof(struct smb_hdr),
956 .max_header_size = MAX_CIFS_HDR_SIZE,
957 .read_rsp_size = sizeof(READ_RSP),
958 .lock_cmd = cpu_to_le16(SMB_COM_LOCKING_ANDX),
959 .cap_unix = CAP_UNIX,
960 .cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND,
961 .cap_large_files = CAP_LARGE_FILES,
962 .oplock_read = OPLOCK_READ,
963};
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c
deleted file mode 100644
index 71e6aed4b38..00000000000
--- a/fs/cifs/smb2file.c
+++ /dev/null
@@ -1,290 +0,0 @@
1/*
2 * fs/cifs/smb2file.c
3 *
4 * Copyright (C) International Business Machines Corp., 2002, 2011
5 * Author(s): Steve French (sfrench@us.ibm.com),
6 * Pavel Shilovsky ((pshilovsky@samba.org) 2012
7 *
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 * the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <linux/fs.h>
23#include <linux/stat.h>
24#include <linux/slab.h>
25#include <linux/pagemap.h>
26#include <asm/div64.h>
27#include "cifsfs.h"
28#include "cifspdu.h"
29#include "cifsglob.h"
30#include "cifsproto.h"
31#include "cifs_debug.h"
32#include "cifs_fs_sb.h"
33#include "cifs_unicode.h"
34#include "fscache.h"
35#include "smb2proto.h"
36
37void
38smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock)
39{
40 oplock &= 0xFF;
41 if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
42 return;
43 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
44 cinode->clientCanCacheAll = true;
45 cinode->clientCanCacheRead = true;
46 cFYI(1, "Exclusive Oplock granted on inode %p",
47 &cinode->vfs_inode);
48 } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
49 cinode->clientCanCacheAll = false;
50 cinode->clientCanCacheRead = true;
51 cFYI(1, "Level II Oplock granted on inode %p",
52 &cinode->vfs_inode);
53 } else {
54 cinode->clientCanCacheAll = false;
55 cinode->clientCanCacheRead = false;
56 }
57}
58
59int
60smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path,
61 int disposition, int desired_access, int create_options,
62 struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf,
63 struct cifs_sb_info *cifs_sb)
64{
65 int rc;
66 __le16 *smb2_path;
67 struct smb2_file_all_info *smb2_data = NULL;
68 __u8 smb2_oplock[17];
69
70 smb2_path = cifs_convert_path_to_utf16(path, cifs_sb);
71 if (smb2_path == NULL) {
72 rc = -ENOMEM;
73 goto out;
74 }
75
76 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
77 GFP_KERNEL);
78 if (smb2_data == NULL) {
79 rc = -ENOMEM;
80 goto out;
81 }
82
83 desired_access |= FILE_READ_ATTRIBUTES;
84 *smb2_oplock = SMB2_OPLOCK_LEVEL_EXCLUSIVE;
85
86 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
87 memcpy(smb2_oplock + 1, fid->lease_key, SMB2_LEASE_KEY_SIZE);
88
89 rc = SMB2_open(xid, tcon, smb2_path, &fid->persistent_fid,
90 &fid->volatile_fid, desired_access, disposition,
91 0, 0, smb2_oplock, smb2_data);
92 if (rc)
93 goto out;
94
95 if (buf) {
96 /* open response does not have IndexNumber field - get it */
97 rc = SMB2_get_srv_num(xid, tcon, fid->persistent_fid,
98 fid->volatile_fid,
99 &smb2_data->IndexNumber);
100 if (rc) {
101 /* let get_inode_info disable server inode numbers */
102 smb2_data->IndexNumber = 0;
103 rc = 0;
104 }
105 move_smb2_info_to_cifs(buf, smb2_data);
106 }
107
108 *oplock = *smb2_oplock;
109out:
110 kfree(smb2_data);
111 kfree(smb2_path);
112 return rc;
113}
114
115int
116smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
117 const unsigned int xid)
118{
119 int rc = 0, stored_rc;
120 unsigned int max_num, num = 0, max_buf;
121 struct smb2_lock_element *buf, *cur;
122 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
123 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
124 struct cifsLockInfo *li, *tmp;
125 __u64 length = 1 + flock->fl_end - flock->fl_start;
126 struct list_head tmp_llist;
127
128 INIT_LIST_HEAD(&tmp_llist);
129
130 /*
131 * Accessing maxBuf is racy with cifs_reconnect - need to store value
132 * and check it for zero before using.
133 */
134 max_buf = tcon->ses->server->maxBuf;
135 if (!max_buf)
136 return -EINVAL;
137
138 max_num = max_buf / sizeof(struct smb2_lock_element);
139 buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL);
140 if (!buf)
141 return -ENOMEM;
142
143 cur = buf;
144
145 down_write(&cinode->lock_sem);
146 list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) {
147 if (flock->fl_start > li->offset ||
148 (flock->fl_start + length) <
149 (li->offset + li->length))
150 continue;
151 if (current->tgid != li->pid)
152 continue;
153 if (cinode->can_cache_brlcks) {
154 /*
155 * We can cache brlock requests - simply remove a lock
156 * from the file's list.
157 */
158 list_del(&li->llist);
159 cifs_del_lock_waiters(li);
160 kfree(li);
161 continue;
162 }
163 cur->Length = cpu_to_le64(li->length);
164 cur->Offset = cpu_to_le64(li->offset);
165 cur->Flags = cpu_to_le32(SMB2_LOCKFLAG_UNLOCK);
166 /*
167 * We need to save a lock here to let us add it again to the
168 * file's list if the unlock range request fails on the server.
169 */
170 list_move(&li->llist, &tmp_llist);
171 if (++num == max_num) {
172 stored_rc = smb2_lockv(xid, tcon,
173 cfile->fid.persistent_fid,
174 cfile->fid.volatile_fid,
175 current->tgid, num, buf);
176 if (stored_rc) {
177 /*
178 * We failed on the unlock range request - add
179 * all locks from the tmp list to the head of
180 * the file's list.
181 */
182 cifs_move_llist(&tmp_llist,
183 &cfile->llist->locks);
184 rc = stored_rc;
185 } else
186 /*
187 * The unlock range request succeed - free the
188 * tmp list.
189 */
190 cifs_free_llist(&tmp_llist);
191 cur = buf;
192 num = 0;
193 } else
194 cur++;
195 }
196 if (num) {
197 stored_rc = smb2_lockv(xid, tcon, cfile->fid.persistent_fid,
198 cfile->fid.volatile_fid, current->tgid,
199 num, buf);
200 if (stored_rc) {
201 cifs_move_llist(&tmp_llist, &cfile->llist->locks);
202 rc = stored_rc;
203 } else
204 cifs_free_llist(&tmp_llist);
205 }
206 up_write(&cinode->lock_sem);
207
208 kfree(buf);
209 return rc;
210}
211
212static int
213smb2_push_mand_fdlocks(struct cifs_fid_locks *fdlocks, const unsigned int xid,
214 struct smb2_lock_element *buf, unsigned int max_num)
215{
216 int rc = 0, stored_rc;
217 struct cifsFileInfo *cfile = fdlocks->cfile;
218 struct cifsLockInfo *li;
219 unsigned int num = 0;
220 struct smb2_lock_element *cur = buf;
221 struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
222
223 list_for_each_entry(li, &fdlocks->locks, llist) {
224 cur->Length = cpu_to_le64(li->length);
225 cur->Offset = cpu_to_le64(li->offset);
226 cur->Flags = cpu_to_le32(li->type |
227 SMB2_LOCKFLAG_FAIL_IMMEDIATELY);
228 if (++num == max_num) {
229 stored_rc = smb2_lockv(xid, tcon,
230 cfile->fid.persistent_fid,
231 cfile->fid.volatile_fid,
232 current->tgid, num, buf);
233 if (stored_rc)
234 rc = stored_rc;
235 cur = buf;
236 num = 0;
237 } else
238 cur++;
239 }
240 if (num) {
241 stored_rc = smb2_lockv(xid, tcon,
242 cfile->fid.persistent_fid,
243 cfile->fid.volatile_fid,
244 current->tgid, num, buf);
245 if (stored_rc)
246 rc = stored_rc;
247 }
248
249 return rc;
250}
251
252int
253smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
254{
255 int rc = 0, stored_rc;
256 unsigned int xid;
257 unsigned int max_num, max_buf;
258 struct smb2_lock_element *buf;
259 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
260 struct cifs_fid_locks *fdlocks;
261
262 xid = get_xid();
263
264 /*
265 * Accessing maxBuf is racy with cifs_reconnect - need to store value
266 * and check it for zero before using.
267 */
268 max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf;
269 if (!max_buf) {
270 free_xid(xid);
271 return -EINVAL;
272 }
273
274 max_num = max_buf / sizeof(struct smb2_lock_element);
275 buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL);
276 if (!buf) {
277 free_xid(xid);
278 return -ENOMEM;
279 }
280
281 list_for_each_entry(fdlocks, &cinode->llist, llist) {
282 stored_rc = smb2_push_mand_fdlocks(fdlocks, xid, buf, max_num);
283 if (stored_rc)
284 rc = stored_rc;
285 }
286
287 kfree(buf);
288 free_xid(xid);
289 return rc;
290}
diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h
deleted file mode 100644
index 7c0e2143e77..00000000000
--- a/fs/cifs/smb2glob.h
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * fs/cifs/smb2glob.h
3 *
4 * Definitions for various global variables and structures
5 *
6 * Copyright (C) International Business Machines Corp., 2002, 2011
7 * Etersoft, 2012
8 * Author(s): Steve French (sfrench@us.ibm.com)
9 * Jeremy Allison (jra@samba.org)
10 * Pavel Shilovsky (pshilovsky@samba.org) 2012
11 *
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published
14 * by the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
20 * the GNU Lesser General Public License for more details.
21 *
22 */
23#ifndef _SMB2_GLOB_H
24#define _SMB2_GLOB_H
25
26#define SMB2_MAGIC_NUMBER 0xFE534D42
27
28/*
29 *****************************************************************
30 * Constants go here
31 *****************************************************************
32 */
33
34/*
35 * Identifiers for functions that use the open, operation, close pattern
36 * in smb2inode.c:smb2_open_op_close()
37 */
38#define SMB2_OP_SET_DELETE 1
39#define SMB2_OP_SET_INFO 2
40#define SMB2_OP_QUERY_INFO 3
41#define SMB2_OP_QUERY_DIR 4
42#define SMB2_OP_MKDIR 5
43#define SMB2_OP_RENAME 6
44#define SMB2_OP_DELETE 7
45#define SMB2_OP_HARDLINK 8
46#define SMB2_OP_SET_EOF 9
47
48/* Used when constructing chained read requests. */
49#define CHAINED_REQUEST 1
50#define START_OF_CHAIN 2
51#define END_OF_CHAIN 4
52#define RELATED_REQUEST 8
53
54#define SMB2_SIGNATURE_SIZE (16)
55#define SMB2_NTLMV2_SESSKEY_SIZE (16)
56#define SMB2_HMACSHA256_SIZE (32)
57
58#endif /* _SMB2_GLOB_H */
diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
deleted file mode 100644
index 706482452df..00000000000
--- a/fs/cifs/smb2inode.c
+++ /dev/null
@@ -1,257 +0,0 @@
1/*
2 * fs/cifs/smb2inode.c
3 *
4 * Copyright (C) International Business Machines Corp., 2002, 2011
5 * Etersoft, 2012
6 * Author(s): Pavel Shilovsky (pshilovsky@samba.org),
7 * Steve French (sfrench@us.ibm.com)
8 *
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23#include <linux/fs.h>
24#include <linux/stat.h>
25#include <linux/slab.h>
26#include <linux/pagemap.h>
27#include <asm/div64.h>
28#include "cifsfs.h"
29#include "cifspdu.h"
30#include "cifsglob.h"
31#include "cifsproto.h"
32#include "cifs_debug.h"
33#include "cifs_fs_sb.h"
34#include "cifs_unicode.h"
35#include "fscache.h"
36#include "smb2glob.h"
37#include "smb2pdu.h"
38#include "smb2proto.h"
39
40static int
41smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
42 struct cifs_sb_info *cifs_sb, const char *full_path,
43 __u32 desired_access, __u32 create_disposition,
44 __u32 file_attributes, __u32 create_options,
45 void *data, int command)
46{
47 int rc, tmprc = 0;
48 u64 persistent_fid, volatile_fid;
49 __le16 *utf16_path;
50 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
51
52 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
53 if (!utf16_path)
54 return -ENOMEM;
55
56 rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
57 desired_access, create_disposition, file_attributes,
58 create_options, &oplock, NULL);
59 if (rc) {
60 kfree(utf16_path);
61 return rc;
62 }
63
64 switch (command) {
65 case SMB2_OP_DELETE:
66 break;
67 case SMB2_OP_QUERY_INFO:
68 tmprc = SMB2_query_info(xid, tcon, persistent_fid,
69 volatile_fid,
70 (struct smb2_file_all_info *)data);
71 break;
72 case SMB2_OP_MKDIR:
73 /*
74 * Directories are created through parameters in the
75 * SMB2_open() call.
76 */
77 break;
78 case SMB2_OP_RENAME:
79 tmprc = SMB2_rename(xid, tcon, persistent_fid, volatile_fid,
80 (__le16 *)data);
81 break;
82 case SMB2_OP_HARDLINK:
83 tmprc = SMB2_set_hardlink(xid, tcon, persistent_fid,
84 volatile_fid, (__le16 *)data);
85 break;
86 case SMB2_OP_SET_EOF:
87 tmprc = SMB2_set_eof(xid, tcon, persistent_fid, volatile_fid,
88 current->tgid, (__le64 *)data);
89 break;
90 case SMB2_OP_SET_INFO:
91 tmprc = SMB2_set_info(xid, tcon, persistent_fid, volatile_fid,
92 (FILE_BASIC_INFO *)data);
93 break;
94 default:
95 cERROR(1, "Invalid command");
96 break;
97 }
98
99 rc = SMB2_close(xid, tcon, persistent_fid, volatile_fid);
100 if (tmprc)
101 rc = tmprc;
102 kfree(utf16_path);
103 return rc;
104}
105
106void
107move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src)
108{
109 memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src);
110 dst->CurrentByteOffset = src->CurrentByteOffset;
111 dst->Mode = src->Mode;
112 dst->AlignmentRequirement = src->AlignmentRequirement;
113 dst->IndexNumber1 = 0; /* we don't use it */
114}
115
116int
117smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
118 struct cifs_sb_info *cifs_sb, const char *full_path,
119 FILE_ALL_INFO *data, bool *adjust_tz)
120{
121 int rc;
122 struct smb2_file_all_info *smb2_data;
123
124 *adjust_tz = false;
125
126 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
127 GFP_KERNEL);
128 if (smb2_data == NULL)
129 return -ENOMEM;
130
131 rc = smb2_open_op_close(xid, tcon, cifs_sb, full_path,
132 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0,
133 smb2_data, SMB2_OP_QUERY_INFO);
134 if (rc)
135 goto out;
136
137 move_smb2_info_to_cifs(data, smb2_data);
138out:
139 kfree(smb2_data);
140 return rc;
141}
142
143int
144smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
145 struct cifs_sb_info *cifs_sb)
146{
147 return smb2_open_op_close(xid, tcon, cifs_sb, name,
148 FILE_WRITE_ATTRIBUTES, FILE_CREATE, 0,
149 CREATE_NOT_FILE, NULL, SMB2_OP_MKDIR);
150}
151
152void
153smb2_mkdir_setinfo(struct inode *inode, const char *name,
154 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
155 const unsigned int xid)
156{
157 FILE_BASIC_INFO data;
158 struct cifsInodeInfo *cifs_i;
159 u32 dosattrs;
160 int tmprc;
161
162 memset(&data, 0, sizeof(data));
163 cifs_i = CIFS_I(inode);
164 dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
165 data.Attributes = cpu_to_le32(dosattrs);
166 tmprc = smb2_open_op_close(xid, tcon, cifs_sb, name,
167 FILE_WRITE_ATTRIBUTES, FILE_CREATE, 0,
168 CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO);
169 if (tmprc == 0)
170 cifs_i->cifsAttrs = dosattrs;
171}
172
173int
174smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
175 struct cifs_sb_info *cifs_sb)
176{
177 return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
178 0, CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE,
179 NULL, SMB2_OP_DELETE);
180}
181
182int
183smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
184 struct cifs_sb_info *cifs_sb)
185{
186 return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
187 0, CREATE_DELETE_ON_CLOSE, NULL,
188 SMB2_OP_DELETE);
189}
190
191static int
192smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
193 const char *from_name, const char *to_name,
194 struct cifs_sb_info *cifs_sb, __u32 access, int command)
195{
196 __le16 *smb2_to_name = NULL;
197 int rc;
198
199 smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
200 if (smb2_to_name == NULL) {
201 rc = -ENOMEM;
202 goto smb2_rename_path;
203 }
204
205 rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access,
206 FILE_OPEN, 0, 0, smb2_to_name, command);
207smb2_rename_path:
208 kfree(smb2_to_name);
209 return rc;
210}
211
212int
213smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
214 const char *from_name, const char *to_name,
215 struct cifs_sb_info *cifs_sb)
216{
217 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
218 DELETE, SMB2_OP_RENAME);
219}
220
221int
222smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
223 const char *from_name, const char *to_name,
224 struct cifs_sb_info *cifs_sb)
225{
226 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
227 FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK);
228}
229
230int
231smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
232 const char *full_path, __u64 size,
233 struct cifs_sb_info *cifs_sb, bool set_alloc)
234{
235 __le64 eof = cpu_to_le64(size);
236 return smb2_open_op_close(xid, tcon, cifs_sb, full_path,
237 FILE_WRITE_DATA, FILE_OPEN, 0, 0, &eof,
238 SMB2_OP_SET_EOF);
239}
240
241int
242smb2_set_file_info(struct inode *inode, const char *full_path,
243 FILE_BASIC_INFO *buf, const unsigned int xid)
244{
245 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
246 struct tcon_link *tlink;
247 int rc;
248
249 tlink = cifs_sb_tlink(cifs_sb);
250 if (IS_ERR(tlink))
251 return PTR_ERR(tlink);
252 rc = smb2_open_op_close(xid, tlink_tcon(tlink), cifs_sb, full_path,
253 FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, 0, buf,
254 SMB2_OP_SET_INFO);
255 cifs_put_tlink(tlink);
256 return rc;
257}
diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c
deleted file mode 100644
index 494c912c76f..00000000000
--- a/fs/cifs/smb2maperror.c
+++ /dev/null
@@ -1,2479 +0,0 @@
1/*
2 * fs/smb2/smb2maperror.c
3 *
4 * Functions which do error mapping of SMB2 status codes to POSIX errors
5 *
6 * Copyright (C) International Business Machines Corp., 2009
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/errno.h>
24#include "cifsglob.h"
25#include "cifs_debug.h"
26#include "smb2pdu.h"
27#include "smb2proto.h"
28#include "smb2status.h"
29
30struct status_to_posix_error {
31 __le32 smb2_status;
32 int posix_error;
33 char *status_string;
34};
35
36static const struct status_to_posix_error smb2_error_map_table[] = {
37 {STATUS_SUCCESS, 0, "STATUS_SUCCESS"},
38 {STATUS_WAIT_0, 0, "STATUS_WAIT_0"},
39 {STATUS_WAIT_1, -EIO, "STATUS_WAIT_1"},
40 {STATUS_WAIT_2, -EIO, "STATUS_WAIT_2"},
41 {STATUS_WAIT_3, -EIO, "STATUS_WAIT_3"},
42 {STATUS_WAIT_63, -EIO, "STATUS_WAIT_63"},
43 {STATUS_ABANDONED, -EIO, "STATUS_ABANDONED"},
44 {STATUS_ABANDONED_WAIT_0, -EIO, "STATUS_ABANDONED_WAIT_0"},
45 {STATUS_ABANDONED_WAIT_63, -EIO, "STATUS_ABANDONED_WAIT_63"},
46 {STATUS_USER_APC, -EIO, "STATUS_USER_APC"},
47 {STATUS_KERNEL_APC, -EIO, "STATUS_KERNEL_APC"},
48 {STATUS_ALERTED, -EIO, "STATUS_ALERTED"},
49 {STATUS_TIMEOUT, -ETIMEDOUT, "STATUS_TIMEOUT"},
50 {STATUS_PENDING, -EIO, "STATUS_PENDING"},
51 {STATUS_REPARSE, -EIO, "STATUS_REPARSE"},
52 {STATUS_MORE_ENTRIES, -EIO, "STATUS_MORE_ENTRIES"},
53 {STATUS_NOT_ALL_ASSIGNED, -EIO, "STATUS_NOT_ALL_ASSIGNED"},
54 {STATUS_SOME_NOT_MAPPED, -EIO, "STATUS_SOME_NOT_MAPPED"},
55 {STATUS_OPLOCK_BREAK_IN_PROGRESS, -EIO,
56 "STATUS_OPLOCK_BREAK_IN_PROGRESS"},
57 {STATUS_VOLUME_MOUNTED, -EIO, "STATUS_VOLUME_MOUNTED"},
58 {STATUS_RXACT_COMMITTED, -EIO, "STATUS_RXACT_COMMITTED"},
59 {STATUS_NOTIFY_CLEANUP, -EIO, "STATUS_NOTIFY_CLEANUP"},
60 {STATUS_NOTIFY_ENUM_DIR, -EIO, "STATUS_NOTIFY_ENUM_DIR"},
61 {STATUS_NO_QUOTAS_FOR_ACCOUNT, -EIO, "STATUS_NO_QUOTAS_FOR_ACCOUNT"},
62 {STATUS_PRIMARY_TRANSPORT_CONNECT_FAILED, -EIO,
63 "STATUS_PRIMARY_TRANSPORT_CONNECT_FAILED"},
64 {STATUS_PAGE_FAULT_TRANSITION, -EIO, "STATUS_PAGE_FAULT_TRANSITION"},
65 {STATUS_PAGE_FAULT_DEMAND_ZERO, -EIO, "STATUS_PAGE_FAULT_DEMAND_ZERO"},
66 {STATUS_PAGE_FAULT_COPY_ON_WRITE, -EIO,
67 "STATUS_PAGE_FAULT_COPY_ON_WRITE"},
68 {STATUS_PAGE_FAULT_GUARD_PAGE, -EIO, "STATUS_PAGE_FAULT_GUARD_PAGE"},
69 {STATUS_PAGE_FAULT_PAGING_FILE, -EIO, "STATUS_PAGE_FAULT_PAGING_FILE"},
70 {STATUS_CACHE_PAGE_LOCKED, -EIO, "STATUS_CACHE_PAGE_LOCKED"},
71 {STATUS_CRASH_DUMP, -EIO, "STATUS_CRASH_DUMP"},
72 {STATUS_BUFFER_ALL_ZEROS, -EIO, "STATUS_BUFFER_ALL_ZEROS"},
73 {STATUS_REPARSE_OBJECT, -EIO, "STATUS_REPARSE_OBJECT"},
74 {STATUS_RESOURCE_REQUIREMENTS_CHANGED, -EIO,
75 "STATUS_RESOURCE_REQUIREMENTS_CHANGED"},
76 {STATUS_TRANSLATION_COMPLETE, -EIO, "STATUS_TRANSLATION_COMPLETE"},
77 {STATUS_DS_MEMBERSHIP_EVALUATED_LOCALLY, -EIO,
78 "STATUS_DS_MEMBERSHIP_EVALUATED_LOCALLY"},
79 {STATUS_NOTHING_TO_TERMINATE, -EIO, "STATUS_NOTHING_TO_TERMINATE"},
80 {STATUS_PROCESS_NOT_IN_JOB, -EIO, "STATUS_PROCESS_NOT_IN_JOB"},
81 {STATUS_PROCESS_IN_JOB, -EIO, "STATUS_PROCESS_IN_JOB"},
82 {STATUS_VOLSNAP_HIBERNATE_READY, -EIO,
83 "STATUS_VOLSNAP_HIBERNATE_READY"},
84 {STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY, -EIO,
85 "STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY"},
86 {STATUS_INTERRUPT_VECTOR_ALREADY_CONNECTED, -EIO,
87 "STATUS_INTERRUPT_VECTOR_ALREADY_CONNECTED"},
88 {STATUS_INTERRUPT_STILL_CONNECTED, -EIO,
89 "STATUS_INTERRUPT_STILL_CONNECTED"},
90 {STATUS_PROCESS_CLONED, -EIO, "STATUS_PROCESS_CLONED"},
91 {STATUS_FILE_LOCKED_WITH_ONLY_READERS, -EIO,
92 "STATUS_FILE_LOCKED_WITH_ONLY_READERS"},
93 {STATUS_FILE_LOCKED_WITH_WRITERS, -EIO,
94 "STATUS_FILE_LOCKED_WITH_WRITERS"},
95 {STATUS_RESOURCEMANAGER_READ_ONLY, -EROFS,
96 "STATUS_RESOURCEMANAGER_READ_ONLY"},
97 {STATUS_WAIT_FOR_OPLOCK, -EIO, "STATUS_WAIT_FOR_OPLOCK"},
98 {DBG_EXCEPTION_HANDLED, -EIO, "DBG_EXCEPTION_HANDLED"},
99 {DBG_CONTINUE, -EIO, "DBG_CONTINUE"},
100 {STATUS_FLT_IO_COMPLETE, -EIO, "STATUS_FLT_IO_COMPLETE"},
101 {STATUS_OBJECT_NAME_EXISTS, -EIO, "STATUS_OBJECT_NAME_EXISTS"},
102 {STATUS_THREAD_WAS_SUSPENDED, -EIO, "STATUS_THREAD_WAS_SUSPENDED"},
103 {STATUS_WORKING_SET_LIMIT_RANGE, -EIO,
104 "STATUS_WORKING_SET_LIMIT_RANGE"},
105 {STATUS_IMAGE_NOT_AT_BASE, -EIO, "STATUS_IMAGE_NOT_AT_BASE"},
106 {STATUS_RXACT_STATE_CREATED, -EIO, "STATUS_RXACT_STATE_CREATED"},
107 {STATUS_SEGMENT_NOTIFICATION, -EIO, "STATUS_SEGMENT_NOTIFICATION"},
108 {STATUS_LOCAL_USER_SESSION_KEY, -EIO, "STATUS_LOCAL_USER_SESSION_KEY"},
109 {STATUS_BAD_CURRENT_DIRECTORY, -EIO, "STATUS_BAD_CURRENT_DIRECTORY"},
110 {STATUS_SERIAL_MORE_WRITES, -EIO, "STATUS_SERIAL_MORE_WRITES"},
111 {STATUS_REGISTRY_RECOVERED, -EIO, "STATUS_REGISTRY_RECOVERED"},
112 {STATUS_FT_READ_RECOVERY_FROM_BACKUP, -EIO,
113 "STATUS_FT_READ_RECOVERY_FROM_BACKUP"},
114 {STATUS_FT_WRITE_RECOVERY, -EIO, "STATUS_FT_WRITE_RECOVERY"},
115 {STATUS_SERIAL_COUNTER_TIMEOUT, -ETIMEDOUT,
116 "STATUS_SERIAL_COUNTER_TIMEOUT"},
117 {STATUS_NULL_LM_PASSWORD, -EIO, "STATUS_NULL_LM_PASSWORD"},
118 {STATUS_IMAGE_MACHINE_TYPE_MISMATCH, -EIO,
119 "STATUS_IMAGE_MACHINE_TYPE_MISMATCH"},
120 {STATUS_RECEIVE_PARTIAL, -EIO, "STATUS_RECEIVE_PARTIAL"},
121 {STATUS_RECEIVE_EXPEDITED, -EIO, "STATUS_RECEIVE_EXPEDITED"},
122 {STATUS_RECEIVE_PARTIAL_EXPEDITED, -EIO,
123 "STATUS_RECEIVE_PARTIAL_EXPEDITED"},
124 {STATUS_EVENT_DONE, -EIO, "STATUS_EVENT_DONE"},
125 {STATUS_EVENT_PENDING, -EIO, "STATUS_EVENT_PENDING"},
126 {STATUS_CHECKING_FILE_SYSTEM, -EIO, "STATUS_CHECKING_FILE_SYSTEM"},
127 {STATUS_FATAL_APP_EXIT, -EIO, "STATUS_FATAL_APP_EXIT"},
128 {STATUS_PREDEFINED_HANDLE, -EIO, "STATUS_PREDEFINED_HANDLE"},
129 {STATUS_WAS_UNLOCKED, -EIO, "STATUS_WAS_UNLOCKED"},
130 {STATUS_SERVICE_NOTIFICATION, -EIO, "STATUS_SERVICE_NOTIFICATION"},
131 {STATUS_WAS_LOCKED, -EIO, "STATUS_WAS_LOCKED"},
132 {STATUS_LOG_HARD_ERROR, -EIO, "STATUS_LOG_HARD_ERROR"},
133 {STATUS_ALREADY_WIN32, -EIO, "STATUS_ALREADY_WIN32"},
134 {STATUS_WX86_UNSIMULATE, -EIO, "STATUS_WX86_UNSIMULATE"},
135 {STATUS_WX86_CONTINUE, -EIO, "STATUS_WX86_CONTINUE"},
136 {STATUS_WX86_SINGLE_STEP, -EIO, "STATUS_WX86_SINGLE_STEP"},
137 {STATUS_WX86_BREAKPOINT, -EIO, "STATUS_WX86_BREAKPOINT"},
138 {STATUS_WX86_EXCEPTION_CONTINUE, -EIO,
139 "STATUS_WX86_EXCEPTION_CONTINUE"},
140 {STATUS_WX86_EXCEPTION_LASTCHANCE, -EIO,
141 "STATUS_WX86_EXCEPTION_LASTCHANCE"},
142 {STATUS_WX86_EXCEPTION_CHAIN, -EIO, "STATUS_WX86_EXCEPTION_CHAIN"},
143 {STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE, -EIO,
144 "STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE"},
145 {STATUS_NO_YIELD_PERFORMED, -EIO, "STATUS_NO_YIELD_PERFORMED"},
146 {STATUS_TIMER_RESUME_IGNORED, -EIO, "STATUS_TIMER_RESUME_IGNORED"},
147 {STATUS_ARBITRATION_UNHANDLED, -EIO, "STATUS_ARBITRATION_UNHANDLED"},
148 {STATUS_CARDBUS_NOT_SUPPORTED, -ENOSYS, "STATUS_CARDBUS_NOT_SUPPORTED"},
149 {STATUS_WX86_CREATEWX86TIB, -EIO, "STATUS_WX86_CREATEWX86TIB"},
150 {STATUS_MP_PROCESSOR_MISMATCH, -EIO, "STATUS_MP_PROCESSOR_MISMATCH"},
151 {STATUS_HIBERNATED, -EIO, "STATUS_HIBERNATED"},
152 {STATUS_RESUME_HIBERNATION, -EIO, "STATUS_RESUME_HIBERNATION"},
153 {STATUS_FIRMWARE_UPDATED, -EIO, "STATUS_FIRMWARE_UPDATED"},
154 {STATUS_DRIVERS_LEAKING_LOCKED_PAGES, -EIO,
155 "STATUS_DRIVERS_LEAKING_LOCKED_PAGES"},
156 {STATUS_MESSAGE_RETRIEVED, -EIO, "STATUS_MESSAGE_RETRIEVED"},
157 {STATUS_SYSTEM_POWERSTATE_TRANSITION, -EIO,
158 "STATUS_SYSTEM_POWERSTATE_TRANSITION"},
159 {STATUS_ALPC_CHECK_COMPLETION_LIST, -EIO,
160 "STATUS_ALPC_CHECK_COMPLETION_LIST"},
161 {STATUS_SYSTEM_POWERSTATE_COMPLEX_TRANSITION, -EIO,
162 "STATUS_SYSTEM_POWERSTATE_COMPLEX_TRANSITION"},
163 {STATUS_ACCESS_AUDIT_BY_POLICY, -EIO, "STATUS_ACCESS_AUDIT_BY_POLICY"},
164 {STATUS_ABANDON_HIBERFILE, -EIO, "STATUS_ABANDON_HIBERFILE"},
165 {STATUS_BIZRULES_NOT_ENABLED, -EIO, "STATUS_BIZRULES_NOT_ENABLED"},
166 {STATUS_WAKE_SYSTEM, -EIO, "STATUS_WAKE_SYSTEM"},
167 {STATUS_DS_SHUTTING_DOWN, -EIO, "STATUS_DS_SHUTTING_DOWN"},
168 {DBG_REPLY_LATER, -EIO, "DBG_REPLY_LATER"},
169 {DBG_UNABLE_TO_PROVIDE_HANDLE, -EIO, "DBG_UNABLE_TO_PROVIDE_HANDLE"},
170 {DBG_TERMINATE_THREAD, -EIO, "DBG_TERMINATE_THREAD"},
171 {DBG_TERMINATE_PROCESS, -EIO, "DBG_TERMINATE_PROCESS"},
172 {DBG_CONTROL_C, -EIO, "DBG_CONTROL_C"},
173 {DBG_PRINTEXCEPTION_C, -EIO, "DBG_PRINTEXCEPTION_C"},
174 {DBG_RIPEXCEPTION, -EIO, "DBG_RIPEXCEPTION"},
175 {DBG_CONTROL_BREAK, -EIO, "DBG_CONTROL_BREAK"},
176 {DBG_COMMAND_EXCEPTION, -EIO, "DBG_COMMAND_EXCEPTION"},
177 {RPC_NT_UUID_LOCAL_ONLY, -EIO, "RPC_NT_UUID_LOCAL_ONLY"},
178 {RPC_NT_SEND_INCOMPLETE, -EIO, "RPC_NT_SEND_INCOMPLETE"},
179 {STATUS_CTX_CDM_CONNECT, -EIO, "STATUS_CTX_CDM_CONNECT"},
180 {STATUS_CTX_CDM_DISCONNECT, -EIO, "STATUS_CTX_CDM_DISCONNECT"},
181 {STATUS_SXS_RELEASE_ACTIVATION_CONTEXT, -EIO,
182 "STATUS_SXS_RELEASE_ACTIVATION_CONTEXT"},
183 {STATUS_RECOVERY_NOT_NEEDED, -EIO, "STATUS_RECOVERY_NOT_NEEDED"},
184 {STATUS_RM_ALREADY_STARTED, -EIO, "STATUS_RM_ALREADY_STARTED"},
185 {STATUS_LOG_NO_RESTART, -EIO, "STATUS_LOG_NO_RESTART"},
186 {STATUS_VIDEO_DRIVER_DEBUG_REPORT_REQUEST, -EIO,
187 "STATUS_VIDEO_DRIVER_DEBUG_REPORT_REQUEST"},
188 {STATUS_GRAPHICS_PARTIAL_DATA_POPULATED, -EIO,
189 "STATUS_GRAPHICS_PARTIAL_DATA_POPULATED"},
190 {STATUS_GRAPHICS_DRIVER_MISMATCH, -EIO,
191 "STATUS_GRAPHICS_DRIVER_MISMATCH"},
192 {STATUS_GRAPHICS_MODE_NOT_PINNED, -EIO,
193 "STATUS_GRAPHICS_MODE_NOT_PINNED"},
194 {STATUS_GRAPHICS_NO_PREFERRED_MODE, -EIO,
195 "STATUS_GRAPHICS_NO_PREFERRED_MODE"},
196 {STATUS_GRAPHICS_DATASET_IS_EMPTY, -EIO,
197 "STATUS_GRAPHICS_DATASET_IS_EMPTY"},
198 {STATUS_GRAPHICS_NO_MORE_ELEMENTS_IN_DATASET, -EIO,
199 "STATUS_GRAPHICS_NO_MORE_ELEMENTS_IN_DATASET"},
200 {STATUS_GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_PINNED, -EIO,
201 "STATUS_GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_PINNED"},
202 {STATUS_GRAPHICS_UNKNOWN_CHILD_STATUS, -EIO,
203 "STATUS_GRAPHICS_UNKNOWN_CHILD_STATUS"},
204 {STATUS_GRAPHICS_LEADLINK_START_DEFERRED, -EIO,
205 "STATUS_GRAPHICS_LEADLINK_START_DEFERRED"},
206 {STATUS_GRAPHICS_POLLING_TOO_FREQUENTLY, -EIO,
207 "STATUS_GRAPHICS_POLLING_TOO_FREQUENTLY"},
208 {STATUS_GRAPHICS_START_DEFERRED, -EIO,
209 "STATUS_GRAPHICS_START_DEFERRED"},
210 {STATUS_NDIS_INDICATION_REQUIRED, -EIO,
211 "STATUS_NDIS_INDICATION_REQUIRED"},
212 {STATUS_GUARD_PAGE_VIOLATION, -EIO, "STATUS_GUARD_PAGE_VIOLATION"},
213 {STATUS_DATATYPE_MISALIGNMENT, -EIO, "STATUS_DATATYPE_MISALIGNMENT"},
214 {STATUS_BREAKPOINT, -EIO, "STATUS_BREAKPOINT"},
215 {STATUS_SINGLE_STEP, -EIO, "STATUS_SINGLE_STEP"},
216 {STATUS_BUFFER_OVERFLOW, -EIO, "STATUS_BUFFER_OVERFLOW"},
217 {STATUS_NO_MORE_FILES, -EIO, "STATUS_NO_MORE_FILES"},
218 {STATUS_WAKE_SYSTEM_DEBUGGER, -EIO, "STATUS_WAKE_SYSTEM_DEBUGGER"},
219 {STATUS_HANDLES_CLOSED, -EIO, "STATUS_HANDLES_CLOSED"},
220 {STATUS_NO_INHERITANCE, -EIO, "STATUS_NO_INHERITANCE"},
221 {STATUS_GUID_SUBSTITUTION_MADE, -EIO, "STATUS_GUID_SUBSTITUTION_MADE"},
222 {STATUS_PARTIAL_COPY, -EIO, "STATUS_PARTIAL_COPY"},
223 {STATUS_DEVICE_PAPER_EMPTY, -EIO, "STATUS_DEVICE_PAPER_EMPTY"},
224 {STATUS_DEVICE_POWERED_OFF, -EIO, "STATUS_DEVICE_POWERED_OFF"},
225 {STATUS_DEVICE_OFF_LINE, -EIO, "STATUS_DEVICE_OFF_LINE"},
226 {STATUS_DEVICE_BUSY, -EBUSY, "STATUS_DEVICE_BUSY"},
227 {STATUS_NO_MORE_EAS, -EIO, "STATUS_NO_MORE_EAS"},
228 {STATUS_INVALID_EA_NAME, -EINVAL, "STATUS_INVALID_EA_NAME"},
229 {STATUS_EA_LIST_INCONSISTENT, -EIO, "STATUS_EA_LIST_INCONSISTENT"},
230 {STATUS_INVALID_EA_FLAG, -EINVAL, "STATUS_INVALID_EA_FLAG"},
231 {STATUS_VERIFY_REQUIRED, -EIO, "STATUS_VERIFY_REQUIRED"},
232 {STATUS_EXTRANEOUS_INFORMATION, -EIO, "STATUS_EXTRANEOUS_INFORMATION"},
233 {STATUS_RXACT_COMMIT_NECESSARY, -EIO, "STATUS_RXACT_COMMIT_NECESSARY"},
234 {STATUS_NO_MORE_ENTRIES, -EIO, "STATUS_NO_MORE_ENTRIES"},
235 {STATUS_FILEMARK_DETECTED, -EIO, "STATUS_FILEMARK_DETECTED"},
236 {STATUS_MEDIA_CHANGED, -EIO, "STATUS_MEDIA_CHANGED"},
237 {STATUS_BUS_RESET, -EIO, "STATUS_BUS_RESET"},
238 {STATUS_END_OF_MEDIA, -EIO, "STATUS_END_OF_MEDIA"},
239 {STATUS_BEGINNING_OF_MEDIA, -EIO, "STATUS_BEGINNING_OF_MEDIA"},
240 {STATUS_MEDIA_CHECK, -EIO, "STATUS_MEDIA_CHECK"},
241 {STATUS_SETMARK_DETECTED, -EIO, "STATUS_SETMARK_DETECTED"},
242 {STATUS_NO_DATA_DETECTED, -EIO, "STATUS_NO_DATA_DETECTED"},
243 {STATUS_REDIRECTOR_HAS_OPEN_HANDLES, -EIO,
244 "STATUS_REDIRECTOR_HAS_OPEN_HANDLES"},
245 {STATUS_SERVER_HAS_OPEN_HANDLES, -EIO,
246 "STATUS_SERVER_HAS_OPEN_HANDLES"},
247 {STATUS_ALREADY_DISCONNECTED, -EIO, "STATUS_ALREADY_DISCONNECTED"},
248 {STATUS_LONGJUMP, -EIO, "STATUS_LONGJUMP"},
249 {STATUS_CLEANER_CARTRIDGE_INSTALLED, -EIO,
250 "STATUS_CLEANER_CARTRIDGE_INSTALLED"},
251 {STATUS_PLUGPLAY_QUERY_VETOED, -EIO, "STATUS_PLUGPLAY_QUERY_VETOED"},
252 {STATUS_UNWIND_CONSOLIDATE, -EIO, "STATUS_UNWIND_CONSOLIDATE"},
253 {STATUS_REGISTRY_HIVE_RECOVERED, -EIO,
254 "STATUS_REGISTRY_HIVE_RECOVERED"},
255 {STATUS_DLL_MIGHT_BE_INSECURE, -EIO, "STATUS_DLL_MIGHT_BE_INSECURE"},
256 {STATUS_DLL_MIGHT_BE_INCOMPATIBLE, -EIO,
257 "STATUS_DLL_MIGHT_BE_INCOMPATIBLE"},
258 {STATUS_STOPPED_ON_SYMLINK, -EOPNOTSUPP, "STATUS_STOPPED_ON_SYMLINK"},
259 {STATUS_DEVICE_REQUIRES_CLEANING, -EIO,
260 "STATUS_DEVICE_REQUIRES_CLEANING"},
261 {STATUS_DEVICE_DOOR_OPEN, -EIO, "STATUS_DEVICE_DOOR_OPEN"},
262 {STATUS_DATA_LOST_REPAIR, -EIO, "STATUS_DATA_LOST_REPAIR"},
263 {DBG_EXCEPTION_NOT_HANDLED, -EIO, "DBG_EXCEPTION_NOT_HANDLED"},
264 {STATUS_CLUSTER_NODE_ALREADY_UP, -EIO,
265 "STATUS_CLUSTER_NODE_ALREADY_UP"},
266 {STATUS_CLUSTER_NODE_ALREADY_DOWN, -EIO,
267 "STATUS_CLUSTER_NODE_ALREADY_DOWN"},
268 {STATUS_CLUSTER_NETWORK_ALREADY_ONLINE, -EIO,
269 "STATUS_CLUSTER_NETWORK_ALREADY_ONLINE"},
270 {STATUS_CLUSTER_NETWORK_ALREADY_OFFLINE, -EIO,
271 "STATUS_CLUSTER_NETWORK_ALREADY_OFFLINE"},
272 {STATUS_CLUSTER_NODE_ALREADY_MEMBER, -EIO,
273 "STATUS_CLUSTER_NODE_ALREADY_MEMBER"},
274 {STATUS_COULD_NOT_RESIZE_LOG, -EIO, "STATUS_COULD_NOT_RESIZE_LOG"},
275 {STATUS_NO_TXF_METADATA, -EIO, "STATUS_NO_TXF_METADATA"},
276 {STATUS_CANT_RECOVER_WITH_HANDLE_OPEN, -EIO,
277 "STATUS_CANT_RECOVER_WITH_HANDLE_OPEN"},
278 {STATUS_TXF_METADATA_ALREADY_PRESENT, -EIO,
279 "STATUS_TXF_METADATA_ALREADY_PRESENT"},
280 {STATUS_TRANSACTION_SCOPE_CALLBACKS_NOT_SET, -EIO,
281 "STATUS_TRANSACTION_SCOPE_CALLBACKS_NOT_SET"},
282 {STATUS_VIDEO_HUNG_DISPLAY_DRIVER_THREAD_RECOVERED, -EIO,
283 "STATUS_VIDEO_HUNG_DISPLAY_DRIVER_THREAD_RECOVERED"},
284 {STATUS_FLT_BUFFER_TOO_SMALL, -ENOBUFS, "STATUS_FLT_BUFFER_TOO_SMALL"},
285 {STATUS_FVE_PARTIAL_METADATA, -EIO, "STATUS_FVE_PARTIAL_METADATA"},
286 {STATUS_UNSUCCESSFUL, -EIO, "STATUS_UNSUCCESSFUL"},
287 {STATUS_NOT_IMPLEMENTED, -ENOSYS, "STATUS_NOT_IMPLEMENTED"},
288 {STATUS_INVALID_INFO_CLASS, -EIO, "STATUS_INVALID_INFO_CLASS"},
289 {STATUS_INFO_LENGTH_MISMATCH, -EIO, "STATUS_INFO_LENGTH_MISMATCH"},
290 {STATUS_ACCESS_VIOLATION, -EACCES, "STATUS_ACCESS_VIOLATION"},
291 {STATUS_IN_PAGE_ERROR, -EFAULT, "STATUS_IN_PAGE_ERROR"},
292 {STATUS_PAGEFILE_QUOTA, -EDQUOT, "STATUS_PAGEFILE_QUOTA"},
293 {STATUS_INVALID_HANDLE, -EBADF, "STATUS_INVALID_HANDLE"},
294 {STATUS_BAD_INITIAL_STACK, -EIO, "STATUS_BAD_INITIAL_STACK"},
295 {STATUS_BAD_INITIAL_PC, -EIO, "STATUS_BAD_INITIAL_PC"},
296 {STATUS_INVALID_CID, -EIO, "STATUS_INVALID_CID"},
297 {STATUS_TIMER_NOT_CANCELED, -EIO, "STATUS_TIMER_NOT_CANCELED"},
298 {STATUS_INVALID_PARAMETER, -EINVAL, "STATUS_INVALID_PARAMETER"},
299 {STATUS_NO_SUCH_DEVICE, -ENODEV, "STATUS_NO_SUCH_DEVICE"},
300 {STATUS_NO_SUCH_FILE, -ENOENT, "STATUS_NO_SUCH_FILE"},
301 {STATUS_INVALID_DEVICE_REQUEST, -EIO, "STATUS_INVALID_DEVICE_REQUEST"},
302 {STATUS_END_OF_FILE, -ENODATA, "STATUS_END_OF_FILE"},
303 {STATUS_WRONG_VOLUME, -EIO, "STATUS_WRONG_VOLUME"},
304 {STATUS_NO_MEDIA_IN_DEVICE, -EIO, "STATUS_NO_MEDIA_IN_DEVICE"},
305 {STATUS_UNRECOGNIZED_MEDIA, -EIO, "STATUS_UNRECOGNIZED_MEDIA"},
306 {STATUS_NONEXISTENT_SECTOR, -EIO, "STATUS_NONEXISTENT_SECTOR"},
307 {STATUS_MORE_PROCESSING_REQUIRED, -EIO,
308 "STATUS_MORE_PROCESSING_REQUIRED"},
309 {STATUS_NO_MEMORY, -ENOMEM, "STATUS_NO_MEMORY"},
310 {STATUS_CONFLICTING_ADDRESSES, -EADDRINUSE,
311 "STATUS_CONFLICTING_ADDRESSES"},
312 {STATUS_NOT_MAPPED_VIEW, -EIO, "STATUS_NOT_MAPPED_VIEW"},
313 {STATUS_UNABLE_TO_FREE_VM, -EIO, "STATUS_UNABLE_TO_FREE_VM"},
314 {STATUS_UNABLE_TO_DELETE_SECTION, -EIO,
315 "STATUS_UNABLE_TO_DELETE_SECTION"},
316 {STATUS_INVALID_SYSTEM_SERVICE, -EIO, "STATUS_INVALID_SYSTEM_SERVICE"},
317 {STATUS_ILLEGAL_INSTRUCTION, -EIO, "STATUS_ILLEGAL_INSTRUCTION"},
318 {STATUS_INVALID_LOCK_SEQUENCE, -EIO, "STATUS_INVALID_LOCK_SEQUENCE"},
319 {STATUS_INVALID_VIEW_SIZE, -EIO, "STATUS_INVALID_VIEW_SIZE"},
320 {STATUS_INVALID_FILE_FOR_SECTION, -EIO,
321 "STATUS_INVALID_FILE_FOR_SECTION"},
322 {STATUS_ALREADY_COMMITTED, -EIO, "STATUS_ALREADY_COMMITTED"},
323 {STATUS_ACCESS_DENIED, -EACCES, "STATUS_ACCESS_DENIED"},
324 {STATUS_BUFFER_TOO_SMALL, -EIO, "STATUS_BUFFER_TOO_SMALL"},
325 {STATUS_OBJECT_TYPE_MISMATCH, -EIO, "STATUS_OBJECT_TYPE_MISMATCH"},
326 {STATUS_NONCONTINUABLE_EXCEPTION, -EIO,
327 "STATUS_NONCONTINUABLE_EXCEPTION"},
328 {STATUS_INVALID_DISPOSITION, -EIO, "STATUS_INVALID_DISPOSITION"},
329 {STATUS_UNWIND, -EIO, "STATUS_UNWIND"},
330 {STATUS_BAD_STACK, -EIO, "STATUS_BAD_STACK"},
331 {STATUS_INVALID_UNWIND_TARGET, -EIO, "STATUS_INVALID_UNWIND_TARGET"},
332 {STATUS_NOT_LOCKED, -EIO, "STATUS_NOT_LOCKED"},
333 {STATUS_PARITY_ERROR, -EIO, "STATUS_PARITY_ERROR"},
334 {STATUS_UNABLE_TO_DECOMMIT_VM, -EIO, "STATUS_UNABLE_TO_DECOMMIT_VM"},
335 {STATUS_NOT_COMMITTED, -EIO, "STATUS_NOT_COMMITTED"},
336 {STATUS_INVALID_PORT_ATTRIBUTES, -EIO,
337 "STATUS_INVALID_PORT_ATTRIBUTES"},
338 {STATUS_PORT_MESSAGE_TOO_LONG, -EIO, "STATUS_PORT_MESSAGE_TOO_LONG"},
339 {STATUS_INVALID_PARAMETER_MIX, -EINVAL, "STATUS_INVALID_PARAMETER_MIX"},
340 {STATUS_INVALID_QUOTA_LOWER, -EIO, "STATUS_INVALID_QUOTA_LOWER"},
341 {STATUS_DISK_CORRUPT_ERROR, -EIO, "STATUS_DISK_CORRUPT_ERROR"},
342 {STATUS_OBJECT_NAME_INVALID, -ENOENT, "STATUS_OBJECT_NAME_INVALID"},
343 {STATUS_OBJECT_NAME_NOT_FOUND, -ENOENT, "STATUS_OBJECT_NAME_NOT_FOUND"},
344 {STATUS_OBJECT_NAME_COLLISION, -EEXIST, "STATUS_OBJECT_NAME_COLLISION"},
345 {STATUS_PORT_DISCONNECTED, -EIO, "STATUS_PORT_DISCONNECTED"},
346 {STATUS_DEVICE_ALREADY_ATTACHED, -EIO,
347 "STATUS_DEVICE_ALREADY_ATTACHED"},
348 {STATUS_OBJECT_PATH_INVALID, -ENOTDIR, "STATUS_OBJECT_PATH_INVALID"},
349 {STATUS_OBJECT_PATH_NOT_FOUND, -ENOENT, "STATUS_OBJECT_PATH_NOT_FOUND"},
350 {STATUS_OBJECT_PATH_SYNTAX_BAD, -EIO, "STATUS_OBJECT_PATH_SYNTAX_BAD"},
351 {STATUS_DATA_OVERRUN, -EIO, "STATUS_DATA_OVERRUN"},
352 {STATUS_DATA_LATE_ERROR, -EIO, "STATUS_DATA_LATE_ERROR"},
353 {STATUS_DATA_ERROR, -EIO, "STATUS_DATA_ERROR"},
354 {STATUS_CRC_ERROR, -EIO, "STATUS_CRC_ERROR"},
355 {STATUS_SECTION_TOO_BIG, -EIO, "STATUS_SECTION_TOO_BIG"},
356 {STATUS_PORT_CONNECTION_REFUSED, -ECONNREFUSED,
357 "STATUS_PORT_CONNECTION_REFUSED"},
358 {STATUS_INVALID_PORT_HANDLE, -EIO, "STATUS_INVALID_PORT_HANDLE"},
359 {STATUS_SHARING_VIOLATION, -EBUSY, "STATUS_SHARING_VIOLATION"},
360 {STATUS_QUOTA_EXCEEDED, -EDQUOT, "STATUS_QUOTA_EXCEEDED"},
361 {STATUS_INVALID_PAGE_PROTECTION, -EIO,
362 "STATUS_INVALID_PAGE_PROTECTION"},
363 {STATUS_MUTANT_NOT_OWNED, -EIO, "STATUS_MUTANT_NOT_OWNED"},
364 {STATUS_SEMAPHORE_LIMIT_EXCEEDED, -EIO,
365 "STATUS_SEMAPHORE_LIMIT_EXCEEDED"},
366 {STATUS_PORT_ALREADY_SET, -EIO, "STATUS_PORT_ALREADY_SET"},
367 {STATUS_SECTION_NOT_IMAGE, -EIO, "STATUS_SECTION_NOT_IMAGE"},
368 {STATUS_SUSPEND_COUNT_EXCEEDED, -EIO, "STATUS_SUSPEND_COUNT_EXCEEDED"},
369 {STATUS_THREAD_IS_TERMINATING, -EIO, "STATUS_THREAD_IS_TERMINATING"},
370 {STATUS_BAD_WORKING_SET_LIMIT, -EIO, "STATUS_BAD_WORKING_SET_LIMIT"},
371 {STATUS_INCOMPATIBLE_FILE_MAP, -EIO, "STATUS_INCOMPATIBLE_FILE_MAP"},
372 {STATUS_SECTION_PROTECTION, -EIO, "STATUS_SECTION_PROTECTION"},
373 {STATUS_EAS_NOT_SUPPORTED, -EOPNOTSUPP, "STATUS_EAS_NOT_SUPPORTED"},
374 {STATUS_EA_TOO_LARGE, -EIO, "STATUS_EA_TOO_LARGE"},
375 {STATUS_NONEXISTENT_EA_ENTRY, -EIO, "STATUS_NONEXISTENT_EA_ENTRY"},
376 {STATUS_NO_EAS_ON_FILE, -ENODATA, "STATUS_NO_EAS_ON_FILE"},
377 {STATUS_EA_CORRUPT_ERROR, -EIO, "STATUS_EA_CORRUPT_ERROR"},
378 {STATUS_FILE_LOCK_CONFLICT, -EIO, "STATUS_FILE_LOCK_CONFLICT"},
379 {STATUS_LOCK_NOT_GRANTED, -EIO, "STATUS_LOCK_NOT_GRANTED"},
380 {STATUS_DELETE_PENDING, -ENOENT, "STATUS_DELETE_PENDING"},
381 {STATUS_CTL_FILE_NOT_SUPPORTED, -ENOSYS,
382 "STATUS_CTL_FILE_NOT_SUPPORTED"},
383 {STATUS_UNKNOWN_REVISION, -EIO, "STATUS_UNKNOWN_REVISION"},
384 {STATUS_REVISION_MISMATCH, -EIO, "STATUS_REVISION_MISMATCH"},
385 {STATUS_INVALID_OWNER, -EIO, "STATUS_INVALID_OWNER"},
386 {STATUS_INVALID_PRIMARY_GROUP, -EIO, "STATUS_INVALID_PRIMARY_GROUP"},
387 {STATUS_NO_IMPERSONATION_TOKEN, -EIO, "STATUS_NO_IMPERSONATION_TOKEN"},
388 {STATUS_CANT_DISABLE_MANDATORY, -EIO, "STATUS_CANT_DISABLE_MANDATORY"},
389 {STATUS_NO_LOGON_SERVERS, -EIO, "STATUS_NO_LOGON_SERVERS"},
390 {STATUS_NO_SUCH_LOGON_SESSION, -EIO, "STATUS_NO_SUCH_LOGON_SESSION"},
391 {STATUS_NO_SUCH_PRIVILEGE, -EIO, "STATUS_NO_SUCH_PRIVILEGE"},
392 {STATUS_PRIVILEGE_NOT_HELD, -EIO, "STATUS_PRIVILEGE_NOT_HELD"},
393 {STATUS_INVALID_ACCOUNT_NAME, -EIO, "STATUS_INVALID_ACCOUNT_NAME"},
394 {STATUS_USER_EXISTS, -EIO, "STATUS_USER_EXISTS"},
395 {STATUS_NO_SUCH_USER, -EIO, "STATUS_NO_SUCH_USER"},
396 {STATUS_GROUP_EXISTS, -EIO, "STATUS_GROUP_EXISTS"},
397 {STATUS_NO_SUCH_GROUP, -EIO, "STATUS_NO_SUCH_GROUP"},
398 {STATUS_MEMBER_IN_GROUP, -EIO, "STATUS_MEMBER_IN_GROUP"},
399 {STATUS_MEMBER_NOT_IN_GROUP, -EIO, "STATUS_MEMBER_NOT_IN_GROUP"},
400 {STATUS_LAST_ADMIN, -EIO, "STATUS_LAST_ADMIN"},
401 {STATUS_WRONG_PASSWORD, -EACCES, "STATUS_WRONG_PASSWORD"},
402 {STATUS_ILL_FORMED_PASSWORD, -EINVAL, "STATUS_ILL_FORMED_PASSWORD"},
403 {STATUS_PASSWORD_RESTRICTION, -EACCES, "STATUS_PASSWORD_RESTRICTION"},
404 {STATUS_LOGON_FAILURE, -EACCES, "STATUS_LOGON_FAILURE"},
405 {STATUS_ACCOUNT_RESTRICTION, -EACCES, "STATUS_ACCOUNT_RESTRICTION"},
406 {STATUS_INVALID_LOGON_HOURS, -EACCES, "STATUS_INVALID_LOGON_HOURS"},
407 {STATUS_INVALID_WORKSTATION, -EACCES, "STATUS_INVALID_WORKSTATION"},
408 {STATUS_PASSWORD_EXPIRED, -EKEYEXPIRED, "STATUS_PASSWORD_EXPIRED"},
409 {STATUS_ACCOUNT_DISABLED, -EKEYREVOKED, "STATUS_ACCOUNT_DISABLED"},
410 {STATUS_NONE_MAPPED, -EIO, "STATUS_NONE_MAPPED"},
411 {STATUS_TOO_MANY_LUIDS_REQUESTED, -EIO,
412 "STATUS_TOO_MANY_LUIDS_REQUESTED"},
413 {STATUS_LUIDS_EXHAUSTED, -EIO, "STATUS_LUIDS_EXHAUSTED"},
414 {STATUS_INVALID_SUB_AUTHORITY, -EIO, "STATUS_INVALID_SUB_AUTHORITY"},
415 {STATUS_INVALID_ACL, -EIO, "STATUS_INVALID_ACL"},
416 {STATUS_INVALID_SID, -EIO, "STATUS_INVALID_SID"},
417 {STATUS_INVALID_SECURITY_DESCR, -EIO, "STATUS_INVALID_SECURITY_DESCR"},
418 {STATUS_PROCEDURE_NOT_FOUND, -EIO, "STATUS_PROCEDURE_NOT_FOUND"},
419 {STATUS_INVALID_IMAGE_FORMAT, -EIO, "STATUS_INVALID_IMAGE_FORMAT"},
420 {STATUS_NO_TOKEN, -EIO, "STATUS_NO_TOKEN"},
421 {STATUS_BAD_INHERITANCE_ACL, -EIO, "STATUS_BAD_INHERITANCE_ACL"},
422 {STATUS_RANGE_NOT_LOCKED, -EIO, "STATUS_RANGE_NOT_LOCKED"},
423 {STATUS_DISK_FULL, -ENOSPC, "STATUS_DISK_FULL"},
424 {STATUS_SERVER_DISABLED, -EIO, "STATUS_SERVER_DISABLED"},
425 {STATUS_SERVER_NOT_DISABLED, -EIO, "STATUS_SERVER_NOT_DISABLED"},
426 {STATUS_TOO_MANY_GUIDS_REQUESTED, -EIO,
427 "STATUS_TOO_MANY_GUIDS_REQUESTED"},
428 {STATUS_GUIDS_EXHAUSTED, -EIO, "STATUS_GUIDS_EXHAUSTED"},
429 {STATUS_INVALID_ID_AUTHORITY, -EIO, "STATUS_INVALID_ID_AUTHORITY"},
430 {STATUS_AGENTS_EXHAUSTED, -EIO, "STATUS_AGENTS_EXHAUSTED"},
431 {STATUS_INVALID_VOLUME_LABEL, -EIO, "STATUS_INVALID_VOLUME_LABEL"},
432 {STATUS_SECTION_NOT_EXTENDED, -EIO, "STATUS_SECTION_NOT_EXTENDED"},
433 {STATUS_NOT_MAPPED_DATA, -EIO, "STATUS_NOT_MAPPED_DATA"},
434 {STATUS_RESOURCE_DATA_NOT_FOUND, -EIO,
435 "STATUS_RESOURCE_DATA_NOT_FOUND"},
436 {STATUS_RESOURCE_TYPE_NOT_FOUND, -EIO,
437 "STATUS_RESOURCE_TYPE_NOT_FOUND"},
438 {STATUS_RESOURCE_NAME_NOT_FOUND, -EIO,
439 "STATUS_RESOURCE_NAME_NOT_FOUND"},
440 {STATUS_ARRAY_BOUNDS_EXCEEDED, -EIO, "STATUS_ARRAY_BOUNDS_EXCEEDED"},
441 {STATUS_FLOAT_DENORMAL_OPERAND, -EIO, "STATUS_FLOAT_DENORMAL_OPERAND"},
442 {STATUS_FLOAT_DIVIDE_BY_ZERO, -EIO, "STATUS_FLOAT_DIVIDE_BY_ZERO"},
443 {STATUS_FLOAT_INEXACT_RESULT, -EIO, "STATUS_FLOAT_INEXACT_RESULT"},
444 {STATUS_FLOAT_INVALID_OPERATION, -EIO,
445 "STATUS_FLOAT_INVALID_OPERATION"},
446 {STATUS_FLOAT_OVERFLOW, -EIO, "STATUS_FLOAT_OVERFLOW"},
447 {STATUS_FLOAT_STACK_CHECK, -EIO, "STATUS_FLOAT_STACK_CHECK"},
448 {STATUS_FLOAT_UNDERFLOW, -EIO, "STATUS_FLOAT_UNDERFLOW"},
449 {STATUS_INTEGER_DIVIDE_BY_ZERO, -EIO, "STATUS_INTEGER_DIVIDE_BY_ZERO"},
450 {STATUS_INTEGER_OVERFLOW, -EIO, "STATUS_INTEGER_OVERFLOW"},
451 {STATUS_PRIVILEGED_INSTRUCTION, -EIO, "STATUS_PRIVILEGED_INSTRUCTION"},
452 {STATUS_TOO_MANY_PAGING_FILES, -EIO, "STATUS_TOO_MANY_PAGING_FILES"},
453 {STATUS_FILE_INVALID, -EIO, "STATUS_FILE_INVALID"},
454 {STATUS_ALLOTTED_SPACE_EXCEEDED, -EIO,
455 "STATUS_ALLOTTED_SPACE_EXCEEDED"},
456 {STATUS_INSUFFICIENT_RESOURCES, -EREMOTEIO,
457 "STATUS_INSUFFICIENT_RESOURCES"},
458 {STATUS_DFS_EXIT_PATH_FOUND, -EIO, "STATUS_DFS_EXIT_PATH_FOUND"},
459 {STATUS_DEVICE_DATA_ERROR, -EIO, "STATUS_DEVICE_DATA_ERROR"},
460 {STATUS_DEVICE_NOT_CONNECTED, -EIO, "STATUS_DEVICE_NOT_CONNECTED"},
461 {STATUS_DEVICE_POWER_FAILURE, -EIO, "STATUS_DEVICE_POWER_FAILURE"},
462 {STATUS_FREE_VM_NOT_AT_BASE, -EIO, "STATUS_FREE_VM_NOT_AT_BASE"},
463 {STATUS_MEMORY_NOT_ALLOCATED, -EFAULT, "STATUS_MEMORY_NOT_ALLOCATED"},
464 {STATUS_WORKING_SET_QUOTA, -EIO, "STATUS_WORKING_SET_QUOTA"},
465 {STATUS_MEDIA_WRITE_PROTECTED, -EROFS, "STATUS_MEDIA_WRITE_PROTECTED"},
466 {STATUS_DEVICE_NOT_READY, -EIO, "STATUS_DEVICE_NOT_READY"},
467 {STATUS_INVALID_GROUP_ATTRIBUTES, -EIO,
468 "STATUS_INVALID_GROUP_ATTRIBUTES"},
469 {STATUS_BAD_IMPERSONATION_LEVEL, -EIO,
470 "STATUS_BAD_IMPERSONATION_LEVEL"},
471 {STATUS_CANT_OPEN_ANONYMOUS, -EIO, "STATUS_CANT_OPEN_ANONYMOUS"},
472 {STATUS_BAD_VALIDATION_CLASS, -EIO, "STATUS_BAD_VALIDATION_CLASS"},
473 {STATUS_BAD_TOKEN_TYPE, -EIO, "STATUS_BAD_TOKEN_TYPE"},
474 {STATUS_BAD_MASTER_BOOT_RECORD, -EIO, "STATUS_BAD_MASTER_BOOT_RECORD"},
475 {STATUS_INSTRUCTION_MISALIGNMENT, -EIO,
476 "STATUS_INSTRUCTION_MISALIGNMENT"},
477 {STATUS_INSTANCE_NOT_AVAILABLE, -EIO, "STATUS_INSTANCE_NOT_AVAILABLE"},
478 {STATUS_PIPE_NOT_AVAILABLE, -EIO, "STATUS_PIPE_NOT_AVAILABLE"},
479 {STATUS_INVALID_PIPE_STATE, -EIO, "STATUS_INVALID_PIPE_STATE"},
480 {STATUS_PIPE_BUSY, -EBUSY, "STATUS_PIPE_BUSY"},
481 {STATUS_ILLEGAL_FUNCTION, -EIO, "STATUS_ILLEGAL_FUNCTION"},
482 {STATUS_PIPE_DISCONNECTED, -EPIPE, "STATUS_PIPE_DISCONNECTED"},
483 {STATUS_PIPE_CLOSING, -EIO, "STATUS_PIPE_CLOSING"},
484 {STATUS_PIPE_CONNECTED, -EIO, "STATUS_PIPE_CONNECTED"},
485 {STATUS_PIPE_LISTENING, -EIO, "STATUS_PIPE_LISTENING"},
486 {STATUS_INVALID_READ_MODE, -EIO, "STATUS_INVALID_READ_MODE"},
487 {STATUS_IO_TIMEOUT, -ETIMEDOUT, "STATUS_IO_TIMEOUT"},
488 {STATUS_FILE_FORCED_CLOSED, -EIO, "STATUS_FILE_FORCED_CLOSED"},
489 {STATUS_PROFILING_NOT_STARTED, -EIO, "STATUS_PROFILING_NOT_STARTED"},
490 {STATUS_PROFILING_NOT_STOPPED, -EIO, "STATUS_PROFILING_NOT_STOPPED"},
491 {STATUS_COULD_NOT_INTERPRET, -EIO, "STATUS_COULD_NOT_INTERPRET"},
492 {STATUS_FILE_IS_A_DIRECTORY, -EISDIR, "STATUS_FILE_IS_A_DIRECTORY"},
493 {STATUS_NOT_SUPPORTED, -EOPNOTSUPP, "STATUS_NOT_SUPPORTED"},
494 {STATUS_REMOTE_NOT_LISTENING, -EHOSTDOWN,
495 "STATUS_REMOTE_NOT_LISTENING"},
496 {STATUS_DUPLICATE_NAME, -ENOTUNIQ, "STATUS_DUPLICATE_NAME"},
497 {STATUS_BAD_NETWORK_PATH, -EINVAL, "STATUS_BAD_NETWORK_PATH"},
498 {STATUS_NETWORK_BUSY, -EBUSY, "STATUS_NETWORK_BUSY"},
499 {STATUS_DEVICE_DOES_NOT_EXIST, -ENODEV, "STATUS_DEVICE_DOES_NOT_EXIST"},
500 {STATUS_TOO_MANY_COMMANDS, -EIO, "STATUS_TOO_MANY_COMMANDS"},
501 {STATUS_ADAPTER_HARDWARE_ERROR, -EIO, "STATUS_ADAPTER_HARDWARE_ERROR"},
502 {STATUS_INVALID_NETWORK_RESPONSE, -EIO,
503 "STATUS_INVALID_NETWORK_RESPONSE"},
504 {STATUS_UNEXPECTED_NETWORK_ERROR, -EIO,
505 "STATUS_UNEXPECTED_NETWORK_ERROR"},
506 {STATUS_BAD_REMOTE_ADAPTER, -EIO, "STATUS_BAD_REMOTE_ADAPTER"},
507 {STATUS_PRINT_QUEUE_FULL, -EIO, "STATUS_PRINT_QUEUE_FULL"},
508 {STATUS_NO_SPOOL_SPACE, -EIO, "STATUS_NO_SPOOL_SPACE"},
509 {STATUS_PRINT_CANCELLED, -EIO, "STATUS_PRINT_CANCELLED"},
510 {STATUS_NETWORK_NAME_DELETED, -EIO, "STATUS_NETWORK_NAME_DELETED"},
511 {STATUS_NETWORK_ACCESS_DENIED, -EACCES, "STATUS_NETWORK_ACCESS_DENIED"},
512 {STATUS_BAD_DEVICE_TYPE, -EIO, "STATUS_BAD_DEVICE_TYPE"},
513 {STATUS_BAD_NETWORK_NAME, -ENOENT, "STATUS_BAD_NETWORK_NAME"},
514 {STATUS_TOO_MANY_NAMES, -EIO, "STATUS_TOO_MANY_NAMES"},
515 {STATUS_TOO_MANY_SESSIONS, -EIO, "STATUS_TOO_MANY_SESSIONS"},
516 {STATUS_SHARING_PAUSED, -EIO, "STATUS_SHARING_PAUSED"},
517 {STATUS_REQUEST_NOT_ACCEPTED, -EIO, "STATUS_REQUEST_NOT_ACCEPTED"},
518 {STATUS_REDIRECTOR_PAUSED, -EIO, "STATUS_REDIRECTOR_PAUSED"},
519 {STATUS_NET_WRITE_FAULT, -EIO, "STATUS_NET_WRITE_FAULT"},
520 {STATUS_PROFILING_AT_LIMIT, -EIO, "STATUS_PROFILING_AT_LIMIT"},
521 {STATUS_NOT_SAME_DEVICE, -EXDEV, "STATUS_NOT_SAME_DEVICE"},
522 {STATUS_FILE_RENAMED, -EIO, "STATUS_FILE_RENAMED"},
523 {STATUS_VIRTUAL_CIRCUIT_CLOSED, -EIO, "STATUS_VIRTUAL_CIRCUIT_CLOSED"},
524 {STATUS_NO_SECURITY_ON_OBJECT, -EIO, "STATUS_NO_SECURITY_ON_OBJECT"},
525 {STATUS_CANT_WAIT, -EIO, "STATUS_CANT_WAIT"},
526 {STATUS_PIPE_EMPTY, -EIO, "STATUS_PIPE_EMPTY"},
527 {STATUS_CANT_ACCESS_DOMAIN_INFO, -EIO,
528 "STATUS_CANT_ACCESS_DOMAIN_INFO"},
529 {STATUS_CANT_TERMINATE_SELF, -EIO, "STATUS_CANT_TERMINATE_SELF"},
530 {STATUS_INVALID_SERVER_STATE, -EIO, "STATUS_INVALID_SERVER_STATE"},
531 {STATUS_INVALID_DOMAIN_STATE, -EIO, "STATUS_INVALID_DOMAIN_STATE"},
532 {STATUS_INVALID_DOMAIN_ROLE, -EIO, "STATUS_INVALID_DOMAIN_ROLE"},
533 {STATUS_NO_SUCH_DOMAIN, -EIO, "STATUS_NO_SUCH_DOMAIN"},
534 {STATUS_DOMAIN_EXISTS, -EIO, "STATUS_DOMAIN_EXISTS"},
535 {STATUS_DOMAIN_LIMIT_EXCEEDED, -EIO, "STATUS_DOMAIN_LIMIT_EXCEEDED"},
536 {STATUS_OPLOCK_NOT_GRANTED, -EIO, "STATUS_OPLOCK_NOT_GRANTED"},
537 {STATUS_INVALID_OPLOCK_PROTOCOL, -EIO,
538 "STATUS_INVALID_OPLOCK_PROTOCOL"},
539 {STATUS_INTERNAL_DB_CORRUPTION, -EIO, "STATUS_INTERNAL_DB_CORRUPTION"},
540 {STATUS_INTERNAL_ERROR, -EIO, "STATUS_INTERNAL_ERROR"},
541 {STATUS_GENERIC_NOT_MAPPED, -EIO, "STATUS_GENERIC_NOT_MAPPED"},
542 {STATUS_BAD_DESCRIPTOR_FORMAT, -EIO, "STATUS_BAD_DESCRIPTOR_FORMAT"},
543 {STATUS_INVALID_USER_BUFFER, -EIO, "STATUS_INVALID_USER_BUFFER"},
544 {STATUS_UNEXPECTED_IO_ERROR, -EIO, "STATUS_UNEXPECTED_IO_ERROR"},
545 {STATUS_UNEXPECTED_MM_CREATE_ERR, -EIO,
546 "STATUS_UNEXPECTED_MM_CREATE_ERR"},
547 {STATUS_UNEXPECTED_MM_MAP_ERROR, -EIO,
548 "STATUS_UNEXPECTED_MM_MAP_ERROR"},
549 {STATUS_UNEXPECTED_MM_EXTEND_ERR, -EIO,
550 "STATUS_UNEXPECTED_MM_EXTEND_ERR"},
551 {STATUS_NOT_LOGON_PROCESS, -EIO, "STATUS_NOT_LOGON_PROCESS"},
552 {STATUS_LOGON_SESSION_EXISTS, -EIO, "STATUS_LOGON_SESSION_EXISTS"},
553 {STATUS_INVALID_PARAMETER_1, -EINVAL, "STATUS_INVALID_PARAMETER_1"},
554 {STATUS_INVALID_PARAMETER_2, -EINVAL, "STATUS_INVALID_PARAMETER_2"},
555 {STATUS_INVALID_PARAMETER_3, -EINVAL, "STATUS_INVALID_PARAMETER_3"},
556 {STATUS_INVALID_PARAMETER_4, -EINVAL, "STATUS_INVALID_PARAMETER_4"},
557 {STATUS_INVALID_PARAMETER_5, -EINVAL, "STATUS_INVALID_PARAMETER_5"},
558 {STATUS_INVALID_PARAMETER_6, -EINVAL, "STATUS_INVALID_PARAMETER_6"},
559 {STATUS_INVALID_PARAMETER_7, -EINVAL, "STATUS_INVALID_PARAMETER_7"},
560 {STATUS_INVALID_PARAMETER_8, -EINVAL, "STATUS_INVALID_PARAMETER_8"},
561 {STATUS_INVALID_PARAMETER_9, -EINVAL, "STATUS_INVALID_PARAMETER_9"},
562 {STATUS_INVALID_PARAMETER_10, -EINVAL, "STATUS_INVALID_PARAMETER_10"},
563 {STATUS_INVALID_PARAMETER_11, -EINVAL, "STATUS_INVALID_PARAMETER_11"},
564 {STATUS_INVALID_PARAMETER_12, -EINVAL, "STATUS_INVALID_PARAMETER_12"},
565 {STATUS_REDIRECTOR_NOT_STARTED, -EIO, "STATUS_REDIRECTOR_NOT_STARTED"},
566 {STATUS_REDIRECTOR_STARTED, -EIO, "STATUS_REDIRECTOR_STARTED"},
567 {STATUS_STACK_OVERFLOW, -EIO, "STATUS_STACK_OVERFLOW"},
568 {STATUS_NO_SUCH_PACKAGE, -EIO, "STATUS_NO_SUCH_PACKAGE"},
569 {STATUS_BAD_FUNCTION_TABLE, -EIO, "STATUS_BAD_FUNCTION_TABLE"},
570 {STATUS_VARIABLE_NOT_FOUND, -EIO, "STATUS_VARIABLE_NOT_FOUND"},
571 {STATUS_DIRECTORY_NOT_EMPTY, -ENOTEMPTY, "STATUS_DIRECTORY_NOT_EMPTY"},
572 {STATUS_FILE_CORRUPT_ERROR, -EIO, "STATUS_FILE_CORRUPT_ERROR"},
573 {STATUS_NOT_A_DIRECTORY, -ENOTDIR, "STATUS_NOT_A_DIRECTORY"},
574 {STATUS_BAD_LOGON_SESSION_STATE, -EIO,
575 "STATUS_BAD_LOGON_SESSION_STATE"},
576 {STATUS_LOGON_SESSION_COLLISION, -EIO,
577 "STATUS_LOGON_SESSION_COLLISION"},
578 {STATUS_NAME_TOO_LONG, -ENAMETOOLONG, "STATUS_NAME_TOO_LONG"},
579 {STATUS_FILES_OPEN, -EIO, "STATUS_FILES_OPEN"},
580 {STATUS_CONNECTION_IN_USE, -EIO, "STATUS_CONNECTION_IN_USE"},
581 {STATUS_MESSAGE_NOT_FOUND, -EIO, "STATUS_MESSAGE_NOT_FOUND"},
582 {STATUS_PROCESS_IS_TERMINATING, -EIO, "STATUS_PROCESS_IS_TERMINATING"},
583 {STATUS_INVALID_LOGON_TYPE, -EIO, "STATUS_INVALID_LOGON_TYPE"},
584 {STATUS_NO_GUID_TRANSLATION, -EIO, "STATUS_NO_GUID_TRANSLATION"},
585 {STATUS_CANNOT_IMPERSONATE, -EIO, "STATUS_CANNOT_IMPERSONATE"},
586 {STATUS_IMAGE_ALREADY_LOADED, -EIO, "STATUS_IMAGE_ALREADY_LOADED"},
587 {STATUS_ABIOS_NOT_PRESENT, -EIO, "STATUS_ABIOS_NOT_PRESENT"},
588 {STATUS_ABIOS_LID_NOT_EXIST, -EIO, "STATUS_ABIOS_LID_NOT_EXIST"},
589 {STATUS_ABIOS_LID_ALREADY_OWNED, -EIO,
590 "STATUS_ABIOS_LID_ALREADY_OWNED"},
591 {STATUS_ABIOS_NOT_LID_OWNER, -EIO, "STATUS_ABIOS_NOT_LID_OWNER"},
592 {STATUS_ABIOS_INVALID_COMMAND, -EIO, "STATUS_ABIOS_INVALID_COMMAND"},
593 {STATUS_ABIOS_INVALID_LID, -EIO, "STATUS_ABIOS_INVALID_LID"},
594 {STATUS_ABIOS_SELECTOR_NOT_AVAILABLE, -EIO,
595 "STATUS_ABIOS_SELECTOR_NOT_AVAILABLE"},
596 {STATUS_ABIOS_INVALID_SELECTOR, -EIO, "STATUS_ABIOS_INVALID_SELECTOR"},
597 {STATUS_NO_LDT, -EIO, "STATUS_NO_LDT"},
598 {STATUS_INVALID_LDT_SIZE, -EIO, "STATUS_INVALID_LDT_SIZE"},
599 {STATUS_INVALID_LDT_OFFSET, -EIO, "STATUS_INVALID_LDT_OFFSET"},
600 {STATUS_INVALID_LDT_DESCRIPTOR, -EIO, "STATUS_INVALID_LDT_DESCRIPTOR"},
601 {STATUS_INVALID_IMAGE_NE_FORMAT, -EIO,
602 "STATUS_INVALID_IMAGE_NE_FORMAT"},
603 {STATUS_RXACT_INVALID_STATE, -EIO, "STATUS_RXACT_INVALID_STATE"},
604 {STATUS_RXACT_COMMIT_FAILURE, -EIO, "STATUS_RXACT_COMMIT_FAILURE"},
605 {STATUS_MAPPED_FILE_SIZE_ZERO, -EIO, "STATUS_MAPPED_FILE_SIZE_ZERO"},
606 {STATUS_TOO_MANY_OPENED_FILES, -EMFILE, "STATUS_TOO_MANY_OPENED_FILES"},
607 {STATUS_CANCELLED, -EIO, "STATUS_CANCELLED"},
608 {STATUS_CANNOT_DELETE, -EIO, "STATUS_CANNOT_DELETE"},
609 {STATUS_INVALID_COMPUTER_NAME, -EIO, "STATUS_INVALID_COMPUTER_NAME"},
610 {STATUS_FILE_DELETED, -EIO, "STATUS_FILE_DELETED"},
611 {STATUS_SPECIAL_ACCOUNT, -EIO, "STATUS_SPECIAL_ACCOUNT"},
612 {STATUS_SPECIAL_GROUP, -EIO, "STATUS_SPECIAL_GROUP"},
613 {STATUS_SPECIAL_USER, -EIO, "STATUS_SPECIAL_USER"},
614 {STATUS_MEMBERS_PRIMARY_GROUP, -EIO, "STATUS_MEMBERS_PRIMARY_GROUP"},
615 {STATUS_FILE_CLOSED, -EBADF, "STATUS_FILE_CLOSED"},
616 {STATUS_TOO_MANY_THREADS, -EIO, "STATUS_TOO_MANY_THREADS"},
617 {STATUS_THREAD_NOT_IN_PROCESS, -EIO, "STATUS_THREAD_NOT_IN_PROCESS"},
618 {STATUS_TOKEN_ALREADY_IN_USE, -EIO, "STATUS_TOKEN_ALREADY_IN_USE"},
619 {STATUS_PAGEFILE_QUOTA_EXCEEDED, -EDQUOT,
620 "STATUS_PAGEFILE_QUOTA_EXCEEDED"},
621 {STATUS_COMMITMENT_LIMIT, -EIO, "STATUS_COMMITMENT_LIMIT"},
622 {STATUS_INVALID_IMAGE_LE_FORMAT, -EIO,
623 "STATUS_INVALID_IMAGE_LE_FORMAT"},
624 {STATUS_INVALID_IMAGE_NOT_MZ, -EIO, "STATUS_INVALID_IMAGE_NOT_MZ"},
625 {STATUS_INVALID_IMAGE_PROTECT, -EIO, "STATUS_INVALID_IMAGE_PROTECT"},
626 {STATUS_INVALID_IMAGE_WIN_16, -EIO, "STATUS_INVALID_IMAGE_WIN_16"},
627 {STATUS_LOGON_SERVER_CONFLICT, -EIO, "STATUS_LOGON_SERVER_CONFLICT"},
628 {STATUS_TIME_DIFFERENCE_AT_DC, -EIO, "STATUS_TIME_DIFFERENCE_AT_DC"},
629 {STATUS_SYNCHRONIZATION_REQUIRED, -EIO,
630 "STATUS_SYNCHRONIZATION_REQUIRED"},
631 {STATUS_DLL_NOT_FOUND, -ENOENT, "STATUS_DLL_NOT_FOUND"},
632 {STATUS_OPEN_FAILED, -EIO, "STATUS_OPEN_FAILED"},
633 {STATUS_IO_PRIVILEGE_FAILED, -EIO, "STATUS_IO_PRIVILEGE_FAILED"},
634 {STATUS_ORDINAL_NOT_FOUND, -EIO, "STATUS_ORDINAL_NOT_FOUND"},
635 {STATUS_ENTRYPOINT_NOT_FOUND, -EIO, "STATUS_ENTRYPOINT_NOT_FOUND"},
636 {STATUS_CONTROL_C_EXIT, -EIO, "STATUS_CONTROL_C_EXIT"},
637 {STATUS_LOCAL_DISCONNECT, -EIO, "STATUS_LOCAL_DISCONNECT"},
638 {STATUS_REMOTE_DISCONNECT, -ESHUTDOWN, "STATUS_REMOTE_DISCONNECT"},
639 {STATUS_REMOTE_RESOURCES, -EIO, "STATUS_REMOTE_RESOURCES"},
640 {STATUS_LINK_FAILED, -EXDEV, "STATUS_LINK_FAILED"},
641 {STATUS_LINK_TIMEOUT, -ETIMEDOUT, "STATUS_LINK_TIMEOUT"},
642 {STATUS_INVALID_CONNECTION, -EIO, "STATUS_INVALID_CONNECTION"},
643 {STATUS_INVALID_ADDRESS, -EIO, "STATUS_INVALID_ADDRESS"},
644 {STATUS_DLL_INIT_FAILED, -EIO, "STATUS_DLL_INIT_FAILED"},
645 {STATUS_MISSING_SYSTEMFILE, -EIO, "STATUS_MISSING_SYSTEMFILE"},
646 {STATUS_UNHANDLED_EXCEPTION, -EIO, "STATUS_UNHANDLED_EXCEPTION"},
647 {STATUS_APP_INIT_FAILURE, -EIO, "STATUS_APP_INIT_FAILURE"},
648 {STATUS_PAGEFILE_CREATE_FAILED, -EIO, "STATUS_PAGEFILE_CREATE_FAILED"},
649 {STATUS_NO_PAGEFILE, -EIO, "STATUS_NO_PAGEFILE"},
650 {STATUS_INVALID_LEVEL, -EIO, "STATUS_INVALID_LEVEL"},
651 {STATUS_WRONG_PASSWORD_CORE, -EIO, "STATUS_WRONG_PASSWORD_CORE"},
652 {STATUS_ILLEGAL_FLOAT_CONTEXT, -EIO, "STATUS_ILLEGAL_FLOAT_CONTEXT"},
653 {STATUS_PIPE_BROKEN, -EPIPE, "STATUS_PIPE_BROKEN"},
654 {STATUS_REGISTRY_CORRUPT, -EIO, "STATUS_REGISTRY_CORRUPT"},
655 {STATUS_REGISTRY_IO_FAILED, -EIO, "STATUS_REGISTRY_IO_FAILED"},
656 {STATUS_NO_EVENT_PAIR, -EIO, "STATUS_NO_EVENT_PAIR"},
657 {STATUS_UNRECOGNIZED_VOLUME, -EIO, "STATUS_UNRECOGNIZED_VOLUME"},
658 {STATUS_SERIAL_NO_DEVICE_INITED, -EIO,
659 "STATUS_SERIAL_NO_DEVICE_INITED"},
660 {STATUS_NO_SUCH_ALIAS, -EIO, "STATUS_NO_SUCH_ALIAS"},
661 {STATUS_MEMBER_NOT_IN_ALIAS, -EIO, "STATUS_MEMBER_NOT_IN_ALIAS"},
662 {STATUS_MEMBER_IN_ALIAS, -EIO, "STATUS_MEMBER_IN_ALIAS"},
663 {STATUS_ALIAS_EXISTS, -EIO, "STATUS_ALIAS_EXISTS"},
664 {STATUS_LOGON_NOT_GRANTED, -EIO, "STATUS_LOGON_NOT_GRANTED"},
665 {STATUS_TOO_MANY_SECRETS, -EIO, "STATUS_TOO_MANY_SECRETS"},
666 {STATUS_SECRET_TOO_LONG, -EIO, "STATUS_SECRET_TOO_LONG"},
667 {STATUS_INTERNAL_DB_ERROR, -EIO, "STATUS_INTERNAL_DB_ERROR"},
668 {STATUS_FULLSCREEN_MODE, -EIO, "STATUS_FULLSCREEN_MODE"},
669 {STATUS_TOO_MANY_CONTEXT_IDS, -EIO, "STATUS_TOO_MANY_CONTEXT_IDS"},
670 {STATUS_LOGON_TYPE_NOT_GRANTED, -EIO, "STATUS_LOGON_TYPE_NOT_GRANTED"},
671 {STATUS_NOT_REGISTRY_FILE, -EIO, "STATUS_NOT_REGISTRY_FILE"},
672 {STATUS_NT_CROSS_ENCRYPTION_REQUIRED, -EIO,
673 "STATUS_NT_CROSS_ENCRYPTION_REQUIRED"},
674 {STATUS_DOMAIN_CTRLR_CONFIG_ERROR, -EIO,
675 "STATUS_DOMAIN_CTRLR_CONFIG_ERROR"},
676 {STATUS_FT_MISSING_MEMBER, -EIO, "STATUS_FT_MISSING_MEMBER"},
677 {STATUS_ILL_FORMED_SERVICE_ENTRY, -EIO,
678 "STATUS_ILL_FORMED_SERVICE_ENTRY"},
679 {STATUS_ILLEGAL_CHARACTER, -EIO, "STATUS_ILLEGAL_CHARACTER"},
680 {STATUS_UNMAPPABLE_CHARACTER, -EIO, "STATUS_UNMAPPABLE_CHARACTER"},
681 {STATUS_UNDEFINED_CHARACTER, -EIO, "STATUS_UNDEFINED_CHARACTER"},
682 {STATUS_FLOPPY_VOLUME, -EIO, "STATUS_FLOPPY_VOLUME"},
683 {STATUS_FLOPPY_ID_MARK_NOT_FOUND, -EIO,
684 "STATUS_FLOPPY_ID_MARK_NOT_FOUND"},
685 {STATUS_FLOPPY_WRONG_CYLINDER, -EIO, "STATUS_FLOPPY_WRONG_CYLINDER"},
686 {STATUS_FLOPPY_UNKNOWN_ERROR, -EIO, "STATUS_FLOPPY_UNKNOWN_ERROR"},
687 {STATUS_FLOPPY_BAD_REGISTERS, -EIO, "STATUS_FLOPPY_BAD_REGISTERS"},
688 {STATUS_DISK_RECALIBRATE_FAILED, -EIO,
689 "STATUS_DISK_RECALIBRATE_FAILED"},
690 {STATUS_DISK_OPERATION_FAILED, -EIO, "STATUS_DISK_OPERATION_FAILED"},
691 {STATUS_DISK_RESET_FAILED, -EIO, "STATUS_DISK_RESET_FAILED"},
692 {STATUS_SHARED_IRQ_BUSY, -EBUSY, "STATUS_SHARED_IRQ_BUSY"},
693 {STATUS_FT_ORPHANING, -EIO, "STATUS_FT_ORPHANING"},
694 {STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT, -EIO,
695 "STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT"},
696 {STATUS_PARTITION_FAILURE, -EIO, "STATUS_PARTITION_FAILURE"},
697 {STATUS_INVALID_BLOCK_LENGTH, -EIO, "STATUS_INVALID_BLOCK_LENGTH"},
698 {STATUS_DEVICE_NOT_PARTITIONED, -EIO, "STATUS_DEVICE_NOT_PARTITIONED"},
699 {STATUS_UNABLE_TO_LOCK_MEDIA, -EIO, "STATUS_UNABLE_TO_LOCK_MEDIA"},
700 {STATUS_UNABLE_TO_UNLOAD_MEDIA, -EIO, "STATUS_UNABLE_TO_UNLOAD_MEDIA"},
701 {STATUS_EOM_OVERFLOW, -EIO, "STATUS_EOM_OVERFLOW"},
702 {STATUS_NO_MEDIA, -EIO, "STATUS_NO_MEDIA"},
703 {STATUS_NO_SUCH_MEMBER, -EIO, "STATUS_NO_SUCH_MEMBER"},
704 {STATUS_INVALID_MEMBER, -EIO, "STATUS_INVALID_MEMBER"},
705 {STATUS_KEY_DELETED, -EIO, "STATUS_KEY_DELETED"},
706 {STATUS_NO_LOG_SPACE, -EIO, "STATUS_NO_LOG_SPACE"},
707 {STATUS_TOO_MANY_SIDS, -EIO, "STATUS_TOO_MANY_SIDS"},
708 {STATUS_LM_CROSS_ENCRYPTION_REQUIRED, -EIO,
709 "STATUS_LM_CROSS_ENCRYPTION_REQUIRED"},
710 {STATUS_KEY_HAS_CHILDREN, -EIO, "STATUS_KEY_HAS_CHILDREN"},
711 {STATUS_CHILD_MUST_BE_VOLATILE, -EIO, "STATUS_CHILD_MUST_BE_VOLATILE"},
712 {STATUS_DEVICE_CONFIGURATION_ERROR, -EIO,
713 "STATUS_DEVICE_CONFIGURATION_ERROR"},
714 {STATUS_DRIVER_INTERNAL_ERROR, -EIO, "STATUS_DRIVER_INTERNAL_ERROR"},
715 {STATUS_INVALID_DEVICE_STATE, -EIO, "STATUS_INVALID_DEVICE_STATE"},
716 {STATUS_IO_DEVICE_ERROR, -EIO, "STATUS_IO_DEVICE_ERROR"},
717 {STATUS_DEVICE_PROTOCOL_ERROR, -EIO, "STATUS_DEVICE_PROTOCOL_ERROR"},
718 {STATUS_BACKUP_CONTROLLER, -EIO, "STATUS_BACKUP_CONTROLLER"},
719 {STATUS_LOG_FILE_FULL, -EIO, "STATUS_LOG_FILE_FULL"},
720 {STATUS_TOO_LATE, -EIO, "STATUS_TOO_LATE"},
721 {STATUS_NO_TRUST_LSA_SECRET, -EIO, "STATUS_NO_TRUST_LSA_SECRET"},
722 {STATUS_NO_TRUST_SAM_ACCOUNT, -EIO, "STATUS_NO_TRUST_SAM_ACCOUNT"},
723 {STATUS_TRUSTED_DOMAIN_FAILURE, -EIO, "STATUS_TRUSTED_DOMAIN_FAILURE"},
724 {STATUS_TRUSTED_RELATIONSHIP_FAILURE, -EIO,
725 "STATUS_TRUSTED_RELATIONSHIP_FAILURE"},
726 {STATUS_EVENTLOG_FILE_CORRUPT, -EIO, "STATUS_EVENTLOG_FILE_CORRUPT"},
727 {STATUS_EVENTLOG_CANT_START, -EIO, "STATUS_EVENTLOG_CANT_START"},
728 {STATUS_TRUST_FAILURE, -EIO, "STATUS_TRUST_FAILURE"},
729 {STATUS_MUTANT_LIMIT_EXCEEDED, -EIO, "STATUS_MUTANT_LIMIT_EXCEEDED"},
730 {STATUS_NETLOGON_NOT_STARTED, -EIO, "STATUS_NETLOGON_NOT_STARTED"},
731 {STATUS_ACCOUNT_EXPIRED, -EKEYEXPIRED, "STATUS_ACCOUNT_EXPIRED"},
732 {STATUS_POSSIBLE_DEADLOCK, -EIO, "STATUS_POSSIBLE_DEADLOCK"},
733 {STATUS_NETWORK_CREDENTIAL_CONFLICT, -EIO,
734 "STATUS_NETWORK_CREDENTIAL_CONFLICT"},
735 {STATUS_REMOTE_SESSION_LIMIT, -EIO, "STATUS_REMOTE_SESSION_LIMIT"},
736 {STATUS_EVENTLOG_FILE_CHANGED, -EIO, "STATUS_EVENTLOG_FILE_CHANGED"},
737 {STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT, -EIO,
738 "STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT"},
739 {STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT, -EIO,
740 "STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT"},
741 {STATUS_NOLOGON_SERVER_TRUST_ACCOUNT, -EIO,
742 "STATUS_NOLOGON_SERVER_TRUST_ACCOUNT"},
743 {STATUS_DOMAIN_TRUST_INCONSISTENT, -EIO,
744 "STATUS_DOMAIN_TRUST_INCONSISTENT"},
745 {STATUS_FS_DRIVER_REQUIRED, -EIO, "STATUS_FS_DRIVER_REQUIRED"},
746 {STATUS_IMAGE_ALREADY_LOADED_AS_DLL, -EIO,
747 "STATUS_IMAGE_ALREADY_LOADED_AS_DLL"},
748 {STATUS_NETWORK_OPEN_RESTRICTION, -EIO,
749 "STATUS_NETWORK_OPEN_RESTRICTION"},
750 {STATUS_NO_USER_SESSION_KEY, -EIO, "STATUS_NO_USER_SESSION_KEY"},
751 {STATUS_USER_SESSION_DELETED, -EIO, "STATUS_USER_SESSION_DELETED"},
752 {STATUS_RESOURCE_LANG_NOT_FOUND, -EIO,
753 "STATUS_RESOURCE_LANG_NOT_FOUND"},
754 {STATUS_INSUFF_SERVER_RESOURCES, -EIO,
755 "STATUS_INSUFF_SERVER_RESOURCES"},
756 {STATUS_INVALID_BUFFER_SIZE, -EIO, "STATUS_INVALID_BUFFER_SIZE"},
757 {STATUS_INVALID_ADDRESS_COMPONENT, -EIO,
758 "STATUS_INVALID_ADDRESS_COMPONENT"},
759 {STATUS_INVALID_ADDRESS_WILDCARD, -EIO,
760 "STATUS_INVALID_ADDRESS_WILDCARD"},
761 {STATUS_TOO_MANY_ADDRESSES, -EIO, "STATUS_TOO_MANY_ADDRESSES"},
762 {STATUS_ADDRESS_ALREADY_EXISTS, -EADDRINUSE,
763 "STATUS_ADDRESS_ALREADY_EXISTS"},
764 {STATUS_ADDRESS_CLOSED, -EIO, "STATUS_ADDRESS_CLOSED"},
765 {STATUS_CONNECTION_DISCONNECTED, -ECONNABORTED,
766 "STATUS_CONNECTION_DISCONNECTED"},
767 {STATUS_CONNECTION_RESET, -ENETRESET, "STATUS_CONNECTION_RESET"},
768 {STATUS_TOO_MANY_NODES, -EIO, "STATUS_TOO_MANY_NODES"},
769 {STATUS_TRANSACTION_ABORTED, -EIO, "STATUS_TRANSACTION_ABORTED"},
770 {STATUS_TRANSACTION_TIMED_OUT, -EIO, "STATUS_TRANSACTION_TIMED_OUT"},
771 {STATUS_TRANSACTION_NO_RELEASE, -EIO, "STATUS_TRANSACTION_NO_RELEASE"},
772 {STATUS_TRANSACTION_NO_MATCH, -EIO, "STATUS_TRANSACTION_NO_MATCH"},
773 {STATUS_TRANSACTION_RESPONDED, -EIO, "STATUS_TRANSACTION_RESPONDED"},
774 {STATUS_TRANSACTION_INVALID_ID, -EIO, "STATUS_TRANSACTION_INVALID_ID"},
775 {STATUS_TRANSACTION_INVALID_TYPE, -EIO,
776 "STATUS_TRANSACTION_INVALID_TYPE"},
777 {STATUS_NOT_SERVER_SESSION, -EIO, "STATUS_NOT_SERVER_SESSION"},
778 {STATUS_NOT_CLIENT_SESSION, -EIO, "STATUS_NOT_CLIENT_SESSION"},
779 {STATUS_CANNOT_LOAD_REGISTRY_FILE, -EIO,
780 "STATUS_CANNOT_LOAD_REGISTRY_FILE"},
781 {STATUS_DEBUG_ATTACH_FAILED, -EIO, "STATUS_DEBUG_ATTACH_FAILED"},
782 {STATUS_SYSTEM_PROCESS_TERMINATED, -EIO,
783 "STATUS_SYSTEM_PROCESS_TERMINATED"},
784 {STATUS_DATA_NOT_ACCEPTED, -EIO, "STATUS_DATA_NOT_ACCEPTED"},
785 {STATUS_NO_BROWSER_SERVERS_FOUND, -EIO,
786 "STATUS_NO_BROWSER_SERVERS_FOUND"},
787 {STATUS_VDM_HARD_ERROR, -EIO, "STATUS_VDM_HARD_ERROR"},
788 {STATUS_DRIVER_CANCEL_TIMEOUT, -EIO, "STATUS_DRIVER_CANCEL_TIMEOUT"},
789 {STATUS_REPLY_MESSAGE_MISMATCH, -EIO, "STATUS_REPLY_MESSAGE_MISMATCH"},
790 {STATUS_MAPPED_ALIGNMENT, -EIO, "STATUS_MAPPED_ALIGNMENT"},
791 {STATUS_IMAGE_CHECKSUM_MISMATCH, -EIO,
792 "STATUS_IMAGE_CHECKSUM_MISMATCH"},
793 {STATUS_LOST_WRITEBEHIND_DATA, -EIO, "STATUS_LOST_WRITEBEHIND_DATA"},
794 {STATUS_CLIENT_SERVER_PARAMETERS_INVALID, -EIO,
795 "STATUS_CLIENT_SERVER_PARAMETERS_INVALID"},
796 {STATUS_PASSWORD_MUST_CHANGE, -EIO, "STATUS_PASSWORD_MUST_CHANGE"},
797 {STATUS_NOT_FOUND, -ENOENT, "STATUS_NOT_FOUND"},
798 {STATUS_NOT_TINY_STREAM, -EIO, "STATUS_NOT_TINY_STREAM"},
799 {STATUS_RECOVERY_FAILURE, -EIO, "STATUS_RECOVERY_FAILURE"},
800 {STATUS_STACK_OVERFLOW_READ, -EIO, "STATUS_STACK_OVERFLOW_READ"},
801 {STATUS_FAIL_CHECK, -EIO, "STATUS_FAIL_CHECK"},
802 {STATUS_DUPLICATE_OBJECTID, -EIO, "STATUS_DUPLICATE_OBJECTID"},
803 {STATUS_OBJECTID_EXISTS, -EIO, "STATUS_OBJECTID_EXISTS"},
804 {STATUS_CONVERT_TO_LARGE, -EIO, "STATUS_CONVERT_TO_LARGE"},
805 {STATUS_RETRY, -EAGAIN, "STATUS_RETRY"},
806 {STATUS_FOUND_OUT_OF_SCOPE, -EIO, "STATUS_FOUND_OUT_OF_SCOPE"},
807 {STATUS_ALLOCATE_BUCKET, -EIO, "STATUS_ALLOCATE_BUCKET"},
808 {STATUS_PROPSET_NOT_FOUND, -EIO, "STATUS_PROPSET_NOT_FOUND"},
809 {STATUS_MARSHALL_OVERFLOW, -EIO, "STATUS_MARSHALL_OVERFLOW"},
810 {STATUS_INVALID_VARIANT, -EIO, "STATUS_INVALID_VARIANT"},
811 {STATUS_DOMAIN_CONTROLLER_NOT_FOUND, -EIO,
812 "STATUS_DOMAIN_CONTROLLER_NOT_FOUND"},
813 {STATUS_ACCOUNT_LOCKED_OUT, -EIO, "STATUS_ACCOUNT_LOCKED_OUT"},
814 {STATUS_HANDLE_NOT_CLOSABLE, -EIO, "STATUS_HANDLE_NOT_CLOSABLE"},
815 {STATUS_CONNECTION_REFUSED, -EIO, "STATUS_CONNECTION_REFUSED"},
816 {STATUS_GRACEFUL_DISCONNECT, -EIO, "STATUS_GRACEFUL_DISCONNECT"},
817 {STATUS_ADDRESS_ALREADY_ASSOCIATED, -EIO,
818 "STATUS_ADDRESS_ALREADY_ASSOCIATED"},
819 {STATUS_ADDRESS_NOT_ASSOCIATED, -EIO, "STATUS_ADDRESS_NOT_ASSOCIATED"},
820 {STATUS_CONNECTION_INVALID, -EIO, "STATUS_CONNECTION_INVALID"},
821 {STATUS_CONNECTION_ACTIVE, -EIO, "STATUS_CONNECTION_ACTIVE"},
822 {STATUS_NETWORK_UNREACHABLE, -ENETUNREACH,
823 "STATUS_NETWORK_UNREACHABLE"},
824 {STATUS_HOST_UNREACHABLE, -EHOSTDOWN, "STATUS_HOST_UNREACHABLE"},
825 {STATUS_PROTOCOL_UNREACHABLE, -ENETUNREACH,
826 "STATUS_PROTOCOL_UNREACHABLE"},
827 {STATUS_PORT_UNREACHABLE, -ENETUNREACH, "STATUS_PORT_UNREACHABLE"},
828 {STATUS_REQUEST_ABORTED, -EIO, "STATUS_REQUEST_ABORTED"},
829 {STATUS_CONNECTION_ABORTED, -ECONNABORTED, "STATUS_CONNECTION_ABORTED"},
830 {STATUS_BAD_COMPRESSION_BUFFER, -EIO, "STATUS_BAD_COMPRESSION_BUFFER"},
831 {STATUS_USER_MAPPED_FILE, -EIO, "STATUS_USER_MAPPED_FILE"},
832 {STATUS_AUDIT_FAILED, -EIO, "STATUS_AUDIT_FAILED"},
833 {STATUS_TIMER_RESOLUTION_NOT_SET, -EIO,
834 "STATUS_TIMER_RESOLUTION_NOT_SET"},
835 {STATUS_CONNECTION_COUNT_LIMIT, -EIO, "STATUS_CONNECTION_COUNT_LIMIT"},
836 {STATUS_LOGIN_TIME_RESTRICTION, -EACCES,
837 "STATUS_LOGIN_TIME_RESTRICTION"},
838 {STATUS_LOGIN_WKSTA_RESTRICTION, -EACCES,
839 "STATUS_LOGIN_WKSTA_RESTRICTION"},
840 {STATUS_IMAGE_MP_UP_MISMATCH, -EIO, "STATUS_IMAGE_MP_UP_MISMATCH"},
841 {STATUS_INSUFFICIENT_LOGON_INFO, -EIO,
842 "STATUS_INSUFFICIENT_LOGON_INFO"},
843 {STATUS_BAD_DLL_ENTRYPOINT, -EIO, "STATUS_BAD_DLL_ENTRYPOINT"},
844 {STATUS_BAD_SERVICE_ENTRYPOINT, -EIO, "STATUS_BAD_SERVICE_ENTRYPOINT"},
845 {STATUS_LPC_REPLY_LOST, -EIO, "STATUS_LPC_REPLY_LOST"},
846 {STATUS_IP_ADDRESS_CONFLICT1, -EIO, "STATUS_IP_ADDRESS_CONFLICT1"},
847 {STATUS_IP_ADDRESS_CONFLICT2, -EIO, "STATUS_IP_ADDRESS_CONFLICT2"},
848 {STATUS_REGISTRY_QUOTA_LIMIT, -EDQUOT, "STATUS_REGISTRY_QUOTA_LIMIT"},
849 {STATUS_PATH_NOT_COVERED, -EREMOTE, "STATUS_PATH_NOT_COVERED"},
850 {STATUS_NO_CALLBACK_ACTIVE, -EIO, "STATUS_NO_CALLBACK_ACTIVE"},
851 {STATUS_LICENSE_QUOTA_EXCEEDED, -EACCES,
852 "STATUS_LICENSE_QUOTA_EXCEEDED"},
853 {STATUS_PWD_TOO_SHORT, -EIO, "STATUS_PWD_TOO_SHORT"},
854 {STATUS_PWD_TOO_RECENT, -EIO, "STATUS_PWD_TOO_RECENT"},
855 {STATUS_PWD_HISTORY_CONFLICT, -EIO, "STATUS_PWD_HISTORY_CONFLICT"},
856 {STATUS_PLUGPLAY_NO_DEVICE, -EIO, "STATUS_PLUGPLAY_NO_DEVICE"},
857 {STATUS_UNSUPPORTED_COMPRESSION, -EIO,
858 "STATUS_UNSUPPORTED_COMPRESSION"},
859 {STATUS_INVALID_HW_PROFILE, -EIO, "STATUS_INVALID_HW_PROFILE"},
860 {STATUS_INVALID_PLUGPLAY_DEVICE_PATH, -EIO,
861 "STATUS_INVALID_PLUGPLAY_DEVICE_PATH"},
862 {STATUS_DRIVER_ORDINAL_NOT_FOUND, -EIO,
863 "STATUS_DRIVER_ORDINAL_NOT_FOUND"},
864 {STATUS_DRIVER_ENTRYPOINT_NOT_FOUND, -EIO,
865 "STATUS_DRIVER_ENTRYPOINT_NOT_FOUND"},
866 {STATUS_RESOURCE_NOT_OWNED, -EIO, "STATUS_RESOURCE_NOT_OWNED"},
867 {STATUS_TOO_MANY_LINKS, -EMLINK, "STATUS_TOO_MANY_LINKS"},
868 {STATUS_QUOTA_LIST_INCONSISTENT, -EIO,
869 "STATUS_QUOTA_LIST_INCONSISTENT"},
870 {STATUS_FILE_IS_OFFLINE, -EIO, "STATUS_FILE_IS_OFFLINE"},
871 {STATUS_EVALUATION_EXPIRATION, -EIO, "STATUS_EVALUATION_EXPIRATION"},
872 {STATUS_ILLEGAL_DLL_RELOCATION, -EIO, "STATUS_ILLEGAL_DLL_RELOCATION"},
873 {STATUS_LICENSE_VIOLATION, -EIO, "STATUS_LICENSE_VIOLATION"},
874 {STATUS_DLL_INIT_FAILED_LOGOFF, -EIO, "STATUS_DLL_INIT_FAILED_LOGOFF"},
875 {STATUS_DRIVER_UNABLE_TO_LOAD, -EIO, "STATUS_DRIVER_UNABLE_TO_LOAD"},
876 {STATUS_DFS_UNAVAILABLE, -EIO, "STATUS_DFS_UNAVAILABLE"},
877 {STATUS_VOLUME_DISMOUNTED, -EIO, "STATUS_VOLUME_DISMOUNTED"},
878 {STATUS_WX86_INTERNAL_ERROR, -EIO, "STATUS_WX86_INTERNAL_ERROR"},
879 {STATUS_WX86_FLOAT_STACK_CHECK, -EIO, "STATUS_WX86_FLOAT_STACK_CHECK"},
880 {STATUS_VALIDATE_CONTINUE, -EIO, "STATUS_VALIDATE_CONTINUE"},
881 {STATUS_NO_MATCH, -EIO, "STATUS_NO_MATCH"},
882 {STATUS_NO_MORE_MATCHES, -EIO, "STATUS_NO_MORE_MATCHES"},
883 {STATUS_NOT_A_REPARSE_POINT, -EIO, "STATUS_NOT_A_REPARSE_POINT"},
884 {STATUS_IO_REPARSE_TAG_INVALID, -EIO, "STATUS_IO_REPARSE_TAG_INVALID"},
885 {STATUS_IO_REPARSE_TAG_MISMATCH, -EIO,
886 "STATUS_IO_REPARSE_TAG_MISMATCH"},
887 {STATUS_IO_REPARSE_DATA_INVALID, -EIO,
888 "STATUS_IO_REPARSE_DATA_INVALID"},
889 {STATUS_IO_REPARSE_TAG_NOT_HANDLED, -EIO,
890 "STATUS_IO_REPARSE_TAG_NOT_HANDLED"},
891 {STATUS_REPARSE_POINT_NOT_RESOLVED, -EIO,
892 "STATUS_REPARSE_POINT_NOT_RESOLVED"},
893 {STATUS_DIRECTORY_IS_A_REPARSE_POINT, -EIO,
894 "STATUS_DIRECTORY_IS_A_REPARSE_POINT"},
895 {STATUS_RANGE_LIST_CONFLICT, -EIO, "STATUS_RANGE_LIST_CONFLICT"},
896 {STATUS_SOURCE_ELEMENT_EMPTY, -EIO, "STATUS_SOURCE_ELEMENT_EMPTY"},
897 {STATUS_DESTINATION_ELEMENT_FULL, -EIO,
898 "STATUS_DESTINATION_ELEMENT_FULL"},
899 {STATUS_ILLEGAL_ELEMENT_ADDRESS, -EIO,
900 "STATUS_ILLEGAL_ELEMENT_ADDRESS"},
901 {STATUS_MAGAZINE_NOT_PRESENT, -EIO, "STATUS_MAGAZINE_NOT_PRESENT"},
902 {STATUS_REINITIALIZATION_NEEDED, -EIO,
903 "STATUS_REINITIALIZATION_NEEDED"},
904 {STATUS_ENCRYPTION_FAILED, -EIO, "STATUS_ENCRYPTION_FAILED"},
905 {STATUS_DECRYPTION_FAILED, -EIO, "STATUS_DECRYPTION_FAILED"},
906 {STATUS_RANGE_NOT_FOUND, -EIO, "STATUS_RANGE_NOT_FOUND"},
907 {STATUS_NO_RECOVERY_POLICY, -EIO, "STATUS_NO_RECOVERY_POLICY"},
908 {STATUS_NO_EFS, -EIO, "STATUS_NO_EFS"},
909 {STATUS_WRONG_EFS, -EIO, "STATUS_WRONG_EFS"},
910 {STATUS_NO_USER_KEYS, -EIO, "STATUS_NO_USER_KEYS"},
911 {STATUS_FILE_NOT_ENCRYPTED, -EIO, "STATUS_FILE_NOT_ENCRYPTED"},
912 {STATUS_NOT_EXPORT_FORMAT, -EIO, "STATUS_NOT_EXPORT_FORMAT"},
913 {STATUS_FILE_ENCRYPTED, -EIO, "STATUS_FILE_ENCRYPTED"},
914 {STATUS_WMI_GUID_NOT_FOUND, -EIO, "STATUS_WMI_GUID_NOT_FOUND"},
915 {STATUS_WMI_INSTANCE_NOT_FOUND, -EIO, "STATUS_WMI_INSTANCE_NOT_FOUND"},
916 {STATUS_WMI_ITEMID_NOT_FOUND, -EIO, "STATUS_WMI_ITEMID_NOT_FOUND"},
917 {STATUS_WMI_TRY_AGAIN, -EIO, "STATUS_WMI_TRY_AGAIN"},
918 {STATUS_SHARED_POLICY, -EIO, "STATUS_SHARED_POLICY"},
919 {STATUS_POLICY_OBJECT_NOT_FOUND, -EIO,
920 "STATUS_POLICY_OBJECT_NOT_FOUND"},
921 {STATUS_POLICY_ONLY_IN_DS, -EIO, "STATUS_POLICY_ONLY_IN_DS"},
922 {STATUS_VOLUME_NOT_UPGRADED, -EIO, "STATUS_VOLUME_NOT_UPGRADED"},
923 {STATUS_REMOTE_STORAGE_NOT_ACTIVE, -EIO,
924 "STATUS_REMOTE_STORAGE_NOT_ACTIVE"},
925 {STATUS_REMOTE_STORAGE_MEDIA_ERROR, -EIO,
926 "STATUS_REMOTE_STORAGE_MEDIA_ERROR"},
927 {STATUS_NO_TRACKING_SERVICE, -EIO, "STATUS_NO_TRACKING_SERVICE"},
928 {STATUS_SERVER_SID_MISMATCH, -EIO, "STATUS_SERVER_SID_MISMATCH"},
929 {STATUS_DS_NO_ATTRIBUTE_OR_VALUE, -EIO,
930 "STATUS_DS_NO_ATTRIBUTE_OR_VALUE"},
931 {STATUS_DS_INVALID_ATTRIBUTE_SYNTAX, -EIO,
932 "STATUS_DS_INVALID_ATTRIBUTE_SYNTAX"},
933 {STATUS_DS_ATTRIBUTE_TYPE_UNDEFINED, -EIO,
934 "STATUS_DS_ATTRIBUTE_TYPE_UNDEFINED"},
935 {STATUS_DS_ATTRIBUTE_OR_VALUE_EXISTS, -EIO,
936 "STATUS_DS_ATTRIBUTE_OR_VALUE_EXISTS"},
937 {STATUS_DS_BUSY, -EBUSY, "STATUS_DS_BUSY"},
938 {STATUS_DS_UNAVAILABLE, -EIO, "STATUS_DS_UNAVAILABLE"},
939 {STATUS_DS_NO_RIDS_ALLOCATED, -EIO, "STATUS_DS_NO_RIDS_ALLOCATED"},
940 {STATUS_DS_NO_MORE_RIDS, -EIO, "STATUS_DS_NO_MORE_RIDS"},
941 {STATUS_DS_INCORRECT_ROLE_OWNER, -EIO,
942 "STATUS_DS_INCORRECT_ROLE_OWNER"},
943 {STATUS_DS_RIDMGR_INIT_ERROR, -EIO, "STATUS_DS_RIDMGR_INIT_ERROR"},
944 {STATUS_DS_OBJ_CLASS_VIOLATION, -EIO, "STATUS_DS_OBJ_CLASS_VIOLATION"},
945 {STATUS_DS_CANT_ON_NON_LEAF, -EIO, "STATUS_DS_CANT_ON_NON_LEAF"},
946 {STATUS_DS_CANT_ON_RDN, -EIO, "STATUS_DS_CANT_ON_RDN"},
947 {STATUS_DS_CANT_MOD_OBJ_CLASS, -EIO, "STATUS_DS_CANT_MOD_OBJ_CLASS"},
948 {STATUS_DS_CROSS_DOM_MOVE_FAILED, -EIO,
949 "STATUS_DS_CROSS_DOM_MOVE_FAILED"},
950 {STATUS_DS_GC_NOT_AVAILABLE, -EIO, "STATUS_DS_GC_NOT_AVAILABLE"},
951 {STATUS_DIRECTORY_SERVICE_REQUIRED, -EIO,
952 "STATUS_DIRECTORY_SERVICE_REQUIRED"},
953 {STATUS_REPARSE_ATTRIBUTE_CONFLICT, -EIO,
954 "STATUS_REPARSE_ATTRIBUTE_CONFLICT"},
955 {STATUS_CANT_ENABLE_DENY_ONLY, -EIO, "STATUS_CANT_ENABLE_DENY_ONLY"},
956 {STATUS_FLOAT_MULTIPLE_FAULTS, -EIO, "STATUS_FLOAT_MULTIPLE_FAULTS"},
957 {STATUS_FLOAT_MULTIPLE_TRAPS, -EIO, "STATUS_FLOAT_MULTIPLE_TRAPS"},
958 {STATUS_DEVICE_REMOVED, -EIO, "STATUS_DEVICE_REMOVED"},
959 {STATUS_JOURNAL_DELETE_IN_PROGRESS, -EIO,
960 "STATUS_JOURNAL_DELETE_IN_PROGRESS"},
961 {STATUS_JOURNAL_NOT_ACTIVE, -EIO, "STATUS_JOURNAL_NOT_ACTIVE"},
962 {STATUS_NOINTERFACE, -EIO, "STATUS_NOINTERFACE"},
963 {STATUS_DS_ADMIN_LIMIT_EXCEEDED, -EIO,
964 "STATUS_DS_ADMIN_LIMIT_EXCEEDED"},
965 {STATUS_DRIVER_FAILED_SLEEP, -EIO, "STATUS_DRIVER_FAILED_SLEEP"},
966 {STATUS_MUTUAL_AUTHENTICATION_FAILED, -EIO,
967 "STATUS_MUTUAL_AUTHENTICATION_FAILED"},
968 {STATUS_CORRUPT_SYSTEM_FILE, -EIO, "STATUS_CORRUPT_SYSTEM_FILE"},
969 {STATUS_DATATYPE_MISALIGNMENT_ERROR, -EIO,
970 "STATUS_DATATYPE_MISALIGNMENT_ERROR"},
971 {STATUS_WMI_READ_ONLY, -EROFS, "STATUS_WMI_READ_ONLY"},
972 {STATUS_WMI_SET_FAILURE, -EIO, "STATUS_WMI_SET_FAILURE"},
973 {STATUS_COMMITMENT_MINIMUM, -EIO, "STATUS_COMMITMENT_MINIMUM"},
974 {STATUS_REG_NAT_CONSUMPTION, -EIO, "STATUS_REG_NAT_CONSUMPTION"},
975 {STATUS_TRANSPORT_FULL, -EIO, "STATUS_TRANSPORT_FULL"},
976 {STATUS_DS_SAM_INIT_FAILURE, -EIO, "STATUS_DS_SAM_INIT_FAILURE"},
977 {STATUS_ONLY_IF_CONNECTED, -EIO, "STATUS_ONLY_IF_CONNECTED"},
978 {STATUS_DS_SENSITIVE_GROUP_VIOLATION, -EIO,
979 "STATUS_DS_SENSITIVE_GROUP_VIOLATION"},
980 {STATUS_PNP_RESTART_ENUMERATION, -EIO,
981 "STATUS_PNP_RESTART_ENUMERATION"},
982 {STATUS_JOURNAL_ENTRY_DELETED, -EIO, "STATUS_JOURNAL_ENTRY_DELETED"},
983 {STATUS_DS_CANT_MOD_PRIMARYGROUPID, -EIO,
984 "STATUS_DS_CANT_MOD_PRIMARYGROUPID"},
985 {STATUS_SYSTEM_IMAGE_BAD_SIGNATURE, -EIO,
986 "STATUS_SYSTEM_IMAGE_BAD_SIGNATURE"},
987 {STATUS_PNP_REBOOT_REQUIRED, -EIO, "STATUS_PNP_REBOOT_REQUIRED"},
988 {STATUS_POWER_STATE_INVALID, -EIO, "STATUS_POWER_STATE_INVALID"},
989 {STATUS_DS_INVALID_GROUP_TYPE, -EIO, "STATUS_DS_INVALID_GROUP_TYPE"},
990 {STATUS_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN, -EIO,
991 "STATUS_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN"},
992 {STATUS_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN, -EIO,
993 "STATUS_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN"},
994 {STATUS_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER, -EIO,
995 "STATUS_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER"},
996 {STATUS_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER, -EIO,
997 "STATUS_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER"},
998 {STATUS_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER, -EIO,
999 "STATUS_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER"},
1000 {STATUS_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER, -EIO,
1001 "STATUS_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER"},
1002 {STATUS_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER, -EIO,
1003 "STATUS_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER"},
1004 {STATUS_DS_HAVE_PRIMARY_MEMBERS, -EIO,
1005 "STATUS_DS_HAVE_PRIMARY_MEMBERS"},
1006 {STATUS_WMI_NOT_SUPPORTED, -EOPNOTSUPP, "STATUS_WMI_NOT_SUPPORTED"},
1007 {STATUS_INSUFFICIENT_POWER, -EIO, "STATUS_INSUFFICIENT_POWER"},
1008 {STATUS_SAM_NEED_BOOTKEY_PASSWORD, -EIO,
1009 "STATUS_SAM_NEED_BOOTKEY_PASSWORD"},
1010 {STATUS_SAM_NEED_BOOTKEY_FLOPPY, -EIO,
1011 "STATUS_SAM_NEED_BOOTKEY_FLOPPY"},
1012 {STATUS_DS_CANT_START, -EIO, "STATUS_DS_CANT_START"},
1013 {STATUS_DS_INIT_FAILURE, -EIO, "STATUS_DS_INIT_FAILURE"},
1014 {STATUS_SAM_INIT_FAILURE, -EIO, "STATUS_SAM_INIT_FAILURE"},
1015 {STATUS_DS_GC_REQUIRED, -EIO, "STATUS_DS_GC_REQUIRED"},
1016 {STATUS_DS_LOCAL_MEMBER_OF_LOCAL_ONLY, -EIO,
1017 "STATUS_DS_LOCAL_MEMBER_OF_LOCAL_ONLY"},
1018 {STATUS_DS_NO_FPO_IN_UNIVERSAL_GROUPS, -EIO,
1019 "STATUS_DS_NO_FPO_IN_UNIVERSAL_GROUPS"},
1020 {STATUS_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED, -EDQUOT,
1021 "STATUS_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED"},
1022 {STATUS_MULTIPLE_FAULT_VIOLATION, -EIO,
1023 "STATUS_MULTIPLE_FAULT_VIOLATION"},
1024 {STATUS_CURRENT_DOMAIN_NOT_ALLOWED, -EIO,
1025 "STATUS_CURRENT_DOMAIN_NOT_ALLOWED"},
1026 {STATUS_CANNOT_MAKE, -EIO, "STATUS_CANNOT_MAKE"},
1027 {STATUS_SYSTEM_SHUTDOWN, -EIO, "STATUS_SYSTEM_SHUTDOWN"},
1028 {STATUS_DS_INIT_FAILURE_CONSOLE, -EIO,
1029 "STATUS_DS_INIT_FAILURE_CONSOLE"},
1030 {STATUS_DS_SAM_INIT_FAILURE_CONSOLE, -EIO,
1031 "STATUS_DS_SAM_INIT_FAILURE_CONSOLE"},
1032 {STATUS_UNFINISHED_CONTEXT_DELETED, -EIO,
1033 "STATUS_UNFINISHED_CONTEXT_DELETED"},
1034 {STATUS_NO_TGT_REPLY, -EIO, "STATUS_NO_TGT_REPLY"},
1035 {STATUS_OBJECTID_NOT_FOUND, -EIO, "STATUS_OBJECTID_NOT_FOUND"},
1036 {STATUS_NO_IP_ADDRESSES, -EIO, "STATUS_NO_IP_ADDRESSES"},
1037 {STATUS_WRONG_CREDENTIAL_HANDLE, -EIO,
1038 "STATUS_WRONG_CREDENTIAL_HANDLE"},
1039 {STATUS_CRYPTO_SYSTEM_INVALID, -EIO, "STATUS_CRYPTO_SYSTEM_INVALID"},
1040 {STATUS_MAX_REFERRALS_EXCEEDED, -EIO, "STATUS_MAX_REFERRALS_EXCEEDED"},
1041 {STATUS_MUST_BE_KDC, -EIO, "STATUS_MUST_BE_KDC"},
1042 {STATUS_STRONG_CRYPTO_NOT_SUPPORTED, -EIO,
1043 "STATUS_STRONG_CRYPTO_NOT_SUPPORTED"},
1044 {STATUS_TOO_MANY_PRINCIPALS, -EIO, "STATUS_TOO_MANY_PRINCIPALS"},
1045 {STATUS_NO_PA_DATA, -EIO, "STATUS_NO_PA_DATA"},
1046 {STATUS_PKINIT_NAME_MISMATCH, -EIO, "STATUS_PKINIT_NAME_MISMATCH"},
1047 {STATUS_SMARTCARD_LOGON_REQUIRED, -EIO,
1048 "STATUS_SMARTCARD_LOGON_REQUIRED"},
1049 {STATUS_KDC_INVALID_REQUEST, -EIO, "STATUS_KDC_INVALID_REQUEST"},
1050 {STATUS_KDC_UNABLE_TO_REFER, -EIO, "STATUS_KDC_UNABLE_TO_REFER"},
1051 {STATUS_KDC_UNKNOWN_ETYPE, -EIO, "STATUS_KDC_UNKNOWN_ETYPE"},
1052 {STATUS_SHUTDOWN_IN_PROGRESS, -EIO, "STATUS_SHUTDOWN_IN_PROGRESS"},
1053 {STATUS_SERVER_SHUTDOWN_IN_PROGRESS, -EIO,
1054 "STATUS_SERVER_SHUTDOWN_IN_PROGRESS"},
1055 {STATUS_NOT_SUPPORTED_ON_SBS, -EOPNOTSUPP,
1056 "STATUS_NOT_SUPPORTED_ON_SBS"},
1057 {STATUS_WMI_GUID_DISCONNECTED, -EIO, "STATUS_WMI_GUID_DISCONNECTED"},
1058 {STATUS_WMI_ALREADY_DISABLED, -EIO, "STATUS_WMI_ALREADY_DISABLED"},
1059 {STATUS_WMI_ALREADY_ENABLED, -EIO, "STATUS_WMI_ALREADY_ENABLED"},
1060 {STATUS_MFT_TOO_FRAGMENTED, -EIO, "STATUS_MFT_TOO_FRAGMENTED"},
1061 {STATUS_COPY_PROTECTION_FAILURE, -EIO,
1062 "STATUS_COPY_PROTECTION_FAILURE"},
1063 {STATUS_CSS_AUTHENTICATION_FAILURE, -EIO,
1064 "STATUS_CSS_AUTHENTICATION_FAILURE"},
1065 {STATUS_CSS_KEY_NOT_PRESENT, -EIO, "STATUS_CSS_KEY_NOT_PRESENT"},
1066 {STATUS_CSS_KEY_NOT_ESTABLISHED, -EIO,
1067 "STATUS_CSS_KEY_NOT_ESTABLISHED"},
1068 {STATUS_CSS_SCRAMBLED_SECTOR, -EIO, "STATUS_CSS_SCRAMBLED_SECTOR"},
1069 {STATUS_CSS_REGION_MISMATCH, -EIO, "STATUS_CSS_REGION_MISMATCH"},
1070 {STATUS_CSS_RESETS_EXHAUSTED, -EIO, "STATUS_CSS_RESETS_EXHAUSTED"},
1071 {STATUS_PKINIT_FAILURE, -EIO, "STATUS_PKINIT_FAILURE"},
1072 {STATUS_SMARTCARD_SUBSYSTEM_FAILURE, -EIO,
1073 "STATUS_SMARTCARD_SUBSYSTEM_FAILURE"},
1074 {STATUS_NO_KERB_KEY, -EIO, "STATUS_NO_KERB_KEY"},
1075 {STATUS_HOST_DOWN, -EIO, "STATUS_HOST_DOWN"},
1076 {STATUS_UNSUPPORTED_PREAUTH, -EIO, "STATUS_UNSUPPORTED_PREAUTH"},
1077 {STATUS_EFS_ALG_BLOB_TOO_BIG, -EIO, "STATUS_EFS_ALG_BLOB_TOO_BIG"},
1078 {STATUS_PORT_NOT_SET, -EIO, "STATUS_PORT_NOT_SET"},
1079 {STATUS_DEBUGGER_INACTIVE, -EIO, "STATUS_DEBUGGER_INACTIVE"},
1080 {STATUS_DS_VERSION_CHECK_FAILURE, -EIO,
1081 "STATUS_DS_VERSION_CHECK_FAILURE"},
1082 {STATUS_AUDITING_DISABLED, -EIO, "STATUS_AUDITING_DISABLED"},
1083 {STATUS_PRENT4_MACHINE_ACCOUNT, -EIO, "STATUS_PRENT4_MACHINE_ACCOUNT"},
1084 {STATUS_DS_AG_CANT_HAVE_UNIVERSAL_MEMBER, -EIO,
1085 "STATUS_DS_AG_CANT_HAVE_UNIVERSAL_MEMBER"},
1086 {STATUS_INVALID_IMAGE_WIN_32, -EIO, "STATUS_INVALID_IMAGE_WIN_32"},
1087 {STATUS_INVALID_IMAGE_WIN_64, -EIO, "STATUS_INVALID_IMAGE_WIN_64"},
1088 {STATUS_BAD_BINDINGS, -EIO, "STATUS_BAD_BINDINGS"},
1089 {STATUS_NETWORK_SESSION_EXPIRED, -EIO,
1090 "STATUS_NETWORK_SESSION_EXPIRED"},
1091 {STATUS_APPHELP_BLOCK, -EIO, "STATUS_APPHELP_BLOCK"},
1092 {STATUS_ALL_SIDS_FILTERED, -EIO, "STATUS_ALL_SIDS_FILTERED"},
1093 {STATUS_NOT_SAFE_MODE_DRIVER, -EIO, "STATUS_NOT_SAFE_MODE_DRIVER"},
1094 {STATUS_ACCESS_DISABLED_BY_POLICY_DEFAULT, -EACCES,
1095 "STATUS_ACCESS_DISABLED_BY_POLICY_DEFAULT"},
1096 {STATUS_ACCESS_DISABLED_BY_POLICY_PATH, -EACCES,
1097 "STATUS_ACCESS_DISABLED_BY_POLICY_PATH"},
1098 {STATUS_ACCESS_DISABLED_BY_POLICY_PUBLISHER, -EACCES,
1099 "STATUS_ACCESS_DISABLED_BY_POLICY_PUBLISHER"},
1100 {STATUS_ACCESS_DISABLED_BY_POLICY_OTHER, -EACCES,
1101 "STATUS_ACCESS_DISABLED_BY_POLICY_OTHER"},
1102 {STATUS_FAILED_DRIVER_ENTRY, -EIO, "STATUS_FAILED_DRIVER_ENTRY"},
1103 {STATUS_DEVICE_ENUMERATION_ERROR, -EIO,
1104 "STATUS_DEVICE_ENUMERATION_ERROR"},
1105 {STATUS_MOUNT_POINT_NOT_RESOLVED, -EIO,
1106 "STATUS_MOUNT_POINT_NOT_RESOLVED"},
1107 {STATUS_INVALID_DEVICE_OBJECT_PARAMETER, -EIO,
1108 "STATUS_INVALID_DEVICE_OBJECT_PARAMETER"},
1109 {STATUS_MCA_OCCURED, -EIO, "STATUS_MCA_OCCURED"},
1110 {STATUS_DRIVER_BLOCKED_CRITICAL, -EIO,
1111 "STATUS_DRIVER_BLOCKED_CRITICAL"},
1112 {STATUS_DRIVER_BLOCKED, -EIO, "STATUS_DRIVER_BLOCKED"},
1113 {STATUS_DRIVER_DATABASE_ERROR, -EIO, "STATUS_DRIVER_DATABASE_ERROR"},
1114 {STATUS_SYSTEM_HIVE_TOO_LARGE, -EIO, "STATUS_SYSTEM_HIVE_TOO_LARGE"},
1115 {STATUS_INVALID_IMPORT_OF_NON_DLL, -EIO,
1116 "STATUS_INVALID_IMPORT_OF_NON_DLL"},
1117 {STATUS_NO_SECRETS, -EIO, "STATUS_NO_SECRETS"},
1118 {STATUS_ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY, -EACCES,
1119 "STATUS_ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY"},
1120 {STATUS_FAILED_STACK_SWITCH, -EIO, "STATUS_FAILED_STACK_SWITCH"},
1121 {STATUS_HEAP_CORRUPTION, -EIO, "STATUS_HEAP_CORRUPTION"},
1122 {STATUS_SMARTCARD_WRONG_PIN, -EIO, "STATUS_SMARTCARD_WRONG_PIN"},
1123 {STATUS_SMARTCARD_CARD_BLOCKED, -EIO, "STATUS_SMARTCARD_CARD_BLOCKED"},
1124 {STATUS_SMARTCARD_CARD_NOT_AUTHENTICATED, -EIO,
1125 "STATUS_SMARTCARD_CARD_NOT_AUTHENTICATED"},
1126 {STATUS_SMARTCARD_NO_CARD, -EIO, "STATUS_SMARTCARD_NO_CARD"},
1127 {STATUS_SMARTCARD_NO_KEY_CONTAINER, -EIO,
1128 "STATUS_SMARTCARD_NO_KEY_CONTAINER"},
1129 {STATUS_SMARTCARD_NO_CERTIFICATE, -EIO,
1130 "STATUS_SMARTCARD_NO_CERTIFICATE"},
1131 {STATUS_SMARTCARD_NO_KEYSET, -EIO, "STATUS_SMARTCARD_NO_KEYSET"},
1132 {STATUS_SMARTCARD_IO_ERROR, -EIO, "STATUS_SMARTCARD_IO_ERROR"},
1133 {STATUS_DOWNGRADE_DETECTED, -EIO, "STATUS_DOWNGRADE_DETECTED"},
1134 {STATUS_SMARTCARD_CERT_REVOKED, -EIO, "STATUS_SMARTCARD_CERT_REVOKED"},
1135 {STATUS_ISSUING_CA_UNTRUSTED, -EIO, "STATUS_ISSUING_CA_UNTRUSTED"},
1136 {STATUS_REVOCATION_OFFLINE_C, -EIO, "STATUS_REVOCATION_OFFLINE_C"},
1137 {STATUS_PKINIT_CLIENT_FAILURE, -EIO, "STATUS_PKINIT_CLIENT_FAILURE"},
1138 {STATUS_SMARTCARD_CERT_EXPIRED, -EIO, "STATUS_SMARTCARD_CERT_EXPIRED"},
1139 {STATUS_DRIVER_FAILED_PRIOR_UNLOAD, -EIO,
1140 "STATUS_DRIVER_FAILED_PRIOR_UNLOAD"},
1141 {STATUS_SMARTCARD_SILENT_CONTEXT, -EIO,
1142 "STATUS_SMARTCARD_SILENT_CONTEXT"},
1143 {STATUS_PER_USER_TRUST_QUOTA_EXCEEDED, -EDQUOT,
1144 "STATUS_PER_USER_TRUST_QUOTA_EXCEEDED"},
1145 {STATUS_ALL_USER_TRUST_QUOTA_EXCEEDED, -EDQUOT,
1146 "STATUS_ALL_USER_TRUST_QUOTA_EXCEEDED"},
1147 {STATUS_USER_DELETE_TRUST_QUOTA_EXCEEDED, -EDQUOT,
1148 "STATUS_USER_DELETE_TRUST_QUOTA_EXCEEDED"},
1149 {STATUS_DS_NAME_NOT_UNIQUE, -EIO, "STATUS_DS_NAME_NOT_UNIQUE"},
1150 {STATUS_DS_DUPLICATE_ID_FOUND, -EIO, "STATUS_DS_DUPLICATE_ID_FOUND"},
1151 {STATUS_DS_GROUP_CONVERSION_ERROR, -EIO,
1152 "STATUS_DS_GROUP_CONVERSION_ERROR"},
1153 {STATUS_VOLSNAP_PREPARE_HIBERNATE, -EIO,
1154 "STATUS_VOLSNAP_PREPARE_HIBERNATE"},
1155 {STATUS_USER2USER_REQUIRED, -EIO, "STATUS_USER2USER_REQUIRED"},
1156 {STATUS_STACK_BUFFER_OVERRUN, -EIO, "STATUS_STACK_BUFFER_OVERRUN"},
1157 {STATUS_NO_S4U_PROT_SUPPORT, -EIO, "STATUS_NO_S4U_PROT_SUPPORT"},
1158 {STATUS_CROSSREALM_DELEGATION_FAILURE, -EIO,
1159 "STATUS_CROSSREALM_DELEGATION_FAILURE"},
1160 {STATUS_REVOCATION_OFFLINE_KDC, -EIO, "STATUS_REVOCATION_OFFLINE_KDC"},
1161 {STATUS_ISSUING_CA_UNTRUSTED_KDC, -EIO,
1162 "STATUS_ISSUING_CA_UNTRUSTED_KDC"},
1163 {STATUS_KDC_CERT_EXPIRED, -EIO, "STATUS_KDC_CERT_EXPIRED"},
1164 {STATUS_KDC_CERT_REVOKED, -EIO, "STATUS_KDC_CERT_REVOKED"},
1165 {STATUS_PARAMETER_QUOTA_EXCEEDED, -EDQUOT,
1166 "STATUS_PARAMETER_QUOTA_EXCEEDED"},
1167 {STATUS_HIBERNATION_FAILURE, -EIO, "STATUS_HIBERNATION_FAILURE"},
1168 {STATUS_DELAY_LOAD_FAILED, -EIO, "STATUS_DELAY_LOAD_FAILED"},
1169 {STATUS_AUTHENTICATION_FIREWALL_FAILED, -EIO,
1170 "STATUS_AUTHENTICATION_FIREWALL_FAILED"},
1171 {STATUS_VDM_DISALLOWED, -EIO, "STATUS_VDM_DISALLOWED"},
1172 {STATUS_HUNG_DISPLAY_DRIVER_THREAD, -EIO,
1173 "STATUS_HUNG_DISPLAY_DRIVER_THREAD"},
1174 {STATUS_INSUFFICIENT_RESOURCE_FOR_SPECIFIED_SHARED_SECTION_SIZE, -EIO,
1175 "STATUS_INSUFFICIENT_RESOURCE_FOR_SPECIFIED_SHARED_SECTION_SIZE"},
1176 {STATUS_INVALID_CRUNTIME_PARAMETER, -EIO,
1177 "STATUS_INVALID_CRUNTIME_PARAMETER"},
1178 {STATUS_NTLM_BLOCKED, -EIO, "STATUS_NTLM_BLOCKED"},
1179 {STATUS_ASSERTION_FAILURE, -EIO, "STATUS_ASSERTION_FAILURE"},
1180 {STATUS_VERIFIER_STOP, -EIO, "STATUS_VERIFIER_STOP"},
1181 {STATUS_CALLBACK_POP_STACK, -EIO, "STATUS_CALLBACK_POP_STACK"},
1182 {STATUS_INCOMPATIBLE_DRIVER_BLOCKED, -EIO,
1183 "STATUS_INCOMPATIBLE_DRIVER_BLOCKED"},
1184 {STATUS_HIVE_UNLOADED, -EIO, "STATUS_HIVE_UNLOADED"},
1185 {STATUS_COMPRESSION_DISABLED, -EIO, "STATUS_COMPRESSION_DISABLED"},
1186 {STATUS_FILE_SYSTEM_LIMITATION, -EIO, "STATUS_FILE_SYSTEM_LIMITATION"},
1187 {STATUS_INVALID_IMAGE_HASH, -EIO, "STATUS_INVALID_IMAGE_HASH"},
1188 {STATUS_NOT_CAPABLE, -EIO, "STATUS_NOT_CAPABLE"},
1189 {STATUS_REQUEST_OUT_OF_SEQUENCE, -EIO,
1190 "STATUS_REQUEST_OUT_OF_SEQUENCE"},
1191 {STATUS_IMPLEMENTATION_LIMIT, -EIO, "STATUS_IMPLEMENTATION_LIMIT"},
1192 {STATUS_ELEVATION_REQUIRED, -EIO, "STATUS_ELEVATION_REQUIRED"},
1193 {STATUS_BEYOND_VDL, -EIO, "STATUS_BEYOND_VDL"},
1194 {STATUS_ENCOUNTERED_WRITE_IN_PROGRESS, -EIO,
1195 "STATUS_ENCOUNTERED_WRITE_IN_PROGRESS"},
1196 {STATUS_PTE_CHANGED, -EIO, "STATUS_PTE_CHANGED"},
1197 {STATUS_PURGE_FAILED, -EIO, "STATUS_PURGE_FAILED"},
1198 {STATUS_CRED_REQUIRES_CONFIRMATION, -EIO,
1199 "STATUS_CRED_REQUIRES_CONFIRMATION"},
1200 {STATUS_CS_ENCRYPTION_INVALID_SERVER_RESPONSE, -EIO,
1201 "STATUS_CS_ENCRYPTION_INVALID_SERVER_RESPONSE"},
1202 {STATUS_CS_ENCRYPTION_UNSUPPORTED_SERVER, -EIO,
1203 "STATUS_CS_ENCRYPTION_UNSUPPORTED_SERVER"},
1204 {STATUS_CS_ENCRYPTION_EXISTING_ENCRYPTED_FILE, -EIO,
1205 "STATUS_CS_ENCRYPTION_EXISTING_ENCRYPTED_FILE"},
1206 {STATUS_CS_ENCRYPTION_NEW_ENCRYPTED_FILE, -EIO,
1207 "STATUS_CS_ENCRYPTION_NEW_ENCRYPTED_FILE"},
1208 {STATUS_CS_ENCRYPTION_FILE_NOT_CSE, -EIO,
1209 "STATUS_CS_ENCRYPTION_FILE_NOT_CSE"},
1210 {STATUS_INVALID_LABEL, -EIO, "STATUS_INVALID_LABEL"},
1211 {STATUS_DRIVER_PROCESS_TERMINATED, -EIO,
1212 "STATUS_DRIVER_PROCESS_TERMINATED"},
1213 {STATUS_AMBIGUOUS_SYSTEM_DEVICE, -EIO,
1214 "STATUS_AMBIGUOUS_SYSTEM_DEVICE"},
1215 {STATUS_SYSTEM_DEVICE_NOT_FOUND, -EIO,
1216 "STATUS_SYSTEM_DEVICE_NOT_FOUND"},
1217 {STATUS_RESTART_BOOT_APPLICATION, -EIO,
1218 "STATUS_RESTART_BOOT_APPLICATION"},
1219 {STATUS_INVALID_TASK_NAME, -EIO, "STATUS_INVALID_TASK_NAME"},
1220 {STATUS_INVALID_TASK_INDEX, -EIO, "STATUS_INVALID_TASK_INDEX"},
1221 {STATUS_THREAD_ALREADY_IN_TASK, -EIO, "STATUS_THREAD_ALREADY_IN_TASK"},
1222 {STATUS_CALLBACK_BYPASS, -EIO, "STATUS_CALLBACK_BYPASS"},
1223 {STATUS_PORT_CLOSED, -EIO, "STATUS_PORT_CLOSED"},
1224 {STATUS_MESSAGE_LOST, -EIO, "STATUS_MESSAGE_LOST"},
1225 {STATUS_INVALID_MESSAGE, -EIO, "STATUS_INVALID_MESSAGE"},
1226 {STATUS_REQUEST_CANCELED, -EIO, "STATUS_REQUEST_CANCELED"},
1227 {STATUS_RECURSIVE_DISPATCH, -EIO, "STATUS_RECURSIVE_DISPATCH"},
1228 {STATUS_LPC_RECEIVE_BUFFER_EXPECTED, -EIO,
1229 "STATUS_LPC_RECEIVE_BUFFER_EXPECTED"},
1230 {STATUS_LPC_INVALID_CONNECTION_USAGE, -EIO,
1231 "STATUS_LPC_INVALID_CONNECTION_USAGE"},
1232 {STATUS_LPC_REQUESTS_NOT_ALLOWED, -EIO,
1233 "STATUS_LPC_REQUESTS_NOT_ALLOWED"},
1234 {STATUS_RESOURCE_IN_USE, -EIO, "STATUS_RESOURCE_IN_USE"},
1235 {STATUS_HARDWARE_MEMORY_ERROR, -EIO, "STATUS_HARDWARE_MEMORY_ERROR"},
1236 {STATUS_THREADPOOL_HANDLE_EXCEPTION, -EIO,
1237 "STATUS_THREADPOOL_HANDLE_EXCEPTION"},
1238 {STATUS_THREADPOOL_SET_EVENT_ON_COMPLETION_FAILED, -EIO,
1239 "STATUS_THREADPOOL_SET_EVENT_ON_COMPLETION_FAILED"},
1240 {STATUS_THREADPOOL_RELEASE_SEMAPHORE_ON_COMPLETION_FAILED, -EIO,
1241 "STATUS_THREADPOOL_RELEASE_SEMAPHORE_ON_COMPLETION_FAILED"},
1242 {STATUS_THREADPOOL_RELEASE_MUTEX_ON_COMPLETION_FAILED, -EIO,
1243 "STATUS_THREADPOOL_RELEASE_MUTEX_ON_COMPLETION_FAILED"},
1244 {STATUS_THREADPOOL_FREE_LIBRARY_ON_COMPLETION_FAILED, -EIO,
1245 "STATUS_THREADPOOL_FREE_LIBRARY_ON_COMPLETION_FAILED"},
1246 {STATUS_THREADPOOL_RELEASED_DURING_OPERATION, -EIO,
1247 "STATUS_THREADPOOL_RELEASED_DURING_OPERATION"},
1248 {STATUS_CALLBACK_RETURNED_WHILE_IMPERSONATING, -EIO,
1249 "STATUS_CALLBACK_RETURNED_WHILE_IMPERSONATING"},
1250 {STATUS_APC_RETURNED_WHILE_IMPERSONATING, -EIO,
1251 "STATUS_APC_RETURNED_WHILE_IMPERSONATING"},
1252 {STATUS_PROCESS_IS_PROTECTED, -EIO, "STATUS_PROCESS_IS_PROTECTED"},
1253 {STATUS_MCA_EXCEPTION, -EIO, "STATUS_MCA_EXCEPTION"},
1254 {STATUS_CERTIFICATE_MAPPING_NOT_UNIQUE, -EIO,
1255 "STATUS_CERTIFICATE_MAPPING_NOT_UNIQUE"},
1256 {STATUS_SYMLINK_CLASS_DISABLED, -EIO, "STATUS_SYMLINK_CLASS_DISABLED"},
1257 {STATUS_INVALID_IDN_NORMALIZATION, -EIO,
1258 "STATUS_INVALID_IDN_NORMALIZATION"},
1259 {STATUS_NO_UNICODE_TRANSLATION, -EIO, "STATUS_NO_UNICODE_TRANSLATION"},
1260 {STATUS_ALREADY_REGISTERED, -EIO, "STATUS_ALREADY_REGISTERED"},
1261 {STATUS_CONTEXT_MISMATCH, -EIO, "STATUS_CONTEXT_MISMATCH"},
1262 {STATUS_PORT_ALREADY_HAS_COMPLETION_LIST, -EIO,
1263 "STATUS_PORT_ALREADY_HAS_COMPLETION_LIST"},
1264 {STATUS_CALLBACK_RETURNED_THREAD_PRIORITY, -EIO,
1265 "STATUS_CALLBACK_RETURNED_THREAD_PRIORITY"},
1266 {STATUS_INVALID_THREAD, -EIO, "STATUS_INVALID_THREAD"},
1267 {STATUS_CALLBACK_RETURNED_TRANSACTION, -EIO,
1268 "STATUS_CALLBACK_RETURNED_TRANSACTION"},
1269 {STATUS_CALLBACK_RETURNED_LDR_LOCK, -EIO,
1270 "STATUS_CALLBACK_RETURNED_LDR_LOCK"},
1271 {STATUS_CALLBACK_RETURNED_LANG, -EIO, "STATUS_CALLBACK_RETURNED_LANG"},
1272 {STATUS_CALLBACK_RETURNED_PRI_BACK, -EIO,
1273 "STATUS_CALLBACK_RETURNED_PRI_BACK"},
1274 {STATUS_CALLBACK_RETURNED_THREAD_AFFINITY, -EIO,
1275 "STATUS_CALLBACK_RETURNED_THREAD_AFFINITY"},
1276 {STATUS_DISK_REPAIR_DISABLED, -EIO, "STATUS_DISK_REPAIR_DISABLED"},
1277 {STATUS_DS_DOMAIN_RENAME_IN_PROGRESS, -EIO,
1278 "STATUS_DS_DOMAIN_RENAME_IN_PROGRESS"},
1279 {STATUS_DISK_QUOTA_EXCEEDED, -EDQUOT, "STATUS_DISK_QUOTA_EXCEEDED"},
1280 {STATUS_CONTENT_BLOCKED, -EIO, "STATUS_CONTENT_BLOCKED"},
1281 {STATUS_BAD_CLUSTERS, -EIO, "STATUS_BAD_CLUSTERS"},
1282 {STATUS_VOLUME_DIRTY, -EIO, "STATUS_VOLUME_DIRTY"},
1283 {STATUS_FILE_CHECKED_OUT, -EIO, "STATUS_FILE_CHECKED_OUT"},
1284 {STATUS_CHECKOUT_REQUIRED, -EIO, "STATUS_CHECKOUT_REQUIRED"},
1285 {STATUS_BAD_FILE_TYPE, -EIO, "STATUS_BAD_FILE_TYPE"},
1286 {STATUS_FILE_TOO_LARGE, -EIO, "STATUS_FILE_TOO_LARGE"},
1287 {STATUS_FORMS_AUTH_REQUIRED, -EIO, "STATUS_FORMS_AUTH_REQUIRED"},
1288 {STATUS_VIRUS_INFECTED, -EIO, "STATUS_VIRUS_INFECTED"},
1289 {STATUS_VIRUS_DELETED, -EIO, "STATUS_VIRUS_DELETED"},
1290 {STATUS_BAD_MCFG_TABLE, -EIO, "STATUS_BAD_MCFG_TABLE"},
1291 {STATUS_WOW_ASSERTION, -EIO, "STATUS_WOW_ASSERTION"},
1292 {STATUS_INVALID_SIGNATURE, -EIO, "STATUS_INVALID_SIGNATURE"},
1293 {STATUS_HMAC_NOT_SUPPORTED, -EIO, "STATUS_HMAC_NOT_SUPPORTED"},
1294 {STATUS_IPSEC_QUEUE_OVERFLOW, -EIO, "STATUS_IPSEC_QUEUE_OVERFLOW"},
1295 {STATUS_ND_QUEUE_OVERFLOW, -EIO, "STATUS_ND_QUEUE_OVERFLOW"},
1296 {STATUS_HOPLIMIT_EXCEEDED, -EIO, "STATUS_HOPLIMIT_EXCEEDED"},
1297 {STATUS_PROTOCOL_NOT_SUPPORTED, -EOPNOTSUPP,
1298 "STATUS_PROTOCOL_NOT_SUPPORTED"},
1299 {STATUS_LOST_WRITEBEHIND_DATA_NETWORK_DISCONNECTED, -EIO,
1300 "STATUS_LOST_WRITEBEHIND_DATA_NETWORK_DISCONNECTED"},
1301 {STATUS_LOST_WRITEBEHIND_DATA_NETWORK_SERVER_ERROR, -EIO,
1302 "STATUS_LOST_WRITEBEHIND_DATA_NETWORK_SERVER_ERROR"},
1303 {STATUS_LOST_WRITEBEHIND_DATA_LOCAL_DISK_ERROR, -EIO,
1304 "STATUS_LOST_WRITEBEHIND_DATA_LOCAL_DISK_ERROR"},
1305 {STATUS_XML_PARSE_ERROR, -EIO, "STATUS_XML_PARSE_ERROR"},
1306 {STATUS_XMLDSIG_ERROR, -EIO, "STATUS_XMLDSIG_ERROR"},
1307 {STATUS_WRONG_COMPARTMENT, -EIO, "STATUS_WRONG_COMPARTMENT"},
1308 {STATUS_AUTHIP_FAILURE, -EIO, "STATUS_AUTHIP_FAILURE"},
1309 {DBG_NO_STATE_CHANGE, -EIO, "DBG_NO_STATE_CHANGE"},
1310 {DBG_APP_NOT_IDLE, -EIO, "DBG_APP_NOT_IDLE"},
1311 {RPC_NT_INVALID_STRING_BINDING, -EIO, "RPC_NT_INVALID_STRING_BINDING"},
1312 {RPC_NT_WRONG_KIND_OF_BINDING, -EIO, "RPC_NT_WRONG_KIND_OF_BINDING"},
1313 {RPC_NT_INVALID_BINDING, -EIO, "RPC_NT_INVALID_BINDING"},
1314 {RPC_NT_PROTSEQ_NOT_SUPPORTED, -EOPNOTSUPP,
1315 "RPC_NT_PROTSEQ_NOT_SUPPORTED"},
1316 {RPC_NT_INVALID_RPC_PROTSEQ, -EIO, "RPC_NT_INVALID_RPC_PROTSEQ"},
1317 {RPC_NT_INVALID_STRING_UUID, -EIO, "RPC_NT_INVALID_STRING_UUID"},
1318 {RPC_NT_INVALID_ENDPOINT_FORMAT, -EIO,
1319 "RPC_NT_INVALID_ENDPOINT_FORMAT"},
1320 {RPC_NT_INVALID_NET_ADDR, -EIO, "RPC_NT_INVALID_NET_ADDR"},
1321 {RPC_NT_NO_ENDPOINT_FOUND, -EIO, "RPC_NT_NO_ENDPOINT_FOUND"},
1322 {RPC_NT_INVALID_TIMEOUT, -EINVAL, "RPC_NT_INVALID_TIMEOUT"},
1323 {RPC_NT_OBJECT_NOT_FOUND, -ENOENT, "RPC_NT_OBJECT_NOT_FOUND"},
1324 {RPC_NT_ALREADY_REGISTERED, -EIO, "RPC_NT_ALREADY_REGISTERED"},
1325 {RPC_NT_TYPE_ALREADY_REGISTERED, -EIO,
1326 "RPC_NT_TYPE_ALREADY_REGISTERED"},
1327 {RPC_NT_ALREADY_LISTENING, -EIO, "RPC_NT_ALREADY_LISTENING"},
1328 {RPC_NT_NO_PROTSEQS_REGISTERED, -EIO, "RPC_NT_NO_PROTSEQS_REGISTERED"},
1329 {RPC_NT_NOT_LISTENING, -EIO, "RPC_NT_NOT_LISTENING"},
1330 {RPC_NT_UNKNOWN_MGR_TYPE, -EIO, "RPC_NT_UNKNOWN_MGR_TYPE"},
1331 {RPC_NT_UNKNOWN_IF, -EIO, "RPC_NT_UNKNOWN_IF"},
1332 {RPC_NT_NO_BINDINGS, -EIO, "RPC_NT_NO_BINDINGS"},
1333 {RPC_NT_NO_PROTSEQS, -EIO, "RPC_NT_NO_PROTSEQS"},
1334 {RPC_NT_CANT_CREATE_ENDPOINT, -EIO, "RPC_NT_CANT_CREATE_ENDPOINT"},
1335 {RPC_NT_OUT_OF_RESOURCES, -EIO, "RPC_NT_OUT_OF_RESOURCES"},
1336 {RPC_NT_SERVER_UNAVAILABLE, -EIO, "RPC_NT_SERVER_UNAVAILABLE"},
1337 {RPC_NT_SERVER_TOO_BUSY, -EBUSY, "RPC_NT_SERVER_TOO_BUSY"},
1338 {RPC_NT_INVALID_NETWORK_OPTIONS, -EIO,
1339 "RPC_NT_INVALID_NETWORK_OPTIONS"},
1340 {RPC_NT_NO_CALL_ACTIVE, -EIO, "RPC_NT_NO_CALL_ACTIVE"},
1341 {RPC_NT_CALL_FAILED, -EIO, "RPC_NT_CALL_FAILED"},
1342 {RPC_NT_CALL_FAILED_DNE, -EIO, "RPC_NT_CALL_FAILED_DNE"},
1343 {RPC_NT_PROTOCOL_ERROR, -EIO, "RPC_NT_PROTOCOL_ERROR"},
1344 {RPC_NT_UNSUPPORTED_TRANS_SYN, -EIO, "RPC_NT_UNSUPPORTED_TRANS_SYN"},
1345 {RPC_NT_UNSUPPORTED_TYPE, -EIO, "RPC_NT_UNSUPPORTED_TYPE"},
1346 {RPC_NT_INVALID_TAG, -EIO, "RPC_NT_INVALID_TAG"},
1347 {RPC_NT_INVALID_BOUND, -EIO, "RPC_NT_INVALID_BOUND"},
1348 {RPC_NT_NO_ENTRY_NAME, -EIO, "RPC_NT_NO_ENTRY_NAME"},
1349 {RPC_NT_INVALID_NAME_SYNTAX, -EIO, "RPC_NT_INVALID_NAME_SYNTAX"},
1350 {RPC_NT_UNSUPPORTED_NAME_SYNTAX, -EIO,
1351 "RPC_NT_UNSUPPORTED_NAME_SYNTAX"},
1352 {RPC_NT_UUID_NO_ADDRESS, -EIO, "RPC_NT_UUID_NO_ADDRESS"},
1353 {RPC_NT_DUPLICATE_ENDPOINT, -ENOTUNIQ, "RPC_NT_DUPLICATE_ENDPOINT"},
1354 {RPC_NT_UNKNOWN_AUTHN_TYPE, -EIO, "RPC_NT_UNKNOWN_AUTHN_TYPE"},
1355 {RPC_NT_MAX_CALLS_TOO_SMALL, -EIO, "RPC_NT_MAX_CALLS_TOO_SMALL"},
1356 {RPC_NT_STRING_TOO_LONG, -EIO, "RPC_NT_STRING_TOO_LONG"},
1357 {RPC_NT_PROTSEQ_NOT_FOUND, -EIO, "RPC_NT_PROTSEQ_NOT_FOUND"},
1358 {RPC_NT_PROCNUM_OUT_OF_RANGE, -EIO, "RPC_NT_PROCNUM_OUT_OF_RANGE"},
1359 {RPC_NT_BINDING_HAS_NO_AUTH, -EIO, "RPC_NT_BINDING_HAS_NO_AUTH"},
1360 {RPC_NT_UNKNOWN_AUTHN_SERVICE, -EIO, "RPC_NT_UNKNOWN_AUTHN_SERVICE"},
1361 {RPC_NT_UNKNOWN_AUTHN_LEVEL, -EIO, "RPC_NT_UNKNOWN_AUTHN_LEVEL"},
1362 {RPC_NT_INVALID_AUTH_IDENTITY, -EIO, "RPC_NT_INVALID_AUTH_IDENTITY"},
1363 {RPC_NT_UNKNOWN_AUTHZ_SERVICE, -EIO, "RPC_NT_UNKNOWN_AUTHZ_SERVICE"},
1364 {EPT_NT_INVALID_ENTRY, -EIO, "EPT_NT_INVALID_ENTRY"},
1365 {EPT_NT_CANT_PERFORM_OP, -EIO, "EPT_NT_CANT_PERFORM_OP"},
1366 {EPT_NT_NOT_REGISTERED, -EIO, "EPT_NT_NOT_REGISTERED"},
1367 {RPC_NT_NOTHING_TO_EXPORT, -EIO, "RPC_NT_NOTHING_TO_EXPORT"},
1368 {RPC_NT_INCOMPLETE_NAME, -EIO, "RPC_NT_INCOMPLETE_NAME"},
1369 {RPC_NT_INVALID_VERS_OPTION, -EIO, "RPC_NT_INVALID_VERS_OPTION"},
1370 {RPC_NT_NO_MORE_MEMBERS, -EIO, "RPC_NT_NO_MORE_MEMBERS"},
1371 {RPC_NT_NOT_ALL_OBJS_UNEXPORTED, -EIO,
1372 "RPC_NT_NOT_ALL_OBJS_UNEXPORTED"},
1373 {RPC_NT_INTERFACE_NOT_FOUND, -EIO, "RPC_NT_INTERFACE_NOT_FOUND"},
1374 {RPC_NT_ENTRY_ALREADY_EXISTS, -EIO, "RPC_NT_ENTRY_ALREADY_EXISTS"},
1375 {RPC_NT_ENTRY_NOT_FOUND, -EIO, "RPC_NT_ENTRY_NOT_FOUND"},
1376 {RPC_NT_NAME_SERVICE_UNAVAILABLE, -EIO,
1377 "RPC_NT_NAME_SERVICE_UNAVAILABLE"},
1378 {RPC_NT_INVALID_NAF_ID, -EIO, "RPC_NT_INVALID_NAF_ID"},
1379 {RPC_NT_CANNOT_SUPPORT, -EOPNOTSUPP, "RPC_NT_CANNOT_SUPPORT"},
1380 {RPC_NT_NO_CONTEXT_AVAILABLE, -EIO, "RPC_NT_NO_CONTEXT_AVAILABLE"},
1381 {RPC_NT_INTERNAL_ERROR, -EIO, "RPC_NT_INTERNAL_ERROR"},
1382 {RPC_NT_ZERO_DIVIDE, -EIO, "RPC_NT_ZERO_DIVIDE"},
1383 {RPC_NT_ADDRESS_ERROR, -EIO, "RPC_NT_ADDRESS_ERROR"},
1384 {RPC_NT_FP_DIV_ZERO, -EIO, "RPC_NT_FP_DIV_ZERO"},
1385 {RPC_NT_FP_UNDERFLOW, -EIO, "RPC_NT_FP_UNDERFLOW"},
1386 {RPC_NT_FP_OVERFLOW, -EIO, "RPC_NT_FP_OVERFLOW"},
1387 {RPC_NT_CALL_IN_PROGRESS, -EIO, "RPC_NT_CALL_IN_PROGRESS"},
1388 {RPC_NT_NO_MORE_BINDINGS, -EIO, "RPC_NT_NO_MORE_BINDINGS"},
1389 {RPC_NT_GROUP_MEMBER_NOT_FOUND, -EIO, "RPC_NT_GROUP_MEMBER_NOT_FOUND"},
1390 {EPT_NT_CANT_CREATE, -EIO, "EPT_NT_CANT_CREATE"},
1391 {RPC_NT_INVALID_OBJECT, -EIO, "RPC_NT_INVALID_OBJECT"},
1392 {RPC_NT_NO_INTERFACES, -EIO, "RPC_NT_NO_INTERFACES"},
1393 {RPC_NT_CALL_CANCELLED, -EIO, "RPC_NT_CALL_CANCELLED"},
1394 {RPC_NT_BINDING_INCOMPLETE, -EIO, "RPC_NT_BINDING_INCOMPLETE"},
1395 {RPC_NT_COMM_FAILURE, -EIO, "RPC_NT_COMM_FAILURE"},
1396 {RPC_NT_UNSUPPORTED_AUTHN_LEVEL, -EIO,
1397 "RPC_NT_UNSUPPORTED_AUTHN_LEVEL"},
1398 {RPC_NT_NO_PRINC_NAME, -EIO, "RPC_NT_NO_PRINC_NAME"},
1399 {RPC_NT_NOT_RPC_ERROR, -EIO, "RPC_NT_NOT_RPC_ERROR"},
1400 {RPC_NT_SEC_PKG_ERROR, -EIO, "RPC_NT_SEC_PKG_ERROR"},
1401 {RPC_NT_NOT_CANCELLED, -EIO, "RPC_NT_NOT_CANCELLED"},
1402 {RPC_NT_INVALID_ASYNC_HANDLE, -EIO, "RPC_NT_INVALID_ASYNC_HANDLE"},
1403 {RPC_NT_INVALID_ASYNC_CALL, -EIO, "RPC_NT_INVALID_ASYNC_CALL"},
1404 {RPC_NT_PROXY_ACCESS_DENIED, -EACCES, "RPC_NT_PROXY_ACCESS_DENIED"},
1405 {RPC_NT_NO_MORE_ENTRIES, -EIO, "RPC_NT_NO_MORE_ENTRIES"},
1406 {RPC_NT_SS_CHAR_TRANS_OPEN_FAIL, -EIO,
1407 "RPC_NT_SS_CHAR_TRANS_OPEN_FAIL"},
1408 {RPC_NT_SS_CHAR_TRANS_SHORT_FILE, -EIO,
1409 "RPC_NT_SS_CHAR_TRANS_SHORT_FILE"},
1410 {RPC_NT_SS_IN_NULL_CONTEXT, -EIO, "RPC_NT_SS_IN_NULL_CONTEXT"},
1411 {RPC_NT_SS_CONTEXT_MISMATCH, -EIO, "RPC_NT_SS_CONTEXT_MISMATCH"},
1412 {RPC_NT_SS_CONTEXT_DAMAGED, -EIO, "RPC_NT_SS_CONTEXT_DAMAGED"},
1413 {RPC_NT_SS_HANDLES_MISMATCH, -EIO, "RPC_NT_SS_HANDLES_MISMATCH"},
1414 {RPC_NT_SS_CANNOT_GET_CALL_HANDLE, -EIO,
1415 "RPC_NT_SS_CANNOT_GET_CALL_HANDLE"},
1416 {RPC_NT_NULL_REF_POINTER, -EIO, "RPC_NT_NULL_REF_POINTER"},
1417 {RPC_NT_ENUM_VALUE_OUT_OF_RANGE, -EIO,
1418 "RPC_NT_ENUM_VALUE_OUT_OF_RANGE"},
1419 {RPC_NT_BYTE_COUNT_TOO_SMALL, -EIO, "RPC_NT_BYTE_COUNT_TOO_SMALL"},
1420 {RPC_NT_BAD_STUB_DATA, -EIO, "RPC_NT_BAD_STUB_DATA"},
1421 {RPC_NT_INVALID_ES_ACTION, -EIO, "RPC_NT_INVALID_ES_ACTION"},
1422 {RPC_NT_WRONG_ES_VERSION, -EIO, "RPC_NT_WRONG_ES_VERSION"},
1423 {RPC_NT_WRONG_STUB_VERSION, -EIO, "RPC_NT_WRONG_STUB_VERSION"},
1424 {RPC_NT_INVALID_PIPE_OBJECT, -EIO, "RPC_NT_INVALID_PIPE_OBJECT"},
1425 {RPC_NT_INVALID_PIPE_OPERATION, -EIO, "RPC_NT_INVALID_PIPE_OPERATION"},
1426 {RPC_NT_WRONG_PIPE_VERSION, -EIO, "RPC_NT_WRONG_PIPE_VERSION"},
1427 {RPC_NT_PIPE_CLOSED, -EIO, "RPC_NT_PIPE_CLOSED"},
1428 {RPC_NT_PIPE_DISCIPLINE_ERROR, -EIO, "RPC_NT_PIPE_DISCIPLINE_ERROR"},
1429 {RPC_NT_PIPE_EMPTY, -EIO, "RPC_NT_PIPE_EMPTY"},
1430 {STATUS_PNP_BAD_MPS_TABLE, -EIO, "STATUS_PNP_BAD_MPS_TABLE"},
1431 {STATUS_PNP_TRANSLATION_FAILED, -EIO, "STATUS_PNP_TRANSLATION_FAILED"},
1432 {STATUS_PNP_IRQ_TRANSLATION_FAILED, -EIO,
1433 "STATUS_PNP_IRQ_TRANSLATION_FAILED"},
1434 {STATUS_PNP_INVALID_ID, -EIO, "STATUS_PNP_INVALID_ID"},
1435 {STATUS_IO_REISSUE_AS_CACHED, -EIO, "STATUS_IO_REISSUE_AS_CACHED"},
1436 {STATUS_CTX_WINSTATION_NAME_INVALID, -EIO,
1437 "STATUS_CTX_WINSTATION_NAME_INVALID"},
1438 {STATUS_CTX_INVALID_PD, -EIO, "STATUS_CTX_INVALID_PD"},
1439 {STATUS_CTX_PD_NOT_FOUND, -EIO, "STATUS_CTX_PD_NOT_FOUND"},
1440 {STATUS_CTX_CLOSE_PENDING, -EIO, "STATUS_CTX_CLOSE_PENDING"},
1441 {STATUS_CTX_NO_OUTBUF, -EIO, "STATUS_CTX_NO_OUTBUF"},
1442 {STATUS_CTX_MODEM_INF_NOT_FOUND, -EIO,
1443 "STATUS_CTX_MODEM_INF_NOT_FOUND"},
1444 {STATUS_CTX_INVALID_MODEMNAME, -EIO, "STATUS_CTX_INVALID_MODEMNAME"},
1445 {STATUS_CTX_RESPONSE_ERROR, -EIO, "STATUS_CTX_RESPONSE_ERROR"},
1446 {STATUS_CTX_MODEM_RESPONSE_TIMEOUT, -ETIMEDOUT,
1447 "STATUS_CTX_MODEM_RESPONSE_TIMEOUT"},
1448 {STATUS_CTX_MODEM_RESPONSE_NO_CARRIER, -EIO,
1449 "STATUS_CTX_MODEM_RESPONSE_NO_CARRIER"},
1450 {STATUS_CTX_MODEM_RESPONSE_NO_DIALTONE, -EIO,
1451 "STATUS_CTX_MODEM_RESPONSE_NO_DIALTONE"},
1452 {STATUS_CTX_MODEM_RESPONSE_BUSY, -EBUSY,
1453 "STATUS_CTX_MODEM_RESPONSE_BUSY"},
1454 {STATUS_CTX_MODEM_RESPONSE_VOICE, -EIO,
1455 "STATUS_CTX_MODEM_RESPONSE_VOICE"},
1456 {STATUS_CTX_TD_ERROR, -EIO, "STATUS_CTX_TD_ERROR"},
1457 {STATUS_CTX_LICENSE_CLIENT_INVALID, -EIO,
1458 "STATUS_CTX_LICENSE_CLIENT_INVALID"},
1459 {STATUS_CTX_LICENSE_NOT_AVAILABLE, -EIO,
1460 "STATUS_CTX_LICENSE_NOT_AVAILABLE"},
1461 {STATUS_CTX_LICENSE_EXPIRED, -EIO, "STATUS_CTX_LICENSE_EXPIRED"},
1462 {STATUS_CTX_WINSTATION_NOT_FOUND, -EIO,
1463 "STATUS_CTX_WINSTATION_NOT_FOUND"},
1464 {STATUS_CTX_WINSTATION_NAME_COLLISION, -EIO,
1465 "STATUS_CTX_WINSTATION_NAME_COLLISION"},
1466 {STATUS_CTX_WINSTATION_BUSY, -EBUSY, "STATUS_CTX_WINSTATION_BUSY"},
1467 {STATUS_CTX_BAD_VIDEO_MODE, -EIO, "STATUS_CTX_BAD_VIDEO_MODE"},
1468 {STATUS_CTX_GRAPHICS_INVALID, -EIO, "STATUS_CTX_GRAPHICS_INVALID"},
1469 {STATUS_CTX_NOT_CONSOLE, -EIO, "STATUS_CTX_NOT_CONSOLE"},
1470 {STATUS_CTX_CLIENT_QUERY_TIMEOUT, -EIO,
1471 "STATUS_CTX_CLIENT_QUERY_TIMEOUT"},
1472 {STATUS_CTX_CONSOLE_DISCONNECT, -EIO, "STATUS_CTX_CONSOLE_DISCONNECT"},
1473 {STATUS_CTX_CONSOLE_CONNECT, -EIO, "STATUS_CTX_CONSOLE_CONNECT"},
1474 {STATUS_CTX_SHADOW_DENIED, -EIO, "STATUS_CTX_SHADOW_DENIED"},
1475 {STATUS_CTX_WINSTATION_ACCESS_DENIED, -EACCES,
1476 "STATUS_CTX_WINSTATION_ACCESS_DENIED"},
1477 {STATUS_CTX_INVALID_WD, -EIO, "STATUS_CTX_INVALID_WD"},
1478 {STATUS_CTX_WD_NOT_FOUND, -EIO, "STATUS_CTX_WD_NOT_FOUND"},
1479 {STATUS_CTX_SHADOW_INVALID, -EIO, "STATUS_CTX_SHADOW_INVALID"},
1480 {STATUS_CTX_SHADOW_DISABLED, -EIO, "STATUS_CTX_SHADOW_DISABLED"},
1481 {STATUS_RDP_PROTOCOL_ERROR, -EIO, "STATUS_RDP_PROTOCOL_ERROR"},
1482 {STATUS_CTX_CLIENT_LICENSE_NOT_SET, -EIO,
1483 "STATUS_CTX_CLIENT_LICENSE_NOT_SET"},
1484 {STATUS_CTX_CLIENT_LICENSE_IN_USE, -EIO,
1485 "STATUS_CTX_CLIENT_LICENSE_IN_USE"},
1486 {STATUS_CTX_SHADOW_ENDED_BY_MODE_CHANGE, -EIO,
1487 "STATUS_CTX_SHADOW_ENDED_BY_MODE_CHANGE"},
1488 {STATUS_CTX_SHADOW_NOT_RUNNING, -EIO, "STATUS_CTX_SHADOW_NOT_RUNNING"},
1489 {STATUS_CTX_LOGON_DISABLED, -EIO, "STATUS_CTX_LOGON_DISABLED"},
1490 {STATUS_CTX_SECURITY_LAYER_ERROR, -EIO,
1491 "STATUS_CTX_SECURITY_LAYER_ERROR"},
1492 {STATUS_TS_INCOMPATIBLE_SESSIONS, -EIO,
1493 "STATUS_TS_INCOMPATIBLE_SESSIONS"},
1494 {STATUS_MUI_FILE_NOT_FOUND, -EIO, "STATUS_MUI_FILE_NOT_FOUND"},
1495 {STATUS_MUI_INVALID_FILE, -EIO, "STATUS_MUI_INVALID_FILE"},
1496 {STATUS_MUI_INVALID_RC_CONFIG, -EIO, "STATUS_MUI_INVALID_RC_CONFIG"},
1497 {STATUS_MUI_INVALID_LOCALE_NAME, -EIO,
1498 "STATUS_MUI_INVALID_LOCALE_NAME"},
1499 {STATUS_MUI_INVALID_ULTIMATEFALLBACK_NAME, -EIO,
1500 "STATUS_MUI_INVALID_ULTIMATEFALLBACK_NAME"},
1501 {STATUS_MUI_FILE_NOT_LOADED, -EIO, "STATUS_MUI_FILE_NOT_LOADED"},
1502 {STATUS_RESOURCE_ENUM_USER_STOP, -EIO,
1503 "STATUS_RESOURCE_ENUM_USER_STOP"},
1504 {STATUS_CLUSTER_INVALID_NODE, -EIO, "STATUS_CLUSTER_INVALID_NODE"},
1505 {STATUS_CLUSTER_NODE_EXISTS, -EIO, "STATUS_CLUSTER_NODE_EXISTS"},
1506 {STATUS_CLUSTER_JOIN_IN_PROGRESS, -EIO,
1507 "STATUS_CLUSTER_JOIN_IN_PROGRESS"},
1508 {STATUS_CLUSTER_NODE_NOT_FOUND, -EIO, "STATUS_CLUSTER_NODE_NOT_FOUND"},
1509 {STATUS_CLUSTER_LOCAL_NODE_NOT_FOUND, -EIO,
1510 "STATUS_CLUSTER_LOCAL_NODE_NOT_FOUND"},
1511 {STATUS_CLUSTER_NETWORK_EXISTS, -EIO, "STATUS_CLUSTER_NETWORK_EXISTS"},
1512 {STATUS_CLUSTER_NETWORK_NOT_FOUND, -EIO,
1513 "STATUS_CLUSTER_NETWORK_NOT_FOUND"},
1514 {STATUS_CLUSTER_NETINTERFACE_EXISTS, -EIO,
1515 "STATUS_CLUSTER_NETINTERFACE_EXISTS"},
1516 {STATUS_CLUSTER_NETINTERFACE_NOT_FOUND, -EIO,
1517 "STATUS_CLUSTER_NETINTERFACE_NOT_FOUND"},
1518 {STATUS_CLUSTER_INVALID_REQUEST, -EIO,
1519 "STATUS_CLUSTER_INVALID_REQUEST"},
1520 {STATUS_CLUSTER_INVALID_NETWORK_PROVIDER, -EIO,
1521 "STATUS_CLUSTER_INVALID_NETWORK_PROVIDER"},
1522 {STATUS_CLUSTER_NODE_DOWN, -EIO, "STATUS_CLUSTER_NODE_DOWN"},
1523 {STATUS_CLUSTER_NODE_UNREACHABLE, -EIO,
1524 "STATUS_CLUSTER_NODE_UNREACHABLE"},
1525 {STATUS_CLUSTER_NODE_NOT_MEMBER, -EIO,
1526 "STATUS_CLUSTER_NODE_NOT_MEMBER"},
1527 {STATUS_CLUSTER_JOIN_NOT_IN_PROGRESS, -EIO,
1528 "STATUS_CLUSTER_JOIN_NOT_IN_PROGRESS"},
1529 {STATUS_CLUSTER_INVALID_NETWORK, -EIO,
1530 "STATUS_CLUSTER_INVALID_NETWORK"},
1531 {STATUS_CLUSTER_NO_NET_ADAPTERS, -EIO,
1532 "STATUS_CLUSTER_NO_NET_ADAPTERS"},
1533 {STATUS_CLUSTER_NODE_UP, -EIO, "STATUS_CLUSTER_NODE_UP"},
1534 {STATUS_CLUSTER_NODE_PAUSED, -EIO, "STATUS_CLUSTER_NODE_PAUSED"},
1535 {STATUS_CLUSTER_NODE_NOT_PAUSED, -EIO,
1536 "STATUS_CLUSTER_NODE_NOT_PAUSED"},
1537 {STATUS_CLUSTER_NO_SECURITY_CONTEXT, -EIO,
1538 "STATUS_CLUSTER_NO_SECURITY_CONTEXT"},
1539 {STATUS_CLUSTER_NETWORK_NOT_INTERNAL, -EIO,
1540 "STATUS_CLUSTER_NETWORK_NOT_INTERNAL"},
1541 {STATUS_CLUSTER_POISONED, -EIO, "STATUS_CLUSTER_POISONED"},
1542 {STATUS_ACPI_INVALID_OPCODE, -EIO, "STATUS_ACPI_INVALID_OPCODE"},
1543 {STATUS_ACPI_STACK_OVERFLOW, -EIO, "STATUS_ACPI_STACK_OVERFLOW"},
1544 {STATUS_ACPI_ASSERT_FAILED, -EIO, "STATUS_ACPI_ASSERT_FAILED"},
1545 {STATUS_ACPI_INVALID_INDEX, -EIO, "STATUS_ACPI_INVALID_INDEX"},
1546 {STATUS_ACPI_INVALID_ARGUMENT, -EIO, "STATUS_ACPI_INVALID_ARGUMENT"},
1547 {STATUS_ACPI_FATAL, -EIO, "STATUS_ACPI_FATAL"},
1548 {STATUS_ACPI_INVALID_SUPERNAME, -EIO, "STATUS_ACPI_INVALID_SUPERNAME"},
1549 {STATUS_ACPI_INVALID_ARGTYPE, -EIO, "STATUS_ACPI_INVALID_ARGTYPE"},
1550 {STATUS_ACPI_INVALID_OBJTYPE, -EIO, "STATUS_ACPI_INVALID_OBJTYPE"},
1551 {STATUS_ACPI_INVALID_TARGETTYPE, -EIO,
1552 "STATUS_ACPI_INVALID_TARGETTYPE"},
1553 {STATUS_ACPI_INCORRECT_ARGUMENT_COUNT, -EIO,
1554 "STATUS_ACPI_INCORRECT_ARGUMENT_COUNT"},
1555 {STATUS_ACPI_ADDRESS_NOT_MAPPED, -EIO,
1556 "STATUS_ACPI_ADDRESS_NOT_MAPPED"},
1557 {STATUS_ACPI_INVALID_EVENTTYPE, -EIO, "STATUS_ACPI_INVALID_EVENTTYPE"},
1558 {STATUS_ACPI_HANDLER_COLLISION, -EIO, "STATUS_ACPI_HANDLER_COLLISION"},
1559 {STATUS_ACPI_INVALID_DATA, -EIO, "STATUS_ACPI_INVALID_DATA"},
1560 {STATUS_ACPI_INVALID_REGION, -EIO, "STATUS_ACPI_INVALID_REGION"},
1561 {STATUS_ACPI_INVALID_ACCESS_SIZE, -EIO,
1562 "STATUS_ACPI_INVALID_ACCESS_SIZE"},
1563 {STATUS_ACPI_ACQUIRE_GLOBAL_LOCK, -EIO,
1564 "STATUS_ACPI_ACQUIRE_GLOBAL_LOCK"},
1565 {STATUS_ACPI_ALREADY_INITIALIZED, -EIO,
1566 "STATUS_ACPI_ALREADY_INITIALIZED"},
1567 {STATUS_ACPI_NOT_INITIALIZED, -EIO, "STATUS_ACPI_NOT_INITIALIZED"},
1568 {STATUS_ACPI_INVALID_MUTEX_LEVEL, -EIO,
1569 "STATUS_ACPI_INVALID_MUTEX_LEVEL"},
1570 {STATUS_ACPI_MUTEX_NOT_OWNED, -EIO, "STATUS_ACPI_MUTEX_NOT_OWNED"},
1571 {STATUS_ACPI_MUTEX_NOT_OWNER, -EIO, "STATUS_ACPI_MUTEX_NOT_OWNER"},
1572 {STATUS_ACPI_RS_ACCESS, -EIO, "STATUS_ACPI_RS_ACCESS"},
1573 {STATUS_ACPI_INVALID_TABLE, -EIO, "STATUS_ACPI_INVALID_TABLE"},
1574 {STATUS_ACPI_REG_HANDLER_FAILED, -EIO,
1575 "STATUS_ACPI_REG_HANDLER_FAILED"},
1576 {STATUS_ACPI_POWER_REQUEST_FAILED, -EIO,
1577 "STATUS_ACPI_POWER_REQUEST_FAILED"},
1578 {STATUS_SXS_SECTION_NOT_FOUND, -EIO, "STATUS_SXS_SECTION_NOT_FOUND"},
1579 {STATUS_SXS_CANT_GEN_ACTCTX, -EIO, "STATUS_SXS_CANT_GEN_ACTCTX"},
1580 {STATUS_SXS_INVALID_ACTCTXDATA_FORMAT, -EIO,
1581 "STATUS_SXS_INVALID_ACTCTXDATA_FORMAT"},
1582 {STATUS_SXS_ASSEMBLY_NOT_FOUND, -EIO, "STATUS_SXS_ASSEMBLY_NOT_FOUND"},
1583 {STATUS_SXS_MANIFEST_FORMAT_ERROR, -EIO,
1584 "STATUS_SXS_MANIFEST_FORMAT_ERROR"},
1585 {STATUS_SXS_MANIFEST_PARSE_ERROR, -EIO,
1586 "STATUS_SXS_MANIFEST_PARSE_ERROR"},
1587 {STATUS_SXS_ACTIVATION_CONTEXT_DISABLED, -EIO,
1588 "STATUS_SXS_ACTIVATION_CONTEXT_DISABLED"},
1589 {STATUS_SXS_KEY_NOT_FOUND, -EIO, "STATUS_SXS_KEY_NOT_FOUND"},
1590 {STATUS_SXS_VERSION_CONFLICT, -EIO, "STATUS_SXS_VERSION_CONFLICT"},
1591 {STATUS_SXS_WRONG_SECTION_TYPE, -EIO, "STATUS_SXS_WRONG_SECTION_TYPE"},
1592 {STATUS_SXS_THREAD_QUERIES_DISABLED, -EIO,
1593 "STATUS_SXS_THREAD_QUERIES_DISABLED"},
1594 {STATUS_SXS_ASSEMBLY_MISSING, -EIO, "STATUS_SXS_ASSEMBLY_MISSING"},
1595 {STATUS_SXS_PROCESS_DEFAULT_ALREADY_SET, -EIO,
1596 "STATUS_SXS_PROCESS_DEFAULT_ALREADY_SET"},
1597 {STATUS_SXS_EARLY_DEACTIVATION, -EIO, "STATUS_SXS_EARLY_DEACTIVATION"},
1598 {STATUS_SXS_INVALID_DEACTIVATION, -EIO,
1599 "STATUS_SXS_INVALID_DEACTIVATION"},
1600 {STATUS_SXS_MULTIPLE_DEACTIVATION, -EIO,
1601 "STATUS_SXS_MULTIPLE_DEACTIVATION"},
1602 {STATUS_SXS_SYSTEM_DEFAULT_ACTIVATION_CONTEXT_EMPTY, -EIO,
1603 "STATUS_SXS_SYSTEM_DEFAULT_ACTIVATION_CONTEXT_EMPTY"},
1604 {STATUS_SXS_PROCESS_TERMINATION_REQUESTED, -EIO,
1605 "STATUS_SXS_PROCESS_TERMINATION_REQUESTED"},
1606 {STATUS_SXS_CORRUPT_ACTIVATION_STACK, -EIO,
1607 "STATUS_SXS_CORRUPT_ACTIVATION_STACK"},
1608 {STATUS_SXS_CORRUPTION, -EIO, "STATUS_SXS_CORRUPTION"},
1609 {STATUS_SXS_INVALID_IDENTITY_ATTRIBUTE_VALUE, -EIO,
1610 "STATUS_SXS_INVALID_IDENTITY_ATTRIBUTE_VALUE"},
1611 {STATUS_SXS_INVALID_IDENTITY_ATTRIBUTE_NAME, -EIO,
1612 "STATUS_SXS_INVALID_IDENTITY_ATTRIBUTE_NAME"},
1613 {STATUS_SXS_IDENTITY_DUPLICATE_ATTRIBUTE, -EIO,
1614 "STATUS_SXS_IDENTITY_DUPLICATE_ATTRIBUTE"},
1615 {STATUS_SXS_IDENTITY_PARSE_ERROR, -EIO,
1616 "STATUS_SXS_IDENTITY_PARSE_ERROR"},
1617 {STATUS_SXS_COMPONENT_STORE_CORRUPT, -EIO,
1618 "STATUS_SXS_COMPONENT_STORE_CORRUPT"},
1619 {STATUS_SXS_FILE_HASH_MISMATCH, -EIO, "STATUS_SXS_FILE_HASH_MISMATCH"},
1620 {STATUS_SXS_MANIFEST_IDENTITY_SAME_BUT_CONTENTS_DIFFERENT, -EIO,
1621 "STATUS_SXS_MANIFEST_IDENTITY_SAME_BUT_CONTENTS_DIFFERENT"},
1622 {STATUS_SXS_IDENTITIES_DIFFERENT, -EIO,
1623 "STATUS_SXS_IDENTITIES_DIFFERENT"},
1624 {STATUS_SXS_ASSEMBLY_IS_NOT_A_DEPLOYMENT, -EIO,
1625 "STATUS_SXS_ASSEMBLY_IS_NOT_A_DEPLOYMENT"},
1626 {STATUS_SXS_FILE_NOT_PART_OF_ASSEMBLY, -EIO,
1627 "STATUS_SXS_FILE_NOT_PART_OF_ASSEMBLY"},
1628 {STATUS_ADVANCED_INSTALLER_FAILED, -EIO,
1629 "STATUS_ADVANCED_INSTALLER_FAILED"},
1630 {STATUS_XML_ENCODING_MISMATCH, -EIO, "STATUS_XML_ENCODING_MISMATCH"},
1631 {STATUS_SXS_MANIFEST_TOO_BIG, -EIO, "STATUS_SXS_MANIFEST_TOO_BIG"},
1632 {STATUS_SXS_SETTING_NOT_REGISTERED, -EIO,
1633 "STATUS_SXS_SETTING_NOT_REGISTERED"},
1634 {STATUS_SXS_TRANSACTION_CLOSURE_INCOMPLETE, -EIO,
1635 "STATUS_SXS_TRANSACTION_CLOSURE_INCOMPLETE"},
1636 {STATUS_SMI_PRIMITIVE_INSTALLER_FAILED, -EIO,
1637 "STATUS_SMI_PRIMITIVE_INSTALLER_FAILED"},
1638 {STATUS_GENERIC_COMMAND_FAILED, -EIO, "STATUS_GENERIC_COMMAND_FAILED"},
1639 {STATUS_SXS_FILE_HASH_MISSING, -EIO, "STATUS_SXS_FILE_HASH_MISSING"},
1640 {STATUS_TRANSACTIONAL_CONFLICT, -EIO, "STATUS_TRANSACTIONAL_CONFLICT"},
1641 {STATUS_INVALID_TRANSACTION, -EIO, "STATUS_INVALID_TRANSACTION"},
1642 {STATUS_TRANSACTION_NOT_ACTIVE, -EIO, "STATUS_TRANSACTION_NOT_ACTIVE"},
1643 {STATUS_TM_INITIALIZATION_FAILED, -EIO,
1644 "STATUS_TM_INITIALIZATION_FAILED"},
1645 {STATUS_RM_NOT_ACTIVE, -EIO, "STATUS_RM_NOT_ACTIVE"},
1646 {STATUS_RM_METADATA_CORRUPT, -EIO, "STATUS_RM_METADATA_CORRUPT"},
1647 {STATUS_TRANSACTION_NOT_JOINED, -EIO, "STATUS_TRANSACTION_NOT_JOINED"},
1648 {STATUS_DIRECTORY_NOT_RM, -EIO, "STATUS_DIRECTORY_NOT_RM"},
1649 {STATUS_TRANSACTIONS_UNSUPPORTED_REMOTE, -EIO,
1650 "STATUS_TRANSACTIONS_UNSUPPORTED_REMOTE"},
1651 {STATUS_LOG_RESIZE_INVALID_SIZE, -EIO,
1652 "STATUS_LOG_RESIZE_INVALID_SIZE"},
1653 {STATUS_REMOTE_FILE_VERSION_MISMATCH, -EIO,
1654 "STATUS_REMOTE_FILE_VERSION_MISMATCH"},
1655 {STATUS_CRM_PROTOCOL_ALREADY_EXISTS, -EIO,
1656 "STATUS_CRM_PROTOCOL_ALREADY_EXISTS"},
1657 {STATUS_TRANSACTION_PROPAGATION_FAILED, -EIO,
1658 "STATUS_TRANSACTION_PROPAGATION_FAILED"},
1659 {STATUS_CRM_PROTOCOL_NOT_FOUND, -EIO, "STATUS_CRM_PROTOCOL_NOT_FOUND"},
1660 {STATUS_TRANSACTION_SUPERIOR_EXISTS, -EIO,
1661 "STATUS_TRANSACTION_SUPERIOR_EXISTS"},
1662 {STATUS_TRANSACTION_REQUEST_NOT_VALID, -EIO,
1663 "STATUS_TRANSACTION_REQUEST_NOT_VALID"},
1664 {STATUS_TRANSACTION_NOT_REQUESTED, -EIO,
1665 "STATUS_TRANSACTION_NOT_REQUESTED"},
1666 {STATUS_TRANSACTION_ALREADY_ABORTED, -EIO,
1667 "STATUS_TRANSACTION_ALREADY_ABORTED"},
1668 {STATUS_TRANSACTION_ALREADY_COMMITTED, -EIO,
1669 "STATUS_TRANSACTION_ALREADY_COMMITTED"},
1670 {STATUS_TRANSACTION_INVALID_MARSHALL_BUFFER, -EIO,
1671 "STATUS_TRANSACTION_INVALID_MARSHALL_BUFFER"},
1672 {STATUS_CURRENT_TRANSACTION_NOT_VALID, -EIO,
1673 "STATUS_CURRENT_TRANSACTION_NOT_VALID"},
1674 {STATUS_LOG_GROWTH_FAILED, -EIO, "STATUS_LOG_GROWTH_FAILED"},
1675 {STATUS_OBJECT_NO_LONGER_EXISTS, -EIO,
1676 "STATUS_OBJECT_NO_LONGER_EXISTS"},
1677 {STATUS_STREAM_MINIVERSION_NOT_FOUND, -EIO,
1678 "STATUS_STREAM_MINIVERSION_NOT_FOUND"},
1679 {STATUS_STREAM_MINIVERSION_NOT_VALID, -EIO,
1680 "STATUS_STREAM_MINIVERSION_NOT_VALID"},
1681 {STATUS_MINIVERSION_INACCESSIBLE_FROM_SPECIFIED_TRANSACTION, -EIO,
1682 "STATUS_MINIVERSION_INACCESSIBLE_FROM_SPECIFIED_TRANSACTION"},
1683 {STATUS_CANT_OPEN_MINIVERSION_WITH_MODIFY_INTENT, -EIO,
1684 "STATUS_CANT_OPEN_MINIVERSION_WITH_MODIFY_INTENT"},
1685 {STATUS_CANT_CREATE_MORE_STREAM_MINIVERSIONS, -EIO,
1686 "STATUS_CANT_CREATE_MORE_STREAM_MINIVERSIONS"},
1687 {STATUS_HANDLE_NO_LONGER_VALID, -EIO, "STATUS_HANDLE_NO_LONGER_VALID"},
1688 {STATUS_LOG_CORRUPTION_DETECTED, -EIO,
1689 "STATUS_LOG_CORRUPTION_DETECTED"},
1690 {STATUS_RM_DISCONNECTED, -EIO, "STATUS_RM_DISCONNECTED"},
1691 {STATUS_ENLISTMENT_NOT_SUPERIOR, -EIO,
1692 "STATUS_ENLISTMENT_NOT_SUPERIOR"},
1693 {STATUS_FILE_IDENTITY_NOT_PERSISTENT, -EIO,
1694 "STATUS_FILE_IDENTITY_NOT_PERSISTENT"},
1695 {STATUS_CANT_BREAK_TRANSACTIONAL_DEPENDENCY, -EIO,
1696 "STATUS_CANT_BREAK_TRANSACTIONAL_DEPENDENCY"},
1697 {STATUS_CANT_CROSS_RM_BOUNDARY, -EIO, "STATUS_CANT_CROSS_RM_BOUNDARY"},
1698 {STATUS_TXF_DIR_NOT_EMPTY, -EIO, "STATUS_TXF_DIR_NOT_EMPTY"},
1699 {STATUS_INDOUBT_TRANSACTIONS_EXIST, -EIO,
1700 "STATUS_INDOUBT_TRANSACTIONS_EXIST"},
1701 {STATUS_TM_VOLATILE, -EIO, "STATUS_TM_VOLATILE"},
1702 {STATUS_ROLLBACK_TIMER_EXPIRED, -EIO, "STATUS_ROLLBACK_TIMER_EXPIRED"},
1703 {STATUS_TXF_ATTRIBUTE_CORRUPT, -EIO, "STATUS_TXF_ATTRIBUTE_CORRUPT"},
1704 {STATUS_EFS_NOT_ALLOWED_IN_TRANSACTION, -EIO,
1705 "STATUS_EFS_NOT_ALLOWED_IN_TRANSACTION"},
1706 {STATUS_TRANSACTIONAL_OPEN_NOT_ALLOWED, -EIO,
1707 "STATUS_TRANSACTIONAL_OPEN_NOT_ALLOWED"},
1708 {STATUS_TRANSACTED_MAPPING_UNSUPPORTED_REMOTE, -EIO,
1709 "STATUS_TRANSACTED_MAPPING_UNSUPPORTED_REMOTE"},
1710 {STATUS_TRANSACTION_REQUIRED_PROMOTION, -EIO,
1711 "STATUS_TRANSACTION_REQUIRED_PROMOTION"},
1712 {STATUS_CANNOT_EXECUTE_FILE_IN_TRANSACTION, -EIO,
1713 "STATUS_CANNOT_EXECUTE_FILE_IN_TRANSACTION"},
1714 {STATUS_TRANSACTIONS_NOT_FROZEN, -EIO,
1715 "STATUS_TRANSACTIONS_NOT_FROZEN"},
1716 {STATUS_TRANSACTION_FREEZE_IN_PROGRESS, -EIO,
1717 "STATUS_TRANSACTION_FREEZE_IN_PROGRESS"},
1718 {STATUS_NOT_SNAPSHOT_VOLUME, -EIO, "STATUS_NOT_SNAPSHOT_VOLUME"},
1719 {STATUS_NO_SAVEPOINT_WITH_OPEN_FILES, -EIO,
1720 "STATUS_NO_SAVEPOINT_WITH_OPEN_FILES"},
1721 {STATUS_SPARSE_NOT_ALLOWED_IN_TRANSACTION, -EIO,
1722 "STATUS_SPARSE_NOT_ALLOWED_IN_TRANSACTION"},
1723 {STATUS_TM_IDENTITY_MISMATCH, -EIO, "STATUS_TM_IDENTITY_MISMATCH"},
1724 {STATUS_FLOATED_SECTION, -EIO, "STATUS_FLOATED_SECTION"},
1725 {STATUS_CANNOT_ACCEPT_TRANSACTED_WORK, -EIO,
1726 "STATUS_CANNOT_ACCEPT_TRANSACTED_WORK"},
1727 {STATUS_CANNOT_ABORT_TRANSACTIONS, -EIO,
1728 "STATUS_CANNOT_ABORT_TRANSACTIONS"},
1729 {STATUS_TRANSACTION_NOT_FOUND, -EIO, "STATUS_TRANSACTION_NOT_FOUND"},
1730 {STATUS_RESOURCEMANAGER_NOT_FOUND, -EIO,
1731 "STATUS_RESOURCEMANAGER_NOT_FOUND"},
1732 {STATUS_ENLISTMENT_NOT_FOUND, -EIO, "STATUS_ENLISTMENT_NOT_FOUND"},
1733 {STATUS_TRANSACTIONMANAGER_NOT_FOUND, -EIO,
1734 "STATUS_TRANSACTIONMANAGER_NOT_FOUND"},
1735 {STATUS_TRANSACTIONMANAGER_NOT_ONLINE, -EIO,
1736 "STATUS_TRANSACTIONMANAGER_NOT_ONLINE"},
1737 {STATUS_TRANSACTIONMANAGER_RECOVERY_NAME_COLLISION, -EIO,
1738 "STATUS_TRANSACTIONMANAGER_RECOVERY_NAME_COLLISION"},
1739 {STATUS_TRANSACTION_NOT_ROOT, -EIO, "STATUS_TRANSACTION_NOT_ROOT"},
1740 {STATUS_TRANSACTION_OBJECT_EXPIRED, -EIO,
1741 "STATUS_TRANSACTION_OBJECT_EXPIRED"},
1742 {STATUS_COMPRESSION_NOT_ALLOWED_IN_TRANSACTION, -EIO,
1743 "STATUS_COMPRESSION_NOT_ALLOWED_IN_TRANSACTION"},
1744 {STATUS_TRANSACTION_RESPONSE_NOT_ENLISTED, -EIO,
1745 "STATUS_TRANSACTION_RESPONSE_NOT_ENLISTED"},
1746 {STATUS_TRANSACTION_RECORD_TOO_LONG, -EIO,
1747 "STATUS_TRANSACTION_RECORD_TOO_LONG"},
1748 {STATUS_NO_LINK_TRACKING_IN_TRANSACTION, -EIO,
1749 "STATUS_NO_LINK_TRACKING_IN_TRANSACTION"},
1750 {STATUS_OPERATION_NOT_SUPPORTED_IN_TRANSACTION, -EOPNOTSUPP,
1751 "STATUS_OPERATION_NOT_SUPPORTED_IN_TRANSACTION"},
1752 {STATUS_TRANSACTION_INTEGRITY_VIOLATED, -EIO,
1753 "STATUS_TRANSACTION_INTEGRITY_VIOLATED"},
1754 {STATUS_LOG_SECTOR_INVALID, -EIO, "STATUS_LOG_SECTOR_INVALID"},
1755 {STATUS_LOG_SECTOR_PARITY_INVALID, -EIO,
1756 "STATUS_LOG_SECTOR_PARITY_INVALID"},
1757 {STATUS_LOG_SECTOR_REMAPPED, -EIO, "STATUS_LOG_SECTOR_REMAPPED"},
1758 {STATUS_LOG_BLOCK_INCOMPLETE, -EIO, "STATUS_LOG_BLOCK_INCOMPLETE"},
1759 {STATUS_LOG_INVALID_RANGE, -EIO, "STATUS_LOG_INVALID_RANGE"},
1760 {STATUS_LOG_BLOCKS_EXHAUSTED, -EIO, "STATUS_LOG_BLOCKS_EXHAUSTED"},
1761 {STATUS_LOG_READ_CONTEXT_INVALID, -EIO,
1762 "STATUS_LOG_READ_CONTEXT_INVALID"},
1763 {STATUS_LOG_RESTART_INVALID, -EIO, "STATUS_LOG_RESTART_INVALID"},
1764 {STATUS_LOG_BLOCK_VERSION, -EIO, "STATUS_LOG_BLOCK_VERSION"},
1765 {STATUS_LOG_BLOCK_INVALID, -EIO, "STATUS_LOG_BLOCK_INVALID"},
1766 {STATUS_LOG_READ_MODE_INVALID, -EIO, "STATUS_LOG_READ_MODE_INVALID"},
1767 {STATUS_LOG_METADATA_CORRUPT, -EIO, "STATUS_LOG_METADATA_CORRUPT"},
1768 {STATUS_LOG_METADATA_INVALID, -EIO, "STATUS_LOG_METADATA_INVALID"},
1769 {STATUS_LOG_METADATA_INCONSISTENT, -EIO,
1770 "STATUS_LOG_METADATA_INCONSISTENT"},
1771 {STATUS_LOG_RESERVATION_INVALID, -EIO,
1772 "STATUS_LOG_RESERVATION_INVALID"},
1773 {STATUS_LOG_CANT_DELETE, -EIO, "STATUS_LOG_CANT_DELETE"},
1774 {STATUS_LOG_CONTAINER_LIMIT_EXCEEDED, -EIO,
1775 "STATUS_LOG_CONTAINER_LIMIT_EXCEEDED"},
1776 {STATUS_LOG_START_OF_LOG, -EIO, "STATUS_LOG_START_OF_LOG"},
1777 {STATUS_LOG_POLICY_ALREADY_INSTALLED, -EIO,
1778 "STATUS_LOG_POLICY_ALREADY_INSTALLED"},
1779 {STATUS_LOG_POLICY_NOT_INSTALLED, -EIO,
1780 "STATUS_LOG_POLICY_NOT_INSTALLED"},
1781 {STATUS_LOG_POLICY_INVALID, -EIO, "STATUS_LOG_POLICY_INVALID"},
1782 {STATUS_LOG_POLICY_CONFLICT, -EIO, "STATUS_LOG_POLICY_CONFLICT"},
1783 {STATUS_LOG_PINNED_ARCHIVE_TAIL, -EIO,
1784 "STATUS_LOG_PINNED_ARCHIVE_TAIL"},
1785 {STATUS_LOG_RECORD_NONEXISTENT, -EIO, "STATUS_LOG_RECORD_NONEXISTENT"},
1786 {STATUS_LOG_RECORDS_RESERVED_INVALID, -EIO,
1787 "STATUS_LOG_RECORDS_RESERVED_INVALID"},
1788 {STATUS_LOG_SPACE_RESERVED_INVALID, -EIO,
1789 "STATUS_LOG_SPACE_RESERVED_INVALID"},
1790 {STATUS_LOG_TAIL_INVALID, -EIO, "STATUS_LOG_TAIL_INVALID"},
1791 {STATUS_LOG_FULL, -EIO, "STATUS_LOG_FULL"},
1792 {STATUS_LOG_MULTIPLEXED, -EIO, "STATUS_LOG_MULTIPLEXED"},
1793 {STATUS_LOG_DEDICATED, -EIO, "STATUS_LOG_DEDICATED"},
1794 {STATUS_LOG_ARCHIVE_NOT_IN_PROGRESS, -EIO,
1795 "STATUS_LOG_ARCHIVE_NOT_IN_PROGRESS"},
1796 {STATUS_LOG_ARCHIVE_IN_PROGRESS, -EIO,
1797 "STATUS_LOG_ARCHIVE_IN_PROGRESS"},
1798 {STATUS_LOG_EPHEMERAL, -EIO, "STATUS_LOG_EPHEMERAL"},
1799 {STATUS_LOG_NOT_ENOUGH_CONTAINERS, -EIO,
1800 "STATUS_LOG_NOT_ENOUGH_CONTAINERS"},
1801 {STATUS_LOG_CLIENT_ALREADY_REGISTERED, -EIO,
1802 "STATUS_LOG_CLIENT_ALREADY_REGISTERED"},
1803 {STATUS_LOG_CLIENT_NOT_REGISTERED, -EIO,
1804 "STATUS_LOG_CLIENT_NOT_REGISTERED"},
1805 {STATUS_LOG_FULL_HANDLER_IN_PROGRESS, -EIO,
1806 "STATUS_LOG_FULL_HANDLER_IN_PROGRESS"},
1807 {STATUS_LOG_CONTAINER_READ_FAILED, -EIO,
1808 "STATUS_LOG_CONTAINER_READ_FAILED"},
1809 {STATUS_LOG_CONTAINER_WRITE_FAILED, -EIO,
1810 "STATUS_LOG_CONTAINER_WRITE_FAILED"},
1811 {STATUS_LOG_CONTAINER_OPEN_FAILED, -EIO,
1812 "STATUS_LOG_CONTAINER_OPEN_FAILED"},
1813 {STATUS_LOG_CONTAINER_STATE_INVALID, -EIO,
1814 "STATUS_LOG_CONTAINER_STATE_INVALID"},
1815 {STATUS_LOG_STATE_INVALID, -EIO, "STATUS_LOG_STATE_INVALID"},
1816 {STATUS_LOG_PINNED, -EIO, "STATUS_LOG_PINNED"},
1817 {STATUS_LOG_METADATA_FLUSH_FAILED, -EIO,
1818 "STATUS_LOG_METADATA_FLUSH_FAILED"},
1819 {STATUS_LOG_INCONSISTENT_SECURITY, -EIO,
1820 "STATUS_LOG_INCONSISTENT_SECURITY"},
1821 {STATUS_LOG_APPENDED_FLUSH_FAILED, -EIO,
1822 "STATUS_LOG_APPENDED_FLUSH_FAILED"},
1823 {STATUS_LOG_PINNED_RESERVATION, -EIO, "STATUS_LOG_PINNED_RESERVATION"},
1824 {STATUS_VIDEO_HUNG_DISPLAY_DRIVER_THREAD, -EIO,
1825 "STATUS_VIDEO_HUNG_DISPLAY_DRIVER_THREAD"},
1826 {STATUS_FLT_NO_HANDLER_DEFINED, -EIO, "STATUS_FLT_NO_HANDLER_DEFINED"},
1827 {STATUS_FLT_CONTEXT_ALREADY_DEFINED, -EIO,
1828 "STATUS_FLT_CONTEXT_ALREADY_DEFINED"},
1829 {STATUS_FLT_INVALID_ASYNCHRONOUS_REQUEST, -EIO,
1830 "STATUS_FLT_INVALID_ASYNCHRONOUS_REQUEST"},
1831 {STATUS_FLT_DISALLOW_FAST_IO, -EIO, "STATUS_FLT_DISALLOW_FAST_IO"},
1832 {STATUS_FLT_INVALID_NAME_REQUEST, -EIO,
1833 "STATUS_FLT_INVALID_NAME_REQUEST"},
1834 {STATUS_FLT_NOT_SAFE_TO_POST_OPERATION, -EIO,
1835 "STATUS_FLT_NOT_SAFE_TO_POST_OPERATION"},
1836 {STATUS_FLT_NOT_INITIALIZED, -EIO, "STATUS_FLT_NOT_INITIALIZED"},
1837 {STATUS_FLT_FILTER_NOT_READY, -EIO, "STATUS_FLT_FILTER_NOT_READY"},
1838 {STATUS_FLT_POST_OPERATION_CLEANUP, -EIO,
1839 "STATUS_FLT_POST_OPERATION_CLEANUP"},
1840 {STATUS_FLT_INTERNAL_ERROR, -EIO, "STATUS_FLT_INTERNAL_ERROR"},
1841 {STATUS_FLT_DELETING_OBJECT, -EIO, "STATUS_FLT_DELETING_OBJECT"},
1842 {STATUS_FLT_MUST_BE_NONPAGED_POOL, -EIO,
1843 "STATUS_FLT_MUST_BE_NONPAGED_POOL"},
1844 {STATUS_FLT_DUPLICATE_ENTRY, -EIO, "STATUS_FLT_DUPLICATE_ENTRY"},
1845 {STATUS_FLT_CBDQ_DISABLED, -EIO, "STATUS_FLT_CBDQ_DISABLED"},
1846 {STATUS_FLT_DO_NOT_ATTACH, -EIO, "STATUS_FLT_DO_NOT_ATTACH"},
1847 {STATUS_FLT_DO_NOT_DETACH, -EIO, "STATUS_FLT_DO_NOT_DETACH"},
1848 {STATUS_FLT_INSTANCE_ALTITUDE_COLLISION, -EIO,
1849 "STATUS_FLT_INSTANCE_ALTITUDE_COLLISION"},
1850 {STATUS_FLT_INSTANCE_NAME_COLLISION, -EIO,
1851 "STATUS_FLT_INSTANCE_NAME_COLLISION"},
1852 {STATUS_FLT_FILTER_NOT_FOUND, -EIO, "STATUS_FLT_FILTER_NOT_FOUND"},
1853 {STATUS_FLT_VOLUME_NOT_FOUND, -EIO, "STATUS_FLT_VOLUME_NOT_FOUND"},
1854 {STATUS_FLT_INSTANCE_NOT_FOUND, -EIO, "STATUS_FLT_INSTANCE_NOT_FOUND"},
1855 {STATUS_FLT_CONTEXT_ALLOCATION_NOT_FOUND, -EIO,
1856 "STATUS_FLT_CONTEXT_ALLOCATION_NOT_FOUND"},
1857 {STATUS_FLT_INVALID_CONTEXT_REGISTRATION, -EIO,
1858 "STATUS_FLT_INVALID_CONTEXT_REGISTRATION"},
1859 {STATUS_FLT_NAME_CACHE_MISS, -EIO, "STATUS_FLT_NAME_CACHE_MISS"},
1860 {STATUS_FLT_NO_DEVICE_OBJECT, -EIO, "STATUS_FLT_NO_DEVICE_OBJECT"},
1861 {STATUS_FLT_VOLUME_ALREADY_MOUNTED, -EIO,
1862 "STATUS_FLT_VOLUME_ALREADY_MOUNTED"},
1863 {STATUS_FLT_ALREADY_ENLISTED, -EIO, "STATUS_FLT_ALREADY_ENLISTED"},
1864 {STATUS_FLT_CONTEXT_ALREADY_LINKED, -EIO,
1865 "STATUS_FLT_CONTEXT_ALREADY_LINKED"},
1866 {STATUS_FLT_NO_WAITER_FOR_REPLY, -EIO,
1867 "STATUS_FLT_NO_WAITER_FOR_REPLY"},
1868 {STATUS_MONITOR_NO_DESCRIPTOR, -EIO, "STATUS_MONITOR_NO_DESCRIPTOR"},
1869 {STATUS_MONITOR_UNKNOWN_DESCRIPTOR_FORMAT, -EIO,
1870 "STATUS_MONITOR_UNKNOWN_DESCRIPTOR_FORMAT"},
1871 {STATUS_MONITOR_INVALID_DESCRIPTOR_CHECKSUM, -EIO,
1872 "STATUS_MONITOR_INVALID_DESCRIPTOR_CHECKSUM"},
1873 {STATUS_MONITOR_INVALID_STANDARD_TIMING_BLOCK, -EIO,
1874 "STATUS_MONITOR_INVALID_STANDARD_TIMING_BLOCK"},
1875 {STATUS_MONITOR_WMI_DATABLOCK_REGISTRATION_FAILED, -EIO,
1876 "STATUS_MONITOR_WMI_DATABLOCK_REGISTRATION_FAILED"},
1877 {STATUS_MONITOR_INVALID_SERIAL_NUMBER_MONDSC_BLOCK, -EIO,
1878 "STATUS_MONITOR_INVALID_SERIAL_NUMBER_MONDSC_BLOCK"},
1879 {STATUS_MONITOR_INVALID_USER_FRIENDLY_MONDSC_BLOCK, -EIO,
1880 "STATUS_MONITOR_INVALID_USER_FRIENDLY_MONDSC_BLOCK"},
1881 {STATUS_MONITOR_NO_MORE_DESCRIPTOR_DATA, -EIO,
1882 "STATUS_MONITOR_NO_MORE_DESCRIPTOR_DATA"},
1883 {STATUS_MONITOR_INVALID_DETAILED_TIMING_BLOCK, -EIO,
1884 "STATUS_MONITOR_INVALID_DETAILED_TIMING_BLOCK"},
1885 {STATUS_GRAPHICS_NOT_EXCLUSIVE_MODE_OWNER, -EIO,
1886 "STATUS_GRAPHICS_NOT_EXCLUSIVE_MODE_OWNER"},
1887 {STATUS_GRAPHICS_INSUFFICIENT_DMA_BUFFER, -EIO,
1888 "STATUS_GRAPHICS_INSUFFICIENT_DMA_BUFFER"},
1889 {STATUS_GRAPHICS_INVALID_DISPLAY_ADAPTER, -EIO,
1890 "STATUS_GRAPHICS_INVALID_DISPLAY_ADAPTER"},
1891 {STATUS_GRAPHICS_ADAPTER_WAS_RESET, -EIO,
1892 "STATUS_GRAPHICS_ADAPTER_WAS_RESET"},
1893 {STATUS_GRAPHICS_INVALID_DRIVER_MODEL, -EIO,
1894 "STATUS_GRAPHICS_INVALID_DRIVER_MODEL"},
1895 {STATUS_GRAPHICS_PRESENT_MODE_CHANGED, -EIO,
1896 "STATUS_GRAPHICS_PRESENT_MODE_CHANGED"},
1897 {STATUS_GRAPHICS_PRESENT_OCCLUDED, -EIO,
1898 "STATUS_GRAPHICS_PRESENT_OCCLUDED"},
1899 {STATUS_GRAPHICS_PRESENT_DENIED, -EIO,
1900 "STATUS_GRAPHICS_PRESENT_DENIED"},
1901 {STATUS_GRAPHICS_CANNOTCOLORCONVERT, -EIO,
1902 "STATUS_GRAPHICS_CANNOTCOLORCONVERT"},
1903 {STATUS_GRAPHICS_NO_VIDEO_MEMORY, -EIO,
1904 "STATUS_GRAPHICS_NO_VIDEO_MEMORY"},
1905 {STATUS_GRAPHICS_CANT_LOCK_MEMORY, -EIO,
1906 "STATUS_GRAPHICS_CANT_LOCK_MEMORY"},
1907 {STATUS_GRAPHICS_ALLOCATION_BUSY, -EBUSY,
1908 "STATUS_GRAPHICS_ALLOCATION_BUSY"},
1909 {STATUS_GRAPHICS_TOO_MANY_REFERENCES, -EIO,
1910 "STATUS_GRAPHICS_TOO_MANY_REFERENCES"},
1911 {STATUS_GRAPHICS_TRY_AGAIN_LATER, -EIO,
1912 "STATUS_GRAPHICS_TRY_AGAIN_LATER"},
1913 {STATUS_GRAPHICS_TRY_AGAIN_NOW, -EIO, "STATUS_GRAPHICS_TRY_AGAIN_NOW"},
1914 {STATUS_GRAPHICS_ALLOCATION_INVALID, -EIO,
1915 "STATUS_GRAPHICS_ALLOCATION_INVALID"},
1916 {STATUS_GRAPHICS_UNSWIZZLING_APERTURE_UNAVAILABLE, -EIO,
1917 "STATUS_GRAPHICS_UNSWIZZLING_APERTURE_UNAVAILABLE"},
1918 {STATUS_GRAPHICS_UNSWIZZLING_APERTURE_UNSUPPORTED, -EIO,
1919 "STATUS_GRAPHICS_UNSWIZZLING_APERTURE_UNSUPPORTED"},
1920 {STATUS_GRAPHICS_CANT_EVICT_PINNED_ALLOCATION, -EIO,
1921 "STATUS_GRAPHICS_CANT_EVICT_PINNED_ALLOCATION"},
1922 {STATUS_GRAPHICS_INVALID_ALLOCATION_USAGE, -EIO,
1923 "STATUS_GRAPHICS_INVALID_ALLOCATION_USAGE"},
1924 {STATUS_GRAPHICS_CANT_RENDER_LOCKED_ALLOCATION, -EIO,
1925 "STATUS_GRAPHICS_CANT_RENDER_LOCKED_ALLOCATION"},
1926 {STATUS_GRAPHICS_ALLOCATION_CLOSED, -EIO,
1927 "STATUS_GRAPHICS_ALLOCATION_CLOSED"},
1928 {STATUS_GRAPHICS_INVALID_ALLOCATION_INSTANCE, -EIO,
1929 "STATUS_GRAPHICS_INVALID_ALLOCATION_INSTANCE"},
1930 {STATUS_GRAPHICS_INVALID_ALLOCATION_HANDLE, -EIO,
1931 "STATUS_GRAPHICS_INVALID_ALLOCATION_HANDLE"},
1932 {STATUS_GRAPHICS_WRONG_ALLOCATION_DEVICE, -EIO,
1933 "STATUS_GRAPHICS_WRONG_ALLOCATION_DEVICE"},
1934 {STATUS_GRAPHICS_ALLOCATION_CONTENT_LOST, -EIO,
1935 "STATUS_GRAPHICS_ALLOCATION_CONTENT_LOST"},
1936 {STATUS_GRAPHICS_GPU_EXCEPTION_ON_DEVICE, -EIO,
1937 "STATUS_GRAPHICS_GPU_EXCEPTION_ON_DEVICE"},
1938 {STATUS_GRAPHICS_INVALID_VIDPN_TOPOLOGY, -EIO,
1939 "STATUS_GRAPHICS_INVALID_VIDPN_TOPOLOGY"},
1940 {STATUS_GRAPHICS_VIDPN_TOPOLOGY_NOT_SUPPORTED, -EIO,
1941 "STATUS_GRAPHICS_VIDPN_TOPOLOGY_NOT_SUPPORTED"},
1942 {STATUS_GRAPHICS_VIDPN_TOPOLOGY_CURRENTLY_NOT_SUPPORTED, -EIO,
1943 "STATUS_GRAPHICS_VIDPN_TOPOLOGY_CURRENTLY_NOT_SUPPORTED"},
1944 {STATUS_GRAPHICS_INVALID_VIDPN, -EIO, "STATUS_GRAPHICS_INVALID_VIDPN"},
1945 {STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE, -EIO,
1946 "STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE"},
1947 {STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_TARGET, -EIO,
1948 "STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_TARGET"},
1949 {STATUS_GRAPHICS_VIDPN_MODALITY_NOT_SUPPORTED, -EIO,
1950 "STATUS_GRAPHICS_VIDPN_MODALITY_NOT_SUPPORTED"},
1951 {STATUS_GRAPHICS_INVALID_VIDPN_SOURCEMODESET, -EIO,
1952 "STATUS_GRAPHICS_INVALID_VIDPN_SOURCEMODESET"},
1953 {STATUS_GRAPHICS_INVALID_VIDPN_TARGETMODESET, -EIO,
1954 "STATUS_GRAPHICS_INVALID_VIDPN_TARGETMODESET"},
1955 {STATUS_GRAPHICS_INVALID_FREQUENCY, -EIO,
1956 "STATUS_GRAPHICS_INVALID_FREQUENCY"},
1957 {STATUS_GRAPHICS_INVALID_ACTIVE_REGION, -EIO,
1958 "STATUS_GRAPHICS_INVALID_ACTIVE_REGION"},
1959 {STATUS_GRAPHICS_INVALID_TOTAL_REGION, -EIO,
1960 "STATUS_GRAPHICS_INVALID_TOTAL_REGION"},
1961 {STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE_MODE, -EIO,
1962 "STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE_MODE"},
1963 {STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_TARGET_MODE, -EIO,
1964 "STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_TARGET_MODE"},
1965 {STATUS_GRAPHICS_PINNED_MODE_MUST_REMAIN_IN_SET, -EIO,
1966 "STATUS_GRAPHICS_PINNED_MODE_MUST_REMAIN_IN_SET"},
1967 {STATUS_GRAPHICS_PATH_ALREADY_IN_TOPOLOGY, -EIO,
1968 "STATUS_GRAPHICS_PATH_ALREADY_IN_TOPOLOGY"},
1969 {STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET, -EIO,
1970 "STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET"},
1971 {STATUS_GRAPHICS_INVALID_VIDEOPRESENTSOURCESET, -EIO,
1972 "STATUS_GRAPHICS_INVALID_VIDEOPRESENTSOURCESET"},
1973 {STATUS_GRAPHICS_INVALID_VIDEOPRESENTTARGETSET, -EIO,
1974 "STATUS_GRAPHICS_INVALID_VIDEOPRESENTTARGETSET"},
1975 {STATUS_GRAPHICS_SOURCE_ALREADY_IN_SET, -EIO,
1976 "STATUS_GRAPHICS_SOURCE_ALREADY_IN_SET"},
1977 {STATUS_GRAPHICS_TARGET_ALREADY_IN_SET, -EIO,
1978 "STATUS_GRAPHICS_TARGET_ALREADY_IN_SET"},
1979 {STATUS_GRAPHICS_INVALID_VIDPN_PRESENT_PATH, -EIO,
1980 "STATUS_GRAPHICS_INVALID_VIDPN_PRESENT_PATH"},
1981 {STATUS_GRAPHICS_NO_RECOMMENDED_VIDPN_TOPOLOGY, -EIO,
1982 "STATUS_GRAPHICS_NO_RECOMMENDED_VIDPN_TOPOLOGY"},
1983 {STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGESET, -EIO,
1984 "STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGESET"},
1985 {STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE, -EIO,
1986 "STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE"},
1987 {STATUS_GRAPHICS_FREQUENCYRANGE_NOT_IN_SET, -EIO,
1988 "STATUS_GRAPHICS_FREQUENCYRANGE_NOT_IN_SET"},
1989 {STATUS_GRAPHICS_FREQUENCYRANGE_ALREADY_IN_SET, -EIO,
1990 "STATUS_GRAPHICS_FREQUENCYRANGE_ALREADY_IN_SET"},
1991 {STATUS_GRAPHICS_STALE_MODESET, -EIO, "STATUS_GRAPHICS_STALE_MODESET"},
1992 {STATUS_GRAPHICS_INVALID_MONITOR_SOURCEMODESET, -EIO,
1993 "STATUS_GRAPHICS_INVALID_MONITOR_SOURCEMODESET"},
1994 {STATUS_GRAPHICS_INVALID_MONITOR_SOURCE_MODE, -EIO,
1995 "STATUS_GRAPHICS_INVALID_MONITOR_SOURCE_MODE"},
1996 {STATUS_GRAPHICS_NO_RECOMMENDED_FUNCTIONAL_VIDPN, -EIO,
1997 "STATUS_GRAPHICS_NO_RECOMMENDED_FUNCTIONAL_VIDPN"},
1998 {STATUS_GRAPHICS_MODE_ID_MUST_BE_UNIQUE, -EIO,
1999 "STATUS_GRAPHICS_MODE_ID_MUST_BE_UNIQUE"},
2000 {STATUS_GRAPHICS_EMPTY_ADAPTER_MONITOR_MODE_SUPPORT_INTERSECTION, -EIO,
2001 "STATUS_GRAPHICS_EMPTY_ADAPTER_MONITOR_MODE_SUPPORT_INTERSECTION"},
2002 {STATUS_GRAPHICS_VIDEO_PRESENT_TARGETS_LESS_THAN_SOURCES, -EIO,
2003 "STATUS_GRAPHICS_VIDEO_PRESENT_TARGETS_LESS_THAN_SOURCES"},
2004 {STATUS_GRAPHICS_PATH_NOT_IN_TOPOLOGY, -EIO,
2005 "STATUS_GRAPHICS_PATH_NOT_IN_TOPOLOGY"},
2006 {STATUS_GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_SOURCE, -EIO,
2007 "STATUS_GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_SOURCE"},
2008 {STATUS_GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_TARGET, -EIO,
2009 "STATUS_GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_TARGET"},
2010 {STATUS_GRAPHICS_INVALID_MONITORDESCRIPTORSET, -EIO,
2011 "STATUS_GRAPHICS_INVALID_MONITORDESCRIPTORSET"},
2012 {STATUS_GRAPHICS_INVALID_MONITORDESCRIPTOR, -EIO,
2013 "STATUS_GRAPHICS_INVALID_MONITORDESCRIPTOR"},
2014 {STATUS_GRAPHICS_MONITORDESCRIPTOR_NOT_IN_SET, -EIO,
2015 "STATUS_GRAPHICS_MONITORDESCRIPTOR_NOT_IN_SET"},
2016 {STATUS_GRAPHICS_MONITORDESCRIPTOR_ALREADY_IN_SET, -EIO,
2017 "STATUS_GRAPHICS_MONITORDESCRIPTOR_ALREADY_IN_SET"},
2018 {STATUS_GRAPHICS_MONITORDESCRIPTOR_ID_MUST_BE_UNIQUE, -EIO,
2019 "STATUS_GRAPHICS_MONITORDESCRIPTOR_ID_MUST_BE_UNIQUE"},
2020 {STATUS_GRAPHICS_INVALID_VIDPN_TARGET_SUBSET_TYPE, -EIO,
2021 "STATUS_GRAPHICS_INVALID_VIDPN_TARGET_SUBSET_TYPE"},
2022 {STATUS_GRAPHICS_RESOURCES_NOT_RELATED, -EIO,
2023 "STATUS_GRAPHICS_RESOURCES_NOT_RELATED"},
2024 {STATUS_GRAPHICS_SOURCE_ID_MUST_BE_UNIQUE, -EIO,
2025 "STATUS_GRAPHICS_SOURCE_ID_MUST_BE_UNIQUE"},
2026 {STATUS_GRAPHICS_TARGET_ID_MUST_BE_UNIQUE, -EIO,
2027 "STATUS_GRAPHICS_TARGET_ID_MUST_BE_UNIQUE"},
2028 {STATUS_GRAPHICS_NO_AVAILABLE_VIDPN_TARGET, -EIO,
2029 "STATUS_GRAPHICS_NO_AVAILABLE_VIDPN_TARGET"},
2030 {STATUS_GRAPHICS_MONITOR_COULD_NOT_BE_ASSOCIATED_WITH_ADAPTER, -EIO,
2031 "STATUS_GRAPHICS_MONITOR_COULD_NOT_BE_ASSOCIATED_WITH_ADAPTER"},
2032 {STATUS_GRAPHICS_NO_VIDPNMGR, -EIO, "STATUS_GRAPHICS_NO_VIDPNMGR"},
2033 {STATUS_GRAPHICS_NO_ACTIVE_VIDPN, -EIO,
2034 "STATUS_GRAPHICS_NO_ACTIVE_VIDPN"},
2035 {STATUS_GRAPHICS_STALE_VIDPN_TOPOLOGY, -EIO,
2036 "STATUS_GRAPHICS_STALE_VIDPN_TOPOLOGY"},
2037 {STATUS_GRAPHICS_MONITOR_NOT_CONNECTED, -EIO,
2038 "STATUS_GRAPHICS_MONITOR_NOT_CONNECTED"},
2039 {STATUS_GRAPHICS_SOURCE_NOT_IN_TOPOLOGY, -EIO,
2040 "STATUS_GRAPHICS_SOURCE_NOT_IN_TOPOLOGY"},
2041 {STATUS_GRAPHICS_INVALID_PRIMARYSURFACE_SIZE, -EIO,
2042 "STATUS_GRAPHICS_INVALID_PRIMARYSURFACE_SIZE"},
2043 {STATUS_GRAPHICS_INVALID_VISIBLEREGION_SIZE, -EIO,
2044 "STATUS_GRAPHICS_INVALID_VISIBLEREGION_SIZE"},
2045 {STATUS_GRAPHICS_INVALID_STRIDE, -EIO,
2046 "STATUS_GRAPHICS_INVALID_STRIDE"},
2047 {STATUS_GRAPHICS_INVALID_PIXELFORMAT, -EIO,
2048 "STATUS_GRAPHICS_INVALID_PIXELFORMAT"},
2049 {STATUS_GRAPHICS_INVALID_COLORBASIS, -EIO,
2050 "STATUS_GRAPHICS_INVALID_COLORBASIS"},
2051 {STATUS_GRAPHICS_INVALID_PIXELVALUEACCESSMODE, -EIO,
2052 "STATUS_GRAPHICS_INVALID_PIXELVALUEACCESSMODE"},
2053 {STATUS_GRAPHICS_TARGET_NOT_IN_TOPOLOGY, -EIO,
2054 "STATUS_GRAPHICS_TARGET_NOT_IN_TOPOLOGY"},
2055 {STATUS_GRAPHICS_NO_DISPLAY_MODE_MANAGEMENT_SUPPORT, -EIO,
2056 "STATUS_GRAPHICS_NO_DISPLAY_MODE_MANAGEMENT_SUPPORT"},
2057 {STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE, -EIO,
2058 "STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE"},
2059 {STATUS_GRAPHICS_CANT_ACCESS_ACTIVE_VIDPN, -EIO,
2060 "STATUS_GRAPHICS_CANT_ACCESS_ACTIVE_VIDPN"},
2061 {STATUS_GRAPHICS_INVALID_PATH_IMPORTANCE_ORDINAL, -EIO,
2062 "STATUS_GRAPHICS_INVALID_PATH_IMPORTANCE_ORDINAL"},
2063 {STATUS_GRAPHICS_INVALID_PATH_CONTENT_GEOMETRY_TRANSFORMATION, -EIO,
2064 "STATUS_GRAPHICS_INVALID_PATH_CONTENT_GEOMETRY_TRANSFORMATION"},
2065 {STATUS_GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_SUPPORTED,
2066 -EIO,
2067 "STATUS_GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_SUPPORTED"},
2068 {STATUS_GRAPHICS_INVALID_GAMMA_RAMP, -EIO,
2069 "STATUS_GRAPHICS_INVALID_GAMMA_RAMP"},
2070 {STATUS_GRAPHICS_GAMMA_RAMP_NOT_SUPPORTED, -EIO,
2071 "STATUS_GRAPHICS_GAMMA_RAMP_NOT_SUPPORTED"},
2072 {STATUS_GRAPHICS_MULTISAMPLING_NOT_SUPPORTED, -EIO,
2073 "STATUS_GRAPHICS_MULTISAMPLING_NOT_SUPPORTED"},
2074 {STATUS_GRAPHICS_MODE_NOT_IN_MODESET, -EIO,
2075 "STATUS_GRAPHICS_MODE_NOT_IN_MODESET"},
2076 {STATUS_GRAPHICS_INVALID_VIDPN_TOPOLOGY_RECOMMENDATION_REASON, -EIO,
2077 "STATUS_GRAPHICS_INVALID_VIDPN_TOPOLOGY_RECOMMENDATION_REASON"},
2078 {STATUS_GRAPHICS_INVALID_PATH_CONTENT_TYPE, -EIO,
2079 "STATUS_GRAPHICS_INVALID_PATH_CONTENT_TYPE"},
2080 {STATUS_GRAPHICS_INVALID_COPYPROTECTION_TYPE, -EIO,
2081 "STATUS_GRAPHICS_INVALID_COPYPROTECTION_TYPE"},
2082 {STATUS_GRAPHICS_UNASSIGNED_MODESET_ALREADY_EXISTS, -EIO,
2083 "STATUS_GRAPHICS_UNASSIGNED_MODESET_ALREADY_EXISTS"},
2084 {STATUS_GRAPHICS_INVALID_SCANLINE_ORDERING, -EIO,
2085 "STATUS_GRAPHICS_INVALID_SCANLINE_ORDERING"},
2086 {STATUS_GRAPHICS_TOPOLOGY_CHANGES_NOT_ALLOWED, -EIO,
2087 "STATUS_GRAPHICS_TOPOLOGY_CHANGES_NOT_ALLOWED"},
2088 {STATUS_GRAPHICS_NO_AVAILABLE_IMPORTANCE_ORDINALS, -EIO,
2089 "STATUS_GRAPHICS_NO_AVAILABLE_IMPORTANCE_ORDINALS"},
2090 {STATUS_GRAPHICS_INCOMPATIBLE_PRIVATE_FORMAT, -EIO,
2091 "STATUS_GRAPHICS_INCOMPATIBLE_PRIVATE_FORMAT"},
2092 {STATUS_GRAPHICS_INVALID_MODE_PRUNING_ALGORITHM, -EIO,
2093 "STATUS_GRAPHICS_INVALID_MODE_PRUNING_ALGORITHM"},
2094 {STATUS_GRAPHICS_INVALID_MONITOR_CAPABILITY_ORIGIN, -EIO,
2095 "STATUS_GRAPHICS_INVALID_MONITOR_CAPABILITY_ORIGIN"},
2096 {STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE_CONSTRAINT, -EIO,
2097 "STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE_CONSTRAINT"},
2098 {STATUS_GRAPHICS_MAX_NUM_PATHS_REACHED, -EIO,
2099 "STATUS_GRAPHICS_MAX_NUM_PATHS_REACHED"},
2100 {STATUS_GRAPHICS_CANCEL_VIDPN_TOPOLOGY_AUGMENTATION, -EIO,
2101 "STATUS_GRAPHICS_CANCEL_VIDPN_TOPOLOGY_AUGMENTATION"},
2102 {STATUS_GRAPHICS_INVALID_CLIENT_TYPE, -EIO,
2103 "STATUS_GRAPHICS_INVALID_CLIENT_TYPE"},
2104 {STATUS_GRAPHICS_CLIENTVIDPN_NOT_SET, -EIO,
2105 "STATUS_GRAPHICS_CLIENTVIDPN_NOT_SET"},
2106 {STATUS_GRAPHICS_SPECIFIED_CHILD_ALREADY_CONNECTED, -EIO,
2107 "STATUS_GRAPHICS_SPECIFIED_CHILD_ALREADY_CONNECTED"},
2108 {STATUS_GRAPHICS_CHILD_DESCRIPTOR_NOT_SUPPORTED, -EIO,
2109 "STATUS_GRAPHICS_CHILD_DESCRIPTOR_NOT_SUPPORTED"},
2110 {STATUS_GRAPHICS_NOT_A_LINKED_ADAPTER, -EIO,
2111 "STATUS_GRAPHICS_NOT_A_LINKED_ADAPTER"},
2112 {STATUS_GRAPHICS_LEADLINK_NOT_ENUMERATED, -EIO,
2113 "STATUS_GRAPHICS_LEADLINK_NOT_ENUMERATED"},
2114 {STATUS_GRAPHICS_CHAINLINKS_NOT_ENUMERATED, -EIO,
2115 "STATUS_GRAPHICS_CHAINLINKS_NOT_ENUMERATED"},
2116 {STATUS_GRAPHICS_ADAPTER_CHAIN_NOT_READY, -EIO,
2117 "STATUS_GRAPHICS_ADAPTER_CHAIN_NOT_READY"},
2118 {STATUS_GRAPHICS_CHAINLINKS_NOT_STARTED, -EIO,
2119 "STATUS_GRAPHICS_CHAINLINKS_NOT_STARTED"},
2120 {STATUS_GRAPHICS_CHAINLINKS_NOT_POWERED_ON, -EIO,
2121 "STATUS_GRAPHICS_CHAINLINKS_NOT_POWERED_ON"},
2122 {STATUS_GRAPHICS_INCONSISTENT_DEVICE_LINK_STATE, -EIO,
2123 "STATUS_GRAPHICS_INCONSISTENT_DEVICE_LINK_STATE"},
2124 {STATUS_GRAPHICS_NOT_POST_DEVICE_DRIVER, -EIO,
2125 "STATUS_GRAPHICS_NOT_POST_DEVICE_DRIVER"},
2126 {STATUS_GRAPHICS_ADAPTER_ACCESS_NOT_EXCLUDED, -EIO,
2127 "STATUS_GRAPHICS_ADAPTER_ACCESS_NOT_EXCLUDED"},
2128 {STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_COPP_SEMANTICS,
2129 -EIO,
2130 "STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_COPP_SEMANTICS"},
2131 {STATUS_GRAPHICS_OPM_INVALID_INFORMATION_REQUEST, -EIO,
2132 "STATUS_GRAPHICS_OPM_INVALID_INFORMATION_REQUEST"},
2133 {STATUS_GRAPHICS_OPM_DRIVER_INTERNAL_ERROR, -EIO,
2134 "STATUS_GRAPHICS_OPM_DRIVER_INTERNAL_ERROR"},
2135 {STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_OPM_SEMANTICS, -EIO,
2136 "STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_OPM_SEMANTICS"},
2137 {STATUS_GRAPHICS_OPM_SIGNALING_NOT_SUPPORTED, -EIO,
2138 "STATUS_GRAPHICS_OPM_SIGNALING_NOT_SUPPORTED"},
2139 {STATUS_GRAPHICS_OPM_INVALID_CONFIGURATION_REQUEST, -EIO,
2140 "STATUS_GRAPHICS_OPM_INVALID_CONFIGURATION_REQUEST"},
2141 {STATUS_GRAPHICS_OPM_NOT_SUPPORTED, -EIO,
2142 "STATUS_GRAPHICS_OPM_NOT_SUPPORTED"},
2143 {STATUS_GRAPHICS_COPP_NOT_SUPPORTED, -EIO,
2144 "STATUS_GRAPHICS_COPP_NOT_SUPPORTED"},
2145 {STATUS_GRAPHICS_UAB_NOT_SUPPORTED, -EIO,
2146 "STATUS_GRAPHICS_UAB_NOT_SUPPORTED"},
2147 {STATUS_GRAPHICS_OPM_INVALID_ENCRYPTED_PARAMETERS, -EIO,
2148 "STATUS_GRAPHICS_OPM_INVALID_ENCRYPTED_PARAMETERS"},
2149 {STATUS_GRAPHICS_OPM_PARAMETER_ARRAY_TOO_SMALL, -EIO,
2150 "STATUS_GRAPHICS_OPM_PARAMETER_ARRAY_TOO_SMALL"},
2151 {STATUS_GRAPHICS_OPM_NO_PROTECTED_OUTPUTS_EXIST, -EIO,
2152 "STATUS_GRAPHICS_OPM_NO_PROTECTED_OUTPUTS_EXIST"},
2153 {STATUS_GRAPHICS_PVP_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME, -EIO,
2154 "STATUS_GRAPHICS_PVP_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME"},
2155 {STATUS_GRAPHICS_PVP_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP, -EIO,
2156 "STATUS_GRAPHICS_PVP_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP"},
2157 {STATUS_GRAPHICS_PVP_MIRRORING_DEVICES_NOT_SUPPORTED, -EIO,
2158 "STATUS_GRAPHICS_PVP_MIRRORING_DEVICES_NOT_SUPPORTED"},
2159 {STATUS_GRAPHICS_OPM_INVALID_POINTER, -EIO,
2160 "STATUS_GRAPHICS_OPM_INVALID_POINTER"},
2161 {STATUS_GRAPHICS_OPM_INTERNAL_ERROR, -EIO,
2162 "STATUS_GRAPHICS_OPM_INTERNAL_ERROR"},
2163 {STATUS_GRAPHICS_OPM_INVALID_HANDLE, -EIO,
2164 "STATUS_GRAPHICS_OPM_INVALID_HANDLE"},
2165 {STATUS_GRAPHICS_PVP_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE, -EIO,
2166 "STATUS_GRAPHICS_PVP_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE"},
2167 {STATUS_GRAPHICS_PVP_INVALID_CERTIFICATE_LENGTH, -EIO,
2168 "STATUS_GRAPHICS_PVP_INVALID_CERTIFICATE_LENGTH"},
2169 {STATUS_GRAPHICS_OPM_SPANNING_MODE_ENABLED, -EIO,
2170 "STATUS_GRAPHICS_OPM_SPANNING_MODE_ENABLED"},
2171 {STATUS_GRAPHICS_OPM_THEATER_MODE_ENABLED, -EIO,
2172 "STATUS_GRAPHICS_OPM_THEATER_MODE_ENABLED"},
2173 {STATUS_GRAPHICS_PVP_HFS_FAILED, -EIO,
2174 "STATUS_GRAPHICS_PVP_HFS_FAILED"},
2175 {STATUS_GRAPHICS_OPM_INVALID_SRM, -EIO,
2176 "STATUS_GRAPHICS_OPM_INVALID_SRM"},
2177 {STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_HDCP, -EIO,
2178 "STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_HDCP"},
2179 {STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_ACP, -EIO,
2180 "STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_ACP"},
2181 {STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_CGMSA, -EIO,
2182 "STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_CGMSA"},
2183 {STATUS_GRAPHICS_OPM_HDCP_SRM_NEVER_SET, -EIO,
2184 "STATUS_GRAPHICS_OPM_HDCP_SRM_NEVER_SET"},
2185 {STATUS_GRAPHICS_OPM_RESOLUTION_TOO_HIGH, -EIO,
2186 "STATUS_GRAPHICS_OPM_RESOLUTION_TOO_HIGH"},
2187 {STATUS_GRAPHICS_OPM_ALL_HDCP_HARDWARE_ALREADY_IN_USE, -EIO,
2188 "STATUS_GRAPHICS_OPM_ALL_HDCP_HARDWARE_ALREADY_IN_USE"},
2189 {STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_NO_LONGER_EXISTS, -EIO,
2190 "STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_NO_LONGER_EXISTS"},
2191 {STATUS_GRAPHICS_OPM_SESSION_TYPE_CHANGE_IN_PROGRESS, -EIO,
2192 "STATUS_GRAPHICS_OPM_SESSION_TYPE_CHANGE_IN_PROGRESS"},
2193 {STATUS_GRAPHICS_I2C_NOT_SUPPORTED, -EIO,
2194 "STATUS_GRAPHICS_I2C_NOT_SUPPORTED"},
2195 {STATUS_GRAPHICS_I2C_DEVICE_DOES_NOT_EXIST, -EIO,
2196 "STATUS_GRAPHICS_I2C_DEVICE_DOES_NOT_EXIST"},
2197 {STATUS_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA, -EIO,
2198 "STATUS_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA"},
2199 {STATUS_GRAPHICS_I2C_ERROR_RECEIVING_DATA, -EIO,
2200 "STATUS_GRAPHICS_I2C_ERROR_RECEIVING_DATA"},
2201 {STATUS_GRAPHICS_DDCCI_VCP_NOT_SUPPORTED, -EIO,
2202 "STATUS_GRAPHICS_DDCCI_VCP_NOT_SUPPORTED"},
2203 {STATUS_GRAPHICS_DDCCI_INVALID_DATA, -EIO,
2204 "STATUS_GRAPHICS_DDCCI_INVALID_DATA"},
2205 {STATUS_GRAPHICS_DDCCI_MONITOR_RETURNED_INVALID_TIMING_STATUS_BYTE,
2206 -EIO,
2207 "STATUS_GRAPHICS_DDCCI_MONITOR_RETURNED_INVALID_TIMING_STATUS_BYTE"},
2208 {STATUS_GRAPHICS_DDCCI_INVALID_CAPABILITIES_STRING, -EIO,
2209 "STATUS_GRAPHICS_DDCCI_INVALID_CAPABILITIES_STRING"},
2210 {STATUS_GRAPHICS_MCA_INTERNAL_ERROR, -EIO,
2211 "STATUS_GRAPHICS_MCA_INTERNAL_ERROR"},
2212 {STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_COMMAND, -EIO,
2213 "STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_COMMAND"},
2214 {STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_LENGTH, -EIO,
2215 "STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_LENGTH"},
2216 {STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_CHECKSUM, -EIO,
2217 "STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_CHECKSUM"},
2218 {STATUS_GRAPHICS_INVALID_PHYSICAL_MONITOR_HANDLE, -EIO,
2219 "STATUS_GRAPHICS_INVALID_PHYSICAL_MONITOR_HANDLE"},
2220 {STATUS_GRAPHICS_MONITOR_NO_LONGER_EXISTS, -EIO,
2221 "STATUS_GRAPHICS_MONITOR_NO_LONGER_EXISTS"},
2222 {STATUS_GRAPHICS_ONLY_CONSOLE_SESSION_SUPPORTED, -EIO,
2223 "STATUS_GRAPHICS_ONLY_CONSOLE_SESSION_SUPPORTED"},
2224 {STATUS_GRAPHICS_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME, -EIO,
2225 "STATUS_GRAPHICS_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME"},
2226 {STATUS_GRAPHICS_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP, -EIO,
2227 "STATUS_GRAPHICS_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP"},
2228 {STATUS_GRAPHICS_MIRRORING_DEVICES_NOT_SUPPORTED, -EIO,
2229 "STATUS_GRAPHICS_MIRRORING_DEVICES_NOT_SUPPORTED"},
2230 {STATUS_GRAPHICS_INVALID_POINTER, -EIO,
2231 "STATUS_GRAPHICS_INVALID_POINTER"},
2232 {STATUS_GRAPHICS_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE, -EIO,
2233 "STATUS_GRAPHICS_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE"},
2234 {STATUS_GRAPHICS_PARAMETER_ARRAY_TOO_SMALL, -EIO,
2235 "STATUS_GRAPHICS_PARAMETER_ARRAY_TOO_SMALL"},
2236 {STATUS_GRAPHICS_INTERNAL_ERROR, -EIO,
2237 "STATUS_GRAPHICS_INTERNAL_ERROR"},
2238 {STATUS_GRAPHICS_SESSION_TYPE_CHANGE_IN_PROGRESS, -EIO,
2239 "STATUS_GRAPHICS_SESSION_TYPE_CHANGE_IN_PROGRESS"},
2240 {STATUS_FVE_LOCKED_VOLUME, -EIO, "STATUS_FVE_LOCKED_VOLUME"},
2241 {STATUS_FVE_NOT_ENCRYPTED, -EIO, "STATUS_FVE_NOT_ENCRYPTED"},
2242 {STATUS_FVE_BAD_INFORMATION, -EIO, "STATUS_FVE_BAD_INFORMATION"},
2243 {STATUS_FVE_TOO_SMALL, -EIO, "STATUS_FVE_TOO_SMALL"},
2244 {STATUS_FVE_FAILED_WRONG_FS, -EIO, "STATUS_FVE_FAILED_WRONG_FS"},
2245 {STATUS_FVE_FAILED_BAD_FS, -EIO, "STATUS_FVE_FAILED_BAD_FS"},
2246 {STATUS_FVE_FS_NOT_EXTENDED, -EIO, "STATUS_FVE_FS_NOT_EXTENDED"},
2247 {STATUS_FVE_FS_MOUNTED, -EIO, "STATUS_FVE_FS_MOUNTED"},
2248 {STATUS_FVE_NO_LICENSE, -EIO, "STATUS_FVE_NO_LICENSE"},
2249 {STATUS_FVE_ACTION_NOT_ALLOWED, -EIO, "STATUS_FVE_ACTION_NOT_ALLOWED"},
2250 {STATUS_FVE_BAD_DATA, -EIO, "STATUS_FVE_BAD_DATA"},
2251 {STATUS_FVE_VOLUME_NOT_BOUND, -EIO, "STATUS_FVE_VOLUME_NOT_BOUND"},
2252 {STATUS_FVE_NOT_DATA_VOLUME, -EIO, "STATUS_FVE_NOT_DATA_VOLUME"},
2253 {STATUS_FVE_CONV_READ_ERROR, -EIO, "STATUS_FVE_CONV_READ_ERROR"},
2254 {STATUS_FVE_CONV_WRITE_ERROR, -EIO, "STATUS_FVE_CONV_WRITE_ERROR"},
2255 {STATUS_FVE_OVERLAPPED_UPDATE, -EIO, "STATUS_FVE_OVERLAPPED_UPDATE"},
2256 {STATUS_FVE_FAILED_SECTOR_SIZE, -EIO, "STATUS_FVE_FAILED_SECTOR_SIZE"},
2257 {STATUS_FVE_FAILED_AUTHENTICATION, -EIO,
2258 "STATUS_FVE_FAILED_AUTHENTICATION"},
2259 {STATUS_FVE_NOT_OS_VOLUME, -EIO, "STATUS_FVE_NOT_OS_VOLUME"},
2260 {STATUS_FVE_KEYFILE_NOT_FOUND, -EIO, "STATUS_FVE_KEYFILE_NOT_FOUND"},
2261 {STATUS_FVE_KEYFILE_INVALID, -EIO, "STATUS_FVE_KEYFILE_INVALID"},
2262 {STATUS_FVE_KEYFILE_NO_VMK, -EIO, "STATUS_FVE_KEYFILE_NO_VMK"},
2263 {STATUS_FVE_TPM_DISABLED, -EIO, "STATUS_FVE_TPM_DISABLED"},
2264 {STATUS_FVE_TPM_SRK_AUTH_NOT_ZERO, -EIO,
2265 "STATUS_FVE_TPM_SRK_AUTH_NOT_ZERO"},
2266 {STATUS_FVE_TPM_INVALID_PCR, -EIO, "STATUS_FVE_TPM_INVALID_PCR"},
2267 {STATUS_FVE_TPM_NO_VMK, -EIO, "STATUS_FVE_TPM_NO_VMK"},
2268 {STATUS_FVE_PIN_INVALID, -EIO, "STATUS_FVE_PIN_INVALID"},
2269 {STATUS_FVE_AUTH_INVALID_APPLICATION, -EIO,
2270 "STATUS_FVE_AUTH_INVALID_APPLICATION"},
2271 {STATUS_FVE_AUTH_INVALID_CONFIG, -EIO,
2272 "STATUS_FVE_AUTH_INVALID_CONFIG"},
2273 {STATUS_FVE_DEBUGGER_ENABLED, -EIO, "STATUS_FVE_DEBUGGER_ENABLED"},
2274 {STATUS_FVE_DRY_RUN_FAILED, -EIO, "STATUS_FVE_DRY_RUN_FAILED"},
2275 {STATUS_FVE_BAD_METADATA_POINTER, -EIO,
2276 "STATUS_FVE_BAD_METADATA_POINTER"},
2277 {STATUS_FVE_OLD_METADATA_COPY, -EIO, "STATUS_FVE_OLD_METADATA_COPY"},
2278 {STATUS_FVE_REBOOT_REQUIRED, -EIO, "STATUS_FVE_REBOOT_REQUIRED"},
2279 {STATUS_FVE_RAW_ACCESS, -EIO, "STATUS_FVE_RAW_ACCESS"},
2280 {STATUS_FVE_RAW_BLOCKED, -EIO, "STATUS_FVE_RAW_BLOCKED"},
2281 {STATUS_FWP_CALLOUT_NOT_FOUND, -EIO, "STATUS_FWP_CALLOUT_NOT_FOUND"},
2282 {STATUS_FWP_CONDITION_NOT_FOUND, -EIO,
2283 "STATUS_FWP_CONDITION_NOT_FOUND"},
2284 {STATUS_FWP_FILTER_NOT_FOUND, -EIO, "STATUS_FWP_FILTER_NOT_FOUND"},
2285 {STATUS_FWP_LAYER_NOT_FOUND, -EIO, "STATUS_FWP_LAYER_NOT_FOUND"},
2286 {STATUS_FWP_PROVIDER_NOT_FOUND, -EIO, "STATUS_FWP_PROVIDER_NOT_FOUND"},
2287 {STATUS_FWP_PROVIDER_CONTEXT_NOT_FOUND, -EIO,
2288 "STATUS_FWP_PROVIDER_CONTEXT_NOT_FOUND"},
2289 {STATUS_FWP_SUBLAYER_NOT_FOUND, -EIO, "STATUS_FWP_SUBLAYER_NOT_FOUND"},
2290 {STATUS_FWP_NOT_FOUND, -EIO, "STATUS_FWP_NOT_FOUND"},
2291 {STATUS_FWP_ALREADY_EXISTS, -EIO, "STATUS_FWP_ALREADY_EXISTS"},
2292 {STATUS_FWP_IN_USE, -EIO, "STATUS_FWP_IN_USE"},
2293 {STATUS_FWP_DYNAMIC_SESSION_IN_PROGRESS, -EIO,
2294 "STATUS_FWP_DYNAMIC_SESSION_IN_PROGRESS"},
2295 {STATUS_FWP_WRONG_SESSION, -EIO, "STATUS_FWP_WRONG_SESSION"},
2296 {STATUS_FWP_NO_TXN_IN_PROGRESS, -EIO, "STATUS_FWP_NO_TXN_IN_PROGRESS"},
2297 {STATUS_FWP_TXN_IN_PROGRESS, -EIO, "STATUS_FWP_TXN_IN_PROGRESS"},
2298 {STATUS_FWP_TXN_ABORTED, -EIO, "STATUS_FWP_TXN_ABORTED"},
2299 {STATUS_FWP_SESSION_ABORTED, -EIO, "STATUS_FWP_SESSION_ABORTED"},
2300 {STATUS_FWP_INCOMPATIBLE_TXN, -EIO, "STATUS_FWP_INCOMPATIBLE_TXN"},
2301 {STATUS_FWP_TIMEOUT, -ETIMEDOUT, "STATUS_FWP_TIMEOUT"},
2302 {STATUS_FWP_NET_EVENTS_DISABLED, -EIO,
2303 "STATUS_FWP_NET_EVENTS_DISABLED"},
2304 {STATUS_FWP_INCOMPATIBLE_LAYER, -EIO, "STATUS_FWP_INCOMPATIBLE_LAYER"},
2305 {STATUS_FWP_KM_CLIENTS_ONLY, -EIO, "STATUS_FWP_KM_CLIENTS_ONLY"},
2306 {STATUS_FWP_LIFETIME_MISMATCH, -EIO, "STATUS_FWP_LIFETIME_MISMATCH"},
2307 {STATUS_FWP_BUILTIN_OBJECT, -EIO, "STATUS_FWP_BUILTIN_OBJECT"},
2308 {STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS, -EIO,
2309 "STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS"},
2310 {STATUS_FWP_TOO_MANY_CALLOUTS, -EIO, "STATUS_FWP_TOO_MANY_CALLOUTS"},
2311 {STATUS_FWP_NOTIFICATION_DROPPED, -EIO,
2312 "STATUS_FWP_NOTIFICATION_DROPPED"},
2313 {STATUS_FWP_TRAFFIC_MISMATCH, -EIO, "STATUS_FWP_TRAFFIC_MISMATCH"},
2314 {STATUS_FWP_INCOMPATIBLE_SA_STATE, -EIO,
2315 "STATUS_FWP_INCOMPATIBLE_SA_STATE"},
2316 {STATUS_FWP_NULL_POINTER, -EIO, "STATUS_FWP_NULL_POINTER"},
2317 {STATUS_FWP_INVALID_ENUMERATOR, -EIO, "STATUS_FWP_INVALID_ENUMERATOR"},
2318 {STATUS_FWP_INVALID_FLAGS, -EIO, "STATUS_FWP_INVALID_FLAGS"},
2319 {STATUS_FWP_INVALID_NET_MASK, -EIO, "STATUS_FWP_INVALID_NET_MASK"},
2320 {STATUS_FWP_INVALID_RANGE, -EIO, "STATUS_FWP_INVALID_RANGE"},
2321 {STATUS_FWP_INVALID_INTERVAL, -EIO, "STATUS_FWP_INVALID_INTERVAL"},
2322 {STATUS_FWP_ZERO_LENGTH_ARRAY, -EIO, "STATUS_FWP_ZERO_LENGTH_ARRAY"},
2323 {STATUS_FWP_NULL_DISPLAY_NAME, -EIO, "STATUS_FWP_NULL_DISPLAY_NAME"},
2324 {STATUS_FWP_INVALID_ACTION_TYPE, -EIO,
2325 "STATUS_FWP_INVALID_ACTION_TYPE"},
2326 {STATUS_FWP_INVALID_WEIGHT, -EIO, "STATUS_FWP_INVALID_WEIGHT"},
2327 {STATUS_FWP_MATCH_TYPE_MISMATCH, -EIO,
2328 "STATUS_FWP_MATCH_TYPE_MISMATCH"},
2329 {STATUS_FWP_TYPE_MISMATCH, -EIO, "STATUS_FWP_TYPE_MISMATCH"},
2330 {STATUS_FWP_OUT_OF_BOUNDS, -EIO, "STATUS_FWP_OUT_OF_BOUNDS"},
2331 {STATUS_FWP_RESERVED, -EIO, "STATUS_FWP_RESERVED"},
2332 {STATUS_FWP_DUPLICATE_CONDITION, -EIO,
2333 "STATUS_FWP_DUPLICATE_CONDITION"},
2334 {STATUS_FWP_DUPLICATE_KEYMOD, -EIO, "STATUS_FWP_DUPLICATE_KEYMOD"},
2335 {STATUS_FWP_ACTION_INCOMPATIBLE_WITH_LAYER, -EIO,
2336 "STATUS_FWP_ACTION_INCOMPATIBLE_WITH_LAYER"},
2337 {STATUS_FWP_ACTION_INCOMPATIBLE_WITH_SUBLAYER, -EIO,
2338 "STATUS_FWP_ACTION_INCOMPATIBLE_WITH_SUBLAYER"},
2339 {STATUS_FWP_CONTEXT_INCOMPATIBLE_WITH_LAYER, -EIO,
2340 "STATUS_FWP_CONTEXT_INCOMPATIBLE_WITH_LAYER"},
2341 {STATUS_FWP_CONTEXT_INCOMPATIBLE_WITH_CALLOUT, -EIO,
2342 "STATUS_FWP_CONTEXT_INCOMPATIBLE_WITH_CALLOUT"},
2343 {STATUS_FWP_INCOMPATIBLE_AUTH_METHOD, -EIO,
2344 "STATUS_FWP_INCOMPATIBLE_AUTH_METHOD"},
2345 {STATUS_FWP_INCOMPATIBLE_DH_GROUP, -EIO,
2346 "STATUS_FWP_INCOMPATIBLE_DH_GROUP"},
2347 {STATUS_FWP_EM_NOT_SUPPORTED, -EOPNOTSUPP,
2348 "STATUS_FWP_EM_NOT_SUPPORTED"},
2349 {STATUS_FWP_NEVER_MATCH, -EIO, "STATUS_FWP_NEVER_MATCH"},
2350 {STATUS_FWP_PROVIDER_CONTEXT_MISMATCH, -EIO,
2351 "STATUS_FWP_PROVIDER_CONTEXT_MISMATCH"},
2352 {STATUS_FWP_INVALID_PARAMETER, -EIO, "STATUS_FWP_INVALID_PARAMETER"},
2353 {STATUS_FWP_TOO_MANY_SUBLAYERS, -EIO, "STATUS_FWP_TOO_MANY_SUBLAYERS"},
2354 {STATUS_FWP_CALLOUT_NOTIFICATION_FAILED, -EIO,
2355 "STATUS_FWP_CALLOUT_NOTIFICATION_FAILED"},
2356 {STATUS_FWP_INCOMPATIBLE_AUTH_CONFIG, -EIO,
2357 "STATUS_FWP_INCOMPATIBLE_AUTH_CONFIG"},
2358 {STATUS_FWP_INCOMPATIBLE_CIPHER_CONFIG, -EIO,
2359 "STATUS_FWP_INCOMPATIBLE_CIPHER_CONFIG"},
2360 {STATUS_FWP_TCPIP_NOT_READY, -EIO, "STATUS_FWP_TCPIP_NOT_READY"},
2361 {STATUS_FWP_INJECT_HANDLE_CLOSING, -EIO,
2362 "STATUS_FWP_INJECT_HANDLE_CLOSING"},
2363 {STATUS_FWP_INJECT_HANDLE_STALE, -EIO,
2364 "STATUS_FWP_INJECT_HANDLE_STALE"},
2365 {STATUS_FWP_CANNOT_PEND, -EIO, "STATUS_FWP_CANNOT_PEND"},
2366 {STATUS_NDIS_CLOSING, -EIO, "STATUS_NDIS_CLOSING"},
2367 {STATUS_NDIS_BAD_VERSION, -EIO, "STATUS_NDIS_BAD_VERSION"},
2368 {STATUS_NDIS_BAD_CHARACTERISTICS, -EIO,
2369 "STATUS_NDIS_BAD_CHARACTERISTICS"},
2370 {STATUS_NDIS_ADAPTER_NOT_FOUND, -EIO, "STATUS_NDIS_ADAPTER_NOT_FOUND"},
2371 {STATUS_NDIS_OPEN_FAILED, -EIO, "STATUS_NDIS_OPEN_FAILED"},
2372 {STATUS_NDIS_DEVICE_FAILED, -EIO, "STATUS_NDIS_DEVICE_FAILED"},
2373 {STATUS_NDIS_MULTICAST_FULL, -EIO, "STATUS_NDIS_MULTICAST_FULL"},
2374 {STATUS_NDIS_MULTICAST_EXISTS, -EIO, "STATUS_NDIS_MULTICAST_EXISTS"},
2375 {STATUS_NDIS_MULTICAST_NOT_FOUND, -EIO,
2376 "STATUS_NDIS_MULTICAST_NOT_FOUND"},
2377 {STATUS_NDIS_REQUEST_ABORTED, -EIO, "STATUS_NDIS_REQUEST_ABORTED"},
2378 {STATUS_NDIS_RESET_IN_PROGRESS, -EIO, "STATUS_NDIS_RESET_IN_PROGRESS"},
2379 {STATUS_NDIS_INVALID_PACKET, -EIO, "STATUS_NDIS_INVALID_PACKET"},
2380 {STATUS_NDIS_INVALID_DEVICE_REQUEST, -EIO,
2381 "STATUS_NDIS_INVALID_DEVICE_REQUEST"},
2382 {STATUS_NDIS_ADAPTER_NOT_READY, -EIO, "STATUS_NDIS_ADAPTER_NOT_READY"},
2383 {STATUS_NDIS_INVALID_LENGTH, -EIO, "STATUS_NDIS_INVALID_LENGTH"},
2384 {STATUS_NDIS_INVALID_DATA, -EIO, "STATUS_NDIS_INVALID_DATA"},
2385 {STATUS_NDIS_BUFFER_TOO_SHORT, -ENOBUFS,
2386 "STATUS_NDIS_BUFFER_TOO_SHORT"},
2387 {STATUS_NDIS_INVALID_OID, -EIO, "STATUS_NDIS_INVALID_OID"},
2388 {STATUS_NDIS_ADAPTER_REMOVED, -EIO, "STATUS_NDIS_ADAPTER_REMOVED"},
2389 {STATUS_NDIS_UNSUPPORTED_MEDIA, -EIO, "STATUS_NDIS_UNSUPPORTED_MEDIA"},
2390 {STATUS_NDIS_GROUP_ADDRESS_IN_USE, -EIO,
2391 "STATUS_NDIS_GROUP_ADDRESS_IN_USE"},
2392 {STATUS_NDIS_FILE_NOT_FOUND, -EIO, "STATUS_NDIS_FILE_NOT_FOUND"},
2393 {STATUS_NDIS_ERROR_READING_FILE, -EIO,
2394 "STATUS_NDIS_ERROR_READING_FILE"},
2395 {STATUS_NDIS_ALREADY_MAPPED, -EIO, "STATUS_NDIS_ALREADY_MAPPED"},
2396 {STATUS_NDIS_RESOURCE_CONFLICT, -EIO, "STATUS_NDIS_RESOURCE_CONFLICT"},
2397 {STATUS_NDIS_MEDIA_DISCONNECTED, -EIO,
2398 "STATUS_NDIS_MEDIA_DISCONNECTED"},
2399 {STATUS_NDIS_INVALID_ADDRESS, -EIO, "STATUS_NDIS_INVALID_ADDRESS"},
2400 {STATUS_NDIS_PAUSED, -EIO, "STATUS_NDIS_PAUSED"},
2401 {STATUS_NDIS_INTERFACE_NOT_FOUND, -EIO,
2402 "STATUS_NDIS_INTERFACE_NOT_FOUND"},
2403 {STATUS_NDIS_UNSUPPORTED_REVISION, -EIO,
2404 "STATUS_NDIS_UNSUPPORTED_REVISION"},
2405 {STATUS_NDIS_INVALID_PORT, -EIO, "STATUS_NDIS_INVALID_PORT"},
2406 {STATUS_NDIS_INVALID_PORT_STATE, -EIO,
2407 "STATUS_NDIS_INVALID_PORT_STATE"},
2408 {STATUS_NDIS_LOW_POWER_STATE, -EIO, "STATUS_NDIS_LOW_POWER_STATE"},
2409 {STATUS_NDIS_NOT_SUPPORTED, -ENOSYS, "STATUS_NDIS_NOT_SUPPORTED"},
2410 {STATUS_NDIS_DOT11_AUTO_CONFIG_ENABLED, -EIO,
2411 "STATUS_NDIS_DOT11_AUTO_CONFIG_ENABLED"},
2412 {STATUS_NDIS_DOT11_MEDIA_IN_USE, -EIO,
2413 "STATUS_NDIS_DOT11_MEDIA_IN_USE"},
2414 {STATUS_NDIS_DOT11_POWER_STATE_INVALID, -EIO,
2415 "STATUS_NDIS_DOT11_POWER_STATE_INVALID"},
2416 {STATUS_IPSEC_BAD_SPI, -EIO, "STATUS_IPSEC_BAD_SPI"},
2417 {STATUS_IPSEC_SA_LIFETIME_EXPIRED, -EIO,
2418 "STATUS_IPSEC_SA_LIFETIME_EXPIRED"},
2419 {STATUS_IPSEC_WRONG_SA, -EIO, "STATUS_IPSEC_WRONG_SA"},
2420 {STATUS_IPSEC_REPLAY_CHECK_FAILED, -EIO,
2421 "STATUS_IPSEC_REPLAY_CHECK_FAILED"},
2422 {STATUS_IPSEC_INVALID_PACKET, -EIO, "STATUS_IPSEC_INVALID_PACKET"},
2423 {STATUS_IPSEC_INTEGRITY_CHECK_FAILED, -EIO,
2424 "STATUS_IPSEC_INTEGRITY_CHECK_FAILED"},
2425 {STATUS_IPSEC_CLEAR_TEXT_DROP, -EIO, "STATUS_IPSEC_CLEAR_TEXT_DROP"},
2426 {0, 0, NULL}
2427};
2428
2429/*****************************************************************************
2430 Print an error message from the status code
2431 *****************************************************************************/
2432static void
2433smb2_print_status(__le32 status)
2434{
2435 int idx = 0;
2436
2437 while (smb2_error_map_table[idx].status_string != NULL) {
2438 if ((smb2_error_map_table[idx].smb2_status) == status) {
2439 pr_notice("Status code returned 0x%08x %s\n", status,
2440 smb2_error_map_table[idx].status_string);
2441 }
2442 idx++;
2443 }
2444 return;
2445}
2446
2447int
2448map_smb2_to_linux_error(char *buf, bool log_err)
2449{
2450 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
2451 unsigned int i;
2452 int rc = -EIO;
2453 __le32 smb2err = hdr->Status;
2454
2455 if (smb2err == 0)
2456 return 0;
2457
2458 /* mask facility */
2459 if (log_err && (smb2err != STATUS_MORE_PROCESSING_REQUIRED) &&
2460 (smb2err != STATUS_END_OF_FILE))
2461 smb2_print_status(smb2err);
2462 else if (cifsFYI & CIFS_RC)
2463 smb2_print_status(smb2err);
2464
2465 for (i = 0; i < sizeof(smb2_error_map_table) /
2466 sizeof(struct status_to_posix_error); i++) {
2467 if (smb2_error_map_table[i].smb2_status == smb2err) {
2468 rc = smb2_error_map_table[i].posix_error;
2469 break;
2470 }
2471 }
2472
2473 /* on error mapping not found - return EIO */
2474
2475 cFYI(1, "Mapping SMB2 status code %d to POSIX err %d",
2476 smb2err, rc);
2477
2478 return rc;
2479}
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
deleted file mode 100644
index 7b1c5e3287f..00000000000
--- a/fs/cifs/smb2misc.c
+++ /dev/null
@@ -1,583 +0,0 @@
1/*
2 * fs/cifs/smb2misc.c
3 *
4 * Copyright (C) International Business Machines Corp., 2002,2011
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
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/ctype.h>
24#include "smb2pdu.h"
25#include "cifsglob.h"
26#include "cifsproto.h"
27#include "smb2proto.h"
28#include "cifs_debug.h"
29#include "cifs_unicode.h"
30#include "smb2status.h"
31
32static int
33check_smb2_hdr(struct smb2_hdr *hdr, __u64 mid)
34{
35 /*
36 * Make sure that this really is an SMB, that it is a response,
37 * and that the message ids match.
38 */
39 if ((*(__le32 *)hdr->ProtocolId == SMB2_PROTO_NUMBER) &&
40 (mid == hdr->MessageId)) {
41 if (hdr->Flags & SMB2_FLAGS_SERVER_TO_REDIR)
42 return 0;
43 else {
44 /* only one valid case where server sends us request */
45 if (hdr->Command == SMB2_OPLOCK_BREAK)
46 return 0;
47 else
48 cERROR(1, "Received Request not response");
49 }
50 } else { /* bad signature or mid */
51 if (*(__le32 *)hdr->ProtocolId != SMB2_PROTO_NUMBER)
52 cERROR(1, "Bad protocol string signature header %x",
53 *(unsigned int *) hdr->ProtocolId);
54 if (mid != hdr->MessageId)
55 cERROR(1, "Mids do not match: %llu and %llu", mid,
56 hdr->MessageId);
57 }
58 cERROR(1, "Bad SMB detected. The Mid=%llu", hdr->MessageId);
59 return 1;
60}
61
62/*
63 * The following table defines the expected "StructureSize" of SMB2 responses
64 * in order by SMB2 command. This is similar to "wct" in SMB/CIFS responses.
65 *
66 * Note that commands are defined in smb2pdu.h in le16 but the array below is
67 * indexed by command in host byte order
68 */
69static const __le16 smb2_rsp_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {
70 /* SMB2_NEGOTIATE */ __constant_cpu_to_le16(65),
71 /* SMB2_SESSION_SETUP */ __constant_cpu_to_le16(9),
72 /* SMB2_LOGOFF */ __constant_cpu_to_le16(4),
73 /* SMB2_TREE_CONNECT */ __constant_cpu_to_le16(16),
74 /* SMB2_TREE_DISCONNECT */ __constant_cpu_to_le16(4),
75 /* SMB2_CREATE */ __constant_cpu_to_le16(89),
76 /* SMB2_CLOSE */ __constant_cpu_to_le16(60),
77 /* SMB2_FLUSH */ __constant_cpu_to_le16(4),
78 /* SMB2_READ */ __constant_cpu_to_le16(17),
79 /* SMB2_WRITE */ __constant_cpu_to_le16(17),
80 /* SMB2_LOCK */ __constant_cpu_to_le16(4),
81 /* SMB2_IOCTL */ __constant_cpu_to_le16(49),
82 /* BB CHECK this ... not listed in documentation */
83 /* SMB2_CANCEL */ __constant_cpu_to_le16(0),
84 /* SMB2_ECHO */ __constant_cpu_to_le16(4),
85 /* SMB2_QUERY_DIRECTORY */ __constant_cpu_to_le16(9),
86 /* SMB2_CHANGE_NOTIFY */ __constant_cpu_to_le16(9),
87 /* SMB2_QUERY_INFO */ __constant_cpu_to_le16(9),
88 /* SMB2_SET_INFO */ __constant_cpu_to_le16(2),
89 /* BB FIXME can also be 44 for lease break */
90 /* SMB2_OPLOCK_BREAK */ __constant_cpu_to_le16(24)
91};
92
93int
94smb2_check_message(char *buf, unsigned int length)
95{
96 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
97 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr;
98 __u64 mid = hdr->MessageId;
99 __u32 len = get_rfc1002_length(buf);
100 __u32 clc_len; /* calculated length */
101 int command;
102
103 /* BB disable following printk later */
104 cFYI(1, "%s length: 0x%x, smb_buf_length: 0x%x", __func__, length, len);
105
106 /*
107 * Add function to do table lookup of StructureSize by command
108 * ie Validate the wct via smb2_struct_sizes table above
109 */
110
111 if (length < sizeof(struct smb2_pdu)) {
112 if ((length >= sizeof(struct smb2_hdr)) && (hdr->Status != 0)) {
113 pdu->StructureSize2 = 0;
114 /*
115 * As with SMB/CIFS, on some error cases servers may
116 * not return wct properly
117 */
118 return 0;
119 } else {
120 cERROR(1, "Length less than SMB header size");
121 }
122 return 1;
123 }
124 if (len > CIFSMaxBufSize + MAX_SMB2_HDR_SIZE - 4) {
125 cERROR(1, "SMB length greater than maximum, mid=%llu", mid);
126 return 1;
127 }
128
129 if (check_smb2_hdr(hdr, mid))
130 return 1;
131
132 if (hdr->StructureSize != SMB2_HEADER_STRUCTURE_SIZE) {
133 cERROR(1, "Illegal structure size %u",
134 le16_to_cpu(hdr->StructureSize));
135 return 1;
136 }
137
138 command = le16_to_cpu(hdr->Command);
139 if (command >= NUMBER_OF_SMB2_COMMANDS) {
140 cERROR(1, "Illegal SMB2 command %d", command);
141 return 1;
142 }
143
144 if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) {
145 if (command != SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0 ||
146 pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) {
147 /* error packets have 9 byte structure size */
148 cERROR(1, "Illegal response size %u for command %d",
149 le16_to_cpu(pdu->StructureSize2), command);
150 return 1;
151 } else if (command == SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0)
152 && (le16_to_cpu(pdu->StructureSize2) != 44)
153 && (le16_to_cpu(pdu->StructureSize2) != 36)) {
154 /* special case for SMB2.1 lease break message */
155 cERROR(1, "Illegal response size %d for oplock break",
156 le16_to_cpu(pdu->StructureSize2));
157 return 1;
158 }
159 }
160
161 if (4 + len != length) {
162 cERROR(1, "Total length %u RFC1002 length %u mismatch mid %llu",
163 length, 4 + len, mid);
164 return 1;
165 }
166
167 clc_len = smb2_calc_size(hdr);
168
169 if (4 + len != clc_len) {
170 cFYI(1, "Calculated size %u length %u mismatch mid %llu",
171 clc_len, 4 + len, mid);
172 /* Windows 7 server returns 24 bytes more */
173 if (clc_len + 20 == len && command == SMB2_OPLOCK_BREAK_HE)
174 return 0;
175 /* server can return one byte more */
176 if (clc_len == 4 + len + 1)
177 return 0;
178 return 1;
179 }
180 return 0;
181}
182
183/*
184 * The size of the variable area depends on the offset and length fields
185 * located in different fields for various SMB2 responses. SMB2 responses
186 * with no variable length info, show an offset of zero for the offset field.
187 */
188static const bool has_smb2_data_area[NUMBER_OF_SMB2_COMMANDS] = {
189 /* SMB2_NEGOTIATE */ true,
190 /* SMB2_SESSION_SETUP */ true,
191 /* SMB2_LOGOFF */ false,
192 /* SMB2_TREE_CONNECT */ false,
193 /* SMB2_TREE_DISCONNECT */ false,
194 /* SMB2_CREATE */ true,
195 /* SMB2_CLOSE */ false,
196 /* SMB2_FLUSH */ false,
197 /* SMB2_READ */ true,
198 /* SMB2_WRITE */ false,
199 /* SMB2_LOCK */ false,
200 /* SMB2_IOCTL */ true,
201 /* SMB2_CANCEL */ false, /* BB CHECK this not listed in documentation */
202 /* SMB2_ECHO */ false,
203 /* SMB2_QUERY_DIRECTORY */ true,
204 /* SMB2_CHANGE_NOTIFY */ true,
205 /* SMB2_QUERY_INFO */ true,
206 /* SMB2_SET_INFO */ false,
207 /* SMB2_OPLOCK_BREAK */ false
208};
209
210/*
211 * Returns the pointer to the beginning of the data area. Length of the data
212 * area and the offset to it (from the beginning of the smb are also returned.
213 */
214char *
215smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
216{
217 *off = 0;
218 *len = 0;
219
220 /* error responses do not have data area */
221 if (hdr->Status && hdr->Status != STATUS_MORE_PROCESSING_REQUIRED &&
222 (((struct smb2_err_rsp *)hdr)->StructureSize) ==
223 SMB2_ERROR_STRUCTURE_SIZE2)
224 return NULL;
225
226 /*
227 * Following commands have data areas so we have to get the location
228 * of the data buffer offset and data buffer length for the particular
229 * command.
230 */
231 switch (hdr->Command) {
232 case SMB2_NEGOTIATE:
233 *off = le16_to_cpu(
234 ((struct smb2_negotiate_rsp *)hdr)->SecurityBufferOffset);
235 *len = le16_to_cpu(
236 ((struct smb2_negotiate_rsp *)hdr)->SecurityBufferLength);
237 break;
238 case SMB2_SESSION_SETUP:
239 *off = le16_to_cpu(
240 ((struct smb2_sess_setup_rsp *)hdr)->SecurityBufferOffset);
241 *len = le16_to_cpu(
242 ((struct smb2_sess_setup_rsp *)hdr)->SecurityBufferLength);
243 break;
244 case SMB2_CREATE:
245 *off = le32_to_cpu(
246 ((struct smb2_create_rsp *)hdr)->CreateContextsOffset);
247 *len = le32_to_cpu(
248 ((struct smb2_create_rsp *)hdr)->CreateContextsLength);
249 break;
250 case SMB2_QUERY_INFO:
251 *off = le16_to_cpu(
252 ((struct smb2_query_info_rsp *)hdr)->OutputBufferOffset);
253 *len = le32_to_cpu(
254 ((struct smb2_query_info_rsp *)hdr)->OutputBufferLength);
255 break;
256 case SMB2_READ:
257 *off = ((struct smb2_read_rsp *)hdr)->DataOffset;
258 *len = le32_to_cpu(((struct smb2_read_rsp *)hdr)->DataLength);
259 break;
260 case SMB2_QUERY_DIRECTORY:
261 *off = le16_to_cpu(
262 ((struct smb2_query_directory_rsp *)hdr)->OutputBufferOffset);
263 *len = le32_to_cpu(
264 ((struct smb2_query_directory_rsp *)hdr)->OutputBufferLength);
265 break;
266 case SMB2_IOCTL:
267 case SMB2_CHANGE_NOTIFY:
268 default:
269 /* BB FIXME for unimplemented cases above */
270 cERROR(1, "no length check for command");
271 break;
272 }
273
274 /*
275 * Invalid length or offset probably means data area is invalid, but
276 * we have little choice but to ignore the data area in this case.
277 */
278 if (*off > 4096) {
279 cERROR(1, "offset %d too large, data area ignored", *off);
280 *len = 0;
281 *off = 0;
282 } else if (*off < 0) {
283 cERROR(1, "negative offset %d to data invalid ignore data area",
284 *off);
285 *off = 0;
286 *len = 0;
287 } else if (*len < 0) {
288 cERROR(1, "negative data length %d invalid, data area ignored",
289 *len);
290 *len = 0;
291 } else if (*len > 128 * 1024) {
292 cERROR(1, "data area larger than 128K: %d", *len);
293 *len = 0;
294 }
295
296 /* return pointer to beginning of data area, ie offset from SMB start */
297 if ((*off != 0) && (*len != 0))
298 return hdr->ProtocolId + *off;
299 else
300 return NULL;
301}
302
303/*
304 * Calculate the size of the SMB message based on the fixed header
305 * portion, the number of word parameters and the data portion of the message.
306 */
307unsigned int
308smb2_calc_size(void *buf)
309{
310 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
311 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr;
312 int offset; /* the offset from the beginning of SMB to data area */
313 int data_length; /* the length of the variable length data area */
314 /* Structure Size has already been checked to make sure it is 64 */
315 int len = 4 + le16_to_cpu(pdu->hdr.StructureSize);
316
317 /*
318 * StructureSize2, ie length of fixed parameter area has already
319 * been checked to make sure it is the correct length.
320 */
321 len += le16_to_cpu(pdu->StructureSize2);
322
323 if (has_smb2_data_area[le16_to_cpu(hdr->Command)] == false)
324 goto calc_size_exit;
325
326 smb2_get_data_area_len(&offset, &data_length, hdr);
327 cFYI(1, "SMB2 data length %d offset %d", data_length, offset);
328
329 if (data_length > 0) {
330 /*
331 * Check to make sure that data area begins after fixed area,
332 * Note that last byte of the fixed area is part of data area
333 * for some commands, typically those with odd StructureSize,
334 * so we must add one to the calculation (and 4 to account for
335 * the size of the RFC1001 hdr.
336 */
337 if (offset + 4 + 1 < len) {
338 cERROR(1, "data area offset %d overlaps SMB2 header %d",
339 offset + 4 + 1, len);
340 data_length = 0;
341 } else {
342 len = 4 + offset + data_length;
343 }
344 }
345calc_size_exit:
346 cFYI(1, "SMB2 len %d", len);
347 return len;
348}
349
350/* Note: caller must free return buffer */
351__le16 *
352cifs_convert_path_to_utf16(const char *from, struct cifs_sb_info *cifs_sb)
353{
354 int len;
355 const char *start_of_path;
356 __le16 *to;
357
358 /* Windows doesn't allow paths beginning with \ */
359 if (from[0] == '\\')
360 start_of_path = from + 1;
361 else
362 start_of_path = from;
363 to = cifs_strndup_to_utf16(start_of_path, PATH_MAX, &len,
364 cifs_sb->local_nls,
365 cifs_sb->mnt_cifs_flags &
366 CIFS_MOUNT_MAP_SPECIAL_CHR);
367 return to;
368}
369
370__le32
371smb2_get_lease_state(struct cifsInodeInfo *cinode)
372{
373 if (cinode->clientCanCacheAll)
374 return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
375 else if (cinode->clientCanCacheRead)
376 return SMB2_LEASE_READ_CACHING;
377 return 0;
378}
379
380__u8 smb2_map_lease_to_oplock(__le32 lease_state)
381{
382 if (lease_state & SMB2_LEASE_WRITE_CACHING) {
383 if (lease_state & SMB2_LEASE_HANDLE_CACHING)
384 return SMB2_OPLOCK_LEVEL_BATCH;
385 else
386 return SMB2_OPLOCK_LEVEL_EXCLUSIVE;
387 } else if (lease_state & SMB2_LEASE_READ_CACHING)
388 return SMB2_OPLOCK_LEVEL_II;
389 return 0;
390}
391
392struct smb2_lease_break_work {
393 struct work_struct lease_break;
394 struct tcon_link *tlink;
395 __u8 lease_key[16];
396 __le32 lease_state;
397};
398
399static void
400cifs_ses_oplock_break(struct work_struct *work)
401{
402 struct smb2_lease_break_work *lw = container_of(work,
403 struct smb2_lease_break_work, lease_break);
404 int rc;
405
406 rc = SMB2_lease_break(0, tlink_tcon(lw->tlink), lw->lease_key,
407 lw->lease_state);
408 cFYI(1, "Lease release rc %d", rc);
409 cifs_put_tlink(lw->tlink);
410 kfree(lw);
411}
412
413static bool
414smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
415{
416 struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
417 struct list_head *tmp, *tmp1, *tmp2;
418 struct cifs_ses *ses;
419 struct cifs_tcon *tcon;
420 struct cifsInodeInfo *cinode;
421 struct cifsFileInfo *cfile;
422 struct cifs_pending_open *open;
423 struct smb2_lease_break_work *lw;
424 bool found;
425 int ack_req = le32_to_cpu(rsp->Flags &
426 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED);
427
428 lw = kmalloc(sizeof(struct smb2_lease_break_work), GFP_KERNEL);
429 if (!lw) {
430 cERROR(1, "Memory allocation failed during lease break check");
431 return false;
432 }
433
434 INIT_WORK(&lw->lease_break, cifs_ses_oplock_break);
435 lw->lease_state = rsp->NewLeaseState;
436
437 cFYI(1, "Checking for lease break");
438
439 /* look up tcon based on tid & uid */
440 spin_lock(&cifs_tcp_ses_lock);
441 list_for_each(tmp, &server->smb_ses_list) {
442 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
443
444 spin_lock(&cifs_file_list_lock);
445 list_for_each(tmp1, &ses->tcon_list) {
446 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
447
448 cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks);
449 list_for_each(tmp2, &tcon->openFileList) {
450 cfile = list_entry(tmp2, struct cifsFileInfo,
451 tlist);
452 cinode = CIFS_I(cfile->dentry->d_inode);
453
454 if (memcmp(cinode->lease_key, rsp->LeaseKey,
455 SMB2_LEASE_KEY_SIZE))
456 continue;
457
458 cFYI(1, "found in the open list");
459 cFYI(1, "lease key match, lease break 0x%d",
460 le32_to_cpu(rsp->NewLeaseState));
461
462 smb2_set_oplock_level(cinode,
463 smb2_map_lease_to_oplock(rsp->NewLeaseState));
464
465 if (ack_req)
466 cfile->oplock_break_cancelled = false;
467 else
468 cfile->oplock_break_cancelled = true;
469
470 queue_work(cifsiod_wq, &cfile->oplock_break);
471
472 spin_unlock(&cifs_file_list_lock);
473 spin_unlock(&cifs_tcp_ses_lock);
474 return true;
475 }
476
477 found = false;
478 list_for_each_entry(open, &tcon->pending_opens, olist) {
479 if (memcmp(open->lease_key, rsp->LeaseKey,
480 SMB2_LEASE_KEY_SIZE))
481 continue;
482
483 if (!found && ack_req) {
484 found = true;
485 memcpy(lw->lease_key, open->lease_key,
486 SMB2_LEASE_KEY_SIZE);
487 lw->tlink = cifs_get_tlink(open->tlink);
488 queue_work(cifsiod_wq,
489 &lw->lease_break);
490 }
491
492 cFYI(1, "found in the pending open list");
493 cFYI(1, "lease key match, lease break 0x%d",
494 le32_to_cpu(rsp->NewLeaseState));
495
496 open->oplock =
497 smb2_map_lease_to_oplock(rsp->NewLeaseState);
498 }
499 if (found) {
500 spin_unlock(&cifs_file_list_lock);
501 spin_unlock(&cifs_tcp_ses_lock);
502 return true;
503 }
504 }
505 spin_unlock(&cifs_file_list_lock);
506 }
507 spin_unlock(&cifs_tcp_ses_lock);
508 kfree(lw);
509 cFYI(1, "Can not process lease break - no lease matched");
510 return false;
511}
512
513bool
514smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
515{
516 struct smb2_oplock_break *rsp = (struct smb2_oplock_break *)buffer;
517 struct list_head *tmp, *tmp1, *tmp2;
518 struct cifs_ses *ses;
519 struct cifs_tcon *tcon;
520 struct cifsInodeInfo *cinode;
521 struct cifsFileInfo *cfile;
522
523 cFYI(1, "Checking for oplock break");
524
525 if (rsp->hdr.Command != SMB2_OPLOCK_BREAK)
526 return false;
527
528 if (rsp->StructureSize !=
529 smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) {
530 if (le16_to_cpu(rsp->StructureSize) == 44)
531 return smb2_is_valid_lease_break(buffer, server);
532 else
533 return false;
534 }
535
536 cFYI(1, "oplock level 0x%d", rsp->OplockLevel);
537
538 /* look up tcon based on tid & uid */
539 spin_lock(&cifs_tcp_ses_lock);
540 list_for_each(tmp, &server->smb_ses_list) {
541 ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
542 list_for_each(tmp1, &ses->tcon_list) {
543 tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
544
545 cifs_stats_inc(&tcon->stats.cifs_stats.num_oplock_brks);
546 spin_lock(&cifs_file_list_lock);
547 list_for_each(tmp2, &tcon->openFileList) {
548 cfile = list_entry(tmp2, struct cifsFileInfo,
549 tlist);
550 if (rsp->PersistentFid !=
551 cfile->fid.persistent_fid ||
552 rsp->VolatileFid !=
553 cfile->fid.volatile_fid)
554 continue;
555
556 cFYI(1, "file id match, oplock break");
557 cinode = CIFS_I(cfile->dentry->d_inode);
558
559 if (!cinode->clientCanCacheAll &&
560 rsp->OplockLevel == SMB2_OPLOCK_LEVEL_NONE)
561 cfile->oplock_break_cancelled = true;
562 else
563 cfile->oplock_break_cancelled = false;
564
565 smb2_set_oplock_level(cinode,
566 rsp->OplockLevel ? SMB2_OPLOCK_LEVEL_II : 0);
567
568 queue_work(cifsiod_wq, &cfile->oplock_break);
569
570 spin_unlock(&cifs_file_list_lock);
571 spin_unlock(&cifs_tcp_ses_lock);
572 return true;
573 }
574 spin_unlock(&cifs_file_list_lock);
575 spin_unlock(&cifs_tcp_ses_lock);
576 cFYI(1, "No matching file for oplock break");
577 return true;
578 }
579 }
580 spin_unlock(&cifs_tcp_ses_lock);
581 cFYI(1, "Can not process oplock break for non-existent connection");
582 return false;
583}
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
deleted file mode 100644
index c9c7aa7ed96..00000000000
--- a/fs/cifs/smb2ops.c
+++ /dev/null
@@ -1,747 +0,0 @@
1/*
2 * SMB2 version specific operations
3 *
4 * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published
8 * by the Free Software Foundation.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/pagemap.h>
21#include <linux/vfs.h>
22#include "cifsglob.h"
23#include "smb2pdu.h"
24#include "smb2proto.h"
25#include "cifsproto.h"
26#include "cifs_debug.h"
27#include "smb2status.h"
28#include "smb2glob.h"
29
30static int
31change_conf(struct TCP_Server_Info *server)
32{
33 server->credits += server->echo_credits + server->oplock_credits;
34 server->oplock_credits = server->echo_credits = 0;
35 switch (server->credits) {
36 case 0:
37 return -1;
38 case 1:
39 server->echoes = false;
40 server->oplocks = false;
41 cERROR(1, "disabling echoes and oplocks");
42 break;
43 case 2:
44 server->echoes = true;
45 server->oplocks = false;
46 server->echo_credits = 1;
47 cFYI(1, "disabling oplocks");
48 break;
49 default:
50 server->echoes = true;
51 server->oplocks = true;
52 server->echo_credits = 1;
53 server->oplock_credits = 1;
54 }
55 server->credits -= server->echo_credits + server->oplock_credits;
56 return 0;
57}
58
59static void
60smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
61 const int optype)
62{
63 int *val, rc = 0;
64 spin_lock(&server->req_lock);
65 val = server->ops->get_credits_field(server, optype);
66 *val += add;
67 server->in_flight--;
68 if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
69 rc = change_conf(server);
70 /*
71 * Sometimes server returns 0 credits on oplock break ack - we need to
72 * rebalance credits in this case.
73 */
74 else if (server->in_flight > 0 && server->oplock_credits == 0 &&
75 server->oplocks) {
76 if (server->credits > 1) {
77 server->credits--;
78 server->oplock_credits++;
79 }
80 }
81 spin_unlock(&server->req_lock);
82 wake_up(&server->request_q);
83 if (rc)
84 cifs_reconnect(server);
85}
86
87static void
88smb2_set_credits(struct TCP_Server_Info *server, const int val)
89{
90 spin_lock(&server->req_lock);
91 server->credits = val;
92 spin_unlock(&server->req_lock);
93}
94
95static int *
96smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
97{
98 switch (optype) {
99 case CIFS_ECHO_OP:
100 return &server->echo_credits;
101 case CIFS_OBREAK_OP:
102 return &server->oplock_credits;
103 default:
104 return &server->credits;
105 }
106}
107
108static unsigned int
109smb2_get_credits(struct mid_q_entry *mid)
110{
111 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
112}
113
114static __u64
115smb2_get_next_mid(struct TCP_Server_Info *server)
116{
117 __u64 mid;
118 /* for SMB2 we need the current value */
119 spin_lock(&GlobalMid_Lock);
120 mid = server->CurrentMid++;
121 spin_unlock(&GlobalMid_Lock);
122 return mid;
123}
124
125static struct mid_q_entry *
126smb2_find_mid(struct TCP_Server_Info *server, char *buf)
127{
128 struct mid_q_entry *mid;
129 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
130
131 spin_lock(&GlobalMid_Lock);
132 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
133 if ((mid->mid == hdr->MessageId) &&
134 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
135 (mid->command == hdr->Command)) {
136 spin_unlock(&GlobalMid_Lock);
137 return mid;
138 }
139 }
140 spin_unlock(&GlobalMid_Lock);
141 return NULL;
142}
143
144static void
145smb2_dump_detail(void *buf)
146{
147#ifdef CONFIG_CIFS_DEBUG2
148 struct smb2_hdr *smb = (struct smb2_hdr *)buf;
149
150 cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d",
151 smb->Command, smb->Status, smb->Flags, smb->MessageId,
152 smb->ProcessId);
153 cERROR(1, "smb buf %p len %u", smb, smb2_calc_size(smb));
154#endif
155}
156
157static bool
158smb2_need_neg(struct TCP_Server_Info *server)
159{
160 return server->max_read == 0;
161}
162
163static int
164smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
165{
166 int rc;
167 ses->server->CurrentMid = 0;
168 rc = SMB2_negotiate(xid, ses);
169 /* BB we probably don't need to retry with modern servers */
170 if (rc == -EAGAIN)
171 rc = -EHOSTDOWN;
172 return rc;
173}
174
175static unsigned int
176smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
177{
178 struct TCP_Server_Info *server = tcon->ses->server;
179 unsigned int wsize;
180
181 /* start with specified wsize, or default */
182 wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
183 wsize = min_t(unsigned int, wsize, server->max_write);
184 /*
185 * limit write size to 2 ** 16, because we don't support multicredit
186 * requests now.
187 */
188 wsize = min_t(unsigned int, wsize, 2 << 15);
189
190 return wsize;
191}
192
193static unsigned int
194smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
195{
196 struct TCP_Server_Info *server = tcon->ses->server;
197 unsigned int rsize;
198
199 /* start with specified rsize, or default */
200 rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
201 rsize = min_t(unsigned int, rsize, server->max_read);
202 /*
203 * limit write size to 2 ** 16, because we don't support multicredit
204 * requests now.
205 */
206 rsize = min_t(unsigned int, rsize, 2 << 15);
207
208 return rsize;
209}
210
211static int
212smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
213 struct cifs_sb_info *cifs_sb, const char *full_path)
214{
215 int rc;
216 __u64 persistent_fid, volatile_fid;
217 __le16 *utf16_path;
218 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
219
220 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
221 if (!utf16_path)
222 return -ENOMEM;
223
224 rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
225 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL);
226 if (rc) {
227 kfree(utf16_path);
228 return rc;
229 }
230
231 rc = SMB2_close(xid, tcon, persistent_fid, volatile_fid);
232 kfree(utf16_path);
233 return rc;
234}
235
236static int
237smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
238 struct cifs_sb_info *cifs_sb, const char *full_path,
239 u64 *uniqueid, FILE_ALL_INFO *data)
240{
241 *uniqueid = le64_to_cpu(data->IndexNumber);
242 return 0;
243}
244
245static int
246smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
247 struct cifs_fid *fid, FILE_ALL_INFO *data)
248{
249 int rc;
250 struct smb2_file_all_info *smb2_data;
251
252 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
253 GFP_KERNEL);
254 if (smb2_data == NULL)
255 return -ENOMEM;
256
257 rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
258 smb2_data);
259 if (!rc)
260 move_smb2_info_to_cifs(data, smb2_data);
261 kfree(smb2_data);
262 return rc;
263}
264
265static bool
266smb2_can_echo(struct TCP_Server_Info *server)
267{
268 return server->echoes;
269}
270
271static void
272smb2_clear_stats(struct cifs_tcon *tcon)
273{
274#ifdef CONFIG_CIFS_STATS
275 int i;
276 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
277 atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
278 atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
279 }
280#endif
281}
282
283static void
284smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
285{
286#ifdef CONFIG_CIFS_STATS
287 atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
288 atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
289 seq_printf(m, "\nNegotiates: %d sent %d failed",
290 atomic_read(&sent[SMB2_NEGOTIATE_HE]),
291 atomic_read(&failed[SMB2_NEGOTIATE_HE]));
292 seq_printf(m, "\nSessionSetups: %d sent %d failed",
293 atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
294 atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
295#define SMB2LOGOFF 0x0002 /* trivial request/resp */
296 seq_printf(m, "\nLogoffs: %d sent %d failed",
297 atomic_read(&sent[SMB2_LOGOFF_HE]),
298 atomic_read(&failed[SMB2_LOGOFF_HE]));
299 seq_printf(m, "\nTreeConnects: %d sent %d failed",
300 atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
301 atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
302 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
303 atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
304 atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
305 seq_printf(m, "\nCreates: %d sent %d failed",
306 atomic_read(&sent[SMB2_CREATE_HE]),
307 atomic_read(&failed[SMB2_CREATE_HE]));
308 seq_printf(m, "\nCloses: %d sent %d failed",
309 atomic_read(&sent[SMB2_CLOSE_HE]),
310 atomic_read(&failed[SMB2_CLOSE_HE]));
311 seq_printf(m, "\nFlushes: %d sent %d failed",
312 atomic_read(&sent[SMB2_FLUSH_HE]),
313 atomic_read(&failed[SMB2_FLUSH_HE]));
314 seq_printf(m, "\nReads: %d sent %d failed",
315 atomic_read(&sent[SMB2_READ_HE]),
316 atomic_read(&failed[SMB2_READ_HE]));
317 seq_printf(m, "\nWrites: %d sent %d failed",
318 atomic_read(&sent[SMB2_WRITE_HE]),
319 atomic_read(&failed[SMB2_WRITE_HE]));
320 seq_printf(m, "\nLocks: %d sent %d failed",
321 atomic_read(&sent[SMB2_LOCK_HE]),
322 atomic_read(&failed[SMB2_LOCK_HE]));
323 seq_printf(m, "\nIOCTLs: %d sent %d failed",
324 atomic_read(&sent[SMB2_IOCTL_HE]),
325 atomic_read(&failed[SMB2_IOCTL_HE]));
326 seq_printf(m, "\nCancels: %d sent %d failed",
327 atomic_read(&sent[SMB2_CANCEL_HE]),
328 atomic_read(&failed[SMB2_CANCEL_HE]));
329 seq_printf(m, "\nEchos: %d sent %d failed",
330 atomic_read(&sent[SMB2_ECHO_HE]),
331 atomic_read(&failed[SMB2_ECHO_HE]));
332 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
333 atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
334 atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
335 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
336 atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
337 atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
338 seq_printf(m, "\nQueryInfos: %d sent %d failed",
339 atomic_read(&sent[SMB2_QUERY_INFO_HE]),
340 atomic_read(&failed[SMB2_QUERY_INFO_HE]));
341 seq_printf(m, "\nSetInfos: %d sent %d failed",
342 atomic_read(&sent[SMB2_SET_INFO_HE]),
343 atomic_read(&failed[SMB2_SET_INFO_HE]));
344 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
345 atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
346 atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
347#endif
348}
349
350static void
351smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
352{
353 struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
354 cfile->fid.persistent_fid = fid->persistent_fid;
355 cfile->fid.volatile_fid = fid->volatile_fid;
356 smb2_set_oplock_level(cinode, oplock);
357 cinode->can_cache_brlcks = cinode->clientCanCacheAll;
358}
359
360static void
361smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
362 struct cifs_fid *fid)
363{
364 SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
365}
366
367static int
368smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
369 struct cifs_fid *fid)
370{
371 return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
372}
373
374static unsigned int
375smb2_read_data_offset(char *buf)
376{
377 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
378 return rsp->DataOffset;
379}
380
381static unsigned int
382smb2_read_data_length(char *buf)
383{
384 struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
385 return le32_to_cpu(rsp->DataLength);
386}
387
388
389static int
390smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
391 struct cifs_io_parms *parms, unsigned int *bytes_read,
392 char **buf, int *buf_type)
393{
394 parms->persistent_fid = cfile->fid.persistent_fid;
395 parms->volatile_fid = cfile->fid.volatile_fid;
396 return SMB2_read(xid, parms, bytes_read, buf, buf_type);
397}
398
399static int
400smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
401 struct cifs_io_parms *parms, unsigned int *written,
402 struct kvec *iov, unsigned long nr_segs)
403{
404
405 parms->persistent_fid = cfile->fid.persistent_fid;
406 parms->volatile_fid = cfile->fid.volatile_fid;
407 return SMB2_write(xid, parms, written, iov, nr_segs);
408}
409
410static int
411smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
412 struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
413{
414 __le64 eof = cpu_to_le64(size);
415 return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
416 cfile->fid.volatile_fid, cfile->pid, &eof);
417}
418
419static int
420smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
421 const char *path, struct cifs_sb_info *cifs_sb,
422 struct cifs_fid *fid, __u16 search_flags,
423 struct cifs_search_info *srch_inf)
424{
425 __le16 *utf16_path;
426 int rc;
427 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
428 __u64 persistent_fid, volatile_fid;
429
430 utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
431 if (!utf16_path)
432 return -ENOMEM;
433
434 rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
435 FILE_READ_ATTRIBUTES | FILE_READ_DATA, FILE_OPEN, 0, 0,
436 &oplock, NULL);
437 kfree(utf16_path);
438 if (rc) {
439 cERROR(1, "open dir failed");
440 return rc;
441 }
442
443 srch_inf->entries_in_buffer = 0;
444 srch_inf->index_of_last_entry = 0;
445 fid->persistent_fid = persistent_fid;
446 fid->volatile_fid = volatile_fid;
447
448 rc = SMB2_query_directory(xid, tcon, persistent_fid, volatile_fid, 0,
449 srch_inf);
450 if (rc) {
451 cERROR(1, "query directory failed");
452 SMB2_close(xid, tcon, persistent_fid, volatile_fid);
453 }
454 return rc;
455}
456
457static int
458smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
459 struct cifs_fid *fid, __u16 search_flags,
460 struct cifs_search_info *srch_inf)
461{
462 return SMB2_query_directory(xid, tcon, fid->persistent_fid,
463 fid->volatile_fid, 0, srch_inf);
464}
465
466static int
467smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
468 struct cifs_fid *fid)
469{
470 return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
471}
472
473/*
474* If we negotiate SMB2 protocol and get STATUS_PENDING - update
475* the number of credits and return true. Otherwise - return false.
476*/
477static bool
478smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
479{
480 struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
481
482 if (hdr->Status != STATUS_PENDING)
483 return false;
484
485 if (!length) {
486 spin_lock(&server->req_lock);
487 server->credits += le16_to_cpu(hdr->CreditRequest);
488 spin_unlock(&server->req_lock);
489 wake_up(&server->request_q);
490 }
491
492 return true;
493}
494
495static int
496smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
497 struct cifsInodeInfo *cinode)
498{
499 if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
500 return SMB2_lease_break(0, tcon, cinode->lease_key,
501 smb2_get_lease_state(cinode));
502
503 return SMB2_oplock_break(0, tcon, fid->persistent_fid,
504 fid->volatile_fid,
505 cinode->clientCanCacheRead ? 1 : 0);
506}
507
508static int
509smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
510 struct kstatfs *buf)
511{
512 int rc;
513 u64 persistent_fid, volatile_fid;
514 __le16 srch_path = 0; /* Null - open root of share */
515 u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
516
517 rc = SMB2_open(xid, tcon, &srch_path, &persistent_fid, &volatile_fid,
518 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL);
519 if (rc)
520 return rc;
521 buf->f_type = SMB2_MAGIC_NUMBER;
522 rc = SMB2_QFS_info(xid, tcon, persistent_fid, volatile_fid, buf);
523 SMB2_close(xid, tcon, persistent_fid, volatile_fid);
524 return rc;
525}
526
527static bool
528smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
529{
530 return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
531 ob1->fid.volatile_fid == ob2->fid.volatile_fid;
532}
533
534static int
535smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
536 __u64 length, __u32 type, int lock, int unlock, bool wait)
537{
538 if (unlock && !lock)
539 type = SMB2_LOCKFLAG_UNLOCK;
540 return SMB2_lock(xid, tlink_tcon(cfile->tlink),
541 cfile->fid.persistent_fid, cfile->fid.volatile_fid,
542 current->tgid, length, offset, type, wait);
543}
544
545static void
546smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
547{
548 memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
549}
550
551static void
552smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
553{
554 memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
555}
556
557static void
558smb2_new_lease_key(struct cifs_fid *fid)
559{
560 get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
561}
562
563struct smb_version_operations smb21_operations = {
564 .compare_fids = smb2_compare_fids,
565 .setup_request = smb2_setup_request,
566 .setup_async_request = smb2_setup_async_request,
567 .check_receive = smb2_check_receive,
568 .add_credits = smb2_add_credits,
569 .set_credits = smb2_set_credits,
570 .get_credits_field = smb2_get_credits_field,
571 .get_credits = smb2_get_credits,
572 .get_next_mid = smb2_get_next_mid,
573 .read_data_offset = smb2_read_data_offset,
574 .read_data_length = smb2_read_data_length,
575 .map_error = map_smb2_to_linux_error,
576 .find_mid = smb2_find_mid,
577 .check_message = smb2_check_message,
578 .dump_detail = smb2_dump_detail,
579 .clear_stats = smb2_clear_stats,
580 .print_stats = smb2_print_stats,
581 .is_oplock_break = smb2_is_valid_oplock_break,
582 .need_neg = smb2_need_neg,
583 .negotiate = smb2_negotiate,
584 .negotiate_wsize = smb2_negotiate_wsize,
585 .negotiate_rsize = smb2_negotiate_rsize,
586 .sess_setup = SMB2_sess_setup,
587 .logoff = SMB2_logoff,
588 .tree_connect = SMB2_tcon,
589 .tree_disconnect = SMB2_tdis,
590 .is_path_accessible = smb2_is_path_accessible,
591 .can_echo = smb2_can_echo,
592 .echo = SMB2_echo,
593 .query_path_info = smb2_query_path_info,
594 .get_srv_inum = smb2_get_srv_inum,
595 .query_file_info = smb2_query_file_info,
596 .set_path_size = smb2_set_path_size,
597 .set_file_size = smb2_set_file_size,
598 .set_file_info = smb2_set_file_info,
599 .mkdir = smb2_mkdir,
600 .mkdir_setinfo = smb2_mkdir_setinfo,
601 .rmdir = smb2_rmdir,
602 .unlink = smb2_unlink,
603 .rename = smb2_rename_path,
604 .create_hardlink = smb2_create_hardlink,
605 .open = smb2_open_file,
606 .set_fid = smb2_set_fid,
607 .close = smb2_close_file,
608 .flush = smb2_flush_file,
609 .async_readv = smb2_async_readv,
610 .async_writev = smb2_async_writev,
611 .sync_read = smb2_sync_read,
612 .sync_write = smb2_sync_write,
613 .query_dir_first = smb2_query_dir_first,
614 .query_dir_next = smb2_query_dir_next,
615 .close_dir = smb2_close_dir,
616 .calc_smb_size = smb2_calc_size,
617 .is_status_pending = smb2_is_status_pending,
618 .oplock_response = smb2_oplock_response,
619 .queryfs = smb2_queryfs,
620 .mand_lock = smb2_mand_lock,
621 .mand_unlock_range = smb2_unlock_range,
622 .push_mand_locks = smb2_push_mandatory_locks,
623 .get_lease_key = smb2_get_lease_key,
624 .set_lease_key = smb2_set_lease_key,
625 .new_lease_key = smb2_new_lease_key,
626 .calc_signature = smb2_calc_signature,
627};
628
629
630struct smb_version_operations smb30_operations = {
631 .compare_fids = smb2_compare_fids,
632 .setup_request = smb2_setup_request,
633 .setup_async_request = smb2_setup_async_request,
634 .check_receive = smb2_check_receive,
635 .add_credits = smb2_add_credits,
636 .set_credits = smb2_set_credits,
637 .get_credits_field = smb2_get_credits_field,
638 .get_credits = smb2_get_credits,
639 .get_next_mid = smb2_get_next_mid,
640 .read_data_offset = smb2_read_data_offset,
641 .read_data_length = smb2_read_data_length,
642 .map_error = map_smb2_to_linux_error,
643 .find_mid = smb2_find_mid,
644 .check_message = smb2_check_message,
645 .dump_detail = smb2_dump_detail,
646 .clear_stats = smb2_clear_stats,
647 .print_stats = smb2_print_stats,
648 .is_oplock_break = smb2_is_valid_oplock_break,
649 .need_neg = smb2_need_neg,
650 .negotiate = smb2_negotiate,
651 .negotiate_wsize = smb2_negotiate_wsize,
652 .negotiate_rsize = smb2_negotiate_rsize,
653 .sess_setup = SMB2_sess_setup,
654 .logoff = SMB2_logoff,
655 .tree_connect = SMB2_tcon,
656 .tree_disconnect = SMB2_tdis,
657 .is_path_accessible = smb2_is_path_accessible,
658 .can_echo = smb2_can_echo,
659 .echo = SMB2_echo,
660 .query_path_info = smb2_query_path_info,
661 .get_srv_inum = smb2_get_srv_inum,
662 .query_file_info = smb2_query_file_info,
663 .set_path_size = smb2_set_path_size,
664 .set_file_size = smb2_set_file_size,
665 .set_file_info = smb2_set_file_info,
666 .mkdir = smb2_mkdir,
667 .mkdir_setinfo = smb2_mkdir_setinfo,
668 .rmdir = smb2_rmdir,
669 .unlink = smb2_unlink,
670 .rename = smb2_rename_path,
671 .create_hardlink = smb2_create_hardlink,
672 .open = smb2_open_file,
673 .set_fid = smb2_set_fid,
674 .close = smb2_close_file,
675 .flush = smb2_flush_file,
676 .async_readv = smb2_async_readv,
677 .async_writev = smb2_async_writev,
678 .sync_read = smb2_sync_read,
679 .sync_write = smb2_sync_write,
680 .query_dir_first = smb2_query_dir_first,
681 .query_dir_next = smb2_query_dir_next,
682 .close_dir = smb2_close_dir,
683 .calc_smb_size = smb2_calc_size,
684 .is_status_pending = smb2_is_status_pending,
685 .oplock_response = smb2_oplock_response,
686 .queryfs = smb2_queryfs,
687 .mand_lock = smb2_mand_lock,
688 .mand_unlock_range = smb2_unlock_range,
689 .push_mand_locks = smb2_push_mandatory_locks,
690 .get_lease_key = smb2_get_lease_key,
691 .set_lease_key = smb2_set_lease_key,
692 .new_lease_key = smb2_new_lease_key,
693 .calc_signature = smb3_calc_signature,
694};
695
696struct smb_version_values smb20_values = {
697 .version_string = SMB20_VERSION_STRING,
698 .protocol_id = SMB20_PROT_ID,
699 .req_capabilities = 0, /* MBZ */
700 .large_lock_type = 0,
701 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
702 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
703 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
704 .header_size = sizeof(struct smb2_hdr),
705 .max_header_size = MAX_SMB2_HDR_SIZE,
706 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
707 .lock_cmd = SMB2_LOCK,
708 .cap_unix = 0,
709 .cap_nt_find = SMB2_NT_FIND,
710 .cap_large_files = SMB2_LARGE_FILES,
711 .oplock_read = SMB2_OPLOCK_LEVEL_II,
712};
713
714struct smb_version_values smb21_values = {
715 .version_string = SMB21_VERSION_STRING,
716 .protocol_id = SMB21_PROT_ID,
717 .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
718 .large_lock_type = 0,
719 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
720 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
721 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
722 .header_size = sizeof(struct smb2_hdr),
723 .max_header_size = MAX_SMB2_HDR_SIZE,
724 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
725 .lock_cmd = SMB2_LOCK,
726 .cap_unix = 0,
727 .cap_nt_find = SMB2_NT_FIND,
728 .cap_large_files = SMB2_LARGE_FILES,
729 .oplock_read = SMB2_OPLOCK_LEVEL_II,
730};
731
732struct smb_version_values smb30_values = {
733 .version_string = SMB30_VERSION_STRING,
734 .protocol_id = SMB30_PROT_ID,
735 .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
736 .large_lock_type = 0,
737 .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
738 .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
739 .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
740 .header_size = sizeof(struct smb2_hdr),
741 .max_header_size = MAX_SMB2_HDR_SIZE,
742 .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
743 .lock_cmd = SMB2_LOCK,
744 .cap_unix = 0,
745 .cap_nt_find = SMB2_NT_FIND,
746 .cap_large_files = SMB2_LARGE_FILES,
747};
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
deleted file mode 100644
index 41d9d0725f0..00000000000
--- a/fs/cifs/smb2pdu.c
+++ /dev/null
@@ -1,2211 +0,0 @@
1/*
2 * fs/cifs/smb2pdu.c
3 *
4 * Copyright (C) International Business Machines Corp., 2009, 2012
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
8 *
9 * Contains the routines for constructing the SMB2 PDUs themselves
10 *
11 * This library is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published
13 * by the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 /* SMB2 PDU handling routines here - except for leftovers (eg session setup) */
27 /* Note that there are handle based routines which must be */
28 /* treated slightly differently for reconnection purposes since we never */
29 /* want to reuse a stale file handle and only the caller knows the file info */
30
31#include <linux/fs.h>
32#include <linux/kernel.h>
33#include <linux/vfs.h>
34#include <linux/task_io_accounting_ops.h>
35#include <linux/uaccess.h>
36#include <linux/pagemap.h>
37#include <linux/xattr.h>
38#include "smb2pdu.h"
39#include "cifsglob.h"
40#include "cifsacl.h"
41#include "cifsproto.h"
42#include "smb2proto.h"
43#include "cifs_unicode.h"
44#include "cifs_debug.h"
45#include "ntlmssp.h"
46#include "smb2status.h"
47#include "smb2glob.h"
48#include "cifspdu.h"
49
50/*
51 * The following table defines the expected "StructureSize" of SMB2 requests
52 * in order by SMB2 command. This is similar to "wct" in SMB/CIFS requests.
53 *
54 * Note that commands are defined in smb2pdu.h in le16 but the array below is
55 * indexed by command in host byte order.
56 */
57static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {
58 /* SMB2_NEGOTIATE */ 36,
59 /* SMB2_SESSION_SETUP */ 25,
60 /* SMB2_LOGOFF */ 4,
61 /* SMB2_TREE_CONNECT */ 9,
62 /* SMB2_TREE_DISCONNECT */ 4,
63 /* SMB2_CREATE */ 57,
64 /* SMB2_CLOSE */ 24,
65 /* SMB2_FLUSH */ 24,
66 /* SMB2_READ */ 49,
67 /* SMB2_WRITE */ 49,
68 /* SMB2_LOCK */ 48,
69 /* SMB2_IOCTL */ 57,
70 /* SMB2_CANCEL */ 4,
71 /* SMB2_ECHO */ 4,
72 /* SMB2_QUERY_DIRECTORY */ 33,
73 /* SMB2_CHANGE_NOTIFY */ 32,
74 /* SMB2_QUERY_INFO */ 41,
75 /* SMB2_SET_INFO */ 33,
76 /* SMB2_OPLOCK_BREAK */ 24 /* BB this is 36 for LEASE_BREAK variant */
77};
78
79
80static void
81smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
82 const struct cifs_tcon *tcon)
83{
84 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr;
85 char *temp = (char *)hdr;
86 /* lookup word count ie StructureSize from table */
87 __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)];
88
89 /*
90 * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of
91 * largest operations (Create)
92 */
93 memset(temp, 0, 256);
94
95 /* Note this is only network field converted to big endian */
96 hdr->smb2_buf_length = cpu_to_be32(parmsize + sizeof(struct smb2_hdr)
97 - 4 /* RFC 1001 length field itself not counted */);
98
99 hdr->ProtocolId[0] = 0xFE;
100 hdr->ProtocolId[1] = 'S';
101 hdr->ProtocolId[2] = 'M';
102 hdr->ProtocolId[3] = 'B';
103 hdr->StructureSize = cpu_to_le16(64);
104 hdr->Command = smb2_cmd;
105 hdr->CreditRequest = cpu_to_le16(2); /* BB make this dynamic */
106 hdr->ProcessId = cpu_to_le32((__u16)current->tgid);
107
108 if (!tcon)
109 goto out;
110
111 hdr->TreeId = tcon->tid;
112 /* Uid is not converted */
113 if (tcon->ses)
114 hdr->SessionId = tcon->ses->Suid;
115 /* BB check following DFS flags BB */
116 /* BB do we have to add check for SHI1005_FLAGS_DFS_ROOT too? */
117 if (tcon->share_flags & SHI1005_FLAGS_DFS)
118 hdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS;
119 /* BB how does SMB2 do case sensitive? */
120 /* if (tcon->nocase)
121 hdr->Flags |= SMBFLG_CASELESS; */
122 if (tcon->ses && tcon->ses->server &&
123 (tcon->ses->server->sec_mode & SECMODE_SIGN_REQUIRED))
124 hdr->Flags |= SMB2_FLAGS_SIGNED;
125out:
126 pdu->StructureSize2 = cpu_to_le16(parmsize);
127 return;
128}
129
130static int
131smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon)
132{
133 int rc = 0;
134 struct nls_table *nls_codepage;
135 struct cifs_ses *ses;
136 struct TCP_Server_Info *server;
137
138 /*
139 * SMB2s NegProt, SessSetup, Logoff do not have tcon yet so
140 * check for tcp and smb session status done differently
141 * for those three - in the calling routine.
142 */
143 if (tcon == NULL)
144 return rc;
145
146 if (smb2_command == SMB2_TREE_CONNECT)
147 return rc;
148
149 if (tcon->tidStatus == CifsExiting) {
150 /*
151 * only tree disconnect, open, and write,
152 * (and ulogoff which does not have tcon)
153 * are allowed as we start force umount.
154 */
155 if ((smb2_command != SMB2_WRITE) &&
156 (smb2_command != SMB2_CREATE) &&
157 (smb2_command != SMB2_TREE_DISCONNECT)) {
158 cFYI(1, "can not send cmd %d while umounting",
159 smb2_command);
160 return -ENODEV;
161 }
162 }
163 if ((!tcon->ses) || (tcon->ses->status == CifsExiting) ||
164 (!tcon->ses->server))
165 return -EIO;
166
167 ses = tcon->ses;
168 server = ses->server;
169
170 /*
171 * Give demultiplex thread up to 10 seconds to reconnect, should be
172 * greater than cifs socket timeout which is 7 seconds
173 */
174 while (server->tcpStatus == CifsNeedReconnect) {
175 /*
176 * Return to caller for TREE_DISCONNECT and LOGOFF and CLOSE
177 * here since they are implicitly done when session drops.
178 */
179 switch (smb2_command) {
180 /*
181 * BB Should we keep oplock break and add flush to exceptions?
182 */
183 case SMB2_TREE_DISCONNECT:
184 case SMB2_CANCEL:
185 case SMB2_CLOSE:
186 case SMB2_OPLOCK_BREAK:
187 return -EAGAIN;
188 }
189
190 wait_event_interruptible_timeout(server->response_q,
191 (server->tcpStatus != CifsNeedReconnect), 10 * HZ);
192
193 /* are we still trying to reconnect? */
194 if (server->tcpStatus != CifsNeedReconnect)
195 break;
196
197 /*
198 * on "soft" mounts we wait once. Hard mounts keep
199 * retrying until process is killed or server comes
200 * back on-line
201 */
202 if (!tcon->retry) {
203 cFYI(1, "gave up waiting on reconnect in smb_init");
204 return -EHOSTDOWN;
205 }
206 }
207
208 if (!tcon->ses->need_reconnect && !tcon->need_reconnect)
209 return rc;
210
211 nls_codepage = load_nls_default();
212
213 /*
214 * need to prevent multiple threads trying to simultaneously reconnect
215 * the same SMB session
216 */
217 mutex_lock(&tcon->ses->session_mutex);
218 rc = cifs_negotiate_protocol(0, tcon->ses);
219 if (!rc && tcon->ses->need_reconnect)
220 rc = cifs_setup_session(0, tcon->ses, nls_codepage);
221
222 if (rc || !tcon->need_reconnect) {
223 mutex_unlock(&tcon->ses->session_mutex);
224 goto out;
225 }
226
227 cifs_mark_open_files_invalid(tcon);
228 rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nls_codepage);
229 mutex_unlock(&tcon->ses->session_mutex);
230 cFYI(1, "reconnect tcon rc = %d", rc);
231 if (rc)
232 goto out;
233 atomic_inc(&tconInfoReconnectCount);
234 /*
235 * BB FIXME add code to check if wsize needs update due to negotiated
236 * smb buffer size shrinking.
237 */
238out:
239 /*
240 * Check if handle based operation so we know whether we can continue
241 * or not without returning to caller to reset file handle.
242 */
243 /*
244 * BB Is flush done by server on drop of tcp session? Should we special
245 * case it and skip above?
246 */
247 switch (smb2_command) {
248 case SMB2_FLUSH:
249 case SMB2_READ:
250 case SMB2_WRITE:
251 case SMB2_LOCK:
252 case SMB2_IOCTL:
253 case SMB2_QUERY_DIRECTORY:
254 case SMB2_CHANGE_NOTIFY:
255 case SMB2_QUERY_INFO:
256 case SMB2_SET_INFO:
257 return -EAGAIN;
258 }
259 unload_nls(nls_codepage);
260 return rc;
261}
262
263/*
264 * Allocate and return pointer to an SMB request hdr, and set basic
265 * SMB information in the SMB header. If the return code is zero, this
266 * function must have filled in request_buf pointer.
267 */
268static int
269small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon,
270 void **request_buf)
271{
272 int rc = 0;
273
274 rc = smb2_reconnect(smb2_command, tcon);
275 if (rc)
276 return rc;
277
278 /* BB eventually switch this to SMB2 specific small buf size */
279 *request_buf = cifs_small_buf_get();
280 if (*request_buf == NULL) {
281 /* BB should we add a retry in here if not a writepage? */
282 return -ENOMEM;
283 }
284
285 smb2_hdr_assemble((struct smb2_hdr *) *request_buf, smb2_command, tcon);
286
287 if (tcon != NULL) {
288#ifdef CONFIG_CIFS_STATS2
289 uint16_t com_code = le16_to_cpu(smb2_command);
290 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]);
291#endif
292 cifs_stats_inc(&tcon->num_smbs_sent);
293 }
294
295 return rc;
296}
297
298static void
299free_rsp_buf(int resp_buftype, void *rsp)
300{
301 if (resp_buftype == CIFS_SMALL_BUFFER)
302 cifs_small_buf_release(rsp);
303 else if (resp_buftype == CIFS_LARGE_BUFFER)
304 cifs_buf_release(rsp);
305}
306
307
308/*
309 *
310 * SMB2 Worker functions follow:
311 *
312 * The general structure of the worker functions is:
313 * 1) Call smb2_init (assembles SMB2 header)
314 * 2) Initialize SMB2 command specific fields in fixed length area of SMB
315 * 3) Call smb_sendrcv2 (sends request on socket and waits for response)
316 * 4) Decode SMB2 command specific fields in the fixed length area
317 * 5) Decode variable length data area (if any for this SMB2 command type)
318 * 6) Call free smb buffer
319 * 7) return
320 *
321 */
322
323int
324SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
325{
326 struct smb2_negotiate_req *req;
327 struct smb2_negotiate_rsp *rsp;
328 struct kvec iov[1];
329 int rc = 0;
330 int resp_buftype;
331 struct TCP_Server_Info *server;
332 unsigned int sec_flags;
333 u16 temp = 0;
334 int blob_offset, blob_length;
335 char *security_blob;
336 int flags = CIFS_NEG_OP;
337
338 cFYI(1, "Negotiate protocol");
339
340 if (ses->server)
341 server = ses->server;
342 else {
343 rc = -EIO;
344 return rc;
345 }
346
347 rc = small_smb2_init(SMB2_NEGOTIATE, NULL, (void **) &req);
348 if (rc)
349 return rc;
350
351 /* if any of auth flags (ie not sign or seal) are overriden use them */
352 if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL)))
353 sec_flags = ses->overrideSecFlg; /* BB FIXME fix sign flags?*/
354 else /* if override flags set only sign/seal OR them with global auth */
355 sec_flags = global_secflags | ses->overrideSecFlg;
356
357 cFYI(1, "sec_flags 0x%x", sec_flags);
358
359 req->hdr.SessionId = 0;
360
361 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
362
363 req->DialectCount = cpu_to_le16(1); /* One vers= at a time for now */
364 inc_rfc1001_len(req, 2);
365
366 /* only one of SMB2 signing flags may be set in SMB2 request */
367 if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN)
368 temp = SMB2_NEGOTIATE_SIGNING_REQUIRED;
369 else if (sec_flags & CIFSSEC_MAY_SIGN) /* MAY_SIGN is a single flag */
370 temp = SMB2_NEGOTIATE_SIGNING_ENABLED;
371
372 req->SecurityMode = cpu_to_le16(temp);
373
374 req->Capabilities = cpu_to_le32(ses->server->vals->req_capabilities);
375
376 memcpy(req->ClientGUID, cifs_client_guid, SMB2_CLIENT_GUID_SIZE);
377
378 iov[0].iov_base = (char *)req;
379 /* 4 for rfc1002 length field */
380 iov[0].iov_len = get_rfc1002_length(req) + 4;
381
382 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, flags);
383
384 rsp = (struct smb2_negotiate_rsp *)iov[0].iov_base;
385 /*
386 * No tcon so can't do
387 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
388 */
389 if (rc != 0)
390 goto neg_exit;
391
392 cFYI(1, "mode 0x%x", rsp->SecurityMode);
393
394 /* BB we may eventually want to match the negotiated vs. requested
395 dialect, even though we are only requesting one at a time */
396 if (rsp->DialectRevision == cpu_to_le16(SMB20_PROT_ID))
397 cFYI(1, "negotiated smb2.0 dialect");
398 else if (rsp->DialectRevision == cpu_to_le16(SMB21_PROT_ID))
399 cFYI(1, "negotiated smb2.1 dialect");
400 else if (rsp->DialectRevision == cpu_to_le16(SMB30_PROT_ID))
401 cFYI(1, "negotiated smb3.0 dialect");
402 else {
403 cERROR(1, "Illegal dialect returned by server %d",
404 le16_to_cpu(rsp->DialectRevision));
405 rc = -EIO;
406 goto neg_exit;
407 }
408 server->dialect = le16_to_cpu(rsp->DialectRevision);
409
410 server->maxBuf = le32_to_cpu(rsp->MaxTransactSize);
411 server->max_read = le32_to_cpu(rsp->MaxReadSize);
412 server->max_write = le32_to_cpu(rsp->MaxWriteSize);
413 /* BB Do we need to validate the SecurityMode? */
414 server->sec_mode = le16_to_cpu(rsp->SecurityMode);
415 server->capabilities = le32_to_cpu(rsp->Capabilities);
416 /* Internal types */
417 server->capabilities |= SMB2_NT_FIND | SMB2_LARGE_FILES;
418
419 security_blob = smb2_get_data_area_len(&blob_offset, &blob_length,
420 &rsp->hdr);
421 if (blob_length == 0) {
422 cERROR(1, "missing security blob on negprot");
423 rc = -EIO;
424 goto neg_exit;
425 }
426
427 cFYI(1, "sec_flags 0x%x", sec_flags);
428 if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) {
429 cFYI(1, "Signing required");
430 if (!(server->sec_mode & (SMB2_NEGOTIATE_SIGNING_REQUIRED |
431 SMB2_NEGOTIATE_SIGNING_ENABLED))) {
432 cERROR(1, "signing required but server lacks support");
433 rc = -EOPNOTSUPP;
434 goto neg_exit;
435 }
436 server->sec_mode |= SECMODE_SIGN_REQUIRED;
437 } else if (sec_flags & CIFSSEC_MAY_SIGN) {
438 cFYI(1, "Signing optional");
439 if (server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) {
440 cFYI(1, "Server requires signing");
441 server->sec_mode |= SECMODE_SIGN_REQUIRED;
442 } else {
443 server->sec_mode &=
444 ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED);
445 }
446 } else {
447 cFYI(1, "Signing disabled");
448 if (server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED) {
449 cERROR(1, "Server requires packet signing to be enabled"
450 " in /proc/fs/cifs/SecurityFlags.");
451 rc = -EOPNOTSUPP;
452 goto neg_exit;
453 }
454 server->sec_mode &=
455 ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED);
456 }
457
458#ifdef CONFIG_SMB2_ASN1 /* BB REMOVEME when updated asn1.c ready */
459 rc = decode_neg_token_init(security_blob, blob_length,
460 &server->sec_type);
461 if (rc == 1)
462 rc = 0;
463 else if (rc == 0) {
464 rc = -EIO;
465 goto neg_exit;
466 }
467#endif
468
469neg_exit:
470 free_rsp_buf(resp_buftype, rsp);
471 return rc;
472}
473
474int
475SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
476 const struct nls_table *nls_cp)
477{
478 struct smb2_sess_setup_req *req;
479 struct smb2_sess_setup_rsp *rsp = NULL;
480 struct kvec iov[2];
481 int rc = 0;
482 int resp_buftype;
483 __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */
484 struct TCP_Server_Info *server;
485 unsigned int sec_flags;
486 u8 temp = 0;
487 u16 blob_length = 0;
488 char *security_blob;
489 char *ntlmssp_blob = NULL;
490 bool use_spnego = false; /* else use raw ntlmssp */
491
492 cFYI(1, "Session Setup");
493
494 if (ses->server)
495 server = ses->server;
496 else {
497 rc = -EIO;
498 return rc;
499 }
500
501 /*
502 * If memory allocation is successful, caller of this function
503 * frees it.
504 */
505 ses->ntlmssp = kmalloc(sizeof(struct ntlmssp_auth), GFP_KERNEL);
506 if (!ses->ntlmssp)
507 return -ENOMEM;
508
509 ses->server->secType = RawNTLMSSP;
510
511ssetup_ntlmssp_authenticate:
512 if (phase == NtLmChallenge)
513 phase = NtLmAuthenticate; /* if ntlmssp, now final phase */
514
515 rc = small_smb2_init(SMB2_SESSION_SETUP, NULL, (void **) &req);
516 if (rc)
517 return rc;
518
519 /* if any of auth flags (ie not sign or seal) are overriden use them */
520 if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL)))
521 sec_flags = ses->overrideSecFlg; /* BB FIXME fix sign flags?*/
522 else /* if override flags set only sign/seal OR them with global auth */
523 sec_flags = global_secflags | ses->overrideSecFlg;
524
525 cFYI(1, "sec_flags 0x%x", sec_flags);
526
527 req->hdr.SessionId = 0; /* First session, not a reauthenticate */
528 req->VcNumber = 0; /* MBZ */
529 /* to enable echos and oplocks */
530 req->hdr.CreditRequest = cpu_to_le16(3);
531
532 /* only one of SMB2 signing flags may be set in SMB2 request */
533 if ((sec_flags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN)
534 temp = SMB2_NEGOTIATE_SIGNING_REQUIRED;
535 else if (ses->server->sec_mode & SMB2_NEGOTIATE_SIGNING_REQUIRED)
536 temp = SMB2_NEGOTIATE_SIGNING_REQUIRED;
537 else if (sec_flags & CIFSSEC_MAY_SIGN) /* MAY_SIGN is a single flag */
538 temp = SMB2_NEGOTIATE_SIGNING_ENABLED;
539
540 req->SecurityMode = temp;
541 req->Capabilities = 0;
542 req->Channel = 0; /* MBZ */
543
544 iov[0].iov_base = (char *)req;
545 /* 4 for rfc1002 length field and 1 for pad */
546 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
547 if (phase == NtLmNegotiate) {
548 ntlmssp_blob = kmalloc(sizeof(struct _NEGOTIATE_MESSAGE),
549 GFP_KERNEL);
550 if (ntlmssp_blob == NULL) {
551 rc = -ENOMEM;
552 goto ssetup_exit;
553 }
554 build_ntlmssp_negotiate_blob(ntlmssp_blob, ses);
555 if (use_spnego) {
556 /* blob_length = build_spnego_ntlmssp_blob(
557 &security_blob,
558 sizeof(struct _NEGOTIATE_MESSAGE),
559 ntlmssp_blob); */
560 /* BB eventually need to add this */
561 cERROR(1, "spnego not supported for SMB2 yet");
562 rc = -EOPNOTSUPP;
563 kfree(ntlmssp_blob);
564 goto ssetup_exit;
565 } else {
566 blob_length = sizeof(struct _NEGOTIATE_MESSAGE);
567 /* with raw NTLMSSP we don't encapsulate in SPNEGO */
568 security_blob = ntlmssp_blob;
569 }
570 } else if (phase == NtLmAuthenticate) {
571 req->hdr.SessionId = ses->Suid;
572 ntlmssp_blob = kzalloc(sizeof(struct _NEGOTIATE_MESSAGE) + 500,
573 GFP_KERNEL);
574 if (ntlmssp_blob == NULL) {
575 cERROR(1, "failed to malloc ntlmssp blob");
576 rc = -ENOMEM;
577 goto ssetup_exit;
578 }
579 rc = build_ntlmssp_auth_blob(ntlmssp_blob, &blob_length, ses,
580 nls_cp);
581 if (rc) {
582 cFYI(1, "build_ntlmssp_auth_blob failed %d", rc);
583 goto ssetup_exit; /* BB double check error handling */
584 }
585 if (use_spnego) {
586 /* blob_length = build_spnego_ntlmssp_blob(
587 &security_blob,
588 blob_length,
589 ntlmssp_blob); */
590 cERROR(1, "spnego not supported for SMB2 yet");
591 rc = -EOPNOTSUPP;
592 kfree(ntlmssp_blob);
593 goto ssetup_exit;
594 } else {
595 security_blob = ntlmssp_blob;
596 }
597 } else {
598 cERROR(1, "illegal ntlmssp phase");
599 rc = -EIO;
600 goto ssetup_exit;
601 }
602
603 /* Testing shows that buffer offset must be at location of Buffer[0] */
604 req->SecurityBufferOffset =
605 cpu_to_le16(sizeof(struct smb2_sess_setup_req) -
606 1 /* pad */ - 4 /* rfc1001 len */);
607 req->SecurityBufferLength = cpu_to_le16(blob_length);
608 iov[1].iov_base = security_blob;
609 iov[1].iov_len = blob_length;
610
611 inc_rfc1001_len(req, blob_length - 1 /* pad */);
612
613 /* BB add code to build os and lm fields */
614
615 rc = SendReceive2(xid, ses, iov, 2, &resp_buftype,
616 CIFS_LOG_ERROR | CIFS_NEG_OP);
617
618 kfree(security_blob);
619 rsp = (struct smb2_sess_setup_rsp *)iov[0].iov_base;
620 if (resp_buftype != CIFS_NO_BUFFER &&
621 rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) {
622 if (phase != NtLmNegotiate) {
623 cERROR(1, "Unexpected more processing error");
624 goto ssetup_exit;
625 }
626 if (offsetof(struct smb2_sess_setup_rsp, Buffer) - 4 !=
627 le16_to_cpu(rsp->SecurityBufferOffset)) {
628 cERROR(1, "Invalid security buffer offset %d",
629 le16_to_cpu(rsp->SecurityBufferOffset));
630 rc = -EIO;
631 goto ssetup_exit;
632 }
633
634 /* NTLMSSP Negotiate sent now processing challenge (response) */
635 phase = NtLmChallenge; /* process ntlmssp challenge */
636 rc = 0; /* MORE_PROCESSING is not an error here but expected */
637 ses->Suid = rsp->hdr.SessionId;
638 rc = decode_ntlmssp_challenge(rsp->Buffer,
639 le16_to_cpu(rsp->SecurityBufferLength), ses);
640 }
641
642 /*
643 * BB eventually add code for SPNEGO decoding of NtlmChallenge blob,
644 * but at least the raw NTLMSSP case works.
645 */
646 /*
647 * No tcon so can't do
648 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
649 */
650 if (rc != 0)
651 goto ssetup_exit;
652
653 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
654ssetup_exit:
655 free_rsp_buf(resp_buftype, rsp);
656
657 /* if ntlmssp, and negotiate succeeded, proceed to authenticate phase */
658 if ((phase == NtLmChallenge) && (rc == 0))
659 goto ssetup_ntlmssp_authenticate;
660 return rc;
661}
662
663int
664SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
665{
666 struct smb2_logoff_req *req; /* response is also trivial struct */
667 int rc = 0;
668 struct TCP_Server_Info *server;
669
670 cFYI(1, "disconnect session %p", ses);
671
672 if (ses && (ses->server))
673 server = ses->server;
674 else
675 return -EIO;
676
677 rc = small_smb2_init(SMB2_LOGOFF, NULL, (void **) &req);
678 if (rc)
679 return rc;
680
681 /* since no tcon, smb2_init can not do this, so do here */
682 req->hdr.SessionId = ses->Suid;
683 if (server->sec_mode & SECMODE_SIGN_REQUIRED)
684 req->hdr.Flags |= SMB2_FLAGS_SIGNED;
685
686 rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0);
687 /*
688 * No tcon so can't do
689 * cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[SMB2...]);
690 */
691 return rc;
692}
693
694static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code)
695{
696 cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]);
697}
698
699#define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */)
700
701int
702SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
703 struct cifs_tcon *tcon, const struct nls_table *cp)
704{
705 struct smb2_tree_connect_req *req;
706 struct smb2_tree_connect_rsp *rsp = NULL;
707 struct kvec iov[2];
708 int rc = 0;
709 int resp_buftype;
710 int unc_path_len;
711 struct TCP_Server_Info *server;
712 __le16 *unc_path = NULL;
713
714 cFYI(1, "TCON");
715
716 if ((ses->server) && tree)
717 server = ses->server;
718 else
719 return -EIO;
720
721 if (tcon && tcon->bad_network_name)
722 return -ENOENT;
723
724 unc_path = kmalloc(MAX_SHARENAME_LENGTH * 2, GFP_KERNEL);
725 if (unc_path == NULL)
726 return -ENOMEM;
727
728 unc_path_len = cifs_strtoUTF16(unc_path, tree, strlen(tree), cp) + 1;
729 unc_path_len *= 2;
730 if (unc_path_len < 2) {
731 kfree(unc_path);
732 return -EINVAL;
733 }
734
735 rc = small_smb2_init(SMB2_TREE_CONNECT, tcon, (void **) &req);
736 if (rc) {
737 kfree(unc_path);
738 return rc;
739 }
740
741 if (tcon == NULL) {
742 /* since no tcon, smb2_init can not do this, so do here */
743 req->hdr.SessionId = ses->Suid;
744 /* if (ses->server->sec_mode & SECMODE_SIGN_REQUIRED)
745 req->hdr.Flags |= SMB2_FLAGS_SIGNED; */
746 }
747
748 iov[0].iov_base = (char *)req;
749 /* 4 for rfc1002 length field and 1 for pad */
750 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
751
752 /* Testing shows that buffer offset must be at location of Buffer[0] */
753 req->PathOffset = cpu_to_le16(sizeof(struct smb2_tree_connect_req)
754 - 1 /* pad */ - 4 /* do not count rfc1001 len field */);
755 req->PathLength = cpu_to_le16(unc_path_len - 2);
756 iov[1].iov_base = unc_path;
757 iov[1].iov_len = unc_path_len;
758
759 inc_rfc1001_len(req, unc_path_len - 1 /* pad */);
760
761 rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, 0);
762 rsp = (struct smb2_tree_connect_rsp *)iov[0].iov_base;
763
764 if (rc != 0) {
765 if (tcon) {
766 cifs_stats_fail_inc(tcon, SMB2_TREE_CONNECT_HE);
767 tcon->need_reconnect = true;
768 }
769 goto tcon_error_exit;
770 }
771
772 if (tcon == NULL) {
773 ses->ipc_tid = rsp->hdr.TreeId;
774 goto tcon_exit;
775 }
776
777 if (rsp->ShareType & SMB2_SHARE_TYPE_DISK)
778 cFYI(1, "connection to disk share");
779 else if (rsp->ShareType & SMB2_SHARE_TYPE_PIPE) {
780 tcon->ipc = true;
781 cFYI(1, "connection to pipe share");
782 } else if (rsp->ShareType & SMB2_SHARE_TYPE_PRINT) {
783 tcon->print = true;
784 cFYI(1, "connection to printer");
785 } else {
786 cERROR(1, "unknown share type %d", rsp->ShareType);
787 rc = -EOPNOTSUPP;
788 goto tcon_error_exit;
789 }
790
791 tcon->share_flags = le32_to_cpu(rsp->ShareFlags);
792 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess);
793 tcon->tidStatus = CifsGood;
794 tcon->need_reconnect = false;
795 tcon->tid = rsp->hdr.TreeId;
796 strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
797
798 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
799 ((tcon->share_flags & SHI1005_FLAGS_DFS) == 0))
800 cERROR(1, "DFS capability contradicts DFS flag");
801
802tcon_exit:
803 free_rsp_buf(resp_buftype, rsp);
804 kfree(unc_path);
805 return rc;
806
807tcon_error_exit:
808 if (rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) {
809 cERROR(1, "BAD_NETWORK_NAME: %s", tree);
810 tcon->bad_network_name = true;
811 }
812 goto tcon_exit;
813}
814
815int
816SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)
817{
818 struct smb2_tree_disconnect_req *req; /* response is trivial */
819 int rc = 0;
820 struct TCP_Server_Info *server;
821 struct cifs_ses *ses = tcon->ses;
822
823 cFYI(1, "Tree Disconnect");
824
825 if (ses && (ses->server))
826 server = ses->server;
827 else
828 return -EIO;
829
830 if ((tcon->need_reconnect) || (tcon->ses->need_reconnect))
831 return 0;
832
833 rc = small_smb2_init(SMB2_TREE_DISCONNECT, tcon, (void **) &req);
834 if (rc)
835 return rc;
836
837 rc = SendReceiveNoRsp(xid, ses, (char *)&req->hdr, 0);
838 if (rc)
839 cifs_stats_fail_inc(tcon, SMB2_TREE_DISCONNECT_HE);
840
841 return rc;
842}
843
844static struct create_lease *
845create_lease_buf(u8 *lease_key, u8 oplock)
846{
847 struct create_lease *buf;
848
849 buf = kmalloc(sizeof(struct create_lease), GFP_KERNEL);
850 if (!buf)
851 return NULL;
852
853 memset(buf, 0, sizeof(struct create_lease));
854
855 buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
856 buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
857 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
858 buf->lcontext.LeaseState = SMB2_LEASE_WRITE_CACHING |
859 SMB2_LEASE_READ_CACHING;
860 else if (oplock == SMB2_OPLOCK_LEVEL_II)
861 buf->lcontext.LeaseState = SMB2_LEASE_READ_CACHING;
862 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
863 buf->lcontext.LeaseState = SMB2_LEASE_HANDLE_CACHING |
864 SMB2_LEASE_READ_CACHING |
865 SMB2_LEASE_WRITE_CACHING;
866
867 buf->ccontext.DataOffset = cpu_to_le16(offsetof
868 (struct create_lease, lcontext));
869 buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
870 buf->ccontext.NameOffset = cpu_to_le16(offsetof
871 (struct create_lease, Name));
872 buf->ccontext.NameLength = cpu_to_le16(4);
873 buf->Name[0] = 'R';
874 buf->Name[1] = 'q';
875 buf->Name[2] = 'L';
876 buf->Name[3] = 's';
877 return buf;
878}
879
880static __u8
881parse_lease_state(struct smb2_create_rsp *rsp)
882{
883 char *data_offset;
884 struct create_lease *lc;
885 bool found = false;
886
887 data_offset = (char *)rsp;
888 data_offset += 4 + le32_to_cpu(rsp->CreateContextsOffset);
889 lc = (struct create_lease *)data_offset;
890 do {
891 char *name = le16_to_cpu(lc->ccontext.NameOffset) + (char *)lc;
892 if (le16_to_cpu(lc->ccontext.NameLength) != 4 ||
893 strncmp(name, "RqLs", 4)) {
894 lc = (struct create_lease *)((char *)lc
895 + le32_to_cpu(lc->ccontext.Next));
896 continue;
897 }
898 if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
899 return SMB2_OPLOCK_LEVEL_NOCHANGE;
900 found = true;
901 break;
902 } while (le32_to_cpu(lc->ccontext.Next) != 0);
903
904 if (!found)
905 return 0;
906
907 return smb2_map_lease_to_oplock(lc->lcontext.LeaseState);
908}
909
910int
911SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path,
912 u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access,
913 __u32 create_disposition, __u32 file_attributes, __u32 create_options,
914 __u8 *oplock, struct smb2_file_all_info *buf)
915{
916 struct smb2_create_req *req;
917 struct smb2_create_rsp *rsp;
918 struct TCP_Server_Info *server;
919 struct cifs_ses *ses = tcon->ses;
920 struct kvec iov[3];
921 int resp_buftype;
922 int uni_path_len;
923 __le16 *copy_path = NULL;
924 int copy_size;
925 int rc = 0;
926 int num_iovecs = 2;
927
928 cFYI(1, "create/open");
929
930 if (ses && (ses->server))
931 server = ses->server;
932 else
933 return -EIO;
934
935 rc = small_smb2_init(SMB2_CREATE, tcon, (void **) &req);
936 if (rc)
937 return rc;
938
939 req->ImpersonationLevel = IL_IMPERSONATION;
940 req->DesiredAccess = cpu_to_le32(desired_access);
941 /* File attributes ignored on open (used in create though) */
942 req->FileAttributes = cpu_to_le32(file_attributes);
943 req->ShareAccess = FILE_SHARE_ALL_LE;
944 req->CreateDisposition = cpu_to_le32(create_disposition);
945 req->CreateOptions = cpu_to_le32(create_options);
946 uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2;
947 req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)
948 - 8 /* pad */ - 4 /* do not count rfc1001 len field */);
949
950 iov[0].iov_base = (char *)req;
951 /* 4 for rfc1002 length field */
952 iov[0].iov_len = get_rfc1002_length(req) + 4;
953
954 /* MUST set path len (NameLength) to 0 opening root of share */
955 if (uni_path_len >= 4) {
956 req->NameLength = cpu_to_le16(uni_path_len - 2);
957 /* -1 since last byte is buf[0] which is sent below (path) */
958 iov[0].iov_len--;
959 if (uni_path_len % 8 != 0) {
960 copy_size = uni_path_len / 8 * 8;
961 if (copy_size < uni_path_len)
962 copy_size += 8;
963
964 copy_path = kzalloc(copy_size, GFP_KERNEL);
965 if (!copy_path)
966 return -ENOMEM;
967 memcpy((char *)copy_path, (const char *)path,
968 uni_path_len);
969 uni_path_len = copy_size;
970 path = copy_path;
971 }
972
973 iov[1].iov_len = uni_path_len;
974 iov[1].iov_base = path;
975 /*
976 * -1 since last byte is buf[0] which was counted in
977 * smb2_buf_len.
978 */
979 inc_rfc1001_len(req, uni_path_len - 1);
980 } else {
981 iov[0].iov_len += 7;
982 req->hdr.smb2_buf_length = cpu_to_be32(be32_to_cpu(
983 req->hdr.smb2_buf_length) + 8 - 1);
984 num_iovecs = 1;
985 req->NameLength = 0;
986 }
987
988 if (!server->oplocks)
989 *oplock = SMB2_OPLOCK_LEVEL_NONE;
990
991 if (!(tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) ||
992 *oplock == SMB2_OPLOCK_LEVEL_NONE)
993 req->RequestedOplockLevel = *oplock;
994 else {
995 iov[num_iovecs].iov_base = create_lease_buf(oplock+1, *oplock);
996 if (iov[num_iovecs].iov_base == NULL) {
997 cifs_small_buf_release(req);
998 kfree(copy_path);
999 return -ENOMEM;
1000 }
1001 iov[num_iovecs].iov_len = sizeof(struct create_lease);
1002 req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE;
1003 req->CreateContextsOffset = cpu_to_le32(
1004 sizeof(struct smb2_create_req) - 4 - 8 +
1005 iov[num_iovecs-1].iov_len);
1006 req->CreateContextsLength = cpu_to_le32(
1007 sizeof(struct create_lease));
1008 inc_rfc1001_len(&req->hdr, sizeof(struct create_lease));
1009 num_iovecs++;
1010 }
1011
1012 rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0);
1013 rsp = (struct smb2_create_rsp *)iov[0].iov_base;
1014
1015 if (rc != 0) {
1016 cifs_stats_fail_inc(tcon, SMB2_CREATE_HE);
1017 goto creat_exit;
1018 }
1019
1020 *persistent_fid = rsp->PersistentFileId;
1021 *volatile_fid = rsp->VolatileFileId;
1022
1023 if (buf) {
1024 memcpy(buf, &rsp->CreationTime, 32);
1025 buf->AllocationSize = rsp->AllocationSize;
1026 buf->EndOfFile = rsp->EndofFile;
1027 buf->Attributes = rsp->FileAttributes;
1028 buf->NumberOfLinks = cpu_to_le32(1);
1029 buf->DeletePending = 0;
1030 }
1031
1032 if (rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
1033 *oplock = parse_lease_state(rsp);
1034 else
1035 *oplock = rsp->OplockLevel;
1036creat_exit:
1037 kfree(copy_path);
1038 free_rsp_buf(resp_buftype, rsp);
1039 return rc;
1040}
1041
1042int
1043SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
1044 u64 persistent_fid, u64 volatile_fid)
1045{
1046 struct smb2_close_req *req;
1047 struct smb2_close_rsp *rsp;
1048 struct TCP_Server_Info *server;
1049 struct cifs_ses *ses = tcon->ses;
1050 struct kvec iov[1];
1051 int resp_buftype;
1052 int rc = 0;
1053
1054 cFYI(1, "Close");
1055
1056 if (ses && (ses->server))
1057 server = ses->server;
1058 else
1059 return -EIO;
1060
1061 rc = small_smb2_init(SMB2_CLOSE, tcon, (void **) &req);
1062 if (rc)
1063 return rc;
1064
1065 req->PersistentFileId = persistent_fid;
1066 req->VolatileFileId = volatile_fid;
1067
1068 iov[0].iov_base = (char *)req;
1069 /* 4 for rfc1002 length field */
1070 iov[0].iov_len = get_rfc1002_length(req) + 4;
1071
1072 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0);
1073 rsp = (struct smb2_close_rsp *)iov[0].iov_base;
1074
1075 if (rc != 0) {
1076 if (tcon)
1077 cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE);
1078 goto close_exit;
1079 }
1080
1081 /* BB FIXME - decode close response, update inode for caching */
1082
1083close_exit:
1084 free_rsp_buf(resp_buftype, rsp);
1085 return rc;
1086}
1087
1088static int
1089validate_buf(unsigned int offset, unsigned int buffer_length,
1090 struct smb2_hdr *hdr, unsigned int min_buf_size)
1091
1092{
1093 unsigned int smb_len = be32_to_cpu(hdr->smb2_buf_length);
1094 char *end_of_smb = smb_len + 4 /* RFC1001 length field */ + (char *)hdr;
1095 char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
1096 char *end_of_buf = begin_of_buf + buffer_length;
1097
1098
1099 if (buffer_length < min_buf_size) {
1100 cERROR(1, "buffer length %d smaller than minimum size %d",
1101 buffer_length, min_buf_size);
1102 return -EINVAL;
1103 }
1104
1105 /* check if beyond RFC1001 maximum length */
1106 if ((smb_len > 0x7FFFFF) || (buffer_length > 0x7FFFFF)) {
1107 cERROR(1, "buffer length %d or smb length %d too large",
1108 buffer_length, smb_len);
1109 return -EINVAL;
1110 }
1111
1112 if ((begin_of_buf > end_of_smb) || (end_of_buf > end_of_smb)) {
1113 cERROR(1, "illegal server response, bad offset to data");
1114 return -EINVAL;
1115 }
1116
1117 return 0;
1118}
1119
1120/*
1121 * If SMB buffer fields are valid, copy into temporary buffer to hold result.
1122 * Caller must free buffer.
1123 */
1124static int
1125validate_and_copy_buf(unsigned int offset, unsigned int buffer_length,
1126 struct smb2_hdr *hdr, unsigned int minbufsize,
1127 char *data)
1128
1129{
1130 char *begin_of_buf = 4 /* RFC1001 len field */ + offset + (char *)hdr;
1131 int rc;
1132
1133 if (!data)
1134 return -EINVAL;
1135
1136 rc = validate_buf(offset, buffer_length, hdr, minbufsize);
1137 if (rc)
1138 return rc;
1139
1140 memcpy(data, begin_of_buf, buffer_length);
1141
1142 return 0;
1143}
1144
1145static int
1146query_info(const unsigned int xid, struct cifs_tcon *tcon,
1147 u64 persistent_fid, u64 volatile_fid, u8 info_class,
1148 size_t output_len, size_t min_len, void *data)
1149{
1150 struct smb2_query_info_req *req;
1151 struct smb2_query_info_rsp *rsp = NULL;
1152 struct kvec iov[2];
1153 int rc = 0;
1154 int resp_buftype;
1155 struct TCP_Server_Info *server;
1156 struct cifs_ses *ses = tcon->ses;
1157
1158 cFYI(1, "Query Info");
1159
1160 if (ses && (ses->server))
1161 server = ses->server;
1162 else
1163 return -EIO;
1164
1165 rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req);
1166 if (rc)
1167 return rc;
1168
1169 req->InfoType = SMB2_O_INFO_FILE;
1170 req->FileInfoClass = info_class;
1171 req->PersistentFileId = persistent_fid;
1172 req->VolatileFileId = volatile_fid;
1173 /* 4 for rfc1002 length field and 1 for Buffer */
1174 req->InputBufferOffset =
1175 cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4);
1176 req->OutputBufferLength = cpu_to_le32(output_len);
1177
1178 iov[0].iov_base = (char *)req;
1179 /* 4 for rfc1002 length field */
1180 iov[0].iov_len = get_rfc1002_length(req) + 4;
1181
1182 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0);
1183 rsp = (struct smb2_query_info_rsp *)iov[0].iov_base;
1184
1185 if (rc) {
1186 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
1187 goto qinf_exit;
1188 }
1189
1190 rc = validate_and_copy_buf(le16_to_cpu(rsp->OutputBufferOffset),
1191 le32_to_cpu(rsp->OutputBufferLength),
1192 &rsp->hdr, min_len, data);
1193
1194qinf_exit:
1195 free_rsp_buf(resp_buftype, rsp);
1196 return rc;
1197}
1198
1199int
1200SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,
1201 u64 persistent_fid, u64 volatile_fid,
1202 struct smb2_file_all_info *data)
1203{
1204 return query_info(xid, tcon, persistent_fid, volatile_fid,
1205 FILE_ALL_INFORMATION,
1206 sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
1207 sizeof(struct smb2_file_all_info), data);
1208}
1209
1210int
1211SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
1212 u64 persistent_fid, u64 volatile_fid, __le64 *uniqueid)
1213{
1214 return query_info(xid, tcon, persistent_fid, volatile_fid,
1215 FILE_INTERNAL_INFORMATION,
1216 sizeof(struct smb2_file_internal_info),
1217 sizeof(struct smb2_file_internal_info), uniqueid);
1218}
1219
1220/*
1221 * This is a no-op for now. We're not really interested in the reply, but
1222 * rather in the fact that the server sent one and that server->lstrp
1223 * gets updated.
1224 *
1225 * FIXME: maybe we should consider checking that the reply matches request?
1226 */
1227static void
1228smb2_echo_callback(struct mid_q_entry *mid)
1229{
1230 struct TCP_Server_Info *server = mid->callback_data;
1231 struct smb2_echo_rsp *smb2 = (struct smb2_echo_rsp *)mid->resp_buf;
1232 unsigned int credits_received = 1;
1233
1234 if (mid->mid_state == MID_RESPONSE_RECEIVED)
1235 credits_received = le16_to_cpu(smb2->hdr.CreditRequest);
1236
1237 DeleteMidQEntry(mid);
1238 add_credits(server, credits_received, CIFS_ECHO_OP);
1239}
1240
1241int
1242SMB2_echo(struct TCP_Server_Info *server)
1243{
1244 struct smb2_echo_req *req;
1245 int rc = 0;
1246 struct kvec iov;
1247 struct smb_rqst rqst = { .rq_iov = &iov,
1248 .rq_nvec = 1 };
1249
1250 cFYI(1, "In echo request");
1251
1252 rc = small_smb2_init(SMB2_ECHO, NULL, (void **)&req);
1253 if (rc)
1254 return rc;
1255
1256 req->hdr.CreditRequest = cpu_to_le16(1);
1257
1258 iov.iov_base = (char *)req;
1259 /* 4 for rfc1002 length field */
1260 iov.iov_len = get_rfc1002_length(req) + 4;
1261
1262 rc = cifs_call_async(server, &rqst, NULL, smb2_echo_callback, server,
1263 CIFS_ECHO_OP);
1264 if (rc)
1265 cFYI(1, "Echo request failed: %d", rc);
1266
1267 cifs_small_buf_release(req);
1268 return rc;
1269}
1270
1271int
1272SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1273 u64 volatile_fid)
1274{
1275 struct smb2_flush_req *req;
1276 struct TCP_Server_Info *server;
1277 struct cifs_ses *ses = tcon->ses;
1278 struct kvec iov[1];
1279 int resp_buftype;
1280 int rc = 0;
1281
1282 cFYI(1, "Flush");
1283
1284 if (ses && (ses->server))
1285 server = ses->server;
1286 else
1287 return -EIO;
1288
1289 rc = small_smb2_init(SMB2_FLUSH, tcon, (void **) &req);
1290 if (rc)
1291 return rc;
1292
1293 req->PersistentFileId = persistent_fid;
1294 req->VolatileFileId = volatile_fid;
1295
1296 iov[0].iov_base = (char *)req;
1297 /* 4 for rfc1002 length field */
1298 iov[0].iov_len = get_rfc1002_length(req) + 4;
1299
1300 rc = SendReceive2(xid, ses, iov, 1, &resp_buftype, 0);
1301
1302 if ((rc != 0) && tcon)
1303 cifs_stats_fail_inc(tcon, SMB2_FLUSH_HE);
1304
1305 free_rsp_buf(resp_buftype, iov[0].iov_base);
1306 return rc;
1307}
1308
1309/*
1310 * To form a chain of read requests, any read requests after the first should
1311 * have the end_of_chain boolean set to true.
1312 */
1313static int
1314smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
1315 unsigned int remaining_bytes, int request_type)
1316{
1317 int rc = -EACCES;
1318 struct smb2_read_req *req = NULL;
1319
1320 rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req);
1321 if (rc)
1322 return rc;
1323 if (io_parms->tcon->ses->server == NULL)
1324 return -ECONNABORTED;
1325
1326 req->hdr.ProcessId = cpu_to_le32(io_parms->pid);
1327
1328 req->PersistentFileId = io_parms->persistent_fid;
1329 req->VolatileFileId = io_parms->volatile_fid;
1330 req->ReadChannelInfoOffset = 0; /* reserved */
1331 req->ReadChannelInfoLength = 0; /* reserved */
1332 req->Channel = 0; /* reserved */
1333 req->MinimumCount = 0;
1334 req->Length = cpu_to_le32(io_parms->length);
1335 req->Offset = cpu_to_le64(io_parms->offset);
1336
1337 if (request_type & CHAINED_REQUEST) {
1338 if (!(request_type & END_OF_CHAIN)) {
1339 /* 4 for rfc1002 length field */
1340 req->hdr.NextCommand =
1341 cpu_to_le32(get_rfc1002_length(req) + 4);
1342 } else /* END_OF_CHAIN */
1343 req->hdr.NextCommand = 0;
1344 if (request_type & RELATED_REQUEST) {
1345 req->hdr.Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
1346 /*
1347 * Related requests use info from previous read request
1348 * in chain.
1349 */
1350 req->hdr.SessionId = 0xFFFFFFFF;
1351 req->hdr.TreeId = 0xFFFFFFFF;
1352 req->PersistentFileId = 0xFFFFFFFF;
1353 req->VolatileFileId = 0xFFFFFFFF;
1354 }
1355 }
1356 if (remaining_bytes > io_parms->length)
1357 req->RemainingBytes = cpu_to_le32(remaining_bytes);
1358 else
1359 req->RemainingBytes = 0;
1360
1361 iov[0].iov_base = (char *)req;
1362 /* 4 for rfc1002 length field */
1363 iov[0].iov_len = get_rfc1002_length(req) + 4;
1364 return rc;
1365}
1366
1367static void
1368smb2_readv_callback(struct mid_q_entry *mid)
1369{
1370 struct cifs_readdata *rdata = mid->callback_data;
1371 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
1372 struct TCP_Server_Info *server = tcon->ses->server;
1373 struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base;
1374 unsigned int credits_received = 1;
1375 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
1376 .rq_nvec = 1,
1377 .rq_pages = rdata->pages,
1378 .rq_npages = rdata->nr_pages,
1379 .rq_pagesz = rdata->pagesz,
1380 .rq_tailsz = rdata->tailsz };
1381
1382 cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__,
1383 mid->mid, mid->mid_state, rdata->result, rdata->bytes);
1384
1385 switch (mid->mid_state) {
1386 case MID_RESPONSE_RECEIVED:
1387 credits_received = le16_to_cpu(buf->CreditRequest);
1388 /* result already set, check signature */
1389 if (server->sec_mode &
1390 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
1391 int rc;
1392
1393 rc = smb2_verify_signature(&rqst, server);
1394 if (rc)
1395 cERROR(1, "SMB signature verification returned "
1396 "error = %d", rc);
1397 }
1398 /* FIXME: should this be counted toward the initiating task? */
1399 task_io_account_read(rdata->bytes);
1400 cifs_stats_bytes_read(tcon, rdata->bytes);
1401 break;
1402 case MID_REQUEST_SUBMITTED:
1403 case MID_RETRY_NEEDED:
1404 rdata->result = -EAGAIN;
1405 break;
1406 default:
1407 if (rdata->result != -ENODATA)
1408 rdata->result = -EIO;
1409 }
1410
1411 if (rdata->result)
1412 cifs_stats_fail_inc(tcon, SMB2_READ_HE);
1413
1414 queue_work(cifsiod_wq, &rdata->work);
1415 DeleteMidQEntry(mid);
1416 add_credits(server, credits_received, 0);
1417}
1418
1419/* smb2_async_readv - send an async write, and set up mid to handle result */
1420int
1421smb2_async_readv(struct cifs_readdata *rdata)
1422{
1423 int rc;
1424 struct smb2_hdr *buf;
1425 struct cifs_io_parms io_parms;
1426 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
1427 .rq_nvec = 1 };
1428
1429 cFYI(1, "%s: offset=%llu bytes=%u", __func__,
1430 rdata->offset, rdata->bytes);
1431
1432 io_parms.tcon = tlink_tcon(rdata->cfile->tlink);
1433 io_parms.offset = rdata->offset;
1434 io_parms.length = rdata->bytes;
1435 io_parms.persistent_fid = rdata->cfile->fid.persistent_fid;
1436 io_parms.volatile_fid = rdata->cfile->fid.volatile_fid;
1437 io_parms.pid = rdata->pid;
1438 rc = smb2_new_read_req(&rdata->iov, &io_parms, 0, 0);
1439 if (rc)
1440 return rc;
1441
1442 buf = (struct smb2_hdr *)rdata->iov.iov_base;
1443 /* 4 for rfc1002 length field */
1444 rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4;
1445
1446 kref_get(&rdata->refcount);
1447 rc = cifs_call_async(io_parms.tcon->ses->server, &rqst,
1448 cifs_readv_receive, smb2_readv_callback,
1449 rdata, 0);
1450 if (rc) {
1451 kref_put(&rdata->refcount, cifs_readdata_release);
1452 cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE);
1453 }
1454
1455 cifs_small_buf_release(buf);
1456 return rc;
1457}
1458
1459int
1460SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
1461 unsigned int *nbytes, char **buf, int *buf_type)
1462{
1463 int resp_buftype, rc = -EACCES;
1464 struct smb2_read_rsp *rsp = NULL;
1465 struct kvec iov[1];
1466
1467 *nbytes = 0;
1468 rc = smb2_new_read_req(iov, io_parms, 0, 0);
1469 if (rc)
1470 return rc;
1471
1472 rc = SendReceive2(xid, io_parms->tcon->ses, iov, 1,
1473 &resp_buftype, CIFS_LOG_ERROR);
1474
1475 rsp = (struct smb2_read_rsp *)iov[0].iov_base;
1476
1477 if (rsp->hdr.Status == STATUS_END_OF_FILE) {
1478 free_rsp_buf(resp_buftype, iov[0].iov_base);
1479 return 0;
1480 }
1481
1482 if (rc) {
1483 cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE);
1484 cERROR(1, "Send error in read = %d", rc);
1485 } else {
1486 *nbytes = le32_to_cpu(rsp->DataLength);
1487 if ((*nbytes > CIFS_MAX_MSGSIZE) ||
1488 (*nbytes > io_parms->length)) {
1489 cFYI(1, "bad length %d for count %d", *nbytes,
1490 io_parms->length);
1491 rc = -EIO;
1492 *nbytes = 0;
1493 }
1494 }
1495
1496 if (*buf) {
1497 memcpy(*buf, (char *)rsp->hdr.ProtocolId + rsp->DataOffset,
1498 *nbytes);
1499 free_rsp_buf(resp_buftype, iov[0].iov_base);
1500 } else if (resp_buftype != CIFS_NO_BUFFER) {
1501 *buf = iov[0].iov_base;
1502 if (resp_buftype == CIFS_SMALL_BUFFER)
1503 *buf_type = CIFS_SMALL_BUFFER;
1504 else if (resp_buftype == CIFS_LARGE_BUFFER)
1505 *buf_type = CIFS_LARGE_BUFFER;
1506 }
1507 return rc;
1508}
1509
1510/*
1511 * Check the mid_state and signature on received buffer (if any), and queue the
1512 * workqueue completion task.
1513 */
1514static void
1515smb2_writev_callback(struct mid_q_entry *mid)
1516{
1517 struct cifs_writedata *wdata = mid->callback_data;
1518 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
1519 unsigned int written;
1520 struct smb2_write_rsp *rsp = (struct smb2_write_rsp *)mid->resp_buf;
1521 unsigned int credits_received = 1;
1522
1523 switch (mid->mid_state) {
1524 case MID_RESPONSE_RECEIVED:
1525 credits_received = le16_to_cpu(rsp->hdr.CreditRequest);
1526 wdata->result = smb2_check_receive(mid, tcon->ses->server, 0);
1527 if (wdata->result != 0)
1528 break;
1529
1530 written = le32_to_cpu(rsp->DataLength);
1531 /*
1532 * Mask off high 16 bits when bytes written as returned
1533 * by the server is greater than bytes requested by the
1534 * client. OS/2 servers are known to set incorrect
1535 * CountHigh values.
1536 */
1537 if (written > wdata->bytes)
1538 written &= 0xFFFF;
1539
1540 if (written < wdata->bytes)
1541 wdata->result = -ENOSPC;
1542 else
1543 wdata->bytes = written;
1544 break;
1545 case MID_REQUEST_SUBMITTED:
1546 case MID_RETRY_NEEDED:
1547 wdata->result = -EAGAIN;
1548 break;
1549 default:
1550 wdata->result = -EIO;
1551 break;
1552 }
1553
1554 if (wdata->result)
1555 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
1556
1557 queue_work(cifsiod_wq, &wdata->work);
1558 DeleteMidQEntry(mid);
1559 add_credits(tcon->ses->server, credits_received, 0);
1560}
1561
1562/* smb2_async_writev - send an async write, and set up mid to handle result */
1563int
1564smb2_async_writev(struct cifs_writedata *wdata)
1565{
1566 int rc = -EACCES;
1567 struct smb2_write_req *req = NULL;
1568 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
1569 struct kvec iov;
1570 struct smb_rqst rqst;
1571
1572 rc = small_smb2_init(SMB2_WRITE, tcon, (void **) &req);
1573 if (rc)
1574 goto async_writev_out;
1575
1576 req->hdr.ProcessId = cpu_to_le32(wdata->cfile->pid);
1577
1578 req->PersistentFileId = wdata->cfile->fid.persistent_fid;
1579 req->VolatileFileId = wdata->cfile->fid.volatile_fid;
1580 req->WriteChannelInfoOffset = 0;
1581 req->WriteChannelInfoLength = 0;
1582 req->Channel = 0;
1583 req->Offset = cpu_to_le64(wdata->offset);
1584 /* 4 for rfc1002 length field */
1585 req->DataOffset = cpu_to_le16(
1586 offsetof(struct smb2_write_req, Buffer) - 4);
1587 req->RemainingBytes = 0;
1588
1589 /* 4 for rfc1002 length field and 1 for Buffer */
1590 iov.iov_len = get_rfc1002_length(req) + 4 - 1;
1591 iov.iov_base = req;
1592
1593 rqst.rq_iov = &iov;
1594 rqst.rq_nvec = 1;
1595 rqst.rq_pages = wdata->pages;
1596 rqst.rq_npages = wdata->nr_pages;
1597 rqst.rq_pagesz = wdata->pagesz;
1598 rqst.rq_tailsz = wdata->tailsz;
1599
1600 cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes);
1601
1602 req->Length = cpu_to_le32(wdata->bytes);
1603
1604 inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */);
1605
1606 kref_get(&wdata->refcount);
1607 rc = cifs_call_async(tcon->ses->server, &rqst, NULL,
1608 smb2_writev_callback, wdata, 0);
1609
1610 if (rc) {
1611 kref_put(&wdata->refcount, cifs_writedata_release);
1612 cifs_stats_fail_inc(tcon, SMB2_WRITE_HE);
1613 }
1614
1615async_writev_out:
1616 cifs_small_buf_release(req);
1617 return rc;
1618}
1619
1620/*
1621 * SMB2_write function gets iov pointer to kvec array with n_vec as a length.
1622 * The length field from io_parms must be at least 1 and indicates a number of
1623 * elements with data to write that begins with position 1 in iov array. All
1624 * data length is specified by count.
1625 */
1626int
1627SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
1628 unsigned int *nbytes, struct kvec *iov, int n_vec)
1629{
1630 int rc = 0;
1631 struct smb2_write_req *req = NULL;
1632 struct smb2_write_rsp *rsp = NULL;
1633 int resp_buftype;
1634 *nbytes = 0;
1635
1636 if (n_vec < 1)
1637 return rc;
1638
1639 rc = small_smb2_init(SMB2_WRITE, io_parms->tcon, (void **) &req);
1640 if (rc)
1641 return rc;
1642
1643 if (io_parms->tcon->ses->server == NULL)
1644 return -ECONNABORTED;
1645
1646 req->hdr.ProcessId = cpu_to_le32(io_parms->pid);
1647
1648 req->PersistentFileId = io_parms->persistent_fid;
1649 req->VolatileFileId = io_parms->volatile_fid;
1650 req->WriteChannelInfoOffset = 0;
1651 req->WriteChannelInfoLength = 0;
1652 req->Channel = 0;
1653 req->Length = cpu_to_le32(io_parms->length);
1654 req->Offset = cpu_to_le64(io_parms->offset);
1655 /* 4 for rfc1002 length field */
1656 req->DataOffset = cpu_to_le16(
1657 offsetof(struct smb2_write_req, Buffer) - 4);
1658 req->RemainingBytes = 0;
1659
1660 iov[0].iov_base = (char *)req;
1661 /* 4 for rfc1002 length field and 1 for Buffer */
1662 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
1663
1664 /* length of entire message including data to be written */
1665 inc_rfc1001_len(req, io_parms->length - 1 /* Buffer */);
1666
1667 rc = SendReceive2(xid, io_parms->tcon->ses, iov, n_vec + 1,
1668 &resp_buftype, 0);
1669 rsp = (struct smb2_write_rsp *)iov[0].iov_base;
1670
1671 if (rc) {
1672 cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE);
1673 cERROR(1, "Send error in write = %d", rc);
1674 } else
1675 *nbytes = le32_to_cpu(rsp->DataLength);
1676
1677 free_rsp_buf(resp_buftype, rsp);
1678 return rc;
1679}
1680
1681static unsigned int
1682num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size)
1683{
1684 int len;
1685 unsigned int entrycount = 0;
1686 unsigned int next_offset = 0;
1687 FILE_DIRECTORY_INFO *entryptr;
1688
1689 if (bufstart == NULL)
1690 return 0;
1691
1692 entryptr = (FILE_DIRECTORY_INFO *)bufstart;
1693
1694 while (1) {
1695 entryptr = (FILE_DIRECTORY_INFO *)
1696 ((char *)entryptr + next_offset);
1697
1698 if ((char *)entryptr + size > end_of_buf) {
1699 cERROR(1, "malformed search entry would overflow");
1700 break;
1701 }
1702
1703 len = le32_to_cpu(entryptr->FileNameLength);
1704 if ((char *)entryptr + len + size > end_of_buf) {
1705 cERROR(1, "directory entry name would overflow frame "
1706 "end of buf %p", end_of_buf);
1707 break;
1708 }
1709
1710 *lastentry = (char *)entryptr;
1711 entrycount++;
1712
1713 next_offset = le32_to_cpu(entryptr->NextEntryOffset);
1714 if (!next_offset)
1715 break;
1716 }
1717
1718 return entrycount;
1719}
1720
1721/*
1722 * Readdir/FindFirst
1723 */
1724int
1725SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
1726 u64 persistent_fid, u64 volatile_fid, int index,
1727 struct cifs_search_info *srch_inf)
1728{
1729 struct smb2_query_directory_req *req;
1730 struct smb2_query_directory_rsp *rsp = NULL;
1731 struct kvec iov[2];
1732 int rc = 0;
1733 int len;
1734 int resp_buftype;
1735 unsigned char *bufptr;
1736 struct TCP_Server_Info *server;
1737 struct cifs_ses *ses = tcon->ses;
1738 __le16 asteriks = cpu_to_le16('*');
1739 char *end_of_smb;
1740 unsigned int output_size = CIFSMaxBufSize;
1741 size_t info_buf_size;
1742
1743 if (ses && (ses->server))
1744 server = ses->server;
1745 else
1746 return -EIO;
1747
1748 rc = small_smb2_init(SMB2_QUERY_DIRECTORY, tcon, (void **) &req);
1749 if (rc)
1750 return rc;
1751
1752 switch (srch_inf->info_level) {
1753 case SMB_FIND_FILE_DIRECTORY_INFO:
1754 req->FileInformationClass = FILE_DIRECTORY_INFORMATION;
1755 info_buf_size = sizeof(FILE_DIRECTORY_INFO) - 1;
1756 break;
1757 case SMB_FIND_FILE_ID_FULL_DIR_INFO:
1758 req->FileInformationClass = FILEID_FULL_DIRECTORY_INFORMATION;
1759 info_buf_size = sizeof(SEARCH_ID_FULL_DIR_INFO) - 1;
1760 break;
1761 default:
1762 cERROR(1, "info level %u isn't supported",
1763 srch_inf->info_level);
1764 rc = -EINVAL;
1765 goto qdir_exit;
1766 }
1767
1768 req->FileIndex = cpu_to_le32(index);
1769 req->PersistentFileId = persistent_fid;
1770 req->VolatileFileId = volatile_fid;
1771
1772 len = 0x2;
1773 bufptr = req->Buffer;
1774 memcpy(bufptr, &asteriks, len);
1775
1776 req->FileNameOffset =
1777 cpu_to_le16(sizeof(struct smb2_query_directory_req) - 1 - 4);
1778 req->FileNameLength = cpu_to_le16(len);
1779 /*
1780 * BB could be 30 bytes or so longer if we used SMB2 specific
1781 * buffer lengths, but this is safe and close enough.
1782 */
1783 output_size = min_t(unsigned int, output_size, server->maxBuf);
1784 output_size = min_t(unsigned int, output_size, 2 << 15);
1785 req->OutputBufferLength = cpu_to_le32(output_size);
1786
1787 iov[0].iov_base = (char *)req;
1788 /* 4 for RFC1001 length and 1 for Buffer */
1789 iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
1790
1791 iov[1].iov_base = (char *)(req->Buffer);
1792 iov[1].iov_len = len;
1793
1794 inc_rfc1001_len(req, len - 1 /* Buffer */);
1795
1796 rc = SendReceive2(xid, ses, iov, 2, &resp_buftype, 0);
1797 rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base;
1798
1799 if (rc) {
1800 cifs_stats_fail_inc(tcon, SMB2_QUERY_DIRECTORY_HE);
1801 goto qdir_exit;
1802 }
1803
1804 rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
1805 le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
1806 info_buf_size);
1807 if (rc)
1808 goto qdir_exit;
1809
1810 srch_inf->unicode = true;
1811
1812 if (srch_inf->ntwrk_buf_start) {
1813 if (srch_inf->smallBuf)
1814 cifs_small_buf_release(srch_inf->ntwrk_buf_start);
1815 else
1816 cifs_buf_release(srch_inf->ntwrk_buf_start);
1817 }
1818 srch_inf->ntwrk_buf_start = (char *)rsp;
1819 srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ +
1820 (char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset);
1821 /* 4 for rfc1002 length field */
1822 end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr;
1823 srch_inf->entries_in_buffer =
1824 num_entries(srch_inf->srch_entries_start, end_of_smb,
1825 &srch_inf->last_entry, info_buf_size);
1826 srch_inf->index_of_last_entry += srch_inf->entries_in_buffer;
1827 cFYI(1, "num entries %d last_index %lld srch start %p srch end %p",
1828 srch_inf->entries_in_buffer, srch_inf->index_of_last_entry,
1829 srch_inf->srch_entries_start, srch_inf->last_entry);
1830 if (resp_buftype == CIFS_LARGE_BUFFER)
1831 srch_inf->smallBuf = false;
1832 else if (resp_buftype == CIFS_SMALL_BUFFER)
1833 srch_inf->smallBuf = true;
1834 else
1835 cERROR(1, "illegal search buffer type");
1836
1837 if (rsp->hdr.Status == STATUS_NO_MORE_FILES)
1838 srch_inf->endOfSearch = 1;
1839 else
1840 srch_inf->endOfSearch = 0;
1841
1842 return rc;
1843
1844qdir_exit:
1845 free_rsp_buf(resp_buftype, rsp);
1846 return rc;
1847}
1848
1849static int
1850send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
1851 u64 persistent_fid, u64 volatile_fid, u32 pid, int info_class,
1852 unsigned int num, void **data, unsigned int *size)
1853{
1854 struct smb2_set_info_req *req;
1855 struct smb2_set_info_rsp *rsp = NULL;
1856 struct kvec *iov;
1857 int rc = 0;
1858 int resp_buftype;
1859 unsigned int i;
1860 struct TCP_Server_Info *server;
1861 struct cifs_ses *ses = tcon->ses;
1862
1863 if (ses && (ses->server))
1864 server = ses->server;
1865 else
1866 return -EIO;
1867
1868 if (!num)
1869 return -EINVAL;
1870
1871 iov = kmalloc(sizeof(struct kvec) * num, GFP_KERNEL);
1872 if (!iov)
1873 return -ENOMEM;
1874
1875 rc = small_smb2_init(SMB2_SET_INFO, tcon, (void **) &req);
1876 if (rc) {
1877 kfree(iov);
1878 return rc;
1879 }
1880
1881 req->hdr.ProcessId = cpu_to_le32(pid);
1882
1883 req->InfoType = SMB2_O_INFO_FILE;
1884 req->FileInfoClass = info_class;
1885 req->PersistentFileId = persistent_fid;
1886 req->VolatileFileId = volatile_fid;
1887
1888 /* 4 for RFC1001 length and 1 for Buffer */
1889 req->BufferOffset =
1890 cpu_to_le16(sizeof(struct smb2_set_info_req) - 1 - 4);
1891 req->BufferLength = cpu_to_le32(*size);
1892
1893 inc_rfc1001_len(req, *size - 1 /* Buffer */);
1894
1895 memcpy(req->Buffer, *data, *size);
1896
1897 iov[0].iov_base = (char *)req;
1898 /* 4 for RFC1001 length */
1899 iov[0].iov_len = get_rfc1002_length(req) + 4;
1900
1901 for (i = 1; i < num; i++) {
1902 inc_rfc1001_len(req, size[i]);
1903 le32_add_cpu(&req->BufferLength, size[i]);
1904 iov[i].iov_base = (char *)data[i];
1905 iov[i].iov_len = size[i];
1906 }
1907
1908 rc = SendReceive2(xid, ses, iov, num, &resp_buftype, 0);
1909 rsp = (struct smb2_set_info_rsp *)iov[0].iov_base;
1910
1911 if (rc != 0) {
1912 cifs_stats_fail_inc(tcon, SMB2_SET_INFO_HE);
1913 goto out;
1914 }
1915out:
1916 free_rsp_buf(resp_buftype, rsp);
1917 kfree(iov);
1918 return rc;
1919}
1920
1921int
1922SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
1923 u64 persistent_fid, u64 volatile_fid, __le16 *target_file)
1924{
1925 struct smb2_file_rename_info info;
1926 void **data;
1927 unsigned int size[2];
1928 int rc;
1929 int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
1930
1931 data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
1932 if (!data)
1933 return -ENOMEM;
1934
1935 info.ReplaceIfExists = 1; /* 1 = replace existing target with new */
1936 /* 0 = fail if target already exists */
1937 info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */
1938 info.FileNameLength = cpu_to_le32(len);
1939
1940 data[0] = &info;
1941 size[0] = sizeof(struct smb2_file_rename_info);
1942
1943 data[1] = target_file;
1944 size[1] = len + 2 /* null */;
1945
1946 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
1947 current->tgid, FILE_RENAME_INFORMATION, 2, data,
1948 size);
1949 kfree(data);
1950 return rc;
1951}
1952
1953int
1954SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
1955 u64 persistent_fid, u64 volatile_fid, __le16 *target_file)
1956{
1957 struct smb2_file_link_info info;
1958 void **data;
1959 unsigned int size[2];
1960 int rc;
1961 int len = (2 * UniStrnlen((wchar_t *)target_file, PATH_MAX));
1962
1963 data = kmalloc(sizeof(void *) * 2, GFP_KERNEL);
1964 if (!data)
1965 return -ENOMEM;
1966
1967 info.ReplaceIfExists = 0; /* 1 = replace existing link with new */
1968 /* 0 = fail if link already exists */
1969 info.RootDirectory = 0; /* MBZ for network ops (why does spec say?) */
1970 info.FileNameLength = cpu_to_le32(len);
1971
1972 data[0] = &info;
1973 size[0] = sizeof(struct smb2_file_link_info);
1974
1975 data[1] = target_file;
1976 size[1] = len + 2 /* null */;
1977
1978 rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
1979 current->tgid, FILE_LINK_INFORMATION, 2, data, size);
1980 kfree(data);
1981 return rc;
1982}
1983
1984int
1985SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1986 u64 volatile_fid, u32 pid, __le64 *eof)
1987{
1988 struct smb2_file_eof_info info;
1989 void *data;
1990 unsigned int size;
1991
1992 info.EndOfFile = *eof;
1993
1994 data = &info;
1995 size = sizeof(struct smb2_file_eof_info);
1996
1997 return send_set_info(xid, tcon, persistent_fid, volatile_fid, pid,
1998 FILE_END_OF_FILE_INFORMATION, 1, &data, &size);
1999}
2000
2001int
2002SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon,
2003 u64 persistent_fid, u64 volatile_fid, FILE_BASIC_INFO *buf)
2004{
2005 unsigned int size;
2006 size = sizeof(FILE_BASIC_INFO);
2007 return send_set_info(xid, tcon, persistent_fid, volatile_fid,
2008 current->tgid, FILE_BASIC_INFORMATION, 1,
2009 (void **)&buf, &size);
2010}
2011
2012int
2013SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
2014 const u64 persistent_fid, const u64 volatile_fid,
2015 __u8 oplock_level)
2016{
2017 int rc;
2018 struct smb2_oplock_break *req = NULL;
2019
2020 cFYI(1, "SMB2_oplock_break");
2021 rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req);
2022
2023 if (rc)
2024 return rc;
2025
2026 req->VolatileFid = volatile_fid;
2027 req->PersistentFid = persistent_fid;
2028 req->OplockLevel = oplock_level;
2029 req->hdr.CreditRequest = cpu_to_le16(1);
2030
2031 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP);
2032 /* SMB2 buffer freed by function above */
2033
2034 if (rc) {
2035 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
2036 cFYI(1, "Send error in Oplock Break = %d", rc);
2037 }
2038
2039 return rc;
2040}
2041
2042static void
2043copy_fs_info_to_kstatfs(struct smb2_fs_full_size_info *pfs_inf,
2044 struct kstatfs *kst)
2045{
2046 kst->f_bsize = le32_to_cpu(pfs_inf->BytesPerSector) *
2047 le32_to_cpu(pfs_inf->SectorsPerAllocationUnit);
2048 kst->f_blocks = le64_to_cpu(pfs_inf->TotalAllocationUnits);
2049 kst->f_bfree = le64_to_cpu(pfs_inf->ActualAvailableAllocationUnits);
2050 kst->f_bavail = le64_to_cpu(pfs_inf->CallerAvailableAllocationUnits);
2051 return;
2052}
2053
2054static int
2055build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon, int level,
2056 int outbuf_len, u64 persistent_fid, u64 volatile_fid)
2057{
2058 int rc;
2059 struct smb2_query_info_req *req;
2060
2061 cFYI(1, "Query FSInfo level %d", level);
2062
2063 if ((tcon->ses == NULL) || (tcon->ses->server == NULL))
2064 return -EIO;
2065
2066 rc = small_smb2_init(SMB2_QUERY_INFO, tcon, (void **) &req);
2067 if (rc)
2068 return rc;
2069
2070 req->InfoType = SMB2_O_INFO_FILESYSTEM;
2071 req->FileInfoClass = level;
2072 req->PersistentFileId = persistent_fid;
2073 req->VolatileFileId = volatile_fid;
2074 /* 4 for rfc1002 length field and 1 for pad */
2075 req->InputBufferOffset =
2076 cpu_to_le16(sizeof(struct smb2_query_info_req) - 1 - 4);
2077 req->OutputBufferLength = cpu_to_le32(
2078 outbuf_len + sizeof(struct smb2_query_info_rsp) - 1 - 4);
2079
2080 iov->iov_base = (char *)req;
2081 /* 4 for rfc1002 length field */
2082 iov->iov_len = get_rfc1002_length(req) + 4;
2083 return 0;
2084}
2085
2086int
2087SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
2088 u64 persistent_fid, u64 volatile_fid, struct kstatfs *fsdata)
2089{
2090 struct smb2_query_info_rsp *rsp = NULL;
2091 struct kvec iov;
2092 int rc = 0;
2093 int resp_buftype;
2094 struct cifs_ses *ses = tcon->ses;
2095 struct smb2_fs_full_size_info *info = NULL;
2096
2097 rc = build_qfs_info_req(&iov, tcon, FS_FULL_SIZE_INFORMATION,
2098 sizeof(struct smb2_fs_full_size_info),
2099 persistent_fid, volatile_fid);
2100 if (rc)
2101 return rc;
2102
2103 rc = SendReceive2(xid, ses, &iov, 1, &resp_buftype, 0);
2104 if (rc) {
2105 cifs_stats_fail_inc(tcon, SMB2_QUERY_INFO_HE);
2106 goto qinf_exit;
2107 }
2108 rsp = (struct smb2_query_info_rsp *)iov.iov_base;
2109
2110 info = (struct smb2_fs_full_size_info *)(4 /* RFC1001 len */ +
2111 le16_to_cpu(rsp->OutputBufferOffset) + (char *)&rsp->hdr);
2112 rc = validate_buf(le16_to_cpu(rsp->OutputBufferOffset),
2113 le32_to_cpu(rsp->OutputBufferLength), &rsp->hdr,
2114 sizeof(struct smb2_fs_full_size_info));
2115 if (!rc)
2116 copy_fs_info_to_kstatfs(info, fsdata);
2117
2118qinf_exit:
2119 free_rsp_buf(resp_buftype, iov.iov_base);
2120 return rc;
2121}
2122
2123int
2124smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
2125 const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid,
2126 const __u32 num_lock, struct smb2_lock_element *buf)
2127{
2128 int rc = 0;
2129 struct smb2_lock_req *req = NULL;
2130 struct kvec iov[2];
2131 int resp_buf_type;
2132 unsigned int count;
2133
2134 cFYI(1, "smb2_lockv num lock %d", num_lock);
2135
2136 rc = small_smb2_init(SMB2_LOCK, tcon, (void **) &req);
2137 if (rc)
2138 return rc;
2139
2140 req->hdr.ProcessId = cpu_to_le32(pid);
2141 req->LockCount = cpu_to_le16(num_lock);
2142
2143 req->PersistentFileId = persist_fid;
2144 req->VolatileFileId = volatile_fid;
2145
2146 count = num_lock * sizeof(struct smb2_lock_element);
2147 inc_rfc1001_len(req, count - sizeof(struct smb2_lock_element));
2148
2149 iov[0].iov_base = (char *)req;
2150 /* 4 for rfc1002 length field and count for all locks */
2151 iov[0].iov_len = get_rfc1002_length(req) + 4 - count;
2152 iov[1].iov_base = (char *)buf;
2153 iov[1].iov_len = count;
2154
2155 cifs_stats_inc(&tcon->stats.cifs_stats.num_locks);
2156 rc = SendReceive2(xid, tcon->ses, iov, 2, &resp_buf_type, CIFS_NO_RESP);
2157 if (rc) {
2158 cFYI(1, "Send error in smb2_lockv = %d", rc);
2159 cifs_stats_fail_inc(tcon, SMB2_LOCK_HE);
2160 }
2161
2162 return rc;
2163}
2164
2165int
2166SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon,
2167 const __u64 persist_fid, const __u64 volatile_fid, const __u32 pid,
2168 const __u64 length, const __u64 offset, const __u32 lock_flags,
2169 const bool wait)
2170{
2171 struct smb2_lock_element lock;
2172
2173 lock.Offset = cpu_to_le64(offset);
2174 lock.Length = cpu_to_le64(length);
2175 lock.Flags = cpu_to_le32(lock_flags);
2176 if (!wait && lock_flags != SMB2_LOCKFLAG_UNLOCK)
2177 lock.Flags |= cpu_to_le32(SMB2_LOCKFLAG_FAIL_IMMEDIATELY);
2178
2179 return smb2_lockv(xid, tcon, persist_fid, volatile_fid, pid, 1, &lock);
2180}
2181
2182int
2183SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
2184 __u8 *lease_key, const __le32 lease_state)
2185{
2186 int rc;
2187 struct smb2_lease_ack *req = NULL;
2188
2189 cFYI(1, "SMB2_lease_break");
2190 rc = small_smb2_init(SMB2_OPLOCK_BREAK, tcon, (void **) &req);
2191
2192 if (rc)
2193 return rc;
2194
2195 req->hdr.CreditRequest = cpu_to_le16(1);
2196 req->StructureSize = cpu_to_le16(36);
2197 inc_rfc1001_len(req, 12);
2198
2199 memcpy(req->LeaseKey, lease_key, 16);
2200 req->LeaseState = lease_state;
2201
2202 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP);
2203 /* SMB2 buffer freed by function above */
2204
2205 if (rc) {
2206 cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
2207 cFYI(1, "Send error in Lease Break = %d", rc);
2208 }
2209
2210 return rc;
2211}
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
deleted file mode 100644
index 4cb4ced258c..00000000000
--- a/fs/cifs/smb2pdu.h
+++ /dev/null
@@ -1,857 +0,0 @@
1/*
2 * fs/cifs/smb2pdu.h
3 *
4 * Copyright (c) International Business Machines Corp., 2009, 2010
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
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
24#ifndef _SMB2PDU_H
25#define _SMB2PDU_H
26
27#include <net/sock.h>
28
29/*
30 * Note that, due to trying to use names similar to the protocol specifications,
31 * there are many mixed case field names in the structures below. Although
32 * this does not match typical Linux kernel style, it is necessary to be
33 * be able to match against the protocol specfication.
34 *
35 * SMB2 commands
36 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
37 * (ie no useful data other than the SMB error code itself) and are marked such.
38 * Knowing this helps avoid response buffer allocations and copy in some cases.
39 */
40
41/* List of commands in host endian */
42#define SMB2_NEGOTIATE_HE 0x0000
43#define SMB2_SESSION_SETUP_HE 0x0001
44#define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
45#define SMB2_TREE_CONNECT_HE 0x0003
46#define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
47#define SMB2_CREATE_HE 0x0005
48#define SMB2_CLOSE_HE 0x0006
49#define SMB2_FLUSH_HE 0x0007 /* trivial resp */
50#define SMB2_READ_HE 0x0008
51#define SMB2_WRITE_HE 0x0009
52#define SMB2_LOCK_HE 0x000A
53#define SMB2_IOCTL_HE 0x000B
54#define SMB2_CANCEL_HE 0x000C
55#define SMB2_ECHO_HE 0x000D
56#define SMB2_QUERY_DIRECTORY_HE 0x000E
57#define SMB2_CHANGE_NOTIFY_HE 0x000F
58#define SMB2_QUERY_INFO_HE 0x0010
59#define SMB2_SET_INFO_HE 0x0011
60#define SMB2_OPLOCK_BREAK_HE 0x0012
61
62/* The same list in little endian */
63#define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
64#define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
65#define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
66#define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
67#define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
68#define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
69#define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
70#define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
71#define SMB2_READ cpu_to_le16(SMB2_READ_HE)
72#define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
73#define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
74#define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
75#define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
76#define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
77#define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
78#define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
79#define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
80#define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
81#define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
82
83#define NUMBER_OF_SMB2_COMMANDS 0x0013
84
85/* BB FIXME - analyze following length BB */
86#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
87
88#define SMB2_PROTO_NUMBER __constant_cpu_to_le32(0x424d53fe)
89
90/*
91 * SMB2 Header Definition
92 *
93 * "MBZ" : Must be Zero
94 * "BB" : BugBug, Something to check/review/analyze later
95 * "PDU" : "Protocol Data Unit" (ie a network "frame")
96 *
97 */
98
99#define SMB2_HEADER_STRUCTURE_SIZE __constant_cpu_to_le16(64)
100
101struct smb2_hdr {
102 __be32 smb2_buf_length; /* big endian on wire */
103 /* length is only two or three bytes - with
104 one or two byte type preceding it that MBZ */
105 __u8 ProtocolId[4]; /* 0xFE 'S' 'M' 'B' */
106 __le16 StructureSize; /* 64 */
107 __le16 CreditCharge; /* MBZ */
108 __le32 Status; /* Error from server */
109 __le16 Command;
110 __le16 CreditRequest; /* CreditResponse */
111 __le32 Flags;
112 __le32 NextCommand;
113 __u64 MessageId; /* opaque - so can stay little endian */
114 __le32 ProcessId;
115 __u32 TreeId; /* opaque - so do not make little endian */
116 __u64 SessionId; /* opaque - so do not make little endian */
117 __u8 Signature[16];
118} __packed;
119
120struct smb2_pdu {
121 struct smb2_hdr hdr;
122 __le16 StructureSize2; /* size of wct area (varies, request specific) */
123} __packed;
124
125/*
126 * SMB2 flag definitions
127 */
128#define SMB2_FLAGS_SERVER_TO_REDIR __constant_cpu_to_le32(0x00000001)
129#define SMB2_FLAGS_ASYNC_COMMAND __constant_cpu_to_le32(0x00000002)
130#define SMB2_FLAGS_RELATED_OPERATIONS __constant_cpu_to_le32(0x00000004)
131#define SMB2_FLAGS_SIGNED __constant_cpu_to_le32(0x00000008)
132#define SMB2_FLAGS_DFS_OPERATIONS __constant_cpu_to_le32(0x10000000)
133
134/*
135 * Definitions for SMB2 Protocol Data Units (network frames)
136 *
137 * See MS-SMB2.PDF specification for protocol details.
138 * The Naming convention is the lower case version of the SMB2
139 * command code name for the struct. Note that structures must be packed.
140 *
141 */
142
143#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_cpu_to_le16(9)
144
145struct smb2_err_rsp {
146 struct smb2_hdr hdr;
147 __le16 StructureSize;
148 __le16 Reserved; /* MBZ */
149 __le32 ByteCount; /* even if zero, at least one byte follows */
150 __u8 ErrorData[1]; /* variable length */
151} __packed;
152
153#define SMB2_CLIENT_GUID_SIZE 16
154
155extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE];
156
157struct smb2_negotiate_req {
158 struct smb2_hdr hdr;
159 __le16 StructureSize; /* Must be 36 */
160 __le16 DialectCount;
161 __le16 SecurityMode;
162 __le16 Reserved; /* MBZ */
163 __le32 Capabilities;
164 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
165 __le64 ClientStartTime; /* MBZ */
166 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
167} __packed;
168
169/* Dialects */
170#define SMB20_PROT_ID 0x0202
171#define SMB21_PROT_ID 0x0210
172#define SMB30_PROT_ID 0x0300
173#define BAD_PROT_ID 0xFFFF
174
175/* SecurityMode flags */
176#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
177#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
178/* Capabilities flags */
179#define SMB2_GLOBAL_CAP_DFS 0x00000001
180#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
181#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
182#define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
183#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
184#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
185#define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
186/* Internal types */
187#define SMB2_NT_FIND 0x00100000
188#define SMB2_LARGE_FILES 0x00200000
189
190struct smb2_negotiate_rsp {
191 struct smb2_hdr hdr;
192 __le16 StructureSize; /* Must be 65 */
193 __le16 SecurityMode;
194 __le16 DialectRevision;
195 __le16 Reserved; /* MBZ */
196 __u8 ServerGUID[16];
197 __le32 Capabilities;
198 __le32 MaxTransactSize;
199 __le32 MaxReadSize;
200 __le32 MaxWriteSize;
201 __le64 SystemTime; /* MBZ */
202 __le64 ServerStartTime;
203 __le16 SecurityBufferOffset;
204 __le16 SecurityBufferLength;
205 __le32 Reserved2; /* may be any value, ignore */
206 __u8 Buffer[1]; /* variable length GSS security buffer */
207} __packed;
208
209struct smb2_sess_setup_req {
210 struct smb2_hdr hdr;
211 __le16 StructureSize; /* Must be 25 */
212 __u8 VcNumber;
213 __u8 SecurityMode;
214 __le32 Capabilities;
215 __le32 Channel;
216 __le16 SecurityBufferOffset;
217 __le16 SecurityBufferLength;
218 __le64 PreviousSessionId;
219 __u8 Buffer[1]; /* variable length GSS security buffer */
220} __packed;
221
222/* Currently defined SessionFlags */
223#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
224#define SMB2_SESSION_FLAG_IS_NULL 0x0002
225struct smb2_sess_setup_rsp {
226 struct smb2_hdr hdr;
227 __le16 StructureSize; /* Must be 9 */
228 __le16 SessionFlags;
229 __le16 SecurityBufferOffset;
230 __le16 SecurityBufferLength;
231 __u8 Buffer[1]; /* variable length GSS security buffer */
232} __packed;
233
234struct smb2_logoff_req {
235 struct smb2_hdr hdr;
236 __le16 StructureSize; /* Must be 4 */
237 __le16 Reserved;
238} __packed;
239
240struct smb2_logoff_rsp {
241 struct smb2_hdr hdr;
242 __le16 StructureSize; /* Must be 4 */
243 __le16 Reserved;
244} __packed;
245
246struct smb2_tree_connect_req {
247 struct smb2_hdr hdr;
248 __le16 StructureSize; /* Must be 9 */
249 __le16 Reserved;
250 __le16 PathOffset;
251 __le16 PathLength;
252 __u8 Buffer[1]; /* variable length */
253} __packed;
254
255struct smb2_tree_connect_rsp {
256 struct smb2_hdr hdr;
257 __le16 StructureSize; /* Must be 16 */
258 __u8 ShareType; /* see below */
259 __u8 Reserved;
260 __le32 ShareFlags; /* see below */
261 __le32 Capabilities; /* see below */
262 __le32 MaximalAccess;
263} __packed;
264
265/* Possible ShareType values */
266#define SMB2_SHARE_TYPE_DISK 0x01
267#define SMB2_SHARE_TYPE_PIPE 0x02
268#define SMB2_SHARE_TYPE_PRINT 0x03
269
270/*
271 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
272 * must be set (any of the remaining, SHI1005, flags may be set individually
273 * or in combination.
274 */
275#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
276#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
277#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
278#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
279#define SHI1005_FLAGS_DFS 0x00000001
280#define SHI1005_FLAGS_DFS_ROOT 0x00000002
281#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
282#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
283#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
284#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
285#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
286#define SHI1005_FLAGS_ENABLE_HASH 0x00002000
287
288/* Possible share capabilities */
289#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008)
290
291struct smb2_tree_disconnect_req {
292 struct smb2_hdr hdr;
293 __le16 StructureSize; /* Must be 4 */
294 __le16 Reserved;
295} __packed;
296
297struct smb2_tree_disconnect_rsp {
298 struct smb2_hdr hdr;
299 __le16 StructureSize; /* Must be 4 */
300 __le16 Reserved;
301} __packed;
302
303/* File Attrubutes */
304#define FILE_ATTRIBUTE_READONLY 0x00000001
305#define FILE_ATTRIBUTE_HIDDEN 0x00000002
306#define FILE_ATTRIBUTE_SYSTEM 0x00000004
307#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
308#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
309#define FILE_ATTRIBUTE_NORMAL 0x00000080
310#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
311#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
312#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
313#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
314#define FILE_ATTRIBUTE_OFFLINE 0x00001000
315#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
316#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
317
318/* Oplock levels */
319#define SMB2_OPLOCK_LEVEL_NONE 0x00
320#define SMB2_OPLOCK_LEVEL_II 0x01
321#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
322#define SMB2_OPLOCK_LEVEL_BATCH 0x09
323#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
324/* Non-spec internal type */
325#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
326
327/* Desired Access Flags */
328#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
329#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
330#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
331#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
332#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
333#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
334#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
335#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
336#define FILE_DELETE_LE cpu_to_le32(0x00010000)
337#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
338#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
339#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
340#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
341#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
342#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
343#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
344#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
345#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
346#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
347
348/* ShareAccess Flags */
349#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
350#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
351#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
352#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
353
354/* CreateDisposition Flags */
355#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
356#define FILE_OPEN_LE cpu_to_le32(0x00000001)
357#define FILE_CREATE_LE cpu_to_le32(0x00000002)
358#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
359#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
360#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
361
362/* CreateOptions Flags */
363#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
364/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
365#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
366#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
367#define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
368#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
369#define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
370#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
371#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
372#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
373#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
374#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
375#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
376#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
377#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
378#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
379#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
380#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
381#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
382
383#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
384 | FILE_READ_ATTRIBUTES_LE)
385#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
386 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
387#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
388
389/* Impersonation Levels */
390#define IL_ANONYMOUS cpu_to_le32(0x00000000)
391#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
392#define IL_IMPERSONATION cpu_to_le32(0x00000002)
393#define IL_DELEGATE cpu_to_le32(0x00000003)
394
395/* Create Context Values */
396#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
397#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
398#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
399#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
400#define SMB2_CREATE_ALLOCATION_SIZE "AlSi"
401#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
402#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
403#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
404#define SMB2_CREATE_REQUEST_LEASE "RqLs"
405
406struct smb2_create_req {
407 struct smb2_hdr hdr;
408 __le16 StructureSize; /* Must be 57 */
409 __u8 SecurityFlags;
410 __u8 RequestedOplockLevel;
411 __le32 ImpersonationLevel;
412 __le64 SmbCreateFlags;
413 __le64 Reserved;
414 __le32 DesiredAccess;
415 __le32 FileAttributes;
416 __le32 ShareAccess;
417 __le32 CreateDisposition;
418 __le32 CreateOptions;
419 __le16 NameOffset;
420 __le16 NameLength;
421 __le32 CreateContextsOffset;
422 __le32 CreateContextsLength;
423 __u8 Buffer[8];
424} __packed;
425
426struct smb2_create_rsp {
427 struct smb2_hdr hdr;
428 __le16 StructureSize; /* Must be 89 */
429 __u8 OplockLevel;
430 __u8 Reserved;
431 __le32 CreateAction;
432 __le64 CreationTime;
433 __le64 LastAccessTime;
434 __le64 LastWriteTime;
435 __le64 ChangeTime;
436 __le64 AllocationSize;
437 __le64 EndofFile;
438 __le32 FileAttributes;
439 __le32 Reserved2;
440 __u64 PersistentFileId; /* opaque endianness */
441 __u64 VolatileFileId; /* opaque endianness */
442 __le32 CreateContextsOffset;
443 __le32 CreateContextsLength;
444 __u8 Buffer[1];
445} __packed;
446
447struct create_context {
448 __le32 Next;
449 __le16 NameOffset;
450 __le16 NameLength;
451 __le16 Reserved;
452 __le16 DataOffset;
453 __le32 DataLength;
454 __u8 Buffer[0];
455} __packed;
456
457#define SMB2_LEASE_NONE __constant_cpu_to_le32(0x00)
458#define SMB2_LEASE_READ_CACHING __constant_cpu_to_le32(0x01)
459#define SMB2_LEASE_HANDLE_CACHING __constant_cpu_to_le32(0x02)
460#define SMB2_LEASE_WRITE_CACHING __constant_cpu_to_le32(0x04)
461
462#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS __constant_cpu_to_le32(0x02)
463
464#define SMB2_LEASE_KEY_SIZE 16
465
466struct lease_context {
467 __le64 LeaseKeyLow;
468 __le64 LeaseKeyHigh;
469 __le32 LeaseState;
470 __le32 LeaseFlags;
471 __le64 LeaseDuration;
472} __packed;
473
474struct create_lease {
475 struct create_context ccontext;
476 __u8 Name[8];
477 struct lease_context lcontext;
478} __packed;
479
480/* Currently defined values for close flags */
481#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
482struct smb2_close_req {
483 struct smb2_hdr hdr;
484 __le16 StructureSize; /* Must be 24 */
485 __le16 Flags;
486 __le32 Reserved;
487 __u64 PersistentFileId; /* opaque endianness */
488 __u64 VolatileFileId; /* opaque endianness */
489} __packed;
490
491struct smb2_close_rsp {
492 struct smb2_hdr hdr;
493 __le16 StructureSize; /* 60 */
494 __le16 Flags;
495 __le32 Reserved;
496 __le64 CreationTime;
497 __le64 LastAccessTime;
498 __le64 LastWriteTime;
499 __le64 ChangeTime;
500 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
501 __le64 EndOfFile;
502 __le32 Attributes;
503} __packed;
504
505struct smb2_flush_req {
506 struct smb2_hdr hdr;
507 __le16 StructureSize; /* Must be 24 */
508 __le16 Reserved1;
509 __le32 Reserved2;
510 __u64 PersistentFileId; /* opaque endianness */
511 __u64 VolatileFileId; /* opaque endianness */
512} __packed;
513
514struct smb2_flush_rsp {
515 struct smb2_hdr hdr;
516 __le16 StructureSize;
517 __le16 Reserved;
518} __packed;
519
520struct smb2_read_req {
521 struct smb2_hdr hdr;
522 __le16 StructureSize; /* Must be 49 */
523 __u8 Padding; /* offset from start of SMB2 header to place read */
524 __u8 Reserved;
525 __le32 Length;
526 __le64 Offset;
527 __u64 PersistentFileId; /* opaque endianness */
528 __u64 VolatileFileId; /* opaque endianness */
529 __le32 MinimumCount;
530 __le32 Channel; /* Reserved MBZ */
531 __le32 RemainingBytes;
532 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
533 __le16 ReadChannelInfoLength; /* Reserved MBZ */
534 __u8 Buffer[1];
535} __packed;
536
537struct smb2_read_rsp {
538 struct smb2_hdr hdr;
539 __le16 StructureSize; /* Must be 17 */
540 __u8 DataOffset;
541 __u8 Reserved;
542 __le32 DataLength;
543 __le32 DataRemaining;
544 __u32 Reserved2;
545 __u8 Buffer[1];
546} __packed;
547
548/* For write request Flags field below the following flag is defined: */
549#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001
550
551struct smb2_write_req {
552 struct smb2_hdr hdr;
553 __le16 StructureSize; /* Must be 49 */
554 __le16 DataOffset; /* offset from start of SMB2 header to write data */
555 __le32 Length;
556 __le64 Offset;
557 __u64 PersistentFileId; /* opaque endianness */
558 __u64 VolatileFileId; /* opaque endianness */
559 __le32 Channel; /* Reserved MBZ */
560 __le32 RemainingBytes;
561 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
562 __le16 WriteChannelInfoLength; /* Reserved MBZ */
563 __le32 Flags;
564 __u8 Buffer[1];
565} __packed;
566
567struct smb2_write_rsp {
568 struct smb2_hdr hdr;
569 __le16 StructureSize; /* Must be 17 */
570 __u8 DataOffset;
571 __u8 Reserved;
572 __le32 DataLength;
573 __le32 DataRemaining;
574 __u32 Reserved2;
575 __u8 Buffer[1];
576} __packed;
577
578#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
579#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
580#define SMB2_LOCKFLAG_UNLOCK 0x0004
581#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
582
583struct smb2_lock_element {
584 __le64 Offset;
585 __le64 Length;
586 __le32 Flags;
587 __le32 Reserved;
588} __packed;
589
590struct smb2_lock_req {
591 struct smb2_hdr hdr;
592 __le16 StructureSize; /* Must be 48 */
593 __le16 LockCount;
594 __le32 Reserved;
595 __u64 PersistentFileId; /* opaque endianness */
596 __u64 VolatileFileId; /* opaque endianness */
597 /* Followed by at least one */
598 struct smb2_lock_element locks[1];
599} __packed;
600
601struct smb2_lock_rsp {
602 struct smb2_hdr hdr;
603 __le16 StructureSize; /* Must be 4 */
604 __le16 Reserved;
605} __packed;
606
607struct smb2_echo_req {
608 struct smb2_hdr hdr;
609 __le16 StructureSize; /* Must be 4 */
610 __u16 Reserved;
611} __packed;
612
613struct smb2_echo_rsp {
614 struct smb2_hdr hdr;
615 __le16 StructureSize; /* Must be 4 */
616 __u16 Reserved;
617} __packed;
618
619/* search (query_directory) Flags field */
620#define SMB2_RESTART_SCANS 0x01
621#define SMB2_RETURN_SINGLE_ENTRY 0x02
622#define SMB2_INDEX_SPECIFIED 0x04
623#define SMB2_REOPEN 0x10
624
625struct smb2_query_directory_req {
626 struct smb2_hdr hdr;
627 __le16 StructureSize; /* Must be 33 */
628 __u8 FileInformationClass;
629 __u8 Flags;
630 __le32 FileIndex;
631 __u64 PersistentFileId; /* opaque endianness */
632 __u64 VolatileFileId; /* opaque endianness */
633 __le16 FileNameOffset;
634 __le16 FileNameLength;
635 __le32 OutputBufferLength;
636 __u8 Buffer[1];
637} __packed;
638
639struct smb2_query_directory_rsp {
640 struct smb2_hdr hdr;
641 __le16 StructureSize; /* Must be 9 */
642 __le16 OutputBufferOffset;
643 __le32 OutputBufferLength;
644 __u8 Buffer[1];
645} __packed;
646
647/* Possible InfoType values */
648#define SMB2_O_INFO_FILE 0x01
649#define SMB2_O_INFO_FILESYSTEM 0x02
650#define SMB2_O_INFO_SECURITY 0x03
651#define SMB2_O_INFO_QUOTA 0x04
652
653struct smb2_query_info_req {
654 struct smb2_hdr hdr;
655 __le16 StructureSize; /* Must be 41 */
656 __u8 InfoType;
657 __u8 FileInfoClass;
658 __le32 OutputBufferLength;
659 __le16 InputBufferOffset;
660 __u16 Reserved;
661 __le32 InputBufferLength;
662 __le32 AdditionalInformation;
663 __le32 Flags;
664 __u64 PersistentFileId; /* opaque endianness */
665 __u64 VolatileFileId; /* opaque endianness */
666 __u8 Buffer[1];
667} __packed;
668
669struct smb2_query_info_rsp {
670 struct smb2_hdr hdr;
671 __le16 StructureSize; /* Must be 9 */
672 __le16 OutputBufferOffset;
673 __le32 OutputBufferLength;
674 __u8 Buffer[1];
675} __packed;
676
677struct smb2_set_info_req {
678 struct smb2_hdr hdr;
679 __le16 StructureSize; /* Must be 33 */
680 __u8 InfoType;
681 __u8 FileInfoClass;
682 __le32 BufferLength;
683 __le16 BufferOffset;
684 __u16 Reserved;
685 __le32 AdditionalInformation;
686 __u64 PersistentFileId; /* opaque endianness */
687 __u64 VolatileFileId; /* opaque endianness */
688 __u8 Buffer[1];
689} __packed;
690
691struct smb2_set_info_rsp {
692 struct smb2_hdr hdr;
693 __le16 StructureSize; /* Must be 2 */
694} __packed;
695
696struct smb2_oplock_break {
697 struct smb2_hdr hdr;
698 __le16 StructureSize; /* Must be 24 */
699 __u8 OplockLevel;
700 __u8 Reserved;
701 __le32 Reserved2;
702 __u64 PersistentFid;
703 __u64 VolatileFid;
704} __packed;
705
706#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
707
708struct smb2_lease_break {
709 struct smb2_hdr hdr;
710 __le16 StructureSize; /* Must be 44 */
711 __le16 Reserved;
712 __le32 Flags;
713 __u8 LeaseKey[16];
714 __le32 CurrentLeaseState;
715 __le32 NewLeaseState;
716 __le32 BreakReason;
717 __le32 AccessMaskHint;
718 __le32 ShareMaskHint;
719} __packed;
720
721struct smb2_lease_ack {
722 struct smb2_hdr hdr;
723 __le16 StructureSize; /* Must be 36 */
724 __le16 Reserved;
725 __le32 Flags;
726 __u8 LeaseKey[16];
727 __le32 LeaseState;
728 __le64 LeaseDuration;
729} __packed;
730
731/*
732 * PDU infolevel structure definitions
733 * BB consider moving to a different header
734 */
735
736/* File System Information Classes */
737#define FS_VOLUME_INFORMATION 1 /* Query */
738#define FS_LABEL_INFORMATION 2 /* Set */
739#define FS_SIZE_INFORMATION 3 /* Query */
740#define FS_DEVICE_INFORMATION 4 /* Query */
741#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
742#define FS_CONTROL_INFORMATION 6 /* Query, Set */
743#define FS_FULL_SIZE_INFORMATION 7 /* Query */
744#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
745#define FS_DRIVER_PATH_INFORMATION 9 /* Query */
746
747struct smb2_fs_full_size_info {
748 __le64 TotalAllocationUnits;
749 __le64 CallerAvailableAllocationUnits;
750 __le64 ActualAvailableAllocationUnits;
751 __le32 SectorsPerAllocationUnit;
752 __le32 BytesPerSector;
753} __packed;
754
755/* partial list of QUERY INFO levels */
756#define FILE_DIRECTORY_INFORMATION 1
757#define FILE_FULL_DIRECTORY_INFORMATION 2
758#define FILE_BOTH_DIRECTORY_INFORMATION 3
759#define FILE_BASIC_INFORMATION 4
760#define FILE_STANDARD_INFORMATION 5
761#define FILE_INTERNAL_INFORMATION 6
762#define FILE_EA_INFORMATION 7
763#define FILE_ACCESS_INFORMATION 8
764#define FILE_NAME_INFORMATION 9
765#define FILE_RENAME_INFORMATION 10
766#define FILE_LINK_INFORMATION 11
767#define FILE_NAMES_INFORMATION 12
768#define FILE_DISPOSITION_INFORMATION 13
769#define FILE_POSITION_INFORMATION 14
770#define FILE_FULL_EA_INFORMATION 15
771#define FILE_MODE_INFORMATION 16
772#define FILE_ALIGNMENT_INFORMATION 17
773#define FILE_ALL_INFORMATION 18
774#define FILE_ALLOCATION_INFORMATION 19
775#define FILE_END_OF_FILE_INFORMATION 20
776#define FILE_ALTERNATE_NAME_INFORMATION 21
777#define FILE_STREAM_INFORMATION 22
778#define FILE_PIPE_INFORMATION 23
779#define FILE_PIPE_LOCAL_INFORMATION 24
780#define FILE_PIPE_REMOTE_INFORMATION 25
781#define FILE_MAILSLOT_QUERY_INFORMATION 26
782#define FILE_MAILSLOT_SET_INFORMATION 27
783#define FILE_COMPRESSION_INFORMATION 28
784#define FILE_OBJECT_ID_INFORMATION 29
785/* Number 30 not defined in documents */
786#define FILE_MOVE_CLUSTER_INFORMATION 31
787#define FILE_QUOTA_INFORMATION 32
788#define FILE_REPARSE_POINT_INFORMATION 33
789#define FILE_NETWORK_OPEN_INFORMATION 34
790#define FILE_ATTRIBUTE_TAG_INFORMATION 35
791#define FILE_TRACKING_INFORMATION 36
792#define FILEID_BOTH_DIRECTORY_INFORMATION 37
793#define FILEID_FULL_DIRECTORY_INFORMATION 38
794#define FILE_VALID_DATA_LENGTH_INFORMATION 39
795#define FILE_SHORT_NAME_INFORMATION 40
796#define FILE_SFIO_RESERVE_INFORMATION 44
797#define FILE_SFIO_VOLUME_INFORMATION 45
798#define FILE_HARD_LINK_INFORMATION 46
799#define FILE_NORMALIZED_NAME_INFORMATION 48
800#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
801#define FILE_STANDARD_LINK_INFORMATION 54
802
803struct smb2_file_internal_info {
804 __le64 IndexNumber;
805} __packed; /* level 6 Query */
806
807struct smb2_file_rename_info { /* encoding of request for level 10 */
808 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
809 /* 0 = fail if target already exists */
810 __u8 Reserved[7];
811 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
812 __le32 FileNameLength;
813 char FileName[0]; /* New name to be assigned */
814} __packed; /* level 10 Set */
815
816struct smb2_file_link_info { /* encoding of request for level 11 */
817 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
818 /* 0 = fail if link already exists */
819 __u8 Reserved[7];
820 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
821 __le32 FileNameLength;
822 char FileName[0]; /* Name to be assigned to new link */
823} __packed; /* level 11 Set */
824
825/*
826 * This level 18, although with struct with same name is different from cifs
827 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
828 * CurrentByteOffset.
829 */
830struct smb2_file_all_info { /* data block encoding of response to level 18 */
831 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
832 __le64 LastAccessTime;
833 __le64 LastWriteTime;
834 __le64 ChangeTime;
835 __le32 Attributes;
836 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
837 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
838 __le64 EndOfFile; /* size ie offset to first free byte in file */
839 __le32 NumberOfLinks; /* hard links */
840 __u8 DeletePending;
841 __u8 Directory;
842 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
843 __le64 IndexNumber;
844 __le32 EASize;
845 __le32 AccessFlags;
846 __le64 CurrentByteOffset;
847 __le32 Mode;
848 __le32 AlignmentRequirement;
849 __le32 FileNameLength;
850 char FileName[1];
851} __packed; /* level 18 Query */
852
853struct smb2_file_eof_info { /* encoding of request for level 10 */
854 __le64 EndOfFile; /* new end of file value */
855} __packed; /* level 20 Set */
856
857#endif /* _SMB2PDU_H */
diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
deleted file mode 100644
index 2aa3535e38c..00000000000
--- a/fs/cifs/smb2proto.h
+++ /dev/null
@@ -1,163 +0,0 @@
1/*
2 * fs/cifs/smb2proto.h
3 *
4 * Copyright (c) International Business Machines Corp., 2002, 2011
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
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#ifndef _SMB2PROTO_H
24#define _SMB2PROTO_H
25#include <linux/nls.h>
26#include <linux/key-type.h>
27
28struct statfs;
29struct smb_rqst;
30
31/*
32 *****************************************************************
33 * All Prototypes
34 *****************************************************************
35 */
36extern int map_smb2_to_linux_error(char *buf, bool log_err);
37extern int smb2_check_message(char *buf, unsigned int length);
38extern unsigned int smb2_calc_size(void *buf);
39extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr);
40extern __le16 *cifs_convert_path_to_utf16(const char *from,
41 struct cifs_sb_info *cifs_sb);
42
43extern int smb2_verify_signature(struct smb_rqst *, struct TCP_Server_Info *);
44extern int smb2_check_receive(struct mid_q_entry *mid,
45 struct TCP_Server_Info *server, bool log_error);
46extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses,
47 struct smb_rqst *rqst);
48extern struct mid_q_entry *smb2_setup_async_request(
49 struct TCP_Server_Info *server, struct smb_rqst *rqst);
50extern int smb2_calc_signature(struct smb_rqst *rqst,
51 struct TCP_Server_Info *server);
52extern int smb3_calc_signature(struct smb_rqst *rqst,
53 struct TCP_Server_Info *server);
54extern void smb2_echo_request(struct work_struct *work);
55extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);
56extern __u8 smb2_map_lease_to_oplock(__le32 lease_state);
57extern bool smb2_is_valid_oplock_break(char *buffer,
58 struct TCP_Server_Info *srv);
59
60extern void move_smb2_info_to_cifs(FILE_ALL_INFO *dst,
61 struct smb2_file_all_info *src);
62extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
63 struct cifs_sb_info *cifs_sb,
64 const char *full_path, FILE_ALL_INFO *data,
65 bool *adjust_tz);
66extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
67 const char *full_path, __u64 size,
68 struct cifs_sb_info *cifs_sb, bool set_alloc);
69extern int smb2_set_file_info(struct inode *inode, const char *full_path,
70 FILE_BASIC_INFO *buf, const unsigned int xid);
71extern int smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon,
72 const char *name, struct cifs_sb_info *cifs_sb);
73extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path,
74 struct cifs_sb_info *cifs_sb,
75 struct cifs_tcon *tcon, const unsigned int xid);
76extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon,
77 const char *name, struct cifs_sb_info *cifs_sb);
78extern int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon,
79 const char *name, struct cifs_sb_info *cifs_sb);
80extern int smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
81 const char *from_name, const char *to_name,
82 struct cifs_sb_info *cifs_sb);
83extern int smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
84 const char *from_name, const char *to_name,
85 struct cifs_sb_info *cifs_sb);
86
87extern int smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon,
88 const char *full_path, int disposition,
89 int desired_access, int create_options,
90 struct cifs_fid *fid, __u32 *oplock,
91 FILE_ALL_INFO *buf, struct cifs_sb_info *cifs_sb);
92extern void smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock);
93extern int smb2_unlock_range(struct cifsFileInfo *cfile,
94 struct file_lock *flock, const unsigned int xid);
95extern int smb2_push_mandatory_locks(struct cifsFileInfo *cfile);
96
97/*
98 * SMB2 Worker functions - most of protocol specific implementation details
99 * are contained within these calls.
100 */
101extern int SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses);
102extern int SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
103 const struct nls_table *nls_cp);
104extern int SMB2_logoff(const unsigned int xid, struct cifs_ses *ses);
105extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,
106 const char *tree, struct cifs_tcon *tcon,
107 const struct nls_table *);
108extern int SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon);
109extern int SMB2_open(const unsigned int xid, struct cifs_tcon *tcon,
110 __le16 *path, u64 *persistent_fid, u64 *volatile_fid,
111 __u32 desired_access, __u32 create_disposition,
112 __u32 file_attributes, __u32 create_options,
113 __u8 *oplock, struct smb2_file_all_info *buf);
114extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
115 u64 persistent_file_id, u64 volatile_file_id);
116extern int SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon,
117 u64 persistent_file_id, u64 volatile_file_id);
118extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,
119 u64 persistent_file_id, u64 volatile_file_id,
120 struct smb2_file_all_info *data);
121extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
122 u64 persistent_fid, u64 volatile_fid,
123 __le64 *uniqueid);
124extern int smb2_async_readv(struct cifs_readdata *rdata);
125extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
126 unsigned int *nbytes, char **buf, int *buf_type);
127extern int smb2_async_writev(struct cifs_writedata *wdata);
128extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
129 unsigned int *nbytes, struct kvec *iov, int n_vec);
130extern int SMB2_echo(struct TCP_Server_Info *server);
131extern int SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
132 u64 persistent_fid, u64 volatile_fid, int index,
133 struct cifs_search_info *srch_inf);
134extern int SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
135 u64 persistent_fid, u64 volatile_fid,
136 __le16 *target_file);
137extern int SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
138 u64 persistent_fid, u64 volatile_fid,
139 __le16 *target_file);
140extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon,
141 u64 persistent_fid, u64 volatile_fid, u32 pid,
142 __le64 *eof);
143extern int SMB2_set_info(const unsigned int xid, struct cifs_tcon *tcon,
144 u64 persistent_fid, u64 volatile_fid,
145 FILE_BASIC_INFO *buf);
146extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
147 const u64 persistent_fid, const u64 volatile_fid,
148 const __u8 oplock_level);
149extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
150 u64 persistent_file_id, u64 volatile_file_id,
151 struct kstatfs *FSData);
152extern int SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon,
153 const __u64 persist_fid, const __u64 volatile_fid,
154 const __u32 pid, const __u64 length, const __u64 offset,
155 const __u32 lockFlags, const bool wait);
156extern int smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
157 const __u64 persist_fid, const __u64 volatile_fid,
158 const __u32 pid, const __u32 num_lock,
159 struct smb2_lock_element *buf);
160extern int SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
161 __u8 *lease_key, const __le32 lease_state);
162
163#endif /* _SMB2PROTO_H */
diff --git a/fs/cifs/smb2status.h b/fs/cifs/smb2status.h
deleted file mode 100644
index 3d5f62150de..00000000000
--- a/fs/cifs/smb2status.h
+++ /dev/null
@@ -1,1782 +0,0 @@
1/*
2 * fs/cifs/smb2status.h
3 *
4 * SMB2 Status code (network error) definitions
5 * Definitions are from MS-ERREF
6 *
7 * Copyright (c) International Business Machines Corp., 2009,2011
8 * Author(s): Steve French (sfrench@us.ibm.com)
9 *
10 * This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 * the GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25/*
26 * 0 1 2 3 4 5 6 7 8 9 0 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
27 * SEV C N <-------Facility--------> <------Error Status Code------>
28 *
29 * C is set if "customer defined" error, N bit is reserved and MBZ
30 */
31
32#define STATUS_SEVERITY_SUCCESS __constant_cpu_to_le32(0x0000)
33#define STATUS_SEVERITY_INFORMATIONAL __constanst_cpu_to_le32(0x0001)
34#define STATUS_SEVERITY_WARNING __constanst_cpu_to_le32(0x0002)
35#define STATUS_SEVERITY_ERROR __constanst_cpu_to_le32(0x0003)
36
37struct ntstatus {
38 /* Facility is the high 12 bits of the following field */
39 __le32 Facility; /* low 2 bits Severity, next is Customer, then rsrvd */
40 __le32 Code;
41};
42
43#define STATUS_SUCCESS __constant_cpu_to_le32(0x00000000)
44#define STATUS_WAIT_0 __constant_cpu_to_le32(0x00000000)
45#define STATUS_WAIT_1 __constant_cpu_to_le32(0x00000001)
46#define STATUS_WAIT_2 __constant_cpu_to_le32(0x00000002)
47#define STATUS_WAIT_3 __constant_cpu_to_le32(0x00000003)
48#define STATUS_WAIT_63 __constant_cpu_to_le32(0x0000003F)
49#define STATUS_ABANDONED __constant_cpu_to_le32(0x00000080)
50#define STATUS_ABANDONED_WAIT_0 __constant_cpu_to_le32(0x00000080)
51#define STATUS_ABANDONED_WAIT_63 __constant_cpu_to_le32(0x000000BF)
52#define STATUS_USER_APC __constant_cpu_to_le32(0x000000C0)
53#define STATUS_KERNEL_APC __constant_cpu_to_le32(0x00000100)
54#define STATUS_ALERTED __constant_cpu_to_le32(0x00000101)
55#define STATUS_TIMEOUT __constant_cpu_to_le32(0x00000102)
56#define STATUS_PENDING __constant_cpu_to_le32(0x00000103)
57#define STATUS_REPARSE __constant_cpu_to_le32(0x00000104)
58#define STATUS_MORE_ENTRIES __constant_cpu_to_le32(0x00000105)
59#define STATUS_NOT_ALL_ASSIGNED __constant_cpu_to_le32(0x00000106)
60#define STATUS_SOME_NOT_MAPPED __constant_cpu_to_le32(0x00000107)
61#define STATUS_OPLOCK_BREAK_IN_PROGRESS __constant_cpu_to_le32(0x00000108)
62#define STATUS_VOLUME_MOUNTED __constant_cpu_to_le32(0x00000109)
63#define STATUS_RXACT_COMMITTED __constant_cpu_to_le32(0x0000010A)
64#define STATUS_NOTIFY_CLEANUP __constant_cpu_to_le32(0x0000010B)
65#define STATUS_NOTIFY_ENUM_DIR __constant_cpu_to_le32(0x0000010C)
66#define STATUS_NO_QUOTAS_FOR_ACCOUNT __constant_cpu_to_le32(0x0000010D)
67#define STATUS_PRIMARY_TRANSPORT_CONNECT_FAILED __constant_cpu_to_le32(0x0000010E)
68#define STATUS_PAGE_FAULT_TRANSITION __constant_cpu_to_le32(0x00000110)
69#define STATUS_PAGE_FAULT_DEMAND_ZERO __constant_cpu_to_le32(0x00000111)
70#define STATUS_PAGE_FAULT_COPY_ON_WRITE __constant_cpu_to_le32(0x00000112)
71#define STATUS_PAGE_FAULT_GUARD_PAGE __constant_cpu_to_le32(0x00000113)
72#define STATUS_PAGE_FAULT_PAGING_FILE __constant_cpu_to_le32(0x00000114)
73#define STATUS_CACHE_PAGE_LOCKED __constant_cpu_to_le32(0x00000115)
74#define STATUS_CRASH_DUMP __constant_cpu_to_le32(0x00000116)
75#define STATUS_BUFFER_ALL_ZEROS __constant_cpu_to_le32(0x00000117)
76#define STATUS_REPARSE_OBJECT __constant_cpu_to_le32(0x00000118)
77#define STATUS_RESOURCE_REQUIREMENTS_CHANGED __constant_cpu_to_le32(0x00000119)
78#define STATUS_TRANSLATION_COMPLETE __constant_cpu_to_le32(0x00000120)
79#define STATUS_DS_MEMBERSHIP_EVALUATED_LOCALLY __constant_cpu_to_le32(0x00000121)
80#define STATUS_NOTHING_TO_TERMINATE __constant_cpu_to_le32(0x00000122)
81#define STATUS_PROCESS_NOT_IN_JOB __constant_cpu_to_le32(0x00000123)
82#define STATUS_PROCESS_IN_JOB __constant_cpu_to_le32(0x00000124)
83#define STATUS_VOLSNAP_HIBERNATE_READY __constant_cpu_to_le32(0x00000125)
84#define STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY __constant_cpu_to_le32(0x00000126)
85#define STATUS_INTERRUPT_VECTOR_ALREADY_CONNECTED __constant_cpu_to_le32(0x00000127)
86#define STATUS_INTERRUPT_STILL_CONNECTED __constant_cpu_to_le32(0x00000128)
87#define STATUS_PROCESS_CLONED __constant_cpu_to_le32(0x00000129)
88#define STATUS_FILE_LOCKED_WITH_ONLY_READERS __constant_cpu_to_le32(0x0000012A)
89#define STATUS_FILE_LOCKED_WITH_WRITERS __constant_cpu_to_le32(0x0000012B)
90#define STATUS_RESOURCEMANAGER_READ_ONLY __constant_cpu_to_le32(0x00000202)
91#define STATUS_WAIT_FOR_OPLOCK __constant_cpu_to_le32(0x00000367)
92#define DBG_EXCEPTION_HANDLED __constant_cpu_to_le32(0x00010001)
93#define DBG_CONTINUE __constant_cpu_to_le32(0x00010002)
94#define STATUS_FLT_IO_COMPLETE __constant_cpu_to_le32(0x001C0001)
95#define STATUS_OBJECT_NAME_EXISTS __constant_cpu_to_le32(0x40000000)
96#define STATUS_THREAD_WAS_SUSPENDED __constant_cpu_to_le32(0x40000001)
97#define STATUS_WORKING_SET_LIMIT_RANGE __constant_cpu_to_le32(0x40000002)
98#define STATUS_IMAGE_NOT_AT_BASE __constant_cpu_to_le32(0x40000003)
99#define STATUS_RXACT_STATE_CREATED __constant_cpu_to_le32(0x40000004)
100#define STATUS_SEGMENT_NOTIFICATION __constant_cpu_to_le32(0x40000005)
101#define STATUS_LOCAL_USER_SESSION_KEY __constant_cpu_to_le32(0x40000006)
102#define STATUS_BAD_CURRENT_DIRECTORY __constant_cpu_to_le32(0x40000007)
103#define STATUS_SERIAL_MORE_WRITES __constant_cpu_to_le32(0x40000008)
104#define STATUS_REGISTRY_RECOVERED __constant_cpu_to_le32(0x40000009)
105#define STATUS_FT_READ_RECOVERY_FROM_BACKUP __constant_cpu_to_le32(0x4000000A)
106#define STATUS_FT_WRITE_RECOVERY __constant_cpu_to_le32(0x4000000B)
107#define STATUS_SERIAL_COUNTER_TIMEOUT __constant_cpu_to_le32(0x4000000C)
108#define STATUS_NULL_LM_PASSWORD __constant_cpu_to_le32(0x4000000D)
109#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH __constant_cpu_to_le32(0x4000000E)
110#define STATUS_RECEIVE_PARTIAL __constant_cpu_to_le32(0x4000000F)
111#define STATUS_RECEIVE_EXPEDITED __constant_cpu_to_le32(0x40000010)
112#define STATUS_RECEIVE_PARTIAL_EXPEDITED __constant_cpu_to_le32(0x40000011)
113#define STATUS_EVENT_DONE __constant_cpu_to_le32(0x40000012)
114#define STATUS_EVENT_PENDING __constant_cpu_to_le32(0x40000013)
115#define STATUS_CHECKING_FILE_SYSTEM __constant_cpu_to_le32(0x40000014)
116#define STATUS_FATAL_APP_EXIT __constant_cpu_to_le32(0x40000015)
117#define STATUS_PREDEFINED_HANDLE __constant_cpu_to_le32(0x40000016)
118#define STATUS_WAS_UNLOCKED __constant_cpu_to_le32(0x40000017)
119#define STATUS_SERVICE_NOTIFICATION __constant_cpu_to_le32(0x40000018)
120#define STATUS_WAS_LOCKED __constant_cpu_to_le32(0x40000019)
121#define STATUS_LOG_HARD_ERROR __constant_cpu_to_le32(0x4000001A)
122#define STATUS_ALREADY_WIN32 __constant_cpu_to_le32(0x4000001B)
123#define STATUS_WX86_UNSIMULATE __constant_cpu_to_le32(0x4000001C)
124#define STATUS_WX86_CONTINUE __constant_cpu_to_le32(0x4000001D)
125#define STATUS_WX86_SINGLE_STEP __constant_cpu_to_le32(0x4000001E)
126#define STATUS_WX86_BREAKPOINT __constant_cpu_to_le32(0x4000001F)
127#define STATUS_WX86_EXCEPTION_CONTINUE __constant_cpu_to_le32(0x40000020)
128#define STATUS_WX86_EXCEPTION_LASTCHANCE __constant_cpu_to_le32(0x40000021)
129#define STATUS_WX86_EXCEPTION_CHAIN __constant_cpu_to_le32(0x40000022)
130#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE __constant_cpu_to_le32(0x40000023)
131#define STATUS_NO_YIELD_PERFORMED __constant_cpu_to_le32(0x40000024)
132#define STATUS_TIMER_RESUME_IGNORED __constant_cpu_to_le32(0x40000025)
133#define STATUS_ARBITRATION_UNHANDLED __constant_cpu_to_le32(0x40000026)
134#define STATUS_CARDBUS_NOT_SUPPORTED __constant_cpu_to_le32(0x40000027)
135#define STATUS_WX86_CREATEWX86TIB __constant_cpu_to_le32(0x40000028)
136#define STATUS_MP_PROCESSOR_MISMATCH __constant_cpu_to_le32(0x40000029)
137#define STATUS_HIBERNATED __constant_cpu_to_le32(0x4000002A)
138#define STATUS_RESUME_HIBERNATION __constant_cpu_to_le32(0x4000002B)
139#define STATUS_FIRMWARE_UPDATED __constant_cpu_to_le32(0x4000002C)
140#define STATUS_DRIVERS_LEAKING_LOCKED_PAGES __constant_cpu_to_le32(0x4000002D)
141#define STATUS_MESSAGE_RETRIEVED __constant_cpu_to_le32(0x4000002E)
142#define STATUS_SYSTEM_POWERSTATE_TRANSITION __constant_cpu_to_le32(0x4000002F)
143#define STATUS_ALPC_CHECK_COMPLETION_LIST __constant_cpu_to_le32(0x40000030)
144#define STATUS_SYSTEM_POWERSTATE_COMPLEX_TRANSITION __constant_cpu_to_le32(0x40000031)
145#define STATUS_ACCESS_AUDIT_BY_POLICY __constant_cpu_to_le32(0x40000032)
146#define STATUS_ABANDON_HIBERFILE __constant_cpu_to_le32(0x40000033)
147#define STATUS_BIZRULES_NOT_ENABLED __constant_cpu_to_le32(0x40000034)
148#define STATUS_WAKE_SYSTEM __constant_cpu_to_le32(0x40000294)
149#define STATUS_DS_SHUTTING_DOWN __constant_cpu_to_le32(0x40000370)
150#define DBG_REPLY_LATER __constant_cpu_to_le32(0x40010001)
151#define DBG_UNABLE_TO_PROVIDE_HANDLE __constant_cpu_to_le32(0x40010002)
152#define DBG_TERMINATE_THREAD __constant_cpu_to_le32(0x40010003)
153#define DBG_TERMINATE_PROCESS __constant_cpu_to_le32(0x40010004)
154#define DBG_CONTROL_C __constant_cpu_to_le32(0x40010005)
155#define DBG_PRINTEXCEPTION_C __constant_cpu_to_le32(0x40010006)
156#define DBG_RIPEXCEPTION __constant_cpu_to_le32(0x40010007)
157#define DBG_CONTROL_BREAK __constant_cpu_to_le32(0x40010008)
158#define DBG_COMMAND_EXCEPTION __constant_cpu_to_le32(0x40010009)
159#define RPC_NT_UUID_LOCAL_ONLY __constant_cpu_to_le32(0x40020056)
160#define RPC_NT_SEND_INCOMPLETE __constant_cpu_to_le32(0x400200AF)
161#define STATUS_CTX_CDM_CONNECT __constant_cpu_to_le32(0x400A0004)
162#define STATUS_CTX_CDM_DISCONNECT __constant_cpu_to_le32(0x400A0005)
163#define STATUS_SXS_RELEASE_ACTIVATION_CONTEXT __constant_cpu_to_le32(0x4015000D)
164#define STATUS_RECOVERY_NOT_NEEDED __constant_cpu_to_le32(0x40190034)
165#define STATUS_RM_ALREADY_STARTED __constant_cpu_to_le32(0x40190035)
166#define STATUS_LOG_NO_RESTART __constant_cpu_to_le32(0x401A000C)
167#define STATUS_VIDEO_DRIVER_DEBUG_REPORT_REQUEST __constant_cpu_to_le32(0x401B00EC)
168#define STATUS_GRAPHICS_PARTIAL_DATA_POPULATED __constant_cpu_to_le32(0x401E000A)
169#define STATUS_GRAPHICS_DRIVER_MISMATCH __constant_cpu_to_le32(0x401E0117)
170#define STATUS_GRAPHICS_MODE_NOT_PINNED __constant_cpu_to_le32(0x401E0307)
171#define STATUS_GRAPHICS_NO_PREFERRED_MODE __constant_cpu_to_le32(0x401E031E)
172#define STATUS_GRAPHICS_DATASET_IS_EMPTY __constant_cpu_to_le32(0x401E034B)
173#define STATUS_GRAPHICS_NO_MORE_ELEMENTS_IN_DATASET __constant_cpu_to_le32(0x401E034C)
174#define STATUS_GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_PINNED __constant_cpu_to_le32(0x401E0351)
175#define STATUS_GRAPHICS_UNKNOWN_CHILD_STATUS __constant_cpu_to_le32(0x401E042F)
176#define STATUS_GRAPHICS_LEADLINK_START_DEFERRED __constant_cpu_to_le32(0x401E0437)
177#define STATUS_GRAPHICS_POLLING_TOO_FREQUENTLY __constant_cpu_to_le32(0x401E0439)
178#define STATUS_GRAPHICS_START_DEFERRED __constant_cpu_to_le32(0x401E043A)
179#define STATUS_NDIS_INDICATION_REQUIRED __constant_cpu_to_le32(0x40230001)
180#define STATUS_GUARD_PAGE_VIOLATION __constant_cpu_to_le32(0x80000001)
181#define STATUS_DATATYPE_MISALIGNMENT __constant_cpu_to_le32(0x80000002)
182#define STATUS_BREAKPOINT __constant_cpu_to_le32(0x80000003)
183#define STATUS_SINGLE_STEP __constant_cpu_to_le32(0x80000004)
184#define STATUS_BUFFER_OVERFLOW __constant_cpu_to_le32(0x80000005)
185#define STATUS_NO_MORE_FILES __constant_cpu_to_le32(0x80000006)
186#define STATUS_WAKE_SYSTEM_DEBUGGER __constant_cpu_to_le32(0x80000007)
187#define STATUS_HANDLES_CLOSED __constant_cpu_to_le32(0x8000000A)
188#define STATUS_NO_INHERITANCE __constant_cpu_to_le32(0x8000000B)
189#define STATUS_GUID_SUBSTITUTION_MADE __constant_cpu_to_le32(0x8000000C)
190#define STATUS_PARTIAL_COPY __constant_cpu_to_le32(0x8000000D)
191#define STATUS_DEVICE_PAPER_EMPTY __constant_cpu_to_le32(0x8000000E)
192#define STATUS_DEVICE_POWERED_OFF __constant_cpu_to_le32(0x8000000F)
193#define STATUS_DEVICE_OFF_LINE __constant_cpu_to_le32(0x80000010)
194#define STATUS_DEVICE_BUSY __constant_cpu_to_le32(0x80000011)
195#define STATUS_NO_MORE_EAS __constant_cpu_to_le32(0x80000012)
196#define STATUS_INVALID_EA_NAME __constant_cpu_to_le32(0x80000013)
197#define STATUS_EA_LIST_INCONSISTENT __constant_cpu_to_le32(0x80000014)
198#define STATUS_INVALID_EA_FLAG __constant_cpu_to_le32(0x80000015)
199#define STATUS_VERIFY_REQUIRED __constant_cpu_to_le32(0x80000016)
200#define STATUS_EXTRANEOUS_INFORMATION __constant_cpu_to_le32(0x80000017)
201#define STATUS_RXACT_COMMIT_NECESSARY __constant_cpu_to_le32(0x80000018)
202#define STATUS_NO_MORE_ENTRIES __constant_cpu_to_le32(0x8000001A)
203#define STATUS_FILEMARK_DETECTED __constant_cpu_to_le32(0x8000001B)
204#define STATUS_MEDIA_CHANGED __constant_cpu_to_le32(0x8000001C)
205#define STATUS_BUS_RESET __constant_cpu_to_le32(0x8000001D)
206#define STATUS_END_OF_MEDIA __constant_cpu_to_le32(0x8000001E)
207#define STATUS_BEGINNING_OF_MEDIA __constant_cpu_to_le32(0x8000001F)
208#define STATUS_MEDIA_CHECK __constant_cpu_to_le32(0x80000020)
209#define STATUS_SETMARK_DETECTED __constant_cpu_to_le32(0x80000021)
210#define STATUS_NO_DATA_DETECTED __constant_cpu_to_le32(0x80000022)
211#define STATUS_REDIRECTOR_HAS_OPEN_HANDLES __constant_cpu_to_le32(0x80000023)
212#define STATUS_SERVER_HAS_OPEN_HANDLES __constant_cpu_to_le32(0x80000024)
213#define STATUS_ALREADY_DISCONNECTED __constant_cpu_to_le32(0x80000025)
214#define STATUS_LONGJUMP __constant_cpu_to_le32(0x80000026)
215#define STATUS_CLEANER_CARTRIDGE_INSTALLED __constant_cpu_to_le32(0x80000027)
216#define STATUS_PLUGPLAY_QUERY_VETOED __constant_cpu_to_le32(0x80000028)
217#define STATUS_UNWIND_CONSOLIDATE __constant_cpu_to_le32(0x80000029)
218#define STATUS_REGISTRY_HIVE_RECOVERED __constant_cpu_to_le32(0x8000002A)
219#define STATUS_DLL_MIGHT_BE_INSECURE __constant_cpu_to_le32(0x8000002B)
220#define STATUS_DLL_MIGHT_BE_INCOMPATIBLE __constant_cpu_to_le32(0x8000002C)
221#define STATUS_STOPPED_ON_SYMLINK __constant_cpu_to_le32(0x8000002D)
222#define STATUS_DEVICE_REQUIRES_CLEANING __constant_cpu_to_le32(0x80000288)
223#define STATUS_DEVICE_DOOR_OPEN __constant_cpu_to_le32(0x80000289)
224#define STATUS_DATA_LOST_REPAIR __constant_cpu_to_le32(0x80000803)
225#define DBG_EXCEPTION_NOT_HANDLED __constant_cpu_to_le32(0x80010001)
226#define STATUS_CLUSTER_NODE_ALREADY_UP __constant_cpu_to_le32(0x80130001)
227#define STATUS_CLUSTER_NODE_ALREADY_DOWN __constant_cpu_to_le32(0x80130002)
228#define STATUS_CLUSTER_NETWORK_ALREADY_ONLINE __constant_cpu_to_le32(0x80130003)
229#define STATUS_CLUSTER_NETWORK_ALREADY_OFFLINE __constant_cpu_to_le32(0x80130004)
230#define STATUS_CLUSTER_NODE_ALREADY_MEMBER __constant_cpu_to_le32(0x80130005)
231#define STATUS_COULD_NOT_RESIZE_LOG __constant_cpu_to_le32(0x80190009)
232#define STATUS_NO_TXF_METADATA __constant_cpu_to_le32(0x80190029)
233#define STATUS_CANT_RECOVER_WITH_HANDLE_OPEN __constant_cpu_to_le32(0x80190031)
234#define STATUS_TXF_METADATA_ALREADY_PRESENT __constant_cpu_to_le32(0x80190041)
235#define STATUS_TRANSACTION_SCOPE_CALLBACKS_NOT_SET __constant_cpu_to_le32(0x80190042)
236#define STATUS_VIDEO_HUNG_DISPLAY_DRIVER_THREAD_RECOVERED __constant_cpu_to_le32(0x801B00EB)
237#define STATUS_FLT_BUFFER_TOO_SMALL __constant_cpu_to_le32(0x801C0001)
238#define STATUS_FVE_PARTIAL_METADATA __constant_cpu_to_le32(0x80210001)
239#define STATUS_UNSUCCESSFUL __constant_cpu_to_le32(0xC0000001)
240#define STATUS_NOT_IMPLEMENTED __constant_cpu_to_le32(0xC0000002)
241#define STATUS_INVALID_INFO_CLASS __constant_cpu_to_le32(0xC0000003)
242#define STATUS_INFO_LENGTH_MISMATCH __constant_cpu_to_le32(0xC0000004)
243#define STATUS_ACCESS_VIOLATION __constant_cpu_to_le32(0xC0000005)
244#define STATUS_IN_PAGE_ERROR __constant_cpu_to_le32(0xC0000006)
245#define STATUS_PAGEFILE_QUOTA __constant_cpu_to_le32(0xC0000007)
246#define STATUS_INVALID_HANDLE __constant_cpu_to_le32(0xC0000008)
247#define STATUS_BAD_INITIAL_STACK __constant_cpu_to_le32(0xC0000009)
248#define STATUS_BAD_INITIAL_PC __constant_cpu_to_le32(0xC000000A)
249#define STATUS_INVALID_CID __constant_cpu_to_le32(0xC000000B)
250#define STATUS_TIMER_NOT_CANCELED __constant_cpu_to_le32(0xC000000C)
251#define STATUS_INVALID_PARAMETER __constant_cpu_to_le32(0xC000000D)
252#define STATUS_NO_SUCH_DEVICE __constant_cpu_to_le32(0xC000000E)
253#define STATUS_NO_SUCH_FILE __constant_cpu_to_le32(0xC000000F)
254#define STATUS_INVALID_DEVICE_REQUEST __constant_cpu_to_le32(0xC0000010)
255#define STATUS_END_OF_FILE __constant_cpu_to_le32(0xC0000011)
256#define STATUS_WRONG_VOLUME __constant_cpu_to_le32(0xC0000012)
257#define STATUS_NO_MEDIA_IN_DEVICE __constant_cpu_to_le32(0xC0000013)
258#define STATUS_UNRECOGNIZED_MEDIA __constant_cpu_to_le32(0xC0000014)
259#define STATUS_NONEXISTENT_SECTOR __constant_cpu_to_le32(0xC0000015)
260#define STATUS_MORE_PROCESSING_REQUIRED __constant_cpu_to_le32(0xC0000016)
261#define STATUS_NO_MEMORY __constant_cpu_to_le32(0xC0000017)
262#define STATUS_CONFLICTING_ADDRESSES __constant_cpu_to_le32(0xC0000018)
263#define STATUS_NOT_MAPPED_VIEW __constant_cpu_to_le32(0xC0000019)
264#define STATUS_UNABLE_TO_FREE_VM __constant_cpu_to_le32(0xC000001A)
265#define STATUS_UNABLE_TO_DELETE_SECTION __constant_cpu_to_le32(0xC000001B)
266#define STATUS_INVALID_SYSTEM_SERVICE __constant_cpu_to_le32(0xC000001C)
267#define STATUS_ILLEGAL_INSTRUCTION __constant_cpu_to_le32(0xC000001D)
268#define STATUS_INVALID_LOCK_SEQUENCE __constant_cpu_to_le32(0xC000001E)
269#define STATUS_INVALID_VIEW_SIZE __constant_cpu_to_le32(0xC000001F)
270#define STATUS_INVALID_FILE_FOR_SECTION __constant_cpu_to_le32(0xC0000020)
271#define STATUS_ALREADY_COMMITTED __constant_cpu_to_le32(0xC0000021)
272#define STATUS_ACCESS_DENIED __constant_cpu_to_le32(0xC0000022)
273#define STATUS_BUFFER_TOO_SMALL __constant_cpu_to_le32(0xC0000023)
274#define STATUS_OBJECT_TYPE_MISMATCH __constant_cpu_to_le32(0xC0000024)
275#define STATUS_NONCONTINUABLE_EXCEPTION __constant_cpu_to_le32(0xC0000025)
276#define STATUS_INVALID_DISPOSITION __constant_cpu_to_le32(0xC0000026)
277#define STATUS_UNWIND __constant_cpu_to_le32(0xC0000027)
278#define STATUS_BAD_STACK __constant_cpu_to_le32(0xC0000028)
279#define STATUS_INVALID_UNWIND_TARGET __constant_cpu_to_le32(0xC0000029)
280#define STATUS_NOT_LOCKED __constant_cpu_to_le32(0xC000002A)
281#define STATUS_PARITY_ERROR __constant_cpu_to_le32(0xC000002B)
282#define STATUS_UNABLE_TO_DECOMMIT_VM __constant_cpu_to_le32(0xC000002C)
283#define STATUS_NOT_COMMITTED __constant_cpu_to_le32(0xC000002D)
284#define STATUS_INVALID_PORT_ATTRIBUTES __constant_cpu_to_le32(0xC000002E)
285#define STATUS_PORT_MESSAGE_TOO_LONG __constant_cpu_to_le32(0xC000002F)
286#define STATUS_INVALID_PARAMETER_MIX __constant_cpu_to_le32(0xC0000030)
287#define STATUS_INVALID_QUOTA_LOWER __constant_cpu_to_le32(0xC0000031)
288#define STATUS_DISK_CORRUPT_ERROR __constant_cpu_to_le32(0xC0000032)
289#define STATUS_OBJECT_NAME_INVALID __constant_cpu_to_le32(0xC0000033)
290#define STATUS_OBJECT_NAME_NOT_FOUND __constant_cpu_to_le32(0xC0000034)
291#define STATUS_OBJECT_NAME_COLLISION __constant_cpu_to_le32(0xC0000035)
292#define STATUS_PORT_DISCONNECTED __constant_cpu_to_le32(0xC0000037)
293#define STATUS_DEVICE_ALREADY_ATTACHED __constant_cpu_to_le32(0xC0000038)
294#define STATUS_OBJECT_PATH_INVALID __constant_cpu_to_le32(0xC0000039)
295#define STATUS_OBJECT_PATH_NOT_FOUND __constant_cpu_to_le32(0xC000003A)
296#define STATUS_OBJECT_PATH_SYNTAX_BAD __constant_cpu_to_le32(0xC000003B)
297#define STATUS_DATA_OVERRUN __constant_cpu_to_le32(0xC000003C)
298#define STATUS_DATA_LATE_ERROR __constant_cpu_to_le32(0xC000003D)
299#define STATUS_DATA_ERROR __constant_cpu_to_le32(0xC000003E)
300#define STATUS_CRC_ERROR __constant_cpu_to_le32(0xC000003F)
301#define STATUS_SECTION_TOO_BIG __constant_cpu_to_le32(0xC0000040)
302#define STATUS_PORT_CONNECTION_REFUSED __constant_cpu_to_le32(0xC0000041)
303#define STATUS_INVALID_PORT_HANDLE __constant_cpu_to_le32(0xC0000042)
304#define STATUS_SHARING_VIOLATION __constant_cpu_to_le32(0xC0000043)
305#define STATUS_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000044)
306#define STATUS_INVALID_PAGE_PROTECTION __constant_cpu_to_le32(0xC0000045)
307#define STATUS_MUTANT_NOT_OWNED __constant_cpu_to_le32(0xC0000046)
308#define STATUS_SEMAPHORE_LIMIT_EXCEEDED __constant_cpu_to_le32(0xC0000047)
309#define STATUS_PORT_ALREADY_SET __constant_cpu_to_le32(0xC0000048)
310#define STATUS_SECTION_NOT_IMAGE __constant_cpu_to_le32(0xC0000049)
311#define STATUS_SUSPEND_COUNT_EXCEEDED __constant_cpu_to_le32(0xC000004A)
312#define STATUS_THREAD_IS_TERMINATING __constant_cpu_to_le32(0xC000004B)
313#define STATUS_BAD_WORKING_SET_LIMIT __constant_cpu_to_le32(0xC000004C)
314#define STATUS_INCOMPATIBLE_FILE_MAP __constant_cpu_to_le32(0xC000004D)
315#define STATUS_SECTION_PROTECTION __constant_cpu_to_le32(0xC000004E)
316#define STATUS_EAS_NOT_SUPPORTED __constant_cpu_to_le32(0xC000004F)
317#define STATUS_EA_TOO_LARGE __constant_cpu_to_le32(0xC0000050)
318#define STATUS_NONEXISTENT_EA_ENTRY __constant_cpu_to_le32(0xC0000051)
319#define STATUS_NO_EAS_ON_FILE __constant_cpu_to_le32(0xC0000052)
320#define STATUS_EA_CORRUPT_ERROR __constant_cpu_to_le32(0xC0000053)
321#define STATUS_FILE_LOCK_CONFLICT __constant_cpu_to_le32(0xC0000054)
322#define STATUS_LOCK_NOT_GRANTED __constant_cpu_to_le32(0xC0000055)
323#define STATUS_DELETE_PENDING __constant_cpu_to_le32(0xC0000056)
324#define STATUS_CTL_FILE_NOT_SUPPORTED __constant_cpu_to_le32(0xC0000057)
325#define STATUS_UNKNOWN_REVISION __constant_cpu_to_le32(0xC0000058)
326#define STATUS_REVISION_MISMATCH __constant_cpu_to_le32(0xC0000059)
327#define STATUS_INVALID_OWNER __constant_cpu_to_le32(0xC000005A)
328#define STATUS_INVALID_PRIMARY_GROUP __constant_cpu_to_le32(0xC000005B)
329#define STATUS_NO_IMPERSONATION_TOKEN __constant_cpu_to_le32(0xC000005C)
330#define STATUS_CANT_DISABLE_MANDATORY __constant_cpu_to_le32(0xC000005D)
331#define STATUS_NO_LOGON_SERVERS __constant_cpu_to_le32(0xC000005E)
332#define STATUS_NO_SUCH_LOGON_SESSION __constant_cpu_to_le32(0xC000005F)
333#define STATUS_NO_SUCH_PRIVILEGE __constant_cpu_to_le32(0xC0000060)
334#define STATUS_PRIVILEGE_NOT_HELD __constant_cpu_to_le32(0xC0000061)
335#define STATUS_INVALID_ACCOUNT_NAME __constant_cpu_to_le32(0xC0000062)
336#define STATUS_USER_EXISTS __constant_cpu_to_le32(0xC0000063)
337#define STATUS_NO_SUCH_USER __constant_cpu_to_le32(0xC0000064)
338#define STATUS_GROUP_EXISTS __constant_cpu_to_le32(0xC0000065)
339#define STATUS_NO_SUCH_GROUP __constant_cpu_to_le32(0xC0000066)
340#define STATUS_MEMBER_IN_GROUP __constant_cpu_to_le32(0xC0000067)
341#define STATUS_MEMBER_NOT_IN_GROUP __constant_cpu_to_le32(0xC0000068)
342#define STATUS_LAST_ADMIN __constant_cpu_to_le32(0xC0000069)
343#define STATUS_WRONG_PASSWORD __constant_cpu_to_le32(0xC000006A)
344#define STATUS_ILL_FORMED_PASSWORD __constant_cpu_to_le32(0xC000006B)
345#define STATUS_PASSWORD_RESTRICTION __constant_cpu_to_le32(0xC000006C)
346#define STATUS_LOGON_FAILURE __constant_cpu_to_le32(0xC000006D)
347#define STATUS_ACCOUNT_RESTRICTION __constant_cpu_to_le32(0xC000006E)
348#define STATUS_INVALID_LOGON_HOURS __constant_cpu_to_le32(0xC000006F)
349#define STATUS_INVALID_WORKSTATION __constant_cpu_to_le32(0xC0000070)
350#define STATUS_PASSWORD_EXPIRED __constant_cpu_to_le32(0xC0000071)
351#define STATUS_ACCOUNT_DISABLED __constant_cpu_to_le32(0xC0000072)
352#define STATUS_NONE_MAPPED __constant_cpu_to_le32(0xC0000073)
353#define STATUS_TOO_MANY_LUIDS_REQUESTED __constant_cpu_to_le32(0xC0000074)
354#define STATUS_LUIDS_EXHAUSTED __constant_cpu_to_le32(0xC0000075)
355#define STATUS_INVALID_SUB_AUTHORITY __constant_cpu_to_le32(0xC0000076)
356#define STATUS_INVALID_ACL __constant_cpu_to_le32(0xC0000077)
357#define STATUS_INVALID_SID __constant_cpu_to_le32(0xC0000078)
358#define STATUS_INVALID_SECURITY_DESCR __constant_cpu_to_le32(0xC0000079)
359#define STATUS_PROCEDURE_NOT_FOUND __constant_cpu_to_le32(0xC000007A)
360#define STATUS_INVALID_IMAGE_FORMAT __constant_cpu_to_le32(0xC000007B)
361#define STATUS_NO_TOKEN __constant_cpu_to_le32(0xC000007C)
362#define STATUS_BAD_INHERITANCE_ACL __constant_cpu_to_le32(0xC000007D)
363#define STATUS_RANGE_NOT_LOCKED __constant_cpu_to_le32(0xC000007E)
364#define STATUS_DISK_FULL __constant_cpu_to_le32(0xC000007F)
365#define STATUS_SERVER_DISABLED __constant_cpu_to_le32(0xC0000080)
366#define STATUS_SERVER_NOT_DISABLED __constant_cpu_to_le32(0xC0000081)
367#define STATUS_TOO_MANY_GUIDS_REQUESTED __constant_cpu_to_le32(0xC0000082)
368#define STATUS_GUIDS_EXHAUSTED __constant_cpu_to_le32(0xC0000083)
369#define STATUS_INVALID_ID_AUTHORITY __constant_cpu_to_le32(0xC0000084)
370#define STATUS_AGENTS_EXHAUSTED __constant_cpu_to_le32(0xC0000085)
371#define STATUS_INVALID_VOLUME_LABEL __constant_cpu_to_le32(0xC0000086)
372#define STATUS_SECTION_NOT_EXTENDED __constant_cpu_to_le32(0xC0000087)
373#define STATUS_NOT_MAPPED_DATA __constant_cpu_to_le32(0xC0000088)
374#define STATUS_RESOURCE_DATA_NOT_FOUND __constant_cpu_to_le32(0xC0000089)
375#define STATUS_RESOURCE_TYPE_NOT_FOUND __constant_cpu_to_le32(0xC000008A)
376#define STATUS_RESOURCE_NAME_NOT_FOUND __constant_cpu_to_le32(0xC000008B)
377#define STATUS_ARRAY_BOUNDS_EXCEEDED __constant_cpu_to_le32(0xC000008C)
378#define STATUS_FLOAT_DENORMAL_OPERAND __constant_cpu_to_le32(0xC000008D)
379#define STATUS_FLOAT_DIVIDE_BY_ZERO __constant_cpu_to_le32(0xC000008E)
380#define STATUS_FLOAT_INEXACT_RESULT __constant_cpu_to_le32(0xC000008F)
381#define STATUS_FLOAT_INVALID_OPERATION __constant_cpu_to_le32(0xC0000090)
382#define STATUS_FLOAT_OVERFLOW __constant_cpu_to_le32(0xC0000091)
383#define STATUS_FLOAT_STACK_CHECK __constant_cpu_to_le32(0xC0000092)
384#define STATUS_FLOAT_UNDERFLOW __constant_cpu_to_le32(0xC0000093)
385#define STATUS_INTEGER_DIVIDE_BY_ZERO __constant_cpu_to_le32(0xC0000094)
386#define STATUS_INTEGER_OVERFLOW __constant_cpu_to_le32(0xC0000095)
387#define STATUS_PRIVILEGED_INSTRUCTION __constant_cpu_to_le32(0xC0000096)
388#define STATUS_TOO_MANY_PAGING_FILES __constant_cpu_to_le32(0xC0000097)
389#define STATUS_FILE_INVALID __constant_cpu_to_le32(0xC0000098)
390#define STATUS_ALLOTTED_SPACE_EXCEEDED __constant_cpu_to_le32(0xC0000099)
391#define STATUS_INSUFFICIENT_RESOURCES __constant_cpu_to_le32(0xC000009A)
392#define STATUS_DFS_EXIT_PATH_FOUND __constant_cpu_to_le32(0xC000009B)
393#define STATUS_DEVICE_DATA_ERROR __constant_cpu_to_le32(0xC000009C)
394#define STATUS_DEVICE_NOT_CONNECTED __constant_cpu_to_le32(0xC000009D)
395#define STATUS_DEVICE_POWER_FAILURE __constant_cpu_to_le32(0xC000009E)
396#define STATUS_FREE_VM_NOT_AT_BASE __constant_cpu_to_le32(0xC000009F)
397#define STATUS_MEMORY_NOT_ALLOCATED __constant_cpu_to_le32(0xC00000A0)
398#define STATUS_WORKING_SET_QUOTA __constant_cpu_to_le32(0xC00000A1)
399#define STATUS_MEDIA_WRITE_PROTECTED __constant_cpu_to_le32(0xC00000A2)
400#define STATUS_DEVICE_NOT_READY __constant_cpu_to_le32(0xC00000A3)
401#define STATUS_INVALID_GROUP_ATTRIBUTES __constant_cpu_to_le32(0xC00000A4)
402#define STATUS_BAD_IMPERSONATION_LEVEL __constant_cpu_to_le32(0xC00000A5)
403#define STATUS_CANT_OPEN_ANONYMOUS __constant_cpu_to_le32(0xC00000A6)
404#define STATUS_BAD_VALIDATION_CLASS __constant_cpu_to_le32(0xC00000A7)
405#define STATUS_BAD_TOKEN_TYPE __constant_cpu_to_le32(0xC00000A8)
406#define STATUS_BAD_MASTER_BOOT_RECORD __constant_cpu_to_le32(0xC00000A9)
407#define STATUS_INSTRUCTION_MISALIGNMENT __constant_cpu_to_le32(0xC00000AA)
408#define STATUS_INSTANCE_NOT_AVAILABLE __constant_cpu_to_le32(0xC00000AB)
409#define STATUS_PIPE_NOT_AVAILABLE __constant_cpu_to_le32(0xC00000AC)
410#define STATUS_INVALID_PIPE_STATE __constant_cpu_to_le32(0xC00000AD)
411#define STATUS_PIPE_BUSY __constant_cpu_to_le32(0xC00000AE)
412#define STATUS_ILLEGAL_FUNCTION __constant_cpu_to_le32(0xC00000AF)
413#define STATUS_PIPE_DISCONNECTED __constant_cpu_to_le32(0xC00000B0)
414#define STATUS_PIPE_CLOSING __constant_cpu_to_le32(0xC00000B1)
415#define STATUS_PIPE_CONNECTED __constant_cpu_to_le32(0xC00000B2)
416#define STATUS_PIPE_LISTENING __constant_cpu_to_le32(0xC00000B3)
417#define STATUS_INVALID_READ_MODE __constant_cpu_to_le32(0xC00000B4)
418#define STATUS_IO_TIMEOUT __constant_cpu_to_le32(0xC00000B5)
419#define STATUS_FILE_FORCED_CLOSED __constant_cpu_to_le32(0xC00000B6)
420#define STATUS_PROFILING_NOT_STARTED __constant_cpu_to_le32(0xC00000B7)
421#define STATUS_PROFILING_NOT_STOPPED __constant_cpu_to_le32(0xC00000B8)
422#define STATUS_COULD_NOT_INTERPRET __constant_cpu_to_le32(0xC00000B9)
423#define STATUS_FILE_IS_A_DIRECTORY __constant_cpu_to_le32(0xC00000BA)
424#define STATUS_NOT_SUPPORTED __constant_cpu_to_le32(0xC00000BB)
425#define STATUS_REMOTE_NOT_LISTENING __constant_cpu_to_le32(0xC00000BC)
426#define STATUS_DUPLICATE_NAME __constant_cpu_to_le32(0xC00000BD)
427#define STATUS_BAD_NETWORK_PATH __constant_cpu_to_le32(0xC00000BE)
428#define STATUS_NETWORK_BUSY __constant_cpu_to_le32(0xC00000BF)
429#define STATUS_DEVICE_DOES_NOT_EXIST __constant_cpu_to_le32(0xC00000C0)
430#define STATUS_TOO_MANY_COMMANDS __constant_cpu_to_le32(0xC00000C1)
431#define STATUS_ADAPTER_HARDWARE_ERROR __constant_cpu_to_le32(0xC00000C2)
432#define STATUS_INVALID_NETWORK_RESPONSE __constant_cpu_to_le32(0xC00000C3)
433#define STATUS_UNEXPECTED_NETWORK_ERROR __constant_cpu_to_le32(0xC00000C4)
434#define STATUS_BAD_REMOTE_ADAPTER __constant_cpu_to_le32(0xC00000C5)
435#define STATUS_PRINT_QUEUE_FULL __constant_cpu_to_le32(0xC00000C6)
436#define STATUS_NO_SPOOL_SPACE __constant_cpu_to_le32(0xC00000C7)
437#define STATUS_PRINT_CANCELLED __constant_cpu_to_le32(0xC00000C8)
438#define STATUS_NETWORK_NAME_DELETED __constant_cpu_to_le32(0xC00000C9)
439#define STATUS_NETWORK_ACCESS_DENIED __constant_cpu_to_le32(0xC00000CA)
440#define STATUS_BAD_DEVICE_TYPE __constant_cpu_to_le32(0xC00000CB)
441#define STATUS_BAD_NETWORK_NAME __constant_cpu_to_le32(0xC00000CC)
442#define STATUS_TOO_MANY_NAMES __constant_cpu_to_le32(0xC00000CD)
443#define STATUS_TOO_MANY_SESSIONS __constant_cpu_to_le32(0xC00000CE)
444#define STATUS_SHARING_PAUSED __constant_cpu_to_le32(0xC00000CF)
445#define STATUS_REQUEST_NOT_ACCEPTED __constant_cpu_to_le32(0xC00000D0)
446#define STATUS_REDIRECTOR_PAUSED __constant_cpu_to_le32(0xC00000D1)
447#define STATUS_NET_WRITE_FAULT __constant_cpu_to_le32(0xC00000D2)
448#define STATUS_PROFILING_AT_LIMIT __constant_cpu_to_le32(0xC00000D3)
449#define STATUS_NOT_SAME_DEVICE __constant_cpu_to_le32(0xC00000D4)
450#define STATUS_FILE_RENAMED __constant_cpu_to_le32(0xC00000D5)
451#define STATUS_VIRTUAL_CIRCUIT_CLOSED __constant_cpu_to_le32(0xC00000D6)
452#define STATUS_NO_SECURITY_ON_OBJECT __constant_cpu_to_le32(0xC00000D7)
453#define STATUS_CANT_WAIT __constant_cpu_to_le32(0xC00000D8)
454#define STATUS_PIPE_EMPTY __constant_cpu_to_le32(0xC00000D9)
455#define STATUS_CANT_ACCESS_DOMAIN_INFO __constant_cpu_to_le32(0xC00000DA)
456#define STATUS_CANT_TERMINATE_SELF __constant_cpu_to_le32(0xC00000DB)
457#define STATUS_INVALID_SERVER_STATE __constant_cpu_to_le32(0xC00000DC)
458#define STATUS_INVALID_DOMAIN_STATE __constant_cpu_to_le32(0xC00000DD)
459#define STATUS_INVALID_DOMAIN_ROLE __constant_cpu_to_le32(0xC00000DE)
460#define STATUS_NO_SUCH_DOMAIN __constant_cpu_to_le32(0xC00000DF)
461#define STATUS_DOMAIN_EXISTS __constant_cpu_to_le32(0xC00000E0)
462#define STATUS_DOMAIN_LIMIT_EXCEEDED __constant_cpu_to_le32(0xC00000E1)
463#define STATUS_OPLOCK_NOT_GRANTED __constant_cpu_to_le32(0xC00000E2)
464#define STATUS_INVALID_OPLOCK_PROTOCOL __constant_cpu_to_le32(0xC00000E3)
465#define STATUS_INTERNAL_DB_CORRUPTION __constant_cpu_to_le32(0xC00000E4)
466#define STATUS_INTERNAL_ERROR __constant_cpu_to_le32(0xC00000E5)
467#define STATUS_GENERIC_NOT_MAPPED __constant_cpu_to_le32(0xC00000E6)
468#define STATUS_BAD_DESCRIPTOR_FORMAT __constant_cpu_to_le32(0xC00000E7)
469#define STATUS_INVALID_USER_BUFFER __constant_cpu_to_le32(0xC00000E8)
470#define STATUS_UNEXPECTED_IO_ERROR __constant_cpu_to_le32(0xC00000E9)
471#define STATUS_UNEXPECTED_MM_CREATE_ERR __constant_cpu_to_le32(0xC00000EA)
472#define STATUS_UNEXPECTED_MM_MAP_ERROR __constant_cpu_to_le32(0xC00000EB)
473#define STATUS_UNEXPECTED_MM_EXTEND_ERR __constant_cpu_to_le32(0xC00000EC)
474#define STATUS_NOT_LOGON_PROCESS __constant_cpu_to_le32(0xC00000ED)
475#define STATUS_LOGON_SESSION_EXISTS __constant_cpu_to_le32(0xC00000EE)
476#define STATUS_INVALID_PARAMETER_1 __constant_cpu_to_le32(0xC00000EF)
477#define STATUS_INVALID_PARAMETER_2 __constant_cpu_to_le32(0xC00000F0)
478#define STATUS_INVALID_PARAMETER_3 __constant_cpu_to_le32(0xC00000F1)
479#define STATUS_INVALID_PARAMETER_4 __constant_cpu_to_le32(0xC00000F2)
480#define STATUS_INVALID_PARAMETER_5 __constant_cpu_to_le32(0xC00000F3)
481#define STATUS_INVALID_PARAMETER_6 __constant_cpu_to_le32(0xC00000F4)
482#define STATUS_INVALID_PARAMETER_7 __constant_cpu_to_le32(0xC00000F5)
483#define STATUS_INVALID_PARAMETER_8 __constant_cpu_to_le32(0xC00000F6)
484#define STATUS_INVALID_PARAMETER_9 __constant_cpu_to_le32(0xC00000F7)
485#define STATUS_INVALID_PARAMETER_10 __constant_cpu_to_le32(0xC00000F8)
486#define STATUS_INVALID_PARAMETER_11 __constant_cpu_to_le32(0xC00000F9)
487#define STATUS_INVALID_PARAMETER_12 __constant_cpu_to_le32(0xC00000FA)
488#define STATUS_REDIRECTOR_NOT_STARTED __constant_cpu_to_le32(0xC00000FB)
489#define STATUS_REDIRECTOR_STARTED __constant_cpu_to_le32(0xC00000FC)
490#define STATUS_STACK_OVERFLOW __constant_cpu_to_le32(0xC00000FD)
491#define STATUS_NO_SUCH_PACKAGE __constant_cpu_to_le32(0xC00000FE)
492#define STATUS_BAD_FUNCTION_TABLE __constant_cpu_to_le32(0xC00000FF)
493#define STATUS_VARIABLE_NOT_FOUND __constant_cpu_to_le32(0xC0000100)
494#define STATUS_DIRECTORY_NOT_EMPTY __constant_cpu_to_le32(0xC0000101)
495#define STATUS_FILE_CORRUPT_ERROR __constant_cpu_to_le32(0xC0000102)
496#define STATUS_NOT_A_DIRECTORY __constant_cpu_to_le32(0xC0000103)
497#define STATUS_BAD_LOGON_SESSION_STATE __constant_cpu_to_le32(0xC0000104)
498#define STATUS_LOGON_SESSION_COLLISION __constant_cpu_to_le32(0xC0000105)
499#define STATUS_NAME_TOO_LONG __constant_cpu_to_le32(0xC0000106)
500#define STATUS_FILES_OPEN __constant_cpu_to_le32(0xC0000107)
501#define STATUS_CONNECTION_IN_USE __constant_cpu_to_le32(0xC0000108)
502#define STATUS_MESSAGE_NOT_FOUND __constant_cpu_to_le32(0xC0000109)
503#define STATUS_PROCESS_IS_TERMINATING __constant_cpu_to_le32(0xC000010A)
504#define STATUS_INVALID_LOGON_TYPE __constant_cpu_to_le32(0xC000010B)
505#define STATUS_NO_GUID_TRANSLATION __constant_cpu_to_le32(0xC000010C)
506#define STATUS_CANNOT_IMPERSONATE __constant_cpu_to_le32(0xC000010D)
507#define STATUS_IMAGE_ALREADY_LOADED __constant_cpu_to_le32(0xC000010E)
508#define STATUS_ABIOS_NOT_PRESENT __constant_cpu_to_le32(0xC000010F)
509#define STATUS_ABIOS_LID_NOT_EXIST __constant_cpu_to_le32(0xC0000110)
510#define STATUS_ABIOS_LID_ALREADY_OWNED __constant_cpu_to_le32(0xC0000111)
511#define STATUS_ABIOS_NOT_LID_OWNER __constant_cpu_to_le32(0xC0000112)
512#define STATUS_ABIOS_INVALID_COMMAND __constant_cpu_to_le32(0xC0000113)
513#define STATUS_ABIOS_INVALID_LID __constant_cpu_to_le32(0xC0000114)
514#define STATUS_ABIOS_SELECTOR_NOT_AVAILABLE __constant_cpu_to_le32(0xC0000115)
515#define STATUS_ABIOS_INVALID_SELECTOR __constant_cpu_to_le32(0xC0000116)
516#define STATUS_NO_LDT __constant_cpu_to_le32(0xC0000117)
517#define STATUS_INVALID_LDT_SIZE __constant_cpu_to_le32(0xC0000118)
518#define STATUS_INVALID_LDT_OFFSET __constant_cpu_to_le32(0xC0000119)
519#define STATUS_INVALID_LDT_DESCRIPTOR __constant_cpu_to_le32(0xC000011A)
520#define STATUS_INVALID_IMAGE_NE_FORMAT __constant_cpu_to_le32(0xC000011B)
521#define STATUS_RXACT_INVALID_STATE __constant_cpu_to_le32(0xC000011C)
522#define STATUS_RXACT_COMMIT_FAILURE __constant_cpu_to_le32(0xC000011D)
523#define STATUS_MAPPED_FILE_SIZE_ZERO __constant_cpu_to_le32(0xC000011E)
524#define STATUS_TOO_MANY_OPENED_FILES __constant_cpu_to_le32(0xC000011F)
525#define STATUS_CANCELLED __constant_cpu_to_le32(0xC0000120)
526#define STATUS_CANNOT_DELETE __constant_cpu_to_le32(0xC0000121)
527#define STATUS_INVALID_COMPUTER_NAME __constant_cpu_to_le32(0xC0000122)
528#define STATUS_FILE_DELETED __constant_cpu_to_le32(0xC0000123)
529#define STATUS_SPECIAL_ACCOUNT __constant_cpu_to_le32(0xC0000124)
530#define STATUS_SPECIAL_GROUP __constant_cpu_to_le32(0xC0000125)
531#define STATUS_SPECIAL_USER __constant_cpu_to_le32(0xC0000126)
532#define STATUS_MEMBERS_PRIMARY_GROUP __constant_cpu_to_le32(0xC0000127)
533#define STATUS_FILE_CLOSED __constant_cpu_to_le32(0xC0000128)
534#define STATUS_TOO_MANY_THREADS __constant_cpu_to_le32(0xC0000129)
535#define STATUS_THREAD_NOT_IN_PROCESS __constant_cpu_to_le32(0xC000012A)
536#define STATUS_TOKEN_ALREADY_IN_USE __constant_cpu_to_le32(0xC000012B)
537#define STATUS_PAGEFILE_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC000012C)
538#define STATUS_COMMITMENT_LIMIT __constant_cpu_to_le32(0xC000012D)
539#define STATUS_INVALID_IMAGE_LE_FORMAT __constant_cpu_to_le32(0xC000012E)
540#define STATUS_INVALID_IMAGE_NOT_MZ __constant_cpu_to_le32(0xC000012F)
541#define STATUS_INVALID_IMAGE_PROTECT __constant_cpu_to_le32(0xC0000130)
542#define STATUS_INVALID_IMAGE_WIN_16 __constant_cpu_to_le32(0xC0000131)
543#define STATUS_LOGON_SERVER_CONFLICT __constant_cpu_to_le32(0xC0000132)
544#define STATUS_TIME_DIFFERENCE_AT_DC __constant_cpu_to_le32(0xC0000133)
545#define STATUS_SYNCHRONIZATION_REQUIRED __constant_cpu_to_le32(0xC0000134)
546#define STATUS_DLL_NOT_FOUND __constant_cpu_to_le32(0xC0000135)
547#define STATUS_OPEN_FAILED __constant_cpu_to_le32(0xC0000136)
548#define STATUS_IO_PRIVILEGE_FAILED __constant_cpu_to_le32(0xC0000137)
549#define STATUS_ORDINAL_NOT_FOUND __constant_cpu_to_le32(0xC0000138)
550#define STATUS_ENTRYPOINT_NOT_FOUND __constant_cpu_to_le32(0xC0000139)
551#define STATUS_CONTROL_C_EXIT __constant_cpu_to_le32(0xC000013A)
552#define STATUS_LOCAL_DISCONNECT __constant_cpu_to_le32(0xC000013B)
553#define STATUS_REMOTE_DISCONNECT __constant_cpu_to_le32(0xC000013C)
554#define STATUS_REMOTE_RESOURCES __constant_cpu_to_le32(0xC000013D)
555#define STATUS_LINK_FAILED __constant_cpu_to_le32(0xC000013E)
556#define STATUS_LINK_TIMEOUT __constant_cpu_to_le32(0xC000013F)
557#define STATUS_INVALID_CONNECTION __constant_cpu_to_le32(0xC0000140)
558#define STATUS_INVALID_ADDRESS __constant_cpu_to_le32(0xC0000141)
559#define STATUS_DLL_INIT_FAILED __constant_cpu_to_le32(0xC0000142)
560#define STATUS_MISSING_SYSTEMFILE __constant_cpu_to_le32(0xC0000143)
561#define STATUS_UNHANDLED_EXCEPTION __constant_cpu_to_le32(0xC0000144)
562#define STATUS_APP_INIT_FAILURE __constant_cpu_to_le32(0xC0000145)
563#define STATUS_PAGEFILE_CREATE_FAILED __constant_cpu_to_le32(0xC0000146)
564#define STATUS_NO_PAGEFILE __constant_cpu_to_le32(0xC0000147)
565#define STATUS_INVALID_LEVEL __constant_cpu_to_le32(0xC0000148)
566#define STATUS_WRONG_PASSWORD_CORE __constant_cpu_to_le32(0xC0000149)
567#define STATUS_ILLEGAL_FLOAT_CONTEXT __constant_cpu_to_le32(0xC000014A)
568#define STATUS_PIPE_BROKEN __constant_cpu_to_le32(0xC000014B)
569#define STATUS_REGISTRY_CORRUPT __constant_cpu_to_le32(0xC000014C)
570#define STATUS_REGISTRY_IO_FAILED __constant_cpu_to_le32(0xC000014D)
571#define STATUS_NO_EVENT_PAIR __constant_cpu_to_le32(0xC000014E)
572#define STATUS_UNRECOGNIZED_VOLUME __constant_cpu_to_le32(0xC000014F)
573#define STATUS_SERIAL_NO_DEVICE_INITED __constant_cpu_to_le32(0xC0000150)
574#define STATUS_NO_SUCH_ALIAS __constant_cpu_to_le32(0xC0000151)
575#define STATUS_MEMBER_NOT_IN_ALIAS __constant_cpu_to_le32(0xC0000152)
576#define STATUS_MEMBER_IN_ALIAS __constant_cpu_to_le32(0xC0000153)
577#define STATUS_ALIAS_EXISTS __constant_cpu_to_le32(0xC0000154)
578#define STATUS_LOGON_NOT_GRANTED __constant_cpu_to_le32(0xC0000155)
579#define STATUS_TOO_MANY_SECRETS __constant_cpu_to_le32(0xC0000156)
580#define STATUS_SECRET_TOO_LONG __constant_cpu_to_le32(0xC0000157)
581#define STATUS_INTERNAL_DB_ERROR __constant_cpu_to_le32(0xC0000158)
582#define STATUS_FULLSCREEN_MODE __constant_cpu_to_le32(0xC0000159)
583#define STATUS_TOO_MANY_CONTEXT_IDS __constant_cpu_to_le32(0xC000015A)
584#define STATUS_LOGON_TYPE_NOT_GRANTED __constant_cpu_to_le32(0xC000015B)
585#define STATUS_NOT_REGISTRY_FILE __constant_cpu_to_le32(0xC000015C)
586#define STATUS_NT_CROSS_ENCRYPTION_REQUIRED __constant_cpu_to_le32(0xC000015D)
587#define STATUS_DOMAIN_CTRLR_CONFIG_ERROR __constant_cpu_to_le32(0xC000015E)
588#define STATUS_FT_MISSING_MEMBER __constant_cpu_to_le32(0xC000015F)
589#define STATUS_ILL_FORMED_SERVICE_ENTRY __constant_cpu_to_le32(0xC0000160)
590#define STATUS_ILLEGAL_CHARACTER __constant_cpu_to_le32(0xC0000161)
591#define STATUS_UNMAPPABLE_CHARACTER __constant_cpu_to_le32(0xC0000162)
592#define STATUS_UNDEFINED_CHARACTER __constant_cpu_to_le32(0xC0000163)
593#define STATUS_FLOPPY_VOLUME __constant_cpu_to_le32(0xC0000164)
594#define STATUS_FLOPPY_ID_MARK_NOT_FOUND __constant_cpu_to_le32(0xC0000165)
595#define STATUS_FLOPPY_WRONG_CYLINDER __constant_cpu_to_le32(0xC0000166)
596#define STATUS_FLOPPY_UNKNOWN_ERROR __constant_cpu_to_le32(0xC0000167)
597#define STATUS_FLOPPY_BAD_REGISTERS __constant_cpu_to_le32(0xC0000168)
598#define STATUS_DISK_RECALIBRATE_FAILED __constant_cpu_to_le32(0xC0000169)
599#define STATUS_DISK_OPERATION_FAILED __constant_cpu_to_le32(0xC000016A)
600#define STATUS_DISK_RESET_FAILED __constant_cpu_to_le32(0xC000016B)
601#define STATUS_SHARED_IRQ_BUSY __constant_cpu_to_le32(0xC000016C)
602#define STATUS_FT_ORPHANING __constant_cpu_to_le32(0xC000016D)
603#define STATUS_BIOS_FAILED_TO_CONNECT_INTERRUPT __constant_cpu_to_le32(0xC000016E)
604#define STATUS_PARTITION_FAILURE __constant_cpu_to_le32(0xC0000172)
605#define STATUS_INVALID_BLOCK_LENGTH __constant_cpu_to_le32(0xC0000173)
606#define STATUS_DEVICE_NOT_PARTITIONED __constant_cpu_to_le32(0xC0000174)
607#define STATUS_UNABLE_TO_LOCK_MEDIA __constant_cpu_to_le32(0xC0000175)
608#define STATUS_UNABLE_TO_UNLOAD_MEDIA __constant_cpu_to_le32(0xC0000176)
609#define STATUS_EOM_OVERFLOW __constant_cpu_to_le32(0xC0000177)
610#define STATUS_NO_MEDIA __constant_cpu_to_le32(0xC0000178)
611#define STATUS_NO_SUCH_MEMBER __constant_cpu_to_le32(0xC000017A)
612#define STATUS_INVALID_MEMBER __constant_cpu_to_le32(0xC000017B)
613#define STATUS_KEY_DELETED __constant_cpu_to_le32(0xC000017C)
614#define STATUS_NO_LOG_SPACE __constant_cpu_to_le32(0xC000017D)
615#define STATUS_TOO_MANY_SIDS __constant_cpu_to_le32(0xC000017E)
616#define STATUS_LM_CROSS_ENCRYPTION_REQUIRED __constant_cpu_to_le32(0xC000017F)
617#define STATUS_KEY_HAS_CHILDREN __constant_cpu_to_le32(0xC0000180)
618#define STATUS_CHILD_MUST_BE_VOLATILE __constant_cpu_to_le32(0xC0000181)
619#define STATUS_DEVICE_CONFIGURATION_ERROR __constant_cpu_to_le32(0xC0000182)
620#define STATUS_DRIVER_INTERNAL_ERROR __constant_cpu_to_le32(0xC0000183)
621#define STATUS_INVALID_DEVICE_STATE __constant_cpu_to_le32(0xC0000184)
622#define STATUS_IO_DEVICE_ERROR __constant_cpu_to_le32(0xC0000185)
623#define STATUS_DEVICE_PROTOCOL_ERROR __constant_cpu_to_le32(0xC0000186)
624#define STATUS_BACKUP_CONTROLLER __constant_cpu_to_le32(0xC0000187)
625#define STATUS_LOG_FILE_FULL __constant_cpu_to_le32(0xC0000188)
626#define STATUS_TOO_LATE __constant_cpu_to_le32(0xC0000189)
627#define STATUS_NO_TRUST_LSA_SECRET __constant_cpu_to_le32(0xC000018A)
628#define STATUS_NO_TRUST_SAM_ACCOUNT __constant_cpu_to_le32(0xC000018B)
629#define STATUS_TRUSTED_DOMAIN_FAILURE __constant_cpu_to_le32(0xC000018C)
630#define STATUS_TRUSTED_RELATIONSHIP_FAILURE __constant_cpu_to_le32(0xC000018D)
631#define STATUS_EVENTLOG_FILE_CORRUPT __constant_cpu_to_le32(0xC000018E)
632#define STATUS_EVENTLOG_CANT_START __constant_cpu_to_le32(0xC000018F)
633#define STATUS_TRUST_FAILURE __constant_cpu_to_le32(0xC0000190)
634#define STATUS_MUTANT_LIMIT_EXCEEDED __constant_cpu_to_le32(0xC0000191)
635#define STATUS_NETLOGON_NOT_STARTED __constant_cpu_to_le32(0xC0000192)
636#define STATUS_ACCOUNT_EXPIRED __constant_cpu_to_le32(0xC0000193)
637#define STATUS_POSSIBLE_DEADLOCK __constant_cpu_to_le32(0xC0000194)
638#define STATUS_NETWORK_CREDENTIAL_CONFLICT __constant_cpu_to_le32(0xC0000195)
639#define STATUS_REMOTE_SESSION_LIMIT __constant_cpu_to_le32(0xC0000196)
640#define STATUS_EVENTLOG_FILE_CHANGED __constant_cpu_to_le32(0xC0000197)
641#define STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT __constant_cpu_to_le32(0xC0000198)
642#define STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT __constant_cpu_to_le32(0xC0000199)
643#define STATUS_NOLOGON_SERVER_TRUST_ACCOUNT __constant_cpu_to_le32(0xC000019A)
644#define STATUS_DOMAIN_TRUST_INCONSISTENT __constant_cpu_to_le32(0xC000019B)
645#define STATUS_FS_DRIVER_REQUIRED __constant_cpu_to_le32(0xC000019C)
646#define STATUS_IMAGE_ALREADY_LOADED_AS_DLL __constant_cpu_to_le32(0xC000019D)
647#define STATUS_NETWORK_OPEN_RESTRICTION __constant_cpu_to_le32(0xC0000201)
648#define STATUS_NO_USER_SESSION_KEY __constant_cpu_to_le32(0xC0000202)
649#define STATUS_USER_SESSION_DELETED __constant_cpu_to_le32(0xC0000203)
650#define STATUS_RESOURCE_LANG_NOT_FOUND __constant_cpu_to_le32(0xC0000204)
651#define STATUS_INSUFF_SERVER_RESOURCES __constant_cpu_to_le32(0xC0000205)
652#define STATUS_INVALID_BUFFER_SIZE __constant_cpu_to_le32(0xC0000206)
653#define STATUS_INVALID_ADDRESS_COMPONENT __constant_cpu_to_le32(0xC0000207)
654#define STATUS_INVALID_ADDRESS_WILDCARD __constant_cpu_to_le32(0xC0000208)
655#define STATUS_TOO_MANY_ADDRESSES __constant_cpu_to_le32(0xC0000209)
656#define STATUS_ADDRESS_ALREADY_EXISTS __constant_cpu_to_le32(0xC000020A)
657#define STATUS_ADDRESS_CLOSED __constant_cpu_to_le32(0xC000020B)
658#define STATUS_CONNECTION_DISCONNECTED __constant_cpu_to_le32(0xC000020C)
659#define STATUS_CONNECTION_RESET __constant_cpu_to_le32(0xC000020D)
660#define STATUS_TOO_MANY_NODES __constant_cpu_to_le32(0xC000020E)
661#define STATUS_TRANSACTION_ABORTED __constant_cpu_to_le32(0xC000020F)
662#define STATUS_TRANSACTION_TIMED_OUT __constant_cpu_to_le32(0xC0000210)
663#define STATUS_TRANSACTION_NO_RELEASE __constant_cpu_to_le32(0xC0000211)
664#define STATUS_TRANSACTION_NO_MATCH __constant_cpu_to_le32(0xC0000212)
665#define STATUS_TRANSACTION_RESPONDED __constant_cpu_to_le32(0xC0000213)
666#define STATUS_TRANSACTION_INVALID_ID __constant_cpu_to_le32(0xC0000214)
667#define STATUS_TRANSACTION_INVALID_TYPE __constant_cpu_to_le32(0xC0000215)
668#define STATUS_NOT_SERVER_SESSION __constant_cpu_to_le32(0xC0000216)
669#define STATUS_NOT_CLIENT_SESSION __constant_cpu_to_le32(0xC0000217)
670#define STATUS_CANNOT_LOAD_REGISTRY_FILE __constant_cpu_to_le32(0xC0000218)
671#define STATUS_DEBUG_ATTACH_FAILED __constant_cpu_to_le32(0xC0000219)
672#define STATUS_SYSTEM_PROCESS_TERMINATED __constant_cpu_to_le32(0xC000021A)
673#define STATUS_DATA_NOT_ACCEPTED __constant_cpu_to_le32(0xC000021B)
674#define STATUS_NO_BROWSER_SERVERS_FOUND __constant_cpu_to_le32(0xC000021C)
675#define STATUS_VDM_HARD_ERROR __constant_cpu_to_le32(0xC000021D)
676#define STATUS_DRIVER_CANCEL_TIMEOUT __constant_cpu_to_le32(0xC000021E)
677#define STATUS_REPLY_MESSAGE_MISMATCH __constant_cpu_to_le32(0xC000021F)
678#define STATUS_MAPPED_ALIGNMENT __constant_cpu_to_le32(0xC0000220)
679#define STATUS_IMAGE_CHECKSUM_MISMATCH __constant_cpu_to_le32(0xC0000221)
680#define STATUS_LOST_WRITEBEHIND_DATA __constant_cpu_to_le32(0xC0000222)
681#define STATUS_CLIENT_SERVER_PARAMETERS_INVALID __constant_cpu_to_le32(0xC0000223)
682#define STATUS_PASSWORD_MUST_CHANGE __constant_cpu_to_le32(0xC0000224)
683#define STATUS_NOT_FOUND __constant_cpu_to_le32(0xC0000225)
684#define STATUS_NOT_TINY_STREAM __constant_cpu_to_le32(0xC0000226)
685#define STATUS_RECOVERY_FAILURE __constant_cpu_to_le32(0xC0000227)
686#define STATUS_STACK_OVERFLOW_READ __constant_cpu_to_le32(0xC0000228)
687#define STATUS_FAIL_CHECK __constant_cpu_to_le32(0xC0000229)
688#define STATUS_DUPLICATE_OBJECTID __constant_cpu_to_le32(0xC000022A)
689#define STATUS_OBJECTID_EXISTS __constant_cpu_to_le32(0xC000022B)
690#define STATUS_CONVERT_TO_LARGE __constant_cpu_to_le32(0xC000022C)
691#define STATUS_RETRY __constant_cpu_to_le32(0xC000022D)
692#define STATUS_FOUND_OUT_OF_SCOPE __constant_cpu_to_le32(0xC000022E)
693#define STATUS_ALLOCATE_BUCKET __constant_cpu_to_le32(0xC000022F)
694#define STATUS_PROPSET_NOT_FOUND __constant_cpu_to_le32(0xC0000230)
695#define STATUS_MARSHALL_OVERFLOW __constant_cpu_to_le32(0xC0000231)
696#define STATUS_INVALID_VARIANT __constant_cpu_to_le32(0xC0000232)
697#define STATUS_DOMAIN_CONTROLLER_NOT_FOUND __constant_cpu_to_le32(0xC0000233)
698#define STATUS_ACCOUNT_LOCKED_OUT __constant_cpu_to_le32(0xC0000234)
699#define STATUS_HANDLE_NOT_CLOSABLE __constant_cpu_to_le32(0xC0000235)
700#define STATUS_CONNECTION_REFUSED __constant_cpu_to_le32(0xC0000236)
701#define STATUS_GRACEFUL_DISCONNECT __constant_cpu_to_le32(0xC0000237)
702#define STATUS_ADDRESS_ALREADY_ASSOCIATED __constant_cpu_to_le32(0xC0000238)
703#define STATUS_ADDRESS_NOT_ASSOCIATED __constant_cpu_to_le32(0xC0000239)
704#define STATUS_CONNECTION_INVALID __constant_cpu_to_le32(0xC000023A)
705#define STATUS_CONNECTION_ACTIVE __constant_cpu_to_le32(0xC000023B)
706#define STATUS_NETWORK_UNREACHABLE __constant_cpu_to_le32(0xC000023C)
707#define STATUS_HOST_UNREACHABLE __constant_cpu_to_le32(0xC000023D)
708#define STATUS_PROTOCOL_UNREACHABLE __constant_cpu_to_le32(0xC000023E)
709#define STATUS_PORT_UNREACHABLE __constant_cpu_to_le32(0xC000023F)
710#define STATUS_REQUEST_ABORTED __constant_cpu_to_le32(0xC0000240)
711#define STATUS_CONNECTION_ABORTED __constant_cpu_to_le32(0xC0000241)
712#define STATUS_BAD_COMPRESSION_BUFFER __constant_cpu_to_le32(0xC0000242)
713#define STATUS_USER_MAPPED_FILE __constant_cpu_to_le32(0xC0000243)
714#define STATUS_AUDIT_FAILED __constant_cpu_to_le32(0xC0000244)
715#define STATUS_TIMER_RESOLUTION_NOT_SET __constant_cpu_to_le32(0xC0000245)
716#define STATUS_CONNECTION_COUNT_LIMIT __constant_cpu_to_le32(0xC0000246)
717#define STATUS_LOGIN_TIME_RESTRICTION __constant_cpu_to_le32(0xC0000247)
718#define STATUS_LOGIN_WKSTA_RESTRICTION __constant_cpu_to_le32(0xC0000248)
719#define STATUS_IMAGE_MP_UP_MISMATCH __constant_cpu_to_le32(0xC0000249)
720#define STATUS_INSUFFICIENT_LOGON_INFO __constant_cpu_to_le32(0xC0000250)
721#define STATUS_BAD_DLL_ENTRYPOINT __constant_cpu_to_le32(0xC0000251)
722#define STATUS_BAD_SERVICE_ENTRYPOINT __constant_cpu_to_le32(0xC0000252)
723#define STATUS_LPC_REPLY_LOST __constant_cpu_to_le32(0xC0000253)
724#define STATUS_IP_ADDRESS_CONFLICT1 __constant_cpu_to_le32(0xC0000254)
725#define STATUS_IP_ADDRESS_CONFLICT2 __constant_cpu_to_le32(0xC0000255)
726#define STATUS_REGISTRY_QUOTA_LIMIT __constant_cpu_to_le32(0xC0000256)
727#define STATUS_PATH_NOT_COVERED __constant_cpu_to_le32(0xC0000257)
728#define STATUS_NO_CALLBACK_ACTIVE __constant_cpu_to_le32(0xC0000258)
729#define STATUS_LICENSE_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000259)
730#define STATUS_PWD_TOO_SHORT __constant_cpu_to_le32(0xC000025A)
731#define STATUS_PWD_TOO_RECENT __constant_cpu_to_le32(0xC000025B)
732#define STATUS_PWD_HISTORY_CONFLICT __constant_cpu_to_le32(0xC000025C)
733#define STATUS_PLUGPLAY_NO_DEVICE __constant_cpu_to_le32(0xC000025E)
734#define STATUS_UNSUPPORTED_COMPRESSION __constant_cpu_to_le32(0xC000025F)
735#define STATUS_INVALID_HW_PROFILE __constant_cpu_to_le32(0xC0000260)
736#define STATUS_INVALID_PLUGPLAY_DEVICE_PATH __constant_cpu_to_le32(0xC0000261)
737#define STATUS_DRIVER_ORDINAL_NOT_FOUND __constant_cpu_to_le32(0xC0000262)
738#define STATUS_DRIVER_ENTRYPOINT_NOT_FOUND __constant_cpu_to_le32(0xC0000263)
739#define STATUS_RESOURCE_NOT_OWNED __constant_cpu_to_le32(0xC0000264)
740#define STATUS_TOO_MANY_LINKS __constant_cpu_to_le32(0xC0000265)
741#define STATUS_QUOTA_LIST_INCONSISTENT __constant_cpu_to_le32(0xC0000266)
742#define STATUS_FILE_IS_OFFLINE __constant_cpu_to_le32(0xC0000267)
743#define STATUS_EVALUATION_EXPIRATION __constant_cpu_to_le32(0xC0000268)
744#define STATUS_ILLEGAL_DLL_RELOCATION __constant_cpu_to_le32(0xC0000269)
745#define STATUS_LICENSE_VIOLATION __constant_cpu_to_le32(0xC000026A)
746#define STATUS_DLL_INIT_FAILED_LOGOFF __constant_cpu_to_le32(0xC000026B)
747#define STATUS_DRIVER_UNABLE_TO_LOAD __constant_cpu_to_le32(0xC000026C)
748#define STATUS_DFS_UNAVAILABLE __constant_cpu_to_le32(0xC000026D)
749#define STATUS_VOLUME_DISMOUNTED __constant_cpu_to_le32(0xC000026E)
750#define STATUS_WX86_INTERNAL_ERROR __constant_cpu_to_le32(0xC000026F)
751#define STATUS_WX86_FLOAT_STACK_CHECK __constant_cpu_to_le32(0xC0000270)
752#define STATUS_VALIDATE_CONTINUE __constant_cpu_to_le32(0xC0000271)
753#define STATUS_NO_MATCH __constant_cpu_to_le32(0xC0000272)
754#define STATUS_NO_MORE_MATCHES __constant_cpu_to_le32(0xC0000273)
755#define STATUS_NOT_A_REPARSE_POINT __constant_cpu_to_le32(0xC0000275)
756#define STATUS_IO_REPARSE_TAG_INVALID __constant_cpu_to_le32(0xC0000276)
757#define STATUS_IO_REPARSE_TAG_MISMATCH __constant_cpu_to_le32(0xC0000277)
758#define STATUS_IO_REPARSE_DATA_INVALID __constant_cpu_to_le32(0xC0000278)
759#define STATUS_IO_REPARSE_TAG_NOT_HANDLED __constant_cpu_to_le32(0xC0000279)
760#define STATUS_REPARSE_POINT_NOT_RESOLVED __constant_cpu_to_le32(0xC0000280)
761#define STATUS_DIRECTORY_IS_A_REPARSE_POINT __constant_cpu_to_le32(0xC0000281)
762#define STATUS_RANGE_LIST_CONFLICT __constant_cpu_to_le32(0xC0000282)
763#define STATUS_SOURCE_ELEMENT_EMPTY __constant_cpu_to_le32(0xC0000283)
764#define STATUS_DESTINATION_ELEMENT_FULL __constant_cpu_to_le32(0xC0000284)
765#define STATUS_ILLEGAL_ELEMENT_ADDRESS __constant_cpu_to_le32(0xC0000285)
766#define STATUS_MAGAZINE_NOT_PRESENT __constant_cpu_to_le32(0xC0000286)
767#define STATUS_REINITIALIZATION_NEEDED __constant_cpu_to_le32(0xC0000287)
768#define STATUS_ENCRYPTION_FAILED __constant_cpu_to_le32(0xC000028A)
769#define STATUS_DECRYPTION_FAILED __constant_cpu_to_le32(0xC000028B)
770#define STATUS_RANGE_NOT_FOUND __constant_cpu_to_le32(0xC000028C)
771#define STATUS_NO_RECOVERY_POLICY __constant_cpu_to_le32(0xC000028D)
772#define STATUS_NO_EFS __constant_cpu_to_le32(0xC000028E)
773#define STATUS_WRONG_EFS __constant_cpu_to_le32(0xC000028F)
774#define STATUS_NO_USER_KEYS __constant_cpu_to_le32(0xC0000290)
775#define STATUS_FILE_NOT_ENCRYPTED __constant_cpu_to_le32(0xC0000291)
776#define STATUS_NOT_EXPORT_FORMAT __constant_cpu_to_le32(0xC0000292)
777#define STATUS_FILE_ENCRYPTED __constant_cpu_to_le32(0xC0000293)
778#define STATUS_WMI_GUID_NOT_FOUND __constant_cpu_to_le32(0xC0000295)
779#define STATUS_WMI_INSTANCE_NOT_FOUND __constant_cpu_to_le32(0xC0000296)
780#define STATUS_WMI_ITEMID_NOT_FOUND __constant_cpu_to_le32(0xC0000297)
781#define STATUS_WMI_TRY_AGAIN __constant_cpu_to_le32(0xC0000298)
782#define STATUS_SHARED_POLICY __constant_cpu_to_le32(0xC0000299)
783#define STATUS_POLICY_OBJECT_NOT_FOUND __constant_cpu_to_le32(0xC000029A)
784#define STATUS_POLICY_ONLY_IN_DS __constant_cpu_to_le32(0xC000029B)
785#define STATUS_VOLUME_NOT_UPGRADED __constant_cpu_to_le32(0xC000029C)
786#define STATUS_REMOTE_STORAGE_NOT_ACTIVE __constant_cpu_to_le32(0xC000029D)
787#define STATUS_REMOTE_STORAGE_MEDIA_ERROR __constant_cpu_to_le32(0xC000029E)
788#define STATUS_NO_TRACKING_SERVICE __constant_cpu_to_le32(0xC000029F)
789#define STATUS_SERVER_SID_MISMATCH __constant_cpu_to_le32(0xC00002A0)
790#define STATUS_DS_NO_ATTRIBUTE_OR_VALUE __constant_cpu_to_le32(0xC00002A1)
791#define STATUS_DS_INVALID_ATTRIBUTE_SYNTAX __constant_cpu_to_le32(0xC00002A2)
792#define STATUS_DS_ATTRIBUTE_TYPE_UNDEFINED __constant_cpu_to_le32(0xC00002A3)
793#define STATUS_DS_ATTRIBUTE_OR_VALUE_EXISTS __constant_cpu_to_le32(0xC00002A4)
794#define STATUS_DS_BUSY __constant_cpu_to_le32(0xC00002A5)
795#define STATUS_DS_UNAVAILABLE __constant_cpu_to_le32(0xC00002A6)
796#define STATUS_DS_NO_RIDS_ALLOCATED __constant_cpu_to_le32(0xC00002A7)
797#define STATUS_DS_NO_MORE_RIDS __constant_cpu_to_le32(0xC00002A8)
798#define STATUS_DS_INCORRECT_ROLE_OWNER __constant_cpu_to_le32(0xC00002A9)
799#define STATUS_DS_RIDMGR_INIT_ERROR __constant_cpu_to_le32(0xC00002AA)
800#define STATUS_DS_OBJ_CLASS_VIOLATION __constant_cpu_to_le32(0xC00002AB)
801#define STATUS_DS_CANT_ON_NON_LEAF __constant_cpu_to_le32(0xC00002AC)
802#define STATUS_DS_CANT_ON_RDN __constant_cpu_to_le32(0xC00002AD)
803#define STATUS_DS_CANT_MOD_OBJ_CLASS __constant_cpu_to_le32(0xC00002AE)
804#define STATUS_DS_CROSS_DOM_MOVE_FAILED __constant_cpu_to_le32(0xC00002AF)
805#define STATUS_DS_GC_NOT_AVAILABLE __constant_cpu_to_le32(0xC00002B0)
806#define STATUS_DIRECTORY_SERVICE_REQUIRED __constant_cpu_to_le32(0xC00002B1)
807#define STATUS_REPARSE_ATTRIBUTE_CONFLICT __constant_cpu_to_le32(0xC00002B2)
808#define STATUS_CANT_ENABLE_DENY_ONLY __constant_cpu_to_le32(0xC00002B3)
809#define STATUS_FLOAT_MULTIPLE_FAULTS __constant_cpu_to_le32(0xC00002B4)
810#define STATUS_FLOAT_MULTIPLE_TRAPS __constant_cpu_to_le32(0xC00002B5)
811#define STATUS_DEVICE_REMOVED __constant_cpu_to_le32(0xC00002B6)
812#define STATUS_JOURNAL_DELETE_IN_PROGRESS __constant_cpu_to_le32(0xC00002B7)
813#define STATUS_JOURNAL_NOT_ACTIVE __constant_cpu_to_le32(0xC00002B8)
814#define STATUS_NOINTERFACE __constant_cpu_to_le32(0xC00002B9)
815#define STATUS_DS_ADMIN_LIMIT_EXCEEDED __constant_cpu_to_le32(0xC00002C1)
816#define STATUS_DRIVER_FAILED_SLEEP __constant_cpu_to_le32(0xC00002C2)
817#define STATUS_MUTUAL_AUTHENTICATION_FAILED __constant_cpu_to_le32(0xC00002C3)
818#define STATUS_CORRUPT_SYSTEM_FILE __constant_cpu_to_le32(0xC00002C4)
819#define STATUS_DATATYPE_MISALIGNMENT_ERROR __constant_cpu_to_le32(0xC00002C5)
820#define STATUS_WMI_READ_ONLY __constant_cpu_to_le32(0xC00002C6)
821#define STATUS_WMI_SET_FAILURE __constant_cpu_to_le32(0xC00002C7)
822#define STATUS_COMMITMENT_MINIMUM __constant_cpu_to_le32(0xC00002C8)
823#define STATUS_REG_NAT_CONSUMPTION __constant_cpu_to_le32(0xC00002C9)
824#define STATUS_TRANSPORT_FULL __constant_cpu_to_le32(0xC00002CA)
825#define STATUS_DS_SAM_INIT_FAILURE __constant_cpu_to_le32(0xC00002CB)
826#define STATUS_ONLY_IF_CONNECTED __constant_cpu_to_le32(0xC00002CC)
827#define STATUS_DS_SENSITIVE_GROUP_VIOLATION __constant_cpu_to_le32(0xC00002CD)
828#define STATUS_PNP_RESTART_ENUMERATION __constant_cpu_to_le32(0xC00002CE)
829#define STATUS_JOURNAL_ENTRY_DELETED __constant_cpu_to_le32(0xC00002CF)
830#define STATUS_DS_CANT_MOD_PRIMARYGROUPID __constant_cpu_to_le32(0xC00002D0)
831#define STATUS_SYSTEM_IMAGE_BAD_SIGNATURE __constant_cpu_to_le32(0xC00002D1)
832#define STATUS_PNP_REBOOT_REQUIRED __constant_cpu_to_le32(0xC00002D2)
833#define STATUS_POWER_STATE_INVALID __constant_cpu_to_le32(0xC00002D3)
834#define STATUS_DS_INVALID_GROUP_TYPE __constant_cpu_to_le32(0xC00002D4)
835#define STATUS_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN __constant_cpu_to_le32(0xC00002D5)
836#define STATUS_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN __constant_cpu_to_le32(0xC00002D6)
837#define STATUS_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER __constant_cpu_to_le32(0xC00002D7)
838#define STATUS_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER __constant_cpu_to_le32(0xC00002D8)
839#define STATUS_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER __constant_cpu_to_le32(0xC00002D9)
840#define STATUS_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER __constant_cpu_to_le32(0xC00002DA)
841#define STATUS_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER __constant_cpu_to_le32(0xC00002DB)
842#define STATUS_DS_HAVE_PRIMARY_MEMBERS __constant_cpu_to_le32(0xC00002DC)
843#define STATUS_WMI_NOT_SUPPORTED __constant_cpu_to_le32(0xC00002DD)
844#define STATUS_INSUFFICIENT_POWER __constant_cpu_to_le32(0xC00002DE)
845#define STATUS_SAM_NEED_BOOTKEY_PASSWORD __constant_cpu_to_le32(0xC00002DF)
846#define STATUS_SAM_NEED_BOOTKEY_FLOPPY __constant_cpu_to_le32(0xC00002E0)
847#define STATUS_DS_CANT_START __constant_cpu_to_le32(0xC00002E1)
848#define STATUS_DS_INIT_FAILURE __constant_cpu_to_le32(0xC00002E2)
849#define STATUS_SAM_INIT_FAILURE __constant_cpu_to_le32(0xC00002E3)
850#define STATUS_DS_GC_REQUIRED __constant_cpu_to_le32(0xC00002E4)
851#define STATUS_DS_LOCAL_MEMBER_OF_LOCAL_ONLY __constant_cpu_to_le32(0xC00002E5)
852#define STATUS_DS_NO_FPO_IN_UNIVERSAL_GROUPS __constant_cpu_to_le32(0xC00002E6)
853#define STATUS_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC00002E7)
854#define STATUS_MULTIPLE_FAULT_VIOLATION __constant_cpu_to_le32(0xC00002E8)
855#define STATUS_CURRENT_DOMAIN_NOT_ALLOWED __constant_cpu_to_le32(0xC00002E9)
856#define STATUS_CANNOT_MAKE __constant_cpu_to_le32(0xC00002EA)
857#define STATUS_SYSTEM_SHUTDOWN __constant_cpu_to_le32(0xC00002EB)
858#define STATUS_DS_INIT_FAILURE_CONSOLE __constant_cpu_to_le32(0xC00002EC)
859#define STATUS_DS_SAM_INIT_FAILURE_CONSOLE __constant_cpu_to_le32(0xC00002ED)
860#define STATUS_UNFINISHED_CONTEXT_DELETED __constant_cpu_to_le32(0xC00002EE)
861#define STATUS_NO_TGT_REPLY __constant_cpu_to_le32(0xC00002EF)
862#define STATUS_OBJECTID_NOT_FOUND __constant_cpu_to_le32(0xC00002F0)
863#define STATUS_NO_IP_ADDRESSES __constant_cpu_to_le32(0xC00002F1)
864#define STATUS_WRONG_CREDENTIAL_HANDLE __constant_cpu_to_le32(0xC00002F2)
865#define STATUS_CRYPTO_SYSTEM_INVALID __constant_cpu_to_le32(0xC00002F3)
866#define STATUS_MAX_REFERRALS_EXCEEDED __constant_cpu_to_le32(0xC00002F4)
867#define STATUS_MUST_BE_KDC __constant_cpu_to_le32(0xC00002F5)
868#define STATUS_STRONG_CRYPTO_NOT_SUPPORTED __constant_cpu_to_le32(0xC00002F6)
869#define STATUS_TOO_MANY_PRINCIPALS __constant_cpu_to_le32(0xC00002F7)
870#define STATUS_NO_PA_DATA __constant_cpu_to_le32(0xC00002F8)
871#define STATUS_PKINIT_NAME_MISMATCH __constant_cpu_to_le32(0xC00002F9)
872#define STATUS_SMARTCARD_LOGON_REQUIRED __constant_cpu_to_le32(0xC00002FA)
873#define STATUS_KDC_INVALID_REQUEST __constant_cpu_to_le32(0xC00002FB)
874#define STATUS_KDC_UNABLE_TO_REFER __constant_cpu_to_le32(0xC00002FC)
875#define STATUS_KDC_UNKNOWN_ETYPE __constant_cpu_to_le32(0xC00002FD)
876#define STATUS_SHUTDOWN_IN_PROGRESS __constant_cpu_to_le32(0xC00002FE)
877#define STATUS_SERVER_SHUTDOWN_IN_PROGRESS __constant_cpu_to_le32(0xC00002FF)
878#define STATUS_NOT_SUPPORTED_ON_SBS __constant_cpu_to_le32(0xC0000300)
879#define STATUS_WMI_GUID_DISCONNECTED __constant_cpu_to_le32(0xC0000301)
880#define STATUS_WMI_ALREADY_DISABLED __constant_cpu_to_le32(0xC0000302)
881#define STATUS_WMI_ALREADY_ENABLED __constant_cpu_to_le32(0xC0000303)
882#define STATUS_MFT_TOO_FRAGMENTED __constant_cpu_to_le32(0xC0000304)
883#define STATUS_COPY_PROTECTION_FAILURE __constant_cpu_to_le32(0xC0000305)
884#define STATUS_CSS_AUTHENTICATION_FAILURE __constant_cpu_to_le32(0xC0000306)
885#define STATUS_CSS_KEY_NOT_PRESENT __constant_cpu_to_le32(0xC0000307)
886#define STATUS_CSS_KEY_NOT_ESTABLISHED __constant_cpu_to_le32(0xC0000308)
887#define STATUS_CSS_SCRAMBLED_SECTOR __constant_cpu_to_le32(0xC0000309)
888#define STATUS_CSS_REGION_MISMATCH __constant_cpu_to_le32(0xC000030A)
889#define STATUS_CSS_RESETS_EXHAUSTED __constant_cpu_to_le32(0xC000030B)
890#define STATUS_PKINIT_FAILURE __constant_cpu_to_le32(0xC0000320)
891#define STATUS_SMARTCARD_SUBSYSTEM_FAILURE __constant_cpu_to_le32(0xC0000321)
892#define STATUS_NO_KERB_KEY __constant_cpu_to_le32(0xC0000322)
893#define STATUS_HOST_DOWN __constant_cpu_to_le32(0xC0000350)
894#define STATUS_UNSUPPORTED_PREAUTH __constant_cpu_to_le32(0xC0000351)
895#define STATUS_EFS_ALG_BLOB_TOO_BIG __constant_cpu_to_le32(0xC0000352)
896#define STATUS_PORT_NOT_SET __constant_cpu_to_le32(0xC0000353)
897#define STATUS_DEBUGGER_INACTIVE __constant_cpu_to_le32(0xC0000354)
898#define STATUS_DS_VERSION_CHECK_FAILURE __constant_cpu_to_le32(0xC0000355)
899#define STATUS_AUDITING_DISABLED __constant_cpu_to_le32(0xC0000356)
900#define STATUS_PRENT4_MACHINE_ACCOUNT __constant_cpu_to_le32(0xC0000357)
901#define STATUS_DS_AG_CANT_HAVE_UNIVERSAL_MEMBER __constant_cpu_to_le32(0xC0000358)
902#define STATUS_INVALID_IMAGE_WIN_32 __constant_cpu_to_le32(0xC0000359)
903#define STATUS_INVALID_IMAGE_WIN_64 __constant_cpu_to_le32(0xC000035A)
904#define STATUS_BAD_BINDINGS __constant_cpu_to_le32(0xC000035B)
905#define STATUS_NETWORK_SESSION_EXPIRED __constant_cpu_to_le32(0xC000035C)
906#define STATUS_APPHELP_BLOCK __constant_cpu_to_le32(0xC000035D)
907#define STATUS_ALL_SIDS_FILTERED __constant_cpu_to_le32(0xC000035E)
908#define STATUS_NOT_SAFE_MODE_DRIVER __constant_cpu_to_le32(0xC000035F)
909#define STATUS_ACCESS_DISABLED_BY_POLICY_DEFAULT __constant_cpu_to_le32(0xC0000361)
910#define STATUS_ACCESS_DISABLED_BY_POLICY_PATH __constant_cpu_to_le32(0xC0000362)
911#define STATUS_ACCESS_DISABLED_BY_POLICY_PUBLISHER __constant_cpu_to_le32(0xC0000363)
912#define STATUS_ACCESS_DISABLED_BY_POLICY_OTHER __constant_cpu_to_le32(0xC0000364)
913#define STATUS_FAILED_DRIVER_ENTRY __constant_cpu_to_le32(0xC0000365)
914#define STATUS_DEVICE_ENUMERATION_ERROR __constant_cpu_to_le32(0xC0000366)
915#define STATUS_MOUNT_POINT_NOT_RESOLVED __constant_cpu_to_le32(0xC0000368)
916#define STATUS_INVALID_DEVICE_OBJECT_PARAMETER __constant_cpu_to_le32(0xC0000369)
917#define STATUS_MCA_OCCURED __constant_cpu_to_le32(0xC000036A)
918#define STATUS_DRIVER_BLOCKED_CRITICAL __constant_cpu_to_le32(0xC000036B)
919#define STATUS_DRIVER_BLOCKED __constant_cpu_to_le32(0xC000036C)
920#define STATUS_DRIVER_DATABASE_ERROR __constant_cpu_to_le32(0xC000036D)
921#define STATUS_SYSTEM_HIVE_TOO_LARGE __constant_cpu_to_le32(0xC000036E)
922#define STATUS_INVALID_IMPORT_OF_NON_DLL __constant_cpu_to_le32(0xC000036F)
923#define STATUS_NO_SECRETS __constant_cpu_to_le32(0xC0000371)
924#define STATUS_ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY __constant_cpu_to_le32(0xC0000372)
925#define STATUS_FAILED_STACK_SWITCH __constant_cpu_to_le32(0xC0000373)
926#define STATUS_HEAP_CORRUPTION __constant_cpu_to_le32(0xC0000374)
927#define STATUS_SMARTCARD_WRONG_PIN __constant_cpu_to_le32(0xC0000380)
928#define STATUS_SMARTCARD_CARD_BLOCKED __constant_cpu_to_le32(0xC0000381)
929#define STATUS_SMARTCARD_CARD_NOT_AUTHENTICATED __constant_cpu_to_le32(0xC0000382)
930#define STATUS_SMARTCARD_NO_CARD __constant_cpu_to_le32(0xC0000383)
931#define STATUS_SMARTCARD_NO_KEY_CONTAINER __constant_cpu_to_le32(0xC0000384)
932#define STATUS_SMARTCARD_NO_CERTIFICATE __constant_cpu_to_le32(0xC0000385)
933#define STATUS_SMARTCARD_NO_KEYSET __constant_cpu_to_le32(0xC0000386)
934#define STATUS_SMARTCARD_IO_ERROR __constant_cpu_to_le32(0xC0000387)
935#define STATUS_DOWNGRADE_DETECTED __constant_cpu_to_le32(0xC0000388)
936#define STATUS_SMARTCARD_CERT_REVOKED __constant_cpu_to_le32(0xC0000389)
937#define STATUS_ISSUING_CA_UNTRUSTED __constant_cpu_to_le32(0xC000038A)
938#define STATUS_REVOCATION_OFFLINE_C __constant_cpu_to_le32(0xC000038B)
939#define STATUS_PKINIT_CLIENT_FAILURE __constant_cpu_to_le32(0xC000038C)
940#define STATUS_SMARTCARD_CERT_EXPIRED __constant_cpu_to_le32(0xC000038D)
941#define STATUS_DRIVER_FAILED_PRIOR_UNLOAD __constant_cpu_to_le32(0xC000038E)
942#define STATUS_SMARTCARD_SILENT_CONTEXT __constant_cpu_to_le32(0xC000038F)
943#define STATUS_PER_USER_TRUST_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000401)
944#define STATUS_ALL_USER_TRUST_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000402)
945#define STATUS_USER_DELETE_TRUST_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000403)
946#define STATUS_DS_NAME_NOT_UNIQUE __constant_cpu_to_le32(0xC0000404)
947#define STATUS_DS_DUPLICATE_ID_FOUND __constant_cpu_to_le32(0xC0000405)
948#define STATUS_DS_GROUP_CONVERSION_ERROR __constant_cpu_to_le32(0xC0000406)
949#define STATUS_VOLSNAP_PREPARE_HIBERNATE __constant_cpu_to_le32(0xC0000407)
950#define STATUS_USER2USER_REQUIRED __constant_cpu_to_le32(0xC0000408)
951#define STATUS_STACK_BUFFER_OVERRUN __constant_cpu_to_le32(0xC0000409)
952#define STATUS_NO_S4U_PROT_SUPPORT __constant_cpu_to_le32(0xC000040A)
953#define STATUS_CROSSREALM_DELEGATION_FAILURE __constant_cpu_to_le32(0xC000040B)
954#define STATUS_REVOCATION_OFFLINE_KDC __constant_cpu_to_le32(0xC000040C)
955#define STATUS_ISSUING_CA_UNTRUSTED_KDC __constant_cpu_to_le32(0xC000040D)
956#define STATUS_KDC_CERT_EXPIRED __constant_cpu_to_le32(0xC000040E)
957#define STATUS_KDC_CERT_REVOKED __constant_cpu_to_le32(0xC000040F)
958#define STATUS_PARAMETER_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000410)
959#define STATUS_HIBERNATION_FAILURE __constant_cpu_to_le32(0xC0000411)
960#define STATUS_DELAY_LOAD_FAILED __constant_cpu_to_le32(0xC0000412)
961#define STATUS_AUTHENTICATION_FIREWALL_FAILED __constant_cpu_to_le32(0xC0000413)
962#define STATUS_VDM_DISALLOWED __constant_cpu_to_le32(0xC0000414)
963#define STATUS_HUNG_DISPLAY_DRIVER_THREAD __constant_cpu_to_le32(0xC0000415)
964#define STATUS_INSUFFICIENT_RESOURCE_FOR_SPECIFIED_SHARED_SECTION_SIZE __constant_cpu_to_le32(0xC0000416)
965#define STATUS_INVALID_CRUNTIME_PARAMETER __constant_cpu_to_le32(0xC0000417)
966#define STATUS_NTLM_BLOCKED __constant_cpu_to_le32(0xC0000418)
967#define STATUS_ASSERTION_FAILURE __constant_cpu_to_le32(0xC0000420)
968#define STATUS_VERIFIER_STOP __constant_cpu_to_le32(0xC0000421)
969#define STATUS_CALLBACK_POP_STACK __constant_cpu_to_le32(0xC0000423)
970#define STATUS_INCOMPATIBLE_DRIVER_BLOCKED __constant_cpu_to_le32(0xC0000424)
971#define STATUS_HIVE_UNLOADED __constant_cpu_to_le32(0xC0000425)
972#define STATUS_COMPRESSION_DISABLED __constant_cpu_to_le32(0xC0000426)
973#define STATUS_FILE_SYSTEM_LIMITATION __constant_cpu_to_le32(0xC0000427)
974#define STATUS_INVALID_IMAGE_HASH __constant_cpu_to_le32(0xC0000428)
975#define STATUS_NOT_CAPABLE __constant_cpu_to_le32(0xC0000429)
976#define STATUS_REQUEST_OUT_OF_SEQUENCE __constant_cpu_to_le32(0xC000042A)
977#define STATUS_IMPLEMENTATION_LIMIT __constant_cpu_to_le32(0xC000042B)
978#define STATUS_ELEVATION_REQUIRED __constant_cpu_to_le32(0xC000042C)
979#define STATUS_BEYOND_VDL __constant_cpu_to_le32(0xC0000432)
980#define STATUS_ENCOUNTERED_WRITE_IN_PROGRESS __constant_cpu_to_le32(0xC0000433)
981#define STATUS_PTE_CHANGED __constant_cpu_to_le32(0xC0000434)
982#define STATUS_PURGE_FAILED __constant_cpu_to_le32(0xC0000435)
983#define STATUS_CRED_REQUIRES_CONFIRMATION __constant_cpu_to_le32(0xC0000440)
984#define STATUS_CS_ENCRYPTION_INVALID_SERVER_RESPONSE __constant_cpu_to_le32(0xC0000441)
985#define STATUS_CS_ENCRYPTION_UNSUPPORTED_SERVER __constant_cpu_to_le32(0xC0000442)
986#define STATUS_CS_ENCRYPTION_EXISTING_ENCRYPTED_FILE __constant_cpu_to_le32(0xC0000443)
987#define STATUS_CS_ENCRYPTION_NEW_ENCRYPTED_FILE __constant_cpu_to_le32(0xC0000444)
988#define STATUS_CS_ENCRYPTION_FILE_NOT_CSE __constant_cpu_to_le32(0xC0000445)
989#define STATUS_INVALID_LABEL __constant_cpu_to_le32(0xC0000446)
990#define STATUS_DRIVER_PROCESS_TERMINATED __constant_cpu_to_le32(0xC0000450)
991#define STATUS_AMBIGUOUS_SYSTEM_DEVICE __constant_cpu_to_le32(0xC0000451)
992#define STATUS_SYSTEM_DEVICE_NOT_FOUND __constant_cpu_to_le32(0xC0000452)
993#define STATUS_RESTART_BOOT_APPLICATION __constant_cpu_to_le32(0xC0000453)
994#define STATUS_INVALID_TASK_NAME __constant_cpu_to_le32(0xC0000500)
995#define STATUS_INVALID_TASK_INDEX __constant_cpu_to_le32(0xC0000501)
996#define STATUS_THREAD_ALREADY_IN_TASK __constant_cpu_to_le32(0xC0000502)
997#define STATUS_CALLBACK_BYPASS __constant_cpu_to_le32(0xC0000503)
998#define STATUS_PORT_CLOSED __constant_cpu_to_le32(0xC0000700)
999#define STATUS_MESSAGE_LOST __constant_cpu_to_le32(0xC0000701)
1000#define STATUS_INVALID_MESSAGE __constant_cpu_to_le32(0xC0000702)
1001#define STATUS_REQUEST_CANCELED __constant_cpu_to_le32(0xC0000703)
1002#define STATUS_RECURSIVE_DISPATCH __constant_cpu_to_le32(0xC0000704)
1003#define STATUS_LPC_RECEIVE_BUFFER_EXPECTED __constant_cpu_to_le32(0xC0000705)
1004#define STATUS_LPC_INVALID_CONNECTION_USAGE __constant_cpu_to_le32(0xC0000706)
1005#define STATUS_LPC_REQUESTS_NOT_ALLOWED __constant_cpu_to_le32(0xC0000707)
1006#define STATUS_RESOURCE_IN_USE __constant_cpu_to_le32(0xC0000708)
1007#define STATUS_HARDWARE_MEMORY_ERROR __constant_cpu_to_le32(0xC0000709)
1008#define STATUS_THREADPOOL_HANDLE_EXCEPTION __constant_cpu_to_le32(0xC000070A)
1009#define STATUS_THREADPOOL_SET_EVENT_ON_COMPLETION_FAILED __constant_cpu_to_le32(0xC000070B)
1010#define STATUS_THREADPOOL_RELEASE_SEMAPHORE_ON_COMPLETION_FAILED __constant_cpu_to_le32(0xC000070C)
1011#define STATUS_THREADPOOL_RELEASE_MUTEX_ON_COMPLETION_FAILED __constant_cpu_to_le32(0xC000070D)
1012#define STATUS_THREADPOOL_FREE_LIBRARY_ON_COMPLETION_FAILED __constant_cpu_to_le32(0xC000070E)
1013#define STATUS_THREADPOOL_RELEASED_DURING_OPERATION __constant_cpu_to_le32(0xC000070F)
1014#define STATUS_CALLBACK_RETURNED_WHILE_IMPERSONATING __constant_cpu_to_le32(0xC0000710)
1015#define STATUS_APC_RETURNED_WHILE_IMPERSONATING __constant_cpu_to_le32(0xC0000711)
1016#define STATUS_PROCESS_IS_PROTECTED __constant_cpu_to_le32(0xC0000712)
1017#define STATUS_MCA_EXCEPTION __constant_cpu_to_le32(0xC0000713)
1018#define STATUS_CERTIFICATE_MAPPING_NOT_UNIQUE __constant_cpu_to_le32(0xC0000714)
1019#define STATUS_SYMLINK_CLASS_DISABLED __constant_cpu_to_le32(0xC0000715)
1020#define STATUS_INVALID_IDN_NORMALIZATION __constant_cpu_to_le32(0xC0000716)
1021#define STATUS_NO_UNICODE_TRANSLATION __constant_cpu_to_le32(0xC0000717)
1022#define STATUS_ALREADY_REGISTERED __constant_cpu_to_le32(0xC0000718)
1023#define STATUS_CONTEXT_MISMATCH __constant_cpu_to_le32(0xC0000719)
1024#define STATUS_PORT_ALREADY_HAS_COMPLETION_LIST __constant_cpu_to_le32(0xC000071A)
1025#define STATUS_CALLBACK_RETURNED_THREAD_PRIORITY __constant_cpu_to_le32(0xC000071B)
1026#define STATUS_INVALID_THREAD __constant_cpu_to_le32(0xC000071C)
1027#define STATUS_CALLBACK_RETURNED_TRANSACTION __constant_cpu_to_le32(0xC000071D)
1028#define STATUS_CALLBACK_RETURNED_LDR_LOCK __constant_cpu_to_le32(0xC000071E)
1029#define STATUS_CALLBACK_RETURNED_LANG __constant_cpu_to_le32(0xC000071F)
1030#define STATUS_CALLBACK_RETURNED_PRI_BACK __constant_cpu_to_le32(0xC0000720)
1031#define STATUS_CALLBACK_RETURNED_THREAD_AFFINITY __constant_cpu_to_le32(0xC0000721)
1032#define STATUS_DISK_REPAIR_DISABLED __constant_cpu_to_le32(0xC0000800)
1033#define STATUS_DS_DOMAIN_RENAME_IN_PROGRESS __constant_cpu_to_le32(0xC0000801)
1034#define STATUS_DISK_QUOTA_EXCEEDED __constant_cpu_to_le32(0xC0000802)
1035#define STATUS_CONTENT_BLOCKED __constant_cpu_to_le32(0xC0000804)
1036#define STATUS_BAD_CLUSTERS __constant_cpu_to_le32(0xC0000805)
1037#define STATUS_VOLUME_DIRTY __constant_cpu_to_le32(0xC0000806)
1038#define STATUS_FILE_CHECKED_OUT __constant_cpu_to_le32(0xC0000901)
1039#define STATUS_CHECKOUT_REQUIRED __constant_cpu_to_le32(0xC0000902)
1040#define STATUS_BAD_FILE_TYPE __constant_cpu_to_le32(0xC0000903)
1041#define STATUS_FILE_TOO_LARGE __constant_cpu_to_le32(0xC0000904)
1042#define STATUS_FORMS_AUTH_REQUIRED __constant_cpu_to_le32(0xC0000905)
1043#define STATUS_VIRUS_INFECTED __constant_cpu_to_le32(0xC0000906)
1044#define STATUS_VIRUS_DELETED __constant_cpu_to_le32(0xC0000907)
1045#define STATUS_BAD_MCFG_TABLE __constant_cpu_to_le32(0xC0000908)
1046#define STATUS_WOW_ASSERTION __constant_cpu_to_le32(0xC0009898)
1047#define STATUS_INVALID_SIGNATURE __constant_cpu_to_le32(0xC000A000)
1048#define STATUS_HMAC_NOT_SUPPORTED __constant_cpu_to_le32(0xC000A001)
1049#define STATUS_IPSEC_QUEUE_OVERFLOW __constant_cpu_to_le32(0xC000A010)
1050#define STATUS_ND_QUEUE_OVERFLOW __constant_cpu_to_le32(0xC000A011)
1051#define STATUS_HOPLIMIT_EXCEEDED __constant_cpu_to_le32(0xC000A012)
1052#define STATUS_PROTOCOL_NOT_SUPPORTED __constant_cpu_to_le32(0xC000A013)
1053#define STATUS_LOST_WRITEBEHIND_DATA_NETWORK_DISCONNECTED __constant_cpu_to_le32(0xC000A080)
1054#define STATUS_LOST_WRITEBEHIND_DATA_NETWORK_SERVER_ERROR __constant_cpu_to_le32(0xC000A081)
1055#define STATUS_LOST_WRITEBEHIND_DATA_LOCAL_DISK_ERROR __constant_cpu_to_le32(0xC000A082)
1056#define STATUS_XML_PARSE_ERROR __constant_cpu_to_le32(0xC000A083)
1057#define STATUS_XMLDSIG_ERROR __constant_cpu_to_le32(0xC000A084)
1058#define STATUS_WRONG_COMPARTMENT __constant_cpu_to_le32(0xC000A085)
1059#define STATUS_AUTHIP_FAILURE __constant_cpu_to_le32(0xC000A086)
1060#define DBG_NO_STATE_CHANGE __constant_cpu_to_le32(0xC0010001)
1061#define DBG_APP_NOT_IDLE __constant_cpu_to_le32(0xC0010002)
1062#define RPC_NT_INVALID_STRING_BINDING __constant_cpu_to_le32(0xC0020001)
1063#define RPC_NT_WRONG_KIND_OF_BINDING __constant_cpu_to_le32(0xC0020002)
1064#define RPC_NT_INVALID_BINDING __constant_cpu_to_le32(0xC0020003)
1065#define RPC_NT_PROTSEQ_NOT_SUPPORTED __constant_cpu_to_le32(0xC0020004)
1066#define RPC_NT_INVALID_RPC_PROTSEQ __constant_cpu_to_le32(0xC0020005)
1067#define RPC_NT_INVALID_STRING_UUID __constant_cpu_to_le32(0xC0020006)
1068#define RPC_NT_INVALID_ENDPOINT_FORMAT __constant_cpu_to_le32(0xC0020007)
1069#define RPC_NT_INVALID_NET_ADDR __constant_cpu_to_le32(0xC0020008)
1070#define RPC_NT_NO_ENDPOINT_FOUND __constant_cpu_to_le32(0xC0020009)
1071#define RPC_NT_INVALID_TIMEOUT __constant_cpu_to_le32(0xC002000A)
1072#define RPC_NT_OBJECT_NOT_FOUND __constant_cpu_to_le32(0xC002000B)
1073#define RPC_NT_ALREADY_REGISTERED __constant_cpu_to_le32(0xC002000C)
1074#define RPC_NT_TYPE_ALREADY_REGISTERED __constant_cpu_to_le32(0xC002000D)
1075#define RPC_NT_ALREADY_LISTENING __constant_cpu_to_le32(0xC002000E)
1076#define RPC_NT_NO_PROTSEQS_REGISTERED __constant_cpu_to_le32(0xC002000F)
1077#define RPC_NT_NOT_LISTENING __constant_cpu_to_le32(0xC0020010)
1078#define RPC_NT_UNKNOWN_MGR_TYPE __constant_cpu_to_le32(0xC0020011)
1079#define RPC_NT_UNKNOWN_IF __constant_cpu_to_le32(0xC0020012)
1080#define RPC_NT_NO_BINDINGS __constant_cpu_to_le32(0xC0020013)
1081#define RPC_NT_NO_PROTSEQS __constant_cpu_to_le32(0xC0020014)
1082#define RPC_NT_CANT_CREATE_ENDPOINT __constant_cpu_to_le32(0xC0020015)
1083#define RPC_NT_OUT_OF_RESOURCES __constant_cpu_to_le32(0xC0020016)
1084#define RPC_NT_SERVER_UNAVAILABLE __constant_cpu_to_le32(0xC0020017)
1085#define RPC_NT_SERVER_TOO_BUSY __constant_cpu_to_le32(0xC0020018)
1086#define RPC_NT_INVALID_NETWORK_OPTIONS __constant_cpu_to_le32(0xC0020019)
1087#define RPC_NT_NO_CALL_ACTIVE __constant_cpu_to_le32(0xC002001A)
1088#define RPC_NT_CALL_FAILED __constant_cpu_to_le32(0xC002001B)
1089#define RPC_NT_CALL_FAILED_DNE __constant_cpu_to_le32(0xC002001C)
1090#define RPC_NT_PROTOCOL_ERROR __constant_cpu_to_le32(0xC002001D)
1091#define RPC_NT_UNSUPPORTED_TRANS_SYN __constant_cpu_to_le32(0xC002001F)
1092#define RPC_NT_UNSUPPORTED_TYPE __constant_cpu_to_le32(0xC0020021)
1093#define RPC_NT_INVALID_TAG __constant_cpu_to_le32(0xC0020022)
1094#define RPC_NT_INVALID_BOUND __constant_cpu_to_le32(0xC0020023)
1095#define RPC_NT_NO_ENTRY_NAME __constant_cpu_to_le32(0xC0020024)
1096#define RPC_NT_INVALID_NAME_SYNTAX __constant_cpu_to_le32(0xC0020025)
1097#define RPC_NT_UNSUPPORTED_NAME_SYNTAX __constant_cpu_to_le32(0xC0020026)
1098#define RPC_NT_UUID_NO_ADDRESS __constant_cpu_to_le32(0xC0020028)
1099#define RPC_NT_DUPLICATE_ENDPOINT __constant_cpu_to_le32(0xC0020029)
1100#define RPC_NT_UNKNOWN_AUTHN_TYPE __constant_cpu_to_le32(0xC002002A)
1101#define RPC_NT_MAX_CALLS_TOO_SMALL __constant_cpu_to_le32(0xC002002B)
1102#define RPC_NT_STRING_TOO_LONG __constant_cpu_to_le32(0xC002002C)
1103#define RPC_NT_PROTSEQ_NOT_FOUND __constant_cpu_to_le32(0xC002002D)
1104#define RPC_NT_PROCNUM_OUT_OF_RANGE __constant_cpu_to_le32(0xC002002E)
1105#define RPC_NT_BINDING_HAS_NO_AUTH __constant_cpu_to_le32(0xC002002F)
1106#define RPC_NT_UNKNOWN_AUTHN_SERVICE __constant_cpu_to_le32(0xC0020030)
1107#define RPC_NT_UNKNOWN_AUTHN_LEVEL __constant_cpu_to_le32(0xC0020031)
1108#define RPC_NT_INVALID_AUTH_IDENTITY __constant_cpu_to_le32(0xC0020032)
1109#define RPC_NT_UNKNOWN_AUTHZ_SERVICE __constant_cpu_to_le32(0xC0020033)
1110#define EPT_NT_INVALID_ENTRY __constant_cpu_to_le32(0xC0020034)
1111#define EPT_NT_CANT_PERFORM_OP __constant_cpu_to_le32(0xC0020035)
1112#define EPT_NT_NOT_REGISTERED __constant_cpu_to_le32(0xC0020036)
1113#define RPC_NT_NOTHING_TO_EXPORT __constant_cpu_to_le32(0xC0020037)
1114#define RPC_NT_INCOMPLETE_NAME __constant_cpu_to_le32(0xC0020038)
1115#define RPC_NT_INVALID_VERS_OPTION __constant_cpu_to_le32(0xC0020039)
1116#define RPC_NT_NO_MORE_MEMBERS __constant_cpu_to_le32(0xC002003A)
1117#define RPC_NT_NOT_ALL_OBJS_UNEXPORTED __constant_cpu_to_le32(0xC002003B)
1118#define RPC_NT_INTERFACE_NOT_FOUND __constant_cpu_to_le32(0xC002003C)
1119#define RPC_NT_ENTRY_ALREADY_EXISTS __constant_cpu_to_le32(0xC002003D)
1120#define RPC_NT_ENTRY_NOT_FOUND __constant_cpu_to_le32(0xC002003E)
1121#define RPC_NT_NAME_SERVICE_UNAVAILABLE __constant_cpu_to_le32(0xC002003F)
1122#define RPC_NT_INVALID_NAF_ID __constant_cpu_to_le32(0xC0020040)
1123#define RPC_NT_CANNOT_SUPPORT __constant_cpu_to_le32(0xC0020041)
1124#define RPC_NT_NO_CONTEXT_AVAILABLE __constant_cpu_to_le32(0xC0020042)
1125#define RPC_NT_INTERNAL_ERROR __constant_cpu_to_le32(0xC0020043)
1126#define RPC_NT_ZERO_DIVIDE __constant_cpu_to_le32(0xC0020044)
1127#define RPC_NT_ADDRESS_ERROR __constant_cpu_to_le32(0xC0020045)
1128#define RPC_NT_FP_DIV_ZERO __constant_cpu_to_le32(0xC0020046)
1129#define RPC_NT_FP_UNDERFLOW __constant_cpu_to_le32(0xC0020047)
1130#define RPC_NT_FP_OVERFLOW __constant_cpu_to_le32(0xC0020048)
1131#define RPC_NT_CALL_IN_PROGRESS __constant_cpu_to_le32(0xC0020049)
1132#define RPC_NT_NO_MORE_BINDINGS __constant_cpu_to_le32(0xC002004A)
1133#define RPC_NT_GROUP_MEMBER_NOT_FOUND __constant_cpu_to_le32(0xC002004B)
1134#define EPT_NT_CANT_CREATE __constant_cpu_to_le32(0xC002004C)
1135#define RPC_NT_INVALID_OBJECT __constant_cpu_to_le32(0xC002004D)
1136#define RPC_NT_NO_INTERFACES __constant_cpu_to_le32(0xC002004F)
1137#define RPC_NT_CALL_CANCELLED __constant_cpu_to_le32(0xC0020050)
1138#define RPC_NT_BINDING_INCOMPLETE __constant_cpu_to_le32(0xC0020051)
1139#define RPC_NT_COMM_FAILURE __constant_cpu_to_le32(0xC0020052)
1140#define RPC_NT_UNSUPPORTED_AUTHN_LEVEL __constant_cpu_to_le32(0xC0020053)
1141#define RPC_NT_NO_PRINC_NAME __constant_cpu_to_le32(0xC0020054)
1142#define RPC_NT_NOT_RPC_ERROR __constant_cpu_to_le32(0xC0020055)
1143#define RPC_NT_SEC_PKG_ERROR __constant_cpu_to_le32(0xC0020057)
1144#define RPC_NT_NOT_CANCELLED __constant_cpu_to_le32(0xC0020058)
1145#define RPC_NT_INVALID_ASYNC_HANDLE __constant_cpu_to_le32(0xC0020062)
1146#define RPC_NT_INVALID_ASYNC_CALL __constant_cpu_to_le32(0xC0020063)
1147#define RPC_NT_PROXY_ACCESS_DENIED __constant_cpu_to_le32(0xC0020064)
1148#define RPC_NT_NO_MORE_ENTRIES __constant_cpu_to_le32(0xC0030001)
1149#define RPC_NT_SS_CHAR_TRANS_OPEN_FAIL __constant_cpu_to_le32(0xC0030002)
1150#define RPC_NT_SS_CHAR_TRANS_SHORT_FILE __constant_cpu_to_le32(0xC0030003)
1151#define RPC_NT_SS_IN_NULL_CONTEXT __constant_cpu_to_le32(0xC0030004)
1152#define RPC_NT_SS_CONTEXT_MISMATCH __constant_cpu_to_le32(0xC0030005)
1153#define RPC_NT_SS_CONTEXT_DAMAGED __constant_cpu_to_le32(0xC0030006)
1154#define RPC_NT_SS_HANDLES_MISMATCH __constant_cpu_to_le32(0xC0030007)
1155#define RPC_NT_SS_CANNOT_GET_CALL_HANDLE __constant_cpu_to_le32(0xC0030008)
1156#define RPC_NT_NULL_REF_POINTER __constant_cpu_to_le32(0xC0030009)
1157#define RPC_NT_ENUM_VALUE_OUT_OF_RANGE __constant_cpu_to_le32(0xC003000A)
1158#define RPC_NT_BYTE_COUNT_TOO_SMALL __constant_cpu_to_le32(0xC003000B)
1159#define RPC_NT_BAD_STUB_DATA __constant_cpu_to_le32(0xC003000C)
1160#define RPC_NT_INVALID_ES_ACTION __constant_cpu_to_le32(0xC0030059)
1161#define RPC_NT_WRONG_ES_VERSION __constant_cpu_to_le32(0xC003005A)
1162#define RPC_NT_WRONG_STUB_VERSION __constant_cpu_to_le32(0xC003005B)
1163#define RPC_NT_INVALID_PIPE_OBJECT __constant_cpu_to_le32(0xC003005C)
1164#define RPC_NT_INVALID_PIPE_OPERATION __constant_cpu_to_le32(0xC003005D)
1165#define RPC_NT_WRONG_PIPE_VERSION __constant_cpu_to_le32(0xC003005E)
1166#define RPC_NT_PIPE_CLOSED __constant_cpu_to_le32(0xC003005F)
1167#define RPC_NT_PIPE_DISCIPLINE_ERROR __constant_cpu_to_le32(0xC0030060)
1168#define RPC_NT_PIPE_EMPTY __constant_cpu_to_le32(0xC0030061)
1169#define STATUS_PNP_BAD_MPS_TABLE __constant_cpu_to_le32(0xC0040035)
1170#define STATUS_PNP_TRANSLATION_FAILED __constant_cpu_to_le32(0xC0040036)
1171#define STATUS_PNP_IRQ_TRANSLATION_FAILED __constant_cpu_to_le32(0xC0040037)
1172#define STATUS_PNP_INVALID_ID __constant_cpu_to_le32(0xC0040038)
1173#define STATUS_IO_REISSUE_AS_CACHED __constant_cpu_to_le32(0xC0040039)
1174#define STATUS_CTX_WINSTATION_NAME_INVALID __constant_cpu_to_le32(0xC00A0001)
1175#define STATUS_CTX_INVALID_PD __constant_cpu_to_le32(0xC00A0002)
1176#define STATUS_CTX_PD_NOT_FOUND __constant_cpu_to_le32(0xC00A0003)
1177#define STATUS_CTX_CLOSE_PENDING __constant_cpu_to_le32(0xC00A0006)
1178#define STATUS_CTX_NO_OUTBUF __constant_cpu_to_le32(0xC00A0007)
1179#define STATUS_CTX_MODEM_INF_NOT_FOUND __constant_cpu_to_le32(0xC00A0008)
1180#define STATUS_CTX_INVALID_MODEMNAME __constant_cpu_to_le32(0xC00A0009)
1181#define STATUS_CTX_RESPONSE_ERROR __constant_cpu_to_le32(0xC00A000A)
1182#define STATUS_CTX_MODEM_RESPONSE_TIMEOUT __constant_cpu_to_le32(0xC00A000B)
1183#define STATUS_CTX_MODEM_RESPONSE_NO_CARRIER __constant_cpu_to_le32(0xC00A000C)
1184#define STATUS_CTX_MODEM_RESPONSE_NO_DIALTONE __constant_cpu_to_le32(0xC00A000D)
1185#define STATUS_CTX_MODEM_RESPONSE_BUSY __constant_cpu_to_le32(0xC00A000E)
1186#define STATUS_CTX_MODEM_RESPONSE_VOICE __constant_cpu_to_le32(0xC00A000F)
1187#define STATUS_CTX_TD_ERROR __constant_cpu_to_le32(0xC00A0010)
1188#define STATUS_CTX_LICENSE_CLIENT_INVALID __constant_cpu_to_le32(0xC00A0012)
1189#define STATUS_CTX_LICENSE_NOT_AVAILABLE __constant_cpu_to_le32(0xC00A0013)
1190#define STATUS_CTX_LICENSE_EXPIRED __constant_cpu_to_le32(0xC00A0014)
1191#define STATUS_CTX_WINSTATION_NOT_FOUND __constant_cpu_to_le32(0xC00A0015)
1192#define STATUS_CTX_WINSTATION_NAME_COLLISION __constant_cpu_to_le32(0xC00A0016)
1193#define STATUS_CTX_WINSTATION_BUSY __constant_cpu_to_le32(0xC00A0017)
1194#define STATUS_CTX_BAD_VIDEO_MODE __constant_cpu_to_le32(0xC00A0018)
1195#define STATUS_CTX_GRAPHICS_INVALID __constant_cpu_to_le32(0xC00A0022)
1196#define STATUS_CTX_NOT_CONSOLE __constant_cpu_to_le32(0xC00A0024)
1197#define STATUS_CTX_CLIENT_QUERY_TIMEOUT __constant_cpu_to_le32(0xC00A0026)
1198#define STATUS_CTX_CONSOLE_DISCONNECT __constant_cpu_to_le32(0xC00A0027)
1199#define STATUS_CTX_CONSOLE_CONNECT __constant_cpu_to_le32(0xC00A0028)
1200#define STATUS_CTX_SHADOW_DENIED __constant_cpu_to_le32(0xC00A002A)
1201#define STATUS_CTX_WINSTATION_ACCESS_DENIED __constant_cpu_to_le32(0xC00A002B)
1202#define STATUS_CTX_INVALID_WD __constant_cpu_to_le32(0xC00A002E)
1203#define STATUS_CTX_WD_NOT_FOUND __constant_cpu_to_le32(0xC00A002F)
1204#define STATUS_CTX_SHADOW_INVALID __constant_cpu_to_le32(0xC00A0030)
1205#define STATUS_CTX_SHADOW_DISABLED __constant_cpu_to_le32(0xC00A0031)
1206#define STATUS_RDP_PROTOCOL_ERROR __constant_cpu_to_le32(0xC00A0032)
1207#define STATUS_CTX_CLIENT_LICENSE_NOT_SET __constant_cpu_to_le32(0xC00A0033)
1208#define STATUS_CTX_CLIENT_LICENSE_IN_USE __constant_cpu_to_le32(0xC00A0034)
1209#define STATUS_CTX_SHADOW_ENDED_BY_MODE_CHANGE __constant_cpu_to_le32(0xC00A0035)
1210#define STATUS_CTX_SHADOW_NOT_RUNNING __constant_cpu_to_le32(0xC00A0036)
1211#define STATUS_CTX_LOGON_DISABLED __constant_cpu_to_le32(0xC00A0037)
1212#define STATUS_CTX_SECURITY_LAYER_ERROR __constant_cpu_to_le32(0xC00A0038)
1213#define STATUS_TS_INCOMPATIBLE_SESSIONS __constant_cpu_to_le32(0xC00A0039)
1214#define STATUS_MUI_FILE_NOT_FOUND __constant_cpu_to_le32(0xC00B0001)
1215#define STATUS_MUI_INVALID_FILE __constant_cpu_to_le32(0xC00B0002)
1216#define STATUS_MUI_INVALID_RC_CONFIG __constant_cpu_to_le32(0xC00B0003)
1217#define STATUS_MUI_INVALID_LOCALE_NAME __constant_cpu_to_le32(0xC00B0004)
1218#define STATUS_MUI_INVALID_ULTIMATEFALLBACK_NAME __constant_cpu_to_le32(0xC00B0005)
1219#define STATUS_MUI_FILE_NOT_LOADED __constant_cpu_to_le32(0xC00B0006)
1220#define STATUS_RESOURCE_ENUM_USER_STOP __constant_cpu_to_le32(0xC00B0007)
1221#define STATUS_CLUSTER_INVALID_NODE __constant_cpu_to_le32(0xC0130001)
1222#define STATUS_CLUSTER_NODE_EXISTS __constant_cpu_to_le32(0xC0130002)
1223#define STATUS_CLUSTER_JOIN_IN_PROGRESS __constant_cpu_to_le32(0xC0130003)
1224#define STATUS_CLUSTER_NODE_NOT_FOUND __constant_cpu_to_le32(0xC0130004)
1225#define STATUS_CLUSTER_LOCAL_NODE_NOT_FOUND __constant_cpu_to_le32(0xC0130005)
1226#define STATUS_CLUSTER_NETWORK_EXISTS __constant_cpu_to_le32(0xC0130006)
1227#define STATUS_CLUSTER_NETWORK_NOT_FOUND __constant_cpu_to_le32(0xC0130007)
1228#define STATUS_CLUSTER_NETINTERFACE_EXISTS __constant_cpu_to_le32(0xC0130008)
1229#define STATUS_CLUSTER_NETINTERFACE_NOT_FOUND __constant_cpu_to_le32(0xC0130009)
1230#define STATUS_CLUSTER_INVALID_REQUEST __constant_cpu_to_le32(0xC013000A)
1231#define STATUS_CLUSTER_INVALID_NETWORK_PROVIDER __constant_cpu_to_le32(0xC013000B)
1232#define STATUS_CLUSTER_NODE_DOWN __constant_cpu_to_le32(0xC013000C)
1233#define STATUS_CLUSTER_NODE_UNREACHABLE __constant_cpu_to_le32(0xC013000D)
1234#define STATUS_CLUSTER_NODE_NOT_MEMBER __constant_cpu_to_le32(0xC013000E)
1235#define STATUS_CLUSTER_JOIN_NOT_IN_PROGRESS __constant_cpu_to_le32(0xC013000F)
1236#define STATUS_CLUSTER_INVALID_NETWORK __constant_cpu_to_le32(0xC0130010)
1237#define STATUS_CLUSTER_NO_NET_ADAPTERS __constant_cpu_to_le32(0xC0130011)
1238#define STATUS_CLUSTER_NODE_UP __constant_cpu_to_le32(0xC0130012)
1239#define STATUS_CLUSTER_NODE_PAUSED __constant_cpu_to_le32(0xC0130013)
1240#define STATUS_CLUSTER_NODE_NOT_PAUSED __constant_cpu_to_le32(0xC0130014)
1241#define STATUS_CLUSTER_NO_SECURITY_CONTEXT __constant_cpu_to_le32(0xC0130015)
1242#define STATUS_CLUSTER_NETWORK_NOT_INTERNAL __constant_cpu_to_le32(0xC0130016)
1243#define STATUS_CLUSTER_POISONED __constant_cpu_to_le32(0xC0130017)
1244#define STATUS_ACPI_INVALID_OPCODE __constant_cpu_to_le32(0xC0140001)
1245#define STATUS_ACPI_STACK_OVERFLOW __constant_cpu_to_le32(0xC0140002)
1246#define STATUS_ACPI_ASSERT_FAILED __constant_cpu_to_le32(0xC0140003)
1247#define STATUS_ACPI_INVALID_INDEX __constant_cpu_to_le32(0xC0140004)
1248#define STATUS_ACPI_INVALID_ARGUMENT __constant_cpu_to_le32(0xC0140005)
1249#define STATUS_ACPI_FATAL __constant_cpu_to_le32(0xC0140006)
1250#define STATUS_ACPI_INVALID_SUPERNAME __constant_cpu_to_le32(0xC0140007)
1251#define STATUS_ACPI_INVALID_ARGTYPE __constant_cpu_to_le32(0xC0140008)
1252#define STATUS_ACPI_INVALID_OBJTYPE __constant_cpu_to_le32(0xC0140009)
1253#define STATUS_ACPI_INVALID_TARGETTYPE __constant_cpu_to_le32(0xC014000A)
1254#define STATUS_ACPI_INCORRECT_ARGUMENT_COUNT __constant_cpu_to_le32(0xC014000B)
1255#define STATUS_ACPI_ADDRESS_NOT_MAPPED __constant_cpu_to_le32(0xC014000C)
1256#define STATUS_ACPI_INVALID_EVENTTYPE __constant_cpu_to_le32(0xC014000D)
1257#define STATUS_ACPI_HANDLER_COLLISION __constant_cpu_to_le32(0xC014000E)
1258#define STATUS_ACPI_INVALID_DATA __constant_cpu_to_le32(0xC014000F)
1259#define STATUS_ACPI_INVALID_REGION __constant_cpu_to_le32(0xC0140010)
1260#define STATUS_ACPI_INVALID_ACCESS_SIZE __constant_cpu_to_le32(0xC0140011)
1261#define STATUS_ACPI_ACQUIRE_GLOBAL_LOCK __constant_cpu_to_le32(0xC0140012)
1262#define STATUS_ACPI_ALREADY_INITIALIZED __constant_cpu_to_le32(0xC0140013)
1263#define STATUS_ACPI_NOT_INITIALIZED __constant_cpu_to_le32(0xC0140014)
1264#define STATUS_ACPI_INVALID_MUTEX_LEVEL __constant_cpu_to_le32(0xC0140015)
1265#define STATUS_ACPI_MUTEX_NOT_OWNED __constant_cpu_to_le32(0xC0140016)
1266#define STATUS_ACPI_MUTEX_NOT_OWNER __constant_cpu_to_le32(0xC0140017)
1267#define STATUS_ACPI_RS_ACCESS __constant_cpu_to_le32(0xC0140018)
1268#define STATUS_ACPI_INVALID_TABLE __constant_cpu_to_le32(0xC0140019)
1269#define STATUS_ACPI_REG_HANDLER_FAILED __constant_cpu_to_le32(0xC0140020)
1270#define STATUS_ACPI_POWER_REQUEST_FAILED __constant_cpu_to_le32(0xC0140021)
1271#define STATUS_SXS_SECTION_NOT_FOUND __constant_cpu_to_le32(0xC0150001)
1272#define STATUS_SXS_CANT_GEN_ACTCTX __constant_cpu_to_le32(0xC0150002)
1273#define STATUS_SXS_INVALID_ACTCTXDATA_FORMAT __constant_cpu_to_le32(0xC0150003)
1274#define STATUS_SXS_ASSEMBLY_NOT_FOUND __constant_cpu_to_le32(0xC0150004)
1275#define STATUS_SXS_MANIFEST_FORMAT_ERROR __constant_cpu_to_le32(0xC0150005)
1276#define STATUS_SXS_MANIFEST_PARSE_ERROR __constant_cpu_to_le32(0xC0150006)
1277#define STATUS_SXS_ACTIVATION_CONTEXT_DISABLED __constant_cpu_to_le32(0xC0150007)
1278#define STATUS_SXS_KEY_NOT_FOUND __constant_cpu_to_le32(0xC0150008)
1279#define STATUS_SXS_VERSION_CONFLICT __constant_cpu_to_le32(0xC0150009)
1280#define STATUS_SXS_WRONG_SECTION_TYPE __constant_cpu_to_le32(0xC015000A)
1281#define STATUS_SXS_THREAD_QUERIES_DISABLED __constant_cpu_to_le32(0xC015000B)
1282#define STATUS_SXS_ASSEMBLY_MISSING __constant_cpu_to_le32(0xC015000C)
1283#define STATUS_SXS_PROCESS_DEFAULT_ALREADY_SET __constant_cpu_to_le32(0xC015000E)
1284#define STATUS_SXS_EARLY_DEACTIVATION __constant_cpu_to_le32(0xC015000F)
1285#define STATUS_SXS_INVALID_DEACTIVATION __constant_cpu_to_le32(0xC0150010)
1286#define STATUS_SXS_MULTIPLE_DEACTIVATION __constant_cpu_to_le32(0xC0150011)
1287#define STATUS_SXS_SYSTEM_DEFAULT_ACTIVATION_CONTEXT_EMPTY __constant_cpu_to_le32(0xC0150012)
1288#define STATUS_SXS_PROCESS_TERMINATION_REQUESTED __constant_cpu_to_le32(0xC0150013)
1289#define STATUS_SXS_CORRUPT_ACTIVATION_STACK __constant_cpu_to_le32(0xC0150014)
1290#define STATUS_SXS_CORRUPTION __constant_cpu_to_le32(0xC0150015)
1291#define STATUS_SXS_INVALID_IDENTITY_ATTRIBUTE_VALUE __constant_cpu_to_le32(0xC0150016)
1292#define STATUS_SXS_INVALID_IDENTITY_ATTRIBUTE_NAME __constant_cpu_to_le32(0xC0150017)
1293#define STATUS_SXS_IDENTITY_DUPLICATE_ATTRIBUTE __constant_cpu_to_le32(0xC0150018)
1294#define STATUS_SXS_IDENTITY_PARSE_ERROR __constant_cpu_to_le32(0xC0150019)
1295#define STATUS_SXS_COMPONENT_STORE_CORRUPT __constant_cpu_to_le32(0xC015001A)
1296#define STATUS_SXS_FILE_HASH_MISMATCH __constant_cpu_to_le32(0xC015001B)
1297#define STATUS_SXS_MANIFEST_IDENTITY_SAME_BUT_CONTENTS_DIFFERENT __constant_cpu_to_le32(0xC015001C)
1298#define STATUS_SXS_IDENTITIES_DIFFERENT __constant_cpu_to_le32(0xC015001D)
1299#define STATUS_SXS_ASSEMBLY_IS_NOT_A_DEPLOYMENT __constant_cpu_to_le32(0xC015001E)
1300#define STATUS_SXS_FILE_NOT_PART_OF_ASSEMBLY __constant_cpu_to_le32(0xC015001F)
1301#define STATUS_ADVANCED_INSTALLER_FAILED __constant_cpu_to_le32(0xC0150020)
1302#define STATUS_XML_ENCODING_MISMATCH __constant_cpu_to_le32(0xC0150021)
1303#define STATUS_SXS_MANIFEST_TOO_BIG __constant_cpu_to_le32(0xC0150022)
1304#define STATUS_SXS_SETTING_NOT_REGISTERED __constant_cpu_to_le32(0xC0150023)
1305#define STATUS_SXS_TRANSACTION_CLOSURE_INCOMPLETE __constant_cpu_to_le32(0xC0150024)
1306#define STATUS_SMI_PRIMITIVE_INSTALLER_FAILED __constant_cpu_to_le32(0xC0150025)
1307#define STATUS_GENERIC_COMMAND_FAILED __constant_cpu_to_le32(0xC0150026)
1308#define STATUS_SXS_FILE_HASH_MISSING __constant_cpu_to_le32(0xC0150027)
1309#define STATUS_TRANSACTIONAL_CONFLICT __constant_cpu_to_le32(0xC0190001)
1310#define STATUS_INVALID_TRANSACTION __constant_cpu_to_le32(0xC0190002)
1311#define STATUS_TRANSACTION_NOT_ACTIVE __constant_cpu_to_le32(0xC0190003)
1312#define STATUS_TM_INITIALIZATION_FAILED __constant_cpu_to_le32(0xC0190004)
1313#define STATUS_RM_NOT_ACTIVE __constant_cpu_to_le32(0xC0190005)
1314#define STATUS_RM_METADATA_CORRUPT __constant_cpu_to_le32(0xC0190006)
1315#define STATUS_TRANSACTION_NOT_JOINED __constant_cpu_to_le32(0xC0190007)
1316#define STATUS_DIRECTORY_NOT_RM __constant_cpu_to_le32(0xC0190008)
1317#define STATUS_TRANSACTIONS_UNSUPPORTED_REMOTE __constant_cpu_to_le32(0xC019000A)
1318#define STATUS_LOG_RESIZE_INVALID_SIZE __constant_cpu_to_le32(0xC019000B)
1319#define STATUS_REMOTE_FILE_VERSION_MISMATCH __constant_cpu_to_le32(0xC019000C)
1320#define STATUS_CRM_PROTOCOL_ALREADY_EXISTS __constant_cpu_to_le32(0xC019000F)
1321#define STATUS_TRANSACTION_PROPAGATION_FAILED __constant_cpu_to_le32(0xC0190010)
1322#define STATUS_CRM_PROTOCOL_NOT_FOUND __constant_cpu_to_le32(0xC0190011)
1323#define STATUS_TRANSACTION_SUPERIOR_EXISTS __constant_cpu_to_le32(0xC0190012)
1324#define STATUS_TRANSACTION_REQUEST_NOT_VALID __constant_cpu_to_le32(0xC0190013)
1325#define STATUS_TRANSACTION_NOT_REQUESTED __constant_cpu_to_le32(0xC0190014)
1326#define STATUS_TRANSACTION_ALREADY_ABORTED __constant_cpu_to_le32(0xC0190015)
1327#define STATUS_TRANSACTION_ALREADY_COMMITTED __constant_cpu_to_le32(0xC0190016)
1328#define STATUS_TRANSACTION_INVALID_MARSHALL_BUFFER __constant_cpu_to_le32(0xC0190017)
1329#define STATUS_CURRENT_TRANSACTION_NOT_VALID __constant_cpu_to_le32(0xC0190018)
1330#define STATUS_LOG_GROWTH_FAILED __constant_cpu_to_le32(0xC0190019)
1331#define STATUS_OBJECT_NO_LONGER_EXISTS __constant_cpu_to_le32(0xC0190021)
1332#define STATUS_STREAM_MINIVERSION_NOT_FOUND __constant_cpu_to_le32(0xC0190022)
1333#define STATUS_STREAM_MINIVERSION_NOT_VALID __constant_cpu_to_le32(0xC0190023)
1334#define STATUS_MINIVERSION_INACCESSIBLE_FROM_SPECIFIED_TRANSACTION __constant_cpu_to_le32(0xC0190024)
1335#define STATUS_CANT_OPEN_MINIVERSION_WITH_MODIFY_INTENT __constant_cpu_to_le32(0xC0190025)
1336#define STATUS_CANT_CREATE_MORE_STREAM_MINIVERSIONS __constant_cpu_to_le32(0xC0190026)
1337#define STATUS_HANDLE_NO_LONGER_VALID __constant_cpu_to_le32(0xC0190028)
1338#define STATUS_LOG_CORRUPTION_DETECTED __constant_cpu_to_le32(0xC0190030)
1339#define STATUS_RM_DISCONNECTED __constant_cpu_to_le32(0xC0190032)
1340#define STATUS_ENLISTMENT_NOT_SUPERIOR __constant_cpu_to_le32(0xC0190033)
1341#define STATUS_FILE_IDENTITY_NOT_PERSISTENT __constant_cpu_to_le32(0xC0190036)
1342#define STATUS_CANT_BREAK_TRANSACTIONAL_DEPENDENCY __constant_cpu_to_le32(0xC0190037)
1343#define STATUS_CANT_CROSS_RM_BOUNDARY __constant_cpu_to_le32(0xC0190038)
1344#define STATUS_TXF_DIR_NOT_EMPTY __constant_cpu_to_le32(0xC0190039)
1345#define STATUS_INDOUBT_TRANSACTIONS_EXIST __constant_cpu_to_le32(0xC019003A)
1346#define STATUS_TM_VOLATILE __constant_cpu_to_le32(0xC019003B)
1347#define STATUS_ROLLBACK_TIMER_EXPIRED __constant_cpu_to_le32(0xC019003C)
1348#define STATUS_TXF_ATTRIBUTE_CORRUPT __constant_cpu_to_le32(0xC019003D)
1349#define STATUS_EFS_NOT_ALLOWED_IN_TRANSACTION __constant_cpu_to_le32(0xC019003E)
1350#define STATUS_TRANSACTIONAL_OPEN_NOT_ALLOWED __constant_cpu_to_le32(0xC019003F)
1351#define STATUS_TRANSACTED_MAPPING_UNSUPPORTED_REMOTE __constant_cpu_to_le32(0xC0190040)
1352#define STATUS_TRANSACTION_REQUIRED_PROMOTION __constant_cpu_to_le32(0xC0190043)
1353#define STATUS_CANNOT_EXECUTE_FILE_IN_TRANSACTION __constant_cpu_to_le32(0xC0190044)
1354#define STATUS_TRANSACTIONS_NOT_FROZEN __constant_cpu_to_le32(0xC0190045)
1355#define STATUS_TRANSACTION_FREEZE_IN_PROGRESS __constant_cpu_to_le32(0xC0190046)
1356#define STATUS_NOT_SNAPSHOT_VOLUME __constant_cpu_to_le32(0xC0190047)
1357#define STATUS_NO_SAVEPOINT_WITH_OPEN_FILES __constant_cpu_to_le32(0xC0190048)
1358#define STATUS_SPARSE_NOT_ALLOWED_IN_TRANSACTION __constant_cpu_to_le32(0xC0190049)
1359#define STATUS_TM_IDENTITY_MISMATCH __constant_cpu_to_le32(0xC019004A)
1360#define STATUS_FLOATED_SECTION __constant_cpu_to_le32(0xC019004B)
1361#define STATUS_CANNOT_ACCEPT_TRANSACTED_WORK __constant_cpu_to_le32(0xC019004C)
1362#define STATUS_CANNOT_ABORT_TRANSACTIONS __constant_cpu_to_le32(0xC019004D)
1363#define STATUS_TRANSACTION_NOT_FOUND __constant_cpu_to_le32(0xC019004E)
1364#define STATUS_RESOURCEMANAGER_NOT_FOUND __constant_cpu_to_le32(0xC019004F)
1365#define STATUS_ENLISTMENT_NOT_FOUND __constant_cpu_to_le32(0xC0190050)
1366#define STATUS_TRANSACTIONMANAGER_NOT_FOUND __constant_cpu_to_le32(0xC0190051)
1367#define STATUS_TRANSACTIONMANAGER_NOT_ONLINE __constant_cpu_to_le32(0xC0190052)
1368#define STATUS_TRANSACTIONMANAGER_RECOVERY_NAME_COLLISION __constant_cpu_to_le32(0xC0190053)
1369#define STATUS_TRANSACTION_NOT_ROOT __constant_cpu_to_le32(0xC0190054)
1370#define STATUS_TRANSACTION_OBJECT_EXPIRED __constant_cpu_to_le32(0xC0190055)
1371#define STATUS_COMPRESSION_NOT_ALLOWED_IN_TRANSACTION __constant_cpu_to_le32(0xC0190056)
1372#define STATUS_TRANSACTION_RESPONSE_NOT_ENLISTED __constant_cpu_to_le32(0xC0190057)
1373#define STATUS_TRANSACTION_RECORD_TOO_LONG __constant_cpu_to_le32(0xC0190058)
1374#define STATUS_NO_LINK_TRACKING_IN_TRANSACTION __constant_cpu_to_le32(0xC0190059)
1375#define STATUS_OPERATION_NOT_SUPPORTED_IN_TRANSACTION __constant_cpu_to_le32(0xC019005A)
1376#define STATUS_TRANSACTION_INTEGRITY_VIOLATED __constant_cpu_to_le32(0xC019005B)
1377#define STATUS_LOG_SECTOR_INVALID __constant_cpu_to_le32(0xC01A0001)
1378#define STATUS_LOG_SECTOR_PARITY_INVALID __constant_cpu_to_le32(0xC01A0002)
1379#define STATUS_LOG_SECTOR_REMAPPED __constant_cpu_to_le32(0xC01A0003)
1380#define STATUS_LOG_BLOCK_INCOMPLETE __constant_cpu_to_le32(0xC01A0004)
1381#define STATUS_LOG_INVALID_RANGE __constant_cpu_to_le32(0xC01A0005)
1382#define STATUS_LOG_BLOCKS_EXHAUSTED __constant_cpu_to_le32(0xC01A0006)
1383#define STATUS_LOG_READ_CONTEXT_INVALID __constant_cpu_to_le32(0xC01A0007)
1384#define STATUS_LOG_RESTART_INVALID __constant_cpu_to_le32(0xC01A0008)
1385#define STATUS_LOG_BLOCK_VERSION __constant_cpu_to_le32(0xC01A0009)
1386#define STATUS_LOG_BLOCK_INVALID __constant_cpu_to_le32(0xC01A000A)
1387#define STATUS_LOG_READ_MODE_INVALID __constant_cpu_to_le32(0xC01A000B)
1388#define STATUS_LOG_METADATA_CORRUPT __constant_cpu_to_le32(0xC01A000D)
1389#define STATUS_LOG_METADATA_INVALID __constant_cpu_to_le32(0xC01A000E)
1390#define STATUS_LOG_METADATA_INCONSISTENT __constant_cpu_to_le32(0xC01A000F)
1391#define STATUS_LOG_RESERVATION_INVALID __constant_cpu_to_le32(0xC01A0010)
1392#define STATUS_LOG_CANT_DELETE __constant_cpu_to_le32(0xC01A0011)
1393#define STATUS_LOG_CONTAINER_LIMIT_EXCEEDED __constant_cpu_to_le32(0xC01A0012)
1394#define STATUS_LOG_START_OF_LOG __constant_cpu_to_le32(0xC01A0013)
1395#define STATUS_LOG_POLICY_ALREADY_INSTALLED __constant_cpu_to_le32(0xC01A0014)
1396#define STATUS_LOG_POLICY_NOT_INSTALLED __constant_cpu_to_le32(0xC01A0015)
1397#define STATUS_LOG_POLICY_INVALID __constant_cpu_to_le32(0xC01A0016)
1398#define STATUS_LOG_POLICY_CONFLICT __constant_cpu_to_le32(0xC01A0017)
1399#define STATUS_LOG_PINNED_ARCHIVE_TAIL __constant_cpu_to_le32(0xC01A0018)
1400#define STATUS_LOG_RECORD_NONEXISTENT __constant_cpu_to_le32(0xC01A0019)
1401#define STATUS_LOG_RECORDS_RESERVED_INVALID __constant_cpu_to_le32(0xC01A001A)
1402#define STATUS_LOG_SPACE_RESERVED_INVALID __constant_cpu_to_le32(0xC01A001B)
1403#define STATUS_LOG_TAIL_INVALID __constant_cpu_to_le32(0xC01A001C)
1404#define STATUS_LOG_FULL __constant_cpu_to_le32(0xC01A001D)
1405#define STATUS_LOG_MULTIPLEXED __constant_cpu_to_le32(0xC01A001E)
1406#define STATUS_LOG_DEDICATED __constant_cpu_to_le32(0xC01A001F)
1407#define STATUS_LOG_ARCHIVE_NOT_IN_PROGRESS __constant_cpu_to_le32(0xC01A0020)
1408#define STATUS_LOG_ARCHIVE_IN_PROGRESS __constant_cpu_to_le32(0xC01A0021)
1409#define STATUS_LOG_EPHEMERAL __constant_cpu_to_le32(0xC01A0022)
1410#define STATUS_LOG_NOT_ENOUGH_CONTAINERS __constant_cpu_to_le32(0xC01A0023)
1411#define STATUS_LOG_CLIENT_ALREADY_REGISTERED __constant_cpu_to_le32(0xC01A0024)
1412#define STATUS_LOG_CLIENT_NOT_REGISTERED __constant_cpu_to_le32(0xC01A0025)
1413#define STATUS_LOG_FULL_HANDLER_IN_PROGRESS __constant_cpu_to_le32(0xC01A0026)
1414#define STATUS_LOG_CONTAINER_READ_FAILED __constant_cpu_to_le32(0xC01A0027)
1415#define STATUS_LOG_CONTAINER_WRITE_FAILED __constant_cpu_to_le32(0xC01A0028)
1416#define STATUS_LOG_CONTAINER_OPEN_FAILED __constant_cpu_to_le32(0xC01A0029)
1417#define STATUS_LOG_CONTAINER_STATE_INVALID __constant_cpu_to_le32(0xC01A002A)
1418#define STATUS_LOG_STATE_INVALID __constant_cpu_to_le32(0xC01A002B)
1419#define STATUS_LOG_PINNED __constant_cpu_to_le32(0xC01A002C)
1420#define STATUS_LOG_METADATA_FLUSH_FAILED __constant_cpu_to_le32(0xC01A002D)
1421#define STATUS_LOG_INCONSISTENT_SECURITY __constant_cpu_to_le32(0xC01A002E)
1422#define STATUS_LOG_APPENDED_FLUSH_FAILED __constant_cpu_to_le32(0xC01A002F)
1423#define STATUS_LOG_PINNED_RESERVATION __constant_cpu_to_le32(0xC01A0030)
1424#define STATUS_VIDEO_HUNG_DISPLAY_DRIVER_THREAD __constant_cpu_to_le32(0xC01B00EA)
1425#define STATUS_FLT_NO_HANDLER_DEFINED __constant_cpu_to_le32(0xC01C0001)
1426#define STATUS_FLT_CONTEXT_ALREADY_DEFINED __constant_cpu_to_le32(0xC01C0002)
1427#define STATUS_FLT_INVALID_ASYNCHRONOUS_REQUEST __constant_cpu_to_le32(0xC01C0003)
1428#define STATUS_FLT_DISALLOW_FAST_IO __constant_cpu_to_le32(0xC01C0004)
1429#define STATUS_FLT_INVALID_NAME_REQUEST __constant_cpu_to_le32(0xC01C0005)
1430#define STATUS_FLT_NOT_SAFE_TO_POST_OPERATION __constant_cpu_to_le32(0xC01C0006)
1431#define STATUS_FLT_NOT_INITIALIZED __constant_cpu_to_le32(0xC01C0007)
1432#define STATUS_FLT_FILTER_NOT_READY __constant_cpu_to_le32(0xC01C0008)
1433#define STATUS_FLT_POST_OPERATION_CLEANUP __constant_cpu_to_le32(0xC01C0009)
1434#define STATUS_FLT_INTERNAL_ERROR __constant_cpu_to_le32(0xC01C000A)
1435#define STATUS_FLT_DELETING_OBJECT __constant_cpu_to_le32(0xC01C000B)
1436#define STATUS_FLT_MUST_BE_NONPAGED_POOL __constant_cpu_to_le32(0xC01C000C)
1437#define STATUS_FLT_DUPLICATE_ENTRY __constant_cpu_to_le32(0xC01C000D)
1438#define STATUS_FLT_CBDQ_DISABLED __constant_cpu_to_le32(0xC01C000E)
1439#define STATUS_FLT_DO_NOT_ATTACH __constant_cpu_to_le32(0xC01C000F)
1440#define STATUS_FLT_DO_NOT_DETACH __constant_cpu_to_le32(0xC01C0010)
1441#define STATUS_FLT_INSTANCE_ALTITUDE_COLLISION __constant_cpu_to_le32(0xC01C0011)
1442#define STATUS_FLT_INSTANCE_NAME_COLLISION __constant_cpu_to_le32(0xC01C0012)
1443#define STATUS_FLT_FILTER_NOT_FOUND __constant_cpu_to_le32(0xC01C0013)
1444#define STATUS_FLT_VOLUME_NOT_FOUND __constant_cpu_to_le32(0xC01C0014)
1445#define STATUS_FLT_INSTANCE_NOT_FOUND __constant_cpu_to_le32(0xC01C0015)
1446#define STATUS_FLT_CONTEXT_ALLOCATION_NOT_FOUND __constant_cpu_to_le32(0xC01C0016)
1447#define STATUS_FLT_INVALID_CONTEXT_REGISTRATION __constant_cpu_to_le32(0xC01C0017)
1448#define STATUS_FLT_NAME_CACHE_MISS __constant_cpu_to_le32(0xC01C0018)
1449#define STATUS_FLT_NO_DEVICE_OBJECT __constant_cpu_to_le32(0xC01C0019)
1450#define STATUS_FLT_VOLUME_ALREADY_MOUNTED __constant_cpu_to_le32(0xC01C001A)
1451#define STATUS_FLT_ALREADY_ENLISTED __constant_cpu_to_le32(0xC01C001B)
1452#define STATUS_FLT_CONTEXT_ALREADY_LINKED __constant_cpu_to_le32(0xC01C001C)
1453#define STATUS_FLT_NO_WAITER_FOR_REPLY __constant_cpu_to_le32(0xC01C0020)
1454#define STATUS_MONITOR_NO_DESCRIPTOR __constant_cpu_to_le32(0xC01D0001)
1455#define STATUS_MONITOR_UNKNOWN_DESCRIPTOR_FORMAT __constant_cpu_to_le32(0xC01D0002)
1456#define STATUS_MONITOR_INVALID_DESCRIPTOR_CHECKSUM __constant_cpu_to_le32(0xC01D0003)
1457#define STATUS_MONITOR_INVALID_STANDARD_TIMING_BLOCK __constant_cpu_to_le32(0xC01D0004)
1458#define STATUS_MONITOR_WMI_DATABLOCK_REGISTRATION_FAILED __constant_cpu_to_le32(0xC01D0005)
1459#define STATUS_MONITOR_INVALID_SERIAL_NUMBER_MONDSC_BLOCK __constant_cpu_to_le32(0xC01D0006)
1460#define STATUS_MONITOR_INVALID_USER_FRIENDLY_MONDSC_BLOCK __constant_cpu_to_le32(0xC01D0007)
1461#define STATUS_MONITOR_NO_MORE_DESCRIPTOR_DATA __constant_cpu_to_le32(0xC01D0008)
1462#define STATUS_MONITOR_INVALID_DETAILED_TIMING_BLOCK __constant_cpu_to_le32(0xC01D0009)
1463#define STATUS_GRAPHICS_NOT_EXCLUSIVE_MODE_OWNER __constant_cpu_to_le32(0xC01E0000)
1464#define STATUS_GRAPHICS_INSUFFICIENT_DMA_BUFFER __constant_cpu_to_le32(0xC01E0001)
1465#define STATUS_GRAPHICS_INVALID_DISPLAY_ADAPTER __constant_cpu_to_le32(0xC01E0002)
1466#define STATUS_GRAPHICS_ADAPTER_WAS_RESET __constant_cpu_to_le32(0xC01E0003)
1467#define STATUS_GRAPHICS_INVALID_DRIVER_MODEL __constant_cpu_to_le32(0xC01E0004)
1468#define STATUS_GRAPHICS_PRESENT_MODE_CHANGED __constant_cpu_to_le32(0xC01E0005)
1469#define STATUS_GRAPHICS_PRESENT_OCCLUDED __constant_cpu_to_le32(0xC01E0006)
1470#define STATUS_GRAPHICS_PRESENT_DENIED __constant_cpu_to_le32(0xC01E0007)
1471#define STATUS_GRAPHICS_CANNOTCOLORCONVERT __constant_cpu_to_le32(0xC01E0008)
1472#define STATUS_GRAPHICS_NO_VIDEO_MEMORY __constant_cpu_to_le32(0xC01E0100)
1473#define STATUS_GRAPHICS_CANT_LOCK_MEMORY __constant_cpu_to_le32(0xC01E0101)
1474#define STATUS_GRAPHICS_ALLOCATION_BUSY __constant_cpu_to_le32(0xC01E0102)
1475#define STATUS_GRAPHICS_TOO_MANY_REFERENCES __constant_cpu_to_le32(0xC01E0103)
1476#define STATUS_GRAPHICS_TRY_AGAIN_LATER __constant_cpu_to_le32(0xC01E0104)
1477#define STATUS_GRAPHICS_TRY_AGAIN_NOW __constant_cpu_to_le32(0xC01E0105)
1478#define STATUS_GRAPHICS_ALLOCATION_INVALID __constant_cpu_to_le32(0xC01E0106)
1479#define STATUS_GRAPHICS_UNSWIZZLING_APERTURE_UNAVAILABLE __constant_cpu_to_le32(0xC01E0107)
1480#define STATUS_GRAPHICS_UNSWIZZLING_APERTURE_UNSUPPORTED __constant_cpu_to_le32(0xC01E0108)
1481#define STATUS_GRAPHICS_CANT_EVICT_PINNED_ALLOCATION __constant_cpu_to_le32(0xC01E0109)
1482#define STATUS_GRAPHICS_INVALID_ALLOCATION_USAGE __constant_cpu_to_le32(0xC01E0110)
1483#define STATUS_GRAPHICS_CANT_RENDER_LOCKED_ALLOCATION __constant_cpu_to_le32(0xC01E0111)
1484#define STATUS_GRAPHICS_ALLOCATION_CLOSED __constant_cpu_to_le32(0xC01E0112)
1485#define STATUS_GRAPHICS_INVALID_ALLOCATION_INSTANCE __constant_cpu_to_le32(0xC01E0113)
1486#define STATUS_GRAPHICS_INVALID_ALLOCATION_HANDLE __constant_cpu_to_le32(0xC01E0114)
1487#define STATUS_GRAPHICS_WRONG_ALLOCATION_DEVICE __constant_cpu_to_le32(0xC01E0115)
1488#define STATUS_GRAPHICS_ALLOCATION_CONTENT_LOST __constant_cpu_to_le32(0xC01E0116)
1489#define STATUS_GRAPHICS_GPU_EXCEPTION_ON_DEVICE __constant_cpu_to_le32(0xC01E0200)
1490#define STATUS_GRAPHICS_INVALID_VIDPN_TOPOLOGY __constant_cpu_to_le32(0xC01E0300)
1491#define STATUS_GRAPHICS_VIDPN_TOPOLOGY_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0301)
1492#define STATUS_GRAPHICS_VIDPN_TOPOLOGY_CURRENTLY_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0302)
1493#define STATUS_GRAPHICS_INVALID_VIDPN __constant_cpu_to_le32(0xC01E0303)
1494#define STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE __constant_cpu_to_le32(0xC01E0304)
1495#define STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_TARGET __constant_cpu_to_le32(0xC01E0305)
1496#define STATUS_GRAPHICS_VIDPN_MODALITY_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0306)
1497#define STATUS_GRAPHICS_INVALID_VIDPN_SOURCEMODESET __constant_cpu_to_le32(0xC01E0308)
1498#define STATUS_GRAPHICS_INVALID_VIDPN_TARGETMODESET __constant_cpu_to_le32(0xC01E0309)
1499#define STATUS_GRAPHICS_INVALID_FREQUENCY __constant_cpu_to_le32(0xC01E030A)
1500#define STATUS_GRAPHICS_INVALID_ACTIVE_REGION __constant_cpu_to_le32(0xC01E030B)
1501#define STATUS_GRAPHICS_INVALID_TOTAL_REGION __constant_cpu_to_le32(0xC01E030C)
1502#define STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_SOURCE_MODE __constant_cpu_to_le32(0xC01E0310)
1503#define STATUS_GRAPHICS_INVALID_VIDEO_PRESENT_TARGET_MODE __constant_cpu_to_le32(0xC01E0311)
1504#define STATUS_GRAPHICS_PINNED_MODE_MUST_REMAIN_IN_SET __constant_cpu_to_le32(0xC01E0312)
1505#define STATUS_GRAPHICS_PATH_ALREADY_IN_TOPOLOGY __constant_cpu_to_le32(0xC01E0313)
1506#define STATUS_GRAPHICS_MODE_ALREADY_IN_MODESET __constant_cpu_to_le32(0xC01E0314)
1507#define STATUS_GRAPHICS_INVALID_VIDEOPRESENTSOURCESET __constant_cpu_to_le32(0xC01E0315)
1508#define STATUS_GRAPHICS_INVALID_VIDEOPRESENTTARGETSET __constant_cpu_to_le32(0xC01E0316)
1509#define STATUS_GRAPHICS_SOURCE_ALREADY_IN_SET __constant_cpu_to_le32(0xC01E0317)
1510#define STATUS_GRAPHICS_TARGET_ALREADY_IN_SET __constant_cpu_to_le32(0xC01E0318)
1511#define STATUS_GRAPHICS_INVALID_VIDPN_PRESENT_PATH __constant_cpu_to_le32(0xC01E0319)
1512#define STATUS_GRAPHICS_NO_RECOMMENDED_VIDPN_TOPOLOGY __constant_cpu_to_le32(0xC01E031A)
1513#define STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGESET __constant_cpu_to_le32(0xC01E031B)
1514#define STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE __constant_cpu_to_le32(0xC01E031C)
1515#define STATUS_GRAPHICS_FREQUENCYRANGE_NOT_IN_SET __constant_cpu_to_le32(0xC01E031D)
1516#define STATUS_GRAPHICS_FREQUENCYRANGE_ALREADY_IN_SET __constant_cpu_to_le32(0xC01E031F)
1517#define STATUS_GRAPHICS_STALE_MODESET __constant_cpu_to_le32(0xC01E0320)
1518#define STATUS_GRAPHICS_INVALID_MONITOR_SOURCEMODESET __constant_cpu_to_le32(0xC01E0321)
1519#define STATUS_GRAPHICS_INVALID_MONITOR_SOURCE_MODE __constant_cpu_to_le32(0xC01E0322)
1520#define STATUS_GRAPHICS_NO_RECOMMENDED_FUNCTIONAL_VIDPN __constant_cpu_to_le32(0xC01E0323)
1521#define STATUS_GRAPHICS_MODE_ID_MUST_BE_UNIQUE __constant_cpu_to_le32(0xC01E0324)
1522#define STATUS_GRAPHICS_EMPTY_ADAPTER_MONITOR_MODE_SUPPORT_INTERSECTION __constant_cpu_to_le32(0xC01E0325)
1523#define STATUS_GRAPHICS_VIDEO_PRESENT_TARGETS_LESS_THAN_SOURCES __constant_cpu_to_le32(0xC01E0326)
1524#define STATUS_GRAPHICS_PATH_NOT_IN_TOPOLOGY __constant_cpu_to_le32(0xC01E0327)
1525#define STATUS_GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_SOURCE __constant_cpu_to_le32(0xC01E0328)
1526#define STATUS_GRAPHICS_ADAPTER_MUST_HAVE_AT_LEAST_ONE_TARGET __constant_cpu_to_le32(0xC01E0329)
1527#define STATUS_GRAPHICS_INVALID_MONITORDESCRIPTORSET __constant_cpu_to_le32(0xC01E032A)
1528#define STATUS_GRAPHICS_INVALID_MONITORDESCRIPTOR __constant_cpu_to_le32(0xC01E032B)
1529#define STATUS_GRAPHICS_MONITORDESCRIPTOR_NOT_IN_SET __constant_cpu_to_le32(0xC01E032C)
1530#define STATUS_GRAPHICS_MONITORDESCRIPTOR_ALREADY_IN_SET __constant_cpu_to_le32(0xC01E032D)
1531#define STATUS_GRAPHICS_MONITORDESCRIPTOR_ID_MUST_BE_UNIQUE __constant_cpu_to_le32(0xC01E032E)
1532#define STATUS_GRAPHICS_INVALID_VIDPN_TARGET_SUBSET_TYPE __constant_cpu_to_le32(0xC01E032F)
1533#define STATUS_GRAPHICS_RESOURCES_NOT_RELATED __constant_cpu_to_le32(0xC01E0330)
1534#define STATUS_GRAPHICS_SOURCE_ID_MUST_BE_UNIQUE __constant_cpu_to_le32(0xC01E0331)
1535#define STATUS_GRAPHICS_TARGET_ID_MUST_BE_UNIQUE __constant_cpu_to_le32(0xC01E0332)
1536#define STATUS_GRAPHICS_NO_AVAILABLE_VIDPN_TARGET __constant_cpu_to_le32(0xC01E0333)
1537#define STATUS_GRAPHICS_MONITOR_COULD_NOT_BE_ASSOCIATED_WITH_ADAPTER __constant_cpu_to_le32(0xC01E0334)
1538#define STATUS_GRAPHICS_NO_VIDPNMGR __constant_cpu_to_le32(0xC01E0335)
1539#define STATUS_GRAPHICS_NO_ACTIVE_VIDPN __constant_cpu_to_le32(0xC01E0336)
1540#define STATUS_GRAPHICS_STALE_VIDPN_TOPOLOGY __constant_cpu_to_le32(0xC01E0337)
1541#define STATUS_GRAPHICS_MONITOR_NOT_CONNECTED __constant_cpu_to_le32(0xC01E0338)
1542#define STATUS_GRAPHICS_SOURCE_NOT_IN_TOPOLOGY __constant_cpu_to_le32(0xC01E0339)
1543#define STATUS_GRAPHICS_INVALID_PRIMARYSURFACE_SIZE __constant_cpu_to_le32(0xC01E033A)
1544#define STATUS_GRAPHICS_INVALID_VISIBLEREGION_SIZE __constant_cpu_to_le32(0xC01E033B)
1545#define STATUS_GRAPHICS_INVALID_STRIDE __constant_cpu_to_le32(0xC01E033C)
1546#define STATUS_GRAPHICS_INVALID_PIXELFORMAT __constant_cpu_to_le32(0xC01E033D)
1547#define STATUS_GRAPHICS_INVALID_COLORBASIS __constant_cpu_to_le32(0xC01E033E)
1548#define STATUS_GRAPHICS_INVALID_PIXELVALUEACCESSMODE __constant_cpu_to_le32(0xC01E033F)
1549#define STATUS_GRAPHICS_TARGET_NOT_IN_TOPOLOGY __constant_cpu_to_le32(0xC01E0340)
1550#define STATUS_GRAPHICS_NO_DISPLAY_MODE_MANAGEMENT_SUPPORT __constant_cpu_to_le32(0xC01E0341)
1551#define STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE __constant_cpu_to_le32(0xC01E0342)
1552#define STATUS_GRAPHICS_CANT_ACCESS_ACTIVE_VIDPN __constant_cpu_to_le32(0xC01E0343)
1553#define STATUS_GRAPHICS_INVALID_PATH_IMPORTANCE_ORDINAL __constant_cpu_to_le32(0xC01E0344)
1554#define STATUS_GRAPHICS_INVALID_PATH_CONTENT_GEOMETRY_TRANSFORMATION __constant_cpu_to_le32(0xC01E0345)
1555#define STATUS_GRAPHICS_PATH_CONTENT_GEOMETRY_TRANSFORMATION_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0346)
1556#define STATUS_GRAPHICS_INVALID_GAMMA_RAMP __constant_cpu_to_le32(0xC01E0347)
1557#define STATUS_GRAPHICS_GAMMA_RAMP_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0348)
1558#define STATUS_GRAPHICS_MULTISAMPLING_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0349)
1559#define STATUS_GRAPHICS_MODE_NOT_IN_MODESET __constant_cpu_to_le32(0xC01E034A)
1560#define STATUS_GRAPHICS_INVALID_VIDPN_TOPOLOGY_RECOMMENDATION_REASON __constant_cpu_to_le32(0xC01E034D)
1561#define STATUS_GRAPHICS_INVALID_PATH_CONTENT_TYPE __constant_cpu_to_le32(0xC01E034E)
1562#define STATUS_GRAPHICS_INVALID_COPYPROTECTION_TYPE __constant_cpu_to_le32(0xC01E034F)
1563#define STATUS_GRAPHICS_UNASSIGNED_MODESET_ALREADY_EXISTS __constant_cpu_to_le32(0xC01E0350)
1564#define STATUS_GRAPHICS_INVALID_SCANLINE_ORDERING __constant_cpu_to_le32(0xC01E0352)
1565#define STATUS_GRAPHICS_TOPOLOGY_CHANGES_NOT_ALLOWED __constant_cpu_to_le32(0xC01E0353)
1566#define STATUS_GRAPHICS_NO_AVAILABLE_IMPORTANCE_ORDINALS __constant_cpu_to_le32(0xC01E0354)
1567#define STATUS_GRAPHICS_INCOMPATIBLE_PRIVATE_FORMAT __constant_cpu_to_le32(0xC01E0355)
1568#define STATUS_GRAPHICS_INVALID_MODE_PRUNING_ALGORITHM __constant_cpu_to_le32(0xC01E0356)
1569#define STATUS_GRAPHICS_INVALID_MONITOR_CAPABILITY_ORIGIN __constant_cpu_to_le32(0xC01E0357)
1570#define STATUS_GRAPHICS_INVALID_MONITOR_FREQUENCYRANGE_CONSTRAINT __constant_cpu_to_le32(0xC01E0358)
1571#define STATUS_GRAPHICS_MAX_NUM_PATHS_REACHED __constant_cpu_to_le32(0xC01E0359)
1572#define STATUS_GRAPHICS_CANCEL_VIDPN_TOPOLOGY_AUGMENTATION __constant_cpu_to_le32(0xC01E035A)
1573#define STATUS_GRAPHICS_INVALID_CLIENT_TYPE __constant_cpu_to_le32(0xC01E035B)
1574#define STATUS_GRAPHICS_CLIENTVIDPN_NOT_SET __constant_cpu_to_le32(0xC01E035C)
1575#define STATUS_GRAPHICS_SPECIFIED_CHILD_ALREADY_CONNECTED __constant_cpu_to_le32(0xC01E0400)
1576#define STATUS_GRAPHICS_CHILD_DESCRIPTOR_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0401)
1577#define STATUS_GRAPHICS_NOT_A_LINKED_ADAPTER __constant_cpu_to_le32(0xC01E0430)
1578#define STATUS_GRAPHICS_LEADLINK_NOT_ENUMERATED __constant_cpu_to_le32(0xC01E0431)
1579#define STATUS_GRAPHICS_CHAINLINKS_NOT_ENUMERATED __constant_cpu_to_le32(0xC01E0432)
1580#define STATUS_GRAPHICS_ADAPTER_CHAIN_NOT_READY __constant_cpu_to_le32(0xC01E0433)
1581#define STATUS_GRAPHICS_CHAINLINKS_NOT_STARTED __constant_cpu_to_le32(0xC01E0434)
1582#define STATUS_GRAPHICS_CHAINLINKS_NOT_POWERED_ON __constant_cpu_to_le32(0xC01E0435)
1583#define STATUS_GRAPHICS_INCONSISTENT_DEVICE_LINK_STATE __constant_cpu_to_le32(0xC01E0436)
1584#define STATUS_GRAPHICS_NOT_POST_DEVICE_DRIVER __constant_cpu_to_le32(0xC01E0438)
1585#define STATUS_GRAPHICS_ADAPTER_ACCESS_NOT_EXCLUDED __constant_cpu_to_le32(0xC01E043B)
1586#define STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_COPP_SEMANTICS __constant_cpu_to_le32(0xC01E051C)
1587#define STATUS_GRAPHICS_OPM_INVALID_INFORMATION_REQUEST __constant_cpu_to_le32(0xC01E051D)
1588#define STATUS_GRAPHICS_OPM_DRIVER_INTERNAL_ERROR __constant_cpu_to_le32(0xC01E051E)
1589#define STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_DOES_NOT_HAVE_OPM_SEMANTICS __constant_cpu_to_le32(0xC01E051F)
1590#define STATUS_GRAPHICS_OPM_SIGNALING_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0520)
1591#define STATUS_GRAPHICS_OPM_INVALID_CONFIGURATION_REQUEST __constant_cpu_to_le32(0xC01E0521)
1592#define STATUS_GRAPHICS_OPM_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0500)
1593#define STATUS_GRAPHICS_COPP_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0501)
1594#define STATUS_GRAPHICS_UAB_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0502)
1595#define STATUS_GRAPHICS_OPM_INVALID_ENCRYPTED_PARAMETERS __constant_cpu_to_le32(0xC01E0503)
1596#define STATUS_GRAPHICS_OPM_PARAMETER_ARRAY_TOO_SMALL __constant_cpu_to_le32(0xC01E0504)
1597#define STATUS_GRAPHICS_OPM_NO_PROTECTED_OUTPUTS_EXIST __constant_cpu_to_le32(0xC01E0505)
1598#define STATUS_GRAPHICS_PVP_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME __constant_cpu_to_le32(0xC01E0506)
1599#define STATUS_GRAPHICS_PVP_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP __constant_cpu_to_le32(0xC01E0507)
1600#define STATUS_GRAPHICS_PVP_MIRRORING_DEVICES_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0508)
1601#define STATUS_GRAPHICS_OPM_INVALID_POINTER __constant_cpu_to_le32(0xC01E050A)
1602#define STATUS_GRAPHICS_OPM_INTERNAL_ERROR __constant_cpu_to_le32(0xC01E050B)
1603#define STATUS_GRAPHICS_OPM_INVALID_HANDLE __constant_cpu_to_le32(0xC01E050C)
1604#define STATUS_GRAPHICS_PVP_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE __constant_cpu_to_le32(0xC01E050D)
1605#define STATUS_GRAPHICS_PVP_INVALID_CERTIFICATE_LENGTH __constant_cpu_to_le32(0xC01E050E)
1606#define STATUS_GRAPHICS_OPM_SPANNING_MODE_ENABLED __constant_cpu_to_le32(0xC01E050F)
1607#define STATUS_GRAPHICS_OPM_THEATER_MODE_ENABLED __constant_cpu_to_le32(0xC01E0510)
1608#define STATUS_GRAPHICS_PVP_HFS_FAILED __constant_cpu_to_le32(0xC01E0511)
1609#define STATUS_GRAPHICS_OPM_INVALID_SRM __constant_cpu_to_le32(0xC01E0512)
1610#define STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_HDCP __constant_cpu_to_le32(0xC01E0513)
1611#define STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_ACP __constant_cpu_to_le32(0xC01E0514)
1612#define STATUS_GRAPHICS_OPM_OUTPUT_DOES_NOT_SUPPORT_CGMSA __constant_cpu_to_le32(0xC01E0515)
1613#define STATUS_GRAPHICS_OPM_HDCP_SRM_NEVER_SET __constant_cpu_to_le32(0xC01E0516)
1614#define STATUS_GRAPHICS_OPM_RESOLUTION_TOO_HIGH __constant_cpu_to_le32(0xC01E0517)
1615#define STATUS_GRAPHICS_OPM_ALL_HDCP_HARDWARE_ALREADY_IN_USE __constant_cpu_to_le32(0xC01E0518)
1616#define STATUS_GRAPHICS_OPM_PROTECTED_OUTPUT_NO_LONGER_EXISTS __constant_cpu_to_le32(0xC01E051A)
1617#define STATUS_GRAPHICS_OPM_SESSION_TYPE_CHANGE_IN_PROGRESS __constant_cpu_to_le32(0xC01E051B)
1618#define STATUS_GRAPHICS_I2C_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0580)
1619#define STATUS_GRAPHICS_I2C_DEVICE_DOES_NOT_EXIST __constant_cpu_to_le32(0xC01E0581)
1620#define STATUS_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA __constant_cpu_to_le32(0xC01E0582)
1621#define STATUS_GRAPHICS_I2C_ERROR_RECEIVING_DATA __constant_cpu_to_le32(0xC01E0583)
1622#define STATUS_GRAPHICS_DDCCI_VCP_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E0584)
1623#define STATUS_GRAPHICS_DDCCI_INVALID_DATA __constant_cpu_to_le32(0xC01E0585)
1624#define STATUS_GRAPHICS_DDCCI_MONITOR_RETURNED_INVALID_TIMING_STATUS_BYTE __constant_cpu_to_le32(0xC01E0586)
1625#define STATUS_GRAPHICS_DDCCI_INVALID_CAPABILITIES_STRING __constant_cpu_to_le32(0xC01E0587)
1626#define STATUS_GRAPHICS_MCA_INTERNAL_ERROR __constant_cpu_to_le32(0xC01E0588)
1627#define STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_COMMAND __constant_cpu_to_le32(0xC01E0589)
1628#define STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_LENGTH __constant_cpu_to_le32(0xC01E058A)
1629#define STATUS_GRAPHICS_DDCCI_INVALID_MESSAGE_CHECKSUM __constant_cpu_to_le32(0xC01E058B)
1630#define STATUS_GRAPHICS_INVALID_PHYSICAL_MONITOR_HANDLE __constant_cpu_to_le32(0xC01E058C)
1631#define STATUS_GRAPHICS_MONITOR_NO_LONGER_EXISTS __constant_cpu_to_le32(0xC01E058D)
1632#define STATUS_GRAPHICS_ONLY_CONSOLE_SESSION_SUPPORTED __constant_cpu_to_le32(0xC01E05E0)
1633#define STATUS_GRAPHICS_NO_DISPLAY_DEVICE_CORRESPONDS_TO_NAME __constant_cpu_to_le32(0xC01E05E1)
1634#define STATUS_GRAPHICS_DISPLAY_DEVICE_NOT_ATTACHED_TO_DESKTOP __constant_cpu_to_le32(0xC01E05E2)
1635#define STATUS_GRAPHICS_MIRRORING_DEVICES_NOT_SUPPORTED __constant_cpu_to_le32(0xC01E05E3)
1636#define STATUS_GRAPHICS_INVALID_POINTER __constant_cpu_to_le32(0xC01E05E4)
1637#define STATUS_GRAPHICS_NO_MONITORS_CORRESPOND_TO_DISPLAY_DEVICE __constant_cpu_to_le32(0xC01E05E5)
1638#define STATUS_GRAPHICS_PARAMETER_ARRAY_TOO_SMALL __constant_cpu_to_le32(0xC01E05E6)
1639#define STATUS_GRAPHICS_INTERNAL_ERROR __constant_cpu_to_le32(0xC01E05E7)
1640#define STATUS_GRAPHICS_SESSION_TYPE_CHANGE_IN_PROGRESS __constant_cpu_to_le32(0xC01E05E8)
1641#define STATUS_FVE_LOCKED_VOLUME __constant_cpu_to_le32(0xC0210000)
1642#define STATUS_FVE_NOT_ENCRYPTED __constant_cpu_to_le32(0xC0210001)
1643#define STATUS_FVE_BAD_INFORMATION __constant_cpu_to_le32(0xC0210002)
1644#define STATUS_FVE_TOO_SMALL __constant_cpu_to_le32(0xC0210003)
1645#define STATUS_FVE_FAILED_WRONG_FS __constant_cpu_to_le32(0xC0210004)
1646#define STATUS_FVE_FAILED_BAD_FS __constant_cpu_to_le32(0xC0210005)
1647#define STATUS_FVE_FS_NOT_EXTENDED __constant_cpu_to_le32(0xC0210006)
1648#define STATUS_FVE_FS_MOUNTED __constant_cpu_to_le32(0xC0210007)
1649#define STATUS_FVE_NO_LICENSE __constant_cpu_to_le32(0xC0210008)
1650#define STATUS_FVE_ACTION_NOT_ALLOWED __constant_cpu_to_le32(0xC0210009)
1651#define STATUS_FVE_BAD_DATA __constant_cpu_to_le32(0xC021000A)
1652#define STATUS_FVE_VOLUME_NOT_BOUND __constant_cpu_to_le32(0xC021000B)
1653#define STATUS_FVE_NOT_DATA_VOLUME __constant_cpu_to_le32(0xC021000C)
1654#define STATUS_FVE_CONV_READ_ERROR __constant_cpu_to_le32(0xC021000D)
1655#define STATUS_FVE_CONV_WRITE_ERROR __constant_cpu_to_le32(0xC021000E)
1656#define STATUS_FVE_OVERLAPPED_UPDATE __constant_cpu_to_le32(0xC021000F)
1657#define STATUS_FVE_FAILED_SECTOR_SIZE __constant_cpu_to_le32(0xC0210010)
1658#define STATUS_FVE_FAILED_AUTHENTICATION __constant_cpu_to_le32(0xC0210011)
1659#define STATUS_FVE_NOT_OS_VOLUME __constant_cpu_to_le32(0xC0210012)
1660#define STATUS_FVE_KEYFILE_NOT_FOUND __constant_cpu_to_le32(0xC0210013)
1661#define STATUS_FVE_KEYFILE_INVALID __constant_cpu_to_le32(0xC0210014)
1662#define STATUS_FVE_KEYFILE_NO_VMK __constant_cpu_to_le32(0xC0210015)
1663#define STATUS_FVE_TPM_DISABLED __constant_cpu_to_le32(0xC0210016)
1664#define STATUS_FVE_TPM_SRK_AUTH_NOT_ZERO __constant_cpu_to_le32(0xC0210017)
1665#define STATUS_FVE_TPM_INVALID_PCR __constant_cpu_to_le32(0xC0210018)
1666#define STATUS_FVE_TPM_NO_VMK __constant_cpu_to_le32(0xC0210019)
1667#define STATUS_FVE_PIN_INVALID __constant_cpu_to_le32(0xC021001A)
1668#define STATUS_FVE_AUTH_INVALID_APPLICATION __constant_cpu_to_le32(0xC021001B)
1669#define STATUS_FVE_AUTH_INVALID_CONFIG __constant_cpu_to_le32(0xC021001C)
1670#define STATUS_FVE_DEBUGGER_ENABLED __constant_cpu_to_le32(0xC021001D)
1671#define STATUS_FVE_DRY_RUN_FAILED __constant_cpu_to_le32(0xC021001E)
1672#define STATUS_FVE_BAD_METADATA_POINTER __constant_cpu_to_le32(0xC021001F)
1673#define STATUS_FVE_OLD_METADATA_COPY __constant_cpu_to_le32(0xC0210020)
1674#define STATUS_FVE_REBOOT_REQUIRED __constant_cpu_to_le32(0xC0210021)
1675#define STATUS_FVE_RAW_ACCESS __constant_cpu_to_le32(0xC0210022)
1676#define STATUS_FVE_RAW_BLOCKED __constant_cpu_to_le32(0xC0210023)
1677#define STATUS_FWP_CALLOUT_NOT_FOUND __constant_cpu_to_le32(0xC0220001)
1678#define STATUS_FWP_CONDITION_NOT_FOUND __constant_cpu_to_le32(0xC0220002)
1679#define STATUS_FWP_FILTER_NOT_FOUND __constant_cpu_to_le32(0xC0220003)
1680#define STATUS_FWP_LAYER_NOT_FOUND __constant_cpu_to_le32(0xC0220004)
1681#define STATUS_FWP_PROVIDER_NOT_FOUND __constant_cpu_to_le32(0xC0220005)
1682#define STATUS_FWP_PROVIDER_CONTEXT_NOT_FOUND __constant_cpu_to_le32(0xC0220006)
1683#define STATUS_FWP_SUBLAYER_NOT_FOUND __constant_cpu_to_le32(0xC0220007)
1684#define STATUS_FWP_NOT_FOUND __constant_cpu_to_le32(0xC0220008)
1685#define STATUS_FWP_ALREADY_EXISTS __constant_cpu_to_le32(0xC0220009)
1686#define STATUS_FWP_IN_USE __constant_cpu_to_le32(0xC022000A)
1687#define STATUS_FWP_DYNAMIC_SESSION_IN_PROGRESS __constant_cpu_to_le32(0xC022000B)
1688#define STATUS_FWP_WRONG_SESSION __constant_cpu_to_le32(0xC022000C)
1689#define STATUS_FWP_NO_TXN_IN_PROGRESS __constant_cpu_to_le32(0xC022000D)
1690#define STATUS_FWP_TXN_IN_PROGRESS __constant_cpu_to_le32(0xC022000E)
1691#define STATUS_FWP_TXN_ABORTED __constant_cpu_to_le32(0xC022000F)
1692#define STATUS_FWP_SESSION_ABORTED __constant_cpu_to_le32(0xC0220010)
1693#define STATUS_FWP_INCOMPATIBLE_TXN __constant_cpu_to_le32(0xC0220011)
1694#define STATUS_FWP_TIMEOUT __constant_cpu_to_le32(0xC0220012)
1695#define STATUS_FWP_NET_EVENTS_DISABLED __constant_cpu_to_le32(0xC0220013)
1696#define STATUS_FWP_INCOMPATIBLE_LAYER __constant_cpu_to_le32(0xC0220014)
1697#define STATUS_FWP_KM_CLIENTS_ONLY __constant_cpu_to_le32(0xC0220015)
1698#define STATUS_FWP_LIFETIME_MISMATCH __constant_cpu_to_le32(0xC0220016)
1699#define STATUS_FWP_BUILTIN_OBJECT __constant_cpu_to_le32(0xC0220017)
1700#define STATUS_FWP_TOO_MANY_BOOTTIME_FILTERS __constant_cpu_to_le32(0xC0220018)
1701#define STATUS_FWP_TOO_MANY_CALLOUTS __constant_cpu_to_le32(0xC0220018)
1702#define STATUS_FWP_NOTIFICATION_DROPPED __constant_cpu_to_le32(0xC0220019)
1703#define STATUS_FWP_TRAFFIC_MISMATCH __constant_cpu_to_le32(0xC022001A)
1704#define STATUS_FWP_INCOMPATIBLE_SA_STATE __constant_cpu_to_le32(0xC022001B)
1705#define STATUS_FWP_NULL_POINTER __constant_cpu_to_le32(0xC022001C)
1706#define STATUS_FWP_INVALID_ENUMERATOR __constant_cpu_to_le32(0xC022001D)
1707#define STATUS_FWP_INVALID_FLAGS __constant_cpu_to_le32(0xC022001E)
1708#define STATUS_FWP_INVALID_NET_MASK __constant_cpu_to_le32(0xC022001F)
1709#define STATUS_FWP_INVALID_RANGE __constant_cpu_to_le32(0xC0220020)
1710#define STATUS_FWP_INVALID_INTERVAL __constant_cpu_to_le32(0xC0220021)
1711#define STATUS_FWP_ZERO_LENGTH_ARRAY __constant_cpu_to_le32(0xC0220022)
1712#define STATUS_FWP_NULL_DISPLAY_NAME __constant_cpu_to_le32(0xC0220023)
1713#define STATUS_FWP_INVALID_ACTION_TYPE __constant_cpu_to_le32(0xC0220024)
1714#define STATUS_FWP_INVALID_WEIGHT __constant_cpu_to_le32(0xC0220025)
1715#define STATUS_FWP_MATCH_TYPE_MISMATCH __constant_cpu_to_le32(0xC0220026)
1716#define STATUS_FWP_TYPE_MISMATCH __constant_cpu_to_le32(0xC0220027)
1717#define STATUS_FWP_OUT_OF_BOUNDS __constant_cpu_to_le32(0xC0220028)
1718#define STATUS_FWP_RESERVED __constant_cpu_to_le32(0xC0220029)
1719#define STATUS_FWP_DUPLICATE_CONDITION __constant_cpu_to_le32(0xC022002A)
1720#define STATUS_FWP_DUPLICATE_KEYMOD __constant_cpu_to_le32(0xC022002B)
1721#define STATUS_FWP_ACTION_INCOMPATIBLE_WITH_LAYER __constant_cpu_to_le32(0xC022002C)
1722#define STATUS_FWP_ACTION_INCOMPATIBLE_WITH_SUBLAYER __constant_cpu_to_le32(0xC022002D)
1723#define STATUS_FWP_CONTEXT_INCOMPATIBLE_WITH_LAYER __constant_cpu_to_le32(0xC022002E)
1724#define STATUS_FWP_CONTEXT_INCOMPATIBLE_WITH_CALLOUT __constant_cpu_to_le32(0xC022002F)
1725#define STATUS_FWP_INCOMPATIBLE_AUTH_METHOD __constant_cpu_to_le32(0xC0220030)
1726#define STATUS_FWP_INCOMPATIBLE_DH_GROUP __constant_cpu_to_le32(0xC0220031)
1727#define STATUS_FWP_EM_NOT_SUPPORTED __constant_cpu_to_le32(0xC0220032)
1728#define STATUS_FWP_NEVER_MATCH __constant_cpu_to_le32(0xC0220033)
1729#define STATUS_FWP_PROVIDER_CONTEXT_MISMATCH __constant_cpu_to_le32(0xC0220034)
1730#define STATUS_FWP_INVALID_PARAMETER __constant_cpu_to_le32(0xC0220035)
1731#define STATUS_FWP_TOO_MANY_SUBLAYERS __constant_cpu_to_le32(0xC0220036)
1732#define STATUS_FWP_CALLOUT_NOTIFICATION_FAILED __constant_cpu_to_le32(0xC0220037)
1733#define STATUS_FWP_INCOMPATIBLE_AUTH_CONFIG __constant_cpu_to_le32(0xC0220038)
1734#define STATUS_FWP_INCOMPATIBLE_CIPHER_CONFIG __constant_cpu_to_le32(0xC0220039)
1735#define STATUS_FWP_TCPIP_NOT_READY __constant_cpu_to_le32(0xC0220100)
1736#define STATUS_FWP_INJECT_HANDLE_CLOSING __constant_cpu_to_le32(0xC0220101)
1737#define STATUS_FWP_INJECT_HANDLE_STALE __constant_cpu_to_le32(0xC0220102)
1738#define STATUS_FWP_CANNOT_PEND __constant_cpu_to_le32(0xC0220103)
1739#define STATUS_NDIS_CLOSING __constant_cpu_to_le32(0xC0230002)
1740#define STATUS_NDIS_BAD_VERSION __constant_cpu_to_le32(0xC0230004)
1741#define STATUS_NDIS_BAD_CHARACTERISTICS __constant_cpu_to_le32(0xC0230005)
1742#define STATUS_NDIS_ADAPTER_NOT_FOUND __constant_cpu_to_le32(0xC0230006)
1743#define STATUS_NDIS_OPEN_FAILED __constant_cpu_to_le32(0xC0230007)
1744#define STATUS_NDIS_DEVICE_FAILED __constant_cpu_to_le32(0xC0230008)
1745#define STATUS_NDIS_MULTICAST_FULL __constant_cpu_to_le32(0xC0230009)
1746#define STATUS_NDIS_MULTICAST_EXISTS __constant_cpu_to_le32(0xC023000A)
1747#define STATUS_NDIS_MULTICAST_NOT_FOUND __constant_cpu_to_le32(0xC023000B)
1748#define STATUS_NDIS_REQUEST_ABORTED __constant_cpu_to_le32(0xC023000C)
1749#define STATUS_NDIS_RESET_IN_PROGRESS __constant_cpu_to_le32(0xC023000D)
1750#define STATUS_NDIS_INVALID_PACKET __constant_cpu_to_le32(0xC023000F)
1751#define STATUS_NDIS_INVALID_DEVICE_REQUEST __constant_cpu_to_le32(0xC0230010)
1752#define STATUS_NDIS_ADAPTER_NOT_READY __constant_cpu_to_le32(0xC0230011)
1753#define STATUS_NDIS_INVALID_LENGTH __constant_cpu_to_le32(0xC0230014)
1754#define STATUS_NDIS_INVALID_DATA __constant_cpu_to_le32(0xC0230015)
1755#define STATUS_NDIS_BUFFER_TOO_SHORT __constant_cpu_to_le32(0xC0230016)
1756#define STATUS_NDIS_INVALID_OID __constant_cpu_to_le32(0xC0230017)
1757#define STATUS_NDIS_ADAPTER_REMOVED __constant_cpu_to_le32(0xC0230018)
1758#define STATUS_NDIS_UNSUPPORTED_MEDIA __constant_cpu_to_le32(0xC0230019)
1759#define STATUS_NDIS_GROUP_ADDRESS_IN_USE __constant_cpu_to_le32(0xC023001A)
1760#define STATUS_NDIS_FILE_NOT_FOUND __constant_cpu_to_le32(0xC023001B)
1761#define STATUS_NDIS_ERROR_READING_FILE __constant_cpu_to_le32(0xC023001C)
1762#define STATUS_NDIS_ALREADY_MAPPED __constant_cpu_to_le32(0xC023001D)
1763#define STATUS_NDIS_RESOURCE_CONFLICT __constant_cpu_to_le32(0xC023001E)
1764#define STATUS_NDIS_MEDIA_DISCONNECTED __constant_cpu_to_le32(0xC023001F)
1765#define STATUS_NDIS_INVALID_ADDRESS __constant_cpu_to_le32(0xC0230022)
1766#define STATUS_NDIS_PAUSED __constant_cpu_to_le32(0xC023002A)
1767#define STATUS_NDIS_INTERFACE_NOT_FOUND __constant_cpu_to_le32(0xC023002B)
1768#define STATUS_NDIS_UNSUPPORTED_REVISION __constant_cpu_to_le32(0xC023002C)
1769#define STATUS_NDIS_INVALID_PORT __constant_cpu_to_le32(0xC023002D)
1770#define STATUS_NDIS_INVALID_PORT_STATE __constant_cpu_to_le32(0xC023002E)
1771#define STATUS_NDIS_LOW_POWER_STATE __constant_cpu_to_le32(0xC023002F)
1772#define STATUS_NDIS_NOT_SUPPORTED __constant_cpu_to_le32(0xC02300BB)
1773#define STATUS_NDIS_DOT11_AUTO_CONFIG_ENABLED __constant_cpu_to_le32(0xC0232000)
1774#define STATUS_NDIS_DOT11_MEDIA_IN_USE __constant_cpu_to_le32(0xC0232001)
1775#define STATUS_NDIS_DOT11_POWER_STATE_INVALID __constant_cpu_to_le32(0xC0232002)
1776#define STATUS_IPSEC_BAD_SPI __constant_cpu_to_le32(0xC0360001)
1777#define STATUS_IPSEC_SA_LIFETIME_EXPIRED __constant_cpu_to_le32(0xC0360002)
1778#define STATUS_IPSEC_WRONG_SA __constant_cpu_to_le32(0xC0360003)
1779#define STATUS_IPSEC_REPLAY_CHECK_FAILED __constant_cpu_to_le32(0xC0360004)
1780#define STATUS_IPSEC_INVALID_PACKET __constant_cpu_to_le32(0xC0360005)
1781#define STATUS_IPSEC_INTEGRITY_CHECK_FAILED __constant_cpu_to_le32(0xC0360006)
1782#define STATUS_IPSEC_CLEAR_TEXT_DROP __constant_cpu_to_le32(0xC0360007)
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
deleted file mode 100644
index 8dd73e61d76..00000000000
--- a/fs/cifs/smb2transport.c
+++ /dev/null
@@ -1,331 +0,0 @@
1/*
2 * fs/cifs/smb2transport.c
3 *
4 * Copyright (C) International Business Machines Corp., 2002, 2011
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Jeremy Allison (jra@samba.org) 2006
8 * Pavel Shilovsky (pshilovsky@samba.org) 2012
9 *
10 * This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 * the GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/fs.h>
26#include <linux/list.h>
27#include <linux/wait.h>
28#include <linux/net.h>
29#include <linux/delay.h>
30#include <linux/uaccess.h>
31#include <asm/processor.h>
32#include <linux/mempool.h>
33#include <linux/highmem.h>
34#include "smb2pdu.h"
35#include "cifsglob.h"
36#include "cifsproto.h"
37#include "smb2proto.h"
38#include "cifs_debug.h"
39#include "smb2status.h"
40#include "smb2glob.h"
41
42int
43smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
44{
45 int i, rc;
46 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
47 unsigned char *sigptr = smb2_signature;
48 struct kvec *iov = rqst->rq_iov;
49 int n_vec = rqst->rq_nvec;
50 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base;
51
52 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
53 memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE);
54
55 rc = crypto_shash_setkey(server->secmech.hmacsha256,
56 server->session_key.response, SMB2_NTLMV2_SESSKEY_SIZE);
57 if (rc) {
58 cERROR(1, "%s: Could not update with response\n", __func__);
59 return rc;
60 }
61
62 rc = crypto_shash_init(&server->secmech.sdeschmacsha256->shash);
63 if (rc) {
64 cERROR(1, "%s: Could not init md5\n", __func__);
65 return rc;
66 }
67
68 for (i = 0; i < n_vec; i++) {
69 if (iov[i].iov_len == 0)
70 continue;
71 if (iov[i].iov_base == NULL) {
72 cERROR(1, "null iovec entry");
73 return -EIO;
74 }
75 /*
76 * The first entry includes a length field (which does not get
77 * signed that occupies the first 4 bytes before the header).
78 */
79 if (i == 0) {
80 if (iov[0].iov_len <= 8) /* cmd field at offset 9 */
81 break; /* nothing to sign or corrupt header */
82 rc =
83 crypto_shash_update(
84 &server->secmech.sdeschmacsha256->shash,
85 iov[i].iov_base + 4, iov[i].iov_len - 4);
86 } else {
87 rc =
88 crypto_shash_update(
89 &server->secmech.sdeschmacsha256->shash,
90 iov[i].iov_base, iov[i].iov_len);
91 }
92 if (rc) {
93 cERROR(1, "%s: Could not update with payload\n",
94 __func__);
95 return rc;
96 }
97 }
98
99 /* now hash over the rq_pages array */
100 for (i = 0; i < rqst->rq_npages; i++) {
101 struct kvec p_iov;
102
103 cifs_rqst_page_to_kvec(rqst, i, &p_iov);
104 crypto_shash_update(&server->secmech.sdeschmacsha256->shash,
105 p_iov.iov_base, p_iov.iov_len);
106 kunmap(rqst->rq_pages[i]);
107 }
108
109 rc = crypto_shash_final(&server->secmech.sdeschmacsha256->shash,
110 sigptr);
111 if (rc)
112 cERROR(1, "%s: Could not generate sha256 hash\n", __func__);
113
114 memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE);
115
116 return rc;
117}
118
119int
120smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
121{
122 cFYI(1, "smb3 signatures not supported yet");
123 return -EOPNOTSUPP;
124}
125
126/* must be called with server->srv_mutex held */
127static int
128smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
129{
130 int rc = 0;
131 struct smb2_hdr *smb2_pdu = rqst->rq_iov[0].iov_base;
132
133 if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) ||
134 server->tcpStatus == CifsNeedNegotiate)
135 return rc;
136
137 if (!server->session_estab) {
138 strncpy(smb2_pdu->Signature, "BSRSPYL", 8);
139 return rc;
140 }
141
142 rc = server->ops->calc_signature(rqst, server);
143
144 return rc;
145}
146
147int
148smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
149{
150 unsigned int rc;
151 char server_response_sig[16];
152 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
153
154 if ((smb2_pdu->Command == SMB2_NEGOTIATE) ||
155 (smb2_pdu->Command == SMB2_OPLOCK_BREAK) ||
156 (!server->session_estab))
157 return 0;
158
159 /*
160 * BB what if signatures are supposed to be on for session but
161 * server does not send one? BB
162 */
163
164 /* Do not need to verify session setups with signature "BSRSPYL " */
165 if (memcmp(smb2_pdu->Signature, "BSRSPYL ", 8) == 0)
166 cFYI(1, "dummy signature received for smb command 0x%x",
167 smb2_pdu->Command);
168
169 /*
170 * Save off the origiginal signature so we can modify the smb and check
171 * our calculated signature against what the server sent.
172 */
173 memcpy(server_response_sig, smb2_pdu->Signature, SMB2_SIGNATURE_SIZE);
174
175 memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE);
176
177 mutex_lock(&server->srv_mutex);
178 rc = server->ops->calc_signature(rqst, server);
179 mutex_unlock(&server->srv_mutex);
180
181 if (rc)
182 return rc;
183
184 if (memcmp(server_response_sig, smb2_pdu->Signature,
185 SMB2_SIGNATURE_SIZE))
186 return -EACCES;
187 else
188 return 0;
189}
190
191/*
192 * Set message id for the request. Should be called after wait_for_free_request
193 * and when srv_mutex is held.
194 */
195static inline void
196smb2_seq_num_into_buf(struct TCP_Server_Info *server, struct smb2_hdr *hdr)
197{
198 hdr->MessageId = get_next_mid(server);
199}
200
201static struct mid_q_entry *
202smb2_mid_entry_alloc(const struct smb2_hdr *smb_buffer,
203 struct TCP_Server_Info *server)
204{
205 struct mid_q_entry *temp;
206
207 if (server == NULL) {
208 cERROR(1, "Null TCP session in smb2_mid_entry_alloc");
209 return NULL;
210 }
211
212 temp = mempool_alloc(cifs_mid_poolp, GFP_NOFS);
213 if (temp == NULL)
214 return temp;
215 else {
216 memset(temp, 0, sizeof(struct mid_q_entry));
217 temp->mid = smb_buffer->MessageId; /* always LE */
218 temp->pid = current->pid;
219 temp->command = smb_buffer->Command; /* Always LE */
220 temp->when_alloc = jiffies;
221 temp->server = server;
222
223 /*
224 * The default is for the mid to be synchronous, so the
225 * default callback just wakes up the current task.
226 */
227 temp->callback = cifs_wake_up_task;
228 temp->callback_data = current;
229 }
230
231 atomic_inc(&midCount);
232 temp->mid_state = MID_REQUEST_ALLOCATED;
233 return temp;
234}
235
236static int
237smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
238 struct mid_q_entry **mid)
239{
240 if (ses->server->tcpStatus == CifsExiting)
241 return -ENOENT;
242
243 if (ses->server->tcpStatus == CifsNeedReconnect) {
244 cFYI(1, "tcp session dead - return to caller to retry");
245 return -EAGAIN;
246 }
247
248 if (ses->status != CifsGood) {
249 /* check if SMB2 session is bad because we are setting it up */
250 if ((buf->Command != SMB2_SESSION_SETUP) &&
251 (buf->Command != SMB2_NEGOTIATE))
252 return -EAGAIN;
253 /* else ok - we are setting up session */
254 }
255 *mid = smb2_mid_entry_alloc(buf, ses->server);
256 if (*mid == NULL)
257 return -ENOMEM;
258 spin_lock(&GlobalMid_Lock);
259 list_add_tail(&(*mid)->qhead, &ses->server->pending_mid_q);
260 spin_unlock(&GlobalMid_Lock);
261 return 0;
262}
263
264int
265smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
266 bool log_error)
267{
268 unsigned int len = get_rfc1002_length(mid->resp_buf);
269 struct kvec iov;
270 struct smb_rqst rqst = { .rq_iov = &iov,
271 .rq_nvec = 1 };
272
273 iov.iov_base = (char *)mid->resp_buf;
274 iov.iov_len = get_rfc1002_length(mid->resp_buf) + 4;
275
276 dump_smb(mid->resp_buf, min_t(u32, 80, len));
277 /* convert the length into a more usable form */
278 if ((len > 24) &&
279 (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) {
280 int rc;
281
282 rc = smb2_verify_signature(&rqst, server);
283 if (rc)
284 cERROR(1, "SMB signature verification returned error = "
285 "%d", rc);
286 }
287
288 return map_smb2_to_linux_error(mid->resp_buf, log_error);
289}
290
291struct mid_q_entry *
292smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
293{
294 int rc;
295 struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
296 struct mid_q_entry *mid;
297
298 smb2_seq_num_into_buf(ses->server, hdr);
299
300 rc = smb2_get_mid_entry(ses, hdr, &mid);
301 if (rc)
302 return ERR_PTR(rc);
303 rc = smb2_sign_rqst(rqst, ses->server);
304 if (rc) {
305 cifs_delete_mid(mid);
306 return ERR_PTR(rc);
307 }
308 return mid;
309}
310
311struct mid_q_entry *
312smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
313{
314 int rc;
315 struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
316 struct mid_q_entry *mid;
317
318 smb2_seq_num_into_buf(server, hdr);
319
320 mid = smb2_mid_entry_alloc(hdr, server);
321 if (mid == NULL)
322 return ERR_PTR(-ENOMEM);
323
324 rc = smb2_sign_rqst(rqst, server);
325 if (rc) {
326 DeleteMidQEntry(mid);
327 return ERR_PTR(rc);
328 }
329
330 return mid;
331}
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
index a0a58fbe2c1..42b9fff4875 100644
--- a/fs/cifs/smbencrypt.c
+++ b/fs/cifs/smbencrypt.c
@@ -78,7 +78,7 @@ smbhash(unsigned char *out, const unsigned char *in, unsigned char *key)
78 tfm_des = crypto_alloc_blkcipher("ecb(des)", 0, CRYPTO_ALG_ASYNC); 78 tfm_des = crypto_alloc_blkcipher("ecb(des)", 0, CRYPTO_ALG_ASYNC);
79 if (IS_ERR(tfm_des)) { 79 if (IS_ERR(tfm_des)) {
80 rc = PTR_ERR(tfm_des); 80 rc = PTR_ERR(tfm_des);
81 cERROR(1, "could not allocate des crypto API"); 81 cERROR(1, "could not allocate des crypto API\n");
82 goto smbhash_err; 82 goto smbhash_err;
83 } 83 }
84 84
@@ -91,7 +91,7 @@ smbhash(unsigned char *out, const unsigned char *in, unsigned char *key)
91 91
92 rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, 8); 92 rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, 8);
93 if (rc) 93 if (rc)
94 cERROR(1, "could not encrypt crypt key rc: %d", rc); 94 cERROR(1, "could not encrypt crypt key rc: %d\n", rc);
95 95
96 crypto_free_blkcipher(tfm_des); 96 crypto_free_blkcipher(tfm_des);
97smbhash_err: 97smbhash_err:
@@ -139,14 +139,14 @@ mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
139 md4 = crypto_alloc_shash("md4", 0, 0); 139 md4 = crypto_alloc_shash("md4", 0, 0);
140 if (IS_ERR(md4)) { 140 if (IS_ERR(md4)) {
141 rc = PTR_ERR(md4); 141 rc = PTR_ERR(md4);
142 cERROR(1, "%s: Crypto md4 allocation error %d", __func__, rc); 142 cERROR(1, "%s: Crypto md4 allocation error %d\n", __func__, rc);
143 return rc; 143 return rc;
144 } 144 }
145 size = sizeof(struct shash_desc) + crypto_shash_descsize(md4); 145 size = sizeof(struct shash_desc) + crypto_shash_descsize(md4);
146 sdescmd4 = kmalloc(size, GFP_KERNEL); 146 sdescmd4 = kmalloc(size, GFP_KERNEL);
147 if (!sdescmd4) { 147 if (!sdescmd4) {
148 rc = -ENOMEM; 148 rc = -ENOMEM;
149 cERROR(1, "%s: Memory allocation failure", __func__); 149 cERROR(1, "%s: Memory allocation failure\n", __func__);
150 goto mdfour_err; 150 goto mdfour_err;
151 } 151 }
152 sdescmd4->shash.tfm = md4; 152 sdescmd4->shash.tfm = md4;
@@ -154,17 +154,17 @@ mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
154 154
155 rc = crypto_shash_init(&sdescmd4->shash); 155 rc = crypto_shash_init(&sdescmd4->shash);
156 if (rc) { 156 if (rc) {
157 cERROR(1, "%s: Could not init md4 shash", __func__); 157 cERROR(1, "%s: Could not init md4 shash\n", __func__);
158 goto mdfour_err; 158 goto mdfour_err;
159 } 159 }
160 rc = crypto_shash_update(&sdescmd4->shash, link_str, link_len); 160 rc = crypto_shash_update(&sdescmd4->shash, link_str, link_len);
161 if (rc) { 161 if (rc) {
162 cERROR(1, "%s: Could not update with link_str", __func__); 162 cERROR(1, "%s: Could not update with link_str\n", __func__);
163 goto mdfour_err; 163 goto mdfour_err;
164 } 164 }
165 rc = crypto_shash_final(&sdescmd4->shash, md4_hash); 165 rc = crypto_shash_final(&sdescmd4->shash, md4_hash);
166 if (rc) 166 if (rc)
167 cERROR(1, "%s: Could not genereate md4 hash", __func__); 167 cERROR(1, "%s: Could not genereate md4 hash\n", __func__);
168 168
169mdfour_err: 169mdfour_err:
170 crypto_free_shash(md4); 170 crypto_free_shash(md4);
@@ -199,36 +199,160 @@ SMBencrypt(unsigned char *passwd, const unsigned char *c8, unsigned char *p24)
199 return rc; 199 return rc;
200} 200}
201 201
202/* Routines for Windows NT MD4 Hash functions. */
203static int
204_my_wcslen(__u16 *str)
205{
206 int len = 0;
207 while (*str++ != 0)
208 len++;
209 return len;
210}
211
212/*
213 * Convert a string into an NT UNICODE string.
214 * Note that regardless of processor type
215 * this must be in intel (little-endian)
216 * format.
217 */
218
219static int
220_my_mbstowcs(__u16 *dst, const unsigned char *src, int len)
221{ /* BB not a very good conversion routine - change/fix */
222 int i;
223 __u16 val;
224
225 for (i = 0; i < len; i++) {
226 val = *src;
227 SSVAL(dst, 0, val);
228 dst++;
229 src++;
230 if (val == 0)
231 break;
232 }
233 return i;
234}
235
202/* 236/*
203 * Creates the MD4 Hash of the users password in NT UNICODE. 237 * Creates the MD4 Hash of the users password in NT UNICODE.
204 */ 238 */
205 239
206int 240int
207E_md4hash(const unsigned char *passwd, unsigned char *p16, 241E_md4hash(const unsigned char *passwd, unsigned char *p16)
208 const struct nls_table *codepage)
209{ 242{
210 int rc; 243 int rc;
211 int len; 244 int len;
212 __le16 wpwd[129]; 245 __u16 wpwd[129];
213 246
214 /* Password cannot be longer than 128 characters */ 247 /* Password cannot be longer than 128 characters */
215 if (passwd) /* Password must be converted to NT unicode */ 248 if (passwd) {
216 len = cifs_strtoUTF16(wpwd, passwd, 128, codepage); 249 len = strlen((char *) passwd);
217 else { 250 if (len > 128)
251 len = 128;
252
253 /* Password must be converted to NT unicode */
254 _my_mbstowcs(wpwd, passwd, len);
255 } else
218 len = 0; 256 len = 0;
219 *wpwd = 0; /* Ensure string is null terminated */
220 }
221 257
222 rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__le16)); 258 wpwd[len] = 0; /* Ensure string is null terminated */
223 memset(wpwd, 0, 129 * sizeof(__le16)); 259 /* Calculate length in bytes */
260 len = _my_wcslen(wpwd) * sizeof(__u16);
261
262 rc = mdfour(p16, (unsigned char *) wpwd, len);
263 memset(wpwd, 0, 129 * 2);
224 264
225 return rc; 265 return rc;
226} 266}
227 267
268#if 0 /* currently unused */
269/* Does both the NT and LM owfs of a user's password */
270static void
271nt_lm_owf_gen(char *pwd, unsigned char nt_p16[16], unsigned char p16[16])
272{
273 char passwd[514];
274
275 memset(passwd, '\0', 514);
276 if (strlen(pwd) < 513)
277 strcpy(passwd, pwd);
278 else
279 memcpy(passwd, pwd, 512);
280 /* Calculate the MD4 hash (NT compatible) of the password */
281 memset(nt_p16, '\0', 16);
282 E_md4hash(passwd, nt_p16);
283
284 /* Mangle the passwords into Lanman format */
285 passwd[14] = '\0';
286/* strupper(passwd); */
287
288 /* Calculate the SMB (lanman) hash functions of the password */
289
290 memset(p16, '\0', 16);
291 E_P16((unsigned char *) passwd, (unsigned char *) p16);
292
293 /* clear out local copy of user's password (just being paranoid). */
294 memset(passwd, '\0', sizeof(passwd));
295}
296#endif
297
298/* Does the NTLMv2 owfs of a user's password */
299#if 0 /* function not needed yet - but will be soon */
300static void
301ntv2_owf_gen(const unsigned char owf[16], const char *user_n,
302 const char *domain_n, unsigned char kr_buf[16],
303 const struct nls_table *nls_codepage)
304{
305 wchar_t *user_u;
306 wchar_t *dom_u;
307 int user_l, domain_l;
308 struct HMACMD5Context ctx;
309
310 /* might as well do one alloc to hold both (user_u and dom_u) */
311 user_u = kmalloc(2048 * sizeof(wchar_t), GFP_KERNEL);
312 if (user_u == NULL)
313 return;
314 dom_u = user_u + 1024;
315
316 /* push_ucs2(NULL, user_u, user_n, (user_l+1)*2,
317 STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER);
318 push_ucs2(NULL, dom_u, domain_n, (domain_l+1)*2,
319 STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER); */
320
321 /* BB user and domain may need to be uppercased */
322 user_l = cifs_strtoUCS(user_u, user_n, 511, nls_codepage);
323 domain_l = cifs_strtoUCS(dom_u, domain_n, 511, nls_codepage);
324
325 user_l++; /* trailing null */
326 domain_l++;
327
328 hmac_md5_init_limK_to_64(owf, 16, &ctx);
329 hmac_md5_update((const unsigned char *) user_u, user_l * 2, &ctx);
330 hmac_md5_update((const unsigned char *) dom_u, domain_l * 2, &ctx);
331 hmac_md5_final(kr_buf, &ctx);
332
333 kfree(user_u);
334}
335#endif
336
337/* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */
338#if 0 /* currently unused */
339static void
340NTLMSSPOWFencrypt(unsigned char passwd[8],
341 unsigned char *ntlmchalresp, unsigned char p24[24])
342{
343 unsigned char p21[21];
344
345 memset(p21, '\0', 21);
346 memcpy(p21, passwd, 8);
347 memset(p21 + 8, 0xbd, 8);
348
349 E_P24(p21, ntlmchalresp, p24);
350}
351#endif
352
228/* Does the NT MD4 hash then des encryption. */ 353/* Does the NT MD4 hash then des encryption. */
229int 354int
230SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24, 355SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24)
231 const struct nls_table *codepage)
232{ 356{
233 int rc; 357 int rc;
234 unsigned char p16[16], p21[21]; 358 unsigned char p16[16], p21[21];
@@ -236,7 +360,7 @@ SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24,
236 memset(p16, '\0', 16); 360 memset(p16, '\0', 16);
237 memset(p21, '\0', 21); 361 memset(p21, '\0', 21);
238 362
239 rc = E_md4hash(passwd, p16, codepage); 363 rc = E_md4hash(passwd, p16);
240 if (rc) { 364 if (rc) {
241 cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc); 365 cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
242 return rc; 366 return rc;
@@ -245,3 +369,39 @@ SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24,
245 rc = E_P24(p21, c8, p24); 369 rc = E_P24(p21, c8, p24);
246 return rc; 370 return rc;
247} 371}
372
373
374/* Does the md5 encryption from the NT hash for NTLMv2. */
375/* These routines will be needed later */
376#if 0
377static void
378SMBOWFencrypt_ntv2(const unsigned char kr[16],
379 const struct data_blob *srv_chal,
380 const struct data_blob *cli_chal, unsigned char resp_buf[16])
381{
382 struct HMACMD5Context ctx;
383
384 hmac_md5_init_limK_to_64(kr, 16, &ctx);
385 hmac_md5_update(srv_chal->data, srv_chal->length, &ctx);
386 hmac_md5_update(cli_chal->data, cli_chal->length, &ctx);
387 hmac_md5_final(resp_buf, &ctx);
388}
389
390static void
391SMBsesskeygen_ntv2(const unsigned char kr[16],
392 const unsigned char *nt_resp, __u8 sess_key[16])
393{
394 struct HMACMD5Context ctx;
395
396 hmac_md5_init_limK_to_64(kr, 16, &ctx);
397 hmac_md5_update(nt_resp, 16, &ctx);
398 hmac_md5_final((unsigned char *) sess_key, &ctx);
399}
400
401static void
402SMBsesskeygen_ntv1(const unsigned char kr[16],
403 const unsigned char *nt_resp, __u8 sess_key[16])
404{
405 mdfour((unsigned char *) sess_key, (unsigned char *) kr, 16);
406}
407#endif
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 1a528680ec5..10ca6b2c26b 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -26,9 +26,6 @@
26#include <linux/wait.h> 26#include <linux/wait.h>
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/freezer.h>
30#include <linux/tcp.h>
31#include <linux/highmem.h>
32#include <asm/uaccess.h> 29#include <asm/uaccess.h>
33#include <asm/processor.h> 30#include <asm/processor.h>
34#include <linux/mempool.h> 31#include <linux/mempool.h>
@@ -37,8 +34,10 @@
37#include "cifsproto.h" 34#include "cifsproto.h"
38#include "cifs_debug.h" 35#include "cifs_debug.h"
39 36
40void 37extern mempool_t *cifs_mid_poolp;
41cifs_wake_up_task(struct mid_q_entry *mid) 38
39static void
40wake_up_task(struct mid_q_entry *mid)
42{ 41{
43 wake_up_process(mid->callback_data); 42 wake_up_process(mid->callback_data);
44} 43}
@@ -60,23 +59,22 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
60 memset(temp, 0, sizeof(struct mid_q_entry)); 59 memset(temp, 0, sizeof(struct mid_q_entry));
61 temp->mid = smb_buffer->Mid; /* always LE */ 60 temp->mid = smb_buffer->Mid; /* always LE */
62 temp->pid = current->pid; 61 temp->pid = current->pid;
63 temp->command = cpu_to_le16(smb_buffer->Command); 62 temp->command = smb_buffer->Command;
64 cFYI(1, "For smb_command %d", smb_buffer->Command); 63 cFYI(1, "For smb_command %d", temp->command);
65 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ 64 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */
66 /* when mid allocated can be before when sent */ 65 /* when mid allocated can be before when sent */
67 temp->when_alloc = jiffies; 66 temp->when_alloc = jiffies;
68 temp->server = server;
69 67
70 /* 68 /*
71 * The default is for the mid to be synchronous, so the 69 * The default is for the mid to be synchronous, so the
72 * default callback just wakes up the current task. 70 * default callback just wakes up the current task.
73 */ 71 */
74 temp->callback = cifs_wake_up_task; 72 temp->callback = wake_up_task;
75 temp->callback_data = current; 73 temp->callback_data = current;
76 } 74 }
77 75
78 atomic_inc(&midCount); 76 atomic_inc(&midCount);
79 temp->mid_state = MID_REQUEST_ALLOCATED; 77 temp->midState = MID_REQUEST_ALLOCATED;
80 return temp; 78 return temp;
81} 79}
82 80
@@ -84,12 +82,11 @@ void
84DeleteMidQEntry(struct mid_q_entry *midEntry) 82DeleteMidQEntry(struct mid_q_entry *midEntry)
85{ 83{
86#ifdef CONFIG_CIFS_STATS2 84#ifdef CONFIG_CIFS_STATS2
87 __le16 command = midEntry->server->vals->lock_cmd;
88 unsigned long now; 85 unsigned long now;
89#endif 86#endif
90 midEntry->mid_state = MID_FREE; 87 midEntry->midState = MID_FREE;
91 atomic_dec(&midCount); 88 atomic_dec(&midCount);
92 if (midEntry->large_buf) 89 if (midEntry->largeBuf)
93 cifs_buf_release(midEntry->resp_buf); 90 cifs_buf_release(midEntry->resp_buf);
94 else 91 else
95 cifs_small_buf_release(midEntry->resp_buf); 92 cifs_small_buf_release(midEntry->resp_buf);
@@ -98,8 +95,9 @@ DeleteMidQEntry(struct mid_q_entry *midEntry)
98 /* commands taking longer than one second are indications that 95 /* commands taking longer than one second are indications that
99 something is wrong, unless it is quite a slow link or server */ 96 something is wrong, unless it is quite a slow link or server */
100 if ((now - midEntry->when_alloc) > HZ) { 97 if ((now - midEntry->when_alloc) > HZ) {
101 if ((cifsFYI & CIFS_TIMER) && (midEntry->command != command)) { 98 if ((cifsFYI & CIFS_TIMER) &&
102 printk(KERN_DEBUG " CIFS slow rsp: cmd %d mid %llu", 99 (midEntry->command != SMB_COM_LOCKING_ANDX)) {
100 printk(KERN_DEBUG " CIFS slow rsp: cmd %d mid %d",
103 midEntry->command, midEntry->mid); 101 midEntry->command, midEntry->mid);
104 printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n", 102 printk(" A: 0x%lx S: 0x%lx R: 0x%lx\n",
105 now - midEntry->when_alloc, 103 now - midEntry->when_alloc,
@@ -111,8 +109,8 @@ DeleteMidQEntry(struct mid_q_entry *midEntry)
111 mempool_free(midEntry, cifs_mid_poolp); 109 mempool_free(midEntry, cifs_mid_poolp);
112} 110}
113 111
114void 112static void
115cifs_delete_mid(struct mid_q_entry *mid) 113delete_mid(struct mid_q_entry *mid)
116{ 114{
117 spin_lock(&GlobalMid_Lock); 115 spin_lock(&GlobalMid_Lock);
118 list_del(&mid->qhead); 116 list_del(&mid->qhead);
@@ -121,28 +119,21 @@ cifs_delete_mid(struct mid_q_entry *mid)
121 DeleteMidQEntry(mid); 119 DeleteMidQEntry(mid);
122} 120}
123 121
124/*
125 * smb_send_kvec - send an array of kvecs to the server
126 * @server: Server to send the data to
127 * @iov: Pointer to array of kvecs
128 * @n_vec: length of kvec array
129 * @sent: amount of data sent on socket is stored here
130 *
131 * Our basic "send data to server" function. Should be called with srv_mutex
132 * held. The caller is responsible for handling the results.
133 */
134static int 122static int
135smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec, 123smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
136 size_t *sent)
137{ 124{
138 int rc = 0; 125 int rc = 0;
139 int i = 0; 126 int i = 0;
140 struct msghdr smb_msg; 127 struct msghdr smb_msg;
141 unsigned int remaining; 128 struct smb_hdr *smb_buffer = iov[0].iov_base;
142 size_t first_vec = 0; 129 unsigned int len = iov[0].iov_len;
130 unsigned int total_len;
131 int first_vec = 0;
132 unsigned int smb_buf_length = be32_to_cpu(smb_buffer->smb_buf_length);
143 struct socket *ssocket = server->ssocket; 133 struct socket *ssocket = server->ssocket;
144 134
145 *sent = 0; 135 if (ssocket == NULL)
136 return -ENOTSOCK; /* BB eventually add reconnect code here */
146 137
147 smb_msg.msg_name = (struct sockaddr *) &server->dstaddr; 138 smb_msg.msg_name = (struct sockaddr *) &server->dstaddr;
148 smb_msg.msg_namelen = sizeof(struct sockaddr); 139 smb_msg.msg_namelen = sizeof(struct sockaddr);
@@ -153,66 +144,56 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,
153 else 144 else
154 smb_msg.msg_flags = MSG_NOSIGNAL; 145 smb_msg.msg_flags = MSG_NOSIGNAL;
155 146
156 remaining = 0; 147 total_len = 0;
157 for (i = 0; i < n_vec; i++) 148 for (i = 0; i < n_vec; i++)
158 remaining += iov[i].iov_len; 149 total_len += iov[i].iov_len;
150
151 cFYI(1, "Sending smb: total_len %d", total_len);
152 dump_smb(smb_buffer, len);
159 153
160 i = 0; 154 i = 0;
161 while (remaining) { 155 while (total_len) {
162 /*
163 * If blocking send, we try 3 times, since each can block
164 * for 5 seconds. For nonblocking we have to try more
165 * but wait increasing amounts of time allowing time for
166 * socket to clear. The overall time we wait in either
167 * case to send on the socket is about 15 seconds.
168 * Similarly we wait for 15 seconds for a response from
169 * the server in SendReceive[2] for the server to send
170 * a response back for most types of requests (except
171 * SMB Write past end of file which can be slow, and
172 * blocking lock operations). NFS waits slightly longer
173 * than CIFS, but this can make it take longer for
174 * nonresponsive servers to be detected and 15 seconds
175 * is more than enough time for modern networks to
176 * send a packet. In most cases if we fail to send
177 * after the retries we will kill the socket and
178 * reconnect which may clear the network problem.
179 */
180 rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec], 156 rc = kernel_sendmsg(ssocket, &smb_msg, &iov[first_vec],
181 n_vec - first_vec, remaining); 157 n_vec - first_vec, total_len);
182 if (rc == -ENOSPC || rc == -EAGAIN) { 158 if ((rc == -ENOSPC) || (rc == -EAGAIN)) {
183 /*
184 * Catch if a low level driver returns -ENOSPC. This
185 * WARN_ON will be removed by 3.10 if no one reports
186 * seeing this.
187 */
188 WARN_ON_ONCE(rc == -ENOSPC);
189 i++; 159 i++;
190 if (i >= 14 || (!server->noblocksnd && (i > 2))) { 160 /* if blocking send we try 3 times, since each can block
191 cERROR(1, "sends on sock %p stuck for 15 " 161 for 5 seconds. For nonblocking we have to try more
192 "seconds", ssocket); 162 but wait increasing amounts of time allowing time for
163 socket to clear. The overall time we wait in either
164 case to send on the socket is about 15 seconds.
165 Similarly we wait for 15 seconds for
166 a response from the server in SendReceive[2]
167 for the server to send a response back for
168 most types of requests (except SMB Write
169 past end of file which can be slow, and
170 blocking lock operations). NFS waits slightly longer
171 than CIFS, but this can make it take longer for
172 nonresponsive servers to be detected and 15 seconds
173 is more than enough time for modern networks to
174 send a packet. In most cases if we fail to send
175 after the retries we will kill the socket and
176 reconnect which may clear the network problem.
177 */
178 if ((i >= 14) || (!server->noblocksnd && (i > 2))) {
179 cERROR(1, "sends on sock %p stuck for 15 seconds",
180 ssocket);
193 rc = -EAGAIN; 181 rc = -EAGAIN;
194 break; 182 break;
195 } 183 }
196 msleep(1 << i); 184 msleep(1 << i);
197 continue; 185 continue;
198 } 186 }
199
200 if (rc < 0) 187 if (rc < 0)
201 break; 188 break;
202 189
203 /* send was at least partially successful */ 190 if (rc == total_len) {
204 *sent += rc; 191 total_len = 0;
205
206 if (rc == remaining) {
207 remaining = 0;
208 break; 192 break;
209 } 193 } else if (rc > total_len) {
210 194 cERROR(1, "sent %d requested %d", rc, total_len);
211 if (rc > remaining) {
212 cERROR(1, "sent %d requested %d", rc, remaining);
213 break; 195 break;
214 } 196 }
215
216 if (rc == 0) { 197 if (rc == 0) {
217 /* should never happen, letting socket clear before 198 /* should never happen, letting socket clear before
218 retrying is our only obvious option here */ 199 retrying is our only obvious option here */
@@ -220,9 +201,7 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,
220 msleep(500); 201 msleep(500);
221 continue; 202 continue;
222 } 203 }
223 204 total_len -= rc;
224 remaining -= rc;
225
226 /* the line below resets i */ 205 /* the line below resets i */
227 for (i = first_vec; i < n_vec; i++) { 206 for (i = first_vec; i < n_vec; i++) {
228 if (iov[i].iov_len) { 207 if (iov[i].iov_len) {
@@ -237,100 +216,16 @@ smb_send_kvec(struct TCP_Server_Info *server, struct kvec *iov, size_t n_vec,
237 } 216 }
238 } 217 }
239 } 218 }
240
241 i = 0; /* in case we get ENOSPC on the next send */ 219 i = 0; /* in case we get ENOSPC on the next send */
242 rc = 0;
243 } 220 }
244 return rc;
245}
246
247/**
248 * rqst_page_to_kvec - Turn a slot in the smb_rqst page array into a kvec
249 * @rqst: pointer to smb_rqst
250 * @idx: index into the array of the page
251 * @iov: pointer to struct kvec that will hold the result
252 *
253 * Helper function to convert a slot in the rqst->rq_pages array into a kvec.
254 * The page will be kmapped and the address placed into iov_base. The length
255 * will then be adjusted according to the ptailoff.
256 */
257void
258cifs_rqst_page_to_kvec(struct smb_rqst *rqst, unsigned int idx,
259 struct kvec *iov)
260{
261 /*
262 * FIXME: We could avoid this kmap altogether if we used
263 * kernel_sendpage instead of kernel_sendmsg. That will only
264 * work if signing is disabled though as sendpage inlines the
265 * page directly into the fraglist. If userspace modifies the
266 * page after we calculate the signature, then the server will
267 * reject it and may break the connection. kernel_sendmsg does
268 * an extra copy of the data and avoids that issue.
269 */
270 iov->iov_base = kmap(rqst->rq_pages[idx]);
271
272 /* if last page, don't send beyond this offset into page */
273 if (idx == (rqst->rq_npages - 1))
274 iov->iov_len = rqst->rq_tailsz;
275 else
276 iov->iov_len = rqst->rq_pagesz;
277}
278
279static int
280smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst)
281{
282 int rc;
283 struct kvec *iov = rqst->rq_iov;
284 int n_vec = rqst->rq_nvec;
285 unsigned int smb_buf_length = get_rfc1002_length(iov[0].iov_base);
286 unsigned int i;
287 size_t total_len = 0, sent;
288 struct socket *ssocket = server->ssocket;
289 int val = 1;
290
291 if (ssocket == NULL)
292 return -ENOTSOCK;
293
294 cFYI(1, "Sending smb: smb_len=%u", smb_buf_length);
295 dump_smb(iov[0].iov_base, iov[0].iov_len);
296
297 /* cork the socket */
298 kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
299 (char *)&val, sizeof(val));
300
301 rc = smb_send_kvec(server, iov, n_vec, &sent);
302 if (rc < 0)
303 goto uncork;
304
305 total_len += sent;
306
307 /* now walk the page array and send each page in it */
308 for (i = 0; i < rqst->rq_npages; i++) {
309 struct kvec p_iov;
310
311 cifs_rqst_page_to_kvec(rqst, i, &p_iov);
312 rc = smb_send_kvec(server, &p_iov, 1, &sent);
313 kunmap(rqst->rq_pages[i]);
314 if (rc < 0)
315 break;
316
317 total_len += sent;
318 }
319
320uncork:
321 /* uncork it */
322 val = 0;
323 kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
324 (char *)&val, sizeof(val));
325 221
326 if ((total_len > 0) && (total_len != smb_buf_length + 4)) { 222 if ((total_len > 0) && (total_len != smb_buf_length + 4)) {
327 cFYI(1, "partial send (wanted=%u sent=%zu): terminating " 223 cFYI(1, "partial send (%d remaining), terminating session",
328 "session", smb_buf_length + 4, total_len); 224 total_len);
329 /* 225 /* If we have only sent part of an SMB then the next SMB
330 * If we have only sent part of an SMB then the next SMB could 226 could be taken as the remainder of this one. We need
331 * be taken as the remainder of this one. We need to kill the 227 to kill the socket so the server throws away the partial
332 * socket so the server throws away the partial SMB 228 SMB */
333 */
334 server->tcpStatus = CifsNeedReconnect; 229 server->tcpStatus = CifsNeedReconnect;
335 } 230 }
336 231
@@ -339,16 +234,11 @@ uncork:
339 else 234 else
340 rc = 0; 235 rc = 0;
341 236
342 return rc; 237 /* Don't want to modify the buffer as a
343} 238 side effect of this call. */
239 smb_buffer->smb_buf_length = cpu_to_be32(smb_buf_length);
344 240
345static int 241 return rc;
346smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
347{
348 struct smb_rqst rqst = { .rq_iov = iov,
349 .rq_nvec = n_vec };
350
351 return smb_send_rqst(server, &rqst);
352} 242}
353 243
354int 244int
@@ -363,62 +253,44 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
363 return smb_sendv(server, &iov, 1); 253 return smb_sendv(server, &iov, 1);
364} 254}
365 255
366static int 256static int wait_for_free_request(struct TCP_Server_Info *server,
367wait_for_free_credits(struct TCP_Server_Info *server, const int timeout, 257 const int long_op)
368 int *credits)
369{ 258{
370 int rc; 259 if (long_op == CIFS_ASYNC_OP) {
371
372 spin_lock(&server->req_lock);
373 if (timeout == CIFS_ASYNC_OP) {
374 /* oplock breaks must not be held up */ 260 /* oplock breaks must not be held up */
375 server->in_flight++; 261 atomic_inc(&server->inFlight);
376 *credits -= 1;
377 spin_unlock(&server->req_lock);
378 return 0; 262 return 0;
379 } 263 }
380 264
265 spin_lock(&GlobalMid_Lock);
381 while (1) { 266 while (1) {
382 if (*credits <= 0) { 267 if (atomic_read(&server->inFlight) >= cifs_max_pending) {
383 spin_unlock(&server->req_lock); 268 spin_unlock(&GlobalMid_Lock);
384 cifs_num_waiters_inc(server); 269 cifs_num_waiters_inc(server);
385 rc = wait_event_killable(server->request_q, 270 wait_event(server->request_q,
386 has_credits(server, credits)); 271 atomic_read(&server->inFlight)
272 < cifs_max_pending);
387 cifs_num_waiters_dec(server); 273 cifs_num_waiters_dec(server);
388 if (rc) 274 spin_lock(&GlobalMid_Lock);
389 return rc;
390 spin_lock(&server->req_lock);
391 } else { 275 } else {
392 if (server->tcpStatus == CifsExiting) { 276 if (server->tcpStatus == CifsExiting) {
393 spin_unlock(&server->req_lock); 277 spin_unlock(&GlobalMid_Lock);
394 return -ENOENT; 278 return -ENOENT;
395 } 279 }
396 280
397 /* 281 /* can not count locking commands against total
398 * Can not count locking commands against total 282 as they are allowed to block on server */
399 * as they are allowed to block on server.
400 */
401 283
402 /* update # of requests on the wire to server */ 284 /* update # of requests on the wire to server */
403 if (timeout != CIFS_BLOCKING_OP) { 285 if (long_op != CIFS_BLOCKING_OP)
404 *credits -= 1; 286 atomic_inc(&server->inFlight);
405 server->in_flight++; 287 spin_unlock(&GlobalMid_Lock);
406 }
407 spin_unlock(&server->req_lock);
408 break; 288 break;
409 } 289 }
410 } 290 }
411 return 0; 291 return 0;
412} 292}
413 293
414static int
415wait_for_free_request(struct TCP_Server_Info *server, const int timeout,
416 const int optype)
417{
418 return wait_for_free_credits(server, timeout,
419 server->ops->get_credits_field(server, optype));
420}
421
422static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf, 294static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
423 struct mid_q_entry **ppmidQ) 295 struct mid_q_entry **ppmidQ)
424{ 296{
@@ -452,88 +324,73 @@ wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ)
452{ 324{
453 int error; 325 int error;
454 326
455 error = wait_event_freezekillable(server->response_q, 327 error = wait_event_killable(server->response_q,
456 midQ->mid_state != MID_REQUEST_SUBMITTED); 328 midQ->midState != MID_REQUEST_SUBMITTED);
457 if (error < 0) 329 if (error < 0)
458 return -ERESTARTSYS; 330 return -ERESTARTSYS;
459 331
460 return 0; 332 return 0;
461} 333}
462 334
463struct mid_q_entry *
464cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
465{
466 int rc;
467 struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
468 struct mid_q_entry *mid;
469
470 /* enable signing if server requires it */
471 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
472 hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
473
474 mid = AllocMidQEntry(hdr, server);
475 if (mid == NULL)
476 return ERR_PTR(-ENOMEM);
477
478 rc = cifs_sign_rqst(rqst, server, &mid->sequence_number);
479 if (rc) {
480 DeleteMidQEntry(mid);
481 return ERR_PTR(rc);
482 }
483
484 return mid;
485}
486 335
487/* 336/*
488 * Send a SMB request and set the callback function in the mid to handle 337 * Send a SMB request and set the callback function in the mid to handle
489 * the result. Caller is responsible for dealing with timeouts. 338 * the result. Caller is responsible for dealing with timeouts.
490 */ 339 */
491int 340int
492cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, 341cifs_call_async(struct TCP_Server_Info *server, struct kvec *iov,
493 mid_receive_t *receive, mid_callback_t *callback, 342 unsigned int nvec, mid_callback_t *callback, void *cbdata,
494 void *cbdata, const int flags) 343 bool ignore_pend)
495{ 344{
496 int rc, timeout, optype; 345 int rc;
497 struct mid_q_entry *mid; 346 struct mid_q_entry *mid;
347 struct smb_hdr *hdr = (struct smb_hdr *)iov[0].iov_base;
498 348
499 timeout = flags & CIFS_TIMEOUT_MASK; 349 rc = wait_for_free_request(server, ignore_pend ? CIFS_ASYNC_OP : 0);
500 optype = flags & CIFS_OP_MASK;
501
502 rc = wait_for_free_request(server, timeout, optype);
503 if (rc) 350 if (rc)
504 return rc; 351 return rc;
505 352
353 /* enable signing if server requires it */
354 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
355 hdr->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
356
506 mutex_lock(&server->srv_mutex); 357 mutex_lock(&server->srv_mutex);
507 mid = server->ops->setup_async_request(server, rqst); 358 mid = AllocMidQEntry(hdr, server);
508 if (IS_ERR(mid)) { 359 if (mid == NULL) {
509 mutex_unlock(&server->srv_mutex); 360 mutex_unlock(&server->srv_mutex);
510 add_credits(server, 1, optype); 361 atomic_dec(&server->inFlight);
511 wake_up(&server->request_q); 362 wake_up(&server->request_q);
512 return PTR_ERR(mid); 363 return -ENOMEM;
513 } 364 }
514 365
515 mid->receive = receive;
516 mid->callback = callback;
517 mid->callback_data = cbdata;
518 mid->mid_state = MID_REQUEST_SUBMITTED;
519
520 /* put it on the pending_mid_q */ 366 /* put it on the pending_mid_q */
521 spin_lock(&GlobalMid_Lock); 367 spin_lock(&GlobalMid_Lock);
522 list_add_tail(&mid->qhead, &server->pending_mid_q); 368 list_add_tail(&mid->qhead, &server->pending_mid_q);
523 spin_unlock(&GlobalMid_Lock); 369 spin_unlock(&GlobalMid_Lock);
524 370
371 rc = cifs_sign_smb2(iov, nvec, server, &mid->sequence_number);
372 if (rc) {
373 mutex_unlock(&server->srv_mutex);
374 goto out_err;
375 }
376
377 mid->callback = callback;
378 mid->callback_data = cbdata;
379 mid->midState = MID_REQUEST_SUBMITTED;
525 380
526 cifs_in_send_inc(server); 381 cifs_in_send_inc(server);
527 rc = smb_send_rqst(server, rqst); 382 rc = smb_sendv(server, iov, nvec);
528 cifs_in_send_dec(server); 383 cifs_in_send_dec(server);
529 cifs_save_when_sent(mid); 384 cifs_save_when_sent(mid);
530 mutex_unlock(&server->srv_mutex); 385 mutex_unlock(&server->srv_mutex);
531 386
532 if (rc == 0) 387 if (rc)
533 return 0; 388 goto out_err;
534 389
535 cifs_delete_mid(mid); 390 return rc;
536 add_credits(server, 1, optype); 391out_err:
392 delete_mid(mid);
393 atomic_dec(&server->inFlight);
537 wake_up(&server->request_q); 394 wake_up(&server->request_q);
538 return rc; 395 return rc;
539} 396}
@@ -549,14 +406,14 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
549 */ 406 */
550int 407int
551SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, 408SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
552 char *in_buf, int flags) 409 struct smb_hdr *in_buf, int flags)
553{ 410{
554 int rc; 411 int rc;
555 struct kvec iov[1]; 412 struct kvec iov[1];
556 int resp_buf_type; 413 int resp_buf_type;
557 414
558 iov[0].iov_base = in_buf; 415 iov[0].iov_base = (char *)in_buf;
559 iov[0].iov_len = get_rfc1002_length(in_buf) + 4; 416 iov[0].iov_len = be32_to_cpu(in_buf->smb_buf_length) + 4;
560 flags |= CIFS_NO_RESP; 417 flags |= CIFS_NO_RESP;
561 rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags); 418 rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags);
562 cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc); 419 cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc);
@@ -569,11 +426,11 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
569{ 426{
570 int rc = 0; 427 int rc = 0;
571 428
572 cFYI(1, "%s: cmd=%d mid=%llu state=%d", __func__, 429 cFYI(1, "%s: cmd=%d mid=%d state=%d", __func__, mid->command,
573 le16_to_cpu(mid->command), mid->mid, mid->mid_state); 430 mid->mid, mid->midState);
574 431
575 spin_lock(&GlobalMid_Lock); 432 spin_lock(&GlobalMid_Lock);
576 switch (mid->mid_state) { 433 switch (mid->midState) {
577 case MID_RESPONSE_RECEIVED: 434 case MID_RESPONSE_RECEIVED:
578 spin_unlock(&GlobalMid_Lock); 435 spin_unlock(&GlobalMid_Lock);
579 return rc; 436 return rc;
@@ -588,8 +445,8 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
588 break; 445 break;
589 default: 446 default:
590 list_del_init(&mid->qhead); 447 list_del_init(&mid->qhead);
591 cERROR(1, "%s: invalid mid state mid=%llu state=%d", __func__, 448 cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__,
592 mid->mid, mid->mid_state); 449 mid->mid, mid->midState);
593 rc = -EIO; 450 rc = -EIO;
594 } 451 }
595 spin_unlock(&GlobalMid_Lock); 452 spin_unlock(&GlobalMid_Lock);
@@ -598,119 +455,120 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
598 return rc; 455 return rc;
599} 456}
600 457
601static inline int 458/*
602send_cancel(struct TCP_Server_Info *server, void *buf, struct mid_q_entry *mid) 459 * An NT cancel request header looks just like the original request except:
460 *
461 * The Command is SMB_COM_NT_CANCEL
462 * The WordCount is zeroed out
463 * The ByteCount is zeroed out
464 *
465 * This function mangles an existing request buffer into a
466 * SMB_COM_NT_CANCEL request and then sends it.
467 */
468static int
469send_nt_cancel(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
470 struct mid_q_entry *mid)
603{ 471{
604 return server->ops->send_cancel ? 472 int rc = 0;
605 server->ops->send_cancel(server, buf, mid) : 0; 473
474 /* -4 for RFC1001 length and +2 for BCC field */
475 in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2);
476 in_buf->Command = SMB_COM_NT_CANCEL;
477 in_buf->WordCount = 0;
478 put_bcc(0, in_buf);
479
480 mutex_lock(&server->srv_mutex);
481 rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
482 if (rc) {
483 mutex_unlock(&server->srv_mutex);
484 return rc;
485 }
486 rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
487 mutex_unlock(&server->srv_mutex);
488
489 cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
490 in_buf->Mid, rc);
491
492 return rc;
606} 493}
607 494
608int 495int
609cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, 496cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
610 bool log_error) 497 bool log_error)
611{ 498{
612 unsigned int len = get_rfc1002_length(mid->resp_buf) + 4; 499 dump_smb(mid->resp_buf,
613 500 min_t(u32, 92, be32_to_cpu(mid->resp_buf->smb_buf_length)));
614 dump_smb(mid->resp_buf, min_t(u32, 92, len));
615 501
616 /* convert the length into a more usable form */ 502 /* convert the length into a more usable form */
617 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { 503 if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
618 struct kvec iov;
619 int rc = 0;
620 struct smb_rqst rqst = { .rq_iov = &iov,
621 .rq_nvec = 1 };
622
623 iov.iov_base = mid->resp_buf;
624 iov.iov_len = len;
625 /* FIXME: add code to kill session */ 504 /* FIXME: add code to kill session */
626 rc = cifs_verify_signature(&rqst, server, 505 if (cifs_verify_signature(mid->resp_buf, server,
627 mid->sequence_number + 1); 506 mid->sequence_number + 1) != 0)
628 if (rc) 507 cERROR(1, "Unexpected SMB signature");
629 cERROR(1, "SMB signature verification returned error = "
630 "%d", rc);
631 } 508 }
632 509
633 /* BB special case reconnect tid and uid here? */ 510 /* BB special case reconnect tid and uid here? */
634 return map_smb_to_linux_error(mid->resp_buf, log_error); 511 return map_smb_to_linux_error(mid->resp_buf, log_error);
635} 512}
636 513
637struct mid_q_entry *
638cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
639{
640 int rc;
641 struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
642 struct mid_q_entry *mid;
643
644 rc = allocate_mid(ses, hdr, &mid);
645 if (rc)
646 return ERR_PTR(rc);
647 rc = cifs_sign_rqst(rqst, ses->server, &mid->sequence_number);
648 if (rc) {
649 cifs_delete_mid(mid);
650 return ERR_PTR(rc);
651 }
652 return mid;
653}
654
655int 514int
656SendReceive2(const unsigned int xid, struct cifs_ses *ses, 515SendReceive2(const unsigned int xid, struct cifs_ses *ses,
657 struct kvec *iov, int n_vec, int *resp_buf_type /* ret */, 516 struct kvec *iov, int n_vec, int *pRespBufType /* ret */,
658 const int flags) 517 const int flags)
659{ 518{
660 int rc = 0; 519 int rc = 0;
661 int timeout, optype; 520 int long_op;
662 struct mid_q_entry *midQ; 521 struct mid_q_entry *midQ;
663 char *buf = iov[0].iov_base; 522 struct smb_hdr *in_buf = iov[0].iov_base;
664 unsigned int credits = 1;
665 struct smb_rqst rqst = { .rq_iov = iov,
666 .rq_nvec = n_vec };
667 523
668 timeout = flags & CIFS_TIMEOUT_MASK; 524 long_op = flags & CIFS_TIMEOUT_MASK;
669 optype = flags & CIFS_OP_MASK;
670 525
671 *resp_buf_type = CIFS_NO_BUFFER; /* no response buf yet */ 526 *pRespBufType = CIFS_NO_BUFFER; /* no response buf yet */
672 527
673 if ((ses == NULL) || (ses->server == NULL)) { 528 if ((ses == NULL) || (ses->server == NULL)) {
674 cifs_small_buf_release(buf); 529 cifs_small_buf_release(in_buf);
675 cERROR(1, "Null session"); 530 cERROR(1, "Null session");
676 return -EIO; 531 return -EIO;
677 } 532 }
678 533
679 if (ses->server->tcpStatus == CifsExiting) { 534 if (ses->server->tcpStatus == CifsExiting) {
680 cifs_small_buf_release(buf); 535 cifs_small_buf_release(in_buf);
681 return -ENOENT; 536 return -ENOENT;
682 } 537 }
683 538
684 /* 539 /* Ensure that we do not send more than 50 overlapping requests
685 * Ensure that we do not send more than 50 overlapping requests 540 to the same server. We may make this configurable later or
686 * to the same server. We may make this configurable later or 541 use ses->maxReq */
687 * use ses->maxReq.
688 */
689 542
690 rc = wait_for_free_request(ses->server, timeout, optype); 543 rc = wait_for_free_request(ses->server, long_op);
691 if (rc) { 544 if (rc) {
692 cifs_small_buf_release(buf); 545 cifs_small_buf_release(in_buf);
693 return rc; 546 return rc;
694 } 547 }
695 548
696 /* 549 /* make sure that we sign in the same order that we send on this socket
697 * Make sure that we sign in the same order that we send on this socket 550 and avoid races inside tcp sendmsg code that could cause corruption
698 * and avoid races inside tcp sendmsg code that could cause corruption 551 of smb data */
699 * of smb data.
700 */
701 552
702 mutex_lock(&ses->server->srv_mutex); 553 mutex_lock(&ses->server->srv_mutex);
703 554
704 midQ = ses->server->ops->setup_request(ses, &rqst); 555 rc = allocate_mid(ses, in_buf, &midQ);
705 if (IS_ERR(midQ)) { 556 if (rc) {
706 mutex_unlock(&ses->server->srv_mutex); 557 mutex_unlock(&ses->server->srv_mutex);
707 cifs_small_buf_release(buf); 558 cifs_small_buf_release(in_buf);
708 /* Update # of requests on wire to server */ 559 /* Update # of requests on wire to server */
709 add_credits(ses->server, 1, optype); 560 atomic_dec(&ses->server->inFlight);
710 return PTR_ERR(midQ); 561 wake_up(&ses->server->request_q);
562 return rc;
563 }
564 rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number);
565 if (rc) {
566 mutex_unlock(&ses->server->srv_mutex);
567 cifs_small_buf_release(in_buf);
568 goto out;
711 } 569 }
712 570
713 midQ->mid_state = MID_REQUEST_SUBMITTED; 571 midQ->midState = MID_REQUEST_SUBMITTED;
714 cifs_in_send_inc(ses->server); 572 cifs_in_send_inc(ses->server);
715 rc = smb_sendv(ses->server, iov, n_vec); 573 rc = smb_sendv(ses->server, iov, n_vec);
716 cifs_in_send_dec(ses->server); 574 cifs_in_send_dec(ses->server);
@@ -719,62 +577,61 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,
719 mutex_unlock(&ses->server->srv_mutex); 577 mutex_unlock(&ses->server->srv_mutex);
720 578
721 if (rc < 0) { 579 if (rc < 0) {
722 cifs_small_buf_release(buf); 580 cifs_small_buf_release(in_buf);
723 goto out; 581 goto out;
724 } 582 }
725 583
726 if (timeout == CIFS_ASYNC_OP) { 584 if (long_op == CIFS_ASYNC_OP) {
727 cifs_small_buf_release(buf); 585 cifs_small_buf_release(in_buf);
728 goto out; 586 goto out;
729 } 587 }
730 588
731 rc = wait_for_response(ses->server, midQ); 589 rc = wait_for_response(ses->server, midQ);
732 if (rc != 0) { 590 if (rc != 0) {
733 send_cancel(ses->server, buf, midQ); 591 send_nt_cancel(ses->server, in_buf, midQ);
734 spin_lock(&GlobalMid_Lock); 592 spin_lock(&GlobalMid_Lock);
735 if (midQ->mid_state == MID_REQUEST_SUBMITTED) { 593 if (midQ->midState == MID_REQUEST_SUBMITTED) {
736 midQ->callback = DeleteMidQEntry; 594 midQ->callback = DeleteMidQEntry;
737 spin_unlock(&GlobalMid_Lock); 595 spin_unlock(&GlobalMid_Lock);
738 cifs_small_buf_release(buf); 596 cifs_small_buf_release(in_buf);
739 add_credits(ses->server, 1, optype); 597 atomic_dec(&ses->server->inFlight);
598 wake_up(&ses->server->request_q);
740 return rc; 599 return rc;
741 } 600 }
742 spin_unlock(&GlobalMid_Lock); 601 spin_unlock(&GlobalMid_Lock);
743 } 602 }
744 603
745 cifs_small_buf_release(buf); 604 cifs_small_buf_release(in_buf);
746 605
747 rc = cifs_sync_mid_result(midQ, ses->server); 606 rc = cifs_sync_mid_result(midQ, ses->server);
748 if (rc != 0) { 607 if (rc != 0) {
749 add_credits(ses->server, 1, optype); 608 atomic_dec(&ses->server->inFlight);
609 wake_up(&ses->server->request_q);
750 return rc; 610 return rc;
751 } 611 }
752 612
753 if (!midQ->resp_buf || midQ->mid_state != MID_RESPONSE_RECEIVED) { 613 if (!midQ->resp_buf || midQ->midState != MID_RESPONSE_RECEIVED) {
754 rc = -EIO; 614 rc = -EIO;
755 cFYI(1, "Bad MID state?"); 615 cFYI(1, "Bad MID state?");
756 goto out; 616 goto out;
757 } 617 }
758 618
759 buf = (char *)midQ->resp_buf; 619 iov[0].iov_base = (char *)midQ->resp_buf;
760 iov[0].iov_base = buf; 620 iov[0].iov_len = be32_to_cpu(midQ->resp_buf->smb_buf_length) + 4;
761 iov[0].iov_len = get_rfc1002_length(buf) + 4; 621 if (midQ->largeBuf)
762 if (midQ->large_buf) 622 *pRespBufType = CIFS_LARGE_BUFFER;
763 *resp_buf_type = CIFS_LARGE_BUFFER;
764 else 623 else
765 *resp_buf_type = CIFS_SMALL_BUFFER; 624 *pRespBufType = CIFS_SMALL_BUFFER;
766
767 credits = ses->server->ops->get_credits(midQ);
768 625
769 rc = ses->server->ops->check_receive(midQ, ses->server, 626 rc = cifs_check_receive(midQ, ses->server, flags & CIFS_LOG_ERROR);
770 flags & CIFS_LOG_ERROR);
771 627
772 /* mark it so buf will not be freed by cifs_delete_mid */ 628 /* mark it so buf will not be freed by delete_mid */
773 if ((flags & CIFS_NO_RESP) == 0) 629 if ((flags & CIFS_NO_RESP) == 0)
774 midQ->resp_buf = NULL; 630 midQ->resp_buf = NULL;
775out: 631out:
776 cifs_delete_mid(midQ); 632 delete_mid(midQ);
777 add_credits(ses->server, credits, optype); 633 atomic_dec(&ses->server->inFlight);
634 wake_up(&ses->server->request_q);
778 635
779 return rc; 636 return rc;
780} 637}
@@ -782,7 +639,7 @@ out:
782int 639int
783SendReceive(const unsigned int xid, struct cifs_ses *ses, 640SendReceive(const unsigned int xid, struct cifs_ses *ses,
784 struct smb_hdr *in_buf, struct smb_hdr *out_buf, 641 struct smb_hdr *in_buf, struct smb_hdr *out_buf,
785 int *pbytes_returned, const int timeout) 642 int *pbytes_returned, const int long_op)
786{ 643{
787 int rc = 0; 644 int rc = 0;
788 struct mid_q_entry *midQ; 645 struct mid_q_entry *midQ;
@@ -810,7 +667,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
810 return -EIO; 667 return -EIO;
811 } 668 }
812 669
813 rc = wait_for_free_request(ses->server, timeout, 0); 670 rc = wait_for_free_request(ses->server, long_op);
814 if (rc) 671 if (rc)
815 return rc; 672 return rc;
816 673
@@ -824,7 +681,8 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
824 if (rc) { 681 if (rc) {
825 mutex_unlock(&ses->server->srv_mutex); 682 mutex_unlock(&ses->server->srv_mutex);
826 /* Update # of requests on wire to server */ 683 /* Update # of requests on wire to server */
827 add_credits(ses->server, 1, 0); 684 atomic_dec(&ses->server->inFlight);
685 wake_up(&ses->server->request_q);
828 return rc; 686 return rc;
829 } 687 }
830 688
@@ -834,7 +692,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
834 goto out; 692 goto out;
835 } 693 }
836 694
837 midQ->mid_state = MID_REQUEST_SUBMITTED; 695 midQ->midState = MID_REQUEST_SUBMITTED;
838 696
839 cifs_in_send_inc(ses->server); 697 cifs_in_send_inc(ses->server);
840 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); 698 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
@@ -845,18 +703,19 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
845 if (rc < 0) 703 if (rc < 0)
846 goto out; 704 goto out;
847 705
848 if (timeout == CIFS_ASYNC_OP) 706 if (long_op == CIFS_ASYNC_OP)
849 goto out; 707 goto out;
850 708
851 rc = wait_for_response(ses->server, midQ); 709 rc = wait_for_response(ses->server, midQ);
852 if (rc != 0) { 710 if (rc != 0) {
853 send_cancel(ses->server, in_buf, midQ); 711 send_nt_cancel(ses->server, in_buf, midQ);
854 spin_lock(&GlobalMid_Lock); 712 spin_lock(&GlobalMid_Lock);
855 if (midQ->mid_state == MID_REQUEST_SUBMITTED) { 713 if (midQ->midState == MID_REQUEST_SUBMITTED) {
856 /* no longer considered to be "in-flight" */ 714 /* no longer considered to be "in-flight" */
857 midQ->callback = DeleteMidQEntry; 715 midQ->callback = DeleteMidQEntry;
858 spin_unlock(&GlobalMid_Lock); 716 spin_unlock(&GlobalMid_Lock);
859 add_credits(ses->server, 1, 0); 717 atomic_dec(&ses->server->inFlight);
718 wake_up(&ses->server->request_q);
860 return rc; 719 return rc;
861 } 720 }
862 spin_unlock(&GlobalMid_Lock); 721 spin_unlock(&GlobalMid_Lock);
@@ -864,23 +723,25 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,
864 723
865 rc = cifs_sync_mid_result(midQ, ses->server); 724 rc = cifs_sync_mid_result(midQ, ses->server);
866 if (rc != 0) { 725 if (rc != 0) {
867 add_credits(ses->server, 1, 0); 726 atomic_dec(&ses->server->inFlight);
727 wake_up(&ses->server->request_q);
868 return rc; 728 return rc;
869 } 729 }
870 730
871 if (!midQ->resp_buf || !out_buf || 731 if (!midQ->resp_buf || !out_buf ||
872 midQ->mid_state != MID_RESPONSE_RECEIVED) { 732 midQ->midState != MID_RESPONSE_RECEIVED) {
873 rc = -EIO; 733 rc = -EIO;
874 cERROR(1, "Bad MID state?"); 734 cERROR(1, "Bad MID state?");
875 goto out; 735 goto out;
876 } 736 }
877 737
878 *pbytes_returned = get_rfc1002_length(midQ->resp_buf); 738 *pbytes_returned = be32_to_cpu(midQ->resp_buf->smb_buf_length);
879 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); 739 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
880 rc = cifs_check_receive(midQ, ses->server, 0); 740 rc = cifs_check_receive(midQ, ses->server, 0);
881out: 741out:
882 cifs_delete_mid(midQ); 742 delete_mid(midQ);
883 add_credits(ses->server, 1, 0); 743 atomic_dec(&ses->server->inFlight);
744 wake_up(&ses->server->request_q);
884 745
885 return rc; 746 return rc;
886} 747}
@@ -904,7 +765,7 @@ send_lock_cancel(const unsigned int xid, struct cifs_tcon *tcon,
904 765
905 pSMB->LockType = LOCKING_ANDX_CANCEL_LOCK|LOCKING_ANDX_LARGE_FILES; 766 pSMB->LockType = LOCKING_ANDX_CANCEL_LOCK|LOCKING_ANDX_LARGE_FILES;
906 pSMB->Timeout = 0; 767 pSMB->Timeout = 0;
907 pSMB->hdr.Mid = get_next_mid(ses->server); 768 pSMB->hdr.Mid = GetNextMid(ses->server);
908 769
909 return SendReceive(xid, ses, in_buf, out_buf, 770 return SendReceive(xid, ses, in_buf, out_buf,
910 &bytes_returned, 0); 771 &bytes_returned, 0);
@@ -945,7 +806,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
945 return -EIO; 806 return -EIO;
946 } 807 }
947 808
948 rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0); 809 rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP);
949 if (rc) 810 if (rc)
950 return rc; 811 return rc;
951 812
@@ -963,12 +824,12 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
963 824
964 rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); 825 rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number);
965 if (rc) { 826 if (rc) {
966 cifs_delete_mid(midQ); 827 delete_mid(midQ);
967 mutex_unlock(&ses->server->srv_mutex); 828 mutex_unlock(&ses->server->srv_mutex);
968 return rc; 829 return rc;
969 } 830 }
970 831
971 midQ->mid_state = MID_REQUEST_SUBMITTED; 832 midQ->midState = MID_REQUEST_SUBMITTED;
972 cifs_in_send_inc(ses->server); 833 cifs_in_send_inc(ses->server);
973 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length)); 834 rc = smb_send(ses->server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
974 cifs_in_send_dec(ses->server); 835 cifs_in_send_dec(ses->server);
@@ -976,28 +837,28 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
976 mutex_unlock(&ses->server->srv_mutex); 837 mutex_unlock(&ses->server->srv_mutex);
977 838
978 if (rc < 0) { 839 if (rc < 0) {
979 cifs_delete_mid(midQ); 840 delete_mid(midQ);
980 return rc; 841 return rc;
981 } 842 }
982 843
983 /* Wait for a reply - allow signals to interrupt. */ 844 /* Wait for a reply - allow signals to interrupt. */
984 rc = wait_event_interruptible(ses->server->response_q, 845 rc = wait_event_interruptible(ses->server->response_q,
985 (!(midQ->mid_state == MID_REQUEST_SUBMITTED)) || 846 (!(midQ->midState == MID_REQUEST_SUBMITTED)) ||
986 ((ses->server->tcpStatus != CifsGood) && 847 ((ses->server->tcpStatus != CifsGood) &&
987 (ses->server->tcpStatus != CifsNew))); 848 (ses->server->tcpStatus != CifsNew)));
988 849
989 /* Were we interrupted by a signal ? */ 850 /* Were we interrupted by a signal ? */
990 if ((rc == -ERESTARTSYS) && 851 if ((rc == -ERESTARTSYS) &&
991 (midQ->mid_state == MID_REQUEST_SUBMITTED) && 852 (midQ->midState == MID_REQUEST_SUBMITTED) &&
992 ((ses->server->tcpStatus == CifsGood) || 853 ((ses->server->tcpStatus == CifsGood) ||
993 (ses->server->tcpStatus == CifsNew))) { 854 (ses->server->tcpStatus == CifsNew))) {
994 855
995 if (in_buf->Command == SMB_COM_TRANSACTION2) { 856 if (in_buf->Command == SMB_COM_TRANSACTION2) {
996 /* POSIX lock. We send a NT_CANCEL SMB to cause the 857 /* POSIX lock. We send a NT_CANCEL SMB to cause the
997 blocking lock to return. */ 858 blocking lock to return. */
998 rc = send_cancel(ses->server, in_buf, midQ); 859 rc = send_nt_cancel(ses->server, in_buf, midQ);
999 if (rc) { 860 if (rc) {
1000 cifs_delete_mid(midQ); 861 delete_mid(midQ);
1001 return rc; 862 return rc;
1002 } 863 }
1003 } else { 864 } else {
@@ -1009,16 +870,16 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
1009 /* If we get -ENOLCK back the lock may have 870 /* If we get -ENOLCK back the lock may have
1010 already been removed. Don't exit in this case. */ 871 already been removed. Don't exit in this case. */
1011 if (rc && rc != -ENOLCK) { 872 if (rc && rc != -ENOLCK) {
1012 cifs_delete_mid(midQ); 873 delete_mid(midQ);
1013 return rc; 874 return rc;
1014 } 875 }
1015 } 876 }
1016 877
1017 rc = wait_for_response(ses->server, midQ); 878 rc = wait_for_response(ses->server, midQ);
1018 if (rc) { 879 if (rc) {
1019 send_cancel(ses->server, in_buf, midQ); 880 send_nt_cancel(ses->server, in_buf, midQ);
1020 spin_lock(&GlobalMid_Lock); 881 spin_lock(&GlobalMid_Lock);
1021 if (midQ->mid_state == MID_REQUEST_SUBMITTED) { 882 if (midQ->midState == MID_REQUEST_SUBMITTED) {
1022 /* no longer considered to be "in-flight" */ 883 /* no longer considered to be "in-flight" */
1023 midQ->callback = DeleteMidQEntry; 884 midQ->callback = DeleteMidQEntry;
1024 spin_unlock(&GlobalMid_Lock); 885 spin_unlock(&GlobalMid_Lock);
@@ -1036,17 +897,17 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,
1036 return rc; 897 return rc;
1037 898
1038 /* rcvd frame is ok */ 899 /* rcvd frame is ok */
1039 if (out_buf == NULL || midQ->mid_state != MID_RESPONSE_RECEIVED) { 900 if (out_buf == NULL || midQ->midState != MID_RESPONSE_RECEIVED) {
1040 rc = -EIO; 901 rc = -EIO;
1041 cERROR(1, "Bad MID state?"); 902 cERROR(1, "Bad MID state?");
1042 goto out; 903 goto out;
1043 } 904 }
1044 905
1045 *pbytes_returned = get_rfc1002_length(midQ->resp_buf); 906 *pbytes_returned = be32_to_cpu(midQ->resp_buf->smb_buf_length);
1046 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4); 907 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
1047 rc = cifs_check_receive(midQ, ses->server, 0); 908 rc = cifs_check_receive(midQ, ses->server, 0);
1048out: 909out:
1049 cifs_delete_mid(midQ); 910 delete_mid(midQ);
1050 if (rstart && rc == -EACCES) 911 if (rstart && rc == -EACCES)
1051 return -ERESTARTSYS; 912 return -ERESTARTSYS;
1052 return rc; 913 return rc;
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index 5142f2c6027..2a22fb2989e 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -22,7 +22,6 @@
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/posix_acl_xattr.h> 23#include <linux/posix_acl_xattr.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/xattr.h>
26#include "cifsfs.h" 25#include "cifsfs.h"
27#include "cifspdu.h" 26#include "cifspdu.h"
28#include "cifsglob.h" 27#include "cifsglob.h"
@@ -32,14 +31,22 @@
32#define MAX_EA_VALUE_SIZE 65535 31#define MAX_EA_VALUE_SIZE 65535
33#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib" 32#define CIFS_XATTR_DOS_ATTRIB "user.DosAttrib"
34#define CIFS_XATTR_CIFS_ACL "system.cifs_acl" 33#define CIFS_XATTR_CIFS_ACL "system.cifs_acl"
35 34#define CIFS_XATTR_USER_PREFIX "user."
35#define CIFS_XATTR_SYSTEM_PREFIX "system."
36#define CIFS_XATTR_OS2_PREFIX "os2."
37#define CIFS_XATTR_SECURITY_PREFIX "security."
38#define CIFS_XATTR_TRUSTED_PREFIX "trusted."
39#define XATTR_TRUSTED_PREFIX_LEN 8
40#define XATTR_SECURITY_PREFIX_LEN 9
36/* BB need to add server (Samba e.g) support for security and trusted prefix */ 41/* BB need to add server (Samba e.g) support for security and trusted prefix */
37 42
43
44
38int cifs_removexattr(struct dentry *direntry, const char *ea_name) 45int cifs_removexattr(struct dentry *direntry, const char *ea_name)
39{ 46{
40 int rc = -EOPNOTSUPP; 47 int rc = -EOPNOTSUPP;
41#ifdef CONFIG_CIFS_XATTR 48#ifdef CONFIG_CIFS_XATTR
42 unsigned int xid; 49 int xid;
43 struct cifs_sb_info *cifs_sb; 50 struct cifs_sb_info *cifs_sb;
44 struct tcon_link *tlink; 51 struct tcon_link *tlink;
45 struct cifs_tcon *pTcon; 52 struct cifs_tcon *pTcon;
@@ -60,7 +67,7 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name)
60 return PTR_ERR(tlink); 67 return PTR_ERR(tlink);
61 pTcon = tlink_tcon(tlink); 68 pTcon = tlink_tcon(tlink);
62 69
63 xid = get_xid(); 70 xid = GetXid();
64 71
65 full_path = build_path_from_dentry(direntry); 72 full_path = build_path_from_dentry(direntry);
66 if (full_path == NULL) { 73 if (full_path == NULL) {
@@ -69,8 +76,8 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name)
69 } 76 }
70 if (ea_name == NULL) { 77 if (ea_name == NULL) {
71 cFYI(1, "Null xattr names not supported"); 78 cFYI(1, "Null xattr names not supported");
72 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) 79 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5)
73 && (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN))) { 80 && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) {
74 cFYI(1, 81 cFYI(1,
75 "illegal xattr request %s (only user namespace supported)", 82 "illegal xattr request %s (only user namespace supported)",
76 ea_name); 83 ea_name);
@@ -81,14 +88,14 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name)
81 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 88 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
82 goto remove_ea_exit; 89 goto remove_ea_exit;
83 90
84 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */ 91 ea_name += 5; /* skip past user. prefix */
85 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL, 92 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, NULL,
86 (__u16)0, cifs_sb->local_nls, 93 (__u16)0, cifs_sb->local_nls,
87 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 94 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
88 } 95 }
89remove_ea_exit: 96remove_ea_exit:
90 kfree(full_path); 97 kfree(full_path);
91 free_xid(xid); 98 FreeXid(xid);
92 cifs_put_tlink(tlink); 99 cifs_put_tlink(tlink);
93#endif 100#endif
94 return rc; 101 return rc;
@@ -99,12 +106,13 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
99{ 106{
100 int rc = -EOPNOTSUPP; 107 int rc = -EOPNOTSUPP;
101#ifdef CONFIG_CIFS_XATTR 108#ifdef CONFIG_CIFS_XATTR
102 unsigned int xid; 109 int xid;
103 struct cifs_sb_info *cifs_sb; 110 struct cifs_sb_info *cifs_sb;
104 struct tcon_link *tlink; 111 struct tcon_link *tlink;
105 struct cifs_tcon *pTcon; 112 struct cifs_tcon *pTcon;
106 struct super_block *sb; 113 struct super_block *sb;
107 char *full_path; 114 char *full_path;
115 struct cifs_ntsd *pacl;
108 116
109 if (direntry == NULL) 117 if (direntry == NULL)
110 return -EIO; 118 return -EIO;
@@ -120,7 +128,7 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
120 return PTR_ERR(tlink); 128 return PTR_ERR(tlink);
121 pTcon = tlink_tcon(tlink); 129 pTcon = tlink_tcon(tlink);
122 130
123 xid = get_xid(); 131 xid = GetXid();
124 132
125 full_path = build_path_from_dentry(direntry); 133 full_path = build_path_from_dentry(direntry);
126 if (full_path == NULL) { 134 if (full_path == NULL) {
@@ -141,46 +149,43 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
141 149
142 if (ea_name == NULL) { 150 if (ea_name == NULL) {
143 cFYI(1, "Null xattr names not supported"); 151 cFYI(1, "Null xattr names not supported");
144 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) 152 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
145 == 0) {
146 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 153 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
147 goto set_ea_exit; 154 goto set_ea_exit;
148 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) 155 if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
149 cFYI(1, "attempt to set cifs inode metadata"); 156 cFYI(1, "attempt to set cifs inode metadata");
150 157
151 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */ 158 ea_name += 5; /* skip past user. prefix */
152 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value, 159 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
153 (__u16)value_size, cifs_sb->local_nls, 160 (__u16)value_size, cifs_sb->local_nls,
154 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 161 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
155 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) 162 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
156 == 0) {
157 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 163 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
158 goto set_ea_exit; 164 goto set_ea_exit;
159 165
160 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */ 166 ea_name += 4; /* skip past os2. prefix */
161 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value, 167 rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
162 (__u16)value_size, cifs_sb->local_nls, 168 (__u16)value_size, cifs_sb->local_nls,
163 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 169 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
164 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL, 170 } else if (strncmp(ea_name, CIFS_XATTR_CIFS_ACL,
165 strlen(CIFS_XATTR_CIFS_ACL)) == 0) { 171 strlen(CIFS_XATTR_CIFS_ACL)) == 0) {
166#ifdef CONFIG_CIFS_ACL
167 struct cifs_ntsd *pacl;
168 pacl = kmalloc(value_size, GFP_KERNEL); 172 pacl = kmalloc(value_size, GFP_KERNEL);
169 if (!pacl) { 173 if (!pacl) {
170 cFYI(1, "%s: Can't allocate memory for ACL", 174 cFYI(1, "%s: Can't allocate memory for ACL",
171 __func__); 175 __func__);
172 rc = -ENOMEM; 176 rc = -ENOMEM;
173 } else { 177 } else {
178#ifdef CONFIG_CIFS_ACL
174 memcpy(pacl, ea_value, value_size); 179 memcpy(pacl, ea_value, value_size);
175 rc = set_cifs_acl(pacl, value_size, 180 rc = set_cifs_acl(pacl, value_size,
176 direntry->d_inode, full_path, CIFS_ACL_DACL); 181 direntry->d_inode, full_path);
177 if (rc == 0) /* force revalidate of the inode */ 182 if (rc == 0) /* force revalidate of the inode */
178 CIFS_I(direntry->d_inode)->time = 0; 183 CIFS_I(direntry->d_inode)->time = 0;
179 kfree(pacl); 184 kfree(pacl);
180 }
181#else 185#else
182 cFYI(1, "Set CIFS ACL not supported yet"); 186 cFYI(1, "Set CIFS ACL not supported yet");
183#endif /* CONFIG_CIFS_ACL */ 187#endif /* CONFIG_CIFS_ACL */
188 }
184 } else { 189 } else {
185 int temp; 190 int temp;
186 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS, 191 temp = strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
@@ -221,7 +226,7 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
221 226
222set_ea_exit: 227set_ea_exit:
223 kfree(full_path); 228 kfree(full_path);
224 free_xid(xid); 229 FreeXid(xid);
225 cifs_put_tlink(tlink); 230 cifs_put_tlink(tlink);
226#endif 231#endif
227 return rc; 232 return rc;
@@ -232,7 +237,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
232{ 237{
233 ssize_t rc = -EOPNOTSUPP; 238 ssize_t rc = -EOPNOTSUPP;
234#ifdef CONFIG_CIFS_XATTR 239#ifdef CONFIG_CIFS_XATTR
235 unsigned int xid; 240 int xid;
236 struct cifs_sb_info *cifs_sb; 241 struct cifs_sb_info *cifs_sb;
237 struct tcon_link *tlink; 242 struct tcon_link *tlink;
238 struct cifs_tcon *pTcon; 243 struct cifs_tcon *pTcon;
@@ -253,7 +258,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
253 return PTR_ERR(tlink); 258 return PTR_ERR(tlink);
254 pTcon = tlink_tcon(tlink); 259 pTcon = tlink_tcon(tlink);
255 260
256 xid = get_xid(); 261 xid = GetXid();
257 262
258 full_path = build_path_from_dentry(direntry); 263 full_path = build_path_from_dentry(direntry);
259 if (full_path == NULL) { 264 if (full_path == NULL) {
@@ -264,8 +269,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
264 /* return alt name if available as pseudo attr */ 269 /* return alt name if available as pseudo attr */
265 if (ea_name == NULL) { 270 if (ea_name == NULL) {
266 cFYI(1, "Null xattr names not supported"); 271 cFYI(1, "Null xattr names not supported");
267 } else if (strncmp(ea_name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) 272 } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
268 == 0) {
269 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 273 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
270 goto get_ea_exit; 274 goto get_ea_exit;
271 275
@@ -273,15 +277,15 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
273 cFYI(1, "attempt to query cifs inode metadata"); 277 cFYI(1, "attempt to query cifs inode metadata");
274 /* revalidate/getattr then populate from inode */ 278 /* revalidate/getattr then populate from inode */
275 } /* BB add else when above is implemented */ 279 } /* BB add else when above is implemented */
276 ea_name += XATTR_USER_PREFIX_LEN; /* skip past user. prefix */ 280 ea_name += 5; /* skip past user. prefix */
277 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value, 281 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
278 buf_size, cifs_sb->local_nls, 282 buf_size, cifs_sb->local_nls,
279 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 283 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
280 } else if (strncmp(ea_name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { 284 } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
281 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR) 285 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
282 goto get_ea_exit; 286 goto get_ea_exit;
283 287
284 ea_name += XATTR_OS2_PREFIX_LEN; /* skip past os2. prefix */ 288 ea_name += 4; /* skip past os2. prefix */
285 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value, 289 rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
286 buf_size, cifs_sb->local_nls, 290 buf_size, cifs_sb->local_nls,
287 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 291 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -335,10 +339,10 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
335 cFYI(1, "Query CIFS ACL not supported yet"); 339 cFYI(1, "Query CIFS ACL not supported yet");
336#endif /* CONFIG_CIFS_ACL */ 340#endif /* CONFIG_CIFS_ACL */
337 } else if (strncmp(ea_name, 341 } else if (strncmp(ea_name,
338 XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) { 342 CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
339 cFYI(1, "Trusted xattr namespace not supported yet"); 343 cFYI(1, "Trusted xattr namespace not supported yet");
340 } else if (strncmp(ea_name, 344 } else if (strncmp(ea_name,
341 XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) { 345 CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
342 cFYI(1, "Security xattr namespace not supported yet"); 346 cFYI(1, "Security xattr namespace not supported yet");
343 } else 347 } else
344 cFYI(1, 348 cFYI(1,
@@ -355,7 +359,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
355 359
356get_ea_exit: 360get_ea_exit:
357 kfree(full_path); 361 kfree(full_path);
358 free_xid(xid); 362 FreeXid(xid);
359 cifs_put_tlink(tlink); 363 cifs_put_tlink(tlink);
360#endif 364#endif
361 return rc; 365 return rc;
@@ -365,7 +369,7 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
365{ 369{
366 ssize_t rc = -EOPNOTSUPP; 370 ssize_t rc = -EOPNOTSUPP;
367#ifdef CONFIG_CIFS_XATTR 371#ifdef CONFIG_CIFS_XATTR
368 unsigned int xid; 372 int xid;
369 struct cifs_sb_info *cifs_sb; 373 struct cifs_sb_info *cifs_sb;
370 struct tcon_link *tlink; 374 struct tcon_link *tlink;
371 struct cifs_tcon *pTcon; 375 struct cifs_tcon *pTcon;
@@ -389,7 +393,7 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
389 return PTR_ERR(tlink); 393 return PTR_ERR(tlink);
390 pTcon = tlink_tcon(tlink); 394 pTcon = tlink_tcon(tlink);
391 395
392 xid = get_xid(); 396 xid = GetXid();
393 397
394 full_path = build_path_from_dentry(direntry); 398 full_path = build_path_from_dentry(direntry);
395 if (full_path == NULL) { 399 if (full_path == NULL) {
@@ -409,7 +413,7 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
409 413
410list_ea_exit: 414list_ea_exit:
411 kfree(full_path); 415 kfree(full_path);
412 free_xid(xid); 416 FreeXid(xid);
413 cifs_put_tlink(tlink); 417 cifs_put_tlink(tlink);
414#endif 418#endif
415 return rc; 419 return rc;