]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/ncpfs/ncplib_kernel.h
UBUNTU: Ubuntu-4.15.0-96.97
[mirror_ubuntu-bionic-kernel.git] / fs / ncpfs / ncplib_kernel.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*
3 * ncplib_kernel.h
4 *
5 * Copyright (C) 1995, 1996 by Volker Lendecke
6 * Modified for big endian by J.F. Chadima and David S. Miller
7 * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache
8 * Modified 1998, 1999 Wolfram Pienkoss for NLS
9 * Modified 1999 Wolfram Pienkoss for directory caching
10 *
11 */
12
13#ifndef _NCPLIB_H
14#define _NCPLIB_H
15
1da177e4
LT
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
7c0f6ba6 25#include <linux/uaccess.h>
1da177e4
LT
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
1da177e4
LT
36#define NCP_MIN_SYMLINK_SIZE 8
37#define NCP_MAX_SYMLINK_SIZE 512
38
39#define NCP_BLOCK_SHIFT 9
40#define NCP_BLOCK_SIZE (1 << (NCP_BLOCK_SHIFT))
41
42int ncp_negotiate_buffersize(struct ncp_server *, int, int *);
43int ncp_negotiate_size_and_options(struct ncp_server *server, int size,
44 int options, int *ret_size, int *ret_options);
45
46int ncp_get_volume_info_with_number(struct ncp_server* server, int n,
47 struct ncp_volume_info *target);
48
49int ncp_get_directory_info(struct ncp_server* server, __u8 dirhandle,
50 struct ncp_volume_info* target);
51
52int ncp_close_file(struct ncp_server *, const char *);
53static inline int ncp_read_bounce_size(__u32 size) {
54 return sizeof(struct ncp_reply_header) + 2 + 2 + size + 8;
55};
56int ncp_read_bounce(struct ncp_server *, const char *, __u32, __u16,
274a4886 57 struct iov_iter *, int *, void *bounce, __u32 bouncelen);
1da177e4
LT
58int ncp_read_kernel(struct ncp_server *, const char *, __u32, __u16,
59 char *, int *);
60int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16,
61 const char *, int *);
62
63static inline void ncp_inode_close(struct inode *inode) {
64 atomic_dec(&NCP_FINFO(inode)->opened);
65}
66
2e54eb96
PV
67void ncp_extract_file_info(const void* src, struct nw_info_struct* target);
68int ncp_obtain_info(struct ncp_server *server, struct inode *, const char *,
1da177e4
LT
69 struct nw_info_struct *target);
70int ncp_obtain_nfs_info(struct ncp_server *server, struct nw_info_struct *target);
2e54eb96 71int ncp_update_known_namespace(struct ncp_server *server, __u8 volume, int *ret_ns);
1da177e4
LT
72int ncp_get_volume_root(struct ncp_server *server, const char *volname,
73 __u32 *volume, __le32 *dirent, __le32 *dosdirent);
74int ncp_lookup_volume(struct ncp_server *, const char *, struct nw_info_struct *);
75int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
76 __le32, const struct nw_modify_dos_info *info);
77int ncp_modify_file_or_subdir_dos_info_path(struct ncp_server *, struct inode *,
78 const char* path, __le32, const struct nw_modify_dos_info *info);
79int ncp_modify_nfs_info(struct ncp_server *, __u8 volnum, __le32 dirent,
80 __u32 mode, __u32 rdev);
81
82int ncp_del_file_or_subdir2(struct ncp_server *, struct dentry*);
2e54eb96
PV
83int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, const char *);
84int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, const char *,
1da177e4
LT
85 int, __le32, __le16, struct ncp_entry_info *);
86
87int ncp_initialize_search(struct ncp_server *, struct inode *,
88 struct nw_search_sequence *target);
1da177e4
LT
89int ncp_search_for_fileset(struct ncp_server *server,
90 struct nw_search_sequence *seq,
91 int* more, int* cnt,
92 char* buffer, size_t bufsize,
93 char** rbuf, size_t* rsize);
94
95int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
2e54eb96 96 struct inode *, const char *, struct inode *, const char *);
1da177e4
LT
97
98
99int
100ncp_LogPhysicalRecord(struct ncp_server *server,
101 const char *file_id, __u8 locktype,
102 __u32 offset, __u32 length, __u16 timeout);
103
104#ifdef CONFIG_NCPFS_IOCTL_LOCKING
105int
106ncp_ClearPhysicalRecord(struct ncp_server *server,
107 const char *file_id,
108 __u32 offset, __u32 length);
109#endif /* CONFIG_NCPFS_IOCTL_LOCKING */
110
111int
112ncp_mount_subdir(struct ncp_server *, __u8, __u8, __le32,
113 __u32* volume, __le32* dirent, __le32* dosdirent);
114int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __le32 dirent, __u8 *dirhandle);
115int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle);
116
117int ncp_create_new(struct inode *dir, struct dentry *dentry,
5eee25ca 118 umode_t mode, dev_t rdev, __le32 attributes);
1da177e4
LT
119
120static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int volnum) {
121#ifdef CONFIG_NCPFS_NFS_NS
122 return (server->m.flags & NCP_MOUNT_NFS_EXTRAS) &&
123 (server->name_space[volnum] == NW_NS_NFS);
124#else
125 return 0;
126#endif
127}
128
129#ifdef CONFIG_NCPFS_NLS
130
131int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
132 const unsigned char *, unsigned int, int);
133int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
134 const unsigned char *, unsigned int, int);
135
136#define NCP_ESC ':'
621e155a 137#define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
1da177e4
LT
138#define ncp_tolower(t, c) nls_tolower(t, c)
139#define ncp_toupper(t, c) nls_toupper(t, c)
140#define ncp_strnicmp(t, s1, s2, len) \
141 nls_strnicmp(t, s1, s2, len)
142#define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U)
143#define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U)
144
145#else
146
147int ncp__io2vol(unsigned char *, unsigned int *,
148 const unsigned char *, unsigned int, int);
149int ncp__vol2io(unsigned char *, unsigned int *,
150 const unsigned char *, unsigned int, int);
151
621e155a 152#define NCP_IO_TABLE(sb) NULL
1da177e4
LT
153#define ncp_tolower(t, c) tolower(c)
154#define ncp_toupper(t, c) toupper(c)
155#define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U)
156#define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U)
157
158
621e155a
NP
159static inline int ncp_strnicmp(const struct nls_table *t,
160 const unsigned char *s1, const unsigned char *s2, int len)
1da177e4
LT
161{
162 while (len--) {
163 if (tolower(*s1++) != tolower(*s2++))
164 return 1;
165 }
166
167 return 0;
168}
169
170#endif /* CONFIG_NCPFS_NLS */
171
172#define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time)
2e54eb96 173#define NCP_MAX_AGE(server) atomic_read(&(server)->dentry_ttl)
1da177e4
LT
174#define NCP_TEST_AGE(server,dentry) (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server))
175
176static inline void
177ncp_age_dentry(struct ncp_server* server, struct dentry* dentry)
178{
2e54eb96 179 dentry->d_time = jiffies - NCP_MAX_AGE(server);
1da177e4
LT
180}
181
182static inline void
183ncp_new_dentry(struct dentry* dentry)
184{
185 dentry->d_time = jiffies;
186}
187
1da177e4
LT
188struct ncp_cache_head {
189 time_t mtime;
190 unsigned long time; /* cache age */
191 unsigned long end; /* last valid fpos in cache */
192 int eof;
193};
194
09cbfeaf 195#define NCP_DIRCACHE_SIZE ((int)(PAGE_SIZE/sizeof(struct dentry *)))
1da177e4
LT
196union ncp_dir_cache {
197 struct ncp_cache_head head;
198 struct dentry *dentry[NCP_DIRCACHE_SIZE];
199};
200
201#define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * \
202 sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \
203 sizeof(struct dentry *)))
204
205#define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
206
207struct ncp_cache_control {
208 struct ncp_cache_head head;
209 struct page *page;
210 union ncp_dir_cache *cache;
211 unsigned long fpos, ofs;
212 int filled, valid, idx;
213};
214
215#endif /* _NCPLIB_H */