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