1 /*
2 * linux/fs/hpfs/hpfs_fn.h
3 *
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
5 *
6 * function headers
7 */
8
9 //#define DBG
10 //#define DEBUG_LOCKS
11
12 #include <linux/fs.h>
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>
25
26 #include <stdarg.h>
27
28 #include "hpfs.h"
29
30 #define EIOERROR EIO
31 #define EFSERROR EPERM
32 #define EMEMERROR ENOMEM
33
34 #define ANODE_ALLOC_FWD 512
35 #define FNODE_ALLOC_FWD 0
36 #define ALLOC_FWD_MIN 16
37 #define ALLOC_FWD_MAX 128
38 #define ALLOC_M 1
39 #define FNODE_RD_AHEAD 16
40 #define ANODE_RD_AHEAD 16
41 #define DNODE_RD_AHEAD 4
42
43 #define FREE_DNODES_ADD 58
44 #define FREE_DNODES_DEL 29
45
46 #define CHKCOND(x,y) if (!(x)) printk y
47
48 #ifdef DBG
49 #define PRINTK(x) printk x
50 #else
51 #undef PRINTK
52 #define PRINTK(x)
53 #endif
54
55 typedef void nonconst; /* What this is for ? */
56
57 /*
58 * local time (HPFS) to GMT (Unix)
59 */
60
local_to_gmt(struct super_block * s,time32_t t)61 extern inline time_t local_to_gmt(struct super_block *s, time32_t t)
62 {
63 extern struct timezone sys_tz;
64 return t + sys_tz.tz_minuteswest * 60 + s->s_hpfs_timeshift;
65 }
66
gmt_to_local(struct super_block * s,time_t t)67 extern inline time32_t gmt_to_local(struct super_block *s, time_t t)
68 {
69 extern struct timezone sys_tz;
70 return t - sys_tz.tz_minuteswest * 60 - s->s_hpfs_timeshift;
71 }
72
73 /*
74 * conv= options
75 */
76
77 #define CONV_BINARY 0 /* no conversion */
78 #define CONV_TEXT 1 /* crlf->newline */
79 #define CONV_AUTO 2 /* decide based on file contents */
80
81 /* Four 512-byte buffers and the 2k block obtained by concatenating them */
82
83 struct quad_buffer_head {
84 struct buffer_head *bh[4];
85 void *data;
86 };
87
88 /* The b-tree down pointer from a dir entry */
89
de_down_pointer(struct hpfs_dirent * de)90 extern inline dnode_secno de_down_pointer (struct hpfs_dirent *de)
91 {
92 CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n"));
93 return *(dnode_secno *) ((void *) de + de->length - 4);
94 }
95
96 /* The first dir entry in a dnode */
97
dnode_first_de(struct dnode * dnode)98 extern inline struct hpfs_dirent *dnode_first_de (struct dnode *dnode)
99 {
100 return (void *) dnode->dirent;
101 }
102
103 /* The end+1 of the dir entries */
104
dnode_end_de(struct dnode * dnode)105 extern inline struct hpfs_dirent *dnode_end_de (struct dnode *dnode)
106 {
107 CHKCOND(dnode->first_free>=0x14 && dnode->first_free<=0xa00,("HPFS: dnode_end_de: dnode->first_free = %d\n",(int)dnode->first_free));
108 return (void *) dnode + dnode->first_free;
109 }
110
111 /* The dir entry after dir entry de */
112
de_next_de(struct hpfs_dirent * de)113 extern inline struct hpfs_dirent *de_next_de (struct hpfs_dirent *de)
114 {
115 CHKCOND(de->length>=0x20 && de->length<0x800,("HPFS: de_next_de: de->length = %d\n",(int)de->length));
116 return (void *) de + de->length;
117 }
118
fnode_ea(struct fnode * fnode)119 extern inline struct extended_attribute *fnode_ea(struct fnode *fnode)
120 {
121 return (struct extended_attribute *)((char *)fnode + fnode->ea_offs + fnode->acl_size_s);
122 }
123
fnode_end_ea(struct fnode * fnode)124 extern inline struct extended_attribute *fnode_end_ea(struct fnode *fnode)
125 {
126 return (struct extended_attribute *)((char *)fnode + fnode->ea_offs + fnode->acl_size_s + fnode->ea_size_s);
127 }
128
next_ea(struct extended_attribute * ea)129 extern inline struct extended_attribute *next_ea(struct extended_attribute *ea)
130 {
131 return (struct extended_attribute *)((char *)ea + 5 + ea->namelen + ea->valuelen);
132 }
133
ea_sec(struct extended_attribute * ea)134 extern inline secno ea_sec(struct extended_attribute *ea)
135 {
136 return *(secno *)((char *)ea + 9 + ea->namelen);
137 }
138
ea_len(struct extended_attribute * ea)139 extern inline secno ea_len(struct extended_attribute *ea)
140 {
141 return *(secno *)((char *)ea + 5 + ea->namelen);
142 }
143
ea_data(struct extended_attribute * ea)144 extern inline char *ea_data(struct extended_attribute *ea)
145 {
146 return (char *)((char *)ea + 5 + ea->namelen);
147 }
148
de_size(int namelen,secno down_ptr)149 extern inline unsigned de_size(int namelen, secno down_ptr)
150 {
151 return ((0x1f + namelen + 3) & ~3) + (down_ptr ? 4 : 0);
152 }
153
copy_de(struct hpfs_dirent * dst,struct hpfs_dirent * src)154 extern inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src)
155 {
156 int a;
157 int n;
158 if (!dst || !src) return;
159 a = dst->down;
160 n = dst->not_8x3;
161 memcpy((char *)dst + 2, (char *)src + 2, 28);
162 dst->down = a;
163 dst->not_8x3 = n;
164 }
165
tstbits(unsigned * bmp,unsigned b,unsigned n)166 extern inline unsigned tstbits(unsigned *bmp, unsigned b, unsigned n)
167 {
168 int i;
169 if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
170 if (!((bmp[(b & 0x3fff) >> 5] >> (b & 0x1f)) & 1)) return 1;
171 for (i = 1; i < n; i++)
172 if (/*b+i < 0x4000 &&*/ !((bmp[((b+i) & 0x3fff) >> 5] >> ((b+i) & 0x1f)) & 1))
173 return i + 1;
174 return 0;
175 }
176
177 /* alloc.c */
178
179 int hpfs_chk_sectors(struct super_block *, secno, int, char *);
180 secno hpfs_alloc_sector(struct super_block *, secno, unsigned, int, int);
181 int hpfs_alloc_if_possible_nolock(struct super_block *, secno);
182 int hpfs_alloc_if_possible(struct super_block *, secno);
183 void hpfs_free_sectors(struct super_block *, secno, unsigned);
184 int hpfs_check_free_dnodes(struct super_block *, int);
185 void hpfs_free_dnode(struct super_block *, secno);
186 struct dnode *hpfs_alloc_dnode(struct super_block *, secno, dnode_secno *, struct quad_buffer_head *, int);
187 struct fnode *hpfs_alloc_fnode(struct super_block *, secno, fnode_secno *, struct buffer_head **);
188 struct anode *hpfs_alloc_anode(struct super_block *, secno, anode_secno *, struct buffer_head **);
189
190 /* anode.c */
191
192 secno hpfs_bplus_lookup(struct super_block *, struct inode *, struct bplus_header *, unsigned, struct buffer_head *);
193 secno hpfs_add_sector_to_btree(struct super_block *, secno, int, unsigned);
194 void hpfs_remove_btree(struct super_block *, struct bplus_header *);
195 int hpfs_ea_read(struct super_block *, secno, int, unsigned, unsigned, char *);
196 int hpfs_ea_write(struct super_block *, secno, int, unsigned, unsigned, char *);
197 void hpfs_ea_remove(struct super_block *, secno, int, unsigned);
198 void hpfs_truncate_btree(struct super_block *, secno, int, unsigned);
199 void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
200
201 /* buffer.c */
202
203 void hpfs_lock_creation(struct super_block *);
204 void hpfs_unlock_creation(struct super_block *);
205 void hpfs_lock_iget(struct super_block *, int);
206 void hpfs_unlock_iget(struct super_block *);
207 void hpfs_lock_inode(struct inode *);
208 void hpfs_unlock_inode(struct inode *);
209 void hpfs_lock_2inodes(struct inode *, struct inode *);
210 void hpfs_unlock_2inodes(struct inode *, struct inode *);
211 void hpfs_lock_3inodes(struct inode *, struct inode *, struct inode *);
212 void hpfs_unlock_3inodes(struct inode *, struct inode *, struct inode *);
213 void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
214 void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
215 void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
216 void *hpfs_get_4sectors(struct super_block *, unsigned, struct quad_buffer_head *);
217 void hpfs_brelse4(struct quad_buffer_head *);
218 void hpfs_mark_4buffers_dirty(struct quad_buffer_head *);
219
220 /* dentry.c */
221
222 void hpfs_set_dentry_operations(struct dentry *);
223
224 /* dir.c */
225
226 int hpfs_dir_release(struct inode *, struct file *);
227 loff_t hpfs_dir_lseek(struct file *, loff_t, int);
228 int hpfs_readdir(struct file *, void *, filldir_t);
229 struct dentry *hpfs_lookup(struct inode *, struct dentry *);
230
231 /* dnode.c */
232
233 void hpfs_add_pos(struct inode *, loff_t *);
234 void hpfs_del_pos(struct inode *, loff_t *);
235 struct hpfs_dirent *hpfs_add_de(struct super_block *, struct dnode *, unsigned char *, unsigned, secno);
236 void hpfs_delete_de(struct super_block *, struct dnode *, struct hpfs_dirent *);
237 int hpfs_add_to_dnode(struct inode *, dnode_secno, unsigned char *, unsigned, struct hpfs_dirent *, dnode_secno);
238 int hpfs_add_dirent(struct inode *, unsigned char *, unsigned, struct hpfs_dirent *, int);
239 int hpfs_remove_dirent(struct inode *, dnode_secno, struct hpfs_dirent *, struct quad_buffer_head *, int);
240 void hpfs_count_dnodes(struct super_block *, dnode_secno, int *, int *, int *);
241 dnode_secno hpfs_de_as_down_as_possible(struct super_block *, dnode_secno dno);
242 struct hpfs_dirent *map_pos_dirent(struct inode *, loff_t *, struct quad_buffer_head *);
243 struct hpfs_dirent *map_dirent(struct inode *, dnode_secno, char *, unsigned, dnode_secno *, struct quad_buffer_head *);
244 void hpfs_remove_dtree(struct super_block *, dnode_secno);
245 struct hpfs_dirent *map_fnode_dirent(struct super_block *, fnode_secno, struct fnode *, struct quad_buffer_head *);
246
247 /* ea.c */
248
249 void hpfs_ea_ext_remove(struct super_block *, secno, int, unsigned);
250 int hpfs_read_ea(struct super_block *, struct fnode *, char *, char *, int);
251 char *hpfs_get_ea(struct super_block *, struct fnode *, char *, int *);
252 void hpfs_set_ea(struct inode *, struct fnode *, char *, char *, int);
253
254 /* file.c */
255
256 int hpfs_file_release(struct inode *, struct file *);
257 int hpfs_open(struct inode *, struct file *);
258 int hpfs_file_fsync(struct file *, struct dentry *, int);
259 secno hpfs_bmap(struct inode *, unsigned);
260 void hpfs_truncate(struct inode *);
261 int hpfs_get_block(struct inode *inode, long iblock, struct buffer_head *bh_result, int create);
262 ssize_t hpfs_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos);
263
264 /* inode.c */
265
266 void hpfs_read_inode(struct inode *);
267 void hpfs_write_inode_ea(struct inode *, struct fnode *);
268 void hpfs_write_inode(struct inode *);
269 void hpfs_write_inode_nolock(struct inode *);
270 int hpfs_notify_change(struct dentry *, struct iattr *);
271 void hpfs_write_if_changed(struct inode *);
272 void hpfs_delete_inode(struct inode *);
273
274 /* map.c */
275
276 unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
277 unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
278 char *hpfs_load_code_page(struct super_block *, secno);
279 secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
280 struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
281 struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
282 struct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *);
283 dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino);
284
285 /* name.c */
286
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);
294
295 /* namei.c */
296
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_symlink_readpage(struct file *, struct page *);
304 int hpfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
305
306 /* super.c */
307
308 void hpfs_error(struct super_block *, char *, ...);
309 int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
310 int hpfs_remount_fs(struct super_block *, int *, char *);
311 void hpfs_put_super(struct super_block *);
312 unsigned hpfs_count_one_bitmap(struct super_block *, secno);
313 int hpfs_statfs(struct super_block *, struct statfs *);
314
315 extern struct address_space_operations hpfs_aops;
316