4 * Copyright (C) International Business Machines Corp., 2002,2008
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 * Jeremy Allison (jra@samba.org)
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 * the GNU Lesser General Public License for more details.
23 #include <linux/in6.h>
24 #include <linux/slab.h>
25 #include <linux/workqueue.h>
26 #include "cifs_fs_sb.h"
28 #include <crypto/internal/hash.h>
29 #include <linux/scatterlist.h>
32 * The sizes of various internal tables and strings
34 #define MAX_UID_INFO 16
35 #define MAX_SES_INFO 2
36 #define MAX_TCON_INFO 4
38 #define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1)
39 #define MAX_SERVER_SIZE 15
40 #define MAX_SHARE_SIZE 80
41 #define MAX_USERNAME_SIZE 256 /* reasonable maximum for current servers */
42 #define MAX_PASSWORD_SIZE 512 /* max for windows seems to be 256 wide chars */
44 #define CIFS_MIN_RCV_POOL 4
47 * default attribute cache timeout (jiffies)
49 #define CIFS_DEF_ACTIMEO (1 * HZ)
52 * max attribute cache timeout (jiffies) - 2^30
54 #define CIFS_MAX_ACTIMEO (1 << 30)
57 * MAX_REQ is the maximum number of requests that WE will send
58 * on one socket concurrently.
60 #define CIFS_MAX_REQ 32767
62 #define RFC1001_NAME_LEN 15
63 #define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
65 /* currently length of NIP6_FMT */
66 #define SERVER_NAME_LENGTH 40
67 #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
69 /* used to define string lengths for reversing unicode strings */
71 /* (max path length + 1 for null) * 2 for unicode */
76 #ifndef XATTR_DOS_ATTRIB
77 #define XATTR_DOS_ATTRIB "user.DOSATTRIB"
81 * CIFS vfs client Status information (based on what we know.)
84 /* associated with each tcp and smb session */
94 LANMAN
= 0, /* Legacy LANMAN auth */
95 NTLM
, /* Legacy NTLM012 auth with NTLM hash */
96 NTLMv2
, /* Legacy NTLM auth with NTLMv2 hash */
97 RawNTLMSSP
, /* NTLMSSP without SPNEGO, NTLMv2 hash */
98 /* NTLMSSP, */ /* can use rawNTLMSSP instead of NTLMSSP via SPNEGO */
99 Kerberos
, /* Kerberos via SPNEGO */
105 /* Netbios frames protocol not supported at this time */
113 /* crypto security descriptor definition */
115 struct shash_desc shash
;
119 /* crypto hashing related structure/fields, not specific to a sec mech */
120 struct cifs_secmech
{
121 struct crypto_shash
*hmacmd5
; /* hmac-md5 hash function */
122 struct crypto_shash
*md5
; /* md5 hash function */
123 struct sdesc
*sdeschmacmd5
; /* ctxt to generate ntlmv2 hash, CR1 */
124 struct sdesc
*sdescmd5
; /* ctxt to generate cifs/smb signature */
127 /* per smb session structure/fields */
128 struct ntlmssp_auth
{
129 __u32 client_flags
; /* sent by client in type 1 ntlmsssp exchange */
130 __u32 server_flags
; /* sent by server in type 2 ntlmssp exchange */
131 unsigned char ciphertext
[CIFS_CPHTXT_SIZE
]; /* sent to server */
132 char cryptkey
[CIFS_CRYPTO_KEY_SIZE
]; /* used by ntlmssp */
140 struct cifs_sid osid
;
141 struct cifs_sid gsid
;
142 struct cifs_ntace
*ntaces
;
143 struct cifs_ace
*aces
;
147 *****************************************************************
148 * Except the CIFS PDUs themselves all the
149 * globally interesting structs should go here
150 *****************************************************************
159 struct TCP_Server_Info
;
163 struct smb_version_operations
{
164 int (*send_cancel
)(struct TCP_Server_Info
*, void *,
165 struct mid_q_entry
*);
166 bool (*compare_fids
)(struct cifsFileInfo
*, struct cifsFileInfo
*);
167 /* setup request: allocate mid, sign message */
168 int (*setup_request
)(struct cifs_ses
*, struct kvec
*, unsigned int,
169 struct mid_q_entry
**);
170 /* check response: verify signature, map error */
171 int (*check_receive
)(struct mid_q_entry
*, struct TCP_Server_Info
*,
173 void (*add_credits
)(struct TCP_Server_Info
*, const unsigned int);
174 void (*set_credits
)(struct TCP_Server_Info
*, const int);
175 int * (*get_credits_field
)(struct TCP_Server_Info
*);
176 /* data offset from read response message */
177 unsigned int (*read_data_offset
)(char *);
178 /* data length from read response message */
179 unsigned int (*read_data_length
)(char *);
180 /* map smb to linux error */
181 int (*map_error
)(char *, bool);
182 /* find mid corresponding to the response message */
183 struct mid_q_entry
* (*find_mid
)(struct TCP_Server_Info
*, char *);
184 void (*dump_detail
)(void *);
185 /* verify the message */
186 int (*check_message
)(char *, unsigned int);
187 bool (*is_oplock_break
)(char *, struct TCP_Server_Info
*);
190 struct smb_version_values
{
191 char *version_string
;
192 __u32 large_lock_type
;
193 __u32 exclusive_lock_type
;
194 __u32 shared_lock_type
;
195 __u32 unlock_lock_type
;
197 size_t max_header_size
;
198 size_t read_rsp_size
;
201 #define HEADER_SIZE(server) (server->vals->header_size)
202 #define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
210 char *iocharset
; /* local code page for mapping to and from Unicode */
211 char source_rfc1001_name
[RFC1001_NAME_LEN_WITH_NULL
]; /* clnt nb name */
212 char target_rfc1001_name
[RFC1001_NAME_LEN_WITH_NULL
]; /* srvr nb name */
228 bool no_psx_acl
:1; /* set if posix acl support should be disabled */
230 bool backupuid_specified
; /* mount option backupuid is specified */
231 bool backupgid_specified
; /* mount option backupgid is specified */
232 bool no_xattr
:1; /* set if xattr (EA) support should be disabled*/
233 bool server_ino
:1; /* use inode numbers from server ie UniqueId */
235 bool strict_io
:1; /* strict cache behavior */
236 bool remap
:1; /* set to remap seven reserved chars in filenames */
237 bool posix_paths
:1; /* unset to not ask for posix pathnames. */
240 bool nullauth
:1; /* attempt to authenticate with null user */
241 bool nocase
:1; /* request case insensitive filenames */
242 bool nobrl
:1; /* disable sending byte range locks to srv */
243 bool mand_lock
:1; /* send mandatory not posix byte range lock reqs */
244 bool seal
:1; /* request transport encryption on share */
245 bool nodfs
:1; /* Do not request DFS, even if available */
246 bool local_lease
:1; /* check leases only on local system, not remote */
249 bool nostrictsync
:1; /* do not force expensive SMBflush on every sync */
250 bool fsc
:1; /* enable fscache */
251 bool mfsymlinks
:1; /* use Minshall+French Symlinks */
253 bool rwpidforward
:1; /* pid forward for read/write operations */
256 bool sockopt_tcp_nodelay
:1;
257 unsigned short int port
;
258 unsigned long actimeo
; /* attribute cache timeout (jiffies) */
259 struct smb_version_operations
*ops
;
260 struct smb_version_values
*vals
;
262 struct sockaddr_storage srcaddr
; /* allow binding to a local IP */
263 struct nls_table
*local_nls
;
266 #define CIFS_MOUNT_MASK (CIFS_MOUNT_NO_PERM | CIFS_MOUNT_SET_UID | \
267 CIFS_MOUNT_SERVER_INUM | CIFS_MOUNT_DIRECT_IO | \
268 CIFS_MOUNT_NO_XATTR | CIFS_MOUNT_MAP_SPECIAL_CHR | \
269 CIFS_MOUNT_UNX_EMUL | CIFS_MOUNT_NO_BRL | \
270 CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_OVERR_UID | \
271 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \
272 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \
273 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \
274 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \
275 CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)
277 #define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \
278 MS_NODEV | MS_SYNCHRONOUS)
280 struct cifs_mnt_data
{
281 struct cifs_sb_info
*cifs_sb
;
286 static inline unsigned int
287 get_rfc1002_length(void *buf
)
289 return be32_to_cpu(*((__be32
*)buf
));
292 struct TCP_Server_Info
{
293 struct list_head tcp_ses_list
;
294 struct list_head smb_ses_list
;
295 int srv_count
; /* reference counter */
296 /* 15 character server name + 0x20 16th byte indicating type = srv */
297 char server_RFC1001_name
[RFC1001_NAME_LEN_WITH_NULL
];
298 struct smb_version_operations
*ops
;
299 struct smb_version_values
*vals
;
300 enum statusEnum tcpStatus
; /* what we think the status is */
301 char *hostname
; /* hostname portion of UNC string */
302 struct socket
*ssocket
;
303 struct sockaddr_storage dstaddr
;
304 struct sockaddr_storage srcaddr
; /* locally bind to this IP */
308 wait_queue_head_t response_q
;
309 wait_queue_head_t request_q
; /* if more than maxmpx to srvr must block*/
310 struct list_head pending_mid_q
;
311 bool noblocksnd
; /* use blocking sendmsg */
312 bool noautotune
; /* do not autotune send buf sizes */
314 int credits
; /* send no more requests at once */
315 unsigned int in_flight
; /* number of requests on the wire to server */
316 spinlock_t req_lock
; /* protect the two values above */
317 struct mutex srv_mutex
;
318 struct task_struct
*tsk
;
319 char server_GUID
[16];
321 bool session_estab
; /* mark when very first sess is established */
322 u16 dialect
; /* dialect index that server chose */
323 enum securityEnum secType
;
324 bool oplocks
:1; /* enable oplocks */
325 unsigned int maxReq
; /* Clients should submit no more */
326 /* than maxReq distinct unanswered SMBs to the server when using */
327 /* multiplexed reads or writes */
328 unsigned int maxBuf
; /* maxBuf specifies the maximum */
329 /* message size the server can send or receive for non-raw SMBs */
330 /* maxBuf is returned by SMB NegotiateProtocol so maxBuf is only 0 */
331 /* when socket is setup (and during reconnect) before NegProt sent */
332 unsigned int max_rw
; /* maxRw specifies the maximum */
333 /* message size the server can send or receive for */
334 /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
335 unsigned int max_vcs
; /* maximum number of smb sessions, at least
336 those that can be specified uniquely with
338 int capabilities
; /* allow selective disabling of caps by smb sess */
339 int timeAdj
; /* Adjust for difference in server time zone in sec */
340 __u64 CurrentMid
; /* multiplex id - rotating counter */
341 char cryptkey
[CIFS_CRYPTO_KEY_SIZE
]; /* used by ntlm, ntlmv2 etc */
342 /* 16th byte of RFC1001 workstation name is always null */
343 char workstation_RFC1001_name
[RFC1001_NAME_LEN_WITH_NULL
];
344 __u32 sequence_number
; /* for signing, protected by srv_mutex */
345 struct session_key session_key
;
346 unsigned long lstrp
; /* when we got last response from this server */
347 struct cifs_secmech secmech
; /* crypto sec mech functs, descriptors */
348 /* extended security flavors that server supports */
349 bool sec_ntlmssp
; /* supports NTLMSSP */
350 bool sec_kerberosu2u
; /* supports U2U Kerberos */
351 bool sec_kerberos
; /* supports plain Kerberos */
352 bool sec_mskerberos
; /* supports legacy MS Kerberos */
353 bool large_buf
; /* is current buffer large? */
354 struct delayed_work echo
; /* echo ping workqueue job */
355 struct kvec
*iov
; /* reusable kvec array for receives */
356 unsigned int nr_iov
; /* number of kvecs in array */
357 char *smallbuf
; /* pointer to current "small" buffer */
358 char *bigbuf
; /* pointer to current "big" buffer */
359 unsigned int total_read
; /* total amount of data read in this pass */
360 #ifdef CONFIG_CIFS_FSCACHE
361 struct fscache_cookie
*fscache
; /* client index cache cookie */
363 #ifdef CONFIG_CIFS_STATS2
364 atomic_t in_send
; /* requests trying to send */
365 atomic_t num_waiters
; /* blocked waiting to get in sendrecv */
369 static inline unsigned int
370 in_flight(struct TCP_Server_Info
*server
)
373 spin_lock(&server
->req_lock
);
374 num
= server
->in_flight
;
375 spin_unlock(&server
->req_lock
);
380 has_credits(struct TCP_Server_Info
*server
, int *credits
)
383 spin_lock(&server
->req_lock
);
385 spin_unlock(&server
->req_lock
);
390 add_credits(struct TCP_Server_Info
*server
, const unsigned int add
)
392 server
->ops
->add_credits(server
, add
);
396 set_credits(struct TCP_Server_Info
*server
, const int val
)
398 server
->ops
->set_credits(server
, val
);
402 * Macros to allow the TCP_Server_Info->net field and related code to drop out
403 * when CONFIG_NET_NS isn't set.
408 static inline struct net
*cifs_net_ns(struct TCP_Server_Info
*srv
)
413 static inline void cifs_set_net_ns(struct TCP_Server_Info
*srv
, struct net
*net
)
420 static inline struct net
*cifs_net_ns(struct TCP_Server_Info
*srv
)
425 static inline void cifs_set_net_ns(struct TCP_Server_Info
*srv
, struct net
*net
)
432 * Session structure. One of these for each uid session with a particular host
435 struct list_head smb_ses_list
;
436 struct list_head tcon_list
;
437 struct mutex session_mutex
;
438 struct TCP_Server_Info
*server
; /* pointer to server info */
439 int ses_count
; /* reference counter */
440 enum statusEnum status
;
441 unsigned overrideSecFlg
; /* if non-zero override global sec flags */
442 __u16 ipc_tid
; /* special tid for connection to IPC share */
445 char *serverOS
; /* name of operating system underlying server */
446 char *serverNOS
; /* name of network operating system of server */
447 char *serverDomain
; /* security realm of server */
448 int Suid
; /* remote smb uid */
449 uid_t linux_uid
; /* overriding owner of files on the mount */
450 uid_t cred_uid
; /* owner of credentials */
452 char serverName
[SERVER_NAME_LEN_WITH_NULL
* 2]; /* BB make bigger for
453 TCP names - will ipv6 and sctp addresses fit? */
454 char *user_name
; /* must not be null except during init of sess
455 and after mount option parsing we fill it */
458 struct session_key auth_key
;
459 struct ntlmssp_auth
*ntlmssp
; /* ciphertext, flags, server challenge */
460 bool need_reconnect
:1; /* connection reset, uid now invalid */
462 /* no more than one of the following three session flags may be set */
463 #define CIFS_SES_NT4 1
464 #define CIFS_SES_OS2 2
465 #define CIFS_SES_W9X 4
466 /* following flag is set for old servers such as OS2 (and Win95?)
467 which do not negotiate NTLM or POSIX dialects, but instead
468 negotiate one of the older LANMAN dialects */
469 #define CIFS_SES_LANMAN 8
471 * there is one of these for each connection to a resource on a particular
475 struct list_head tcon_list
;
477 struct list_head openFileList
;
478 struct cifs_ses
*ses
; /* pointer to session associated with */
479 char treeName
[MAX_TREE_SIZE
+ 1]; /* UNC name of resource in ASCII */
480 char *nativeFileSystem
;
481 char *password
; /* for share-level security */
482 __u16 tid
; /* The 2 byte tree id */
483 __u16 Flags
; /* optional support bits */
484 enum statusEnum tidStatus
;
485 #ifdef CONFIG_CIFS_STATS
486 atomic_t num_smbs_sent
;
489 atomic_t num_flushes
;
490 atomic_t num_oplock_brks
;
493 atomic_t num_deletes
;
495 atomic_t num_posixopens
;
496 atomic_t num_posixmkdirs
;
498 atomic_t num_renames
;
499 atomic_t num_t2renames
;
503 atomic_t num_hardlinks
;
504 atomic_t num_symlinks
;
506 atomic_t num_acl_get
;
507 atomic_t num_acl_set
;
508 #ifdef CONFIG_CIFS_STATS2
509 unsigned long long time_writes
;
510 unsigned long long time_reads
;
511 unsigned long long time_opens
;
512 unsigned long long time_deletes
;
513 unsigned long long time_closes
;
514 unsigned long long time_mkdirs
;
515 unsigned long long time_rmdirs
;
516 unsigned long long time_renames
;
517 unsigned long long time_t2renames
;
518 unsigned long long time_ffirst
;
519 unsigned long long time_fnext
;
520 unsigned long long time_fclose
;
521 #endif /* CONFIG_CIFS_STATS2 */
524 spinlock_t stat_lock
;
525 #endif /* CONFIG_CIFS_STATS */
526 FILE_SYSTEM_DEVICE_INFO fsDevInfo
;
527 FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo
; /* ok if fs name truncated */
528 FILE_SYSTEM_UNIX_INFO fsUnixInfo
;
529 bool ipc
:1; /* set if connection to IPC$ eg for RPC/PIPES */
532 bool seal
:1; /* transport encryption for this mounted share */
533 bool unix_ext
:1; /* if false disable Linux extensions to CIFS protocol
534 for this mount even if server would support */
535 bool local_lease
:1; /* check leases (only) on local system not remote */
536 bool broken_posix_open
; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
537 bool need_reconnect
:1; /* connection reset, tid now invalid */
538 #ifdef CONFIG_CIFS_FSCACHE
539 u64 resource_id
; /* server resource id */
540 struct fscache_cookie
*fscache
; /* cookie for share */
542 /* BB add field for back pointer to sb struct(s)? */
546 * This is a refcounted and timestamped container for a tcon pointer. The
547 * container holds a tcon reference. It is considered safe to free one of
548 * these when the tl_count goes to 0. The tl_time is the time of the last
549 * "get" on the container.
552 struct rb_node tl_rbnode
;
554 unsigned long tl_flags
;
555 #define TCON_LINK_MASTER 0
556 #define TCON_LINK_PENDING 1
557 #define TCON_LINK_IN_TREE 2
558 unsigned long tl_time
;
560 struct cifs_tcon
*tl_tcon
;
563 extern struct tcon_link
*cifs_sb_tlink(struct cifs_sb_info
*cifs_sb
);
565 static inline struct cifs_tcon
*
566 tlink_tcon(struct tcon_link
*tlink
)
568 return tlink
->tl_tcon
;
571 extern void cifs_put_tlink(struct tcon_link
*tlink
);
573 static inline struct tcon_link
*
574 cifs_get_tlink(struct tcon_link
*tlink
)
576 if (tlink
&& !IS_ERR(tlink
))
577 atomic_inc(&tlink
->tl_count
);
581 /* This function is always expected to succeed */
582 extern struct cifs_tcon
*cifs_sb_master_tcon(struct cifs_sb_info
*cifs_sb
);
585 * This info hangs off the cifsFileInfo structure, pointed to by llist.
586 * This is used to track byte stream locks on the file
588 struct cifsLockInfo
{
589 struct list_head llist
; /* pointer to next cifsLockInfo */
590 struct list_head blist
; /* pointer to locks blocked on this */
591 wait_queue_head_t block_q
;
599 * One of these for each open instance of a file
601 struct cifs_search_info
{
602 loff_t index_of_last_entry
;
603 __u16 entries_in_buffer
;
606 char *ntwrk_buf_start
;
607 char *srch_entries_start
;
609 const char *presume_name
;
610 unsigned int resume_name_len
;
614 bool smallBuf
:1; /* so we know which buf_release function to call */
617 struct cifsFileInfo
{
618 struct list_head tlist
; /* pointer to next fid owned by tcon */
619 struct list_head flist
; /* next fid (file instance) for this inode */
620 struct list_head llist
; /*
621 * brlocks held by this fid, protected by
622 * lock_mutex from cifsInodeInfo structure
624 unsigned int uid
; /* allows finding which FileInfo structure */
625 __u32 pid
; /* process id who opened file */
626 __u16 netfid
; /* file id from remote */
627 /* BB add lock scope info here if needed */ ;
628 /* lock scope id (0 if none) */
629 struct dentry
*dentry
;
630 unsigned int f_flags
;
631 struct tcon_link
*tlink
;
632 bool invalidHandle
:1; /* file closed via session abend */
633 bool oplock_break_cancelled
:1;
634 int count
; /* refcount protected by cifs_file_list_lock */
635 struct mutex fh_mutex
; /* prevents reopen race after dead ses*/
636 struct cifs_search_info srch_inf
;
637 struct work_struct oplock_break
; /* work for oplock breaks */
640 struct cifs_io_parms
{
645 struct cifs_tcon
*tcon
;
649 * Take a reference on the file private data. Must be called with
650 * cifs_file_list_lock held.
653 struct cifsFileInfo
*cifsFileInfo_get(struct cifsFileInfo
*cifs_file
)
659 void cifsFileInfo_put(struct cifsFileInfo
*cifs_file
);
662 * One of these for each file inode
665 struct cifsInodeInfo
{
666 bool can_cache_brlcks
;
667 struct mutex lock_mutex
; /*
668 * protect the field above and llist
669 * from every cifsFileInfo structure
672 /* BB add in lists for dirty pages i.e. write caching info for oplock */
673 struct list_head openFileList
;
674 __u32 cifsAttrs
; /* e.g. DOS archive bit, sparse, compressed, system */
675 bool clientCanCacheRead
; /* read oplock */
676 bool clientCanCacheAll
; /* read and writebehind oplock */
677 bool delete_pending
; /* DELETE_ON_CLOSE is set */
678 bool invalid_mapping
; /* pagecache is invalid */
679 unsigned long time
; /* jiffies of last update of inode */
680 u64 server_eof
; /* current file size on server -- protected by i_lock */
681 u64 uniqueid
; /* server inode number */
682 u64 createtime
; /* creation time on server */
683 #ifdef CONFIG_CIFS_FSCACHE
684 struct fscache_cookie
*fscache
;
686 struct inode vfs_inode
;
689 static inline struct cifsInodeInfo
*
690 CIFS_I(struct inode
*inode
)
692 return container_of(inode
, struct cifsInodeInfo
, vfs_inode
);
695 static inline struct cifs_sb_info
*
696 CIFS_SB(struct super_block
*sb
)
698 return sb
->s_fs_info
;
701 static inline char CIFS_DIR_SEP(const struct cifs_sb_info
*cifs_sb
)
703 if (cifs_sb
->mnt_cifs_flags
& CIFS_MOUNT_POSIX_PATHS
)
710 convert_delimiter(char *path
, char delim
)
723 for (i
= 0; path
[i
] != '\0'; i
++) {
724 if (path
[i
] == old_delim
)
729 #ifdef CONFIG_CIFS_STATS
730 #define cifs_stats_inc atomic_inc
732 static inline void cifs_stats_bytes_written(struct cifs_tcon
*tcon
,
736 spin_lock(&tcon
->stat_lock
);
737 tcon
->bytes_written
+= bytes
;
738 spin_unlock(&tcon
->stat_lock
);
742 static inline void cifs_stats_bytes_read(struct cifs_tcon
*tcon
,
745 spin_lock(&tcon
->stat_lock
);
746 tcon
->bytes_read
+= bytes
;
747 spin_unlock(&tcon
->stat_lock
);
751 #define cifs_stats_inc(field) do {} while (0)
752 #define cifs_stats_bytes_written(tcon, bytes) do {} while (0)
753 #define cifs_stats_bytes_read(tcon, bytes) do {} while (0)
759 * This is the prototype for the mid receive function. This function is for
760 * receiving the rest of the SMB frame, starting with the WordCount (which is
761 * just after the MID in struct smb_hdr). Note:
763 * - This will be called by cifsd, with no locks held.
764 * - The mid will still be on the pending_mid_q.
765 * - mid->resp_buf will point to the current buffer.
767 * Returns zero on a successful receive, or an error. The receive state in
768 * the TCP_Server_Info will also be updated.
770 typedef int (mid_receive_t
)(struct TCP_Server_Info
*server
,
771 struct mid_q_entry
*mid
);
774 * This is the prototype for the mid callback function. This is called once the
775 * mid has been received off of the socket. When creating one, take special
776 * care to avoid deadlocks. Things to bear in mind:
778 * - it will be called by cifsd, with no locks held
779 * - the mid will be removed from any lists
781 typedef void (mid_callback_t
)(struct mid_q_entry
*mid
);
783 /* one of these for every pending CIFS request to the server */
785 struct list_head qhead
; /* mids waiting on reply from this server */
786 __u64 mid
; /* multiplex id */
787 __u32 pid
; /* process id */
788 __u32 sequence_number
; /* for CIFS signing */
789 unsigned long when_alloc
; /* when mid was created */
790 #ifdef CONFIG_CIFS_STATS2
791 unsigned long when_sent
; /* time when smb send finished */
792 unsigned long when_received
; /* when demux complete (taken off wire) */
794 mid_receive_t
*receive
; /* call receive callback */
795 mid_callback_t
*callback
; /* call completion callback */
796 void *callback_data
; /* general purpose pointer for callback */
797 void *resp_buf
; /* pointer to received SMB header */
798 int mid_state
; /* wish this were enum but can not pass to wait_event */
799 __le16 command
; /* smb command code */
800 bool large_buf
:1; /* if valid response, is pointer to large buf */
801 bool multiRsp
:1; /* multiple trans2 responses for one request */
802 bool multiEnd
:1; /* both received */
805 /* Make code in transport.c a little cleaner by moving
806 update of optional stats into function below */
807 #ifdef CONFIG_CIFS_STATS2
809 static inline void cifs_in_send_inc(struct TCP_Server_Info
*server
)
811 atomic_inc(&server
->in_send
);
814 static inline void cifs_in_send_dec(struct TCP_Server_Info
*server
)
816 atomic_dec(&server
->in_send
);
819 static inline void cifs_num_waiters_inc(struct TCP_Server_Info
*server
)
821 atomic_inc(&server
->num_waiters
);
824 static inline void cifs_num_waiters_dec(struct TCP_Server_Info
*server
)
826 atomic_dec(&server
->num_waiters
);
829 static inline void cifs_save_when_sent(struct mid_q_entry
*mid
)
831 mid
->when_sent
= jiffies
;
834 static inline void cifs_in_send_inc(struct TCP_Server_Info
*server
)
837 static inline void cifs_in_send_dec(struct TCP_Server_Info
*server
)
841 static inline void cifs_num_waiters_inc(struct TCP_Server_Info
*server
)
845 static inline void cifs_num_waiters_dec(struct TCP_Server_Info
*server
)
849 static inline void cifs_save_when_sent(struct mid_q_entry
*mid
)
854 /* for pending dnotify requests */
855 struct dir_notify_req
{
856 struct list_head lhead
;
863 __u32 filter
; /* CompletionFilter (for multishot) */
868 struct dfs_info3_param
{
869 int flags
; /* DFSREF_REFERRAL_SERVER, DFSREF_STORAGE_SERVER*/
878 * common struct for holding inode info when searching for or updating an
879 * inode with new info
882 #define CIFS_FATTR_DFS_REFERRAL 0x1
883 #define CIFS_FATTR_DELETE_PENDING 0x2
884 #define CIFS_FATTR_NEED_REVAL 0x4
885 #define CIFS_FATTR_INO_COLLISION 0x8
898 unsigned int cf_nlink
;
899 unsigned int cf_dtype
;
900 struct timespec cf_atime
;
901 struct timespec cf_mtime
;
902 struct timespec cf_ctime
;
905 static inline void free_dfs_info_param(struct dfs_info3_param
*param
)
908 kfree(param
->path_name
);
909 kfree(param
->node_name
);
914 static inline void free_dfs_info_array(struct dfs_info3_param
*param
,
918 if ((number_of_items
== 0) || (param
== NULL
))
920 for (i
= 0; i
< number_of_items
; i
++) {
921 kfree(param
[i
].path_name
);
922 kfree(param
[i
].node_name
);
928 #define MID_REQUEST_ALLOCATED 1
929 #define MID_REQUEST_SUBMITTED 2
930 #define MID_RESPONSE_RECEIVED 4
931 #define MID_RETRY_NEEDED 8 /* session closed while this request out */
932 #define MID_RESPONSE_MALFORMED 0x10
933 #define MID_SHUTDOWN 0x20
935 /* Types of response buffer returned from SendReceive2 */
936 #define CIFS_NO_BUFFER 0 /* Response buffer not returned */
937 #define CIFS_SMALL_BUFFER 1
938 #define CIFS_LARGE_BUFFER 2
939 #define CIFS_IOVEC 4 /* array of response buffers */
941 /* Type of Request to SendReceive2 */
942 #define CIFS_BLOCKING_OP 1 /* operation can block */
943 #define CIFS_ASYNC_OP 2 /* do not wait for response */
944 #define CIFS_TIMEOUT_MASK 0x003 /* only one of above set in req */
945 #define CIFS_LOG_ERROR 0x010 /* log NT STATUS if non-zero */
946 #define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */
947 #define CIFS_NO_RESP 0x040 /* no response buffer required */
949 /* Security Flags: indicate type of session setup needed */
950 #define CIFSSEC_MAY_SIGN 0x00001
951 #define CIFSSEC_MAY_NTLM 0x00002
952 #define CIFSSEC_MAY_NTLMV2 0x00004
953 #define CIFSSEC_MAY_KRB5 0x00008
954 #ifdef CONFIG_CIFS_WEAK_PW_HASH
955 #define CIFSSEC_MAY_LANMAN 0x00010
956 #define CIFSSEC_MAY_PLNTXT 0x00020
958 #define CIFSSEC_MAY_LANMAN 0
959 #define CIFSSEC_MAY_PLNTXT 0
960 #endif /* weak passwords */
961 #define CIFSSEC_MAY_SEAL 0x00040 /* not supported yet */
962 #define CIFSSEC_MAY_NTLMSSP 0x00080 /* raw ntlmssp with ntlmv2 */
964 #define CIFSSEC_MUST_SIGN 0x01001
965 /* note that only one of the following can be set so the
966 result of setting MUST flags more than once will be to
967 require use of the stronger protocol */
968 #define CIFSSEC_MUST_NTLM 0x02002
969 #define CIFSSEC_MUST_NTLMV2 0x04004
970 #define CIFSSEC_MUST_KRB5 0x08008
971 #ifdef CONFIG_CIFS_WEAK_PW_HASH
972 #define CIFSSEC_MUST_LANMAN 0x10010
973 #define CIFSSEC_MUST_PLNTXT 0x20020
974 #ifdef CONFIG_CIFS_UPCALL
975 #define CIFSSEC_MASK 0xBF0BF /* allows weak security but also krb5 */
977 #define CIFSSEC_MASK 0xB70B7 /* current flags supported if weak */
979 #else /* do not allow weak pw hash */
980 #define CIFSSEC_MUST_LANMAN 0
981 #define CIFSSEC_MUST_PLNTXT 0
982 #ifdef CONFIG_CIFS_UPCALL
983 #define CIFSSEC_MASK 0x8F08F /* flags supported if no weak allowed */
985 #define CIFSSEC_MASK 0x87087 /* flags supported if no weak allowed */
987 #endif /* WEAK_PW_HASH */
988 #define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */
989 #define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */
991 #define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2)
992 #define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2)
993 #define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
995 *****************************************************************
996 * All constants go here
997 *****************************************************************
1000 #define UID_HASH (16)
1003 * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
1004 * following to be declared.
1007 /****************************************************************************
1008 * Locking notes. All updates to global variables and lists should be
1009 * protected by spinlocks or semaphores.
1013 * GlobalMid_Lock protects:
1014 * list operations on pending_mid_q and oplockQ
1015 * updates to XID counters, multiplex id and SMB sequence numbers
1016 * cifs_file_list_lock protects:
1017 * list operations on tcp and SMB session lists and tCon lists
1018 * f_owner.lock protects certain per file struct operations
1019 * mapping->page_lock protects certain per page operations
1023 * sesSem operations on smb session
1024 * tconSem operations on tree connection
1025 * fh_sem file handle reconnection operations
1027 ****************************************************************************/
1029 #ifdef DECLARE_GLOBALS_HERE
1030 #define GLOBAL_EXTERN
1032 #define GLOBAL_EXTERN extern
1036 * the list of TCP_Server_Info structures, ie each of the sockets
1037 * connecting our client to a distinct server (ip address), is
1038 * chained together by cifs_tcp_ses_list. The list of all our SMB
1039 * sessions (and from that the tree connections) can be found
1040 * by iterating over cifs_tcp_ses_list
1042 GLOBAL_EXTERN
struct list_head cifs_tcp_ses_list
;
1045 * This lock protects the cifs_tcp_ses_list, the list of smb sessions per
1046 * tcp session, and the list of tcon's per smb session. It also protects
1047 * the reference counters for the server, smb session, and tcon. Finally,
1048 * changes to the tcon->tidStatus should be done while holding this lock.
1050 GLOBAL_EXTERN spinlock_t cifs_tcp_ses_lock
;
1053 * This lock protects the cifs_file->llist and cifs_file->flist
1054 * list operations, and updates to some flags (cifs_file->invalidHandle)
1055 * It will be moved to either use the tcon->stat_lock or equivalent later.
1056 * If cifs_tcp_ses_lock and the lock below are both needed to be held, then
1057 * the cifs_tcp_ses_lock must be grabbed first and released last.
1059 GLOBAL_EXTERN spinlock_t cifs_file_list_lock
;
1061 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1062 /* Outstanding dir notify requests */
1063 GLOBAL_EXTERN
struct list_head GlobalDnotifyReqList
;
1064 /* DirNotify response queue */
1065 GLOBAL_EXTERN
struct list_head GlobalDnotifyRsp_Q
;
1066 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1069 * Global transaction id (XID) information
1071 GLOBAL_EXTERN
unsigned int GlobalCurrentXid
; /* protected by GlobalMid_Sem */
1072 GLOBAL_EXTERN
unsigned int GlobalTotalActiveXid
; /* prot by GlobalMid_Sem */
1073 GLOBAL_EXTERN
unsigned int GlobalMaxActiveXid
; /* prot by GlobalMid_Sem */
1074 GLOBAL_EXTERN spinlock_t GlobalMid_Lock
; /* protects above & list operations */
1075 /* on midQ entries */
1077 * Global counters, updated atomically
1079 GLOBAL_EXTERN atomic_t sesInfoAllocCount
;
1080 GLOBAL_EXTERN atomic_t tconInfoAllocCount
;
1081 GLOBAL_EXTERN atomic_t tcpSesAllocCount
;
1082 GLOBAL_EXTERN atomic_t tcpSesReconnectCount
;
1083 GLOBAL_EXTERN atomic_t tconInfoReconnectCount
;
1085 /* Various Debug counters */
1086 GLOBAL_EXTERN atomic_t bufAllocCount
; /* current number allocated */
1087 #ifdef CONFIG_CIFS_STATS2
1088 GLOBAL_EXTERN atomic_t totBufAllocCount
; /* total allocated over all time */
1089 GLOBAL_EXTERN atomic_t totSmBufAllocCount
;
1091 GLOBAL_EXTERN atomic_t smBufAllocCount
;
1092 GLOBAL_EXTERN atomic_t midCount
;
1095 GLOBAL_EXTERN
bool enable_oplocks
; /* enable or disable oplocks */
1096 GLOBAL_EXTERN
unsigned int lookupCacheEnabled
;
1097 GLOBAL_EXTERN
unsigned int global_secflags
; /* if on, session setup sent
1098 with more secure ntlmssp2 challenge/resp */
1099 GLOBAL_EXTERN
unsigned int sign_CIFS_PDUs
; /* enable smb packet signing */
1100 GLOBAL_EXTERN
unsigned int linuxExtEnabled
;/*enable Linux/Unix CIFS extensions*/
1101 GLOBAL_EXTERN
unsigned int CIFSMaxBufSize
; /* max size not including hdr */
1102 GLOBAL_EXTERN
unsigned int cifs_min_rcv
; /* min size of big ntwrk buf pool */
1103 GLOBAL_EXTERN
unsigned int cifs_min_small
; /* min size of small buf pool */
1104 GLOBAL_EXTERN
unsigned int cifs_max_pending
; /* MAX requests at once to server*/
1106 #ifdef CONFIG_CIFS_ACL
1107 GLOBAL_EXTERN
struct rb_root uidtree
;
1108 GLOBAL_EXTERN
struct rb_root gidtree
;
1109 GLOBAL_EXTERN spinlock_t siduidlock
;
1110 GLOBAL_EXTERN spinlock_t sidgidlock
;
1111 GLOBAL_EXTERN
struct rb_root siduidtree
;
1112 GLOBAL_EXTERN
struct rb_root sidgidtree
;
1113 GLOBAL_EXTERN spinlock_t uidsidlock
;
1114 GLOBAL_EXTERN spinlock_t gidsidlock
;
1115 #endif /* CONFIG_CIFS_ACL */
1117 void cifs_oplock_break(struct work_struct
*work
);
1119 extern const struct slow_work_ops cifs_oplock_break_ops
;
1120 extern struct workqueue_struct
*cifsiod_wq
;
1122 /* Operations for different SMB versions */
1123 #define SMB1_VERSION_STRING "1.0"
1124 extern struct smb_version_operations smb1_operations
;
1125 extern struct smb_version_values smb1_values
;
1126 #define SMB21_VERSION_STRING "2.1"
1127 extern struct smb_version_operations smb21_operations
;
1128 extern struct smb_version_values smb21_values
;
1129 #endif /* _CIFS_GLOB_H */