ncplib_kernel.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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 *, int,
  39. struct ncp_volume_info *);
  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 *, 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. int ncp_obtain_info(struct ncp_server *server, struct inode *, char *,
  54. struct nw_info_struct *target);
  55. int ncp_lookup_volume(struct ncp_server *, char *, struct nw_info_struct *);
  56. int ncp_modify_file_or_subdir_dos_info(struct ncp_server *, struct inode *,
  57.  __u32, const struct nw_modify_dos_info *info);
  58. int ncp_modify_file_or_subdir_dos_info_path(struct ncp_server *, struct inode *,
  59.  const char* path, __u32, const struct nw_modify_dos_info *info);
  60. int ncp_del_file_or_subdir2(struct ncp_server *, struct dentry*);
  61. int ncp_del_file_or_subdir(struct ncp_server *, struct inode *, char *);
  62. int ncp_open_create_file_or_subdir(struct ncp_server *, struct inode *, char *,
  63. int, __u32, int, struct ncp_entry_info *);
  64. int ncp_initialize_search(struct ncp_server *, struct inode *,
  65.       struct nw_search_sequence *target);
  66. int ncp_search_for_file_or_subdir(struct ncp_server *server,
  67.       struct nw_search_sequence *seq,
  68.       struct nw_info_struct *target);
  69. int ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
  70.       struct inode *, char *, struct inode *, char *);
  71. int
  72. ncp_LogPhysicalRecord(struct ncp_server *server,
  73.       const char *file_id, __u8 locktype,
  74.       __u32 offset, __u32 length, __u16 timeout);
  75. #ifdef CONFIG_NCPFS_IOCTL_LOCKING
  76. int
  77. ncp_ClearPhysicalRecord(struct ncp_server *server,
  78. const char *file_id,
  79. __u32 offset, __u32 length);
  80. #endif /* CONFIG_NCPFS_IOCTL_LOCKING */
  81. int
  82. ncp_mount_subdir(struct ncp_server *, struct nw_info_struct *,
  83. __u8, __u8, __u32);
  84. #ifdef CONFIG_NCPFS_NLS
  85. unsigned char ncp__tolower(struct nls_table *, unsigned char);
  86. unsigned char ncp__toupper(struct nls_table *, unsigned char);
  87. int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
  88. const unsigned char *, unsigned int, int);
  89. int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
  90. const unsigned char *, unsigned int, int);
  91. #define NCP_ESC ':'
  92. #define NCP_IO_TABLE(dentry) (NCP_SERVER((dentry)->d_inode)->nls_io)
  93. #define ncp_tolower(t, c) ncp__tolower(t, c)
  94. #define ncp_toupper(t, c) ncp__toupper(t, c)
  95. #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(S,m,i,n,k,U)
  96. #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(S,m,i,n,k,U)
  97. #else
  98. int ncp__io2vol(unsigned char *, unsigned int *,
  99. const unsigned char *, unsigned int, int);
  100. int ncp__vol2io(unsigned char *, unsigned int *,
  101. const unsigned char *, unsigned int, int);
  102. #define NCP_IO_TABLE(dentry) NULL
  103. #define ncp_tolower(t, c) tolower(c)
  104. #define ncp_toupper(t, c) toupper(c)
  105. #define ncp_io2vol(S,m,i,n,k,U) ncp__io2vol(m,i,n,k,U)
  106. #define ncp_vol2io(S,m,i,n,k,U) ncp__vol2io(m,i,n,k,U)
  107. #endif /* CONFIG_NCPFS_NLS */
  108. inline int
  109. ncp_strnicmp(struct nls_table *,
  110. const unsigned char *, const unsigned char *, int);
  111. #define NCP_GET_AGE(dentry) (jiffies - (dentry)->d_time)
  112. #define NCP_MAX_AGE(server) ((server)->dentry_ttl)
  113. #define NCP_TEST_AGE(server,dentry) (NCP_GET_AGE(dentry) < NCP_MAX_AGE(server))
  114. static inline void
  115. ncp_age_dentry(struct ncp_server* server, struct dentry* dentry)
  116. {
  117. dentry->d_time = jiffies - server->dentry_ttl;
  118. }
  119. static inline void
  120. ncp_new_dentry(struct dentry* dentry)
  121. {
  122. dentry->d_time = jiffies;
  123. }
  124. static inline void
  125. ncp_renew_dentries(struct dentry *parent)
  126. {
  127. struct ncp_server *server = NCP_SERVER(parent->d_inode);
  128. struct list_head *next;
  129. struct dentry *dentry;
  130. spin_lock(&dcache_lock);
  131. next = parent->d_subdirs.next;
  132. while (next != &parent->d_subdirs) {
  133. dentry = list_entry(next, struct dentry, d_child);
  134. if (dentry->d_fsdata == NULL)
  135. ncp_age_dentry(server, dentry);
  136. else
  137. ncp_new_dentry(dentry);
  138. next = next->next;
  139. }
  140. spin_unlock(&dcache_lock);
  141. }
  142. static inline void
  143. ncp_invalidate_dircache_entries(struct dentry *parent)
  144. {
  145. struct ncp_server *server = NCP_SERVER(parent->d_inode);
  146. struct list_head *next;
  147. struct dentry *dentry;
  148. spin_lock(&dcache_lock);
  149. next = parent->d_subdirs.next;
  150. while (next != &parent->d_subdirs) {
  151. dentry = list_entry(next, struct dentry, d_child);
  152. dentry->d_fsdata = NULL;
  153. ncp_age_dentry(server, dentry);
  154. next = next->next;
  155. }
  156. spin_unlock(&dcache_lock);
  157. }
  158. struct ncp_cache_head {
  159. time_t mtime;
  160. unsigned long time; /* cache age */
  161. unsigned long end; /* last valid fpos in cache */
  162. int eof;
  163. };
  164. #define NCP_DIRCACHE_SIZE ((int)(PAGE_CACHE_SIZE/sizeof(struct dentry *)))
  165. union ncp_dir_cache {
  166. struct ncp_cache_head head;
  167. struct dentry *dentry[NCP_DIRCACHE_SIZE];
  168. };
  169. #define NCP_FIRSTCACHE_SIZE ((int)((NCP_DIRCACHE_SIZE * 
  170. sizeof(struct dentry *) - sizeof(struct ncp_cache_head)) / 
  171. sizeof(struct dentry *)))
  172. #define NCP_DIRCACHE_START (NCP_DIRCACHE_SIZE - NCP_FIRSTCACHE_SIZE)
  173. struct ncp_cache_control {
  174. struct ncp_cache_head head;
  175. struct page *page;
  176. union ncp_dir_cache *cache;
  177. unsigned long fpos, ofs;
  178. int filled, valid, idx;
  179. };
  180. #endif /* _NCPLIB_H */