OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [fs/] [ufs/] [super.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  linux/fs/ufs/super.c
3
 *
4
 * Copyright (C) 1998
5
 * Daniel Pirkl <daniel.pirkl@email.cz>
6
 * Charles University, Faculty of Mathematics and Physics
7
 */
8
 
9
/* Derived from
10
 *
11
 *  linux/fs/ext2/super.c
12
 *
13
 * Copyright (C) 1992, 1993, 1994, 1995
14
 * Remy Card (card@masi.ibp.fr)
15
 * Laboratoire MASI - Institut Blaise Pascal
16
 * Universite Pierre et Marie Curie (Paris VI)
17
 *
18
 *  from
19
 *
20
 *  linux/fs/minix/inode.c
21
 *
22
 *  Copyright (C) 1991, 1992  Linus Torvalds
23
 *
24
 *  Big-endian to little-endian byte-swapping/bitmaps by
25
 *        David S. Miller (davem@caip.rutgers.edu), 1995
26
 */
27
 
28
/*
29
 * Inspired by
30
 *
31
 *  linux/fs/ufs/super.c
32
 *
33
 * Copyright (C) 1996
34
 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
35
 * Laboratory for Computer Science Research Computing Facility
36
 * Rutgers, The State University of New Jersey
37
 *
38
 * Copyright (C) 1996  Eddie C. Dost  (ecd@skynet.be)
39
 *
40
 * Kernel module support added on 96/04/26 by
41
 * Stefan Reinauer <stepan@home.culture.mipt.ru>
42
 *
43
 * Module usage counts added on 96/04/29 by
44
 * Gertjan van Wingerde <gertjan@cs.vu.nl>
45
 *
46
 * Clean swab support on 19970406 by
47
 * Francois-Rene Rideau <fare@tunes.org>
48
 *
49
 * 4.4BSD (FreeBSD) support added on February 1st 1998 by
50
 * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
51
 * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
52
 *
53
 * NeXTstep support added on February 5th 1998 by
54
 * Niels Kristian Bech Jensen <nkbj@image.dk>.
55
 *
56
 * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
57
 *
58
 * HP/UX hfs filesystem support added by
59
 * Martin K. Petersen <mkp@mkp.net>, August 1999
60
 *
61
 */
62
 
63
 
64
#include <linux/config.h>
65
#include <linux/module.h>
66
 
67
#include <stdarg.h>
68
 
69
#include <asm/bitops.h>
70
#include <asm/uaccess.h>
71
#include <asm/system.h>
72
 
73
#include <linux/errno.h>
74
#include <linux/fs.h>
75
#include <linux/ufs_fs.h>
76
#include <linux/slab.h>
77
#include <linux/sched.h>
78
#include <linux/stat.h>
79
#include <linux/string.h>
80
#include <linux/locks.h>
81
#include <linux/blkdev.h>
82
#include <linux/init.h>
83
 
84
#include "swab.h"
85
#include "util.h"
86
 
87
#undef UFS_SUPER_DEBUG
88
#undef UFS_SUPER_DEBUG_MORE
89
 
90
#ifdef UFS_SUPER_DEBUG
91
#define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
92
#else
93
#define UFSD(x)
94
#endif
95
 
96
#ifdef UFS_SUPER_DEBUG_MORE
97
/*
98
 * Print contents of ufs_super_block, useful for debugging
99
 */
100
void ufs_print_super_stuff(struct super_block *sb,
101
        struct ufs_super_block_first * usb1,
102
        struct ufs_super_block_second * usb2,
103
        struct ufs_super_block_third * usb3)
104
{
105
        printk("ufs_print_super_stuff\n");
106
        printk("size of usb:     %u\n", sizeof(struct ufs_super_block));
107
        printk("  magic:         0x%x\n", fs32_to_cpu(sb, usb3->fs_magic));
108
        printk("  sblkno:        %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
109
        printk("  cblkno:        %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
110
        printk("  iblkno:        %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
111
        printk("  dblkno:        %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
112
        printk("  cgoffset:      %u\n", fs32_to_cpu(sb, usb1->fs_cgoffset));
113
        printk("  ~cgmask:       0x%x\n", ~fs32_to_cpu(sb, usb1->fs_cgmask));
114
        printk("  size:          %u\n", fs32_to_cpu(sb, usb1->fs_size));
115
        printk("  dsize:         %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
116
        printk("  ncg:           %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
117
        printk("  bsize:         %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
118
        printk("  fsize:         %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
119
        printk("  frag:          %u\n", fs32_to_cpu(sb, usb1->fs_frag));
120
        printk("  fragshift:     %u\n", fs32_to_cpu(sb, usb1->fs_fragshift));
121
        printk("  ~fmask:        %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
122
        printk("  fshift:        %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
123
        printk("  sbsize:        %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
124
        printk("  spc:           %u\n", fs32_to_cpu(sb, usb1->fs_spc));
125
        printk("  cpg:           %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
126
        printk("  ipg:           %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
127
        printk("  fpg:           %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
128
        printk("  csaddr:        %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
129
        printk("  cssize:        %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
130
        printk("  cgsize:        %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
131
        printk("  fstodb:        %u\n", fs32_to_cpu(sb, usb1->fs_fsbtodb));
132
        printk("  contigsumsize: %d\n", fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_contigsumsize));
133
        printk("  postblformat:  %u\n", fs32_to_cpu(sb, usb3->fs_postblformat));
134
        printk("  nrpos:         %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
135
        printk("  ndir           %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
136
        printk("  nifree         %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
137
        printk("  nbfree         %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
138
        printk("  nffree         %u\n", fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
139
        printk("\n");
140
}
141
 
142
 
143
/*
144
 * Print contents of ufs_cylinder_group, useful for debugging
145
 */
146
void ufs_print_cylinder_stuff(struct super_block *sb, struct ufs_cylinder_group *cg)
147
{
148
        printk("\nufs_print_cylinder_stuff\n");
149
        printk("size of ucg: %u\n", sizeof(struct ufs_cylinder_group));
150
        printk("  magic:        %x\n", fs32_to_cpu(sb, cg->cg_magic));
151
        printk("  time:         %u\n", fs32_to_cpu(sb, cg->cg_time));
152
        printk("  cgx:          %u\n", fs32_to_cpu(sb, cg->cg_cgx));
153
        printk("  ncyl:         %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
154
        printk("  niblk:        %u\n", fs16_to_cpu(sb, cg->cg_niblk));
155
        printk("  ndblk:        %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
156
        printk("  cs_ndir:      %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
157
        printk("  cs_nbfree:    %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
158
        printk("  cs_nifree:    %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
159
        printk("  cs_nffree:    %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
160
        printk("  rotor:        %u\n", fs32_to_cpu(sb, cg->cg_rotor));
161
        printk("  frotor:       %u\n", fs32_to_cpu(sb, cg->cg_frotor));
162
        printk("  irotor:       %u\n", fs32_to_cpu(sb, cg->cg_irotor));
163
        printk("  frsum:        %u, %u, %u, %u, %u, %u, %u, %u\n",
164
            fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
165
            fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
166
            fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
167
            fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
168
        printk("  btotoff:      %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
169
        printk("  boff:         %u\n", fs32_to_cpu(sb, cg->cg_boff));
170
        printk("  iuseoff:      %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
171
        printk("  freeoff:      %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
172
        printk("  nextfreeoff:  %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
173
        printk("  clustersumoff %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
174
        printk("  clusteroff    %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
175
        printk("  nclusterblks  %u\n", fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
176
        printk("\n");
177
}
178
#endif /* UFS_SUPER_DEBUG_MORE */
179
 
180
static struct super_operations ufs_super_ops;
181
 
182
static char error_buf[1024];
183
 
184
void ufs_error (struct super_block * sb, const char * function,
185
        const char * fmt, ...)
186
{
187
        struct ufs_sb_private_info * uspi;
188
        struct ufs_super_block_first * usb1;
189
        va_list args;
190
 
191
        uspi = sb->u.ufs_sb.s_uspi;
192
        usb1 = ubh_get_usb_first(USPI_UBH);
193
 
194
        if (!(sb->s_flags & MS_RDONLY)) {
195
                usb1->fs_clean = UFS_FSBAD;
196
                ubh_mark_buffer_dirty(USPI_UBH);
197
                sb->s_dirt = 1;
198
                sb->s_flags |= MS_RDONLY;
199
        }
200
        va_start (args, fmt);
201
        vsprintf (error_buf, fmt, args);
202
        va_end (args);
203
        switch (sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_ONERROR) {
204
        case UFS_MOUNT_ONERROR_PANIC:
205
                panic ("UFS-fs panic (device %s): %s: %s\n",
206
                        kdevname(sb->s_dev), function, error_buf);
207
 
208
        case UFS_MOUNT_ONERROR_LOCK:
209
        case UFS_MOUNT_ONERROR_UMOUNT:
210
        case UFS_MOUNT_ONERROR_REPAIR:
211
                printk (KERN_CRIT "UFS-fs error (device %s): %s: %s\n",
212
                        kdevname(sb->s_dev), function, error_buf);
213
        }
214
}
215
 
216
void ufs_panic (struct super_block * sb, const char * function,
217
        const char * fmt, ...)
218
{
219
        struct ufs_sb_private_info * uspi;
220
        struct ufs_super_block_first * usb1;
221
        va_list args;
222
 
223
        uspi = sb->u.ufs_sb.s_uspi;
224
        usb1 = ubh_get_usb_first(USPI_UBH);
225
 
226
        if (!(sb->s_flags & MS_RDONLY)) {
227
                usb1->fs_clean = UFS_FSBAD;
228
                ubh_mark_buffer_dirty(USPI_UBH);
229
                sb->s_dirt = 1;
230
        }
231
        va_start (args, fmt);
232
        vsprintf (error_buf, fmt, args);
233
        va_end (args);
234
        sb->s_flags |= MS_RDONLY;
235
        printk (KERN_CRIT "UFS-fs panic (device %s): %s: %s\n",
236
                kdevname(sb->s_dev), function, error_buf);
237
}
238
 
239
void ufs_warning (struct super_block * sb, const char * function,
240
        const char * fmt, ...)
241
{
242
        va_list args;
243
 
244
        va_start (args, fmt);
245
        vsprintf (error_buf, fmt, args);
246
        va_end (args);
247
        printk (KERN_WARNING "UFS-fs warning (device %s): %s: %s\n",
248
                kdevname(sb->s_dev), function, error_buf);
249
}
250
 
251
static int ufs_parse_options (char * options, unsigned * mount_options)
252
{
253
        char * this_char;
254
        char * value;
255
 
256
        UFSD(("ENTER\n"))
257
 
258
        if (!options)
259
                return 1;
260
 
261
        for (this_char = strtok (options, ",");
262
             this_char != NULL;
263
             this_char = strtok (NULL, ",")) {
264
 
265
                if ((value = strchr (this_char, '=')) != NULL)
266
                        *value++ = 0;
267
                if (!strcmp (this_char, "ufstype")) {
268
                        ufs_clear_opt (*mount_options, UFSTYPE);
269
                        if (!strcmp (value, "old"))
270
                                ufs_set_opt (*mount_options, UFSTYPE_OLD);
271
                        else if (!strcmp (value, "sun"))
272
                                ufs_set_opt (*mount_options, UFSTYPE_SUN);
273
                        else if (!strcmp (value, "44bsd"))
274
                                ufs_set_opt (*mount_options, UFSTYPE_44BSD);
275
                        else if (!strcmp (value, "nextstep"))
276
                                ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
277
                        else if (!strcmp (value, "nextstep-cd"))
278
                                ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
279
                        else if (!strcmp (value, "openstep"))
280
                                ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
281
                        else if (!strcmp (value, "sunx86"))
282
                                ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
283
                        else if (!strcmp (value, "hp"))
284
                                ufs_set_opt (*mount_options, UFSTYPE_HP);
285
                        else {
286
                                printk ("UFS-fs: Invalid type option: %s\n", value);
287
                                return 0;
288
                        }
289
                }
290
                else if (!strcmp (this_char, "onerror")) {
291
                        ufs_clear_opt (*mount_options, ONERROR);
292
                        if (!strcmp (value, "panic"))
293
                                ufs_set_opt (*mount_options, ONERROR_PANIC);
294
                        else if (!strcmp (value, "lock"))
295
                                ufs_set_opt (*mount_options, ONERROR_LOCK);
296
                        else if (!strcmp (value, "umount"))
297
                                ufs_set_opt (*mount_options, ONERROR_UMOUNT);
298
                        else if (!strcmp (value, "repair")) {
299
                                printk("UFS-fs: Unable to do repair on error, "
300
                                        "will lock lock instead \n");
301
                                ufs_set_opt (*mount_options, ONERROR_REPAIR);
302
                        }
303
                        else {
304
                                printk ("UFS-fs: Invalid action onerror: %s\n", value);
305
                                return 0;
306
                        }
307
                }
308
                else {
309
                        printk("UFS-fs: Invalid option: %s\n", this_char);
310
                        return 0;
311
                }
312
        }
313
        return 1;
314
}
315
 
316
/*
317
 * Read on-disk structures associated with cylinder groups
318
 */
319
int ufs_read_cylinder_structures (struct super_block * sb) {
320
        struct ufs_sb_private_info * uspi;
321
        struct ufs_buffer_head * ubh;
322
        unsigned char * base, * space;
323
        unsigned size, blks, i;
324
 
325
        UFSD(("ENTER\n"))
326
 
327
        uspi = sb->u.ufs_sb.s_uspi;
328
 
329
        /*
330
         * Read cs structures from (usually) first data block
331
         * on the device.
332
         */
333
        size = uspi->s_cssize;
334
        blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
335
        base = space = kmalloc(size, GFP_KERNEL);
336
        if (!base)
337
                goto failed;
338
        for (i = 0; i < blks; i += uspi->s_fpb) {
339
                size = uspi->s_bsize;
340
                if (i + uspi->s_fpb > blks)
341
                        size = (blks - i) * uspi->s_fsize;
342
                ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
343
                if (!ubh)
344
                        goto failed;
345
                ubh_ubhcpymem (space, ubh, size);
346
                sb->u.ufs_sb.s_csp[ufs_fragstoblks(i)] = (struct ufs_csum *)space;
347
                space += size;
348
                ubh_brelse (ubh);
349
                ubh = NULL;
350
        }
351
 
352
        /*
353
         * Read cylinder group (we read only first fragment from block
354
         * at this time) and prepare internal data structures for cg caching.
355
         */
356
        if (!(sb->u.ufs_sb.s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_KERNEL)))
357
                goto failed;
358
        for (i = 0; i < uspi->s_ncg; i++)
359
                sb->u.ufs_sb.s_ucg[i] = NULL;
360
        for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
361
                sb->u.ufs_sb.s_ucpi[i] = NULL;
362
                sb->u.ufs_sb.s_cgno[i] = UFS_CGNO_EMPTY;
363
        }
364
        for (i = 0; i < uspi->s_ncg; i++) {
365
                UFSD(("read cg %u\n", i))
366
                if (!(sb->u.ufs_sb.s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
367
                        goto failed;
368
                if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sb->u.ufs_sb.s_ucg[i]->b_data))
369
                        goto failed;
370
#ifdef UFS_SUPER_DEBUG_MORE
371
                ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sb->u.ufs_sb.s_ucg[i]->b_data);
372
#endif
373
        }
374
        for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
375
                if (!(sb->u.ufs_sb.s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_KERNEL)))
376
                        goto failed;
377
                sb->u.ufs_sb.s_cgno[i] = UFS_CGNO_EMPTY;
378
        }
379
        sb->u.ufs_sb.s_cg_loaded = 0;
380
        UFSD(("EXIT\n"))
381
        return 1;
382
 
383
failed:
384
        if (base) kfree (base);
385
        if (sb->u.ufs_sb.s_ucg) {
386
                for (i = 0; i < uspi->s_ncg; i++)
387
                        if (sb->u.ufs_sb.s_ucg[i]) brelse (sb->u.ufs_sb.s_ucg[i]);
388
                kfree (sb->u.ufs_sb.s_ucg);
389
                for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
390
                        if (sb->u.ufs_sb.s_ucpi[i]) kfree (sb->u.ufs_sb.s_ucpi[i]);
391
        }
392
        UFSD(("EXIT (FAILED)\n"))
393
        return 0;
394
}
395
 
396
/*
397
 * Put on-disk structures associated with cylinder groups and
398
 * write them back to disk
399
 */
400
void ufs_put_cylinder_structures (struct super_block * sb) {
401
        struct ufs_sb_private_info * uspi;
402
        struct ufs_buffer_head * ubh;
403
        unsigned char * base, * space;
404
        unsigned blks, size, i;
405
 
406
        UFSD(("ENTER\n"))
407
 
408
        uspi = sb->u.ufs_sb.s_uspi;
409
 
410
        size = uspi->s_cssize;
411
        blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
412
        base = space = (char*) sb->u.ufs_sb.s_csp[0];
413
        for (i = 0; i < blks; i += uspi->s_fpb) {
414
                size = uspi->s_bsize;
415
                if (i + uspi->s_fpb > blks)
416
                        size = (blks - i) * uspi->s_fsize;
417
                ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
418
                ubh_memcpyubh (ubh, space, size);
419
                space += size;
420
                ubh_mark_buffer_uptodate (ubh, 1);
421
                ubh_mark_buffer_dirty (ubh);
422
                ubh_brelse (ubh);
423
        }
424
        for (i = 0; i < sb->u.ufs_sb.s_cg_loaded; i++) {
425
                ufs_put_cylinder (sb, i);
426
                kfree (sb->u.ufs_sb.s_ucpi[i]);
427
        }
428
        for (; i < UFS_MAX_GROUP_LOADED; i++)
429
                kfree (sb->u.ufs_sb.s_ucpi[i]);
430
        for (i = 0; i < uspi->s_ncg; i++)
431
                brelse (sb->u.ufs_sb.s_ucg[i]);
432
        kfree (sb->u.ufs_sb.s_ucg);
433
        kfree (base);
434
        UFSD(("EXIT\n"))
435
}
436
 
437
struct super_block * ufs_read_super (struct super_block * sb, void * data,
438
        int silent)
439
{
440
        struct ufs_sb_private_info * uspi;
441
        struct ufs_super_block_first * usb1;
442
        struct ufs_super_block_second * usb2;
443
        struct ufs_super_block_third * usb3;
444
        struct ufs_buffer_head * ubh;
445
        struct inode *inode;
446
        unsigned block_size, super_block_size;
447
        unsigned flags;
448
 
449
        uspi = NULL;
450
        ubh = NULL;
451
        flags = 0;
452
 
453
        UFSD(("ENTER\n"))
454
 
455
        UFSD(("flag %u\n", (int)(sb->s_flags & MS_RDONLY)))
456
 
457
#ifndef CONFIG_UFS_FS_WRITE
458
        if (!(sb->s_flags & MS_RDONLY)) {
459
                printk("ufs was compiled with read-only support, "
460
                "can't be mounted as read-write\n");
461
                goto failed;
462
        }
463
#endif
464
        /*
465
         * Set default mount options
466
         * Parse mount options
467
         */
468
        sb->u.ufs_sb.s_mount_opt = 0;
469
        ufs_set_opt (sb->u.ufs_sb.s_mount_opt, ONERROR_LOCK);
470
        if (!ufs_parse_options ((char *) data, &sb->u.ufs_sb.s_mount_opt)) {
471
                printk("wrong mount options\n");
472
                goto failed;
473
        }
474
        if (!(sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE)) {
475
                printk("You didn't specify the type of your ufs filesystem\n\n"
476
                "mount -t ufs -o ufstype="
477
                "sun|sunx86|44bsd|old|hp|nextstep|netxstep-cd|openstep ...\n\n"
478
                ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
479
                "default is ufstype=old\n");
480
                ufs_set_opt (sb->u.ufs_sb.s_mount_opt, UFSTYPE_OLD);
481
        }
482
 
483
        sb->u.ufs_sb.s_uspi = uspi =
484
                kmalloc (sizeof(struct ufs_sb_private_info), GFP_KERNEL);
485
        if (!uspi)
486
                goto failed;
487
 
488
        /* Keep 2Gig file limit. Some UFS variants need to override
489
           this but as I don't know which I'll let those in the know loosen
490
           the rules */
491
 
492
        switch (sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) {
493
        case UFS_MOUNT_UFSTYPE_44BSD:
494
                UFSD(("ufstype=44bsd\n"))
495
                uspi->s_fsize = block_size = 512;
496
                uspi->s_fmask = ~(512 - 1);
497
                uspi->s_fshift = 9;
498
                uspi->s_sbsize = super_block_size = 1536;
499
                uspi->s_sbbase = 0;
500
                flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
501
                break;
502
 
503
        case UFS_MOUNT_UFSTYPE_SUN:
504
                UFSD(("ufstype=sun\n"))
505
                uspi->s_fsize = block_size = 1024;
506
                uspi->s_fmask = ~(1024 - 1);
507
                uspi->s_fshift = 10;
508
                uspi->s_sbsize = super_block_size = 2048;
509
                uspi->s_sbbase = 0;
510
                uspi->s_maxsymlinklen = 56;
511
                flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
512
                break;
513
 
514
        case UFS_MOUNT_UFSTYPE_SUNx86:
515
                UFSD(("ufstype=sunx86\n"))
516
                uspi->s_fsize = block_size = 1024;
517
                uspi->s_fmask = ~(1024 - 1);
518
                uspi->s_fshift = 10;
519
                uspi->s_sbsize = super_block_size = 2048;
520
                uspi->s_sbbase = 0;
521
                uspi->s_maxsymlinklen = 56;
522
                flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
523
                break;
524
 
525
        case UFS_MOUNT_UFSTYPE_OLD:
526
                UFSD(("ufstype=old\n"))
527
                uspi->s_fsize = block_size = 1024;
528
                uspi->s_fmask = ~(1024 - 1);
529
                uspi->s_fshift = 10;
530
                uspi->s_sbsize = super_block_size = 2048;
531
                uspi->s_sbbase = 0;
532
                flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
533
                if (!(sb->s_flags & MS_RDONLY)) {
534
                        printk(KERN_INFO "ufstype=old is supported read-only\n");
535
                        sb->s_flags |= MS_RDONLY;
536
                }
537
                break;
538
 
539
        case UFS_MOUNT_UFSTYPE_NEXTSTEP:
540
                UFSD(("ufstype=nextstep\n"))
541
                uspi->s_fsize = block_size = 1024;
542
                uspi->s_fmask = ~(1024 - 1);
543
                uspi->s_fshift = 10;
544
                uspi->s_sbsize = super_block_size = 2048;
545
                uspi->s_sbbase = 0;
546
                flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
547
                if (!(sb->s_flags & MS_RDONLY)) {
548
                        printk(KERN_INFO "ufstype=nextstep is supported read-only\n");
549
                        sb->s_flags |= MS_RDONLY;
550
                }
551
                break;
552
 
553
        case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
554
                UFSD(("ufstype=nextstep-cd\n"))
555
                uspi->s_fsize = block_size = 2048;
556
                uspi->s_fmask = ~(2048 - 1);
557
                uspi->s_fshift = 11;
558
                uspi->s_sbsize = super_block_size = 2048;
559
                uspi->s_sbbase = 0;
560
                flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
561
                if (!(sb->s_flags & MS_RDONLY)) {
562
                        printk(KERN_INFO "ufstype=nextstep-cd is supported read-only\n");
563
                        sb->s_flags |= MS_RDONLY;
564
                }
565
                break;
566
 
567
        case UFS_MOUNT_UFSTYPE_OPENSTEP:
568
                UFSD(("ufstype=openstep\n"))
569
                uspi->s_fsize = block_size = 1024;
570
                uspi->s_fmask = ~(1024 - 1);
571
                uspi->s_fshift = 10;
572
                uspi->s_sbsize = super_block_size = 2048;
573
                uspi->s_sbbase = 0;
574
                flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
575
                if (!(sb->s_flags & MS_RDONLY)) {
576
                        printk(KERN_INFO "ufstype=openstep is supported read-only\n");
577
                        sb->s_flags |= MS_RDONLY;
578
                }
579
                break;
580
 
581
        case UFS_MOUNT_UFSTYPE_HP:
582
                UFSD(("ufstype=hp\n"))
583
                uspi->s_fsize = block_size = 1024;
584
                uspi->s_fmask = ~(1024 - 1);
585
                uspi->s_fshift = 10;
586
                uspi->s_sbsize = super_block_size = 2048;
587
                uspi->s_sbbase = 0;
588
                flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
589
                if (!(sb->s_flags & MS_RDONLY)) {
590
                        printk(KERN_INFO "ufstype=hp is supported read-only\n");
591
                        sb->s_flags |= MS_RDONLY;
592
                }
593
                break;
594
        default:
595
                printk("unknown ufstype\n");
596
                goto failed;
597
        }
598
 
599
again:
600
        if (set_blocksize (sb->s_dev, block_size)) {
601
                printk(KERN_ERR "UFS: failed to set blocksize\n");
602
                goto failed;
603
        }
604
 
605
        sb->s_blocksize = block_size;
606
 
607
        /*
608
         * read ufs super block from device
609
         */
610
        ubh = ubh_bread_uspi (uspi, sb, uspi->s_sbbase + UFS_SBLOCK/block_size, super_block_size);
611
        if (!ubh)
612
                goto failed;
613
 
614
        usb1 = ubh_get_usb_first(USPI_UBH);
615
        usb2 = ubh_get_usb_second(USPI_UBH);
616
        usb3 = ubh_get_usb_third(USPI_UBH);
617
 
618
        /*
619
         * Check ufs magic number
620
         */
621
        switch (__constant_le32_to_cpu(usb3->fs_magic)) {
622
                case UFS_MAGIC:
623
                case UFS_MAGIC_LFN:
624
                case UFS_MAGIC_FEA:
625
                case UFS_MAGIC_4GB:
626
                        sb->u.ufs_sb.s_bytesex = BYTESEX_LE;
627
                        goto magic_found;
628
        }
629
        switch (__constant_be32_to_cpu(usb3->fs_magic)) {
630
                case UFS_MAGIC:
631
                case UFS_MAGIC_LFN:
632
                case UFS_MAGIC_FEA:
633
                case UFS_MAGIC_4GB:
634
                        sb->u.ufs_sb.s_bytesex = BYTESEX_BE;
635
                        goto magic_found;
636
        }
637
 
638
        if ((((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
639
          || ((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
640
          || ((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
641
          && uspi->s_sbbase < 256) {
642
                ubh_brelse_uspi(uspi);
643
                ubh = NULL;
644
                uspi->s_sbbase += 8;
645
                goto again;
646
        }
647
        printk("ufs_read_super: bad magic number\n");
648
        goto failed;
649
 
650
magic_found:
651
        /*
652
         * Check block and fragment sizes
653
         */
654
        uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
655
        uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
656
        uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
657
        uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
658
        uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
659
 
660
        if (uspi->s_fsize & (uspi->s_fsize - 1)) {
661
                printk(KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
662
                        uspi->s_fsize);
663
                goto failed;
664
        }
665
        if (uspi->s_fsize < 512) {
666
                printk(KERN_ERR "ufs_read_super: fragment size %u is too small\n",
667
                        uspi->s_fsize);
668
                goto failed;
669
        }
670
        if (uspi->s_fsize > 4096) {
671
                printk(KERN_ERR "ufs_read_super: fragment size %u is too large\n",
672
                        uspi->s_fsize);
673
                goto failed;
674
        }
675
        if (uspi->s_bsize & (uspi->s_bsize - 1)) {
676
                printk(KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
677
                        uspi->s_bsize);
678
                goto failed;
679
        }
680
        if (uspi->s_bsize < 4096) {
681
                printk(KERN_ERR "ufs_read_super: block size %u is too small\n",
682
                        uspi->s_bsize);
683
                goto failed;
684
        }
685
        if (uspi->s_bsize / uspi->s_fsize > 8) {
686
                printk(KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
687
                        uspi->s_bsize / uspi->s_fsize);
688
                goto failed;
689
        }
690
        if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
691
                ubh_brelse_uspi(uspi);
692
                ubh = NULL;
693
                block_size = uspi->s_fsize;
694
                super_block_size = uspi->s_sbsize;
695
                UFSD(("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size))
696
                goto again;
697
        }
698
 
699
#ifdef UFS_SUPER_DEBUG_MORE
700
        ufs_print_super_stuff(sb, usb1, usb2, usb3);
701
#endif
702
 
703
        /*
704
         * Check, if file system was correctly unmounted.
705
         * If not, make it read only.
706
         */
707
        if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
708
          ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
709
          (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
710
          (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
711
          (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
712
                switch(usb1->fs_clean) {
713
                case UFS_FSCLEAN:
714
                        UFSD(("fs is clean\n"))
715
                        break;
716
                case UFS_FSSTABLE:
717
                        UFSD(("fs is stable\n"))
718
                        break;
719
                case UFS_FSOSF1:
720
                        UFSD(("fs is DEC OSF/1\n"))
721
                        break;
722
                case UFS_FSACTIVE:
723
                        printk("ufs_read_super: fs is active\n");
724
                        sb->s_flags |= MS_RDONLY;
725
                        break;
726
                case UFS_FSBAD:
727
                        printk("ufs_read_super: fs is bad\n");
728
                        sb->s_flags |= MS_RDONLY;
729
                        break;
730
                default:
731
                        printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1->fs_clean);
732
                        sb->s_flags |= MS_RDONLY;
733
                        break;
734
                }
735
        }
736
        else {
737
                printk("ufs_read_super: fs needs fsck\n");
738
                sb->s_flags |= MS_RDONLY;
739
        }
740
 
741
        /*
742
         * Read ufs_super_block into internal data structures
743
         */
744
        sb->s_blocksize = fs32_to_cpu(sb, usb1->fs_fsize);
745
        sb->s_blocksize_bits = fs32_to_cpu(sb, usb1->fs_fshift);
746
        sb->s_op = &ufs_super_ops;
747
        sb->dq_op = NULL; /***/
748
        sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
749
 
750
        uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
751
        uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
752
        uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
753
        uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
754
        uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
755
        uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
756
        uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
757
        uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
758
        uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
759
        /* s_bsize already set */
760
        /* s_fsize already set */
761
        uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
762
        uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
763
        uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
764
        uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
765
        uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
766
        uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
767
        uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
768
        uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
769
        /* s_sbsize already set */
770
        uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
771
        uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
772
        uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
773
        uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
774
        uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
775
        uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
776
        uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
777
        uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
778
        uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
779
        uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
780
        uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
781
        uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
782
        uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
783
        uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
784
        uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
785
        uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
786
        uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_cpc);
787
        uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_contigsumsize);
788
        uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
789
        uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
790
        uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
791
        uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
792
        uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
793
        uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
794
 
795
        /*
796
         * Compute another frequently used values
797
         */
798
        uspi->s_fpbmask = uspi->s_fpb - 1;
799
        uspi->s_apbshift = uspi->s_bshift - 2;
800
        uspi->s_2apbshift = uspi->s_apbshift * 2;
801
        uspi->s_3apbshift = uspi->s_apbshift * 3;
802
        uspi->s_apb = 1 << uspi->s_apbshift;
803
        uspi->s_2apb = 1 << uspi->s_2apbshift;
804
        uspi->s_3apb = 1 << uspi->s_3apbshift;
805
        uspi->s_apbmask = uspi->s_apb - 1;
806
        uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
807
        uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
808
        uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
809
        uspi->s_bpf = uspi->s_fsize << 3;
810
        uspi->s_bpfshift = uspi->s_fshift + 3;
811
        uspi->s_bpfmask = uspi->s_bpf - 1;
812
        if ((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) ==
813
            UFS_MOUNT_UFSTYPE_44BSD)
814
                uspi->s_maxsymlinklen =
815
                    fs32_to_cpu(sb, usb3->fs_u2.fs_44.fs_maxsymlinklen);
816
 
817
        sb->u.ufs_sb.s_flags = flags;
818
 
819
        inode = iget(sb, UFS_ROOTINO);
820
        if (!inode || is_bad_inode(inode))
821
                goto failed;
822
        sb->s_root = d_alloc_root(inode);
823
        if (!sb->s_root)
824
                goto dalloc_failed;
825
 
826
 
827
        /*
828
         * Read cylinder group structures
829
         */
830
        if (!(sb->s_flags & MS_RDONLY))
831
                if (!ufs_read_cylinder_structures(sb))
832
                        goto failed;
833
 
834
        UFSD(("EXIT\n"))
835
        return(sb);
836
 
837
dalloc_failed:
838
        iput(inode);
839
failed:
840
        if (ubh) ubh_brelse_uspi (uspi);
841
        if (uspi) kfree (uspi);
842
        UFSD(("EXIT (FAILED)\n"))
843
        return(NULL);
844
}
845
 
846
void ufs_write_super (struct super_block * sb) {
847
        struct ufs_sb_private_info * uspi;
848
        struct ufs_super_block_first * usb1;
849
        struct ufs_super_block_third * usb3;
850
        unsigned flags;
851
 
852
        UFSD(("ENTER\n"))
853
        flags = sb->u.ufs_sb.s_flags;
854
        uspi = sb->u.ufs_sb.s_uspi;
855
        usb1 = ubh_get_usb_first(USPI_UBH);
856
        usb3 = ubh_get_usb_third(USPI_UBH);
857
 
858
        if (!(sb->s_flags & MS_RDONLY)) {
859
                usb1->fs_time = cpu_to_fs32(sb, CURRENT_TIME);
860
                if ((flags & UFS_ST_MASK) == UFS_ST_SUN
861
                  || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
862
                        ufs_set_fs_state(sb, usb1, usb3,
863
                                        UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
864
                ubh_mark_buffer_dirty (USPI_UBH);
865
        }
866
        sb->s_dirt = 0;
867
        UFSD(("EXIT\n"))
868
}
869
 
870
void ufs_put_super (struct super_block * sb)
871
{
872
        struct ufs_sb_private_info * uspi;
873
 
874
        UFSD(("ENTER\n"))
875
 
876
        uspi = sb->u.ufs_sb.s_uspi;
877
 
878
        if (!(sb->s_flags & MS_RDONLY))
879
                ufs_put_cylinder_structures (sb);
880
 
881
        ubh_brelse_uspi (uspi);
882
        kfree (sb->u.ufs_sb.s_uspi);
883
        return;
884
}
885
 
886
 
887
int ufs_remount (struct super_block * sb, int * mount_flags, char * data)
888
{
889
        struct ufs_sb_private_info * uspi;
890
        struct ufs_super_block_first * usb1;
891
        struct ufs_super_block_third * usb3;
892
        unsigned new_mount_opt, ufstype;
893
        unsigned flags;
894
 
895
        uspi = sb->u.ufs_sb.s_uspi;
896
        flags = sb->u.ufs_sb.s_flags;
897
        usb1 = ubh_get_usb_first(USPI_UBH);
898
        usb3 = ubh_get_usb_third(USPI_UBH);
899
 
900
        /*
901
         * Allow the "check" option to be passed as a remount option.
902
         * It is not possible to change ufstype option during remount
903
         */
904
        ufstype = sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE;
905
        new_mount_opt = 0;
906
        ufs_set_opt (new_mount_opt, ONERROR_LOCK);
907
        if (!ufs_parse_options (data, &new_mount_opt))
908
                return -EINVAL;
909
        if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
910
                new_mount_opt |= ufstype;
911
        }
912
        else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
913
                printk("ufstype can't be changed during remount\n");
914
                return -EINVAL;
915
        }
916
 
917
        if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
918
                sb->u.ufs_sb.s_mount_opt = new_mount_opt;
919
                return 0;
920
        }
921
 
922
        /*
923
         * fs was mouted as rw, remounting ro
924
         */
925
        if (*mount_flags & MS_RDONLY) {
926
                ufs_put_cylinder_structures(sb);
927
                usb1->fs_time = cpu_to_fs32(sb, CURRENT_TIME);
928
                if ((flags & UFS_ST_MASK) == UFS_ST_SUN
929
                  || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
930
                        ufs_set_fs_state(sb, usb1, usb3,
931
                                UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
932
                ubh_mark_buffer_dirty (USPI_UBH);
933
                sb->s_dirt = 0;
934
                sb->s_flags |= MS_RDONLY;
935
        }
936
        /*
937
         * fs was mounted as ro, remounting rw
938
         */
939
        else {
940
#ifndef CONFIG_UFS_FS_WRITE
941
                printk("ufs was compiled with read-only support, "
942
                "can't be mounted as read-write\n");
943
                return -EINVAL;
944
#else
945
                if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
946
                    ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
947
                    ufstype != UFS_MOUNT_UFSTYPE_SUNx86) {
948
                        printk("this ufstype is read-only supported\n");
949
                        return -EINVAL;
950
                }
951
                if (!ufs_read_cylinder_structures (sb)) {
952
                        printk("failed during remounting\n");
953
                        return -EPERM;
954
                }
955
                sb->s_flags &= ~MS_RDONLY;
956
#endif
957
        }
958
        sb->u.ufs_sb.s_mount_opt = new_mount_opt;
959
        return 0;
960
}
961
 
962
int ufs_statfs (struct super_block * sb, struct statfs * buf)
963
{
964
        struct ufs_sb_private_info * uspi;
965
        struct ufs_super_block_first * usb1;
966
 
967
        uspi = sb->u.ufs_sb.s_uspi;
968
        usb1 = ubh_get_usb_first (USPI_UBH);
969
 
970
        buf->f_type = UFS_MAGIC;
971
        buf->f_bsize = sb->s_blocksize;
972
        buf->f_blocks = uspi->s_dsize;
973
        buf->f_bfree = ufs_blkstofrags(fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree)) +
974
                fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
975
        buf->f_bavail = (buf->f_bfree > ((buf->f_blocks / 100) * uspi->s_minfree))
976
                ? (buf->f_bfree - ((buf->f_blocks / 100) * uspi->s_minfree)) : 0;
977
        buf->f_files = uspi->s_ncg * uspi->s_ipg;
978
        buf->f_ffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
979
        buf->f_namelen = UFS_MAXNAMLEN;
980
        return 0;
981
}
982
 
983
static struct super_operations ufs_super_ops = {
984
        read_inode:     ufs_read_inode,
985
        write_inode:    ufs_write_inode,
986
        delete_inode:   ufs_delete_inode,
987
        put_super:      ufs_put_super,
988
        write_super:    ufs_write_super,
989
        statfs:         ufs_statfs,
990
        remount_fs:     ufs_remount,
991
};
992
 
993
static DECLARE_FSTYPE_DEV(ufs_fs_type, "ufs", ufs_read_super);
994
 
995
static int __init init_ufs_fs(void)
996
{
997
        return register_filesystem(&ufs_fs_type);
998
}
999
 
1000
static void __exit exit_ufs_fs(void)
1001
{
1002
        unregister_filesystem(&ufs_fs_type);
1003
}
1004
 
1005
EXPORT_NO_SYMBOLS;
1006
 
1007
module_init(init_ufs_fs)
1008
module_exit(exit_ufs_fs)
1009
MODULE_LICENSE("GPL");

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.