ncplib_kernel.h 7.7 KB

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