ncplib_kernel.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. struct iov_iter *, 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. umode_t 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. struct ncp_cache_head {
  152. time_t mtime;
  153. unsigned long time; /* cache age */
  154. unsigned long end; /* last valid fpos in cache */
  155. int eof;
  156. };
  157. #define NCP_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
  158. union ncp_dir_cache {
  159. struct ncp_cache_head head;
  160. struct dentry *dentry[NCP_DIRCACHE_SIZE];
  161. };
  162. #define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * \
  163. sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / \
  164. sizeof(struct dentry *)))
  165. #define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
  166. struct ncp_cache_control {
  167. struct ncp_cache_head head;
  168. struct page *page;
  169. union ncp_dir_cache *cache;
  170. unsigned long fpos, ofs;
  171. int filled, valid, idx;
  172. };
  173. #endif /* _NCPLIB_H */