blob: 923cd8a247b103bfeae72cc2680b55db0636d8ad [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
9#ifndef _LINUX_SMB_FS_H
10#define _LINUX_SMB_FS_H
11
12#include <linux/smb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/*
15 * ioctl commands
16 */
17#define SMB_IOC_GETMOUNTUID _IOR('u', 1, __kernel_old_uid_t)
18#define SMB_IOC_NEWCONN _IOW('u', 2, struct smb_conn_opt)
19
20/* __kernel_uid_t can never change, so we have to use __kernel_uid32_t */
21#define SMB_IOC_GETMOUNTUID32 _IOR('u', 3, __kernel_uid32_t)
22
23
24#ifdef __KERNEL__
David Woodhouse19b3bd62006-04-25 15:18:05 +010025#include <linux/smb_fs_i.h>
26#include <linux/smb_fs_sb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include <linux/fs.h>
29#include <linux/pagemap.h>
30#include <linux/vmalloc.h>
31#include <linux/smb_mount.h>
Stephen Rothwelld2579052007-05-22 11:10:19 +100032#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/unaligned.h>
34
35static inline struct smb_sb_info *SMB_SB(struct super_block *sb)
36{
37 return sb->s_fs_info;
38}
39
40static inline struct smb_inode_info *SMB_I(struct inode *inode)
41{
42 return container_of(inode, struct smb_inode_info, vfs_inode);
43}
44
45/* macro names are short for word, double-word, long value (?) */
Harvey Harrison8b5ac312008-07-25 01:45:26 -070046#define WVAL(buf, pos) (get_unaligned_le16((u8 *)(buf) + (pos)))
47#define DVAL(buf, pos) (get_unaligned_le32((u8 *)(buf) + (pos)))
48#define LVAL(buf, pos) (get_unaligned_le64((u8 *)(buf) + (pos)))
49
50#define WSET(buf, pos, val) put_unaligned_le16((val), (u8 *)(buf) + (pos))
51#define DSET(buf, pos, val) put_unaligned_le32((val), (u8 *)(buf) + (pos))
52#define LSET(buf, pos, val) put_unaligned_le64((val), (u8 *)(buf) + (pos))
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/* where to find the base of the SMB packet proper */
55#define smb_base(buf) ((u8 *)(((u8 *)(buf))+4))
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Flags for the in-memory inode
59 */
60#define SMB_F_LOCALWRITE 0x02 /* file modified locally */
61
62
63/* NT1 protocol capability bits */
64#define SMB_CAP_RAW_MODE 0x00000001
65#define SMB_CAP_MPX_MODE 0x00000002
66#define SMB_CAP_UNICODE 0x00000004
67#define SMB_CAP_LARGE_FILES 0x00000008
68#define SMB_CAP_NT_SMBS 0x00000010
69#define SMB_CAP_RPC_REMOTE_APIS 0x00000020
70#define SMB_CAP_STATUS32 0x00000040
71#define SMB_CAP_LEVEL_II_OPLOCKS 0x00000080
72#define SMB_CAP_LOCK_AND_READ 0x00000100
73#define SMB_CAP_NT_FIND 0x00000200
74#define SMB_CAP_DFS 0x00001000
75#define SMB_CAP_LARGE_READX 0x00004000
76#define SMB_CAP_LARGE_WRITEX 0x00008000
77#define SMB_CAP_UNIX 0x00800000 /* unofficial ... */
78
79
80/*
81 * This is the time we allow an inode, dentry or dir cache to live. It is bad
82 * for performance to have shorter ttl on an inode than on the cache. It can
83 * cause refresh on each inode for a dir listing ... one-by-one
84 */
85#define SMB_MAX_AGE(server) (((server)->mnt->ttl * HZ) / 1000)
86
87static inline void
88smb_age_dentry(struct smb_sb_info *server, struct dentry *dentry)
89{
90 dentry->d_time = jiffies - SMB_MAX_AGE(server);
91}
92
93struct smb_cache_head {
94 time_t mtime; /* unused */
95 unsigned long time; /* cache age */
96 unsigned long end; /* last valid fpos in cache */
97 int eof;
98};
99
100#define SMB_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
101union smb_dir_cache {
102 struct smb_cache_head head;
103 struct dentry *dentry[SMB_DIRCACHE_SIZE];
104};
105
106#define SMB_FIRSTCACHE_SIZE ((int)((SMB_DIRCACHE_SIZE * \
107 sizeof(struct dentry *) - sizeof(struct smb_cache_head)) / \
108 sizeof(struct dentry *)))
109
110#define SMB_DIRCACHE_START (SMB_DIRCACHE_SIZE - SMB_FIRSTCACHE_SIZE)
111
112struct smb_cache_control {
113 struct smb_cache_head head;
114 struct page *page;
115 union smb_dir_cache *cache;
116 unsigned long fpos, ofs;
117 int filled, valid, idx;
118};
119
120#define SMB_OPS_NUM_STATIC 5
121struct smb_ops {
122 int (*read)(struct inode *inode, loff_t offset, int count,
123 char *data);
124 int (*write)(struct inode *inode, loff_t offset, int count, const
125 char *data);
126 int (*readdir)(struct file *filp, void *dirent, filldir_t filldir,
127 struct smb_cache_control *ctl);
128
129 int (*getattr)(struct smb_sb_info *server, struct dentry *dir,
130 struct smb_fattr *fattr);
131 /* int (*setattr)(...); */ /* setattr is really icky! */
132
133 int (*truncate)(struct inode *inode, loff_t length);
134
135
136 /* --- --- --- end of "static" entries --- --- --- */
137
138 int (*convert)(unsigned char *output, int olen,
139 const unsigned char *input, int ilen,
140 struct nls_table *nls_from,
141 struct nls_table *nls_to);
142};
143
144static inline int
145smb_is_open(struct inode *i)
146{
147 return (SMB_I(i)->open == server_from_inode(i)->generation);
148}
149
150extern void smb_install_null_ops(struct smb_ops *);
151#endif /* __KERNEL__ */
152
153#endif /* _LINUX_SMB_FS_H */