4 * Copyright (C) International Business Machines Corp., 2002,2010
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Contains the routines for constructing the SMB PDUs themselves
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */
25 /* These are mostly routines that operate on a pathname, or on a tree id */
26 /* (mounted volume), but there are eight handle based routines which must be */
27 /* treated slightly differently for reconnection purposes since we never */
28 /* want to reuse a stale file handle and only the caller knows the file info */
31 #include <linux/kernel.h>
32 #include <linux/vfs.h>
33 #include <linux/slab.h>
34 #include <linux/posix_acl_xattr.h>
35 #include <linux/pagemap.h>
36 #include <linux/swap.h>
37 #include <linux/task_io_accounting_ops.h>
38 #include <linux/uaccess.h>
42 #include "cifsproto.h"
43 #include "cifs_unicode.h"
44 #include "cifs_debug.h"
45 #include "smb2proto.h"
47 #include "smbdirect.h"
48 #ifdef CONFIG_CIFS_DFS_UPCALL
49 #include "dfs_cache.h"
52 #ifdef CONFIG_CIFS_POSIX
57 #ifdef CONFIG_CIFS_WEAK_PW_HASH
58 {LANMAN_PROT
, "\2LM1.2X002"},
59 {LANMAN2_PROT
, "\2LANMAN2.1"},
60 #endif /* weak password hashing for legacy clients */
61 {CIFS_PROT
, "\2NT LM 0.12"},
62 {POSIX_PROT
, "\2POSIX 2"},
70 #ifdef CONFIG_CIFS_WEAK_PW_HASH
71 {LANMAN_PROT
, "\2LM1.2X002"},
72 {LANMAN2_PROT
, "\2LANMAN2.1"},
73 #endif /* weak password hashing for legacy clients */
74 {CIFS_PROT
, "\2NT LM 0.12"},
79 /* define the number of elements in the cifs dialect array */
80 #ifdef CONFIG_CIFS_POSIX
81 #ifdef CONFIG_CIFS_WEAK_PW_HASH
82 #define CIFS_NUM_PROT 4
84 #define CIFS_NUM_PROT 2
85 #endif /* CIFS_WEAK_PW_HASH */
87 #ifdef CONFIG_CIFS_WEAK_PW_HASH
88 #define CIFS_NUM_PROT 3
90 #define CIFS_NUM_PROT 1
91 #endif /* CONFIG_CIFS_WEAK_PW_HASH */
92 #endif /* CIFS_POSIX */
95 * Mark as invalid, all open files on tree connections since they
96 * were closed when session to server was lost.
99 cifs_mark_open_files_invalid(struct cifs_tcon
*tcon
)
101 struct cifsFileInfo
*open_file
= NULL
;
102 struct list_head
*tmp
;
103 struct list_head
*tmp1
;
105 /* list all files open on tree connection and mark them invalid */
106 spin_lock(&tcon
->open_file_lock
);
107 list_for_each_safe(tmp
, tmp1
, &tcon
->openFileList
) {
108 open_file
= list_entry(tmp
, struct cifsFileInfo
, tlist
);
109 open_file
->invalidHandle
= true;
110 open_file
->oplock_break_cancelled
= true;
112 spin_unlock(&tcon
->open_file_lock
);
114 mutex_lock(&tcon
->crfid
.fid_mutex
);
115 tcon
->crfid
.is_valid
= false;
116 /* cached handle is not valid, so SMB2_CLOSE won't be sent below */
117 close_shroot_lease_locked(&tcon
->crfid
);
118 memset(tcon
->crfid
.fid
, 0, sizeof(struct cifs_fid
));
119 mutex_unlock(&tcon
->crfid
.fid_mutex
);
122 * BB Add call to invalidate_inodes(sb) for all superblocks mounted
127 #ifdef CONFIG_CIFS_DFS_UPCALL
128 static int __cifs_reconnect_tcon(const struct nls_table
*nlsc
,
129 struct cifs_tcon
*tcon
)
132 struct dfs_cache_tgt_list tl
;
133 struct dfs_cache_tgt_iterator
*it
= NULL
;
135 const char *tcp_host
;
137 const char *dfs_host
;
140 tree
= kzalloc(MAX_TREE_SIZE
, GFP_KERNEL
);
145 scnprintf(tree
, MAX_TREE_SIZE
, "\\\\%s\\IPC$",
146 tcon
->ses
->server
->hostname
);
147 rc
= CIFSTCon(0, tcon
->ses
, tree
, tcon
, nlsc
);
151 if (!tcon
->dfs_path
) {
152 rc
= CIFSTCon(0, tcon
->ses
, tcon
->treeName
, tcon
, nlsc
);
156 rc
= dfs_cache_noreq_find(tcon
->dfs_path
+ 1, NULL
, &tl
);
160 extract_unc_hostname(tcon
->ses
->server
->hostname
, &tcp_host
,
163 for (it
= dfs_cache_get_tgt_iterator(&tl
); it
;
164 it
= dfs_cache_get_next_tgt(&tl
, it
)) {
165 const char *share
, *prefix
;
166 size_t share_len
, prefix_len
;
168 rc
= dfs_cache_get_tgt_share(it
, &share
, &share_len
, &prefix
,
171 cifs_dbg(VFS
, "%s: failed to parse target share %d\n",
176 extract_unc_hostname(share
, &dfs_host
, &dfs_host_len
);
178 if (dfs_host_len
!= tcp_host_len
179 || strncasecmp(dfs_host
, tcp_host
, dfs_host_len
) != 0) {
180 cifs_dbg(FYI
, "%s: skipping %.*s, doesn't match %.*s",
182 (int)dfs_host_len
, dfs_host
,
183 (int)tcp_host_len
, tcp_host
);
187 scnprintf(tree
, MAX_TREE_SIZE
, "\\%.*s", (int)share_len
, share
);
189 rc
= CIFSTCon(0, tcon
->ses
, tree
, tcon
, nlsc
);
191 rc
= update_super_prepath(tcon
, prefix
, prefix_len
);
200 rc
= dfs_cache_noreq_update_tgthint(tcon
->dfs_path
+ 1,
205 dfs_cache_free_tgts(&tl
);
211 static inline int __cifs_reconnect_tcon(const struct nls_table
*nlsc
,
212 struct cifs_tcon
*tcon
)
214 return CIFSTCon(0, tcon
->ses
, tcon
->treeName
, tcon
, nlsc
);
218 /* reconnect the socket, tcon, and smb session if needed */
220 cifs_reconnect_tcon(struct cifs_tcon
*tcon
, int smb_command
)
223 struct cifs_ses
*ses
;
224 struct TCP_Server_Info
*server
;
225 struct nls_table
*nls_codepage
;
229 * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
230 * tcp and smb session status done differently for those three - in the
237 server
= ses
->server
;
240 * only tree disconnect, open, and write, (and ulogoff which does not
241 * have tcon) are allowed as we start force umount
243 if (tcon
->tidStatus
== CifsExiting
) {
244 if (smb_command
!= SMB_COM_WRITE_ANDX
&&
245 smb_command
!= SMB_COM_OPEN_ANDX
&&
246 smb_command
!= SMB_COM_TREE_DISCONNECT
) {
247 cifs_dbg(FYI
, "can not send cmd %d while umounting\n",
253 retries
= server
->nr_targets
;
256 * Give demultiplex thread up to 10 seconds to each target available for
257 * reconnect -- should be greater than cifs socket timeout which is 7
260 while (server
->tcpStatus
== CifsNeedReconnect
) {
261 rc
= wait_event_interruptible_timeout(server
->response_q
,
262 (server
->tcpStatus
!= CifsNeedReconnect
),
265 cifs_dbg(FYI
, "%s: aborting reconnect due to a received"
266 " signal by the process\n", __func__
);
270 /* are we still trying to reconnect? */
271 if (server
->tcpStatus
!= CifsNeedReconnect
)
274 if (retries
&& --retries
)
278 * on "soft" mounts we wait once. Hard mounts keep
279 * retrying until process is killed or server comes
283 cifs_dbg(FYI
, "gave up waiting on reconnect in smb_init\n");
286 retries
= server
->nr_targets
;
289 if (!ses
->need_reconnect
&& !tcon
->need_reconnect
)
292 nls_codepage
= load_nls_default();
295 * need to prevent multiple threads trying to simultaneously
296 * reconnect the same SMB session
298 mutex_lock(&ses
->session_mutex
);
301 * Recheck after acquire mutex. If another thread is negotiating
302 * and the server never sends an answer the socket will be closed
303 * and tcpStatus set to reconnect.
305 if (server
->tcpStatus
== CifsNeedReconnect
) {
307 mutex_unlock(&ses
->session_mutex
);
311 rc
= cifs_negotiate_protocol(0, ses
);
312 if (rc
== 0 && ses
->need_reconnect
)
313 rc
= cifs_setup_session(0, ses
, nls_codepage
);
315 /* do we need to reconnect tcon? */
316 if (rc
|| !tcon
->need_reconnect
) {
317 mutex_unlock(&ses
->session_mutex
);
321 cifs_mark_open_files_invalid(tcon
);
322 rc
= __cifs_reconnect_tcon(nls_codepage
, tcon
);
323 mutex_unlock(&ses
->session_mutex
);
324 cifs_dbg(FYI
, "reconnect tcon rc = %d\n", rc
);
327 printk_once(KERN_WARNING
"reconnect tcon failed rc = %d\n", rc
);
331 atomic_inc(&tconInfoReconnectCount
);
333 /* tell server Unix caps we support */
335 reset_cifs_unix_caps(0, tcon
, NULL
, NULL
);
338 * Removed call to reopen open files here. It is safer (and faster) to
339 * reopen files one at a time as needed in read and write.
341 * FIXME: what about file locks? don't we need to reclaim them ASAP?
346 * Check if handle based operation so we know whether we can continue
347 * or not without returning to caller to reset file handle
349 switch (smb_command
) {
350 case SMB_COM_READ_ANDX
:
351 case SMB_COM_WRITE_ANDX
:
353 case SMB_COM_FIND_CLOSE2
:
354 case SMB_COM_LOCKING_ANDX
:
358 unload_nls(nls_codepage
);
362 /* Allocate and return pointer to an SMB request buffer, and set basic
363 SMB information in the SMB header. If the return code is zero, this
364 function must have filled in request_buf pointer */
366 small_smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
371 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
375 *request_buf
= cifs_small_buf_get();
376 if (*request_buf
== NULL
) {
377 /* BB should we add a retry in here if not a writepage? */
381 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
,
385 cifs_stats_inc(&tcon
->num_smbs_sent
);
391 small_smb_init_no_tc(const int smb_command
, const int wct
,
392 struct cifs_ses
*ses
, void **request_buf
)
395 struct smb_hdr
*buffer
;
397 rc
= small_smb_init(smb_command
, wct
, NULL
, request_buf
);
401 buffer
= (struct smb_hdr
*)*request_buf
;
402 buffer
->Mid
= get_next_mid(ses
->server
);
403 if (ses
->capabilities
& CAP_UNICODE
)
404 buffer
->Flags2
|= SMBFLG2_UNICODE
;
405 if (ses
->capabilities
& CAP_STATUS32
)
406 buffer
->Flags2
|= SMBFLG2_ERR_STATUS
;
408 /* uid, tid can stay at zero as set in header assemble */
410 /* BB add support for turning on the signing when
411 this function is used after 1st of session setup requests */
416 /* If the return code is zero, this function must fill in request_buf pointer */
418 __smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
419 void **request_buf
, void **response_buf
)
421 *request_buf
= cifs_buf_get();
422 if (*request_buf
== NULL
) {
423 /* BB should we add a retry in here if not a writepage? */
426 /* Although the original thought was we needed the response buf for */
427 /* potential retries of smb operations it turns out we can determine */
428 /* from the mid flags when the request buffer can be resent without */
429 /* having to use a second distinct buffer for the response */
431 *response_buf
= *request_buf
;
433 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
437 cifs_stats_inc(&tcon
->num_smbs_sent
);
442 /* If the return code is zero, this function must fill in request_buf pointer */
444 smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
445 void **request_buf
, void **response_buf
)
449 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
453 return __smb_init(smb_command
, wct
, tcon
, request_buf
, response_buf
);
457 smb_init_no_reconnect(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
458 void **request_buf
, void **response_buf
)
460 if (tcon
->ses
->need_reconnect
|| tcon
->need_reconnect
)
463 return __smb_init(smb_command
, wct
, tcon
, request_buf
, response_buf
);
466 static int validate_t2(struct smb_t2_rsp
*pSMB
)
468 unsigned int total_size
;
470 /* check for plausible wct */
471 if (pSMB
->hdr
.WordCount
< 10)
474 /* check for parm and data offset going beyond end of smb */
475 if (get_unaligned_le16(&pSMB
->t2_rsp
.ParameterOffset
) > 1024 ||
476 get_unaligned_le16(&pSMB
->t2_rsp
.DataOffset
) > 1024)
479 total_size
= get_unaligned_le16(&pSMB
->t2_rsp
.ParameterCount
);
480 if (total_size
>= 512)
483 /* check that bcc is at least as big as parms + data, and that it is
484 * less than negotiated smb buffer
486 total_size
+= get_unaligned_le16(&pSMB
->t2_rsp
.DataCount
);
487 if (total_size
> get_bcc(&pSMB
->hdr
) ||
488 total_size
>= CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
)
493 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB
,
494 sizeof(struct smb_t2_rsp
) + 16);
499 decode_ext_sec_blob(struct cifs_ses
*ses
, NEGOTIATE_RSP
*pSMBr
)
503 char *guid
= pSMBr
->u
.extended_response
.GUID
;
504 struct TCP_Server_Info
*server
= ses
->server
;
506 count
= get_bcc(&pSMBr
->hdr
);
507 if (count
< SMB1_CLIENT_GUID_SIZE
)
510 spin_lock(&cifs_tcp_ses_lock
);
511 if (server
->srv_count
> 1) {
512 spin_unlock(&cifs_tcp_ses_lock
);
513 if (memcmp(server
->server_GUID
, guid
, SMB1_CLIENT_GUID_SIZE
) != 0) {
514 cifs_dbg(FYI
, "server UID changed\n");
515 memcpy(server
->server_GUID
, guid
, SMB1_CLIENT_GUID_SIZE
);
518 spin_unlock(&cifs_tcp_ses_lock
);
519 memcpy(server
->server_GUID
, guid
, SMB1_CLIENT_GUID_SIZE
);
522 if (count
== SMB1_CLIENT_GUID_SIZE
) {
523 server
->sec_ntlmssp
= true;
525 count
-= SMB1_CLIENT_GUID_SIZE
;
526 rc
= decode_negTokenInit(
527 pSMBr
->u
.extended_response
.SecurityBlob
, count
, server
);
536 cifs_enable_signing(struct TCP_Server_Info
*server
, bool mnt_sign_required
)
538 bool srv_sign_required
= server
->sec_mode
& server
->vals
->signing_required
;
539 bool srv_sign_enabled
= server
->sec_mode
& server
->vals
->signing_enabled
;
540 bool mnt_sign_enabled
= global_secflags
& CIFSSEC_MAY_SIGN
;
543 * Is signing required by mnt options? If not then check
544 * global_secflags to see if it is there.
546 if (!mnt_sign_required
)
547 mnt_sign_required
= ((global_secflags
& CIFSSEC_MUST_SIGN
) ==
551 * If signing is required then it's automatically enabled too,
552 * otherwise, check to see if the secflags allow it.
554 mnt_sign_enabled
= mnt_sign_required
? mnt_sign_required
:
555 (global_secflags
& CIFSSEC_MAY_SIGN
);
557 /* If server requires signing, does client allow it? */
558 if (srv_sign_required
) {
559 if (!mnt_sign_enabled
) {
560 cifs_dbg(VFS
, "Server requires signing, but it's disabled in SecurityFlags!");
566 /* If client requires signing, does server allow it? */
567 if (mnt_sign_required
) {
568 if (!srv_sign_enabled
) {
569 cifs_dbg(VFS
, "Server does not support signing!");
575 if (cifs_rdma_enabled(server
) && server
->sign
)
576 cifs_dbg(VFS
, "Signing is enabled, and RDMA read/write will be disabled");
581 #ifdef CONFIG_CIFS_WEAK_PW_HASH
583 decode_lanman_negprot_rsp(struct TCP_Server_Info
*server
, NEGOTIATE_RSP
*pSMBr
)
586 struct lanman_neg_rsp
*rsp
= (struct lanman_neg_rsp
*)pSMBr
;
588 if (server
->dialect
!= LANMAN_PROT
&& server
->dialect
!= LANMAN2_PROT
)
591 server
->sec_mode
= le16_to_cpu(rsp
->SecurityMode
);
592 server
->maxReq
= min_t(unsigned int,
593 le16_to_cpu(rsp
->MaxMpxCount
),
595 set_credits(server
, server
->maxReq
);
596 server
->maxBuf
= le16_to_cpu(rsp
->MaxBufSize
);
597 /* set up max_read for readpages check */
598 server
->max_read
= server
->maxBuf
;
599 /* even though we do not use raw we might as well set this
600 accurately, in case we ever find a need for it */
601 if ((le16_to_cpu(rsp
->RawMode
) & RAW_ENABLE
) == RAW_ENABLE
) {
602 server
->max_rw
= 0xFF00;
603 server
->capabilities
= CAP_MPX_MODE
| CAP_RAW_MODE
;
605 server
->max_rw
= 0;/* do not need to use raw anyway */
606 server
->capabilities
= CAP_MPX_MODE
;
608 tmp
= (__s16
)le16_to_cpu(rsp
->ServerTimeZone
);
610 /* OS/2 often does not set timezone therefore
611 * we must use server time to calc time zone.
612 * Could deviate slightly from the right zone.
613 * Smallest defined timezone difference is 15 minutes
614 * (i.e. Nepal). Rounding up/down is done to match
617 int val
, seconds
, remain
, result
;
618 struct timespec64 ts
;
619 time64_t utc
= ktime_get_real_seconds();
620 ts
= cnvrtDosUnixTm(rsp
->SrvTime
.Date
,
621 rsp
->SrvTime
.Time
, 0);
622 cifs_dbg(FYI
, "SrvTime %lld sec since 1970 (utc: %lld) diff: %lld\n",
625 val
= (int)(utc
- ts
.tv_sec
);
627 result
= (seconds
/ MIN_TZ_ADJ
) * MIN_TZ_ADJ
;
628 remain
= seconds
% MIN_TZ_ADJ
;
629 if (remain
>= (MIN_TZ_ADJ
/ 2))
630 result
+= MIN_TZ_ADJ
;
633 server
->timeAdj
= result
;
635 server
->timeAdj
= (int)tmp
;
636 server
->timeAdj
*= 60; /* also in seconds */
638 cifs_dbg(FYI
, "server->timeAdj: %d seconds\n", server
->timeAdj
);
641 /* BB get server time for time conversions and add
642 code to use it and timezone since this is not UTC */
644 if (rsp
->EncryptionKeyLength
==
645 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE
)) {
646 memcpy(server
->cryptkey
, rsp
->EncryptionKey
,
647 CIFS_CRYPTO_KEY_SIZE
);
648 } else if (server
->sec_mode
& SECMODE_PW_ENCRYPT
) {
649 return -EIO
; /* need cryptkey unless plain text */
652 cifs_dbg(FYI
, "LANMAN negotiated\n");
657 decode_lanman_negprot_rsp(struct TCP_Server_Info
*server
, NEGOTIATE_RSP
*pSMBr
)
659 cifs_dbg(VFS
, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n");
665 should_set_ext_sec_flag(enum securityEnum sectype
)
672 if (global_secflags
&
673 (CIFSSEC_MAY_KRB5
| CIFSSEC_MAY_NTLMSSP
))
682 CIFSSMBNegotiate(const unsigned int xid
, struct cifs_ses
*ses
)
685 NEGOTIATE_RSP
*pSMBr
;
689 struct TCP_Server_Info
*server
= ses
->server
;
693 WARN(1, "%s: server is NULL!\n", __func__
);
697 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
698 (void **) &pSMB
, (void **) &pSMBr
);
702 pSMB
->hdr
.Mid
= get_next_mid(server
);
703 pSMB
->hdr
.Flags2
|= (SMBFLG2_UNICODE
| SMBFLG2_ERR_STATUS
);
705 if (should_set_ext_sec_flag(ses
->sectype
)) {
706 cifs_dbg(FYI
, "Requesting extended security.");
707 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
712 * We know that all the name entries in the protocols array
713 * are short (< 16 bytes anyway) and are NUL terminated.
715 for (i
= 0; i
< CIFS_NUM_PROT
; i
++) {
716 size_t len
= strlen(protocols
[i
].name
) + 1;
718 memcpy(pSMB
->DialectsArray
+count
, protocols
[i
].name
, len
);
721 inc_rfc1001_len(pSMB
, count
);
722 pSMB
->ByteCount
= cpu_to_le16(count
);
724 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
725 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
729 server
->dialect
= le16_to_cpu(pSMBr
->DialectIndex
);
730 cifs_dbg(FYI
, "Dialect: %d\n", server
->dialect
);
731 /* Check wct = 1 error case */
732 if ((pSMBr
->hdr
.WordCount
< 13) || (server
->dialect
== BAD_PROT
)) {
733 /* core returns wct = 1, but we do not ask for core - otherwise
734 small wct just comes when dialect index is -1 indicating we
735 could not negotiate a common dialect */
738 } else if (pSMBr
->hdr
.WordCount
== 13) {
739 server
->negflavor
= CIFS_NEGFLAVOR_LANMAN
;
740 rc
= decode_lanman_negprot_rsp(server
, pSMBr
);
742 } else if (pSMBr
->hdr
.WordCount
!= 17) {
747 /* else wct == 17, NTLM or better */
749 server
->sec_mode
= pSMBr
->SecurityMode
;
750 if ((server
->sec_mode
& SECMODE_USER
) == 0)
751 cifs_dbg(FYI
, "share mode security\n");
753 /* one byte, so no need to convert this or EncryptionKeyLen from
755 server
->maxReq
= min_t(unsigned int, le16_to_cpu(pSMBr
->MaxMpxCount
),
757 set_credits(server
, server
->maxReq
);
758 /* probably no need to store and check maxvcs */
759 server
->maxBuf
= le32_to_cpu(pSMBr
->MaxBufferSize
);
760 /* set up max_read for readpages check */
761 server
->max_read
= server
->maxBuf
;
762 server
->max_rw
= le32_to_cpu(pSMBr
->MaxRawSize
);
763 cifs_dbg(NOISY
, "Max buf = %d\n", ses
->server
->maxBuf
);
764 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
765 server
->timeAdj
= (int)(__s16
)le16_to_cpu(pSMBr
->ServerTimeZone
);
766 server
->timeAdj
*= 60;
768 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
769 server
->negflavor
= CIFS_NEGFLAVOR_UNENCAP
;
770 memcpy(ses
->server
->cryptkey
, pSMBr
->u
.EncryptionKey
,
771 CIFS_CRYPTO_KEY_SIZE
);
772 } else if (pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
||
773 server
->capabilities
& CAP_EXTENDED_SECURITY
) {
774 server
->negflavor
= CIFS_NEGFLAVOR_EXTENDED
;
775 rc
= decode_ext_sec_blob(ses
, pSMBr
);
776 } else if (server
->sec_mode
& SECMODE_PW_ENCRYPT
) {
777 rc
= -EIO
; /* no crypt key only if plain text pwd */
779 server
->negflavor
= CIFS_NEGFLAVOR_UNENCAP
;
780 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
785 rc
= cifs_enable_signing(server
, ses
->sign
);
787 cifs_buf_release(pSMB
);
789 cifs_dbg(FYI
, "negprot rc %d\n", rc
);
794 CIFSSMBTDis(const unsigned int xid
, struct cifs_tcon
*tcon
)
796 struct smb_hdr
*smb_buffer
;
799 cifs_dbg(FYI
, "In tree disconnect\n");
801 /* BB: do we need to check this? These should never be NULL. */
802 if ((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
))
806 * No need to return error on this operation if tid invalidated and
807 * closed on server already e.g. due to tcp session crashing. Also,
808 * the tcon is no longer on the list, so no need to take lock before
811 if ((tcon
->need_reconnect
) || (tcon
->ses
->need_reconnect
))
814 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
815 (void **)&smb_buffer
);
819 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *)smb_buffer
, 0);
820 cifs_small_buf_release(smb_buffer
);
822 cifs_dbg(FYI
, "Tree disconnect failed %d\n", rc
);
824 /* No need to return error on this operation if tid invalidated and
825 closed on server already e.g. due to tcp session crashing */
833 * This is a no-op for now. We're not really interested in the reply, but
834 * rather in the fact that the server sent one and that server->lstrp
837 * FIXME: maybe we should consider checking that the reply matches request?
840 cifs_echo_callback(struct mid_q_entry
*mid
)
842 struct TCP_Server_Info
*server
= mid
->callback_data
;
843 struct cifs_credits credits
= { .value
= 1, .instance
= 0 };
845 DeleteMidQEntry(mid
);
846 add_credits(server
, &credits
, CIFS_ECHO_OP
);
850 CIFSSMBEcho(struct TCP_Server_Info
*server
)
855 struct smb_rqst rqst
= { .rq_iov
= iov
,
858 cifs_dbg(FYI
, "In echo request\n");
860 rc
= small_smb_init(SMB_COM_ECHO
, 0, NULL
, (void **)&smb
);
864 if (server
->capabilities
& CAP_UNICODE
)
865 smb
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
867 /* set up echo request */
868 smb
->hdr
.Tid
= 0xffff;
869 smb
->hdr
.WordCount
= 1;
870 put_unaligned_le16(1, &smb
->EchoCount
);
871 put_bcc(1, &smb
->hdr
);
873 inc_rfc1001_len(smb
, 3);
876 iov
[0].iov_base
= smb
;
877 iov
[1].iov_len
= get_rfc1002_length(smb
);
878 iov
[1].iov_base
= (char *)smb
+ 4;
880 rc
= cifs_call_async(server
, &rqst
, NULL
, cifs_echo_callback
, NULL
,
881 server
, CIFS_NON_BLOCKING
| CIFS_ECHO_OP
, NULL
);
883 cifs_dbg(FYI
, "Echo request failed: %d\n", rc
);
885 cifs_small_buf_release(smb
);
891 CIFSSMBLogoff(const unsigned int xid
, struct cifs_ses
*ses
)
893 LOGOFF_ANDX_REQ
*pSMB
;
896 cifs_dbg(FYI
, "In SMBLogoff for session disconnect\n");
899 * BB: do we need to check validity of ses and server? They should
900 * always be valid since we have an active reference. If not, that
901 * should probably be a BUG()
903 if (!ses
|| !ses
->server
)
906 mutex_lock(&ses
->session_mutex
);
907 if (ses
->need_reconnect
)
908 goto session_already_dead
; /* no need to send SMBlogoff if uid
909 already closed due to reconnect */
910 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
912 mutex_unlock(&ses
->session_mutex
);
916 pSMB
->hdr
.Mid
= get_next_mid(ses
->server
);
918 if (ses
->server
->sign
)
919 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
921 pSMB
->hdr
.Uid
= ses
->Suid
;
923 pSMB
->AndXCommand
= 0xFF;
924 rc
= SendReceiveNoRsp(xid
, ses
, (char *) pSMB
, 0);
925 cifs_small_buf_release(pSMB
);
926 session_already_dead
:
927 mutex_unlock(&ses
->session_mutex
);
929 /* if session dead then we do not need to do ulogoff,
930 since server closed smb session, no sense reporting
938 CIFSPOSIXDelFile(const unsigned int xid
, struct cifs_tcon
*tcon
,
939 const char *fileName
, __u16 type
,
940 const struct nls_table
*nls_codepage
, int remap
)
942 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
943 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
944 struct unlink_psx_rq
*pRqD
;
947 int bytes_returned
= 0;
948 __u16 params
, param_offset
, offset
, byte_count
;
950 cifs_dbg(FYI
, "In POSIX delete\n");
952 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
957 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
959 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
960 PATH_MAX
, nls_codepage
, remap
);
961 name_len
++; /* trailing null */
964 name_len
= copy_path_name(pSMB
->FileName
, fileName
);
967 params
= 6 + name_len
;
968 pSMB
->MaxParameterCount
= cpu_to_le16(2);
969 pSMB
->MaxDataCount
= 0; /* BB double check this with jra */
970 pSMB
->MaxSetupCount
= 0;
975 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
976 InformationLevel
) - 4;
977 offset
= param_offset
+ params
;
979 /* Setup pointer to Request Data (inode type) */
980 pRqD
= (struct unlink_psx_rq
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
981 pRqD
->type
= cpu_to_le16(type
);
982 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
983 pSMB
->DataOffset
= cpu_to_le16(offset
);
984 pSMB
->SetupCount
= 1;
986 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
987 byte_count
= 3 /* pad */ + params
+ sizeof(struct unlink_psx_rq
);
989 pSMB
->DataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
990 pSMB
->TotalDataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
991 pSMB
->ParameterCount
= cpu_to_le16(params
);
992 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
993 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_UNLINK
);
995 inc_rfc1001_len(pSMB
, byte_count
);
996 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
997 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
998 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1000 cifs_dbg(FYI
, "Posix delete returned %d\n", rc
);
1001 cifs_buf_release(pSMB
);
1003 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_deletes
);
1012 CIFSSMBDelFile(const unsigned int xid
, struct cifs_tcon
*tcon
, const char *name
,
1013 struct cifs_sb_info
*cifs_sb
)
1015 DELETE_FILE_REQ
*pSMB
= NULL
;
1016 DELETE_FILE_RSP
*pSMBr
= NULL
;
1020 int remap
= cifs_remap(cifs_sb
);
1023 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
1028 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1029 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->fileName
, name
,
1030 PATH_MAX
, cifs_sb
->local_nls
,
1032 name_len
++; /* trailing null */
1035 name_len
= copy_path_name(pSMB
->fileName
, name
);
1037 pSMB
->SearchAttributes
=
1038 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
);
1039 pSMB
->BufferFormat
= 0x04;
1040 inc_rfc1001_len(pSMB
, name_len
+ 1);
1041 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
1042 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1043 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1044 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_deletes
);
1046 cifs_dbg(FYI
, "Error in RMFile = %d\n", rc
);
1048 cifs_buf_release(pSMB
);
1056 CIFSSMBRmDir(const unsigned int xid
, struct cifs_tcon
*tcon
, const char *name
,
1057 struct cifs_sb_info
*cifs_sb
)
1059 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
1060 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
1064 int remap
= cifs_remap(cifs_sb
);
1066 cifs_dbg(FYI
, "In CIFSSMBRmDir\n");
1068 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
1073 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1074 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->DirName
, name
,
1075 PATH_MAX
, cifs_sb
->local_nls
,
1077 name_len
++; /* trailing null */
1080 name_len
= copy_path_name(pSMB
->DirName
, name
);
1083 pSMB
->BufferFormat
= 0x04;
1084 inc_rfc1001_len(pSMB
, name_len
+ 1);
1085 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
1086 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1087 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1088 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_rmdirs
);
1090 cifs_dbg(FYI
, "Error in RMDir = %d\n", rc
);
1092 cifs_buf_release(pSMB
);
1099 CIFSSMBMkDir(const unsigned int xid
, struct inode
*inode
, umode_t mode
,
1100 struct cifs_tcon
*tcon
, const char *name
,
1101 struct cifs_sb_info
*cifs_sb
)
1104 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
1105 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
1108 int remap
= cifs_remap(cifs_sb
);
1110 cifs_dbg(FYI
, "In CIFSSMBMkDir\n");
1112 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
1117 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1118 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->DirName
, name
,
1119 PATH_MAX
, cifs_sb
->local_nls
,
1121 name_len
++; /* trailing null */
1124 name_len
= copy_path_name(pSMB
->DirName
, name
);
1127 pSMB
->BufferFormat
= 0x04;
1128 inc_rfc1001_len(pSMB
, name_len
+ 1);
1129 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
1130 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1131 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1132 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_mkdirs
);
1134 cifs_dbg(FYI
, "Error in Mkdir = %d\n", rc
);
1136 cifs_buf_release(pSMB
);
1143 CIFSPOSIXCreate(const unsigned int xid
, struct cifs_tcon
*tcon
,
1144 __u32 posix_flags
, __u64 mode
, __u16
*netfid
,
1145 FILE_UNIX_BASIC_INFO
*pRetData
, __u32
*pOplock
,
1146 const char *name
, const struct nls_table
*nls_codepage
,
1149 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
1150 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
1153 int bytes_returned
= 0;
1154 __u16 params
, param_offset
, offset
, byte_count
, count
;
1155 OPEN_PSX_REQ
*pdata
;
1156 OPEN_PSX_RSP
*psx_rsp
;
1158 cifs_dbg(FYI
, "In POSIX Create\n");
1160 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1165 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1167 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, name
,
1168 PATH_MAX
, nls_codepage
, remap
);
1169 name_len
++; /* trailing null */
1172 name_len
= copy_path_name(pSMB
->FileName
, name
);
1175 params
= 6 + name_len
;
1176 count
= sizeof(OPEN_PSX_REQ
);
1177 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1178 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* large enough */
1179 pSMB
->MaxSetupCount
= 0;
1183 pSMB
->Reserved2
= 0;
1184 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
1185 InformationLevel
) - 4;
1186 offset
= param_offset
+ params
;
1187 pdata
= (OPEN_PSX_REQ
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
1188 pdata
->Level
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
1189 pdata
->Permissions
= cpu_to_le64(mode
);
1190 pdata
->PosixOpenFlags
= cpu_to_le32(posix_flags
);
1191 pdata
->OpenFlags
= cpu_to_le32(*pOplock
);
1192 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1193 pSMB
->DataOffset
= cpu_to_le16(offset
);
1194 pSMB
->SetupCount
= 1;
1195 pSMB
->Reserved3
= 0;
1196 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1197 byte_count
= 3 /* pad */ + params
+ count
;
1199 pSMB
->DataCount
= cpu_to_le16(count
);
1200 pSMB
->ParameterCount
= cpu_to_le16(params
);
1201 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1202 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1203 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_OPEN
);
1204 pSMB
->Reserved4
= 0;
1205 inc_rfc1001_len(pSMB
, byte_count
);
1206 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1207 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1208 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1210 cifs_dbg(FYI
, "Posix create returned %d\n", rc
);
1211 goto psx_create_err
;
1214 cifs_dbg(FYI
, "copying inode info\n");
1215 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1217 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(OPEN_PSX_RSP
)) {
1218 rc
= -EIO
; /* bad smb */
1219 goto psx_create_err
;
1222 /* copy return information to pRetData */
1223 psx_rsp
= (OPEN_PSX_RSP
*)((char *) &pSMBr
->hdr
.Protocol
1224 + le16_to_cpu(pSMBr
->t2
.DataOffset
));
1226 *pOplock
= le16_to_cpu(psx_rsp
->OplockFlags
);
1228 *netfid
= psx_rsp
->Fid
; /* cifs fid stays in le */
1229 /* Let caller know file was created so we can set the mode. */
1230 /* Do we care about the CreateAction in any other cases? */
1231 if (cpu_to_le32(FILE_CREATE
) == psx_rsp
->CreateAction
)
1232 *pOplock
|= CIFS_CREATE_ACTION
;
1233 /* check to make sure response data is there */
1234 if (psx_rsp
->ReturnedLevel
!= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
)) {
1235 pRetData
->Type
= cpu_to_le32(-1); /* unknown */
1236 cifs_dbg(NOISY
, "unknown type\n");
1238 if (get_bcc(&pSMBr
->hdr
) < sizeof(OPEN_PSX_RSP
)
1239 + sizeof(FILE_UNIX_BASIC_INFO
)) {
1240 cifs_dbg(VFS
, "Open response data too small\n");
1241 pRetData
->Type
= cpu_to_le32(-1);
1242 goto psx_create_err
;
1244 memcpy((char *) pRetData
,
1245 (char *)psx_rsp
+ sizeof(OPEN_PSX_RSP
),
1246 sizeof(FILE_UNIX_BASIC_INFO
));
1250 cifs_buf_release(pSMB
);
1252 if (posix_flags
& SMB_O_DIRECTORY
)
1253 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_posixmkdirs
);
1255 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_posixopens
);
1263 static __u16
convert_disposition(int disposition
)
1267 switch (disposition
) {
1268 case FILE_SUPERSEDE
:
1269 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1272 ofun
= SMBOPEN_OAPPEND
;
1275 ofun
= SMBOPEN_OCREATE
;
1278 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
1280 case FILE_OVERWRITE
:
1281 ofun
= SMBOPEN_OTRUNC
;
1283 case FILE_OVERWRITE_IF
:
1284 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1287 cifs_dbg(FYI
, "unknown disposition %d\n", disposition
);
1288 ofun
= SMBOPEN_OAPPEND
; /* regular open */
1294 access_flags_to_smbopen_mode(const int access_flags
)
1296 int masked_flags
= access_flags
& (GENERIC_READ
| GENERIC_WRITE
);
1298 if (masked_flags
== GENERIC_READ
)
1299 return SMBOPEN_READ
;
1300 else if (masked_flags
== GENERIC_WRITE
)
1301 return SMBOPEN_WRITE
;
1303 /* just go for read/write */
1304 return SMBOPEN_READWRITE
;
1308 SMBLegacyOpen(const unsigned int xid
, struct cifs_tcon
*tcon
,
1309 const char *fileName
, const int openDisposition
,
1310 const int access_flags
, const int create_options
, __u16
*netfid
,
1311 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1312 const struct nls_table
*nls_codepage
, int remap
)
1315 OPENX_REQ
*pSMB
= NULL
;
1316 OPENX_RSP
*pSMBr
= NULL
;
1322 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
1327 pSMB
->AndXCommand
= 0xFF; /* none */
1329 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1330 count
= 1; /* account for one byte pad to word boundary */
1332 cifsConvertToUTF16((__le16
*) (pSMB
->fileName
+ 1),
1333 fileName
, PATH_MAX
, nls_codepage
, remap
);
1334 name_len
++; /* trailing null */
1337 count
= 0; /* no pad */
1338 name_len
= copy_path_name(pSMB
->fileName
, fileName
);
1340 if (*pOplock
& REQ_OPLOCK
)
1341 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
1342 else if (*pOplock
& REQ_BATCHOPLOCK
)
1343 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
1345 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
1346 pSMB
->Mode
= cpu_to_le16(access_flags_to_smbopen_mode(access_flags
));
1347 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
1348 /* set file as system file if special file such
1349 as fifo and server expecting SFU style and
1350 no Unix extensions */
1352 if (create_options
& CREATE_OPTION_SPECIAL
)
1353 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
1354 else /* BB FIXME BB */
1355 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/);
1357 if (create_options
& CREATE_OPTION_READONLY
)
1358 pSMB
->FileAttributes
|= cpu_to_le16(ATTR_READONLY
);
1361 /* pSMB->CreateOptions = cpu_to_le32(create_options &
1362 CREATE_OPTIONS_MASK); */
1363 /* BB FIXME END BB */
1365 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
1366 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
1368 inc_rfc1001_len(pSMB
, count
);
1370 pSMB
->ByteCount
= cpu_to_le16(count
);
1371 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1372 (struct smb_hdr
*)pSMBr
, &bytes_returned
, 0);
1373 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_opens
);
1375 cifs_dbg(FYI
, "Error in Open = %d\n", rc
);
1377 /* BB verify if wct == 15 */
1379 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
1381 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1382 /* Let caller know file was created so we can set the mode. */
1383 /* Do we care about the CreateAction in any other cases? */
1385 /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1386 *pOplock |= CIFS_CREATE_ACTION; */
1390 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
1391 pfile_info
->LastAccessTime
= 0; /* BB fixme */
1392 pfile_info
->LastWriteTime
= 0; /* BB fixme */
1393 pfile_info
->ChangeTime
= 0; /* BB fixme */
1394 pfile_info
->Attributes
=
1395 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
1396 /* the file_info buf is endian converted by caller */
1397 pfile_info
->AllocationSize
=
1398 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
1399 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
1400 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1401 pfile_info
->DeletePending
= 0;
1405 cifs_buf_release(pSMB
);
1412 CIFS_open(const unsigned int xid
, struct cifs_open_parms
*oparms
, int *oplock
,
1416 OPEN_REQ
*req
= NULL
;
1417 OPEN_RSP
*rsp
= NULL
;
1421 struct cifs_sb_info
*cifs_sb
= oparms
->cifs_sb
;
1422 struct cifs_tcon
*tcon
= oparms
->tcon
;
1423 int remap
= cifs_remap(cifs_sb
);
1424 const struct nls_table
*nls
= cifs_sb
->local_nls
;
1425 int create_options
= oparms
->create_options
;
1426 int desired_access
= oparms
->desired_access
;
1427 int disposition
= oparms
->disposition
;
1428 const char *path
= oparms
->path
;
1431 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **)&req
,
1436 /* no commands go after this */
1437 req
->AndXCommand
= 0xFF;
1439 if (req
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1440 /* account for one byte pad to word boundary */
1442 name_len
= cifsConvertToUTF16((__le16
*)(req
->fileName
+ 1),
1443 path
, PATH_MAX
, nls
, remap
);
1447 req
->NameLength
= cpu_to_le16(name_len
);
1449 /* BB improve check for buffer overruns BB */
1452 name_len
= copy_path_name(req
->fileName
, path
);
1453 req
->NameLength
= cpu_to_le16(name_len
);
1456 if (*oplock
& REQ_OPLOCK
)
1457 req
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
1458 else if (*oplock
& REQ_BATCHOPLOCK
)
1459 req
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
1461 req
->DesiredAccess
= cpu_to_le32(desired_access
);
1462 req
->AllocationSize
= 0;
1465 * Set file as system file if special file such as fifo and server
1466 * expecting SFU style and no Unix extensions.
1468 if (create_options
& CREATE_OPTION_SPECIAL
)
1469 req
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
1471 req
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
1474 * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case
1475 * sensitive checks for other servers such as Samba.
1477 if (tcon
->ses
->capabilities
& CAP_UNIX
)
1478 req
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
1480 if (create_options
& CREATE_OPTION_READONLY
)
1481 req
->FileAttributes
|= cpu_to_le32(ATTR_READONLY
);
1483 req
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
1484 req
->CreateDisposition
= cpu_to_le32(disposition
);
1485 req
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
1487 /* BB Expirement with various impersonation levels and verify */
1488 req
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
1489 req
->SecurityFlags
= SECURITY_CONTEXT_TRACKING
|SECURITY_EFFECTIVE_ONLY
;
1492 inc_rfc1001_len(req
, count
);
1494 req
->ByteCount
= cpu_to_le16(count
);
1495 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*)req
,
1496 (struct smb_hdr
*)rsp
, &bytes_returned
, 0);
1497 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_opens
);
1499 cifs_dbg(FYI
, "Error in Open = %d\n", rc
);
1500 cifs_buf_release(req
);
1506 /* 1 byte no need to le_to_cpu */
1507 *oplock
= rsp
->OplockLevel
;
1508 /* cifs fid stays in le */
1509 oparms
->fid
->netfid
= rsp
->Fid
;
1510 oparms
->fid
->access
= desired_access
;
1512 /* Let caller know file was created so we can set the mode. */
1513 /* Do we care about the CreateAction in any other cases? */
1514 if (cpu_to_le32(FILE_CREATE
) == rsp
->CreateAction
)
1515 *oplock
|= CIFS_CREATE_ACTION
;
1518 /* copy from CreationTime to Attributes */
1519 memcpy((char *)buf
, (char *)&rsp
->CreationTime
, 36);
1520 /* the file_info buf is endian converted by caller */
1521 buf
->AllocationSize
= rsp
->AllocationSize
;
1522 buf
->EndOfFile
= rsp
->EndOfFile
;
1523 buf
->NumberOfLinks
= cpu_to_le32(1);
1524 buf
->DeletePending
= 0;
1527 cifs_buf_release(req
);
1532 * Discard any remaining data in the current SMB. To do this, we borrow the
1536 cifs_discard_remaining_data(struct TCP_Server_Info
*server
)
1538 unsigned int rfclen
= server
->pdu_size
;
1539 int remaining
= rfclen
+ server
->vals
->header_preamble_size
-
1542 while (remaining
> 0) {
1545 length
= cifs_read_from_socket(server
, server
->bigbuf
,
1546 min_t(unsigned int, remaining
,
1547 CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
)));
1550 server
->total_read
+= length
;
1551 remaining
-= length
;
1558 __cifs_readv_discard(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
,
1563 length
= cifs_discard_remaining_data(server
);
1564 dequeue_mid(mid
, malformed
);
1565 mid
->resp_buf
= server
->smallbuf
;
1566 server
->smallbuf
= NULL
;
1571 cifs_readv_discard(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
1573 struct cifs_readdata
*rdata
= mid
->callback_data
;
1575 return __cifs_readv_discard(server
, mid
, rdata
->result
);
1579 cifs_readv_receive(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
1582 unsigned int data_offset
, data_len
;
1583 struct cifs_readdata
*rdata
= mid
->callback_data
;
1584 char *buf
= server
->smallbuf
;
1585 unsigned int buflen
= server
->pdu_size
+
1586 server
->vals
->header_preamble_size
;
1587 bool use_rdma_mr
= false;
1589 cifs_dbg(FYI
, "%s: mid=%llu offset=%llu bytes=%u\n",
1590 __func__
, mid
->mid
, rdata
->offset
, rdata
->bytes
);
1593 * read the rest of READ_RSP header (sans Data array), or whatever we
1594 * can if there's not enough data. At this point, we've read down to
1597 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
) -
1598 HEADER_SIZE(server
) + 1;
1600 length
= cifs_read_from_socket(server
,
1601 buf
+ HEADER_SIZE(server
) - 1, len
);
1604 server
->total_read
+= length
;
1606 if (server
->ops
->is_session_expired
&&
1607 server
->ops
->is_session_expired(buf
)) {
1608 cifs_reconnect(server
);
1612 if (server
->ops
->is_status_pending
&&
1613 server
->ops
->is_status_pending(buf
, server
)) {
1614 cifs_discard_remaining_data(server
);
1618 /* set up first two iov for signature check and to get credits */
1619 rdata
->iov
[0].iov_base
= buf
;
1620 rdata
->iov
[0].iov_len
= server
->vals
->header_preamble_size
;
1621 rdata
->iov
[1].iov_base
= buf
+ server
->vals
->header_preamble_size
;
1622 rdata
->iov
[1].iov_len
=
1623 server
->total_read
- server
->vals
->header_preamble_size
;
1624 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%zu\n",
1625 rdata
->iov
[0].iov_base
, rdata
->iov
[0].iov_len
);
1626 cifs_dbg(FYI
, "1: iov_base=%p iov_len=%zu\n",
1627 rdata
->iov
[1].iov_base
, rdata
->iov
[1].iov_len
);
1629 /* Was the SMB read successful? */
1630 rdata
->result
= server
->ops
->map_error(buf
, false);
1631 if (rdata
->result
!= 0) {
1632 cifs_dbg(FYI
, "%s: server returned error %d\n",
1633 __func__
, rdata
->result
);
1634 /* normal error on read response */
1635 return __cifs_readv_discard(server
, mid
, false);
1638 /* Is there enough to get to the rest of the READ_RSP header? */
1639 if (server
->total_read
< server
->vals
->read_rsp_size
) {
1640 cifs_dbg(FYI
, "%s: server returned short header. got=%u expected=%zu\n",
1641 __func__
, server
->total_read
,
1642 server
->vals
->read_rsp_size
);
1643 rdata
->result
= -EIO
;
1644 return cifs_readv_discard(server
, mid
);
1647 data_offset
= server
->ops
->read_data_offset(buf
) +
1648 server
->vals
->header_preamble_size
;
1649 if (data_offset
< server
->total_read
) {
1651 * win2k8 sometimes sends an offset of 0 when the read
1652 * is beyond the EOF. Treat it as if the data starts just after
1655 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
1656 __func__
, data_offset
);
1657 data_offset
= server
->total_read
;
1658 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
1659 /* data_offset is beyond the end of smallbuf */
1660 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
1661 __func__
, data_offset
);
1662 rdata
->result
= -EIO
;
1663 return cifs_readv_discard(server
, mid
);
1666 cifs_dbg(FYI
, "%s: total_read=%u data_offset=%u\n",
1667 __func__
, server
->total_read
, data_offset
);
1669 len
= data_offset
- server
->total_read
;
1671 /* read any junk before data into the rest of smallbuf */
1672 length
= cifs_read_from_socket(server
,
1673 buf
+ server
->total_read
, len
);
1676 server
->total_read
+= length
;
1679 /* how much data is in the response? */
1680 #ifdef CONFIG_CIFS_SMB_DIRECT
1681 use_rdma_mr
= rdata
->mr
;
1683 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
1684 if (!use_rdma_mr
&& (data_offset
+ data_len
> buflen
)) {
1685 /* data_len is corrupt -- discard frame */
1686 rdata
->result
= -EIO
;
1687 return cifs_readv_discard(server
, mid
);
1690 length
= rdata
->read_into_pages(server
, rdata
, data_len
);
1694 server
->total_read
+= length
;
1696 cifs_dbg(FYI
, "total_read=%u buflen=%u remaining=%u\n",
1697 server
->total_read
, buflen
, data_len
);
1699 /* discard anything left over */
1700 if (server
->total_read
< buflen
)
1701 return cifs_readv_discard(server
, mid
);
1703 dequeue_mid(mid
, false);
1704 mid
->resp_buf
= server
->smallbuf
;
1705 server
->smallbuf
= NULL
;
1710 cifs_readv_callback(struct mid_q_entry
*mid
)
1712 struct cifs_readdata
*rdata
= mid
->callback_data
;
1713 struct cifs_tcon
*tcon
= tlink_tcon(rdata
->cfile
->tlink
);
1714 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
1715 struct smb_rqst rqst
= { .rq_iov
= rdata
->iov
,
1717 .rq_pages
= rdata
->pages
,
1718 .rq_offset
= rdata
->page_offset
,
1719 .rq_npages
= rdata
->nr_pages
,
1720 .rq_pagesz
= rdata
->pagesz
,
1721 .rq_tailsz
= rdata
->tailsz
};
1722 struct cifs_credits credits
= { .value
= 1, .instance
= 0 };
1724 cifs_dbg(FYI
, "%s: mid=%llu state=%d result=%d bytes=%u\n",
1725 __func__
, mid
->mid
, mid
->mid_state
, rdata
->result
,
1728 switch (mid
->mid_state
) {
1729 case MID_RESPONSE_RECEIVED
:
1730 /* result already set, check signature */
1734 rc
= cifs_verify_signature(&rqst
, server
,
1735 mid
->sequence_number
);
1737 cifs_dbg(VFS
, "SMB signature verification returned error = %d\n",
1740 /* FIXME: should this be counted toward the initiating task? */
1741 task_io_account_read(rdata
->got_bytes
);
1742 cifs_stats_bytes_read(tcon
, rdata
->got_bytes
);
1744 case MID_REQUEST_SUBMITTED
:
1745 case MID_RETRY_NEEDED
:
1746 rdata
->result
= -EAGAIN
;
1747 if (server
->sign
&& rdata
->got_bytes
)
1748 /* reset bytes number since we can not check a sign */
1749 rdata
->got_bytes
= 0;
1750 /* FIXME: should this be counted toward the initiating task? */
1751 task_io_account_read(rdata
->got_bytes
);
1752 cifs_stats_bytes_read(tcon
, rdata
->got_bytes
);
1755 rdata
->result
= -EIO
;
1758 queue_work(cifsiod_wq
, &rdata
->work
);
1759 DeleteMidQEntry(mid
);
1760 add_credits(server
, &credits
, 0);
1763 /* cifs_async_readv - send an async write, and set up mid to handle result */
1765 cifs_async_readv(struct cifs_readdata
*rdata
)
1768 READ_REQ
*smb
= NULL
;
1770 struct cifs_tcon
*tcon
= tlink_tcon(rdata
->cfile
->tlink
);
1771 struct smb_rqst rqst
= { .rq_iov
= rdata
->iov
,
1774 cifs_dbg(FYI
, "%s: offset=%llu bytes=%u\n",
1775 __func__
, rdata
->offset
, rdata
->bytes
);
1777 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1780 wct
= 10; /* old style read */
1781 if ((rdata
->offset
>> 32) > 0) {
1782 /* can not handle this big offset for old */
1787 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **)&smb
);
1791 smb
->hdr
.Pid
= cpu_to_le16((__u16
)rdata
->pid
);
1792 smb
->hdr
.PidHigh
= cpu_to_le16((__u16
)(rdata
->pid
>> 16));
1794 smb
->AndXCommand
= 0xFF; /* none */
1795 smb
->Fid
= rdata
->cfile
->fid
.netfid
;
1796 smb
->OffsetLow
= cpu_to_le32(rdata
->offset
& 0xFFFFFFFF);
1798 smb
->OffsetHigh
= cpu_to_le32(rdata
->offset
>> 32);
1800 smb
->MaxCount
= cpu_to_le16(rdata
->bytes
& 0xFFFF);
1801 smb
->MaxCountHigh
= cpu_to_le32(rdata
->bytes
>> 16);
1805 /* old style read */
1806 struct smb_com_readx_req
*smbr
=
1807 (struct smb_com_readx_req
*)smb
;
1808 smbr
->ByteCount
= 0;
1811 /* 4 for RFC1001 length + 1 for BCC */
1812 rdata
->iov
[0].iov_base
= smb
;
1813 rdata
->iov
[0].iov_len
= 4;
1814 rdata
->iov
[1].iov_base
= (char *)smb
+ 4;
1815 rdata
->iov
[1].iov_len
= get_rfc1002_length(smb
);
1817 kref_get(&rdata
->refcount
);
1818 rc
= cifs_call_async(tcon
->ses
->server
, &rqst
, cifs_readv_receive
,
1819 cifs_readv_callback
, NULL
, rdata
, 0, NULL
);
1822 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_reads
);
1824 kref_put(&rdata
->refcount
, cifs_readdata_release
);
1826 cifs_small_buf_release(smb
);
1831 CIFSSMBRead(const unsigned int xid
, struct cifs_io_parms
*io_parms
,
1832 unsigned int *nbytes
, char **buf
, int *pbuf_type
)
1835 READ_REQ
*pSMB
= NULL
;
1836 READ_RSP
*pSMBr
= NULL
;
1837 char *pReadData
= NULL
;
1839 int resp_buf_type
= 0;
1841 struct kvec rsp_iov
;
1842 __u32 pid
= io_parms
->pid
;
1843 __u16 netfid
= io_parms
->netfid
;
1844 __u64 offset
= io_parms
->offset
;
1845 struct cifs_tcon
*tcon
= io_parms
->tcon
;
1846 unsigned int count
= io_parms
->length
;
1848 cifs_dbg(FYI
, "Reading %d bytes on fid %d\n", count
, netfid
);
1849 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1852 wct
= 10; /* old style read */
1853 if ((offset
>> 32) > 0) {
1854 /* can not handle this big offset for old */
1860 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
1864 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
1865 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
1867 /* tcon and ses pointer are checked in smb_init */
1868 if (tcon
->ses
->server
== NULL
)
1869 return -ECONNABORTED
;
1871 pSMB
->AndXCommand
= 0xFF; /* none */
1873 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1875 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1877 pSMB
->Remaining
= 0;
1878 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1879 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1881 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1883 /* old style read */
1884 struct smb_com_readx_req
*pSMBW
=
1885 (struct smb_com_readx_req
*)pSMB
;
1886 pSMBW
->ByteCount
= 0;
1889 iov
[0].iov_base
= (char *)pSMB
;
1890 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
1891 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1, &resp_buf_type
,
1892 CIFS_LOG_ERROR
, &rsp_iov
);
1893 cifs_small_buf_release(pSMB
);
1894 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_reads
);
1895 pSMBr
= (READ_RSP
*)rsp_iov
.iov_base
;
1897 cifs_dbg(VFS
, "Send error in read = %d\n", rc
);
1899 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1900 data_length
= data_length
<< 16;
1901 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1902 *nbytes
= data_length
;
1904 /*check that DataLength would not go beyond end of SMB */
1905 if ((data_length
> CIFSMaxBufSize
)
1906 || (data_length
> count
)) {
1907 cifs_dbg(FYI
, "bad length %d for count %d\n",
1908 data_length
, count
);
1912 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1913 le16_to_cpu(pSMBr
->DataOffset
);
1914 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1915 cifs_dbg(VFS, "Faulting on read rc = %d\n",rc);
1917 }*/ /* can not use copy_to_user when using page cache*/
1919 memcpy(*buf
, pReadData
, data_length
);
1924 free_rsp_buf(resp_buf_type
, rsp_iov
.iov_base
);
1925 } else if (resp_buf_type
!= CIFS_NO_BUFFER
) {
1926 /* return buffer to caller to free */
1927 *buf
= rsp_iov
.iov_base
;
1928 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1929 *pbuf_type
= CIFS_SMALL_BUFFER
;
1930 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1931 *pbuf_type
= CIFS_LARGE_BUFFER
;
1932 } /* else no valid buffer on return - leave as null */
1934 /* Note: On -EAGAIN error only caller can retry on handle based calls
1935 since file handle passed in no longer valid */
1941 CIFSSMBWrite(const unsigned int xid
, struct cifs_io_parms
*io_parms
,
1942 unsigned int *nbytes
, const char *buf
)
1945 WRITE_REQ
*pSMB
= NULL
;
1946 WRITE_RSP
*pSMBr
= NULL
;
1947 int bytes_returned
, wct
;
1950 __u32 pid
= io_parms
->pid
;
1951 __u16 netfid
= io_parms
->netfid
;
1952 __u64 offset
= io_parms
->offset
;
1953 struct cifs_tcon
*tcon
= io_parms
->tcon
;
1954 unsigned int count
= io_parms
->length
;
1958 /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/
1959 if (tcon
->ses
== NULL
)
1960 return -ECONNABORTED
;
1962 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1966 if ((offset
>> 32) > 0) {
1967 /* can not handle big offset for old srv */
1972 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1977 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
1978 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
1980 /* tcon and ses pointer are checked in smb_init */
1981 if (tcon
->ses
->server
== NULL
)
1982 return -ECONNABORTED
;
1984 pSMB
->AndXCommand
= 0xFF; /* none */
1986 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1988 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1990 pSMB
->Reserved
= 0xFFFFFFFF;
1991 pSMB
->WriteMode
= 0;
1992 pSMB
->Remaining
= 0;
1994 /* Can increase buffer size if buffer is big enough in some cases ie we
1995 can send more if LARGE_WRITE_X capability returned by the server and if
1996 our buffer is big enough or if we convert to iovecs on socket writes
1997 and eliminate the copy to the CIFS buffer */
1998 if (tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1999 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
2001 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
2005 if (bytes_sent
> count
)
2008 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2010 memcpy(pSMB
->Data
, buf
, bytes_sent
);
2011 else if (count
!= 0) {
2013 cifs_buf_release(pSMB
);
2015 } /* else setting file size with write of zero bytes */
2017 byte_count
= bytes_sent
+ 1; /* pad */
2018 else /* wct == 12 */
2019 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
2021 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
2022 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
2023 inc_rfc1001_len(pSMB
, byte_count
);
2026 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2027 else { /* old style write has byte count 4 bytes earlier
2029 struct smb_com_writex_req
*pSMBW
=
2030 (struct smb_com_writex_req
*)pSMB
;
2031 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
2034 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2035 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2036 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_writes
);
2038 cifs_dbg(FYI
, "Send error in write = %d\n", rc
);
2040 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
2041 *nbytes
= (*nbytes
) << 16;
2042 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
2045 * Mask off high 16 bits when bytes written as returned by the
2046 * server is greater than bytes requested by the client. Some
2047 * OS/2 servers are known to set incorrect CountHigh values.
2049 if (*nbytes
> count
)
2053 cifs_buf_release(pSMB
);
2055 /* Note: On -EAGAIN error only caller can retry on handle based calls
2056 since file handle passed in no longer valid */
2062 cifs_writedata_release(struct kref
*refcount
)
2064 struct cifs_writedata
*wdata
= container_of(refcount
,
2065 struct cifs_writedata
, refcount
);
2066 #ifdef CONFIG_CIFS_SMB_DIRECT
2068 smbd_deregister_mr(wdata
->mr
);
2074 cifsFileInfo_put(wdata
->cfile
);
2076 kvfree(wdata
->pages
);
2081 * Write failed with a retryable error. Resend the write request. It's also
2082 * possible that the page was redirtied so re-clean the page.
2085 cifs_writev_requeue(struct cifs_writedata
*wdata
)
2088 struct inode
*inode
= d_inode(wdata
->cfile
->dentry
);
2089 struct TCP_Server_Info
*server
;
2090 unsigned int rest_len
;
2092 server
= tlink_tcon(wdata
->cfile
->tlink
)->ses
->server
;
2094 rest_len
= wdata
->bytes
;
2096 struct cifs_writedata
*wdata2
;
2097 unsigned int j
, nr_pages
, wsize
, tailsz
, cur_len
;
2099 wsize
= server
->ops
->wp_retry_size(inode
);
2100 if (wsize
< rest_len
) {
2101 nr_pages
= wsize
/ PAGE_SIZE
;
2106 cur_len
= nr_pages
* PAGE_SIZE
;
2109 nr_pages
= DIV_ROUND_UP(rest_len
, PAGE_SIZE
);
2111 tailsz
= rest_len
- (nr_pages
- 1) * PAGE_SIZE
;
2114 wdata2
= cifs_writedata_alloc(nr_pages
, cifs_writev_complete
);
2120 for (j
= 0; j
< nr_pages
; j
++) {
2121 wdata2
->pages
[j
] = wdata
->pages
[i
+ j
];
2122 lock_page(wdata2
->pages
[j
]);
2123 clear_page_dirty_for_io(wdata2
->pages
[j
]);
2126 wdata2
->sync_mode
= wdata
->sync_mode
;
2127 wdata2
->nr_pages
= nr_pages
;
2128 wdata2
->offset
= page_offset(wdata2
->pages
[0]);
2129 wdata2
->pagesz
= PAGE_SIZE
;
2130 wdata2
->tailsz
= tailsz
;
2131 wdata2
->bytes
= cur_len
;
2133 rc
= cifs_get_writable_file(CIFS_I(inode
), FIND_WR_ANY
,
2135 if (!wdata2
->cfile
) {
2136 cifs_dbg(VFS
, "No writable handle to retry writepages rc=%d\n",
2138 if (!is_retryable_error(rc
))
2141 wdata2
->pid
= wdata2
->cfile
->pid
;
2142 rc
= server
->ops
->async_writev(wdata2
,
2143 cifs_writedata_release
);
2146 for (j
= 0; j
< nr_pages
; j
++) {
2147 unlock_page(wdata2
->pages
[j
]);
2148 if (rc
!= 0 && !is_retryable_error(rc
)) {
2149 SetPageError(wdata2
->pages
[j
]);
2150 end_page_writeback(wdata2
->pages
[j
]);
2151 put_page(wdata2
->pages
[j
]);
2155 kref_put(&wdata2
->refcount
, cifs_writedata_release
);
2157 if (is_retryable_error(rc
))
2163 rest_len
-= cur_len
;
2165 } while (i
< wdata
->nr_pages
);
2167 /* cleanup remaining pages from the original wdata */
2168 for (; i
< wdata
->nr_pages
; i
++) {
2169 SetPageError(wdata
->pages
[i
]);
2170 end_page_writeback(wdata
->pages
[i
]);
2171 put_page(wdata
->pages
[i
]);
2174 if (rc
!= 0 && !is_retryable_error(rc
))
2175 mapping_set_error(inode
->i_mapping
, rc
);
2176 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2180 cifs_writev_complete(struct work_struct
*work
)
2182 struct cifs_writedata
*wdata
= container_of(work
,
2183 struct cifs_writedata
, work
);
2184 struct inode
*inode
= d_inode(wdata
->cfile
->dentry
);
2187 if (wdata
->result
== 0) {
2188 spin_lock(&inode
->i_lock
);
2189 cifs_update_eof(CIFS_I(inode
), wdata
->offset
, wdata
->bytes
);
2190 spin_unlock(&inode
->i_lock
);
2191 cifs_stats_bytes_written(tlink_tcon(wdata
->cfile
->tlink
),
2193 } else if (wdata
->sync_mode
== WB_SYNC_ALL
&& wdata
->result
== -EAGAIN
)
2194 return cifs_writev_requeue(wdata
);
2196 for (i
= 0; i
< wdata
->nr_pages
; i
++) {
2197 struct page
*page
= wdata
->pages
[i
];
2198 if (wdata
->result
== -EAGAIN
)
2199 __set_page_dirty_nobuffers(page
);
2200 else if (wdata
->result
< 0)
2202 end_page_writeback(page
);
2205 if (wdata
->result
!= -EAGAIN
)
2206 mapping_set_error(inode
->i_mapping
, wdata
->result
);
2207 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2210 struct cifs_writedata
*
2211 cifs_writedata_alloc(unsigned int nr_pages
, work_func_t complete
)
2213 struct page
**pages
=
2214 kcalloc(nr_pages
, sizeof(struct page
*), GFP_NOFS
);
2216 return cifs_writedata_direct_alloc(pages
, complete
);
2221 struct cifs_writedata
*
2222 cifs_writedata_direct_alloc(struct page
**pages
, work_func_t complete
)
2224 struct cifs_writedata
*wdata
;
2226 wdata
= kzalloc(sizeof(*wdata
), GFP_NOFS
);
2227 if (wdata
!= NULL
) {
2228 wdata
->pages
= pages
;
2229 kref_init(&wdata
->refcount
);
2230 INIT_LIST_HEAD(&wdata
->list
);
2231 init_completion(&wdata
->done
);
2232 INIT_WORK(&wdata
->work
, complete
);
2238 * Check the mid_state and signature on received buffer (if any), and queue the
2239 * workqueue completion task.
2242 cifs_writev_callback(struct mid_q_entry
*mid
)
2244 struct cifs_writedata
*wdata
= mid
->callback_data
;
2245 struct cifs_tcon
*tcon
= tlink_tcon(wdata
->cfile
->tlink
);
2246 unsigned int written
;
2247 WRITE_RSP
*smb
= (WRITE_RSP
*)mid
->resp_buf
;
2248 struct cifs_credits credits
= { .value
= 1, .instance
= 0 };
2250 switch (mid
->mid_state
) {
2251 case MID_RESPONSE_RECEIVED
:
2252 wdata
->result
= cifs_check_receive(mid
, tcon
->ses
->server
, 0);
2253 if (wdata
->result
!= 0)
2256 written
= le16_to_cpu(smb
->CountHigh
);
2258 written
+= le16_to_cpu(smb
->Count
);
2260 * Mask off high 16 bits when bytes written as returned
2261 * by the server is greater than bytes requested by the
2262 * client. OS/2 servers are known to set incorrect
2265 if (written
> wdata
->bytes
)
2268 if (written
< wdata
->bytes
)
2269 wdata
->result
= -ENOSPC
;
2271 wdata
->bytes
= written
;
2273 case MID_REQUEST_SUBMITTED
:
2274 case MID_RETRY_NEEDED
:
2275 wdata
->result
= -EAGAIN
;
2278 wdata
->result
= -EIO
;
2282 queue_work(cifsiod_wq
, &wdata
->work
);
2283 DeleteMidQEntry(mid
);
2284 add_credits(tcon
->ses
->server
, &credits
, 0);
2287 /* cifs_async_writev - send an async write, and set up mid to handle result */
2289 cifs_async_writev(struct cifs_writedata
*wdata
,
2290 void (*release
)(struct kref
*kref
))
2293 WRITE_REQ
*smb
= NULL
;
2295 struct cifs_tcon
*tcon
= tlink_tcon(wdata
->cfile
->tlink
);
2297 struct smb_rqst rqst
= { };
2299 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
2303 if (wdata
->offset
>> 32 > 0) {
2304 /* can not handle big offset for old srv */
2309 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **)&smb
);
2311 goto async_writev_out
;
2313 smb
->hdr
.Pid
= cpu_to_le16((__u16
)wdata
->pid
);
2314 smb
->hdr
.PidHigh
= cpu_to_le16((__u16
)(wdata
->pid
>> 16));
2316 smb
->AndXCommand
= 0xFF; /* none */
2317 smb
->Fid
= wdata
->cfile
->fid
.netfid
;
2318 smb
->OffsetLow
= cpu_to_le32(wdata
->offset
& 0xFFFFFFFF);
2320 smb
->OffsetHigh
= cpu_to_le32(wdata
->offset
>> 32);
2321 smb
->Reserved
= 0xFFFFFFFF;
2326 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2328 /* 4 for RFC1001 length + 1 for BCC */
2330 iov
[0].iov_base
= smb
;
2331 iov
[1].iov_len
= get_rfc1002_length(smb
) + 1;
2332 iov
[1].iov_base
= (char *)smb
+ 4;
2336 rqst
.rq_pages
= wdata
->pages
;
2337 rqst
.rq_offset
= wdata
->page_offset
;
2338 rqst
.rq_npages
= wdata
->nr_pages
;
2339 rqst
.rq_pagesz
= wdata
->pagesz
;
2340 rqst
.rq_tailsz
= wdata
->tailsz
;
2342 cifs_dbg(FYI
, "async write at %llu %u bytes\n",
2343 wdata
->offset
, wdata
->bytes
);
2345 smb
->DataLengthLow
= cpu_to_le16(wdata
->bytes
& 0xFFFF);
2346 smb
->DataLengthHigh
= cpu_to_le16(wdata
->bytes
>> 16);
2349 inc_rfc1001_len(&smb
->hdr
, wdata
->bytes
+ 1);
2350 put_bcc(wdata
->bytes
+ 1, &smb
->hdr
);
2353 struct smb_com_writex_req
*smbw
=
2354 (struct smb_com_writex_req
*)smb
;
2355 inc_rfc1001_len(&smbw
->hdr
, wdata
->bytes
+ 5);
2356 put_bcc(wdata
->bytes
+ 5, &smbw
->hdr
);
2357 iov
[1].iov_len
+= 4; /* pad bigger by four bytes */
2360 kref_get(&wdata
->refcount
);
2361 rc
= cifs_call_async(tcon
->ses
->server
, &rqst
, NULL
,
2362 cifs_writev_callback
, NULL
, wdata
, 0, NULL
);
2365 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_writes
);
2367 kref_put(&wdata
->refcount
, release
);
2370 cifs_small_buf_release(smb
);
2375 CIFSSMBWrite2(const unsigned int xid
, struct cifs_io_parms
*io_parms
,
2376 unsigned int *nbytes
, struct kvec
*iov
, int n_vec
)
2379 WRITE_REQ
*pSMB
= NULL
;
2382 int resp_buf_type
= 0;
2383 __u32 pid
= io_parms
->pid
;
2384 __u16 netfid
= io_parms
->netfid
;
2385 __u64 offset
= io_parms
->offset
;
2386 struct cifs_tcon
*tcon
= io_parms
->tcon
;
2387 unsigned int count
= io_parms
->length
;
2388 struct kvec rsp_iov
;
2392 cifs_dbg(FYI
, "write2 at %lld %d bytes\n", (long long)offset
, count
);
2394 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
2398 if ((offset
>> 32) > 0) {
2399 /* can not handle big offset for old srv */
2403 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
2407 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
2408 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
2410 /* tcon and ses pointer are checked in smb_init */
2411 if (tcon
->ses
->server
== NULL
)
2412 return -ECONNABORTED
;
2414 pSMB
->AndXCommand
= 0xFF; /* none */
2416 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
2418 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
2419 pSMB
->Reserved
= 0xFFFFFFFF;
2420 pSMB
->WriteMode
= 0;
2421 pSMB
->Remaining
= 0;
2424 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2426 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
2427 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
2428 /* header + 1 byte pad */
2429 smb_hdr_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 1;
2431 inc_rfc1001_len(pSMB
, count
+ 1);
2432 else /* wct == 12 */
2433 inc_rfc1001_len(pSMB
, count
+ 5); /* smb data starts later */
2435 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
2436 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
2437 struct smb_com_writex_req
*pSMBW
=
2438 (struct smb_com_writex_req
*)pSMB
;
2439 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
2441 iov
[0].iov_base
= pSMB
;
2443 iov
[0].iov_len
= smb_hdr_len
+ 4;
2444 else /* wct == 12 pad bigger by four bytes */
2445 iov
[0].iov_len
= smb_hdr_len
+ 8;
2447 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
, 0,
2449 cifs_small_buf_release(pSMB
);
2450 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_writes
);
2452 cifs_dbg(FYI
, "Send error Write2 = %d\n", rc
);
2453 } else if (resp_buf_type
== 0) {
2454 /* presumably this can not happen, but best to be safe */
2457 WRITE_RSP
*pSMBr
= (WRITE_RSP
*)rsp_iov
.iov_base
;
2458 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
2459 *nbytes
= (*nbytes
) << 16;
2460 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
2463 * Mask off high 16 bits when bytes written as returned by the
2464 * server is greater than bytes requested by the client. OS/2
2465 * servers are known to set incorrect CountHigh values.
2467 if (*nbytes
> count
)
2471 free_rsp_buf(resp_buf_type
, rsp_iov
.iov_base
);
2473 /* Note: On -EAGAIN error only caller can retry on handle based calls
2474 since file handle passed in no longer valid */
2479 int cifs_lockv(const unsigned int xid
, struct cifs_tcon
*tcon
,
2480 const __u16 netfid
, const __u8 lock_type
, const __u32 num_unlock
,
2481 const __u32 num_lock
, LOCKING_ANDX_RANGE
*buf
)
2484 LOCK_REQ
*pSMB
= NULL
;
2486 struct kvec rsp_iov
;
2490 cifs_dbg(FYI
, "cifs_lockv num lock %d num unlock %d\n",
2491 num_lock
, num_unlock
);
2493 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
2498 pSMB
->NumberOfLocks
= cpu_to_le16(num_lock
);
2499 pSMB
->NumberOfUnlocks
= cpu_to_le16(num_unlock
);
2500 pSMB
->LockType
= lock_type
;
2501 pSMB
->AndXCommand
= 0xFF; /* none */
2502 pSMB
->Fid
= netfid
; /* netfid stays le */
2504 count
= (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2505 inc_rfc1001_len(pSMB
, count
);
2506 pSMB
->ByteCount
= cpu_to_le16(count
);
2508 iov
[0].iov_base
= (char *)pSMB
;
2509 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4 -
2510 (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2511 iov
[1].iov_base
= (char *)buf
;
2512 iov
[1].iov_len
= (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2514 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_locks
);
2515 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 2, &resp_buf_type
,
2516 CIFS_NO_RSP_BUF
, &rsp_iov
);
2517 cifs_small_buf_release(pSMB
);
2519 cifs_dbg(FYI
, "Send error in cifs_lockv = %d\n", rc
);
2525 CIFSSMBLock(const unsigned int xid
, struct cifs_tcon
*tcon
,
2526 const __u16 smb_file_id
, const __u32 netpid
, const __u64 len
,
2527 const __u64 offset
, const __u32 numUnlock
,
2528 const __u32 numLock
, const __u8 lockType
,
2529 const bool waitFlag
, const __u8 oplock_level
)
2532 LOCK_REQ
*pSMB
= NULL
;
2533 /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
2538 cifs_dbg(FYI
, "CIFSSMBLock timeout %d numLock %d\n",
2539 (int)waitFlag
, numLock
);
2540 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
2545 if (lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
2546 /* no response expected */
2547 flags
= CIFS_NO_SRV_RSP
| CIFS_NON_BLOCKING
| CIFS_OBREAK_OP
;
2549 } else if (waitFlag
) {
2550 flags
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
2551 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
2556 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
2557 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
2558 pSMB
->LockType
= lockType
;
2559 pSMB
->OplockLevel
= oplock_level
;
2560 pSMB
->AndXCommand
= 0xFF; /* none */
2561 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
2563 if ((numLock
!= 0) || (numUnlock
!= 0)) {
2564 pSMB
->Locks
[0].Pid
= cpu_to_le16(netpid
);
2565 /* BB where to store pid high? */
2566 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
2567 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
2568 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
2569 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
2570 count
= sizeof(LOCKING_ANDX_RANGE
);
2575 inc_rfc1001_len(pSMB
, count
);
2576 pSMB
->ByteCount
= cpu_to_le16(count
);
2579 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
2580 (struct smb_hdr
*) pSMB
, &bytes_returned
);
2582 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *)pSMB
, flags
);
2583 cifs_small_buf_release(pSMB
);
2584 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_locks
);
2586 cifs_dbg(FYI
, "Send error in Lock = %d\n", rc
);
2588 /* Note: On -EAGAIN error only caller can retry on handle based calls
2589 since file handle passed in no longer valid */
2594 CIFSSMBPosixLock(const unsigned int xid
, struct cifs_tcon
*tcon
,
2595 const __u16 smb_file_id
, const __u32 netpid
,
2596 const loff_t start_offset
, const __u64 len
,
2597 struct file_lock
*pLockData
, const __u16 lock_type
,
2598 const bool waitFlag
)
2600 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2601 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2602 struct cifs_posix_lock
*parm_data
;
2605 int bytes_returned
= 0;
2606 int resp_buf_type
= 0;
2607 __u16 params
, param_offset
, offset
, byte_count
, count
;
2609 struct kvec rsp_iov
;
2611 cifs_dbg(FYI
, "Posix Lock\n");
2613 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
2618 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
2621 pSMB
->MaxSetupCount
= 0;
2624 pSMB
->Reserved2
= 0;
2625 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2626 offset
= param_offset
+ params
;
2628 count
= sizeof(struct cifs_posix_lock
);
2629 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2630 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2631 pSMB
->SetupCount
= 1;
2632 pSMB
->Reserved3
= 0;
2634 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
2636 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2637 byte_count
= 3 /* pad */ + params
+ count
;
2638 pSMB
->DataCount
= cpu_to_le16(count
);
2639 pSMB
->ParameterCount
= cpu_to_le16(params
);
2640 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2641 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2642 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2643 parm_data
= (struct cifs_posix_lock
*)
2644 (((char *) &pSMB
->hdr
.Protocol
) + offset
);
2646 parm_data
->lock_type
= cpu_to_le16(lock_type
);
2648 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
2649 parm_data
->lock_flags
= cpu_to_le16(1);
2650 pSMB
->Timeout
= cpu_to_le32(-1);
2654 parm_data
->pid
= cpu_to_le32(netpid
);
2655 parm_data
->start
= cpu_to_le64(start_offset
);
2656 parm_data
->length
= cpu_to_le64(len
); /* normalize negative numbers */
2658 pSMB
->DataOffset
= cpu_to_le16(offset
);
2659 pSMB
->Fid
= smb_file_id
;
2660 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_LOCK
);
2661 pSMB
->Reserved4
= 0;
2662 inc_rfc1001_len(pSMB
, byte_count
);
2663 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2665 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
2666 (struct smb_hdr
*) pSMBr
, &bytes_returned
);
2668 iov
[0].iov_base
= (char *)pSMB
;
2669 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
2670 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
2671 &resp_buf_type
, timeout
, &rsp_iov
);
2672 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)rsp_iov
.iov_base
;
2674 cifs_small_buf_release(pSMB
);
2677 cifs_dbg(FYI
, "Send error in Posix Lock = %d\n", rc
);
2678 } else if (pLockData
) {
2679 /* lock structure can be returned on get */
2682 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2684 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(*parm_data
)) {
2685 rc
= -EIO
; /* bad smb */
2688 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2689 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2690 if (data_count
< sizeof(struct cifs_posix_lock
)) {
2694 parm_data
= (struct cifs_posix_lock
*)
2695 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
2696 if (parm_data
->lock_type
== cpu_to_le16(CIFS_UNLCK
))
2697 pLockData
->fl_type
= F_UNLCK
;
2699 if (parm_data
->lock_type
==
2700 cpu_to_le16(CIFS_RDLCK
))
2701 pLockData
->fl_type
= F_RDLCK
;
2702 else if (parm_data
->lock_type
==
2703 cpu_to_le16(CIFS_WRLCK
))
2704 pLockData
->fl_type
= F_WRLCK
;
2706 pLockData
->fl_start
= le64_to_cpu(parm_data
->start
);
2707 pLockData
->fl_end
= pLockData
->fl_start
+
2708 le64_to_cpu(parm_data
->length
) - 1;
2709 pLockData
->fl_pid
= -le32_to_cpu(parm_data
->pid
);
2714 free_rsp_buf(resp_buf_type
, rsp_iov
.iov_base
);
2716 /* Note: On -EAGAIN error only caller can retry on handle based calls
2717 since file handle passed in no longer valid */
2724 CIFSSMBClose(const unsigned int xid
, struct cifs_tcon
*tcon
, int smb_file_id
)
2727 CLOSE_REQ
*pSMB
= NULL
;
2728 cifs_dbg(FYI
, "In CIFSSMBClose\n");
2730 /* do not retry on dead session on close */
2731 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
2737 pSMB
->FileID
= (__u16
) smb_file_id
;
2738 pSMB
->LastWriteTime
= 0xFFFFFFFF;
2739 pSMB
->ByteCount
= 0;
2740 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
2741 cifs_small_buf_release(pSMB
);
2742 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_closes
);
2745 /* EINTR is expected when user ctl-c to kill app */
2746 cifs_dbg(VFS
, "Send error in Close = %d\n", rc
);
2750 /* Since session is dead, file will be closed on server already */
2758 CIFSSMBFlush(const unsigned int xid
, struct cifs_tcon
*tcon
, int smb_file_id
)
2761 FLUSH_REQ
*pSMB
= NULL
;
2762 cifs_dbg(FYI
, "In CIFSSMBFlush\n");
2764 rc
= small_smb_init(SMB_COM_FLUSH
, 1, tcon
, (void **) &pSMB
);
2768 pSMB
->FileID
= (__u16
) smb_file_id
;
2769 pSMB
->ByteCount
= 0;
2770 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
2771 cifs_small_buf_release(pSMB
);
2772 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_flushes
);
2774 cifs_dbg(VFS
, "Send error in Flush = %d\n", rc
);
2780 CIFSSMBRename(const unsigned int xid
, struct cifs_tcon
*tcon
,
2781 const char *from_name
, const char *to_name
,
2782 struct cifs_sb_info
*cifs_sb
)
2785 RENAME_REQ
*pSMB
= NULL
;
2786 RENAME_RSP
*pSMBr
= NULL
;
2788 int name_len
, name_len2
;
2790 int remap
= cifs_remap(cifs_sb
);
2792 cifs_dbg(FYI
, "In CIFSSMBRename\n");
2794 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
2799 pSMB
->BufferFormat
= 0x04;
2800 pSMB
->SearchAttributes
=
2801 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2804 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2805 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
,
2806 from_name
, PATH_MAX
,
2807 cifs_sb
->local_nls
, remap
);
2808 name_len
++; /* trailing null */
2810 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2811 /* protocol requires ASCII signature byte on Unicode string */
2812 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2814 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
2815 to_name
, PATH_MAX
, cifs_sb
->local_nls
,
2817 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2818 name_len2
*= 2; /* convert to bytes */
2820 name_len
= copy_path_name(pSMB
->OldFileName
, from_name
);
2821 name_len2
= copy_path_name(pSMB
->OldFileName
+name_len
+1, to_name
);
2822 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2823 name_len2
++; /* signature byte */
2826 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2827 inc_rfc1001_len(pSMB
, count
);
2828 pSMB
->ByteCount
= cpu_to_le16(count
);
2830 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2831 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2832 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_renames
);
2834 cifs_dbg(FYI
, "Send error in rename = %d\n", rc
);
2836 cifs_buf_release(pSMB
);
2844 int CIFSSMBRenameOpenFile(const unsigned int xid
, struct cifs_tcon
*pTcon
,
2845 int netfid
, const char *target_name
,
2846 const struct nls_table
*nls_codepage
, int remap
)
2848 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2849 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2850 struct set_file_rename
*rename_info
;
2852 char dummy_string
[30];
2854 int bytes_returned
= 0;
2856 __u16 params
, param_offset
, offset
, count
, byte_count
;
2858 cifs_dbg(FYI
, "Rename to File by handle\n");
2859 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
2865 pSMB
->MaxSetupCount
= 0;
2869 pSMB
->Reserved2
= 0;
2870 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2871 offset
= param_offset
+ params
;
2873 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2874 rename_info
= (struct set_file_rename
*) data_offset
;
2875 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2876 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2877 pSMB
->SetupCount
= 1;
2878 pSMB
->Reserved3
= 0;
2879 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2880 byte_count
= 3 /* pad */ + params
;
2881 pSMB
->ParameterCount
= cpu_to_le16(params
);
2882 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2883 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2884 pSMB
->DataOffset
= cpu_to_le16(offset
);
2885 /* construct random name ".cifs_tmp<inodenum><mid>" */
2886 rename_info
->overwrite
= cpu_to_le32(1);
2887 rename_info
->root_fid
= 0;
2888 /* unicode only call */
2889 if (target_name
== NULL
) {
2890 sprintf(dummy_string
, "cifs%x", pSMB
->hdr
.Mid
);
2892 cifsConvertToUTF16((__le16
*)rename_info
->target_name
,
2893 dummy_string
, 24, nls_codepage
, remap
);
2896 cifsConvertToUTF16((__le16
*)rename_info
->target_name
,
2897 target_name
, PATH_MAX
, nls_codepage
,
2900 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
2901 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
);
2902 byte_count
+= count
;
2903 pSMB
->DataCount
= cpu_to_le16(count
);
2904 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2906 pSMB
->InformationLevel
=
2907 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
2908 pSMB
->Reserved4
= 0;
2909 inc_rfc1001_len(pSMB
, byte_count
);
2910 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2911 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
2912 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2913 cifs_stats_inc(&pTcon
->stats
.cifs_stats
.num_t2renames
);
2915 cifs_dbg(FYI
, "Send error in Rename (by file handle) = %d\n",
2918 cifs_buf_release(pSMB
);
2920 /* Note: On -EAGAIN error only caller can retry on handle based calls
2921 since file handle passed in no longer valid */
2927 CIFSSMBCopy(const unsigned int xid
, struct cifs_tcon
*tcon
,
2928 const char *fromName
, const __u16 target_tid
, const char *toName
,
2929 const int flags
, const struct nls_table
*nls_codepage
, int remap
)
2932 COPY_REQ
*pSMB
= NULL
;
2933 COPY_RSP
*pSMBr
= NULL
;
2935 int name_len
, name_len2
;
2938 cifs_dbg(FYI
, "In CIFSSMBCopy\n");
2940 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
2945 pSMB
->BufferFormat
= 0x04;
2946 pSMB
->Tid2
= target_tid
;
2948 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
2950 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2951 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
,
2952 fromName
, PATH_MAX
, nls_codepage
,
2954 name_len
++; /* trailing null */
2956 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2957 /* protocol requires ASCII signature byte on Unicode string */
2958 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2960 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
2961 toName
, PATH_MAX
, nls_codepage
, remap
);
2962 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2963 name_len2
*= 2; /* convert to bytes */
2965 name_len
= copy_path_name(pSMB
->OldFileName
, fromName
);
2966 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2967 name_len2
= copy_path_name(pSMB
->OldFileName
+name_len
+1, toName
);
2968 name_len2
++; /* signature byte */
2971 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2972 inc_rfc1001_len(pSMB
, count
);
2973 pSMB
->ByteCount
= cpu_to_le16(count
);
2975 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2976 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2978 cifs_dbg(FYI
, "Send error in copy = %d with %d files copied\n",
2979 rc
, le16_to_cpu(pSMBr
->CopyCount
));
2981 cifs_buf_release(pSMB
);
2990 CIFSUnixCreateSymLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
2991 const char *fromName
, const char *toName
,
2992 const struct nls_table
*nls_codepage
, int remap
)
2994 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2995 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2998 int name_len_target
;
3000 int bytes_returned
= 0;
3001 __u16 params
, param_offset
, offset
, byte_count
;
3003 cifs_dbg(FYI
, "In Symlink Unix style\n");
3005 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3010 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3012 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fromName
,
3013 /* find define for this maxpathcomponent */
3014 PATH_MAX
, nls_codepage
, remap
);
3015 name_len
++; /* trailing null */
3019 name_len
= copy_path_name(pSMB
->FileName
, fromName
);
3021 params
= 6 + name_len
;
3022 pSMB
->MaxSetupCount
= 0;
3026 pSMB
->Reserved2
= 0;
3027 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
3028 InformationLevel
) - 4;
3029 offset
= param_offset
+ params
;
3031 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
3032 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3034 cifsConvertToUTF16((__le16
*) data_offset
, toName
,
3035 /* find define for this maxpathcomponent */
3036 PATH_MAX
, nls_codepage
, remap
);
3037 name_len_target
++; /* trailing null */
3038 name_len_target
*= 2;
3040 name_len_target
= copy_path_name(data_offset
, toName
);
3043 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3044 /* BB find exact max on data count below from sess */
3045 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3046 pSMB
->SetupCount
= 1;
3047 pSMB
->Reserved3
= 0;
3048 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
3049 byte_count
= 3 /* pad */ + params
+ name_len_target
;
3050 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
3051 pSMB
->ParameterCount
= cpu_to_le16(params
);
3052 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3053 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3054 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3055 pSMB
->DataOffset
= cpu_to_le16(offset
);
3056 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
3057 pSMB
->Reserved4
= 0;
3058 inc_rfc1001_len(pSMB
, byte_count
);
3059 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3060 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3061 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3062 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_symlinks
);
3064 cifs_dbg(FYI
, "Send error in SetPathInfo create symlink = %d\n",
3067 cifs_buf_release(pSMB
);
3070 goto createSymLinkRetry
;
3076 CIFSUnixCreateHardLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3077 const char *fromName
, const char *toName
,
3078 const struct nls_table
*nls_codepage
, int remap
)
3080 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
3081 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
3084 int name_len_target
;
3086 int bytes_returned
= 0;
3087 __u16 params
, param_offset
, offset
, byte_count
;
3089 cifs_dbg(FYI
, "In Create Hard link Unix style\n");
3090 createHardLinkRetry
:
3091 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3096 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3097 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->FileName
, toName
,
3098 PATH_MAX
, nls_codepage
, remap
);
3099 name_len
++; /* trailing null */
3103 name_len
= copy_path_name(pSMB
->FileName
, toName
);
3105 params
= 6 + name_len
;
3106 pSMB
->MaxSetupCount
= 0;
3110 pSMB
->Reserved2
= 0;
3111 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
3112 InformationLevel
) - 4;
3113 offset
= param_offset
+ params
;
3115 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
3116 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3118 cifsConvertToUTF16((__le16
*) data_offset
, fromName
,
3119 PATH_MAX
, nls_codepage
, remap
);
3120 name_len_target
++; /* trailing null */
3121 name_len_target
*= 2;
3123 name_len_target
= copy_path_name(data_offset
, fromName
);
3126 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3127 /* BB find exact max on data count below from sess*/
3128 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3129 pSMB
->SetupCount
= 1;
3130 pSMB
->Reserved3
= 0;
3131 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
3132 byte_count
= 3 /* pad */ + params
+ name_len_target
;
3133 pSMB
->ParameterCount
= cpu_to_le16(params
);
3134 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3135 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
3136 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3137 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3138 pSMB
->DataOffset
= cpu_to_le16(offset
);
3139 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
3140 pSMB
->Reserved4
= 0;
3141 inc_rfc1001_len(pSMB
, byte_count
);
3142 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3143 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3144 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3145 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_hardlinks
);
3147 cifs_dbg(FYI
, "Send error in SetPathInfo (hard link) = %d\n",
3150 cifs_buf_release(pSMB
);
3152 goto createHardLinkRetry
;
3158 CIFSCreateHardLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3159 const char *from_name
, const char *to_name
,
3160 struct cifs_sb_info
*cifs_sb
)
3163 NT_RENAME_REQ
*pSMB
= NULL
;
3164 RENAME_RSP
*pSMBr
= NULL
;
3166 int name_len
, name_len2
;
3168 int remap
= cifs_remap(cifs_sb
);
3170 cifs_dbg(FYI
, "In CIFSCreateHardLink\n");
3171 winCreateHardLinkRetry
:
3173 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
3178 pSMB
->SearchAttributes
=
3179 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
3181 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
3182 pSMB
->ClusterCount
= 0;
3184 pSMB
->BufferFormat
= 0x04;
3186 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3188 cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
, from_name
,
3189 PATH_MAX
, cifs_sb
->local_nls
, remap
);
3190 name_len
++; /* trailing null */
3193 /* protocol specifies ASCII buffer format (0x04) for unicode */
3194 pSMB
->OldFileName
[name_len
] = 0x04;
3195 pSMB
->OldFileName
[name_len
+ 1] = 0x00; /* pad */
3197 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
3198 to_name
, PATH_MAX
, cifs_sb
->local_nls
,
3200 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
3201 name_len2
*= 2; /* convert to bytes */
3203 name_len
= copy_path_name(pSMB
->OldFileName
, from_name
);
3204 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
3205 name_len2
= copy_path_name(pSMB
->OldFileName
+name_len
+1, to_name
);
3206 name_len2
++; /* signature byte */
3209 count
= 1 /* string type byte */ + name_len
+ name_len2
;
3210 inc_rfc1001_len(pSMB
, count
);
3211 pSMB
->ByteCount
= cpu_to_le16(count
);
3213 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3214 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3215 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_hardlinks
);
3217 cifs_dbg(FYI
, "Send error in hard link (NT rename) = %d\n", rc
);
3219 cifs_buf_release(pSMB
);
3221 goto winCreateHardLinkRetry
;
3227 CIFSSMBUnixQuerySymLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3228 const unsigned char *searchName
, char **symlinkinfo
,
3229 const struct nls_table
*nls_codepage
, int remap
)
3231 /* SMB_QUERY_FILE_UNIX_LINK */
3232 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3233 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3237 __u16 params
, byte_count
;
3240 cifs_dbg(FYI
, "In QPathSymLinkInfo (Unix) for path %s\n", searchName
);
3243 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3248 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3250 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
3251 searchName
, PATH_MAX
, nls_codepage
,
3253 name_len
++; /* trailing null */
3256 name_len
= copy_path_name(pSMB
->FileName
, searchName
);
3259 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3260 pSMB
->TotalDataCount
= 0;
3261 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3262 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
3263 pSMB
->MaxSetupCount
= 0;
3267 pSMB
->Reserved2
= 0;
3268 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3269 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3270 pSMB
->DataCount
= 0;
3271 pSMB
->DataOffset
= 0;
3272 pSMB
->SetupCount
= 1;
3273 pSMB
->Reserved3
= 0;
3274 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3275 byte_count
= params
+ 1 /* pad */ ;
3276 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3277 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3278 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
3279 pSMB
->Reserved4
= 0;
3280 inc_rfc1001_len(pSMB
, byte_count
);
3281 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3283 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3284 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3286 cifs_dbg(FYI
, "Send error in QuerySymLinkInfo = %d\n", rc
);
3288 /* decode response */
3290 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3291 /* BB also check enough total bytes returned */
3292 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3296 u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3298 data_start
= ((char *) &pSMBr
->hdr
.Protocol
) +
3299 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3301 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3306 /* BB FIXME investigate remapping reserved chars here */
3307 *symlinkinfo
= cifs_strndup_from_utf16(data_start
,
3308 count
, is_unicode
, nls_codepage
);
3313 cifs_buf_release(pSMB
);
3315 goto querySymLinkRetry
;
3320 * Recent Windows versions now create symlinks more frequently
3321 * and they use the "reparse point" mechanism below. We can of course
3322 * do symlinks nicely to Samba and other servers which support the
3323 * CIFS Unix Extensions and we can also do SFU symlinks and "client only"
3324 * "MF" symlinks optionally, but for recent Windows we really need to
3325 * reenable the code below and fix the cifs_symlink callers to handle this.
3326 * In the interim this code has been moved to its own config option so
3327 * it is not compiled in by default until callers fixed up and more tested.
3330 CIFSSMBQuerySymLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3331 __u16 fid
, char **symlinkinfo
,
3332 const struct nls_table
*nls_codepage
)
3336 struct smb_com_transaction_ioctl_req
*pSMB
;
3337 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
3339 unsigned int sub_len
;
3341 struct reparse_symlink_data
*reparse_buf
;
3342 struct reparse_posix_data
*posix_buf
;
3343 __u32 data_offset
, data_count
;
3346 cifs_dbg(FYI
, "In Windows reparse style QueryLink for fid %u\n", fid
);
3347 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
3352 pSMB
->TotalParameterCount
= 0 ;
3353 pSMB
->TotalDataCount
= 0;
3354 pSMB
->MaxParameterCount
= cpu_to_le32(2);
3355 /* BB find exact data count max from sess structure BB */
3356 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
3357 pSMB
->MaxSetupCount
= 4;
3359 pSMB
->ParameterOffset
= 0;
3360 pSMB
->DataCount
= 0;
3361 pSMB
->DataOffset
= 0;
3362 pSMB
->SetupCount
= 4;
3363 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
3364 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3365 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
3366 pSMB
->IsFsctl
= 1; /* FSCTL */
3367 pSMB
->IsRootFlag
= 0;
3368 pSMB
->Fid
= fid
; /* file handle always le */
3369 pSMB
->ByteCount
= 0;
3371 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3372 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3374 cifs_dbg(FYI
, "Send error in QueryReparseLinkInfo = %d\n", rc
);
3378 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
3379 data_count
= le32_to_cpu(pSMBr
->DataCount
);
3380 if (get_bcc(&pSMBr
->hdr
) < 2 || data_offset
> 512) {
3381 /* BB also check enough total bytes returned */
3382 rc
= -EIO
; /* bad smb */
3385 if (!data_count
|| (data_count
> 2048)) {
3387 cifs_dbg(FYI
, "Invalid return data count on get reparse info ioctl\n");
3390 end_of_smb
= 2 + get_bcc(&pSMBr
->hdr
) + (char *)&pSMBr
->ByteCount
;
3391 reparse_buf
= (struct reparse_symlink_data
*)
3392 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
3393 if ((char *)reparse_buf
>= end_of_smb
) {
3397 if (reparse_buf
->ReparseTag
== cpu_to_le32(IO_REPARSE_TAG_NFS
)) {
3398 cifs_dbg(FYI
, "NFS style reparse tag\n");
3399 posix_buf
= (struct reparse_posix_data
*)reparse_buf
;
3401 if (posix_buf
->InodeType
!= cpu_to_le64(NFS_SPECFILE_LNK
)) {
3402 cifs_dbg(FYI
, "unsupported file type 0x%llx\n",
3403 le64_to_cpu(posix_buf
->InodeType
));
3408 sub_len
= le16_to_cpu(reparse_buf
->ReparseDataLength
);
3409 if (posix_buf
->PathBuffer
+ sub_len
> end_of_smb
) {
3410 cifs_dbg(FYI
, "reparse buf beyond SMB\n");
3414 *symlinkinfo
= cifs_strndup_from_utf16(posix_buf
->PathBuffer
,
3415 sub_len
, is_unicode
, nls_codepage
);
3417 } else if (reparse_buf
->ReparseTag
!=
3418 cpu_to_le32(IO_REPARSE_TAG_SYMLINK
)) {
3423 /* Reparse tag is NTFS symlink */
3424 sub_start
= le16_to_cpu(reparse_buf
->SubstituteNameOffset
) +
3425 reparse_buf
->PathBuffer
;
3426 sub_len
= le16_to_cpu(reparse_buf
->SubstituteNameLength
);
3427 if (sub_start
+ sub_len
> end_of_smb
) {
3428 cifs_dbg(FYI
, "reparse buf beyond SMB\n");
3432 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3437 /* BB FIXME investigate remapping reserved chars here */
3438 *symlinkinfo
= cifs_strndup_from_utf16(sub_start
, sub_len
, is_unicode
,
3443 cifs_buf_release(pSMB
);
3446 * Note: On -EAGAIN error only caller can retry on handle based calls
3447 * since file handle passed in no longer valid.
3453 CIFSSMB_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
3458 struct smb_com_transaction_compr_ioctl_req
*pSMB
;
3459 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
3461 cifs_dbg(FYI
, "Set compression for %u\n", fid
);
3462 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
3467 pSMB
->compression_state
= cpu_to_le16(COMPRESSION_FORMAT_DEFAULT
);
3469 pSMB
->TotalParameterCount
= 0;
3470 pSMB
->TotalDataCount
= cpu_to_le32(2);
3471 pSMB
->MaxParameterCount
= 0;
3472 pSMB
->MaxDataCount
= 0;
3473 pSMB
->MaxSetupCount
= 4;
3475 pSMB
->ParameterOffset
= 0;
3476 pSMB
->DataCount
= cpu_to_le32(2);
3478 cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req
,
3479 compression_state
) - 4); /* 84 */
3480 pSMB
->SetupCount
= 4;
3481 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
3482 pSMB
->ParameterCount
= 0;
3483 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_SET_COMPRESSION
);
3484 pSMB
->IsFsctl
= 1; /* FSCTL */
3485 pSMB
->IsRootFlag
= 0;
3486 pSMB
->Fid
= fid
; /* file handle always le */
3487 /* 3 byte pad, followed by 2 byte compress state */
3488 pSMB
->ByteCount
= cpu_to_le16(5);
3489 inc_rfc1001_len(pSMB
, 5);
3491 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3492 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3494 cifs_dbg(FYI
, "Send error in SetCompression = %d\n", rc
);
3496 cifs_buf_release(pSMB
);
3499 * Note: On -EAGAIN error only caller can retry on handle based calls
3500 * since file handle passed in no longer valid.
3506 #ifdef CONFIG_CIFS_POSIX
3508 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
3509 static void cifs_convert_ace(struct posix_acl_xattr_entry
*ace
,
3510 struct cifs_posix_ace
*cifs_ace
)
3512 /* u8 cifs fields do not need le conversion */
3513 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
3514 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
3515 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
3517 cifs_dbg(FYI, "perm %d tag %d id %d\n",
3518 ace->e_perm, ace->e_tag, ace->e_id);
3524 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
3525 static int cifs_copy_posix_acl(char *trgt
, char *src
, const int buflen
,
3526 const int acl_type
, const int size_of_data_area
)
3531 struct cifs_posix_ace
*pACE
;
3532 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)src
;
3533 struct posix_acl_xattr_header
*local_acl
= (void *)trgt
;
3535 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
3538 if (acl_type
== ACL_TYPE_ACCESS
) {
3539 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
3540 pACE
= &cifs_acl
->ace_array
[0];
3541 size
= sizeof(struct cifs_posix_acl
);
3542 size
+= sizeof(struct cifs_posix_ace
) * count
;
3543 /* check if we would go beyond end of SMB */
3544 if (size_of_data_area
< size
) {
3545 cifs_dbg(FYI
, "bad CIFS POSIX ACL size %d vs. %d\n",
3546 size_of_data_area
, size
);
3549 } else if (acl_type
== ACL_TYPE_DEFAULT
) {
3550 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
3551 size
= sizeof(struct cifs_posix_acl
);
3552 size
+= sizeof(struct cifs_posix_ace
) * count
;
3553 /* skip past access ACEs to get to default ACEs */
3554 pACE
= &cifs_acl
->ace_array
[count
];
3555 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
3556 size
+= sizeof(struct cifs_posix_ace
) * count
;
3557 /* check if we would go beyond end of SMB */
3558 if (size_of_data_area
< size
)
3565 size
= posix_acl_xattr_size(count
);
3566 if ((buflen
== 0) || (local_acl
== NULL
)) {
3567 /* used to query ACL EA size */
3568 } else if (size
> buflen
) {
3570 } else /* buffer big enough */ {
3571 struct posix_acl_xattr_entry
*ace
= (void *)(local_acl
+ 1);
3573 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
3574 for (i
= 0; i
< count
; i
++) {
3575 cifs_convert_ace(&ace
[i
], pACE
);
3582 static void convert_ace_to_cifs_ace(struct cifs_posix_ace
*cifs_ace
,
3583 const struct posix_acl_xattr_entry
*local_ace
)
3585 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
3586 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
3587 /* BB is there a better way to handle the large uid? */
3588 if (local_ace
->e_id
== cpu_to_le32(-1)) {
3589 /* Probably no need to le convert -1 on any arch but can not hurt */
3590 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
3592 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
3594 cifs_dbg(FYI, "perm %d tag %d id %d\n",
3595 ace->e_perm, ace->e_tag, ace->e_id);
3599 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
3600 static __u16
ACL_to_cifs_posix(char *parm_data
, const char *pACL
,
3601 const int buflen
, const int acl_type
)
3604 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
3605 struct posix_acl_xattr_header
*local_acl
= (void *)pACL
;
3606 struct posix_acl_xattr_entry
*ace
= (void *)(local_acl
+ 1);
3610 if ((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
3613 count
= posix_acl_xattr_count((size_t)buflen
);
3614 cifs_dbg(FYI
, "setting acl with %d entries from buf of length %d and version of %d\n",
3615 count
, buflen
, le32_to_cpu(local_acl
->a_version
));
3616 if (le32_to_cpu(local_acl
->a_version
) != 2) {
3617 cifs_dbg(FYI
, "unknown POSIX ACL version %d\n",
3618 le32_to_cpu(local_acl
->a_version
));
3621 cifs_acl
->version
= cpu_to_le16(1);
3622 if (acl_type
== ACL_TYPE_ACCESS
) {
3623 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
3624 cifs_acl
->default_entry_count
= cpu_to_le16(0xFFFF);
3625 } else if (acl_type
== ACL_TYPE_DEFAULT
) {
3626 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
3627 cifs_acl
->access_entry_count
= cpu_to_le16(0xFFFF);
3629 cifs_dbg(FYI
, "unknown ACL type %d\n", acl_type
);
3632 for (i
= 0; i
< count
; i
++)
3633 convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
], &ace
[i
]);
3635 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
3636 rc
+= sizeof(struct cifs_posix_acl
);
3637 /* BB add check to make sure ACL does not overflow SMB */
3643 CIFSSMBGetPosixACL(const unsigned int xid
, struct cifs_tcon
*tcon
,
3644 const unsigned char *searchName
,
3645 char *acl_inf
, const int buflen
, const int acl_type
,
3646 const struct nls_table
*nls_codepage
, int remap
)
3648 /* SMB_QUERY_POSIX_ACL */
3649 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3650 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3654 __u16 params
, byte_count
;
3656 cifs_dbg(FYI
, "In GetPosixACL (Unix) for path %s\n", searchName
);
3659 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3664 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3666 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
3667 searchName
, PATH_MAX
, nls_codepage
,
3669 name_len
++; /* trailing null */
3671 pSMB
->FileName
[name_len
] = 0;
3672 pSMB
->FileName
[name_len
+1] = 0;
3674 name_len
= copy_path_name(pSMB
->FileName
, searchName
);
3677 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3678 pSMB
->TotalDataCount
= 0;
3679 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3680 /* BB find exact max data count below from sess structure BB */
3681 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3682 pSMB
->MaxSetupCount
= 0;
3686 pSMB
->Reserved2
= 0;
3687 pSMB
->ParameterOffset
= cpu_to_le16(
3688 offsetof(struct smb_com_transaction2_qpi_req
,
3689 InformationLevel
) - 4);
3690 pSMB
->DataCount
= 0;
3691 pSMB
->DataOffset
= 0;
3692 pSMB
->SetupCount
= 1;
3693 pSMB
->Reserved3
= 0;
3694 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3695 byte_count
= params
+ 1 /* pad */ ;
3696 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3697 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3698 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
3699 pSMB
->Reserved4
= 0;
3700 inc_rfc1001_len(pSMB
, byte_count
);
3701 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3703 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3704 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3705 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_acl_get
);
3707 cifs_dbg(FYI
, "Send error in Query POSIX ACL = %d\n", rc
);
3709 /* decode response */
3711 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3712 /* BB also check enough total bytes returned */
3713 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3714 rc
= -EIO
; /* bad smb */
3716 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3717 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3718 rc
= cifs_copy_posix_acl(acl_inf
,
3719 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
3720 buflen
, acl_type
, count
);
3723 cifs_buf_release(pSMB
);
3730 CIFSSMBSetPosixACL(const unsigned int xid
, struct cifs_tcon
*tcon
,
3731 const unsigned char *fileName
,
3732 const char *local_acl
, const int buflen
,
3734 const struct nls_table
*nls_codepage
, int remap
)
3736 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
3737 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
3741 int bytes_returned
= 0;
3742 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
3744 cifs_dbg(FYI
, "In SetPosixACL (Unix) for path %s\n", fileName
);
3746 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3750 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3752 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
3753 PATH_MAX
, nls_codepage
, remap
);
3754 name_len
++; /* trailing null */
3757 name_len
= copy_path_name(pSMB
->FileName
, fileName
);
3759 params
= 6 + name_len
;
3760 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3761 /* BB find max SMB size from sess */
3762 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3763 pSMB
->MaxSetupCount
= 0;
3767 pSMB
->Reserved2
= 0;
3768 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
3769 InformationLevel
) - 4;
3770 offset
= param_offset
+ params
;
3771 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
3772 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3774 /* convert to on the wire format for POSIX ACL */
3775 data_count
= ACL_to_cifs_posix(parm_data
, local_acl
, buflen
, acl_type
);
3777 if (data_count
== 0) {
3779 goto setACLerrorExit
;
3781 pSMB
->DataOffset
= cpu_to_le16(offset
);
3782 pSMB
->SetupCount
= 1;
3783 pSMB
->Reserved3
= 0;
3784 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
3785 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
3786 byte_count
= 3 /* pad */ + params
+ data_count
;
3787 pSMB
->DataCount
= cpu_to_le16(data_count
);
3788 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3789 pSMB
->ParameterCount
= cpu_to_le16(params
);
3790 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3791 pSMB
->Reserved4
= 0;
3792 inc_rfc1001_len(pSMB
, byte_count
);
3793 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3794 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3795 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3797 cifs_dbg(FYI
, "Set POSIX ACL returned %d\n", rc
);
3800 cifs_buf_release(pSMB
);
3806 /* BB fix tabs in this function FIXME BB */
3808 CIFSGetExtAttr(const unsigned int xid
, struct cifs_tcon
*tcon
,
3809 const int netfid
, __u64
*pExtAttrBits
, __u64
*pMask
)
3812 struct smb_t2_qfi_req
*pSMB
= NULL
;
3813 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
3815 __u16 params
, byte_count
;
3817 cifs_dbg(FYI
, "In GetExtAttr\n");
3822 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3827 params
= 2 /* level */ + 2 /* fid */;
3828 pSMB
->t2
.TotalDataCount
= 0;
3829 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
3830 /* BB find exact max data count below from sess structure BB */
3831 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
3832 pSMB
->t2
.MaxSetupCount
= 0;
3833 pSMB
->t2
.Reserved
= 0;
3835 pSMB
->t2
.Timeout
= 0;
3836 pSMB
->t2
.Reserved2
= 0;
3837 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
3839 pSMB
->t2
.DataCount
= 0;
3840 pSMB
->t2
.DataOffset
= 0;
3841 pSMB
->t2
.SetupCount
= 1;
3842 pSMB
->t2
.Reserved3
= 0;
3843 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
3844 byte_count
= params
+ 1 /* pad */ ;
3845 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
3846 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
3847 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
3850 inc_rfc1001_len(pSMB
, byte_count
);
3851 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
3853 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3854 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3856 cifs_dbg(FYI
, "error %d in GetExtAttr\n", rc
);
3858 /* decode response */
3859 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3860 /* BB also check enough total bytes returned */
3861 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3862 /* If rc should we check for EOPNOSUPP and
3863 disable the srvino flag? or in caller? */
3864 rc
= -EIO
; /* bad smb */
3866 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3867 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3868 struct file_chattr_info
*pfinfo
;
3869 /* BB Do we need a cast or hash here ? */
3871 cifs_dbg(FYI
, "Illegal size ret in GetExtAttr\n");
3875 pfinfo
= (struct file_chattr_info
*)
3876 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3877 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
3878 *pMask
= le64_to_cpu(pfinfo
->mask
);
3882 cifs_buf_release(pSMB
);
3884 goto GetExtAttrRetry
;
3888 #endif /* CONFIG_POSIX */
3891 * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that
3892 * all NT TRANSACTS that we init here have total parm and data under about 400
3893 * bytes (to fit in small cifs buffer size), which is the case so far, it
3894 * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of
3895 * returned setup area) and MaxParameterCount (returned parms size) must be set
3899 smb_init_nttransact(const __u16 sub_command
, const int setup_count
,
3900 const int parm_len
, struct cifs_tcon
*tcon
,
3905 struct smb_com_ntransact_req
*pSMB
;
3907 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
3911 *ret_buf
= (void *)pSMB
;
3913 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
3914 pSMB
->TotalDataCount
= 0;
3915 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
3916 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3917 pSMB
->DataCount
= pSMB
->TotalDataCount
;
3918 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
3919 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
3920 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
3921 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
3922 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
3923 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
3928 validate_ntransact(char *buf
, char **ppparm
, char **ppdata
,
3929 __u32
*pparmlen
, __u32
*pdatalen
)
3932 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
3933 struct smb_com_ntransact_rsp
*pSMBr
;
3942 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
3944 bcc
= get_bcc(&pSMBr
->hdr
);
3945 end_of_smb
= 2 /* sizeof byte count */ + bcc
+
3946 (char *)&pSMBr
->ByteCount
;
3948 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
3949 data_count
= le32_to_cpu(pSMBr
->DataCount
);
3950 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
3951 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
3953 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
3954 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
3956 /* should we also check that parm and data areas do not overlap? */
3957 if (*ppparm
> end_of_smb
) {
3958 cifs_dbg(FYI
, "parms start after end of smb\n");
3960 } else if (parm_count
+ *ppparm
> end_of_smb
) {
3961 cifs_dbg(FYI
, "parm end after end of smb\n");
3963 } else if (*ppdata
> end_of_smb
) {
3964 cifs_dbg(FYI
, "data starts after end of smb\n");
3966 } else if (data_count
+ *ppdata
> end_of_smb
) {
3967 cifs_dbg(FYI
, "data %p + count %d (%p) past smb end %p start %p\n",
3968 *ppdata
, data_count
, (data_count
+ *ppdata
),
3971 } else if (parm_count
+ data_count
> bcc
) {
3972 cifs_dbg(FYI
, "parm count and data count larger than SMB\n");
3975 *pdatalen
= data_count
;
3976 *pparmlen
= parm_count
;
3980 /* Get Security Descriptor (by handle) from remote server for a file or dir */
3982 CIFSSMBGetCIFSACL(const unsigned int xid
, struct cifs_tcon
*tcon
, __u16 fid
,
3983 struct cifs_ntsd
**acl_inf
, __u32
*pbuflen
)
3987 QUERY_SEC_DESC_REQ
*pSMB
;
3989 struct kvec rsp_iov
;
3991 cifs_dbg(FYI
, "GetCifsACL\n");
3996 rc
= smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
3997 8 /* parm len */, tcon
, (void **) &pSMB
);
4001 pSMB
->MaxParameterCount
= cpu_to_le32(4);
4002 /* BB TEST with big acls that might need to be e.g. larger than 16K */
4003 pSMB
->MaxSetupCount
= 0;
4004 pSMB
->Fid
= fid
; /* file handle always le */
4005 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
4007 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
4008 inc_rfc1001_len(pSMB
, 11);
4009 iov
[0].iov_base
= (char *)pSMB
;
4010 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
4012 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
,
4014 cifs_small_buf_release(pSMB
);
4015 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_acl_get
);
4017 cifs_dbg(FYI
, "Send error in QuerySecDesc = %d\n", rc
);
4018 } else { /* decode response */
4022 struct smb_com_ntransact_rsp
*pSMBr
;
4025 /* validate_nttransact */
4026 rc
= validate_ntransact(rsp_iov
.iov_base
, (char **)&parm
,
4027 &pdata
, &parm_len
, pbuflen
);
4030 pSMBr
= (struct smb_com_ntransact_rsp
*)rsp_iov
.iov_base
;
4032 cifs_dbg(FYI
, "smb %p parm %p data %p\n",
4033 pSMBr
, parm
, *acl_inf
);
4035 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
4036 rc
= -EIO
; /* bad smb */
4041 /* BB check that data area is minimum length and as big as acl_len */
4043 acl_len
= le32_to_cpu(*parm
);
4044 if (acl_len
!= *pbuflen
) {
4045 cifs_dbg(VFS
, "acl length %d does not match %d\n",
4047 if (*pbuflen
> acl_len
)
4051 /* check if buffer is big enough for the acl
4052 header followed by the smallest SID */
4053 if ((*pbuflen
< sizeof(struct cifs_ntsd
) + 8) ||
4054 (*pbuflen
>= 64 * 1024)) {
4055 cifs_dbg(VFS
, "bad acl length %d\n", *pbuflen
);
4059 *acl_inf
= kmemdup(pdata
, *pbuflen
, GFP_KERNEL
);
4060 if (*acl_inf
== NULL
) {
4067 free_rsp_buf(buf_type
, rsp_iov
.iov_base
);
4072 CIFSSMBSetCIFSACL(const unsigned int xid
, struct cifs_tcon
*tcon
, __u16 fid
,
4073 struct cifs_ntsd
*pntsd
, __u32 acllen
, int aclflag
)
4075 __u16 byte_count
, param_count
, data_count
, param_offset
, data_offset
;
4077 int bytes_returned
= 0;
4078 SET_SEC_DESC_REQ
*pSMB
= NULL
;
4082 rc
= smb_init(SMB_COM_NT_TRANSACT
, 19, tcon
, (void **) &pSMB
, &pSMBr
);
4086 pSMB
->MaxSetupCount
= 0;
4090 param_offset
= offsetof(struct smb_com_transaction_ssec_req
, Fid
) - 4;
4091 data_count
= acllen
;
4092 data_offset
= param_offset
+ param_count
;
4093 byte_count
= 3 /* pad */ + param_count
;
4095 pSMB
->DataCount
= cpu_to_le32(data_count
);
4096 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4097 pSMB
->MaxParameterCount
= cpu_to_le32(4);
4098 pSMB
->MaxDataCount
= cpu_to_le32(16384);
4099 pSMB
->ParameterCount
= cpu_to_le32(param_count
);
4100 pSMB
->ParameterOffset
= cpu_to_le32(param_offset
);
4101 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4102 pSMB
->DataOffset
= cpu_to_le32(data_offset
);
4103 pSMB
->SetupCount
= 0;
4104 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC
);
4105 pSMB
->ByteCount
= cpu_to_le16(byte_count
+data_count
);
4107 pSMB
->Fid
= fid
; /* file handle always le */
4108 pSMB
->Reserved2
= 0;
4109 pSMB
->AclFlags
= cpu_to_le32(aclflag
);
4111 if (pntsd
&& acllen
) {
4112 memcpy((char *)pSMBr
+ offsetof(struct smb_hdr
, Protocol
) +
4113 data_offset
, pntsd
, acllen
);
4114 inc_rfc1001_len(pSMB
, byte_count
+ data_count
);
4116 inc_rfc1001_len(pSMB
, byte_count
);
4118 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4119 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4121 cifs_dbg(FYI
, "SetCIFSACL bytes_returned: %d, rc: %d\n",
4122 bytes_returned
, rc
);
4124 cifs_dbg(FYI
, "Set CIFS ACL returned %d\n", rc
);
4125 cifs_buf_release(pSMB
);
4128 goto setCifsAclRetry
;
4134 /* Legacy Query Path Information call for lookup to old servers such
4137 SMBQueryInformation(const unsigned int xid
, struct cifs_tcon
*tcon
,
4138 const char *search_name
, FILE_ALL_INFO
*data
,
4139 const struct nls_table
*nls_codepage
, int remap
)
4141 QUERY_INFORMATION_REQ
*pSMB
;
4142 QUERY_INFORMATION_RSP
*pSMBr
;
4147 cifs_dbg(FYI
, "In SMBQPath path %s\n", search_name
);
4149 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
4154 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4156 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
4157 search_name
, PATH_MAX
, nls_codepage
,
4159 name_len
++; /* trailing null */
4162 name_len
= copy_path_name(pSMB
->FileName
, search_name
);
4164 pSMB
->BufferFormat
= 0x04;
4165 name_len
++; /* account for buffer type byte */
4166 inc_rfc1001_len(pSMB
, (__u16
)name_len
);
4167 pSMB
->ByteCount
= cpu_to_le16(name_len
);
4169 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4170 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4172 cifs_dbg(FYI
, "Send error in QueryInfo = %d\n", rc
);
4174 struct timespec64 ts
;
4175 __u32 time
= le32_to_cpu(pSMBr
->last_write_time
);
4177 /* decode response */
4178 /* BB FIXME - add time zone adjustment BB */
4179 memset(data
, 0, sizeof(FILE_ALL_INFO
));
4182 /* decode time fields */
4183 data
->ChangeTime
= cpu_to_le64(cifs_UnixTimeToNT(ts
));
4184 data
->LastWriteTime
= data
->ChangeTime
;
4185 data
->LastAccessTime
= 0;
4186 data
->AllocationSize
=
4187 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
4188 data
->EndOfFile
= data
->AllocationSize
;
4190 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
4192 rc
= -EIO
; /* bad buffer passed in */
4194 cifs_buf_release(pSMB
);
4203 CIFSSMBQFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4204 u16 netfid
, FILE_ALL_INFO
*pFindData
)
4206 struct smb_t2_qfi_req
*pSMB
= NULL
;
4207 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
4210 __u16 params
, byte_count
;
4213 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4218 params
= 2 /* level */ + 2 /* fid */;
4219 pSMB
->t2
.TotalDataCount
= 0;
4220 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
4221 /* BB find exact max data count below from sess structure BB */
4222 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
4223 pSMB
->t2
.MaxSetupCount
= 0;
4224 pSMB
->t2
.Reserved
= 0;
4226 pSMB
->t2
.Timeout
= 0;
4227 pSMB
->t2
.Reserved2
= 0;
4228 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
4230 pSMB
->t2
.DataCount
= 0;
4231 pSMB
->t2
.DataOffset
= 0;
4232 pSMB
->t2
.SetupCount
= 1;
4233 pSMB
->t2
.Reserved3
= 0;
4234 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
4235 byte_count
= params
+ 1 /* pad */ ;
4236 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
4237 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
4238 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
4241 inc_rfc1001_len(pSMB
, byte_count
);
4242 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
4244 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4245 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4247 cifs_dbg(FYI
, "Send error in QFileInfo = %d", rc
);
4248 } else { /* decode response */
4249 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4251 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
4253 else if (get_bcc(&pSMBr
->hdr
) < 40)
4254 rc
= -EIO
; /* bad smb */
4255 else if (pFindData
) {
4256 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4257 memcpy((char *) pFindData
,
4258 (char *) &pSMBr
->hdr
.Protocol
+
4259 data_offset
, sizeof(FILE_ALL_INFO
));
4263 cifs_buf_release(pSMB
);
4265 goto QFileInfoRetry
;
4271 CIFSSMBQPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4272 const char *search_name
, FILE_ALL_INFO
*data
,
4273 int legacy
/* old style infolevel */,
4274 const struct nls_table
*nls_codepage
, int remap
)
4276 /* level 263 SMB_QUERY_FILE_ALL_INFO */
4277 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4278 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4282 __u16 params
, byte_count
;
4284 /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */
4286 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4291 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4293 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, search_name
,
4294 PATH_MAX
, nls_codepage
, remap
);
4295 name_len
++; /* trailing null */
4298 name_len
= copy_path_name(pSMB
->FileName
, search_name
);
4301 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
4302 pSMB
->TotalDataCount
= 0;
4303 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4304 /* BB find exact max SMB PDU from sess structure BB */
4305 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4306 pSMB
->MaxSetupCount
= 0;
4310 pSMB
->Reserved2
= 0;
4311 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4312 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4313 pSMB
->DataCount
= 0;
4314 pSMB
->DataOffset
= 0;
4315 pSMB
->SetupCount
= 1;
4316 pSMB
->Reserved3
= 0;
4317 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4318 byte_count
= params
+ 1 /* pad */ ;
4319 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4320 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4322 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_STANDARD
);
4324 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
4325 pSMB
->Reserved4
= 0;
4326 inc_rfc1001_len(pSMB
, byte_count
);
4327 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4329 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4330 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4332 cifs_dbg(FYI
, "Send error in QPathInfo = %d\n", rc
);
4333 } else { /* decode response */
4334 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4336 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
4338 else if (!legacy
&& get_bcc(&pSMBr
->hdr
) < 40)
4339 rc
= -EIO
; /* bad smb */
4340 else if (legacy
&& get_bcc(&pSMBr
->hdr
) < 24)
4341 rc
= -EIO
; /* 24 or 26 expected but we do not read
4345 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4348 * On legacy responses we do not read the last field,
4349 * EAsize, fortunately since it varies by subdialect and
4350 * also note it differs on Set vs Get, ie two bytes or 4
4351 * bytes depending but we don't care here.
4354 size
= sizeof(FILE_INFO_STANDARD
);
4356 size
= sizeof(FILE_ALL_INFO
);
4357 memcpy((char *) data
, (char *) &pSMBr
->hdr
.Protocol
+
4362 cifs_buf_release(pSMB
);
4364 goto QPathInfoRetry
;
4370 CIFSSMBUnixQFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4371 u16 netfid
, FILE_UNIX_BASIC_INFO
*pFindData
)
4373 struct smb_t2_qfi_req
*pSMB
= NULL
;
4374 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
4377 __u16 params
, byte_count
;
4380 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4385 params
= 2 /* level */ + 2 /* fid */;
4386 pSMB
->t2
.TotalDataCount
= 0;
4387 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
4388 /* BB find exact max data count below from sess structure BB */
4389 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
4390 pSMB
->t2
.MaxSetupCount
= 0;
4391 pSMB
->t2
.Reserved
= 0;
4393 pSMB
->t2
.Timeout
= 0;
4394 pSMB
->t2
.Reserved2
= 0;
4395 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
4397 pSMB
->t2
.DataCount
= 0;
4398 pSMB
->t2
.DataOffset
= 0;
4399 pSMB
->t2
.SetupCount
= 1;
4400 pSMB
->t2
.Reserved3
= 0;
4401 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
4402 byte_count
= params
+ 1 /* pad */ ;
4403 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
4404 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
4405 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
4408 inc_rfc1001_len(pSMB
, byte_count
);
4409 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
4411 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4412 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4414 cifs_dbg(FYI
, "Send error in UnixQFileInfo = %d", rc
);
4415 } else { /* decode response */
4416 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4418 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(FILE_UNIX_BASIC_INFO
)) {
4419 cifs_dbg(VFS
, "Malformed FILE_UNIX_BASIC_INFO response. Unix Extensions can be disabled on mount by specifying the nosfu mount option.\n");
4420 rc
= -EIO
; /* bad smb */
4422 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4423 memcpy((char *) pFindData
,
4424 (char *) &pSMBr
->hdr
.Protocol
+
4426 sizeof(FILE_UNIX_BASIC_INFO
));
4430 cifs_buf_release(pSMB
);
4432 goto UnixQFileInfoRetry
;
4438 CIFSSMBUnixQPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4439 const unsigned char *searchName
,
4440 FILE_UNIX_BASIC_INFO
*pFindData
,
4441 const struct nls_table
*nls_codepage
, int remap
)
4443 /* SMB_QUERY_FILE_UNIX_BASIC */
4444 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4445 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4447 int bytes_returned
= 0;
4449 __u16 params
, byte_count
;
4451 cifs_dbg(FYI
, "In QPathInfo (Unix) the path %s\n", searchName
);
4453 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4458 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4460 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4461 PATH_MAX
, nls_codepage
, remap
);
4462 name_len
++; /* trailing null */
4465 name_len
= copy_path_name(pSMB
->FileName
, searchName
);
4468 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
4469 pSMB
->TotalDataCount
= 0;
4470 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4471 /* BB find exact max SMB PDU from sess structure BB */
4472 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4473 pSMB
->MaxSetupCount
= 0;
4477 pSMB
->Reserved2
= 0;
4478 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4479 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4480 pSMB
->DataCount
= 0;
4481 pSMB
->DataOffset
= 0;
4482 pSMB
->SetupCount
= 1;
4483 pSMB
->Reserved3
= 0;
4484 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4485 byte_count
= params
+ 1 /* pad */ ;
4486 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4487 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4488 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
4489 pSMB
->Reserved4
= 0;
4490 inc_rfc1001_len(pSMB
, byte_count
);
4491 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4493 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4494 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4496 cifs_dbg(FYI
, "Send error in UnixQPathInfo = %d", rc
);
4497 } else { /* decode response */
4498 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4500 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(FILE_UNIX_BASIC_INFO
)) {
4501 cifs_dbg(VFS
, "Malformed FILE_UNIX_BASIC_INFO response. Unix Extensions can be disabled on mount by specifying the nosfu mount option.\n");
4502 rc
= -EIO
; /* bad smb */
4504 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4505 memcpy((char *) pFindData
,
4506 (char *) &pSMBr
->hdr
.Protocol
+
4508 sizeof(FILE_UNIX_BASIC_INFO
));
4511 cifs_buf_release(pSMB
);
4513 goto UnixQPathInfoRetry
;
4518 /* xid, tcon, searchName and codepage are input parms, rest are returned */
4520 CIFSFindFirst(const unsigned int xid
, struct cifs_tcon
*tcon
,
4521 const char *searchName
, struct cifs_sb_info
*cifs_sb
,
4522 __u16
*pnetfid
, __u16 search_flags
,
4523 struct cifs_search_info
*psrch_inf
, bool msearch
)
4525 /* level 257 SMB_ */
4526 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
4527 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
4528 T2_FFIRST_RSP_PARMS
*parms
;
4530 int bytes_returned
= 0;
4531 int name_len
, remap
;
4532 __u16 params
, byte_count
;
4533 struct nls_table
*nls_codepage
;
4535 cifs_dbg(FYI
, "In FindFirst for %s\n", searchName
);
4538 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4543 nls_codepage
= cifs_sb
->local_nls
;
4544 remap
= cifs_remap(cifs_sb
);
4546 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4548 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4549 PATH_MAX
, nls_codepage
, remap
);
4550 /* We can not add the asterik earlier in case
4551 it got remapped to 0xF03A as if it were part of the
4552 directory name instead of a wildcard */
4555 pSMB
->FileName
[name_len
] = CIFS_DIR_SEP(cifs_sb
);
4556 pSMB
->FileName
[name_len
+1] = 0;
4557 pSMB
->FileName
[name_len
+2] = '*';
4558 pSMB
->FileName
[name_len
+3] = 0;
4559 name_len
+= 4; /* now the trailing null */
4560 /* null terminate just in case */
4561 pSMB
->FileName
[name_len
] = 0;
4562 pSMB
->FileName
[name_len
+1] = 0;
4566 name_len
= copy_path_name(pSMB
->FileName
, searchName
);
4568 if (WARN_ON_ONCE(name_len
> PATH_MAX
-2))
4569 name_len
= PATH_MAX
-2;
4570 /* overwrite nul byte */
4571 pSMB
->FileName
[name_len
-1] = CIFS_DIR_SEP(cifs_sb
);
4572 pSMB
->FileName
[name_len
] = '*';
4573 pSMB
->FileName
[name_len
+1] = 0;
4578 params
= 12 + name_len
/* includes null */ ;
4579 pSMB
->TotalDataCount
= 0; /* no EAs */
4580 pSMB
->MaxParameterCount
= cpu_to_le16(10);
4581 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
& 0xFFFFFF00);
4582 pSMB
->MaxSetupCount
= 0;
4586 pSMB
->Reserved2
= 0;
4587 byte_count
= params
+ 1 /* pad */ ;
4588 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4589 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4590 pSMB
->ParameterOffset
= cpu_to_le16(
4591 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
)
4593 pSMB
->DataCount
= 0;
4594 pSMB
->DataOffset
= 0;
4595 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
4596 pSMB
->Reserved3
= 0;
4597 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
4598 pSMB
->SearchAttributes
=
4599 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
4601 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
4602 pSMB
->SearchFlags
= cpu_to_le16(search_flags
);
4603 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
4605 /* BB what should we set StorageType to? Does it matter? BB */
4606 pSMB
->SearchStorageType
= 0;
4607 inc_rfc1001_len(pSMB
, byte_count
);
4608 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4610 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4611 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4612 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_ffirst
);
4614 if (rc
) {/* BB add logic to retry regular search if Unix search
4615 rejected unexpectedly by server */
4616 /* BB Add code to handle unsupported level rc */
4617 cifs_dbg(FYI
, "Error in FindFirst = %d\n", rc
);
4619 cifs_buf_release(pSMB
);
4621 /* BB eventually could optimize out free and realloc of buf */
4624 goto findFirstRetry
;
4625 } else { /* decode response */
4626 /* BB remember to free buffer if error BB */
4627 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4631 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4632 psrch_inf
->unicode
= true;
4634 psrch_inf
->unicode
= false;
4636 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
4637 psrch_inf
->smallBuf
= false;
4638 psrch_inf
->srch_entries_start
=
4639 (char *) &pSMBr
->hdr
.Protocol
+
4640 le16_to_cpu(pSMBr
->t2
.DataOffset
);
4641 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
4642 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
4644 if (parms
->EndofSearch
)
4645 psrch_inf
->endOfSearch
= true;
4647 psrch_inf
->endOfSearch
= false;
4649 psrch_inf
->entries_in_buffer
=
4650 le16_to_cpu(parms
->SearchCount
);
4651 psrch_inf
->index_of_last_entry
= 2 /* skip . and .. */ +
4652 psrch_inf
->entries_in_buffer
;
4653 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
4654 if (CIFSMaxBufSize
< lnoff
) {
4655 cifs_dbg(VFS
, "ignoring corrupt resume name\n");
4656 psrch_inf
->last_entry
= NULL
;
4660 psrch_inf
->last_entry
= psrch_inf
->srch_entries_start
+
4664 *pnetfid
= parms
->SearchHandle
;
4666 cifs_buf_release(pSMB
);
4673 int CIFSFindNext(const unsigned int xid
, struct cifs_tcon
*tcon
,
4674 __u16 searchHandle
, __u16 search_flags
,
4675 struct cifs_search_info
*psrch_inf
)
4677 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
4678 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
4679 T2_FNEXT_RSP_PARMS
*parms
;
4680 char *response_data
;
4683 unsigned int name_len
;
4684 __u16 params
, byte_count
;
4686 cifs_dbg(FYI
, "In FindNext\n");
4688 if (psrch_inf
->endOfSearch
)
4691 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4696 params
= 14; /* includes 2 bytes of null string, converted to LE below*/
4698 pSMB
->TotalDataCount
= 0; /* no EAs */
4699 pSMB
->MaxParameterCount
= cpu_to_le16(8);
4700 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
& 0xFFFFFF00);
4701 pSMB
->MaxSetupCount
= 0;
4705 pSMB
->Reserved2
= 0;
4706 pSMB
->ParameterOffset
= cpu_to_le16(
4707 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
4708 pSMB
->DataCount
= 0;
4709 pSMB
->DataOffset
= 0;
4710 pSMB
->SetupCount
= 1;
4711 pSMB
->Reserved3
= 0;
4712 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
4713 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
4715 cpu_to_le16(CIFSMaxBufSize
/ sizeof(FILE_UNIX_INFO
));
4716 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
4717 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
4718 pSMB
->SearchFlags
= cpu_to_le16(search_flags
);
4720 name_len
= psrch_inf
->resume_name_len
;
4722 if (name_len
< PATH_MAX
) {
4723 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
4724 byte_count
+= name_len
;
4725 /* 14 byte parm len above enough for 2 byte null terminator */
4726 pSMB
->ResumeFileName
[name_len
] = 0;
4727 pSMB
->ResumeFileName
[name_len
+1] = 0;
4730 goto FNext2_err_exit
;
4732 byte_count
= params
+ 1 /* pad */ ;
4733 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4734 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4735 inc_rfc1001_len(pSMB
, byte_count
);
4736 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4738 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4739 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4740 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_fnext
);
4743 psrch_inf
->endOfSearch
= true;
4744 cifs_buf_release(pSMB
);
4745 rc
= 0; /* search probably was closed at end of search*/
4747 cifs_dbg(FYI
, "FindNext returned = %d\n", rc
);
4748 } else { /* decode response */
4749 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4754 /* BB fixme add lock for file (srch_info) struct here */
4755 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4756 psrch_inf
->unicode
= true;
4758 psrch_inf
->unicode
= false;
4759 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
4760 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
4761 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
4762 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
4763 le16_to_cpu(pSMBr
->t2
.DataOffset
);
4764 if (psrch_inf
->smallBuf
)
4765 cifs_small_buf_release(
4766 psrch_inf
->ntwrk_buf_start
);
4768 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
4769 psrch_inf
->srch_entries_start
= response_data
;
4770 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
4771 psrch_inf
->smallBuf
= false;
4772 if (parms
->EndofSearch
)
4773 psrch_inf
->endOfSearch
= true;
4775 psrch_inf
->endOfSearch
= false;
4776 psrch_inf
->entries_in_buffer
=
4777 le16_to_cpu(parms
->SearchCount
);
4778 psrch_inf
->index_of_last_entry
+=
4779 psrch_inf
->entries_in_buffer
;
4780 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
4781 if (CIFSMaxBufSize
< lnoff
) {
4782 cifs_dbg(VFS
, "ignoring corrupt resume name\n");
4783 psrch_inf
->last_entry
= NULL
;
4786 psrch_inf
->last_entry
=
4787 psrch_inf
->srch_entries_start
+ lnoff
;
4789 /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n",
4790 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */
4792 /* BB fixme add unlock here */
4797 /* BB On error, should we leave previous search buf (and count and
4798 last entry fields) intact or free the previous one? */
4800 /* Note: On -EAGAIN error only caller can retry on handle based calls
4801 since file handle passed in no longer valid */
4804 cifs_buf_release(pSMB
);
4809 CIFSFindClose(const unsigned int xid
, struct cifs_tcon
*tcon
,
4810 const __u16 searchHandle
)
4813 FINDCLOSE_REQ
*pSMB
= NULL
;
4815 cifs_dbg(FYI
, "In CIFSSMBFindClose\n");
4816 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
4818 /* no sense returning error if session restarted
4819 as file handle has been closed */
4825 pSMB
->FileID
= searchHandle
;
4826 pSMB
->ByteCount
= 0;
4827 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
4828 cifs_small_buf_release(pSMB
);
4830 cifs_dbg(VFS
, "Send error in FindClose = %d\n", rc
);
4832 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_fclose
);
4834 /* Since session is dead, search handle closed on server already */
4842 CIFSGetSrvInodeNumber(const unsigned int xid
, struct cifs_tcon
*tcon
,
4843 const char *search_name
, __u64
*inode_number
,
4844 const struct nls_table
*nls_codepage
, int remap
)
4847 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4848 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4849 int name_len
, bytes_returned
;
4850 __u16 params
, byte_count
;
4852 cifs_dbg(FYI
, "In GetSrvInodeNum for %s\n", search_name
);
4856 GetInodeNumberRetry
:
4857 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4862 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4864 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
4865 search_name
, PATH_MAX
, nls_codepage
,
4867 name_len
++; /* trailing null */
4870 name_len
= copy_path_name(pSMB
->FileName
, search_name
);
4873 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
4874 pSMB
->TotalDataCount
= 0;
4875 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4876 /* BB find exact max data count below from sess structure BB */
4877 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4878 pSMB
->MaxSetupCount
= 0;
4882 pSMB
->Reserved2
= 0;
4883 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4884 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4885 pSMB
->DataCount
= 0;
4886 pSMB
->DataOffset
= 0;
4887 pSMB
->SetupCount
= 1;
4888 pSMB
->Reserved3
= 0;
4889 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4890 byte_count
= params
+ 1 /* pad */ ;
4891 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4892 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4893 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
4894 pSMB
->Reserved4
= 0;
4895 inc_rfc1001_len(pSMB
, byte_count
);
4896 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4898 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4899 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4901 cifs_dbg(FYI
, "error %d in QueryInternalInfo\n", rc
);
4903 /* decode response */
4904 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4905 /* BB also check enough total bytes returned */
4906 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
4907 /* If rc should we check for EOPNOSUPP and
4908 disable the srvino flag? or in caller? */
4909 rc
= -EIO
; /* bad smb */
4911 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4912 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
4913 struct file_internal_info
*pfinfo
;
4914 /* BB Do we need a cast or hash here ? */
4916 cifs_dbg(FYI
, "Illegal size ret in QryIntrnlInf\n");
4918 goto GetInodeNumOut
;
4920 pfinfo
= (struct file_internal_info
*)
4921 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
4922 *inode_number
= le64_to_cpu(pfinfo
->UniqueId
);
4926 cifs_buf_release(pSMB
);
4928 goto GetInodeNumberRetry
;
4933 CIFSGetDFSRefer(const unsigned int xid
, struct cifs_ses
*ses
,
4934 const char *search_name
, struct dfs_info3_param
**target_nodes
,
4935 unsigned int *num_of_nodes
,
4936 const struct nls_table
*nls_codepage
, int remap
)
4938 /* TRANS2_GET_DFS_REFERRAL */
4939 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
4940 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
4944 __u16 params
, byte_count
;
4946 *target_nodes
= NULL
;
4948 cifs_dbg(FYI
, "In GetDFSRefer the path %s\n", search_name
);
4949 if (ses
== NULL
|| ses
->tcon_ipc
== NULL
)
4953 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, ses
->tcon_ipc
, (void **) &pSMB
,
4958 /* server pointer checked in called function,
4959 but should never be null here anyway */
4960 pSMB
->hdr
.Mid
= get_next_mid(ses
->server
);
4961 pSMB
->hdr
.Tid
= ses
->tcon_ipc
->tid
;
4962 pSMB
->hdr
.Uid
= ses
->Suid
;
4963 if (ses
->capabilities
& CAP_STATUS32
)
4964 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
4965 if (ses
->capabilities
& CAP_DFS
)
4966 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
4968 if (ses
->capabilities
& CAP_UNICODE
) {
4969 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
4971 cifsConvertToUTF16((__le16
*) pSMB
->RequestFileName
,
4972 search_name
, PATH_MAX
, nls_codepage
,
4974 name_len
++; /* trailing null */
4976 } else { /* BB improve the check for buffer overruns BB */
4977 name_len
= copy_path_name(pSMB
->RequestFileName
, search_name
);
4980 if (ses
->server
->sign
)
4981 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
4983 pSMB
->hdr
.Uid
= ses
->Suid
;
4985 params
= 2 /* level */ + name_len
/*includes null */ ;
4986 pSMB
->TotalDataCount
= 0;
4987 pSMB
->DataCount
= 0;
4988 pSMB
->DataOffset
= 0;
4989 pSMB
->MaxParameterCount
= 0;
4990 /* BB find exact max SMB PDU from sess structure BB */
4991 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4992 pSMB
->MaxSetupCount
= 0;
4996 pSMB
->Reserved2
= 0;
4997 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4998 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
4999 pSMB
->SetupCount
= 1;
5000 pSMB
->Reserved3
= 0;
5001 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
5002 byte_count
= params
+ 3 /* pad */ ;
5003 pSMB
->ParameterCount
= cpu_to_le16(params
);
5004 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5005 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
5006 inc_rfc1001_len(pSMB
, byte_count
);
5007 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5009 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
5010 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5012 cifs_dbg(FYI
, "Send error in GetDFSRefer = %d\n", rc
);
5015 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5017 /* BB Also check if enough total bytes returned? */
5018 if (rc
|| get_bcc(&pSMBr
->hdr
) < 17) {
5019 rc
= -EIO
; /* bad smb */
5023 cifs_dbg(FYI
, "Decoding GetDFSRefer response BCC: %d Offset %d\n",
5024 get_bcc(&pSMBr
->hdr
), le16_to_cpu(pSMBr
->t2
.DataOffset
));
5026 /* parse returned result into more usable form */
5027 rc
= parse_dfs_referrals(&pSMBr
->dfs_data
,
5028 le16_to_cpu(pSMBr
->t2
.DataCount
),
5029 num_of_nodes
, target_nodes
, nls_codepage
,
5031 (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) != 0);
5034 cifs_buf_release(pSMB
);
5042 /* Query File System Info such as free space to old servers such as Win 9x */
5044 SMBOldQFSInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5045 struct kstatfs
*FSData
)
5047 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
5048 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5049 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5050 FILE_SYSTEM_ALLOC_INFO
*response_data
;
5052 int bytes_returned
= 0;
5053 __u16 params
, byte_count
;
5055 cifs_dbg(FYI
, "OldQFSInfo\n");
5057 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5062 params
= 2; /* level */
5063 pSMB
->TotalDataCount
= 0;
5064 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5065 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5066 pSMB
->MaxSetupCount
= 0;
5070 pSMB
->Reserved2
= 0;
5071 byte_count
= params
+ 1 /* pad */ ;
5072 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5073 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5074 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5075 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5076 pSMB
->DataCount
= 0;
5077 pSMB
->DataOffset
= 0;
5078 pSMB
->SetupCount
= 1;
5079 pSMB
->Reserved3
= 0;
5080 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5081 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
5082 inc_rfc1001_len(pSMB
, byte_count
);
5083 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5085 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5086 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5088 cifs_dbg(FYI
, "Send error in QFSInfo = %d\n", rc
);
5089 } else { /* decode response */
5090 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5092 if (rc
|| get_bcc(&pSMBr
->hdr
) < 18)
5093 rc
= -EIO
; /* bad smb */
5095 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5096 cifs_dbg(FYI
, "qfsinf resp BCC: %d Offset %d\n",
5097 get_bcc(&pSMBr
->hdr
), data_offset
);
5099 response_data
= (FILE_SYSTEM_ALLOC_INFO
*)
5100 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
5102 le16_to_cpu(response_data
->BytesPerSector
) *
5103 le32_to_cpu(response_data
->
5104 SectorsPerAllocationUnit
);
5106 * much prefer larger but if server doesn't report
5107 * a valid size than 4K is a reasonable minimum
5109 if (FSData
->f_bsize
< 512)
5110 FSData
->f_bsize
= 4096;
5113 le32_to_cpu(response_data
->TotalAllocationUnits
);
5114 FSData
->f_bfree
= FSData
->f_bavail
=
5115 le32_to_cpu(response_data
->FreeAllocationUnits
);
5116 cifs_dbg(FYI
, "Blocks: %lld Free: %lld Block size %ld\n",
5117 (unsigned long long)FSData
->f_blocks
,
5118 (unsigned long long)FSData
->f_bfree
,
5122 cifs_buf_release(pSMB
);
5125 goto oldQFSInfoRetry
;
5131 CIFSSMBQFSInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5132 struct kstatfs
*FSData
)
5134 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
5135 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5136 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5137 FILE_SYSTEM_INFO
*response_data
;
5139 int bytes_returned
= 0;
5140 __u16 params
, byte_count
;
5142 cifs_dbg(FYI
, "In QFSInfo\n");
5144 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5149 params
= 2; /* level */
5150 pSMB
->TotalDataCount
= 0;
5151 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5152 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5153 pSMB
->MaxSetupCount
= 0;
5157 pSMB
->Reserved2
= 0;
5158 byte_count
= params
+ 1 /* pad */ ;
5159 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5160 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5161 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5162 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5163 pSMB
->DataCount
= 0;
5164 pSMB
->DataOffset
= 0;
5165 pSMB
->SetupCount
= 1;
5166 pSMB
->Reserved3
= 0;
5167 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5168 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
5169 inc_rfc1001_len(pSMB
, byte_count
);
5170 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5172 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5173 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5175 cifs_dbg(FYI
, "Send error in QFSInfo = %d\n", rc
);
5176 } else { /* decode response */
5177 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5179 if (rc
|| get_bcc(&pSMBr
->hdr
) < 24)
5180 rc
= -EIO
; /* bad smb */
5182 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5186 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5189 le32_to_cpu(response_data
->BytesPerSector
) *
5190 le32_to_cpu(response_data
->
5191 SectorsPerAllocationUnit
);
5193 * much prefer larger but if server doesn't report
5194 * a valid size than 4K is a reasonable minimum
5196 if (FSData
->f_bsize
< 512)
5197 FSData
->f_bsize
= 4096;
5200 le64_to_cpu(response_data
->TotalAllocationUnits
);
5201 FSData
->f_bfree
= FSData
->f_bavail
=
5202 le64_to_cpu(response_data
->FreeAllocationUnits
);
5203 cifs_dbg(FYI
, "Blocks: %lld Free: %lld Block size %ld\n",
5204 (unsigned long long)FSData
->f_blocks
,
5205 (unsigned long long)FSData
->f_bfree
,
5209 cifs_buf_release(pSMB
);
5218 CIFSSMBQFSAttributeInfo(const unsigned int xid
, struct cifs_tcon
*tcon
)
5220 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
5221 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5222 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5223 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
5225 int bytes_returned
= 0;
5226 __u16 params
, byte_count
;
5228 cifs_dbg(FYI
, "In QFSAttributeInfo\n");
5230 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5235 params
= 2; /* level */
5236 pSMB
->TotalDataCount
= 0;
5237 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5238 /* BB find exact max SMB PDU from sess structure BB */
5239 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5240 pSMB
->MaxSetupCount
= 0;
5244 pSMB
->Reserved2
= 0;
5245 byte_count
= params
+ 1 /* pad */ ;
5246 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5247 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5248 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5249 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5250 pSMB
->DataCount
= 0;
5251 pSMB
->DataOffset
= 0;
5252 pSMB
->SetupCount
= 1;
5253 pSMB
->Reserved3
= 0;
5254 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5255 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
5256 inc_rfc1001_len(pSMB
, byte_count
);
5257 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5259 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5260 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5262 cifs_dbg(VFS
, "Send error in QFSAttributeInfo = %d\n", rc
);
5263 } else { /* decode response */
5264 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5266 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5267 /* BB also check if enough bytes returned */
5268 rc
= -EIO
; /* bad smb */
5270 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5272 (FILE_SYSTEM_ATTRIBUTE_INFO
5273 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5275 memcpy(&tcon
->fsAttrInfo
, response_data
,
5276 sizeof(FILE_SYSTEM_ATTRIBUTE_INFO
));
5279 cifs_buf_release(pSMB
);
5282 goto QFSAttributeRetry
;
5288 CIFSSMBQFSDeviceInfo(const unsigned int xid
, struct cifs_tcon
*tcon
)
5290 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
5291 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5292 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5293 FILE_SYSTEM_DEVICE_INFO
*response_data
;
5295 int bytes_returned
= 0;
5296 __u16 params
, byte_count
;
5298 cifs_dbg(FYI
, "In QFSDeviceInfo\n");
5300 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5305 params
= 2; /* level */
5306 pSMB
->TotalDataCount
= 0;
5307 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5308 /* BB find exact max SMB PDU from sess structure BB */
5309 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5310 pSMB
->MaxSetupCount
= 0;
5314 pSMB
->Reserved2
= 0;
5315 byte_count
= params
+ 1 /* pad */ ;
5316 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5317 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5318 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5319 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5321 pSMB
->DataCount
= 0;
5322 pSMB
->DataOffset
= 0;
5323 pSMB
->SetupCount
= 1;
5324 pSMB
->Reserved3
= 0;
5325 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5326 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
5327 inc_rfc1001_len(pSMB
, byte_count
);
5328 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5330 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5331 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5333 cifs_dbg(FYI
, "Send error in QFSDeviceInfo = %d\n", rc
);
5334 } else { /* decode response */
5335 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5337 if (rc
|| get_bcc(&pSMBr
->hdr
) <
5338 sizeof(FILE_SYSTEM_DEVICE_INFO
))
5339 rc
= -EIO
; /* bad smb */
5341 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5343 (FILE_SYSTEM_DEVICE_INFO
*)
5344 (((char *) &pSMBr
->hdr
.Protocol
) +
5346 memcpy(&tcon
->fsDevInfo
, response_data
,
5347 sizeof(FILE_SYSTEM_DEVICE_INFO
));
5350 cifs_buf_release(pSMB
);
5353 goto QFSDeviceRetry
;
5359 CIFSSMBQFSUnixInfo(const unsigned int xid
, struct cifs_tcon
*tcon
)
5361 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
5362 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5363 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5364 FILE_SYSTEM_UNIX_INFO
*response_data
;
5366 int bytes_returned
= 0;
5367 __u16 params
, byte_count
;
5369 cifs_dbg(FYI
, "In QFSUnixInfo\n");
5371 rc
= smb_init_no_reconnect(SMB_COM_TRANSACTION2
, 15, tcon
,
5372 (void **) &pSMB
, (void **) &pSMBr
);
5376 params
= 2; /* level */
5377 pSMB
->TotalDataCount
= 0;
5378 pSMB
->DataCount
= 0;
5379 pSMB
->DataOffset
= 0;
5380 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5381 /* BB find exact max SMB PDU from sess structure BB */
5382 pSMB
->MaxDataCount
= cpu_to_le16(100);
5383 pSMB
->MaxSetupCount
= 0;
5387 pSMB
->Reserved2
= 0;
5388 byte_count
= params
+ 1 /* pad */ ;
5389 pSMB
->ParameterCount
= cpu_to_le16(params
);
5390 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5391 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
5392 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5393 pSMB
->SetupCount
= 1;
5394 pSMB
->Reserved3
= 0;
5395 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5396 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
5397 inc_rfc1001_len(pSMB
, byte_count
);
5398 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5400 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5401 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5403 cifs_dbg(VFS
, "Send error in QFSUnixInfo = %d\n", rc
);
5404 } else { /* decode response */
5405 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5407 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5408 rc
= -EIO
; /* bad smb */
5410 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5412 (FILE_SYSTEM_UNIX_INFO
5413 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5415 memcpy(&tcon
->fsUnixInfo
, response_data
,
5416 sizeof(FILE_SYSTEM_UNIX_INFO
));
5419 cifs_buf_release(pSMB
);
5429 CIFSSMBSetFSUnixInfo(const unsigned int xid
, struct cifs_tcon
*tcon
, __u64 cap
)
5431 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
5432 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
5433 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
5435 int bytes_returned
= 0;
5436 __u16 params
, param_offset
, offset
, byte_count
;
5438 cifs_dbg(FYI
, "In SETFSUnixInfo\n");
5440 /* BB switch to small buf init to save memory */
5441 rc
= smb_init_no_reconnect(SMB_COM_TRANSACTION2
, 15, tcon
,
5442 (void **) &pSMB
, (void **) &pSMBr
);
5446 params
= 4; /* 2 bytes zero followed by info level. */
5447 pSMB
->MaxSetupCount
= 0;
5451 pSMB
->Reserved2
= 0;
5452 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
)
5454 offset
= param_offset
+ params
;
5456 pSMB
->MaxParameterCount
= cpu_to_le16(4);
5457 /* BB find exact max SMB PDU from sess structure BB */
5458 pSMB
->MaxDataCount
= cpu_to_le16(100);
5459 pSMB
->SetupCount
= 1;
5460 pSMB
->Reserved3
= 0;
5461 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
5462 byte_count
= 1 /* pad */ + params
+ 12;
5464 pSMB
->DataCount
= cpu_to_le16(12);
5465 pSMB
->ParameterCount
= cpu_to_le16(params
);
5466 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5467 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5468 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5469 pSMB
->DataOffset
= cpu_to_le16(offset
);
5473 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
5476 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
5477 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
5478 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
5480 inc_rfc1001_len(pSMB
, byte_count
);
5481 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5483 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5484 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5486 cifs_dbg(VFS
, "Send error in SETFSUnixInfo = %d\n", rc
);
5487 } else { /* decode response */
5488 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5490 rc
= -EIO
; /* bad smb */
5492 cifs_buf_release(pSMB
);
5495 goto SETFSUnixRetry
;
5503 CIFSSMBQFSPosixInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5504 struct kstatfs
*FSData
)
5506 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
5507 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5508 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5509 FILE_SYSTEM_POSIX_INFO
*response_data
;
5511 int bytes_returned
= 0;
5512 __u16 params
, byte_count
;
5514 cifs_dbg(FYI
, "In QFSPosixInfo\n");
5516 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5521 params
= 2; /* level */
5522 pSMB
->TotalDataCount
= 0;
5523 pSMB
->DataCount
= 0;
5524 pSMB
->DataOffset
= 0;
5525 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5526 /* BB find exact max SMB PDU from sess structure BB */
5527 pSMB
->MaxDataCount
= cpu_to_le16(100);
5528 pSMB
->MaxSetupCount
= 0;
5532 pSMB
->Reserved2
= 0;
5533 byte_count
= params
+ 1 /* pad */ ;
5534 pSMB
->ParameterCount
= cpu_to_le16(params
);
5535 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5536 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
5537 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5538 pSMB
->SetupCount
= 1;
5539 pSMB
->Reserved3
= 0;
5540 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5541 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
5542 inc_rfc1001_len(pSMB
, byte_count
);
5543 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5545 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5546 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5548 cifs_dbg(FYI
, "Send error in QFSUnixInfo = %d\n", rc
);
5549 } else { /* decode response */
5550 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5552 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5553 rc
= -EIO
; /* bad smb */
5555 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5557 (FILE_SYSTEM_POSIX_INFO
5558 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5561 le32_to_cpu(response_data
->BlockSize
);
5563 * much prefer larger but if server doesn't report
5564 * a valid size than 4K is a reasonable minimum
5566 if (FSData
->f_bsize
< 512)
5567 FSData
->f_bsize
= 4096;
5570 le64_to_cpu(response_data
->TotalBlocks
);
5572 le64_to_cpu(response_data
->BlocksAvail
);
5573 if (response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
5574 FSData
->f_bavail
= FSData
->f_bfree
;
5577 le64_to_cpu(response_data
->UserBlocksAvail
);
5579 if (response_data
->TotalFileNodes
!= cpu_to_le64(-1))
5581 le64_to_cpu(response_data
->TotalFileNodes
);
5582 if (response_data
->FreeFileNodes
!= cpu_to_le64(-1))
5584 le64_to_cpu(response_data
->FreeFileNodes
);
5587 cifs_buf_release(pSMB
);
5597 * We can not use write of zero bytes trick to set file size due to need for
5598 * large file support. Also note that this SetPathInfo is preferred to
5599 * SetFileInfo based method in next routine which is only needed to work around
5600 * a sharing violation bugin Samba which this routine can run into.
5603 CIFSSMBSetEOF(const unsigned int xid
, struct cifs_tcon
*tcon
,
5604 const char *file_name
, __u64 size
, struct cifs_sb_info
*cifs_sb
,
5605 bool set_allocation
)
5607 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
5608 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
5609 struct file_end_of_file_info
*parm_data
;
5612 int bytes_returned
= 0;
5613 int remap
= cifs_remap(cifs_sb
);
5615 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
5617 cifs_dbg(FYI
, "In SetEOF\n");
5619 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5624 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5626 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, file_name
,
5627 PATH_MAX
, cifs_sb
->local_nls
, remap
);
5628 name_len
++; /* trailing null */
5631 name_len
= copy_path_name(pSMB
->FileName
, file_name
);
5633 params
= 6 + name_len
;
5634 data_count
= sizeof(struct file_end_of_file_info
);
5635 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5636 pSMB
->MaxDataCount
= cpu_to_le16(4100);
5637 pSMB
->MaxSetupCount
= 0;
5641 pSMB
->Reserved2
= 0;
5642 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5643 InformationLevel
) - 4;
5644 offset
= param_offset
+ params
;
5645 if (set_allocation
) {
5646 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5647 pSMB
->InformationLevel
=
5648 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
5650 pSMB
->InformationLevel
=
5651 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
5652 } else /* Set File Size */ {
5653 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5654 pSMB
->InformationLevel
=
5655 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
5657 pSMB
->InformationLevel
=
5658 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
5662 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
5664 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5665 pSMB
->DataOffset
= cpu_to_le16(offset
);
5666 pSMB
->SetupCount
= 1;
5667 pSMB
->Reserved3
= 0;
5668 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5669 byte_count
= 3 /* pad */ + params
+ data_count
;
5670 pSMB
->DataCount
= cpu_to_le16(data_count
);
5671 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5672 pSMB
->ParameterCount
= cpu_to_le16(params
);
5673 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5674 pSMB
->Reserved4
= 0;
5675 inc_rfc1001_len(pSMB
, byte_count
);
5676 parm_data
->FileSize
= cpu_to_le64(size
);
5677 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5678 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5679 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5681 cifs_dbg(FYI
, "SetPathInfo (file size) returned %d\n", rc
);
5683 cifs_buf_release(pSMB
);
5692 CIFSSMBSetFileSize(const unsigned int xid
, struct cifs_tcon
*tcon
,
5693 struct cifsFileInfo
*cfile
, __u64 size
, bool set_allocation
)
5695 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5696 struct file_end_of_file_info
*parm_data
;
5698 __u16 params
, param_offset
, offset
, byte_count
, count
;
5700 cifs_dbg(FYI
, "SetFileSize (via SetFileInfo) %lld\n",
5702 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5707 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)cfile
->pid
);
5708 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(cfile
->pid
>> 16));
5711 pSMB
->MaxSetupCount
= 0;
5715 pSMB
->Reserved2
= 0;
5716 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5717 offset
= param_offset
+ params
;
5719 count
= sizeof(struct file_end_of_file_info
);
5720 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5721 /* BB find exact max SMB PDU from sess structure BB */
5722 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5723 pSMB
->SetupCount
= 1;
5724 pSMB
->Reserved3
= 0;
5725 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5726 byte_count
= 3 /* pad */ + params
+ count
;
5727 pSMB
->DataCount
= cpu_to_le16(count
);
5728 pSMB
->ParameterCount
= cpu_to_le16(params
);
5729 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5730 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5731 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5733 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
)
5735 pSMB
->DataOffset
= cpu_to_le16(offset
);
5736 parm_data
->FileSize
= cpu_to_le64(size
);
5737 pSMB
->Fid
= cfile
->fid
.netfid
;
5738 if (set_allocation
) {
5739 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5740 pSMB
->InformationLevel
=
5741 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
5743 pSMB
->InformationLevel
=
5744 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
5745 } else /* Set File Size */ {
5746 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5747 pSMB
->InformationLevel
=
5748 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
5750 pSMB
->InformationLevel
=
5751 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
5753 pSMB
->Reserved4
= 0;
5754 inc_rfc1001_len(pSMB
, byte_count
);
5755 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5756 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5757 cifs_small_buf_release(pSMB
);
5759 cifs_dbg(FYI
, "Send error in SetFileInfo (SetFileSize) = %d\n",
5763 /* Note: On -EAGAIN error only caller can retry on handle based calls
5764 since file handle passed in no longer valid */
5769 /* Some legacy servers such as NT4 require that the file times be set on
5770 an open handle, rather than by pathname - this is awkward due to
5771 potential access conflicts on the open, but it is unavoidable for these
5772 old servers since the only other choice is to go from 100 nanosecond DCE
5773 time and resort to the original setpathinfo level which takes the ancient
5774 DOS time format with 2 second granularity */
5776 CIFSSMBSetFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5777 const FILE_BASIC_INFO
*data
, __u16 fid
, __u32 pid_of_opener
)
5779 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5782 __u16 params
, param_offset
, offset
, byte_count
, count
;
5784 cifs_dbg(FYI
, "Set Times (via SetFileInfo)\n");
5785 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5790 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5791 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5794 pSMB
->MaxSetupCount
= 0;
5798 pSMB
->Reserved2
= 0;
5799 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5800 offset
= param_offset
+ params
;
5802 data_offset
= (char *)pSMB
+
5803 offsetof(struct smb_hdr
, Protocol
) + offset
;
5805 count
= sizeof(FILE_BASIC_INFO
);
5806 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5807 /* BB find max SMB PDU from sess */
5808 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5809 pSMB
->SetupCount
= 1;
5810 pSMB
->Reserved3
= 0;
5811 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5812 byte_count
= 3 /* pad */ + params
+ count
;
5813 pSMB
->DataCount
= cpu_to_le16(count
);
5814 pSMB
->ParameterCount
= cpu_to_le16(params
);
5815 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5816 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5817 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5818 pSMB
->DataOffset
= cpu_to_le16(offset
);
5820 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5821 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5823 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5824 pSMB
->Reserved4
= 0;
5825 inc_rfc1001_len(pSMB
, byte_count
);
5826 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5827 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5828 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5829 cifs_small_buf_release(pSMB
);
5831 cifs_dbg(FYI
, "Send error in Set Time (SetFileInfo) = %d\n",
5834 /* Note: On -EAGAIN error only caller can retry on handle based calls
5835 since file handle passed in no longer valid */
5841 CIFSSMBSetFileDisposition(const unsigned int xid
, struct cifs_tcon
*tcon
,
5842 bool delete_file
, __u16 fid
, __u32 pid_of_opener
)
5844 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5847 __u16 params
, param_offset
, offset
, byte_count
, count
;
5849 cifs_dbg(FYI
, "Set File Disposition (via SetFileInfo)\n");
5850 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5855 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5856 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5859 pSMB
->MaxSetupCount
= 0;
5863 pSMB
->Reserved2
= 0;
5864 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5865 offset
= param_offset
+ params
;
5867 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5870 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5871 /* BB find max SMB PDU from sess */
5872 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5873 pSMB
->SetupCount
= 1;
5874 pSMB
->Reserved3
= 0;
5875 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5876 byte_count
= 3 /* pad */ + params
+ count
;
5877 pSMB
->DataCount
= cpu_to_le16(count
);
5878 pSMB
->ParameterCount
= cpu_to_le16(params
);
5879 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5880 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5881 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5882 pSMB
->DataOffset
= cpu_to_le16(offset
);
5884 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO
);
5885 pSMB
->Reserved4
= 0;
5886 inc_rfc1001_len(pSMB
, byte_count
);
5887 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5888 *data_offset
= delete_file
? 1 : 0;
5889 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5890 cifs_small_buf_release(pSMB
);
5892 cifs_dbg(FYI
, "Send error in SetFileDisposition = %d\n", rc
);
5898 CIFSSMBSetPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5899 const char *fileName
, const FILE_BASIC_INFO
*data
,
5900 const struct nls_table
*nls_codepage
, int remap
)
5902 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5903 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5906 int bytes_returned
= 0;
5908 __u16 params
, param_offset
, offset
, byte_count
, count
;
5910 cifs_dbg(FYI
, "In SetTimes\n");
5913 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5918 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5920 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
5921 PATH_MAX
, nls_codepage
, remap
);
5922 name_len
++; /* trailing null */
5925 name_len
= copy_path_name(pSMB
->FileName
, fileName
);
5928 params
= 6 + name_len
;
5929 count
= sizeof(FILE_BASIC_INFO
);
5930 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5931 /* BB find max SMB PDU from sess structure BB */
5932 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5933 pSMB
->MaxSetupCount
= 0;
5937 pSMB
->Reserved2
= 0;
5938 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5939 InformationLevel
) - 4;
5940 offset
= param_offset
+ params
;
5941 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5942 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5943 pSMB
->DataOffset
= cpu_to_le16(offset
);
5944 pSMB
->SetupCount
= 1;
5945 pSMB
->Reserved3
= 0;
5946 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5947 byte_count
= 3 /* pad */ + params
+ count
;
5949 pSMB
->DataCount
= cpu_to_le16(count
);
5950 pSMB
->ParameterCount
= cpu_to_le16(params
);
5951 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5952 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5953 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5954 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5956 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5957 pSMB
->Reserved4
= 0;
5958 inc_rfc1001_len(pSMB
, byte_count
);
5959 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5960 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5961 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5962 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5964 cifs_dbg(FYI
, "SetPathInfo (times) returned %d\n", rc
);
5966 cifs_buf_release(pSMB
);
5974 /* Can not be used to set time stamps yet (due to old DOS time format) */
5975 /* Can be used to set attributes */
5976 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
5977 handling it anyway and NT4 was what we thought it would be needed for
5978 Do not delete it until we prove whether needed for Win9x though */
5980 CIFSSMBSetAttrLegacy(unsigned int xid
, struct cifs_tcon
*tcon
, char *fileName
,
5981 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
5983 SETATTR_REQ
*pSMB
= NULL
;
5984 SETATTR_RSP
*pSMBr
= NULL
;
5989 cifs_dbg(FYI
, "In SetAttrLegacy\n");
5992 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
5997 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5999 ConvertToUTF16((__le16
*) pSMB
->fileName
, fileName
,
6000 PATH_MAX
, nls_codepage
);
6001 name_len
++; /* trailing null */
6004 name_len
= copy_path_name(pSMB
->fileName
, fileName
);
6006 pSMB
->attr
= cpu_to_le16(dos_attrs
);
6007 pSMB
->BufferFormat
= 0x04;
6008 inc_rfc1001_len(pSMB
, name_len
+ 1);
6009 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
6010 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6011 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6013 cifs_dbg(FYI
, "Error in LegacySetAttr = %d\n", rc
);
6015 cifs_buf_release(pSMB
);
6018 goto SetAttrLgcyRetry
;
6022 #endif /* temporarily unneeded SetAttr legacy function */
6025 cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO
*data_offset
,
6026 const struct cifs_unix_set_info_args
*args
)
6028 u64 uid
= NO_CHANGE_64
, gid
= NO_CHANGE_64
;
6029 u64 mode
= args
->mode
;
6031 if (uid_valid(args
->uid
))
6032 uid
= from_kuid(&init_user_ns
, args
->uid
);
6033 if (gid_valid(args
->gid
))
6034 gid
= from_kgid(&init_user_ns
, args
->gid
);
6037 * Samba server ignores set of file size to zero due to bugs in some
6038 * older clients, but we should be precise - we use SetFileSize to
6039 * set file size and do not want to truncate file size to zero
6040 * accidentally as happened on one Samba server beta by putting
6041 * zero instead of -1 here
6043 data_offset
->EndOfFile
= cpu_to_le64(NO_CHANGE_64
);
6044 data_offset
->NumOfBytes
= cpu_to_le64(NO_CHANGE_64
);
6045 data_offset
->LastStatusChange
= cpu_to_le64(args
->ctime
);
6046 data_offset
->LastAccessTime
= cpu_to_le64(args
->atime
);
6047 data_offset
->LastModificationTime
= cpu_to_le64(args
->mtime
);
6048 data_offset
->Uid
= cpu_to_le64(uid
);
6049 data_offset
->Gid
= cpu_to_le64(gid
);
6050 /* better to leave device as zero when it is */
6051 data_offset
->DevMajor
= cpu_to_le64(MAJOR(args
->device
));
6052 data_offset
->DevMinor
= cpu_to_le64(MINOR(args
->device
));
6053 data_offset
->Permissions
= cpu_to_le64(mode
);
6056 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
6057 else if (S_ISDIR(mode
))
6058 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
6059 else if (S_ISLNK(mode
))
6060 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
6061 else if (S_ISCHR(mode
))
6062 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
6063 else if (S_ISBLK(mode
))
6064 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
6065 else if (S_ISFIFO(mode
))
6066 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
6067 else if (S_ISSOCK(mode
))
6068 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
6072 CIFSSMBUnixSetFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
6073 const struct cifs_unix_set_info_args
*args
,
6074 u16 fid
, u32 pid_of_opener
)
6076 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
6079 u16 params
, param_offset
, offset
, byte_count
, count
;
6081 cifs_dbg(FYI
, "Set Unix Info (via SetFileInfo)\n");
6082 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
6087 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
6088 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
6091 pSMB
->MaxSetupCount
= 0;
6095 pSMB
->Reserved2
= 0;
6096 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
6097 offset
= param_offset
+ params
;
6099 data_offset
= (char *)pSMB
+
6100 offsetof(struct smb_hdr
, Protocol
) + offset
;
6102 count
= sizeof(FILE_UNIX_BASIC_INFO
);
6104 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6105 /* BB find max SMB PDU from sess */
6106 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6107 pSMB
->SetupCount
= 1;
6108 pSMB
->Reserved3
= 0;
6109 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
6110 byte_count
= 3 /* pad */ + params
+ count
;
6111 pSMB
->DataCount
= cpu_to_le16(count
);
6112 pSMB
->ParameterCount
= cpu_to_le16(params
);
6113 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6114 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6115 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6116 pSMB
->DataOffset
= cpu_to_le16(offset
);
6118 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
6119 pSMB
->Reserved4
= 0;
6120 inc_rfc1001_len(pSMB
, byte_count
);
6121 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6123 cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO
*)data_offset
, args
);
6125 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
6126 cifs_small_buf_release(pSMB
);
6128 cifs_dbg(FYI
, "Send error in Set Time (SetFileInfo) = %d\n",
6131 /* Note: On -EAGAIN error only caller can retry on handle based calls
6132 since file handle passed in no longer valid */
6138 CIFSSMBUnixSetPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
6139 const char *file_name
,
6140 const struct cifs_unix_set_info_args
*args
,
6141 const struct nls_table
*nls_codepage
, int remap
)
6143 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
6144 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
6147 int bytes_returned
= 0;
6148 FILE_UNIX_BASIC_INFO
*data_offset
;
6149 __u16 params
, param_offset
, offset
, count
, byte_count
;
6151 cifs_dbg(FYI
, "In SetUID/GID/Mode\n");
6153 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6158 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6160 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, file_name
,
6161 PATH_MAX
, nls_codepage
, remap
);
6162 name_len
++; /* trailing null */
6165 name_len
= copy_path_name(pSMB
->FileName
, file_name
);
6168 params
= 6 + name_len
;
6169 count
= sizeof(FILE_UNIX_BASIC_INFO
);
6170 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6171 /* BB find max SMB PDU from sess structure BB */
6172 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6173 pSMB
->MaxSetupCount
= 0;
6177 pSMB
->Reserved2
= 0;
6178 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
6179 InformationLevel
) - 4;
6180 offset
= param_offset
+ params
;
6182 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
6184 memset(data_offset
, 0, count
);
6185 pSMB
->DataOffset
= cpu_to_le16(offset
);
6186 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6187 pSMB
->SetupCount
= 1;
6188 pSMB
->Reserved3
= 0;
6189 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
6190 byte_count
= 3 /* pad */ + params
+ count
;
6191 pSMB
->ParameterCount
= cpu_to_le16(params
);
6192 pSMB
->DataCount
= cpu_to_le16(count
);
6193 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6194 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6195 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
6196 pSMB
->Reserved4
= 0;
6197 inc_rfc1001_len(pSMB
, byte_count
);
6199 cifs_fill_unix_set_info(data_offset
, args
);
6201 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6202 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6203 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6205 cifs_dbg(FYI
, "SetPathInfo (perms) returned %d\n", rc
);
6207 cifs_buf_release(pSMB
);
6213 #ifdef CONFIG_CIFS_XATTR
6215 * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common
6216 * function used by listxattr and getxattr type calls. When ea_name is set,
6217 * it looks for that attribute name and stuffs that value into the EAData
6218 * buffer. When ea_name is NULL, it stuffs a list of attribute names into the
6219 * buffer. In both cases, the return value is either the length of the
6220 * resulting data or a negative error code. If EAData is a NULL pointer then
6221 * the data isn't copied to it, but the length is returned.
6224 CIFSSMBQAllEAs(const unsigned int xid
, struct cifs_tcon
*tcon
,
6225 const unsigned char *searchName
, const unsigned char *ea_name
,
6226 char *EAData
, size_t buf_size
,
6227 struct cifs_sb_info
*cifs_sb
)
6229 /* BB assumes one setup word */
6230 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
6231 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
6232 int remap
= cifs_remap(cifs_sb
);
6233 struct nls_table
*nls_codepage
= cifs_sb
->local_nls
;
6237 struct fealist
*ea_response_data
;
6238 struct fea
*temp_fea
;
6241 __u16 params
, byte_count
, data_offset
;
6242 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
6244 cifs_dbg(FYI
, "In Query All EAs path %s\n", searchName
);
6246 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6251 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6253 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
6254 PATH_MAX
, nls_codepage
, remap
);
6255 list_len
++; /* trailing null */
6258 list_len
= copy_path_name(pSMB
->FileName
, searchName
);
6261 params
= 2 /* level */ + 4 /* reserved */ + list_len
/* includes NUL */;
6262 pSMB
->TotalDataCount
= 0;
6263 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6264 /* BB find exact max SMB PDU from sess structure BB */
6265 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
6266 pSMB
->MaxSetupCount
= 0;
6270 pSMB
->Reserved2
= 0;
6271 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
6272 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
6273 pSMB
->DataCount
= 0;
6274 pSMB
->DataOffset
= 0;
6275 pSMB
->SetupCount
= 1;
6276 pSMB
->Reserved3
= 0;
6277 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
6278 byte_count
= params
+ 1 /* pad */ ;
6279 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
6280 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
6281 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
6282 pSMB
->Reserved4
= 0;
6283 inc_rfc1001_len(pSMB
, byte_count
);
6284 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6286 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6287 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6289 cifs_dbg(FYI
, "Send error in QueryAllEAs = %d\n", rc
);
6294 /* BB also check enough total bytes returned */
6295 /* BB we need to improve the validity checking
6296 of these trans2 responses */
6298 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
6299 if (rc
|| get_bcc(&pSMBr
->hdr
) < 4) {
6300 rc
= -EIO
; /* bad smb */
6304 /* check that length of list is not more than bcc */
6305 /* check that each entry does not go beyond length
6307 /* check that each element of each entry does not
6308 go beyond end of list */
6309 /* validate_trans2_offsets() */
6310 /* BB check if start of smb + data_offset > &bcc+ bcc */
6312 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
6313 ea_response_data
= (struct fealist
*)
6314 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
6316 list_len
= le32_to_cpu(ea_response_data
->list_len
);
6317 cifs_dbg(FYI
, "ea length %d\n", list_len
);
6318 if (list_len
<= 8) {
6319 cifs_dbg(FYI
, "empty EA list returned from server\n");
6320 /* didn't find the named attribute */
6326 /* make sure list_len doesn't go past end of SMB */
6327 end_of_smb
= (char *)pByteArea(&pSMBr
->hdr
) + get_bcc(&pSMBr
->hdr
);
6328 if ((char *)ea_response_data
+ list_len
> end_of_smb
) {
6329 cifs_dbg(FYI
, "EA list appears to go beyond SMB\n");
6334 /* account for ea list len */
6336 temp_fea
= ea_response_data
->list
;
6337 temp_ptr
= (char *)temp_fea
;
6338 while (list_len
> 0) {
6339 unsigned int name_len
;
6344 /* make sure we can read name_len and value_len */
6346 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
6351 name_len
= temp_fea
->name_len
;
6352 value_len
= le16_to_cpu(temp_fea
->value_len
);
6353 list_len
-= name_len
+ 1 + value_len
;
6355 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
6361 if (ea_name_len
== name_len
&&
6362 memcmp(ea_name
, temp_ptr
, name_len
) == 0) {
6363 temp_ptr
+= name_len
+ 1;
6367 if ((size_t)value_len
> buf_size
) {
6371 memcpy(EAData
, temp_ptr
, value_len
);
6375 /* account for prefix user. and trailing null */
6376 rc
+= (5 + 1 + name_len
);
6377 if (rc
< (int) buf_size
) {
6378 memcpy(EAData
, "user.", 5);
6380 memcpy(EAData
, temp_ptr
, name_len
);
6382 /* null terminate name */
6385 } else if (buf_size
== 0) {
6386 /* skip copy - calc size only */
6388 /* stop before overrun buffer */
6393 temp_ptr
+= name_len
+ 1 + value_len
;
6394 temp_fea
= (struct fea
*)temp_ptr
;
6397 /* didn't find the named attribute */
6402 cifs_buf_release(pSMB
);
6410 CIFSSMBSetEA(const unsigned int xid
, struct cifs_tcon
*tcon
,
6411 const char *fileName
, const char *ea_name
, const void *ea_value
,
6412 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
6413 struct cifs_sb_info
*cifs_sb
)
6415 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
6416 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
6417 struct fealist
*parm_data
;
6420 int bytes_returned
= 0;
6421 __u16 params
, param_offset
, byte_count
, offset
, count
;
6422 int remap
= cifs_remap(cifs_sb
);
6424 cifs_dbg(FYI
, "In SetEA\n");
6426 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6431 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6433 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
6434 PATH_MAX
, nls_codepage
, remap
);
6435 name_len
++; /* trailing null */
6438 name_len
= copy_path_name(pSMB
->FileName
, fileName
);
6441 params
= 6 + name_len
;
6443 /* done calculating parms using name_len of file name,
6444 now use name_len to calculate length of ea name
6445 we are going to create in the inode xattrs */
6446 if (ea_name
== NULL
)
6449 name_len
= strnlen(ea_name
, 255);
6451 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
;
6452 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6453 /* BB find max SMB PDU from sess */
6454 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6455 pSMB
->MaxSetupCount
= 0;
6459 pSMB
->Reserved2
= 0;
6460 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
6461 InformationLevel
) - 4;
6462 offset
= param_offset
+ params
;
6463 pSMB
->InformationLevel
=
6464 cpu_to_le16(SMB_SET_FILE_EA
);
6466 parm_data
= (void *)pSMB
+ offsetof(struct smb_hdr
, Protocol
) + offset
;
6467 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6468 pSMB
->DataOffset
= cpu_to_le16(offset
);
6469 pSMB
->SetupCount
= 1;
6470 pSMB
->Reserved3
= 0;
6471 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
6472 byte_count
= 3 /* pad */ + params
+ count
;
6473 pSMB
->DataCount
= cpu_to_le16(count
);
6474 parm_data
->list_len
= cpu_to_le32(count
);
6475 parm_data
->list
[0].EA_flags
= 0;
6476 /* we checked above that name len is less than 255 */
6477 parm_data
->list
[0].name_len
= (__u8
)name_len
;
6478 /* EA names are always ASCII */
6480 strncpy(parm_data
->list
[0].name
, ea_name
, name_len
);
6481 parm_data
->list
[0].name
[name_len
] = 0;
6482 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
6483 /* caller ensures that ea_value_len is less than 64K but
6484 we need to ensure that it fits within the smb */
6486 /*BB add length check to see if it would fit in
6487 negotiated SMB buffer size BB */
6488 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
6490 memcpy(parm_data
->list
[0].name
+name_len
+1,
6491 ea_value
, ea_value_len
);
6493 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6494 pSMB
->ParameterCount
= cpu_to_le16(params
);
6495 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6496 pSMB
->Reserved4
= 0;
6497 inc_rfc1001_len(pSMB
, byte_count
);
6498 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6499 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6500 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6502 cifs_dbg(FYI
, "SetPathInfo (EA) returned %d\n", rc
);
6504 cifs_buf_release(pSMB
);