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