aboutsummaryrefslogtreecommitdiffstats
path: root/fs/efs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/efs
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/efs')
-rw-r--r--fs/efs/Makefile7
-rw-r--r--fs/efs/dir.c113
-rw-r--r--fs/efs/file.c60
-rw-r--r--fs/efs/inode.c305
-rw-r--r--fs/efs/namei.c110
-rw-r--r--fs/efs/super.c343
-rw-r--r--fs/efs/symlink.c58
7 files changed, 996 insertions, 0 deletions
diff --git a/fs/efs/Makefile b/fs/efs/Makefile
new file mode 100644
index 000000000000..963543d46f0d
--- /dev/null
+++ b/fs/efs/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the linux efs-filesystem routines.
3#
4
5obj-$(CONFIG_EFS_FS) += efs.o
6
7efs-objs := super.o inode.o namei.o dir.o file.o symlink.o
diff --git a/fs/efs/dir.c b/fs/efs/dir.c
new file mode 100644
index 000000000000..777c614ff360
--- /dev/null
+++ b/fs/efs/dir.c
@@ -0,0 +1,113 @@
1/*
2 * dir.c
3 *
4 * Copyright (c) 1999 Al Smith
5 */
6
7#include <linux/buffer_head.h>
8#include <linux/efs_fs.h>
9#include <linux/smp_lock.h>
10
11static int efs_readdir(struct file *, void *, filldir_t);
12
13struct file_operations efs_dir_operations = {
14 .read = generic_read_dir,
15 .readdir = efs_readdir,
16};
17
18struct inode_operations efs_dir_inode_operations = {
19 .lookup = efs_lookup,
20};
21
22static int efs_readdir(struct file *filp, void *dirent, filldir_t filldir) {
23 struct inode *inode = filp->f_dentry->d_inode;
24 struct buffer_head *bh;
25
26 struct efs_dir *dirblock;
27 struct efs_dentry *dirslot;
28 efs_ino_t inodenum;
29 efs_block_t block;
30 int slot, namelen;
31 char *nameptr;
32
33 if (inode->i_size & (EFS_DIRBSIZE-1))
34 printk(KERN_WARNING "EFS: WARNING: readdir(): directory size not a multiple of EFS_DIRBSIZE\n");
35
36 lock_kernel();
37
38 /* work out where this entry can be found */
39 block = filp->f_pos >> EFS_DIRBSIZE_BITS;
40
41 /* each block contains at most 256 slots */
42 slot = filp->f_pos & 0xff;
43
44 /* look at all blocks */
45 while (block < inode->i_blocks) {
46 /* read the dir block */
47 bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
48
49 if (!bh) {
50 printk(KERN_ERR "EFS: readdir(): failed to read dir block %d\n", block);
51 break;
52 }
53
54 dirblock = (struct efs_dir *) bh->b_data;
55
56 if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
57 printk(KERN_ERR "EFS: readdir(): invalid directory block\n");
58 brelse(bh);
59 break;
60 }
61
62 while (slot < dirblock->slots) {
63 if (dirblock->space[slot] == 0) {
64 slot++;
65 continue;
66 }
67
68 dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
69
70 inodenum = be32_to_cpu(dirslot->inode);
71 namelen = dirslot->namelen;
72 nameptr = dirslot->name;
73
74#ifdef DEBUG
75 printk(KERN_DEBUG "EFS: readdir(): block %d slot %d/%d: inode %u, name \"%s\", namelen %u\n", block, slot, dirblock->slots-1, inodenum, nameptr, namelen);
76#endif
77 if (namelen > 0) {
78 /* found the next entry */
79 filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
80
81 /* copy filename and data in dirslot */
82 filldir(dirent, nameptr, namelen, filp->f_pos, inodenum, DT_UNKNOWN);
83
84 /* sanity check */
85 if (nameptr - (char *) dirblock + namelen > EFS_DIRBSIZE) {
86 printk(KERN_WARNING "EFS: directory entry %d exceeds directory block\n", slot);
87 slot++;
88 continue;
89 }
90
91 /* store position of next slot */
92 if (++slot == dirblock->slots) {
93 slot = 0;
94 block++;
95 }
96 brelse(bh);
97 filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
98 goto out;
99 }
100 slot++;
101 }
102 brelse(bh);
103
104 slot = 0;
105 block++;
106 }
107
108 filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
109out:
110 unlock_kernel();
111 return 0;
112}
113
diff --git a/fs/efs/file.c b/fs/efs/file.c
new file mode 100644
index 000000000000..5db20129681e
--- /dev/null
+++ b/fs/efs/file.c
@@ -0,0 +1,60 @@
1/*
2 * file.c
3 *
4 * Copyright (c) 1999 Al Smith
5 *
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
7 */
8
9#include <linux/buffer_head.h>
10#include <linux/efs_fs.h>
11
12int efs_get_block(struct inode *inode, sector_t iblock,
13 struct buffer_head *bh_result, int create)
14{
15 int error = -EROFS;
16 long phys;
17
18 if (create)
19 return error;
20 if (iblock >= inode->i_blocks) {
21#ifdef DEBUG
22 /*
23 * i have no idea why this happens as often as it does
24 */
25 printk(KERN_WARNING "EFS: bmap(): block %d >= %ld (filesize %ld)\n",
26 block,
27 inode->i_blocks,
28 inode->i_size);
29#endif
30 return 0;
31 }
32 phys = efs_map_block(inode, iblock);
33 if (phys)
34 map_bh(bh_result, inode->i_sb, phys);
35 return 0;
36}
37
38int efs_bmap(struct inode *inode, efs_block_t block) {
39
40 if (block < 0) {
41 printk(KERN_WARNING "EFS: bmap(): block < 0\n");
42 return 0;
43 }
44
45 /* are we about to read past the end of a file ? */
46 if (!(block < inode->i_blocks)) {
47#ifdef DEBUG
48 /*
49 * i have no idea why this happens as often as it does
50 */
51 printk(KERN_WARNING "EFS: bmap(): block %d >= %ld (filesize %ld)\n",
52 block,
53 inode->i_blocks,
54 inode->i_size);
55#endif
56 return 0;
57 }
58
59 return efs_map_block(inode, block);
60}
diff --git a/fs/efs/inode.c b/fs/efs/inode.c
new file mode 100644
index 000000000000..180607f9314d
--- /dev/null
+++ b/fs/efs/inode.c
@@ -0,0 +1,305 @@
1/*
2 * inode.c
3 *
4 * Copyright (c) 1999 Al Smith
5 *
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang,
7 * and from work (c) 1998 Mike Shaver.
8 */
9
10#include <linux/efs_fs.h>
11#include <linux/efs_fs_sb.h>
12#include <linux/buffer_head.h>
13#include <linux/module.h>
14#include <linux/fs.h>
15
16static int efs_readpage(struct file *file, struct page *page)
17{
18 return block_read_full_page(page,efs_get_block);
19}
20static sector_t _efs_bmap(struct address_space *mapping, sector_t block)
21{
22 return generic_block_bmap(mapping,block,efs_get_block);
23}
24static struct address_space_operations efs_aops = {
25 .readpage = efs_readpage,
26 .sync_page = block_sync_page,
27 .bmap = _efs_bmap
28};
29
30static inline void extent_copy(efs_extent *src, efs_extent *dst) {
31 /*
32 * this is slightly evil. it doesn't just copy
33 * efs_extent from src to dst, it also mangles
34 * the bits so that dst ends up in cpu byte-order.
35 */
36
37 dst->cooked.ex_magic = (unsigned int) src->raw[0];
38 dst->cooked.ex_bn = ((unsigned int) src->raw[1] << 16) |
39 ((unsigned int) src->raw[2] << 8) |
40 ((unsigned int) src->raw[3] << 0);
41 dst->cooked.ex_length = (unsigned int) src->raw[4];
42 dst->cooked.ex_offset = ((unsigned int) src->raw[5] << 16) |
43 ((unsigned int) src->raw[6] << 8) |
44 ((unsigned int) src->raw[7] << 0);
45 return;
46}
47
48void efs_read_inode(struct inode *inode)
49{
50 int i, inode_index;
51 dev_t device;
52 u32 rdev;
53 struct buffer_head *bh;
54 struct efs_sb_info *sb = SUPER_INFO(inode->i_sb);
55 struct efs_inode_info *in = INODE_INFO(inode);
56 efs_block_t block, offset;
57 struct efs_dinode *efs_inode;
58
59 /*
60 ** EFS layout:
61 **
62 ** | cylinder group | cylinder group | cylinder group ..etc
63 ** |inodes|data |inodes|data |inodes|data ..etc
64 **
65 ** work out the inode block index, (considering initially that the
66 ** inodes are stored as consecutive blocks). then work out the block
67 ** number of that inode given the above layout, and finally the
68 ** offset of the inode within that block.
69 */
70
71 inode_index = inode->i_ino /
72 (EFS_BLOCKSIZE / sizeof(struct efs_dinode));
73
74 block = sb->fs_start + sb->first_block +
75 (sb->group_size * (inode_index / sb->inode_blocks)) +
76 (inode_index % sb->inode_blocks);
77
78 offset = (inode->i_ino %
79 (EFS_BLOCKSIZE / sizeof(struct efs_dinode))) *
80 sizeof(struct efs_dinode);
81
82 bh = sb_bread(inode->i_sb, block);
83 if (!bh) {
84 printk(KERN_WARNING "EFS: bread() failed at block %d\n", block);
85 goto read_inode_error;
86 }
87
88 efs_inode = (struct efs_dinode *) (bh->b_data + offset);
89
90 inode->i_mode = be16_to_cpu(efs_inode->di_mode);
91 inode->i_nlink = be16_to_cpu(efs_inode->di_nlink);
92 inode->i_uid = (uid_t)be16_to_cpu(efs_inode->di_uid);
93 inode->i_gid = (gid_t)be16_to_cpu(efs_inode->di_gid);
94 inode->i_size = be32_to_cpu(efs_inode->di_size);
95 inode->i_atime.tv_sec = be32_to_cpu(efs_inode->di_atime);
96 inode->i_mtime.tv_sec = be32_to_cpu(efs_inode->di_mtime);
97 inode->i_ctime.tv_sec = be32_to_cpu(efs_inode->di_ctime);
98 inode->i_atime.tv_nsec = inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = 0;
99
100 /* this is the number of blocks in the file */
101 if (inode->i_size == 0) {
102 inode->i_blocks = 0;
103 } else {
104 inode->i_blocks = ((inode->i_size - 1) >> EFS_BLOCKSIZE_BITS) + 1;
105 }
106
107 rdev = be16_to_cpu(efs_inode->di_u.di_dev.odev);
108 if (rdev == 0xffff) {
109 rdev = be32_to_cpu(efs_inode->di_u.di_dev.ndev);
110 if (sysv_major(rdev) > 0xfff)
111 device = 0;
112 else
113 device = MKDEV(sysv_major(rdev), sysv_minor(rdev));
114 } else
115 device = old_decode_dev(rdev);
116
117 /* get the number of extents for this object */
118 in->numextents = be16_to_cpu(efs_inode->di_numextents);
119 in->lastextent = 0;
120
121 /* copy the extents contained within the inode to memory */
122 for(i = 0; i < EFS_DIRECTEXTENTS; i++) {
123 extent_copy(&(efs_inode->di_u.di_extents[i]), &(in->extents[i]));
124 if (i < in->numextents && in->extents[i].cooked.ex_magic != 0) {
125 printk(KERN_WARNING "EFS: extent %d has bad magic number in inode %lu\n", i, inode->i_ino);
126 brelse(bh);
127 goto read_inode_error;
128 }
129 }
130
131 brelse(bh);
132
133#ifdef DEBUG
134 printk(KERN_DEBUG "EFS: read_inode(): inode %lu, extents %d, mode %o\n",
135 inode->i_ino, in->numextents, inode->i_mode);
136#endif
137
138 switch (inode->i_mode & S_IFMT) {
139 case S_IFDIR:
140 inode->i_op = &efs_dir_inode_operations;
141 inode->i_fop = &efs_dir_operations;
142 break;
143 case S_IFREG:
144 inode->i_fop = &generic_ro_fops;
145 inode->i_data.a_ops = &efs_aops;
146 break;
147 case S_IFLNK:
148 inode->i_op = &page_symlink_inode_operations;
149 inode->i_data.a_ops = &efs_symlink_aops;
150 break;
151 case S_IFCHR:
152 case S_IFBLK:
153 case S_IFIFO:
154 init_special_inode(inode, inode->i_mode, device);
155 break;
156 default:
157 printk(KERN_WARNING "EFS: unsupported inode mode %o\n", inode->i_mode);
158 goto read_inode_error;
159 break;
160 }
161
162 return;
163
164read_inode_error:
165 printk(KERN_WARNING "EFS: failed to read inode %lu\n", inode->i_ino);
166 make_bad_inode(inode);
167
168 return;
169}
170
171static inline efs_block_t
172efs_extent_check(efs_extent *ptr, efs_block_t block, struct efs_sb_info *sb) {
173 efs_block_t start;
174 efs_block_t length;
175 efs_block_t offset;
176
177 /*
178 * given an extent and a logical block within a file,
179 * can this block be found within this extent ?
180 */
181 start = ptr->cooked.ex_bn;
182 length = ptr->cooked.ex_length;
183 offset = ptr->cooked.ex_offset;
184
185 if ((block >= offset) && (block < offset+length)) {
186 return(sb->fs_start + start + block - offset);
187 } else {
188 return 0;
189 }
190}
191
192efs_block_t efs_map_block(struct inode *inode, efs_block_t block) {
193 struct efs_sb_info *sb = SUPER_INFO(inode->i_sb);
194 struct efs_inode_info *in = INODE_INFO(inode);
195 struct buffer_head *bh = NULL;
196
197 int cur, last, first = 1;
198 int ibase, ioffset, dirext, direxts, indext, indexts;
199 efs_block_t iblock, result = 0, lastblock = 0;
200 efs_extent ext, *exts;
201
202 last = in->lastextent;
203
204 if (in->numextents <= EFS_DIRECTEXTENTS) {
205 /* first check the last extent we returned */
206 if ((result = efs_extent_check(&in->extents[last], block, sb)))
207 return result;
208
209 /* if we only have one extent then nothing can be found */
210 if (in->numextents == 1) {
211 printk(KERN_ERR "EFS: map_block() failed to map (1 extent)\n");
212 return 0;
213 }
214
215 direxts = in->numextents;
216
217 /*
218 * check the stored extents in the inode
219 * start with next extent and check forwards
220 */
221 for(dirext = 1; dirext < direxts; dirext++) {
222 cur = (last + dirext) % in->numextents;
223 if ((result = efs_extent_check(&in->extents[cur], block, sb))) {
224 in->lastextent = cur;
225 return result;
226 }
227 }
228
229 printk(KERN_ERR "EFS: map_block() failed to map block %u (dir)\n", block);
230 return 0;
231 }
232
233#ifdef DEBUG
234 printk(KERN_DEBUG "EFS: map_block(): indirect search for logical block %u\n", block);
235#endif
236 direxts = in->extents[0].cooked.ex_offset;
237 indexts = in->numextents;
238
239 for(indext = 0; indext < indexts; indext++) {
240 cur = (last + indext) % indexts;
241
242 /*
243 * work out which direct extent contains `cur'.
244 *
245 * also compute ibase: i.e. the number of the first
246 * indirect extent contained within direct extent `cur'.
247 *
248 */
249 ibase = 0;
250 for(dirext = 0; cur < ibase && dirext < direxts; dirext++) {
251 ibase += in->extents[dirext].cooked.ex_length *
252 (EFS_BLOCKSIZE / sizeof(efs_extent));
253 }
254
255 if (dirext == direxts) {
256 /* should never happen */
257 printk(KERN_ERR "EFS: couldn't find direct extent for indirect extent %d (block %u)\n", cur, block);
258 if (bh) brelse(bh);
259 return 0;
260 }
261
262 /* work out block number and offset of this indirect extent */
263 iblock = sb->fs_start + in->extents[dirext].cooked.ex_bn +
264 (cur - ibase) /
265 (EFS_BLOCKSIZE / sizeof(efs_extent));
266 ioffset = (cur - ibase) %
267 (EFS_BLOCKSIZE / sizeof(efs_extent));
268
269 if (first || lastblock != iblock) {
270 if (bh) brelse(bh);
271
272 bh = sb_bread(inode->i_sb, iblock);
273 if (!bh) {
274 printk(KERN_ERR "EFS: bread() failed at block %d\n", iblock);
275 return 0;
276 }
277#ifdef DEBUG
278 printk(KERN_DEBUG "EFS: map_block(): read indirect extent block %d\n", iblock);
279#endif
280 first = 0;
281 lastblock = iblock;
282 }
283
284 exts = (efs_extent *) bh->b_data;
285
286 extent_copy(&(exts[ioffset]), &ext);
287
288 if (ext.cooked.ex_magic != 0) {
289 printk(KERN_ERR "EFS: extent %d has bad magic number in block %d\n", cur, iblock);
290 if (bh) brelse(bh);
291 return 0;
292 }
293
294 if ((result = efs_extent_check(&ext, block, sb))) {
295 if (bh) brelse(bh);
296 in->lastextent = cur;
297 return result;
298 }
299 }
300 if (bh) brelse(bh);
301 printk(KERN_ERR "EFS: map_block() failed to map block %u (indir)\n", block);
302 return 0;
303}
304
305MODULE_LICENSE("GPL");
diff --git a/fs/efs/namei.c b/fs/efs/namei.c
new file mode 100644
index 000000000000..ed4a207fe22a
--- /dev/null
+++ b/fs/efs/namei.c
@@ -0,0 +1,110 @@
1/*
2 * namei.c
3 *
4 * Copyright (c) 1999 Al Smith
5 *
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
7 */
8
9#include <linux/buffer_head.h>
10#include <linux/string.h>
11#include <linux/efs_fs.h>
12#include <linux/smp_lock.h>
13
14static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) {
15 struct buffer_head *bh;
16
17 int slot, namelen;
18 char *nameptr;
19 struct efs_dir *dirblock;
20 struct efs_dentry *dirslot;
21 efs_ino_t inodenum;
22 efs_block_t block;
23
24 if (inode->i_size & (EFS_DIRBSIZE-1))
25 printk(KERN_WARNING "EFS: WARNING: find_entry(): directory size not a multiple of EFS_DIRBSIZE\n");
26
27 for(block = 0; block < inode->i_blocks; block++) {
28
29 bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
30 if (!bh) {
31 printk(KERN_ERR "EFS: find_entry(): failed to read dir block %d\n", block);
32 return 0;
33 }
34
35 dirblock = (struct efs_dir *) bh->b_data;
36
37 if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
38 printk(KERN_ERR "EFS: find_entry(): invalid directory block\n");
39 brelse(bh);
40 return(0);
41 }
42
43 for(slot = 0; slot < dirblock->slots; slot++) {
44 dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
45
46 namelen = dirslot->namelen;
47 nameptr = dirslot->name;
48
49 if ((namelen == len) && (!memcmp(name, nameptr, len))) {
50 inodenum = be32_to_cpu(dirslot->inode);
51 brelse(bh);
52 return(inodenum);
53 }
54 }
55 brelse(bh);
56 }
57 return(0);
58}
59
60struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) {
61 efs_ino_t inodenum;
62 struct inode * inode = NULL;
63
64 lock_kernel();
65 inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
66 if (inodenum) {
67 if (!(inode = iget(dir->i_sb, inodenum))) {
68 unlock_kernel();
69 return ERR_PTR(-EACCES);
70 }
71 }
72 unlock_kernel();
73
74 d_add(dentry, inode);
75 return NULL;
76}
77
78struct dentry *efs_get_parent(struct dentry *child)
79{
80 struct dentry *parent;
81 struct inode *inode;
82 efs_ino_t ino;
83 int error;
84
85 lock_kernel();
86
87 error = -ENOENT;
88 ino = efs_find_entry(child->d_inode, "..", 2);
89 if (!ino)
90 goto fail;
91
92 error = -EACCES;
93 inode = iget(child->d_inode->i_sb, ino);
94 if (!inode)
95 goto fail;
96
97 error = -ENOMEM;
98 parent = d_alloc_anon(inode);
99 if (!parent)
100 goto fail_iput;
101
102 unlock_kernel();
103 return parent;
104
105 fail_iput:
106 iput(inode);
107 fail:
108 unlock_kernel();
109 return ERR_PTR(error);
110}
diff --git a/fs/efs/super.c b/fs/efs/super.c
new file mode 100644
index 000000000000..d8d5ea9a9997
--- /dev/null
+++ b/fs/efs/super.c
@@ -0,0 +1,343 @@
1/*
2 * super.c
3 *
4 * Copyright (c) 1999 Al Smith
5 *
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
7 */
8
9#include <linux/init.h>
10#include <linux/module.h>
11#include <linux/efs_fs.h>
12#include <linux/efs_vh.h>
13#include <linux/efs_fs_sb.h>
14#include <linux/slab.h>
15#include <linux/buffer_head.h>
16#include <linux/vfs.h>
17
18static int efs_statfs(struct super_block *s, struct kstatfs *buf);
19static int efs_fill_super(struct super_block *s, void *d, int silent);
20
21static struct super_block *efs_get_sb(struct file_system_type *fs_type,
22 int flags, const char *dev_name, void *data)
23{
24 return get_sb_bdev(fs_type, flags, dev_name, data, efs_fill_super);
25}
26
27static struct file_system_type efs_fs_type = {
28 .owner = THIS_MODULE,
29 .name = "efs",
30 .get_sb = efs_get_sb,
31 .kill_sb = kill_block_super,
32 .fs_flags = FS_REQUIRES_DEV,
33};
34
35static struct pt_types sgi_pt_types[] = {
36 {0x00, "SGI vh"},
37 {0x01, "SGI trkrepl"},
38 {0x02, "SGI secrepl"},
39 {0x03, "SGI raw"},
40 {0x04, "SGI bsd"},
41 {SGI_SYSV, "SGI sysv"},
42 {0x06, "SGI vol"},
43 {SGI_EFS, "SGI efs"},
44 {0x08, "SGI lv"},
45 {0x09, "SGI rlv"},
46 {0x0A, "SGI xfs"},
47 {0x0B, "SGI xfslog"},
48 {0x0C, "SGI xlv"},
49 {0x82, "Linux swap"},
50 {0x83, "Linux native"},
51 {0, NULL}
52};
53
54
55static kmem_cache_t * efs_inode_cachep;
56
57static struct inode *efs_alloc_inode(struct super_block *sb)
58{
59 struct efs_inode_info *ei;
60 ei = (struct efs_inode_info *)kmem_cache_alloc(efs_inode_cachep, SLAB_KERNEL);
61 if (!ei)
62 return NULL;
63 return &ei->vfs_inode;
64}
65
66static void efs_destroy_inode(struct inode *inode)
67{
68 kmem_cache_free(efs_inode_cachep, INODE_INFO(inode));
69}
70
71static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
72{
73 struct efs_inode_info *ei = (struct efs_inode_info *) foo;
74
75 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
76 SLAB_CTOR_CONSTRUCTOR)
77 inode_init_once(&ei->vfs_inode);
78}
79
80static int init_inodecache(void)
81{
82 efs_inode_cachep = kmem_cache_create("efs_inode_cache",
83 sizeof(struct efs_inode_info),
84 0, SLAB_RECLAIM_ACCOUNT,
85 init_once, NULL);
86 if (efs_inode_cachep == NULL)
87 return -ENOMEM;
88 return 0;
89}
90
91static void destroy_inodecache(void)
92{
93 if (kmem_cache_destroy(efs_inode_cachep))
94 printk(KERN_INFO "efs_inode_cache: not all structures were freed\n");
95}
96
97static void efs_put_super(struct super_block *s)
98{
99 kfree(s->s_fs_info);
100 s->s_fs_info = NULL;
101}
102
103static int efs_remount(struct super_block *sb, int *flags, char *data)
104{
105 *flags |= MS_RDONLY;
106 return 0;
107}
108
109static struct super_operations efs_superblock_operations = {
110 .alloc_inode = efs_alloc_inode,
111 .destroy_inode = efs_destroy_inode,
112 .read_inode = efs_read_inode,
113 .put_super = efs_put_super,
114 .statfs = efs_statfs,
115 .remount_fs = efs_remount,
116};
117
118static struct export_operations efs_export_ops = {
119 .get_parent = efs_get_parent,
120};
121
122static int __init init_efs_fs(void) {
123 int err;
124 printk("EFS: "EFS_VERSION" - http://aeschi.ch.eu.org/efs/\n");
125 err = init_inodecache();
126 if (err)
127 goto out1;
128 err = register_filesystem(&efs_fs_type);
129 if (err)
130 goto out;
131 return 0;
132out:
133 destroy_inodecache();
134out1:
135 return err;
136}
137
138static void __exit exit_efs_fs(void) {
139 unregister_filesystem(&efs_fs_type);
140 destroy_inodecache();
141}
142
143module_init(init_efs_fs)
144module_exit(exit_efs_fs)
145
146static efs_block_t efs_validate_vh(struct volume_header *vh) {
147 int i;
148 __be32 cs, *ui;
149 int csum;
150 efs_block_t sblock = 0; /* shuts up gcc */
151 struct pt_types *pt_entry;
152 int pt_type, slice = -1;
153
154 if (be32_to_cpu(vh->vh_magic) != VHMAGIC) {
155 /*
156 * assume that we're dealing with a partition and allow
157 * read_super() to try and detect a valid superblock
158 * on the next block.
159 */
160 return 0;
161 }
162
163 ui = ((__be32 *) (vh + 1)) - 1;
164 for(csum = 0; ui >= ((__be32 *) vh);) {
165 cs = *ui--;
166 csum += be32_to_cpu(cs);
167 }
168 if (csum) {
169 printk(KERN_INFO "EFS: SGI disklabel: checksum bad, label corrupted\n");
170 return 0;
171 }
172
173#ifdef DEBUG
174 printk(KERN_DEBUG "EFS: bf: \"%16s\"\n", vh->vh_bootfile);
175
176 for(i = 0; i < NVDIR; i++) {
177 int j;
178 char name[VDNAMESIZE+1];
179
180 for(j = 0; j < VDNAMESIZE; j++) {
181 name[j] = vh->vh_vd[i].vd_name[j];
182 }
183 name[j] = (char) 0;
184
185 if (name[0]) {
186 printk(KERN_DEBUG "EFS: vh: %8s block: 0x%08x size: 0x%08x\n",
187 name,
188 (int) be32_to_cpu(vh->vh_vd[i].vd_lbn),
189 (int) be32_to_cpu(vh->vh_vd[i].vd_nbytes));
190 }
191 }
192#endif
193
194 for(i = 0; i < NPARTAB; i++) {
195 pt_type = (int) be32_to_cpu(vh->vh_pt[i].pt_type);
196 for(pt_entry = sgi_pt_types; pt_entry->pt_name; pt_entry++) {
197 if (pt_type == pt_entry->pt_type) break;
198 }
199#ifdef DEBUG
200 if (be32_to_cpu(vh->vh_pt[i].pt_nblks)) {
201 printk(KERN_DEBUG "EFS: pt %2d: start: %08d size: %08d type: 0x%02x (%s)\n",
202 i,
203 (int) be32_to_cpu(vh->vh_pt[i].pt_firstlbn),
204 (int) be32_to_cpu(vh->vh_pt[i].pt_nblks),
205 pt_type,
206 (pt_entry->pt_name) ? pt_entry->pt_name : "unknown");
207 }
208#endif
209 if (IS_EFS(pt_type)) {
210 sblock = be32_to_cpu(vh->vh_pt[i].pt_firstlbn);
211 slice = i;
212 }
213 }
214
215 if (slice == -1) {
216 printk(KERN_NOTICE "EFS: partition table contained no EFS partitions\n");
217#ifdef DEBUG
218 } else {
219 printk(KERN_INFO "EFS: using slice %d (type %s, offset 0x%x)\n",
220 slice,
221 (pt_entry->pt_name) ? pt_entry->pt_name : "unknown",
222 sblock);
223#endif
224 }
225 return(sblock);
226}
227
228static int efs_validate_super(struct efs_sb_info *sb, struct efs_super *super) {
229
230 if (!IS_EFS_MAGIC(be32_to_cpu(super->fs_magic))) return -1;
231
232 sb->fs_magic = be32_to_cpu(super->fs_magic);
233 sb->total_blocks = be32_to_cpu(super->fs_size);
234 sb->first_block = be32_to_cpu(super->fs_firstcg);
235 sb->group_size = be32_to_cpu(super->fs_cgfsize);
236 sb->data_free = be32_to_cpu(super->fs_tfree);
237 sb->inode_free = be32_to_cpu(super->fs_tinode);
238 sb->inode_blocks = be16_to_cpu(super->fs_cgisize);
239 sb->total_groups = be16_to_cpu(super->fs_ncg);
240
241 return 0;
242}
243
244static int efs_fill_super(struct super_block *s, void *d, int silent)
245{
246 struct efs_sb_info *sb;
247 struct buffer_head *bh;
248 struct inode *root;
249
250 sb = kmalloc(sizeof(struct efs_sb_info), GFP_KERNEL);
251 if (!sb)
252 return -ENOMEM;
253 s->s_fs_info = sb;
254 memset(sb, 0, sizeof(struct efs_sb_info));
255
256 s->s_magic = EFS_SUPER_MAGIC;
257 if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
258 printk(KERN_ERR "EFS: device does not support %d byte blocks\n",
259 EFS_BLOCKSIZE);
260 goto out_no_fs_ul;
261 }
262
263 /* read the vh (volume header) block */
264 bh = sb_bread(s, 0);
265
266 if (!bh) {
267 printk(KERN_ERR "EFS: cannot read volume header\n");
268 goto out_no_fs_ul;
269 }
270
271 /*
272 * if this returns zero then we didn't find any partition table.
273 * this isn't (yet) an error - just assume for the moment that
274 * the device is valid and go on to search for a superblock.
275 */
276 sb->fs_start = efs_validate_vh((struct volume_header *) bh->b_data);
277 brelse(bh);
278
279 if (sb->fs_start == -1) {
280 goto out_no_fs_ul;
281 }
282
283 bh = sb_bread(s, sb->fs_start + EFS_SUPER);
284 if (!bh) {
285 printk(KERN_ERR "EFS: cannot read superblock\n");
286 goto out_no_fs_ul;
287 }
288
289 if (efs_validate_super(sb, (struct efs_super *) bh->b_data)) {
290#ifdef DEBUG
291 printk(KERN_WARNING "EFS: invalid superblock at block %u\n", sb->fs_start + EFS_SUPER);
292#endif
293 brelse(bh);
294 goto out_no_fs_ul;
295 }
296 brelse(bh);
297
298 if (!(s->s_flags & MS_RDONLY)) {
299#ifdef DEBUG
300 printk(KERN_INFO "EFS: forcing read-only mode\n");
301#endif
302 s->s_flags |= MS_RDONLY;
303 }
304 s->s_op = &efs_superblock_operations;
305 s->s_export_op = &efs_export_ops;
306 root = iget(s, EFS_ROOTINODE);
307 s->s_root = d_alloc_root(root);
308
309 if (!(s->s_root)) {
310 printk(KERN_ERR "EFS: get root inode failed\n");
311 iput(root);
312 goto out_no_fs;
313 }
314
315 return 0;
316
317out_no_fs_ul:
318out_no_fs:
319 s->s_fs_info = NULL;
320 kfree(sb);
321 return -EINVAL;
322}
323
324static int efs_statfs(struct super_block *s, struct kstatfs *buf) {
325 struct efs_sb_info *sb = SUPER_INFO(s);
326
327 buf->f_type = EFS_SUPER_MAGIC; /* efs magic number */
328 buf->f_bsize = EFS_BLOCKSIZE; /* blocksize */
329 buf->f_blocks = sb->total_groups * /* total data blocks */
330 (sb->group_size - sb->inode_blocks);
331 buf->f_bfree = sb->data_free; /* free data blocks */
332 buf->f_bavail = sb->data_free; /* free blocks for non-root */
333 buf->f_files = sb->total_groups * /* total inodes */
334 sb->inode_blocks *
335 (EFS_BLOCKSIZE / sizeof(struct efs_dinode));
336 buf->f_ffree = sb->inode_free; /* free inodes */
337 buf->f_fsid.val[0] = (sb->fs_magic >> 16) & 0xffff; /* fs ID */
338 buf->f_fsid.val[1] = sb->fs_magic & 0xffff; /* fs ID */
339 buf->f_namelen = EFS_MAXNAMELEN; /* max filename length */
340
341 return 0;
342}
343
diff --git a/fs/efs/symlink.c b/fs/efs/symlink.c
new file mode 100644
index 000000000000..3d9a350e3e7f
--- /dev/null
+++ b/fs/efs/symlink.c
@@ -0,0 +1,58 @@
1/*
2 * symlink.c
3 *
4 * Copyright (c) 1999 Al Smith
5 *
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
7 */
8
9#include <linux/string.h>
10#include <linux/efs_fs.h>
11#include <linux/pagemap.h>
12#include <linux/buffer_head.h>
13#include <linux/smp_lock.h>
14
15static int efs_symlink_readpage(struct file *file, struct page *page)
16{
17 char *link = kmap(page);
18 struct buffer_head * bh;
19 struct inode * inode = page->mapping->host;
20 efs_block_t size = inode->i_size;
21 int err;
22
23 err = -ENAMETOOLONG;
24 if (size > 2 * EFS_BLOCKSIZE)
25 goto fail;
26
27 lock_kernel();
28 /* read first 512 bytes of link target */
29 err = -EIO;
30 bh = sb_bread(inode->i_sb, efs_bmap(inode, 0));
31 if (!bh)
32 goto fail;
33 memcpy(link, bh->b_data, (size > EFS_BLOCKSIZE) ? EFS_BLOCKSIZE : size);
34 brelse(bh);
35 if (size > EFS_BLOCKSIZE) {
36 bh = sb_bread(inode->i_sb, efs_bmap(inode, 1));
37 if (!bh)
38 goto fail;
39 memcpy(link + EFS_BLOCKSIZE, bh->b_data, size - EFS_BLOCKSIZE);
40 brelse(bh);
41 }
42 link[size] = '\0';
43 unlock_kernel();
44 SetPageUptodate(page);
45 kunmap(page);
46 unlock_page(page);
47 return 0;
48fail:
49 unlock_kernel();
50 SetPageError(page);
51 kunmap(page);
52 unlock_page(page);
53 return err;
54}
55
56struct address_space_operations efs_symlink_aops = {
57 .readpage = efs_symlink_readpage
58};