2 * linux/fs/hpfs/hpfs_fn.h
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
13 #include <linux/hpfs_fs.h>
14 #include <linux/errno.h>
15 #include <linux/slab.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>
30 #define memcpy_tofs memcpy
31 #define memcpy_fromfs memcpy
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
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
52 #define PRINTK(x) printk x
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;
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];
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)
161 if (!dst || !src) return;
164 memcpy((char *)dst + 2, (char *)src + 2, 28);
169 extern inline unsigned tstbits(unsigned *bmp, unsigned b, unsigned n)
172 if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
173 if (!((bmp[(b & 0x3fff) >> 5] >> (b & 0x1f)) & 1)) return 1;
174 for (i = 1; i < n; i++)
175 if (/*b+i < 0x4000 &&*/ !((bmp[((b+i) & 0x3fff) >> 5] >> ((b+i) & 0x1f)) & 1))
182 int hpfs_chk_sectors(struct super_block *, secno, int, char *);
183 secno hpfs_alloc_sector(struct super_block *, secno, unsigned, int, int);
184 int hpfs_alloc_if_possible_nolock(struct super_block *, secno);
185 int hpfs_alloc_if_possible(struct super_block *, secno);
186 void hpfs_free_sectors(struct super_block *, secno, unsigned);
187 int hpfs_check_free_dnodes(struct super_block *, int);
188 void hpfs_free_dnode(struct super_block *, secno);
189 struct dnode *hpfs_alloc_dnode(struct super_block *, secno, dnode_secno *, struct quad_buffer_head *, int);
190 struct fnode *hpfs_alloc_fnode(struct super_block *, secno, fnode_secno *, struct buffer_head **);
191 struct anode *hpfs_alloc_anode(struct super_block *, secno, anode_secno *, struct buffer_head **);
195 secno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_header *, unsigned, struct buffer_head *);
196 secno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
197 void hpfs_remove_btree(struct super_block *, struct bplus_header *);
198 int hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
199 int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, char *);
200 void hpfs_ea_remove(struct super_block *, secno, int, unsigned);
201 void hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
202 void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
206 void hpfs_lock_creation(struct super_block *);
207 void hpfs_unlock_creation(struct super_block *);
208 void hpfs_lock_iget(struct super_block *, int);
209 void hpfs_unlock_iget(struct super_block *);
210 void hpfs_lock_inode(struct inode *);
211 void hpfs_unlock_inode(struct inode *);
212 void hpfs_lock_2inodes(struct inode *, struct inode *);
213 void hpfs_unlock_2inodes(struct inode *, struct inode *);
214 void hpfs_lock_3inodes(struct inode *, struct inode *, struct inode *);
215 void hpfs_unlock_3inodes(struct inode *, struct inode *, struct inode *);
216 void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
217 void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
218 void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
219 void *hpfs_get_4sectors(struct super_block *, unsigned, struct quad_buffer_head *);
220 void hpfs_brelse4(struct quad_buffer_head *);
221 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *);
225 void hpfs_set_dentry_operations(struct dentry *);
229 int hpfs_dir_release(struct inode *, struct file *);
230 loff_t hpfs_dir_lseek(struct file *, loff_t, int);
231 int hpfs_readdir(struct file *, void *, filldir_t);
232 struct dentry *hpfs_lookup(struct inode *, struct dentry *);
236 void hpfs_add_pos(struct inode *, loff_t *);
237 void hpfs_del_pos(struct inode *, loff_t *);
238 struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *, unsigned char *, unsigned, secno);
239 void hpfs_delete_de(struct super_block *, struct dnode *, struct hpfs_dirent *);
240 int hpfs_add_to_dnode(struct inode *, dnode_secno, unsigned char *, unsigned, struct hpfs_dirent *, dnode_secno);
241 int hpfs_add_dirent(struct inode *, unsigned char *, unsigned, struct hpfs_dirent *, int);
242 int hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
243 void hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
244 dnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
245 struct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
246 struct hpfs_dirent *map_dirent(struct inode *, dnode_secno, char *, unsigned, dnode_secno *, struct quad_buffer_head *);
247 void hpfs_remove_dtree(struct super_block *, dnode_secno);
248 struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);
252 void hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
253 int hpfs_read_ea(struct super_block *, struct fnode *, char *, char *, int);
254 char *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
255 void hpfs_set_ea(struct inode *, struct fnode *, char *, char *, int);
259 int hpfs_file_release(struct inode *, struct file *);
260 int hpfs_open(struct inode *, struct file *);
261 int hpfs_file_fsync(struct file *, struct dentry *, int);
262 secno hpfs_bmap(struct inode *, unsigned);
263 void hpfs_truncate(struct inode *);
264 int hpfs_get_block(struct inode *inode, long iblock, struct buffer_head *bh_result, int create);
265 ssize_t hpfs_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos);
269 void hpfs_read_inode(struct inode *);
270 void hpfs_write_inode_ea(struct inode *, struct fnode *);
271 void hpfs_write_inode(struct inode *);
272 void hpfs_write_inode_nolock(struct inode *);
273 int hpfs_notify_change(struct dentry *, struct iattr *);
274 void hpfs_write_if_changed(struct inode *);
275 void hpfs_delete_inode(struct inode *);
279 unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
280 unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
281 char *hpfs_load_code_page(struct super_block *, secno);
282 secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
283 struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
284 struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
285 struct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *);
286 dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
290 unsigned char hpfs_upcase(unsigned char *, unsigned char);
291 int hpfs_chk_name(unsigned char *, unsigned *);
292 char *hpfs_translate_name(struct super_block *, unsigned char *, unsigned, int, int);
293 int hpfs_compare_names(struct super_block *, unsigned char *, unsigned, unsigned char *, unsigned, int);
294 int hpfs_is_name_long(unsigned char *, unsigned);
295 void hpfs_adjust_length(unsigned char *, unsigned *);
296 void hpfs_decide_conv(struct inode *, unsigned char *, unsigned);
300 int hpfs_mkdir(struct inode *, struct dentry *, int);
301 int hpfs_create(struct inode *, struct dentry *, int);
302 int hpfs_mknod(struct inode *, struct dentry *, int, int);
303 int hpfs_symlink(struct inode *, struct dentry *, const char *);
304 int hpfs_unlink(struct inode *, struct dentry *);
305 int hpfs_rmdir(struct inode *, struct dentry *);
306 int hpfs_symlink_readpage(struct file *, struct page *);
307 int hpfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
311 void hpfs_error(struct super_block *, char *, ...);
312 int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
313 int hpfs_remount_fs(struct super_block *, int *, char *);
314 void hpfs_put_super(struct super_block *);
315 unsigned hpfs_count_one_bitmap(struct super_block *, secno);
316 int hpfs_statfs(struct super_block *, struct statfs *);
318 extern struct address_space_operations hpfs_aops;