Linux-2.6.12-rc2
[safe/jmp/linux-2.6] / fs / ncpfs / ncplib_kernel.h
1 /*
2  *  ncplib_kernel.h
3  *
4  *  Copyright (C) 1995, 1996 by Volker Lendecke
5  *  Modified for big endian by J.F. Chadima and David S. Miller
6  *  Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
7  *  Modified 1998, 1999 Wolfram Pienkoss for NLS
8  *  Modified 1999 Wolfram Pienkoss for directory caching
9  *
10  */
11
12 #ifndef _NCPLIB_H
13 #define _NCPLIB_H
14
15 #include <linux/config.h>
16
17 #include <linux/fs.h>
18 #include <linux/types.h>
19 #include <linux/errno.h>
20 #include <linux/slab.h>
21 #include <linux/stat.h>
22 #include <linux/fcntl.h>
23 #include <linux/pagemap.h>
24
25 #include <asm/uaccess.h>
26 #include <asm/byteorder.h>
27 #include <asm/unaligned.h>
28 #include <asm/string.h>
29
30 #ifdef CONFIG_NCPFS_NLS
31 #include <linux/nls.h>
32 #else
33 #include <linux/ctype.h>
34 #endif /* CONFIG_NCPFS_NLS */
35
36 #include <linux/ncp_fs.h>
37
38 #define NCP_MIN_SYMLINK_SIZE    8
39 #define NCP_MAX_SYMLINK_SIZE    512
40
41 #define NCP_BLOCK_SHIFT         9
42 #define NCP_BLOCK_SIZE          (1 << (NCP_BLOCK_SHIFT))
43
44 int ncp_negotiate_buffersize(struct ncp_server *, int, int *);
45 int ncp_negotiate_size_and_options(struct ncp_server *server, int size,
46                           int options, int *ret_size, int *ret_options);
47
48 int ncp_get_volume_info_with_number(struct ncp_server* server, int n,
49                                     struct ncp_volume_info *target);
50
51 int ncp_get_directory_info(struct ncp_server* server, __u8 dirhandle,
52                            struct ncp_volume_info* target);
53
54 int ncp_close_file(struct ncp_server *, const char *);
55 static inline int ncp_read_bounce_size(__u32 size) {
56         return sizeof(struct ncp_reply_header) + 2 + 2 + size + 8;
57 };
58 int ncp_read_bounce(struct ncp_server *, const char *, __u32, __u16, 
59                 char __user *, int *, void* bounce, __u32 bouncelen);
60 int ncp_read_kernel(struct ncp_server *, const char *, __u32, __u16, 
61                 char *, int *);
62 int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16,
63                 const char *, int *);
64
65 static inline void ncp_inode_close(struct inode *inode) {
66         atomic_dec(&NCP_FINFO(inode)->opened);
67 }
68
69 void ncp_extract_file_info(void* src, struct nw_info_struct* target);
70 int ncp_obtain_info(struct ncp_server *server, struct inode *, char *,
71                 struct nw_info_struct *target);
72 int ncp_obtain_nfs_info(struct ncp_server *server, struct nw_info_struct *target);
73 int ncp_get_volume_root(struct ncp_server *server, const char *volname,
74                         __u32 *volume, __le32 *dirent, __le32 *dosdirent);
75 int ncp_lookup_volume(struct ncp_server *, const char *, struct nw_info_struct *);
76 int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
77          __le32, const struct nw_modify_dos_info *info);
78 int ncp_modify_file_or_subdir_dos_info_path(struct ncp_server *, struct inode *,
79          const char* path, __le32, const struct nw_modify_dos_info *info);
80 int ncp_modify_nfs_info(struct ncp_server *, __u8 volnum, __le32 dirent,
81                         __u32 mode, __u32 rdev);
82
83 int ncp_del_file_or_subdir2(struct ncp_server *, struct dentry*);
84 int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, char *);
85 int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, char *,
86                                 int, __le32, __le16, struct ncp_entry_info *);
87
88 int ncp_initialize_search(struct ncp_server *, struct inode *,
89                       struct nw_search_sequence *target);
90 int ncp_search_for_file_or_subdir(struct ncp_server *server,
91                               struct nw_search_sequence *seq,
92                               struct nw_info_struct *target);
93 int ncp_search_for_fileset(struct ncp_server *server,
94                            struct nw_search_sequence *seq,
95                            int* more, int* cnt,
96                            char* buffer, size_t bufsize,
97                            char** rbuf, size_t* rsize);
98
99 int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
100                               struct inode *, char *, struct inode *, char *);
101
102
103 int
104 ncp_LogPhysicalRecord(struct ncp_server *server,
105                       const char *file_id, __u8 locktype,
106                       __u32 offset, __u32 length, __u16 timeout);
107
108 #ifdef CONFIG_NCPFS_IOCTL_LOCKING
109 int
110 ncp_ClearPhysicalRecord(struct ncp_server *server,
111                         const char *file_id,
112                         __u32 offset, __u32 length);
113 #endif  /* CONFIG_NCPFS_IOCTL_LOCKING */
114
115 int
116 ncp_mount_subdir(struct ncp_server *, __u8, __u8, __le32,
117                  __u32* volume, __le32* dirent, __le32* dosdirent);
118 int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __le32 dirent, __u8 *dirhandle);
119 int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle);
120
121 int ncp_create_new(struct inode *dir, struct dentry *dentry,
122                           int mode, dev_t rdev, __le32 attributes);
123
124 static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int volnum) {
125 #ifdef CONFIG_NCPFS_NFS_NS
126         return (server->m.flags & NCP_MOUNT_NFS_EXTRAS) &&
127                (server->name_space[volnum] == NW_NS_NFS);
128 #else
129         return 0;
130 #endif
131 }
132
133 #ifdef CONFIG_NCPFS_NLS
134
135 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
136                                 const unsigned char *, unsigned int, int);
137 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
138                                 const unsigned char *, unsigned int, int);
139
140 #define NCP_ESC                 ':'
141 #define NCP_IO_TABLE(dentry)    (NCP_SERVER((dentry)->d_inode)->nls_io)
142 #define ncp_tolower(t, c)       nls_tolower(t, c)
143 #define ncp_toupper(t, c)       nls_toupper(t, c)
144 #define ncp_strnicmp(t, s1, s2, len) \
145         nls_strnicmp(t, s1, s2, len)
146 #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U)
147 #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U)
148
149 #else
150
151 int ncp__io2vol(unsigned char *, unsigned int *,
152                                 const unsigned char *, unsigned int, int);
153 int ncp__vol2io(unsigned char *, unsigned int *,
154                                 const unsigned char *, unsigned int, int);
155
156 #define NCP_IO_TABLE(dentry)    NULL
157 #define ncp_tolower(t, c)       tolower(c)
158 #define ncp_toupper(t, c)       toupper(c)
159 #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U)
160 #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U)
161
162
163 static inline int ncp_strnicmp(struct nls_table *t, const unsigned char *s1,
164                 const unsigned char *s2, int len)
165 {
166         while (len--) {
167                 if (tolower(*s1++) != tolower(*s2++))
168                         return 1;
169         }
170
171         return 0;
172 }
173
174 #endif /* CONFIG_NCPFS_NLS */
175
176 #define NCP_GET_AGE(dentry)     (jiffies - (dentry)->d_time)
177 #define NCP_MAX_AGE(server)     ((server)->dentry_ttl)
178 #define NCP_TEST_AGE(server,dentry)     (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server))
179
180 static inline void
181 ncp_age_dentry(struct ncp_server* server, struct dentry* dentry)
182 {
183         dentry->d_time = jiffies - server->dentry_ttl;
184 }
185
186 static inline void
187 ncp_new_dentry(struct dentry* dentry)
188 {
189         dentry->d_time = jiffies;
190 }
191
192 static inline void
193 ncp_renew_dentries(struct dentry *parent)
194 {
195         struct ncp_server *server = NCP_SERVER(parent->d_inode);
196         struct list_head *next;
197         struct dentry *dentry;
198
199         spin_lock(&dcache_lock);
200         next = parent->d_subdirs.next;
201         while (next != &parent->d_subdirs) {
202                 dentry = list_entry(next, struct dentry, d_child);
203
204                 if (dentry->d_fsdata == NULL)
205                         ncp_age_dentry(server, dentry);
206                 else
207                         ncp_new_dentry(dentry);
208
209                 next = next->next;
210         }
211         spin_unlock(&dcache_lock);
212 }
213
214 static inline void
215 ncp_invalidate_dircache_entries(struct dentry *parent)
216 {
217         struct ncp_server *server = NCP_SERVER(parent->d_inode);
218         struct list_head *next;
219         struct dentry *dentry;
220
221         spin_lock(&dcache_lock);
222         next = parent->d_subdirs.next;
223         while (next != &parent->d_subdirs) {
224                 dentry = list_entry(next, struct dentry, d_child);
225                 dentry->d_fsdata = NULL;
226                 ncp_age_dentry(server, dentry);
227                 next = next->next;
228         }
229         spin_unlock(&dcache_lock);
230 }
231
232 struct ncp_cache_head {
233         time_t          mtime;
234         unsigned long   time;   /* cache age */
235         unsigned long   end;    /* last valid fpos in cache */
236         int             eof;
237 };
238
239 #define NCP_DIRCACHE_SIZE       ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
240 union ncp_dir_cache {
241         struct ncp_cache_head   head;
242         struct dentry           *dentry[NCP_DIRCACHE_SIZE];
243 };
244
245 #define NCP_FIRSTCACHE_SIZE     ((int)((NCP_DIRCACHE_SIZE * \
246         sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \
247         sizeof(struct dentry *)))
248
249 #define NCP_DIRCACHE_START      (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
250
251 struct ncp_cache_control {
252         struct  ncp_cache_head          head;
253         struct  page                    *page;
254         union   ncp_dir_cache           *cache;
255         unsigned long                   fpos, ofs;
256         int                             filled, valid, idx;
257 };
258
259 #endif /* _NCPLIB_H */