Merge with 2.3.99-pre1.
[linux-2.6/linux-mips.git] / fs / hpfs / hpfs_fn.h
blob5071782b0d6ebae6072f62956fb64e3f1babe838
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>
24 #include <linux/smp_lock.h>
26 #include <stdarg.h>
28 #include "hpfs.h"
30 #define memcpy_tofs memcpy
31 #define memcpy_fromfs memcpy
33 #define EIOERROR EIO
34 #define EFSERROR EPERM
35 #define EMEMERROR ENOMEM
37 #define ANODE_ALLOC_FWD 512
38 #define FNODE_ALLOC_FWD 0
39 #define ALLOC_FWD_MIN 16
40 #define ALLOC_FWD_MAX 128
41 #define ALLOC_M 1
42 #define FNODE_RD_AHEAD 16
43 #define ANODE_RD_AHEAD 16
44 #define DNODE_RD_AHEAD 4
46 #define FREE_DNODES_ADD 58
47 #define FREE_DNODES_DEL 29
49 #define CHKCOND(x,y) if (!(x)) printk y
51 #ifdef DBG
52 #define PRINTK(x) printk x
53 #else
54 #undef PRINTK
55 #define PRINTK(x)
56 #endif
58 typedef void nonconst; /* What this is for ? */
61 * local time (HPFS) to GMT (Unix)
64 extern inline time_t local_to_gmt(struct super_block *s, time_t t)
66 extern struct timezone sys_tz;
67 return t + sys_tz.tz_minuteswest * 60 + s->s_hpfs_timeshift;
70 extern inline time_t gmt_to_local(struct super_block *s, time_t t)
72 extern struct timezone sys_tz;
73 return t - sys_tz.tz_minuteswest * 60 - s->s_hpfs_timeshift;
77 * conv= options
80 #define CONV_BINARY 0 /* no conversion */
81 #define CONV_TEXT 1 /* crlf->newline */
82 #define CONV_AUTO 2 /* decide based on file contents */
84 /* Four 512-byte buffers and the 2k block obtained by concatenating them */
86 struct quad_buffer_head {
87 struct buffer_head *bh[4];
88 void *data;
91 /* The b-tree down pointer from a dir entry */
93 extern inline dnode_secno de_down_pointer (struct hpfs_dirent *de)
95 CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n"));
96 return *(dnode_secno *) ((void *) de + de->length - 4);
99 /* The first dir entry in a dnode */
101 extern inline struct hpfs_dirent *dnode_first_de (struct dnode *dnode)
103 return (void *) dnode->dirent;
106 /* The end+1 of the dir entries */
108 extern inline struct hpfs_dirent *dnode_end_de (struct dnode *dnode)
110 CHKCOND(dnode->first_free>=0x14 && dnode->first_free<=0xa00,("HPFS: dnode_end_de: dnode->first_free = %d\n",(int)dnode->first_free));
111 return (void *) dnode + dnode->first_free;
114 /* The dir entry after dir entry de */
116 extern inline struct hpfs_dirent *de_next_de (struct hpfs_dirent *de)
118 CHKCOND(de->length>=0x20 && de->length<0x800,("HPFS: de_next_de: de->length = %d\n",(int)de->length));
119 return (void *) de + de->length;
122 extern inline struct extended_attribute *fnode_ea(struct fnode *fnode)
124 return (struct extended_attribute *)((char *)fnode + fnode->ea_offs);
127 extern inline struct extended_attribute *fnode_end_ea(struct fnode *fnode)
129 return (struct extended_attribute *)((char *)fnode + fnode->ea_offs + fnode->ea_size_s);
132 extern inline struct extended_attribute *next_ea(struct extended_attribute *ea)
134 return (struct extended_attribute *)((char *)ea + 5 + ea->namelen + ea->valuelen);
137 extern inline secno ea_sec(struct extended_attribute *ea)
139 return *(secno *)((char *)ea + 9 + ea->namelen);
142 extern inline secno ea_len(struct extended_attribute *ea)
144 return *(secno *)((char *)ea + 5 + ea->namelen);
147 extern inline char *ea_data(struct extended_attribute *ea)
149 return (char *)((char *)ea + 5 + ea->namelen);
152 extern inline unsigned de_size(int namelen, secno down_ptr)
154 return ((0x1f + namelen + 3) & ~3) + (down_ptr ? 4 : 0);
157 extern inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src)
159 int a = dst->down;
160 int n = dst->not_8x3;
161 if (!dst || !src) return;
162 memcpy((char *)dst + 2, (char *)src + 2, 28);
163 dst->down = a;
164 dst->not_8x3 = n;
167 extern inline unsigned tstbits(unsigned *bmp, unsigned b, unsigned n)
169 int i;
170 if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
171 if (!((bmp[(b & 0x3fff) >> 5] >> (b & 0x1f)) & 1)) return 1;
172 for (i = 1; i < n; i++)
173 if (/*b+i < 0x4000 &&*/ !((bmp[((b+i) & 0x3fff) >> 5] >> ((b+i) & 0x1f)) & 1))
174 return i + 1;
175 return 0;
178 /* alloc.c */
180 int hpfs_chk_sectors(struct super_block *, secno, int, char *);
181 secno hpfs_alloc_sector(struct super_block *, secno, unsigned, int, int);
182 int hpfs_alloc_if_possible_nolock(struct super_block *, secno);
183 int hpfs_alloc_if_possible(struct super_block *, secno);
184 void hpfs_free_sectors(struct super_block *, secno, unsigned);
185 int hpfs_check_free_dnodes(struct super_block *, int);
186 void hpfs_free_dnode(struct super_block *, secno);
187 struct dnode *hpfs_alloc_dnode(struct super_block *, secno, dnode_secno *, struct quad_buffer_head *, int);
188 struct fnode *hpfs_alloc_fnode(struct super_block *, secno, fnode_secno *, struct buffer_head **);
189 struct anode *hpfs_alloc_anode(struct super_block *, secno, anode_secno *, struct buffer_head **);
191 /* anode.c */
193 secno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_header *, unsigned, struct buffer_head *);
194 secno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
195 void hpfs_remove_btree(struct super_block *, struct bplus_header *);
196 int hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
197 int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, char *);
198 void hpfs_ea_remove(struct super_block *, secno, int, unsigned);
199 void hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
200 void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
202 /* buffer.c */
204 void hpfs_lock_creation(struct super_block *);
205 void hpfs_unlock_creation(struct super_block *);
206 void hpfs_lock_iget(struct super_block *, int);
207 void hpfs_unlock_iget(struct super_block *);
208 void hpfs_lock_inode(struct inode *);
209 void hpfs_unlock_inode(struct inode *);
210 void hpfs_lock_2inodes(struct inode *, struct inode *);
211 void hpfs_unlock_2inodes(struct inode *, struct inode *);
212 void hpfs_lock_3inodes(struct inode *, struct inode *, struct inode *);
213 void hpfs_unlock_3inodes(struct inode *, struct inode *, struct inode *);
214 void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
215 void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
216 void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
217 void *hpfs_get_4sectors(struct super_block *, unsigned, struct quad_buffer_head *);
218 void hpfs_brelse4(struct quad_buffer_head *);
219 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *);
221 /* dentry.c */
223 void hpfs_set_dentry_operations(struct dentry *);
225 /* dir.c */
227 int hpfs_dir_release(struct inode *, struct file *);
228 loff_t hpfs_dir_lseek(struct file *, loff_t, int);
229 int hpfs_readdir(struct file *, void *, filldir_t);
230 struct dentry *hpfs_lookup(struct inode *, struct dentry *);
232 /* dnode.c */
234 void hpfs_add_pos(struct inode *, loff_t *);
235 void hpfs_del_pos(struct inode *, loff_t *);
236 struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *, unsigned char *, unsigned, secno);
237 void hpfs_delete_de(struct super_block *, struct dnode *, struct hpfs_dirent *);
238 int hpfs_add_to_dnode(struct inode *, dnode_secno, unsigned char *, unsigned, struct hpfs_dirent *, dnode_secno);
239 int hpfs_add_dirent(struct inode *, unsigned char *, unsigned, struct hpfs_dirent *, int);
240 int hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
241 void hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
242 dnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
243 struct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
244 struct hpfs_dirent *map_dirent(struct inode *, dnode_secno, char *, unsigned, dnode_secno *, struct quad_buffer_head *);
245 void hpfs_remove_dtree(struct super_block *, dnode_secno);
246 struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);
248 /* ea.c */
250 void hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
251 int hpfs_read_ea(struct super_block *, struct fnode *, char *, char *, int);
252 char *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
253 void hpfs_set_ea(struct inode *, struct fnode *, char *, char *, int);
255 /* file.c */
257 int hpfs_file_release(struct inode *, struct file *);
258 int hpfs_open(struct inode *, struct file *);
259 int hpfs_file_fsync(struct file *, struct dentry *);
260 secno hpfs_bmap(struct inode *, unsigned);
261 void hpfs_truncate(struct inode *);
262 int hpfs_get_block(struct inode *inode, long iblock, struct buffer_head *bh_result, int create);
263 ssize_t hpfs_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos);
265 /* inode.c */
267 void hpfs_read_inode(struct inode *);
268 void hpfs_write_inode_ea(struct inode *, struct fnode *);
269 void hpfs_write_inode(struct inode *);
270 void hpfs_write_inode_nolock(struct inode *);
271 int hpfs_notify_change(struct dentry *, struct iattr *);
272 void hpfs_write_if_changed(struct inode *);
273 void hpfs_delete_inode(struct inode *);
275 /* map.c */
277 unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
278 unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
279 char *hpfs_load_code_page(struct super_block *, secno);
280 secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
281 struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
282 struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
283 struct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *);
284 dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
286 /* name.c */
288 unsigned char hpfs_upcase(unsigned char *, unsigned char);
289 int hpfs_chk_name(unsigned char *, unsigned *);
290 char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
291 int hpfs_compare_names(struct super_block *, unsigned char *, unsigned, unsigned char *, unsigned, int);
292 int hpfs_is_name_long(unsigned char *, unsigned);
293 void hpfs_adjust_length(unsigned char *, unsigned *);
294 void hpfs_decide_conv(struct inode *, unsigned char *, unsigned);
296 /* namei.c */
298 int hpfs_mkdir(struct inode *, struct dentry *, int);
299 int hpfs_create(struct inode *, struct dentry *, int);
300 int hpfs_mknod(struct inode *, struct dentry *, int, int);
301 int hpfs_symlink(struct inode *, struct dentry *, const char *);
302 int hpfs_unlink(struct inode *, struct dentry *);
303 int hpfs_rmdir(struct inode *, struct dentry *);
304 int hpfs_symlink_readpage(struct dentry *, struct page *);
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 unsigned hpfs_count_one_bitmap(struct super_block *, secno);
314 int hpfs_statfs(struct super_block *, struct statfs *);
316 extern struct address_space_operations hpfs_aops;