cifsglob.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /*
  2. * fs/cifs/cifsglob.h
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2005
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published
  9. * by the Free Software Foundation; either version 2.1 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  15. * the GNU Lesser General Public License for more details.
  16. *
  17. */
  18. #include <linux/in.h>
  19. #include <linux/in6.h>
  20. #include "cifs_fs_sb.h"
  21. /*
  22. * The sizes of various internal tables and strings
  23. */
  24. #define MAX_UID_INFO 16
  25. #define MAX_SES_INFO 2
  26. #define MAX_TCON_INFO 4
  27. #define MAX_TREE_SIZE 2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1
  28. #define MAX_SERVER_SIZE 15
  29. #define MAX_SHARE_SIZE 64 /* used to be 20 - this should still be enough */
  30. #define MAX_USERNAME_SIZE 32 /* 32 is to allow for 15 char names + null
  31. termination then *2 for unicode versions */
  32. #define MAX_PASSWORD_SIZE 16
  33. #define CIFS_MIN_RCV_POOL 4
  34. /*
  35. * MAX_REQ is the maximum number of requests that WE will send
  36. * on one socket concurently. It also matches the most common
  37. * value of max multiplex returned by servers. We may
  38. * eventually want to use the negotiated value (in case
  39. * future servers can handle more) when we are more confident that
  40. * we will not have problems oveloading the socket with pending
  41. * write data.
  42. */
  43. #define CIFS_MAX_REQ 50
  44. #define SERVER_NAME_LENGTH 15
  45. #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
  46. /* used to define string lengths for reversing unicode strings */
  47. /* (256+1)*2 = 514 */
  48. /* (max path length + 1 for null) * 2 for unicode */
  49. #define MAX_NAME 514
  50. #include "cifspdu.h"
  51. #ifndef FALSE
  52. #define FALSE 0
  53. #endif
  54. #ifndef TRUE
  55. #define TRUE 1
  56. #endif
  57. #ifndef XATTR_DOS_ATTRIB
  58. #define XATTR_DOS_ATTRIB "user.DOSATTRIB"
  59. #endif
  60. /*
  61. * This information is kept on every Server we know about.
  62. *
  63. * Some things to note:
  64. *
  65. */
  66. #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
  67. /*
  68. * CIFS vfs client Status information (based on what we know.)
  69. */
  70. /* associated with each tcp and smb session */
  71. enum statusEnum {
  72. CifsNew = 0,
  73. CifsGood,
  74. CifsExiting,
  75. CifsNeedReconnect
  76. };
  77. enum securityEnum {
  78. NTLM = 0, /* Legacy NTLM012 auth with NTLM hash */
  79. NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */
  80. RawNTLMSSP, /* NTLMSSP without SPNEGO */
  81. NTLMSSP, /* NTLMSSP via SPNEGO */
  82. Kerberos /* Kerberos via SPNEGO */
  83. };
  84. enum protocolEnum {
  85. IPV4 = 0,
  86. IPV6,
  87. SCTP
  88. /* Netbios frames protocol not supported at this time */
  89. };
  90. /*
  91. *****************************************************************
  92. * Except the CIFS PDUs themselves all the
  93. * globally interesting structs should go here
  94. *****************************************************************
  95. */
  96. struct TCP_Server_Info {
  97. /* 15 character server name + 0x20 16th byte indicating type = srv */
  98. char server_RFC1001_name[SERVER_NAME_LEN_WITH_NULL];
  99. char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2];
  100. struct socket *ssocket;
  101. union {
  102. struct sockaddr_in sockAddr;
  103. struct sockaddr_in6 sockAddr6;
  104. } addr;
  105. wait_queue_head_t response_q;
  106. wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
  107. struct list_head pending_mid_q;
  108. void *Server_NlsInfo; /* BB - placeholder for future NLS info */
  109. unsigned short server_codepage; /* codepage for the server */
  110. unsigned long ip_address; /* IP addr for the server if known */
  111. enum protocolEnum protocolType;
  112. char versionMajor;
  113. char versionMinor;
  114. unsigned svlocal:1; /* local server or remote */
  115. atomic_t socketUseCount; /* number of open cifs sessions on socket */
  116. atomic_t inFlight; /* number of requests on the wire to server */
  117. enum statusEnum tcpStatus; /* what we think the status is */
  118. struct semaphore tcpSem;
  119. struct task_struct *tsk;
  120. char server_GUID[16];
  121. char secMode;
  122. enum securityEnum secType;
  123. unsigned int maxReq; /* Clients should submit no more */
  124. /* than maxReq distinct unanswered SMBs to the server when using */
  125. /* multiplexed reads or writes */
  126. unsigned int maxBuf; /* maxBuf specifies the maximum */
  127. /* message size the server can send or receive for non-raw SMBs */
  128. unsigned int maxRw; /* maxRw specifies the maximum */
  129. /* message size the server can send or receive for */
  130. /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
  131. char sessid[4]; /* unique token id for this session */
  132. /* (returned on Negotiate */
  133. int capabilities; /* allow selective disabling of caps by smb sess */
  134. __u16 timeZone;
  135. __u16 CurrentMid; /* multiplex id - rotating counter */
  136. char cryptKey[CIFS_CRYPTO_KEY_SIZE];
  137. /* 16th byte of RFC1001 workstation name is always null */
  138. char workstation_RFC1001_name[SERVER_NAME_LEN_WITH_NULL];
  139. __u32 sequence_number; /* needed for CIFS PDU signature */
  140. char mac_signing_key[CIFS_SESSION_KEY_SIZE + 16];
  141. };
  142. /*
  143. * The following is our shortcut to user information. We surface the uid,
  144. * and name. We always get the password on the fly in case it
  145. * has changed. We also hang a list of sessions owned by this user off here.
  146. */
  147. struct cifsUidInfo {
  148. struct list_head userList;
  149. struct list_head sessionList; /* SMB sessions for this user */
  150. uid_t linux_uid;
  151. char user[MAX_USERNAME_SIZE + 1]; /* ascii name of user */
  152. /* BB may need ptr or callback for PAM or WinBind info */
  153. };
  154. /*
  155. * Session structure. One of these for each uid session with a particular host
  156. */
  157. struct cifsSesInfo {
  158. struct list_head cifsSessionList;
  159. struct semaphore sesSem;
  160. struct cifsUidInfo *uidInfo; /* pointer to user info */
  161. struct TCP_Server_Info *server; /* pointer to server info */
  162. atomic_t inUse; /* # of mounts (tree connections) on this ses */
  163. enum statusEnum status;
  164. __u16 ipc_tid; /* special tid for connection to IPC share */
  165. __u16 flags;
  166. char *serverOS; /* name of operating system underlying server */
  167. char *serverNOS; /* name of network operating system of server */
  168. char *serverDomain; /* security realm of server */
  169. int Suid; /* remote smb uid */
  170. uid_t linux_uid; /* local Linux uid */
  171. int capabilities;
  172. char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
  173. TCP names - will ipv6 and sctp addresses fit? */
  174. char userName[MAX_USERNAME_SIZE + 1];
  175. char domainName[MAX_USERNAME_SIZE + 1];
  176. char * password;
  177. };
  178. /* session flags */
  179. #define CIFS_SES_NT4 1
  180. /*
  181. * there is one of these for each connection to a resource on a particular
  182. * session
  183. */
  184. struct cifsTconInfo {
  185. struct list_head cifsConnectionList;
  186. struct list_head openFileList;
  187. struct semaphore tconSem;
  188. struct cifsSesInfo *ses; /* pointer to session associated with */
  189. char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource (in ASCII not UTF) */
  190. char *nativeFileSystem;
  191. __u16 tid; /* The 2 byte tree id */
  192. __u16 Flags; /* optional support bits */
  193. enum statusEnum tidStatus;
  194. atomic_t useCount; /* how many mounts (explicit or implicit) to this share */
  195. #ifdef CONFIG_CIFS_STATS
  196. atomic_t num_smbs_sent;
  197. atomic_t num_writes;
  198. atomic_t num_reads;
  199. atomic_t num_oplock_brks;
  200. atomic_t num_opens;
  201. atomic_t num_closes;
  202. atomic_t num_deletes;
  203. atomic_t num_mkdirs;
  204. atomic_t num_rmdirs;
  205. atomic_t num_renames;
  206. atomic_t num_t2renames;
  207. atomic_t num_ffirst;
  208. atomic_t num_fnext;
  209. atomic_t num_fclose;
  210. atomic_t num_hardlinks;
  211. atomic_t num_symlinks;
  212. atomic_t num_locks;
  213. #ifdef CONFIG_CIFS_STATS2
  214. unsigned long long time_writes;
  215. unsigned long long time_reads;
  216. unsigned long long time_opens;
  217. unsigned long long time_deletes;
  218. unsigned long long time_closes;
  219. unsigned long long time_mkdirs;
  220. unsigned long long time_rmdirs;
  221. unsigned long long time_renames;
  222. unsigned long long time_t2renames;
  223. unsigned long long time_ffirst;
  224. unsigned long long time_fnext;
  225. unsigned long long time_fclose;
  226. #endif /* CONFIG_CIFS_STATS2 */
  227. __u64 bytes_read;
  228. __u64 bytes_written;
  229. spinlock_t stat_lock;
  230. #endif /* CONFIG_CIFS_STATS */
  231. FILE_SYSTEM_DEVICE_INFO fsDevInfo;
  232. FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if file system name truncated */
  233. FILE_SYSTEM_UNIX_INFO fsUnixInfo;
  234. unsigned retry:1;
  235. unsigned nocase:1;
  236. /* BB add field for back pointer to sb struct? */
  237. };
  238. /*
  239. * This info hangs off the cifsFileInfo structure. This is used to track
  240. * byte stream locks on the file
  241. */
  242. struct cifsLockInfo {
  243. struct cifsLockInfo *next;
  244. int start;
  245. int length;
  246. int type;
  247. };
  248. /*
  249. * One of these for each open instance of a file
  250. */
  251. struct cifs_search_info {
  252. loff_t index_of_last_entry;
  253. __u16 entries_in_buffer;
  254. __u16 info_level;
  255. __u32 resume_key;
  256. char * ntwrk_buf_start;
  257. char * srch_entries_start;
  258. char * presume_name;
  259. unsigned int resume_name_len;
  260. unsigned endOfSearch:1;
  261. unsigned emptyDir:1;
  262. unsigned unicode:1;
  263. };
  264. struct cifsFileInfo {
  265. struct list_head tlist; /* pointer to next fid owned by tcon */
  266. struct list_head flist; /* next fid (file instance) for this inode */
  267. unsigned int uid; /* allows finding which FileInfo structure */
  268. __u32 pid; /* process id who opened file */
  269. __u16 netfid; /* file id from remote */
  270. /* BB add lock scope info here if needed */ ;
  271. /* lock scope id (0 if none) */
  272. struct file * pfile; /* needed for writepage */
  273. struct inode * pInode; /* needed for oplock break */
  274. unsigned closePend:1; /* file is marked to close */
  275. unsigned invalidHandle:1; /* file closed via session abend */
  276. struct semaphore fh_sem; /* prevents reopen race after dead ses*/
  277. char * search_resume_name; /* BB removeme BB */
  278. unsigned int resume_name_length; /* BB removeme - field renamed and moved BB */
  279. struct cifs_search_info srch_inf;
  280. };
  281. /*
  282. * One of these for each file inode
  283. */
  284. struct cifsInodeInfo {
  285. struct list_head lockList;
  286. /* BB add in lists for dirty pages - i.e. write caching info for oplock */
  287. struct list_head openFileList;
  288. int write_behind_rc;
  289. __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
  290. atomic_t inUse; /* num concurrent users (local openers cifs) of file*/
  291. unsigned long time; /* jiffies of last update/check of inode */
  292. unsigned clientCanCacheRead:1; /* read oplock */
  293. unsigned clientCanCacheAll:1; /* read and writebehind oplock */
  294. unsigned oplockPending:1;
  295. struct inode vfs_inode;
  296. };
  297. static inline struct cifsInodeInfo *
  298. CIFS_I(struct inode *inode)
  299. {
  300. return container_of(inode, struct cifsInodeInfo, vfs_inode);
  301. }
  302. static inline struct cifs_sb_info *
  303. CIFS_SB(struct super_block *sb)
  304. {
  305. return sb->s_fs_info;
  306. }
  307. static inline const char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
  308. {
  309. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
  310. return '/';
  311. else
  312. return '\\';
  313. }
  314. /* one of these for every pending CIFS request to the server */
  315. struct mid_q_entry {
  316. struct list_head qhead; /* mids waiting on reply from this server */
  317. __u16 mid; /* multiplex id */
  318. __u16 pid; /* process id */
  319. __u32 sequence_number; /* for CIFS signing */
  320. struct timeval when_sent; /* time when smb sent */
  321. struct cifsSesInfo *ses; /* smb was sent to this server */
  322. struct task_struct *tsk; /* task waiting for response */
  323. struct smb_hdr *resp_buf; /* response buffer */
  324. int midState; /* wish this were enum but can not pass to wait_event */
  325. __u8 command; /* smb command code */
  326. unsigned multiPart:1; /* multiple responses to one SMB request */
  327. unsigned largeBuf:1; /* if valid response, is pointer to large buf */
  328. unsigned multiResp:1; /* multiple trans2 responses for one request */
  329. };
  330. struct oplock_q_entry {
  331. struct list_head qhead;
  332. struct inode * pinode;
  333. struct cifsTconInfo * tcon;
  334. __u16 netfid;
  335. };
  336. #define MID_FREE 0
  337. #define MID_REQUEST_ALLOCATED 1
  338. #define MID_REQUEST_SUBMITTED 2
  339. #define MID_RESPONSE_RECEIVED 4
  340. #define MID_RETRY_NEEDED 8 /* session closed while this request out */
  341. #define MID_NO_RESP_NEEDED 0x10
  342. #define MID_SMALL_BUFFER 0x20 /* 112 byte response buffer instead of 4K */
  343. /*
  344. *****************************************************************
  345. * All constants go here
  346. *****************************************************************
  347. */
  348. #define UID_HASH (16)
  349. /*
  350. * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
  351. * following to be declared.
  352. */
  353. /****************************************************************************
  354. * Locking notes. All updates to global variables and lists should be
  355. * protected by spinlocks or semaphores.
  356. *
  357. * Spinlocks
  358. * ---------
  359. * GlobalMid_Lock protects:
  360. * list operations on pending_mid_q and oplockQ
  361. * updates to XID counters, multiplex id and SMB sequence numbers
  362. * GlobalSMBSesLock protects:
  363. * list operations on tcp and SMB session lists and tCon lists
  364. * f_owner.lock protects certain per file struct operations
  365. * mapping->page_lock protects certain per page operations
  366. *
  367. * Semaphores
  368. * ----------
  369. * sesSem operations on smb session
  370. * tconSem operations on tree connection
  371. * fh_sem file handle reconnection operations
  372. *
  373. ****************************************************************************/
  374. #ifdef DECLARE_GLOBALS_HERE
  375. #define GLOBAL_EXTERN
  376. #else
  377. #define GLOBAL_EXTERN extern
  378. #endif
  379. /*
  380. * The list of servers that did not respond with NT LM 0.12.
  381. * This list helps improve performance and eliminate the messages indicating
  382. * that we had a communications error talking to the server in this list.
  383. */
  384. GLOBAL_EXTERN struct servers_not_supported *NotSuppList; /*@z4a */
  385. /*
  386. * The following is a hash table of all the users we know about.
  387. */
  388. GLOBAL_EXTERN struct smbUidInfo *GlobalUidList[UID_HASH];
  389. GLOBAL_EXTERN struct list_head GlobalServerList; /* BB not implemented yet */
  390. GLOBAL_EXTERN struct list_head GlobalSMBSessionList;
  391. GLOBAL_EXTERN struct list_head GlobalTreeConnectionList;
  392. GLOBAL_EXTERN rwlock_t GlobalSMBSeslock; /* protects list inserts on 3 above */
  393. GLOBAL_EXTERN struct list_head GlobalOplock_Q;
  394. /*
  395. * Global transaction id (XID) information
  396. */
  397. GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
  398. GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
  399. GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
  400. GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above and list operations */
  401. /* on midQ entries */
  402. GLOBAL_EXTERN char Local_System_Name[15];
  403. /*
  404. * Global counters, updated atomically
  405. */
  406. GLOBAL_EXTERN atomic_t sesInfoAllocCount;
  407. GLOBAL_EXTERN atomic_t tconInfoAllocCount;
  408. GLOBAL_EXTERN atomic_t tcpSesAllocCount;
  409. GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
  410. GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
  411. /* Various Debug counters to remove someday (BB) */
  412. GLOBAL_EXTERN atomic_t bufAllocCount;
  413. GLOBAL_EXTERN atomic_t smBufAllocCount;
  414. GLOBAL_EXTERN atomic_t midCount;
  415. /* Misc globals */
  416. GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
  417. to be established on existing mount if we
  418. have the uid/password or Kerberos credential
  419. or equivalent for current user */
  420. GLOBAL_EXTERN unsigned int oplockEnabled;
  421. GLOBAL_EXTERN unsigned int experimEnabled;
  422. GLOBAL_EXTERN unsigned int lookupCacheEnabled;
  423. GLOBAL_EXTERN unsigned int extended_security; /* if on, session setup sent
  424. with more secure ntlmssp2 challenge/resp */
  425. GLOBAL_EXTERN unsigned int ntlmv2_support; /* better optional password hash */
  426. GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
  427. GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
  428. GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
  429. GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
  430. GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
  431. GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/