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
15 #include <linux/config.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>
25 #include <asm/uaccess.h>
26 #include <asm/byteorder.h>
27 #include <asm/unaligned.h>
28 #include <asm/string.h>
30 #ifdef CONFIG_NCPFS_NLS
31 #include <linux/nls.h>
33 #include <linux/ctype.h>
34 #endif /* CONFIG_NCPFS_NLS */
36 #include <linux/ncp_fs.h>
38 #define NCP_MIN_SYMLINK_SIZE 8
39 #define NCP_MAX_SYMLINK_SIZE 512
41 #define NCP_BLOCK_SHIFT 9
42 #define NCP_BLOCK_SIZE (1 << (NCP_BLOCK_SHIFT))
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);
48 int ncp_get_volume_info_with_number(struct ncp_server* server, int n,
49 struct ncp_volume_info *target);
51 int ncp_get_directory_info(struct ncp_server* server, __u8 dirhandle,
52 struct ncp_volume_info* target);
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;
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,
62 int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16,
65 static inline void ncp_inode_close(struct inode *inode) {
66 atomic_dec(&NCP_FINFO(inode)->opened);
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_lookup_volume(struct ncp_server *, char *, struct nw_info_struct *);
74 int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
75 __u32, 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, __u32, const struct nw_modify_dos_info *info);
78 int ncp_modify_nfs_info(struct ncp_server *, __u8 volnum, __u32 dirent,
79 __u32 mode, __u32 rdev);
81 int ncp_del_file_or_subdir2(struct ncp_server *, struct dentry*);
82 int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, char *);
83 int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, char *,
84 int, __u32, int, struct ncp_entry_info *);
86 int ncp_initialize_search(struct ncp_server *, struct inode *,
87 struct nw_search_sequence *target);
88 int ncp_search_for_file_or_subdir(struct ncp_server *server,
89 struct nw_search_sequence *seq,
90 struct nw_info_struct *target);
91 int ncp_search_for_fileset(struct ncp_server *server,
92 struct nw_search_sequence *seq,
94 char* buffer, size_t bufsize,
95 char** rbuf, size_t* rsize);
97 int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
98 struct inode *, char *, struct inode *, char *);
102 ncp_LogPhysicalRecord(struct ncp_server *server,
103 const char *file_id, __u8 locktype,
104 __u32 offset, __u32 length, __u16 timeout);
106 #ifdef CONFIG_NCPFS_IOCTL_LOCKING
108 ncp_ClearPhysicalRecord(struct ncp_server *server,
110 __u32 offset, __u32 length);
111 #endif /* CONFIG_NCPFS_IOCTL_LOCKING */
114 ncp_mount_subdir(struct ncp_server *, struct nw_info_struct *,
116 int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __u32 dirent, __u8 *dirhandle);
117 int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle);
119 int ncp_create_new(struct inode *dir, struct dentry *dentry,
120 int mode, dev_t rdev, int attributes);
122 static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int volnum) {
123 #ifdef CONFIG_NCPFS_NFS_NS
124 return (server->m.flags & NCP_MOUNT_NFS_EXTRAS) &&
125 (server->name_space[volnum] == NW_NS_NFS);
131 #ifdef CONFIG_NCPFS_NLS
133 unsigned char ncp__tolower(struct nls_table *, unsigned char);
134 unsigned char ncp__toupper(struct nls_table *, unsigned char);
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);
141 #define NCP_IO_TABLE(dentry) (NCP_SERVER((dentry)->d_inode)->nls_io)
142 #define ncp_tolower(t, c) ncp__tolower(t, c)
143 #define ncp_toupper(t, c) ncp__toupper(t, c)
144 #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U)
145 #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U)
149 int ncp__io2vol(unsigned char *, unsigned int *,
150 const unsigned char *, unsigned int, int);
151 int ncp__vol2io(unsigned char *, unsigned int *,
152 const unsigned char *, unsigned int, int);
154 #define NCP_IO_TABLE(dentry) NULL
155 #define ncp_tolower(t, c) tolower(c)
156 #define ncp_toupper(t, c) toupper(c)
157 #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U)
158 #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U)
160 #endif /* CONFIG_NCPFS_NLS */
163 ncp_strnicmp(struct nls_table *,
164 const unsigned char *, const unsigned char *, int);
166 #define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time)
167 #define NCP_MAX_AGE(server) ((server)->dentry_ttl)
168 #define NCP_TEST_AGE(server,dentry) (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server))
171 ncp_age_dentry(struct ncp_server* server, struct dentry* dentry)
173 dentry->d_time = jiffies - server->dentry_ttl;
177 ncp_new_dentry(struct dentry* dentry)
179 dentry->d_time = jiffies;
183 ncp_renew_dentries(struct dentry *parent)
185 struct ncp_server *server = NCP_SERVER(parent->d_inode);
186 struct list_head *next;
187 struct dentry *dentry;
189 spin_lock(&dcache_lock);
190 next = parent->d_subdirs.next;
191 while (next != &parent->d_subdirs) {
192 dentry = list_entry(next, struct dentry, d_child);
194 if (dentry->d_fsdata == NULL)
195 ncp_age_dentry(server, dentry);
197 ncp_new_dentry(dentry);
201 spin_unlock(&dcache_lock);
205 ncp_invalidate_dircache_entries(struct dentry *parent)
207 struct ncp_server *server = NCP_SERVER(parent->d_inode);
208 struct list_head *next;
209 struct dentry *dentry;
211 spin_lock(&dcache_lock);
212 next = parent->d_subdirs.next;
213 while (next != &parent->d_subdirs) {
214 dentry = list_entry(next, struct dentry, d_child);
215 dentry->d_fsdata = NULL;
216 ncp_age_dentry(server, dentry);
219 spin_unlock(&dcache_lock);
222 struct ncp_cache_head {
224 unsigned long time; /* cache age */
225 unsigned long end; /* last valid fpos in cache */
229 #define NCP_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
230 union ncp_dir_cache {
231 struct ncp_cache_head head;
232 struct dentry *dentry[NCP_DIRCACHE_SIZE];
235 #define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * \
236 sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \
237 sizeof(struct dentry *)))
239 #define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
241 struct ncp_cache_control {
242 struct ncp_cache_head head;
244 union ncp_dir_cache *cache;
245 unsigned long fpos, ofs;
246 int filled, valid, idx;
249 #endif /* _NCPLIB_H */