blob: 250e443a07f32ec8188aa4f98db5bbeadcf59f19 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#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
41int ncp_negotiate_buffersize(struct ncp_server *, int, int *);
42int ncp_negotiate_size_and_options(struct ncp_server *server, int size,
43 int options, int *ret_size, int *ret_options);
44
45int ncp_get_volume_info_with_number(struct ncp_server* server, int n,
46 struct ncp_volume_info *target);
47
48int ncp_get_directory_info(struct ncp_server* server, __u8 dirhandle,
49 struct ncp_volume_info* target);
50
51int ncp_close_file(struct ncp_server *, const char *);
52static inline int ncp_read_bounce_size(__u32 size) {
53 return sizeof(struct ncp_reply_header) + 2 + 2 + size + 8;
54};
55int ncp_read_bounce(struct ncp_server *, const char *, __u32, __u16,
56 char __user *, int *, void* bounce, __u32 bouncelen);
57int ncp_read_kernel(struct ncp_server *, const char *, __u32, __u16,
58 char *, int *);
59int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16,
60 const char *, int *);
61
62static inline void ncp_inode_close(struct inode *inode) {
63 atomic_dec(&NCP_FINFO(inode)->opened);
64}
65
Petr Vandrovec2e54eb92010-09-27 01:47:33 +020066void ncp_extract_file_info(const void* src, struct nw_info_struct* target);
67int ncp_obtain_info(struct ncp_server *server, struct inode *, const char *,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 struct nw_info_struct *target);
69int ncp_obtain_nfs_info(struct ncp_server *server, struct nw_info_struct *target);
Petr Vandrovec2e54eb92010-09-27 01:47:33 +020070int ncp_update_known_namespace(struct ncp_server *server, __u8 volume, int *ret_ns);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071int ncp_get_volume_root(struct ncp_server *server, const char *volname,
72 __u32 *volume, __le32 *dirent, __le32 *dosdirent);
73int ncp_lookup_volume(struct ncp_server *, const char *, struct nw_info_struct *);
74int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
75 __le32, const struct nw_modify_dos_info *info);
76int 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);
78int ncp_modify_nfs_info(struct ncp_server *, __u8 volnum, __le32 dirent,
79 __u32 mode, __u32 rdev);
80
81int ncp_del_file_or_subdir2(struct ncp_server *, struct dentry*);
Petr Vandrovec2e54eb92010-09-27 01:47:33 +020082int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, const char *);
83int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, const char *,
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 int, __le32, __le16, struct ncp_entry_info *);
85
86int ncp_initialize_search(struct ncp_server *, struct inode *,
87 struct nw_search_sequence *target);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088int 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
94int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
Petr Vandrovec2e54eb92010-09-27 01:47:33 +020095 struct inode *, const char *, struct inode *, const char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97
98int
99ncp_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
104int
105ncp_ClearPhysicalRecord(struct ncp_server *server,
106 const char *file_id,
107 __u32 offset, __u32 length);
108#endif /* CONFIG_NCPFS_IOCTL_LOCKING */
109
110int
111ncp_mount_subdir(struct ncp_server *, __u8, __u8, __le32,
112 __u32* volume, __le32* dirent, __le32* dosdirent);
113int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __le32 dirent, __u8 *dirhandle);
114int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle);
115
116int ncp_create_new(struct inode *dir, struct dentry *dentry,
Al Viro5eee25c2011-07-26 03:12:16 -0400117 umode_t mode, dev_t rdev, __le32 attributes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119static 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
130int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
131 const unsigned char *, unsigned int, int);
132int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
133 const unsigned char *, unsigned int, int);
134
135#define NCP_ESC ':'
Nick Piggin621e1552011-01-07 17:49:27 +1100136#define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#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
146int ncp__io2vol(unsigned char *, unsigned int *,
147 const unsigned char *, unsigned int, int);
148int ncp__vol2io(unsigned char *, unsigned int *,
149 const unsigned char *, unsigned int, int);
150
Nick Piggin621e1552011-01-07 17:49:27 +1100151#define NCP_IO_TABLE(sb) NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#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
Nick Piggin621e1552011-01-07 17:49:27 +1100158static inline int ncp_strnicmp(const struct nls_table *t,
159 const unsigned char *s1, const unsigned char *s2, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
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)
Petr Vandrovec2e54eb92010-09-27 01:47:33 +0200172#define NCP_MAX_AGE(server) atomic_read(&(server)->dentry_ttl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#define NCP_TEST_AGE(server,dentry) (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server))
174
175static inline void
176ncp_age_dentry(struct ncp_server* server, struct dentry* dentry)
177{
Petr Vandrovec2e54eb92010-09-27 01:47:33 +0200178 dentry->d_time = jiffies - NCP_MAX_AGE(server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
181static inline void
182ncp_new_dentry(struct dentry* dentry)
183{
184 dentry->d_time = jiffies;
185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187struct ncp_cache_head {
188 time_t mtime;
189 unsigned long time; /* cache age */
190 unsigned long end; /* last valid fpos in cache */
191 int eof;
192};
193
194#define NCP_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
195union ncp_dir_cache {
196 struct ncp_cache_head head;
197 struct dentry *dentry[NCP_DIRCACHE_SIZE];
198};
199
200#define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * \
201 sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \
202 sizeof(struct dentry *)))
203
204#define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
205
206struct ncp_cache_control {
207 struct ncp_cache_head head;
208 struct page *page;
209 union ncp_dir_cache *cache;
210 unsigned long fpos, ofs;
211 int filled, valid, idx;
212};
213
214#endif /* _NCPLIB_H */