blob: c4153120ade634391c295eb97d6a046d2ba23b90 [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>
13#include <linux/smb_fs_i.h>
14#include <linux/smb_fs_sb.h>
15
16/*
17 * ioctl commands
18 */
19#define SMB_IOC_GETMOUNTUID _IOR('u', 1, __kernel_old_uid_t)
20#define SMB_IOC_NEWCONN _IOW('u', 2, struct smb_conn_opt)
21
22/* __kernel_uid_t can never change, so we have to use __kernel_uid32_t */
23#define SMB_IOC_GETMOUNTUID32 _IOR('u', 3, __kernel_uid32_t)
24
25
26#ifdef __KERNEL__
27
28#include <linux/fs.h>
29#include <linux/pagemap.h>
30#include <linux/vmalloc.h>
31#include <linux/smb_mount.h>
32#include <asm/unaligned.h>
33
34static inline struct smb_sb_info *SMB_SB(struct super_block *sb)
35{
36 return sb->s_fs_info;
37}
38
39static inline struct smb_inode_info *SMB_I(struct inode *inode)
40{
41 return container_of(inode, struct smb_inode_info, vfs_inode);
42}
43
44/* macro names are short for word, double-word, long value (?) */
45#define WVAL(buf,pos) \
46 (le16_to_cpu(get_unaligned((u16 *)((u8 *)(buf) + (pos)))))
47#define DVAL(buf,pos) \
48 (le32_to_cpu(get_unaligned((u32 *)((u8 *)(buf) + (pos)))))
49#define LVAL(buf,pos) \
50 (le64_to_cpu(get_unaligned((u64 *)((u8 *)(buf) + (pos)))))
51#define WSET(buf,pos,val) \
52 put_unaligned(cpu_to_le16((u16)(val)), (u16 *)((u8 *)(buf) + (pos)))
53#define DSET(buf,pos,val) \
54 put_unaligned(cpu_to_le32((u32)(val)), (u32 *)((u8 *)(buf) + (pos)))
55#define LSET(buf,pos,val) \
56 put_unaligned(cpu_to_le64((u64)(val)), (u64 *)((u8 *)(buf) + (pos)))
57
58/* where to find the base of the SMB packet proper */
59#define smb_base(buf) ((u8 *)(((u8 *)(buf))+4))
60
61#ifdef DEBUG_SMB_MALLOC
62
63#include <linux/slab.h>
64
65extern int smb_malloced;
66extern int smb_current_vmalloced;
67extern int smb_current_kmalloced;
68
69static inline void *
70smb_vmalloc(unsigned int size)
71{
72 smb_malloced += 1;
73 smb_current_vmalloced += 1;
74 return vmalloc(size);
75}
76
77static inline void
78smb_vfree(void *obj)
79{
80 smb_current_vmalloced -= 1;
81 vfree(obj);
82}
83
84static inline void *
85smb_kmalloc(size_t size, int flags)
86{
87 smb_malloced += 1;
88 smb_current_kmalloced += 1;
89 return kmalloc(size, flags);
90}
91
92static inline void
93smb_kfree(void *obj)
94{
95 smb_current_kmalloced -= 1;
96 kfree(obj);
97}
98
99#else /* DEBUG_SMB_MALLOC */
100
101#define smb_kmalloc(s,p) kmalloc(s,p)
102#define smb_kfree(o) kfree(o)
103#define smb_vmalloc(s) vmalloc(s)
104#define smb_vfree(o) vfree(o)
105
106#endif /* DEBUG_SMB_MALLOC */
107
108/*
109 * Flags for the in-memory inode
110 */
111#define SMB_F_LOCALWRITE 0x02 /* file modified locally */
112
113
114/* NT1 protocol capability bits */
115#define SMB_CAP_RAW_MODE 0x00000001
116#define SMB_CAP_MPX_MODE 0x00000002
117#define SMB_CAP_UNICODE 0x00000004
118#define SMB_CAP_LARGE_FILES 0x00000008
119#define SMB_CAP_NT_SMBS 0x00000010
120#define SMB_CAP_RPC_REMOTE_APIS 0x00000020
121#define SMB_CAP_STATUS32 0x00000040
122#define SMB_CAP_LEVEL_II_OPLOCKS 0x00000080
123#define SMB_CAP_LOCK_AND_READ 0x00000100
124#define SMB_CAP_NT_FIND 0x00000200
125#define SMB_CAP_DFS 0x00001000
126#define SMB_CAP_LARGE_READX 0x00004000
127#define SMB_CAP_LARGE_WRITEX 0x00008000
128#define SMB_CAP_UNIX 0x00800000 /* unofficial ... */
129
130
131/*
132 * This is the time we allow an inode, dentry or dir cache to live. It is bad
133 * for performance to have shorter ttl on an inode than on the cache. It can
134 * cause refresh on each inode for a dir listing ... one-by-one
135 */
136#define SMB_MAX_AGE(server) (((server)->mnt->ttl * HZ) / 1000)
137
138static inline void
139smb_age_dentry(struct smb_sb_info *server, struct dentry *dentry)
140{
141 dentry->d_time = jiffies - SMB_MAX_AGE(server);
142}
143
144struct smb_cache_head {
145 time_t mtime; /* unused */
146 unsigned long time; /* cache age */
147 unsigned long end; /* last valid fpos in cache */
148 int eof;
149};
150
151#define SMB_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
152union smb_dir_cache {
153 struct smb_cache_head head;
154 struct dentry *dentry[SMB_DIRCACHE_SIZE];
155};
156
157#define SMB_FIRSTCACHE_SIZE ((int)((SMB_DIRCACHE_SIZE * \
158 sizeof(struct dentry *) - sizeof(struct smb_cache_head)) / \
159 sizeof(struct dentry *)))
160
161#define SMB_DIRCACHE_START (SMB_DIRCACHE_SIZE - SMB_FIRSTCACHE_SIZE)
162
163struct smb_cache_control {
164 struct smb_cache_head head;
165 struct page *page;
166 union smb_dir_cache *cache;
167 unsigned long fpos, ofs;
168 int filled, valid, idx;
169};
170
171#define SMB_OPS_NUM_STATIC 5
172struct smb_ops {
173 int (*read)(struct inode *inode, loff_t offset, int count,
174 char *data);
175 int (*write)(struct inode *inode, loff_t offset, int count, const
176 char *data);
177 int (*readdir)(struct file *filp, void *dirent, filldir_t filldir,
178 struct smb_cache_control *ctl);
179
180 int (*getattr)(struct smb_sb_info *server, struct dentry *dir,
181 struct smb_fattr *fattr);
182 /* int (*setattr)(...); */ /* setattr is really icky! */
183
184 int (*truncate)(struct inode *inode, loff_t length);
185
186
187 /* --- --- --- end of "static" entries --- --- --- */
188
189 int (*convert)(unsigned char *output, int olen,
190 const unsigned char *input, int ilen,
191 struct nls_table *nls_from,
192 struct nls_table *nls_to);
193};
194
195static inline int
196smb_is_open(struct inode *i)
197{
198 return (SMB_I(i)->open == server_from_inode(i)->generation);
199}
200
201extern void smb_install_null_ops(struct smb_ops *);
202#endif /* __KERNEL__ */
203
204#endif /* _LINUX_SMB_FS_H */