4 * Copyright (c) 1999 Al Smith
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/locks.h>
12 #include <linux/efs_fs.h>
13 #include <linux/efs_vh.h>
14 #include <linux/efs_fs_sb.h>
16 static struct file_system_type efs_fs_type
= {
17 "efs", /* filesystem name */
18 FS_REQUIRES_DEV
, /* fs_flags */
19 efs_read_super
, /* entry function pointer */
23 static struct super_operations efs_superblock_operations
= {
24 efs_read_inode
, /* read_inode */
25 NULL
, /* write_inode */
27 NULL
, /* delete_inode */
28 NULL
, /* notify_change */
29 efs_put_super
, /* put_super */
30 NULL
, /* write_super */
31 efs_statfs
, /* statfs */
35 int __init
init_efs_fs(void) {
36 return register_filesystem(&efs_fs_type
);
42 int init_module(void) {
43 printk("EFS: "EFS_VERSION
" - http://aeschi.ch.eu.org/efs/\n");
47 void cleanup_module(void) {
48 unregister_filesystem(&efs_fs_type
);
52 static efs_block_t
efs_validate_vh(struct volume_header
*vh
) {
54 unsigned int cs
, csum
, *ui
;
55 efs_block_t sblock
= 0; /* shuts up gcc */
56 struct pt_types
*pt_entry
;
57 int pt_type
, slice
= -1;
59 if (be32_to_cpu(vh
->vh_magic
) != VHMAGIC
) {
61 * assume that we're dealing with a partition and allow
62 * read_super() to try and detect a valid superblock
68 ui
= ((unsigned int *) (vh
+ 1)) - 1;
69 for(csum
= 0; ui
>= ((unsigned int *) vh
);) {
71 csum
+= be32_to_cpu(cs
);
74 printk(KERN_INFO
"EFS: SGI disklabel: checksum bad, label corrupted\n");
79 printk(KERN_DEBUG
"EFS: bf: \"%16s\"\n", vh
->vh_bootfile
);
81 for(i
= 0; i
< NVDIR
; i
++) {
83 char name
[VDNAMESIZE
+1];
85 for(j
= 0; j
< VDNAMESIZE
; j
++) {
86 name
[j
] = vh
->vh_vd
[i
].vd_name
[j
];
91 printk(KERN_DEBUG
"EFS: vh: %8s block: 0x%08x size: 0x%08x\n",
93 (int) be32_to_cpu(vh
->vh_vd
[i
].vd_lbn
),
94 (int) be32_to_cpu(vh
->vh_vd
[i
].vd_nbytes
));
99 for(i
= 0; i
< NPARTAB
; i
++) {
100 pt_type
= (int) be32_to_cpu(vh
->vh_pt
[i
].pt_type
);
101 for(pt_entry
= sgi_pt_types
; pt_entry
->pt_name
; pt_entry
++) {
102 if (pt_type
== pt_entry
->pt_type
) break;
105 if (be32_to_cpu(vh
->vh_pt
[i
].pt_nblks
)) {
106 printk(KERN_DEBUG
"EFS: pt %2d: start: %08d size: %08d type: 0x%02x (%s)\n",
108 (int) be32_to_cpu(vh
->vh_pt
[i
].pt_firstlbn
),
109 (int) be32_to_cpu(vh
->vh_pt
[i
].pt_nblks
),
111 (pt_entry
->pt_name
) ? pt_entry
->pt_name
: "unknown");
114 if (IS_EFS(pt_type
)) {
115 sblock
= be32_to_cpu(vh
->vh_pt
[i
].pt_firstlbn
);
121 printk(KERN_NOTICE
"EFS: partition table contained no EFS partitions\n");
124 printk(KERN_INFO
"EFS: using slice %d (type %s, offset 0x%x)\n",
126 (pt_entry
->pt_name
) ? pt_entry
->pt_name
: "unknown",
133 static int efs_validate_super(struct efs_sb_info
*sb
, struct efs_super
*super
) {
135 if (!IS_EFS_MAGIC(be32_to_cpu(super
->fs_magic
))) return -1;
137 sb
->fs_magic
= be32_to_cpu(super
->fs_magic
);
138 sb
->total_blocks
= be32_to_cpu(super
->fs_size
);
139 sb
->first_block
= be32_to_cpu(super
->fs_firstcg
);
140 sb
->group_size
= be32_to_cpu(super
->fs_cgfsize
);
141 sb
->data_free
= be32_to_cpu(super
->fs_tfree
);
142 sb
->inode_free
= be32_to_cpu(super
->fs_tinode
);
143 sb
->inode_blocks
= be16_to_cpu(super
->fs_cgisize
);
144 sb
->total_groups
= be16_to_cpu(super
->fs_ncg
);
149 struct super_block
*efs_read_super(struct super_block
*s
, void *d
, int silent
) {
150 kdev_t dev
= s
->s_dev
;
151 struct efs_sb_info
*sb
;
152 struct buffer_head
*bh
;
159 set_blocksize(dev
, EFS_BLOCKSIZE
);
161 /* read the vh (volume header) block */
162 bh
= bread(dev
, 0, EFS_BLOCKSIZE
);
165 printk(KERN_ERR
"EFS: cannot read volume header\n");
170 * if this returns zero then we didn't find any partition table.
171 * this isn't (yet) an error - just assume for the moment that
172 * the device is valid and go on to search for a superblock.
174 sb
->fs_start
= efs_validate_vh((struct volume_header
*) bh
->b_data
);
177 if (sb
->fs_start
== -1) {
181 bh
= bread(dev
, sb
->fs_start
+ EFS_SUPER
, EFS_BLOCKSIZE
);
183 printk(KERN_ERR
"EFS: cannot read superblock\n");
187 if (efs_validate_super(sb
, (struct efs_super
*) bh
->b_data
)) {
189 printk(KERN_WARNING
"EFS: invalid superblock at block %u\n", sb
->fs_start
+ EFS_SUPER
);
196 s
->s_magic
= EFS_SUPER_MAGIC
;
197 s
->s_blocksize
= EFS_BLOCKSIZE
;
198 s
->s_blocksize_bits
= EFS_BLOCKSIZE_BITS
;
199 if (!(s
->s_flags
& MS_RDONLY
)) {
201 printk(KERN_INFO
"EFS: forcing read-only mode\n");
203 s
->s_flags
|= MS_RDONLY
;
205 s
->s_op
= &efs_superblock_operations
;
207 s
->s_root
= d_alloc_root(iget(s
, EFS_ROOTINODE
));
211 printk(KERN_ERR
"EFS: get root inode failed\n");
215 if (check_disk_change(s
->s_dev
)) {
216 printk(KERN_ERR
"EFS: device changed\n");
230 void efs_put_super(struct super_block
*s
) {
234 int efs_statfs(struct super_block
*s
, struct statfs
*buf
, int bufsiz
) {
236 struct efs_sb_info
*sb
= SUPER_INFO(s
);
238 ret
.f_type
= EFS_SUPER_MAGIC
; /* efs magic number */
239 ret
.f_bsize
= EFS_BLOCKSIZE
; /* blocksize */
240 ret
.f_blocks
= sb
->total_groups
* /* total data blocks */
241 (sb
->group_size
- sb
->inode_blocks
);
242 ret
.f_bfree
= sb
->data_free
; /* free data blocks */
243 ret
.f_bavail
= sb
->data_free
; /* free blocks for non-root */
244 ret
.f_files
= sb
->total_groups
* /* total inodes */
246 (EFS_BLOCKSIZE
/ sizeof(struct efs_dinode
));
247 ret
.f_ffree
= sb
->inode_free
; /* free inodes */
248 ret
.f_fsid
.val
[0] = (sb
->fs_magic
>> 16) & 0xffff; /* fs ID */
249 ret
.f_fsid
.val
[1] = sb
->fs_magic
& 0xffff; /* fs ID */
250 ret
.f_namelen
= EFS_MAXNAMELEN
; /* max filename length */
252 return copy_to_user(buf
, &ret
, bufsiz
) ? -EFAULT
: 0;