Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | #include <linux/ncp_fs.h> |
| 36 | |
| 37 | #define NCP_MIN_SYMLINK_SIZE 8 |
| 38 | #define NCP_MAX_SYMLINK_SIZE 512 |
| 39 | |
| 40 | #define NCP_BLOCK_SHIFT 9 |
| 41 | #define NCP_BLOCK_SIZE (1 << (NCP_BLOCK_SHIFT)) |
| 42 | |
| 43 | int ncp_negotiate_buffersize(struct ncp_server *, int, int *); |
| 44 | int ncp_negotiate_size_and_options(struct ncp_server *server, int size, |
| 45 | int options, int *ret_size, int *ret_options); |
| 46 | |
| 47 | int ncp_get_volume_info_with_number(struct ncp_server* server, int n, |
| 48 | struct ncp_volume_info *target); |
| 49 | |
| 50 | int ncp_get_directory_info(struct ncp_server* server, __u8 dirhandle, |
| 51 | struct ncp_volume_info* target); |
| 52 | |
| 53 | int ncp_close_file(struct ncp_server *, const char *); |
| 54 | static inline int ncp_read_bounce_size(__u32 size) { |
| 55 | return sizeof(struct ncp_reply_header) + 2 + 2 + size + 8; |
| 56 | }; |
| 57 | int ncp_read_bounce(struct ncp_server *, const char *, __u32, __u16, |
| 58 | char __user *, int *, void* bounce, __u32 bouncelen); |
| 59 | int ncp_read_kernel(struct ncp_server *, const char *, __u32, __u16, |
| 60 | char *, int *); |
| 61 | int ncp_write_kernel(struct ncp_server *, const char *, __u32, __u16, |
| 62 | const char *, int *); |
| 63 | |
| 64 | static inline void ncp_inode_close(struct inode *inode) { |
| 65 | atomic_dec(&NCP_FINFO(inode)->opened); |
| 66 | } |
| 67 | |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 68 | void ncp_extract_file_info(const void* src, struct nw_info_struct* target); |
| 69 | int ncp_obtain_info(struct ncp_server *server, struct inode *, const char *, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | struct nw_info_struct *target); |
| 71 | int ncp_obtain_nfs_info(struct ncp_server *server, struct nw_info_struct *target); |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 72 | int ncp_update_known_namespace(struct ncp_server *server, __u8 volume, int *ret_ns); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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*); |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 84 | int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, const char *); |
| 85 | int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, const char *, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | int ncp_search_for_fileset(struct ncp_server *server, |
| 91 | struct nw_search_sequence *seq, |
| 92 | int* more, int* cnt, |
| 93 | char* buffer, size_t bufsize, |
| 94 | char** rbuf, size_t* rsize); |
| 95 | |
| 96 | int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server, |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 97 | struct inode *, const char *, struct inode *, const char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | |
| 100 | int |
| 101 | ncp_LogPhysicalRecord(struct ncp_server *server, |
| 102 | const char *file_id, __u8 locktype, |
| 103 | __u32 offset, __u32 length, __u16 timeout); |
| 104 | |
| 105 | #ifdef CONFIG_NCPFS_IOCTL_LOCKING |
| 106 | int |
| 107 | ncp_ClearPhysicalRecord(struct ncp_server *server, |
| 108 | const char *file_id, |
| 109 | __u32 offset, __u32 length); |
| 110 | #endif /* CONFIG_NCPFS_IOCTL_LOCKING */ |
| 111 | |
| 112 | int |
| 113 | ncp_mount_subdir(struct ncp_server *, __u8, __u8, __le32, |
| 114 | __u32* volume, __le32* dirent, __le32* dosdirent); |
| 115 | int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __le32 dirent, __u8 *dirhandle); |
| 116 | int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle); |
| 117 | |
| 118 | int ncp_create_new(struct inode *dir, struct dentry *dentry, |
| 119 | int mode, dev_t rdev, __le32 attributes); |
| 120 | |
| 121 | static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int volnum) { |
| 122 | #ifdef CONFIG_NCPFS_NFS_NS |
| 123 | return (server->m.flags & NCP_MOUNT_NFS_EXTRAS) && |
| 124 | (server->name_space[volnum] == NW_NS_NFS); |
| 125 | #else |
| 126 | return 0; |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | #ifdef CONFIG_NCPFS_NLS |
| 131 | |
| 132 | int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *, |
| 133 | const unsigned char *, unsigned int, int); |
| 134 | int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *, |
| 135 | const unsigned char *, unsigned int, int); |
| 136 | |
| 137 | #define NCP_ESC ':' |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 138 | #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | #define ncp_tolower(t, c) nls_tolower(t, c) |
| 140 | #define ncp_toupper(t, c) nls_toupper(t, c) |
| 141 | #define ncp_strnicmp(t, s1, s2, len) \ |
| 142 | nls_strnicmp(t, s1, s2, len) |
| 143 | #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U) |
| 144 | #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U) |
| 145 | |
| 146 | #else |
| 147 | |
| 148 | int ncp__io2vol(unsigned char *, unsigned int *, |
| 149 | const unsigned char *, unsigned int, int); |
| 150 | int ncp__vol2io(unsigned char *, unsigned int *, |
| 151 | const unsigned char *, unsigned int, int); |
| 152 | |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 153 | #define NCP_IO_TABLE(sb) NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #define ncp_tolower(t, c) tolower(c) |
| 155 | #define ncp_toupper(t, c) toupper(c) |
| 156 | #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U) |
| 157 | #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U) |
| 158 | |
| 159 | |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 160 | static inline int ncp_strnicmp(const struct nls_table *t, |
| 161 | const unsigned char *s1, const unsigned char *s2, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
| 163 | while (len--) { |
| 164 | if (tolower(*s1++) != tolower(*s2++)) |
| 165 | return 1; |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | #endif /* CONFIG_NCPFS_NLS */ |
| 172 | |
| 173 | #define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time) |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 174 | #define NCP_MAX_AGE(server) atomic_read(&(server)->dentry_ttl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #define NCP_TEST_AGE(server,dentry) (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server)) |
| 176 | |
| 177 | static inline void |
| 178 | ncp_age_dentry(struct ncp_server* server, struct dentry* dentry) |
| 179 | { |
Petr Vandrovec | 2e54eb9 | 2010-09-27 01:47:33 +0200 | [diff] [blame] | 180 | dentry->d_time = jiffies - NCP_MAX_AGE(server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static inline void |
| 184 | ncp_new_dentry(struct dentry* dentry) |
| 185 | { |
| 186 | dentry->d_time = jiffies; |
| 187 | } |
| 188 | |
| 189 | static inline void |
| 190 | ncp_renew_dentries(struct dentry *parent) |
| 191 | { |
| 192 | struct ncp_server *server = NCP_SERVER(parent->d_inode); |
| 193 | struct list_head *next; |
| 194 | struct dentry *dentry; |
| 195 | |
| 196 | spin_lock(&dcache_lock); |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame^] | 197 | spin_lock(&parent->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | next = parent->d_subdirs.next; |
| 199 | while (next != &parent->d_subdirs) { |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 200 | dentry = list_entry(next, struct dentry, d_u.d_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if (dentry->d_fsdata == NULL) |
| 203 | ncp_age_dentry(server, dentry); |
| 204 | else |
| 205 | ncp_new_dentry(dentry); |
| 206 | |
| 207 | next = next->next; |
| 208 | } |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame^] | 209 | spin_unlock(&parent->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | spin_unlock(&dcache_lock); |
| 211 | } |
| 212 | |
| 213 | static inline void |
| 214 | ncp_invalidate_dircache_entries(struct dentry *parent) |
| 215 | { |
| 216 | struct ncp_server *server = NCP_SERVER(parent->d_inode); |
| 217 | struct list_head *next; |
| 218 | struct dentry *dentry; |
| 219 | |
| 220 | spin_lock(&dcache_lock); |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame^] | 221 | spin_lock(&parent->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | next = parent->d_subdirs.next; |
| 223 | while (next != &parent->d_subdirs) { |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 224 | dentry = list_entry(next, struct dentry, d_u.d_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | dentry->d_fsdata = NULL; |
| 226 | ncp_age_dentry(server, dentry); |
| 227 | next = next->next; |
| 228 | } |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame^] | 229 | spin_unlock(&parent->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | spin_unlock(&dcache_lock); |
| 231 | } |
| 232 | |
| 233 | struct ncp_cache_head { |
| 234 | time_t mtime; |
| 235 | unsigned long time; /* cache age */ |
| 236 | unsigned long end; /* last valid fpos in cache */ |
| 237 | int eof; |
| 238 | }; |
| 239 | |
| 240 | #define NCP_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *))) |
| 241 | union ncp_dir_cache { |
| 242 | struct ncp_cache_head head; |
| 243 | struct dentry *dentry[NCP_DIRCACHE_SIZE]; |
| 244 | }; |
| 245 | |
| 246 | #define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * \ |
| 247 | sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \ |
| 248 | sizeof(struct dentry *))) |
| 249 | |
| 250 | #define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE) |
| 251 | |
| 252 | struct ncp_cache_control { |
| 253 | struct ncp_cache_head head; |
| 254 | struct page *page; |
| 255 | union ncp_dir_cache *cache; |
| 256 | unsigned long fpos, ofs; |
| 257 | int filled, valid, idx; |
| 258 | }; |
| 259 | |
| 260 | #endif /* _NCPLIB_H */ |