smb_fs.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * smb_fs.h
  3. *
  4. * Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
  5. * Copyright (C) 1997 by Volker Lendecke
  6. *
  7. */
  8. #ifndef _LINUX_SMB_FS_H
  9. #define _LINUX_SMB_FS_H
  10. #include <linux/smb.h>
  11. /*
  12. * ioctl commands
  13. */
  14. #define SMB_IOC_GETMOUNTUID _IOR('u', 1, __kernel_old_uid_t)
  15. #define SMB_IOC_NEWCONN _IOW('u', 2, struct smb_conn_opt)
  16. /* __kernel_uid_t can never change, so we have to use __kernel_uid32_t */
  17. #define SMB_IOC_GETMOUNTUID32 _IOR('u', 3, __kernel_uid32_t)
  18. #ifdef __KERNEL__
  19. #include <linux/smb_fs_i.h>
  20. #include <linux/smb_fs_sb.h>
  21. #include <linux/fs.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/smb_mount.h>
  25. #include <asm/unaligned.h>
  26. static inline struct smb_sb_info *SMB_SB(struct super_block *sb)
  27. {
  28. return sb->s_fs_info;
  29. }
  30. static inline struct smb_inode_info *SMB_I(struct inode *inode)
  31. {
  32. return container_of(inode, struct smb_inode_info, vfs_inode);
  33. }
  34. /* macro names are short for word, double-word, long value (?) */
  35. #define WVAL(buf,pos) \
  36. (le16_to_cpu(get_unaligned((__le16 *)((u8 *)(buf) + (pos)))))
  37. #define DVAL(buf,pos) \
  38. (le32_to_cpu(get_unaligned((__le32 *)((u8 *)(buf) + (pos)))))
  39. #define LVAL(buf,pos) \
  40. (le64_to_cpu(get_unaligned((__le64 *)((u8 *)(buf) + (pos)))))
  41. #define WSET(buf,pos,val) \
  42. put_unaligned(cpu_to_le16((u16)(val)), (__le16 *)((u8 *)(buf) + (pos)))
  43. #define DSET(buf,pos,val) \
  44. put_unaligned(cpu_to_le32((u32)(val)), (__le32 *)((u8 *)(buf) + (pos)))
  45. #define LSET(buf,pos,val) \
  46. put_unaligned(cpu_to_le64((u64)(val)), (__le64 *)((u8 *)(buf) + (pos)))
  47. /* where to find the base of the SMB packet proper */
  48. #define smb_base(buf) ((u8 *)(((u8 *)(buf))+4))
  49. /*
  50. * Flags for the in-memory inode
  51. */
  52. #define SMB_F_LOCALWRITE 0x02 /* file modified locally */
  53. /* NT1 protocol capability bits */
  54. #define SMB_CAP_RAW_MODE 0x00000001
  55. #define SMB_CAP_MPX_MODE 0x00000002
  56. #define SMB_CAP_UNICODE 0x00000004
  57. #define SMB_CAP_LARGE_FILES 0x00000008
  58. #define SMB_CAP_NT_SMBS 0x00000010
  59. #define SMB_CAP_RPC_REMOTE_APIS 0x00000020
  60. #define SMB_CAP_STATUS32 0x00000040
  61. #define SMB_CAP_LEVEL_II_OPLOCKS 0x00000080
  62. #define SMB_CAP_LOCK_AND_READ 0x00000100
  63. #define SMB_CAP_NT_FIND 0x00000200
  64. #define SMB_CAP_DFS 0x00001000
  65. #define SMB_CAP_LARGE_READX 0x00004000
  66. #define SMB_CAP_LARGE_WRITEX 0x00008000
  67. #define SMB_CAP_UNIX 0x00800000 /* unofficial ... */
  68. /*
  69. * This is the time we allow an inode, dentry or dir cache to live. It is bad
  70. * for performance to have shorter ttl on an inode than on the cache. It can
  71. * cause refresh on each inode for a dir listing ... one-by-one
  72. */
  73. #define SMB_MAX_AGE(server) (((server)->mnt->ttl * HZ) / 1000)
  74. static inline void
  75. smb_age_dentry(struct smb_sb_info *server, struct dentry *dentry)
  76. {
  77. dentry->d_time = jiffies - SMB_MAX_AGE(server);
  78. }
  79. struct smb_cache_head {
  80. time_t mtime; /* unused */
  81. unsigned long time; /* cache age */
  82. unsigned long end; /* last valid fpos in cache */
  83. int eof;
  84. };
  85. #define SMB_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
  86. union smb_dir_cache {
  87. struct smb_cache_head head;
  88. struct dentry *dentry[SMB_DIRCACHE_SIZE];
  89. };
  90. #define SMB_FIRSTCACHE_SIZE ((int)((SMB_DIRCACHE_SIZE * \
  91. sizeof(struct dentry *) - sizeof(struct smb_cache_head)) / \
  92. sizeof(struct dentry *)))
  93. #define SMB_DIRCACHE_START (SMB_DIRCACHE_SIZE - SMB_FIRSTCACHE_SIZE)
  94. struct smb_cache_control {
  95. struct smb_cache_head head;
  96. struct page *page;
  97. union smb_dir_cache *cache;
  98. unsigned long fpos, ofs;
  99. int filled, valid, idx;
  100. };
  101. #define SMB_OPS_NUM_STATIC 5
  102. struct smb_ops {
  103. int (*read)(struct inode *inode, loff_t offset, int count,
  104. char *data);
  105. int (*write)(struct inode *inode, loff_t offset, int count, const
  106. char *data);
  107. int (*readdir)(struct file *filp, void *dirent, filldir_t filldir,
  108. struct smb_cache_control *ctl);
  109. int (*getattr)(struct smb_sb_info *server, struct dentry *dir,
  110. struct smb_fattr *fattr);
  111. /* int (*setattr)(...); */ /* setattr is really icky! */
  112. int (*truncate)(struct inode *inode, loff_t length);
  113. /* --- --- --- end of "static" entries --- --- --- */
  114. int (*convert)(unsigned char *output, int olen,
  115. const unsigned char *input, int ilen,
  116. struct nls_table *nls_from,
  117. struct nls_table *nls_to);
  118. };
  119. static inline int
  120. smb_is_open(struct inode *i)
  121. {
  122. return (SMB_I(i)->open == server_from_inode(i)->generation);
  123. }
  124. extern void smb_install_null_ops(struct smb_ops *);
  125. #endif /* __KERNEL__ */
  126. #endif /* _LINUX_SMB_FS_H */