1 |
1628 |
jcastillo |
/*
|
2 |
|
|
* linux/fs/affs/inode.c
|
3 |
|
|
*
|
4 |
|
|
* (c) 1996 Hans-Joachim Widmaier - Rewritten
|
5 |
|
|
*
|
6 |
|
|
* (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
|
7 |
|
|
*
|
8 |
|
|
* (C) 1992 Eric Youngdale Modified for ISO9660 filesystem.
|
9 |
|
|
*
|
10 |
|
|
* (C) 1991 Linus Torvalds - minix filesystem
|
11 |
|
|
*/
|
12 |
|
|
|
13 |
|
|
#include <linux/module.h>
|
14 |
|
|
#include <linux/errno.h>
|
15 |
|
|
#include <linux/fs.h>
|
16 |
|
|
#include <linux/malloc.h>
|
17 |
|
|
#include <linux/stat.h>
|
18 |
|
|
#include <linux/sched.h>
|
19 |
|
|
#include <linux/affs_fs.h>
|
20 |
|
|
#include <linux/kernel.h>
|
21 |
|
|
#include <linux/mm.h>
|
22 |
|
|
#include <linux/string.h>
|
23 |
|
|
#include <linux/locks.h>
|
24 |
|
|
#include <linux/errno.h>
|
25 |
|
|
#include <linux/genhd.h>
|
26 |
|
|
#include <linux/amigaffs.h>
|
27 |
|
|
#include <linux/major.h>
|
28 |
|
|
#include <linux/blkdev.h>
|
29 |
|
|
#include <asm/system.h>
|
30 |
|
|
#include <asm/segment.h>
|
31 |
|
|
|
32 |
|
|
extern int *blk_size[];
|
33 |
|
|
extern struct timezone sys_tz;
|
34 |
|
|
|
35 |
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
36 |
|
|
|
37 |
|
|
void
|
38 |
|
|
affs_put_super(struct super_block *sb)
|
39 |
|
|
{
|
40 |
|
|
int i;
|
41 |
|
|
|
42 |
|
|
pr_debug("affs_put_super()\n");
|
43 |
|
|
|
44 |
|
|
lock_super(sb);
|
45 |
|
|
for (i = 0; i < sb->u.affs_sb.s_bm_count; i++)
|
46 |
|
|
affs_brelse(sb->u.affs_sb.s_bitmap[i].bm_bh);
|
47 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
48 |
|
|
ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->bm_flag = htonl(1);
|
49 |
|
|
secs_to_datestamp(CURRENT_TIME,
|
50 |
|
|
&ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->disk_altered);
|
51 |
|
|
affs_fix_checksum(sb->s_blocksize,sb->u.affs_sb.s_root_bh->b_data,5);
|
52 |
|
|
mark_buffer_dirty(sb->u.affs_sb.s_root_bh,1);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
if (sb->u.affs_sb.s_flags & SF_PREFIX)
|
56 |
|
|
kfree(sb->u.affs_sb.s_prefix);
|
57 |
|
|
kfree(sb->u.affs_sb.s_bitmap);
|
58 |
|
|
affs_brelse(sb->u.affs_sb.s_root_bh);
|
59 |
|
|
|
60 |
|
|
/* I'm not happy with this. It would be better to save the previous
|
61 |
|
|
* value of this devices blksize_size[][] in the super block and
|
62 |
|
|
* restore it here, but with the affs superblock being quite large
|
63 |
|
|
* already ...
|
64 |
|
|
*/
|
65 |
|
|
set_blocksize(sb->s_dev,BLOCK_SIZE);
|
66 |
|
|
|
67 |
|
|
sb->s_dev = 0;
|
68 |
|
|
unlock_super(sb);
|
69 |
|
|
MOD_DEC_USE_COUNT;
|
70 |
|
|
return;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
static void
|
74 |
|
|
affs_write_super(struct super_block *sb)
|
75 |
|
|
{
|
76 |
|
|
int i, clean = 2;
|
77 |
|
|
|
78 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
79 |
|
|
lock_super(sb);
|
80 |
|
|
for (i = 0, clean = 1; i < sb->u.affs_sb.s_bm_count; i++) {
|
81 |
|
|
if (sb->u.affs_sb.s_bitmap[i].bm_bh) {
|
82 |
|
|
if (buffer_dirty(sb->u.affs_sb.s_bitmap[i].bm_bh)) {
|
83 |
|
|
clean = 0;
|
84 |
|
|
break;
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
unlock_super(sb);
|
89 |
|
|
ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->bm_flag = htonl(clean);
|
90 |
|
|
secs_to_datestamp(CURRENT_TIME,
|
91 |
|
|
&ROOT_END_S(sb->u.affs_sb.s_root_bh->b_data,sb)->disk_altered);
|
92 |
|
|
affs_fix_checksum(sb->s_blocksize,sb->u.affs_sb.s_root_bh->b_data,5);
|
93 |
|
|
mark_buffer_dirty(sb->u.affs_sb.s_root_bh,1);
|
94 |
|
|
sb->s_dirt = !clean; /* redo until bitmap synced */
|
95 |
|
|
} else
|
96 |
|
|
sb->s_dirt = 0;
|
97 |
|
|
|
98 |
|
|
pr_debug("AFFS: write_super() at %d, clean=%d\n",CURRENT_TIME,clean);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
static struct super_operations affs_sops = {
|
102 |
|
|
affs_read_inode,
|
103 |
|
|
affs_notify_change,
|
104 |
|
|
affs_write_inode,
|
105 |
|
|
affs_put_inode,
|
106 |
|
|
affs_put_super,
|
107 |
|
|
affs_write_super,
|
108 |
|
|
affs_statfs,
|
109 |
|
|
NULL /* remount */
|
110 |
|
|
};
|
111 |
|
|
|
112 |
|
|
int
|
113 |
|
|
affs_parent_ino(struct inode *dir)
|
114 |
|
|
{
|
115 |
|
|
int root_ino = (dir->i_sb->u.affs_sb.s_root_block);
|
116 |
|
|
|
117 |
|
|
if (!S_ISDIR (dir->i_mode)) {
|
118 |
|
|
printk ("affs_parent_ino: argument is not a directory\n");
|
119 |
|
|
return root_ino;
|
120 |
|
|
}
|
121 |
|
|
if (dir->i_ino == root_ino)
|
122 |
|
|
return root_ino;
|
123 |
|
|
return dir->u.affs_i.i_parent;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
static int
|
127 |
|
|
parse_options(char *options, uid_t *uid, gid_t *gid, int *mode, int *reserved, int *root,
|
128 |
|
|
int *blocksize, char **prefix, char *volume, unsigned long *mount_opts)
|
129 |
|
|
{
|
130 |
|
|
char *this_char, *value;
|
131 |
|
|
int f;
|
132 |
|
|
|
133 |
|
|
/* Fill in defaults */
|
134 |
|
|
|
135 |
|
|
*uid = 0;
|
136 |
|
|
*gid = 0;
|
137 |
|
|
*reserved = 2;
|
138 |
|
|
*root = -1;
|
139 |
|
|
*blocksize = -1;
|
140 |
|
|
*prefix = "/";
|
141 |
|
|
volume[0] = ':';
|
142 |
|
|
volume[1] = 0;
|
143 |
|
|
*mount_opts = 0;
|
144 |
|
|
if (!options)
|
145 |
|
|
return 1;
|
146 |
|
|
for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
|
147 |
|
|
f = 0;
|
148 |
|
|
if ((value = strchr(this_char,'=')) != NULL)
|
149 |
|
|
*value++ = 0;
|
150 |
|
|
if (!strcmp(this_char,"protect")) {
|
151 |
|
|
if (value) {
|
152 |
|
|
printk("AFFS: option protect does not take an argument\n");
|
153 |
|
|
return 0;
|
154 |
|
|
}
|
155 |
|
|
*mount_opts |= SF_IMMUTABLE;
|
156 |
|
|
}
|
157 |
|
|
else if (!strcmp(this_char,"verbose")) {
|
158 |
|
|
if (value) {
|
159 |
|
|
printk("AFFS: option verbose does not take an argument\n");
|
160 |
|
|
return 0;
|
161 |
|
|
}
|
162 |
|
|
*mount_opts |= SF_VERBOSE;
|
163 |
|
|
}
|
164 |
|
|
else if ((f = !strcmp(this_char,"uid")) || !strcmp(this_char,"setuid")) {
|
165 |
|
|
if (!value)
|
166 |
|
|
*uid = current->uid;
|
167 |
|
|
else if (!*value) {
|
168 |
|
|
printk("AFFS: argument for uid option missing\n");
|
169 |
|
|
return 0;
|
170 |
|
|
} else {
|
171 |
|
|
*uid = simple_strtoul(value,&value,0);
|
172 |
|
|
if (*value)
|
173 |
|
|
return 0;
|
174 |
|
|
if (!f)
|
175 |
|
|
*mount_opts |= SF_SETUID;
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
else if ((f = !strcmp(this_char,"gid")) || !strcmp(this_char,"setgid")) {
|
179 |
|
|
if (!value)
|
180 |
|
|
*gid = current->gid;
|
181 |
|
|
else if (!*value) {
|
182 |
|
|
printk("AFFS: argument for gid option missing\n");
|
183 |
|
|
return 0;
|
184 |
|
|
} else {
|
185 |
|
|
*gid = simple_strtoul(value,&value,0);
|
186 |
|
|
if (*value)
|
187 |
|
|
return 0;
|
188 |
|
|
if (!f)
|
189 |
|
|
*mount_opts |= SF_SETGID;
|
190 |
|
|
}
|
191 |
|
|
}
|
192 |
|
|
else if (!strcmp(this_char,"prefix")) {
|
193 |
|
|
if (!value) {
|
194 |
|
|
printk("AFFS: The prefix option requires an argument\n");
|
195 |
|
|
return 0;
|
196 |
|
|
}
|
197 |
|
|
*prefix = kmalloc(strlen(value) + 1,GFP_KERNEL);
|
198 |
|
|
if (!*prefix)
|
199 |
|
|
return 0;
|
200 |
|
|
strcpy(*prefix,value);
|
201 |
|
|
*mount_opts |= SF_PREFIX;
|
202 |
|
|
}
|
203 |
|
|
else if (!strcmp(this_char,"volume")) {
|
204 |
|
|
if (!value) {
|
205 |
|
|
printk("AFFS: The volume option requires an argument\n");
|
206 |
|
|
return 0;
|
207 |
|
|
}
|
208 |
|
|
if (strlen(value) > 30)
|
209 |
|
|
value[30] = 0;
|
210 |
|
|
strcpy(volume,value);
|
211 |
|
|
}
|
212 |
|
|
else if (!strcmp(this_char,"mode")) {
|
213 |
|
|
if (!value || !*value) {
|
214 |
|
|
printk("AFFS: The mode option requires an argument\n");
|
215 |
|
|
return 0;
|
216 |
|
|
}
|
217 |
|
|
*mode = simple_strtoul(value,&value,8) & 0777;
|
218 |
|
|
if (*value)
|
219 |
|
|
return 0;
|
220 |
|
|
*mount_opts |= SF_SETMODE;
|
221 |
|
|
}
|
222 |
|
|
else if (!strcmp(this_char,"reserved")) {
|
223 |
|
|
if (!value || !*value) {
|
224 |
|
|
printk("AFFS: The reserved option requires an argument\n");
|
225 |
|
|
return 0;
|
226 |
|
|
}
|
227 |
|
|
*reserved = simple_strtoul(value,&value,0);
|
228 |
|
|
if (*value)
|
229 |
|
|
return 0;
|
230 |
|
|
}
|
231 |
|
|
else if (!strcmp(this_char,"root")) {
|
232 |
|
|
if (!value || !*value) {
|
233 |
|
|
printk("AFFS: The root option requires an argument\n");
|
234 |
|
|
return 0;
|
235 |
|
|
}
|
236 |
|
|
*root = simple_strtoul(value,&value,0);
|
237 |
|
|
if (*value)
|
238 |
|
|
return 0;
|
239 |
|
|
}
|
240 |
|
|
else if (!strcmp(this_char,"bs")) {
|
241 |
|
|
if (!value || !*value) {
|
242 |
|
|
printk("AFFS: The bs option requires an argument\n");
|
243 |
|
|
return 0;
|
244 |
|
|
}
|
245 |
|
|
*blocksize = simple_strtoul(value,&value,0);
|
246 |
|
|
if (*value)
|
247 |
|
|
return 0;
|
248 |
|
|
if (*blocksize != 512 && *blocksize != 1024 && *blocksize != 2048
|
249 |
|
|
&& *blocksize != 4096) {
|
250 |
|
|
printk ("AFFS: Invalid blocksize (512, 1024, 2048, 4096 allowed).\n");
|
251 |
|
|
return 0;
|
252 |
|
|
}
|
253 |
|
|
}
|
254 |
|
|
/* Silently ignore the quota options */
|
255 |
|
|
else if (!strcmp (this_char, "grpquota")
|
256 |
|
|
|| !strcmp (this_char, "noquota")
|
257 |
|
|
|| !strcmp (this_char, "quota")
|
258 |
|
|
|| !strcmp (this_char, "usrquota"))
|
259 |
|
|
;
|
260 |
|
|
else {
|
261 |
|
|
printk("AFFS: Unrecognized mount option %s\n", this_char);
|
262 |
|
|
return 0;
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
return 1;
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
/* This function definitely needs to be split up. Some fine day I'll
|
269 |
|
|
* hopefully have the guts to do so. Until then: sorry for the mess.
|
270 |
|
|
*/
|
271 |
|
|
|
272 |
|
|
struct super_block *
|
273 |
|
|
affs_read_super(struct super_block *s,void *data, int silent)
|
274 |
|
|
{
|
275 |
|
|
struct buffer_head *bh = NULL;
|
276 |
|
|
struct buffer_head *bb;
|
277 |
|
|
kdev_t dev = s->s_dev;
|
278 |
|
|
int root_block;
|
279 |
|
|
int size;
|
280 |
|
|
__u32 chksum;
|
281 |
|
|
__u32 *bm;
|
282 |
|
|
int ptype, stype;
|
283 |
|
|
int mapidx;
|
284 |
|
|
int num_bm;
|
285 |
|
|
int i, j;
|
286 |
|
|
int key;
|
287 |
|
|
int blocksize;
|
288 |
|
|
uid_t uid;
|
289 |
|
|
gid_t gid;
|
290 |
|
|
int reserved;
|
291 |
|
|
int az_no;
|
292 |
|
|
unsigned long mount_flags;
|
293 |
|
|
unsigned long offset;
|
294 |
|
|
|
295 |
|
|
pr_debug("affs_read_super(%s)\n",data ? (const char *)data : "no options");
|
296 |
|
|
|
297 |
|
|
MOD_INC_USE_COUNT;
|
298 |
|
|
|
299 |
|
|
if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block,
|
300 |
|
|
&blocksize,&s->u.affs_sb.s_prefix,s->u.affs_sb.s_volume,&mount_flags)) {
|
301 |
|
|
s->s_dev = 0;
|
302 |
|
|
printk("AFFS: error parsing options.\n");
|
303 |
|
|
MOD_DEC_USE_COUNT;
|
304 |
|
|
return NULL;
|
305 |
|
|
}
|
306 |
|
|
lock_super(s);
|
307 |
|
|
|
308 |
|
|
/* Get the size of the device in 512-byte blocks.
|
309 |
|
|
* If we later see that the partition uses bigger
|
310 |
|
|
* blocks, we will have to change it.
|
311 |
|
|
*/
|
312 |
|
|
|
313 |
|
|
size = blksize_size[MAJOR(dev)][MINOR(dev)];
|
314 |
|
|
size = (size ? size : BLOCK_SIZE) / 512 * blk_size[MAJOR(dev)][MINOR(dev)];
|
315 |
|
|
|
316 |
|
|
s->u.affs_sb.s_bitmap = NULL;
|
317 |
|
|
s->u.affs_sb.s_root_bh = NULL;
|
318 |
|
|
s->u.affs_sb.s_flags = mount_flags;
|
319 |
|
|
s->u.affs_sb.s_mode = i;
|
320 |
|
|
s->u.affs_sb.s_uid = uid;
|
321 |
|
|
s->u.affs_sb.s_gid = gid;
|
322 |
|
|
|
323 |
|
|
if (size == 0) {
|
324 |
|
|
s->s_dev = 0;
|
325 |
|
|
unlock_super(s);
|
326 |
|
|
printk("affs_read_super: could not determine device size\n");
|
327 |
|
|
goto out;
|
328 |
|
|
}
|
329 |
|
|
s->u.affs_sb.s_partition_size = size;
|
330 |
|
|
s->u.affs_sb.s_reserved = reserved;
|
331 |
|
|
|
332 |
|
|
/* Try to find root block. Its location may depend on the block size. */
|
333 |
|
|
|
334 |
|
|
s->u.affs_sb.s_hashsize = 0;
|
335 |
|
|
if (blocksize > 0) {
|
336 |
|
|
chksum = blocksize;
|
337 |
|
|
num_bm = blocksize;
|
338 |
|
|
} else {
|
339 |
|
|
chksum = 512;
|
340 |
|
|
num_bm = 4096;
|
341 |
|
|
}
|
342 |
|
|
for (blocksize = chksum; blocksize <= num_bm; blocksize <<= 1, size >>= 1) {
|
343 |
|
|
if (root_block < 0)
|
344 |
|
|
s->u.affs_sb.s_root_block = (reserved + size - 1) / 2;
|
345 |
|
|
else
|
346 |
|
|
s->u.affs_sb.s_root_block = root_block;
|
347 |
|
|
pr_debug("Trying bs=%d bytes, root at %d, size=%d blocks (%d reserved)\n",
|
348 |
|
|
blocksize,s->u.affs_sb.s_root_block,size,reserved);
|
349 |
|
|
set_blocksize(dev,blocksize);
|
350 |
|
|
bh = affs_bread(dev,s->u.affs_sb.s_root_block,blocksize);
|
351 |
|
|
if (!bh) {
|
352 |
|
|
printk("AFFS: unable to read root block\n");
|
353 |
|
|
goto out;
|
354 |
|
|
}
|
355 |
|
|
if (!affs_checksum_block(blocksize,bh->b_data,&ptype,&stype) &&
|
356 |
|
|
ptype == T_SHORT && stype == ST_ROOT) {
|
357 |
|
|
s->s_blocksize = blocksize;
|
358 |
|
|
s->u.affs_sb.s_hashsize = blocksize / 4 - 56;
|
359 |
|
|
break;
|
360 |
|
|
}
|
361 |
|
|
affs_brelse(bh);
|
362 |
|
|
bh = NULL;
|
363 |
|
|
}
|
364 |
|
|
if (!s->u.affs_sb.s_hashsize) {
|
365 |
|
|
affs_brelse(bh);
|
366 |
|
|
if (!silent)
|
367 |
|
|
printk("AFFS: Can't find a valid root block on device %s\n",kdevname(dev));
|
368 |
|
|
goto out;
|
369 |
|
|
}
|
370 |
|
|
root_block = s->u.affs_sb.s_root_block;
|
371 |
|
|
|
372 |
|
|
s->u.affs_sb.s_partition_size = size;
|
373 |
|
|
s->s_blocksize_bits = blocksize == 512 ? 9 :
|
374 |
|
|
blocksize == 1024 ? 10 :
|
375 |
|
|
blocksize == 2048 ? 11 : 12;
|
376 |
|
|
|
377 |
|
|
/* Find out which kind of FS we have */
|
378 |
|
|
bb = affs_bread(dev,0,s->s_blocksize);
|
379 |
|
|
if (bb) {
|
380 |
|
|
chksum = htonl(*(__u32 *)bb->b_data);
|
381 |
|
|
|
382 |
|
|
/* Dircache filesystems are compatible with non-dircache ones
|
383 |
|
|
* when reading. As long as they aren't supported, writing is
|
384 |
|
|
* not recommended.
|
385 |
|
|
*/
|
386 |
|
|
if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
|
387 |
|
|
|| chksum == MUFS_DCOFS) && !(s->s_flags & MS_RDONLY)) {
|
388 |
|
|
printk("AFFS: Dircache FS - mounting %s read only.\n",kdevname(dev));
|
389 |
|
|
s->s_flags |= MS_RDONLY;
|
390 |
|
|
}
|
391 |
|
|
switch (chksum) {
|
392 |
|
|
case MUFS_FS:
|
393 |
|
|
case MUFS_INTLFFS:
|
394 |
|
|
s->u.affs_sb.s_flags |= SF_MUFS;
|
395 |
|
|
/* fall thru */
|
396 |
|
|
case FS_INTLFFS:
|
397 |
|
|
s->u.affs_sb.s_flags |= SF_INTL;
|
398 |
|
|
break;
|
399 |
|
|
case MUFS_DCFFS:
|
400 |
|
|
case MUFS_FFS:
|
401 |
|
|
s->u.affs_sb.s_flags |= SF_MUFS;
|
402 |
|
|
break;
|
403 |
|
|
case FS_DCFFS:
|
404 |
|
|
case FS_FFS:
|
405 |
|
|
break;
|
406 |
|
|
case MUFS_OFS:
|
407 |
|
|
s->u.affs_sb.s_flags |= SF_MUFS;
|
408 |
|
|
/* fall thru */
|
409 |
|
|
case FS_OFS:
|
410 |
|
|
s->u.affs_sb.s_flags |= SF_OFS;
|
411 |
|
|
break;
|
412 |
|
|
case MUFS_DCOFS:
|
413 |
|
|
case MUFS_INTLOFS:
|
414 |
|
|
s->u.affs_sb.s_flags |= SF_MUFS;
|
415 |
|
|
case FS_DCOFS:
|
416 |
|
|
case FS_INTLOFS:
|
417 |
|
|
s->u.affs_sb.s_flags |= SF_INTL | SF_OFS;
|
418 |
|
|
break;
|
419 |
|
|
default:
|
420 |
|
|
printk("AFFS: Unknown filesystem on device %s: %08X\n",
|
421 |
|
|
kdevname(dev),chksum);
|
422 |
|
|
affs_brelse(bb);
|
423 |
|
|
goto out;
|
424 |
|
|
}
|
425 |
|
|
affs_brelse(bb);
|
426 |
|
|
} else {
|
427 |
|
|
printk("AFFS: Can't get boot block.\n");
|
428 |
|
|
goto out;
|
429 |
|
|
}
|
430 |
|
|
if (mount_flags & SF_VERBOSE) {
|
431 |
|
|
chksum = ntohl(chksum);
|
432 |
|
|
printk("AFFS: Mounting volume \"%*s\": Type=%.3s\\%c, Blocksize=%d\n",
|
433 |
|
|
GET_END_PTR(struct root_end,bh->b_data,blocksize)->disk_name[0],
|
434 |
|
|
&GET_END_PTR(struct root_end,bh->b_data,blocksize)->disk_name[1],
|
435 |
|
|
(char *)&chksum,((char *)&chksum)[3] + '0',blocksize);
|
436 |
|
|
}
|
437 |
|
|
|
438 |
|
|
s->s_magic = AFFS_SUPER_MAGIC;
|
439 |
|
|
s->s_flags |= MS_NODEV | MS_NOSUID;
|
440 |
|
|
|
441 |
|
|
/* Keep super block in cache */
|
442 |
|
|
if (!(s->u.affs_sb.s_root_bh = affs_bread(dev,root_block,s->s_blocksize))) {
|
443 |
|
|
printk("AFFS: Can't read root block a second time\n");
|
444 |
|
|
goto out;
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
/* Allocate space for bitmaps, zones and others */
|
448 |
|
|
|
449 |
|
|
size = s->u.affs_sb.s_partition_size - reserved;
|
450 |
|
|
num_bm = (size + s->s_blocksize * 8 - 32 - 1) / (s->s_blocksize * 8 - 32);
|
451 |
|
|
az_no = (size + AFFS_ZONE_SIZE - 1) / (AFFS_ZONE_SIZE - 32);
|
452 |
|
|
ptype = num_bm * sizeof(struct affs_bm_info) +
|
453 |
|
|
az_no * sizeof(struct affs_alloc_zone) +
|
454 |
|
|
MAX_ZONES * sizeof(struct affs_zone);
|
455 |
|
|
pr_debug("num_bm=%d, az_no=%d, sum=%d\n",num_bm,az_no,ptype);
|
456 |
|
|
if (!(s->u.affs_sb.s_bitmap = kmalloc(ptype,GFP_KERNEL))) {
|
457 |
|
|
printk("AFFS: Not enough memory.\n");
|
458 |
|
|
goto out;
|
459 |
|
|
}
|
460 |
|
|
memset(s->u.affs_sb.s_bitmap,0,ptype);
|
461 |
|
|
|
462 |
|
|
s->u.affs_sb.s_zones = (struct affs_zone *)&s->u.affs_sb.s_bitmap[num_bm];
|
463 |
|
|
s->u.affs_sb.s_alloc = (struct affs_alloc_zone *)&s->u.affs_sb.s_zones[MAX_ZONES];
|
464 |
|
|
s->u.affs_sb.s_num_az = az_no;
|
465 |
|
|
|
466 |
|
|
mapidx = 0;
|
467 |
|
|
|
468 |
|
|
if (ROOT_END_S(bh->b_data,s)->bm_flag == 0) {
|
469 |
|
|
if (!(s->s_flags & MS_RDONLY)) {
|
470 |
|
|
printk("AFFS: Bitmap invalid - mounting %s read only.\n",kdevname(dev));
|
471 |
|
|
s->s_flags |= MS_RDONLY;
|
472 |
|
|
}
|
473 |
|
|
affs_brelse(bh);
|
474 |
|
|
bh = NULL;
|
475 |
|
|
goto nobitmap;
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
/* The following section is ugly, I know. Especially because of the
|
479 |
|
|
* reuse of some variables that are not named properly.
|
480 |
|
|
*/
|
481 |
|
|
|
482 |
|
|
key = root_block;
|
483 |
|
|
ptype = s->s_blocksize / 4 - 49;
|
484 |
|
|
stype = ptype + 25;
|
485 |
|
|
offset = s->u.affs_sb.s_reserved;
|
486 |
|
|
az_no = 0;
|
487 |
|
|
while (bh) {
|
488 |
|
|
bm = (__u32 *)bh->b_data;
|
489 |
|
|
for (i = ptype; i < stype && bm[i]; i++, mapidx++) {
|
490 |
|
|
if (mapidx >= num_bm) {
|
491 |
|
|
printk("AFFS: Not enough bitmap space!?\n");
|
492 |
|
|
goto out;
|
493 |
|
|
}
|
494 |
|
|
bb = affs_bread(s->s_dev,htonl(bm[i]),s->s_blocksize);
|
495 |
|
|
if (bb) {
|
496 |
|
|
if (affs_checksum_block(s->s_blocksize,bb->b_data,NULL,NULL) &&
|
497 |
|
|
!(s->s_flags & MS_RDONLY)) {
|
498 |
|
|
printk("AFFS: Bitmap (%d,key=%lu) invalid - "
|
499 |
|
|
"mounting %s read only.\n",mapidx,htonl(bm[i]),
|
500 |
|
|
kdevname(dev));
|
501 |
|
|
s->s_flags |= MS_RDONLY;
|
502 |
|
|
}
|
503 |
|
|
/* Mark unused bits in the last word as allocated */
|
504 |
|
|
if (size <= s->s_blocksize * 8 - 32) { /* last bitmap */
|
505 |
|
|
ptype = size / 32 + 1; /* word number */
|
506 |
|
|
key = size & 0x1F; /* used bits */
|
507 |
|
|
if (key) {
|
508 |
|
|
chksum = ntohl(0x7FFFFFFF >> (31 - key));
|
509 |
|
|
((__u32 *)bb->b_data)[ptype] &= chksum;
|
510 |
|
|
affs_fix_checksum(s->s_blocksize,bb->b_data,0);
|
511 |
|
|
mark_buffer_dirty(bb,1);
|
512 |
|
|
}
|
513 |
|
|
ptype = (size + 31) & ~0x1F;
|
514 |
|
|
size = 0;
|
515 |
|
|
if (!(s->s_flags & MS_RDONLY))
|
516 |
|
|
s->u.affs_sb.s_flags |= SF_BM_VALID;
|
517 |
|
|
} else {
|
518 |
|
|
ptype = s->s_blocksize * 8 - 32;
|
519 |
|
|
size -= ptype;
|
520 |
|
|
}
|
521 |
|
|
s->u.affs_sb.s_bitmap[mapidx].bm_firstblk = offset;
|
522 |
|
|
s->u.affs_sb.s_bitmap[mapidx].bm_bh = NULL;
|
523 |
|
|
s->u.affs_sb.s_bitmap[mapidx].bm_key = htonl(bm[i]);
|
524 |
|
|
s->u.affs_sb.s_bitmap[mapidx].bm_count = 0;
|
525 |
|
|
offset += ptype;
|
526 |
|
|
|
527 |
|
|
for (j = 0; ptype > 0; j++, az_no++, ptype -= key) {
|
528 |
|
|
key = MIN(ptype,AFFS_ZONE_SIZE); /* size in bits */
|
529 |
|
|
s->u.affs_sb.s_alloc[az_no].az_size = key / 32;
|
530 |
|
|
s->u.affs_sb.s_alloc[az_no].az_free =
|
531 |
|
|
affs_count_free_bits(key / 8,bb->b_data +
|
532 |
|
|
j * (AFFS_ZONE_SIZE / 8) + 4);
|
533 |
|
|
}
|
534 |
|
|
affs_brelse(bb);
|
535 |
|
|
} else {
|
536 |
|
|
printk("AFFS: Can't read bitmap.\n");
|
537 |
|
|
goto out;
|
538 |
|
|
}
|
539 |
|
|
}
|
540 |
|
|
key = htonl(bm[stype]); /* Next block of bitmap pointers */
|
541 |
|
|
ptype = 0;
|
542 |
|
|
stype = s->s_blocksize / 4 - 1;
|
543 |
|
|
affs_brelse(bh);
|
544 |
|
|
if (key) {
|
545 |
|
|
if (!(bh = affs_bread(s->s_dev,key,s->s_blocksize))) {
|
546 |
|
|
printk("AFFS: Can't read bitmap extension.\n");
|
547 |
|
|
goto out;
|
548 |
|
|
}
|
549 |
|
|
} else
|
550 |
|
|
bh = NULL;
|
551 |
|
|
}
|
552 |
|
|
if (mapidx != num_bm) {
|
553 |
|
|
printk("AFFS: Got only %d bitmap blocks, expected %d\n",mapidx,num_bm);
|
554 |
|
|
goto out;
|
555 |
|
|
}
|
556 |
|
|
nobitmap:
|
557 |
|
|
s->u.affs_sb.s_bm_count = mapidx;
|
558 |
|
|
|
559 |
|
|
/* set up enough so that it can read an inode */
|
560 |
|
|
|
561 |
|
|
s->s_dev = dev;
|
562 |
|
|
s->s_op = &affs_sops;
|
563 |
|
|
s->s_mounted = iget(s,root_block);
|
564 |
|
|
s->s_dirt = 1;
|
565 |
|
|
unlock_super(s);
|
566 |
|
|
|
567 |
|
|
if (!(s->s_mounted)) {
|
568 |
|
|
s->s_dev = 0;
|
569 |
|
|
printk("AFFS: get root inode failed\n");
|
570 |
|
|
MOD_DEC_USE_COUNT;
|
571 |
|
|
return NULL;
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
/* create data zones if the fs is mounted r/w */
|
575 |
|
|
|
576 |
|
|
if (!(s->s_flags & MS_RDONLY)) {
|
577 |
|
|
ROOT_END(s->u.affs_sb.s_root_bh->b_data,s->s_mounted)->bm_flag = 0;
|
578 |
|
|
secs_to_datestamp(CURRENT_TIME,&ROOT_END(s->u.affs_sb.s_root_bh->b_data,
|
579 |
|
|
s->s_mounted)->disk_altered);
|
580 |
|
|
affs_fix_checksum(s->s_blocksize,s->u.affs_sb.s_root_bh->b_data,5);
|
581 |
|
|
mark_buffer_dirty(s->u.affs_sb.s_root_bh,1);
|
582 |
|
|
affs_make_zones(s);
|
583 |
|
|
}
|
584 |
|
|
|
585 |
|
|
pr_debug("AFFS: s_flags=%lX\n",s->s_flags);
|
586 |
|
|
return s;
|
587 |
|
|
|
588 |
|
|
out: /* Kick out for various error conditions */
|
589 |
|
|
affs_brelse (bh);
|
590 |
|
|
affs_brelse(s->u.affs_sb.s_root_bh);
|
591 |
|
|
if (s->u.affs_sb.s_bitmap)
|
592 |
|
|
kfree(s->u.affs_sb.s_bitmap);
|
593 |
|
|
set_blocksize(dev,BLOCK_SIZE);
|
594 |
|
|
s->s_dev = 0;
|
595 |
|
|
unlock_super(s);
|
596 |
|
|
MOD_DEC_USE_COUNT;
|
597 |
|
|
return NULL;
|
598 |
|
|
}
|
599 |
|
|
|
600 |
|
|
void
|
601 |
|
|
affs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
|
602 |
|
|
{
|
603 |
|
|
int free;
|
604 |
|
|
struct statfs tmp;
|
605 |
|
|
|
606 |
|
|
pr_debug("AFFS: statfs() partsize=%d, reserved=%d\n",sb->u.affs_sb.s_partition_size,
|
607 |
|
|
sb->u.affs_sb.s_reserved);
|
608 |
|
|
|
609 |
|
|
free = affs_count_free_blocks(sb);
|
610 |
|
|
tmp.f_type = AFFS_SUPER_MAGIC;
|
611 |
|
|
tmp.f_bsize = sb->s_blocksize;
|
612 |
|
|
tmp.f_blocks = sb->u.affs_sb.s_partition_size - sb->u.affs_sb.s_reserved;
|
613 |
|
|
tmp.f_bfree = free;
|
614 |
|
|
tmp.f_bavail = free;
|
615 |
|
|
tmp.f_files = 0;
|
616 |
|
|
tmp.f_ffree = 0;
|
617 |
|
|
memcpy_tofs(buf,&tmp,bufsiz);
|
618 |
|
|
}
|
619 |
|
|
|
620 |
|
|
void
|
621 |
|
|
affs_read_inode(struct inode *inode)
|
622 |
|
|
{
|
623 |
|
|
struct buffer_head *bh, *lbh;
|
624 |
|
|
struct file_front *file_front;
|
625 |
|
|
struct file_end *file_end;
|
626 |
|
|
int block;
|
627 |
|
|
unsigned long prot;
|
628 |
|
|
int ptype, stype;
|
629 |
|
|
unsigned short id;
|
630 |
|
|
|
631 |
|
|
pr_debug("AFFS: read_inode(%lu)\n",inode->i_ino);
|
632 |
|
|
lbh = NULL;
|
633 |
|
|
block = inode->i_ino;
|
634 |
|
|
if (!(bh = affs_bread(inode->i_dev,block,AFFS_I2BSIZE(inode)))) {
|
635 |
|
|
printk("AFFS: unable to read i-node block %d\n",block);
|
636 |
|
|
return;
|
637 |
|
|
}
|
638 |
|
|
if (affs_checksum_block(AFFS_I2BSIZE(inode),bh->b_data,&ptype,&stype) || ptype != T_SHORT) {
|
639 |
|
|
printk("AFFS: read_inode(): checksum or type (ptype=%d) error on inode %d\n",
|
640 |
|
|
ptype,block);
|
641 |
|
|
affs_brelse(bh);
|
642 |
|
|
return;
|
643 |
|
|
}
|
644 |
|
|
|
645 |
|
|
file_front = (struct file_front *)bh->b_data;
|
646 |
|
|
file_end = GET_END_PTR(struct file_end, bh->b_data,AFFS_I2BSIZE(inode));
|
647 |
|
|
prot = (htonl(file_end->protect) & ~0x10) ^ FIBF_OWNER;
|
648 |
|
|
|
649 |
|
|
inode->u.affs_i.i_protect = prot;
|
650 |
|
|
inode->u.affs_i.i_parent = htonl(file_end->parent);
|
651 |
|
|
inode->u.affs_i.i_original = 0;
|
652 |
|
|
inode->u.affs_i.i_zone = 0;
|
653 |
|
|
inode->u.affs_i.i_hlink = 0;
|
654 |
|
|
inode->u.affs_i.i_pa_cnt = 0;
|
655 |
|
|
inode->u.affs_i.i_pa_next = 0;
|
656 |
|
|
inode->u.affs_i.i_pa_last = 0;
|
657 |
|
|
inode->u.affs_i.i_ext[0] = 0;
|
658 |
|
|
inode->u.affs_i.i_max_ext = 0;
|
659 |
|
|
inode->u.affs_i.i_lastblock = -1;
|
660 |
|
|
inode->i_nlink = 1;
|
661 |
|
|
inode->i_mode = 0;
|
662 |
|
|
|
663 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_SETMODE)
|
664 |
|
|
inode->i_mode = inode->i_sb->u.affs_sb.s_mode;
|
665 |
|
|
else
|
666 |
|
|
inode->i_mode = prot_to_mode(prot);
|
667 |
|
|
|
668 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_SETUID)
|
669 |
|
|
inode->i_uid = inode->i_sb->u.affs_sb.s_uid;
|
670 |
|
|
else {
|
671 |
|
|
id = htons(file_end->owner_uid);
|
672 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_MUFS) {
|
673 |
|
|
if (id == 0 || id == 0xFFFF)
|
674 |
|
|
id ^= ~0;
|
675 |
|
|
}
|
676 |
|
|
inode->i_uid = id;
|
677 |
|
|
}
|
678 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_SETGID)
|
679 |
|
|
inode->i_gid = inode->i_sb->u.affs_sb.s_gid;
|
680 |
|
|
else {
|
681 |
|
|
id = htons(file_end->owner_gid);
|
682 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_MUFS) {
|
683 |
|
|
if (id == 0 || id == 0xFFFF)
|
684 |
|
|
id ^= ~0;
|
685 |
|
|
}
|
686 |
|
|
inode->i_gid = id;
|
687 |
|
|
}
|
688 |
|
|
|
689 |
|
|
switch (htonl(file_end->secondary_type)) {
|
690 |
|
|
case ST_ROOT:
|
691 |
|
|
inode->i_uid = inode->i_sb->u.affs_sb.s_uid;
|
692 |
|
|
inode->i_gid = inode->i_sb->u.affs_sb.s_gid;
|
693 |
|
|
case ST_USERDIR:
|
694 |
|
|
if (htonl(file_end->secondary_type) == ST_USERDIR ||
|
695 |
|
|
inode->i_sb->u.affs_sb.s_flags & SF_SETMODE) {
|
696 |
|
|
if (inode->i_mode & S_IRUSR)
|
697 |
|
|
inode->i_mode |= S_IXUSR;
|
698 |
|
|
if (inode->i_mode & S_IRGRP)
|
699 |
|
|
inode->i_mode |= S_IXGRP;
|
700 |
|
|
if (inode->i_mode & S_IROTH)
|
701 |
|
|
inode->i_mode |= S_IXOTH;
|
702 |
|
|
inode->i_mode |= S_IFDIR;
|
703 |
|
|
} else
|
704 |
|
|
inode->i_mode = S_IRUGO | S_IXUGO | S_IWUSR | S_IFDIR;
|
705 |
|
|
inode->i_size = 0;
|
706 |
|
|
break;
|
707 |
|
|
case ST_LINKDIR:
|
708 |
|
|
inode->u.affs_i.i_original = htonl(file_end->original);
|
709 |
|
|
inode->u.affs_i.i_hlink = 1;
|
710 |
|
|
inode->i_mode |= S_IFDIR;
|
711 |
|
|
inode->i_size = 0;
|
712 |
|
|
break;
|
713 |
|
|
case ST_LINKFILE:
|
714 |
|
|
inode->u.affs_i.i_original = htonl(file_end->original);
|
715 |
|
|
inode->u.affs_i.i_hlink = 1;
|
716 |
|
|
if (!(lbh = affs_bread(inode->i_dev,inode->u.affs_i.i_original,
|
717 |
|
|
AFFS_I2BSIZE(inode)))) {
|
718 |
|
|
affs_brelse(bh);
|
719 |
|
|
printk("AFFS: unable to read i-node block %ld\n",inode->i_ino);
|
720 |
|
|
return;
|
721 |
|
|
}
|
722 |
|
|
file_end = GET_END_PTR(struct file_end,lbh->b_data,AFFS_I2BSIZE(inode));
|
723 |
|
|
case ST_FILE:
|
724 |
|
|
inode->i_mode |= S_IFREG;
|
725 |
|
|
inode->i_size = htonl(file_end->byte_size);
|
726 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_OFS)
|
727 |
|
|
block = AFFS_I2BSIZE(inode) - 24;
|
728 |
|
|
else
|
729 |
|
|
block = AFFS_I2BSIZE(inode);
|
730 |
|
|
inode->u.affs_i.i_lastblock = ((inode->i_size + block - 1) / block) - 1;
|
731 |
|
|
break;
|
732 |
|
|
case ST_SOFTLINK:
|
733 |
|
|
inode->i_mode |= S_IFLNK;
|
734 |
|
|
inode->i_size = 0;
|
735 |
|
|
break;
|
736 |
|
|
}
|
737 |
|
|
|
738 |
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime
|
739 |
|
|
= (htonl(file_end->created.ds_Days) * (24 * 60 * 60) +
|
740 |
|
|
htonl(file_end->created.ds_Minute) * 60 +
|
741 |
|
|
htonl(file_end->created.ds_Tick) / 50 +
|
742 |
|
|
((8 * 365 + 2) * 24 * 60 * 60)) +
|
743 |
|
|
sys_tz.tz_minuteswest * 60;
|
744 |
|
|
affs_brelse(bh);
|
745 |
|
|
affs_brelse(lbh);
|
746 |
|
|
|
747 |
|
|
inode->i_op = NULL;
|
748 |
|
|
if (S_ISREG(inode->i_mode)) {
|
749 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_OFS) {
|
750 |
|
|
inode->i_op = &affs_file_inode_operations_ofs;
|
751 |
|
|
} else {
|
752 |
|
|
inode->i_op = &affs_file_inode_operations;
|
753 |
|
|
}
|
754 |
|
|
} else if (S_ISDIR(inode->i_mode))
|
755 |
|
|
inode->i_op = &affs_dir_inode_operations;
|
756 |
|
|
else if (S_ISLNK(inode->i_mode))
|
757 |
|
|
inode->i_op = &affs_symlink_inode_operations;
|
758 |
|
|
}
|
759 |
|
|
|
760 |
|
|
void
|
761 |
|
|
affs_write_inode(struct inode *inode)
|
762 |
|
|
{
|
763 |
|
|
struct buffer_head *bh;
|
764 |
|
|
struct file_end *file_end;
|
765 |
|
|
short uid, gid;
|
766 |
|
|
|
767 |
|
|
pr_debug("AFFS: write_inode(%lu)\n",inode->i_ino);
|
768 |
|
|
|
769 |
|
|
inode->i_dirt = 0;
|
770 |
|
|
if (!inode->i_nlink)
|
771 |
|
|
return;
|
772 |
|
|
if (!(bh = bread(inode->i_dev,inode->i_ino,AFFS_I2BSIZE(inode)))) {
|
773 |
|
|
printk("AFFS: Unable to read block of inode %ld on %s\n",
|
774 |
|
|
inode->i_ino,kdevname(inode->i_dev));
|
775 |
|
|
return;
|
776 |
|
|
}
|
777 |
|
|
file_end = GET_END_PTR(struct file_end, bh->b_data,AFFS_I2BSIZE(inode));
|
778 |
|
|
if (file_end->secondary_type == htonl(ST_ROOT)) {
|
779 |
|
|
secs_to_datestamp(inode->i_mtime,&ROOT_END(bh->b_data,inode)->disk_altered);
|
780 |
|
|
} else {
|
781 |
|
|
file_end->protect = ntohl(inode->u.affs_i.i_protect ^ FIBF_OWNER);
|
782 |
|
|
file_end->byte_size = ntohl(inode->i_size);
|
783 |
|
|
secs_to_datestamp(inode->i_mtime,&file_end->created);
|
784 |
|
|
if (!(inode->i_ino == inode->i_sb->u.affs_sb.s_root_block)) {
|
785 |
|
|
uid = inode->i_uid;
|
786 |
|
|
gid = inode->i_gid;
|
787 |
|
|
if (inode->i_sb->u.affs_sb.s_flags & SF_MUFS) {
|
788 |
|
|
if (inode->i_uid == 0 || inode->i_uid == 0xFFFF)
|
789 |
|
|
uid = inode->i_uid ^ ~0;
|
790 |
|
|
if (inode->i_gid == 0 || inode->i_gid == 0xFFFF)
|
791 |
|
|
gid = inode->i_gid ^ ~0;
|
792 |
|
|
}
|
793 |
|
|
if (!(inode->i_sb->u.affs_sb.s_flags & SF_SETUID))
|
794 |
|
|
file_end->owner_uid = ntohs(uid);
|
795 |
|
|
if (!(inode->i_sb->u.affs_sb.s_flags & SF_SETGID))
|
796 |
|
|
file_end->owner_gid = ntohs(gid);
|
797 |
|
|
}
|
798 |
|
|
}
|
799 |
|
|
affs_fix_checksum(AFFS_I2BSIZE(inode),bh->b_data,5);
|
800 |
|
|
mark_buffer_dirty(bh,1);
|
801 |
|
|
brelse(bh);
|
802 |
|
|
}
|
803 |
|
|
|
804 |
|
|
int
|
805 |
|
|
affs_notify_change(struct inode *inode, struct iattr *attr)
|
806 |
|
|
{
|
807 |
|
|
int error;
|
808 |
|
|
|
809 |
|
|
pr_debug("AFFS: notify_change(%lu,0x%x)\n",inode->i_ino,attr->ia_valid);
|
810 |
|
|
|
811 |
|
|
error = inode_change_ok(inode,attr);
|
812 |
|
|
if (error)
|
813 |
|
|
return error;
|
814 |
|
|
|
815 |
|
|
if (((attr->ia_valid & ATTR_UID) && (inode->i_sb->u.affs_sb.s_flags & SF_SETUID)) ||
|
816 |
|
|
((attr->ia_valid & ATTR_GID) && (inode->i_sb->u.affs_sb.s_flags & SF_SETGID)) ||
|
817 |
|
|
((attr->ia_valid & ATTR_MODE) &&
|
818 |
|
|
(inode->i_sb->u.affs_sb.s_flags & (SF_SETMODE | SF_IMMUTABLE))))
|
819 |
|
|
error = -EPERM;
|
820 |
|
|
|
821 |
|
|
if (error)
|
822 |
|
|
return (inode->i_sb->u.affs_sb.s_flags & SF_QUIET) ? 0 : error;
|
823 |
|
|
|
824 |
|
|
if (attr->ia_valid & ATTR_MODE)
|
825 |
|
|
inode->u.affs_i.i_protect = mode_to_prot(attr->ia_mode);
|
826 |
|
|
|
827 |
|
|
inode_setattr(inode,attr);
|
828 |
|
|
|
829 |
|
|
return 0;
|
830 |
|
|
}
|
831 |
|
|
|
832 |
|
|
void
|
833 |
|
|
affs_put_inode(struct inode *inode)
|
834 |
|
|
{
|
835 |
|
|
pr_debug("AFFS: put_inode(ino=%lu, nlink=%u)\n",inode->i_ino,inode->i_nlink);
|
836 |
|
|
if (inode->i_nlink) {
|
837 |
|
|
return;
|
838 |
|
|
}
|
839 |
|
|
inode->i_size = 0;
|
840 |
|
|
if (S_ISREG(inode->i_mode) && !inode->u.affs_i.i_hlink)
|
841 |
|
|
affs_truncate(inode);
|
842 |
|
|
affs_free_block(inode->i_sb,inode->i_ino);
|
843 |
|
|
clear_inode(inode);
|
844 |
|
|
}
|
845 |
|
|
|
846 |
|
|
struct inode *
|
847 |
|
|
affs_new_inode(const struct inode *dir)
|
848 |
|
|
{
|
849 |
|
|
struct inode *inode;
|
850 |
|
|
struct super_block *sb;
|
851 |
|
|
int block;
|
852 |
|
|
|
853 |
|
|
if (!dir || !(inode = get_empty_inode()))
|
854 |
|
|
return NULL;
|
855 |
|
|
|
856 |
|
|
sb = dir->i_sb;
|
857 |
|
|
inode->i_sb = sb;
|
858 |
|
|
inode->i_flags = sb->s_flags;
|
859 |
|
|
|
860 |
|
|
if (!(block = affs_new_header((struct inode *)dir))) {
|
861 |
|
|
iput(inode);
|
862 |
|
|
return NULL;
|
863 |
|
|
}
|
864 |
|
|
|
865 |
|
|
inode->i_count = 1;
|
866 |
|
|
inode->i_nlink = 1;
|
867 |
|
|
inode->i_dev = sb->s_dev;
|
868 |
|
|
inode->i_uid = current->fsuid;
|
869 |
|
|
inode->i_gid = current->fsgid;
|
870 |
|
|
inode->i_dirt = 1;
|
871 |
|
|
inode->i_ino = block;
|
872 |
|
|
inode->i_op = NULL;
|
873 |
|
|
inode->i_blocks = 0;
|
874 |
|
|
inode->i_size = 0;
|
875 |
|
|
inode->i_mode = 0;
|
876 |
|
|
inode->i_blksize = 0;
|
877 |
|
|
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
|
878 |
|
|
|
879 |
|
|
inode->u.affs_i.i_original = 0;
|
880 |
|
|
inode->u.affs_i.i_parent = dir->i_ino;
|
881 |
|
|
inode->u.affs_i.i_zone = 0;
|
882 |
|
|
inode->u.affs_i.i_hlink = 0;
|
883 |
|
|
inode->u.affs_i.i_pa_cnt = 0;
|
884 |
|
|
inode->u.affs_i.i_pa_next = 0;
|
885 |
|
|
inode->u.affs_i.i_pa_last = 0;
|
886 |
|
|
inode->u.affs_i.i_ext[0] = 0;
|
887 |
|
|
inode->u.affs_i.i_max_ext = 0;
|
888 |
|
|
inode->u.affs_i.i_lastblock = -1;
|
889 |
|
|
|
890 |
|
|
insert_inode_hash(inode);
|
891 |
|
|
|
892 |
|
|
return inode;
|
893 |
|
|
}
|
894 |
|
|
|
895 |
|
|
int
|
896 |
|
|
affs_add_entry(struct inode *dir, struct inode *link, struct inode *inode,
|
897 |
|
|
const char *name, int len, int type)
|
898 |
|
|
{
|
899 |
|
|
struct buffer_head *dir_bh;
|
900 |
|
|
struct buffer_head *inode_bh;
|
901 |
|
|
struct buffer_head *link_bh;
|
902 |
|
|
int hash;
|
903 |
|
|
|
904 |
|
|
pr_debug("AFFS: add_entry(dir=%lu,inode=%lu,\"%*s\",type=%d\n",dir->i_ino,inode->i_ino,
|
905 |
|
|
len,name,type);
|
906 |
|
|
|
907 |
|
|
dir_bh = affs_bread(dir->i_dev,dir->i_ino,AFFS_I2BSIZE(dir));
|
908 |
|
|
inode_bh = affs_bread(inode->i_dev,inode->i_ino,AFFS_I2BSIZE(inode));
|
909 |
|
|
link_bh = NULL;
|
910 |
|
|
if (!dir_bh || !inode_bh) {
|
911 |
|
|
affs_brelse(dir_bh);
|
912 |
|
|
affs_brelse(inode_bh);
|
913 |
|
|
return -ENOSPC;
|
914 |
|
|
}
|
915 |
|
|
if (link) {
|
916 |
|
|
link_bh = affs_bread(link->i_dev,link->i_ino,AFFS_I2BSIZE(link));
|
917 |
|
|
if (!link_bh) {
|
918 |
|
|
affs_brelse(dir_bh);
|
919 |
|
|
affs_brelse(inode_bh);
|
920 |
|
|
return -EINVAL;
|
921 |
|
|
}
|
922 |
|
|
}
|
923 |
|
|
((struct dir_front *)inode_bh->b_data)->primary_type = ntohl(T_SHORT);
|
924 |
|
|
((struct dir_front *)inode_bh->b_data)->own_key = ntohl(inode->i_ino);
|
925 |
|
|
|
926 |
|
|
if (len > 30) /* truncate name quietly */
|
927 |
|
|
len = 30;
|
928 |
|
|
DIR_END(inode_bh->b_data,inode)->dir_name[0] = len;
|
929 |
|
|
strncpy(DIR_END(inode_bh->b_data,inode)->dir_name + 1,name,len);
|
930 |
|
|
DIR_END(inode_bh->b_data,inode)->secondary_type = ntohl(type);
|
931 |
|
|
DIR_END(inode_bh->b_data,inode)->parent = ntohl(dir->i_ino);
|
932 |
|
|
hash = affs_hash_name(name,len,AFFS_I2FSTYPE(dir),AFFS_I2HSIZE(dir));
|
933 |
|
|
|
934 |
|
|
lock_super(inode->i_sb);
|
935 |
|
|
DIR_END(inode_bh->b_data,inode)->hash_chain =
|
936 |
|
|
((struct dir_front *)dir_bh->b_data)->hashtable[hash];
|
937 |
|
|
((struct dir_front *)dir_bh->b_data)->hashtable[hash] = ntohl(inode->i_ino);
|
938 |
|
|
if (link_bh) {
|
939 |
|
|
LINK_END(inode_bh->b_data,inode)->original = ntohl(link->i_ino);
|
940 |
|
|
LINK_END(inode_bh->b_data,inode)->link_chain =
|
941 |
|
|
FILE_END(link_bh->b_data,link)->link_chain;
|
942 |
|
|
FILE_END(link_bh->b_data,link)->link_chain = ntohl(inode->i_ino);
|
943 |
|
|
affs_fix_checksum(AFFS_I2BSIZE(link),link_bh->b_data,5);
|
944 |
|
|
link->i_version = ++event;
|
945 |
|
|
link->i_dirt = 1;
|
946 |
|
|
mark_buffer_dirty(link_bh,1);
|
947 |
|
|
}
|
948 |
|
|
affs_fix_checksum(AFFS_I2BSIZE(inode),inode_bh->b_data,5);
|
949 |
|
|
affs_fix_checksum(AFFS_I2BSIZE(dir),dir_bh->b_data,5);
|
950 |
|
|
dir->i_version = ++event;
|
951 |
|
|
dir->i_mtime = dir->i_atime = dir->i_ctime = CURRENT_TIME;
|
952 |
|
|
unlock_super(inode->i_sb);
|
953 |
|
|
|
954 |
|
|
dir->i_dirt = 1;
|
955 |
|
|
inode->i_dirt = 1;
|
956 |
|
|
mark_buffer_dirty(dir_bh,1);
|
957 |
|
|
mark_buffer_dirty(inode_bh,1);
|
958 |
|
|
affs_brelse(dir_bh);
|
959 |
|
|
affs_brelse(inode_bh);
|
960 |
|
|
affs_brelse(link_bh);
|
961 |
|
|
|
962 |
|
|
return 0;
|
963 |
|
|
}
|
964 |
|
|
|
965 |
|
|
static struct file_system_type affs_fs_type = {
|
966 |
|
|
affs_read_super,
|
967 |
|
|
"affs",
|
968 |
|
|
1,
|
969 |
|
|
NULL
|
970 |
|
|
};
|
971 |
|
|
|
972 |
|
|
int
|
973 |
|
|
init_affs_fs(void)
|
974 |
|
|
{
|
975 |
|
|
return register_filesystem(&affs_fs_type);
|
976 |
|
|
}
|
977 |
|
|
|
978 |
|
|
#ifdef MODULE
|
979 |
|
|
|
980 |
|
|
int
|
981 |
|
|
init_module(void)
|
982 |
|
|
{
|
983 |
|
|
int status;
|
984 |
|
|
if ((status = init_affs_fs()) == 0)
|
985 |
|
|
register_symtab(0);
|
986 |
|
|
return status;
|
987 |
|
|
}
|
988 |
|
|
|
989 |
|
|
void
|
990 |
|
|
cleanup_module(void)
|
991 |
|
|
{
|
992 |
|
|
unregister_filesystem(&affs_fs_type);
|
993 |
|
|
}
|
994 |
|
|
|
995 |
|
|
#endif
|