ncplib_kernel.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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_file_or_subdir(struct ncp_server *server,
  75. struct nw_search_sequence *seq,
  76. struct nw_info_struct *target);
  77. int ncp_search_for_fileset(struct ncp_server *server,
  78. struct nw_search_sequence *seq,
  79. int* more, int* cnt,
  80. char* buffer, size_t bufsize,
  81. char** rbuf, size_t* rsize);
  82. int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
  83. struct inode *, char *, struct inode *, char *);
  84. int
  85. ncp_LogPhysicalRecord(struct ncp_server *server,
  86. const char *file_id, __u8 locktype,
  87. __u32 offset, __u32 length, __u16 timeout);
  88. #ifdef CONFIG_NCPFS_IOCTL_LOCKING
  89. int
  90. ncp_ClearPhysicalRecord(struct ncp_server *server,
  91. const char *file_id,
  92. __u32 offset, __u32 length);
  93. #endif /* CONFIG_NCPFS_IOCTL_LOCKING */
  94. int
  95. ncp_mount_subdir(struct ncp_server *, __u8, __u8, __le32,
  96. __u32* volume, __le32* dirent, __le32* dosdirent);
  97. int ncp_dirhandle_alloc(struct ncp_server *, __u8 vol, __le32 dirent, __u8 *dirhandle);
  98. int ncp_dirhandle_free(struct ncp_server *, __u8 dirhandle);
  99. int ncp_create_new(struct inode *dir, struct dentry *dentry,
  100. int mode, dev_t rdev, __le32 attributes);
  101. static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int volnum) {
  102. #ifdef CONFIG_NCPFS_NFS_NS
  103. return (server->m.flags & NCP_MOUNT_NFS_EXTRAS) &&
  104. (server->name_space[volnum] == NW_NS_NFS);
  105. #else
  106. return 0;
  107. #endif
  108. }
  109. #ifdef CONFIG_NCPFS_NLS
  110. int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
  111. const unsigned char *, unsigned int, int);
  112. int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
  113. const unsigned char *, unsigned int, int);
  114. #define NCP_ESC ':'
  115. #define NCP_IO_TABLE(dentry) (NCP_SERVER((dentry)->d_inode)->nls_io)
  116. #define ncp_tolower(t, c) nls_tolower(t, c)
  117. #define ncp_toupper(t, c) nls_toupper(t, c)
  118. #define ncp_strnicmp(t, s1, s2, len) \
  119. nls_strnicmp(t, s1, s2, len)
  120. #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U)
  121. #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U)
  122. #else
  123. int ncp__io2vol(unsigned char *, unsigned int *,
  124. const unsigned char *, unsigned int, int);
  125. int ncp__vol2io(unsigned char *, unsigned int *,
  126. const unsigned char *, unsigned int, int);
  127. #define NCP_IO_TABLE(dentry) NULL
  128. #define ncp_tolower(t, c) tolower(c)
  129. #define ncp_toupper(t, c) toupper(c)
  130. #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U)
  131. #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U)
  132. static inline int ncp_strnicmp(struct nls_table *t, const unsigned char *s1,
  133. const unsigned char *s2, int len)
  134. {
  135. while (len--) {
  136. if (tolower(*s1++) != tolower(*s2++))
  137. return 1;
  138. }
  139. return 0;
  140. }
  141. #endif /* CONFIG_NCPFS_NLS */
  142. #define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time)
  143. #define NCP_MAX_AGE(server) ((server)->dentry_ttl)
  144. #define NCP_TEST_AGE(server,dentry) (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server))
  145. static inline void
  146. ncp_age_dentry(struct ncp_server* server, struct dentry* dentry)
  147. {
  148. dentry->d_time = jiffies - server->dentry_ttl;
  149. }
  150. static inline void
  151. ncp_new_dentry(struct dentry* dentry)
  152. {
  153. dentry->d_time = jiffies;
  154. }
  155. static inline void
  156. ncp_renew_dentries(struct dentry *parent)
  157. {
  158. struct ncp_server *server = NCP_SERVER(parent->d_inode);
  159. struct list_head *next;
  160. struct dentry *dentry;
  161. spin_lock(&dcache_lock);
  162. next = parent->d_subdirs.next;
  163. while (next != &parent->d_subdirs) {
  164. dentry = list_entry(next, struct dentry, d_child);
  165. if (dentry->d_fsdata == NULL)
  166. ncp_age_dentry(server, dentry);
  167. else
  168. ncp_new_dentry(dentry);
  169. next = next->next;
  170. }
  171. spin_unlock(&dcache_lock);
  172. }
  173. static inline void
  174. ncp_invalidate_dircache_entries(struct dentry *parent)
  175. {
  176. struct ncp_server *server = NCP_SERVER(parent->d_inode);
  177. struct list_head *next;
  178. struct dentry *dentry;
  179. spin_lock(&dcache_lock);
  180. next = parent->d_subdirs.next;
  181. while (next != &parent->d_subdirs) {
  182. dentry = list_entry(next, struct dentry, d_child);
  183. dentry->d_fsdata = NULL;
  184. ncp_age_dentry(server, dentry);
  185. next = next->next;
  186. }
  187. spin_unlock(&dcache_lock);
  188. }
  189. struct ncp_cache_head {
  190. time_t mtime;
  191. unsigned long time; /* cache age */
  192. unsigned long end; /* last valid fpos in cache */
  193. int eof;
  194. };
  195. #define NCP_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
  196. union ncp_dir_cache {
  197. struct ncp_cache_head head;
  198. struct dentry *dentry[NCP_DIRCACHE_SIZE];
  199. };
  200. #define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * \
  201. sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \
  202. sizeof(struct dentry *)))
  203. #define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
  204. struct ncp_cache_control {
  205. struct ncp_cache_head head;
  206. struct page *page;
  207. union ncp_dir_cache *cache;
  208. unsigned long fpos, ofs;
  209. int filled, valid, idx;
  210. };
  211. #endif /* _NCPLIB_H */