1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef _CIFS_GLOB_H
20#define _CIFS_GLOB_H
21
22#include <linux/in.h>
23#include <linux/in6.h>
24#include <linux/slab.h>
25#include <linux/mempool.h>
26#include <linux/workqueue.h>
27#include "cifs_fs_sb.h"
28#include "cifsacl.h"
29#include <crypto/internal/hash.h>
30#include <linux/scatterlist.h>
31#ifdef CONFIG_CIFS_SMB2
32#include "smb2pdu.h"
33#endif
34
35
36
37
38#define MAX_UID_INFO 16
39#define MAX_SES_INFO 2
40#define MAX_TCON_INFO 4
41
42#define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1)
43#define MAX_SERVER_SIZE 15
44#define MAX_SHARE_SIZE 80
45#define MAX_USERNAME_SIZE 256
46#define MAX_PASSWORD_SIZE 512
47
48#define CIFS_MIN_RCV_POOL 4
49
50#define MAX_REOPEN_ATT 5
51
52
53
54#define CIFS_DEF_ACTIMEO (1 * HZ)
55
56
57
58
59#define CIFS_MAX_ACTIMEO (1 << 30)
60
61
62
63
64
65#define CIFS_MAX_REQ 32767
66
67#define RFC1001_NAME_LEN 15
68#define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
69
70
71#define SERVER_NAME_LENGTH 40
72#define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
73
74
75
76
77#define MAX_NAME 514
78
79
80#define SMB_ECHO_INTERVAL (60 * HZ)
81
82#include "cifspdu.h"
83
84#ifndef XATTR_DOS_ATTRIB
85#define XATTR_DOS_ATTRIB "user.DOSATTRIB"
86#endif
87
88
89
90
91
92
93enum statusEnum {
94 CifsNew = 0,
95 CifsGood,
96 CifsExiting,
97 CifsNeedReconnect,
98 CifsNeedNegotiate
99};
100
101enum securityEnum {
102 LANMAN = 0,
103 NTLM,
104 NTLMv2,
105 RawNTLMSSP,
106
107 Kerberos,
108};
109
110enum protocolEnum {
111 TCP = 0,
112 SCTP
113
114};
115
116struct session_key {
117 unsigned int len;
118 char *response;
119};
120
121
122struct sdesc {
123 struct shash_desc shash;
124 char ctx[];
125};
126
127
128struct cifs_secmech {
129 struct crypto_shash *hmacmd5;
130 struct crypto_shash *md5;
131 struct sdesc *sdeschmacmd5;
132 struct sdesc *sdescmd5;
133};
134
135
136struct ntlmssp_auth {
137 __u32 client_flags;
138 __u32 server_flags;
139 unsigned char ciphertext[CIFS_CPHTXT_SIZE];
140 char cryptkey[CIFS_CRYPTO_KEY_SIZE];
141};
142
143struct cifs_cred {
144 int uid;
145 int gid;
146 int mode;
147 int cecount;
148 struct cifs_sid osid;
149 struct cifs_sid gsid;
150 struct cifs_ntace *ntaces;
151 struct cifs_ace *aces;
152};
153
154
155
156
157
158
159
160
161enum smb_version {
162 Smb_1 = 1,
163 Smb_21,
164};
165
166struct mid_q_entry;
167struct TCP_Server_Info;
168struct cifsFileInfo;
169struct cifs_ses;
170struct cifs_tcon;
171struct dfs_info3_param;
172struct cifs_fattr;
173struct smb_vol;
174
175struct smb_version_operations {
176 int (*send_cancel)(struct TCP_Server_Info *, void *,
177 struct mid_q_entry *);
178 bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
179
180 int (*setup_request)(struct cifs_ses *, struct kvec *, unsigned int,
181 struct mid_q_entry **);
182
183 int (*setup_async_request)(struct TCP_Server_Info *, struct kvec *,
184 unsigned int, struct mid_q_entry **);
185
186 int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *,
187 bool);
188 void (*add_credits)(struct TCP_Server_Info *, const unsigned int,
189 const int);
190 void (*set_credits)(struct TCP_Server_Info *, const int);
191 int * (*get_credits_field)(struct TCP_Server_Info *, const int);
192 unsigned int (*get_credits)(struct mid_q_entry *);
193 __u64 (*get_next_mid)(struct TCP_Server_Info *);
194
195 unsigned int (*read_data_offset)(char *);
196
197 unsigned int (*read_data_length)(char *);
198
199 int (*map_error)(char *, bool);
200
201 struct mid_q_entry * (*find_mid)(struct TCP_Server_Info *, char *);
202 void (*dump_detail)(void *);
203 void (*clear_stats)(struct cifs_tcon *);
204 void (*print_stats)(struct seq_file *m, struct cifs_tcon *);
205
206 int (*check_message)(char *, unsigned int);
207 bool (*is_oplock_break)(char *, struct TCP_Server_Info *);
208
209 bool (*check_trans2)(struct mid_q_entry *, struct TCP_Server_Info *,
210 char *, int);
211
212 bool (*need_neg)(struct TCP_Server_Info *);
213
214 int (*negotiate)(const unsigned int, struct cifs_ses *);
215
216 int (*sess_setup)(const unsigned int, struct cifs_ses *,
217 const struct nls_table *);
218
219 int (*logoff)(const unsigned int, struct cifs_ses *);
220
221 int (*tree_connect)(const unsigned int, struct cifs_ses *, const char *,
222 struct cifs_tcon *, const struct nls_table *);
223
224 int (*tree_disconnect)(const unsigned int, struct cifs_tcon *);
225
226 int (*get_dfs_refer)(const unsigned int, struct cifs_ses *,
227 const char *, struct dfs_info3_param **,
228 unsigned int *, const struct nls_table *, int);
229
230 void (*qfs_tcon)(const unsigned int, struct cifs_tcon *);
231
232 int (*is_path_accessible)(const unsigned int, struct cifs_tcon *,
233 struct cifs_sb_info *, const char *);
234
235 int (*query_path_info)(const unsigned int, struct cifs_tcon *,
236 struct cifs_sb_info *, const char *,
237 FILE_ALL_INFO *, bool *);
238
239 int (*get_srv_inum)(const unsigned int, struct cifs_tcon *,
240 struct cifs_sb_info *, const char *,
241 u64 *uniqueid, FILE_ALL_INFO *);
242
243 char * (*build_path_to_root)(struct smb_vol *, struct cifs_sb_info *,
244 struct cifs_tcon *);
245
246 bool (*can_echo)(struct TCP_Server_Info *);
247
248 int (*echo)(struct TCP_Server_Info *);
249
250 int (*mkdir)(const unsigned int, struct cifs_tcon *, const char *,
251 struct cifs_sb_info *);
252
253 void (*mkdir_setinfo)(struct inode *, const char *,
254 struct cifs_sb_info *, struct cifs_tcon *,
255 const unsigned int);
256
257 int (*rmdir)(const unsigned int, struct cifs_tcon *, const char *,
258 struct cifs_sb_info *);
259};
260
261struct smb_version_values {
262 char *version_string;
263 __u32 large_lock_type;
264 __u32 exclusive_lock_type;
265 __u32 shared_lock_type;
266 __u32 unlock_lock_type;
267 size_t header_size;
268 size_t max_header_size;
269 size_t read_rsp_size;
270 __le16 lock_cmd;
271 unsigned int cap_unix;
272 unsigned int cap_nt_find;
273 unsigned int cap_large_files;
274};
275
276#define HEADER_SIZE(server) (server->vals->header_size)
277#define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
278
279struct smb_vol {
280 char *username;
281 char *password;
282 char *domainname;
283 char *UNC;
284 char *UNCip;
285 char *iocharset;
286 char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL];
287 char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL];
288 uid_t cred_uid;
289 uid_t linux_uid;
290 gid_t linux_gid;
291 uid_t backupuid;
292 gid_t backupgid;
293 umode_t file_mode;
294 umode_t dir_mode;
295 unsigned secFlg;
296 bool retry:1;
297 bool intr:1;
298 bool setuids:1;
299 bool override_uid:1;
300 bool override_gid:1;
301 bool dynperm:1;
302 bool noperm:1;
303 bool no_psx_acl:1;
304 bool cifs_acl:1;
305 bool backupuid_specified;
306 bool backupgid_specified;
307 bool no_xattr:1;
308 bool server_ino:1;
309 bool direct_io:1;
310 bool strict_io:1;
311 bool remap:1;
312 bool posix_paths:1;
313 bool no_linux_ext:1;
314 bool sfu_emul:1;
315 bool nullauth:1;
316 bool nocase:1;
317 bool nobrl:1;
318 bool mand_lock:1;
319 bool seal:1;
320 bool nodfs:1;
321 bool local_lease:1;
322 bool noblocksnd:1;
323 bool noautotune:1;
324 bool nostrictsync:1;
325 bool fsc:1;
326 bool mfsymlinks:1;
327 bool multiuser:1;
328 bool rwpidforward:1;
329 unsigned int rsize;
330 unsigned int wsize;
331 bool sockopt_tcp_nodelay:1;
332 unsigned short int port;
333 unsigned long actimeo;
334 struct smb_version_operations *ops;
335 struct smb_version_values *vals;
336 char *prepath;
337 struct sockaddr_storage srcaddr;
338 struct nls_table *local_nls;
339};
340
341#define CIFS_MOUNT_MASK (CIFS_MOUNT_NO_PERM | CIFS_MOUNT_SET_UID | \
342 CIFS_MOUNT_SERVER_INUM | CIFS_MOUNT_DIRECT_IO | \
343 CIFS_MOUNT_NO_XATTR | CIFS_MOUNT_MAP_SPECIAL_CHR | \
344 CIFS_MOUNT_UNX_EMUL | CIFS_MOUNT_NO_BRL | \
345 CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_OVERR_UID | \
346 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \
347 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \
348 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \
349 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \
350 CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)
351
352#define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \
353 MS_NODEV | MS_SYNCHRONOUS)
354
355struct cifs_mnt_data {
356 struct cifs_sb_info *cifs_sb;
357 struct smb_vol *vol;
358 int flags;
359};
360
361static inline unsigned int
362get_rfc1002_length(void *buf)
363{
364 return be32_to_cpu(*((__be32 *)buf));
365}
366
367static inline void
368inc_rfc1001_len(void *buf, int count)
369{
370 be32_add_cpu((__be32 *)buf, count);
371}
372
373struct TCP_Server_Info {
374 struct list_head tcp_ses_list;
375 struct list_head smb_ses_list;
376 int srv_count;
377
378 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
379 struct smb_version_operations *ops;
380 struct smb_version_values *vals;
381 enum statusEnum tcpStatus;
382 char *hostname;
383 struct socket *ssocket;
384 struct sockaddr_storage dstaddr;
385 struct sockaddr_storage srcaddr;
386#ifdef CONFIG_NET_NS
387 struct net *net;
388#endif
389 wait_queue_head_t response_q;
390 wait_queue_head_t request_q;
391 struct list_head pending_mid_q;
392 bool noblocksnd;
393 bool noautotune;
394 bool tcp_nodelay;
395 int credits;
396 unsigned int in_flight;
397 spinlock_t req_lock;
398 struct mutex srv_mutex;
399 struct task_struct *tsk;
400 char server_GUID[16];
401 __u16 sec_mode;
402 bool session_estab;
403#ifdef CONFIG_CIFS_SMB2
404 int echo_credits;
405 int oplock_credits;
406 bool echoes:1;
407#endif
408 u16 dialect;
409 enum securityEnum secType;
410 bool oplocks:1;
411 unsigned int maxReq;
412
413
414 unsigned int maxBuf;
415
416
417
418 unsigned int max_rw;
419
420
421 unsigned int max_vcs;
422
423
424 unsigned int capabilities;
425 int timeAdj;
426 __u64 CurrentMid;
427 char cryptkey[CIFS_CRYPTO_KEY_SIZE];
428
429 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
430 __u32 sequence_number;
431 struct session_key session_key;
432 unsigned long lstrp;
433 struct cifs_secmech secmech;
434
435 bool sec_ntlmssp;
436 bool sec_kerberosu2u;
437 bool sec_kerberos;
438 bool sec_mskerberos;
439 bool large_buf;
440 struct delayed_work echo;
441 struct kvec *iov;
442 unsigned int nr_iov;
443 char *smallbuf;
444 char *bigbuf;
445 unsigned int total_read;
446#ifdef CONFIG_CIFS_FSCACHE
447 struct fscache_cookie *fscache;
448#endif
449#ifdef CONFIG_CIFS_STATS2
450 atomic_t in_send;
451 atomic_t num_waiters;
452#endif
453#ifdef CONFIG_CIFS_SMB2
454 unsigned int max_read;
455 unsigned int max_write;
456#endif
457};
458
459static inline unsigned int
460in_flight(struct TCP_Server_Info *server)
461{
462 unsigned int num;
463 spin_lock(&server->req_lock);
464 num = server->in_flight;
465 spin_unlock(&server->req_lock);
466 return num;
467}
468
469static inline bool
470has_credits(struct TCP_Server_Info *server, int *credits)
471{
472 int num;
473 spin_lock(&server->req_lock);
474 num = *credits;
475 spin_unlock(&server->req_lock);
476 return num > 0;
477}
478
479static inline void
480add_credits(struct TCP_Server_Info *server, const unsigned int add,
481 const int optype)
482{
483 server->ops->add_credits(server, add, optype);
484}
485
486static inline void
487set_credits(struct TCP_Server_Info *server, const int val)
488{
489 server->ops->set_credits(server, val);
490}
491
492static inline __u64
493get_next_mid(struct TCP_Server_Info *server)
494{
495 return server->ops->get_next_mid(server);
496}
497
498
499
500
501
502
503#ifdef CONFIG_NET_NS
504
505static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
506{
507 return srv->net;
508}
509
510static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
511{
512 srv->net = net;
513}
514
515#else
516
517static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
518{
519 return &init_net;
520}
521
522static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
523{
524}
525
526#endif
527
528
529
530
531struct cifs_ses {
532 struct list_head smb_ses_list;
533 struct list_head tcon_list;
534 struct mutex session_mutex;
535 struct TCP_Server_Info *server;
536 int ses_count;
537 enum statusEnum status;
538 unsigned overrideSecFlg;
539 __u16 ipc_tid;
540 __u16 flags;
541 __u16 vcnum;
542 char *serverOS;
543 char *serverNOS;
544 char *serverDomain;
545 __u64 Suid;
546 uid_t linux_uid;
547 uid_t cred_uid;
548 unsigned int capabilities;
549 char serverName[SERVER_NAME_LEN_WITH_NULL * 2];
550
551 char *user_name;
552
553 char *domainName;
554 char *password;
555 struct session_key auth_key;
556 struct ntlmssp_auth *ntlmssp;
557 bool need_reconnect:1;
558#ifdef CONFIG_CIFS_SMB2
559 __u16 session_flags;
560#endif
561};
562
563#define CIFS_SES_NT4 1
564#define CIFS_SES_OS2 2
565#define CIFS_SES_W9X 4
566
567
568
569#define CIFS_SES_LANMAN 8
570
571static inline bool
572cap_unix(struct cifs_ses *ses)
573{
574 return ses->server->vals->cap_unix & ses->capabilities;
575}
576
577
578
579
580
581struct cifs_tcon {
582 struct list_head tcon_list;
583 int tc_count;
584 struct list_head openFileList;
585 struct cifs_ses *ses;
586 char treeName[MAX_TREE_SIZE + 1];
587 char *nativeFileSystem;
588 char *password;
589 __u32 tid;
590 __u16 Flags;
591 enum statusEnum tidStatus;
592#ifdef CONFIG_CIFS_STATS
593 atomic_t num_smbs_sent;
594 union {
595 struct {
596 atomic_t num_writes;
597 atomic_t num_reads;
598 atomic_t num_flushes;
599 atomic_t num_oplock_brks;
600 atomic_t num_opens;
601 atomic_t num_closes;
602 atomic_t num_deletes;
603 atomic_t num_mkdirs;
604 atomic_t num_posixopens;
605 atomic_t num_posixmkdirs;
606 atomic_t num_rmdirs;
607 atomic_t num_renames;
608 atomic_t num_t2renames;
609 atomic_t num_ffirst;
610 atomic_t num_fnext;
611 atomic_t num_fclose;
612 atomic_t num_hardlinks;
613 atomic_t num_symlinks;
614 atomic_t num_locks;
615 atomic_t num_acl_get;
616 atomic_t num_acl_set;
617 } cifs_stats;
618#ifdef CONFIG_CIFS_SMB2
619 struct {
620 atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
621 atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
622 } smb2_stats;
623#endif
624 } stats;
625#ifdef CONFIG_CIFS_STATS2
626 unsigned long long time_writes;
627 unsigned long long time_reads;
628 unsigned long long time_opens;
629 unsigned long long time_deletes;
630 unsigned long long time_closes;
631 unsigned long long time_mkdirs;
632 unsigned long long time_rmdirs;
633 unsigned long long time_renames;
634 unsigned long long time_t2renames;
635 unsigned long long time_ffirst;
636 unsigned long long time_fnext;
637 unsigned long long time_fclose;
638#endif
639 __u64 bytes_read;
640 __u64 bytes_written;
641 spinlock_t stat_lock;
642#endif
643 FILE_SYSTEM_DEVICE_INFO fsDevInfo;
644 FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo;
645 FILE_SYSTEM_UNIX_INFO fsUnixInfo;
646 bool ipc:1;
647 bool retry:1;
648 bool nocase:1;
649 bool seal:1;
650 bool unix_ext:1;
651
652 bool local_lease:1;
653 bool broken_posix_open;
654 bool need_reconnect:1;
655#ifdef CONFIG_CIFS_SMB2
656 bool print:1;
657 bool bad_network_name:1;
658 __u32 capabilities;
659 __u32 share_flags;
660 __u32 maximal_access;
661 __u32 vol_serial_number;
662 __le64 vol_create_time;
663#endif
664#ifdef CONFIG_CIFS_FSCACHE
665 u64 resource_id;
666 struct fscache_cookie *fscache;
667#endif
668
669};
670
671
672
673
674
675
676
677struct tcon_link {
678 struct rb_node tl_rbnode;
679 uid_t tl_uid;
680 unsigned long tl_flags;
681#define TCON_LINK_MASTER 0
682#define TCON_LINK_PENDING 1
683#define TCON_LINK_IN_TREE 2
684 unsigned long tl_time;
685 atomic_t tl_count;
686 struct cifs_tcon *tl_tcon;
687};
688
689extern struct tcon_link *cifs_sb_tlink(struct cifs_sb_info *cifs_sb);
690
691static inline struct cifs_tcon *
692tlink_tcon(struct tcon_link *tlink)
693{
694 return tlink->tl_tcon;
695}
696
697extern void cifs_put_tlink(struct tcon_link *tlink);
698
699static inline struct tcon_link *
700cifs_get_tlink(struct tcon_link *tlink)
701{
702 if (tlink && !IS_ERR(tlink))
703 atomic_inc(&tlink->tl_count);
704 return tlink;
705}
706
707
708extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb);
709
710
711
712
713
714struct cifsLockInfo {
715 struct list_head llist;
716 struct list_head blist;
717 wait_queue_head_t block_q;
718 __u64 offset;
719 __u64 length;
720 __u32 pid;
721 __u32 type;
722};
723
724
725
726
727struct cifs_search_info {
728 loff_t index_of_last_entry;
729 __u16 entries_in_buffer;
730 __u16 info_level;
731 __u32 resume_key;
732 char *ntwrk_buf_start;
733 char *srch_entries_start;
734 char *last_entry;
735 const char *presume_name;
736 unsigned int resume_name_len;
737 bool endOfSearch:1;
738 bool emptyDir:1;
739 bool unicode:1;
740 bool smallBuf:1;
741};
742
743struct cifsFileInfo {
744 struct list_head tlist;
745 struct list_head flist;
746 struct list_head llist;
747
748
749
750 unsigned int uid;
751 __u32 pid;
752 __u16 netfid;
753 ;
754
755 struct dentry *dentry;
756 unsigned int f_flags;
757 struct tcon_link *tlink;
758 bool invalidHandle:1;
759 bool oplock_break_cancelled:1;
760 int count;
761 struct mutex fh_mutex;
762 struct cifs_search_info srch_inf;
763 struct work_struct oplock_break;
764};
765
766struct cifs_io_parms {
767 __u16 netfid;
768 __u32 pid;
769 __u64 offset;
770 unsigned int length;
771 struct cifs_tcon *tcon;
772};
773
774
775
776
777
778static inline void
779cifsFileInfo_get_locked(struct cifsFileInfo *cifs_file)
780{
781 ++cifs_file->count;
782}
783
784struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file);
785void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
786
787
788
789
790
791struct cifsInodeInfo {
792 bool can_cache_brlcks;
793 struct mutex lock_mutex;
794
795
796
797
798
799 struct list_head openFileList;
800 __u32 cifsAttrs;
801 bool clientCanCacheRead;
802 bool clientCanCacheAll;
803 bool delete_pending;
804 bool invalid_mapping;
805 unsigned long time;
806 u64 server_eof;
807 u64 uniqueid;
808 u64 createtime;
809#ifdef CONFIG_CIFS_FSCACHE
810 struct fscache_cookie *fscache;
811#endif
812 struct inode vfs_inode;
813};
814
815static inline struct cifsInodeInfo *
816CIFS_I(struct inode *inode)
817{
818 return container_of(inode, struct cifsInodeInfo, vfs_inode);
819}
820
821static inline struct cifs_sb_info *
822CIFS_SB(struct super_block *sb)
823{
824 return sb->s_fs_info;
825}
826
827static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
828{
829 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
830 return '/';
831 else
832 return '\\';
833}
834
835static inline void
836convert_delimiter(char *path, char delim)
837{
838 int i;
839 char old_delim;
840
841 if (path == NULL)
842 return;
843
844 if (delim == '/')
845 old_delim = '\\';
846 else
847 old_delim = '/';
848
849 for (i = 0; path[i] != '\0'; i++) {
850 if (path[i] == old_delim)
851 path[i] = delim;
852 }
853}
854
855static inline char *
856build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
857 struct cifs_tcon *tcon)
858{
859 if (!vol->ops->build_path_to_root)
860 return NULL;
861 return vol->ops->build_path_to_root(vol, cifs_sb, tcon);
862}
863
864#ifdef CONFIG_CIFS_STATS
865#define cifs_stats_inc atomic_inc
866
867static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
868 unsigned int bytes)
869{
870 if (bytes) {
871 spin_lock(&tcon->stat_lock);
872 tcon->bytes_written += bytes;
873 spin_unlock(&tcon->stat_lock);
874 }
875}
876
877static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,
878 unsigned int bytes)
879{
880 spin_lock(&tcon->stat_lock);
881 tcon->bytes_read += bytes;
882 spin_unlock(&tcon->stat_lock);
883}
884#else
885
886#define cifs_stats_inc(field) do {} while (0)
887#define cifs_stats_bytes_written(tcon, bytes) do {} while (0)
888#define cifs_stats_bytes_read(tcon, bytes) do {} while (0)
889
890#endif
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905typedef int (mid_receive_t)(struct TCP_Server_Info *server,
906 struct mid_q_entry *mid);
907
908
909
910
911
912
913
914
915
916typedef void (mid_callback_t)(struct mid_q_entry *mid);
917
918
919struct mid_q_entry {
920 struct list_head qhead;
921 struct TCP_Server_Info *server;
922 __u64 mid;
923 __u32 pid;
924 __u32 sequence_number;
925 unsigned long when_alloc;
926#ifdef CONFIG_CIFS_STATS2
927 unsigned long when_sent;
928 unsigned long when_received;
929#endif
930 mid_receive_t *receive;
931 mid_callback_t *callback;
932 void *callback_data;
933 void *resp_buf;
934 int mid_state;
935 __le16 command;
936 bool large_buf:1;
937 bool multiRsp:1;
938 bool multiEnd:1;
939};
940
941
942
943#ifdef CONFIG_CIFS_STATS2
944
945static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
946{
947 atomic_inc(&server->in_send);
948}
949
950static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
951{
952 atomic_dec(&server->in_send);
953}
954
955static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
956{
957 atomic_inc(&server->num_waiters);
958}
959
960static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
961{
962 atomic_dec(&server->num_waiters);
963}
964
965static inline void cifs_save_when_sent(struct mid_q_entry *mid)
966{
967 mid->when_sent = jiffies;
968}
969#else
970static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
971{
972}
973static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
974{
975}
976
977static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
978{
979}
980
981static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
982{
983}
984
985static inline void cifs_save_when_sent(struct mid_q_entry *mid)
986{
987}
988#endif
989
990
991struct dir_notify_req {
992 struct list_head lhead;
993 __le16 Pid;
994 __le16 PidHigh;
995 __u16 Mid;
996 __u16 Tid;
997 __u16 Uid;
998 __u16 netfid;
999 __u32 filter;
1000 int multishot;
1001 struct file *pfile;
1002};
1003
1004struct dfs_info3_param {
1005 int flags;
1006 int path_consumed;
1007 int server_type;
1008 int ref_flag;
1009 char *path_name;
1010 char *node_name;
1011};
1012
1013
1014
1015
1016
1017
1018#define CIFS_FATTR_DFS_REFERRAL 0x1
1019#define CIFS_FATTR_DELETE_PENDING 0x2
1020#define CIFS_FATTR_NEED_REVAL 0x4
1021#define CIFS_FATTR_INO_COLLISION 0x8
1022
1023struct cifs_fattr {
1024 u32 cf_flags;
1025 u32 cf_cifsattrs;
1026 u64 cf_uniqueid;
1027 u64 cf_eof;
1028 u64 cf_bytes;
1029 u64 cf_createtime;
1030 uid_t cf_uid;
1031 gid_t cf_gid;
1032 umode_t cf_mode;
1033 dev_t cf_rdev;
1034 unsigned int cf_nlink;
1035 unsigned int cf_dtype;
1036 struct timespec cf_atime;
1037 struct timespec cf_mtime;
1038 struct timespec cf_ctime;
1039};
1040
1041static inline void free_dfs_info_param(struct dfs_info3_param *param)
1042{
1043 if (param) {
1044 kfree(param->path_name);
1045 kfree(param->node_name);
1046 kfree(param);
1047 }
1048}
1049
1050static inline void free_dfs_info_array(struct dfs_info3_param *param,
1051 int number_of_items)
1052{
1053 int i;
1054 if ((number_of_items == 0) || (param == NULL))
1055 return;
1056 for (i = 0; i < number_of_items; i++) {
1057 kfree(param[i].path_name);
1058 kfree(param[i].node_name);
1059 }
1060 kfree(param);
1061}
1062
1063#define MID_FREE 0
1064#define MID_REQUEST_ALLOCATED 1
1065#define MID_REQUEST_SUBMITTED 2
1066#define MID_RESPONSE_RECEIVED 4
1067#define MID_RETRY_NEEDED 8
1068#define MID_RESPONSE_MALFORMED 0x10
1069#define MID_SHUTDOWN 0x20
1070
1071
1072#define CIFS_NO_BUFFER 0
1073#define CIFS_SMALL_BUFFER 1
1074#define CIFS_LARGE_BUFFER 2
1075#define CIFS_IOVEC 4
1076
1077
1078#define CIFS_BLOCKING_OP 1
1079#define CIFS_ASYNC_OP 2
1080#define CIFS_TIMEOUT_MASK 0x003
1081#define CIFS_LOG_ERROR 0x010
1082#define CIFS_LARGE_BUF_OP 0x020
1083#define CIFS_NO_RESP 0x040
1084
1085
1086#define CIFS_ECHO_OP 0x080
1087#define CIFS_OBREAK_OP 0x0100
1088#define CIFS_NEG_OP 0x0200
1089#define CIFS_OP_MASK 0x0380
1090
1091
1092#define CIFSSEC_MAY_SIGN 0x00001
1093#define CIFSSEC_MAY_NTLM 0x00002
1094#define CIFSSEC_MAY_NTLMV2 0x00004
1095#define CIFSSEC_MAY_KRB5 0x00008
1096#ifdef CONFIG_CIFS_WEAK_PW_HASH
1097#define CIFSSEC_MAY_LANMAN 0x00010
1098#define CIFSSEC_MAY_PLNTXT 0x00020
1099#else
1100#define CIFSSEC_MAY_LANMAN 0
1101#define CIFSSEC_MAY_PLNTXT 0
1102#endif
1103#define CIFSSEC_MAY_SEAL 0x00040
1104#define CIFSSEC_MAY_NTLMSSP 0x00080
1105
1106#define CIFSSEC_MUST_SIGN 0x01001
1107
1108
1109
1110#define CIFSSEC_MUST_NTLM 0x02002
1111#define CIFSSEC_MUST_NTLMV2 0x04004
1112#define CIFSSEC_MUST_KRB5 0x08008
1113#ifdef CONFIG_CIFS_WEAK_PW_HASH
1114#define CIFSSEC_MUST_LANMAN 0x10010
1115#define CIFSSEC_MUST_PLNTXT 0x20020
1116#ifdef CONFIG_CIFS_UPCALL
1117#define CIFSSEC_MASK 0xBF0BF
1118#else
1119#define CIFSSEC_MASK 0xB70B7
1120#endif
1121#else
1122#define CIFSSEC_MUST_LANMAN 0
1123#define CIFSSEC_MUST_PLNTXT 0
1124#ifdef CONFIG_CIFS_UPCALL
1125#define CIFSSEC_MASK 0x8F08F
1126#else
1127#define CIFSSEC_MASK 0x87087
1128#endif
1129#endif
1130#define CIFSSEC_MUST_SEAL 0x40040
1131#define CIFSSEC_MUST_NTLMSSP 0x80080
1132
1133#define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2)
1134#define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2)
1135#define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
1136
1137
1138
1139
1140
1141
1142#define UID_HASH (16)
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171#ifdef DECLARE_GLOBALS_HERE
1172#define GLOBAL_EXTERN
1173#else
1174#define GLOBAL_EXTERN extern
1175#endif
1176
1177
1178
1179
1180
1181
1182
1183
1184GLOBAL_EXTERN struct list_head cifs_tcp_ses_list;
1185
1186
1187
1188
1189
1190
1191
1192GLOBAL_EXTERN spinlock_t cifs_tcp_ses_lock;
1193
1194
1195
1196
1197
1198
1199
1200
1201GLOBAL_EXTERN spinlock_t cifs_file_list_lock;
1202
1203#ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL
1204
1205GLOBAL_EXTERN struct list_head GlobalDnotifyReqList;
1206
1207GLOBAL_EXTERN struct list_head GlobalDnotifyRsp_Q;
1208#endif
1209
1210
1211
1212
1213GLOBAL_EXTERN unsigned int GlobalCurrentXid;
1214GLOBAL_EXTERN unsigned int GlobalTotalActiveXid;
1215GLOBAL_EXTERN unsigned int GlobalMaxActiveXid;
1216GLOBAL_EXTERN spinlock_t GlobalMid_Lock;
1217
1218
1219
1220
1221GLOBAL_EXTERN atomic_t sesInfoAllocCount;
1222GLOBAL_EXTERN atomic_t tconInfoAllocCount;
1223GLOBAL_EXTERN atomic_t tcpSesAllocCount;
1224GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
1225GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
1226
1227
1228GLOBAL_EXTERN atomic_t bufAllocCount;
1229#ifdef CONFIG_CIFS_STATS2
1230GLOBAL_EXTERN atomic_t totBufAllocCount;
1231GLOBAL_EXTERN atomic_t totSmBufAllocCount;
1232#endif
1233GLOBAL_EXTERN atomic_t smBufAllocCount;
1234GLOBAL_EXTERN atomic_t midCount;
1235
1236
1237GLOBAL_EXTERN bool enable_oplocks;
1238GLOBAL_EXTERN unsigned int lookupCacheEnabled;
1239GLOBAL_EXTERN unsigned int global_secflags;
1240
1241GLOBAL_EXTERN unsigned int sign_CIFS_PDUs;
1242GLOBAL_EXTERN unsigned int linuxExtEnabled;
1243GLOBAL_EXTERN unsigned int CIFSMaxBufSize;
1244GLOBAL_EXTERN unsigned int cifs_min_rcv;
1245GLOBAL_EXTERN unsigned int cifs_min_small;
1246GLOBAL_EXTERN unsigned int cifs_max_pending;
1247
1248#ifdef CONFIG_CIFS_ACL
1249GLOBAL_EXTERN struct rb_root uidtree;
1250GLOBAL_EXTERN struct rb_root gidtree;
1251GLOBAL_EXTERN spinlock_t siduidlock;
1252GLOBAL_EXTERN spinlock_t sidgidlock;
1253GLOBAL_EXTERN struct rb_root siduidtree;
1254GLOBAL_EXTERN struct rb_root sidgidtree;
1255GLOBAL_EXTERN spinlock_t uidsidlock;
1256GLOBAL_EXTERN spinlock_t gidsidlock;
1257#endif
1258
1259void cifs_oplock_break(struct work_struct *work);
1260
1261extern const struct slow_work_ops cifs_oplock_break_ops;
1262extern struct workqueue_struct *cifsiod_wq;
1263
1264extern mempool_t *cifs_mid_poolp;
1265
1266
1267#define SMB1_VERSION_STRING "1.0"
1268extern struct smb_version_operations smb1_operations;
1269extern struct smb_version_values smb1_values;
1270#define SMB21_VERSION_STRING "2.1"
1271extern struct smb_version_operations smb21_operations;
1272extern struct smb_version_values smb21_values;
1273#endif
1274