58
58
extern mempool_t *cifs_req_poolp;
66
char *iocharset; /* local code page for mapping to and from Unicode */
67
char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
68
char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
82
bool no_psx_acl:1; /* set if posix acl support should be disabled */
84
bool no_xattr:1; /* set if xattr (EA) support should be disabled*/
85
bool server_ino:1; /* use inode numbers from server ie UniqueId */
87
bool strict_io:1; /* strict cache behavior */
88
bool remap:1; /* set to remap seven reserved chars in filenames */
89
bool posix_paths:1; /* unset to not ask for posix pathnames. */
92
bool nullauth:1; /* attempt to authenticate with null user */
93
bool nocase:1; /* request case insensitive filenames */
94
bool nobrl:1; /* disable sending byte range locks to srv */
95
bool mand_lock:1; /* send mandatory not posix byte range lock reqs */
96
bool seal:1; /* request transport encryption on share */
97
bool nodfs:1; /* Do not request DFS, even if available */
98
bool local_lease:1; /* check leases only on local system, not remote */
101
bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
102
bool fsc:1; /* enable fscache */
103
bool mfsymlinks:1; /* use Minshall+French Symlinks */
107
bool sockopt_tcp_nodelay:1;
108
unsigned short int port;
109
unsigned long actimeo; /* attribute cache timeout (jiffies) */
111
struct sockaddr_storage srcaddr; /* allow binding to a local IP */
112
struct nls_table *local_nls;
115
60
/* FIXME: should these be tunable? */
116
61
#define TLINK_ERROR_EXPIRE (1 * HZ)
117
62
#define TLINK_IDLE_EXPIRE (600 * HZ)
188
136
mutex_unlock(&server->srv_mutex);
190
138
/* mark submitted MIDs for retry and issue callback */
191
cFYI(1, "%s: issuing mid callbacks", __func__);
139
INIT_LIST_HEAD(&retry_list);
140
cFYI(1, "%s: moving mids to private list", __func__);
192
141
spin_lock(&GlobalMid_Lock);
193
142
list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
194
143
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
195
144
if (mid_entry->midState == MID_REQUEST_SUBMITTED)
196
145
mid_entry->midState = MID_RETRY_NEEDED;
146
list_move(&mid_entry->qhead, &retry_list);
148
spin_unlock(&GlobalMid_Lock);
150
cFYI(1, "%s: issuing mid callbacks", __func__);
151
list_for_each_safe(tmp, tmp2, &retry_list) {
152
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
197
153
list_del_init(&mid_entry->qhead);
198
154
mid_entry->callback(mid_entry);
200
spin_unlock(&GlobalMid_Lock);
202
while ((server->tcpStatus != CifsExiting) &&
203
(server->tcpStatus != CifsGood)) {
206
160
/* we should try only the port we connected to before */
248
202
total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
249
203
data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
251
remaining = total_data_size - data_in_this_rsp;
205
if (total_data_size == data_in_this_rsp)
255
else if (remaining < 0) {
207
else if (total_data_size < data_in_this_rsp) {
256
208
cFYI(1, "total data %d smaller than data in frame %d",
257
209
total_data_size, data_in_this_rsp);
260
cFYI(1, "missing %d bytes from transact2, check next response",
262
if (total_data_size > maxBufSize) {
263
cERROR(1, "TotalDataSize %d is over maximum buffer %d",
264
total_data_size, maxBufSize);
213
remaining = total_data_size - data_in_this_rsp;
215
cFYI(1, "missing %d bytes from transact2, check next response",
217
if (total_data_size > maxBufSize) {
218
cERROR(1, "TotalDataSize %d is over maximum buffer %d",
219
total_data_size, maxBufSize);
271
225
static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
309
264
data_area_of_target += total_in_buf;
311
266
/* copy second buffer into end of first buffer */
312
memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
313
267
total_in_buf += total_in_buf2;
268
/* is the result too big for the field? */
269
if (total_in_buf > USHRT_MAX)
314
271
put_unaligned_le16(total_in_buf, &pSMBt->t2_rsp.DataCount);
315
byte_count = get_bcc_le(pTargetSMB);
316
byte_count += total_in_buf2;
317
put_bcc_le(byte_count, pTargetSMB);
319
byte_count = pTargetSMB->smb_buf_length;
320
byte_count += total_in_buf2;
322
/* BB also add check that we are not beyond maximum buffer size */
324
pTargetSMB->smb_buf_length = byte_count;
274
byte_count = get_bcc(pTargetSMB);
275
byte_count += total_in_buf2;
276
/* is the result too big for the field? */
277
if (byte_count > USHRT_MAX)
279
put_bcc(byte_count, pTargetSMB);
281
byte_count = be32_to_cpu(pTargetSMB->smb_buf_length);
282
byte_count += total_in_buf2;
283
/* don't allow buffer to overflow */
284
if (byte_count > CIFSMaxBufSize)
286
pTargetSMB->smb_buf_length = cpu_to_be32(byte_count);
288
memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
326
290
if (remaining == total_in_buf2) {
327
291
cFYI(1, "found the last secondary response");
608
571
list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
609
572
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
611
if ((mid_entry->mid == smb_buffer->Mid) &&
612
(mid_entry->midState == MID_REQUEST_SUBMITTED) &&
613
(mid_entry->command == smb_buffer->Command)) {
615
check2ndT2(smb_buffer, server->maxBuf) > 0) {
616
/* We have a multipart transact2 resp */
618
if (mid_entry->resp_buf) {
619
/* merge response - fix up 1st*/
620
if (coalesce_t2(smb_buffer,
621
mid_entry->resp_buf)) {
622
mid_entry->multiRsp =
626
/* all parts received */
627
mid_entry->multiEnd =
633
cERROR(1, "1st trans2 resp needs bigbuf");
634
/* BB maybe we can fix this up, switch
635
to already allocated large buffer? */
637
/* Have first buffer */
638
mid_entry->resp_buf =
640
mid_entry->largeBuf =
574
if (mid_entry->mid != smb_buffer->Mid ||
575
mid_entry->midState != MID_REQUEST_SUBMITTED ||
576
mid_entry->command != smb_buffer->Command) {
582
check2ndT2(smb_buffer, server->maxBuf) > 0) {
583
/* We have a multipart transact2 resp */
585
if (mid_entry->resp_buf) {
586
/* merge response - fix up 1st*/
587
length = coalesce_t2(smb_buffer,
588
mid_entry->resp_buf);
591
mid_entry->multiRsp = true;
594
/* all parts received or
595
* packet is malformed
597
mid_entry->multiEnd = true;
603
* FIXME: switch to already
604
* allocated largebuf?
606
cERROR(1, "1st trans2 resp "
609
/* Have first buffer */
610
mid_entry->resp_buf =
612
mid_entry->largeBuf = true;
647
mid_entry->resp_buf = smb_buffer;
648
mid_entry->largeBuf = isLargeBuf;
618
mid_entry->resp_buf = smb_buffer;
619
mid_entry->largeBuf = isLargeBuf;
651
mid_entry->midState =
652
MID_RESPONSE_RECEIVED;
654
mid_entry->midState =
655
MID_RESPONSE_MALFORMED;
622
mid_entry->midState = MID_RESPONSE_RECEIVED;
624
mid_entry->midState = MID_RESPONSE_MALFORMED;
656
625
#ifdef CONFIG_CIFS_STATS2
657
mid_entry->when_received = jiffies;
626
mid_entry->when_received = jiffies;
659
list_del_init(&mid_entry->qhead);
660
mid_entry->callback(mid_entry);
628
list_del_init(&mid_entry->qhead);
665
631
spin_unlock(&GlobalMid_Lock);
667
633
if (mid_entry != NULL) {
634
mid_entry->callback(mid_entry);
668
635
/* Was previous buf put in mpx struct for multi-rsp? */
669
636
if (!isMultiRsp) {
670
637
/* smb buffer will be freed by user thread */
722
689
sock_release(csocket);
723
690
server->ssocket = NULL;
725
/* buffer usuallly freed in free_mid - need to free it here on exit */
692
/* buffer usually freed in free_mid - need to free it here on exit */
726
693
cifs_buf_release(bigbuf);
727
694
if (smallbuf) /* no sense logging a debug message if NULL */
728
695
cifs_small_buf_release(smallbuf);
730
697
if (!list_empty(&server->pending_mid_q)) {
698
struct list_head dispose_list;
700
INIT_LIST_HEAD(&dispose_list);
731
701
spin_lock(&GlobalMid_Lock);
732
702
list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
733
703
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
734
cFYI(1, "Clearing Mid 0x%x - issuing callback",
704
cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
705
mid_entry->midState = MID_SHUTDOWN;
706
list_move(&mid_entry->qhead, &dispose_list);
708
spin_unlock(&GlobalMid_Lock);
710
/* now walk dispose list and issue callbacks */
711
list_for_each_safe(tmp, tmp2, &dispose_list) {
712
mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
713
cFYI(1, "Callback mid 0x%x", mid_entry->mid);
736
714
list_del_init(&mid_entry->qhead);
737
715
mid_entry->callback(mid_entry);
739
spin_unlock(&GlobalMid_Lock);
740
717
/* 1/8th of sec is more than enough time for them to exit */
1043
1047
printk(KERN_WARNING
1044
1048
"CIFS: UNC Path does not begin "
1045
1049
"with // or \\\\ \n");
1050
goto cifs_parse_mount_err;
1049
1053
printk(KERN_WARNING "CIFS: UNC name too long\n");
1054
goto cifs_parse_mount_err;
1052
1056
} else if ((strnicmp(data, "domain", 3) == 0)
1053
1057
|| (strnicmp(data, "workgroup", 5) == 0)) {
1054
1058
if (!value || !*value) {
1055
1059
printk(KERN_WARNING "CIFS: invalid domain name\n");
1056
return 1; /* needs_arg; */
1060
goto cifs_parse_mount_err;
1058
1062
/* BB are there cases in which a comma can be valid in
1059
1063
a domain name and need special handling? */
1060
1064
if (strnlen(value, 256) < 256) {
1061
vol->domainname = value;
1065
vol->domainname = kstrdup(value, GFP_KERNEL);
1066
if (!vol->domainname) {
1067
printk(KERN_WARNING "CIFS: no memory "
1068
"for domainname\n");
1069
goto cifs_parse_mount_err;
1062
1071
cFYI(1, "Domain name set");
1064
1073
printk(KERN_WARNING "CIFS: domain name too "
1075
goto cifs_parse_mount_err;
1068
1077
} else if (strnicmp(data, "srcaddr", 7) == 0) {
1069
1078
vol->srcaddr.ss_family = AF_UNSPEC;
1101
1110
cFYI(1, "prefix path %s", vol->prepath);
1103
1112
printk(KERN_WARNING "CIFS: prefix too long\n");
1113
goto cifs_parse_mount_err;
1106
1115
} else if (strnicmp(data, "iocharset", 9) == 0) {
1107
1116
if (!value || !*value) {
1108
1117
printk(KERN_WARNING "CIFS: invalid iocharset "
1109
1118
"specified\n");
1110
return 1; /* needs_arg; */
1119
goto cifs_parse_mount_err;
1112
1121
if (strnlen(value, 65) < 65) {
1113
if (strnicmp(value, "default", 7))
1114
vol->iocharset = value;
1122
if (strnicmp(value, "default", 7)) {
1123
vol->iocharset = kstrdup(value,
1126
if (!vol->iocharset) {
1127
printk(KERN_WARNING "CIFS: no "
1130
goto cifs_parse_mount_err;
1115
1133
/* if iocharset not set then load_nls_default
1116
1134
is used by caller */
1117
1135
cFYI(1, "iocharset set to %s", value);
1119
1137
printk(KERN_WARNING "CIFS: iocharset name "
1120
1138
"too long.\n");
1139
goto cifs_parse_mount_err;
1123
1141
} else if (!strnicmp(data, "uid", 3) && value && *value) {
1124
1142
vol->linux_uid = simple_strtoul(value, &value, 0);
1794
1829
return ERR_PTR(rc);
1797
static struct cifsSesInfo *
1832
static int match_session(struct cifs_ses *ses, struct smb_vol *vol)
1834
switch (ses->server->secType) {
1836
if (vol->cred_uid != ses->cred_uid)
1840
/* anything else takes username/password */
1841
if (ses->user_name == NULL)
1843
if (strncmp(ses->user_name, vol->username,
1846
if (strlen(vol->username) != 0 &&
1847
ses->password != NULL &&
1848
strncmp(ses->password,
1849
vol->password ? vol->password : "",
1856
static struct cifs_ses *
1798
1857
cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
1800
struct cifsSesInfo *ses;
1859
struct cifs_ses *ses;
1802
1861
spin_lock(&cifs_tcp_ses_lock);
1803
1862
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
1804
switch (server->secType) {
1806
if (vol->cred_uid != ses->cred_uid)
1810
/* anything else takes username/password */
1811
if (strncmp(ses->userName, vol->username,
1814
if (strlen(vol->username) != 0 &&
1815
ses->password != NULL &&
1816
strncmp(ses->password,
1817
vol->password ? vol->password : "",
1863
if (!match_session(ses, vol))
1821
1865
++ses->ses_count;
1822
1866
spin_unlock(&cifs_tcp_ses_lock);
1947
2004
return ERR_PTR(rc);
1950
static struct cifsTconInfo *
1951
cifs_find_tcon(struct cifsSesInfo *ses, const char *unc)
2007
static int match_tcon(struct cifs_tcon *tcon, const char *unc)
2009
if (tcon->tidStatus == CifsExiting)
2011
if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE))
2016
static struct cifs_tcon *
2017
cifs_find_tcon(struct cifs_ses *ses, const char *unc)
1953
2019
struct list_head *tmp;
1954
struct cifsTconInfo *tcon;
2020
struct cifs_tcon *tcon;
1956
2022
spin_lock(&cifs_tcp_ses_lock);
1957
2023
list_for_each(tmp, &ses->tcon_list) {
1958
tcon = list_entry(tmp, struct cifsTconInfo, tcon_list);
1959
if (tcon->tidStatus == CifsExiting)
1961
if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE))
2024
tcon = list_entry(tmp, struct cifs_tcon, tcon_list);
2025
if (!match_tcon(tcon, unc))
1964
2027
++tcon->tc_count;
1965
2028
spin_unlock(&cifs_tcp_ses_lock);
2091
get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path,
2153
static inline struct tcon_link *
2154
cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
2156
return cifs_sb->master_tlink;
2160
compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data)
2162
struct cifs_sb_info *old = CIFS_SB(sb);
2163
struct cifs_sb_info *new = mnt_data->cifs_sb;
2165
if ((sb->s_flags & CIFS_MS_MASK) != (mnt_data->flags & CIFS_MS_MASK))
2168
if ((old->mnt_cifs_flags & CIFS_MOUNT_MASK) !=
2169
(new->mnt_cifs_flags & CIFS_MOUNT_MASK))
2172
if (old->rsize != new->rsize)
2176
* We want to share sb only if we don't specify wsize or specified wsize
2177
* is greater or equal than existing one.
2179
if (new->wsize && new->wsize < old->wsize)
2182
if (old->mnt_uid != new->mnt_uid || old->mnt_gid != new->mnt_gid)
2185
if (old->mnt_file_mode != new->mnt_file_mode ||
2186
old->mnt_dir_mode != new->mnt_dir_mode)
2189
if (strcmp(old->local_nls->charset, new->local_nls->charset))
2192
if (old->actimeo != new->actimeo)
2199
cifs_match_super(struct super_block *sb, void *data)
2201
struct cifs_mnt_data *mnt_data = (struct cifs_mnt_data *)data;
2202
struct smb_vol *volume_info;
2203
struct cifs_sb_info *cifs_sb;
2204
struct TCP_Server_Info *tcp_srv;
2205
struct cifs_ses *ses;
2206
struct cifs_tcon *tcon;
2207
struct tcon_link *tlink;
2208
struct sockaddr_storage addr;
2211
memset(&addr, 0, sizeof(struct sockaddr_storage));
2213
spin_lock(&cifs_tcp_ses_lock);
2214
cifs_sb = CIFS_SB(sb);
2215
tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
2216
if (IS_ERR(tlink)) {
2217
spin_unlock(&cifs_tcp_ses_lock);
2220
tcon = tlink_tcon(tlink);
2222
tcp_srv = ses->server;
2224
volume_info = mnt_data->vol;
2226
if (!volume_info->UNCip || !volume_info->UNC)
2229
rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
2231
strlen(volume_info->UNCip),
2236
if (!match_server(tcp_srv, (struct sockaddr *)&addr, volume_info) ||
2237
!match_session(ses, volume_info) ||
2238
!match_tcon(tcon, volume_info->UNC)) {
2243
rc = compare_mount_options(sb, mnt_data);
2245
spin_unlock(&cifs_tcp_ses_lock);
2246
cifs_put_tlink(tlink);
2251
get_dfs_path(int xid, struct cifs_ses *pSesInfo, const char *old_path,
2092
2252
const struct nls_table *nls_codepage, unsigned int *pnum_referrals,
2093
2253
struct dfs_info3_param **preferrals, int remap)
2597
if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)
2598
cERROR(1, "per-share encryption not supported yet");
2437
2600
cap &= CIFS_UNIX_CAP_MASK;
2438
2601
if (vol_info && vol_info->no_psx_acl)
2439
2602
cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
2440
2603
else if (CIFS_UNIX_POSIX_ACL_CAP & cap) {
2441
2604
cFYI(1, "negotiated posix acl support");
2443
sb->s_flags |= MS_POSIXACL;
2606
cifs_sb->mnt_cifs_flags |=
2607
CIFS_MOUNT_POSIXACL;
2446
2610
if (vol_info && vol_info->posix_paths == 0)
2447
2611
cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP;
2448
2612
else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
2449
2613
cFYI(1, "negotiate posix pathnames");
2451
CIFS_SB(sb)->mnt_cifs_flags |=
2615
cifs_sb->mnt_cifs_flags |=
2452
2616
CIFS_MOUNT_POSIX_PATHS;
2455
/* We might be setting the path sep back to a different
2456
form if we are reconnecting and the server switched its
2457
posix path capability for this share */
2458
if (sb && (CIFS_SB(sb)->prepathlen > 0))
2459
CIFS_SB(sb)->prepath[0] = CIFS_DIR_SEP(CIFS_SB(sb));
2461
if (sb && (CIFS_SB(sb)->rsize > 127 * 1024)) {
2619
if (cifs_sb && (cifs_sb->rsize > 127 * 1024)) {
2462
2620
if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) {
2463
CIFS_SB(sb)->rsize = 127 * 1024;
2621
cifs_sb->rsize = 127 * 1024;
2464
2622
cFYI(DBG2, "larger reads not supported by srv");
2533
2678
else /* default */
2534
2679
cifs_sb->rsize = CIFSMaxBufSize;
2536
if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
2537
cERROR(1, "wsize %d too large, using 4096 instead",
2538
pvolume_info->wsize);
2539
cifs_sb->wsize = 4096;
2540
} else if (pvolume_info->wsize)
2541
cifs_sb->wsize = pvolume_info->wsize;
2543
cifs_sb->wsize = min_t(const int,
2544
PAGEVEC_SIZE * PAGE_CACHE_SIZE,
2546
/* old default of CIFSMaxBufSize was too small now
2547
that SMB Write2 can send multiple pages in kvec.
2548
RFC1001 does not describe what happens when frame
2549
bigger than 128K is sent so use that as max in
2550
conjunction with 52K kvec constraint on arch with 4K
2553
2681
if (cifs_sb->rsize < 2048) {
2554
2682
cifs_sb->rsize = 2048;
2555
2683
/* Windows ME may prefer this */
2556
2684
cFYI(1, "readsize set to minimum: 2048");
2558
/* calculate prepath */
2559
cifs_sb->prepath = pvolume_info->prepath;
2560
if (cifs_sb->prepath) {
2561
cifs_sb->prepathlen = strlen(cifs_sb->prepath);
2562
/* we can not convert the / to \ in the path
2563
separators in the prefixpath yet because we do not
2564
know (until reset_cifs_unix_caps is called later)
2565
whether POSIX PATH CAP is available. We normalize
2566
the / to \ after reset_cifs_unix_caps is called */
2567
pvolume_info->prepath = NULL;
2569
cifs_sb->prepathlen = 0;
2688
* Temporarily set wsize for matching superblock. If we end up using
2689
* new sb then cifs_negotiate_wsize will later negotiate it downward
2692
cifs_sb->wsize = pvolume_info->wsize;
2570
2694
cifs_sb->mnt_uid = pvolume_info->linux_uid;
2571
2695
cifs_sb->mnt_gid = pvolume_info->linux_gid;
2572
2696
cifs_sb->mnt_file_mode = pvolume_info->file_mode;
2627
2754
"mount option supported");
2758
* When the server supports very large writes via POSIX extensions, we can
2759
* allow up to 2^24-1, minus the size of a WRITE_AND_X header, not including
2760
* the RFC1001 length.
2762
* Note that this might make for "interesting" allocation problems during
2763
* writeback however as we have to allocate an array of pointers for the
2764
* pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096.
2766
#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4)
2769
* When the server doesn't allow large posix writes, only allow a wsize of
2770
* 128k minus the size of the WRITE_AND_X header. That allows for a write up
2771
* to the maximum size described by RFC1002.
2773
#define CIFS_MAX_RFC1002_WSIZE (128 * 1024 - sizeof(WRITE_REQ) + 4)
2776
* The default wsize is 1M. find_get_pages seems to return a maximum of 256
2777
* pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill
2778
* a single wsize request with a single call.
2780
#define CIFS_DEFAULT_WSIZE (1024 * 1024)
2783
cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)
2785
__u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
2786
struct TCP_Server_Info *server = tcon->ses->server;
2787
unsigned int wsize = pvolume_info->wsize ? pvolume_info->wsize :
2790
/* can server support 24-bit write sizes? (via UNIX extensions) */
2791
if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
2792
wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE);
2795
* no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set?
2796
* Limit it to max buffer offered by the server, minus the size of the
2797
* WRITEX header, not including the 4 byte RFC1001 length.
2799
if (!(server->capabilities & CAP_LARGE_WRITE_X) ||
2800
(!(server->capabilities & CAP_UNIX) &&
2801
(server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED))))
2802
wsize = min_t(unsigned int, wsize,
2803
server->maxBuf - sizeof(WRITE_REQ) + 4);
2805
/* hard limit of CIFS_MAX_WSIZE */
2806
wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
2631
is_path_accessible(int xid, struct cifsTconInfo *tcon,
2812
is_path_accessible(int xid, struct cifs_tcon *tcon,
2632
2813
struct cifs_sb_info *cifs_sb, const char *full_path)
2642
2823
0 /* not legacy */, cifs_sb->local_nls,
2643
2824
cifs_sb->mnt_cifs_flags &
2644
2825
CIFS_MOUNT_MAP_SPECIAL_CHR);
2827
if (rc == -EOPNOTSUPP || rc == -EINVAL)
2828
rc = SMBQueryInformation(xid, tcon, full_path, pfile_info,
2829
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
2830
CIFS_MOUNT_MAP_SPECIAL_CHR);
2645
2831
kfree(pfile_info);
2650
cleanup_volume_info(struct smb_vol **pvolume_info)
2836
cleanup_volume_info_contents(struct smb_vol *volume_info)
2652
struct smb_vol *volume_info;
2654
if (!pvolume_info || !*pvolume_info)
2657
volume_info = *pvolume_info;
2838
kfree(volume_info->username);
2658
2839
kzfree(volume_info->password);
2659
2840
kfree(volume_info->UNC);
2841
kfree(volume_info->UNCip);
2842
kfree(volume_info->domainname);
2843
kfree(volume_info->iocharset);
2660
2844
kfree(volume_info->prepath);
2848
cifs_cleanup_volume_info(struct smb_vol *volume_info)
2852
cleanup_volume_info_contents(volume_info);
2661
2853
kfree(volume_info);
2662
*pvolume_info = NULL;
2666
2857
#ifdef CONFIG_CIFS_DFS_UPCALL
2667
2858
/* build_path_to_root returns full path to root when
2668
2859
* we do not have an exiting connection (tcon) */
2670
build_unc_path_to_root(const struct smb_vol *volume_info,
2861
build_unc_path_to_root(const struct smb_vol *vol,
2671
2862
const struct cifs_sb_info *cifs_sb)
2864
char *full_path, *pos;
2865
unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
2866
unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
2675
int unc_len = strnlen(volume_info->UNC, MAX_TREE_SIZE + 1);
2676
full_path = kmalloc(unc_len + cifs_sb->prepathlen + 1, GFP_KERNEL);
2868
full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
2677
2869
if (full_path == NULL)
2678
2870
return ERR_PTR(-ENOMEM);
2680
strncpy(full_path, volume_info->UNC, unc_len);
2681
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
2683
for (i = 0; i < unc_len; i++) {
2684
if (full_path[i] == '\\')
2872
strncpy(full_path, vol->UNC, unc_len);
2873
pos = full_path + unc_len;
2876
strncpy(pos, vol->prepath, pplen);
2689
if (cifs_sb->prepathlen)
2690
strncpy(full_path + unc_len, cifs_sb->prepath,
2691
cifs_sb->prepathlen);
2693
full_path[unc_len + cifs_sb->prepathlen] = 0; /* add trailing null */
2880
*pos = '\0'; /* add trailing null */
2881
convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
2882
cFYI(1, "%s: full_path=%s", __func__, full_path);
2694
2883
return full_path;
2699
cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2700
char *mount_data_global, const char *devname)
2887
* Perform a dfs referral query for a share and (optionally) prefix
2889
* If a referral is found, cifs_sb->mountdata will be (re-)allocated
2890
* to a string containing updated options for the submount. Otherwise it
2891
* will be left untouched.
2893
* Returns the rc from get_dfs_path to the caller, which can be used to
2894
* determine whether there were referrals.
2897
expand_dfs_referral(int xid, struct cifs_ses *pSesInfo,
2898
struct smb_vol *volume_info, struct cifs_sb_info *cifs_sb,
2704
struct smb_vol *volume_info;
2705
struct cifsSesInfo *pSesInfo;
2706
struct cifsTconInfo *tcon;
2707
struct TCP_Server_Info *srvTcp;
2709
char *mount_data = mount_data_global;
2710
struct tcon_link *tlink;
2711
#ifdef CONFIG_CIFS_DFS_UPCALL
2902
unsigned int num_referrals = 0;
2712
2903
struct dfs_info3_param *referrals = NULL;
2713
unsigned int num_referrals = 0;
2714
int referral_walks_count = 0;
2904
char *full_path = NULL, *ref_path = NULL, *mdata = NULL;
2906
full_path = build_unc_path_to_root(volume_info, cifs_sb);
2907
if (IS_ERR(full_path))
2908
return PTR_ERR(full_path);
2910
/* For DFS paths, skip the first '\' of the UNC */
2911
ref_path = check_prefix ? full_path + 1 : volume_info->UNC + 1;
2913
rc = get_dfs_path(xid, pSesInfo , ref_path, cifs_sb->local_nls,
2914
&num_referrals, &referrals,
2915
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
2917
if (!rc && num_referrals > 0) {
2918
char *fake_devname = NULL;
2920
mdata = cifs_compose_mount_options(cifs_sb->mountdata,
2921
full_path + 1, referrals,
2924
free_dfs_info_array(referrals, num_referrals);
2926
if (IS_ERR(mdata)) {
2927
rc = PTR_ERR(mdata);
2930
cleanup_volume_info_contents(volume_info);
2931
memset(volume_info, '\0', sizeof(*volume_info));
2932
rc = cifs_setup_volume_info(volume_info, mdata,
2935
kfree(fake_devname);
2936
kfree(cifs_sb->mountdata);
2937
cifs_sb->mountdata = mdata;
2726
volume_info = kzalloc(sizeof(struct smb_vol), GFP_KERNEL);
2732
if (cifs_parse_mount_options(mount_data, devname, volume_info)) {
2945
cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
2946
const char *devname)
2950
if (cifs_parse_mount_options(mount_data, devname, volume_info))
2737
2953
if (volume_info->nullauth) {
2738
2954
cFYI(1, "null user");
2739
volume_info->username = "";
2955
volume_info->username = kzalloc(1, GFP_KERNEL);
2956
if (volume_info->username == NULL)
2740
2958
} else if (volume_info->username) {
2741
2959
/* BB fixme parse for domain name here */
2742
2960
cFYI(1, "Username: %s", volume_info->username);
2757
2974
if (volume_info->local_nls == NULL) {
2758
2975
cERROR(1, "CIFS mount error: iocharset %s not found",
2759
2976
volume_info->iocharset);
2764
cifs_sb->local_nls = volume_info->local_nls;
2985
cifs_get_volume_info(char *mount_data, const char *devname)
2988
struct smb_vol *volume_info;
2990
volume_info = kzalloc(sizeof(struct smb_vol), GFP_KERNEL);
2992
return ERR_PTR(-ENOMEM);
2994
rc = cifs_setup_volume_info(volume_info, mount_data, devname);
2996
cifs_cleanup_volume_info(volume_info);
2997
volume_info = ERR_PTR(rc);
3004
cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
3008
struct cifs_ses *pSesInfo;
3009
struct cifs_tcon *tcon;
3010
struct TCP_Server_Info *srvTcp;
3012
struct tcon_link *tlink;
3013
#ifdef CONFIG_CIFS_DFS_UPCALL
3014
int referral_walks_count = 0;
3017
rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY);
3021
cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages;
3023
#ifdef CONFIG_CIFS_DFS_UPCALL
3025
/* cleanup activities if we're chasing a referral */
3026
if (referral_walks_count) {
3028
cifs_put_tcon(tcon);
3030
cifs_put_smb_ses(pSesInfo);
2766
3043
/* get a reference to a tcp session */
2767
3044
srvTcp = cifs_get_tcp_session(volume_info);
2768
3045
if (IS_ERR(srvTcp)) {
2769
3046
rc = PTR_ERR(srvTcp);
3047
bdi_destroy(&cifs_sb->bdi);
2795
3064
goto remote_path_check;
3067
/* tell server which Unix caps we support */
3068
if (tcon->ses->capabilities & CAP_UNIX) {
3069
/* reset of caps checks mount to see if unix extensions
3070
disabled for just this mount */
3071
reset_cifs_unix_caps(xid, tcon, cifs_sb, volume_info);
3072
if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) &&
3073
(le64_to_cpu(tcon->fsUnixInfo.Capability) &
3074
CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)) {
3076
goto mount_fail_check;
3079
tcon->unix_ext = 0; /* server does not support them */
2798
3081
/* do not care if following two calls succeed - informational */
2799
3082
if (!tcon->ipc) {
2800
3083
CIFSSMBQFSDeviceInfo(xid, tcon);
2801
3084
CIFSSMBQFSAttributeInfo(xid, tcon);
2804
/* tell server which Unix caps we support */
2805
if (tcon->ses->capabilities & CAP_UNIX)
2806
/* reset of caps checks mount to see if unix extensions
2807
disabled for just this mount */
2808
reset_cifs_unix_caps(xid, tcon, sb, volume_info);
2810
tcon->unix_ext = 0; /* server does not support them */
2812
/* convert forward to back slashes in prepath here if needed */
2813
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0)
2814
convert_delimiter(cifs_sb->prepath, CIFS_DIR_SEP(cifs_sb));
2816
3087
if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) {
2817
3088
cifs_sb->rsize = 1024 * 127;
2818
3089
cFYI(DBG2, "no very large read support, rsize now 127K");
2820
if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
2821
cifs_sb->wsize = min(cifs_sb->wsize,
2822
(tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
2823
3091
if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
2824
3092
cifs_sb->rsize = min(cifs_sb->rsize,
2825
3093
(tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
3095
cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info);
2827
3097
remote_path_check:
2828
/* check if a whole path (including prepath) is not remote */
3098
#ifdef CONFIG_CIFS_DFS_UPCALL
3100
* Perform an unconditional check for whether there are DFS
3101
* referrals for this path without prefix, to provide support
3102
* for DFS referrals from w2k8 servers which don't seem to respond
3103
* with PATH_NOT_COVERED to requests that include the prefix.
3104
* Chase the referral if found, otherwise continue normally.
3106
if (referral_walks_count == 0) {
3107
int refrc = expand_dfs_referral(xid, pSesInfo, volume_info,
3110
referral_walks_count++;
3111
goto try_mount_again;
3116
/* check if a whole path is not remote */
2829
3117
if (!rc && tcon) {
2830
3118
/* build_path_to_root works only when we have a valid tcon */
2831
full_path = cifs_build_path_to_root(cifs_sb, tcon);
3119
full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
2832
3120
if (full_path == NULL) {
2834
3122
goto mount_fail_check;
2855
3143
goto mount_fail_check;
2857
/* convert forward to back slashes in prepath here if needed */
2858
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0)
2859
convert_delimiter(cifs_sb->prepath,
2860
CIFS_DIR_SEP(cifs_sb));
2861
full_path = build_unc_path_to_root(volume_info, cifs_sb);
2862
if (IS_ERR(full_path)) {
2863
rc = PTR_ERR(full_path);
2864
goto mount_fail_check;
2867
cFYI(1, "Getting referral for: %s", full_path);
2868
rc = get_dfs_path(xid, pSesInfo , full_path + 1,
2869
cifs_sb->local_nls, &num_referrals, &referrals,
2870
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
2871
if (!rc && num_referrals > 0) {
2872
char *fake_devname = NULL;
2874
if (mount_data != mount_data_global)
2877
mount_data = cifs_compose_mount_options(
2878
cifs_sb->mountdata, full_path + 1,
2879
referrals, &fake_devname);
2881
free_dfs_info_array(referrals, num_referrals);
2882
kfree(fake_devname);
2885
if (IS_ERR(mount_data)) {
2886
rc = PTR_ERR(mount_data);
2888
goto mount_fail_check;
2892
cifs_put_tcon(tcon);
2894
cifs_put_smb_ses(pSesInfo);
2896
cleanup_volume_info(&volume_info);
3146
rc = expand_dfs_referral(xid, pSesInfo, volume_info, cifs_sb,
2897
3150
referral_walks_count++;
2899
3151
goto try_mount_again;
3153
goto mount_fail_check;
2901
3154
#else /* No DFS support, return error on mount */
2902
3155
rc = -EOPNOTSUPP;