cifsglob.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. char server_Name[SERVER_NAME_LEN_WITH_NULL]; /* 15 chars + X'20' 16th */
  98. char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2];
  99. struct socket *ssocket;
  100. union {
  101. struct sockaddr_in sockAddr;
  102. struct sockaddr_in6 sockAddr6;
  103. } addr;
  104. wait_queue_head_t response_q;
  105. wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
  106. struct list_head pending_mid_q;
  107. void *Server_NlsInfo; /* BB - placeholder for future NLS info */
  108. unsigned short server_codepage; /* codepage for the server */
  109. unsigned long ip_address; /* IP addr for the server if known */
  110. enum protocolEnum protocolType;
  111. char versionMajor;
  112. char versionMinor;
  113. unsigned svlocal:1; /* local server or remote */
  114. atomic_t socketUseCount; /* number of open cifs sessions on socket */
  115. atomic_t inFlight; /* number of requests on the wire to server */
  116. enum statusEnum tcpStatus; /* what we think the status is */
  117. struct semaphore tcpSem;
  118. struct task_struct *tsk;
  119. char server_GUID[16];
  120. char secMode;
  121. enum securityEnum secType;
  122. unsigned int maxReq; /* Clients should submit no more */
  123. /* than maxReq distinct unanswered SMBs to the server when using */
  124. /* multiplexed reads or writes */
  125. unsigned int maxBuf; /* maxBuf specifies the maximum */
  126. /* message size the server can send or receive for non-raw SMBs */
  127. unsigned int maxRw; /* maxRw specifies the maximum */
  128. /* message size the server can send or receive for */
  129. /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
  130. char sessid[4]; /* unique token id for this session */
  131. /* (returned on Negotiate */
  132. int capabilities; /* allow selective disabling of caps by smb sess */
  133. __u16 timeZone;
  134. __u16 CurrentMid; /* multiplex id - rotating counter */
  135. char cryptKey[CIFS_CRYPTO_KEY_SIZE];
  136. char workstation_RFC1001_name[16]; /* 16th byte is always zero */
  137. __u32 sequence_number; /* needed for CIFS PDU signature */
  138. char mac_signing_key[CIFS_SESSION_KEY_SIZE + 16];
  139. };
  140. /*
  141. * The following is our shortcut to user information. We surface the uid,
  142. * and name. We always get the password on the fly in case it
  143. * has changed. We also hang a list of sessions owned by this user off here.
  144. */
  145. struct cifsUidInfo {
  146. struct list_head userList;
  147. struct list_head sessionList; /* SMB sessions for this user */
  148. uid_t linux_uid;
  149. char user[MAX_USERNAME_SIZE + 1]; /* ascii name of user */
  150. /* BB may need ptr or callback for PAM or WinBind info */
  151. };
  152. /*
  153. * Session structure. One of these for each uid session with a particular host
  154. */
  155. struct cifsSesInfo {
  156. struct list_head cifsSessionList;
  157. struct semaphore sesSem;
  158. struct cifsUidInfo *uidInfo; /* pointer to user info */
  159. struct TCP_Server_Info *server; /* pointer to server info */
  160. atomic_t inUse; /* # of mounts (tree connections) on this ses */
  161. enum statusEnum status;
  162. __u16 ipc_tid; /* special tid for connection to IPC share */
  163. __u16 flags;
  164. char *serverOS; /* name of operating system underlying server */
  165. char *serverNOS; /* name of network operating system of server */
  166. char *serverDomain; /* security realm of server */
  167. int Suid; /* remote smb uid */
  168. uid_t linux_uid; /* local Linux uid */
  169. int capabilities;
  170. char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
  171. TCP names - will ipv6 and sctp addresses fit? */
  172. char userName[MAX_USERNAME_SIZE + 1];
  173. char domainName[MAX_USERNAME_SIZE + 1];
  174. char * password;
  175. };
  176. /* session flags */
  177. #define CIFS_SES_NT4 1
  178. /*
  179. * there is one of these for each connection to a resource on a particular
  180. * session
  181. */
  182. struct cifsTconInfo {
  183. struct list_head cifsConnectionList;
  184. struct list_head openFileList;
  185. struct semaphore tconSem;
  186. struct cifsSesInfo *ses; /* pointer to session associated with */
  187. char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource (in ASCII not UTF) */
  188. char *nativeFileSystem;
  189. __u16 tid; /* The 2 byte tree id */
  190. __u16 Flags; /* optional support bits */
  191. enum statusEnum tidStatus;
  192. atomic_t useCount; /* how many mounts (explicit or implicit) to this share */
  193. #ifdef CONFIG_CIFS_STATS
  194. atomic_t num_smbs_sent;
  195. atomic_t num_writes;
  196. atomic_t num_reads;
  197. atomic_t num_oplock_brks;
  198. atomic_t num_opens;
  199. atomic_t num_closes;
  200. atomic_t num_deletes;
  201. atomic_t num_mkdirs;
  202. atomic_t num_rmdirs;
  203. atomic_t num_renames;
  204. atomic_t num_t2renames;
  205. atomic_t num_ffirst;
  206. atomic_t num_fnext;
  207. atomic_t num_fclose;
  208. atomic_t num_hardlinks;
  209. atomic_t num_symlinks;
  210. atomic_t num_locks;
  211. #ifdef CONFIG_CIFS_STATS2
  212. unsigned long long time_writes;
  213. unsigned long long time_reads;
  214. unsigned long long time_opens;
  215. unsigned long long time_deletes;
  216. unsigned long long time_closes;
  217. unsigned long long time_mkdirs;
  218. unsigned long long time_rmdirs;
  219. unsigned long long time_renames;
  220. unsigned long long time_t2renames;
  221. unsigned long long time_ffirst;
  222. unsigned long long time_fnext;
  223. unsigned long long time_fclose;
  224. #endif /* CONFIG_CIFS_STATS2 */
  225. __u64 bytes_read;
  226. __u64 bytes_written;
  227. spinlock_t stat_lock;
  228. #endif /* CONFIG_CIFS_STATS */
  229. FILE_SYSTEM_DEVICE_INFO fsDevInfo;
  230. FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if file system name truncated */
  231. FILE_SYSTEM_UNIX_INFO fsUnixInfo;
  232. unsigned retry:1;
  233. unsigned nocase:1;
  234. /* BB add field for back pointer to sb struct? */
  235. };
  236. /*
  237. * This info hangs off the cifsFileInfo structure. This is used to track
  238. * byte stream locks on the file
  239. */
  240. struct cifsLockInfo {
  241. struct cifsLockInfo *next;
  242. int start;
  243. int length;
  244. int type;
  245. };
  246. /*
  247. * One of these for each open instance of a file
  248. */
  249. struct cifs_search_info {
  250. loff_t index_of_last_entry;
  251. __u16 entries_in_buffer;
  252. __u16 info_level;
  253. __u32 resume_key;
  254. char * ntwrk_buf_start;
  255. char * srch_entries_start;
  256. char * presume_name;
  257. unsigned int resume_name_len;
  258. unsigned endOfSearch:1;
  259. unsigned emptyDir:1;
  260. unsigned unicode:1;
  261. };
  262. struct cifsFileInfo {
  263. struct list_head tlist; /* pointer to next fid owned by tcon */
  264. struct list_head flist; /* next fid (file instance) for this inode */
  265. unsigned int uid; /* allows finding which FileInfo structure */
  266. __u32 pid; /* process id who opened file */
  267. __u16 netfid; /* file id from remote */
  268. /* BB add lock scope info here if needed */ ;
  269. /* lock scope id (0 if none) */
  270. struct file * pfile; /* needed for writepage */
  271. struct inode * pInode; /* needed for oplock break */
  272. unsigned closePend:1; /* file is marked to close */
  273. unsigned invalidHandle:1; /* file closed via session abend */
  274. struct semaphore fh_sem; /* prevents reopen race after dead ses*/
  275. char * search_resume_name; /* BB removeme BB */
  276. unsigned int resume_name_length; /* BB removeme - field renamed and moved BB */
  277. struct cifs_search_info srch_inf;
  278. };
  279. /*
  280. * One of these for each file inode
  281. */
  282. struct cifsInodeInfo {
  283. struct list_head lockList;
  284. /* BB add in lists for dirty pages - i.e. write caching info for oplock */
  285. struct list_head openFileList;
  286. int write_behind_rc;
  287. __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
  288. atomic_t inUse; /* num concurrent users (local openers cifs) of file*/
  289. unsigned long time; /* jiffies of last update/check of inode */
  290. unsigned clientCanCacheRead:1; /* read oplock */
  291. unsigned clientCanCacheAll:1; /* read and writebehind oplock */
  292. unsigned oplockPending:1;
  293. struct inode vfs_inode;
  294. };
  295. static inline struct cifsInodeInfo *
  296. CIFS_I(struct inode *inode)
  297. {
  298. return container_of(inode, struct cifsInodeInfo, vfs_inode);
  299. }
  300. static inline struct cifs_sb_info *
  301. CIFS_SB(struct super_block *sb)
  302. {
  303. return sb->s_fs_info;
  304. }
  305. static inline const char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
  306. {
  307. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
  308. return '/';
  309. else
  310. return '\\';
  311. }
  312. /* one of these for every pending CIFS request to the server */
  313. struct mid_q_entry {
  314. struct list_head qhead; /* mids waiting on reply from this server */
  315. __u16 mid; /* multiplex id */
  316. __u16 pid; /* process id */
  317. __u32 sequence_number; /* for CIFS signing */
  318. struct timeval when_sent; /* time when smb sent */
  319. struct cifsSesInfo *ses; /* smb was sent to this server */
  320. struct task_struct *tsk; /* task waiting for response */
  321. struct smb_hdr *resp_buf; /* response buffer */
  322. int midState; /* wish this were enum but can not pass to wait_event */
  323. __u8 command; /* smb command code */
  324. unsigned multiPart:1; /* multiple responses to one SMB request */
  325. unsigned largeBuf:1; /* if valid response, is pointer to large buf */
  326. unsigned multiResp:1; /* multiple trans2 responses for one request */
  327. };
  328. struct oplock_q_entry {
  329. struct list_head qhead;
  330. struct inode * pinode;
  331. struct cifsTconInfo * tcon;
  332. __u16 netfid;
  333. };
  334. #define MID_FREE 0
  335. #define MID_REQUEST_ALLOCATED 1
  336. #define MID_REQUEST_SUBMITTED 2
  337. #define MID_RESPONSE_RECEIVED 4
  338. #define MID_RETRY_NEEDED 8 /* session closed while this request out */
  339. #define MID_NO_RESP_NEEDED 0x10
  340. #define MID_SMALL_BUFFER 0x20 /* 112 byte response buffer instead of 4K */
  341. /*
  342. *****************************************************************
  343. * All constants go here
  344. *****************************************************************
  345. */
  346. #define UID_HASH (16)
  347. /*
  348. * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
  349. * following to be declared.
  350. */
  351. /****************************************************************************
  352. * Locking notes. All updates to global variables and lists should be
  353. * protected by spinlocks or semaphores.
  354. *
  355. * Spinlocks
  356. * ---------
  357. * GlobalMid_Lock protects:
  358. * list operations on pending_mid_q and oplockQ
  359. * updates to XID counters, multiplex id and SMB sequence numbers
  360. * GlobalSMBSesLock protects:
  361. * list operations on tcp and SMB session lists and tCon lists
  362. * f_owner.lock protects certain per file struct operations
  363. * mapping->page_lock protects certain per page operations
  364. *
  365. * Semaphores
  366. * ----------
  367. * sesSem operations on smb session
  368. * tconSem operations on tree connection
  369. * fh_sem file handle reconnection operations
  370. *
  371. ****************************************************************************/
  372. #ifdef DECLARE_GLOBALS_HERE
  373. #define GLOBAL_EXTERN
  374. #else
  375. #define GLOBAL_EXTERN extern
  376. #endif
  377. /*
  378. * The list of servers that did not respond with NT LM 0.12.
  379. * This list helps improve performance and eliminate the messages indicating
  380. * that we had a communications error talking to the server in this list.
  381. */
  382. GLOBAL_EXTERN struct servers_not_supported *NotSuppList; /*@z4a */
  383. /*
  384. * The following is a hash table of all the users we know about.
  385. */
  386. GLOBAL_EXTERN struct smbUidInfo *GlobalUidList[UID_HASH];
  387. GLOBAL_EXTERN struct list_head GlobalServerList; /* BB not implemented yet */
  388. GLOBAL_EXTERN struct list_head GlobalSMBSessionList;
  389. GLOBAL_EXTERN struct list_head GlobalTreeConnectionList;
  390. GLOBAL_EXTERN rwlock_t GlobalSMBSeslock; /* protects list inserts on 3 above */
  391. GLOBAL_EXTERN struct list_head GlobalOplock_Q;
  392. /*
  393. * Global transaction id (XID) information
  394. */
  395. GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
  396. GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
  397. GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
  398. GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above and list operations */
  399. /* on midQ entries */
  400. GLOBAL_EXTERN char Local_System_Name[15];
  401. /*
  402. * Global counters, updated atomically
  403. */
  404. GLOBAL_EXTERN atomic_t sesInfoAllocCount;
  405. GLOBAL_EXTERN atomic_t tconInfoAllocCount;
  406. GLOBAL_EXTERN atomic_t tcpSesAllocCount;
  407. GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
  408. GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
  409. /* Various Debug counters to remove someday (BB) */
  410. GLOBAL_EXTERN atomic_t bufAllocCount;
  411. GLOBAL_EXTERN atomic_t smBufAllocCount;
  412. GLOBAL_EXTERN atomic_t midCount;
  413. /* Misc globals */
  414. GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
  415. to be established on existing mount if we
  416. have the uid/password or Kerberos credential
  417. or equivalent for current user */
  418. GLOBAL_EXTERN unsigned int oplockEnabled;
  419. GLOBAL_EXTERN unsigned int experimEnabled;
  420. GLOBAL_EXTERN unsigned int lookupCacheEnabled;
  421. GLOBAL_EXTERN unsigned int extended_security; /* if on, session setup sent
  422. with more secure ntlmssp2 challenge/resp */
  423. GLOBAL_EXTERN unsigned int ntlmv2_support; /* better optional password hash */
  424. GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
  425. GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
  426. GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
  427. GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
  428. GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
  429. GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/