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"
46 #include "smbdirect.h"
48 #ifdef CONFIG_CIFS_POSIX
53 #ifdef CONFIG_CIFS_WEAK_PW_HASH
54 {LANMAN_PROT
, "\2LM1.2X002"},
55 {LANMAN2_PROT
, "\2LANMAN2.1"},
56 #endif /* weak password hashing for legacy clients */
57 {CIFS_PROT
, "\2NT LM 0.12"},
58 {POSIX_PROT
, "\2POSIX 2"},
66 #ifdef CONFIG_CIFS_WEAK_PW_HASH
67 {LANMAN_PROT
, "\2LM1.2X002"},
68 {LANMAN2_PROT
, "\2LANMAN2.1"},
69 #endif /* weak password hashing for legacy clients */
70 {CIFS_PROT
, "\2NT LM 0.12"},
75 /* define the number of elements in the cifs dialect array */
76 #ifdef CONFIG_CIFS_POSIX
77 #ifdef CONFIG_CIFS_WEAK_PW_HASH
78 #define CIFS_NUM_PROT 4
80 #define CIFS_NUM_PROT 2
81 #endif /* CIFS_WEAK_PW_HASH */
83 #ifdef CONFIG_CIFS_WEAK_PW_HASH
84 #define CIFS_NUM_PROT 3
86 #define CIFS_NUM_PROT 1
87 #endif /* CONFIG_CIFS_WEAK_PW_HASH */
88 #endif /* CIFS_POSIX */
91 * Mark as invalid, all open files on tree connections since they
92 * were closed when session to server was lost.
95 cifs_mark_open_files_invalid(struct cifs_tcon
*tcon
)
97 struct cifsFileInfo
*open_file
= NULL
;
98 struct list_head
*tmp
;
99 struct list_head
*tmp1
;
101 /* list all files open on tree connection and mark them invalid */
102 spin_lock(&tcon
->open_file_lock
);
103 list_for_each_safe(tmp
, tmp1
, &tcon
->openFileList
) {
104 open_file
= list_entry(tmp
, struct cifsFileInfo
, tlist
);
105 open_file
->invalidHandle
= true;
106 open_file
->oplock_break_cancelled
= true;
108 spin_unlock(&tcon
->open_file_lock
);
110 * BB Add call to invalidate_inodes(sb) for all superblocks mounted
115 /* reconnect the socket, tcon, and smb session if needed */
117 cifs_reconnect_tcon(struct cifs_tcon
*tcon
, int smb_command
)
120 struct cifs_ses
*ses
;
121 struct TCP_Server_Info
*server
;
122 struct nls_table
*nls_codepage
;
125 * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
126 * tcp and smb session status done differently for those three - in the
133 server
= ses
->server
;
136 * only tree disconnect, open, and write, (and ulogoff which does not
137 * have tcon) are allowed as we start force umount
139 if (tcon
->tidStatus
== CifsExiting
) {
140 if (smb_command
!= SMB_COM_WRITE_ANDX
&&
141 smb_command
!= SMB_COM_OPEN_ANDX
&&
142 smb_command
!= SMB_COM_TREE_DISCONNECT
) {
143 cifs_dbg(FYI
, "can not send cmd %d while umounting\n",
150 * Give demultiplex thread up to 10 seconds to reconnect, should be
151 * greater than cifs socket timeout which is 7 seconds
153 while (server
->tcpStatus
== CifsNeedReconnect
) {
154 wait_event_interruptible_timeout(server
->response_q
,
155 (server
->tcpStatus
!= CifsNeedReconnect
), 10 * HZ
);
157 /* are we still trying to reconnect? */
158 if (server
->tcpStatus
!= CifsNeedReconnect
)
162 * on "soft" mounts we wait once. Hard mounts keep
163 * retrying until process is killed or server comes
167 cifs_dbg(FYI
, "gave up waiting on reconnect in smb_init\n");
172 if (!ses
->need_reconnect
&& !tcon
->need_reconnect
)
175 nls_codepage
= load_nls_default();
178 * need to prevent multiple threads trying to simultaneously
179 * reconnect the same SMB session
181 mutex_lock(&ses
->session_mutex
);
184 * Recheck after acquire mutex. If another thread is negotiating
185 * and the server never sends an answer the socket will be closed
186 * and tcpStatus set to reconnect.
188 if (server
->tcpStatus
== CifsNeedReconnect
) {
190 mutex_unlock(&ses
->session_mutex
);
194 rc
= cifs_negotiate_protocol(0, ses
);
195 if (rc
== 0 && ses
->need_reconnect
)
196 rc
= cifs_setup_session(0, ses
, nls_codepage
);
198 /* do we need to reconnect tcon? */
199 if (rc
|| !tcon
->need_reconnect
) {
200 mutex_unlock(&ses
->session_mutex
);
204 cifs_mark_open_files_invalid(tcon
);
205 rc
= CIFSTCon(0, ses
, tcon
->treeName
, tcon
, nls_codepage
);
206 mutex_unlock(&ses
->session_mutex
);
207 cifs_dbg(FYI
, "reconnect tcon rc = %d\n", rc
);
212 atomic_inc(&tconInfoReconnectCount
);
214 /* tell server Unix caps we support */
215 if (ses
->capabilities
& CAP_UNIX
)
216 reset_cifs_unix_caps(0, tcon
, NULL
, NULL
);
219 * Removed call to reopen open files here. It is safer (and faster) to
220 * reopen files one at a time as needed in read and write.
222 * FIXME: what about file locks? don't we need to reclaim them ASAP?
227 * Check if handle based operation so we know whether we can continue
228 * or not without returning to caller to reset file handle
230 switch (smb_command
) {
231 case SMB_COM_READ_ANDX
:
232 case SMB_COM_WRITE_ANDX
:
234 case SMB_COM_FIND_CLOSE2
:
235 case SMB_COM_LOCKING_ANDX
:
239 unload_nls(nls_codepage
);
243 /* Allocate and return pointer to an SMB request buffer, and set basic
244 SMB information in the SMB header. If the return code is zero, this
245 function must have filled in request_buf pointer */
247 small_smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
252 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
256 *request_buf
= cifs_small_buf_get();
257 if (*request_buf
== NULL
) {
258 /* BB should we add a retry in here if not a writepage? */
262 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
,
266 cifs_stats_inc(&tcon
->num_smbs_sent
);
272 small_smb_init_no_tc(const int smb_command
, const int wct
,
273 struct cifs_ses
*ses
, void **request_buf
)
276 struct smb_hdr
*buffer
;
278 rc
= small_smb_init(smb_command
, wct
, NULL
, request_buf
);
282 buffer
= (struct smb_hdr
*)*request_buf
;
283 buffer
->Mid
= get_next_mid(ses
->server
);
284 if (ses
->capabilities
& CAP_UNICODE
)
285 buffer
->Flags2
|= SMBFLG2_UNICODE
;
286 if (ses
->capabilities
& CAP_STATUS32
)
287 buffer
->Flags2
|= SMBFLG2_ERR_STATUS
;
289 /* uid, tid can stay at zero as set in header assemble */
291 /* BB add support for turning on the signing when
292 this function is used after 1st of session setup requests */
297 /* If the return code is zero, this function must fill in request_buf pointer */
299 __smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
300 void **request_buf
, void **response_buf
)
302 *request_buf
= cifs_buf_get();
303 if (*request_buf
== NULL
) {
304 /* BB should we add a retry in here if not a writepage? */
307 /* Although the original thought was we needed the response buf for */
308 /* potential retries of smb operations it turns out we can determine */
309 /* from the mid flags when the request buffer can be resent without */
310 /* having to use a second distinct buffer for the response */
312 *response_buf
= *request_buf
;
314 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
318 cifs_stats_inc(&tcon
->num_smbs_sent
);
323 /* If the return code is zero, this function must fill in request_buf pointer */
325 smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
326 void **request_buf
, void **response_buf
)
330 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
334 return __smb_init(smb_command
, wct
, tcon
, request_buf
, response_buf
);
338 smb_init_no_reconnect(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
339 void **request_buf
, void **response_buf
)
341 if (tcon
->ses
->need_reconnect
|| tcon
->need_reconnect
)
344 return __smb_init(smb_command
, wct
, tcon
, request_buf
, response_buf
);
347 static int validate_t2(struct smb_t2_rsp
*pSMB
)
349 unsigned int total_size
;
351 /* check for plausible wct */
352 if (pSMB
->hdr
.WordCount
< 10)
355 /* check for parm and data offset going beyond end of smb */
356 if (get_unaligned_le16(&pSMB
->t2_rsp
.ParameterOffset
) > 1024 ||
357 get_unaligned_le16(&pSMB
->t2_rsp
.DataOffset
) > 1024)
360 total_size
= get_unaligned_le16(&pSMB
->t2_rsp
.ParameterCount
);
361 if (total_size
>= 512)
364 /* check that bcc is at least as big as parms + data, and that it is
365 * less than negotiated smb buffer
367 total_size
+= get_unaligned_le16(&pSMB
->t2_rsp
.DataCount
);
368 if (total_size
> get_bcc(&pSMB
->hdr
) ||
369 total_size
>= CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
)
374 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB
,
375 sizeof(struct smb_t2_rsp
) + 16);
380 decode_ext_sec_blob(struct cifs_ses
*ses
, NEGOTIATE_RSP
*pSMBr
)
384 char *guid
= pSMBr
->u
.extended_response
.GUID
;
385 struct TCP_Server_Info
*server
= ses
->server
;
387 count
= get_bcc(&pSMBr
->hdr
);
388 if (count
< SMB1_CLIENT_GUID_SIZE
)
391 spin_lock(&cifs_tcp_ses_lock
);
392 if (server
->srv_count
> 1) {
393 spin_unlock(&cifs_tcp_ses_lock
);
394 if (memcmp(server
->server_GUID
, guid
, SMB1_CLIENT_GUID_SIZE
) != 0) {
395 cifs_dbg(FYI
, "server UID changed\n");
396 memcpy(server
->server_GUID
, guid
, SMB1_CLIENT_GUID_SIZE
);
399 spin_unlock(&cifs_tcp_ses_lock
);
400 memcpy(server
->server_GUID
, guid
, SMB1_CLIENT_GUID_SIZE
);
403 if (count
== SMB1_CLIENT_GUID_SIZE
) {
404 server
->sec_ntlmssp
= true;
406 count
-= SMB1_CLIENT_GUID_SIZE
;
407 rc
= decode_negTokenInit(
408 pSMBr
->u
.extended_response
.SecurityBlob
, count
, server
);
417 cifs_enable_signing(struct TCP_Server_Info
*server
, bool mnt_sign_required
)
419 bool srv_sign_required
= server
->sec_mode
& server
->vals
->signing_required
;
420 bool srv_sign_enabled
= server
->sec_mode
& server
->vals
->signing_enabled
;
421 bool mnt_sign_enabled
= global_secflags
& CIFSSEC_MAY_SIGN
;
424 * Is signing required by mnt options? If not then check
425 * global_secflags to see if it is there.
427 if (!mnt_sign_required
)
428 mnt_sign_required
= ((global_secflags
& CIFSSEC_MUST_SIGN
) ==
432 * If signing is required then it's automatically enabled too,
433 * otherwise, check to see if the secflags allow it.
435 mnt_sign_enabled
= mnt_sign_required
? mnt_sign_required
:
436 (global_secflags
& CIFSSEC_MAY_SIGN
);
438 /* If server requires signing, does client allow it? */
439 if (srv_sign_required
) {
440 if (!mnt_sign_enabled
) {
441 cifs_dbg(VFS
, "Server requires signing, but it's disabled in SecurityFlags!");
447 /* If client requires signing, does server allow it? */
448 if (mnt_sign_required
) {
449 if (!srv_sign_enabled
) {
450 cifs_dbg(VFS
, "Server does not support signing!");
459 #ifdef CONFIG_CIFS_WEAK_PW_HASH
461 decode_lanman_negprot_rsp(struct TCP_Server_Info
*server
, NEGOTIATE_RSP
*pSMBr
)
464 struct lanman_neg_rsp
*rsp
= (struct lanman_neg_rsp
*)pSMBr
;
466 if (server
->dialect
!= LANMAN_PROT
&& server
->dialect
!= LANMAN2_PROT
)
469 server
->sec_mode
= le16_to_cpu(rsp
->SecurityMode
);
470 server
->maxReq
= min_t(unsigned int,
471 le16_to_cpu(rsp
->MaxMpxCount
),
473 set_credits(server
, server
->maxReq
);
474 server
->maxBuf
= le16_to_cpu(rsp
->MaxBufSize
);
475 /* even though we do not use raw we might as well set this
476 accurately, in case we ever find a need for it */
477 if ((le16_to_cpu(rsp
->RawMode
) & RAW_ENABLE
) == RAW_ENABLE
) {
478 server
->max_rw
= 0xFF00;
479 server
->capabilities
= CAP_MPX_MODE
| CAP_RAW_MODE
;
481 server
->max_rw
= 0;/* do not need to use raw anyway */
482 server
->capabilities
= CAP_MPX_MODE
;
484 tmp
= (__s16
)le16_to_cpu(rsp
->ServerTimeZone
);
486 /* OS/2 often does not set timezone therefore
487 * we must use server time to calc time zone.
488 * Could deviate slightly from the right zone.
489 * Smallest defined timezone difference is 15 minutes
490 * (i.e. Nepal). Rounding up/down is done to match
493 int val
, seconds
, remain
, result
;
495 unsigned long utc
= ktime_get_real_seconds();
496 ts
= cnvrtDosUnixTm(rsp
->SrvTime
.Date
,
497 rsp
->SrvTime
.Time
, 0);
498 cifs_dbg(FYI
, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n",
499 (int)ts
.tv_sec
, (int)utc
,
500 (int)(utc
- ts
.tv_sec
));
501 val
= (int)(utc
- ts
.tv_sec
);
503 result
= (seconds
/ MIN_TZ_ADJ
) * MIN_TZ_ADJ
;
504 remain
= seconds
% MIN_TZ_ADJ
;
505 if (remain
>= (MIN_TZ_ADJ
/ 2))
506 result
+= MIN_TZ_ADJ
;
509 server
->timeAdj
= result
;
511 server
->timeAdj
= (int)tmp
;
512 server
->timeAdj
*= 60; /* also in seconds */
514 cifs_dbg(FYI
, "server->timeAdj: %d seconds\n", server
->timeAdj
);
517 /* BB get server time for time conversions and add
518 code to use it and timezone since this is not UTC */
520 if (rsp
->EncryptionKeyLength
==
521 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE
)) {
522 memcpy(server
->cryptkey
, rsp
->EncryptionKey
,
523 CIFS_CRYPTO_KEY_SIZE
);
524 } else if (server
->sec_mode
& SECMODE_PW_ENCRYPT
) {
525 return -EIO
; /* need cryptkey unless plain text */
528 cifs_dbg(FYI
, "LANMAN negotiated\n");
533 decode_lanman_negprot_rsp(struct TCP_Server_Info
*server
, NEGOTIATE_RSP
*pSMBr
)
535 cifs_dbg(VFS
, "mount failed, cifs module not built with CIFS_WEAK_PW_HASH support\n");
541 should_set_ext_sec_flag(enum securityEnum sectype
)
548 if (global_secflags
&
549 (CIFSSEC_MAY_KRB5
| CIFSSEC_MAY_NTLMSSP
))
558 CIFSSMBNegotiate(const unsigned int xid
, struct cifs_ses
*ses
)
561 NEGOTIATE_RSP
*pSMBr
;
565 struct TCP_Server_Info
*server
= ses
->server
;
569 WARN(1, "%s: server is NULL!\n", __func__
);
573 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
574 (void **) &pSMB
, (void **) &pSMBr
);
578 pSMB
->hdr
.Mid
= get_next_mid(server
);
579 pSMB
->hdr
.Flags2
|= (SMBFLG2_UNICODE
| SMBFLG2_ERR_STATUS
);
581 if (should_set_ext_sec_flag(ses
->sectype
)) {
582 cifs_dbg(FYI
, "Requesting extended security.");
583 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
587 for (i
= 0; i
< CIFS_NUM_PROT
; i
++) {
588 strncpy(pSMB
->DialectsArray
+count
, protocols
[i
].name
, 16);
589 count
+= strlen(protocols
[i
].name
) + 1;
590 /* null at end of source and target buffers anyway */
592 inc_rfc1001_len(pSMB
, count
);
593 pSMB
->ByteCount
= cpu_to_le16(count
);
595 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
596 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
600 server
->dialect
= le16_to_cpu(pSMBr
->DialectIndex
);
601 cifs_dbg(FYI
, "Dialect: %d\n", server
->dialect
);
602 /* Check wct = 1 error case */
603 if ((pSMBr
->hdr
.WordCount
< 13) || (server
->dialect
== BAD_PROT
)) {
604 /* core returns wct = 1, but we do not ask for core - otherwise
605 small wct just comes when dialect index is -1 indicating we
606 could not negotiate a common dialect */
609 } else if (pSMBr
->hdr
.WordCount
== 13) {
610 server
->negflavor
= CIFS_NEGFLAVOR_LANMAN
;
611 rc
= decode_lanman_negprot_rsp(server
, pSMBr
);
613 } else if (pSMBr
->hdr
.WordCount
!= 17) {
618 /* else wct == 17, NTLM or better */
620 server
->sec_mode
= pSMBr
->SecurityMode
;
621 if ((server
->sec_mode
& SECMODE_USER
) == 0)
622 cifs_dbg(FYI
, "share mode security\n");
624 /* one byte, so no need to convert this or EncryptionKeyLen from
626 server
->maxReq
= min_t(unsigned int, le16_to_cpu(pSMBr
->MaxMpxCount
),
628 set_credits(server
, server
->maxReq
);
629 /* probably no need to store and check maxvcs */
630 server
->maxBuf
= le32_to_cpu(pSMBr
->MaxBufferSize
);
631 server
->max_rw
= le32_to_cpu(pSMBr
->MaxRawSize
);
632 cifs_dbg(NOISY
, "Max buf = %d\n", ses
->server
->maxBuf
);
633 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
634 server
->timeAdj
= (int)(__s16
)le16_to_cpu(pSMBr
->ServerTimeZone
);
635 server
->timeAdj
*= 60;
637 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
638 server
->negflavor
= CIFS_NEGFLAVOR_UNENCAP
;
639 memcpy(ses
->server
->cryptkey
, pSMBr
->u
.EncryptionKey
,
640 CIFS_CRYPTO_KEY_SIZE
);
641 } else if (pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
||
642 server
->capabilities
& CAP_EXTENDED_SECURITY
) {
643 server
->negflavor
= CIFS_NEGFLAVOR_EXTENDED
;
644 rc
= decode_ext_sec_blob(ses
, pSMBr
);
645 } else if (server
->sec_mode
& SECMODE_PW_ENCRYPT
) {
646 rc
= -EIO
; /* no crypt key only if plain text pwd */
648 server
->negflavor
= CIFS_NEGFLAVOR_UNENCAP
;
649 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
654 rc
= cifs_enable_signing(server
, ses
->sign
);
656 cifs_buf_release(pSMB
);
658 cifs_dbg(FYI
, "negprot rc %d\n", rc
);
663 CIFSSMBTDis(const unsigned int xid
, struct cifs_tcon
*tcon
)
665 struct smb_hdr
*smb_buffer
;
668 cifs_dbg(FYI
, "In tree disconnect\n");
670 /* BB: do we need to check this? These should never be NULL. */
671 if ((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
))
675 * No need to return error on this operation if tid invalidated and
676 * closed on server already e.g. due to tcp session crashing. Also,
677 * the tcon is no longer on the list, so no need to take lock before
680 if ((tcon
->need_reconnect
) || (tcon
->ses
->need_reconnect
))
683 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
684 (void **)&smb_buffer
);
688 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *)smb_buffer
, 0);
689 cifs_small_buf_release(smb_buffer
);
691 cifs_dbg(FYI
, "Tree disconnect failed %d\n", rc
);
693 /* No need to return error on this operation if tid invalidated and
694 closed on server already e.g. due to tcp session crashing */
702 * This is a no-op for now. We're not really interested in the reply, but
703 * rather in the fact that the server sent one and that server->lstrp
706 * FIXME: maybe we should consider checking that the reply matches request?
709 cifs_echo_callback(struct mid_q_entry
*mid
)
711 struct TCP_Server_Info
*server
= mid
->callback_data
;
713 DeleteMidQEntry(mid
);
714 add_credits(server
, 1, CIFS_ECHO_OP
);
718 CIFSSMBEcho(struct TCP_Server_Info
*server
)
723 struct smb_rqst rqst
= { .rq_iov
= iov
,
726 cifs_dbg(FYI
, "In echo request\n");
728 rc
= small_smb_init(SMB_COM_ECHO
, 0, NULL
, (void **)&smb
);
732 if (server
->capabilities
& CAP_UNICODE
)
733 smb
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
735 /* set up echo request */
736 smb
->hdr
.Tid
= 0xffff;
737 smb
->hdr
.WordCount
= 1;
738 put_unaligned_le16(1, &smb
->EchoCount
);
739 put_bcc(1, &smb
->hdr
);
741 inc_rfc1001_len(smb
, 3);
744 iov
[0].iov_base
= smb
;
745 iov
[1].iov_len
= get_rfc1002_length(smb
);
746 iov
[1].iov_base
= (char *)smb
+ 4;
748 rc
= cifs_call_async(server
, &rqst
, NULL
, cifs_echo_callback
, NULL
,
749 server
, CIFS_ASYNC_OP
| CIFS_ECHO_OP
);
751 cifs_dbg(FYI
, "Echo request failed: %d\n", rc
);
753 cifs_small_buf_release(smb
);
759 CIFSSMBLogoff(const unsigned int xid
, struct cifs_ses
*ses
)
761 LOGOFF_ANDX_REQ
*pSMB
;
764 cifs_dbg(FYI
, "In SMBLogoff for session disconnect\n");
767 * BB: do we need to check validity of ses and server? They should
768 * always be valid since we have an active reference. If not, that
769 * should probably be a BUG()
771 if (!ses
|| !ses
->server
)
774 mutex_lock(&ses
->session_mutex
);
775 if (ses
->need_reconnect
)
776 goto session_already_dead
; /* no need to send SMBlogoff if uid
777 already closed due to reconnect */
778 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
780 mutex_unlock(&ses
->session_mutex
);
784 pSMB
->hdr
.Mid
= get_next_mid(ses
->server
);
786 if (ses
->server
->sign
)
787 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
789 pSMB
->hdr
.Uid
= ses
->Suid
;
791 pSMB
->AndXCommand
= 0xFF;
792 rc
= SendReceiveNoRsp(xid
, ses
, (char *) pSMB
, 0);
793 cifs_small_buf_release(pSMB
);
794 session_already_dead
:
795 mutex_unlock(&ses
->session_mutex
);
797 /* if session dead then we do not need to do ulogoff,
798 since server closed smb session, no sense reporting
806 CIFSPOSIXDelFile(const unsigned int xid
, struct cifs_tcon
*tcon
,
807 const char *fileName
, __u16 type
,
808 const struct nls_table
*nls_codepage
, int remap
)
810 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
811 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
812 struct unlink_psx_rq
*pRqD
;
815 int bytes_returned
= 0;
816 __u16 params
, param_offset
, offset
, byte_count
;
818 cifs_dbg(FYI
, "In POSIX delete\n");
820 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
825 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
827 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
828 PATH_MAX
, nls_codepage
, remap
);
829 name_len
++; /* trailing null */
831 } else { /* BB add path length overrun check */
832 name_len
= strnlen(fileName
, PATH_MAX
);
833 name_len
++; /* trailing null */
834 strncpy(pSMB
->FileName
, fileName
, name_len
);
837 params
= 6 + name_len
;
838 pSMB
->MaxParameterCount
= cpu_to_le16(2);
839 pSMB
->MaxDataCount
= 0; /* BB double check this with jra */
840 pSMB
->MaxSetupCount
= 0;
845 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
846 InformationLevel
) - 4;
847 offset
= param_offset
+ params
;
849 /* Setup pointer to Request Data (inode type) */
850 pRqD
= (struct unlink_psx_rq
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
851 pRqD
->type
= cpu_to_le16(type
);
852 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
853 pSMB
->DataOffset
= cpu_to_le16(offset
);
854 pSMB
->SetupCount
= 1;
856 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
857 byte_count
= 3 /* pad */ + params
+ sizeof(struct unlink_psx_rq
);
859 pSMB
->DataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
860 pSMB
->TotalDataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
861 pSMB
->ParameterCount
= cpu_to_le16(params
);
862 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
863 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_UNLINK
);
865 inc_rfc1001_len(pSMB
, byte_count
);
866 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
867 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
868 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
870 cifs_dbg(FYI
, "Posix delete returned %d\n", rc
);
871 cifs_buf_release(pSMB
);
873 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_deletes
);
882 CIFSSMBDelFile(const unsigned int xid
, struct cifs_tcon
*tcon
, const char *name
,
883 struct cifs_sb_info
*cifs_sb
)
885 DELETE_FILE_REQ
*pSMB
= NULL
;
886 DELETE_FILE_RSP
*pSMBr
= NULL
;
890 int remap
= cifs_remap(cifs_sb
);
893 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
898 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
899 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->fileName
, name
,
900 PATH_MAX
, cifs_sb
->local_nls
,
902 name_len
++; /* trailing null */
904 } else { /* BB improve check for buffer overruns BB */
905 name_len
= strnlen(name
, PATH_MAX
);
906 name_len
++; /* trailing null */
907 strncpy(pSMB
->fileName
, name
, name_len
);
909 pSMB
->SearchAttributes
=
910 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
);
911 pSMB
->BufferFormat
= 0x04;
912 inc_rfc1001_len(pSMB
, name_len
+ 1);
913 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
914 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
915 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
916 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_deletes
);
918 cifs_dbg(FYI
, "Error in RMFile = %d\n", rc
);
920 cifs_buf_release(pSMB
);
928 CIFSSMBRmDir(const unsigned int xid
, struct cifs_tcon
*tcon
, const char *name
,
929 struct cifs_sb_info
*cifs_sb
)
931 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
932 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
936 int remap
= cifs_remap(cifs_sb
);
938 cifs_dbg(FYI
, "In CIFSSMBRmDir\n");
940 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
945 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
946 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->DirName
, name
,
947 PATH_MAX
, cifs_sb
->local_nls
,
949 name_len
++; /* trailing null */
951 } else { /* BB improve check for buffer overruns BB */
952 name_len
= strnlen(name
, PATH_MAX
);
953 name_len
++; /* trailing null */
954 strncpy(pSMB
->DirName
, name
, name_len
);
957 pSMB
->BufferFormat
= 0x04;
958 inc_rfc1001_len(pSMB
, name_len
+ 1);
959 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
960 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
961 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
962 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_rmdirs
);
964 cifs_dbg(FYI
, "Error in RMDir = %d\n", rc
);
966 cifs_buf_release(pSMB
);
973 CIFSSMBMkDir(const unsigned int xid
, struct cifs_tcon
*tcon
, const char *name
,
974 struct cifs_sb_info
*cifs_sb
)
977 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
978 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
981 int remap
= cifs_remap(cifs_sb
);
983 cifs_dbg(FYI
, "In CIFSSMBMkDir\n");
985 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
990 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
991 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->DirName
, name
,
992 PATH_MAX
, cifs_sb
->local_nls
,
994 name_len
++; /* trailing null */
996 } else { /* BB improve check for buffer overruns BB */
997 name_len
= strnlen(name
, PATH_MAX
);
998 name_len
++; /* trailing null */
999 strncpy(pSMB
->DirName
, name
, name_len
);
1002 pSMB
->BufferFormat
= 0x04;
1003 inc_rfc1001_len(pSMB
, name_len
+ 1);
1004 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
1005 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1006 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1007 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_mkdirs
);
1009 cifs_dbg(FYI
, "Error in Mkdir = %d\n", rc
);
1011 cifs_buf_release(pSMB
);
1018 CIFSPOSIXCreate(const unsigned int xid
, struct cifs_tcon
*tcon
,
1019 __u32 posix_flags
, __u64 mode
, __u16
*netfid
,
1020 FILE_UNIX_BASIC_INFO
*pRetData
, __u32
*pOplock
,
1021 const char *name
, const struct nls_table
*nls_codepage
,
1024 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
1025 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
1028 int bytes_returned
= 0;
1029 __u16 params
, param_offset
, offset
, byte_count
, count
;
1030 OPEN_PSX_REQ
*pdata
;
1031 OPEN_PSX_RSP
*psx_rsp
;
1033 cifs_dbg(FYI
, "In POSIX Create\n");
1035 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1040 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1042 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, name
,
1043 PATH_MAX
, nls_codepage
, remap
);
1044 name_len
++; /* trailing null */
1046 } else { /* BB improve the check for buffer overruns BB */
1047 name_len
= strnlen(name
, PATH_MAX
);
1048 name_len
++; /* trailing null */
1049 strncpy(pSMB
->FileName
, name
, name_len
);
1052 params
= 6 + name_len
;
1053 count
= sizeof(OPEN_PSX_REQ
);
1054 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1055 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* large enough */
1056 pSMB
->MaxSetupCount
= 0;
1060 pSMB
->Reserved2
= 0;
1061 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
1062 InformationLevel
) - 4;
1063 offset
= param_offset
+ params
;
1064 pdata
= (OPEN_PSX_REQ
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
1065 pdata
->Level
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
1066 pdata
->Permissions
= cpu_to_le64(mode
);
1067 pdata
->PosixOpenFlags
= cpu_to_le32(posix_flags
);
1068 pdata
->OpenFlags
= cpu_to_le32(*pOplock
);
1069 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1070 pSMB
->DataOffset
= cpu_to_le16(offset
);
1071 pSMB
->SetupCount
= 1;
1072 pSMB
->Reserved3
= 0;
1073 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1074 byte_count
= 3 /* pad */ + params
+ count
;
1076 pSMB
->DataCount
= cpu_to_le16(count
);
1077 pSMB
->ParameterCount
= cpu_to_le16(params
);
1078 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1079 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1080 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_OPEN
);
1081 pSMB
->Reserved4
= 0;
1082 inc_rfc1001_len(pSMB
, byte_count
);
1083 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1084 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1085 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1087 cifs_dbg(FYI
, "Posix create returned %d\n", rc
);
1088 goto psx_create_err
;
1091 cifs_dbg(FYI
, "copying inode info\n");
1092 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1094 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(OPEN_PSX_RSP
)) {
1095 rc
= -EIO
; /* bad smb */
1096 goto psx_create_err
;
1099 /* copy return information to pRetData */
1100 psx_rsp
= (OPEN_PSX_RSP
*)((char *) &pSMBr
->hdr
.Protocol
1101 + le16_to_cpu(pSMBr
->t2
.DataOffset
));
1103 *pOplock
= le16_to_cpu(psx_rsp
->OplockFlags
);
1105 *netfid
= psx_rsp
->Fid
; /* cifs fid stays in le */
1106 /* Let caller know file was created so we can set the mode. */
1107 /* Do we care about the CreateAction in any other cases? */
1108 if (cpu_to_le32(FILE_CREATE
) == psx_rsp
->CreateAction
)
1109 *pOplock
|= CIFS_CREATE_ACTION
;
1110 /* check to make sure response data is there */
1111 if (psx_rsp
->ReturnedLevel
!= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
)) {
1112 pRetData
->Type
= cpu_to_le32(-1); /* unknown */
1113 cifs_dbg(NOISY
, "unknown type\n");
1115 if (get_bcc(&pSMBr
->hdr
) < sizeof(OPEN_PSX_RSP
)
1116 + sizeof(FILE_UNIX_BASIC_INFO
)) {
1117 cifs_dbg(VFS
, "Open response data too small\n");
1118 pRetData
->Type
= cpu_to_le32(-1);
1119 goto psx_create_err
;
1121 memcpy((char *) pRetData
,
1122 (char *)psx_rsp
+ sizeof(OPEN_PSX_RSP
),
1123 sizeof(FILE_UNIX_BASIC_INFO
));
1127 cifs_buf_release(pSMB
);
1129 if (posix_flags
& SMB_O_DIRECTORY
)
1130 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_posixmkdirs
);
1132 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_posixopens
);
1140 static __u16
convert_disposition(int disposition
)
1144 switch (disposition
) {
1145 case FILE_SUPERSEDE
:
1146 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1149 ofun
= SMBOPEN_OAPPEND
;
1152 ofun
= SMBOPEN_OCREATE
;
1155 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
1157 case FILE_OVERWRITE
:
1158 ofun
= SMBOPEN_OTRUNC
;
1160 case FILE_OVERWRITE_IF
:
1161 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1164 cifs_dbg(FYI
, "unknown disposition %d\n", disposition
);
1165 ofun
= SMBOPEN_OAPPEND
; /* regular open */
1171 access_flags_to_smbopen_mode(const int access_flags
)
1173 int masked_flags
= access_flags
& (GENERIC_READ
| GENERIC_WRITE
);
1175 if (masked_flags
== GENERIC_READ
)
1176 return SMBOPEN_READ
;
1177 else if (masked_flags
== GENERIC_WRITE
)
1178 return SMBOPEN_WRITE
;
1180 /* just go for read/write */
1181 return SMBOPEN_READWRITE
;
1185 SMBLegacyOpen(const unsigned int xid
, struct cifs_tcon
*tcon
,
1186 const char *fileName
, const int openDisposition
,
1187 const int access_flags
, const int create_options
, __u16
*netfid
,
1188 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1189 const struct nls_table
*nls_codepage
, int remap
)
1192 OPENX_REQ
*pSMB
= NULL
;
1193 OPENX_RSP
*pSMBr
= NULL
;
1199 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
1204 pSMB
->AndXCommand
= 0xFF; /* none */
1206 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1207 count
= 1; /* account for one byte pad to word boundary */
1209 cifsConvertToUTF16((__le16
*) (pSMB
->fileName
+ 1),
1210 fileName
, PATH_MAX
, nls_codepage
, remap
);
1211 name_len
++; /* trailing null */
1213 } else { /* BB improve check for buffer overruns BB */
1214 count
= 0; /* no pad */
1215 name_len
= strnlen(fileName
, PATH_MAX
);
1216 name_len
++; /* trailing null */
1217 strncpy(pSMB
->fileName
, fileName
, name_len
);
1219 if (*pOplock
& REQ_OPLOCK
)
1220 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
1221 else if (*pOplock
& REQ_BATCHOPLOCK
)
1222 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
1224 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
1225 pSMB
->Mode
= cpu_to_le16(access_flags_to_smbopen_mode(access_flags
));
1226 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
1227 /* set file as system file if special file such
1228 as fifo and server expecting SFU style and
1229 no Unix extensions */
1231 if (create_options
& CREATE_OPTION_SPECIAL
)
1232 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
1233 else /* BB FIXME BB */
1234 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/);
1236 if (create_options
& CREATE_OPTION_READONLY
)
1237 pSMB
->FileAttributes
|= cpu_to_le16(ATTR_READONLY
);
1240 /* pSMB->CreateOptions = cpu_to_le32(create_options &
1241 CREATE_OPTIONS_MASK); */
1242 /* BB FIXME END BB */
1244 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
1245 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
1247 inc_rfc1001_len(pSMB
, count
);
1249 pSMB
->ByteCount
= cpu_to_le16(count
);
1250 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1251 (struct smb_hdr
*)pSMBr
, &bytes_returned
, 0);
1252 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_opens
);
1254 cifs_dbg(FYI
, "Error in Open = %d\n", rc
);
1256 /* BB verify if wct == 15 */
1258 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
1260 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1261 /* Let caller know file was created so we can set the mode. */
1262 /* Do we care about the CreateAction in any other cases? */
1264 /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1265 *pOplock |= CIFS_CREATE_ACTION; */
1269 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
1270 pfile_info
->LastAccessTime
= 0; /* BB fixme */
1271 pfile_info
->LastWriteTime
= 0; /* BB fixme */
1272 pfile_info
->ChangeTime
= 0; /* BB fixme */
1273 pfile_info
->Attributes
=
1274 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
1275 /* the file_info buf is endian converted by caller */
1276 pfile_info
->AllocationSize
=
1277 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
1278 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
1279 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1280 pfile_info
->DeletePending
= 0;
1284 cifs_buf_release(pSMB
);
1291 CIFS_open(const unsigned int xid
, struct cifs_open_parms
*oparms
, int *oplock
,
1295 OPEN_REQ
*req
= NULL
;
1296 OPEN_RSP
*rsp
= NULL
;
1300 struct cifs_sb_info
*cifs_sb
= oparms
->cifs_sb
;
1301 struct cifs_tcon
*tcon
= oparms
->tcon
;
1302 int remap
= cifs_remap(cifs_sb
);
1303 const struct nls_table
*nls
= cifs_sb
->local_nls
;
1304 int create_options
= oparms
->create_options
;
1305 int desired_access
= oparms
->desired_access
;
1306 int disposition
= oparms
->disposition
;
1307 const char *path
= oparms
->path
;
1310 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **)&req
,
1315 /* no commands go after this */
1316 req
->AndXCommand
= 0xFF;
1318 if (req
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1319 /* account for one byte pad to word boundary */
1321 name_len
= cifsConvertToUTF16((__le16
*)(req
->fileName
+ 1),
1322 path
, PATH_MAX
, nls
, remap
);
1326 req
->NameLength
= cpu_to_le16(name_len
);
1328 /* BB improve check for buffer overruns BB */
1331 name_len
= strnlen(path
, PATH_MAX
);
1334 req
->NameLength
= cpu_to_le16(name_len
);
1335 strncpy(req
->fileName
, path
, name_len
);
1338 if (*oplock
& REQ_OPLOCK
)
1339 req
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
1340 else if (*oplock
& REQ_BATCHOPLOCK
)
1341 req
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
1343 req
->DesiredAccess
= cpu_to_le32(desired_access
);
1344 req
->AllocationSize
= 0;
1347 * Set file as system file if special file such as fifo and server
1348 * expecting SFU style and no Unix extensions.
1350 if (create_options
& CREATE_OPTION_SPECIAL
)
1351 req
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
1353 req
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
1356 * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case
1357 * sensitive checks for other servers such as Samba.
1359 if (tcon
->ses
->capabilities
& CAP_UNIX
)
1360 req
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
1362 if (create_options
& CREATE_OPTION_READONLY
)
1363 req
->FileAttributes
|= cpu_to_le32(ATTR_READONLY
);
1365 req
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
1366 req
->CreateDisposition
= cpu_to_le32(disposition
);
1367 req
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
1369 /* BB Expirement with various impersonation levels and verify */
1370 req
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
1371 req
->SecurityFlags
= SECURITY_CONTEXT_TRACKING
|SECURITY_EFFECTIVE_ONLY
;
1374 inc_rfc1001_len(req
, count
);
1376 req
->ByteCount
= cpu_to_le16(count
);
1377 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*)req
,
1378 (struct smb_hdr
*)rsp
, &bytes_returned
, 0);
1379 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_opens
);
1381 cifs_dbg(FYI
, "Error in Open = %d\n", rc
);
1382 cifs_buf_release(req
);
1388 /* 1 byte no need to le_to_cpu */
1389 *oplock
= rsp
->OplockLevel
;
1390 /* cifs fid stays in le */
1391 oparms
->fid
->netfid
= rsp
->Fid
;
1393 /* Let caller know file was created so we can set the mode. */
1394 /* Do we care about the CreateAction in any other cases? */
1395 if (cpu_to_le32(FILE_CREATE
) == rsp
->CreateAction
)
1396 *oplock
|= CIFS_CREATE_ACTION
;
1399 /* copy from CreationTime to Attributes */
1400 memcpy((char *)buf
, (char *)&rsp
->CreationTime
, 36);
1401 /* the file_info buf is endian converted by caller */
1402 buf
->AllocationSize
= rsp
->AllocationSize
;
1403 buf
->EndOfFile
= rsp
->EndOfFile
;
1404 buf
->NumberOfLinks
= cpu_to_le32(1);
1405 buf
->DeletePending
= 0;
1408 cifs_buf_release(req
);
1413 * Discard any remaining data in the current SMB. To do this, we borrow the
1417 cifs_discard_remaining_data(struct TCP_Server_Info
*server
)
1419 unsigned int rfclen
= get_rfc1002_length(server
->smallbuf
);
1420 int remaining
= rfclen
+ 4 - server
->total_read
;
1422 while (remaining
> 0) {
1425 length
= cifs_read_from_socket(server
, server
->bigbuf
,
1426 min_t(unsigned int, remaining
,
1427 CIFSMaxBufSize
+ MAX_HEADER_SIZE(server
)));
1430 server
->total_read
+= length
;
1431 remaining
-= length
;
1438 cifs_readv_discard(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
1441 struct cifs_readdata
*rdata
= mid
->callback_data
;
1443 length
= cifs_discard_remaining_data(server
);
1444 dequeue_mid(mid
, rdata
->result
);
1445 mid
->resp_buf
= server
->smallbuf
;
1446 server
->smallbuf
= NULL
;
1451 cifs_readv_receive(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
1454 unsigned int data_offset
, data_len
;
1455 struct cifs_readdata
*rdata
= mid
->callback_data
;
1456 char *buf
= server
->smallbuf
;
1457 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
1458 bool use_rdma_mr
= false;
1460 cifs_dbg(FYI
, "%s: mid=%llu offset=%llu bytes=%u\n",
1461 __func__
, mid
->mid
, rdata
->offset
, rdata
->bytes
);
1464 * read the rest of READ_RSP header (sans Data array), or whatever we
1465 * can if there's not enough data. At this point, we've read down to
1468 len
= min_t(unsigned int, buflen
, server
->vals
->read_rsp_size
) -
1469 HEADER_SIZE(server
) + 1;
1471 length
= cifs_read_from_socket(server
,
1472 buf
+ HEADER_SIZE(server
) - 1, len
);
1475 server
->total_read
+= length
;
1477 if (server
->ops
->is_session_expired
&&
1478 server
->ops
->is_session_expired(buf
)) {
1479 cifs_reconnect(server
);
1480 wake_up(&server
->response_q
);
1484 if (server
->ops
->is_status_pending
&&
1485 server
->ops
->is_status_pending(buf
, server
, 0)) {
1486 cifs_discard_remaining_data(server
);
1490 /* Was the SMB read successful? */
1491 rdata
->result
= server
->ops
->map_error(buf
, false);
1492 if (rdata
->result
!= 0) {
1493 cifs_dbg(FYI
, "%s: server returned error %d\n",
1494 __func__
, rdata
->result
);
1495 return cifs_readv_discard(server
, mid
);
1498 /* Is there enough to get to the rest of the READ_RSP header? */
1499 if (server
->total_read
< server
->vals
->read_rsp_size
) {
1500 cifs_dbg(FYI
, "%s: server returned short header. got=%u expected=%zu\n",
1501 __func__
, server
->total_read
,
1502 server
->vals
->read_rsp_size
);
1503 rdata
->result
= -EIO
;
1504 return cifs_readv_discard(server
, mid
);
1507 data_offset
= server
->ops
->read_data_offset(buf
) + 4;
1508 if (data_offset
< server
->total_read
) {
1510 * win2k8 sometimes sends an offset of 0 when the read
1511 * is beyond the EOF. Treat it as if the data starts just after
1514 cifs_dbg(FYI
, "%s: data offset (%u) inside read response header\n",
1515 __func__
, data_offset
);
1516 data_offset
= server
->total_read
;
1517 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
1518 /* data_offset is beyond the end of smallbuf */
1519 cifs_dbg(FYI
, "%s: data offset (%u) beyond end of smallbuf\n",
1520 __func__
, data_offset
);
1521 rdata
->result
= -EIO
;
1522 return cifs_readv_discard(server
, mid
);
1525 cifs_dbg(FYI
, "%s: total_read=%u data_offset=%u\n",
1526 __func__
, server
->total_read
, data_offset
);
1528 len
= data_offset
- server
->total_read
;
1530 /* read any junk before data into the rest of smallbuf */
1531 length
= cifs_read_from_socket(server
,
1532 buf
+ server
->total_read
, len
);
1535 server
->total_read
+= length
;
1538 /* set up first iov for signature check */
1539 rdata
->iov
[0].iov_base
= buf
;
1540 rdata
->iov
[0].iov_len
= 4;
1541 rdata
->iov
[1].iov_base
= buf
+ 4;
1542 rdata
->iov
[1].iov_len
= server
->total_read
- 4;
1543 cifs_dbg(FYI
, "0: iov_base=%p iov_len=%u\n",
1544 rdata
->iov
[0].iov_base
, server
->total_read
);
1546 /* how much data is in the response? */
1547 #ifdef CONFIG_CIFS_SMB_DIRECT
1548 use_rdma_mr
= rdata
->mr
;
1550 data_len
= server
->ops
->read_data_length(buf
, use_rdma_mr
);
1551 if (!use_rdma_mr
&& (data_offset
+ data_len
> buflen
)) {
1552 /* data_len is corrupt -- discard frame */
1553 rdata
->result
= -EIO
;
1554 return cifs_readv_discard(server
, mid
);
1557 length
= rdata
->read_into_pages(server
, rdata
, data_len
);
1561 server
->total_read
+= length
;
1563 cifs_dbg(FYI
, "total_read=%u buflen=%u remaining=%u\n",
1564 server
->total_read
, buflen
, data_len
);
1566 /* discard anything left over */
1567 if (server
->total_read
< buflen
)
1568 return cifs_readv_discard(server
, mid
);
1570 dequeue_mid(mid
, false);
1571 mid
->resp_buf
= server
->smallbuf
;
1572 server
->smallbuf
= NULL
;
1577 cifs_readv_callback(struct mid_q_entry
*mid
)
1579 struct cifs_readdata
*rdata
= mid
->callback_data
;
1580 struct cifs_tcon
*tcon
= tlink_tcon(rdata
->cfile
->tlink
);
1581 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
1582 struct smb_rqst rqst
= { .rq_iov
= rdata
->iov
,
1584 .rq_pages
= rdata
->pages
,
1585 .rq_npages
= rdata
->nr_pages
,
1586 .rq_pagesz
= rdata
->pagesz
,
1587 .rq_tailsz
= rdata
->tailsz
};
1589 cifs_dbg(FYI
, "%s: mid=%llu state=%d result=%d bytes=%u\n",
1590 __func__
, mid
->mid
, mid
->mid_state
, rdata
->result
,
1593 switch (mid
->mid_state
) {
1594 case MID_RESPONSE_RECEIVED
:
1595 /* result already set, check signature */
1599 rc
= cifs_verify_signature(&rqst
, server
,
1600 mid
->sequence_number
);
1602 cifs_dbg(VFS
, "SMB signature verification returned error = %d\n",
1605 /* FIXME: should this be counted toward the initiating task? */
1606 task_io_account_read(rdata
->got_bytes
);
1607 cifs_stats_bytes_read(tcon
, rdata
->got_bytes
);
1609 case MID_REQUEST_SUBMITTED
:
1610 case MID_RETRY_NEEDED
:
1611 rdata
->result
= -EAGAIN
;
1612 if (server
->sign
&& rdata
->got_bytes
)
1613 /* reset bytes number since we can not check a sign */
1614 rdata
->got_bytes
= 0;
1615 /* FIXME: should this be counted toward the initiating task? */
1616 task_io_account_read(rdata
->got_bytes
);
1617 cifs_stats_bytes_read(tcon
, rdata
->got_bytes
);
1620 rdata
->result
= -EIO
;
1623 queue_work(cifsiod_wq
, &rdata
->work
);
1624 DeleteMidQEntry(mid
);
1625 add_credits(server
, 1, 0);
1628 /* cifs_async_readv - send an async write, and set up mid to handle result */
1630 cifs_async_readv(struct cifs_readdata
*rdata
)
1633 READ_REQ
*smb
= NULL
;
1635 struct cifs_tcon
*tcon
= tlink_tcon(rdata
->cfile
->tlink
);
1636 struct smb_rqst rqst
= { .rq_iov
= rdata
->iov
,
1639 cifs_dbg(FYI
, "%s: offset=%llu bytes=%u\n",
1640 __func__
, rdata
->offset
, rdata
->bytes
);
1642 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1645 wct
= 10; /* old style read */
1646 if ((rdata
->offset
>> 32) > 0) {
1647 /* can not handle this big offset for old */
1652 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **)&smb
);
1656 smb
->hdr
.Pid
= cpu_to_le16((__u16
)rdata
->pid
);
1657 smb
->hdr
.PidHigh
= cpu_to_le16((__u16
)(rdata
->pid
>> 16));
1659 smb
->AndXCommand
= 0xFF; /* none */
1660 smb
->Fid
= rdata
->cfile
->fid
.netfid
;
1661 smb
->OffsetLow
= cpu_to_le32(rdata
->offset
& 0xFFFFFFFF);
1663 smb
->OffsetHigh
= cpu_to_le32(rdata
->offset
>> 32);
1665 smb
->MaxCount
= cpu_to_le16(rdata
->bytes
& 0xFFFF);
1666 smb
->MaxCountHigh
= cpu_to_le32(rdata
->bytes
>> 16);
1670 /* old style read */
1671 struct smb_com_readx_req
*smbr
=
1672 (struct smb_com_readx_req
*)smb
;
1673 smbr
->ByteCount
= 0;
1676 /* 4 for RFC1001 length + 1 for BCC */
1677 rdata
->iov
[0].iov_base
= smb
;
1678 rdata
->iov
[0].iov_len
= 4;
1679 rdata
->iov
[1].iov_base
= (char *)smb
+ 4;
1680 rdata
->iov
[1].iov_len
= get_rfc1002_length(smb
);
1682 kref_get(&rdata
->refcount
);
1683 rc
= cifs_call_async(tcon
->ses
->server
, &rqst
, cifs_readv_receive
,
1684 cifs_readv_callback
, NULL
, rdata
, 0);
1687 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_reads
);
1689 kref_put(&rdata
->refcount
, cifs_readdata_release
);
1691 cifs_small_buf_release(smb
);
1696 CIFSSMBRead(const unsigned int xid
, struct cifs_io_parms
*io_parms
,
1697 unsigned int *nbytes
, char **buf
, int *pbuf_type
)
1700 READ_REQ
*pSMB
= NULL
;
1701 READ_RSP
*pSMBr
= NULL
;
1702 char *pReadData
= NULL
;
1704 int resp_buf_type
= 0;
1706 struct kvec rsp_iov
;
1707 __u32 pid
= io_parms
->pid
;
1708 __u16 netfid
= io_parms
->netfid
;
1709 __u64 offset
= io_parms
->offset
;
1710 struct cifs_tcon
*tcon
= io_parms
->tcon
;
1711 unsigned int count
= io_parms
->length
;
1713 cifs_dbg(FYI
, "Reading %d bytes on fid %d\n", count
, netfid
);
1714 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1717 wct
= 10; /* old style read */
1718 if ((offset
>> 32) > 0) {
1719 /* can not handle this big offset for old */
1725 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
1729 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
1730 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
1732 /* tcon and ses pointer are checked in smb_init */
1733 if (tcon
->ses
->server
== NULL
)
1734 return -ECONNABORTED
;
1736 pSMB
->AndXCommand
= 0xFF; /* none */
1738 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1740 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1742 pSMB
->Remaining
= 0;
1743 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1744 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1746 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1748 /* old style read */
1749 struct smb_com_readx_req
*pSMBW
=
1750 (struct smb_com_readx_req
*)pSMB
;
1751 pSMBW
->ByteCount
= 0;
1754 iov
[0].iov_base
= (char *)pSMB
;
1755 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
1756 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1, &resp_buf_type
,
1757 CIFS_LOG_ERROR
, &rsp_iov
);
1758 cifs_small_buf_release(pSMB
);
1759 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_reads
);
1760 pSMBr
= (READ_RSP
*)rsp_iov
.iov_base
;
1762 cifs_dbg(VFS
, "Send error in read = %d\n", rc
);
1764 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1765 data_length
= data_length
<< 16;
1766 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1767 *nbytes
= data_length
;
1769 /*check that DataLength would not go beyond end of SMB */
1770 if ((data_length
> CIFSMaxBufSize
)
1771 || (data_length
> count
)) {
1772 cifs_dbg(FYI
, "bad length %d for count %d\n",
1773 data_length
, count
);
1777 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1778 le16_to_cpu(pSMBr
->DataOffset
);
1779 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1780 cifs_dbg(VFS, "Faulting on read rc = %d\n",rc);
1782 }*/ /* can not use copy_to_user when using page cache*/
1784 memcpy(*buf
, pReadData
, data_length
);
1789 free_rsp_buf(resp_buf_type
, rsp_iov
.iov_base
);
1790 } else if (resp_buf_type
!= CIFS_NO_BUFFER
) {
1791 /* return buffer to caller to free */
1792 *buf
= rsp_iov
.iov_base
;
1793 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1794 *pbuf_type
= CIFS_SMALL_BUFFER
;
1795 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1796 *pbuf_type
= CIFS_LARGE_BUFFER
;
1797 } /* else no valid buffer on return - leave as null */
1799 /* Note: On -EAGAIN error only caller can retry on handle based calls
1800 since file handle passed in no longer valid */
1806 CIFSSMBWrite(const unsigned int xid
, struct cifs_io_parms
*io_parms
,
1807 unsigned int *nbytes
, const char *buf
)
1810 WRITE_REQ
*pSMB
= NULL
;
1811 WRITE_RSP
*pSMBr
= NULL
;
1812 int bytes_returned
, wct
;
1815 __u32 pid
= io_parms
->pid
;
1816 __u16 netfid
= io_parms
->netfid
;
1817 __u64 offset
= io_parms
->offset
;
1818 struct cifs_tcon
*tcon
= io_parms
->tcon
;
1819 unsigned int count
= io_parms
->length
;
1823 /* cifs_dbg(FYI, "write at %lld %d bytes\n", offset, count);*/
1824 if (tcon
->ses
== NULL
)
1825 return -ECONNABORTED
;
1827 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1831 if ((offset
>> 32) > 0) {
1832 /* can not handle big offset for old srv */
1837 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1842 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
1843 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
1845 /* tcon and ses pointer are checked in smb_init */
1846 if (tcon
->ses
->server
== NULL
)
1847 return -ECONNABORTED
;
1849 pSMB
->AndXCommand
= 0xFF; /* none */
1851 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1853 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1855 pSMB
->Reserved
= 0xFFFFFFFF;
1856 pSMB
->WriteMode
= 0;
1857 pSMB
->Remaining
= 0;
1859 /* Can increase buffer size if buffer is big enough in some cases ie we
1860 can send more if LARGE_WRITE_X capability returned by the server and if
1861 our buffer is big enough or if we convert to iovecs on socket writes
1862 and eliminate the copy to the CIFS buffer */
1863 if (tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1864 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
1866 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
1870 if (bytes_sent
> count
)
1873 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1875 memcpy(pSMB
->Data
, buf
, bytes_sent
);
1876 else if (count
!= 0) {
1878 cifs_buf_release(pSMB
);
1880 } /* else setting file size with write of zero bytes */
1882 byte_count
= bytes_sent
+ 1; /* pad */
1883 else /* wct == 12 */
1884 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
1886 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
1887 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
1888 inc_rfc1001_len(pSMB
, byte_count
);
1891 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1892 else { /* old style write has byte count 4 bytes earlier
1894 struct smb_com_writex_req
*pSMBW
=
1895 (struct smb_com_writex_req
*)pSMB
;
1896 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
1899 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1900 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1901 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_writes
);
1903 cifs_dbg(FYI
, "Send error in write = %d\n", rc
);
1905 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1906 *nbytes
= (*nbytes
) << 16;
1907 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1910 * Mask off high 16 bits when bytes written as returned by the
1911 * server is greater than bytes requested by the client. Some
1912 * OS/2 servers are known to set incorrect CountHigh values.
1914 if (*nbytes
> count
)
1918 cifs_buf_release(pSMB
);
1920 /* Note: On -EAGAIN error only caller can retry on handle based calls
1921 since file handle passed in no longer valid */
1927 cifs_writedata_release(struct kref
*refcount
)
1929 struct cifs_writedata
*wdata
= container_of(refcount
,
1930 struct cifs_writedata
, refcount
);
1931 #ifdef CONFIG_CIFS_SMB_DIRECT
1933 smbd_deregister_mr(wdata
->mr
);
1939 cifsFileInfo_put(wdata
->cfile
);
1945 * Write failed with a retryable error. Resend the write request. It's also
1946 * possible that the page was redirtied so re-clean the page.
1949 cifs_writev_requeue(struct cifs_writedata
*wdata
)
1952 struct inode
*inode
= d_inode(wdata
->cfile
->dentry
);
1953 struct TCP_Server_Info
*server
;
1954 unsigned int rest_len
;
1956 server
= tlink_tcon(wdata
->cfile
->tlink
)->ses
->server
;
1958 rest_len
= wdata
->bytes
;
1960 struct cifs_writedata
*wdata2
;
1961 unsigned int j
, nr_pages
, wsize
, tailsz
, cur_len
;
1963 wsize
= server
->ops
->wp_retry_size(inode
);
1964 if (wsize
< rest_len
) {
1965 nr_pages
= wsize
/ PAGE_SIZE
;
1970 cur_len
= nr_pages
* PAGE_SIZE
;
1973 nr_pages
= DIV_ROUND_UP(rest_len
, PAGE_SIZE
);
1975 tailsz
= rest_len
- (nr_pages
- 1) * PAGE_SIZE
;
1978 wdata2
= cifs_writedata_alloc(nr_pages
, cifs_writev_complete
);
1984 for (j
= 0; j
< nr_pages
; j
++) {
1985 wdata2
->pages
[j
] = wdata
->pages
[i
+ j
];
1986 lock_page(wdata2
->pages
[j
]);
1987 clear_page_dirty_for_io(wdata2
->pages
[j
]);
1990 wdata2
->sync_mode
= wdata
->sync_mode
;
1991 wdata2
->nr_pages
= nr_pages
;
1992 wdata2
->offset
= page_offset(wdata2
->pages
[0]);
1993 wdata2
->pagesz
= PAGE_SIZE
;
1994 wdata2
->tailsz
= tailsz
;
1995 wdata2
->bytes
= cur_len
;
1997 wdata2
->cfile
= find_writable_file(CIFS_I(inode
), false);
1998 if (!wdata2
->cfile
) {
1999 cifs_dbg(VFS
, "No writable handles for inode\n");
2003 wdata2
->pid
= wdata2
->cfile
->pid
;
2004 rc
= server
->ops
->async_writev(wdata2
, cifs_writedata_release
);
2006 for (j
= 0; j
< nr_pages
; j
++) {
2007 unlock_page(wdata2
->pages
[j
]);
2008 if (rc
!= 0 && rc
!= -EAGAIN
) {
2009 SetPageError(wdata2
->pages
[j
]);
2010 end_page_writeback(wdata2
->pages
[j
]);
2011 put_page(wdata2
->pages
[j
]);
2016 kref_put(&wdata2
->refcount
, cifs_writedata_release
);
2022 rest_len
-= cur_len
;
2024 } while (i
< wdata
->nr_pages
);
2026 mapping_set_error(inode
->i_mapping
, rc
);
2027 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2031 cifs_writev_complete(struct work_struct
*work
)
2033 struct cifs_writedata
*wdata
= container_of(work
,
2034 struct cifs_writedata
, work
);
2035 struct inode
*inode
= d_inode(wdata
->cfile
->dentry
);
2038 if (wdata
->result
== 0) {
2039 spin_lock(&inode
->i_lock
);
2040 cifs_update_eof(CIFS_I(inode
), wdata
->offset
, wdata
->bytes
);
2041 spin_unlock(&inode
->i_lock
);
2042 cifs_stats_bytes_written(tlink_tcon(wdata
->cfile
->tlink
),
2044 } else if (wdata
->sync_mode
== WB_SYNC_ALL
&& wdata
->result
== -EAGAIN
)
2045 return cifs_writev_requeue(wdata
);
2047 for (i
= 0; i
< wdata
->nr_pages
; i
++) {
2048 struct page
*page
= wdata
->pages
[i
];
2049 if (wdata
->result
== -EAGAIN
)
2050 __set_page_dirty_nobuffers(page
);
2051 else if (wdata
->result
< 0)
2053 end_page_writeback(page
);
2056 if (wdata
->result
!= -EAGAIN
)
2057 mapping_set_error(inode
->i_mapping
, wdata
->result
);
2058 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2061 struct cifs_writedata
*
2062 cifs_writedata_alloc(unsigned int nr_pages
, work_func_t complete
)
2064 struct cifs_writedata
*wdata
;
2066 /* writedata + number of page pointers */
2067 wdata
= kzalloc(sizeof(*wdata
) +
2068 sizeof(struct page
*) * nr_pages
, GFP_NOFS
);
2069 if (wdata
!= NULL
) {
2070 kref_init(&wdata
->refcount
);
2071 INIT_LIST_HEAD(&wdata
->list
);
2072 init_completion(&wdata
->done
);
2073 INIT_WORK(&wdata
->work
, complete
);
2079 * Check the mid_state and signature on received buffer (if any), and queue the
2080 * workqueue completion task.
2083 cifs_writev_callback(struct mid_q_entry
*mid
)
2085 struct cifs_writedata
*wdata
= mid
->callback_data
;
2086 struct cifs_tcon
*tcon
= tlink_tcon(wdata
->cfile
->tlink
);
2087 unsigned int written
;
2088 WRITE_RSP
*smb
= (WRITE_RSP
*)mid
->resp_buf
;
2090 switch (mid
->mid_state
) {
2091 case MID_RESPONSE_RECEIVED
:
2092 wdata
->result
= cifs_check_receive(mid
, tcon
->ses
->server
, 0);
2093 if (wdata
->result
!= 0)
2096 written
= le16_to_cpu(smb
->CountHigh
);
2098 written
+= le16_to_cpu(smb
->Count
);
2100 * Mask off high 16 bits when bytes written as returned
2101 * by the server is greater than bytes requested by the
2102 * client. OS/2 servers are known to set incorrect
2105 if (written
> wdata
->bytes
)
2108 if (written
< wdata
->bytes
)
2109 wdata
->result
= -ENOSPC
;
2111 wdata
->bytes
= written
;
2113 case MID_REQUEST_SUBMITTED
:
2114 case MID_RETRY_NEEDED
:
2115 wdata
->result
= -EAGAIN
;
2118 wdata
->result
= -EIO
;
2122 queue_work(cifsiod_wq
, &wdata
->work
);
2123 DeleteMidQEntry(mid
);
2124 add_credits(tcon
->ses
->server
, 1, 0);
2127 /* cifs_async_writev - send an async write, and set up mid to handle result */
2129 cifs_async_writev(struct cifs_writedata
*wdata
,
2130 void (*release
)(struct kref
*kref
))
2133 WRITE_REQ
*smb
= NULL
;
2135 struct cifs_tcon
*tcon
= tlink_tcon(wdata
->cfile
->tlink
);
2137 struct smb_rqst rqst
= { };
2139 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
2143 if (wdata
->offset
>> 32 > 0) {
2144 /* can not handle big offset for old srv */
2149 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **)&smb
);
2151 goto async_writev_out
;
2153 smb
->hdr
.Pid
= cpu_to_le16((__u16
)wdata
->pid
);
2154 smb
->hdr
.PidHigh
= cpu_to_le16((__u16
)(wdata
->pid
>> 16));
2156 smb
->AndXCommand
= 0xFF; /* none */
2157 smb
->Fid
= wdata
->cfile
->fid
.netfid
;
2158 smb
->OffsetLow
= cpu_to_le32(wdata
->offset
& 0xFFFFFFFF);
2160 smb
->OffsetHigh
= cpu_to_le32(wdata
->offset
>> 32);
2161 smb
->Reserved
= 0xFFFFFFFF;
2166 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2168 /* 4 for RFC1001 length + 1 for BCC */
2170 iov
[0].iov_base
= smb
;
2171 iov
[1].iov_len
= get_rfc1002_length(smb
) + 1;
2172 iov
[1].iov_base
= (char *)smb
+ 4;
2176 rqst
.rq_pages
= wdata
->pages
;
2177 rqst
.rq_npages
= wdata
->nr_pages
;
2178 rqst
.rq_pagesz
= wdata
->pagesz
;
2179 rqst
.rq_tailsz
= wdata
->tailsz
;
2181 cifs_dbg(FYI
, "async write at %llu %u bytes\n",
2182 wdata
->offset
, wdata
->bytes
);
2184 smb
->DataLengthLow
= cpu_to_le16(wdata
->bytes
& 0xFFFF);
2185 smb
->DataLengthHigh
= cpu_to_le16(wdata
->bytes
>> 16);
2188 inc_rfc1001_len(&smb
->hdr
, wdata
->bytes
+ 1);
2189 put_bcc(wdata
->bytes
+ 1, &smb
->hdr
);
2192 struct smb_com_writex_req
*smbw
=
2193 (struct smb_com_writex_req
*)smb
;
2194 inc_rfc1001_len(&smbw
->hdr
, wdata
->bytes
+ 5);
2195 put_bcc(wdata
->bytes
+ 5, &smbw
->hdr
);
2196 iov
[1].iov_len
+= 4; /* pad bigger by four bytes */
2199 kref_get(&wdata
->refcount
);
2200 rc
= cifs_call_async(tcon
->ses
->server
, &rqst
, NULL
,
2201 cifs_writev_callback
, NULL
, wdata
, 0);
2204 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_writes
);
2206 kref_put(&wdata
->refcount
, release
);
2209 cifs_small_buf_release(smb
);
2214 CIFSSMBWrite2(const unsigned int xid
, struct cifs_io_parms
*io_parms
,
2215 unsigned int *nbytes
, struct kvec
*iov
, int n_vec
)
2218 WRITE_REQ
*pSMB
= NULL
;
2221 int resp_buf_type
= 0;
2222 __u32 pid
= io_parms
->pid
;
2223 __u16 netfid
= io_parms
->netfid
;
2224 __u64 offset
= io_parms
->offset
;
2225 struct cifs_tcon
*tcon
= io_parms
->tcon
;
2226 unsigned int count
= io_parms
->length
;
2227 struct kvec rsp_iov
;
2231 cifs_dbg(FYI
, "write2 at %lld %d bytes\n", (long long)offset
, count
);
2233 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
2237 if ((offset
>> 32) > 0) {
2238 /* can not handle big offset for old srv */
2242 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
2246 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
2247 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
2249 /* tcon and ses pointer are checked in smb_init */
2250 if (tcon
->ses
->server
== NULL
)
2251 return -ECONNABORTED
;
2253 pSMB
->AndXCommand
= 0xFF; /* none */
2255 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
2257 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
2258 pSMB
->Reserved
= 0xFFFFFFFF;
2259 pSMB
->WriteMode
= 0;
2260 pSMB
->Remaining
= 0;
2263 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2265 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
2266 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
2267 /* header + 1 byte pad */
2268 smb_hdr_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 1;
2270 inc_rfc1001_len(pSMB
, count
+ 1);
2271 else /* wct == 12 */
2272 inc_rfc1001_len(pSMB
, count
+ 5); /* smb data starts later */
2274 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
2275 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
2276 struct smb_com_writex_req
*pSMBW
=
2277 (struct smb_com_writex_req
*)pSMB
;
2278 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
2280 iov
[0].iov_base
= pSMB
;
2282 iov
[0].iov_len
= smb_hdr_len
+ 4;
2283 else /* wct == 12 pad bigger by four bytes */
2284 iov
[0].iov_len
= smb_hdr_len
+ 8;
2286 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
, 0,
2288 cifs_small_buf_release(pSMB
);
2289 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_writes
);
2291 cifs_dbg(FYI
, "Send error Write2 = %d\n", rc
);
2292 } else if (resp_buf_type
== 0) {
2293 /* presumably this can not happen, but best to be safe */
2296 WRITE_RSP
*pSMBr
= (WRITE_RSP
*)rsp_iov
.iov_base
;
2297 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
2298 *nbytes
= (*nbytes
) << 16;
2299 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
2302 * Mask off high 16 bits when bytes written as returned by the
2303 * server is greater than bytes requested by the client. OS/2
2304 * servers are known to set incorrect CountHigh values.
2306 if (*nbytes
> count
)
2310 free_rsp_buf(resp_buf_type
, rsp_iov
.iov_base
);
2312 /* Note: On -EAGAIN error only caller can retry on handle based calls
2313 since file handle passed in no longer valid */
2318 int cifs_lockv(const unsigned int xid
, struct cifs_tcon
*tcon
,
2319 const __u16 netfid
, const __u8 lock_type
, const __u32 num_unlock
,
2320 const __u32 num_lock
, LOCKING_ANDX_RANGE
*buf
)
2323 LOCK_REQ
*pSMB
= NULL
;
2325 struct kvec rsp_iov
;
2329 cifs_dbg(FYI
, "cifs_lockv num lock %d num unlock %d\n",
2330 num_lock
, num_unlock
);
2332 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
2337 pSMB
->NumberOfLocks
= cpu_to_le16(num_lock
);
2338 pSMB
->NumberOfUnlocks
= cpu_to_le16(num_unlock
);
2339 pSMB
->LockType
= lock_type
;
2340 pSMB
->AndXCommand
= 0xFF; /* none */
2341 pSMB
->Fid
= netfid
; /* netfid stays le */
2343 count
= (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2344 inc_rfc1001_len(pSMB
, count
);
2345 pSMB
->ByteCount
= cpu_to_le16(count
);
2347 iov
[0].iov_base
= (char *)pSMB
;
2348 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4 -
2349 (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2350 iov
[1].iov_base
= (char *)buf
;
2351 iov
[1].iov_len
= (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2353 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_locks
);
2354 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 2, &resp_buf_type
, CIFS_NO_RESP
,
2356 cifs_small_buf_release(pSMB
);
2358 cifs_dbg(FYI
, "Send error in cifs_lockv = %d\n", rc
);
2364 CIFSSMBLock(const unsigned int xid
, struct cifs_tcon
*tcon
,
2365 const __u16 smb_file_id
, const __u32 netpid
, const __u64 len
,
2366 const __u64 offset
, const __u32 numUnlock
,
2367 const __u32 numLock
, const __u8 lockType
,
2368 const bool waitFlag
, const __u8 oplock_level
)
2371 LOCK_REQ
*pSMB
= NULL
;
2372 /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
2377 cifs_dbg(FYI
, "CIFSSMBLock timeout %d numLock %d\n",
2378 (int)waitFlag
, numLock
);
2379 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
2384 if (lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
2385 /* no response expected */
2386 flags
= CIFS_ASYNC_OP
| CIFS_OBREAK_OP
;
2388 } else if (waitFlag
) {
2389 flags
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
2390 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
2395 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
2396 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
2397 pSMB
->LockType
= lockType
;
2398 pSMB
->OplockLevel
= oplock_level
;
2399 pSMB
->AndXCommand
= 0xFF; /* none */
2400 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
2402 if ((numLock
!= 0) || (numUnlock
!= 0)) {
2403 pSMB
->Locks
[0].Pid
= cpu_to_le16(netpid
);
2404 /* BB where to store pid high? */
2405 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
2406 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
2407 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
2408 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
2409 count
= sizeof(LOCKING_ANDX_RANGE
);
2414 inc_rfc1001_len(pSMB
, count
);
2415 pSMB
->ByteCount
= cpu_to_le16(count
);
2418 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
2419 (struct smb_hdr
*) pSMB
, &bytes_returned
);
2421 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *)pSMB
, flags
);
2422 cifs_small_buf_release(pSMB
);
2423 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_locks
);
2425 cifs_dbg(FYI
, "Send error in Lock = %d\n", rc
);
2427 /* Note: On -EAGAIN error only caller can retry on handle based calls
2428 since file handle passed in no longer valid */
2433 CIFSSMBPosixLock(const unsigned int xid
, struct cifs_tcon
*tcon
,
2434 const __u16 smb_file_id
, const __u32 netpid
,
2435 const loff_t start_offset
, const __u64 len
,
2436 struct file_lock
*pLockData
, const __u16 lock_type
,
2437 const bool waitFlag
)
2439 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2440 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2441 struct cifs_posix_lock
*parm_data
;
2444 int bytes_returned
= 0;
2445 int resp_buf_type
= 0;
2446 __u16 params
, param_offset
, offset
, byte_count
, count
;
2448 struct kvec rsp_iov
;
2450 cifs_dbg(FYI
, "Posix Lock\n");
2452 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
2457 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
2460 pSMB
->MaxSetupCount
= 0;
2463 pSMB
->Reserved2
= 0;
2464 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2465 offset
= param_offset
+ params
;
2467 count
= sizeof(struct cifs_posix_lock
);
2468 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2469 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2470 pSMB
->SetupCount
= 1;
2471 pSMB
->Reserved3
= 0;
2473 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
2475 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2476 byte_count
= 3 /* pad */ + params
+ count
;
2477 pSMB
->DataCount
= cpu_to_le16(count
);
2478 pSMB
->ParameterCount
= cpu_to_le16(params
);
2479 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2480 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2481 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2482 parm_data
= (struct cifs_posix_lock
*)
2483 (((char *) &pSMB
->hdr
.Protocol
) + offset
);
2485 parm_data
->lock_type
= cpu_to_le16(lock_type
);
2487 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
2488 parm_data
->lock_flags
= cpu_to_le16(1);
2489 pSMB
->Timeout
= cpu_to_le32(-1);
2493 parm_data
->pid
= cpu_to_le32(netpid
);
2494 parm_data
->start
= cpu_to_le64(start_offset
);
2495 parm_data
->length
= cpu_to_le64(len
); /* normalize negative numbers */
2497 pSMB
->DataOffset
= cpu_to_le16(offset
);
2498 pSMB
->Fid
= smb_file_id
;
2499 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_LOCK
);
2500 pSMB
->Reserved4
= 0;
2501 inc_rfc1001_len(pSMB
, byte_count
);
2502 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2504 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
2505 (struct smb_hdr
*) pSMBr
, &bytes_returned
);
2507 iov
[0].iov_base
= (char *)pSMB
;
2508 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
2509 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
2510 &resp_buf_type
, timeout
, &rsp_iov
);
2511 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)rsp_iov
.iov_base
;
2513 cifs_small_buf_release(pSMB
);
2516 cifs_dbg(FYI
, "Send error in Posix Lock = %d\n", rc
);
2517 } else if (pLockData
) {
2518 /* lock structure can be returned on get */
2521 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2523 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(*parm_data
)) {
2524 rc
= -EIO
; /* bad smb */
2527 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2528 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2529 if (data_count
< sizeof(struct cifs_posix_lock
)) {
2533 parm_data
= (struct cifs_posix_lock
*)
2534 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
2535 if (parm_data
->lock_type
== cpu_to_le16(CIFS_UNLCK
))
2536 pLockData
->fl_type
= F_UNLCK
;
2538 if (parm_data
->lock_type
==
2539 cpu_to_le16(CIFS_RDLCK
))
2540 pLockData
->fl_type
= F_RDLCK
;
2541 else if (parm_data
->lock_type
==
2542 cpu_to_le16(CIFS_WRLCK
))
2543 pLockData
->fl_type
= F_WRLCK
;
2545 pLockData
->fl_start
= le64_to_cpu(parm_data
->start
);
2546 pLockData
->fl_end
= pLockData
->fl_start
+
2547 le64_to_cpu(parm_data
->length
) - 1;
2548 pLockData
->fl_pid
= -le32_to_cpu(parm_data
->pid
);
2553 free_rsp_buf(resp_buf_type
, rsp_iov
.iov_base
);
2555 /* Note: On -EAGAIN error only caller can retry on handle based calls
2556 since file handle passed in no longer valid */
2563 CIFSSMBClose(const unsigned int xid
, struct cifs_tcon
*tcon
, int smb_file_id
)
2566 CLOSE_REQ
*pSMB
= NULL
;
2567 cifs_dbg(FYI
, "In CIFSSMBClose\n");
2569 /* do not retry on dead session on close */
2570 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
2576 pSMB
->FileID
= (__u16
) smb_file_id
;
2577 pSMB
->LastWriteTime
= 0xFFFFFFFF;
2578 pSMB
->ByteCount
= 0;
2579 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
2580 cifs_small_buf_release(pSMB
);
2581 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_closes
);
2584 /* EINTR is expected when user ctl-c to kill app */
2585 cifs_dbg(VFS
, "Send error in Close = %d\n", rc
);
2589 /* Since session is dead, file will be closed on server already */
2597 CIFSSMBFlush(const unsigned int xid
, struct cifs_tcon
*tcon
, int smb_file_id
)
2600 FLUSH_REQ
*pSMB
= NULL
;
2601 cifs_dbg(FYI
, "In CIFSSMBFlush\n");
2603 rc
= small_smb_init(SMB_COM_FLUSH
, 1, tcon
, (void **) &pSMB
);
2607 pSMB
->FileID
= (__u16
) smb_file_id
;
2608 pSMB
->ByteCount
= 0;
2609 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
2610 cifs_small_buf_release(pSMB
);
2611 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_flushes
);
2613 cifs_dbg(VFS
, "Send error in Flush = %d\n", rc
);
2619 CIFSSMBRename(const unsigned int xid
, struct cifs_tcon
*tcon
,
2620 const char *from_name
, const char *to_name
,
2621 struct cifs_sb_info
*cifs_sb
)
2624 RENAME_REQ
*pSMB
= NULL
;
2625 RENAME_RSP
*pSMBr
= NULL
;
2627 int name_len
, name_len2
;
2629 int remap
= cifs_remap(cifs_sb
);
2631 cifs_dbg(FYI
, "In CIFSSMBRename\n");
2633 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
2638 pSMB
->BufferFormat
= 0x04;
2639 pSMB
->SearchAttributes
=
2640 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2643 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2644 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
,
2645 from_name
, PATH_MAX
,
2646 cifs_sb
->local_nls
, remap
);
2647 name_len
++; /* trailing null */
2649 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2650 /* protocol requires ASCII signature byte on Unicode string */
2651 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2653 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
2654 to_name
, PATH_MAX
, cifs_sb
->local_nls
,
2656 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2657 name_len2
*= 2; /* convert to bytes */
2658 } else { /* BB improve the check for buffer overruns BB */
2659 name_len
= strnlen(from_name
, PATH_MAX
);
2660 name_len
++; /* trailing null */
2661 strncpy(pSMB
->OldFileName
, from_name
, name_len
);
2662 name_len2
= strnlen(to_name
, PATH_MAX
);
2663 name_len2
++; /* trailing null */
2664 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2665 strncpy(&pSMB
->OldFileName
[name_len
+ 1], to_name
, name_len2
);
2666 name_len2
++; /* trailing null */
2667 name_len2
++; /* signature byte */
2670 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2671 inc_rfc1001_len(pSMB
, count
);
2672 pSMB
->ByteCount
= cpu_to_le16(count
);
2674 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2675 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2676 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_renames
);
2678 cifs_dbg(FYI
, "Send error in rename = %d\n", rc
);
2680 cifs_buf_release(pSMB
);
2688 int CIFSSMBRenameOpenFile(const unsigned int xid
, struct cifs_tcon
*pTcon
,
2689 int netfid
, const char *target_name
,
2690 const struct nls_table
*nls_codepage
, int remap
)
2692 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2693 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2694 struct set_file_rename
*rename_info
;
2696 char dummy_string
[30];
2698 int bytes_returned
= 0;
2700 __u16 params
, param_offset
, offset
, count
, byte_count
;
2702 cifs_dbg(FYI
, "Rename to File by handle\n");
2703 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
2709 pSMB
->MaxSetupCount
= 0;
2713 pSMB
->Reserved2
= 0;
2714 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2715 offset
= param_offset
+ params
;
2717 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2718 rename_info
= (struct set_file_rename
*) data_offset
;
2719 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2720 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2721 pSMB
->SetupCount
= 1;
2722 pSMB
->Reserved3
= 0;
2723 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2724 byte_count
= 3 /* pad */ + params
;
2725 pSMB
->ParameterCount
= cpu_to_le16(params
);
2726 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2727 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2728 pSMB
->DataOffset
= cpu_to_le16(offset
);
2729 /* construct random name ".cifs_tmp<inodenum><mid>" */
2730 rename_info
->overwrite
= cpu_to_le32(1);
2731 rename_info
->root_fid
= 0;
2732 /* unicode only call */
2733 if (target_name
== NULL
) {
2734 sprintf(dummy_string
, "cifs%x", pSMB
->hdr
.Mid
);
2736 cifsConvertToUTF16((__le16
*)rename_info
->target_name
,
2737 dummy_string
, 24, nls_codepage
, remap
);
2740 cifsConvertToUTF16((__le16
*)rename_info
->target_name
,
2741 target_name
, PATH_MAX
, nls_codepage
,
2744 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
2745 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
);
2746 byte_count
+= count
;
2747 pSMB
->DataCount
= cpu_to_le16(count
);
2748 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2750 pSMB
->InformationLevel
=
2751 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
2752 pSMB
->Reserved4
= 0;
2753 inc_rfc1001_len(pSMB
, byte_count
);
2754 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2755 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
2756 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2757 cifs_stats_inc(&pTcon
->stats
.cifs_stats
.num_t2renames
);
2759 cifs_dbg(FYI
, "Send error in Rename (by file handle) = %d\n",
2762 cifs_buf_release(pSMB
);
2764 /* Note: On -EAGAIN error only caller can retry on handle based calls
2765 since file handle passed in no longer valid */
2771 CIFSSMBCopy(const unsigned int xid
, struct cifs_tcon
*tcon
,
2772 const char *fromName
, const __u16 target_tid
, const char *toName
,
2773 const int flags
, const struct nls_table
*nls_codepage
, int remap
)
2776 COPY_REQ
*pSMB
= NULL
;
2777 COPY_RSP
*pSMBr
= NULL
;
2779 int name_len
, name_len2
;
2782 cifs_dbg(FYI
, "In CIFSSMBCopy\n");
2784 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
2789 pSMB
->BufferFormat
= 0x04;
2790 pSMB
->Tid2
= target_tid
;
2792 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
2794 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2795 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
,
2796 fromName
, PATH_MAX
, nls_codepage
,
2798 name_len
++; /* trailing null */
2800 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2801 /* protocol requires ASCII signature byte on Unicode string */
2802 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2804 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
2805 toName
, PATH_MAX
, nls_codepage
, remap
);
2806 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2807 name_len2
*= 2; /* convert to bytes */
2808 } else { /* BB improve the check for buffer overruns BB */
2809 name_len
= strnlen(fromName
, PATH_MAX
);
2810 name_len
++; /* trailing null */
2811 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2812 name_len2
= strnlen(toName
, PATH_MAX
);
2813 name_len2
++; /* trailing null */
2814 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2815 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2816 name_len2
++; /* trailing null */
2817 name_len2
++; /* signature byte */
2820 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2821 inc_rfc1001_len(pSMB
, count
);
2822 pSMB
->ByteCount
= cpu_to_le16(count
);
2824 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2825 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2827 cifs_dbg(FYI
, "Send error in copy = %d with %d files copied\n",
2828 rc
, le16_to_cpu(pSMBr
->CopyCount
));
2830 cifs_buf_release(pSMB
);
2839 CIFSUnixCreateSymLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
2840 const char *fromName
, const char *toName
,
2841 const struct nls_table
*nls_codepage
, int remap
)
2843 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2844 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2847 int name_len_target
;
2849 int bytes_returned
= 0;
2850 __u16 params
, param_offset
, offset
, byte_count
;
2852 cifs_dbg(FYI
, "In Symlink Unix style\n");
2854 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2859 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2861 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fromName
,
2862 /* find define for this maxpathcomponent */
2863 PATH_MAX
, nls_codepage
, remap
);
2864 name_len
++; /* trailing null */
2867 } else { /* BB improve the check for buffer overruns BB */
2868 name_len
= strnlen(fromName
, PATH_MAX
);
2869 name_len
++; /* trailing null */
2870 strncpy(pSMB
->FileName
, fromName
, name_len
);
2872 params
= 6 + name_len
;
2873 pSMB
->MaxSetupCount
= 0;
2877 pSMB
->Reserved2
= 0;
2878 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2879 InformationLevel
) - 4;
2880 offset
= param_offset
+ params
;
2882 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2883 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2885 cifsConvertToUTF16((__le16
*) data_offset
, toName
,
2886 /* find define for this maxpathcomponent */
2887 PATH_MAX
, nls_codepage
, remap
);
2888 name_len_target
++; /* trailing null */
2889 name_len_target
*= 2;
2890 } else { /* BB improve the check for buffer overruns BB */
2891 name_len_target
= strnlen(toName
, PATH_MAX
);
2892 name_len_target
++; /* trailing null */
2893 strncpy(data_offset
, toName
, name_len_target
);
2896 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2897 /* BB find exact max on data count below from sess */
2898 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2899 pSMB
->SetupCount
= 1;
2900 pSMB
->Reserved3
= 0;
2901 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2902 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2903 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2904 pSMB
->ParameterCount
= cpu_to_le16(params
);
2905 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2906 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2907 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2908 pSMB
->DataOffset
= cpu_to_le16(offset
);
2909 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
2910 pSMB
->Reserved4
= 0;
2911 inc_rfc1001_len(pSMB
, byte_count
);
2912 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2913 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2914 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2915 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_symlinks
);
2917 cifs_dbg(FYI
, "Send error in SetPathInfo create symlink = %d\n",
2920 cifs_buf_release(pSMB
);
2923 goto createSymLinkRetry
;
2929 CIFSUnixCreateHardLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
2930 const char *fromName
, const char *toName
,
2931 const struct nls_table
*nls_codepage
, int remap
)
2933 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2934 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2937 int name_len_target
;
2939 int bytes_returned
= 0;
2940 __u16 params
, param_offset
, offset
, byte_count
;
2942 cifs_dbg(FYI
, "In Create Hard link Unix style\n");
2943 createHardLinkRetry
:
2944 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2949 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2950 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->FileName
, toName
,
2951 PATH_MAX
, nls_codepage
, remap
);
2952 name_len
++; /* trailing null */
2955 } else { /* BB improve the check for buffer overruns BB */
2956 name_len
= strnlen(toName
, PATH_MAX
);
2957 name_len
++; /* trailing null */
2958 strncpy(pSMB
->FileName
, toName
, name_len
);
2960 params
= 6 + name_len
;
2961 pSMB
->MaxSetupCount
= 0;
2965 pSMB
->Reserved2
= 0;
2966 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2967 InformationLevel
) - 4;
2968 offset
= param_offset
+ params
;
2970 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2971 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2973 cifsConvertToUTF16((__le16
*) data_offset
, fromName
,
2974 PATH_MAX
, nls_codepage
, remap
);
2975 name_len_target
++; /* trailing null */
2976 name_len_target
*= 2;
2977 } else { /* BB improve the check for buffer overruns BB */
2978 name_len_target
= strnlen(fromName
, PATH_MAX
);
2979 name_len_target
++; /* trailing null */
2980 strncpy(data_offset
, fromName
, name_len_target
);
2983 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2984 /* BB find exact max on data count below from sess*/
2985 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2986 pSMB
->SetupCount
= 1;
2987 pSMB
->Reserved3
= 0;
2988 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2989 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2990 pSMB
->ParameterCount
= cpu_to_le16(params
);
2991 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2992 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2993 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2994 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2995 pSMB
->DataOffset
= cpu_to_le16(offset
);
2996 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
2997 pSMB
->Reserved4
= 0;
2998 inc_rfc1001_len(pSMB
, byte_count
);
2999 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3000 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3001 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3002 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_hardlinks
);
3004 cifs_dbg(FYI
, "Send error in SetPathInfo (hard link) = %d\n",
3007 cifs_buf_release(pSMB
);
3009 goto createHardLinkRetry
;
3015 CIFSCreateHardLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3016 const char *from_name
, const char *to_name
,
3017 struct cifs_sb_info
*cifs_sb
)
3020 NT_RENAME_REQ
*pSMB
= NULL
;
3021 RENAME_RSP
*pSMBr
= NULL
;
3023 int name_len
, name_len2
;
3025 int remap
= cifs_remap(cifs_sb
);
3027 cifs_dbg(FYI
, "In CIFSCreateHardLink\n");
3028 winCreateHardLinkRetry
:
3030 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
3035 pSMB
->SearchAttributes
=
3036 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
3038 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
3039 pSMB
->ClusterCount
= 0;
3041 pSMB
->BufferFormat
= 0x04;
3043 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3045 cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
, from_name
,
3046 PATH_MAX
, cifs_sb
->local_nls
, remap
);
3047 name_len
++; /* trailing null */
3050 /* protocol specifies ASCII buffer format (0x04) for unicode */
3051 pSMB
->OldFileName
[name_len
] = 0x04;
3052 pSMB
->OldFileName
[name_len
+ 1] = 0x00; /* pad */
3054 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
3055 to_name
, PATH_MAX
, cifs_sb
->local_nls
,
3057 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
3058 name_len2
*= 2; /* convert to bytes */
3059 } else { /* BB improve the check for buffer overruns BB */
3060 name_len
= strnlen(from_name
, PATH_MAX
);
3061 name_len
++; /* trailing null */
3062 strncpy(pSMB
->OldFileName
, from_name
, name_len
);
3063 name_len2
= strnlen(to_name
, PATH_MAX
);
3064 name_len2
++; /* trailing null */
3065 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
3066 strncpy(&pSMB
->OldFileName
[name_len
+ 1], to_name
, name_len2
);
3067 name_len2
++; /* trailing null */
3068 name_len2
++; /* signature byte */
3071 count
= 1 /* string type byte */ + name_len
+ name_len2
;
3072 inc_rfc1001_len(pSMB
, count
);
3073 pSMB
->ByteCount
= cpu_to_le16(count
);
3075 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3076 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3077 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_hardlinks
);
3079 cifs_dbg(FYI
, "Send error in hard link (NT rename) = %d\n", rc
);
3081 cifs_buf_release(pSMB
);
3083 goto winCreateHardLinkRetry
;
3089 CIFSSMBUnixQuerySymLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3090 const unsigned char *searchName
, char **symlinkinfo
,
3091 const struct nls_table
*nls_codepage
, int remap
)
3093 /* SMB_QUERY_FILE_UNIX_LINK */
3094 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3095 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3099 __u16 params
, byte_count
;
3102 cifs_dbg(FYI
, "In QPathSymLinkInfo (Unix) for path %s\n", searchName
);
3105 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3110 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3112 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
3113 searchName
, PATH_MAX
, nls_codepage
,
3115 name_len
++; /* trailing null */
3117 } else { /* BB improve the check for buffer overruns BB */
3118 name_len
= strnlen(searchName
, PATH_MAX
);
3119 name_len
++; /* trailing null */
3120 strncpy(pSMB
->FileName
, searchName
, name_len
);
3123 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3124 pSMB
->TotalDataCount
= 0;
3125 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3126 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
3127 pSMB
->MaxSetupCount
= 0;
3131 pSMB
->Reserved2
= 0;
3132 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3133 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3134 pSMB
->DataCount
= 0;
3135 pSMB
->DataOffset
= 0;
3136 pSMB
->SetupCount
= 1;
3137 pSMB
->Reserved3
= 0;
3138 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3139 byte_count
= params
+ 1 /* pad */ ;
3140 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3141 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3142 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
3143 pSMB
->Reserved4
= 0;
3144 inc_rfc1001_len(pSMB
, byte_count
);
3145 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3147 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3148 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3150 cifs_dbg(FYI
, "Send error in QuerySymLinkInfo = %d\n", rc
);
3152 /* decode response */
3154 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3155 /* BB also check enough total bytes returned */
3156 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3160 u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3162 data_start
= ((char *) &pSMBr
->hdr
.Protocol
) +
3163 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3165 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3170 /* BB FIXME investigate remapping reserved chars here */
3171 *symlinkinfo
= cifs_strndup_from_utf16(data_start
,
3172 count
, is_unicode
, nls_codepage
);
3177 cifs_buf_release(pSMB
);
3179 goto querySymLinkRetry
;
3184 * Recent Windows versions now create symlinks more frequently
3185 * and they use the "reparse point" mechanism below. We can of course
3186 * do symlinks nicely to Samba and other servers which support the
3187 * CIFS Unix Extensions and we can also do SFU symlinks and "client only"
3188 * "MF" symlinks optionally, but for recent Windows we really need to
3189 * reenable the code below and fix the cifs_symlink callers to handle this.
3190 * In the interim this code has been moved to its own config option so
3191 * it is not compiled in by default until callers fixed up and more tested.
3194 CIFSSMBQuerySymLink(const unsigned int xid
, struct cifs_tcon
*tcon
,
3195 __u16 fid
, char **symlinkinfo
,
3196 const struct nls_table
*nls_codepage
)
3200 struct smb_com_transaction_ioctl_req
*pSMB
;
3201 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
3203 unsigned int sub_len
;
3205 struct reparse_symlink_data
*reparse_buf
;
3206 struct reparse_posix_data
*posix_buf
;
3207 __u32 data_offset
, data_count
;
3210 cifs_dbg(FYI
, "In Windows reparse style QueryLink for fid %u\n", fid
);
3211 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
3216 pSMB
->TotalParameterCount
= 0 ;
3217 pSMB
->TotalDataCount
= 0;
3218 pSMB
->MaxParameterCount
= cpu_to_le32(2);
3219 /* BB find exact data count max from sess structure BB */
3220 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
3221 pSMB
->MaxSetupCount
= 4;
3223 pSMB
->ParameterOffset
= 0;
3224 pSMB
->DataCount
= 0;
3225 pSMB
->DataOffset
= 0;
3226 pSMB
->SetupCount
= 4;
3227 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
3228 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3229 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
3230 pSMB
->IsFsctl
= 1; /* FSCTL */
3231 pSMB
->IsRootFlag
= 0;
3232 pSMB
->Fid
= fid
; /* file handle always le */
3233 pSMB
->ByteCount
= 0;
3235 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3236 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3238 cifs_dbg(FYI
, "Send error in QueryReparseLinkInfo = %d\n", rc
);
3242 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
3243 data_count
= le32_to_cpu(pSMBr
->DataCount
);
3244 if (get_bcc(&pSMBr
->hdr
) < 2 || data_offset
> 512) {
3245 /* BB also check enough total bytes returned */
3246 rc
= -EIO
; /* bad smb */
3249 if (!data_count
|| (data_count
> 2048)) {
3251 cifs_dbg(FYI
, "Invalid return data count on get reparse info ioctl\n");
3254 end_of_smb
= 2 + get_bcc(&pSMBr
->hdr
) + (char *)&pSMBr
->ByteCount
;
3255 reparse_buf
= (struct reparse_symlink_data
*)
3256 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
3257 if ((char *)reparse_buf
>= end_of_smb
) {
3261 if (reparse_buf
->ReparseTag
== cpu_to_le32(IO_REPARSE_TAG_NFS
)) {
3262 cifs_dbg(FYI
, "NFS style reparse tag\n");
3263 posix_buf
= (struct reparse_posix_data
*)reparse_buf
;
3265 if (posix_buf
->InodeType
!= cpu_to_le64(NFS_SPECFILE_LNK
)) {
3266 cifs_dbg(FYI
, "unsupported file type 0x%llx\n",
3267 le64_to_cpu(posix_buf
->InodeType
));
3272 sub_len
= le16_to_cpu(reparse_buf
->ReparseDataLength
);
3273 if (posix_buf
->PathBuffer
+ sub_len
> end_of_smb
) {
3274 cifs_dbg(FYI
, "reparse buf beyond SMB\n");
3278 *symlinkinfo
= cifs_strndup_from_utf16(posix_buf
->PathBuffer
,
3279 sub_len
, is_unicode
, nls_codepage
);
3281 } else if (reparse_buf
->ReparseTag
!=
3282 cpu_to_le32(IO_REPARSE_TAG_SYMLINK
)) {
3287 /* Reparse tag is NTFS symlink */
3288 sub_start
= le16_to_cpu(reparse_buf
->SubstituteNameOffset
) +
3289 reparse_buf
->PathBuffer
;
3290 sub_len
= le16_to_cpu(reparse_buf
->SubstituteNameLength
);
3291 if (sub_start
+ sub_len
> end_of_smb
) {
3292 cifs_dbg(FYI
, "reparse buf beyond SMB\n");
3296 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3301 /* BB FIXME investigate remapping reserved chars here */
3302 *symlinkinfo
= cifs_strndup_from_utf16(sub_start
, sub_len
, is_unicode
,
3307 cifs_buf_release(pSMB
);
3310 * Note: On -EAGAIN error only caller can retry on handle based calls
3311 * since file handle passed in no longer valid.
3317 CIFSSMB_set_compression(const unsigned int xid
, struct cifs_tcon
*tcon
,
3322 struct smb_com_transaction_compr_ioctl_req
*pSMB
;
3323 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
3325 cifs_dbg(FYI
, "Set compression for %u\n", fid
);
3326 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
3331 pSMB
->compression_state
= cpu_to_le16(COMPRESSION_FORMAT_DEFAULT
);
3333 pSMB
->TotalParameterCount
= 0;
3334 pSMB
->TotalDataCount
= cpu_to_le32(2);
3335 pSMB
->MaxParameterCount
= 0;
3336 pSMB
->MaxDataCount
= 0;
3337 pSMB
->MaxSetupCount
= 4;
3339 pSMB
->ParameterOffset
= 0;
3340 pSMB
->DataCount
= cpu_to_le32(2);
3342 cpu_to_le32(offsetof(struct smb_com_transaction_compr_ioctl_req
,
3343 compression_state
) - 4); /* 84 */
3344 pSMB
->SetupCount
= 4;
3345 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
3346 pSMB
->ParameterCount
= 0;
3347 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_SET_COMPRESSION
);
3348 pSMB
->IsFsctl
= 1; /* FSCTL */
3349 pSMB
->IsRootFlag
= 0;
3350 pSMB
->Fid
= fid
; /* file handle always le */
3351 /* 3 byte pad, followed by 2 byte compress state */
3352 pSMB
->ByteCount
= cpu_to_le16(5);
3353 inc_rfc1001_len(pSMB
, 5);
3355 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3356 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3358 cifs_dbg(FYI
, "Send error in SetCompression = %d\n", rc
);
3360 cifs_buf_release(pSMB
);
3363 * Note: On -EAGAIN error only caller can retry on handle based calls
3364 * since file handle passed in no longer valid.
3370 #ifdef CONFIG_CIFS_POSIX
3372 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
3373 static void cifs_convert_ace(struct posix_acl_xattr_entry
*ace
,
3374 struct cifs_posix_ace
*cifs_ace
)
3376 /* u8 cifs fields do not need le conversion */
3377 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
3378 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
3379 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
3381 cifs_dbg(FYI, "perm %d tag %d id %d\n",
3382 ace->e_perm, ace->e_tag, ace->e_id);
3388 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
3389 static int cifs_copy_posix_acl(char *trgt
, char *src
, const int buflen
,
3390 const int acl_type
, const int size_of_data_area
)
3395 struct cifs_posix_ace
*pACE
;
3396 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)src
;
3397 struct posix_acl_xattr_header
*local_acl
= (void *)trgt
;
3399 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
3402 if (acl_type
== ACL_TYPE_ACCESS
) {
3403 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
3404 pACE
= &cifs_acl
->ace_array
[0];
3405 size
= sizeof(struct cifs_posix_acl
);
3406 size
+= sizeof(struct cifs_posix_ace
) * count
;
3407 /* check if we would go beyond end of SMB */
3408 if (size_of_data_area
< size
) {
3409 cifs_dbg(FYI
, "bad CIFS POSIX ACL size %d vs. %d\n",
3410 size_of_data_area
, size
);
3413 } else if (acl_type
== ACL_TYPE_DEFAULT
) {
3414 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
3415 size
= sizeof(struct cifs_posix_acl
);
3416 size
+= sizeof(struct cifs_posix_ace
) * count
;
3417 /* skip past access ACEs to get to default ACEs */
3418 pACE
= &cifs_acl
->ace_array
[count
];
3419 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
3420 size
+= sizeof(struct cifs_posix_ace
) * count
;
3421 /* check if we would go beyond end of SMB */
3422 if (size_of_data_area
< size
)
3429 size
= posix_acl_xattr_size(count
);
3430 if ((buflen
== 0) || (local_acl
== NULL
)) {
3431 /* used to query ACL EA size */
3432 } else if (size
> buflen
) {
3434 } else /* buffer big enough */ {
3435 struct posix_acl_xattr_entry
*ace
= (void *)(local_acl
+ 1);
3437 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
3438 for (i
= 0; i
< count
; i
++) {
3439 cifs_convert_ace(&ace
[i
], pACE
);
3446 static __u16
convert_ace_to_cifs_ace(struct cifs_posix_ace
*cifs_ace
,
3447 const struct posix_acl_xattr_entry
*local_ace
)
3449 __u16 rc
= 0; /* 0 = ACL converted ok */
3451 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
3452 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
3453 /* BB is there a better way to handle the large uid? */
3454 if (local_ace
->e_id
== cpu_to_le32(-1)) {
3455 /* Probably no need to le convert -1 on any arch but can not hurt */
3456 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
3458 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
3460 cifs_dbg(FYI, "perm %d tag %d id %d\n",
3461 ace->e_perm, ace->e_tag, ace->e_id);
3466 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
3467 static __u16
ACL_to_cifs_posix(char *parm_data
, const char *pACL
,
3468 const int buflen
, const int acl_type
)
3471 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
3472 struct posix_acl_xattr_header
*local_acl
= (void *)pACL
;
3473 struct posix_acl_xattr_entry
*ace
= (void *)(local_acl
+ 1);
3477 if ((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
3480 count
= posix_acl_xattr_count((size_t)buflen
);
3481 cifs_dbg(FYI
, "setting acl with %d entries from buf of length %d and version of %d\n",
3482 count
, buflen
, le32_to_cpu(local_acl
->a_version
));
3483 if (le32_to_cpu(local_acl
->a_version
) != 2) {
3484 cifs_dbg(FYI
, "unknown POSIX ACL version %d\n",
3485 le32_to_cpu(local_acl
->a_version
));
3488 cifs_acl
->version
= cpu_to_le16(1);
3489 if (acl_type
== ACL_TYPE_ACCESS
) {
3490 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
3491 cifs_acl
->default_entry_count
= cpu_to_le16(0xFFFF);
3492 } else if (acl_type
== ACL_TYPE_DEFAULT
) {
3493 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
3494 cifs_acl
->access_entry_count
= cpu_to_le16(0xFFFF);
3496 cifs_dbg(FYI
, "unknown ACL type %d\n", acl_type
);
3499 for (i
= 0; i
< count
; i
++) {
3500 rc
= convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
], &ace
[i
]);
3502 /* ACE not converted */
3507 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
3508 rc
+= sizeof(struct cifs_posix_acl
);
3509 /* BB add check to make sure ACL does not overflow SMB */
3515 CIFSSMBGetPosixACL(const unsigned int xid
, struct cifs_tcon
*tcon
,
3516 const unsigned char *searchName
,
3517 char *acl_inf
, const int buflen
, const int acl_type
,
3518 const struct nls_table
*nls_codepage
, int remap
)
3520 /* SMB_QUERY_POSIX_ACL */
3521 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3522 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3526 __u16 params
, byte_count
;
3528 cifs_dbg(FYI
, "In GetPosixACL (Unix) for path %s\n", searchName
);
3531 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3536 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3538 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
3539 searchName
, PATH_MAX
, nls_codepage
,
3541 name_len
++; /* trailing null */
3543 pSMB
->FileName
[name_len
] = 0;
3544 pSMB
->FileName
[name_len
+1] = 0;
3545 } else { /* BB improve the check for buffer overruns BB */
3546 name_len
= strnlen(searchName
, PATH_MAX
);
3547 name_len
++; /* trailing null */
3548 strncpy(pSMB
->FileName
, searchName
, name_len
);
3551 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3552 pSMB
->TotalDataCount
= 0;
3553 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3554 /* BB find exact max data count below from sess structure BB */
3555 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3556 pSMB
->MaxSetupCount
= 0;
3560 pSMB
->Reserved2
= 0;
3561 pSMB
->ParameterOffset
= cpu_to_le16(
3562 offsetof(struct smb_com_transaction2_qpi_req
,
3563 InformationLevel
) - 4);
3564 pSMB
->DataCount
= 0;
3565 pSMB
->DataOffset
= 0;
3566 pSMB
->SetupCount
= 1;
3567 pSMB
->Reserved3
= 0;
3568 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3569 byte_count
= params
+ 1 /* pad */ ;
3570 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3571 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3572 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
3573 pSMB
->Reserved4
= 0;
3574 inc_rfc1001_len(pSMB
, byte_count
);
3575 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3577 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3578 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3579 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_acl_get
);
3581 cifs_dbg(FYI
, "Send error in Query POSIX ACL = %d\n", rc
);
3583 /* decode response */
3585 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3586 /* BB also check enough total bytes returned */
3587 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3588 rc
= -EIO
; /* bad smb */
3590 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3591 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3592 rc
= cifs_copy_posix_acl(acl_inf
,
3593 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
3594 buflen
, acl_type
, count
);
3597 cifs_buf_release(pSMB
);
3604 CIFSSMBSetPosixACL(const unsigned int xid
, struct cifs_tcon
*tcon
,
3605 const unsigned char *fileName
,
3606 const char *local_acl
, const int buflen
,
3608 const struct nls_table
*nls_codepage
, int remap
)
3610 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
3611 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
3615 int bytes_returned
= 0;
3616 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
3618 cifs_dbg(FYI
, "In SetPosixACL (Unix) for path %s\n", fileName
);
3620 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3624 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3626 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
3627 PATH_MAX
, nls_codepage
, remap
);
3628 name_len
++; /* trailing null */
3630 } else { /* BB improve the check for buffer overruns BB */
3631 name_len
= strnlen(fileName
, PATH_MAX
);
3632 name_len
++; /* trailing null */
3633 strncpy(pSMB
->FileName
, fileName
, name_len
);
3635 params
= 6 + name_len
;
3636 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3637 /* BB find max SMB size from sess */
3638 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3639 pSMB
->MaxSetupCount
= 0;
3643 pSMB
->Reserved2
= 0;
3644 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
3645 InformationLevel
) - 4;
3646 offset
= param_offset
+ params
;
3647 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
3648 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3650 /* convert to on the wire format for POSIX ACL */
3651 data_count
= ACL_to_cifs_posix(parm_data
, local_acl
, buflen
, acl_type
);
3653 if (data_count
== 0) {
3655 goto setACLerrorExit
;
3657 pSMB
->DataOffset
= cpu_to_le16(offset
);
3658 pSMB
->SetupCount
= 1;
3659 pSMB
->Reserved3
= 0;
3660 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
3661 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
3662 byte_count
= 3 /* pad */ + params
+ data_count
;
3663 pSMB
->DataCount
= cpu_to_le16(data_count
);
3664 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3665 pSMB
->ParameterCount
= cpu_to_le16(params
);
3666 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3667 pSMB
->Reserved4
= 0;
3668 inc_rfc1001_len(pSMB
, byte_count
);
3669 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3670 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3671 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3673 cifs_dbg(FYI
, "Set POSIX ACL returned %d\n", rc
);
3676 cifs_buf_release(pSMB
);
3682 /* BB fix tabs in this function FIXME BB */
3684 CIFSGetExtAttr(const unsigned int xid
, struct cifs_tcon
*tcon
,
3685 const int netfid
, __u64
*pExtAttrBits
, __u64
*pMask
)
3688 struct smb_t2_qfi_req
*pSMB
= NULL
;
3689 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
3691 __u16 params
, byte_count
;
3693 cifs_dbg(FYI
, "In GetExtAttr\n");
3698 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3703 params
= 2 /* level */ + 2 /* fid */;
3704 pSMB
->t2
.TotalDataCount
= 0;
3705 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
3706 /* BB find exact max data count below from sess structure BB */
3707 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
3708 pSMB
->t2
.MaxSetupCount
= 0;
3709 pSMB
->t2
.Reserved
= 0;
3711 pSMB
->t2
.Timeout
= 0;
3712 pSMB
->t2
.Reserved2
= 0;
3713 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
3715 pSMB
->t2
.DataCount
= 0;
3716 pSMB
->t2
.DataOffset
= 0;
3717 pSMB
->t2
.SetupCount
= 1;
3718 pSMB
->t2
.Reserved3
= 0;
3719 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
3720 byte_count
= params
+ 1 /* pad */ ;
3721 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
3722 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
3723 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
3726 inc_rfc1001_len(pSMB
, byte_count
);
3727 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
3729 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3730 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3732 cifs_dbg(FYI
, "error %d in GetExtAttr\n", rc
);
3734 /* decode response */
3735 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3736 /* BB also check enough total bytes returned */
3737 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3738 /* If rc should we check for EOPNOSUPP and
3739 disable the srvino flag? or in caller? */
3740 rc
= -EIO
; /* bad smb */
3742 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3743 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3744 struct file_chattr_info
*pfinfo
;
3745 /* BB Do we need a cast or hash here ? */
3747 cifs_dbg(FYI
, "Illegal size ret in GetExtAttr\n");
3751 pfinfo
= (struct file_chattr_info
*)
3752 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3753 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
3754 *pMask
= le64_to_cpu(pfinfo
->mask
);
3758 cifs_buf_release(pSMB
);
3760 goto GetExtAttrRetry
;
3764 #endif /* CONFIG_POSIX */
3766 #ifdef CONFIG_CIFS_ACL
3768 * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that
3769 * all NT TRANSACTS that we init here have total parm and data under about 400
3770 * bytes (to fit in small cifs buffer size), which is the case so far, it
3771 * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of
3772 * returned setup area) and MaxParameterCount (returned parms size) must be set
3776 smb_init_nttransact(const __u16 sub_command
, const int setup_count
,
3777 const int parm_len
, struct cifs_tcon
*tcon
,
3782 struct smb_com_ntransact_req
*pSMB
;
3784 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
3788 *ret_buf
= (void *)pSMB
;
3790 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
3791 pSMB
->TotalDataCount
= 0;
3792 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
3793 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3794 pSMB
->DataCount
= pSMB
->TotalDataCount
;
3795 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
3796 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
3797 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
3798 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
3799 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
3800 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
3805 validate_ntransact(char *buf
, char **ppparm
, char **ppdata
,
3806 __u32
*pparmlen
, __u32
*pdatalen
)
3809 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
3810 struct smb_com_ntransact_rsp
*pSMBr
;
3819 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
3821 bcc
= get_bcc(&pSMBr
->hdr
);
3822 end_of_smb
= 2 /* sizeof byte count */ + bcc
+
3823 (char *)&pSMBr
->ByteCount
;
3825 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
3826 data_count
= le32_to_cpu(pSMBr
->DataCount
);
3827 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
3828 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
3830 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
3831 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
3833 /* should we also check that parm and data areas do not overlap? */
3834 if (*ppparm
> end_of_smb
) {
3835 cifs_dbg(FYI
, "parms start after end of smb\n");
3837 } else if (parm_count
+ *ppparm
> end_of_smb
) {
3838 cifs_dbg(FYI
, "parm end after end of smb\n");
3840 } else if (*ppdata
> end_of_smb
) {
3841 cifs_dbg(FYI
, "data starts after end of smb\n");
3843 } else if (data_count
+ *ppdata
> end_of_smb
) {
3844 cifs_dbg(FYI
, "data %p + count %d (%p) past smb end %p start %p\n",
3845 *ppdata
, data_count
, (data_count
+ *ppdata
),
3848 } else if (parm_count
+ data_count
> bcc
) {
3849 cifs_dbg(FYI
, "parm count and data count larger than SMB\n");
3852 *pdatalen
= data_count
;
3853 *pparmlen
= parm_count
;
3857 /* Get Security Descriptor (by handle) from remote server for a file or dir */
3859 CIFSSMBGetCIFSACL(const unsigned int xid
, struct cifs_tcon
*tcon
, __u16 fid
,
3860 struct cifs_ntsd
**acl_inf
, __u32
*pbuflen
)
3864 QUERY_SEC_DESC_REQ
*pSMB
;
3866 struct kvec rsp_iov
;
3868 cifs_dbg(FYI
, "GetCifsACL\n");
3873 rc
= smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
3874 8 /* parm len */, tcon
, (void **) &pSMB
);
3878 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3879 /* BB TEST with big acls that might need to be e.g. larger than 16K */
3880 pSMB
->MaxSetupCount
= 0;
3881 pSMB
->Fid
= fid
; /* file handle always le */
3882 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
3884 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
3885 inc_rfc1001_len(pSMB
, 11);
3886 iov
[0].iov_base
= (char *)pSMB
;
3887 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
3889 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
,
3891 cifs_small_buf_release(pSMB
);
3892 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_acl_get
);
3894 cifs_dbg(FYI
, "Send error in QuerySecDesc = %d\n", rc
);
3895 } else { /* decode response */
3899 struct smb_com_ntransact_rsp
*pSMBr
;
3902 /* validate_nttransact */
3903 rc
= validate_ntransact(rsp_iov
.iov_base
, (char **)&parm
,
3904 &pdata
, &parm_len
, pbuflen
);
3907 pSMBr
= (struct smb_com_ntransact_rsp
*)rsp_iov
.iov_base
;
3909 cifs_dbg(FYI
, "smb %p parm %p data %p\n",
3910 pSMBr
, parm
, *acl_inf
);
3912 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
3913 rc
= -EIO
; /* bad smb */
3918 /* BB check that data area is minimum length and as big as acl_len */
3920 acl_len
= le32_to_cpu(*parm
);
3921 if (acl_len
!= *pbuflen
) {
3922 cifs_dbg(VFS
, "acl length %d does not match %d\n",
3924 if (*pbuflen
> acl_len
)
3928 /* check if buffer is big enough for the acl
3929 header followed by the smallest SID */
3930 if ((*pbuflen
< sizeof(struct cifs_ntsd
) + 8) ||
3931 (*pbuflen
>= 64 * 1024)) {
3932 cifs_dbg(VFS
, "bad acl length %d\n", *pbuflen
);
3936 *acl_inf
= kmemdup(pdata
, *pbuflen
, GFP_KERNEL
);
3937 if (*acl_inf
== NULL
) {
3944 free_rsp_buf(buf_type
, rsp_iov
.iov_base
);
3949 CIFSSMBSetCIFSACL(const unsigned int xid
, struct cifs_tcon
*tcon
, __u16 fid
,
3950 struct cifs_ntsd
*pntsd
, __u32 acllen
, int aclflag
)
3952 __u16 byte_count
, param_count
, data_count
, param_offset
, data_offset
;
3954 int bytes_returned
= 0;
3955 SET_SEC_DESC_REQ
*pSMB
= NULL
;
3959 rc
= smb_init(SMB_COM_NT_TRANSACT
, 19, tcon
, (void **) &pSMB
, &pSMBr
);
3963 pSMB
->MaxSetupCount
= 0;
3967 param_offset
= offsetof(struct smb_com_transaction_ssec_req
, Fid
) - 4;
3968 data_count
= acllen
;
3969 data_offset
= param_offset
+ param_count
;
3970 byte_count
= 3 /* pad */ + param_count
;
3972 pSMB
->DataCount
= cpu_to_le32(data_count
);
3973 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3974 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3975 pSMB
->MaxDataCount
= cpu_to_le32(16384);
3976 pSMB
->ParameterCount
= cpu_to_le32(param_count
);
3977 pSMB
->ParameterOffset
= cpu_to_le32(param_offset
);
3978 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3979 pSMB
->DataOffset
= cpu_to_le32(data_offset
);
3980 pSMB
->SetupCount
= 0;
3981 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC
);
3982 pSMB
->ByteCount
= cpu_to_le16(byte_count
+data_count
);
3984 pSMB
->Fid
= fid
; /* file handle always le */
3985 pSMB
->Reserved2
= 0;
3986 pSMB
->AclFlags
= cpu_to_le32(aclflag
);
3988 if (pntsd
&& acllen
) {
3989 memcpy((char *)pSMBr
+ offsetof(struct smb_hdr
, Protocol
) +
3990 data_offset
, pntsd
, acllen
);
3991 inc_rfc1001_len(pSMB
, byte_count
+ data_count
);
3993 inc_rfc1001_len(pSMB
, byte_count
);
3995 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3996 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3998 cifs_dbg(FYI
, "SetCIFSACL bytes_returned: %d, rc: %d\n",
3999 bytes_returned
, rc
);
4001 cifs_dbg(FYI
, "Set CIFS ACL returned %d\n", rc
);
4002 cifs_buf_release(pSMB
);
4005 goto setCifsAclRetry
;
4010 #endif /* CONFIG_CIFS_ACL */
4012 /* Legacy Query Path Information call for lookup to old servers such
4015 SMBQueryInformation(const unsigned int xid
, struct cifs_tcon
*tcon
,
4016 const char *search_name
, FILE_ALL_INFO
*data
,
4017 const struct nls_table
*nls_codepage
, int remap
)
4019 QUERY_INFORMATION_REQ
*pSMB
;
4020 QUERY_INFORMATION_RSP
*pSMBr
;
4025 cifs_dbg(FYI
, "In SMBQPath path %s\n", search_name
);
4027 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
4032 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4034 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
4035 search_name
, PATH_MAX
, nls_codepage
,
4037 name_len
++; /* trailing null */
4040 name_len
= strnlen(search_name
, PATH_MAX
);
4041 name_len
++; /* trailing null */
4042 strncpy(pSMB
->FileName
, search_name
, name_len
);
4044 pSMB
->BufferFormat
= 0x04;
4045 name_len
++; /* account for buffer type byte */
4046 inc_rfc1001_len(pSMB
, (__u16
)name_len
);
4047 pSMB
->ByteCount
= cpu_to_le16(name_len
);
4049 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4050 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4052 cifs_dbg(FYI
, "Send error in QueryInfo = %d\n", rc
);
4055 __u32 time
= le32_to_cpu(pSMBr
->last_write_time
);
4057 /* decode response */
4058 /* BB FIXME - add time zone adjustment BB */
4059 memset(data
, 0, sizeof(FILE_ALL_INFO
));
4062 /* decode time fields */
4063 data
->ChangeTime
= cpu_to_le64(cifs_UnixTimeToNT(ts
));
4064 data
->LastWriteTime
= data
->ChangeTime
;
4065 data
->LastAccessTime
= 0;
4066 data
->AllocationSize
=
4067 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
4068 data
->EndOfFile
= data
->AllocationSize
;
4070 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
4072 rc
= -EIO
; /* bad buffer passed in */
4074 cifs_buf_release(pSMB
);
4083 CIFSSMBQFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4084 u16 netfid
, FILE_ALL_INFO
*pFindData
)
4086 struct smb_t2_qfi_req
*pSMB
= NULL
;
4087 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
4090 __u16 params
, byte_count
;
4093 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4098 params
= 2 /* level */ + 2 /* fid */;
4099 pSMB
->t2
.TotalDataCount
= 0;
4100 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
4101 /* BB find exact max data count below from sess structure BB */
4102 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
4103 pSMB
->t2
.MaxSetupCount
= 0;
4104 pSMB
->t2
.Reserved
= 0;
4106 pSMB
->t2
.Timeout
= 0;
4107 pSMB
->t2
.Reserved2
= 0;
4108 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
4110 pSMB
->t2
.DataCount
= 0;
4111 pSMB
->t2
.DataOffset
= 0;
4112 pSMB
->t2
.SetupCount
= 1;
4113 pSMB
->t2
.Reserved3
= 0;
4114 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
4115 byte_count
= params
+ 1 /* pad */ ;
4116 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
4117 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
4118 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
4121 inc_rfc1001_len(pSMB
, byte_count
);
4122 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
4124 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4125 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4127 cifs_dbg(FYI
, "Send error in QFileInfo = %d", rc
);
4128 } else { /* decode response */
4129 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4131 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
4133 else if (get_bcc(&pSMBr
->hdr
) < 40)
4134 rc
= -EIO
; /* bad smb */
4135 else if (pFindData
) {
4136 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4137 memcpy((char *) pFindData
,
4138 (char *) &pSMBr
->hdr
.Protocol
+
4139 data_offset
, sizeof(FILE_ALL_INFO
));
4143 cifs_buf_release(pSMB
);
4145 goto QFileInfoRetry
;
4151 CIFSSMBQPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4152 const char *search_name
, FILE_ALL_INFO
*data
,
4153 int legacy
/* old style infolevel */,
4154 const struct nls_table
*nls_codepage
, int remap
)
4156 /* level 263 SMB_QUERY_FILE_ALL_INFO */
4157 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4158 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4162 __u16 params
, byte_count
;
4164 /* cifs_dbg(FYI, "In QPathInfo path %s\n", search_name); */
4166 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4171 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4173 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, search_name
,
4174 PATH_MAX
, nls_codepage
, remap
);
4175 name_len
++; /* trailing null */
4177 } else { /* BB improve the check for buffer overruns BB */
4178 name_len
= strnlen(search_name
, PATH_MAX
);
4179 name_len
++; /* trailing null */
4180 strncpy(pSMB
->FileName
, search_name
, name_len
);
4183 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
4184 pSMB
->TotalDataCount
= 0;
4185 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4186 /* BB find exact max SMB PDU from sess structure BB */
4187 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4188 pSMB
->MaxSetupCount
= 0;
4192 pSMB
->Reserved2
= 0;
4193 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4194 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4195 pSMB
->DataCount
= 0;
4196 pSMB
->DataOffset
= 0;
4197 pSMB
->SetupCount
= 1;
4198 pSMB
->Reserved3
= 0;
4199 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4200 byte_count
= params
+ 1 /* pad */ ;
4201 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4202 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4204 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_STANDARD
);
4206 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
4207 pSMB
->Reserved4
= 0;
4208 inc_rfc1001_len(pSMB
, byte_count
);
4209 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4211 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4212 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4214 cifs_dbg(FYI
, "Send error in QPathInfo = %d\n", rc
);
4215 } else { /* decode response */
4216 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4218 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
4220 else if (!legacy
&& get_bcc(&pSMBr
->hdr
) < 40)
4221 rc
= -EIO
; /* bad smb */
4222 else if (legacy
&& get_bcc(&pSMBr
->hdr
) < 24)
4223 rc
= -EIO
; /* 24 or 26 expected but we do not read
4227 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4230 * On legacy responses we do not read the last field,
4231 * EAsize, fortunately since it varies by subdialect and
4232 * also note it differs on Set vs Get, ie two bytes or 4
4233 * bytes depending but we don't care here.
4236 size
= sizeof(FILE_INFO_STANDARD
);
4238 size
= sizeof(FILE_ALL_INFO
);
4239 memcpy((char *) data
, (char *) &pSMBr
->hdr
.Protocol
+
4244 cifs_buf_release(pSMB
);
4246 goto QPathInfoRetry
;
4252 CIFSSMBUnixQFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4253 u16 netfid
, FILE_UNIX_BASIC_INFO
*pFindData
)
4255 struct smb_t2_qfi_req
*pSMB
= NULL
;
4256 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
4259 __u16 params
, byte_count
;
4262 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4267 params
= 2 /* level */ + 2 /* fid */;
4268 pSMB
->t2
.TotalDataCount
= 0;
4269 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
4270 /* BB find exact max data count below from sess structure BB */
4271 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
4272 pSMB
->t2
.MaxSetupCount
= 0;
4273 pSMB
->t2
.Reserved
= 0;
4275 pSMB
->t2
.Timeout
= 0;
4276 pSMB
->t2
.Reserved2
= 0;
4277 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
4279 pSMB
->t2
.DataCount
= 0;
4280 pSMB
->t2
.DataOffset
= 0;
4281 pSMB
->t2
.SetupCount
= 1;
4282 pSMB
->t2
.Reserved3
= 0;
4283 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
4284 byte_count
= params
+ 1 /* pad */ ;
4285 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
4286 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
4287 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
4290 inc_rfc1001_len(pSMB
, byte_count
);
4291 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
4293 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4294 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4296 cifs_dbg(FYI
, "Send error in UnixQFileInfo = %d", rc
);
4297 } else { /* decode response */
4298 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4300 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(FILE_UNIX_BASIC_INFO
)) {
4301 cifs_dbg(VFS
, "Malformed FILE_UNIX_BASIC_INFO response. Unix Extensions can be disabled on mount by specifying the nosfu mount option.\n");
4302 rc
= -EIO
; /* bad smb */
4304 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4305 memcpy((char *) pFindData
,
4306 (char *) &pSMBr
->hdr
.Protocol
+
4308 sizeof(FILE_UNIX_BASIC_INFO
));
4312 cifs_buf_release(pSMB
);
4314 goto UnixQFileInfoRetry
;
4320 CIFSSMBUnixQPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4321 const unsigned char *searchName
,
4322 FILE_UNIX_BASIC_INFO
*pFindData
,
4323 const struct nls_table
*nls_codepage
, int remap
)
4325 /* SMB_QUERY_FILE_UNIX_BASIC */
4326 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4327 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4329 int bytes_returned
= 0;
4331 __u16 params
, byte_count
;
4333 cifs_dbg(FYI
, "In QPathInfo (Unix) the path %s\n", searchName
);
4335 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4340 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4342 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4343 PATH_MAX
, nls_codepage
, remap
);
4344 name_len
++; /* trailing null */
4346 } else { /* BB improve the check for buffer overruns BB */
4347 name_len
= strnlen(searchName
, PATH_MAX
);
4348 name_len
++; /* trailing null */
4349 strncpy(pSMB
->FileName
, searchName
, name_len
);
4352 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
4353 pSMB
->TotalDataCount
= 0;
4354 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4355 /* BB find exact max SMB PDU from sess structure BB */
4356 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4357 pSMB
->MaxSetupCount
= 0;
4361 pSMB
->Reserved2
= 0;
4362 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4363 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4364 pSMB
->DataCount
= 0;
4365 pSMB
->DataOffset
= 0;
4366 pSMB
->SetupCount
= 1;
4367 pSMB
->Reserved3
= 0;
4368 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4369 byte_count
= params
+ 1 /* pad */ ;
4370 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4371 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4372 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
4373 pSMB
->Reserved4
= 0;
4374 inc_rfc1001_len(pSMB
, byte_count
);
4375 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4377 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4378 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4380 cifs_dbg(FYI
, "Send error in UnixQPathInfo = %d", rc
);
4381 } else { /* decode response */
4382 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4384 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(FILE_UNIX_BASIC_INFO
)) {
4385 cifs_dbg(VFS
, "Malformed FILE_UNIX_BASIC_INFO response. Unix Extensions can be disabled on mount by specifying the nosfu mount option.\n");
4386 rc
= -EIO
; /* bad smb */
4388 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4389 memcpy((char *) pFindData
,
4390 (char *) &pSMBr
->hdr
.Protocol
+
4392 sizeof(FILE_UNIX_BASIC_INFO
));
4395 cifs_buf_release(pSMB
);
4397 goto UnixQPathInfoRetry
;
4402 /* xid, tcon, searchName and codepage are input parms, rest are returned */
4404 CIFSFindFirst(const unsigned int xid
, struct cifs_tcon
*tcon
,
4405 const char *searchName
, struct cifs_sb_info
*cifs_sb
,
4406 __u16
*pnetfid
, __u16 search_flags
,
4407 struct cifs_search_info
*psrch_inf
, bool msearch
)
4409 /* level 257 SMB_ */
4410 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
4411 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
4412 T2_FFIRST_RSP_PARMS
*parms
;
4414 int bytes_returned
= 0;
4415 int name_len
, remap
;
4416 __u16 params
, byte_count
;
4417 struct nls_table
*nls_codepage
;
4419 cifs_dbg(FYI
, "In FindFirst for %s\n", searchName
);
4422 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4427 nls_codepage
= cifs_sb
->local_nls
;
4428 remap
= cifs_remap(cifs_sb
);
4430 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4432 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4433 PATH_MAX
, nls_codepage
, remap
);
4434 /* We can not add the asterik earlier in case
4435 it got remapped to 0xF03A as if it were part of the
4436 directory name instead of a wildcard */
4439 pSMB
->FileName
[name_len
] = CIFS_DIR_SEP(cifs_sb
);
4440 pSMB
->FileName
[name_len
+1] = 0;
4441 pSMB
->FileName
[name_len
+2] = '*';
4442 pSMB
->FileName
[name_len
+3] = 0;
4443 name_len
+= 4; /* now the trailing null */
4444 /* null terminate just in case */
4445 pSMB
->FileName
[name_len
] = 0;
4446 pSMB
->FileName
[name_len
+1] = 0;
4449 } else { /* BB add check for overrun of SMB buf BB */
4450 name_len
= strnlen(searchName
, PATH_MAX
);
4451 /* BB fix here and in unicode clause above ie
4452 if (name_len > buffersize-header)
4453 free buffer exit; BB */
4454 strncpy(pSMB
->FileName
, searchName
, name_len
);
4456 pSMB
->FileName
[name_len
] = CIFS_DIR_SEP(cifs_sb
);
4457 pSMB
->FileName
[name_len
+1] = '*';
4458 pSMB
->FileName
[name_len
+2] = 0;
4463 params
= 12 + name_len
/* includes null */ ;
4464 pSMB
->TotalDataCount
= 0; /* no EAs */
4465 pSMB
->MaxParameterCount
= cpu_to_le16(10);
4466 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
& 0xFFFFFF00);
4467 pSMB
->MaxSetupCount
= 0;
4471 pSMB
->Reserved2
= 0;
4472 byte_count
= params
+ 1 /* pad */ ;
4473 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4474 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4475 pSMB
->ParameterOffset
= cpu_to_le16(
4476 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
)
4478 pSMB
->DataCount
= 0;
4479 pSMB
->DataOffset
= 0;
4480 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
4481 pSMB
->Reserved3
= 0;
4482 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
4483 pSMB
->SearchAttributes
=
4484 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
4486 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
4487 pSMB
->SearchFlags
= cpu_to_le16(search_flags
);
4488 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
4490 /* BB what should we set StorageType to? Does it matter? BB */
4491 pSMB
->SearchStorageType
= 0;
4492 inc_rfc1001_len(pSMB
, byte_count
);
4493 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4495 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4496 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4497 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_ffirst
);
4499 if (rc
) {/* BB add logic to retry regular search if Unix search
4500 rejected unexpectedly by server */
4501 /* BB Add code to handle unsupported level rc */
4502 cifs_dbg(FYI
, "Error in FindFirst = %d\n", rc
);
4504 cifs_buf_release(pSMB
);
4506 /* BB eventually could optimize out free and realloc of buf */
4509 goto findFirstRetry
;
4510 } else { /* decode response */
4511 /* BB remember to free buffer if error BB */
4512 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4516 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4517 psrch_inf
->unicode
= true;
4519 psrch_inf
->unicode
= false;
4521 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
4522 psrch_inf
->smallBuf
= 0;
4523 psrch_inf
->srch_entries_start
=
4524 (char *) &pSMBr
->hdr
.Protocol
+
4525 le16_to_cpu(pSMBr
->t2
.DataOffset
);
4526 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
4527 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
4529 if (parms
->EndofSearch
)
4530 psrch_inf
->endOfSearch
= true;
4532 psrch_inf
->endOfSearch
= false;
4534 psrch_inf
->entries_in_buffer
=
4535 le16_to_cpu(parms
->SearchCount
);
4536 psrch_inf
->index_of_last_entry
= 2 /* skip . and .. */ +
4537 psrch_inf
->entries_in_buffer
;
4538 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
4539 if (CIFSMaxBufSize
< lnoff
) {
4540 cifs_dbg(VFS
, "ignoring corrupt resume name\n");
4541 psrch_inf
->last_entry
= NULL
;
4545 psrch_inf
->last_entry
= psrch_inf
->srch_entries_start
+
4549 *pnetfid
= parms
->SearchHandle
;
4551 cifs_buf_release(pSMB
);
4558 int CIFSFindNext(const unsigned int xid
, struct cifs_tcon
*tcon
,
4559 __u16 searchHandle
, __u16 search_flags
,
4560 struct cifs_search_info
*psrch_inf
)
4562 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
4563 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
4564 T2_FNEXT_RSP_PARMS
*parms
;
4565 char *response_data
;
4568 unsigned int name_len
;
4569 __u16 params
, byte_count
;
4571 cifs_dbg(FYI
, "In FindNext\n");
4573 if (psrch_inf
->endOfSearch
)
4576 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4581 params
= 14; /* includes 2 bytes of null string, converted to LE below*/
4583 pSMB
->TotalDataCount
= 0; /* no EAs */
4584 pSMB
->MaxParameterCount
= cpu_to_le16(8);
4585 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
& 0xFFFFFF00);
4586 pSMB
->MaxSetupCount
= 0;
4590 pSMB
->Reserved2
= 0;
4591 pSMB
->ParameterOffset
= cpu_to_le16(
4592 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
4593 pSMB
->DataCount
= 0;
4594 pSMB
->DataOffset
= 0;
4595 pSMB
->SetupCount
= 1;
4596 pSMB
->Reserved3
= 0;
4597 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
4598 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
4600 cpu_to_le16(CIFSMaxBufSize
/ sizeof(FILE_UNIX_INFO
));
4601 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
4602 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
4603 pSMB
->SearchFlags
= cpu_to_le16(search_flags
);
4605 name_len
= psrch_inf
->resume_name_len
;
4607 if (name_len
< PATH_MAX
) {
4608 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
4609 byte_count
+= name_len
;
4610 /* 14 byte parm len above enough for 2 byte null terminator */
4611 pSMB
->ResumeFileName
[name_len
] = 0;
4612 pSMB
->ResumeFileName
[name_len
+1] = 0;
4615 goto FNext2_err_exit
;
4617 byte_count
= params
+ 1 /* pad */ ;
4618 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4619 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4620 inc_rfc1001_len(pSMB
, byte_count
);
4621 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4623 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4624 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4625 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_fnext
);
4628 psrch_inf
->endOfSearch
= true;
4629 cifs_buf_release(pSMB
);
4630 rc
= 0; /* search probably was closed at end of search*/
4632 cifs_dbg(FYI
, "FindNext returned = %d\n", rc
);
4633 } else { /* decode response */
4634 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4639 /* BB fixme add lock for file (srch_info) struct here */
4640 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4641 psrch_inf
->unicode
= true;
4643 psrch_inf
->unicode
= false;
4644 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
4645 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
4646 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
4647 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
4648 le16_to_cpu(pSMBr
->t2
.DataOffset
);
4649 if (psrch_inf
->smallBuf
)
4650 cifs_small_buf_release(
4651 psrch_inf
->ntwrk_buf_start
);
4653 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
4654 psrch_inf
->srch_entries_start
= response_data
;
4655 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
4656 psrch_inf
->smallBuf
= 0;
4657 if (parms
->EndofSearch
)
4658 psrch_inf
->endOfSearch
= true;
4660 psrch_inf
->endOfSearch
= false;
4661 psrch_inf
->entries_in_buffer
=
4662 le16_to_cpu(parms
->SearchCount
);
4663 psrch_inf
->index_of_last_entry
+=
4664 psrch_inf
->entries_in_buffer
;
4665 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
4666 if (CIFSMaxBufSize
< lnoff
) {
4667 cifs_dbg(VFS
, "ignoring corrupt resume name\n");
4668 psrch_inf
->last_entry
= NULL
;
4671 psrch_inf
->last_entry
=
4672 psrch_inf
->srch_entries_start
+ lnoff
;
4674 /* cifs_dbg(FYI, "fnxt2 entries in buf %d index_of_last %d\n",
4675 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */
4677 /* BB fixme add unlock here */
4682 /* BB On error, should we leave previous search buf (and count and
4683 last entry fields) intact or free the previous one? */
4685 /* Note: On -EAGAIN error only caller can retry on handle based calls
4686 since file handle passed in no longer valid */
4689 cifs_buf_release(pSMB
);
4694 CIFSFindClose(const unsigned int xid
, struct cifs_tcon
*tcon
,
4695 const __u16 searchHandle
)
4698 FINDCLOSE_REQ
*pSMB
= NULL
;
4700 cifs_dbg(FYI
, "In CIFSSMBFindClose\n");
4701 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
4703 /* no sense returning error if session restarted
4704 as file handle has been closed */
4710 pSMB
->FileID
= searchHandle
;
4711 pSMB
->ByteCount
= 0;
4712 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
4713 cifs_small_buf_release(pSMB
);
4715 cifs_dbg(VFS
, "Send error in FindClose = %d\n", rc
);
4717 cifs_stats_inc(&tcon
->stats
.cifs_stats
.num_fclose
);
4719 /* Since session is dead, search handle closed on server already */
4727 CIFSGetSrvInodeNumber(const unsigned int xid
, struct cifs_tcon
*tcon
,
4728 const char *search_name
, __u64
*inode_number
,
4729 const struct nls_table
*nls_codepage
, int remap
)
4732 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4733 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4734 int name_len
, bytes_returned
;
4735 __u16 params
, byte_count
;
4737 cifs_dbg(FYI
, "In GetSrvInodeNum for %s\n", search_name
);
4741 GetInodeNumberRetry
:
4742 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4747 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4749 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
4750 search_name
, PATH_MAX
, nls_codepage
,
4752 name_len
++; /* trailing null */
4754 } else { /* BB improve the check for buffer overruns BB */
4755 name_len
= strnlen(search_name
, PATH_MAX
);
4756 name_len
++; /* trailing null */
4757 strncpy(pSMB
->FileName
, search_name
, name_len
);
4760 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
4761 pSMB
->TotalDataCount
= 0;
4762 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4763 /* BB find exact max data count below from sess structure BB */
4764 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4765 pSMB
->MaxSetupCount
= 0;
4769 pSMB
->Reserved2
= 0;
4770 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4771 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4772 pSMB
->DataCount
= 0;
4773 pSMB
->DataOffset
= 0;
4774 pSMB
->SetupCount
= 1;
4775 pSMB
->Reserved3
= 0;
4776 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4777 byte_count
= params
+ 1 /* pad */ ;
4778 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4779 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4780 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
4781 pSMB
->Reserved4
= 0;
4782 inc_rfc1001_len(pSMB
, byte_count
);
4783 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4785 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4786 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4788 cifs_dbg(FYI
, "error %d in QueryInternalInfo\n", rc
);
4790 /* decode response */
4791 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4792 /* BB also check enough total bytes returned */
4793 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
4794 /* If rc should we check for EOPNOSUPP and
4795 disable the srvino flag? or in caller? */
4796 rc
= -EIO
; /* bad smb */
4798 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4799 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
4800 struct file_internal_info
*pfinfo
;
4801 /* BB Do we need a cast or hash here ? */
4803 cifs_dbg(FYI
, "Illegal size ret in QryIntrnlInf\n");
4805 goto GetInodeNumOut
;
4807 pfinfo
= (struct file_internal_info
*)
4808 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
4809 *inode_number
= le64_to_cpu(pfinfo
->UniqueId
);
4813 cifs_buf_release(pSMB
);
4815 goto GetInodeNumberRetry
;
4820 CIFSGetDFSRefer(const unsigned int xid
, struct cifs_ses
*ses
,
4821 const char *search_name
, struct dfs_info3_param
**target_nodes
,
4822 unsigned int *num_of_nodes
,
4823 const struct nls_table
*nls_codepage
, int remap
)
4825 /* TRANS2_GET_DFS_REFERRAL */
4826 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
4827 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
4831 __u16 params
, byte_count
;
4833 *target_nodes
= NULL
;
4835 cifs_dbg(FYI
, "In GetDFSRefer the path %s\n", search_name
);
4836 if (ses
== NULL
|| ses
->tcon_ipc
== NULL
)
4840 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, ses
->tcon_ipc
, (void **) &pSMB
,
4845 /* server pointer checked in called function,
4846 but should never be null here anyway */
4847 pSMB
->hdr
.Mid
= get_next_mid(ses
->server
);
4848 pSMB
->hdr
.Tid
= ses
->tcon_ipc
->tid
;
4849 pSMB
->hdr
.Uid
= ses
->Suid
;
4850 if (ses
->capabilities
& CAP_STATUS32
)
4851 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
4852 if (ses
->capabilities
& CAP_DFS
)
4853 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
4855 if (ses
->capabilities
& CAP_UNICODE
) {
4856 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
4858 cifsConvertToUTF16((__le16
*) pSMB
->RequestFileName
,
4859 search_name
, PATH_MAX
, nls_codepage
,
4861 name_len
++; /* trailing null */
4863 } else { /* BB improve the check for buffer overruns BB */
4864 name_len
= strnlen(search_name
, PATH_MAX
);
4865 name_len
++; /* trailing null */
4866 strncpy(pSMB
->RequestFileName
, search_name
, name_len
);
4869 if (ses
->server
->sign
)
4870 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
4872 pSMB
->hdr
.Uid
= ses
->Suid
;
4874 params
= 2 /* level */ + name_len
/*includes null */ ;
4875 pSMB
->TotalDataCount
= 0;
4876 pSMB
->DataCount
= 0;
4877 pSMB
->DataOffset
= 0;
4878 pSMB
->MaxParameterCount
= 0;
4879 /* BB find exact max SMB PDU from sess structure BB */
4880 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4881 pSMB
->MaxSetupCount
= 0;
4885 pSMB
->Reserved2
= 0;
4886 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4887 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
4888 pSMB
->SetupCount
= 1;
4889 pSMB
->Reserved3
= 0;
4890 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
4891 byte_count
= params
+ 3 /* pad */ ;
4892 pSMB
->ParameterCount
= cpu_to_le16(params
);
4893 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4894 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
4895 inc_rfc1001_len(pSMB
, byte_count
);
4896 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4898 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
4899 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4901 cifs_dbg(FYI
, "Send error in GetDFSRefer = %d\n", rc
);
4904 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4906 /* BB Also check if enough total bytes returned? */
4907 if (rc
|| get_bcc(&pSMBr
->hdr
) < 17) {
4908 rc
= -EIO
; /* bad smb */
4912 cifs_dbg(FYI
, "Decoding GetDFSRefer response BCC: %d Offset %d\n",
4913 get_bcc(&pSMBr
->hdr
), le16_to_cpu(pSMBr
->t2
.DataOffset
));
4915 /* parse returned result into more usable form */
4916 rc
= parse_dfs_referrals(&pSMBr
->dfs_data
,
4917 le16_to_cpu(pSMBr
->t2
.DataCount
),
4918 num_of_nodes
, target_nodes
, nls_codepage
,
4920 (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) != 0);
4923 cifs_buf_release(pSMB
);
4931 /* Query File System Info such as free space to old servers such as Win 9x */
4933 SMBOldQFSInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
4934 struct kstatfs
*FSData
)
4936 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
4937 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4938 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4939 FILE_SYSTEM_ALLOC_INFO
*response_data
;
4941 int bytes_returned
= 0;
4942 __u16 params
, byte_count
;
4944 cifs_dbg(FYI
, "OldQFSInfo\n");
4946 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4951 params
= 2; /* level */
4952 pSMB
->TotalDataCount
= 0;
4953 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4954 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4955 pSMB
->MaxSetupCount
= 0;
4959 pSMB
->Reserved2
= 0;
4960 byte_count
= params
+ 1 /* pad */ ;
4961 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4962 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4963 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4964 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4965 pSMB
->DataCount
= 0;
4966 pSMB
->DataOffset
= 0;
4967 pSMB
->SetupCount
= 1;
4968 pSMB
->Reserved3
= 0;
4969 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4970 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
4971 inc_rfc1001_len(pSMB
, byte_count
);
4972 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4974 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4975 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4977 cifs_dbg(FYI
, "Send error in QFSInfo = %d\n", rc
);
4978 } else { /* decode response */
4979 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4981 if (rc
|| get_bcc(&pSMBr
->hdr
) < 18)
4982 rc
= -EIO
; /* bad smb */
4984 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4985 cifs_dbg(FYI
, "qfsinf resp BCC: %d Offset %d\n",
4986 get_bcc(&pSMBr
->hdr
), data_offset
);
4988 response_data
= (FILE_SYSTEM_ALLOC_INFO
*)
4989 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
4991 le16_to_cpu(response_data
->BytesPerSector
) *
4992 le32_to_cpu(response_data
->
4993 SectorsPerAllocationUnit
);
4995 le32_to_cpu(response_data
->TotalAllocationUnits
);
4996 FSData
->f_bfree
= FSData
->f_bavail
=
4997 le32_to_cpu(response_data
->FreeAllocationUnits
);
4998 cifs_dbg(FYI
, "Blocks: %lld Free: %lld Block size %ld\n",
4999 (unsigned long long)FSData
->f_blocks
,
5000 (unsigned long long)FSData
->f_bfree
,
5004 cifs_buf_release(pSMB
);
5007 goto oldQFSInfoRetry
;
5013 CIFSSMBQFSInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5014 struct kstatfs
*FSData
)
5016 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
5017 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5018 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5019 FILE_SYSTEM_INFO
*response_data
;
5021 int bytes_returned
= 0;
5022 __u16 params
, byte_count
;
5024 cifs_dbg(FYI
, "In QFSInfo\n");
5026 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5031 params
= 2; /* level */
5032 pSMB
->TotalDataCount
= 0;
5033 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5034 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5035 pSMB
->MaxSetupCount
= 0;
5039 pSMB
->Reserved2
= 0;
5040 byte_count
= params
+ 1 /* pad */ ;
5041 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5042 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5043 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5044 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5045 pSMB
->DataCount
= 0;
5046 pSMB
->DataOffset
= 0;
5047 pSMB
->SetupCount
= 1;
5048 pSMB
->Reserved3
= 0;
5049 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5050 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
5051 inc_rfc1001_len(pSMB
, byte_count
);
5052 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5054 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5055 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5057 cifs_dbg(FYI
, "Send error in QFSInfo = %d\n", rc
);
5058 } else { /* decode response */
5059 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5061 if (rc
|| get_bcc(&pSMBr
->hdr
) < 24)
5062 rc
= -EIO
; /* bad smb */
5064 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5068 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5071 le32_to_cpu(response_data
->BytesPerSector
) *
5072 le32_to_cpu(response_data
->
5073 SectorsPerAllocationUnit
);
5075 le64_to_cpu(response_data
->TotalAllocationUnits
);
5076 FSData
->f_bfree
= FSData
->f_bavail
=
5077 le64_to_cpu(response_data
->FreeAllocationUnits
);
5078 cifs_dbg(FYI
, "Blocks: %lld Free: %lld Block size %ld\n",
5079 (unsigned long long)FSData
->f_blocks
,
5080 (unsigned long long)FSData
->f_bfree
,
5084 cifs_buf_release(pSMB
);
5093 CIFSSMBQFSAttributeInfo(const unsigned int xid
, struct cifs_tcon
*tcon
)
5095 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
5096 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5097 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5098 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
5100 int bytes_returned
= 0;
5101 __u16 params
, byte_count
;
5103 cifs_dbg(FYI
, "In QFSAttributeInfo\n");
5105 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5110 params
= 2; /* level */
5111 pSMB
->TotalDataCount
= 0;
5112 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5113 /* BB find exact max SMB PDU from sess structure BB */
5114 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5115 pSMB
->MaxSetupCount
= 0;
5119 pSMB
->Reserved2
= 0;
5120 byte_count
= params
+ 1 /* pad */ ;
5121 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5122 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5123 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5124 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5125 pSMB
->DataCount
= 0;
5126 pSMB
->DataOffset
= 0;
5127 pSMB
->SetupCount
= 1;
5128 pSMB
->Reserved3
= 0;
5129 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5130 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
5131 inc_rfc1001_len(pSMB
, byte_count
);
5132 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5134 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5135 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5137 cifs_dbg(VFS
, "Send error in QFSAttributeInfo = %d\n", rc
);
5138 } else { /* decode response */
5139 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5141 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5142 /* BB also check if enough bytes returned */
5143 rc
= -EIO
; /* bad smb */
5145 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5147 (FILE_SYSTEM_ATTRIBUTE_INFO
5148 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5150 memcpy(&tcon
->fsAttrInfo
, response_data
,
5151 sizeof(FILE_SYSTEM_ATTRIBUTE_INFO
));
5154 cifs_buf_release(pSMB
);
5157 goto QFSAttributeRetry
;
5163 CIFSSMBQFSDeviceInfo(const unsigned int xid
, struct cifs_tcon
*tcon
)
5165 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
5166 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5167 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5168 FILE_SYSTEM_DEVICE_INFO
*response_data
;
5170 int bytes_returned
= 0;
5171 __u16 params
, byte_count
;
5173 cifs_dbg(FYI
, "In QFSDeviceInfo\n");
5175 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5180 params
= 2; /* level */
5181 pSMB
->TotalDataCount
= 0;
5182 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5183 /* BB find exact max SMB PDU from sess structure BB */
5184 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5185 pSMB
->MaxSetupCount
= 0;
5189 pSMB
->Reserved2
= 0;
5190 byte_count
= params
+ 1 /* pad */ ;
5191 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5192 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5193 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5194 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5196 pSMB
->DataCount
= 0;
5197 pSMB
->DataOffset
= 0;
5198 pSMB
->SetupCount
= 1;
5199 pSMB
->Reserved3
= 0;
5200 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5201 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
5202 inc_rfc1001_len(pSMB
, byte_count
);
5203 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5205 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5206 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5208 cifs_dbg(FYI
, "Send error in QFSDeviceInfo = %d\n", rc
);
5209 } else { /* decode response */
5210 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5212 if (rc
|| get_bcc(&pSMBr
->hdr
) <
5213 sizeof(FILE_SYSTEM_DEVICE_INFO
))
5214 rc
= -EIO
; /* bad smb */
5216 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5218 (FILE_SYSTEM_DEVICE_INFO
*)
5219 (((char *) &pSMBr
->hdr
.Protocol
) +
5221 memcpy(&tcon
->fsDevInfo
, response_data
,
5222 sizeof(FILE_SYSTEM_DEVICE_INFO
));
5225 cifs_buf_release(pSMB
);
5228 goto QFSDeviceRetry
;
5234 CIFSSMBQFSUnixInfo(const unsigned int xid
, struct cifs_tcon
*tcon
)
5236 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
5237 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5238 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5239 FILE_SYSTEM_UNIX_INFO
*response_data
;
5241 int bytes_returned
= 0;
5242 __u16 params
, byte_count
;
5244 cifs_dbg(FYI
, "In QFSUnixInfo\n");
5246 rc
= smb_init_no_reconnect(SMB_COM_TRANSACTION2
, 15, tcon
,
5247 (void **) &pSMB
, (void **) &pSMBr
);
5251 params
= 2; /* level */
5252 pSMB
->TotalDataCount
= 0;
5253 pSMB
->DataCount
= 0;
5254 pSMB
->DataOffset
= 0;
5255 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5256 /* BB find exact max SMB PDU from sess structure BB */
5257 pSMB
->MaxDataCount
= cpu_to_le16(100);
5258 pSMB
->MaxSetupCount
= 0;
5262 pSMB
->Reserved2
= 0;
5263 byte_count
= params
+ 1 /* pad */ ;
5264 pSMB
->ParameterCount
= cpu_to_le16(params
);
5265 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5266 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
5267 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5268 pSMB
->SetupCount
= 1;
5269 pSMB
->Reserved3
= 0;
5270 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5271 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
5272 inc_rfc1001_len(pSMB
, byte_count
);
5273 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5275 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5276 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5278 cifs_dbg(VFS
, "Send error in QFSUnixInfo = %d\n", rc
);
5279 } else { /* decode response */
5280 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5282 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5283 rc
= -EIO
; /* bad smb */
5285 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5287 (FILE_SYSTEM_UNIX_INFO
5288 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5290 memcpy(&tcon
->fsUnixInfo
, response_data
,
5291 sizeof(FILE_SYSTEM_UNIX_INFO
));
5294 cifs_buf_release(pSMB
);
5304 CIFSSMBSetFSUnixInfo(const unsigned int xid
, struct cifs_tcon
*tcon
, __u64 cap
)
5306 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
5307 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
5308 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
5310 int bytes_returned
= 0;
5311 __u16 params
, param_offset
, offset
, byte_count
;
5313 cifs_dbg(FYI
, "In SETFSUnixInfo\n");
5315 /* BB switch to small buf init to save memory */
5316 rc
= smb_init_no_reconnect(SMB_COM_TRANSACTION2
, 15, tcon
,
5317 (void **) &pSMB
, (void **) &pSMBr
);
5321 params
= 4; /* 2 bytes zero followed by info level. */
5322 pSMB
->MaxSetupCount
= 0;
5326 pSMB
->Reserved2
= 0;
5327 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
)
5329 offset
= param_offset
+ params
;
5331 pSMB
->MaxParameterCount
= cpu_to_le16(4);
5332 /* BB find exact max SMB PDU from sess structure BB */
5333 pSMB
->MaxDataCount
= cpu_to_le16(100);
5334 pSMB
->SetupCount
= 1;
5335 pSMB
->Reserved3
= 0;
5336 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
5337 byte_count
= 1 /* pad */ + params
+ 12;
5339 pSMB
->DataCount
= cpu_to_le16(12);
5340 pSMB
->ParameterCount
= cpu_to_le16(params
);
5341 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5342 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5343 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5344 pSMB
->DataOffset
= cpu_to_le16(offset
);
5348 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
5351 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
5352 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
5353 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
5355 inc_rfc1001_len(pSMB
, byte_count
);
5356 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5358 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5359 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5361 cifs_dbg(VFS
, "Send error in SETFSUnixInfo = %d\n", rc
);
5362 } else { /* decode response */
5363 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5365 rc
= -EIO
; /* bad smb */
5367 cifs_buf_release(pSMB
);
5370 goto SETFSUnixRetry
;
5378 CIFSSMBQFSPosixInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5379 struct kstatfs
*FSData
)
5381 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
5382 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5383 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5384 FILE_SYSTEM_POSIX_INFO
*response_data
;
5386 int bytes_returned
= 0;
5387 __u16 params
, byte_count
;
5389 cifs_dbg(FYI
, "In QFSPosixInfo\n");
5391 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5396 params
= 2; /* level */
5397 pSMB
->TotalDataCount
= 0;
5398 pSMB
->DataCount
= 0;
5399 pSMB
->DataOffset
= 0;
5400 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5401 /* BB find exact max SMB PDU from sess structure BB */
5402 pSMB
->MaxDataCount
= cpu_to_le16(100);
5403 pSMB
->MaxSetupCount
= 0;
5407 pSMB
->Reserved2
= 0;
5408 byte_count
= params
+ 1 /* pad */ ;
5409 pSMB
->ParameterCount
= cpu_to_le16(params
);
5410 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5411 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
5412 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5413 pSMB
->SetupCount
= 1;
5414 pSMB
->Reserved3
= 0;
5415 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5416 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
5417 inc_rfc1001_len(pSMB
, byte_count
);
5418 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5420 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5421 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5423 cifs_dbg(FYI
, "Send error in QFSUnixInfo = %d\n", rc
);
5424 } else { /* decode response */
5425 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5427 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5428 rc
= -EIO
; /* bad smb */
5430 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5432 (FILE_SYSTEM_POSIX_INFO
5433 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5436 le32_to_cpu(response_data
->BlockSize
);
5438 le64_to_cpu(response_data
->TotalBlocks
);
5440 le64_to_cpu(response_data
->BlocksAvail
);
5441 if (response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
5442 FSData
->f_bavail
= FSData
->f_bfree
;
5445 le64_to_cpu(response_data
->UserBlocksAvail
);
5447 if (response_data
->TotalFileNodes
!= cpu_to_le64(-1))
5449 le64_to_cpu(response_data
->TotalFileNodes
);
5450 if (response_data
->FreeFileNodes
!= cpu_to_le64(-1))
5452 le64_to_cpu(response_data
->FreeFileNodes
);
5455 cifs_buf_release(pSMB
);
5465 * We can not use write of zero bytes trick to set file size due to need for
5466 * large file support. Also note that this SetPathInfo is preferred to
5467 * SetFileInfo based method in next routine which is only needed to work around
5468 * a sharing violation bugin Samba which this routine can run into.
5471 CIFSSMBSetEOF(const unsigned int xid
, struct cifs_tcon
*tcon
,
5472 const char *file_name
, __u64 size
, struct cifs_sb_info
*cifs_sb
,
5473 bool set_allocation
)
5475 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
5476 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
5477 struct file_end_of_file_info
*parm_data
;
5480 int bytes_returned
= 0;
5481 int remap
= cifs_remap(cifs_sb
);
5483 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
5485 cifs_dbg(FYI
, "In SetEOF\n");
5487 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5492 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5494 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, file_name
,
5495 PATH_MAX
, cifs_sb
->local_nls
, remap
);
5496 name_len
++; /* trailing null */
5498 } else { /* BB improve the check for buffer overruns BB */
5499 name_len
= strnlen(file_name
, PATH_MAX
);
5500 name_len
++; /* trailing null */
5501 strncpy(pSMB
->FileName
, file_name
, name_len
);
5503 params
= 6 + name_len
;
5504 data_count
= sizeof(struct file_end_of_file_info
);
5505 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5506 pSMB
->MaxDataCount
= cpu_to_le16(4100);
5507 pSMB
->MaxSetupCount
= 0;
5511 pSMB
->Reserved2
= 0;
5512 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5513 InformationLevel
) - 4;
5514 offset
= param_offset
+ params
;
5515 if (set_allocation
) {
5516 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5517 pSMB
->InformationLevel
=
5518 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
5520 pSMB
->InformationLevel
=
5521 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
5522 } else /* Set File Size */ {
5523 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5524 pSMB
->InformationLevel
=
5525 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
5527 pSMB
->InformationLevel
=
5528 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
5532 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
5534 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5535 pSMB
->DataOffset
= cpu_to_le16(offset
);
5536 pSMB
->SetupCount
= 1;
5537 pSMB
->Reserved3
= 0;
5538 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5539 byte_count
= 3 /* pad */ + params
+ data_count
;
5540 pSMB
->DataCount
= cpu_to_le16(data_count
);
5541 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5542 pSMB
->ParameterCount
= cpu_to_le16(params
);
5543 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5544 pSMB
->Reserved4
= 0;
5545 inc_rfc1001_len(pSMB
, byte_count
);
5546 parm_data
->FileSize
= cpu_to_le64(size
);
5547 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5548 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5549 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5551 cifs_dbg(FYI
, "SetPathInfo (file size) returned %d\n", rc
);
5553 cifs_buf_release(pSMB
);
5562 CIFSSMBSetFileSize(const unsigned int xid
, struct cifs_tcon
*tcon
,
5563 struct cifsFileInfo
*cfile
, __u64 size
, bool set_allocation
)
5565 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5566 struct file_end_of_file_info
*parm_data
;
5568 __u16 params
, param_offset
, offset
, byte_count
, count
;
5570 cifs_dbg(FYI
, "SetFileSize (via SetFileInfo) %lld\n",
5572 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5577 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)cfile
->pid
);
5578 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(cfile
->pid
>> 16));
5581 pSMB
->MaxSetupCount
= 0;
5585 pSMB
->Reserved2
= 0;
5586 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5587 offset
= param_offset
+ params
;
5589 count
= sizeof(struct file_end_of_file_info
);
5590 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5591 /* BB find exact max SMB PDU from sess structure BB */
5592 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5593 pSMB
->SetupCount
= 1;
5594 pSMB
->Reserved3
= 0;
5595 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5596 byte_count
= 3 /* pad */ + params
+ count
;
5597 pSMB
->DataCount
= cpu_to_le16(count
);
5598 pSMB
->ParameterCount
= cpu_to_le16(params
);
5599 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5600 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5601 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5603 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
)
5605 pSMB
->DataOffset
= cpu_to_le16(offset
);
5606 parm_data
->FileSize
= cpu_to_le64(size
);
5607 pSMB
->Fid
= cfile
->fid
.netfid
;
5608 if (set_allocation
) {
5609 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5610 pSMB
->InformationLevel
=
5611 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
5613 pSMB
->InformationLevel
=
5614 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
5615 } else /* Set File Size */ {
5616 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5617 pSMB
->InformationLevel
=
5618 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
5620 pSMB
->InformationLevel
=
5621 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
5623 pSMB
->Reserved4
= 0;
5624 inc_rfc1001_len(pSMB
, byte_count
);
5625 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5626 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5627 cifs_small_buf_release(pSMB
);
5629 cifs_dbg(FYI
, "Send error in SetFileInfo (SetFileSize) = %d\n",
5633 /* Note: On -EAGAIN error only caller can retry on handle based calls
5634 since file handle passed in no longer valid */
5639 /* Some legacy servers such as NT4 require that the file times be set on
5640 an open handle, rather than by pathname - this is awkward due to
5641 potential access conflicts on the open, but it is unavoidable for these
5642 old servers since the only other choice is to go from 100 nanosecond DCE
5643 time and resort to the original setpathinfo level which takes the ancient
5644 DOS time format with 2 second granularity */
5646 CIFSSMBSetFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5647 const FILE_BASIC_INFO
*data
, __u16 fid
, __u32 pid_of_opener
)
5649 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5652 __u16 params
, param_offset
, offset
, byte_count
, count
;
5654 cifs_dbg(FYI
, "Set Times (via SetFileInfo)\n");
5655 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5660 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5661 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5664 pSMB
->MaxSetupCount
= 0;
5668 pSMB
->Reserved2
= 0;
5669 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5670 offset
= param_offset
+ params
;
5672 data_offset
= (char *)pSMB
+
5673 offsetof(struct smb_hdr
, Protocol
) + offset
;
5675 count
= sizeof(FILE_BASIC_INFO
);
5676 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5677 /* BB find max SMB PDU from sess */
5678 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5679 pSMB
->SetupCount
= 1;
5680 pSMB
->Reserved3
= 0;
5681 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5682 byte_count
= 3 /* pad */ + params
+ count
;
5683 pSMB
->DataCount
= cpu_to_le16(count
);
5684 pSMB
->ParameterCount
= cpu_to_le16(params
);
5685 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5686 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5687 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5688 pSMB
->DataOffset
= cpu_to_le16(offset
);
5690 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5691 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5693 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5694 pSMB
->Reserved4
= 0;
5695 inc_rfc1001_len(pSMB
, byte_count
);
5696 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5697 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5698 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5699 cifs_small_buf_release(pSMB
);
5701 cifs_dbg(FYI
, "Send error in Set Time (SetFileInfo) = %d\n",
5704 /* Note: On -EAGAIN error only caller can retry on handle based calls
5705 since file handle passed in no longer valid */
5711 CIFSSMBSetFileDisposition(const unsigned int xid
, struct cifs_tcon
*tcon
,
5712 bool delete_file
, __u16 fid
, __u32 pid_of_opener
)
5714 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5717 __u16 params
, param_offset
, offset
, byte_count
, count
;
5719 cifs_dbg(FYI
, "Set File Disposition (via SetFileInfo)\n");
5720 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5725 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5726 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5729 pSMB
->MaxSetupCount
= 0;
5733 pSMB
->Reserved2
= 0;
5734 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5735 offset
= param_offset
+ params
;
5737 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5740 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5741 /* BB find max SMB PDU from sess */
5742 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5743 pSMB
->SetupCount
= 1;
5744 pSMB
->Reserved3
= 0;
5745 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5746 byte_count
= 3 /* pad */ + params
+ count
;
5747 pSMB
->DataCount
= cpu_to_le16(count
);
5748 pSMB
->ParameterCount
= cpu_to_le16(params
);
5749 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5750 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5751 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5752 pSMB
->DataOffset
= cpu_to_le16(offset
);
5754 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO
);
5755 pSMB
->Reserved4
= 0;
5756 inc_rfc1001_len(pSMB
, byte_count
);
5757 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5758 *data_offset
= delete_file
? 1 : 0;
5759 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5760 cifs_small_buf_release(pSMB
);
5762 cifs_dbg(FYI
, "Send error in SetFileDisposition = %d\n", rc
);
5768 CIFSSMBSetPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5769 const char *fileName
, const FILE_BASIC_INFO
*data
,
5770 const struct nls_table
*nls_codepage
, int remap
)
5772 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5773 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5776 int bytes_returned
= 0;
5778 __u16 params
, param_offset
, offset
, byte_count
, count
;
5780 cifs_dbg(FYI
, "In SetTimes\n");
5783 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5788 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5790 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
5791 PATH_MAX
, nls_codepage
, remap
);
5792 name_len
++; /* trailing null */
5794 } else { /* BB improve the check for buffer overruns BB */
5795 name_len
= strnlen(fileName
, PATH_MAX
);
5796 name_len
++; /* trailing null */
5797 strncpy(pSMB
->FileName
, fileName
, name_len
);
5800 params
= 6 + name_len
;
5801 count
= sizeof(FILE_BASIC_INFO
);
5802 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5803 /* BB find max SMB PDU from sess structure BB */
5804 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5805 pSMB
->MaxSetupCount
= 0;
5809 pSMB
->Reserved2
= 0;
5810 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5811 InformationLevel
) - 4;
5812 offset
= param_offset
+ params
;
5813 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5814 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5815 pSMB
->DataOffset
= cpu_to_le16(offset
);
5816 pSMB
->SetupCount
= 1;
5817 pSMB
->Reserved3
= 0;
5818 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5819 byte_count
= 3 /* pad */ + params
+ count
;
5821 pSMB
->DataCount
= cpu_to_le16(count
);
5822 pSMB
->ParameterCount
= cpu_to_le16(params
);
5823 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5824 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5825 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5826 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5828 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5829 pSMB
->Reserved4
= 0;
5830 inc_rfc1001_len(pSMB
, byte_count
);
5831 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5832 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5833 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5834 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5836 cifs_dbg(FYI
, "SetPathInfo (times) returned %d\n", rc
);
5838 cifs_buf_release(pSMB
);
5846 /* Can not be used to set time stamps yet (due to old DOS time format) */
5847 /* Can be used to set attributes */
5848 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
5849 handling it anyway and NT4 was what we thought it would be needed for
5850 Do not delete it until we prove whether needed for Win9x though */
5852 CIFSSMBSetAttrLegacy(unsigned int xid
, struct cifs_tcon
*tcon
, char *fileName
,
5853 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
5855 SETATTR_REQ
*pSMB
= NULL
;
5856 SETATTR_RSP
*pSMBr
= NULL
;
5861 cifs_dbg(FYI
, "In SetAttrLegacy\n");
5864 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
5869 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5871 ConvertToUTF16((__le16
*) pSMB
->fileName
, fileName
,
5872 PATH_MAX
, nls_codepage
);
5873 name_len
++; /* trailing null */
5875 } else { /* BB improve the check for buffer overruns BB */
5876 name_len
= strnlen(fileName
, PATH_MAX
);
5877 name_len
++; /* trailing null */
5878 strncpy(pSMB
->fileName
, fileName
, name_len
);
5880 pSMB
->attr
= cpu_to_le16(dos_attrs
);
5881 pSMB
->BufferFormat
= 0x04;
5882 inc_rfc1001_len(pSMB
, name_len
+ 1);
5883 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
5884 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5885 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5887 cifs_dbg(FYI
, "Error in LegacySetAttr = %d\n", rc
);
5889 cifs_buf_release(pSMB
);
5892 goto SetAttrLgcyRetry
;
5896 #endif /* temporarily unneeded SetAttr legacy function */
5899 cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO
*data_offset
,
5900 const struct cifs_unix_set_info_args
*args
)
5902 u64 uid
= NO_CHANGE_64
, gid
= NO_CHANGE_64
;
5903 u64 mode
= args
->mode
;
5905 if (uid_valid(args
->uid
))
5906 uid
= from_kuid(&init_user_ns
, args
->uid
);
5907 if (gid_valid(args
->gid
))
5908 gid
= from_kgid(&init_user_ns
, args
->gid
);
5911 * Samba server ignores set of file size to zero due to bugs in some
5912 * older clients, but we should be precise - we use SetFileSize to
5913 * set file size and do not want to truncate file size to zero
5914 * accidentally as happened on one Samba server beta by putting
5915 * zero instead of -1 here
5917 data_offset
->EndOfFile
= cpu_to_le64(NO_CHANGE_64
);
5918 data_offset
->NumOfBytes
= cpu_to_le64(NO_CHANGE_64
);
5919 data_offset
->LastStatusChange
= cpu_to_le64(args
->ctime
);
5920 data_offset
->LastAccessTime
= cpu_to_le64(args
->atime
);
5921 data_offset
->LastModificationTime
= cpu_to_le64(args
->mtime
);
5922 data_offset
->Uid
= cpu_to_le64(uid
);
5923 data_offset
->Gid
= cpu_to_le64(gid
);
5924 /* better to leave device as zero when it is */
5925 data_offset
->DevMajor
= cpu_to_le64(MAJOR(args
->device
));
5926 data_offset
->DevMinor
= cpu_to_le64(MINOR(args
->device
));
5927 data_offset
->Permissions
= cpu_to_le64(mode
);
5930 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
5931 else if (S_ISDIR(mode
))
5932 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
5933 else if (S_ISLNK(mode
))
5934 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
5935 else if (S_ISCHR(mode
))
5936 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
5937 else if (S_ISBLK(mode
))
5938 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
5939 else if (S_ISFIFO(mode
))
5940 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
5941 else if (S_ISSOCK(mode
))
5942 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
5946 CIFSSMBUnixSetFileInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
5947 const struct cifs_unix_set_info_args
*args
,
5948 u16 fid
, u32 pid_of_opener
)
5950 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5953 u16 params
, param_offset
, offset
, byte_count
, count
;
5955 cifs_dbg(FYI
, "Set Unix Info (via SetFileInfo)\n");
5956 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5961 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5962 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5965 pSMB
->MaxSetupCount
= 0;
5969 pSMB
->Reserved2
= 0;
5970 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5971 offset
= param_offset
+ params
;
5973 data_offset
= (char *)pSMB
+
5974 offsetof(struct smb_hdr
, Protocol
) + offset
;
5976 count
= sizeof(FILE_UNIX_BASIC_INFO
);
5978 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5979 /* BB find max SMB PDU from sess */
5980 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5981 pSMB
->SetupCount
= 1;
5982 pSMB
->Reserved3
= 0;
5983 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5984 byte_count
= 3 /* pad */ + params
+ count
;
5985 pSMB
->DataCount
= cpu_to_le16(count
);
5986 pSMB
->ParameterCount
= cpu_to_le16(params
);
5987 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5988 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5989 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5990 pSMB
->DataOffset
= cpu_to_le16(offset
);
5992 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
5993 pSMB
->Reserved4
= 0;
5994 inc_rfc1001_len(pSMB
, byte_count
);
5995 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5997 cifs_fill_unix_set_info((FILE_UNIX_BASIC_INFO
*)data_offset
, args
);
5999 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
6000 cifs_small_buf_release(pSMB
);
6002 cifs_dbg(FYI
, "Send error in Set Time (SetFileInfo) = %d\n",
6005 /* Note: On -EAGAIN error only caller can retry on handle based calls
6006 since file handle passed in no longer valid */
6012 CIFSSMBUnixSetPathInfo(const unsigned int xid
, struct cifs_tcon
*tcon
,
6013 const char *file_name
,
6014 const struct cifs_unix_set_info_args
*args
,
6015 const struct nls_table
*nls_codepage
, int remap
)
6017 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
6018 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
6021 int bytes_returned
= 0;
6022 FILE_UNIX_BASIC_INFO
*data_offset
;
6023 __u16 params
, param_offset
, offset
, count
, byte_count
;
6025 cifs_dbg(FYI
, "In SetUID/GID/Mode\n");
6027 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6032 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6034 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, file_name
,
6035 PATH_MAX
, nls_codepage
, remap
);
6036 name_len
++; /* trailing null */
6038 } else { /* BB improve the check for buffer overruns BB */
6039 name_len
= strnlen(file_name
, PATH_MAX
);
6040 name_len
++; /* trailing null */
6041 strncpy(pSMB
->FileName
, file_name
, name_len
);
6044 params
= 6 + name_len
;
6045 count
= sizeof(FILE_UNIX_BASIC_INFO
);
6046 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6047 /* BB find max SMB PDU from sess structure BB */
6048 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6049 pSMB
->MaxSetupCount
= 0;
6053 pSMB
->Reserved2
= 0;
6054 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
6055 InformationLevel
) - 4;
6056 offset
= param_offset
+ params
;
6058 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
6060 memset(data_offset
, 0, count
);
6061 pSMB
->DataOffset
= cpu_to_le16(offset
);
6062 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6063 pSMB
->SetupCount
= 1;
6064 pSMB
->Reserved3
= 0;
6065 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
6066 byte_count
= 3 /* pad */ + params
+ count
;
6067 pSMB
->ParameterCount
= cpu_to_le16(params
);
6068 pSMB
->DataCount
= cpu_to_le16(count
);
6069 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6070 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6071 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
6072 pSMB
->Reserved4
= 0;
6073 inc_rfc1001_len(pSMB
, byte_count
);
6075 cifs_fill_unix_set_info(data_offset
, args
);
6077 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6078 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6079 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6081 cifs_dbg(FYI
, "SetPathInfo (perms) returned %d\n", rc
);
6083 cifs_buf_release(pSMB
);
6089 #ifdef CONFIG_CIFS_XATTR
6091 * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common
6092 * function used by listxattr and getxattr type calls. When ea_name is set,
6093 * it looks for that attribute name and stuffs that value into the EAData
6094 * buffer. When ea_name is NULL, it stuffs a list of attribute names into the
6095 * buffer. In both cases, the return value is either the length of the
6096 * resulting data or a negative error code. If EAData is a NULL pointer then
6097 * the data isn't copied to it, but the length is returned.
6100 CIFSSMBQAllEAs(const unsigned int xid
, struct cifs_tcon
*tcon
,
6101 const unsigned char *searchName
, const unsigned char *ea_name
,
6102 char *EAData
, size_t buf_size
,
6103 struct cifs_sb_info
*cifs_sb
)
6105 /* BB assumes one setup word */
6106 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
6107 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
6108 int remap
= cifs_remap(cifs_sb
);
6109 struct nls_table
*nls_codepage
= cifs_sb
->local_nls
;
6113 struct fealist
*ea_response_data
;
6114 struct fea
*temp_fea
;
6117 __u16 params
, byte_count
, data_offset
;
6118 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
6120 cifs_dbg(FYI
, "In Query All EAs path %s\n", searchName
);
6122 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6127 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6129 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
6130 PATH_MAX
, nls_codepage
, remap
);
6131 list_len
++; /* trailing null */
6133 } else { /* BB improve the check for buffer overruns BB */
6134 list_len
= strnlen(searchName
, PATH_MAX
);
6135 list_len
++; /* trailing null */
6136 strncpy(pSMB
->FileName
, searchName
, list_len
);
6139 params
= 2 /* level */ + 4 /* reserved */ + list_len
/* includes NUL */;
6140 pSMB
->TotalDataCount
= 0;
6141 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6142 /* BB find exact max SMB PDU from sess structure BB */
6143 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
6144 pSMB
->MaxSetupCount
= 0;
6148 pSMB
->Reserved2
= 0;
6149 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
6150 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
6151 pSMB
->DataCount
= 0;
6152 pSMB
->DataOffset
= 0;
6153 pSMB
->SetupCount
= 1;
6154 pSMB
->Reserved3
= 0;
6155 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
6156 byte_count
= params
+ 1 /* pad */ ;
6157 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
6158 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
6159 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
6160 pSMB
->Reserved4
= 0;
6161 inc_rfc1001_len(pSMB
, byte_count
);
6162 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6164 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6165 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6167 cifs_dbg(FYI
, "Send error in QueryAllEAs = %d\n", rc
);
6172 /* BB also check enough total bytes returned */
6173 /* BB we need to improve the validity checking
6174 of these trans2 responses */
6176 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
6177 if (rc
|| get_bcc(&pSMBr
->hdr
) < 4) {
6178 rc
= -EIO
; /* bad smb */
6182 /* check that length of list is not more than bcc */
6183 /* check that each entry does not go beyond length
6185 /* check that each element of each entry does not
6186 go beyond end of list */
6187 /* validate_trans2_offsets() */
6188 /* BB check if start of smb + data_offset > &bcc+ bcc */
6190 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
6191 ea_response_data
= (struct fealist
*)
6192 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
6194 list_len
= le32_to_cpu(ea_response_data
->list_len
);
6195 cifs_dbg(FYI
, "ea length %d\n", list_len
);
6196 if (list_len
<= 8) {
6197 cifs_dbg(FYI
, "empty EA list returned from server\n");
6198 /* didn't find the named attribute */
6204 /* make sure list_len doesn't go past end of SMB */
6205 end_of_smb
= (char *)pByteArea(&pSMBr
->hdr
) + get_bcc(&pSMBr
->hdr
);
6206 if ((char *)ea_response_data
+ list_len
> end_of_smb
) {
6207 cifs_dbg(FYI
, "EA list appears to go beyond SMB\n");
6212 /* account for ea list len */
6214 temp_fea
= ea_response_data
->list
;
6215 temp_ptr
= (char *)temp_fea
;
6216 while (list_len
> 0) {
6217 unsigned int name_len
;
6222 /* make sure we can read name_len and value_len */
6224 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
6229 name_len
= temp_fea
->name_len
;
6230 value_len
= le16_to_cpu(temp_fea
->value_len
);
6231 list_len
-= name_len
+ 1 + value_len
;
6233 cifs_dbg(FYI
, "EA entry goes beyond length of list\n");
6239 if (ea_name_len
== name_len
&&
6240 memcmp(ea_name
, temp_ptr
, name_len
) == 0) {
6241 temp_ptr
+= name_len
+ 1;
6245 if ((size_t)value_len
> buf_size
) {
6249 memcpy(EAData
, temp_ptr
, value_len
);
6253 /* account for prefix user. and trailing null */
6254 rc
+= (5 + 1 + name_len
);
6255 if (rc
< (int) buf_size
) {
6256 memcpy(EAData
, "user.", 5);
6258 memcpy(EAData
, temp_ptr
, name_len
);
6260 /* null terminate name */
6263 } else if (buf_size
== 0) {
6264 /* skip copy - calc size only */
6266 /* stop before overrun buffer */
6271 temp_ptr
+= name_len
+ 1 + value_len
;
6272 temp_fea
= (struct fea
*)temp_ptr
;
6275 /* didn't find the named attribute */
6280 cifs_buf_release(pSMB
);
6288 CIFSSMBSetEA(const unsigned int xid
, struct cifs_tcon
*tcon
,
6289 const char *fileName
, const char *ea_name
, const void *ea_value
,
6290 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
6291 struct cifs_sb_info
*cifs_sb
)
6293 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
6294 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
6295 struct fealist
*parm_data
;
6298 int bytes_returned
= 0;
6299 __u16 params
, param_offset
, byte_count
, offset
, count
;
6300 int remap
= cifs_remap(cifs_sb
);
6302 cifs_dbg(FYI
, "In SetEA\n");
6304 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6309 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6311 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
6312 PATH_MAX
, nls_codepage
, remap
);
6313 name_len
++; /* trailing null */
6315 } else { /* BB improve the check for buffer overruns BB */
6316 name_len
= strnlen(fileName
, PATH_MAX
);
6317 name_len
++; /* trailing null */
6318 strncpy(pSMB
->FileName
, fileName
, name_len
);
6321 params
= 6 + name_len
;
6323 /* done calculating parms using name_len of file name,
6324 now use name_len to calculate length of ea name
6325 we are going to create in the inode xattrs */
6326 if (ea_name
== NULL
)
6329 name_len
= strnlen(ea_name
, 255);
6331 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
;
6332 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6333 /* BB find max SMB PDU from sess */
6334 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6335 pSMB
->MaxSetupCount
= 0;
6339 pSMB
->Reserved2
= 0;
6340 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
6341 InformationLevel
) - 4;
6342 offset
= param_offset
+ params
;
6343 pSMB
->InformationLevel
=
6344 cpu_to_le16(SMB_SET_FILE_EA
);
6346 parm_data
= (void *)pSMB
+ offsetof(struct smb_hdr
, Protocol
) + offset
;
6347 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6348 pSMB
->DataOffset
= cpu_to_le16(offset
);
6349 pSMB
->SetupCount
= 1;
6350 pSMB
->Reserved3
= 0;
6351 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
6352 byte_count
= 3 /* pad */ + params
+ count
;
6353 pSMB
->DataCount
= cpu_to_le16(count
);
6354 parm_data
->list_len
= cpu_to_le32(count
);
6355 parm_data
->list
[0].EA_flags
= 0;
6356 /* we checked above that name len is less than 255 */
6357 parm_data
->list
[0].name_len
= (__u8
)name_len
;
6358 /* EA names are always ASCII */
6360 strncpy(parm_data
->list
[0].name
, ea_name
, name_len
);
6361 parm_data
->list
[0].name
[name_len
] = 0;
6362 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
6363 /* caller ensures that ea_value_len is less than 64K but
6364 we need to ensure that it fits within the smb */
6366 /*BB add length check to see if it would fit in
6367 negotiated SMB buffer size BB */
6368 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
6370 memcpy(parm_data
->list
[0].name
+name_len
+1,
6371 ea_value
, ea_value_len
);
6373 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6374 pSMB
->ParameterCount
= cpu_to_le16(params
);
6375 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6376 pSMB
->Reserved4
= 0;
6377 inc_rfc1001_len(pSMB
, byte_count
);
6378 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6379 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6380 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6382 cifs_dbg(FYI
, "SetPathInfo (EA) returned %d\n", rc
);
6384 cifs_buf_release(pSMB
);
6393 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */
6395 * Years ago the kernel added a "dnotify" function for Samba server,
6396 * to allow network clients (such as Windows) to display updated
6397 * lists of files in directory listings automatically when
6398 * files are added by one user when another user has the
6399 * same directory open on their desktop. The Linux cifs kernel
6400 * client hooked into the kernel side of this interface for
6401 * the same reason, but ironically when the VFS moved from
6402 * "dnotify" to "inotify" it became harder to plug in Linux
6403 * network file system clients (the most obvious use case
6404 * for notify interfaces is when multiple users can update
6405 * the contents of the same directory - exactly what network
6406 * file systems can do) although the server (Samba) could
6407 * still use it. For the short term we leave the worker
6408 * function ifdeffed out (below) until inotify is fixed
6409 * in the VFS to make it easier to plug in network file
6410 * system clients. If inotify turns out to be permanently
6411 * incompatible for network fs clients, we could instead simply
6412 * expose this config flag by adding a future cifs (and smb2) notify ioctl.
6414 int CIFSSMBNotify(const unsigned int xid
, struct cifs_tcon
*tcon
,
6415 const int notify_subdirs
, const __u16 netfid
,
6416 __u32 filter
, struct file
*pfile
, int multishot
,
6417 const struct nls_table
*nls_codepage
)
6420 struct smb_com_transaction_change_notify_req
*pSMB
= NULL
;
6421 struct smb_com_ntransaction_change_notify_rsp
*pSMBr
= NULL
;
6422 struct dir_notify_req
*dnotify_req
;
6425 cifs_dbg(FYI
, "In CIFSSMBNotify for file handle %d\n", (int)netfid
);
6426 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
6431 pSMB
->TotalParameterCount
= 0 ;
6432 pSMB
->TotalDataCount
= 0;
6433 pSMB
->MaxParameterCount
= cpu_to_le32(2);
6434 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
6435 pSMB
->MaxSetupCount
= 4;
6437 pSMB
->ParameterOffset
= 0;
6438 pSMB
->DataCount
= 0;
6439 pSMB
->DataOffset
= 0;
6440 pSMB
->SetupCount
= 4; /* single byte does not need le conversion */
6441 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE
);
6442 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
6444 pSMB
->WatchTree
= 1; /* one byte - no le conversion needed */
6445 pSMB
->Reserved2
= 0;
6446 pSMB
->CompletionFilter
= cpu_to_le32(filter
);
6447 pSMB
->Fid
= netfid
; /* file handle always le */
6448 pSMB
->ByteCount
= 0;
6450 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6451 (struct smb_hdr
*)pSMBr
, &bytes_returned
,
6454 cifs_dbg(FYI
, "Error in Notify = %d\n", rc
);
6456 /* Add file to outstanding requests */
6457 /* BB change to kmem cache alloc */
6458 dnotify_req
= kmalloc(
6459 sizeof(struct dir_notify_req
),
6462 dnotify_req
->Pid
= pSMB
->hdr
.Pid
;
6463 dnotify_req
->PidHigh
= pSMB
->hdr
.PidHigh
;
6464 dnotify_req
->Mid
= pSMB
->hdr
.Mid
;
6465 dnotify_req
->Tid
= pSMB
->hdr
.Tid
;
6466 dnotify_req
->Uid
= pSMB
->hdr
.Uid
;
6467 dnotify_req
->netfid
= netfid
;
6468 dnotify_req
->pfile
= pfile
;
6469 dnotify_req
->filter
= filter
;
6470 dnotify_req
->multishot
= multishot
;
6471 spin_lock(&GlobalMid_Lock
);
6472 list_add_tail(&dnotify_req
->lhead
,
6473 &GlobalDnotifyReqList
);
6474 spin_unlock(&GlobalMid_Lock
);
6478 cifs_buf_release(pSMB
);
6481 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */