ncplib_kernel.h 7.6 KB

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