summaryrefslogtreecommitdiffstats
path: root/fs/efs
diff options
context:
space:
mode:
authorTimothy Pearson <tpearson@raptorengineering.com>2017-08-23 14:45:25 -0500
committerTimothy Pearson <tpearson@raptorengineering.com>2017-08-23 14:45:25 -0500
commitfcbb27b0ec6dcbc5a5108cb8fb19eae64593d204 (patch)
tree22962a4387943edc841c72a4e636a068c66d58fd /fs/efs
downloadast2050-linux-kernel-fcbb27b0ec6dcbc5a5108cb8fb19eae64593d204.zip
ast2050-linux-kernel-fcbb27b0ec6dcbc5a5108cb8fb19eae64593d204.tar.gz
Initial import of modified Linux 2.6.28 tree
Original upstream URL: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git | branch linux-2.6.28.y
Diffstat (limited to 'fs/efs')
-rw-r--r--fs/efs/Makefile7
-rw-r--r--fs/efs/dir.c113
-rw-r--r--fs/efs/efs.h140
-rw-r--r--fs/efs/file.c60
-rw-r--r--fs/efs/inode.c314
-rw-r--r--fs/efs/namei.c125
-rw-r--r--fs/efs/super.c348
-rw-r--r--fs/efs/symlink.c59
8 files changed, 1166 insertions, 0 deletions
diff --git a/fs/efs/Makefile b/fs/efs/Makefile
new file mode 100644
index 0000000..963543d
--- /dev/null
+++ b/fs/efs/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for the linux efs-filesystem routines.
+#
+
+obj-$(CONFIG_EFS_FS) += efs.o
+
+efs-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 0000000..49308a2
--- /dev/null
+++ b/fs/efs/dir.c
@@ -0,0 +1,113 @@
+/*
+ * dir.c
+ *
+ * Copyright (c) 1999 Al Smith
+ */
+
+#include <linux/buffer_head.h>
+#include <linux/smp_lock.h>
+#include "efs.h"
+
+static int efs_readdir(struct file *, void *, filldir_t);
+
+const struct file_operations efs_dir_operations = {
+ .read = generic_read_dir,
+ .readdir = efs_readdir,
+};
+
+const struct inode_operations efs_dir_inode_operations = {
+ .lookup = efs_lookup,
+};
+
+static int efs_readdir(struct file *filp, void *dirent, filldir_t filldir) {
+ struct inode *inode = filp->f_path.dentry->d_inode;
+ struct buffer_head *bh;
+
+ struct efs_dir *dirblock;
+ struct efs_dentry *dirslot;
+ efs_ino_t inodenum;
+ efs_block_t block;
+ int slot, namelen;
+ char *nameptr;
+
+ if (inode->i_size & (EFS_DIRBSIZE-1))
+ printk(KERN_WARNING "EFS: WARNING: readdir(): directory size not a multiple of EFS_DIRBSIZE\n");
+
+ lock_kernel();
+
+ /* work out where this entry can be found */
+ block = filp->f_pos >> EFS_DIRBSIZE_BITS;
+
+ /* each block contains at most 256 slots */
+ slot = filp->f_pos & 0xff;
+
+ /* look at all blocks */
+ while (block < inode->i_blocks) {
+ /* read the dir block */
+ bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
+
+ if (!bh) {
+ printk(KERN_ERR "EFS: readdir(): failed to read dir block %d\n", block);
+ break;
+ }
+
+ dirblock = (struct efs_dir *) bh->b_data;
+
+ if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
+ printk(KERN_ERR "EFS: readdir(): invalid directory block\n");
+ brelse(bh);
+ break;
+ }
+
+ while (slot < dirblock->slots) {
+ if (dirblock->space[slot] == 0) {
+ slot++;
+ continue;
+ }
+
+ dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
+
+ inodenum = be32_to_cpu(dirslot->inode);
+ namelen = dirslot->namelen;
+ nameptr = dirslot->name;
+
+#ifdef DEBUG
+ 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);
+#endif
+ if (namelen > 0) {
+ /* found the next entry */
+ filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
+
+ /* copy filename and data in dirslot */
+ filldir(dirent, nameptr, namelen, filp->f_pos, inodenum, DT_UNKNOWN);
+
+ /* sanity check */
+ if (nameptr - (char *) dirblock + namelen > EFS_DIRBSIZE) {
+ printk(KERN_WARNING "EFS: directory entry %d exceeds directory block\n", slot);
+ slot++;
+ continue;
+ }
+
+ /* store position of next slot */
+ if (++slot == dirblock->slots) {
+ slot = 0;
+ block++;
+ }
+ brelse(bh);
+ filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
+ goto out;
+ }
+ slot++;
+ }
+ brelse(bh);
+
+ slot = 0;
+ block++;
+ }
+
+ filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
+out:
+ unlock_kernel();
+ return 0;
+}
+
diff --git a/fs/efs/efs.h b/fs/efs/efs.h
new file mode 100644
index 0000000..d8305b5
--- /dev/null
+++ b/fs/efs/efs.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 1999 Al Smith
+ *
+ * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
+ * Portions derived from IRIX header files (c) 1988 Silicon Graphics
+ */
+#ifndef _EFS_EFS_H_
+#define _EFS_EFS_H_
+
+#include <linux/fs.h>
+#include <asm/uaccess.h>
+
+#define EFS_VERSION "1.0a"
+
+static const char cprt[] = "EFS: "EFS_VERSION" - (c) 1999 Al Smith <Al.Smith@aeschi.ch.eu.org>";
+
+
+/* 1 block is 512 bytes */
+#define EFS_BLOCKSIZE_BITS 9
+#define EFS_BLOCKSIZE (1 << EFS_BLOCKSIZE_BITS)
+
+typedef int32_t efs_block_t;
+typedef uint32_t efs_ino_t;
+
+#define EFS_DIRECTEXTENTS 12
+
+/*
+ * layout of an extent, in memory and on disk. 8 bytes exactly.
+ */
+typedef union extent_u {
+ unsigned char raw[8];
+ struct extent_s {
+ unsigned int ex_magic:8; /* magic # (zero) */
+ unsigned int ex_bn:24; /* basic block */
+ unsigned int ex_length:8; /* numblocks in this extent */
+ unsigned int ex_offset:24; /* logical offset into file */
+ } cooked;
+} efs_extent;
+
+typedef struct edevs {
+ __be16 odev;
+ __be32 ndev;
+} efs_devs;
+
+/*
+ * extent based filesystem inode as it appears on disk. The efs inode
+ * is exactly 128 bytes long.
+ */
+struct efs_dinode {
+ __be16 di_mode; /* mode and type of file */
+ __be16 di_nlink; /* number of links to file */
+ __be16 di_uid; /* owner's user id */
+ __be16 di_gid; /* owner's group id */
+ __be32 di_size; /* number of bytes in file */
+ __be32 di_atime; /* time last accessed */
+ __be32 di_mtime; /* time last modified */
+ __be32 di_ctime; /* time created */
+ __be32 di_gen; /* generation number */
+ __be16 di_numextents; /* # of extents */
+ u_char di_version; /* version of inode */
+ u_char di_spare; /* spare - used by AFS */
+ union di_addr {
+ efs_extent di_extents[EFS_DIRECTEXTENTS];
+ efs_devs di_dev; /* device for IFCHR/IFBLK */
+ } di_u;
+};
+
+/* efs inode storage in memory */
+struct efs_inode_info {
+ int numextents;
+ int lastextent;
+
+ efs_extent extents[EFS_DIRECTEXTENTS];
+ struct inode vfs_inode;
+};
+
+#include <linux/efs_fs_sb.h>
+
+#define EFS_DIRBSIZE_BITS EFS_BLOCKSIZE_BITS
+#define EFS_DIRBSIZE (1 << EFS_DIRBSIZE_BITS)
+
+struct efs_dentry {
+ __be32 inode;
+ unsigned char namelen;
+ char name[3];
+};
+
+#define EFS_DENTSIZE (sizeof(struct efs_dentry) - 3 + 1)
+#define EFS_MAXNAMELEN ((1 << (sizeof(char) * 8)) - 1)
+
+#define EFS_DIRBLK_HEADERSIZE 4
+#define EFS_DIRBLK_MAGIC 0xbeef /* moo */
+
+struct efs_dir {
+ __be16 magic;
+ unsigned char firstused;
+ unsigned char slots;
+
+ unsigned char space[EFS_DIRBSIZE - EFS_DIRBLK_HEADERSIZE];
+};
+
+#define EFS_MAXENTS \
+ ((EFS_DIRBSIZE - EFS_DIRBLK_HEADERSIZE) / \
+ (EFS_DENTSIZE + sizeof(char)))
+
+#define EFS_SLOTAT(dir, slot) EFS_REALOFF((dir)->space[slot])
+
+#define EFS_REALOFF(offset) ((offset << 1))
+
+
+static inline struct efs_inode_info *INODE_INFO(struct inode *inode)
+{
+ return container_of(inode, struct efs_inode_info, vfs_inode);
+}
+
+static inline struct efs_sb_info *SUPER_INFO(struct super_block *sb)
+{
+ return sb->s_fs_info;
+}
+
+struct statfs;
+struct fid;
+
+extern const struct inode_operations efs_dir_inode_operations;
+extern const struct file_operations efs_dir_operations;
+extern const struct address_space_operations efs_symlink_aops;
+
+extern struct inode *efs_iget(struct super_block *, unsigned long);
+extern efs_block_t efs_map_block(struct inode *, efs_block_t);
+extern int efs_get_block(struct inode *, sector_t, struct buffer_head *, int);
+
+extern struct dentry *efs_lookup(struct inode *, struct dentry *, struct nameidata *);
+extern struct dentry *efs_fh_to_dentry(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type);
+extern struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type);
+extern struct dentry *efs_get_parent(struct dentry *);
+extern int efs_bmap(struct inode *, int);
+
+#endif /* _EFS_EFS_H_ */
diff --git a/fs/efs/file.c b/fs/efs/file.c
new file mode 100644
index 0000000..1ccb364
--- /dev/null
+++ b/fs/efs/file.c
@@ -0,0 +1,60 @@
+/*
+ * file.c
+ *
+ * Copyright (c) 1999 Al Smith
+ *
+ * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
+ */
+
+#include <linux/buffer_head.h>
+#include "efs.h"
+
+int efs_get_block(struct inode *inode, sector_t iblock,
+ struct buffer_head *bh_result, int create)
+{
+ int error = -EROFS;
+ long phys;
+
+ if (create)
+ return error;
+ if (iblock >= inode->i_blocks) {
+#ifdef DEBUG
+ /*
+ * i have no idea why this happens as often as it does
+ */
+ printk(KERN_WARNING "EFS: bmap(): block %d >= %ld (filesize %ld)\n",
+ block,
+ inode->i_blocks,
+ inode->i_size);
+#endif
+ return 0;
+ }
+ phys = efs_map_block(inode, iblock);
+ if (phys)
+ map_bh(bh_result, inode->i_sb, phys);
+ return 0;
+}
+
+int efs_bmap(struct inode *inode, efs_block_t block) {
+
+ if (block < 0) {
+ printk(KERN_WARNING "EFS: bmap(): block < 0\n");
+ return 0;
+ }
+
+ /* are we about to read past the end of a file ? */
+ if (!(block < inode->i_blocks)) {
+#ifdef DEBUG
+ /*
+ * i have no idea why this happens as often as it does
+ */
+ printk(KERN_WARNING "EFS: bmap(): block %d >= %ld (filesize %ld)\n",
+ block,
+ inode->i_blocks,
+ inode->i_size);
+#endif
+ return 0;
+ }
+
+ return efs_map_block(inode, block);
+}
diff --git a/fs/efs/inode.c b/fs/efs/inode.c
new file mode 100644
index 0000000..a8e7797
--- /dev/null
+++ b/fs/efs/inode.c
@@ -0,0 +1,314 @@
+/*
+ * inode.c
+ *
+ * Copyright (c) 1999 Al Smith
+ *
+ * Portions derived from work (c) 1995,1996 Christian Vogelgsang,
+ * and from work (c) 1998 Mike Shaver.
+ */
+
+#include <linux/buffer_head.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include "efs.h"
+#include <linux/efs_fs_sb.h>
+
+static int efs_readpage(struct file *file, struct page *page)
+{
+ return block_read_full_page(page,efs_get_block);
+}
+static sector_t _efs_bmap(struct address_space *mapping, sector_t block)
+{
+ return generic_block_bmap(mapping,block,efs_get_block);
+}
+static const struct address_space_operations efs_aops = {
+ .readpage = efs_readpage,
+ .sync_page = block_sync_page,
+ .bmap = _efs_bmap
+};
+
+static inline void extent_copy(efs_extent *src, efs_extent *dst) {
+ /*
+ * this is slightly evil. it doesn't just copy
+ * efs_extent from src to dst, it also mangles
+ * the bits so that dst ends up in cpu byte-order.
+ */
+
+ dst->cooked.ex_magic = (unsigned int) src->raw[0];
+ dst->cooked.ex_bn = ((unsigned int) src->raw[1] << 16) |
+ ((unsigned int) src->raw[2] << 8) |
+ ((unsigned int) src->raw[3] << 0);
+ dst->cooked.ex_length = (unsigned int) src->raw[4];
+ dst->cooked.ex_offset = ((unsigned int) src->raw[5] << 16) |
+ ((unsigned int) src->raw[6] << 8) |
+ ((unsigned int) src->raw[7] << 0);
+ return;
+}
+
+struct inode *efs_iget(struct super_block *super, unsigned long ino)
+{
+ int i, inode_index;
+ dev_t device;
+ u32 rdev;
+ struct buffer_head *bh;
+ struct efs_sb_info *sb = SUPER_INFO(super);
+ struct efs_inode_info *in;
+ efs_block_t block, offset;
+ struct efs_dinode *efs_inode;
+ struct inode *inode;
+
+ inode = iget_locked(super, ino);
+ if (IS_ERR(inode))
+ return ERR_PTR(-ENOMEM);
+ if (!(inode->i_state & I_NEW))
+ return inode;
+
+ in = INODE_INFO(inode);
+
+ /*
+ ** EFS layout:
+ **
+ ** | cylinder group | cylinder group | cylinder group ..etc
+ ** |inodes|data |inodes|data |inodes|data ..etc
+ **
+ ** work out the inode block index, (considering initially that the
+ ** inodes are stored as consecutive blocks). then work out the block
+ ** number of that inode given the above layout, and finally the
+ ** offset of the inode within that block.
+ */
+
+ inode_index = inode->i_ino /
+ (EFS_BLOCKSIZE / sizeof(struct efs_dinode));
+
+ block = sb->fs_start + sb->first_block +
+ (sb->group_size * (inode_index / sb->inode_blocks)) +
+ (inode_index % sb->inode_blocks);
+
+ offset = (inode->i_ino %
+ (EFS_BLOCKSIZE / sizeof(struct efs_dinode))) *
+ sizeof(struct efs_dinode);
+
+ bh = sb_bread(inode->i_sb, block);
+ if (!bh) {
+ printk(KERN_WARNING "EFS: bread() failed at block %d\n", block);
+ goto read_inode_error;
+ }
+
+ efs_inode = (struct efs_dinode *) (bh->b_data + offset);
+
+ inode->i_mode = be16_to_cpu(efs_inode->di_mode);
+ inode->i_nlink = be16_to_cpu(efs_inode->di_nlink);
+ inode->i_uid = (uid_t)be16_to_cpu(efs_inode->di_uid);
+ inode->i_gid = (gid_t)be16_to_cpu(efs_inode->di_gid);
+ inode->i_size = be32_to_cpu(efs_inode->di_size);
+ inode->i_atime.tv_sec = be32_to_cpu(efs_inode->di_atime);
+ inode->i_mtime.tv_sec = be32_to_cpu(efs_inode->di_mtime);
+ inode->i_ctime.tv_sec = be32_to_cpu(efs_inode->di_ctime);
+ inode->i_atime.tv_nsec = inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = 0;
+
+ /* this is the number of blocks in the file */
+ if (inode->i_size == 0) {
+ inode->i_blocks = 0;
+ } else {
+ inode->i_blocks = ((inode->i_size - 1) >> EFS_BLOCKSIZE_BITS) + 1;
+ }
+
+ rdev = be16_to_cpu(efs_inode->di_u.di_dev.odev);
+ if (rdev == 0xffff) {
+ rdev = be32_to_cpu(efs_inode->di_u.di_dev.ndev);
+ if (sysv_major(rdev) > 0xfff)
+ device = 0;
+ else
+ device = MKDEV(sysv_major(rdev), sysv_minor(rdev));
+ } else
+ device = old_decode_dev(rdev);
+
+ /* get the number of extents for this object */
+ in->numextents = be16_to_cpu(efs_inode->di_numextents);
+ in->lastextent = 0;
+
+ /* copy the extents contained within the inode to memory */
+ for(i = 0; i < EFS_DIRECTEXTENTS; i++) {
+ extent_copy(&(efs_inode->di_u.di_extents[i]), &(in->extents[i]));
+ if (i < in->numextents && in->extents[i].cooked.ex_magic != 0) {
+ printk(KERN_WARNING "EFS: extent %d has bad magic number in inode %lu\n", i, inode->i_ino);
+ brelse(bh);
+ goto read_inode_error;
+ }
+ }
+
+ brelse(bh);
+
+#ifdef DEBUG
+ printk(KERN_DEBUG "EFS: efs_iget(): inode %lu, extents %d, mode %o\n",
+ inode->i_ino, in->numextents, inode->i_mode);
+#endif
+
+ switch (inode->i_mode & S_IFMT) {
+ case S_IFDIR:
+ inode->i_op = &efs_dir_inode_operations;
+ inode->i_fop = &efs_dir_operations;
+ break;
+ case S_IFREG:
+ inode->i_fop = &generic_ro_fops;
+ inode->i_data.a_ops = &efs_aops;
+ break;
+ case S_IFLNK:
+ inode->i_op = &page_symlink_inode_operations;
+ inode->i_data.a_ops = &efs_symlink_aops;
+ break;
+ case S_IFCHR:
+ case S_IFBLK:
+ case S_IFIFO:
+ init_special_inode(inode, inode->i_mode, device);
+ break;
+ default:
+ printk(KERN_WARNING "EFS: unsupported inode mode %o\n", inode->i_mode);
+ goto read_inode_error;
+ break;
+ }
+
+ unlock_new_inode(inode);
+ return inode;
+
+read_inode_error:
+ printk(KERN_WARNING "EFS: failed to read inode %lu\n", inode->i_ino);
+ iget_failed(inode);
+ return ERR_PTR(-EIO);
+}
+
+static inline efs_block_t
+efs_extent_check(efs_extent *ptr, efs_block_t block, struct efs_sb_info *sb) {
+ efs_block_t start;
+ efs_block_t length;
+ efs_block_t offset;
+
+ /*
+ * given an extent and a logical block within a file,
+ * can this block be found within this extent ?
+ */
+ start = ptr->cooked.ex_bn;
+ length = ptr->cooked.ex_length;
+ offset = ptr->cooked.ex_offset;
+
+ if ((block >= offset) && (block < offset+length)) {
+ return(sb->fs_start + start + block - offset);
+ } else {
+ return 0;
+ }
+}
+
+efs_block_t efs_map_block(struct inode *inode, efs_block_t block) {
+ struct efs_sb_info *sb = SUPER_INFO(inode->i_sb);
+ struct efs_inode_info *in = INODE_INFO(inode);
+ struct buffer_head *bh = NULL;
+
+ int cur, last, first = 1;
+ int ibase, ioffset, dirext, direxts, indext, indexts;
+ efs_block_t iblock, result = 0, lastblock = 0;
+ efs_extent ext, *exts;
+
+ last = in->lastextent;
+
+ if (in->numextents <= EFS_DIRECTEXTENTS) {
+ /* first check the last extent we returned */
+ if ((result = efs_extent_check(&in->extents[last], block, sb)))
+ return result;
+
+ /* if we only have one extent then nothing can be found */
+ if (in->numextents == 1) {
+ printk(KERN_ERR "EFS: map_block() failed to map (1 extent)\n");
+ return 0;
+ }
+
+ direxts = in->numextents;
+
+ /*
+ * check the stored extents in the inode
+ * start with next extent and check forwards
+ */
+ for(dirext = 1; dirext < direxts; dirext++) {
+ cur = (last + dirext) % in->numextents;
+ if ((result = efs_extent_check(&in->extents[cur], block, sb))) {
+ in->lastextent = cur;
+ return result;
+ }
+ }
+
+ printk(KERN_ERR "EFS: map_block() failed to map block %u (dir)\n", block);
+ return 0;
+ }
+
+#ifdef DEBUG
+ printk(KERN_DEBUG "EFS: map_block(): indirect search for logical block %u\n", block);
+#endif
+ direxts = in->extents[0].cooked.ex_offset;
+ indexts = in->numextents;
+
+ for(indext = 0; indext < indexts; indext++) {
+ cur = (last + indext) % indexts;
+
+ /*
+ * work out which direct extent contains `cur'.
+ *
+ * also compute ibase: i.e. the number of the first
+ * indirect extent contained within direct extent `cur'.
+ *
+ */
+ ibase = 0;
+ for(dirext = 0; cur < ibase && dirext < direxts; dirext++) {
+ ibase += in->extents[dirext].cooked.ex_length *
+ (EFS_BLOCKSIZE / sizeof(efs_extent));
+ }
+
+ if (dirext == direxts) {
+ /* should never happen */
+ printk(KERN_ERR "EFS: couldn't find direct extent for indirect extent %d (block %u)\n", cur, block);
+ if (bh) brelse(bh);
+ return 0;
+ }
+
+ /* work out block number and offset of this indirect extent */
+ iblock = sb->fs_start + in->extents[dirext].cooked.ex_bn +
+ (cur - ibase) /
+ (EFS_BLOCKSIZE / sizeof(efs_extent));
+ ioffset = (cur - ibase) %
+ (EFS_BLOCKSIZE / sizeof(efs_extent));
+
+ if (first || lastblock != iblock) {
+ if (bh) brelse(bh);
+
+ bh = sb_bread(inode->i_sb, iblock);
+ if (!bh) {
+ printk(KERN_ERR "EFS: bread() failed at block %d\n", iblock);
+ return 0;
+ }
+#ifdef DEBUG
+ printk(KERN_DEBUG "EFS: map_block(): read indirect extent block %d\n", iblock);
+#endif
+ first = 0;
+ lastblock = iblock;
+ }
+
+ exts = (efs_extent *) bh->b_data;
+
+ extent_copy(&(exts[ioffset]), &ext);
+
+ if (ext.cooked.ex_magic != 0) {
+ printk(KERN_ERR "EFS: extent %d has bad magic number in block %d\n", cur, iblock);
+ if (bh) brelse(bh);
+ return 0;
+ }
+
+ if ((result = efs_extent_check(&ext, block, sb))) {
+ if (bh) brelse(bh);
+ in->lastextent = cur;
+ return result;
+ }
+ }
+ if (bh) brelse(bh);
+ printk(KERN_ERR "EFS: map_block() failed to map block %u (indir)\n", block);
+ return 0;
+}
+
+MODULE_LICENSE("GPL");
diff --git a/fs/efs/namei.c b/fs/efs/namei.c
new file mode 100644
index 0000000..c3fb5f9
--- /dev/null
+++ b/fs/efs/namei.c
@@ -0,0 +1,125 @@
+/*
+ * namei.c
+ *
+ * Copyright (c) 1999 Al Smith
+ *
+ * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
+ */
+
+#include <linux/buffer_head.h>
+#include <linux/string.h>
+#include <linux/smp_lock.h>
+#include <linux/exportfs.h>
+#include "efs.h"
+
+
+static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) {
+ struct buffer_head *bh;
+
+ int slot, namelen;
+ char *nameptr;
+ struct efs_dir *dirblock;
+ struct efs_dentry *dirslot;
+ efs_ino_t inodenum;
+ efs_block_t block;
+
+ if (inode->i_size & (EFS_DIRBSIZE-1))
+ printk(KERN_WARNING "EFS: WARNING: find_entry(): directory size not a multiple of EFS_DIRBSIZE\n");
+
+ for(block = 0; block < inode->i_blocks; block++) {
+
+ bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
+ if (!bh) {
+ printk(KERN_ERR "EFS: find_entry(): failed to read dir block %d\n", block);
+ return 0;
+ }
+
+ dirblock = (struct efs_dir *) bh->b_data;
+
+ if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
+ printk(KERN_ERR "EFS: find_entry(): invalid directory block\n");
+ brelse(bh);
+ return(0);
+ }
+
+ for(slot = 0; slot < dirblock->slots; slot++) {
+ dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
+
+ namelen = dirslot->namelen;
+ nameptr = dirslot->name;
+
+ if ((namelen == len) && (!memcmp(name, nameptr, len))) {
+ inodenum = be32_to_cpu(dirslot->inode);
+ brelse(bh);
+ return(inodenum);
+ }
+ }
+ brelse(bh);
+ }
+ return(0);
+}
+
+struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) {
+ efs_ino_t inodenum;
+ struct inode * inode = NULL;
+
+ lock_kernel();
+ inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
+ if (inodenum) {
+ inode = efs_iget(dir->i_sb, inodenum);
+ if (IS_ERR(inode)) {
+ unlock_kernel();
+ return ERR_CAST(inode);
+ }
+ }
+ unlock_kernel();
+
+ return d_splice_alias(inode, dentry);
+}
+
+static struct inode *efs_nfs_get_inode(struct super_block *sb, u64 ino,
+ u32 generation)
+{
+ struct inode *inode;
+
+ if (ino == 0)
+ return ERR_PTR(-ESTALE);
+ inode = efs_iget(sb, ino);
+ if (IS_ERR(inode))
+ return ERR_CAST(inode);
+
+ if (generation && inode->i_generation != generation) {
+ iput(inode);
+ return ERR_PTR(-ESTALE);
+ }
+
+ return inode;
+}
+
+struct dentry *efs_fh_to_dentry(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type)
+{
+ return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
+ efs_nfs_get_inode);
+}
+
+struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
+ int fh_len, int fh_type)
+{
+ return generic_fh_to_parent(sb, fid, fh_len, fh_type,
+ efs_nfs_get_inode);
+}
+
+struct dentry *efs_get_parent(struct dentry *child)
+{
+ struct dentry *parent = ERR_PTR(-ENOENT);
+ efs_ino_t ino;
+
+ lock_kernel();
+ ino = efs_find_entry(child->d_inode, "..", 2);
+ if (ino)
+ parent = d_obtain_alias(efs_iget(child->d_inode->i_sb, ino));
+ unlock_kernel();
+
+ return parent;
+}
diff --git a/fs/efs/super.c b/fs/efs/super.c
new file mode 100644
index 0000000..73b19cf
--- /dev/null
+++ b/fs/efs/super.c
@@ -0,0 +1,348 @@
+/*
+ * super.c
+ *
+ * Copyright (c) 1999 Al Smith
+ *
+ * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/exportfs.h>
+#include <linux/slab.h>
+#include <linux/buffer_head.h>
+#include <linux/vfs.h>
+
+#include "efs.h"
+#include <linux/efs_vh.h>
+#include <linux/efs_fs_sb.h>
+
+static int efs_statfs(struct dentry *dentry, struct kstatfs *buf);
+static int efs_fill_super(struct super_block *s, void *d, int silent);
+
+static int efs_get_sb(struct file_system_type *fs_type,
+ int flags, const char *dev_name, void *data, struct vfsmount *mnt)
+{
+ return get_sb_bdev(fs_type, flags, dev_name, data, efs_fill_super, mnt);
+}
+
+static struct file_system_type efs_fs_type = {
+ .owner = THIS_MODULE,
+ .name = "efs",
+ .get_sb = efs_get_sb,
+ .kill_sb = kill_block_super,
+ .fs_flags = FS_REQUIRES_DEV,
+};
+
+static struct pt_types sgi_pt_types[] = {
+ {0x00, "SGI vh"},
+ {0x01, "SGI trkrepl"},
+ {0x02, "SGI secrepl"},
+ {0x03, "SGI raw"},
+ {0x04, "SGI bsd"},
+ {SGI_SYSV, "SGI sysv"},
+ {0x06, "SGI vol"},
+ {SGI_EFS, "SGI efs"},
+ {0x08, "SGI lv"},
+ {0x09, "SGI rlv"},
+ {0x0A, "SGI xfs"},
+ {0x0B, "SGI xfslog"},
+ {0x0C, "SGI xlv"},
+ {0x82, "Linux swap"},
+ {0x83, "Linux native"},
+ {0, NULL}
+};
+
+
+static struct kmem_cache * efs_inode_cachep;
+
+static struct inode *efs_alloc_inode(struct super_block *sb)
+{
+ struct efs_inode_info *ei;
+ ei = (struct efs_inode_info *)kmem_cache_alloc(efs_inode_cachep, GFP_KERNEL);
+ if (!ei)
+ return NULL;
+ return &ei->vfs_inode;
+}
+
+static void efs_destroy_inode(struct inode *inode)
+{
+ kmem_cache_free(efs_inode_cachep, INODE_INFO(inode));
+}
+
+static void init_once(void *foo)
+{
+ struct efs_inode_info *ei = (struct efs_inode_info *) foo;
+
+ inode_init_once(&ei->vfs_inode);
+}
+
+static int init_inodecache(void)
+{
+ efs_inode_cachep = kmem_cache_create("efs_inode_cache",
+ sizeof(struct efs_inode_info),
+ 0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
+ init_once);
+ if (efs_inode_cachep == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+static void destroy_inodecache(void)
+{
+ kmem_cache_destroy(efs_inode_cachep);
+}
+
+static void efs_put_super(struct super_block *s)
+{
+ kfree(s->s_fs_info);
+ s->s_fs_info = NULL;
+}
+
+static int efs_remount(struct super_block *sb, int *flags, char *data)
+{
+ *flags |= MS_RDONLY;
+ return 0;
+}
+
+static const struct super_operations efs_superblock_operations = {
+ .alloc_inode = efs_alloc_inode,
+ .destroy_inode = efs_destroy_inode,
+ .put_super = efs_put_super,
+ .statfs = efs_statfs,
+ .remount_fs = efs_remount,
+};
+
+static const struct export_operations efs_export_ops = {
+ .fh_to_dentry = efs_fh_to_dentry,
+ .fh_to_parent = efs_fh_to_parent,
+ .get_parent = efs_get_parent,
+};
+
+static int __init init_efs_fs(void) {
+ int err;
+ printk("EFS: "EFS_VERSION" - http://aeschi.ch.eu.org/efs/\n");
+ err = init_inodecache();
+ if (err)
+ goto out1;
+ err = register_filesystem(&efs_fs_type);
+ if (err)
+ goto out;
+ return 0;
+out:
+ destroy_inodecache();
+out1:
+ return err;
+}
+
+static void __exit exit_efs_fs(void) {
+ unregister_filesystem(&efs_fs_type);
+ destroy_inodecache();
+}
+
+module_init(init_efs_fs)
+module_exit(exit_efs_fs)
+
+static efs_block_t efs_validate_vh(struct volume_header *vh) {
+ int i;
+ __be32 cs, *ui;
+ int csum;
+ efs_block_t sblock = 0; /* shuts up gcc */
+ struct pt_types *pt_entry;
+ int pt_type, slice = -1;
+
+ if (be32_to_cpu(vh->vh_magic) != VHMAGIC) {
+ /*
+ * assume that we're dealing with a partition and allow
+ * read_super() to try and detect a valid superblock
+ * on the next block.
+ */
+ return 0;
+ }
+
+ ui = ((__be32 *) (vh + 1)) - 1;
+ for(csum = 0; ui >= ((__be32 *) vh);) {
+ cs = *ui--;
+ csum += be32_to_cpu(cs);
+ }
+ if (csum) {
+ printk(KERN_INFO "EFS: SGI disklabel: checksum bad, label corrupted\n");
+ return 0;
+ }
+
+#ifdef DEBUG
+ printk(KERN_DEBUG "EFS: bf: \"%16s\"\n", vh->vh_bootfile);
+
+ for(i = 0; i < NVDIR; i++) {
+ int j;
+ char name[VDNAMESIZE+1];
+
+ for(j = 0; j < VDNAMESIZE; j++) {
+ name[j] = vh->vh_vd[i].vd_name[j];
+ }
+ name[j] = (char) 0;
+
+ if (name[0]) {
+ printk(KERN_DEBUG "EFS: vh: %8s block: 0x%08x size: 0x%08x\n",
+ name,
+ (int) be32_to_cpu(vh->vh_vd[i].vd_lbn),
+ (int) be32_to_cpu(vh->vh_vd[i].vd_nbytes));
+ }
+ }
+#endif
+
+ for(i = 0; i < NPARTAB; i++) {
+ pt_type = (int) be32_to_cpu(vh->vh_pt[i].pt_type);
+ for(pt_entry = sgi_pt_types; pt_entry->pt_name; pt_entry++) {
+ if (pt_type == pt_entry->pt_type) break;
+ }
+#ifdef DEBUG
+ if (be32_to_cpu(vh->vh_pt[i].pt_nblks)) {
+ printk(KERN_DEBUG "EFS: pt %2d: start: %08d size: %08d type: 0x%02x (%s)\n",
+ i,
+ (int) be32_to_cpu(vh->vh_pt[i].pt_firstlbn),
+ (int) be32_to_cpu(vh->vh_pt[i].pt_nblks),
+ pt_type,
+ (pt_entry->pt_name) ? pt_entry->pt_name : "unknown");
+ }
+#endif
+ if (IS_EFS(pt_type)) {
+ sblock = be32_to_cpu(vh->vh_pt[i].pt_firstlbn);
+ slice = i;
+ }
+ }
+
+ if (slice == -1) {
+ printk(KERN_NOTICE "EFS: partition table contained no EFS partitions\n");
+#ifdef DEBUG
+ } else {
+ printk(KERN_INFO "EFS: using slice %d (type %s, offset 0x%x)\n",
+ slice,
+ (pt_entry->pt_name) ? pt_entry->pt_name : "unknown",
+ sblock);
+#endif
+ }
+ return sblock;
+}
+
+static int efs_validate_super(struct efs_sb_info *sb, struct efs_super *super) {
+
+ if (!IS_EFS_MAGIC(be32_to_cpu(super->fs_magic)))
+ return -1;
+
+ sb->fs_magic = be32_to_cpu(super->fs_magic);
+ sb->total_blocks = be32_to_cpu(super->fs_size);
+ sb->first_block = be32_to_cpu(super->fs_firstcg);
+ sb->group_size = be32_to_cpu(super->fs_cgfsize);
+ sb->data_free = be32_to_cpu(super->fs_tfree);
+ sb->inode_free = be32_to_cpu(super->fs_tinode);
+ sb->inode_blocks = be16_to_cpu(super->fs_cgisize);
+ sb->total_groups = be16_to_cpu(super->fs_ncg);
+
+ return 0;
+}
+
+static int efs_fill_super(struct super_block *s, void *d, int silent)
+{
+ struct efs_sb_info *sb;
+ struct buffer_head *bh;
+ struct inode *root;
+ int ret = -EINVAL;
+
+ sb = kzalloc(sizeof(struct efs_sb_info), GFP_KERNEL);
+ if (!sb)
+ return -ENOMEM;
+ s->s_fs_info = sb;
+
+ s->s_magic = EFS_SUPER_MAGIC;
+ if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
+ printk(KERN_ERR "EFS: device does not support %d byte blocks\n",
+ EFS_BLOCKSIZE);
+ goto out_no_fs_ul;
+ }
+
+ /* read the vh (volume header) block */
+ bh = sb_bread(s, 0);
+
+ if (!bh) {
+ printk(KERN_ERR "EFS: cannot read volume header\n");
+ goto out_no_fs_ul;
+ }
+
+ /*
+ * if this returns zero then we didn't find any partition table.
+ * this isn't (yet) an error - just assume for the moment that
+ * the device is valid and go on to search for a superblock.
+ */
+ sb->fs_start = efs_validate_vh((struct volume_header *) bh->b_data);
+ brelse(bh);
+
+ if (sb->fs_start == -1) {
+ goto out_no_fs_ul;
+ }
+
+ bh = sb_bread(s, sb->fs_start + EFS_SUPER);
+ if (!bh) {
+ printk(KERN_ERR "EFS: cannot read superblock\n");
+ goto out_no_fs_ul;
+ }
+
+ if (efs_validate_super(sb, (struct efs_super *) bh->b_data)) {
+#ifdef DEBUG
+ printk(KERN_WARNING "EFS: invalid superblock at block %u\n", sb->fs_start + EFS_SUPER);
+#endif
+ brelse(bh);
+ goto out_no_fs_ul;
+ }
+ brelse(bh);
+
+ if (!(s->s_flags & MS_RDONLY)) {
+#ifdef DEBUG
+ printk(KERN_INFO "EFS: forcing read-only mode\n");
+#endif
+ s->s_flags |= MS_RDONLY;
+ }
+ s->s_op = &efs_superblock_operations;
+ s->s_export_op = &efs_export_ops;
+ root = efs_iget(s, EFS_ROOTINODE);
+ if (IS_ERR(root)) {
+ printk(KERN_ERR "EFS: get root inode failed\n");
+ ret = PTR_ERR(root);
+ goto out_no_fs;
+ }
+
+ s->s_root = d_alloc_root(root);
+ if (!(s->s_root)) {
+ printk(KERN_ERR "EFS: get root dentry failed\n");
+ iput(root);
+ ret = -ENOMEM;
+ goto out_no_fs;
+ }
+
+ return 0;
+
+out_no_fs_ul:
+out_no_fs:
+ s->s_fs_info = NULL;
+ kfree(sb);
+ return ret;
+}
+
+static int efs_statfs(struct dentry *dentry, struct kstatfs *buf) {
+ struct efs_sb_info *sb = SUPER_INFO(dentry->d_sb);
+
+ buf->f_type = EFS_SUPER_MAGIC; /* efs magic number */
+ buf->f_bsize = EFS_BLOCKSIZE; /* blocksize */
+ buf->f_blocks = sb->total_groups * /* total data blocks */
+ (sb->group_size - sb->inode_blocks);
+ buf->f_bfree = sb->data_free; /* free data blocks */
+ buf->f_bavail = sb->data_free; /* free blocks for non-root */
+ buf->f_files = sb->total_groups * /* total inodes */
+ sb->inode_blocks *
+ (EFS_BLOCKSIZE / sizeof(struct efs_dinode));
+ buf->f_ffree = sb->inode_free; /* free inodes */
+ buf->f_namelen = EFS_MAXNAMELEN; /* max filename length */
+
+ return 0;
+}
+
diff --git a/fs/efs/symlink.c b/fs/efs/symlink.c
new file mode 100644
index 0000000..41911ec
--- /dev/null
+++ b/fs/efs/symlink.c
@@ -0,0 +1,59 @@
+/*
+ * symlink.c
+ *
+ * Copyright (c) 1999 Al Smith
+ *
+ * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
+ */
+
+#include <linux/string.h>
+#include <linux/pagemap.h>
+#include <linux/buffer_head.h>
+#include <linux/smp_lock.h>
+#include "efs.h"
+
+static int efs_symlink_readpage(struct file *file, struct page *page)
+{
+ char *link = kmap(page);
+ struct buffer_head * bh;
+ struct inode * inode = page->mapping->host;
+ efs_block_t size = inode->i_size;
+ int err;
+
+ err = -ENAMETOOLONG;
+ if (size > 2 * EFS_BLOCKSIZE)
+ goto fail_notlocked;
+
+ lock_kernel();
+ /* read first 512 bytes of link target */
+ err = -EIO;
+ bh = sb_bread(inode->i_sb, efs_bmap(inode, 0));
+ if (!bh)
+ goto fail;
+ memcpy(link, bh->b_data, (size > EFS_BLOCKSIZE) ? EFS_BLOCKSIZE : size);
+ brelse(bh);
+ if (size > EFS_BLOCKSIZE) {
+ bh = sb_bread(inode->i_sb, efs_bmap(inode, 1));
+ if (!bh)
+ goto fail;
+ memcpy(link + EFS_BLOCKSIZE, bh->b_data, size - EFS_BLOCKSIZE);
+ brelse(bh);
+ }
+ link[size] = '\0';
+ unlock_kernel();
+ SetPageUptodate(page);
+ kunmap(page);
+ unlock_page(page);
+ return 0;
+fail:
+ unlock_kernel();
+fail_notlocked:
+ SetPageError(page);
+ kunmap(page);
+ unlock_page(page);
+ return err;
+}
+
+const struct address_space_operations efs_symlink_aops = {
+ .readpage = efs_symlink_readpage
+};
OpenPOWER on IntegriCloud