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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [ufs/] [ufs_super.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/ufs/ufs_super.c
3
 *
4
 * Copyright (C) 1996
5
 * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
6
 * Laboratory for Computer Science Research Computing Facility
7
 * Rutgers, The State University of New Jersey
8
 *
9
 * $Id: ufs_super.c,v 1.1 2005-12-20 10:26:35 jcastillo Exp $
10
 *
11
 */
12
 
13
/*
14
 * Kernel module support added on 96/04/26 by
15
 * Stefan Reinauer <stepan@home.culture.mipt.ru>
16
 *
17
 * Module usage counts added on 96/04/29 by
18
 * Gertjan van Wingerde <gertjan@cs.vu.nl>
19
 */
20
 
21
#include <linux/module.h>
22
 
23
#include <linux/kernel.h>
24
#include <linux/fs.h>
25
#include <linux/ufs_fs.h>
26
#include <linux/module.h>
27
#include <linux/locks.h>
28
 
29
#include <asm/segment.h>
30
 
31
struct super_block * ufs_read_super(struct super_block * sb, void * data, int silent);
32
void ufs_put_super (struct super_block * sb);
33
void ufs_statfs(struct super_block * sb, struct statfs * buf, int bufsize);
34
 
35
extern void ufs_read_inode(struct inode * inode);
36
extern void ufs_put_inode(struct inode * inode);
37
 
38
static struct super_operations ufs_super_ops = {
39
        ufs_read_inode,
40
        NULL,                   /* notify_change() */
41
        NULL,                   /* XXX - ufs_write_inode() */
42
        ufs_put_inode,
43
        ufs_put_super,
44
        NULL,                   /* XXX - ufs_write_super() */
45
        ufs_statfs,
46
        NULL,                   /* XXX - ufs_remount() */
47
};
48
 
49
static struct file_system_type ufs_fs_type = {
50
        ufs_read_super, "ufs", 1, NULL
51
};
52
 
53
int
54
init_ufs_fs(void)
55
{
56
        return(register_filesystem(&ufs_fs_type));
57
}
58
 
59
#ifdef MODULE
60
int init_module(void)
61
{
62
        int status;
63
 
64
        if ((status = init_ufs_fs()) == 0)
65
                register_symtab(0);
66
        return status;
67
}
68
 
69
void cleanup_module(void)
70
{
71
        unregister_filesystem(&ufs_fs_type);
72
}
73
#endif
74
 
75
#if 0 /* unused */
76
static void
77
ufs_print_super_stuff(struct super_block * sb, struct ufs_superblock * usb)
78
{
79
 
80
        printk("fs_sblkno: 0x%8.8x\n", usb->fs_sblkno);
81
        printk("fs_size: 0x%8.8x\n", usb->fs_size);
82
        printk("fs_ncg: 0x%8.8x\n", usb->fs_ncg);
83
        printk("fs_bsize: 0x%8.8x\n", usb->fs_bsize);
84
        printk("fs_frag: 0x%8.8x\n", usb->fs_frag);
85
        printk("fs_nindir: 0x%8.8x\n", usb->fs_nindir);
86
        printk("fs_inopb: 0x%8.8x\n", usb->fs_inopb);
87
        printk("fs_optim: 0x%8.8x\n", usb->fs_optim);
88
        printk("fs_ncyl: 0x%8.8x\n", usb->fs_ncyl);
89
        printk("fs_state: 0x%8.8x\n", usb->fs_state);
90
        printk("fs_magic: 0x%8.8x\n", usb->fs_magic);
91
        printk("fs_fsmnt: `%s'\n", usb->fs_fsmnt);
92
 
93
        return;
94
}
95
#endif
96
 
97
struct super_block *
98
ufs_read_super(struct super_block * sb, void * data, int silent)
99
{
100
        struct ufs_superblock * usb;
101
        struct buffer_head * bh1, *bh2;
102
 
103
        /* sb->s_dev and sb->s_flags are set by our caller
104
         * data is the mystery argument to sys_mount()
105
         *
106
         * Our caller also sets s_dev, s_covered, s_rd_only, s_dirt,
107
         *   and s_type when we return.
108
         */
109
 
110
        MOD_INC_USE_COUNT;
111
        lock_super (sb);
112
 
113
        /* XXX - make everything read only for testing */
114
        sb->s_flags |= MS_RDONLY;
115
 
116
        if (!(bh1 = bread(sb->s_dev, UFS_SBLOCK/BLOCK_SIZE, BLOCK_SIZE)) ||
117
            !(bh2 = bread(sb->s_dev, (UFS_SBLOCK + BLOCK_SIZE)/BLOCK_SIZE,
118
                          BLOCK_SIZE))) {
119
                sb->s_dev = 0;
120
                unlock_super (sb);
121
                if (bh1) {
122
                        brelse(bh1);
123
                }
124
                printk ("ufs_read_super: unable to read superblock\n");
125
 
126
                MOD_DEC_USE_COUNT;
127
                return(NULL);
128
        }
129
        /* XXX - redo this so we can free it later... */
130
        usb = (struct ufs_superblock *)__get_free_page(GFP_KERNEL);
131
        if (usb == NULL) {
132
                sb->s_dev=0;
133
                unlock_super(sb);
134
                brelse(bh1);
135
                brelse(bh2);
136
                printk ("ufs_read_super: get_free_page() failed\n");
137
                MOD_DEC_USE_COUNT;
138
                return (NULL);
139
        }
140
 
141
        memcpy((char *)usb, bh1->b_data, BLOCK_SIZE);
142
        memcpy((char *)usb + BLOCK_SIZE, bh2->b_data,
143
               sizeof(struct ufs_superblock) - BLOCK_SIZE);
144
 
145
        brelse(bh1);
146
        brelse(bh2);
147
 
148
        if (usb->fs_magic != UFS_MAGIC) {
149
                /* XXX - replace hard-coded constant with a byte-swap macro */
150
                if (usb->fs_magic == 0x54190100) {
151
                        printk ("ufs_read_super: can't grok byteswapped fs on dev %d/%d\n",
152
                                MAJOR(sb->s_dev), MINOR(sb->s_dev));
153
                        silent = 1;
154
                }
155
                sb->s_dev = 0;
156
                unlock_super (sb);
157
                if (!silent)
158
                        printk ("ufs_read_super: bad magic number 0x%8.8x on dev %d/%d\n",
159
                                usb->fs_magic, MAJOR(sb->s_dev),
160
                                MINOR(sb->s_dev));
161
                MOD_DEC_USE_COUNT;
162
                return(NULL);
163
        }
164
 
165
        /* We found a UFS filesystem on this device. */
166
 
167
        /* XXX - parse args */
168
 
169
        if (usb->fs_bsize != UFS_BSIZE) {
170
                printk("ufs_read_super: fs_bsize %d != %d\n", usb->fs_bsize,
171
                       UFS_BSIZE);
172
                goto ufs_read_super_lose;
173
        }
174
 
175
        if (usb->fs_fsize != UFS_FSIZE) {
176
                printk("ufs_read_super: fs_fsize %d != %d\n", usb->fs_fsize,
177
                       UFS_FSIZE);
178
                goto ufs_read_super_lose;
179
        }
180
 
181
        if (usb->fs_nindir != UFS_NINDIR) {
182
                printk("ufs_read_super: fs_nindir %d != %d\n", usb->fs_nindir,
183
                       UFS_NINDIR);
184
                printk("ufs_read_super: fucking Sun blows me\n");
185
        }
186
 
187
        printk("ufs_read_super: fs last mounted on \"%s\"\n", usb->fs_fsmnt);
188
 
189
        if (usb->fs_state == UFS_FSOK - usb->fs_time) {
190
                switch(usb->fs_clean) {
191
                        case UFS_FSCLEAN:
192
                          printk("ufs_read_super: fs is clean\n");
193
                          break;
194
                        case UFS_FSSTABLE:
195
                          printk("ufs_read_super: fs is stable\n");
196
                          break;
197
                        case UFS_FSACTIVE:
198
                          printk("ufs_read_super: fs is active\n");
199
                          sb->s_flags |= MS_RDONLY;
200
                          break;
201
                        case UFS_FSBAD:
202
                          printk("ufs_read_super: fs is bad\n");
203
                          sb->s_flags |= MS_RDONLY;
204
                          break;
205
                        default:
206
                          printk("ufs_read_super: can't grok fs_clean 0x%x\n",
207
                                 usb->fs_clean);
208
                          sb->s_flags |= MS_RDONLY;
209
                          break;
210
                }
211
        } else {
212
                printk("ufs_read_super: fs needs fsck\n");
213
                sb->s_flags |= MS_RDONLY;
214
                /* XXX - make it read only or barf if it's not (/, /usr) */
215
        }
216
 
217
        /* XXX - sanity check sb fields */
218
 
219
        sb->s_blocksize = usb->fs_fsize;
220
        sb->s_blocksize_bits = 10;  /* XXX */
221
        /* XXX - sb->s_lock */
222
        sb->s_op = &ufs_super_ops;
223
        sb->dq_op = 0; /* XXX */
224
        sb->s_magic = usb->fs_magic;
225
        /* sb->s_time */
226
        /* sb->s_wait */
227
        /* XXX - sb->u.ufs_sb */
228
        sb->u.ufs_sb.s_raw_sb = usb; /* XXX - maybe move this to the top */
229
        sb->u.ufs_sb.s_flags = 0;
230
        sb->u.ufs_sb.s_ncg = usb->fs_ncg;
231
        sb->u.ufs_sb.s_ipg = usb->fs_ipg;
232
        sb->u.ufs_sb.s_fpg = usb->fs_fpg;
233
        sb->u.ufs_sb.s_fsize = usb->fs_fsize;
234
        sb->u.ufs_sb.s_bsize = usb->fs_bsize;
235
        sb->u.ufs_sb.s_iblkno = usb->fs_iblkno;
236
        sb->u.ufs_sb.s_dblkno = usb->fs_dblkno;
237
        sb->u.ufs_sb.s_cgoffset = usb->fs_cgoffset;
238
        sb->u.ufs_sb.s_cgmask = usb->fs_cgmask;
239
        sb->u.ufs_sb.s_inopb = usb->fs_inopb;
240
        sb->u.ufs_sb.s_fsfrag = usb->fs_frag; /* XXX - rename this later */
241
        sb->s_mounted = iget(sb, UFS_ROOTINO);
242
 
243
        printk("ufs_read_super: inopb %u\n", sb->u.ufs_sb.s_inopb);
244
        /*
245
         * XXX - read cg structs?
246
         */
247
 
248
        unlock_super(sb);
249
        return(sb);
250
 
251
       ufs_read_super_lose:
252
        /* XXX - clean up */
253
        MOD_DEC_USE_COUNT;
254
        return(NULL);
255
}
256
 
257
void ufs_put_super (struct super_block * sb)
258
{
259
 
260
        printk("ufs_put_super\n"); /* XXX */
261
 
262
        lock_super (sb);
263
        /* XXX - sync fs data, set state to ok, and flush buffers */
264
        sb->s_dev = 0;
265
 
266
        /* XXX - free allocated kernel memory */
267
 
268
        unlock_super (sb);
269
        MOD_DEC_USE_COUNT;
270
 
271
        return;
272
}
273
 
274
void ufs_statfs(struct super_block * sb, struct statfs * buf, int bufsiz)
275
{
276
        struct statfs tmp;
277
 
278
        printk("ufs_statfs\n"); /* XXX */
279
        tmp.f_type = sb->s_magic;
280
        tmp.f_bsize = PAGE_SIZE;
281
        tmp.f_blocks = sb->u.ufs_sb.s_raw_sb->fs_dsize;
282
        tmp.f_bfree = sb->u.ufs_sb.s_raw_sb->fs_cstotal.cs_nbfree;
283
        tmp.f_bavail =  sb->u.ufs_sb.s_raw_sb->fs_cstotal.cs_nbfree; /* XXX */
284
        tmp.f_files = sb->u.ufs_sb.s_ncg * sb->u.ufs_sb.s_ipg;
285
        tmp.f_ffree = sb->u.ufs_sb.s_raw_sb->fs_cstotal.cs_nifree;
286
        tmp.f_fsid.val[0] = sb->u.ufs_sb.s_raw_sb->fs_id[0];
287
        tmp.f_fsid.val[1] = sb->u.ufs_sb.s_raw_sb->fs_id[1];
288
        tmp.f_namelen = UFS_MAXNAMLEN;
289
/*        tmp.f_spare[6] */
290
 
291
        memcpy_tofs(buf, &tmp, bufsiz);
292
 
293
        return;
294
}
295
 
296
 
297
/*
298
 * Local Variables: ***
299
 * c-indent-level: 8 ***
300
 * c-continued-statement-offset: 8 ***
301
 * c-brace-offset: -8 ***
302
 * c-argdecl-indent: 0 ***
303
 * c-label-offset: -8 ***
304
 * End: ***
305
 */

powered by: WebSVN 2.1.0

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