Import 2.3.2
[davej-history.git] / fs / hpfs / hpfs_fn.h
blob09744ce8ce8bcf6b07a306c51191c25a84e35043
1 /*
2 * linux/fs/hpfs/hpfs_fn.h
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
6 * function headers
7 */
9 //#define DBG
10 //#define DEBUG_LOCKS
12 #include <linux/fs.h>
13 #include <linux/hpfs_fs.h>
14 #include <linux/errno.h>
15 #include <linux/malloc.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/locks.h>
19 #include <linux/stat.h>
20 #include <linux/string.h>
21 #include <asm/bitops.h>
22 #include <asm/segment.h>
23 #include <asm/uaccess.h>
25 #include <stdarg.h>
27 #include "hpfs.h"
29 #define memcpy_tofs memcpy
30 #define memcpy_fromfs memcpy
32 #define EIOERROR EIO
33 #define EFSERROR EPERM
34 #define EMEMERROR ENOMEM
36 #define ANODE_ALLOC_FWD 512
37 #define FNODE_ALLOC_FWD 0
38 #define ALLOC_FWD_MIN 16
39 #define ALLOC_FWD_MAX 512
40 #define ALLOC_M 1
41 #define FNODE_RD_AHEAD 16
42 #define ANODE_RD_AHEAD 16
43 #define DNODE_RD_AHEAD 4
45 #define CHKCOND(x,y) if (!(x)) printk y
47 #ifdef DBG
48 #define PRINTK(x) printk x
49 #else
50 #undef PRINTK
51 #define PRINTK(x)
52 #endif
54 typedef void nonconst; /* What this is for ? */
57 * local time (HPFS) to GMT (Unix)
60 extern inline time_t local_to_gmt(struct super_block *s, time_t t)
62 extern struct timezone sys_tz;
63 return t + sys_tz.tz_minuteswest * 60 - (sys_tz.tz_dsttime ? 3600 : 0) +s->s_hpfs_timeshift;
66 extern inline time_t gmt_to_local(struct super_block *s, time_t t)
68 extern struct timezone sys_tz;
69 return t - sys_tz.tz_minuteswest * 60 + (sys_tz.tz_dsttime ? 3600 : 0) -s->s_hpfs_timeshift;
73 * conv= options
76 #define CONV_BINARY 0 /* no conversion */
77 #define CONV_TEXT 1 /* crlf->newline */
78 #define CONV_AUTO 2 /* decide based on file contents */
80 /* Four 512-byte buffers and the 2k block obtained by concatenating them */
82 struct quad_buffer_head {
83 struct buffer_head *bh[4];
84 void *data;
87 /* The b-tree down pointer from a dir entry */
89 extern inline dnode_secno de_down_pointer (struct hpfs_dirent *de)
91 CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n"));
92 return *(dnode_secno *) ((void *) de + de->length - 4);
95 /* The first dir entry in a dnode */
97 extern inline struct hpfs_dirent *dnode_first_de (struct dnode *dnode)
99 return (void *) dnode->dirent;
102 /* The end+1 of the dir entries */
104 extern inline struct hpfs_dirent *dnode_end_de (struct dnode *dnode)
106 CHKCOND(dnode->first_free>=0x14 && dnode->first_free<=0xa00,("HPFS: dnode_end_de: dnode->first_free = %d\n",(int)dnode->first_free));
107 return (void *) dnode + dnode->first_free;
110 /* The dir entry after dir entry de */
112 extern inline struct hpfs_dirent *de_next_de (struct hpfs_dirent *de)
114 CHKCOND(de->length>=0x20 && de->length<0x800,("HPFS: de_next_de: de->length = %d\n",(int)de->length));
115 return (void *) de + de->length;
118 extern inline struct extended_attribute *fnode_ea(struct fnode *fnode)
120 return (struct extended_attribute *)((char *)fnode + fnode->ea_offs);
123 extern inline struct extended_attribute *fnode_end_ea(struct fnode *fnode)
125 return (struct extended_attribute *)((char *)fnode + fnode->ea_offs + fnode->ea_size_s);
128 extern inline struct extended_attribute *next_ea(struct extended_attribute *ea)
130 return (struct extended_attribute *)((char *)ea + 5 + ea->namelen + ea->valuelen);
133 extern inline secno ea_sec(struct extended_attribute *ea)
135 return *(secno *)((char *)ea + 9 + ea->namelen);
138 extern inline secno ea_len(struct extended_attribute *ea)
140 return *(secno *)((char *)ea + 5 + ea->namelen);
143 extern inline char *ea_data(struct extended_attribute *ea)
145 return (char *)((char *)ea + 5 + ea->namelen);
148 extern inline unsigned de_size(int namelen, secno down_ptr)
150 return ((0x1f + namelen + 3) & ~3) + (down_ptr ? 4 : 0);
153 extern inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src)
155 int a = dst->down;
156 int n = dst->not_8x3;
157 if (!dst || !src) return;
158 memcpy((char *)dst + 2, (char *)src + 2, 28);
159 dst->down = a;
160 dst->not_8x3 = n;
163 extern inline unsigned tstbits(unsigned *bmp, unsigned b, unsigned n)
165 int i;
166 if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
167 if (!((bmp[(b & 0x3fff) >> 5] >> (b & 0x1f)) & 1)) return 1;
168 for (i = 1; i < n; i++)
169 if (/*b+i < 0x4000 &&*/ !((bmp[((b+i) & 0x3fff) >> 5] >> ((b+i) & 0x1f)) & 1))
170 return i + 1;
171 return 0;
174 /* alloc.c */
176 int hpfs_chk_sectors(struct super_block *, secno, int, char *);
177 secno hpfs_alloc_sector(struct super_block *, secno, unsigned, int, int);
178 int hpfs_alloc_if_possible_nolock(struct super_block *, secno);
179 int hpfs_alloc_if_possible(struct super_block *, secno);
180 void hpfs_free_sectors(struct super_block *, secno, unsigned);
181 int hpfs_check_free_dnodes(struct super_block *, int);
182 void hpfs_free_dnode(struct super_block *, secno);
183 struct dnode *hpfs_alloc_dnode(struct super_block *, secno, dnode_secno *, struct quad_buffer_head *, int);
184 struct fnode *hpfs_alloc_fnode(struct super_block *, secno, fnode_secno *, struct buffer_head **);
185 struct anode *hpfs_alloc_anode(struct super_block *, secno, anode_secno *, struct buffer_head **);
187 /* anode.c */
189 secno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_header *, unsigned, struct buffer_head *);
190 secno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
191 void hpfs_remove_btree(struct super_block *, struct bplus_header *);
192 int hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
193 int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, char *);
194 void hpfs_ea_remove(struct super_block *, secno, int, unsigned);
195 void hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
196 void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
198 /* buffer.c */
200 void hpfs_lock_creation(struct super_block *);
201 void hpfs_unlock_creation(struct super_block *);
202 void hpfs_lock_iget(struct super_block *, int);
203 void hpfs_unlock_iget(struct super_block *);
204 void hpfs_lock_inode(struct inode *);
205 void hpfs_unlock_inode(struct inode *);
206 void hpfs_lock_2inodes(struct inode *, struct inode *);
207 void hpfs_unlock_2inodes(struct inode *, struct inode *);
208 void hpfs_lock_3inodes(struct inode *, struct inode *, struct inode *);
209 void hpfs_unlock_3inodes(struct inode *, struct inode *, struct inode *);
210 void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
211 void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
212 void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
213 void *hpfs_get_4sectors(struct super_block *, unsigned, struct quad_buffer_head *);
214 void hpfs_brelse4(struct quad_buffer_head *);
215 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *);
217 /* dentry.c */
219 void hpfs_set_dentry_operations(struct dentry *);
221 /* dir.c */
223 int hpfs_dir_read(struct file *, char *, size_t, loff_t *);
224 int hpfs_dir_release(struct inode *, struct file *);
225 int hpfs_readdir(struct file *, void *, filldir_t);
226 struct dentry *hpfs_lookup(struct inode *, struct dentry *);
228 /* dnode.c */
230 void hpfs_add_pos(struct inode *, loff_t *);
231 void hpfs_del_pos(struct inode *, loff_t *);
232 struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *, unsigned char *, unsigned, secno);
233 void hpfs_delete_de(struct super_block *, struct dnode *, struct hpfs_dirent *);
234 int hpfs_add_to_dnode(struct inode *, dnode_secno, unsigned char *, unsigned, struct hpfs_dirent *, dnode_secno);
235 int hpfs_add_dirent(struct inode *, unsigned char *, unsigned, struct hpfs_dirent *, int);
236 int hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
237 void hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
238 dnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
239 struct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
240 struct hpfs_dirent *map_dirent(struct inode *, dnode_secno, char *, unsigned, dnode_secno *, struct quad_buffer_head *, int *depth);
241 void hpfs_remove_dtree(struct super_block *, dnode_secno);
242 struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);
244 /* ea.c */
246 void hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
247 char *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
248 void hpfs_set_ea(struct inode *, struct fnode *, char *, char *, int);
250 /* file.c */
252 int hpfs_file_release(struct inode *, struct file *);
253 int hpfs_open(struct inode *, struct file *);
254 int hpfs_file_fsync(struct file *, struct dentry *);
255 secno hpfs_bmap(struct inode *, unsigned);
256 void hpfs_truncate(struct inode *);
257 ssize_t hpfs_file_read(struct file *, char *, size_t, loff_t *);
258 ssize_t hpfs_file_write(struct file *, const char *, size_t, loff_t *);
260 /* inode.c */
262 void hpfs_read_inode(struct inode *);
263 void hpfs_write_inode_ea(struct inode *, struct fnode *);
264 void hpfs_write_inode(struct inode *);
265 void hpfs_write_inode_nolock(struct inode *);
266 int hpfs_notify_change(struct dentry *, struct iattr *);
267 void hpfs_write_if_changed(struct inode *);
268 void hpfs_delete_inode(struct inode *);
270 /* map.c */
272 unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
273 unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
274 char *hpfs_load_code_page(struct super_block *, secno);
275 secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
276 struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
277 struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
278 struct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *);
279 dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
281 /* mmap.c */
283 int hpfs_mmap(struct file *, struct vm_area_struct *);
285 /* name.c */
287 unsigned char hpfs_upcase(unsigned char *, unsigned char);
288 int hpfs_chk_name(unsigned char *, unsigned);
289 char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
290 int hpfs_compare_names(struct super_block *, unsigned char *, unsigned, unsigned char *, unsigned, int);
291 int hpfs_is_name_long(unsigned char *, unsigned);
292 void hpfs_adjust_length(unsigned char *, unsigned *);
293 void hpfs_decide_conv(struct inode *, unsigned char *, unsigned);
295 /* namei.c */
297 int hpfs_mkdir(struct inode *, struct dentry *, int);
298 int hpfs_create(struct inode *, struct dentry *, int);
299 int hpfs_mknod(struct inode *, struct dentry *, int, int);
300 int hpfs_symlink(struct inode *, struct dentry *, const char *);
301 int hpfs_unlink(struct inode *, struct dentry *);
302 int hpfs_rmdir(struct inode *, struct dentry *);
303 int hpfs_readlink(struct dentry *, char *, int);
304 struct dentry *hpfs_follow_link(struct dentry *, struct dentry *, unsigned int);
305 int hpfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
307 /* super.c */
309 void hpfs_error(struct super_block *, char *, ...);
310 int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
311 int hpfs_remount_fs(struct super_block *, int *, char *);
312 void hpfs_put_super(struct super_block *);
313 int hpfs_statfs(struct super_block *, struct statfs *, int);
314 struct super_block *hpfs_read_super(struct super_block *, void *, int);