summaryrefslogtreecommitdiffstats
path: root/fs/isofs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/isofs
Linux-2.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/isofs')
-rw-r--r--fs/isofs/Makefile10
-rw-r--r--fs/isofs/compress.c359
-rw-r--r--fs/isofs/dir.c280
-rw-r--r--fs/isofs/export.c228
-rw-r--r--fs/isofs/inode.c1503
-rw-r--r--fs/isofs/joliet.c103
-rw-r--r--fs/isofs/namei.c201
-rw-r--r--fs/isofs/rock.c565
-rw-r--r--fs/isofs/rock.h119
-rw-r--r--fs/isofs/util.c83
-rw-r--r--fs/isofs/zisofs.h21
11 files changed, 3472 insertions, 0 deletions
diff --git a/fs/isofs/Makefile b/fs/isofs/Makefile
new file mode 100644
index 000000000000..bf162f0942d5
--- /dev/null
+++ b/fs/isofs/Makefile
@@ -0,0 +1,10 @@
+#
+# Makefile for the Linux isofs filesystem routines.
+#
+
+obj-$(CONFIG_ISO9660_FS) += isofs.o
+
+isofs-objs-y := namei.o inode.o dir.o util.o rock.o export.o
+isofs-objs-$(CONFIG_JOLIET) += joliet.o
+isofs-objs-$(CONFIG_ZISOFS) += compress.o
+isofs-objs := $(isofs-objs-y)
diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
new file mode 100644
index 000000000000..fb42c3f3bf0d
--- /dev/null
+++ b/fs/isofs/compress.c
@@ -0,0 +1,359 @@
+/* -*- linux-c -*- ------------------------------------------------------- *
+ *
+ * Copyright 2001 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ * USA; either version 2 of the License, or (at your option) any later
+ * version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * linux/fs/isofs/compress.c
+ *
+ * Transparent decompression of files on an iso9660 filesystem
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+
+#include <linux/stat.h>
+#include <linux/time.h>
+#include <linux/iso_fs.h>
+#include <linux/kernel.h>
+#include <linux/major.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/nls.h>
+#include <linux/ctype.h>
+#include <linux/smp_lock.h>
+#include <linux/blkdev.h>
+#include <linux/vmalloc.h>
+#include <linux/zlib.h>
+#include <linux/buffer_head.h>
+
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/semaphore.h>
+
+#include "zisofs.h"
+
+/* This should probably be global. */
+static char zisofs_sink_page[PAGE_CACHE_SIZE];
+
+/*
+ * This contains the zlib memory allocation and the mutex for the
+ * allocation; this avoids failures at block-decompression time.
+ */
+static void *zisofs_zlib_workspace;
+static struct semaphore zisofs_zlib_semaphore;
+
+/*
+ * When decompressing, we typically obtain more than one page
+ * per reference. We inject the additional pages into the page
+ * cache as a form of readahead.
+ */
+static int zisofs_readpage(struct file *file, struct page *page)
+{
+ struct inode *inode = file->f_dentry->d_inode;
+ struct address_space *mapping = inode->i_mapping;
+ unsigned int maxpage, xpage, fpage, blockindex;
+ unsigned long offset;
+ unsigned long blockptr, blockendptr, cstart, cend, csize;
+ struct buffer_head *bh, *ptrbh[2];
+ unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
+ unsigned int bufshift = ISOFS_BUFFER_BITS(inode);
+ unsigned long bufmask = bufsize - 1;
+ int err = -EIO;
+ int i;
+ unsigned int header_size = ISOFS_I(inode)->i_format_parm[0];
+ unsigned int zisofs_block_shift = ISOFS_I(inode)->i_format_parm[1];
+ /* unsigned long zisofs_block_size = 1UL << zisofs_block_shift; */
+ unsigned int zisofs_block_page_shift = zisofs_block_shift-PAGE_CACHE_SHIFT;
+ unsigned long zisofs_block_pages = 1UL << zisofs_block_page_shift;
+ unsigned long zisofs_block_page_mask = zisofs_block_pages-1;
+ struct page *pages[zisofs_block_pages];
+ unsigned long index = page->index;
+ int indexblocks;
+
+ /* We have already been given one page, this is the one
+ we must do. */
+ xpage = index & zisofs_block_page_mask;
+ pages[xpage] = page;
+
+ /* The remaining pages need to be allocated and inserted */
+ offset = index & ~zisofs_block_page_mask;
+ blockindex = offset >> zisofs_block_page_shift;
+ maxpage = (inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
+ maxpage = min(zisofs_block_pages, maxpage-offset);
+
+ for ( i = 0 ; i < maxpage ; i++, offset++ ) {
+ if ( i != xpage ) {
+ pages[i] = grab_cache_page_nowait(mapping, offset);
+ }
+ page = pages[i];
+ if ( page ) {
+ ClearPageError(page);
+ kmap(page);
+ }
+ }
+
+ /* This is the last page filled, plus one; used in case of abort. */
+ fpage = 0;
+
+ /* Find the pointer to this specific chunk */
+ /* Note: we're not using isonum_731() here because the data is known aligned */
+ /* Note: header_size is in 32-bit words (4 bytes) */
+ blockptr = (header_size + blockindex) << 2;
+ blockendptr = blockptr + 4;
+
+ indexblocks = ((blockptr^blockendptr) >> bufshift) ? 2 : 1;
+ ptrbh[0] = ptrbh[1] = NULL;
+
+ if ( isofs_get_blocks(inode, blockptr >> bufshift, ptrbh, indexblocks) != indexblocks ) {
+ if ( ptrbh[0] ) brelse(ptrbh[0]);
+ printk(KERN_DEBUG "zisofs: Null buffer on reading block table, inode = %lu, block = %lu\n",
+ inode->i_ino, blockptr >> bufshift);
+ goto eio;
+ }
+ ll_rw_block(READ, indexblocks, ptrbh);
+
+ bh = ptrbh[0];
+ if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
+ printk(KERN_DEBUG "zisofs: Failed to read block table, inode = %lu, block = %lu\n",
+ inode->i_ino, blockptr >> bufshift);
+ if ( ptrbh[1] )
+ brelse(ptrbh[1]);
+ goto eio;
+ }
+ cstart = le32_to_cpu(*(__le32 *)(bh->b_data + (blockptr & bufmask)));
+
+ if ( indexblocks == 2 ) {
+ /* We just crossed a block boundary. Switch to the next block */
+ brelse(bh);
+ bh = ptrbh[1];
+ if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
+ printk(KERN_DEBUG "zisofs: Failed to read block table, inode = %lu, block = %lu\n",
+ inode->i_ino, blockendptr >> bufshift);
+ goto eio;
+ }
+ }
+ cend = le32_to_cpu(*(__le32 *)(bh->b_data + (blockendptr & bufmask)));
+ brelse(bh);
+
+ csize = cend-cstart;
+
+ /* Now page[] contains an array of pages, any of which can be NULL,
+ and the locks on which we hold. We should now read the data and
+ release the pages. If the pages are NULL the decompressed data
+ for that particular page should be discarded. */
+
+ if ( csize == 0 ) {
+ /* This data block is empty. */
+
+ for ( fpage = 0 ; fpage < maxpage ; fpage++ ) {
+ if ( (page = pages[fpage]) != NULL ) {
+ memset(page_address(page), 0, PAGE_CACHE_SIZE);
+
+ flush_dcache_page(page);
+ SetPageUptodate(page);
+ kunmap(page);
+ unlock_page(page);
+ if ( fpage == xpage )
+ err = 0; /* The critical page */
+ else
+ page_cache_release(page);
+ }
+ }
+ } else {
+ /* This data block is compressed. */
+ z_stream stream;
+ int bail = 0, left_out = -1;
+ int zerr;
+ int needblocks = (csize + (cstart & bufmask) + bufmask) >> bufshift;
+ int haveblocks;
+ struct buffer_head *bhs[needblocks+1];
+ struct buffer_head **bhptr;
+
+ /* Because zlib is not thread-safe, do all the I/O at the top. */
+
+ blockptr = cstart >> bufshift;
+ memset(bhs, 0, (needblocks+1)*sizeof(struct buffer_head *));
+ haveblocks = isofs_get_blocks(inode, blockptr, bhs, needblocks);
+ ll_rw_block(READ, haveblocks, bhs);
+
+ bhptr = &bhs[0];
+ bh = *bhptr++;
+
+ /* First block is special since it may be fractional.
+ We also wait for it before grabbing the zlib
+ semaphore; odds are that the subsequent blocks are
+ going to come in in short order so we don't hold
+ the zlib semaphore longer than necessary. */
+
+ if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
+ printk(KERN_DEBUG "zisofs: Hit null buffer, fpage = %d, xpage = %d, csize = %ld\n",
+ fpage, xpage, csize);
+ goto b_eio;
+ }
+ stream.next_in = bh->b_data + (cstart & bufmask);
+ stream.avail_in = min(bufsize-(cstart & bufmask), csize);
+ csize -= stream.avail_in;
+
+ stream.workspace = zisofs_zlib_workspace;
+ down(&zisofs_zlib_semaphore);
+
+ zerr = zlib_inflateInit(&stream);
+ if ( zerr != Z_OK ) {
+ if ( err && zerr == Z_MEM_ERROR )
+ err = -ENOMEM;
+ printk(KERN_DEBUG "zisofs: zisofs_inflateInit returned %d\n",
+ zerr);
+ goto z_eio;
+ }
+
+ while ( !bail && fpage < maxpage ) {
+ page = pages[fpage];
+ if ( page )
+ stream.next_out = page_address(page);
+ else
+ stream.next_out = (void *)&zisofs_sink_page;
+ stream.avail_out = PAGE_CACHE_SIZE;
+
+ while ( stream.avail_out ) {
+ int ao, ai;
+ if ( stream.avail_in == 0 && left_out ) {
+ if ( !csize ) {
+ printk(KERN_WARNING "zisofs: ZF read beyond end of input\n");
+ bail = 1;
+ break;
+ } else {
+ bh = *bhptr++;
+ if ( !bh ||
+ (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
+ /* Reached an EIO */
+ printk(KERN_DEBUG "zisofs: Hit null buffer, fpage = %d, xpage = %d, csize = %ld\n",
+ fpage, xpage, csize);
+
+ bail = 1;
+ break;
+ }
+ stream.next_in = bh->b_data;
+ stream.avail_in = min(csize,bufsize);
+ csize -= stream.avail_in;
+ }
+ }
+ ao = stream.avail_out; ai = stream.avail_in;
+ zerr = zlib_inflate(&stream, Z_SYNC_FLUSH);
+ left_out = stream.avail_out;
+ if ( zerr == Z_BUF_ERROR && stream.avail_in == 0 )
+ continue;
+ if ( zerr != Z_OK ) {
+ /* EOF, error, or trying to read beyond end of input */
+ if ( err && zerr == Z_MEM_ERROR )
+ err = -ENOMEM;
+ if ( zerr != Z_STREAM_END )
+ printk(KERN_DEBUG "zisofs: zisofs_inflate returned %d, inode = %lu, index = %lu, fpage = %d, xpage = %d, avail_in = %d, avail_out = %d, ai = %d, ao = %d\n",
+ zerr, inode->i_ino, index,
+ fpage, xpage,
+ stream.avail_in, stream.avail_out,
+ ai, ao);
+ bail = 1;
+ break;
+ }
+ }
+
+ if ( stream.avail_out && zerr == Z_STREAM_END ) {
+ /* Fractional page written before EOF. This may
+ be the last page in the file. */
+ memset(stream.next_out, 0, stream.avail_out);
+ stream.avail_out = 0;
+ }
+
+ if ( !stream.avail_out ) {
+ /* This page completed */
+ if ( page ) {
+ flush_dcache_page(page);
+ SetPageUptodate(page);
+ kunmap(page);
+ unlock_page(page);
+ if ( fpage == xpage )
+ err = 0; /* The critical page */
+ else
+ page_cache_release(page);
+ }
+ fpage++;
+ }
+ }
+ zlib_inflateEnd(&stream);
+
+ z_eio:
+ up(&zisofs_zlib_semaphore);
+
+ b_eio:
+ for ( i = 0 ; i < haveblocks ; i++ ) {
+ if ( bhs[i] )
+ brelse(bhs[i]);
+ }
+ }
+
+eio:
+
+ /* Release any residual pages, do not SetPageUptodate */
+ while ( fpage < maxpage ) {
+ page = pages[fpage];
+ if ( page ) {
+ flush_dcache_page(page);
+ if ( fpage == xpage )
+ SetPageError(page);
+ kunmap(page);
+ unlock_page(page);
+ if ( fpage != xpage )
+ page_cache_release(page);
+ }
+ fpage++;
+ }
+
+ /* At this point, err contains 0 or -EIO depending on the "critical" page */
+ return err;
+}
+
+struct address_space_operations zisofs_aops = {
+ .readpage = zisofs_readpage,
+ /* No sync_page operation supported? */
+ /* No bmap operation supported */
+};
+
+static int initialized;
+
+int __init zisofs_init(void)
+{
+ if ( initialized ) {
+ printk("zisofs_init: called more than once\n");
+ return 0;
+ }
+
+ zisofs_zlib_workspace = vmalloc(zlib_inflate_workspacesize());
+ if ( !zisofs_zlib_workspace )
+ return -ENOMEM;
+ init_MUTEX(&zisofs_zlib_semaphore);
+
+ initialized = 1;
+ return 0;
+}
+
+void zisofs_cleanup(void)
+{
+ if ( !initialized ) {
+ printk("zisofs_cleanup: called without initialization\n");
+ return;
+ }
+
+ vfree(zisofs_zlib_workspace);
+ initialized = 0;
+}
diff --git a/fs/isofs/dir.c b/fs/isofs/dir.c
new file mode 100644
index 000000000000..14d86de6637d
--- /dev/null
+++ b/fs/isofs/dir.c
@@ -0,0 +1,280 @@
+/*
+ * linux/fs/isofs/dir.c
+ *
+ * (C) 1992, 1993, 1994 Eric Youngdale Modified for ISO 9660 filesystem.
+ *
+ * (C) 1991 Linus Torvalds - minix filesystem
+ *
+ * Steve Beynon : Missing last directory entries fixed
+ * (stephen@askone.demon.co.uk) : 21st June 1996
+ *
+ * isofs directory handling functions
+ */
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/iso_fs.h>
+#include <linux/kernel.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/time.h>
+#include <linux/config.h>
+#include <linux/smp_lock.h>
+#include <linux/buffer_head.h>
+
+#include <asm/uaccess.h>
+
+static int isofs_readdir(struct file *, void *, filldir_t);
+
+struct file_operations isofs_dir_operations =
+{
+ .read = generic_read_dir,
+ .readdir = isofs_readdir,
+};
+
+/*
+ * directories can handle most operations...
+ */
+struct inode_operations isofs_dir_inode_operations =
+{
+ .lookup = isofs_lookup,
+};
+
+int isofs_name_translate(struct iso_directory_record *de, char *new, struct inode *inode)
+{
+ char * old = de->name;
+ int len = de->name_len[0];
+ int i;
+
+ for (i = 0; i < len; i++) {
+ unsigned char c = old[i];
+ if (!c)
+ break;
+
+ if (c >= 'A' && c <= 'Z')
+ c |= 0x20; /* lower case */
+
+ /* Drop trailing '.;1' (ISO 9660:1988 7.5.1 requires period) */
+ if (c == '.' && i == len - 3 && old[i + 1] == ';' && old[i + 2] == '1')
+ break;
+
+ /* Drop trailing ';1' */
+ if (c == ';' && i == len - 2 && old[i + 1] == '1')
+ break;
+
+ /* Convert remaining ';' to '.' */
+ /* Also '/' to '.' (broken Acorn-generated ISO9660 images) */
+ if (c == ';' || c == '/')
+ c = '.';
+
+ new[i] = c;
+ }
+ return i;
+}
+
+/* Acorn extensions written by Matthew Wilcox <willy@bofh.ai> 1998 */
+int get_acorn_filename(struct iso_directory_record * de,
+ char * retname, struct inode * inode)
+{
+ int std;
+ unsigned char * chr;
+ int retnamlen = isofs_name_translate(de, retname, inode);
+ if (retnamlen == 0) return 0;
+ std = sizeof(struct iso_directory_record) + de->name_len[0];
+ if (std & 1) std++;
+ if ((*((unsigned char *) de) - std) != 32) return retnamlen;
+ chr = ((unsigned char *) de) + std;
+ if (strncmp(chr, "ARCHIMEDES", 10)) return retnamlen;
+ if ((*retname == '_') && ((chr[19] & 1) == 1)) *retname = '!';
+ if (((de->flags[0] & 2) == 0) && (chr[13] == 0xff)
+ && ((chr[12] & 0xf0) == 0xf0))
+ {
+ retname[retnamlen] = ',';
+ sprintf(retname+retnamlen+1, "%3.3x",
+ ((chr[12] & 0xf) << 8) | chr[11]);
+ retnamlen += 4;
+ }
+ return retnamlen;
+}
+
+/*
+ * This should _really_ be cleaned up some day..
+ */
+static int do_isofs_readdir(struct inode *inode, struct file *filp,
+ void *dirent, filldir_t filldir,
+ char * tmpname, struct iso_directory_record * tmpde)
+{
+ unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
+ unsigned char bufbits = ISOFS_BUFFER_BITS(inode);
+ unsigned long block, offset, block_saved, offset_saved;
+ unsigned long inode_number = 0; /* Quiet GCC */
+ struct buffer_head *bh = NULL;
+ int len;
+ int map;
+ int first_de = 1;
+ char *p = NULL; /* Quiet GCC */
+ struct iso_directory_record *de;
+ struct isofs_sb_info *sbi = ISOFS_SB(inode->i_sb);
+
+ offset = filp->f_pos & (bufsize - 1);
+ block = filp->f_pos >> bufbits;
+
+ while (filp->f_pos < inode->i_size) {
+ int de_len;
+
+ if (!bh) {
+ bh = isofs_bread(inode, block);
+ if (!bh)
+ return 0;
+ }
+
+ de = (struct iso_directory_record *) (bh->b_data + offset);
+
+ de_len = *(unsigned char *) de;
+
+ /* If the length byte is zero, we should move on to the next
+ CDROM sector. If we are at the end of the directory, we
+ kick out of the while loop. */
+
+ if (de_len == 0) {
+ brelse(bh);
+ bh = NULL;
+ filp->f_pos = (filp->f_pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1);
+ block = filp->f_pos >> bufbits;
+ offset = 0;
+ continue;
+ }
+
+ block_saved = block;
+ offset_saved = offset;
+ offset += de_len;
+
+ /* Make sure we have a full directory entry */
+ if (offset >= bufsize) {
+ int slop = bufsize - offset + de_len;
+ memcpy(tmpde, de, slop);
+ offset &= bufsize - 1;
+ block++;
+ brelse(bh);
+ bh = NULL;
+ if (offset) {
+ bh = isofs_bread(inode, block);
+ if (!bh)
+ return 0;
+ memcpy((void *) tmpde + slop, bh->b_data, offset);
+ }
+ de = tmpde;
+ }
+
+ if (first_de) {
+ isofs_normalize_block_and_offset(de,
+ &block_saved,
+ &offset_saved);
+ inode_number = isofs_get_ino(block_saved,
+ offset_saved,
+ bufbits);
+ }
+
+ if (de->flags[-sbi->s_high_sierra] & 0x80) {
+ first_de = 0;
+ filp->f_pos += de_len;
+ continue;
+ }
+ first_de = 1;
+
+ /* Handle the case of the '.' directory */
+ if (de->name_len[0] == 1 && de->name[0] == 0) {
+ if (filldir(dirent, ".", 1, filp->f_pos, inode->i_ino, DT_DIR) < 0)
+ break;
+ filp->f_pos += de_len;
+ continue;
+ }
+
+ len = 0;
+
+ /* Handle the case of the '..' directory */
+ if (de->name_len[0] == 1 && de->name[0] == 1) {
+ inode_number = parent_ino(filp->f_dentry);
+ if (filldir(dirent, "..", 2, filp->f_pos, inode_number, DT_DIR) < 0)
+ break;
+ filp->f_pos += de_len;
+ continue;
+ }
+
+ /* Handle everything else. Do name translation if there
+ is no Rock Ridge NM field. */
+ if (sbi->s_unhide == 'n') {
+ /* Do not report hidden or associated files */
+ if (de->flags[-sbi->s_high_sierra] & 5) {
+ filp->f_pos += de_len;
+ continue;
+ }
+ }
+
+ map = 1;
+ if (sbi->s_rock) {
+ len = get_rock_ridge_filename(de, tmpname, inode);
+ if (len != 0) { /* may be -1 */
+ p = tmpname;
+ map = 0;
+ }
+ }
+ if (map) {
+#ifdef CONFIG_JOLIET
+ if (sbi->s_joliet_level) {
+ len = get_joliet_filename(de, tmpname, inode);
+ p = tmpname;
+ } else
+#endif
+ if (sbi->s_mapping == 'a') {
+ len = get_acorn_filename(de, tmpname, inode);
+ p = tmpname;
+ } else
+ if (sbi->s_mapping == 'n') {
+ len = isofs_name_translate(de, tmpname, inode);
+ p = tmpname;
+ } else {
+ p = de->name;
+ len = de->name_len[0];
+ }
+ }
+ if (len > 0) {
+ if (filldir(dirent, p, len, filp->f_pos, inode_number, DT_UNKNOWN) < 0)
+ break;
+ }
+ filp->f_pos += de_len;
+
+ continue;
+ }
+ if (bh) brelse(bh);
+ return 0;
+}
+
+/*
+ * Handle allocation of temporary space for name translation and
+ * handling split directory entries.. The real work is done by
+ * "do_isofs_readdir()".
+ */
+static int isofs_readdir(struct file *filp,
+ void *dirent, filldir_t filldir)
+{
+ int result;
+ char * tmpname;
+ struct iso_directory_record * tmpde;
+ struct inode *inode = filp->f_dentry->d_inode;
+
+
+ tmpname = (char *)__get_free_page(GFP_KERNEL);
+ if (tmpname == NULL)
+ return -ENOMEM;
+
+ lock_kernel();
+ tmpde = (struct iso_directory_record *) (tmpname+1024);
+
+ result = do_isofs_readdir(inode, filp, dirent, filldir, tmpname, tmpde);
+
+ free_page((unsigned long) tmpname);
+ unlock_kernel();
+ return result;
+}
diff --git a/fs/isofs/export.c b/fs/isofs/export.c
new file mode 100644
index 000000000000..e4252c960871
--- /dev/null
+++ b/fs/isofs/export.c
@@ -0,0 +1,228 @@
+/*
+ * fs/isofs/export.c
+ *
+ * (C) 2004 Paul Serice - The new inode scheme requires switching
+ * from iget() to iget5_locked() which means
+ * the NFS export operations have to be hand
+ * coded because the default routines rely on
+ * iget().
+ *
+ * The following files are helpful:
+ *
+ * Documentation/filesystems/Exporting
+ * fs/exportfs/expfs.c.
+ */
+
+#include <linux/buffer_head.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/iso_fs.h>
+#include <linux/kernel.h>
+
+static struct dentry *
+isofs_export_iget(struct super_block *sb,
+ unsigned long block,
+ unsigned long offset,
+ __u32 generation)
+{
+ struct inode *inode;
+ struct dentry *result;
+ if (block == 0)
+ return ERR_PTR(-ESTALE);
+ inode = isofs_iget(sb, block, offset);
+ if (inode == NULL)
+ return ERR_PTR(-ENOMEM);
+ if (is_bad_inode(inode)
+ || (generation && inode->i_generation != generation))
+ {
+ iput(inode);
+ return ERR_PTR(-ESTALE);
+ }
+ result = d_alloc_anon(inode);
+ if (!result) {
+ iput(inode);
+ return ERR_PTR(-ENOMEM);
+ }
+ return result;
+}
+
+static struct dentry *
+isofs_export_get_dentry(struct super_block *sb, void *vobjp)
+{
+ __u32 *objp = vobjp;
+ unsigned long block = objp[0];
+ unsigned long offset = objp[1];
+ __u32 generation = objp[2];
+ return isofs_export_iget(sb, block, offset, generation);
+}
+
+/* This function is surprisingly simple. The trick is understanding
+ * that "child" is always a directory. So, to find its parent, you
+ * simply need to find its ".." entry, normalize its block and offset,
+ * and return the underlying inode. See the comments for
+ * isofs_normalize_block_and_offset(). */
+static struct dentry *isofs_export_get_parent(struct dentry *child)
+{
+ unsigned long parent_block = 0;
+ unsigned long parent_offset = 0;
+ struct inode *child_inode = child->d_inode;
+ struct iso_inode_info *e_child_inode = ISOFS_I(child_inode);
+ struct inode *parent_inode = NULL;
+ struct iso_directory_record *de = NULL;
+ struct buffer_head * bh = NULL;
+ struct dentry *rv = NULL;
+
+ /* "child" must always be a directory. */
+ if (!S_ISDIR(child_inode->i_mode)) {
+ printk(KERN_ERR "isofs: isofs_export_get_parent(): "
+ "child is not a directory!\n");
+ rv = ERR_PTR(-EACCES);
+ goto out;
+ }
+
+ /* It is an invariant that the directory offset is zero. If
+ * it is not zero, it means the directory failed to be
+ * normalized for some reason. */
+ if (e_child_inode->i_iget5_offset != 0) {
+ printk(KERN_ERR "isofs: isofs_export_get_parent(): "
+ "child directory not normalized!\n");
+ rv = ERR_PTR(-EACCES);
+ goto out;
+ }
+
+ /* The child inode has been normalized such that its
+ * i_iget5_block value points to the "." entry. Fortunately,
+ * the ".." entry is located in the same block. */
+ parent_block = e_child_inode->i_iget5_block;
+
+ /* Get the block in question. */
+ bh = sb_bread(child_inode->i_sb, parent_block);
+ if (bh == NULL) {
+ rv = ERR_PTR(-EACCES);
+ goto out;
+ }
+
+ /* This is the "." entry. */
+ de = (struct iso_directory_record*)bh->b_data;
+
+ /* The ".." entry is always the second entry. */
+ parent_offset = (unsigned long)isonum_711(de->length);
+ de = (struct iso_directory_record*)(bh->b_data + parent_offset);
+
+ /* Verify it is in fact the ".." entry. */
+ if ((isonum_711(de->name_len) != 1) || (de->name[0] != 1)) {
+ printk(KERN_ERR "isofs: Unable to find the \"..\" "
+ "directory for NFS.\n");
+ rv = ERR_PTR(-EACCES);
+ goto out;
+ }
+
+ /* Normalize */
+ isofs_normalize_block_and_offset(de, &parent_block, &parent_offset);
+
+ /* Get the inode. */
+ parent_inode = isofs_iget(child_inode->i_sb,
+ parent_block,
+ parent_offset);
+ if (parent_inode == NULL) {
+ rv = ERR_PTR(-EACCES);
+ goto out;
+ }
+
+ /* Allocate the dentry. */
+ rv = d_alloc_anon(parent_inode);
+ if (rv == NULL) {
+ rv = ERR_PTR(-ENOMEM);
+ goto out;
+ }
+
+ out:
+ if (bh) {
+ brelse(bh);
+ }
+ return rv;
+}
+
+static int
+isofs_export_encode_fh(struct dentry *dentry,
+ __u32 *fh32,
+ int *max_len,
+ int connectable)
+{
+ struct inode * inode = dentry->d_inode;
+ struct iso_inode_info * ei = ISOFS_I(inode);
+ int len = *max_len;
+ int type = 1;
+ __u16 *fh16 = (__u16*)fh32;
+
+ /*
+ * WARNING: max_len is 5 for NFSv2. Because of this
+ * limitation, we use the lower 16 bits of fh32[1] to hold the
+ * offset of the inode and the upper 16 bits of fh32[1] to
+ * hold the offset of the parent.
+ */
+
+ if (len < 3 || (connectable && len < 5))
+ return 255;
+
+ len = 3;
+ fh32[0] = ei->i_iget5_block;
+ fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
+ fh32[2] = inode->i_generation;
+ if (connectable && !S_ISDIR(inode->i_mode)) {
+ struct inode *parent;
+ struct iso_inode_info *eparent;
+ spin_lock(&dentry->d_lock);
+ parent = dentry->d_parent->d_inode;
+ eparent = ISOFS_I(parent);
+ fh32[3] = eparent->i_iget5_block;
+ fh16[3] = (__u16)eparent->i_iget5_offset; /* fh16 [sic] */
+ fh32[4] = parent->i_generation;
+ spin_unlock(&dentry->d_lock);
+ len = 5;
+ type = 2;
+ }
+ *max_len = len;
+ return type;
+}
+
+
+static struct dentry *
+isofs_export_decode_fh(struct super_block *sb,
+ __u32 *fh32,
+ int fh_len,
+ int fileid_type,
+ int (*acceptable)(void *context, struct dentry *de),
+ void *context)
+{
+ __u16 *fh16 = (__u16*)fh32;
+ __u32 child[3]; /* The child is what triggered all this. */
+ __u32 parent[3]; /* The parent is just along for the ride. */
+
+ if (fh_len < 3 || fileid_type > 2)
+ return NULL;
+
+ child[0] = fh32[0];
+ child[1] = fh16[2]; /* fh16 [sic] */
+ child[2] = fh32[2];
+
+ parent[0] = 0;
+ parent[1] = 0;
+ parent[2] = 0;
+ if (fileid_type == 2) {
+ if (fh_len > 2) parent[0] = fh32[3];
+ parent[1] = fh16[3]; /* fh16 [sic] */
+ if (fh_len > 4) parent[2] = fh32[4];
+ }
+
+ return sb->s_export_op->find_exported_dentry(sb, child, parent,
+ acceptable, context);
+}
+
+
+struct export_operations isofs_export_ops = {
+ .decode_fh = isofs_export_decode_fh,
+ .encode_fh = isofs_export_encode_fh,
+ .get_dentry = isofs_export_get_dentry,
+ .get_parent = isofs_export_get_parent,
+};
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
new file mode 100644
index 000000000000..b9256e65e144
--- /dev/null
+++ b/fs/isofs/inode.c
@@ -0,0 +1,1503 @@
+/*
+ * linux/fs/isofs/inode.c
+ *
+ * (C) 1991 Linus Torvalds - minix filesystem
+ * 1992, 1993, 1994 Eric Youngdale Modified for ISO 9660 filesystem.
+ * 1994 Eberhard Moenkeberg - multi session handling.
+ * 1995 Mark Dobie - allow mounting of some weird VideoCDs and PhotoCDs.
+ * 1997 Gordon Chaffee - Joliet CDs
+ * 1998 Eric Lammerts - ISO 9660 Level 3
+ * 2004 Paul Serice - Inode Support pushed out from 4GB to 128GB
+ * 2004 Paul Serice - NFS Export Operations
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+
+#include <linux/stat.h>
+#include <linux/time.h>
+#include <linux/iso_fs.h>
+#include <linux/kernel.h>
+#include <linux/major.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/cdrom.h>
+#include <linux/init.h>
+#include <linux/nls.h>
+#include <linux/ctype.h>
+#include <linux/smp_lock.h>
+#include <linux/blkdev.h>
+#include <linux/buffer_head.h>
+#include <linux/vfs.h>
+#include <linux/parser.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+
+#include "zisofs.h"
+
+#define BEQUIET
+
+#ifdef LEAK_CHECK
+static int check_malloc;
+static int check_bread;
+#endif
+
+static int isofs_hashi(struct dentry *parent, struct qstr *qstr);
+static int isofs_hash(struct dentry *parent, struct qstr *qstr);
+static int isofs_dentry_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b);
+static int isofs_dentry_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b);
+
+#ifdef CONFIG_JOLIET
+static int isofs_hashi_ms(struct dentry *parent, struct qstr *qstr);
+static int isofs_hash_ms(struct dentry *parent, struct qstr *qstr);
+static int isofs_dentry_cmpi_ms(struct dentry *dentry, struct qstr *a, struct qstr *b);
+static int isofs_dentry_cmp_ms(struct dentry *dentry, struct qstr *a, struct qstr *b);
+#endif
+
+static void isofs_put_super(struct super_block *sb)
+{
+ struct isofs_sb_info *sbi = ISOFS_SB(sb);
+#ifdef CONFIG_JOLIET
+ if (sbi->s_nls_iocharset) {
+ unload_nls(sbi->s_nls_iocharset);
+ sbi->s_nls_iocharset = NULL;
+ }
+#endif
+
+#ifdef LEAK_CHECK
+ printk("Outstanding mallocs:%d, outstanding buffers: %d\n",
+ check_malloc, check_bread);
+#endif
+
+ kfree(sbi);
+ sb->s_fs_info = NULL;
+ return;
+}
+
+static void isofs_read_inode(struct inode *);
+static int isofs_statfs (struct super_block *, struct kstatfs *);
+
+static kmem_cache_t *isofs_inode_cachep;
+
+static struct inode *isofs_alloc_inode(struct super_block *sb)
+{
+ struct iso_inode_info *ei;
+ ei = (struct iso_inode_info *)kmem_cache_alloc(isofs_inode_cachep, SLAB_KERNEL);
+ if (!ei)
+ return NULL;
+ return &ei->vfs_inode;
+}
+
+static void isofs_destroy_inode(struct inode *inode)
+{
+ kmem_cache_free(isofs_inode_cachep, ISOFS_I(inode));
+}
+
+static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+{
+ struct iso_inode_info *ei = (struct iso_inode_info *) foo;
+
+ if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
+ SLAB_CTOR_CONSTRUCTOR)
+ inode_init_once(&ei->vfs_inode);
+}
+
+static int init_inodecache(void)
+{
+ isofs_inode_cachep = kmem_cache_create("isofs_inode_cache",
+ sizeof(struct iso_inode_info),
+ 0, SLAB_RECLAIM_ACCOUNT,
+ init_once, NULL);
+ if (isofs_inode_cachep == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
+static void destroy_inodecache(void)
+{
+ if (kmem_cache_destroy(isofs_inode_cachep))
+ printk(KERN_INFO "iso_inode_cache: not all structures were freed\n");
+}
+
+static int isofs_remount(struct super_block *sb, int *flags, char *data)
+{
+ /* we probably want a lot more here */
+ *flags |= MS_RDONLY;
+ return 0;
+}
+
+static struct super_operations isofs_sops = {
+ .alloc_inode = isofs_alloc_inode,
+ .destroy_inode = isofs_destroy_inode,
+ .read_inode = isofs_read_inode,
+ .put_super = isofs_put_super,
+ .statfs = isofs_statfs,
+ .remount_fs = isofs_remount,
+};
+
+
+static struct dentry_operations isofs_dentry_ops[] = {
+ {
+ .d_hash = isofs_hash,
+ .d_compare = isofs_dentry_cmp,
+ },
+ {
+ .d_hash = isofs_hashi,
+ .d_compare = isofs_dentry_cmpi,
+ },
+#ifdef CONFIG_JOLIET
+ {
+ .d_hash = isofs_hash_ms,
+ .d_compare = isofs_dentry_cmp_ms,
+ },
+ {
+ .d_hash = isofs_hashi_ms,
+ .d_compare = isofs_dentry_cmpi_ms,
+ }
+#endif
+};
+
+struct iso9660_options{
+ char map;
+ char rock;
+ char joliet;
+ char cruft;
+ char unhide;
+ char nocompress;
+ unsigned char check;
+ unsigned int blocksize;
+ mode_t mode;
<