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 <asm/uaccess.h>
42 #include "cifsproto.h"
43 #include "cifs_unicode.h"
44 #include "cifs_debug.h"
47 #ifdef CONFIG_CIFS_POSIX
52 #ifdef CONFIG_CIFS_WEAK_PW_HASH
53 {LANMAN_PROT
, "\2LM1.2X002"},
54 {LANMAN2_PROT
, "\2LANMAN2.1"},
55 #endif /* weak password hashing for legacy clients */
56 {CIFS_PROT
, "\2NT LM 0.12"},
57 {POSIX_PROT
, "\2POSIX 2"},
65 #ifdef CONFIG_CIFS_WEAK_PW_HASH
66 {LANMAN_PROT
, "\2LM1.2X002"},
67 {LANMAN2_PROT
, "\2LANMAN2.1"},
68 #endif /* weak password hashing for legacy clients */
69 {CIFS_PROT
, "\2NT LM 0.12"},
74 /* define the number of elements in the cifs dialect array */
75 #ifdef CONFIG_CIFS_POSIX
76 #ifdef CONFIG_CIFS_WEAK_PW_HASH
77 #define CIFS_NUM_PROT 4
79 #define CIFS_NUM_PROT 2
80 #endif /* CIFS_WEAK_PW_HASH */
82 #ifdef CONFIG_CIFS_WEAK_PW_HASH
83 #define CIFS_NUM_PROT 3
85 #define CIFS_NUM_PROT 1
86 #endif /* CONFIG_CIFS_WEAK_PW_HASH */
87 #endif /* CIFS_POSIX */
89 /* Forward declarations */
90 static void cifs_readv_complete(struct work_struct
*work
);
92 /* Mark as invalid, all open files on tree connections since they
93 were closed when session to server was lost */
94 static void mark_open_files_invalid(struct cifs_tcon
*pTcon
)
96 struct cifsFileInfo
*open_file
= NULL
;
97 struct list_head
*tmp
;
98 struct list_head
*tmp1
;
100 /* list all files open on tree connection and mark them invalid */
101 spin_lock(&cifs_file_list_lock
);
102 list_for_each_safe(tmp
, tmp1
, &pTcon
->openFileList
) {
103 open_file
= list_entry(tmp
, struct cifsFileInfo
, tlist
);
104 open_file
->invalidHandle
= true;
105 open_file
->oplock_break_cancelled
= true;
107 spin_unlock(&cifs_file_list_lock
);
108 /* BB Add call to invalidate_inodes(sb) for all superblocks mounted
112 /* reconnect the socket, tcon, and smb session if needed */
114 cifs_reconnect_tcon(struct cifs_tcon
*tcon
, int smb_command
)
117 struct cifs_ses
*ses
;
118 struct TCP_Server_Info
*server
;
119 struct nls_table
*nls_codepage
;
122 * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
123 * tcp and smb session status done differently for those three - in the
130 server
= ses
->server
;
133 * only tree disconnect, open, and write, (and ulogoff which does not
134 * have tcon) are allowed as we start force umount
136 if (tcon
->tidStatus
== CifsExiting
) {
137 if (smb_command
!= SMB_COM_WRITE_ANDX
&&
138 smb_command
!= SMB_COM_OPEN_ANDX
&&
139 smb_command
!= SMB_COM_TREE_DISCONNECT
) {
140 cFYI(1, "can not send cmd %d while umounting",
147 * Give demultiplex thread up to 10 seconds to reconnect, should be
148 * greater than cifs socket timeout which is 7 seconds
150 while (server
->tcpStatus
== CifsNeedReconnect
) {
151 wait_event_interruptible_timeout(server
->response_q
,
152 (server
->tcpStatus
!= CifsNeedReconnect
), 10 * HZ
);
154 /* are we still trying to reconnect? */
155 if (server
->tcpStatus
!= CifsNeedReconnect
)
159 * on "soft" mounts we wait once. Hard mounts keep
160 * retrying until process is killed or server comes
164 cFYI(1, "gave up waiting on reconnect in smb_init");
169 if (!ses
->need_reconnect
&& !tcon
->need_reconnect
)
172 nls_codepage
= load_nls_default();
175 * need to prevent multiple threads trying to simultaneously
176 * reconnect the same SMB session
178 mutex_lock(&ses
->session_mutex
);
179 rc
= cifs_negotiate_protocol(0, ses
);
180 if (rc
== 0 && ses
->need_reconnect
)
181 rc
= cifs_setup_session(0, ses
, nls_codepage
);
183 /* do we need to reconnect tcon? */
184 if (rc
|| !tcon
->need_reconnect
) {
185 mutex_unlock(&ses
->session_mutex
);
189 mark_open_files_invalid(tcon
);
190 rc
= CIFSTCon(0, ses
, tcon
->treeName
, tcon
, nls_codepage
);
191 mutex_unlock(&ses
->session_mutex
);
192 cFYI(1, "reconnect tcon rc = %d", rc
);
198 * FIXME: check if wsize needs updated due to negotiated smb buffer
201 atomic_inc(&tconInfoReconnectCount
);
203 /* tell server Unix caps we support */
204 if (ses
->capabilities
& CAP_UNIX
)
205 reset_cifs_unix_caps(0, tcon
, NULL
, NULL
);
208 * Removed call to reopen open files here. It is safer (and faster) to
209 * reopen files one at a time as needed in read and write.
211 * FIXME: what about file locks? don't we need to reclaim them ASAP?
216 * Check if handle based operation so we know whether we can continue
217 * or not without returning to caller to reset file handle
219 switch (smb_command
) {
220 case SMB_COM_READ_ANDX
:
221 case SMB_COM_WRITE_ANDX
:
223 case SMB_COM_FIND_CLOSE2
:
224 case SMB_COM_LOCKING_ANDX
:
228 unload_nls(nls_codepage
);
232 /* Allocate and return pointer to an SMB request buffer, and set basic
233 SMB information in the SMB header. If the return code is zero, this
234 function must have filled in request_buf pointer */
236 small_smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
241 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
245 *request_buf
= cifs_small_buf_get();
246 if (*request_buf
== NULL
) {
247 /* BB should we add a retry in here if not a writepage? */
251 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
,
255 cifs_stats_inc(&tcon
->num_smbs_sent
);
261 small_smb_init_no_tc(const int smb_command
, const int wct
,
262 struct cifs_ses
*ses
, void **request_buf
)
265 struct smb_hdr
*buffer
;
267 rc
= small_smb_init(smb_command
, wct
, NULL
, request_buf
);
271 buffer
= (struct smb_hdr
*)*request_buf
;
272 buffer
->Mid
= GetNextMid(ses
->server
);
273 if (ses
->capabilities
& CAP_UNICODE
)
274 buffer
->Flags2
|= SMBFLG2_UNICODE
;
275 if (ses
->capabilities
& CAP_STATUS32
)
276 buffer
->Flags2
|= SMBFLG2_ERR_STATUS
;
278 /* uid, tid can stay at zero as set in header assemble */
280 /* BB add support for turning on the signing when
281 this function is used after 1st of session setup requests */
286 /* If the return code is zero, this function must fill in request_buf pointer */
288 __smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
289 void **request_buf
, void **response_buf
)
291 *request_buf
= cifs_buf_get();
292 if (*request_buf
== NULL
) {
293 /* BB should we add a retry in here if not a writepage? */
296 /* Although the original thought was we needed the response buf for */
297 /* potential retries of smb operations it turns out we can determine */
298 /* from the mid flags when the request buffer can be resent without */
299 /* having to use a second distinct buffer for the response */
301 *response_buf
= *request_buf
;
303 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
307 cifs_stats_inc(&tcon
->num_smbs_sent
);
312 /* If the return code is zero, this function must fill in request_buf pointer */
314 smb_init(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
315 void **request_buf
, void **response_buf
)
319 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
323 return __smb_init(smb_command
, wct
, tcon
, request_buf
, response_buf
);
327 smb_init_no_reconnect(int smb_command
, int wct
, struct cifs_tcon
*tcon
,
328 void **request_buf
, void **response_buf
)
330 if (tcon
->ses
->need_reconnect
|| tcon
->need_reconnect
)
333 return __smb_init(smb_command
, wct
, tcon
, request_buf
, response_buf
);
336 static int validate_t2(struct smb_t2_rsp
*pSMB
)
338 unsigned int total_size
;
340 /* check for plausible wct */
341 if (pSMB
->hdr
.WordCount
< 10)
344 /* check for parm and data offset going beyond end of smb */
345 if (get_unaligned_le16(&pSMB
->t2_rsp
.ParameterOffset
) > 1024 ||
346 get_unaligned_le16(&pSMB
->t2_rsp
.DataOffset
) > 1024)
349 total_size
= get_unaligned_le16(&pSMB
->t2_rsp
.ParameterCount
);
350 if (total_size
>= 512)
353 /* check that bcc is at least as big as parms + data, and that it is
354 * less than negotiated smb buffer
356 total_size
+= get_unaligned_le16(&pSMB
->t2_rsp
.DataCount
);
357 if (total_size
> get_bcc(&pSMB
->hdr
) ||
358 total_size
>= CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
)
363 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB
,
364 sizeof(struct smb_t2_rsp
) + 16);
368 static inline void inc_rfc1001_len(void *pSMB
, int count
)
370 struct smb_hdr
*hdr
= (struct smb_hdr
*)pSMB
;
372 be32_add_cpu(&hdr
->smb_buf_length
, count
);
376 CIFSSMBNegotiate(unsigned int xid
, struct cifs_ses
*ses
)
379 NEGOTIATE_RSP
*pSMBr
;
383 struct TCP_Server_Info
*server
;
385 unsigned int secFlags
;
388 server
= ses
->server
;
393 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
394 (void **) &pSMB
, (void **) &pSMBr
);
398 /* if any of auth flags (ie not sign or seal) are overriden use them */
399 if (ses
->overrideSecFlg
& (~(CIFSSEC_MUST_SIGN
| CIFSSEC_MUST_SEAL
)))
400 secFlags
= ses
->overrideSecFlg
; /* BB FIXME fix sign flags? */
401 else /* if override flags set only sign/seal OR them with global auth */
402 secFlags
= global_secflags
| ses
->overrideSecFlg
;
404 cFYI(1, "secFlags 0x%x", secFlags
);
406 pSMB
->hdr
.Mid
= GetNextMid(server
);
407 pSMB
->hdr
.Flags2
|= (SMBFLG2_UNICODE
| SMBFLG2_ERR_STATUS
);
409 if ((secFlags
& CIFSSEC_MUST_KRB5
) == CIFSSEC_MUST_KRB5
)
410 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
411 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_KRB5
) {
412 cFYI(1, "Kerberos only mechanism, enable extended security");
413 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
414 } else if ((secFlags
& CIFSSEC_MUST_NTLMSSP
) == CIFSSEC_MUST_NTLMSSP
)
415 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
416 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_NTLMSSP
) {
417 cFYI(1, "NTLMSSP only mechanism, enable extended security");
418 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
422 for (i
= 0; i
< CIFS_NUM_PROT
; i
++) {
423 strncpy(pSMB
->DialectsArray
+count
, protocols
[i
].name
, 16);
424 count
+= strlen(protocols
[i
].name
) + 1;
425 /* null at end of source and target buffers anyway */
427 inc_rfc1001_len(pSMB
, count
);
428 pSMB
->ByteCount
= cpu_to_le16(count
);
430 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
431 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
435 server
->dialect
= le16_to_cpu(pSMBr
->DialectIndex
);
436 cFYI(1, "Dialect: %d", server
->dialect
);
437 /* Check wct = 1 error case */
438 if ((pSMBr
->hdr
.WordCount
< 13) || (server
->dialect
== BAD_PROT
)) {
439 /* core returns wct = 1, but we do not ask for core - otherwise
440 small wct just comes when dialect index is -1 indicating we
441 could not negotiate a common dialect */
444 #ifdef CONFIG_CIFS_WEAK_PW_HASH
445 } else if ((pSMBr
->hdr
.WordCount
== 13)
446 && ((server
->dialect
== LANMAN_PROT
)
447 || (server
->dialect
== LANMAN2_PROT
))) {
449 struct lanman_neg_rsp
*rsp
= (struct lanman_neg_rsp
*)pSMBr
;
451 if ((secFlags
& CIFSSEC_MAY_LANMAN
) ||
452 (secFlags
& CIFSSEC_MAY_PLNTXT
))
453 server
->secType
= LANMAN
;
455 cERROR(1, "mount failed weak security disabled"
456 " in /proc/fs/cifs/SecurityFlags");
460 server
->sec_mode
= (__u8
)le16_to_cpu(rsp
->SecurityMode
);
461 server
->maxReq
= min_t(unsigned int,
462 le16_to_cpu(rsp
->MaxMpxCount
),
464 cifs_set_credits(server
, server
->maxReq
);
465 server
->maxBuf
= le16_to_cpu(rsp
->MaxBufSize
);
466 server
->max_vcs
= le16_to_cpu(rsp
->MaxNumberVcs
);
467 /* even though we do not use raw we might as well set this
468 accurately, in case we ever find a need for it */
469 if ((le16_to_cpu(rsp
->RawMode
) & RAW_ENABLE
) == RAW_ENABLE
) {
470 server
->max_rw
= 0xFF00;
471 server
->capabilities
= CAP_MPX_MODE
| CAP_RAW_MODE
;
473 server
->max_rw
= 0;/* do not need to use raw anyway */
474 server
->capabilities
= CAP_MPX_MODE
;
476 tmp
= (__s16
)le16_to_cpu(rsp
->ServerTimeZone
);
478 /* OS/2 often does not set timezone therefore
479 * we must use server time to calc time zone.
480 * Could deviate slightly from the right zone.
481 * Smallest defined timezone difference is 15 minutes
482 * (i.e. Nepal). Rounding up/down is done to match
485 int val
, seconds
, remain
, result
;
486 struct timespec ts
, utc
;
488 ts
= cnvrtDosUnixTm(rsp
->SrvTime
.Date
,
489 rsp
->SrvTime
.Time
, 0);
490 cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d",
491 (int)ts
.tv_sec
, (int)utc
.tv_sec
,
492 (int)(utc
.tv_sec
- ts
.tv_sec
));
493 val
= (int)(utc
.tv_sec
- ts
.tv_sec
);
495 result
= (seconds
/ MIN_TZ_ADJ
) * MIN_TZ_ADJ
;
496 remain
= seconds
% MIN_TZ_ADJ
;
497 if (remain
>= (MIN_TZ_ADJ
/ 2))
498 result
+= MIN_TZ_ADJ
;
501 server
->timeAdj
= result
;
503 server
->timeAdj
= (int)tmp
;
504 server
->timeAdj
*= 60; /* also in seconds */
506 cFYI(1, "server->timeAdj: %d seconds", server
->timeAdj
);
509 /* BB get server time for time conversions and add
510 code to use it and timezone since this is not UTC */
512 if (rsp
->EncryptionKeyLength
==
513 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE
)) {
514 memcpy(ses
->server
->cryptkey
, rsp
->EncryptionKey
,
515 CIFS_CRYPTO_KEY_SIZE
);
516 } else if (server
->sec_mode
& SECMODE_PW_ENCRYPT
) {
517 rc
= -EIO
; /* need cryptkey unless plain text */
521 cFYI(1, "LANMAN negotiated");
522 /* we will not end up setting signing flags - as no signing
523 was in LANMAN and server did not return the flags on */
525 #else /* weak security disabled */
526 } else if (pSMBr
->hdr
.WordCount
== 13) {
527 cERROR(1, "mount failed, cifs module not built "
528 "with CIFS_WEAK_PW_HASH support");
530 #endif /* WEAK_PW_HASH */
532 } else if (pSMBr
->hdr
.WordCount
!= 17) {
537 /* else wct == 17 NTLM */
538 server
->sec_mode
= pSMBr
->SecurityMode
;
539 if ((server
->sec_mode
& SECMODE_USER
) == 0)
540 cFYI(1, "share mode security");
542 if ((server
->sec_mode
& SECMODE_PW_ENCRYPT
) == 0)
543 #ifdef CONFIG_CIFS_WEAK_PW_HASH
544 if ((secFlags
& CIFSSEC_MAY_PLNTXT
) == 0)
545 #endif /* CIFS_WEAK_PW_HASH */
546 cERROR(1, "Server requests plain text password"
547 " but client support disabled");
549 if ((secFlags
& CIFSSEC_MUST_NTLMV2
) == CIFSSEC_MUST_NTLMV2
)
550 server
->secType
= NTLMv2
;
551 else if (secFlags
& CIFSSEC_MAY_NTLM
)
552 server
->secType
= NTLM
;
553 else if (secFlags
& CIFSSEC_MAY_NTLMV2
)
554 server
->secType
= NTLMv2
;
555 else if (secFlags
& CIFSSEC_MAY_KRB5
)
556 server
->secType
= Kerberos
;
557 else if (secFlags
& CIFSSEC_MAY_NTLMSSP
)
558 server
->secType
= RawNTLMSSP
;
559 else if (secFlags
& CIFSSEC_MAY_LANMAN
)
560 server
->secType
= LANMAN
;
563 cERROR(1, "Invalid security type");
566 /* else ... any others ...? */
568 /* one byte, so no need to convert this or EncryptionKeyLen from
570 server
->maxReq
= min_t(unsigned int, le16_to_cpu(pSMBr
->MaxMpxCount
),
572 cifs_set_credits(server
, server
->maxReq
);
573 /* probably no need to store and check maxvcs */
574 server
->maxBuf
= le32_to_cpu(pSMBr
->MaxBufferSize
);
575 server
->max_rw
= le32_to_cpu(pSMBr
->MaxRawSize
);
576 cFYI(DBG2
, "Max buf = %d", ses
->server
->maxBuf
);
577 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
578 server
->timeAdj
= (int)(__s16
)le16_to_cpu(pSMBr
->ServerTimeZone
);
579 server
->timeAdj
*= 60;
580 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
581 memcpy(ses
->server
->cryptkey
, pSMBr
->u
.EncryptionKey
,
582 CIFS_CRYPTO_KEY_SIZE
);
583 } else if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
||
584 server
->capabilities
& CAP_EXTENDED_SECURITY
) &&
585 (pSMBr
->EncryptionKeyLength
== 0)) {
586 /* decode security blob */
587 count
= get_bcc(&pSMBr
->hdr
);
592 spin_lock(&cifs_tcp_ses_lock
);
593 if (server
->srv_count
> 1) {
594 spin_unlock(&cifs_tcp_ses_lock
);
595 if (memcmp(server
->server_GUID
,
596 pSMBr
->u
.extended_response
.
598 cFYI(1, "server UID changed");
599 memcpy(server
->server_GUID
,
600 pSMBr
->u
.extended_response
.GUID
,
604 spin_unlock(&cifs_tcp_ses_lock
);
605 memcpy(server
->server_GUID
,
606 pSMBr
->u
.extended_response
.GUID
, 16);
610 server
->secType
= RawNTLMSSP
;
612 rc
= decode_negTokenInit(pSMBr
->u
.extended_response
.
613 SecurityBlob
, count
- 16,
619 if (server
->secType
== Kerberos
) {
620 if (!server
->sec_kerberos
&&
621 !server
->sec_mskerberos
)
623 } else if (server
->secType
== RawNTLMSSP
) {
624 if (!server
->sec_ntlmssp
)
629 } else if (server
->sec_mode
& SECMODE_PW_ENCRYPT
) {
630 rc
= -EIO
; /* no crypt key only if plain text pwd */
633 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
635 #ifdef CONFIG_CIFS_WEAK_PW_HASH
638 if ((secFlags
& CIFSSEC_MAY_SIGN
) == 0) {
639 /* MUST_SIGN already includes the MAY_SIGN FLAG
640 so if this is zero it means that signing is disabled */
641 cFYI(1, "Signing disabled");
642 if (server
->sec_mode
& SECMODE_SIGN_REQUIRED
) {
643 cERROR(1, "Server requires "
644 "packet signing to be enabled in "
645 "/proc/fs/cifs/SecurityFlags.");
649 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
650 } else if ((secFlags
& CIFSSEC_MUST_SIGN
) == CIFSSEC_MUST_SIGN
) {
651 /* signing required */
652 cFYI(1, "Must sign - secFlags 0x%x", secFlags
);
653 if ((server
->sec_mode
&
654 (SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
)) == 0) {
655 cERROR(1, "signing required but server lacks support");
658 server
->sec_mode
|= SECMODE_SIGN_REQUIRED
;
660 /* signing optional ie CIFSSEC_MAY_SIGN */
661 if ((server
->sec_mode
& SECMODE_SIGN_REQUIRED
) == 0)
663 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
667 cifs_buf_release(pSMB
);
669 cFYI(1, "negprot rc %d", rc
);
674 CIFSSMBTDis(const int xid
, struct cifs_tcon
*tcon
)
676 struct smb_hdr
*smb_buffer
;
679 cFYI(1, "In tree disconnect");
681 /* BB: do we need to check this? These should never be NULL. */
682 if ((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
))
686 * No need to return error on this operation if tid invalidated and
687 * closed on server already e.g. due to tcp session crashing. Also,
688 * the tcon is no longer on the list, so no need to take lock before
691 if ((tcon
->need_reconnect
) || (tcon
->ses
->need_reconnect
))
694 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
695 (void **)&smb_buffer
);
699 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *)smb_buffer
, 0);
701 cFYI(1, "Tree disconnect failed %d", rc
);
703 /* No need to return error on this operation if tid invalidated and
704 closed on server already e.g. due to tcp session crashing */
712 * This is a no-op for now. We're not really interested in the reply, but
713 * rather in the fact that the server sent one and that server->lstrp
716 * FIXME: maybe we should consider checking that the reply matches request?
719 cifs_echo_callback(struct mid_q_entry
*mid
)
721 struct TCP_Server_Info
*server
= mid
->callback_data
;
723 DeleteMidQEntry(mid
);
724 cifs_add_credits(server
, 1);
728 CIFSSMBEcho(struct TCP_Server_Info
*server
)
734 cFYI(1, "In echo request");
736 rc
= small_smb_init(SMB_COM_ECHO
, 0, NULL
, (void **)&smb
);
740 /* set up echo request */
741 smb
->hdr
.Tid
= 0xffff;
742 smb
->hdr
.WordCount
= 1;
743 put_unaligned_le16(1, &smb
->EchoCount
);
744 put_bcc(1, &smb
->hdr
);
746 inc_rfc1001_len(smb
, 3);
748 iov
.iov_len
= be32_to_cpu(smb
->hdr
.smb_buf_length
) + 4;
750 rc
= cifs_call_async(server
, &iov
, 1, NULL
, cifs_echo_callback
,
753 cFYI(1, "Echo request failed: %d", rc
);
755 cifs_small_buf_release(smb
);
761 CIFSSMBLogoff(const int xid
, struct cifs_ses
*ses
)
763 LOGOFF_ANDX_REQ
*pSMB
;
766 cFYI(1, "In SMBLogoff for session disconnect");
769 * BB: do we need to check validity of ses and server? They should
770 * always be valid since we have an active reference. If not, that
771 * should probably be a BUG()
773 if (!ses
|| !ses
->server
)
776 mutex_lock(&ses
->session_mutex
);
777 if (ses
->need_reconnect
)
778 goto session_already_dead
; /* no need to send SMBlogoff if uid
779 already closed due to reconnect */
780 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
782 mutex_unlock(&ses
->session_mutex
);
786 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
788 if (ses
->server
->sec_mode
&
789 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
790 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
792 pSMB
->hdr
.Uid
= ses
->Suid
;
794 pSMB
->AndXCommand
= 0xFF;
795 rc
= SendReceiveNoRsp(xid
, ses
, (char *) pSMB
, 0);
796 session_already_dead
:
797 mutex_unlock(&ses
->session_mutex
);
799 /* if session dead then we do not need to do ulogoff,
800 since server closed smb session, no sense reporting
808 CIFSPOSIXDelFile(const int xid
, struct cifs_tcon
*tcon
, const char *fileName
,
809 __u16 type
, const struct nls_table
*nls_codepage
, int remap
)
811 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
812 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
813 struct unlink_psx_rq
*pRqD
;
816 int bytes_returned
= 0;
817 __u16 params
, param_offset
, offset
, byte_count
;
819 cFYI(1, "In POSIX delete");
821 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
826 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
828 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
829 PATH_MAX
, nls_codepage
, remap
);
830 name_len
++; /* trailing null */
832 } else { /* BB add path length overrun check */
833 name_len
= strnlen(fileName
, PATH_MAX
);
834 name_len
++; /* trailing null */
835 strncpy(pSMB
->FileName
, fileName
, name_len
);
838 params
= 6 + name_len
;
839 pSMB
->MaxParameterCount
= cpu_to_le16(2);
840 pSMB
->MaxDataCount
= 0; /* BB double check this with jra */
841 pSMB
->MaxSetupCount
= 0;
846 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
847 InformationLevel
) - 4;
848 offset
= param_offset
+ params
;
850 /* Setup pointer to Request Data (inode type) */
851 pRqD
= (struct unlink_psx_rq
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
852 pRqD
->type
= cpu_to_le16(type
);
853 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
854 pSMB
->DataOffset
= cpu_to_le16(offset
);
855 pSMB
->SetupCount
= 1;
857 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
858 byte_count
= 3 /* pad */ + params
+ sizeof(struct unlink_psx_rq
);
860 pSMB
->DataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
861 pSMB
->TotalDataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
862 pSMB
->ParameterCount
= cpu_to_le16(params
);
863 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
864 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_UNLINK
);
866 inc_rfc1001_len(pSMB
, byte_count
);
867 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
868 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
869 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
871 cFYI(1, "Posix delete returned %d", rc
);
872 cifs_buf_release(pSMB
);
874 cifs_stats_inc(&tcon
->num_deletes
);
883 CIFSSMBDelFile(const int xid
, struct cifs_tcon
*tcon
, const char *fileName
,
884 const struct nls_table
*nls_codepage
, int remap
)
886 DELETE_FILE_REQ
*pSMB
= NULL
;
887 DELETE_FILE_RSP
*pSMBr
= NULL
;
893 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
898 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
900 cifsConvertToUTF16((__le16
*) pSMB
->fileName
, fileName
,
901 PATH_MAX
, nls_codepage
, remap
);
902 name_len
++; /* trailing null */
904 } else { /* BB improve check for buffer overruns BB */
905 name_len
= strnlen(fileName
, PATH_MAX
);
906 name_len
++; /* trailing null */
907 strncpy(pSMB
->fileName
, fileName
, 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
->num_deletes
);
918 cFYI(1, "Error in RMFile = %d", rc
);
920 cifs_buf_release(pSMB
);
928 CIFSSMBRmDir(const int xid
, struct cifs_tcon
*tcon
, const char *dirName
,
929 const struct nls_table
*nls_codepage
, int remap
)
931 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
932 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
937 cFYI(1, "In CIFSSMBRmDir");
939 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
944 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
945 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->DirName
, dirName
,
946 PATH_MAX
, nls_codepage
, remap
);
947 name_len
++; /* trailing null */
949 } else { /* BB improve check for buffer overruns BB */
950 name_len
= strnlen(dirName
, PATH_MAX
);
951 name_len
++; /* trailing null */
952 strncpy(pSMB
->DirName
, dirName
, name_len
);
955 pSMB
->BufferFormat
= 0x04;
956 inc_rfc1001_len(pSMB
, name_len
+ 1);
957 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
958 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
959 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
960 cifs_stats_inc(&tcon
->num_rmdirs
);
962 cFYI(1, "Error in RMDir = %d", rc
);
964 cifs_buf_release(pSMB
);
971 CIFSSMBMkDir(const int xid
, struct cifs_tcon
*tcon
,
972 const char *name
, const struct nls_table
*nls_codepage
, int remap
)
975 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
976 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
980 cFYI(1, "In CIFSSMBMkDir");
982 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
987 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
988 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->DirName
, name
,
989 PATH_MAX
, nls_codepage
, remap
);
990 name_len
++; /* trailing null */
992 } else { /* BB improve check for buffer overruns BB */
993 name_len
= strnlen(name
, PATH_MAX
);
994 name_len
++; /* trailing null */
995 strncpy(pSMB
->DirName
, name
, name_len
);
998 pSMB
->BufferFormat
= 0x04;
999 inc_rfc1001_len(pSMB
, name_len
+ 1);
1000 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
1001 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1002 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1003 cifs_stats_inc(&tcon
->num_mkdirs
);
1005 cFYI(1, "Error in Mkdir = %d", rc
);
1007 cifs_buf_release(pSMB
);
1014 CIFSPOSIXCreate(const int xid
, struct cifs_tcon
*tcon
, __u32 posix_flags
,
1015 __u64 mode
, __u16
*netfid
, FILE_UNIX_BASIC_INFO
*pRetData
,
1016 __u32
*pOplock
, const char *name
,
1017 const struct nls_table
*nls_codepage
, int remap
)
1019 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
1020 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
1023 int bytes_returned
= 0;
1024 __u16 params
, param_offset
, offset
, byte_count
, count
;
1025 OPEN_PSX_REQ
*pdata
;
1026 OPEN_PSX_RSP
*psx_rsp
;
1028 cFYI(1, "In POSIX Create");
1030 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1035 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1037 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, name
,
1038 PATH_MAX
, nls_codepage
, remap
);
1039 name_len
++; /* trailing null */
1041 } else { /* BB improve the check for buffer overruns BB */
1042 name_len
= strnlen(name
, PATH_MAX
);
1043 name_len
++; /* trailing null */
1044 strncpy(pSMB
->FileName
, name
, name_len
);
1047 params
= 6 + name_len
;
1048 count
= sizeof(OPEN_PSX_REQ
);
1049 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1050 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* large enough */
1051 pSMB
->MaxSetupCount
= 0;
1055 pSMB
->Reserved2
= 0;
1056 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
1057 InformationLevel
) - 4;
1058 offset
= param_offset
+ params
;
1059 pdata
= (OPEN_PSX_REQ
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
1060 pdata
->Level
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
1061 pdata
->Permissions
= cpu_to_le64(mode
);
1062 pdata
->PosixOpenFlags
= cpu_to_le32(posix_flags
);
1063 pdata
->OpenFlags
= cpu_to_le32(*pOplock
);
1064 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1065 pSMB
->DataOffset
= cpu_to_le16(offset
);
1066 pSMB
->SetupCount
= 1;
1067 pSMB
->Reserved3
= 0;
1068 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1069 byte_count
= 3 /* pad */ + params
+ count
;
1071 pSMB
->DataCount
= cpu_to_le16(count
);
1072 pSMB
->ParameterCount
= cpu_to_le16(params
);
1073 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1074 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1075 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_OPEN
);
1076 pSMB
->Reserved4
= 0;
1077 inc_rfc1001_len(pSMB
, byte_count
);
1078 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1079 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1080 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1082 cFYI(1, "Posix create returned %d", rc
);
1083 goto psx_create_err
;
1086 cFYI(1, "copying inode info");
1087 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1089 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(OPEN_PSX_RSP
)) {
1090 rc
= -EIO
; /* bad smb */
1091 goto psx_create_err
;
1094 /* copy return information to pRetData */
1095 psx_rsp
= (OPEN_PSX_RSP
*)((char *) &pSMBr
->hdr
.Protocol
1096 + le16_to_cpu(pSMBr
->t2
.DataOffset
));
1098 *pOplock
= le16_to_cpu(psx_rsp
->OplockFlags
);
1100 *netfid
= psx_rsp
->Fid
; /* cifs fid stays in le */
1101 /* Let caller know file was created so we can set the mode. */
1102 /* Do we care about the CreateAction in any other cases? */
1103 if (cpu_to_le32(FILE_CREATE
) == psx_rsp
->CreateAction
)
1104 *pOplock
|= CIFS_CREATE_ACTION
;
1105 /* check to make sure response data is there */
1106 if (psx_rsp
->ReturnedLevel
!= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
)) {
1107 pRetData
->Type
= cpu_to_le32(-1); /* unknown */
1108 cFYI(DBG2
, "unknown type");
1110 if (get_bcc(&pSMBr
->hdr
) < sizeof(OPEN_PSX_RSP
)
1111 + sizeof(FILE_UNIX_BASIC_INFO
)) {
1112 cERROR(1, "Open response data too small");
1113 pRetData
->Type
= cpu_to_le32(-1);
1114 goto psx_create_err
;
1116 memcpy((char *) pRetData
,
1117 (char *)psx_rsp
+ sizeof(OPEN_PSX_RSP
),
1118 sizeof(FILE_UNIX_BASIC_INFO
));
1122 cifs_buf_release(pSMB
);
1124 if (posix_flags
& SMB_O_DIRECTORY
)
1125 cifs_stats_inc(&tcon
->num_posixmkdirs
);
1127 cifs_stats_inc(&tcon
->num_posixopens
);
1135 static __u16
convert_disposition(int disposition
)
1139 switch (disposition
) {
1140 case FILE_SUPERSEDE
:
1141 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1144 ofun
= SMBOPEN_OAPPEND
;
1147 ofun
= SMBOPEN_OCREATE
;
1150 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
1152 case FILE_OVERWRITE
:
1153 ofun
= SMBOPEN_OTRUNC
;
1155 case FILE_OVERWRITE_IF
:
1156 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1159 cFYI(1, "unknown disposition %d", disposition
);
1160 ofun
= SMBOPEN_OAPPEND
; /* regular open */
1166 access_flags_to_smbopen_mode(const int access_flags
)
1168 int masked_flags
= access_flags
& (GENERIC_READ
| GENERIC_WRITE
);
1170 if (masked_flags
== GENERIC_READ
)
1171 return SMBOPEN_READ
;
1172 else if (masked_flags
== GENERIC_WRITE
)
1173 return SMBOPEN_WRITE
;
1175 /* just go for read/write */
1176 return SMBOPEN_READWRITE
;
1180 SMBLegacyOpen(const int xid
, struct cifs_tcon
*tcon
,
1181 const char *fileName
, const int openDisposition
,
1182 const int access_flags
, const int create_options
, __u16
*netfid
,
1183 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1184 const struct nls_table
*nls_codepage
, int remap
)
1187 OPENX_REQ
*pSMB
= NULL
;
1188 OPENX_RSP
*pSMBr
= NULL
;
1194 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
1199 pSMB
->AndXCommand
= 0xFF; /* none */
1201 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1202 count
= 1; /* account for one byte pad to word boundary */
1204 cifsConvertToUTF16((__le16
*) (pSMB
->fileName
+ 1),
1205 fileName
, PATH_MAX
, nls_codepage
, remap
);
1206 name_len
++; /* trailing null */
1208 } else { /* BB improve check for buffer overruns BB */
1209 count
= 0; /* no pad */
1210 name_len
= strnlen(fileName
, PATH_MAX
);
1211 name_len
++; /* trailing null */
1212 strncpy(pSMB
->fileName
, fileName
, name_len
);
1214 if (*pOplock
& REQ_OPLOCK
)
1215 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
1216 else if (*pOplock
& REQ_BATCHOPLOCK
)
1217 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
1219 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
1220 pSMB
->Mode
= cpu_to_le16(access_flags_to_smbopen_mode(access_flags
));
1221 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
1222 /* set file as system file if special file such
1223 as fifo and server expecting SFU style and
1224 no Unix extensions */
1226 if (create_options
& CREATE_OPTION_SPECIAL
)
1227 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
1228 else /* BB FIXME BB */
1229 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/);
1231 if (create_options
& CREATE_OPTION_READONLY
)
1232 pSMB
->FileAttributes
|= cpu_to_le16(ATTR_READONLY
);
1235 /* pSMB->CreateOptions = cpu_to_le32(create_options &
1236 CREATE_OPTIONS_MASK); */
1237 /* BB FIXME END BB */
1239 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
1240 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
1242 inc_rfc1001_len(pSMB
, count
);
1244 pSMB
->ByteCount
= cpu_to_le16(count
);
1245 /* long_op set to 1 to allow for oplock break timeouts */
1246 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1247 (struct smb_hdr
*)pSMBr
, &bytes_returned
, 0);
1248 cifs_stats_inc(&tcon
->num_opens
);
1250 cFYI(1, "Error in Open = %d", rc
);
1252 /* BB verify if wct == 15 */
1254 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
1256 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1257 /* Let caller know file was created so we can set the mode. */
1258 /* Do we care about the CreateAction in any other cases? */
1260 /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1261 *pOplock |= CIFS_CREATE_ACTION; */
1265 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
1266 pfile_info
->LastAccessTime
= 0; /* BB fixme */
1267 pfile_info
->LastWriteTime
= 0; /* BB fixme */
1268 pfile_info
->ChangeTime
= 0; /* BB fixme */
1269 pfile_info
->Attributes
=
1270 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
1271 /* the file_info buf is endian converted by caller */
1272 pfile_info
->AllocationSize
=
1273 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
1274 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
1275 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1276 pfile_info
->DeletePending
= 0;
1280 cifs_buf_release(pSMB
);
1287 CIFSSMBOpen(const int xid
, struct cifs_tcon
*tcon
,
1288 const char *fileName
, const int openDisposition
,
1289 const int access_flags
, const int create_options
, __u16
*netfid
,
1290 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1291 const struct nls_table
*nls_codepage
, int remap
)
1294 OPEN_REQ
*pSMB
= NULL
;
1295 OPEN_RSP
*pSMBr
= NULL
;
1301 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **) &pSMB
,
1306 pSMB
->AndXCommand
= 0xFF; /* none */
1308 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1309 count
= 1; /* account for one byte pad to word boundary */
1311 cifsConvertToUTF16((__le16
*) (pSMB
->fileName
+ 1),
1312 fileName
, PATH_MAX
, nls_codepage
, remap
);
1313 name_len
++; /* trailing null */
1315 pSMB
->NameLength
= cpu_to_le16(name_len
);
1316 } else { /* BB improve check for buffer overruns BB */
1317 count
= 0; /* no pad */
1318 name_len
= strnlen(fileName
, PATH_MAX
);
1319 name_len
++; /* trailing null */
1320 pSMB
->NameLength
= cpu_to_le16(name_len
);
1321 strncpy(pSMB
->fileName
, fileName
, name_len
);
1323 if (*pOplock
& REQ_OPLOCK
)
1324 pSMB
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
1325 else if (*pOplock
& REQ_BATCHOPLOCK
)
1326 pSMB
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
1327 pSMB
->DesiredAccess
= cpu_to_le32(access_flags
);
1328 pSMB
->AllocationSize
= 0;
1329 /* set file as system file if special file such
1330 as fifo and server expecting SFU style and
1331 no Unix extensions */
1332 if (create_options
& CREATE_OPTION_SPECIAL
)
1333 pSMB
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
1335 pSMB
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
1337 /* XP does not handle ATTR_POSIX_SEMANTICS */
1338 /* but it helps speed up case sensitive checks for other
1339 servers such as Samba */
1340 if (tcon
->ses
->capabilities
& CAP_UNIX
)
1341 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
1343 if (create_options
& CREATE_OPTION_READONLY
)
1344 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_READONLY
);
1346 pSMB
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
1347 pSMB
->CreateDisposition
= cpu_to_le32(openDisposition
);
1348 pSMB
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
1349 /* BB Expirement with various impersonation levels and verify */
1350 pSMB
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
1351 pSMB
->SecurityFlags
=
1352 SECURITY_CONTEXT_TRACKING
| SECURITY_EFFECTIVE_ONLY
;
1355 inc_rfc1001_len(pSMB
, count
);
1357 pSMB
->ByteCount
= cpu_to_le16(count
);
1358 /* long_op set to 1 to allow for oplock break timeouts */
1359 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1360 (struct smb_hdr
*)pSMBr
, &bytes_returned
, 0);
1361 cifs_stats_inc(&tcon
->num_opens
);
1363 cFYI(1, "Error in Open = %d", rc
);
1365 *pOplock
= pSMBr
->OplockLevel
; /* 1 byte no need to le_to_cpu */
1366 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1367 /* Let caller know file was created so we can set the mode. */
1368 /* Do we care about the CreateAction in any other cases? */
1369 if (cpu_to_le32(FILE_CREATE
) == pSMBr
->CreateAction
)
1370 *pOplock
|= CIFS_CREATE_ACTION
;
1372 memcpy((char *)pfile_info
, (char *)&pSMBr
->CreationTime
,
1373 36 /* CreationTime to Attributes */);
1374 /* the file_info buf is endian converted by caller */
1375 pfile_info
->AllocationSize
= pSMBr
->AllocationSize
;
1376 pfile_info
->EndOfFile
= pSMBr
->EndOfFile
;
1377 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1378 pfile_info
->DeletePending
= 0;
1382 cifs_buf_release(pSMB
);
1388 struct cifs_readdata
*
1389 cifs_readdata_alloc(unsigned int nr_pages
)
1391 struct cifs_readdata
*rdata
;
1393 /* readdata + 1 kvec for each page */
1394 rdata
= kzalloc(sizeof(*rdata
) +
1395 sizeof(struct kvec
) * nr_pages
, GFP_KERNEL
);
1396 if (rdata
!= NULL
) {
1397 INIT_WORK(&rdata
->work
, cifs_readv_complete
);
1398 INIT_LIST_HEAD(&rdata
->pages
);
1404 cifs_readdata_free(struct cifs_readdata
*rdata
)
1406 cifsFileInfo_put(rdata
->cfile
);
1411 * Discard any remaining data in the current SMB. To do this, we borrow the
1415 cifs_readv_discard(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
1417 unsigned int rfclen
= get_rfc1002_length(server
->smallbuf
);
1418 int remaining
= rfclen
+ 4 - server
->total_read
;
1419 struct cifs_readdata
*rdata
= mid
->callback_data
;
1421 while (remaining
> 0) {
1424 length
= cifs_read_from_socket(server
, server
->bigbuf
,
1425 min_t(unsigned int, remaining
,
1426 CIFSMaxBufSize
+ max_header_size()));
1429 server
->total_read
+= length
;
1430 remaining
-= length
;
1433 dequeue_mid(mid
, rdata
->result
);
1437 static inline size_t
1440 return sizeof(READ_RSP
);
1443 static inline unsigned int
1444 read_data_offset(char *buf
)
1446 READ_RSP
*rsp
= (READ_RSP
*)buf
;
1447 return le16_to_cpu(rsp
->DataOffset
);
1450 static inline unsigned int
1451 read_data_length(char *buf
)
1453 READ_RSP
*rsp
= (READ_RSP
*)buf
;
1454 return (le16_to_cpu(rsp
->DataLengthHigh
) << 16) +
1455 le16_to_cpu(rsp
->DataLength
);
1459 cifs_readv_receive(struct TCP_Server_Info
*server
, struct mid_q_entry
*mid
)
1462 unsigned int data_offset
, remaining
, data_len
;
1463 struct cifs_readdata
*rdata
= mid
->callback_data
;
1464 char *buf
= server
->smallbuf
;
1465 unsigned int buflen
= get_rfc1002_length(buf
) + 4;
1468 struct page
*page
, *tpage
;
1470 cFYI(1, "%s: mid=%llu offset=%llu bytes=%u", __func__
,
1471 mid
->mid
, rdata
->offset
, rdata
->bytes
);
1474 * read the rest of READ_RSP header (sans Data array), or whatever we
1475 * can if there's not enough data. At this point, we've read down to
1478 len
= min_t(unsigned int, buflen
, read_rsp_size()) - header_size() + 1;
1480 rdata
->iov
[0].iov_base
= buf
+ header_size() - 1;
1481 rdata
->iov
[0].iov_len
= len
;
1483 length
= cifs_readv_from_socket(server
, rdata
->iov
, 1, len
);
1486 server
->total_read
+= length
;
1488 /* Was the SMB read successful? */
1489 rdata
->result
= map_smb_to_linux_error(buf
, false);
1490 if (rdata
->result
!= 0) {
1491 cFYI(1, "%s: server returned error %d", __func__
,
1493 return cifs_readv_discard(server
, mid
);
1496 /* Is there enough to get to the rest of the READ_RSP header? */
1497 if (server
->total_read
< read_rsp_size()) {
1498 cFYI(1, "%s: server returned short header. got=%u expected=%zu",
1499 __func__
, server
->total_read
, read_rsp_size());
1500 rdata
->result
= -EIO
;
1501 return cifs_readv_discard(server
, mid
);
1504 data_offset
= read_data_offset(buf
) + 4;
1505 if (data_offset
< server
->total_read
) {
1507 * win2k8 sometimes sends an offset of 0 when the read
1508 * is beyond the EOF. Treat it as if the data starts just after
1511 cFYI(1, "%s: data offset (%u) inside read response header",
1512 __func__
, data_offset
);
1513 data_offset
= server
->total_read
;
1514 } else if (data_offset
> MAX_CIFS_SMALL_BUFFER_SIZE
) {
1515 /* data_offset is beyond the end of smallbuf */
1516 cFYI(1, "%s: data offset (%u) beyond end of smallbuf",
1517 __func__
, data_offset
);
1518 rdata
->result
= -EIO
;
1519 return cifs_readv_discard(server
, mid
);
1522 cFYI(1, "%s: total_read=%u data_offset=%u", __func__
,
1523 server
->total_read
, data_offset
);
1525 len
= data_offset
- server
->total_read
;
1527 /* read any junk before data into the rest of smallbuf */
1528 rdata
->iov
[0].iov_base
= buf
+ server
->total_read
;
1529 rdata
->iov
[0].iov_len
= len
;
1530 length
= cifs_readv_from_socket(server
, rdata
->iov
, 1, len
);
1533 server
->total_read
+= length
;
1536 /* set up first iov for signature check */
1537 rdata
->iov
[0].iov_base
= buf
;
1538 rdata
->iov
[0].iov_len
= server
->total_read
;
1539 cFYI(1, "0: iov_base=%p iov_len=%zu",
1540 rdata
->iov
[0].iov_base
, rdata
->iov
[0].iov_len
);
1542 /* how much data is in the response? */
1543 data_len
= read_data_length(buf
);
1544 if (data_offset
+ data_len
> buflen
) {
1545 /* data_len is corrupt -- discard frame */
1546 rdata
->result
= -EIO
;
1547 return cifs_readv_discard(server
, mid
);
1550 /* marshal up the page array */
1552 remaining
= data_len
;
1555 /* determine the eof that the server (probably) has */
1556 eof
= CIFS_I(rdata
->mapping
->host
)->server_eof
;
1557 eof_index
= eof
? (eof
- 1) >> PAGE_CACHE_SHIFT
: 0;
1558 cFYI(1, "eof=%llu eof_index=%lu", eof
, eof_index
);
1560 list_for_each_entry_safe(page
, tpage
, &rdata
->pages
, lru
) {
1561 if (remaining
>= PAGE_CACHE_SIZE
) {
1562 /* enough data to fill the page */
1563 rdata
->iov
[rdata
->nr_iov
].iov_base
= kmap(page
);
1564 rdata
->iov
[rdata
->nr_iov
].iov_len
= PAGE_CACHE_SIZE
;
1565 cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu",
1566 rdata
->nr_iov
, page
->index
,
1567 rdata
->iov
[rdata
->nr_iov
].iov_base
,
1568 rdata
->iov
[rdata
->nr_iov
].iov_len
);
1570 len
+= PAGE_CACHE_SIZE
;
1571 remaining
-= PAGE_CACHE_SIZE
;
1572 } else if (remaining
> 0) {
1573 /* enough for partial page, fill and zero the rest */
1574 rdata
->iov
[rdata
->nr_iov
].iov_base
= kmap(page
);
1575 rdata
->iov
[rdata
->nr_iov
].iov_len
= remaining
;
1576 cFYI(1, "%u: idx=%lu iov_base=%p iov_len=%zu",
1577 rdata
->nr_iov
, page
->index
,
1578 rdata
->iov
[rdata
->nr_iov
].iov_base
,
1579 rdata
->iov
[rdata
->nr_iov
].iov_len
);
1580 memset(rdata
->iov
[rdata
->nr_iov
].iov_base
+ remaining
,
1581 '\0', PAGE_CACHE_SIZE
- remaining
);
1585 } else if (page
->index
> eof_index
) {
1587 * The VFS will not try to do readahead past the
1588 * i_size, but it's possible that we have outstanding
1589 * writes with gaps in the middle and the i_size hasn't
1590 * caught up yet. Populate those with zeroed out pages
1591 * to prevent the VFS from repeatedly attempting to
1592 * fill them until the writes are flushed.
1594 zero_user(page
, 0, PAGE_CACHE_SIZE
);
1595 list_del(&page
->lru
);
1596 lru_cache_add_file(page
);
1597 flush_dcache_page(page
);
1598 SetPageUptodate(page
);
1600 page_cache_release(page
);
1602 /* no need to hold page hostage */
1603 list_del(&page
->lru
);
1604 lru_cache_add_file(page
);
1606 page_cache_release(page
);
1610 /* issue the read if we have any iovecs left to fill */
1611 if (rdata
->nr_iov
> 1) {
1612 length
= cifs_readv_from_socket(server
, &rdata
->iov
[1],
1613 rdata
->nr_iov
- 1, len
);
1616 server
->total_read
+= length
;
1621 rdata
->bytes
= length
;
1623 cFYI(1, "total_read=%u buflen=%u remaining=%u", server
->total_read
,
1626 /* discard anything left over */
1627 if (server
->total_read
< buflen
)
1628 return cifs_readv_discard(server
, mid
);
1630 dequeue_mid(mid
, false);
1635 cifs_readv_complete(struct work_struct
*work
)
1637 struct cifs_readdata
*rdata
= container_of(work
,
1638 struct cifs_readdata
, work
);
1639 struct page
*page
, *tpage
;
1641 list_for_each_entry_safe(page
, tpage
, &rdata
->pages
, lru
) {
1642 list_del(&page
->lru
);
1643 lru_cache_add_file(page
);
1645 if (rdata
->result
== 0) {
1647 flush_dcache_page(page
);
1648 SetPageUptodate(page
);
1653 if (rdata
->result
== 0)
1654 cifs_readpage_to_fscache(rdata
->mapping
->host
, page
);
1656 page_cache_release(page
);
1658 cifs_readdata_free(rdata
);
1662 cifs_readv_callback(struct mid_q_entry
*mid
)
1664 struct cifs_readdata
*rdata
= mid
->callback_data
;
1665 struct cifs_tcon
*tcon
= tlink_tcon(rdata
->cfile
->tlink
);
1666 struct TCP_Server_Info
*server
= tcon
->ses
->server
;
1668 cFYI(1, "%s: mid=%llu state=%d result=%d bytes=%u", __func__
,
1669 mid
->mid
, mid
->mid_state
, rdata
->result
, rdata
->bytes
);
1671 switch (mid
->mid_state
) {
1672 case MID_RESPONSE_RECEIVED
:
1673 /* result already set, check signature */
1674 if (server
->sec_mode
&
1675 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
)) {
1676 if (cifs_verify_signature(rdata
->iov
, rdata
->nr_iov
,
1677 server
, mid
->sequence_number
+ 1))
1678 cERROR(1, "Unexpected SMB signature");
1680 /* FIXME: should this be counted toward the initiating task? */
1681 task_io_account_read(rdata
->bytes
);
1682 cifs_stats_bytes_read(tcon
, rdata
->bytes
);
1684 case MID_REQUEST_SUBMITTED
:
1685 case MID_RETRY_NEEDED
:
1686 rdata
->result
= -EAGAIN
;
1689 rdata
->result
= -EIO
;
1692 queue_work(system_nrt_wq
, &rdata
->work
);
1693 DeleteMidQEntry(mid
);
1694 cifs_add_credits(server
, 1);
1697 /* cifs_async_readv - send an async write, and set up mid to handle result */
1699 cifs_async_readv(struct cifs_readdata
*rdata
)
1702 READ_REQ
*smb
= NULL
;
1704 struct cifs_tcon
*tcon
= tlink_tcon(rdata
->cfile
->tlink
);
1706 cFYI(1, "%s: offset=%llu bytes=%u", __func__
,
1707 rdata
->offset
, rdata
->bytes
);
1709 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1712 wct
= 10; /* old style read */
1713 if ((rdata
->offset
>> 32) > 0) {
1714 /* can not handle this big offset for old */
1719 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **)&smb
);
1723 smb
->hdr
.Pid
= cpu_to_le16((__u16
)rdata
->pid
);
1724 smb
->hdr
.PidHigh
= cpu_to_le16((__u16
)(rdata
->pid
>> 16));
1726 smb
->AndXCommand
= 0xFF; /* none */
1727 smb
->Fid
= rdata
->cfile
->netfid
;
1728 smb
->OffsetLow
= cpu_to_le32(rdata
->offset
& 0xFFFFFFFF);
1730 smb
->OffsetHigh
= cpu_to_le32(rdata
->offset
>> 32);
1732 smb
->MaxCount
= cpu_to_le16(rdata
->bytes
& 0xFFFF);
1733 smb
->MaxCountHigh
= cpu_to_le32(rdata
->bytes
>> 16);
1737 /* old style read */
1738 struct smb_com_readx_req
*smbr
=
1739 (struct smb_com_readx_req
*)smb
;
1740 smbr
->ByteCount
= 0;
1743 /* 4 for RFC1001 length + 1 for BCC */
1744 rdata
->iov
[0].iov_base
= smb
;
1745 rdata
->iov
[0].iov_len
= be32_to_cpu(smb
->hdr
.smb_buf_length
) + 4;
1747 rc
= cifs_call_async(tcon
->ses
->server
, rdata
->iov
, 1,
1748 cifs_readv_receive
, cifs_readv_callback
,
1752 cifs_stats_inc(&tcon
->num_reads
);
1754 cifs_small_buf_release(smb
);
1759 CIFSSMBRead(const int xid
, struct cifs_io_parms
*io_parms
, unsigned int *nbytes
,
1760 char **buf
, int *pbuf_type
)
1763 READ_REQ
*pSMB
= NULL
;
1764 READ_RSP
*pSMBr
= NULL
;
1765 char *pReadData
= NULL
;
1767 int resp_buf_type
= 0;
1769 __u32 pid
= io_parms
->pid
;
1770 __u16 netfid
= io_parms
->netfid
;
1771 __u64 offset
= io_parms
->offset
;
1772 struct cifs_tcon
*tcon
= io_parms
->tcon
;
1773 unsigned int count
= io_parms
->length
;
1775 cFYI(1, "Reading %d bytes on fid %d", count
, netfid
);
1776 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1779 wct
= 10; /* old style read */
1780 if ((offset
>> 32) > 0) {
1781 /* can not handle this big offset for old */
1787 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
1791 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
1792 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
1794 /* tcon and ses pointer are checked in smb_init */
1795 if (tcon
->ses
->server
== NULL
)
1796 return -ECONNABORTED
;
1798 pSMB
->AndXCommand
= 0xFF; /* none */
1800 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1802 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1804 pSMB
->Remaining
= 0;
1805 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1806 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1808 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1810 /* old style read */
1811 struct smb_com_readx_req
*pSMBW
=
1812 (struct smb_com_readx_req
*)pSMB
;
1813 pSMBW
->ByteCount
= 0;
1816 iov
[0].iov_base
= (char *)pSMB
;
1817 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
1818 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1819 &resp_buf_type
, CIFS_LOG_ERROR
);
1820 cifs_stats_inc(&tcon
->num_reads
);
1821 pSMBr
= (READ_RSP
*)iov
[0].iov_base
;
1823 cERROR(1, "Send error in read = %d", rc
);
1825 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1826 data_length
= data_length
<< 16;
1827 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1828 *nbytes
= data_length
;
1830 /*check that DataLength would not go beyond end of SMB */
1831 if ((data_length
> CIFSMaxBufSize
)
1832 || (data_length
> count
)) {
1833 cFYI(1, "bad length %d for count %d",
1834 data_length
, count
);
1838 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1839 le16_to_cpu(pSMBr
->DataOffset
);
1840 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1841 cERROR(1, "Faulting on read rc = %d",rc);
1843 }*/ /* can not use copy_to_user when using page cache*/
1845 memcpy(*buf
, pReadData
, data_length
);
1849 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1851 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1852 cifs_small_buf_release(iov
[0].iov_base
);
1853 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1854 cifs_buf_release(iov
[0].iov_base
);
1855 } else if (resp_buf_type
!= CIFS_NO_BUFFER
) {
1856 /* return buffer to caller to free */
1857 *buf
= iov
[0].iov_base
;
1858 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1859 *pbuf_type
= CIFS_SMALL_BUFFER
;
1860 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1861 *pbuf_type
= CIFS_LARGE_BUFFER
;
1862 } /* else no valid buffer on return - leave as null */
1864 /* Note: On -EAGAIN error only caller can retry on handle based calls
1865 since file handle passed in no longer valid */
1871 CIFSSMBWrite(const int xid
, struct cifs_io_parms
*io_parms
,
1872 unsigned int *nbytes
, const char *buf
,
1873 const char __user
*ubuf
, const int long_op
)
1876 WRITE_REQ
*pSMB
= NULL
;
1877 WRITE_RSP
*pSMBr
= NULL
;
1878 int bytes_returned
, wct
;
1881 __u32 pid
= io_parms
->pid
;
1882 __u16 netfid
= io_parms
->netfid
;
1883 __u64 offset
= io_parms
->offset
;
1884 struct cifs_tcon
*tcon
= io_parms
->tcon
;
1885 unsigned int count
= io_parms
->length
;
1889 /* cFYI(1, "write at %lld %d bytes", offset, count);*/
1890 if (tcon
->ses
== NULL
)
1891 return -ECONNABORTED
;
1893 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1897 if ((offset
>> 32) > 0) {
1898 /* can not handle big offset for old srv */
1903 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1908 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
1909 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
1911 /* tcon and ses pointer are checked in smb_init */
1912 if (tcon
->ses
->server
== NULL
)
1913 return -ECONNABORTED
;
1915 pSMB
->AndXCommand
= 0xFF; /* none */
1917 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1919 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1921 pSMB
->Reserved
= 0xFFFFFFFF;
1922 pSMB
->WriteMode
= 0;
1923 pSMB
->Remaining
= 0;
1925 /* Can increase buffer size if buffer is big enough in some cases ie we
1926 can send more if LARGE_WRITE_X capability returned by the server and if
1927 our buffer is big enough or if we convert to iovecs on socket writes
1928 and eliminate the copy to the CIFS buffer */
1929 if (tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1930 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
1932 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
1936 if (bytes_sent
> count
)
1939 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1941 memcpy(pSMB
->Data
, buf
, bytes_sent
);
1943 if (copy_from_user(pSMB
->Data
, ubuf
, bytes_sent
)) {
1944 cifs_buf_release(pSMB
);
1947 } else if (count
!= 0) {
1949 cifs_buf_release(pSMB
);
1951 } /* else setting file size with write of zero bytes */
1953 byte_count
= bytes_sent
+ 1; /* pad */
1954 else /* wct == 12 */
1955 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
1957 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
1958 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
1959 inc_rfc1001_len(pSMB
, byte_count
);
1962 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1963 else { /* old style write has byte count 4 bytes earlier
1965 struct smb_com_writex_req
*pSMBW
=
1966 (struct smb_com_writex_req
*)pSMB
;
1967 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
1970 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1971 (struct smb_hdr
*) pSMBr
, &bytes_returned
, long_op
);
1972 cifs_stats_inc(&tcon
->num_writes
);
1974 cFYI(1, "Send error in write = %d", rc
);
1976 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1977 *nbytes
= (*nbytes
) << 16;
1978 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1981 * Mask off high 16 bits when bytes written as returned by the
1982 * server is greater than bytes requested by the client. Some
1983 * OS/2 servers are known to set incorrect CountHigh values.
1985 if (*nbytes
> count
)
1989 cifs_buf_release(pSMB
);
1991 /* Note: On -EAGAIN error only caller can retry on handle based calls
1992 since file handle passed in no longer valid */
1998 cifs_writedata_release(struct kref
*refcount
)
2000 struct cifs_writedata
*wdata
= container_of(refcount
,
2001 struct cifs_writedata
, refcount
);
2004 cifsFileInfo_put(wdata
->cfile
);
2010 * Write failed with a retryable error. Resend the write request. It's also
2011 * possible that the page was redirtied so re-clean the page.
2014 cifs_writev_requeue(struct cifs_writedata
*wdata
)
2017 struct inode
*inode
= wdata
->cfile
->dentry
->d_inode
;
2019 for (i
= 0; i
< wdata
->nr_pages
; i
++) {
2020 lock_page(wdata
->pages
[i
]);
2021 clear_page_dirty_for_io(wdata
->pages
[i
]);
2025 rc
= cifs_async_writev(wdata
);
2026 } while (rc
== -EAGAIN
);
2028 for (i
= 0; i
< wdata
->nr_pages
; i
++) {
2030 SetPageError(wdata
->pages
[i
]);
2031 unlock_page(wdata
->pages
[i
]);
2034 mapping_set_error(inode
->i_mapping
, rc
);
2035 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2039 cifs_writev_complete(struct work_struct
*work
)
2041 struct cifs_writedata
*wdata
= container_of(work
,
2042 struct cifs_writedata
, work
);
2043 struct inode
*inode
= wdata
->cfile
->dentry
->d_inode
;
2046 if (wdata
->result
== 0) {
2047 cifs_update_eof(CIFS_I(inode
), wdata
->offset
, wdata
->bytes
);
2048 cifs_stats_bytes_written(tlink_tcon(wdata
->cfile
->tlink
),
2050 } else if (wdata
->sync_mode
== WB_SYNC_ALL
&& wdata
->result
== -EAGAIN
)
2051 return cifs_writev_requeue(wdata
);
2053 for (i
= 0; i
< wdata
->nr_pages
; i
++) {
2054 struct page
*page
= wdata
->pages
[i
];
2055 if (wdata
->result
== -EAGAIN
)
2056 __set_page_dirty_nobuffers(page
);
2057 else if (wdata
->result
< 0)
2059 end_page_writeback(page
);
2060 page_cache_release(page
);
2062 if (wdata
->result
!= -EAGAIN
)
2063 mapping_set_error(inode
->i_mapping
, wdata
->result
);
2064 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2067 struct cifs_writedata
*
2068 cifs_writedata_alloc(unsigned int nr_pages
)
2070 struct cifs_writedata
*wdata
;
2072 /* this would overflow */
2073 if (nr_pages
== 0) {
2074 cERROR(1, "%s: called with nr_pages == 0!", __func__
);
2078 /* writedata + number of page pointers */
2079 wdata
= kzalloc(sizeof(*wdata
) +
2080 sizeof(struct page
*) * (nr_pages
- 1), GFP_NOFS
);
2081 if (wdata
!= NULL
) {
2082 INIT_WORK(&wdata
->work
, cifs_writev_complete
);
2083 kref_init(&wdata
->refcount
);
2089 * Check the mid_state and signature on received buffer (if any), and queue the
2090 * workqueue completion task.
2093 cifs_writev_callback(struct mid_q_entry
*mid
)
2095 struct cifs_writedata
*wdata
= mid
->callback_data
;
2096 struct cifs_tcon
*tcon
= tlink_tcon(wdata
->cfile
->tlink
);
2097 unsigned int written
;
2098 WRITE_RSP
*smb
= (WRITE_RSP
*)mid
->resp_buf
;
2100 switch (mid
->mid_state
) {
2101 case MID_RESPONSE_RECEIVED
:
2102 wdata
->result
= cifs_check_receive(mid
, tcon
->ses
->server
, 0);
2103 if (wdata
->result
!= 0)
2106 written
= le16_to_cpu(smb
->CountHigh
);
2108 written
+= le16_to_cpu(smb
->Count
);
2110 * Mask off high 16 bits when bytes written as returned
2111 * by the server is greater than bytes requested by the
2112 * client. OS/2 servers are known to set incorrect
2115 if (written
> wdata
->bytes
)
2118 if (written
< wdata
->bytes
)
2119 wdata
->result
= -ENOSPC
;
2121 wdata
->bytes
= written
;
2123 case MID_REQUEST_SUBMITTED
:
2124 case MID_RETRY_NEEDED
:
2125 wdata
->result
= -EAGAIN
;
2128 wdata
->result
= -EIO
;
2132 queue_work(system_nrt_wq
, &wdata
->work
);
2133 DeleteMidQEntry(mid
);
2134 cifs_add_credits(tcon
->ses
->server
, 1);
2137 /* cifs_async_writev - send an async write, and set up mid to handle result */
2139 cifs_async_writev(struct cifs_writedata
*wdata
)
2141 int i
, rc
= -EACCES
;
2142 WRITE_REQ
*smb
= NULL
;
2144 struct cifs_tcon
*tcon
= tlink_tcon(wdata
->cfile
->tlink
);
2145 struct inode
*inode
= wdata
->cfile
->dentry
->d_inode
;
2146 struct kvec
*iov
= NULL
;
2148 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
2152 if (wdata
->offset
>> 32 > 0) {
2153 /* can not handle big offset for old srv */
2158 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **)&smb
);
2160 goto async_writev_out
;
2162 /* 1 iov per page + 1 for header */
2163 iov
= kzalloc((wdata
->nr_pages
+ 1) * sizeof(*iov
), GFP_NOFS
);
2166 goto async_writev_out
;
2169 smb
->hdr
.Pid
= cpu_to_le16((__u16
)wdata
->cfile
->pid
);
2170 smb
->hdr
.PidHigh
= cpu_to_le16((__u16
)(wdata
->cfile
->pid
>> 16));
2172 smb
->AndXCommand
= 0xFF; /* none */
2173 smb
->Fid
= wdata
->cfile
->netfid
;
2174 smb
->OffsetLow
= cpu_to_le32(wdata
->offset
& 0xFFFFFFFF);
2176 smb
->OffsetHigh
= cpu_to_le32(wdata
->offset
>> 32);
2177 smb
->Reserved
= 0xFFFFFFFF;
2182 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2184 /* 4 for RFC1001 length + 1 for BCC */
2185 iov
[0].iov_len
= be32_to_cpu(smb
->hdr
.smb_buf_length
) + 4 + 1;
2186 iov
[0].iov_base
= smb
;
2188 /* marshal up the pages into iov array */
2190 for (i
= 0; i
< wdata
->nr_pages
; i
++) {
2191 iov
[i
+ 1].iov_len
= min(inode
->i_size
-
2192 page_offset(wdata
->pages
[i
]),
2193 (loff_t
)PAGE_CACHE_SIZE
);
2194 iov
[i
+ 1].iov_base
= kmap(wdata
->pages
[i
]);
2195 wdata
->bytes
+= iov
[i
+ 1].iov_len
;
2198 cFYI(1, "async write at %llu %u bytes", wdata
->offset
, wdata
->bytes
);
2200 smb
->DataLengthLow
= cpu_to_le16(wdata
->bytes
& 0xFFFF);
2201 smb
->DataLengthHigh
= cpu_to_le16(wdata
->bytes
>> 16);
2204 inc_rfc1001_len(&smb
->hdr
, wdata
->bytes
+ 1);
2205 put_bcc(wdata
->bytes
+ 1, &smb
->hdr
);
2208 struct smb_com_writex_req
*smbw
=
2209 (struct smb_com_writex_req
*)smb
;
2210 inc_rfc1001_len(&smbw
->hdr
, wdata
->bytes
+ 5);
2211 put_bcc(wdata
->bytes
+ 5, &smbw
->hdr
);
2212 iov
[0].iov_len
+= 4; /* pad bigger by four bytes */
2215 kref_get(&wdata
->refcount
);
2216 rc
= cifs_call_async(tcon
->ses
->server
, iov
, wdata
->nr_pages
+ 1,
2217 NULL
, cifs_writev_callback
, wdata
, false);
2220 cifs_stats_inc(&tcon
->num_writes
);
2222 kref_put(&wdata
->refcount
, cifs_writedata_release
);
2224 /* send is done, unmap pages */
2225 for (i
= 0; i
< wdata
->nr_pages
; i
++)
2226 kunmap(wdata
->pages
[i
]);
2229 cifs_small_buf_release(smb
);
2235 CIFSSMBWrite2(const int xid
, struct cifs_io_parms
*io_parms
,
2236 unsigned int *nbytes
, struct kvec
*iov
, int n_vec
,
2240 WRITE_REQ
*pSMB
= NULL
;
2243 int resp_buf_type
= 0;
2244 __u32 pid
= io_parms
->pid
;
2245 __u16 netfid
= io_parms
->netfid
;
2246 __u64 offset
= io_parms
->offset
;
2247 struct cifs_tcon
*tcon
= io_parms
->tcon
;
2248 unsigned int count
= io_parms
->length
;
2252 cFYI(1, "write2 at %lld %d bytes", (long long)offset
, count
);
2254 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
2258 if ((offset
>> 32) > 0) {
2259 /* can not handle big offset for old srv */
2263 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
2267 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid
);
2268 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid
>> 16));
2270 /* tcon and ses pointer are checked in smb_init */
2271 if (tcon
->ses
->server
== NULL
)
2272 return -ECONNABORTED
;
2274 pSMB
->AndXCommand
= 0xFF; /* none */
2276 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
2278 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
2279 pSMB
->Reserved
= 0xFFFFFFFF;
2280 pSMB
->WriteMode
= 0;
2281 pSMB
->Remaining
= 0;
2284 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
2286 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
2287 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
2288 /* header + 1 byte pad */
2289 smb_hdr_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 1;
2291 inc_rfc1001_len(pSMB
, count
+ 1);
2292 else /* wct == 12 */
2293 inc_rfc1001_len(pSMB
, count
+ 5); /* smb data starts later */
2295 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
2296 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
2297 struct smb_com_writex_req
*pSMBW
=
2298 (struct smb_com_writex_req
*)pSMB
;
2299 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
2301 iov
[0].iov_base
= pSMB
;
2303 iov
[0].iov_len
= smb_hdr_len
+ 4;
2304 else /* wct == 12 pad bigger by four bytes */
2305 iov
[0].iov_len
= smb_hdr_len
+ 8;
2308 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
,
2310 cifs_stats_inc(&tcon
->num_writes
);
2312 cFYI(1, "Send error Write2 = %d", rc
);
2313 } else if (resp_buf_type
== 0) {
2314 /* presumably this can not happen, but best to be safe */
2317 WRITE_RSP
*pSMBr
= (WRITE_RSP
*)iov
[0].iov_base
;
2318 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
2319 *nbytes
= (*nbytes
) << 16;
2320 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
2323 * Mask off high 16 bits when bytes written as returned by the
2324 * server is greater than bytes requested by the client. OS/2
2325 * servers are known to set incorrect CountHigh values.
2327 if (*nbytes
> count
)
2331 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
2332 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
2333 cifs_small_buf_release(iov
[0].iov_base
);
2334 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
2335 cifs_buf_release(iov
[0].iov_base
);
2337 /* Note: On -EAGAIN error only caller can retry on handle based calls
2338 since file handle passed in no longer valid */
2343 int cifs_lockv(const int xid
, struct cifs_tcon
*tcon
, const __u16 netfid
,
2344 const __u8 lock_type
, const __u32 num_unlock
,
2345 const __u32 num_lock
, LOCKING_ANDX_RANGE
*buf
)
2348 LOCK_REQ
*pSMB
= NULL
;
2353 cFYI(1, "cifs_lockv num lock %d num unlock %d", num_lock
, num_unlock
);
2355 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
2360 pSMB
->NumberOfLocks
= cpu_to_le16(num_lock
);
2361 pSMB
->NumberOfUnlocks
= cpu_to_le16(num_unlock
);
2362 pSMB
->LockType
= lock_type
;
2363 pSMB
->AndXCommand
= 0xFF; /* none */
2364 pSMB
->Fid
= netfid
; /* netfid stays le */
2366 count
= (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2367 inc_rfc1001_len(pSMB
, count
);
2368 pSMB
->ByteCount
= cpu_to_le16(count
);
2370 iov
[0].iov_base
= (char *)pSMB
;
2371 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4 -
2372 (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2373 iov
[1].iov_base
= (char *)buf
;
2374 iov
[1].iov_len
= (num_unlock
+ num_lock
) * sizeof(LOCKING_ANDX_RANGE
);
2376 cifs_stats_inc(&tcon
->num_locks
);
2377 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 2, &resp_buf_type
, CIFS_NO_RESP
);
2379 cFYI(1, "Send error in cifs_lockv = %d", rc
);
2385 CIFSSMBLock(const int xid
, struct cifs_tcon
*tcon
,
2386 const __u16 smb_file_id
, const __u32 netpid
, const __u64 len
,
2387 const __u64 offset
, const __u32 numUnlock
,
2388 const __u32 numLock
, const __u8 lockType
,
2389 const bool waitFlag
, const __u8 oplock_level
)
2392 LOCK_REQ
*pSMB
= NULL
;
2393 /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
2398 cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag
, numLock
);
2399 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
2404 if (lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
2405 timeout
= CIFS_ASYNC_OP
; /* no response expected */
2407 } else if (waitFlag
) {
2408 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
2409 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
2414 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
2415 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
2416 pSMB
->LockType
= lockType
;
2417 pSMB
->OplockLevel
= oplock_level
;
2418 pSMB
->AndXCommand
= 0xFF; /* none */
2419 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
2421 if ((numLock
!= 0) || (numUnlock
!= 0)) {
2422 pSMB
->Locks
[0].Pid
= cpu_to_le16(netpid
);
2423 /* BB where to store pid high? */
2424 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
2425 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
2426 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
2427 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
2428 count
= sizeof(LOCKING_ANDX_RANGE
);
2433 inc_rfc1001_len(pSMB
, count
);
2434 pSMB
->ByteCount
= cpu_to_le16(count
);
2437 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
2438 (struct smb_hdr
*) pSMB
, &bytes_returned
);
2439 cifs_small_buf_release(pSMB
);
2441 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *)pSMB
, timeout
);
2442 /* SMB buffer freed by function above */
2444 cifs_stats_inc(&tcon
->num_locks
);
2446 cFYI(1, "Send error in Lock = %d", rc
);
2448 /* Note: On -EAGAIN error only caller can retry on handle based calls
2449 since file handle passed in no longer valid */
2454 CIFSSMBPosixLock(const int xid
, struct cifs_tcon
*tcon
,
2455 const __u16 smb_file_id
, const __u32 netpid
, const int get_flag
,
2456 const __u64 len
, struct file_lock
*pLockData
,
2457 const __u16 lock_type
, const bool waitFlag
)
2459 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2460 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2461 struct cifs_posix_lock
*parm_data
;
2464 int bytes_returned
= 0;
2465 int resp_buf_type
= 0;
2466 __u16 params
, param_offset
, offset
, byte_count
, count
;
2469 cFYI(1, "Posix Lock");
2471 if (pLockData
== NULL
)
2474 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
2479 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
2482 pSMB
->MaxSetupCount
= 0;
2485 pSMB
->Reserved2
= 0;
2486 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2487 offset
= param_offset
+ params
;
2489 count
= sizeof(struct cifs_posix_lock
);
2490 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2491 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2492 pSMB
->SetupCount
= 1;
2493 pSMB
->Reserved3
= 0;
2495 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
2497 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2498 byte_count
= 3 /* pad */ + params
+ count
;
2499 pSMB
->DataCount
= cpu_to_le16(count
);
2500 pSMB
->ParameterCount
= cpu_to_le16(params
);
2501 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2502 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2503 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2504 parm_data
= (struct cifs_posix_lock
*)
2505 (((char *) &pSMB
->hdr
.Protocol
) + offset
);
2507 parm_data
->lock_type
= cpu_to_le16(lock_type
);
2509 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
2510 parm_data
->lock_flags
= cpu_to_le16(1);
2511 pSMB
->Timeout
= cpu_to_le32(-1);
2515 parm_data
->pid
= cpu_to_le32(netpid
);
2516 parm_data
->start
= cpu_to_le64(pLockData
->fl_start
);
2517 parm_data
->length
= cpu_to_le64(len
); /* normalize negative numbers */
2519 pSMB
->DataOffset
= cpu_to_le16(offset
);
2520 pSMB
->Fid
= smb_file_id
;
2521 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_LOCK
);
2522 pSMB
->Reserved4
= 0;
2523 inc_rfc1001_len(pSMB
, byte_count
);
2524 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2526 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
2527 (struct smb_hdr
*) pSMBr
, &bytes_returned
);
2529 iov
[0].iov_base
= (char *)pSMB
;
2530 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
2531 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
2532 &resp_buf_type
, timeout
);
2533 pSMB
= NULL
; /* request buf already freed by SendReceive2. Do
2534 not try to free it twice below on exit */
2535 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)iov
[0].iov_base
;
2539 cFYI(1, "Send error in Posix Lock = %d", rc
);
2540 } else if (get_flag
) {
2541 /* lock structure can be returned on get */
2544 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2546 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(*parm_data
)) {
2547 rc
= -EIO
; /* bad smb */
2550 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2551 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2552 if (data_count
< sizeof(struct cifs_posix_lock
)) {
2556 parm_data
= (struct cifs_posix_lock
*)
2557 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
2558 if (parm_data
->lock_type
== __constant_cpu_to_le16(CIFS_UNLCK
))
2559 pLockData
->fl_type
= F_UNLCK
;
2561 if (parm_data
->lock_type
==
2562 __constant_cpu_to_le16(CIFS_RDLCK
))
2563 pLockData
->fl_type
= F_RDLCK
;
2564 else if (parm_data
->lock_type
==
2565 __constant_cpu_to_le16(CIFS_WRLCK
))
2566 pLockData
->fl_type
= F_WRLCK
;
2568 pLockData
->fl_start
= le64_to_cpu(parm_data
->start
);
2569 pLockData
->fl_end
= pLockData
->fl_start
+
2570 le64_to_cpu(parm_data
->length
) - 1;
2571 pLockData
->fl_pid
= le32_to_cpu(parm_data
->pid
);
2577 cifs_small_buf_release(pSMB
);
2579 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
2580 cifs_small_buf_release(iov
[0].iov_base
);
2581 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
2582 cifs_buf_release(iov
[0].iov_base
);
2584 /* Note: On -EAGAIN error only caller can retry on handle based calls
2585 since file handle passed in no longer valid */
2592 CIFSSMBClose(const int xid
, struct cifs_tcon
*tcon
, int smb_file_id
)
2595 CLOSE_REQ
*pSMB
= NULL
;
2596 cFYI(1, "In CIFSSMBClose");
2598 /* do not retry on dead session on close */
2599 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
2605 pSMB
->FileID
= (__u16
) smb_file_id
;
2606 pSMB
->LastWriteTime
= 0xFFFFFFFF;
2607 pSMB
->ByteCount
= 0;
2608 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
2609 cifs_stats_inc(&tcon
->num_closes
);
2612 /* EINTR is expected when user ctl-c to kill app */
2613 cERROR(1, "Send error in Close = %d", rc
);
2617 /* Since session is dead, file will be closed on server already */
2625 CIFSSMBFlush(const int xid
, struct cifs_tcon
*tcon
, int smb_file_id
)
2628 FLUSH_REQ
*pSMB
= NULL
;
2629 cFYI(1, "In CIFSSMBFlush");
2631 rc
= small_smb_init(SMB_COM_FLUSH
, 1, tcon
, (void **) &pSMB
);
2635 pSMB
->FileID
= (__u16
) smb_file_id
;
2636 pSMB
->ByteCount
= 0;
2637 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
2638 cifs_stats_inc(&tcon
->num_flushes
);
2640 cERROR(1, "Send error in Flush = %d", rc
);
2646 CIFSSMBRename(const int xid
, struct cifs_tcon
*tcon
,
2647 const char *fromName
, const char *toName
,
2648 const struct nls_table
*nls_codepage
, int remap
)
2651 RENAME_REQ
*pSMB
= NULL
;
2652 RENAME_RSP
*pSMBr
= NULL
;
2654 int name_len
, name_len2
;
2657 cFYI(1, "In CIFSSMBRename");
2659 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
2664 pSMB
->BufferFormat
= 0x04;
2665 pSMB
->SearchAttributes
=
2666 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2669 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2671 cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
, fromName
,
2672 PATH_MAX
, nls_codepage
, remap
);
2673 name_len
++; /* trailing null */
2675 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2676 /* protocol requires ASCII signature byte on Unicode string */
2677 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2679 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
2680 toName
, PATH_MAX
, nls_codepage
, remap
);
2681 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2682 name_len2
*= 2; /* convert to bytes */
2683 } else { /* BB improve the check for buffer overruns BB */
2684 name_len
= strnlen(fromName
, PATH_MAX
);
2685 name_len
++; /* trailing null */
2686 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2687 name_len2
= strnlen(toName
, PATH_MAX
);
2688 name_len2
++; /* trailing null */
2689 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2690 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2691 name_len2
++; /* trailing null */
2692 name_len2
++; /* signature byte */
2695 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2696 inc_rfc1001_len(pSMB
, count
);
2697 pSMB
->ByteCount
= cpu_to_le16(count
);
2699 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2700 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2701 cifs_stats_inc(&tcon
->num_renames
);
2703 cFYI(1, "Send error in rename = %d", rc
);
2705 cifs_buf_release(pSMB
);
2713 int CIFSSMBRenameOpenFile(const int xid
, struct cifs_tcon
*pTcon
,
2714 int netfid
, const char *target_name
,
2715 const struct nls_table
*nls_codepage
, int remap
)
2717 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2718 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2719 struct set_file_rename
*rename_info
;
2721 char dummy_string
[30];
2723 int bytes_returned
= 0;
2725 __u16 params
, param_offset
, offset
, count
, byte_count
;
2727 cFYI(1, "Rename to File by handle");
2728 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
2734 pSMB
->MaxSetupCount
= 0;
2738 pSMB
->Reserved2
= 0;
2739 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2740 offset
= param_offset
+ params
;
2742 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2743 rename_info
= (struct set_file_rename
*) data_offset
;
2744 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2745 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2746 pSMB
->SetupCount
= 1;
2747 pSMB
->Reserved3
= 0;
2748 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2749 byte_count
= 3 /* pad */ + params
;
2750 pSMB
->ParameterCount
= cpu_to_le16(params
);
2751 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2752 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2753 pSMB
->DataOffset
= cpu_to_le16(offset
);
2754 /* construct random name ".cifs_tmp<inodenum><mid>" */
2755 rename_info
->overwrite
= cpu_to_le32(1);
2756 rename_info
->root_fid
= 0;
2757 /* unicode only call */
2758 if (target_name
== NULL
) {
2759 sprintf(dummy_string
, "cifs%x", pSMB
->hdr
.Mid
);
2761 cifsConvertToUTF16((__le16
*)rename_info
->target_name
,
2762 dummy_string
, 24, nls_codepage
, remap
);
2765 cifsConvertToUTF16((__le16
*)rename_info
->target_name
,
2766 target_name
, PATH_MAX
, nls_codepage
,
2769 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
2770 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
);
2771 byte_count
+= count
;
2772 pSMB
->DataCount
= cpu_to_le16(count
);
2773 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2775 pSMB
->InformationLevel
=
2776 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
2777 pSMB
->Reserved4
= 0;
2778 inc_rfc1001_len(pSMB
, byte_count
);
2779 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2780 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
2781 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2782 cifs_stats_inc(&pTcon
->num_t2renames
);
2784 cFYI(1, "Send error in Rename (by file handle) = %d", rc
);
2786 cifs_buf_release(pSMB
);
2788 /* Note: On -EAGAIN error only caller can retry on handle based calls
2789 since file handle passed in no longer valid */
2795 CIFSSMBCopy(const int xid
, struct cifs_tcon
*tcon
, const char *fromName
,
2796 const __u16 target_tid
, const char *toName
, const int flags
,
2797 const struct nls_table
*nls_codepage
, int remap
)
2800 COPY_REQ
*pSMB
= NULL
;
2801 COPY_RSP
*pSMBr
= NULL
;
2803 int name_len
, name_len2
;
2806 cFYI(1, "In CIFSSMBCopy");
2808 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
2813 pSMB
->BufferFormat
= 0x04;
2814 pSMB
->Tid2
= target_tid
;
2816 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
2818 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2819 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
,
2820 fromName
, PATH_MAX
, nls_codepage
,
2822 name_len
++; /* trailing null */
2824 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2825 /* protocol requires ASCII signature byte on Unicode string */
2826 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2828 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
2829 toName
, PATH_MAX
, nls_codepage
, remap
);
2830 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2831 name_len2
*= 2; /* convert to bytes */
2832 } else { /* BB improve the check for buffer overruns BB */
2833 name_len
= strnlen(fromName
, PATH_MAX
);
2834 name_len
++; /* trailing null */
2835 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2836 name_len2
= strnlen(toName
, PATH_MAX
);
2837 name_len2
++; /* trailing null */
2838 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2839 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2840 name_len2
++; /* trailing null */
2841 name_len2
++; /* signature byte */
2844 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2845 inc_rfc1001_len(pSMB
, count
);
2846 pSMB
->ByteCount
= cpu_to_le16(count
);
2848 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2849 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2851 cFYI(1, "Send error in copy = %d with %d files copied",
2852 rc
, le16_to_cpu(pSMBr
->CopyCount
));
2854 cifs_buf_release(pSMB
);
2863 CIFSUnixCreateSymLink(const int xid
, struct cifs_tcon
*tcon
,
2864 const char *fromName
, const char *toName
,
2865 const struct nls_table
*nls_codepage
)
2867 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2868 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2871 int name_len_target
;
2873 int bytes_returned
= 0;
2874 __u16 params
, param_offset
, offset
, byte_count
;
2876 cFYI(1, "In Symlink Unix style");
2878 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2883 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2885 cifs_strtoUTF16((__le16
*) pSMB
->FileName
, fromName
,
2886 /* find define for this maxpathcomponent */
2887 PATH_MAX
, nls_codepage
);
2888 name_len
++; /* trailing null */
2891 } else { /* BB improve the check for buffer overruns BB */
2892 name_len
= strnlen(fromName
, PATH_MAX
);
2893 name_len
++; /* trailing null */
2894 strncpy(pSMB
->FileName
, fromName
, name_len
);
2896 params
= 6 + name_len
;
2897 pSMB
->MaxSetupCount
= 0;
2901 pSMB
->Reserved2
= 0;
2902 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2903 InformationLevel
) - 4;
2904 offset
= param_offset
+ params
;
2906 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2907 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2909 cifs_strtoUTF16((__le16
*) data_offset
, toName
, PATH_MAX
2910 /* find define for this maxpathcomponent */
2912 name_len_target
++; /* trailing null */
2913 name_len_target
*= 2;
2914 } else { /* BB improve the check for buffer overruns BB */
2915 name_len_target
= strnlen(toName
, PATH_MAX
);
2916 name_len_target
++; /* trailing null */
2917 strncpy(data_offset
, toName
, name_len_target
);
2920 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2921 /* BB find exact max on data count below from sess */
2922 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2923 pSMB
->SetupCount
= 1;
2924 pSMB
->Reserved3
= 0;
2925 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2926 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2927 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2928 pSMB
->ParameterCount
= cpu_to_le16(params
);
2929 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2930 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2931 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2932 pSMB
->DataOffset
= cpu_to_le16(offset
);
2933 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
2934 pSMB
->Reserved4
= 0;
2935 inc_rfc1001_len(pSMB
, byte_count
);
2936 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2937 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2938 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2939 cifs_stats_inc(&tcon
->num_symlinks
);
2941 cFYI(1, "Send error in SetPathInfo create symlink = %d", rc
);
2943 cifs_buf_release(pSMB
);
2946 goto createSymLinkRetry
;
2952 CIFSUnixCreateHardLink(const int xid
, struct cifs_tcon
*tcon
,
2953 const char *fromName
, const char *toName
,
2954 const struct nls_table
*nls_codepage
, int remap
)
2956 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2957 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2960 int name_len_target
;
2962 int bytes_returned
= 0;
2963 __u16 params
, param_offset
, offset
, byte_count
;
2965 cFYI(1, "In Create Hard link Unix style");
2966 createHardLinkRetry
:
2967 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2972 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2973 name_len
= cifsConvertToUTF16((__le16
*) pSMB
->FileName
, toName
,
2974 PATH_MAX
, nls_codepage
, remap
);
2975 name_len
++; /* trailing null */
2978 } else { /* BB improve the check for buffer overruns BB */
2979 name_len
= strnlen(toName
, PATH_MAX
);
2980 name_len
++; /* trailing null */
2981 strncpy(pSMB
->FileName
, toName
, name_len
);
2983 params
= 6 + name_len
;
2984 pSMB
->MaxSetupCount
= 0;
2988 pSMB
->Reserved2
= 0;
2989 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2990 InformationLevel
) - 4;
2991 offset
= param_offset
+ params
;
2993 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2994 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2996 cifsConvertToUTF16((__le16
*) data_offset
, fromName
,
2997 PATH_MAX
, nls_codepage
, remap
);
2998 name_len_target
++; /* trailing null */
2999 name_len_target
*= 2;
3000 } else { /* BB improve the check for buffer overruns BB */
3001 name_len_target
= strnlen(fromName
, PATH_MAX
);
3002 name_len_target
++; /* trailing null */
3003 strncpy(data_offset
, fromName
, name_len_target
);
3006 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3007 /* BB find exact max on data count below from sess*/
3008 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3009 pSMB
->SetupCount
= 1;
3010 pSMB
->Reserved3
= 0;
3011 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
3012 byte_count
= 3 /* pad */ + params
+ name_len_target
;
3013 pSMB
->ParameterCount
= cpu_to_le16(params
);
3014 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3015 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
3016 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3017 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3018 pSMB
->DataOffset
= cpu_to_le16(offset
);
3019 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
3020 pSMB
->Reserved4
= 0;
3021 inc_rfc1001_len(pSMB
, byte_count
);
3022 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3023 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3024 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3025 cifs_stats_inc(&tcon
->num_hardlinks
);
3027 cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc
);
3029 cifs_buf_release(pSMB
);
3031 goto createHardLinkRetry
;
3037 CIFSCreateHardLink(const int xid
, struct cifs_tcon
*tcon
,
3038 const char *fromName
, const char *toName
,
3039 const struct nls_table
*nls_codepage
, int remap
)
3042 NT_RENAME_REQ
*pSMB
= NULL
;
3043 RENAME_RSP
*pSMBr
= NULL
;
3045 int name_len
, name_len2
;
3048 cFYI(1, "In CIFSCreateHardLink");
3049 winCreateHardLinkRetry
:
3051 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
3056 pSMB
->SearchAttributes
=
3057 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
3059 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
3060 pSMB
->ClusterCount
= 0;
3062 pSMB
->BufferFormat
= 0x04;
3064 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3066 cifsConvertToUTF16((__le16
*) pSMB
->OldFileName
, fromName
,
3067 PATH_MAX
, nls_codepage
, remap
);
3068 name_len
++; /* trailing null */
3071 /* protocol specifies ASCII buffer format (0x04) for unicode */
3072 pSMB
->OldFileName
[name_len
] = 0x04;
3073 pSMB
->OldFileName
[name_len
+ 1] = 0x00; /* pad */
3075 cifsConvertToUTF16((__le16
*)&pSMB
->OldFileName
[name_len
+2],
3076 toName
, PATH_MAX
, nls_codepage
, remap
);
3077 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
3078 name_len2
*= 2; /* convert to bytes */
3079 } else { /* BB improve the check for buffer overruns BB */
3080 name_len
= strnlen(fromName
, PATH_MAX
);
3081 name_len
++; /* trailing null */
3082 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
3083 name_len2
= strnlen(toName
, PATH_MAX
);
3084 name_len2
++; /* trailing null */
3085 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
3086 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
3087 name_len2
++; /* trailing null */
3088 name_len2
++; /* signature byte */
3091 count
= 1 /* string type byte */ + name_len
+ name_len2
;
3092 inc_rfc1001_len(pSMB
, count
);
3093 pSMB
->ByteCount
= cpu_to_le16(count
);
3095 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3096 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3097 cifs_stats_inc(&tcon
->num_hardlinks
);
3099 cFYI(1, "Send error in hard link (NT rename) = %d", rc
);
3101 cifs_buf_release(pSMB
);
3103 goto winCreateHardLinkRetry
;
3109 CIFSSMBUnixQuerySymLink(const int xid
, struct cifs_tcon
*tcon
,
3110 const unsigned char *searchName
, char **symlinkinfo
,
3111 const struct nls_table
*nls_codepage
)
3113 /* SMB_QUERY_FILE_UNIX_LINK */
3114 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3115 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3119 __u16 params
, byte_count
;
3122 cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName
);
3125 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3130 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3132 cifs_strtoUTF16((__le16
*) pSMB
->FileName
, searchName
,
3133 PATH_MAX
, nls_codepage
);
3134 name_len
++; /* trailing null */
3136 } else { /* BB improve the check for buffer overruns BB */
3137 name_len
= strnlen(searchName
, PATH_MAX
);
3138 name_len
++; /* trailing null */
3139 strncpy(pSMB
->FileName
, searchName
, name_len
);
3142 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3143 pSMB
->TotalDataCount
= 0;
3144 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3145 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
3146 pSMB
->MaxSetupCount
= 0;
3150 pSMB
->Reserved2
= 0;
3151 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3152 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3153 pSMB
->DataCount
= 0;
3154 pSMB
->DataOffset
= 0;
3155 pSMB
->SetupCount
= 1;
3156 pSMB
->Reserved3
= 0;
3157 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3158 byte_count
= params
+ 1 /* pad */ ;
3159 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3160 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3161 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
3162 pSMB
->Reserved4
= 0;
3163 inc_rfc1001_len(pSMB
, byte_count
);
3164 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3166 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3167 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3169 cFYI(1, "Send error in QuerySymLinkInfo = %d", rc
);
3171 /* decode response */
3173 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3174 /* BB also check enough total bytes returned */
3175 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3179 u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3181 data_start
= ((char *) &pSMBr
->hdr
.Protocol
) +
3182 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3184 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3189 /* BB FIXME investigate remapping reserved chars here */
3190 *symlinkinfo
= cifs_strndup_from_utf16(data_start
,
3191 count
, is_unicode
, nls_codepage
);
3196 cifs_buf_release(pSMB
);
3198 goto querySymLinkRetry
;
3202 #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL
3204 * Recent Windows versions now create symlinks more frequently
3205 * and they use the "reparse point" mechanism below. We can of course
3206 * do symlinks nicely to Samba and other servers which support the
3207 * CIFS Unix Extensions and we can also do SFU symlinks and "client only"
3208 * "MF" symlinks optionally, but for recent Windows we really need to
3209 * reenable the code below and fix the cifs_symlink callers to handle this.
3210 * In the interim this code has been moved to its own config option so
3211 * it is not compiled in by default until callers fixed up and more tested.
3214 CIFSSMBQueryReparseLinkInfo(const int xid
, struct cifs_tcon
*tcon
,
3215 const unsigned char *searchName
,
3216 char *symlinkinfo
, const int buflen
, __u16 fid
,
3217 const struct nls_table
*nls_codepage
)
3221 struct smb_com_transaction_ioctl_req
*pSMB
;
3222 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
3224 cFYI(1, "In Windows reparse style QueryLink for path %s", searchName
);
3225 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
3230 pSMB
->TotalParameterCount
= 0 ;
3231 pSMB
->TotalDataCount
= 0;
3232 pSMB
->MaxParameterCount
= cpu_to_le32(2);
3233 /* BB find exact data count max from sess structure BB */
3234 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
3235 pSMB
->MaxSetupCount
= 4;
3237 pSMB
->ParameterOffset
= 0;
3238 pSMB
->DataCount
= 0;
3239 pSMB
->DataOffset
= 0;
3240 pSMB
->SetupCount
= 4;
3241 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
3242 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3243 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
3244 pSMB
->IsFsctl
= 1; /* FSCTL */
3245 pSMB
->IsRootFlag
= 0;
3246 pSMB
->Fid
= fid
; /* file handle always le */
3247 pSMB
->ByteCount
= 0;
3249 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3250 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3252 cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc
);
3253 } else { /* decode response */
3254 __u32 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
3255 __u32 data_count
= le32_to_cpu(pSMBr
->DataCount
);
3256 if (get_bcc(&pSMBr
->hdr
) < 2 || data_offset
> 512) {
3257 /* BB also check enough total bytes returned */
3258 rc
= -EIO
; /* bad smb */
3261 if (data_count
&& (data_count
< 2048)) {
3262 char *end_of_smb
= 2 /* sizeof byte count */ +
3263 get_bcc(&pSMBr
->hdr
) + (char *)&pSMBr
->ByteCount
;
3265 struct reparse_data
*reparse_buf
=
3266 (struct reparse_data
*)
3267 ((char *)&pSMBr
->hdr
.Protocol
3269 if ((char *)reparse_buf
>= end_of_smb
) {
3273 if ((reparse_buf
->LinkNamesBuf
+
3274 reparse_buf
->TargetNameOffset
+
3275 reparse_buf
->TargetNameLen
) > end_of_smb
) {
3276 cFYI(1, "reparse buf beyond SMB");
3281 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3282 cifs_from_ucs2(symlinkinfo
, (__le16
*)
3283 (reparse_buf
->LinkNamesBuf
+
3284 reparse_buf
->TargetNameOffset
),
3286 reparse_buf
->TargetNameLen
,
3288 } else { /* ASCII names */
3289 strncpy(symlinkinfo
,
3290 reparse_buf
->LinkNamesBuf
+
3291 reparse_buf
->TargetNameOffset
,
3292 min_t(const int, buflen
,
3293 reparse_buf
->TargetNameLen
));
3297 cFYI(1, "Invalid return data count on "
3298 "get reparse info ioctl");
3300 symlinkinfo
[buflen
] = 0; /* just in case so the caller
3301 does not go off the end of the buffer */
3302 cFYI(1, "readlink result - %s", symlinkinfo
);
3306 cifs_buf_release(pSMB
);
3308 /* Note: On -EAGAIN error only caller can retry on handle based calls
3309 since file handle passed in no longer valid */
3313 #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */
3315 #ifdef CONFIG_CIFS_POSIX
3317 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
3318 static void cifs_convert_ace(posix_acl_xattr_entry
*ace
,
3319 struct cifs_posix_ace
*cifs_ace
)
3321 /* u8 cifs fields do not need le conversion */
3322 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
3323 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
3324 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
3325 /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */
3330 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
3331 static int cifs_copy_posix_acl(char *trgt
, char *src
, const int buflen
,
3332 const int acl_type
, const int size_of_data_area
)
3337 struct cifs_posix_ace
*pACE
;
3338 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)src
;
3339 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)trgt
;
3341 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
3344 if (acl_type
& ACL_TYPE_ACCESS
) {
3345 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
3346 pACE
= &cifs_acl
->ace_array
[0];
3347 size
= sizeof(struct cifs_posix_acl
);
3348 size
+= sizeof(struct cifs_posix_ace
) * count
;
3349 /* check if we would go beyond end of SMB */
3350 if (size_of_data_area
< size
) {
3351 cFYI(1, "bad CIFS POSIX ACL size %d vs. %d",
3352 size_of_data_area
, size
);
3355 } else if (acl_type
& ACL_TYPE_DEFAULT
) {
3356 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
3357 size
= sizeof(struct cifs_posix_acl
);
3358 size
+= sizeof(struct cifs_posix_ace
) * count
;
3359 /* skip past access ACEs to get to default ACEs */
3360 pACE
= &cifs_acl
->ace_array
[count
];
3361 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
3362 size
+= sizeof(struct cifs_posix_ace
) * count
;
3363 /* check if we would go beyond end of SMB */
3364 if (size_of_data_area
< size
)
3371 size
= posix_acl_xattr_size(count
);
3372 if ((buflen
== 0) || (local_acl
== NULL
)) {
3373 /* used to query ACL EA size */
3374 } else if (size
> buflen
) {
3376 } else /* buffer big enough */ {
3377 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
3378 for (i
= 0; i
< count
; i
++) {
3379 cifs_convert_ace(&local_acl
->a_entries
[i
], pACE
);
3386 static __u16
convert_ace_to_cifs_ace(struct cifs_posix_ace
*cifs_ace
,
3387 const posix_acl_xattr_entry
*local_ace
)
3389 __u16 rc
= 0; /* 0 = ACL converted ok */
3391 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
3392 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
3393 /* BB is there a better way to handle the large uid? */
3394 if (local_ace
->e_id
== cpu_to_le32(-1)) {
3395 /* Probably no need to le convert -1 on any arch but can not hurt */
3396 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
3398 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
3399 /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/
3403 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
3404 static __u16
ACL_to_cifs_posix(char *parm_data
, const char *pACL
,
3405 const int buflen
, const int acl_type
)
3408 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
3409 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)pACL
;
3413 if ((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
3416 count
= posix_acl_xattr_count((size_t)buflen
);
3417 cFYI(1, "setting acl with %d entries from buf of length %d and "
3419 count
, buflen
, le32_to_cpu(local_acl
->a_version
));
3420 if (le32_to_cpu(local_acl
->a_version
) != 2) {
3421 cFYI(1, "unknown POSIX ACL version %d",
3422 le32_to_cpu(local_acl
->a_version
));
3425 cifs_acl
->version
= cpu_to_le16(1);
3426 if (acl_type
== ACL_TYPE_ACCESS
)
3427 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
3428 else if (acl_type
== ACL_TYPE_DEFAULT
)
3429 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
3431 cFYI(1, "unknown ACL type %d", acl_type
);
3434 for (i
= 0; i
< count
; i
++) {
3435 rc
= convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
],
3436 &local_acl
->a_entries
[i
]);
3438 /* ACE not converted */
3443 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
3444 rc
+= sizeof(struct cifs_posix_acl
);
3445 /* BB add check to make sure ACL does not overflow SMB */
3451 CIFSSMBGetPosixACL(const int xid
, struct cifs_tcon
*tcon
,
3452 const unsigned char *searchName
,
3453 char *acl_inf
, const int buflen
, const int acl_type
,
3454 const struct nls_table
*nls_codepage
, int remap
)
3456 /* SMB_QUERY_POSIX_ACL */
3457 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3458 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3462 __u16 params
, byte_count
;
3464 cFYI(1, "In GetPosixACL (Unix) for path %s", searchName
);
3467 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3472 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3474 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
3475 searchName
, PATH_MAX
, nls_codepage
,
3477 name_len
++; /* trailing null */
3479 pSMB
->FileName
[name_len
] = 0;
3480 pSMB
->FileName
[name_len
+1] = 0;
3481 } else { /* BB improve the check for buffer overruns BB */
3482 name_len
= strnlen(searchName
, PATH_MAX
);
3483 name_len
++; /* trailing null */
3484 strncpy(pSMB
->FileName
, searchName
, name_len
);
3487 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3488 pSMB
->TotalDataCount
= 0;
3489 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3490 /* BB find exact max data count below from sess structure BB */
3491 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3492 pSMB
->MaxSetupCount
= 0;
3496 pSMB
->Reserved2
= 0;
3497 pSMB
->ParameterOffset
= cpu_to_le16(
3498 offsetof(struct smb_com_transaction2_qpi_req
,
3499 InformationLevel
) - 4);
3500 pSMB
->DataCount
= 0;
3501 pSMB
->DataOffset
= 0;
3502 pSMB
->SetupCount
= 1;
3503 pSMB
->Reserved3
= 0;
3504 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3505 byte_count
= params
+ 1 /* pad */ ;
3506 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3507 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3508 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
3509 pSMB
->Reserved4
= 0;
3510 inc_rfc1001_len(pSMB
, byte_count
);
3511 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3513 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3514 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3515 cifs_stats_inc(&tcon
->num_acl_get
);
3517 cFYI(1, "Send error in Query POSIX ACL = %d", rc
);
3519 /* decode response */
3521 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3522 /* BB also check enough total bytes returned */
3523 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3524 rc
= -EIO
; /* bad smb */
3526 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3527 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3528 rc
= cifs_copy_posix_acl(acl_inf
,
3529 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
3530 buflen
, acl_type
, count
);
3533 cifs_buf_release(pSMB
);
3540 CIFSSMBSetPosixACL(const int xid
, struct cifs_tcon
*tcon
,
3541 const unsigned char *fileName
,
3542 const char *local_acl
, const int buflen
,
3544 const struct nls_table
*nls_codepage
, int remap
)
3546 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
3547 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
3551 int bytes_returned
= 0;
3552 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
3554 cFYI(1, "In SetPosixACL (Unix) for path %s", fileName
);
3556 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3560 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3562 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
3563 PATH_MAX
, nls_codepage
, remap
);
3564 name_len
++; /* trailing null */
3566 } else { /* BB improve the check for buffer overruns BB */
3567 name_len
= strnlen(fileName
, PATH_MAX
);
3568 name_len
++; /* trailing null */
3569 strncpy(pSMB
->FileName
, fileName
, name_len
);
3571 params
= 6 + name_len
;
3572 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3573 /* BB find max SMB size from sess */
3574 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3575 pSMB
->MaxSetupCount
= 0;
3579 pSMB
->Reserved2
= 0;
3580 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
3581 InformationLevel
) - 4;
3582 offset
= param_offset
+ params
;
3583 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
3584 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3586 /* convert to on the wire format for POSIX ACL */
3587 data_count
= ACL_to_cifs_posix(parm_data
, local_acl
, buflen
, acl_type
);
3589 if (data_count
== 0) {
3591 goto setACLerrorExit
;
3593 pSMB
->DataOffset
= cpu_to_le16(offset
);
3594 pSMB
->SetupCount
= 1;
3595 pSMB
->Reserved3
= 0;
3596 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
3597 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
3598 byte_count
= 3 /* pad */ + params
+ data_count
;
3599 pSMB
->DataCount
= cpu_to_le16(data_count
);
3600 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3601 pSMB
->ParameterCount
= cpu_to_le16(params
);
3602 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3603 pSMB
->Reserved4
= 0;
3604 inc_rfc1001_len(pSMB
, byte_count
);
3605 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3606 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3607 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3609 cFYI(1, "Set POSIX ACL returned %d", rc
);
3612 cifs_buf_release(pSMB
);
3618 /* BB fix tabs in this function FIXME BB */
3620 CIFSGetExtAttr(const int xid
, struct cifs_tcon
*tcon
,
3621 const int netfid
, __u64
*pExtAttrBits
, __u64
*pMask
)
3624 struct smb_t2_qfi_req
*pSMB
= NULL
;
3625 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
3627 __u16 params
, byte_count
;
3629 cFYI(1, "In GetExtAttr");
3634 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3639 params
= 2 /* level */ + 2 /* fid */;
3640 pSMB
->t2
.TotalDataCount
= 0;
3641 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
3642 /* BB find exact max data count below from sess structure BB */
3643 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
3644 pSMB
->t2
.MaxSetupCount
= 0;
3645 pSMB
->t2
.Reserved
= 0;
3647 pSMB
->t2
.Timeout
= 0;
3648 pSMB
->t2
.Reserved2
= 0;
3649 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
3651 pSMB
->t2
.DataCount
= 0;
3652 pSMB
->t2
.DataOffset
= 0;
3653 pSMB
->t2
.SetupCount
= 1;
3654 pSMB
->t2
.Reserved3
= 0;
3655 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
3656 byte_count
= params
+ 1 /* pad */ ;
3657 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
3658 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
3659 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
3662 inc_rfc1001_len(pSMB
, byte_count
);
3663 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
3665 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3666 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3668 cFYI(1, "error %d in GetExtAttr", rc
);
3670 /* decode response */
3671 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3672 /* BB also check enough total bytes returned */
3673 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
3674 /* If rc should we check for EOPNOSUPP and
3675 disable the srvino flag? or in caller? */
3676 rc
= -EIO
; /* bad smb */
3678 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3679 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3680 struct file_chattr_info
*pfinfo
;
3681 /* BB Do we need a cast or hash here ? */
3683 cFYI(1, "Illegal size ret in GetExtAttr");
3687 pfinfo
= (struct file_chattr_info
*)
3688 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3689 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
3690 *pMask
= le64_to_cpu(pfinfo
->mask
);
3694 cifs_buf_release(pSMB
);
3696 goto GetExtAttrRetry
;
3700 #endif /* CONFIG_POSIX */
3702 #ifdef CONFIG_CIFS_ACL
3704 * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that
3705 * all NT TRANSACTS that we init here have total parm and data under about 400
3706 * bytes (to fit in small cifs buffer size), which is the case so far, it
3707 * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of
3708 * returned setup area) and MaxParameterCount (returned parms size) must be set
3712 smb_init_nttransact(const __u16 sub_command
, const int setup_count
,
3713 const int parm_len
, struct cifs_tcon
*tcon
,
3718 struct smb_com_ntransact_req
*pSMB
;
3720 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
3724 *ret_buf
= (void *)pSMB
;
3726 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
3727 pSMB
->TotalDataCount
= 0;
3728 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
3729 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3730 pSMB
->DataCount
= pSMB
->TotalDataCount
;
3731 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
3732 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
3733 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
3734 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
3735 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
3736 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
3741 validate_ntransact(char *buf
, char **ppparm
, char **ppdata
,
3742 __u32
*pparmlen
, __u32
*pdatalen
)
3745 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
3746 struct smb_com_ntransact_rsp
*pSMBr
;
3755 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
3757 bcc
= get_bcc(&pSMBr
->hdr
);
3758 end_of_smb
= 2 /* sizeof byte count */ + bcc
+
3759 (char *)&pSMBr
->ByteCount
;
3761 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
3762 data_count
= le32_to_cpu(pSMBr
->DataCount
);
3763 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
3764 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
3766 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
3767 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
3769 /* should we also check that parm and data areas do not overlap? */
3770 if (*ppparm
> end_of_smb
) {
3771 cFYI(1, "parms start after end of smb");
3773 } else if (parm_count
+ *ppparm
> end_of_smb
) {
3774 cFYI(1, "parm end after end of smb");
3776 } else if (*ppdata
> end_of_smb
) {
3777 cFYI(1, "data starts after end of smb");
3779 } else if (data_count
+ *ppdata
> end_of_smb
) {
3780 cFYI(1, "data %p + count %d (%p) past smb end %p start %p",
3781 *ppdata
, data_count
, (data_count
+ *ppdata
),
3784 } else if (parm_count
+ data_count
> bcc
) {
3785 cFYI(1, "parm count and data count larger than SMB");
3788 *pdatalen
= data_count
;
3789 *pparmlen
= parm_count
;
3793 /* Get Security Descriptor (by handle) from remote server for a file or dir */
3795 CIFSSMBGetCIFSACL(const int xid
, struct cifs_tcon
*tcon
, __u16 fid
,
3796 struct cifs_ntsd
**acl_inf
, __u32
*pbuflen
)
3800 QUERY_SEC_DESC_REQ
*pSMB
;
3803 cFYI(1, "GetCifsACL");
3808 rc
= smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
3809 8 /* parm len */, tcon
, (void **) &pSMB
);
3813 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3814 /* BB TEST with big acls that might need to be e.g. larger than 16K */
3815 pSMB
->MaxSetupCount
= 0;
3816 pSMB
->Fid
= fid
; /* file handle always le */
3817 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
3819 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
3820 inc_rfc1001_len(pSMB
, 11);
3821 iov
[0].iov_base
= (char *)pSMB
;
3822 iov
[0].iov_len
= be32_to_cpu(pSMB
->hdr
.smb_buf_length
) + 4;
3824 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
,
3826 cifs_stats_inc(&tcon
->num_acl_get
);
3828 cFYI(1, "Send error in QuerySecDesc = %d", rc
);
3829 } else { /* decode response */
3833 struct smb_com_ntransact_rsp
*pSMBr
;
3836 /* validate_nttransact */
3837 rc
= validate_ntransact(iov
[0].iov_base
, (char **)&parm
,
3838 &pdata
, &parm_len
, pbuflen
);
3841 pSMBr
= (struct smb_com_ntransact_rsp
*)iov
[0].iov_base
;
3843 cFYI(1, "smb %p parm %p data %p", pSMBr
, parm
, *acl_inf
);
3845 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
3846 rc
= -EIO
; /* bad smb */
3851 /* BB check that data area is minimum length and as big as acl_len */
3853 acl_len
= le32_to_cpu(*parm
);
3854 if (acl_len
!= *pbuflen
) {
3855 cERROR(1, "acl length %d does not match %d",
3857 if (*pbuflen
> acl_len
)
3861 /* check if buffer is big enough for the acl
3862 header followed by the smallest SID */
3863 if ((*pbuflen
< sizeof(struct cifs_ntsd
) + 8) ||
3864 (*pbuflen
>= 64 * 1024)) {
3865 cERROR(1, "bad acl length %d", *pbuflen
);
3869 *acl_inf
= kmalloc(*pbuflen
, GFP_KERNEL
);
3870 if (*acl_inf
== NULL
) {
3874 memcpy(*acl_inf
, pdata
, *pbuflen
);
3878 if (buf_type
== CIFS_SMALL_BUFFER
)
3879 cifs_small_buf_release(iov
[0].iov_base
);
3880 else if (buf_type
== CIFS_LARGE_BUFFER
)
3881 cifs_buf_release(iov
[0].iov_base
);
3882 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
3887 CIFSSMBSetCIFSACL(const int xid
, struct cifs_tcon
*tcon
, __u16 fid
,
3888 struct cifs_ntsd
*pntsd
, __u32 acllen
, int aclflag
)
3890 __u16 byte_count
, param_count
, data_count
, param_offset
, data_offset
;
3892 int bytes_returned
= 0;
3893 SET_SEC_DESC_REQ
*pSMB
= NULL
;
3894 NTRANSACT_RSP
*pSMBr
= NULL
;
3897 rc
= smb_init(SMB_COM_NT_TRANSACT
, 19, tcon
, (void **) &pSMB
,
3902 pSMB
->MaxSetupCount
= 0;
3906 param_offset
= offsetof(struct smb_com_transaction_ssec_req
, Fid
) - 4;
3907 data_count
= acllen
;
3908 data_offset
= param_offset
+ param_count
;
3909 byte_count
= 3 /* pad */ + param_count
;
3911 pSMB
->DataCount
= cpu_to_le32(data_count
);
3912 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3913 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3914 pSMB
->MaxDataCount
= cpu_to_le32(16384);
3915 pSMB
->ParameterCount
= cpu_to_le32(param_count
);
3916 pSMB
->ParameterOffset
= cpu_to_le32(param_offset
);
3917 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3918 pSMB
->DataOffset
= cpu_to_le32(data_offset
);
3919 pSMB
->SetupCount
= 0;
3920 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC
);
3921 pSMB
->ByteCount
= cpu_to_le16(byte_count
+data_count
);
3923 pSMB
->Fid
= fid
; /* file handle always le */
3924 pSMB
->Reserved2
= 0;
3925 pSMB
->AclFlags
= cpu_to_le32(aclflag
);
3927 if (pntsd
&& acllen
) {
3928 memcpy((char *) &pSMBr
->hdr
.Protocol
+ data_offset
,
3931 inc_rfc1001_len(pSMB
, byte_count
+ data_count
);
3933 inc_rfc1001_len(pSMB
, byte_count
);
3935 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3936 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3938 cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned
, rc
);
3940 cFYI(1, "Set CIFS ACL returned %d", rc
);
3941 cifs_buf_release(pSMB
);
3944 goto setCifsAclRetry
;
3949 #endif /* CONFIG_CIFS_ACL */
3951 /* Legacy Query Path Information call for lookup to old servers such
3953 int SMBQueryInformation(const int xid
, struct cifs_tcon
*tcon
,
3954 const unsigned char *searchName
,
3955 FILE_ALL_INFO
*pFinfo
,
3956 const struct nls_table
*nls_codepage
, int remap
)
3958 QUERY_INFORMATION_REQ
*pSMB
;
3959 QUERY_INFORMATION_RSP
*pSMBr
;
3964 cFYI(1, "In SMBQPath path %s", searchName
);
3966 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
3971 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3973 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
3974 searchName
, PATH_MAX
, nls_codepage
,
3976 name_len
++; /* trailing null */
3979 name_len
= strnlen(searchName
, PATH_MAX
);
3980 name_len
++; /* trailing null */
3981 strncpy(pSMB
->FileName
, searchName
, name_len
);
3983 pSMB
->BufferFormat
= 0x04;
3984 name_len
++; /* account for buffer type byte */
3985 inc_rfc1001_len(pSMB
, (__u16
)name_len
);
3986 pSMB
->ByteCount
= cpu_to_le16(name_len
);
3988 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3989 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3991 cFYI(1, "Send error in QueryInfo = %d", rc
);
3992 } else if (pFinfo
) {
3994 __u32 time
= le32_to_cpu(pSMBr
->last_write_time
);
3996 /* decode response */
3997 /* BB FIXME - add time zone adjustment BB */
3998 memset(pFinfo
, 0, sizeof(FILE_ALL_INFO
));
4001 /* decode time fields */
4002 pFinfo
->ChangeTime
= cpu_to_le64(cifs_UnixTimeToNT(ts
));
4003 pFinfo
->LastWriteTime
= pFinfo
->ChangeTime
;
4004 pFinfo
->LastAccessTime
= 0;
4005 pFinfo
->AllocationSize
=
4006 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
4007 pFinfo
->EndOfFile
= pFinfo
->AllocationSize
;
4008 pFinfo
->Attributes
=
4009 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
4011 rc
= -EIO
; /* bad buffer passed in */
4013 cifs_buf_release(pSMB
);
4022 CIFSSMBQFileInfo(const int xid
, struct cifs_tcon
*tcon
,
4023 u16 netfid
, FILE_ALL_INFO
*pFindData
)
4025 struct smb_t2_qfi_req
*pSMB
= NULL
;
4026 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
4029 __u16 params
, byte_count
;
4032 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4037 params
= 2 /* level */ + 2 /* fid */;
4038 pSMB
->t2
.TotalDataCount
= 0;
4039 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
4040 /* BB find exact max data count below from sess structure BB */
4041 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
4042 pSMB
->t2
.MaxSetupCount
= 0;
4043 pSMB
->t2
.Reserved
= 0;
4045 pSMB
->t2
.Timeout
= 0;
4046 pSMB
->t2
.Reserved2
= 0;
4047 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
4049 pSMB
->t2
.DataCount
= 0;
4050 pSMB
->t2
.DataOffset
= 0;
4051 pSMB
->t2
.SetupCount
= 1;
4052 pSMB
->t2
.Reserved3
= 0;
4053 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
4054 byte_count
= params
+ 1 /* pad */ ;
4055 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
4056 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
4057 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
4060 inc_rfc1001_len(pSMB
, byte_count
);
4062 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4063 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4065 cFYI(1, "Send error in QPathInfo = %d", rc
);
4066 } else { /* decode response */
4067 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4069 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
4071 else if (get_bcc(&pSMBr
->hdr
) < 40)
4072 rc
= -EIO
; /* bad smb */
4073 else if (pFindData
) {
4074 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4075 memcpy((char *) pFindData
,
4076 (char *) &pSMBr
->hdr
.Protocol
+
4077 data_offset
, sizeof(FILE_ALL_INFO
));
4081 cifs_buf_release(pSMB
);
4083 goto QFileInfoRetry
;
4089 CIFSSMBQPathInfo(const int xid
, struct cifs_tcon
*tcon
,
4090 const unsigned char *searchName
,
4091 FILE_ALL_INFO
*pFindData
,
4092 int legacy
/* old style infolevel */,
4093 const struct nls_table
*nls_codepage
, int remap
)
4095 /* level 263 SMB_QUERY_FILE_ALL_INFO */
4096 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4097 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4101 __u16 params
, byte_count
;
4103 /* cFYI(1, "In QPathInfo path %s", searchName); */
4105 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4110 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4112 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4113 PATH_MAX
, nls_codepage
, remap
);
4114 name_len
++; /* trailing null */
4116 } else { /* BB improve the check for buffer overruns BB */
4117 name_len
= strnlen(searchName
, PATH_MAX
);
4118 name_len
++; /* trailing null */
4119 strncpy(pSMB
->FileName
, searchName
, name_len
);
4122 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
4123 pSMB
->TotalDataCount
= 0;
4124 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4125 /* BB find exact max SMB PDU from sess structure BB */
4126 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4127 pSMB
->MaxSetupCount
= 0;
4131 pSMB
->Reserved2
= 0;
4132 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4133 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4134 pSMB
->DataCount
= 0;
4135 pSMB
->DataOffset
= 0;
4136 pSMB
->SetupCount
= 1;
4137 pSMB
->Reserved3
= 0;
4138 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4139 byte_count
= params
+ 1 /* pad */ ;
4140 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4141 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4143 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_STANDARD
);
4145 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
4146 pSMB
->Reserved4
= 0;
4147 inc_rfc1001_len(pSMB
, byte_count
);
4148 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4150 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4151 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4153 cFYI(1, "Send error in QPathInfo = %d", rc
);
4154 } else { /* decode response */
4155 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4157 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
4159 else if (!legacy
&& get_bcc(&pSMBr
->hdr
) < 40)
4160 rc
= -EIO
; /* bad smb */
4161 else if (legacy
&& get_bcc(&pSMBr
->hdr
) < 24)
4162 rc
= -EIO
; /* 24 or 26 expected but we do not read
4164 else if (pFindData
) {
4166 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4168 /* On legacy responses we do not read the last field,
4169 EAsize, fortunately since it varies by subdialect and
4170 also note it differs on Set vs. Get, ie two bytes or 4
4171 bytes depending but we don't care here */
4173 size
= sizeof(FILE_INFO_STANDARD
);
4175 size
= sizeof(FILE_ALL_INFO
);
4176 memcpy((char *) pFindData
,
4177 (char *) &pSMBr
->hdr
.Protocol
+
4182 cifs_buf_release(pSMB
);
4184 goto QPathInfoRetry
;
4190 CIFSSMBUnixQFileInfo(const int xid
, struct cifs_tcon
*tcon
,
4191 u16 netfid
, FILE_UNIX_BASIC_INFO
*pFindData
)
4193 struct smb_t2_qfi_req
*pSMB
= NULL
;
4194 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
4197 __u16 params
, byte_count
;
4200 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4205 params
= 2 /* level */ + 2 /* fid */;
4206 pSMB
->t2
.TotalDataCount
= 0;
4207 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
4208 /* BB find exact max data count below from sess structure BB */
4209 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
4210 pSMB
->t2
.MaxSetupCount
= 0;
4211 pSMB
->t2
.Reserved
= 0;
4213 pSMB
->t2
.Timeout
= 0;
4214 pSMB
->t2
.Reserved2
= 0;
4215 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
4217 pSMB
->t2
.DataCount
= 0;
4218 pSMB
->t2
.DataOffset
= 0;
4219 pSMB
->t2
.SetupCount
= 1;
4220 pSMB
->t2
.Reserved3
= 0;
4221 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
4222 byte_count
= params
+ 1 /* pad */ ;
4223 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
4224 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
4225 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
4228 inc_rfc1001_len(pSMB
, byte_count
);
4230 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4231 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4233 cFYI(1, "Send error in QPathInfo = %d", rc
);
4234 } else { /* decode response */
4235 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4237 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(FILE_UNIX_BASIC_INFO
)) {
4238 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
4239 "Unix Extensions can be disabled on mount "
4240 "by specifying the nosfu mount option.");
4241 rc
= -EIO
; /* bad smb */
4243 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4244 memcpy((char *) pFindData
,
4245 (char *) &pSMBr
->hdr
.Protocol
+
4247 sizeof(FILE_UNIX_BASIC_INFO
));
4251 cifs_buf_release(pSMB
);
4253 goto UnixQFileInfoRetry
;
4259 CIFSSMBUnixQPathInfo(const int xid
, struct cifs_tcon
*tcon
,
4260 const unsigned char *searchName
,
4261 FILE_UNIX_BASIC_INFO
*pFindData
,
4262 const struct nls_table
*nls_codepage
, int remap
)
4264 /* SMB_QUERY_FILE_UNIX_BASIC */
4265 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4266 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4268 int bytes_returned
= 0;
4270 __u16 params
, byte_count
;
4272 cFYI(1, "In QPathInfo (Unix) the path %s", searchName
);
4274 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4279 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4281 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4282 PATH_MAX
, nls_codepage
, remap
);
4283 name_len
++; /* trailing null */
4285 } else { /* BB improve the check for buffer overruns BB */
4286 name_len
= strnlen(searchName
, PATH_MAX
);
4287 name_len
++; /* trailing null */
4288 strncpy(pSMB
->FileName
, searchName
, name_len
);
4291 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
4292 pSMB
->TotalDataCount
= 0;
4293 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4294 /* BB find exact max SMB PDU from sess structure BB */
4295 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4296 pSMB
->MaxSetupCount
= 0;
4300 pSMB
->Reserved2
= 0;
4301 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4302 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4303 pSMB
->DataCount
= 0;
4304 pSMB
->DataOffset
= 0;
4305 pSMB
->SetupCount
= 1;
4306 pSMB
->Reserved3
= 0;
4307 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4308 byte_count
= params
+ 1 /* pad */ ;
4309 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4310 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4311 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
4312 pSMB
->Reserved4
= 0;
4313 inc_rfc1001_len(pSMB
, byte_count
);
4314 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4316 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4317 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4319 cFYI(1, "Send error in QPathInfo = %d", rc
);
4320 } else { /* decode response */
4321 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4323 if (rc
|| get_bcc(&pSMBr
->hdr
) < sizeof(FILE_UNIX_BASIC_INFO
)) {
4324 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
4325 "Unix Extensions can be disabled on mount "
4326 "by specifying the nosfu mount option.");
4327 rc
= -EIO
; /* bad smb */
4329 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4330 memcpy((char *) pFindData
,
4331 (char *) &pSMBr
->hdr
.Protocol
+
4333 sizeof(FILE_UNIX_BASIC_INFO
));
4336 cifs_buf_release(pSMB
);
4338 goto UnixQPathInfoRetry
;
4343 /* xid, tcon, searchName and codepage are input parms, rest are returned */
4345 CIFSFindFirst(const int xid
, struct cifs_tcon
*tcon
,
4346 const char *searchName
,
4347 const struct nls_table
*nls_codepage
,
4349 struct cifs_search_info
*psrch_inf
, int remap
, const char dirsep
)
4351 /* level 257 SMB_ */
4352 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
4353 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
4354 T2_FFIRST_RSP_PARMS
*parms
;
4356 int bytes_returned
= 0;
4358 __u16 params
, byte_count
;
4360 cFYI(1, "In FindFirst for %s", searchName
);
4363 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4368 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4370 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
4371 PATH_MAX
, nls_codepage
, remap
);
4372 /* We can not add the asterik earlier in case
4373 it got remapped to 0xF03A as if it were part of the
4374 directory name instead of a wildcard */
4376 pSMB
->FileName
[name_len
] = dirsep
;
4377 pSMB
->FileName
[name_len
+1] = 0;
4378 pSMB
->FileName
[name_len
+2] = '*';
4379 pSMB
->FileName
[name_len
+3] = 0;
4380 name_len
+= 4; /* now the trailing null */
4381 pSMB
->FileName
[name_len
] = 0; /* null terminate just in case */
4382 pSMB
->FileName
[name_len
+1] = 0;
4384 } else { /* BB add check for overrun of SMB buf BB */
4385 name_len
= strnlen(searchName
, PATH_MAX
);
4386 /* BB fix here and in unicode clause above ie
4387 if (name_len > buffersize-header)
4388 free buffer exit; BB */
4389 strncpy(pSMB
->FileName
, searchName
, name_len
);
4390 pSMB
->FileName
[name_len
] = dirsep
;
4391 pSMB
->FileName
[name_len
+1] = '*';
4392 pSMB
->FileName
[name_len
+2] = 0;
4396 params
= 12 + name_len
/* includes null */ ;
4397 pSMB
->TotalDataCount
= 0; /* no EAs */
4398 pSMB
->MaxParameterCount
= cpu_to_le16(10);
4399 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
& 0xFFFFFF00);
4400 pSMB
->MaxSetupCount
= 0;
4404 pSMB
->Reserved2
= 0;
4405 byte_count
= params
+ 1 /* pad */ ;
4406 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4407 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4408 pSMB
->ParameterOffset
= cpu_to_le16(
4409 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
)
4411 pSMB
->DataCount
= 0;
4412 pSMB
->DataOffset
= 0;
4413 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
4414 pSMB
->Reserved3
= 0;
4415 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
4416 pSMB
->SearchAttributes
=
4417 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
4419 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
4420 pSMB
->SearchFlags
= cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
|
4421 CIFS_SEARCH_RETURN_RESUME
);
4422 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
4424 /* BB what should we set StorageType to? Does it matter? BB */
4425 pSMB
->SearchStorageType
= 0;
4426 inc_rfc1001_len(pSMB
, byte_count
);
4427 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4429 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4430 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4431 cifs_stats_inc(&tcon
->num_ffirst
);
4433 if (rc
) {/* BB add logic to retry regular search if Unix search
4434 rejected unexpectedly by server */
4435 /* BB Add code to handle unsupported level rc */
4436 cFYI(1, "Error in FindFirst = %d", rc
);
4438 cifs_buf_release(pSMB
);
4440 /* BB eventually could optimize out free and realloc of buf */
4443 goto findFirstRetry
;
4444 } else { /* decode response */
4445 /* BB remember to free buffer if error BB */
4446 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4450 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4451 psrch_inf
->unicode
= true;
4453 psrch_inf
->unicode
= false;
4455 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
4456 psrch_inf
->smallBuf
= 0;
4457 psrch_inf
->srch_entries_start
=
4458 (char *) &pSMBr
->hdr
.Protocol
+
4459 le16_to_cpu(pSMBr
->t2
.DataOffset
);
4460 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
4461 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
4463 if (parms
->EndofSearch
)
4464 psrch_inf
->endOfSearch
= true;
4466 psrch_inf
->endOfSearch
= false;
4468 psrch_inf
->entries_in_buffer
=
4469 le16_to_cpu(parms
->SearchCount
);
4470 psrch_inf
->index_of_last_entry
= 2 /* skip . and .. */ +
4471 psrch_inf
->entries_in_buffer
;
4472 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
4473 if (CIFSMaxBufSize
< lnoff
) {
4474 cERROR(1, "ignoring corrupt resume name");
4475 psrch_inf
->last_entry
= NULL
;
4479 psrch_inf
->last_entry
= psrch_inf
->srch_entries_start
+
4482 *pnetfid
= parms
->SearchHandle
;
4484 cifs_buf_release(pSMB
);
4491 int CIFSFindNext(const int xid
, struct cifs_tcon
*tcon
,
4492 __u16 searchHandle
, struct cifs_search_info
*psrch_inf
)
4494 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
4495 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
4496 T2_FNEXT_RSP_PARMS
*parms
;
4497 char *response_data
;
4500 unsigned int name_len
;
4501 __u16 params
, byte_count
;
4503 cFYI(1, "In FindNext");
4505 if (psrch_inf
->endOfSearch
)
4508 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4513 params
= 14; /* includes 2 bytes of null string, converted to LE below*/
4515 pSMB
->TotalDataCount
= 0; /* no EAs */
4516 pSMB
->MaxParameterCount
= cpu_to_le16(8);
4517 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
& 0xFFFFFF00);
4518 pSMB
->MaxSetupCount
= 0;
4522 pSMB
->Reserved2
= 0;
4523 pSMB
->ParameterOffset
= cpu_to_le16(
4524 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
4525 pSMB
->DataCount
= 0;
4526 pSMB
->DataOffset
= 0;
4527 pSMB
->SetupCount
= 1;
4528 pSMB
->Reserved3
= 0;
4529 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
4530 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
4532 cpu_to_le16(CIFSMaxBufSize
/ sizeof(FILE_UNIX_INFO
));
4533 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
4534 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
4536 cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
| CIFS_SEARCH_RETURN_RESUME
);
4538 name_len
= psrch_inf
->resume_name_len
;
4540 if (name_len
< PATH_MAX
) {
4541 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
4542 byte_count
+= name_len
;
4543 /* 14 byte parm len above enough for 2 byte null terminator */
4544 pSMB
->ResumeFileName
[name_len
] = 0;
4545 pSMB
->ResumeFileName
[name_len
+1] = 0;
4548 goto FNext2_err_exit
;
4550 byte_count
= params
+ 1 /* pad */ ;
4551 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4552 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4553 inc_rfc1001_len(pSMB
, byte_count
);
4554 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4556 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4557 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4558 cifs_stats_inc(&tcon
->num_fnext
);
4561 psrch_inf
->endOfSearch
= true;
4562 cifs_buf_release(pSMB
);
4563 rc
= 0; /* search probably was closed at end of search*/
4565 cFYI(1, "FindNext returned = %d", rc
);
4566 } else { /* decode response */
4567 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4572 /* BB fixme add lock for file (srch_info) struct here */
4573 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4574 psrch_inf
->unicode
= true;
4576 psrch_inf
->unicode
= false;
4577 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
4578 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
4579 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
4580 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
4581 le16_to_cpu(pSMBr
->t2
.DataOffset
);
4582 if (psrch_inf
->smallBuf
)
4583 cifs_small_buf_release(
4584 psrch_inf
->ntwrk_buf_start
);
4586 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
4587 psrch_inf
->srch_entries_start
= response_data
;
4588 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
4589 psrch_inf
->smallBuf
= 0;
4590 if (parms
->EndofSearch
)
4591 psrch_inf
->endOfSearch
= true;
4593 psrch_inf
->endOfSearch
= false;
4594 psrch_inf
->entries_in_buffer
=
4595 le16_to_cpu(parms
->SearchCount
);
4596 psrch_inf
->index_of_last_entry
+=
4597 psrch_inf
->entries_in_buffer
;
4598 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
4599 if (CIFSMaxBufSize
< lnoff
) {
4600 cERROR(1, "ignoring corrupt resume name");
4601 psrch_inf
->last_entry
= NULL
;
4604 psrch_inf
->last_entry
=
4605 psrch_inf
->srch_entries_start
+ lnoff
;
4607 /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d",
4608 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */
4610 /* BB fixme add unlock here */
4615 /* BB On error, should we leave previous search buf (and count and
4616 last entry fields) intact or free the previous one? */
4618 /* Note: On -EAGAIN error only caller can retry on handle based calls
4619 since file handle passed in no longer valid */
4622 cifs_buf_release(pSMB
);
4627 CIFSFindClose(const int xid
, struct cifs_tcon
*tcon
,
4628 const __u16 searchHandle
)
4631 FINDCLOSE_REQ
*pSMB
= NULL
;
4633 cFYI(1, "In CIFSSMBFindClose");
4634 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
4636 /* no sense returning error if session restarted
4637 as file handle has been closed */
4643 pSMB
->FileID
= searchHandle
;
4644 pSMB
->ByteCount
= 0;
4645 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
4647 cERROR(1, "Send error in FindClose = %d", rc
);
4649 cifs_stats_inc(&tcon
->num_fclose
);
4651 /* Since session is dead, search handle closed on server already */
4659 CIFSGetSrvInodeNumber(const int xid
, struct cifs_tcon
*tcon
,
4660 const unsigned char *searchName
,
4661 __u64
*inode_number
,
4662 const struct nls_table
*nls_codepage
, int remap
)
4665 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4666 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4667 int name_len
, bytes_returned
;
4668 __u16 params
, byte_count
;
4670 cFYI(1, "In GetSrvInodeNum for %s", searchName
);
4674 GetInodeNumberRetry
:
4675 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4680 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4682 cifsConvertToUTF16((__le16
*) pSMB
->FileName
,
4683 searchName
, PATH_MAX
, nls_codepage
,
4685 name_len
++; /* trailing null */
4687 } else { /* BB improve the check for buffer overruns BB */
4688 name_len
= strnlen(searchName
, PATH_MAX
);
4689 name_len
++; /* trailing null */
4690 strncpy(pSMB
->FileName
, searchName
, name_len
);
4693 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
4694 pSMB
->TotalDataCount
= 0;
4695 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4696 /* BB find exact max data count below from sess structure BB */
4697 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4698 pSMB
->MaxSetupCount
= 0;
4702 pSMB
->Reserved2
= 0;
4703 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4704 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
4705 pSMB
->DataCount
= 0;
4706 pSMB
->DataOffset
= 0;
4707 pSMB
->SetupCount
= 1;
4708 pSMB
->Reserved3
= 0;
4709 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4710 byte_count
= params
+ 1 /* pad */ ;
4711 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4712 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4713 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
4714 pSMB
->Reserved4
= 0;
4715 inc_rfc1001_len(pSMB
, byte_count
);
4716 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4718 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4719 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4721 cFYI(1, "error %d in QueryInternalInfo", rc
);
4723 /* decode response */
4724 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4725 /* BB also check enough total bytes returned */
4726 if (rc
|| get_bcc(&pSMBr
->hdr
) < 2)
4727 /* If rc should we check for EOPNOSUPP and
4728 disable the srvino flag? or in caller? */
4729 rc
= -EIO
; /* bad smb */
4731 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4732 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
4733 struct file_internal_info
*pfinfo
;
4734 /* BB Do we need a cast or hash here ? */
4736 cFYI(1, "Illegal size ret in QryIntrnlInf");
4738 goto GetInodeNumOut
;
4740 pfinfo
= (struct file_internal_info
*)
4741 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
4742 *inode_number
= le64_to_cpu(pfinfo
->UniqueId
);
4746 cifs_buf_release(pSMB
);
4748 goto GetInodeNumberRetry
;
4752 /* parses DFS refferal V3 structure
4753 * caller is responsible for freeing target_nodes
4756 * on failure - errno
4759 parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
,
4760 unsigned int *num_of_nodes
,
4761 struct dfs_info3_param
**target_nodes
,
4762 const struct nls_table
*nls_codepage
, int remap
,
4763 const char *searchName
)
4768 struct dfs_referral_level_3
*ref
;
4770 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4774 *num_of_nodes
= le16_to_cpu(pSMBr
->NumberOfReferrals
);
4776 if (*num_of_nodes
< 1) {
4777 cERROR(1, "num_referrals: must be at least > 0,"
4778 "but we get num_referrals = %d\n", *num_of_nodes
);
4780 goto parse_DFS_referrals_exit
;
4783 ref
= (struct dfs_referral_level_3
*) &(pSMBr
->referrals
);
4784 if (ref
->VersionNumber
!= cpu_to_le16(3)) {
4785 cERROR(1, "Referrals of V%d version are not supported,"
4786 "should be V3", le16_to_cpu(ref
->VersionNumber
));
4788 goto parse_DFS_referrals_exit
;
4791 /* get the upper boundary of the resp buffer */
4792 data_end
= (char *)(&(pSMBr
->PathConsumed
)) +
4793 le16_to_cpu(pSMBr
->t2
.DataCount
);
4795 cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n",
4797 le32_to_cpu(pSMBr
->DFSFlags
));
4799 *target_nodes
= kzalloc(sizeof(struct dfs_info3_param
) *
4800 *num_of_nodes
, GFP_KERNEL
);
4801 if (*target_nodes
== NULL
) {
4802 cERROR(1, "Failed to allocate buffer for target_nodes\n");
4804 goto parse_DFS_referrals_exit
;
4807 /* collect necessary data from referrals */
4808 for (i
= 0; i
< *num_of_nodes
; i
++) {
4811 struct dfs_info3_param
*node
= (*target_nodes
)+i
;
4813 node
->flags
= le32_to_cpu(pSMBr
->DFSFlags
);
4815 __le16
*tmp
= kmalloc(strlen(searchName
)*2 + 2,
4819 goto parse_DFS_referrals_exit
;
4821 cifsConvertToUTF16((__le16
*) tmp
, searchName
,
4822 PATH_MAX
, nls_codepage
, remap
);
4823 node
->path_consumed
= cifs_utf16_bytes(tmp
,
4824 le16_to_cpu(pSMBr
->PathConsumed
),
4828 node
->path_consumed
= le16_to_cpu(pSMBr
->PathConsumed
);
4830 node
->server_type
= le16_to_cpu(ref
->ServerType
);
4831 node
->ref_flag
= le16_to_cpu(ref
->ReferralEntryFlags
);
4834 temp
= (char *)ref
+ le16_to_cpu(ref
->DfsPathOffset
);
4835 max_len
= data_end
- temp
;
4836 node
->path_name
= cifs_strndup_from_utf16(temp
, max_len
,
4837 is_unicode
, nls_codepage
);
4838 if (!node
->path_name
) {
4840 goto parse_DFS_referrals_exit
;
4843 /* copy link target UNC */
4844 temp
= (char *)ref
+ le16_to_cpu(ref
->NetworkAddressOffset
);
4845 max_len
= data_end
- temp
;
4846 node
->node_name
= cifs_strndup_from_utf16(temp
, max_len
,
4847 is_unicode
, nls_codepage
);
4848 if (!node
->node_name
)
4852 parse_DFS_referrals_exit
:
4854 free_dfs_info_array(*target_nodes
, *num_of_nodes
);
4855 *target_nodes
= NULL
;
4862 CIFSGetDFSRefer(const int xid
, struct cifs_ses
*ses
,
4863 const unsigned char *searchName
,
4864 struct dfs_info3_param
**target_nodes
,
4865 unsigned int *num_of_nodes
,
4866 const struct nls_table
*nls_codepage
, int remap
)
4868 /* TRANS2_GET_DFS_REFERRAL */
4869 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
4870 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
4874 __u16 params
, byte_count
;
4876 *target_nodes
= NULL
;
4878 cFYI(1, "In GetDFSRefer the path %s", searchName
);
4882 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, NULL
, (void **) &pSMB
,
4887 /* server pointer checked in called function,
4888 but should never be null here anyway */
4889 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
4890 pSMB
->hdr
.Tid
= ses
->ipc_tid
;
4891 pSMB
->hdr
.Uid
= ses
->Suid
;
4892 if (ses
->capabilities
& CAP_STATUS32
)
4893 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
4894 if (ses
->capabilities
& CAP_DFS
)
4895 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
4897 if (ses
->capabilities
& CAP_UNICODE
) {
4898 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
4900 cifsConvertToUTF16((__le16
*) pSMB
->RequestFileName
,
4901 searchName
, PATH_MAX
, nls_codepage
,
4903 name_len
++; /* trailing null */
4905 } else { /* BB improve the check for buffer overruns BB */
4906 name_len
= strnlen(searchName
, PATH_MAX
);
4907 name_len
++; /* trailing null */
4908 strncpy(pSMB
->RequestFileName
, searchName
, name_len
);
4912 if (ses
->server
->sec_mode
&
4913 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
4914 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
4917 pSMB
->hdr
.Uid
= ses
->Suid
;
4919 params
= 2 /* level */ + name_len
/*includes null */ ;
4920 pSMB
->TotalDataCount
= 0;
4921 pSMB
->DataCount
= 0;
4922 pSMB
->DataOffset
= 0;
4923 pSMB
->MaxParameterCount
= 0;
4924 /* BB find exact max SMB PDU from sess structure BB */
4925 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4926 pSMB
->MaxSetupCount
= 0;
4930 pSMB
->Reserved2
= 0;
4931 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4932 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
4933 pSMB
->SetupCount
= 1;
4934 pSMB
->Reserved3
= 0;
4935 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
4936 byte_count
= params
+ 3 /* pad */ ;
4937 pSMB
->ParameterCount
= cpu_to_le16(params
);
4938 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4939 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
4940 inc_rfc1001_len(pSMB
, byte_count
);
4941 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4943 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
4944 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4946 cFYI(1, "Send error in GetDFSRefer = %d", rc
);
4949 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4951 /* BB Also check if enough total bytes returned? */
4952 if (rc
|| get_bcc(&pSMBr
->hdr
) < 17) {
4953 rc
= -EIO
; /* bad smb */
4957 cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d",
4958 get_bcc(&pSMBr
->hdr
),
4959 le16_to_cpu(pSMBr
->t2
.DataOffset
));
4961 /* parse returned result into more usable form */
4962 rc
= parse_DFS_referrals(pSMBr
, num_of_nodes
,
4963 target_nodes
, nls_codepage
, remap
,
4967 cifs_buf_release(pSMB
);
4975 /* Query File System Info such as free space to old servers such as Win 9x */
4977 SMBOldQFSInfo(const int xid
, struct cifs_tcon
*tcon
, struct kstatfs
*FSData
)
4979 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
4980 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4981 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4982 FILE_SYSTEM_ALLOC_INFO
*response_data
;
4984 int bytes_returned
= 0;
4985 __u16 params
, byte_count
;
4987 cFYI(1, "OldQFSInfo");
4989 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4994 params
= 2; /* level */
4995 pSMB
->TotalDataCount
= 0;
4996 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4997 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4998 pSMB
->MaxSetupCount
= 0;
5002 pSMB
->Reserved2
= 0;
5003 byte_count
= params
+ 1 /* pad */ ;
5004 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5005 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5006 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5007 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5008 pSMB
->DataCount
= 0;
5009 pSMB
->DataOffset
= 0;
5010 pSMB
->SetupCount
= 1;
5011 pSMB
->Reserved3
= 0;
5012 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5013 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
5014 inc_rfc1001_len(pSMB
, byte_count
);
5015 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5017 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5018 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5020 cFYI(1, "Send error in QFSInfo = %d", rc
);
5021 } else { /* decode response */
5022 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5024 if (rc
|| get_bcc(&pSMBr
->hdr
) < 18)
5025 rc
= -EIO
; /* bad smb */
5027 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5028 cFYI(1, "qfsinf resp BCC: %d Offset %d",
5029 get_bcc(&pSMBr
->hdr
), data_offset
);
5031 response_data
= (FILE_SYSTEM_ALLOC_INFO
*)
5032 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
5034 le16_to_cpu(response_data
->BytesPerSector
) *
5035 le32_to_cpu(response_data
->
5036 SectorsPerAllocationUnit
);
5038 le32_to_cpu(response_data
->TotalAllocationUnits
);
5039 FSData
->f_bfree
= FSData
->f_bavail
=
5040 le32_to_cpu(response_data
->FreeAllocationUnits
);
5041 cFYI(1, "Blocks: %lld Free: %lld Block size %ld",
5042 (unsigned long long)FSData
->f_blocks
,
5043 (unsigned long long)FSData
->f_bfree
,
5047 cifs_buf_release(pSMB
);
5050 goto oldQFSInfoRetry
;
5056 CIFSSMBQFSInfo(const int xid
, struct cifs_tcon
*tcon
, struct kstatfs
*FSData
)
5058 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
5059 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5060 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5061 FILE_SYSTEM_INFO
*response_data
;
5063 int bytes_returned
= 0;
5064 __u16 params
, byte_count
;
5066 cFYI(1, "In QFSInfo");
5068 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5073 params
= 2; /* level */
5074 pSMB
->TotalDataCount
= 0;
5075 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5076 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5077 pSMB
->MaxSetupCount
= 0;
5081 pSMB
->Reserved2
= 0;
5082 byte_count
= params
+ 1 /* pad */ ;
5083 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5084 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5085 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5086 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5087 pSMB
->DataCount
= 0;
5088 pSMB
->DataOffset
= 0;
5089 pSMB
->SetupCount
= 1;
5090 pSMB
->Reserved3
= 0;
5091 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5092 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
5093 inc_rfc1001_len(pSMB
, byte_count
);
5094 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5096 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5097 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5099 cFYI(1, "Send error in QFSInfo = %d", rc
);
5100 } else { /* decode response */
5101 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5103 if (rc
|| get_bcc(&pSMBr
->hdr
) < 24)
5104 rc
= -EIO
; /* bad smb */
5106 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5110 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5113 le32_to_cpu(response_data
->BytesPerSector
) *
5114 le32_to_cpu(response_data
->
5115 SectorsPerAllocationUnit
);
5117 le64_to_cpu(response_data
->TotalAllocationUnits
);
5118 FSData
->f_bfree
= FSData
->f_bavail
=
5119 le64_to_cpu(response_data
->FreeAllocationUnits
);
5120 cFYI(1, "Blocks: %lld Free: %lld Block size %ld",
5121 (unsigned long long)FSData
->f_blocks
,
5122 (unsigned long long)FSData
->f_bfree
,
5126 cifs_buf_release(pSMB
);
5135 CIFSSMBQFSAttributeInfo(const int xid
, struct cifs_tcon
*tcon
)
5137 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
5138 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5139 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5140 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
5142 int bytes_returned
= 0;
5143 __u16 params
, byte_count
;
5145 cFYI(1, "In QFSAttributeInfo");
5147 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5152 params
= 2; /* level */
5153 pSMB
->TotalDataCount
= 0;
5154 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5155 /* BB find exact max SMB PDU from sess structure BB */
5156 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5157 pSMB
->MaxSetupCount
= 0;
5161 pSMB
->Reserved2
= 0;
5162 byte_count
= params
+ 1 /* pad */ ;
5163 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5164 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5165 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5166 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5167 pSMB
->DataCount
= 0;
5168 pSMB
->DataOffset
= 0;
5169 pSMB
->SetupCount
= 1;
5170 pSMB
->Reserved3
= 0;
5171 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5172 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
5173 inc_rfc1001_len(pSMB
, byte_count
);
5174 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5176 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5177 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5179 cERROR(1, "Send error in QFSAttributeInfo = %d", rc
);
5180 } else { /* decode response */
5181 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5183 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5184 /* BB also check if enough bytes returned */
5185 rc
= -EIO
; /* bad smb */
5187 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5189 (FILE_SYSTEM_ATTRIBUTE_INFO
5190 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5192 memcpy(&tcon
->fsAttrInfo
, response_data
,
5193 sizeof(FILE_SYSTEM_ATTRIBUTE_INFO
));
5196 cifs_buf_release(pSMB
);
5199 goto QFSAttributeRetry
;
5205 CIFSSMBQFSDeviceInfo(const int xid
, struct cifs_tcon
*tcon
)
5207 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
5208 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5209 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5210 FILE_SYSTEM_DEVICE_INFO
*response_data
;
5212 int bytes_returned
= 0;
5213 __u16 params
, byte_count
;
5215 cFYI(1, "In QFSDeviceInfo");
5217 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5222 params
= 2; /* level */
5223 pSMB
->TotalDataCount
= 0;
5224 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5225 /* BB find exact max SMB PDU from sess structure BB */
5226 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5227 pSMB
->MaxSetupCount
= 0;
5231 pSMB
->Reserved2
= 0;
5232 byte_count
= params
+ 1 /* pad */ ;
5233 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5234 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5235 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5236 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5238 pSMB
->DataCount
= 0;
5239 pSMB
->DataOffset
= 0;
5240 pSMB
->SetupCount
= 1;
5241 pSMB
->Reserved3
= 0;
5242 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5243 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
5244 inc_rfc1001_len(pSMB
, byte_count
);
5245 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5247 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5248 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5250 cFYI(1, "Send error in QFSDeviceInfo = %d", rc
);
5251 } else { /* decode response */
5252 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5254 if (rc
|| get_bcc(&pSMBr
->hdr
) <
5255 sizeof(FILE_SYSTEM_DEVICE_INFO
))
5256 rc
= -EIO
; /* bad smb */
5258 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5260 (FILE_SYSTEM_DEVICE_INFO
*)
5261 (((char *) &pSMBr
->hdr
.Protocol
) +
5263 memcpy(&tcon
->fsDevInfo
, response_data
,
5264 sizeof(FILE_SYSTEM_DEVICE_INFO
));
5267 cifs_buf_release(pSMB
);
5270 goto QFSDeviceRetry
;
5276 CIFSSMBQFSUnixInfo(const int xid
, struct cifs_tcon
*tcon
)
5278 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
5279 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5280 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5281 FILE_SYSTEM_UNIX_INFO
*response_data
;
5283 int bytes_returned
= 0;
5284 __u16 params
, byte_count
;
5286 cFYI(1, "In QFSUnixInfo");
5288 rc
= smb_init_no_reconnect(SMB_COM_TRANSACTION2
, 15, tcon
,
5289 (void **) &pSMB
, (void **) &pSMBr
);
5293 params
= 2; /* level */
5294 pSMB
->TotalDataCount
= 0;
5295 pSMB
->DataCount
= 0;
5296 pSMB
->DataOffset
= 0;
5297 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5298 /* BB find exact max SMB PDU from sess structure BB */
5299 pSMB
->MaxDataCount
= cpu_to_le16(100);
5300 pSMB
->MaxSetupCount
= 0;
5304 pSMB
->Reserved2
= 0;
5305 byte_count
= params
+ 1 /* pad */ ;
5306 pSMB
->ParameterCount
= cpu_to_le16(params
);
5307 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5308 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
5309 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5310 pSMB
->SetupCount
= 1;
5311 pSMB
->Reserved3
= 0;
5312 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5313 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
5314 inc_rfc1001_len(pSMB
, byte_count
);
5315 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5317 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5318 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5320 cERROR(1, "Send error in QFSUnixInfo = %d", rc
);
5321 } else { /* decode response */
5322 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5324 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5325 rc
= -EIO
; /* bad smb */
5327 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5329 (FILE_SYSTEM_UNIX_INFO
5330 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5332 memcpy(&tcon
->fsUnixInfo
, response_data
,
5333 sizeof(FILE_SYSTEM_UNIX_INFO
));
5336 cifs_buf_release(pSMB
);
5346 CIFSSMBSetFSUnixInfo(const int xid
, struct cifs_tcon
*tcon
, __u64 cap
)
5348 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
5349 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
5350 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
5352 int bytes_returned
= 0;
5353 __u16 params
, param_offset
, offset
, byte_count
;
5355 cFYI(1, "In SETFSUnixInfo");
5357 /* BB switch to small buf init to save memory */
5358 rc
= smb_init_no_reconnect(SMB_COM_TRANSACTION2
, 15, tcon
,
5359 (void **) &pSMB
, (void **) &pSMBr
);
5363 params
= 4; /* 2 bytes zero followed by info level. */
5364 pSMB
->MaxSetupCount
= 0;
5368 pSMB
->Reserved2
= 0;
5369 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
)
5371 offset
= param_offset
+ params
;
5373 pSMB
->MaxParameterCount
= cpu_to_le16(4);
5374 /* BB find exact max SMB PDU from sess structure BB */
5375 pSMB
->MaxDataCount
= cpu_to_le16(100);
5376 pSMB
->SetupCount
= 1;
5377 pSMB
->Reserved3
= 0;
5378 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
5379 byte_count
= 1 /* pad */ + params
+ 12;
5381 pSMB
->DataCount
= cpu_to_le16(12);
5382 pSMB
->ParameterCount
= cpu_to_le16(params
);
5383 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5384 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5385 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5386 pSMB
->DataOffset
= cpu_to_le16(offset
);
5390 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
5393 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
5394 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
5395 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
5397 inc_rfc1001_len(pSMB
, byte_count
);
5398 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5400 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5401 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5403 cERROR(1, "Send error in SETFSUnixInfo = %d", rc
);
5404 } else { /* decode response */
5405 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5407 rc
= -EIO
; /* bad smb */
5409 cifs_buf_release(pSMB
);
5412 goto SETFSUnixRetry
;
5420 CIFSSMBQFSPosixInfo(const int xid
, struct cifs_tcon
*tcon
,
5421 struct kstatfs
*FSData
)
5423 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
5424 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
5425 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
5426 FILE_SYSTEM_POSIX_INFO
*response_data
;
5428 int bytes_returned
= 0;
5429 __u16 params
, byte_count
;
5431 cFYI(1, "In QFSPosixInfo");
5433 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5438 params
= 2; /* level */
5439 pSMB
->TotalDataCount
= 0;
5440 pSMB
->DataCount
= 0;
5441 pSMB
->DataOffset
= 0;
5442 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5443 /* BB find exact max SMB PDU from sess structure BB */
5444 pSMB
->MaxDataCount
= cpu_to_le16(100);
5445 pSMB
->MaxSetupCount
= 0;
5449 pSMB
->Reserved2
= 0;
5450 byte_count
= params
+ 1 /* pad */ ;
5451 pSMB
->ParameterCount
= cpu_to_le16(params
);
5452 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5453 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
5454 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
5455 pSMB
->SetupCount
= 1;
5456 pSMB
->Reserved3
= 0;
5457 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
5458 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
5459 inc_rfc1001_len(pSMB
, byte_count
);
5460 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5462 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5463 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5465 cFYI(1, "Send error in QFSUnixInfo = %d", rc
);
5466 } else { /* decode response */
5467 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5469 if (rc
|| get_bcc(&pSMBr
->hdr
) < 13) {
5470 rc
= -EIO
; /* bad smb */
5472 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5474 (FILE_SYSTEM_POSIX_INFO
5475 *) (((char *) &pSMBr
->hdr
.Protocol
) +
5478 le32_to_cpu(response_data
->BlockSize
);
5480 le64_to_cpu(response_data
->TotalBlocks
);
5482 le64_to_cpu(response_data
->BlocksAvail
);
5483 if (response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
5484 FSData
->f_bavail
= FSData
->f_bfree
;
5487 le64_to_cpu(response_data
->UserBlocksAvail
);
5489 if (response_data
->TotalFileNodes
!= cpu_to_le64(-1))
5491 le64_to_cpu(response_data
->TotalFileNodes
);
5492 if (response_data
->FreeFileNodes
!= cpu_to_le64(-1))
5494 le64_to_cpu(response_data
->FreeFileNodes
);
5497 cifs_buf_release(pSMB
);
5506 /* We can not use write of zero bytes trick to
5507 set file size due to need for large file support. Also note that
5508 this SetPathInfo is preferred to SetFileInfo based method in next
5509 routine which is only needed to work around a sharing violation bug
5510 in Samba which this routine can run into */
5513 CIFSSMBSetEOF(const int xid
, struct cifs_tcon
*tcon
, const char *fileName
,
5514 __u64 size
, bool SetAllocation
,
5515 const struct nls_table
*nls_codepage
, int remap
)
5517 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
5518 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
5519 struct file_end_of_file_info
*parm_data
;
5522 int bytes_returned
= 0;
5523 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
5525 cFYI(1, "In SetEOF");
5527 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5532 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5534 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
5535 PATH_MAX
, nls_codepage
, remap
);
5536 name_len
++; /* trailing null */
5538 } else { /* BB improve the check for buffer overruns BB */
5539 name_len
= strnlen(fileName
, PATH_MAX
);
5540 name_len
++; /* trailing null */
5541 strncpy(pSMB
->FileName
, fileName
, name_len
);
5543 params
= 6 + name_len
;
5544 data_count
= sizeof(struct file_end_of_file_info
);
5545 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5546 pSMB
->MaxDataCount
= cpu_to_le16(4100);
5547 pSMB
->MaxSetupCount
= 0;
5551 pSMB
->Reserved2
= 0;
5552 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5553 InformationLevel
) - 4;
5554 offset
= param_offset
+ params
;
5555 if (SetAllocation
) {
5556 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5557 pSMB
->InformationLevel
=
5558 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
5560 pSMB
->InformationLevel
=
5561 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
5562 } else /* Set File Size */ {
5563 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5564 pSMB
->InformationLevel
=
5565 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
5567 pSMB
->InformationLevel
=
5568 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
5572 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
5574 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5575 pSMB
->DataOffset
= cpu_to_le16(offset
);
5576 pSMB
->SetupCount
= 1;
5577 pSMB
->Reserved3
= 0;
5578 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5579 byte_count
= 3 /* pad */ + params
+ data_count
;
5580 pSMB
->DataCount
= cpu_to_le16(data_count
);
5581 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5582 pSMB
->ParameterCount
= cpu_to_le16(params
);
5583 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5584 pSMB
->Reserved4
= 0;
5585 inc_rfc1001_len(pSMB
, byte_count
);
5586 parm_data
->FileSize
= cpu_to_le64(size
);
5587 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5588 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5589 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5591 cFYI(1, "SetPathInfo (file size) returned %d", rc
);
5593 cifs_buf_release(pSMB
);
5602 CIFSSMBSetFileSize(const int xid
, struct cifs_tcon
*tcon
, __u64 size
,
5603 __u16 fid
, __u32 pid_of_opener
, bool SetAllocation
)
5605 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5606 struct file_end_of_file_info
*parm_data
;
5608 __u16 params
, param_offset
, offset
, byte_count
, count
;
5610 cFYI(1, "SetFileSize (via SetFileInfo) %lld",
5612 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5617 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5618 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5621 pSMB
->MaxSetupCount
= 0;
5625 pSMB
->Reserved2
= 0;
5626 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5627 offset
= param_offset
+ params
;
5629 count
= sizeof(struct file_end_of_file_info
);
5630 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5631 /* BB find exact max SMB PDU from sess structure BB */
5632 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5633 pSMB
->SetupCount
= 1;
5634 pSMB
->Reserved3
= 0;
5635 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5636 byte_count
= 3 /* pad */ + params
+ count
;
5637 pSMB
->DataCount
= cpu_to_le16(count
);
5638 pSMB
->ParameterCount
= cpu_to_le16(params
);
5639 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5640 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5641 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5643 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
)
5645 pSMB
->DataOffset
= cpu_to_le16(offset
);
5646 parm_data
->FileSize
= cpu_to_le64(size
);
5648 if (SetAllocation
) {
5649 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5650 pSMB
->InformationLevel
=
5651 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
5653 pSMB
->InformationLevel
=
5654 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
5655 } else /* Set File Size */ {
5656 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5657 pSMB
->InformationLevel
=
5658 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
5660 pSMB
->InformationLevel
=
5661 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
5663 pSMB
->Reserved4
= 0;
5664 inc_rfc1001_len(pSMB
, byte_count
);
5665 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5666 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5668 cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc
);
5671 /* Note: On -EAGAIN error only caller can retry on handle based calls
5672 since file handle passed in no longer valid */
5677 /* Some legacy servers such as NT4 require that the file times be set on
5678 an open handle, rather than by pathname - this is awkward due to
5679 potential access conflicts on the open, but it is unavoidable for these
5680 old servers since the only other choice is to go from 100 nanosecond DCE
5681 time and resort to the original setpathinfo level which takes the ancient
5682 DOS time format with 2 second granularity */
5684 CIFSSMBSetFileInfo(const int xid
, struct cifs_tcon
*tcon
,
5685 const FILE_BASIC_INFO
*data
, __u16 fid
, __u32 pid_of_opener
)
5687 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5690 __u16 params
, param_offset
, offset
, byte_count
, count
;
5692 cFYI(1, "Set Times (via SetFileInfo)");
5693 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5698 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5699 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5702 pSMB
->MaxSetupCount
= 0;
5706 pSMB
->Reserved2
= 0;
5707 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5708 offset
= param_offset
+ params
;
5710 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5712 count
= sizeof(FILE_BASIC_INFO
);
5713 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5714 /* BB find max SMB PDU from sess */
5715 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5716 pSMB
->SetupCount
= 1;
5717 pSMB
->Reserved3
= 0;
5718 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5719 byte_count
= 3 /* pad */ + params
+ count
;
5720 pSMB
->DataCount
= cpu_to_le16(count
);
5721 pSMB
->ParameterCount
= cpu_to_le16(params
);
5722 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5723 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5724 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5725 pSMB
->DataOffset
= cpu_to_le16(offset
);
5727 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5728 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5730 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5731 pSMB
->Reserved4
= 0;
5732 inc_rfc1001_len(pSMB
, byte_count
);
5733 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5734 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5735 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5737 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc
);
5739 /* Note: On -EAGAIN error only caller can retry on handle based calls
5740 since file handle passed in no longer valid */
5746 CIFSSMBSetFileDisposition(const int xid
, struct cifs_tcon
*tcon
,
5747 bool delete_file
, __u16 fid
, __u32 pid_of_opener
)
5749 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5752 __u16 params
, param_offset
, offset
, byte_count
, count
;
5754 cFYI(1, "Set File Disposition (via SetFileInfo)");
5755 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5760 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5761 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5764 pSMB
->MaxSetupCount
= 0;
5768 pSMB
->Reserved2
= 0;
5769 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5770 offset
= param_offset
+ params
;
5772 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5775 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5776 /* BB find max SMB PDU from sess */
5777 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5778 pSMB
->SetupCount
= 1;
5779 pSMB
->Reserved3
= 0;
5780 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5781 byte_count
= 3 /* pad */ + params
+ count
;
5782 pSMB
->DataCount
= cpu_to_le16(count
);
5783 pSMB
->ParameterCount
= cpu_to_le16(params
);
5784 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5785 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5786 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5787 pSMB
->DataOffset
= cpu_to_le16(offset
);
5789 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO
);
5790 pSMB
->Reserved4
= 0;
5791 inc_rfc1001_len(pSMB
, byte_count
);
5792 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5793 *data_offset
= delete_file
? 1 : 0;
5794 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
5796 cFYI(1, "Send error in SetFileDisposition = %d", rc
);
5802 CIFSSMBSetPathInfo(const int xid
, struct cifs_tcon
*tcon
,
5803 const char *fileName
, const FILE_BASIC_INFO
*data
,
5804 const struct nls_table
*nls_codepage
, int remap
)
5806 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5807 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5810 int bytes_returned
= 0;
5812 __u16 params
, param_offset
, offset
, byte_count
, count
;
5814 cFYI(1, "In SetTimes");
5817 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5822 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5824 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
5825 PATH_MAX
, nls_codepage
, remap
);
5826 name_len
++; /* trailing null */
5828 } else { /* BB improve the check for buffer overruns BB */
5829 name_len
= strnlen(fileName
, PATH_MAX
);
5830 name_len
++; /* trailing null */
5831 strncpy(pSMB
->FileName
, fileName
, name_len
);
5834 params
= 6 + name_len
;
5835 count
= sizeof(FILE_BASIC_INFO
);
5836 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5837 /* BB find max SMB PDU from sess structure BB */
5838 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5839 pSMB
->MaxSetupCount
= 0;
5843 pSMB
->Reserved2
= 0;
5844 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5845 InformationLevel
) - 4;
5846 offset
= param_offset
+ params
;
5847 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5848 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5849 pSMB
->DataOffset
= cpu_to_le16(offset
);
5850 pSMB
->SetupCount
= 1;
5851 pSMB
->Reserved3
= 0;
5852 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5853 byte_count
= 3 /* pad */ + params
+ count
;
5855 pSMB
->DataCount
= cpu_to_le16(count
);
5856 pSMB
->ParameterCount
= cpu_to_le16(params
);
5857 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5858 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5859 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5860 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5862 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5863 pSMB
->Reserved4
= 0;
5864 inc_rfc1001_len(pSMB
, byte_count
);
5865 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5866 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5867 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5868 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5870 cFYI(1, "SetPathInfo (times) returned %d", rc
);
5872 cifs_buf_release(pSMB
);
5880 /* Can not be used to set time stamps yet (due to old DOS time format) */
5881 /* Can be used to set attributes */
5882 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
5883 handling it anyway and NT4 was what we thought it would be needed for
5884 Do not delete it until we prove whether needed for Win9x though */
5886 CIFSSMBSetAttrLegacy(int xid
, struct cifs_tcon
*tcon
, char *fileName
,
5887 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
5889 SETATTR_REQ
*pSMB
= NULL
;
5890 SETATTR_RSP
*pSMBr
= NULL
;
5895 cFYI(1, "In SetAttrLegacy");
5898 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
5903 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5905 ConvertToUTF16((__le16
*) pSMB
->fileName
, fileName
,
5906 PATH_MAX
, nls_codepage
);
5907 name_len
++; /* trailing null */
5909 } else { /* BB improve the check for buffer overruns BB */
5910 name_len
= strnlen(fileName
, PATH_MAX
);
5911 name_len
++; /* trailing null */
5912 strncpy(pSMB
->fileName
, fileName
, name_len
);
5914 pSMB
->attr
= cpu_to_le16(dos_attrs
);
5915 pSMB
->BufferFormat
= 0x04;
5916 inc_rfc1001_len(pSMB
, name_len
+ 1);
5917 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
5918 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5919 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5921 cFYI(1, "Error in LegacySetAttr = %d", rc
);
5923 cifs_buf_release(pSMB
);
5926 goto SetAttrLgcyRetry
;
5930 #endif /* temporarily unneeded SetAttr legacy function */
5933 cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO
*data_offset
,
5934 const struct cifs_unix_set_info_args
*args
)
5936 u64 mode
= args
->mode
;
5939 * Samba server ignores set of file size to zero due to bugs in some
5940 * older clients, but we should be precise - we use SetFileSize to
5941 * set file size and do not want to truncate file size to zero
5942 * accidentally as happened on one Samba server beta by putting
5943 * zero instead of -1 here
5945 data_offset
->EndOfFile
= cpu_to_le64(NO_CHANGE_64
);
5946 data_offset
->NumOfBytes
= cpu_to_le64(NO_CHANGE_64
);
5947 data_offset
->LastStatusChange
= cpu_to_le64(args
->ctime
);
5948 data_offset
->LastAccessTime
= cpu_to_le64(args
->atime
);
5949 data_offset
->LastModificationTime
= cpu_to_le64(args
->mtime
);
5950 data_offset
->Uid
= cpu_to_le64(args
->uid
);
5951 data_offset
->Gid
= cpu_to_le64(args
->gid
);
5952 /* better to leave device as zero when it is */
5953 data_offset
->DevMajor
= cpu_to_le64(MAJOR(args
->device
));
5954 data_offset
->DevMinor
= cpu_to_le64(MINOR(args
->device
));
5955 data_offset
->Permissions
= cpu_to_le64(mode
);
5958 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
5959 else if (S_ISDIR(mode
))
5960 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
5961 else if (S_ISLNK(mode
))
5962 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
5963 else if (S_ISCHR(mode
))
5964 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
5965 else if (S_ISBLK(mode
))
5966 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
5967 else if (S_ISFIFO(mode
))
5968 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
5969 else if (S_ISSOCK(mode
))
5970 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
5974 CIFSSMBUnixSetFileInfo(const int xid
, struct cifs_tcon
*tcon
,
5975 const struct cifs_unix_set_info_args
*args
,
5976 u16 fid
, u32 pid_of_opener
)
5978 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5979 FILE_UNIX_BASIC_INFO
*data_offset
;
5981 u16 params
, param_offset
, offset
, byte_count
, count
;
5983 cFYI(1, "Set Unix Info (via SetFileInfo)");
5984 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5989 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5990 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5993 pSMB
->MaxSetupCount
= 0;
5997 pSMB
->Reserved2
= 0;
5998 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5999 offset
= param_offset
+ params
;
6001 data_offset
= (FILE_UNIX_BASIC_INFO
*)
6002 ((char *)(&pSMB
->hdr
.Protocol
) + offset
);
6003 count
= sizeof(FILE_UNIX_BASIC_INFO
);
6005 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6006 /* BB find max SMB PDU from sess */
6007 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6008 pSMB
->SetupCount
= 1;
6009 pSMB
->Reserved3
= 0;
6010 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
6011 byte_count
= 3 /* pad */ + params
+ count
;
6012 pSMB
->DataCount
= cpu_to_le16(count
);
6013 pSMB
->ParameterCount
= cpu_to_le16(params
);
6014 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6015 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6016 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6017 pSMB
->DataOffset
= cpu_to_le16(offset
);
6019 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
6020 pSMB
->Reserved4
= 0;
6021 inc_rfc1001_len(pSMB
, byte_count
);
6022 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6024 cifs_fill_unix_set_info(data_offset
, args
);
6026 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (char *) pSMB
, 0);
6028 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc
);
6030 /* Note: On -EAGAIN error only caller can retry on handle based calls
6031 since file handle passed in no longer valid */
6037 CIFSSMBUnixSetPathInfo(const int xid
, struct cifs_tcon
*tcon
, char *fileName
,
6038 const struct cifs_unix_set_info_args
*args
,
6039 const struct nls_table
*nls_codepage
, int remap
)
6041 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
6042 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
6045 int bytes_returned
= 0;
6046 FILE_UNIX_BASIC_INFO
*data_offset
;
6047 __u16 params
, param_offset
, offset
, count
, byte_count
;
6049 cFYI(1, "In SetUID/GID/Mode");
6051 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6056 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6058 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
6059 PATH_MAX
, nls_codepage
, remap
);
6060 name_len
++; /* trailing null */
6062 } else { /* BB improve the check for buffer overruns BB */
6063 name_len
= strnlen(fileName
, PATH_MAX
);
6064 name_len
++; /* trailing null */
6065 strncpy(pSMB
->FileName
, fileName
, name_len
);
6068 params
= 6 + name_len
;
6069 count
= sizeof(FILE_UNIX_BASIC_INFO
);
6070 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6071 /* BB find max SMB PDU from sess structure BB */
6072 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6073 pSMB
->MaxSetupCount
= 0;
6077 pSMB
->Reserved2
= 0;
6078 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
6079 InformationLevel
) - 4;
6080 offset
= param_offset
+ params
;
6082 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
6084 memset(data_offset
, 0, count
);
6085 pSMB
->DataOffset
= cpu_to_le16(offset
);
6086 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6087 pSMB
->SetupCount
= 1;
6088 pSMB
->Reserved3
= 0;
6089 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
6090 byte_count
= 3 /* pad */ + params
+ count
;
6091 pSMB
->ParameterCount
= cpu_to_le16(params
);
6092 pSMB
->DataCount
= cpu_to_le16(count
);
6093 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6094 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6095 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
6096 pSMB
->Reserved4
= 0;
6097 inc_rfc1001_len(pSMB
, byte_count
);
6099 cifs_fill_unix_set_info(data_offset
, args
);
6101 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6102 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6103 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6105 cFYI(1, "SetPathInfo (perms) returned %d", rc
);
6107 cifs_buf_release(pSMB
);
6113 #ifdef CONFIG_CIFS_XATTR
6115 * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common
6116 * function used by listxattr and getxattr type calls. When ea_name is set,
6117 * it looks for that attribute name and stuffs that value into the EAData
6118 * buffer. When ea_name is NULL, it stuffs a list of attribute names into the
6119 * buffer. In both cases, the return value is either the length of the
6120 * resulting data or a negative error code. If EAData is a NULL pointer then
6121 * the data isn't copied to it, but the length is returned.
6124 CIFSSMBQAllEAs(const int xid
, struct cifs_tcon
*tcon
,
6125 const unsigned char *searchName
, const unsigned char *ea_name
,
6126 char *EAData
, size_t buf_size
,
6127 const struct nls_table
*nls_codepage
, int remap
)
6129 /* BB assumes one setup word */
6130 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
6131 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
6135 struct fealist
*ea_response_data
;
6136 struct fea
*temp_fea
;
6139 __u16 params
, byte_count
, data_offset
;
6140 unsigned int ea_name_len
= ea_name
? strlen(ea_name
) : 0;
6142 cFYI(1, "In Query All EAs path %s", searchName
);
6144 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6149 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6151 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, searchName
,
6152 PATH_MAX
, nls_codepage
, remap
);
6153 list_len
++; /* trailing null */
6155 } else { /* BB improve the check for buffer overruns BB */
6156 list_len
= strnlen(searchName
, PATH_MAX
);
6157 list_len
++; /* trailing null */
6158 strncpy(pSMB
->FileName
, searchName
, list_len
);
6161 params
= 2 /* level */ + 4 /* reserved */ + list_len
/* includes NUL */;
6162 pSMB
->TotalDataCount
= 0;
6163 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6164 /* BB find exact max SMB PDU from sess structure BB */
6165 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
6166 pSMB
->MaxSetupCount
= 0;
6170 pSMB
->Reserved2
= 0;
6171 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
6172 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
6173 pSMB
->DataCount
= 0;
6174 pSMB
->DataOffset
= 0;
6175 pSMB
->SetupCount
= 1;
6176 pSMB
->Reserved3
= 0;
6177 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
6178 byte_count
= params
+ 1 /* pad */ ;
6179 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
6180 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
6181 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
6182 pSMB
->Reserved4
= 0;
6183 inc_rfc1001_len(pSMB
, byte_count
);
6184 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6186 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6187 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6189 cFYI(1, "Send error in QueryAllEAs = %d", rc
);
6194 /* BB also check enough total bytes returned */
6195 /* BB we need to improve the validity checking
6196 of these trans2 responses */
6198 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
6199 if (rc
|| get_bcc(&pSMBr
->hdr
) < 4) {
6200 rc
= -EIO
; /* bad smb */
6204 /* check that length of list is not more than bcc */
6205 /* check that each entry does not go beyond length
6207 /* check that each element of each entry does not
6208 go beyond end of list */
6209 /* validate_trans2_offsets() */
6210 /* BB check if start of smb + data_offset > &bcc+ bcc */
6212 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
6213 ea_response_data
= (struct fealist
*)
6214 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
6216 list_len
= le32_to_cpu(ea_response_data
->list_len
);
6217 cFYI(1, "ea length %d", list_len
);
6218 if (list_len
<= 8) {
6219 cFYI(1, "empty EA list returned from server");
6223 /* make sure list_len doesn't go past end of SMB */
6224 end_of_smb
= (char *)pByteArea(&pSMBr
->hdr
) + get_bcc(&pSMBr
->hdr
);
6225 if ((char *)ea_response_data
+ list_len
> end_of_smb
) {
6226 cFYI(1, "EA list appears to go beyond SMB");
6231 /* account for ea list len */
6233 temp_fea
= ea_response_data
->list
;
6234 temp_ptr
= (char *)temp_fea
;
6235 while (list_len
> 0) {
6236 unsigned int name_len
;
6241 /* make sure we can read name_len and value_len */
6243 cFYI(1, "EA entry goes beyond length of list");
6248 name_len
= temp_fea
->name_len
;
6249 value_len
= le16_to_cpu(temp_fea
->value_len
);
6250 list_len
-= name_len
+ 1 + value_len
;
6252 cFYI(1, "EA entry goes beyond length of list");
6258 if (ea_name_len
== name_len
&&
6259 memcmp(ea_name
, temp_ptr
, name_len
) == 0) {
6260 temp_ptr
+= name_len
+ 1;
6264 if ((size_t)value_len
> buf_size
) {
6268 memcpy(EAData
, temp_ptr
, value_len
);
6272 /* account for prefix user. and trailing null */
6273 rc
+= (5 + 1 + name_len
);
6274 if (rc
< (int) buf_size
) {
6275 memcpy(EAData
, "user.", 5);
6277 memcpy(EAData
, temp_ptr
, name_len
);
6279 /* null terminate name */
6282 } else if (buf_size
== 0) {
6283 /* skip copy - calc size only */
6285 /* stop before overrun buffer */
6290 temp_ptr
+= name_len
+ 1 + value_len
;
6291 temp_fea
= (struct fea
*)temp_ptr
;
6294 /* didn't find the named attribute */
6299 cifs_buf_release(pSMB
);
6307 CIFSSMBSetEA(const int xid
, struct cifs_tcon
*tcon
, const char *fileName
,
6308 const char *ea_name
, const void *ea_value
,
6309 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
6312 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
6313 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
6314 struct fealist
*parm_data
;
6317 int bytes_returned
= 0;
6318 __u16 params
, param_offset
, byte_count
, offset
, count
;
6320 cFYI(1, "In SetEA");
6322 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
6327 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
6329 cifsConvertToUTF16((__le16
*) pSMB
->FileName
, fileName
,
6330 PATH_MAX
, nls_codepage
, remap
);
6331 name_len
++; /* trailing null */
6333 } else { /* BB improve the check for buffer overruns BB */
6334 name_len
= strnlen(fileName
, PATH_MAX
);
6335 name_len
++; /* trailing null */
6336 strncpy(pSMB
->FileName
, fileName
, name_len
);
6339 params
= 6 + name_len
;
6341 /* done calculating parms using name_len of file name,
6342 now use name_len to calculate length of ea name
6343 we are going to create in the inode xattrs */
6344 if (ea_name
== NULL
)
6347 name_len
= strnlen(ea_name
, 255);
6349 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
;
6350 pSMB
->MaxParameterCount
= cpu_to_le16(2);
6351 /* BB find max SMB PDU from sess */
6352 pSMB
->MaxDataCount
= cpu_to_le16(1000);
6353 pSMB
->MaxSetupCount
= 0;
6357 pSMB
->Reserved2
= 0;
6358 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
6359 InformationLevel
) - 4;
6360 offset
= param_offset
+ params
;
6361 pSMB
->InformationLevel
=
6362 cpu_to_le16(SMB_SET_FILE_EA
);
6365 (struct fealist
*) (((char *) &pSMB
->hdr
.Protocol
) +
6367 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
6368 pSMB
->DataOffset
= cpu_to_le16(offset
);
6369 pSMB
->SetupCount
= 1;
6370 pSMB
->Reserved3
= 0;
6371 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
6372 byte_count
= 3 /* pad */ + params
+ count
;
6373 pSMB
->DataCount
= cpu_to_le16(count
);
6374 parm_data
->list_len
= cpu_to_le32(count
);
6375 parm_data
->list
[0].EA_flags
= 0;
6376 /* we checked above that name len is less than 255 */
6377 parm_data
->list
[0].name_len
= (__u8
)name_len
;
6378 /* EA names are always ASCII */
6380 strncpy(parm_data
->list
[0].name
, ea_name
, name_len
);
6381 parm_data
->list
[0].name
[name_len
] = 0;
6382 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
6383 /* caller ensures that ea_value_len is less than 64K but
6384 we need to ensure that it fits within the smb */
6386 /*BB add length check to see if it would fit in
6387 negotiated SMB buffer size BB */
6388 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
6390 memcpy(parm_data
->list
[0].name
+name_len
+1,
6391 ea_value
, ea_value_len
);
6393 pSMB
->TotalDataCount
= pSMB
->DataCount
;
6394 pSMB
->ParameterCount
= cpu_to_le16(params
);
6395 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
6396 pSMB
->Reserved4
= 0;
6397 inc_rfc1001_len(pSMB
, byte_count
);
6398 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
6399 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6400 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
6402 cFYI(1, "SetPathInfo (EA) returned %d", rc
);
6404 cifs_buf_release(pSMB
);
6413 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */
6415 * Years ago the kernel added a "dnotify" function for Samba server,
6416 * to allow network clients (such as Windows) to display updated
6417 * lists of files in directory listings automatically when
6418 * files are added by one user when another user has the
6419 * same directory open on their desktop. The Linux cifs kernel
6420 * client hooked into the kernel side of this interface for
6421 * the same reason, but ironically when the VFS moved from
6422 * "dnotify" to "inotify" it became harder to plug in Linux
6423 * network file system clients (the most obvious use case
6424 * for notify interfaces is when multiple users can update
6425 * the contents of the same directory - exactly what network
6426 * file systems can do) although the server (Samba) could
6427 * still use it. For the short term we leave the worker
6428 * function ifdeffed out (below) until inotify is fixed
6429 * in the VFS to make it easier to plug in network file
6430 * system clients. If inotify turns out to be permanently
6431 * incompatible for network fs clients, we could instead simply
6432 * expose this config flag by adding a future cifs (and smb2) notify ioctl.
6434 int CIFSSMBNotify(const int xid
, struct cifs_tcon
*tcon
,
6435 const int notify_subdirs
, const __u16 netfid
,
6436 __u32 filter
, struct file
*pfile
, int multishot
,
6437 const struct nls_table
*nls_codepage
)
6440 struct smb_com_transaction_change_notify_req
*pSMB
= NULL
;
6441 struct smb_com_ntransaction_change_notify_rsp
*pSMBr
= NULL
;
6442 struct dir_notify_req
*dnotify_req
;
6445 cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid
);
6446 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
6451 pSMB
->TotalParameterCount
= 0 ;
6452 pSMB
->TotalDataCount
= 0;
6453 pSMB
->MaxParameterCount
= cpu_to_le32(2);
6454 pSMB
->MaxDataCount
= cpu_to_le32(CIFSMaxBufSize
& 0xFFFFFF00);
6455 pSMB
->MaxSetupCount
= 4;
6457 pSMB
->ParameterOffset
= 0;
6458 pSMB
->DataCount
= 0;
6459 pSMB
->DataOffset
= 0;
6460 pSMB
->SetupCount
= 4; /* single byte does not need le conversion */
6461 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE
);
6462 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
6464 pSMB
->WatchTree
= 1; /* one byte - no le conversion needed */
6465 pSMB
->Reserved2
= 0;
6466 pSMB
->CompletionFilter
= cpu_to_le32(filter
);
6467 pSMB
->Fid
= netfid
; /* file handle always le */
6468 pSMB
->ByteCount
= 0;
6470 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
6471 (struct smb_hdr
*)pSMBr
, &bytes_returned
,
6474 cFYI(1, "Error in Notify = %d", rc
);
6476 /* Add file to outstanding requests */
6477 /* BB change to kmem cache alloc */
6478 dnotify_req
= kmalloc(
6479 sizeof(struct dir_notify_req
),
6482 dnotify_req
->Pid
= pSMB
->hdr
.Pid
;
6483 dnotify_req
->PidHigh
= pSMB
->hdr
.PidHigh
;
6484 dnotify_req
->Mid
= pSMB
->hdr
.Mid
;
6485 dnotify_req
->Tid
= pSMB
->hdr
.Tid
;
6486 dnotify_req
->Uid
= pSMB
->hdr
.Uid
;
6487 dnotify_req
->netfid
= netfid
;
6488 dnotify_req
->pfile
= pfile
;
6489 dnotify_req
->filter
= filter
;
6490 dnotify_req
->multishot
= multishot
;
6491 spin_lock(&GlobalMid_Lock
);
6492 list_add_tail(&dnotify_req
->lhead
,
6493 &GlobalDnotifyReqList
);
6494 spin_unlock(&GlobalMid_Lock
);
6498 cifs_buf_release(pSMB
);
6501 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */