From 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 16 Apr 2005 15:20:36 -0700 Subject: 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! --- fs/isofs/Makefile | 10 + fs/isofs/compress.c | 359 ++++++++++++ fs/isofs/dir.c | 280 ++++++++++ fs/isofs/export.c | 228 ++++++++ fs/isofs/inode.c | 1503 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/isofs/joliet.c | 103 ++++ fs/isofs/namei.c | 201 +++++++ fs/isofs/rock.c | 565 +++++++++++++++++++ fs/isofs/rock.h | 119 ++++ fs/isofs/util.c | 83 +++ fs/isofs/zisofs.h | 21 + 11 files changed, 3472 insertions(+) create mode 100644 fs/isofs/Makefile create mode 100644 fs/isofs/compress.c create mode 100644 fs/isofs/dir.c create mode 100644 fs/isofs/export.c create mode 100644 fs/isofs/inode.c create mode 100644 fs/isofs/joliet.c create mode 100644 fs/isofs/namei.c create mode 100644 fs/isofs/rock.c create mode 100644 fs/isofs/rock.h create mode 100644 fs/isofs/util.c create mode 100644 fs/isofs/zisofs.h (limited to 'fs/isofs') 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +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 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 +#include +#include +#include +#include + +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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; + gid_t gid; + uid_t uid; + char *iocharset; + unsigned char utf8; + /* LVE */ + s32 session; + s32 sbsector; +}; + +/* + * Compute the hash for the isofs name corresponding to the dentry. + */ +static int +isofs_hash_common(struct dentry *dentry, struct qstr *qstr, int ms) +{ + const char *name; + int len; + + len = qstr->len; + name = qstr->name; + if (ms) { + while (len && name[len-1] == '.') + len--; + } + + qstr->hash = full_name_hash(name, len); + + return 0; +} + +/* + * Compute the hash for the isofs name corresponding to the dentry. + */ +static int +isofs_hashi_common(struct dentry *dentry, struct qstr *qstr, int ms) +{ + const char *name; + int len; + char c; + unsigned long hash; + + len = qstr->len; + name = qstr->name; + if (ms) { + while (len && name[len-1] == '.') + len--; + } + + hash = init_name_hash(); + while (len--) { + c = tolower(*name++); + hash = partial_name_hash(tolower(c), hash); + } + qstr->hash = end_name_hash(hash); + + return 0; +} + +/* + * Case insensitive compare of two isofs names. + */ +static int +isofs_dentry_cmpi_common(struct dentry *dentry,struct qstr *a,struct qstr *b,int ms) +{ + int alen, blen; + + /* A filename cannot end in '.' or we treat it like it has none */ + alen = a->len; + blen = b->len; + if (ms) { + while (alen && a->name[alen-1] == '.') + alen--; + while (blen && b->name[blen-1] == '.') + blen--; + } + if (alen == blen) { + if (strnicmp(a->name, b->name, alen) == 0) + return 0; + } + return 1; +} + +/* + * Case sensitive compare of two isofs names. + */ +static int +isofs_dentry_cmp_common(struct dentry *dentry,struct qstr *a,struct qstr *b,int ms) +{ + int alen, blen; + + /* A filename cannot end in '.' or we treat it like it has none */ + alen = a->len; + blen = b->len; + if (ms) { + while (alen && a->name[alen-1] == '.') + alen--; + while (blen && b->name[blen-1] == '.') + blen--; + } + if (alen == blen) { + if (strncmp(a->name, b->name, alen) == 0) + return 0; + } + return 1; +} + +static int +isofs_hash(struct dentry *dentry, struct qstr *qstr) +{ + return isofs_hash_common(dentry, qstr, 0); +} + +static int +isofs_hashi(struct dentry *dentry, struct qstr *qstr) +{ + return isofs_hashi_common(dentry, qstr, 0); +} + +static int +isofs_dentry_cmp(struct dentry *dentry,struct qstr *a,struct qstr *b) +{ + return isofs_dentry_cmp_common(dentry, a, b, 0); +} + +static int +isofs_dentry_cmpi(struct dentry *dentry,struct qstr *a,struct qstr *b) +{ + return isofs_dentry_cmpi_common(dentry, a, b, 0); +} + +#ifdef CONFIG_JOLIET +static int +isofs_hash_ms(struct dentry *dentry, struct qstr *qstr) +{ + return isofs_hash_common(dentry, qstr, 1); +} + +static int +isofs_hashi_ms(struct dentry *dentry, struct qstr *qstr) +{ + return isofs_hashi_common(dentry, qstr, 1); +} + +static int +isofs_dentry_cmp_ms(struct dentry *dentry,struct qstr *a,struct qstr *b) +{ + return isofs_dentry_cmp_common(dentry, a, b, 1); +} + +static int +isofs_dentry_cmpi_ms(struct dentry *dentry,struct qstr *a,struct qstr *b) +{ + return isofs_dentry_cmpi_common(dentry, a, b, 1); +} +#endif + +enum { + Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore, + Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet, + Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err, + Opt_nocompress, +}; + +static match_table_t tokens = { + {Opt_norock, "norock"}, + {Opt_nojoliet, "nojoliet"}, + {Opt_unhide, "unhide"}, + {Opt_cruft, "cruft"}, + {Opt_utf8, "utf8"}, + {Opt_iocharset, "iocharset=%s"}, + {Opt_map_a, "map=acorn"}, + {Opt_map_a, "map=a"}, + {Opt_map_n, "map=normal"}, + {Opt_map_n, "map=n"}, + {Opt_map_o, "map=off"}, + {Opt_map_o, "map=o"}, + {Opt_session, "session=%u"}, + {Opt_sb, "sbsector=%u"}, + {Opt_check_r, "check=relaxed"}, + {Opt_check_r, "check=r"}, + {Opt_check_s, "check=strict"}, + {Opt_check_s, "check=s"}, + {Opt_uid, "uid=%u"}, + {Opt_gid, "gid=%u"}, + {Opt_mode, "mode=%u"}, + {Opt_block, "block=%u"}, + {Opt_ignore, "conv=binary"}, + {Opt_ignore, "conv=b"}, + {Opt_ignore, "conv=text"}, + {Opt_ignore, "conv=t"}, + {Opt_ignore, "conv=mtext"}, + {Opt_ignore, "conv=m"}, + {Opt_ignore, "conv=auto"}, + {Opt_ignore, "conv=a"}, + {Opt_nocompress, "nocompress"}, + {Opt_err, NULL} +}; + +static int parse_options(char *options, struct iso9660_options * popt) +{ + char *p; + int option; + + popt->map = 'n'; + popt->rock = 'y'; + popt->joliet = 'y'; + popt->cruft = 'n'; + popt->unhide = 'n'; + popt->check = 'u'; /* unset */ + popt->nocompress = 0; + popt->blocksize = 1024; + popt->mode = S_IRUGO | S_IXUGO; /* r-x for all. The disc could + be shared with DOS machines so + virtually anything could be + a valid executable. */ + popt->gid = 0; + popt->uid = 0; + popt->iocharset = NULL; + popt->utf8 = 0; + popt->session=-1; + popt->sbsector=-1; + if (!options) + return 1; + + while ((p = strsep(&options, ",")) != NULL) { + int token; + substring_t args[MAX_OPT_ARGS]; + unsigned n; + + if (!*p) + continue; + + token = match_token(p, tokens, args); + switch (token) { + case Opt_norock: + popt->rock = 'n'; + break; + case Opt_nojoliet: + popt->joliet = 'n'; + break; + case Opt_unhide: + popt->unhide = 'y'; + break; + case Opt_cruft: + popt->cruft = 'y'; + break; + case Opt_utf8: + popt->utf8 = 1; + break; +#ifdef CONFIG_JOLIET + case Opt_iocharset: + popt->iocharset = match_strdup(&args[0]); + break; +#endif + case Opt_map_a: + popt->map = 'a'; + break; + case Opt_map_o: + popt->map = 'o'; + break; + case Opt_map_n: + popt->map = 'n'; + break; + case Opt_session: + if (match_int(&args[0], &option)) + return 0; + n = option; + if (n > 99) + return 0; + popt->session = n + 1; + break; + case Opt_sb: + if (match_int(&args[0], &option)) + return 0; + popt->sbsector = option; + break; + case Opt_check_r: + popt->check = 'r'; + break; + case Opt_check_s: + popt->check = 's'; + break; + case Opt_ignore: + break; + case Opt_uid: + if (match_int(&args[0], &option)) + return 0; + popt->uid = option; + break; + case Opt_gid: + if (match_int(&args[0], &option)) + return 0; + popt->gid = option; + break; + case Opt_mode: + if (match_int(&args[0], &option)) + return 0; + popt->mode = option; + break; + case Opt_block: + if (match_int(&args[0], &option)) + return 0; + n = option; + if (n != 512 && n != 1024 && n != 2048) + return 0; + popt->blocksize = n; + break; + case Opt_nocompress: + popt->nocompress = 1; + break; + default: + return 0; + } + } + return 1; +} + +/* + * look if the driver can tell the multi session redirection value + * + * don't change this if you don't know what you do, please! + * Multisession is legal only with XA disks. + * A non-XA disk with more than one volume descriptor may do it right, but + * usually is written in a nowhere standardized "multi-partition" manner. + * Multisession uses absolute addressing (solely the first frame of the whole + * track is #0), multi-partition uses relative addressing (each first frame of + * each track is #0), and a track is not a session. + * + * A broken CDwriter software or drive firmware does not set new standards, + * at least not if conflicting with the existing ones. + * + * emoenke@gwdg.de + */ +#define WE_OBEY_THE_WRITTEN_STANDARDS 1 + +static unsigned int isofs_get_last_session(struct super_block *sb,s32 session ) +{ + struct cdrom_multisession ms_info; + unsigned int vol_desc_start; + struct block_device *bdev = sb->s_bdev; + int i; + + vol_desc_start=0; + ms_info.addr_format=CDROM_LBA; + if(session >= 0 && session <= 99) { + struct cdrom_tocentry Te; + Te.cdte_track=session; + Te.cdte_format=CDROM_LBA; + i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te); + if (!i) { + printk(KERN_DEBUG "Session %d start %d type %d\n", + session, Te.cdte_addr.lba, + Te.cdte_ctrl&CDROM_DATA_TRACK); + if ((Te.cdte_ctrl&CDROM_DATA_TRACK) == 4) + return Te.cdte_addr.lba; + } + + printk(KERN_ERR "Invalid session number or type of track\n"); + } + i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info); + if(session > 0) printk(KERN_ERR "Invalid session number\n"); +#if 0 + printk("isofs.inode: CDROMMULTISESSION: rc=%d\n",i); + if (i==0) { + printk("isofs.inode: XA disk: %s\n",ms_info.xa_flag?"yes":"no"); + printk("isofs.inode: vol_desc_start = %d\n", ms_info.addr.lba); + } +#endif + if (i==0) +#if WE_OBEY_THE_WRITTEN_STANDARDS + if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */ +#endif + vol_desc_start=ms_info.addr.lba; + return vol_desc_start; +} + +/* + * Initialize the superblock and read the root inode. + * + * Note: a check_disk_change() has been done immediately prior + * to this call, so we don't need to check again. + */ +static int isofs_fill_super(struct super_block *s, void *data, int silent) +{ + struct buffer_head * bh = NULL, *pri_bh = NULL; + struct hs_primary_descriptor * h_pri = NULL; + struct iso_primary_descriptor * pri = NULL; + struct iso_supplementary_descriptor *sec = NULL; + struct iso_directory_record * rootp; + int joliet_level = 0; + int iso_blknum, block; + int orig_zonesize; + int table; + unsigned int vol_desc_start; + unsigned long first_data_zone; + struct inode * inode; + struct iso9660_options opt; + struct isofs_sb_info * sbi; + + sbi = kmalloc(sizeof(struct isofs_sb_info), GFP_KERNEL); + if (!sbi) + return -ENOMEM; + s->s_fs_info = sbi; + memset(sbi, 0, sizeof(struct isofs_sb_info)); + + if (!parse_options((char *) data, &opt)) + goto out_freesbi; + + /* + * First of all, get the hardware blocksize for this device. + * If we don't know what it is, or the hardware blocksize is + * larger than the blocksize the user specified, then use + * that value. + */ + /* + * What if bugger tells us to go beyond page size? + */ + opt.blocksize = sb_min_blocksize(s, opt.blocksize); + + sbi->s_high_sierra = 0; /* default is iso9660 */ + + vol_desc_start = (opt.sbsector != -1) ? + opt.sbsector : isofs_get_last_session(s,opt.session); + + for (iso_blknum = vol_desc_start+16; + iso_blknum < vol_desc_start+100; iso_blknum++) + { + struct hs_volume_descriptor * hdp; + struct iso_volume_descriptor * vdp; + + block = iso_blknum << (ISOFS_BLOCK_BITS - s->s_blocksize_bits); + if (!(bh = sb_bread(s, block))) + goto out_no_read; + + vdp = (struct iso_volume_descriptor *)bh->b_data; + hdp = (struct hs_volume_descriptor *)bh->b_data; + + /* Due to the overlapping physical location of the descriptors, + * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure + * proper identification in this case, we first check for ISO. + */ + if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) { + if (isonum_711 (vdp->type) == ISO_VD_END) + break; + if (isonum_711 (vdp->type) == ISO_VD_PRIMARY) { + if (pri == NULL) { + pri = (struct iso_primary_descriptor *)vdp; + /* Save the buffer in case we need it ... */ + pri_bh = bh; + bh = NULL; + } + } +#ifdef CONFIG_JOLIET + else if (isonum_711 (vdp->type) == ISO_VD_SUPPLEMENTARY) { + sec = (struct iso_supplementary_descriptor *)vdp; + if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) { + if (opt.joliet == 'y') { + if (sec->escape[2] == 0x40) { + joliet_level = 1; + } else if (sec->escape[2] == 0x43) { + joliet_level = 2; + } else if (sec->escape[2] == 0x45) { + joliet_level = 3; + } + printk(KERN_DEBUG"ISO 9660 Extensions: Microsoft Joliet Level %d\n", + joliet_level); + } + goto root_found; + } else { + /* Unknown supplementary volume descriptor */ + sec = NULL; + } + } +#endif + } else { + if (strncmp (hdp->id, HS_STANDARD_ID, sizeof hdp->id) == 0) { + if (isonum_711 (hdp->type) != ISO_VD_PRIMARY) + goto out_freebh; + + sbi->s_high_sierra = 1; + opt.rock = 'n'; + h_pri = (struct hs_primary_descriptor *)vdp; + goto root_found; + } + } + + /* Just skip any volume descriptors we don't recognize */ + + brelse(bh); + bh = NULL; + } + /* + * If we fall through, either no volume descriptor was found, + * or else we passed a primary descriptor looking for others. + */ + if (!pri) + goto out_unknown_format; + brelse(bh); + bh = pri_bh; + pri_bh = NULL; + +root_found: + + if (joliet_level && (pri == NULL || opt.rock == 'n')) { + /* This is the case of Joliet with the norock mount flag. + * A disc with both Joliet and Rock Ridge is handled later + */ + pri = (struct iso_primary_descriptor *) sec; + } + + if(sbi->s_high_sierra){ + rootp = (struct iso_directory_record *) h_pri->root_directory_record; + sbi->s_nzones = isonum_733 (h_pri->volume_space_size); + sbi->s_log_zone_size = isonum_723 (h_pri->logical_block_size); + sbi->s_max_size = isonum_733(h_pri->volume_space_size); + } else { + if (!pri) + goto out_freebh; + rootp = (struct iso_directory_record *) pri->root_directory_record; + sbi->s_nzones = isonum_733 (pri->volume_space_size); + sbi->s_log_zone_size = isonum_723 (pri->logical_block_size); + sbi->s_max_size = isonum_733(pri->volume_space_size); + } + + sbi->s_ninodes = 0; /* No way to figure this out easily */ + + orig_zonesize = sbi->s_log_zone_size; + /* + * If the zone size is smaller than the hardware sector size, + * this is a fatal error. This would occur if the disc drive + * had sectors that were 2048 bytes, but the filesystem had + * blocks that were 512 bytes (which should only very rarely + * happen.) + */ + if(orig_zonesize < opt.blocksize) + goto out_bad_size; + + /* RDE: convert log zone size to bit shift */ + switch (sbi->s_log_zone_size) + { case 512: sbi->s_log_zone_size = 9; break; + case 1024: sbi->s_log_zone_size = 10; break; + case 2048: sbi->s_log_zone_size = 11; break; + + default: + goto out_bad_zone_size; + } + + s->s_magic = ISOFS_SUPER_MAGIC; + s->s_maxbytes = 0xffffffff; /* We can handle files up to 4 GB */ + + /* The CDROM is read-only, has no nodes (devices) on it, and since + all of the files appear to be owned by root, we really do not want + to allow suid. (suid or devices will not show up unless we have + Rock Ridge extensions) */ + + s->s_flags |= MS_RDONLY /* | MS_NODEV | MS_NOSUID */; + + /* Set this for reference. Its not currently used except on write + which we don't have .. */ + + first_data_zone = isonum_733 (rootp->extent) + + isonum_711 (rootp->ext_attr_length); + sbi->s_firstdatazone = first_data_zone; +#ifndef BEQUIET + printk(KERN_DEBUG "Max size:%ld Log zone size:%ld\n", + sbi->s_max_size, + 1UL << sbi->s_log_zone_size); + printk(KERN_DEBUG "First datazone:%ld\n", sbi->s_firstdatazone); + if(sbi->s_high_sierra) + printk(KERN_DEBUG "Disc in High Sierra format.\n"); +#endif + + /* + * If the Joliet level is set, we _may_ decide to use the + * secondary descriptor, but can't be sure until after we + * read the root inode. But before reading the root inode + * we may need to change the device blocksize, and would + * rather release the old buffer first. So, we cache the + * first_data_zone value from the secondary descriptor. + */ + if (joliet_level) { + pri = (struct iso_primary_descriptor *) sec; + rootp = (struct iso_directory_record *) + pri->root_directory_record; + first_data_zone = isonum_733 (rootp->extent) + + isonum_711 (rootp->ext_attr_length); + } + + /* + * We're all done using the volume descriptor, and may need + * to change the device blocksize, so release the buffer now. + */ + brelse(pri_bh); + brelse(bh); + + /* + * Force the blocksize to 512 for 512 byte sectors. The file + * read primitives really get it wrong in a bad way if we don't + * do this. + * + * Note - we should never be setting the blocksize to something + * less than the hardware sector size for the device. If we + * do, we would end up having to read larger buffers and split + * out portions to satisfy requests. + * + * Note2- the idea here is that we want to deal with the optimal + * zonesize in the filesystem. If we have it set to something less, + * then we have horrible problems with trying to piece together + * bits of adjacent blocks in order to properly read directory + * entries. By forcing the blocksize in this way, we ensure + * that we will never be required to do this. + */ + sb_set_blocksize(s, orig_zonesize); + + sbi->s_nls_iocharset = NULL; + +#ifdef CONFIG_JOLIET + if (joliet_level && opt.utf8 == 0) { + char * p = opt.iocharset ? opt.iocharset : CONFIG_NLS_DEFAULT; + sbi->s_nls_iocharset = load_nls(p); + if (! sbi->s_nls_iocharset) { + /* Fail only if explicit charset specified */ + if (opt.iocharset) + goto out_freesbi; + sbi->s_nls_iocharset = load_nls_default(); + } + } +#endif + s->s_op = &isofs_sops; + s->s_export_op = &isofs_export_ops; + sbi->s_mapping = opt.map; + sbi->s_rock = (opt.rock == 'y' ? 2 : 0); + sbi->s_rock_offset = -1; /* initial offset, will guess until SP is found*/ + sbi->s_cruft = opt.cruft; + sbi->s_unhide = opt.unhide; + sbi->s_uid = opt.uid; + sbi->s_gid = opt.gid; + sbi->s_utf8 = opt.utf8; + sbi->s_nocompress = opt.nocompress; + /* + * It would be incredibly stupid to allow people to mark every file + * on the disk as suid, so we merely allow them to set the default + * permissions. + */ + sbi->s_mode = opt.mode & 0777; + + /* + * Read the root inode, which _may_ result in changing + * the s_rock flag. Once we have the final s_rock value, + * we then decide whether to use the Joliet descriptor. + */ + inode = isofs_iget(s, sbi->s_firstdatazone, 0); + + /* + * If this disk has both Rock Ridge and Joliet on it, then we + * want to use Rock Ridge by default. This can be overridden + * by using the norock mount option. There is still one other + * possibility that is not taken into account: a Rock Ridge + * CD with Unicode names. Until someone sees such a beast, it + * will not be supported. + */ + if (sbi->s_rock == 1) { + joliet_level = 0; + } else if (joliet_level) { + sbi->s_rock = 0; + if (sbi->s_firstdatazone != first_data_zone) { + sbi->s_firstdatazone = first_data_zone; + printk(KERN_DEBUG + "ISOFS: changing to secondary root\n"); + iput(inode); + inode = isofs_iget(s, sbi->s_firstdatazone, 0); + } + } + + if (opt.check == 'u') { + /* Only Joliet is case insensitive by default */ + if (joliet_level) opt.check = 'r'; + else opt.check = 's'; + } + sbi->s_joliet_level = joliet_level; + + /* check the root inode */ + if (!inode) + goto out_no_root; + if (!inode->i_op) + goto out_bad_root; + /* get the root dentry */ + s->s_root = d_alloc_root(inode); + if (!(s->s_root)) + goto out_no_root; + + table = 0; + if (joliet_level) table += 2; + if (opt.check == 'r') table++; + s->s_root->d_op = &isofs_dentry_ops[table]; + + if (opt.iocharset) + kfree(opt.iocharset); + + return 0; + + /* + * Display error messages and free resources. + */ +out_bad_root: + printk(KERN_WARNING "isofs_fill_super: root inode not initialized\n"); + goto out_iput; +out_no_root: + printk(KERN_WARNING "isofs_fill_super: get root inode failed\n"); +out_iput: + iput(inode); +#ifdef CONFIG_JOLIET + if (sbi->s_nls_iocharset) + unload_nls(sbi->s_nls_iocharset); +#endif + goto out_freesbi; +out_no_read: + printk(KERN_WARNING "isofs_fill_super: " + "bread failed, dev=%s, iso_blknum=%d, block=%d\n", + s->s_id, iso_blknum, block); + goto out_freesbi; +out_bad_zone_size: + printk(KERN_WARNING "Bad logical zone size %ld\n", + sbi->s_log_zone_size); + goto out_freebh; +out_bad_size: + printk(KERN_WARNING "Logical zone size(%d) < hardware blocksize(%u)\n", + orig_zonesize, opt.blocksize); + goto out_freebh; +out_unknown_format: + if (!silent) + printk(KERN_WARNING "Unable to identify CD-ROM format.\n"); + +out_freebh: + brelse(bh); +out_freesbi: + if (opt.iocharset) + kfree(opt.iocharset); + kfree(sbi); + s->s_fs_info = NULL; + return -EINVAL; +} + +static int isofs_statfs (struct super_block *sb, struct kstatfs *buf) +{ + buf->f_type = ISOFS_SUPER_MAGIC; + buf->f_bsize = sb->s_blocksize; + buf->f_blocks = (ISOFS_SB(sb)->s_nzones + << (ISOFS_SB(sb)->s_log_zone_size - sb->s_blocksize_bits)); + buf->f_bfree = 0; + buf->f_bavail = 0; + buf->f_files = ISOFS_SB(sb)->s_ninodes; + buf->f_ffree = 0; + buf->f_namelen = NAME_MAX; + return 0; +} + +/* + * Get a set of blocks; filling in buffer_heads if already allocated + * or getblk() if they are not. Returns the number of blocks inserted + * (0 == error.) + */ +int isofs_get_blocks(struct inode *inode, sector_t iblock_s, + struct buffer_head **bh, unsigned long nblocks) +{ + unsigned long b_off; + unsigned offset, sect_size; + unsigned int firstext; + unsigned long nextblk, nextoff; + long iblock = (long)iblock_s; + int section, rv; + struct iso_inode_info *ei = ISOFS_I(inode); + + lock_kernel(); + + rv = 0; + if (iblock < 0 || iblock != iblock_s) { + printk("isofs_get_blocks: block number too large\n"); + goto abort; + } + + b_off = iblock; + + offset = 0; + firstext = ei->i_first_extent; + sect_size = ei->i_section_size >> ISOFS_BUFFER_BITS(inode); + nextblk = ei->i_next_section_block; + nextoff = ei->i_next_section_offset; + section = 0; + + while ( nblocks ) { + /* If we are *way* beyond the end of the file, print a message. + * Access beyond the end of the file up to the next page boundary + * is normal, however because of the way the page cache works. + * In this case, we just return 0 so that we can properly fill + * the page with useless information without generating any + * I/O errors. + */ + if (b_off > ((inode->i_size + PAGE_CACHE_SIZE - 1) >> ISOFS_BUFFER_BITS(inode))) { + printk("isofs_get_blocks: block >= EOF (%ld, %ld)\n", + iblock, (unsigned long) inode->i_size); + goto abort; + } + + if (nextblk) { + while (b_off >= (offset + sect_size)) { + struct inode *ninode; + + offset += sect_size; + if (nextblk == 0) + goto abort; + ninode = isofs_iget(inode->i_sb, nextblk, nextoff); + if (!ninode) + goto abort; + firstext = ISOFS_I(ninode)->i_first_extent; + sect_size = ISOFS_I(ninode)->i_section_size >> ISOFS_BUFFER_BITS(ninode); + nextblk = ISOFS_I(ninode)->i_next_section_block; + nextoff = ISOFS_I(ninode)->i_next_section_offset; + iput(ninode); + + if (++section > 100) { + printk("isofs_get_blocks: More than 100 file sections ?!?, aborting...\n"); + printk("isofs_get_blocks: block=%ld firstext=%u sect_size=%u " + "nextblk=%lu nextoff=%lu\n", + iblock, firstext, (unsigned) sect_size, + nextblk, nextoff); + goto abort; + } + } + } + + if ( *bh ) { + map_bh(*bh, inode->i_sb, firstext + b_off - offset); + } else { + *bh = sb_getblk(inode->i_sb, firstext+b_off-offset); + if ( !*bh ) + goto abort; + } + bh++; /* Next buffer head */ + b_off++; /* Next buffer offset */ + nblocks--; + rv++; + } + + +abort: + unlock_kernel(); + return rv; +} + +/* + * Used by the standard interfaces. + */ +static int isofs_get_block(struct inode *inode, sector_t iblock, + struct buffer_head *bh_result, int create) +{ + if ( create ) { + printk("isofs_get_block: Kernel tries to allocate a block\n"); + return -EROFS; + } + + return isofs_get_blocks(inode, iblock, &bh_result, 1) ? 0 : -EIO; +} + +static int isofs_bmap(struct inode *inode, sector_t block) +{ + struct buffer_head dummy; + int error; + + dummy.b_state = 0; + dummy.b_blocknr = -1000; + error = isofs_get_block(inode, block, &dummy, 0); + if (!error) + return dummy.b_blocknr; + return 0; +} + +struct buffer_head *isofs_bread(struct inode *inode, sector_t block) +{ + sector_t blknr = isofs_bmap(inode, block); + if (!blknr) + return NULL; + return sb_bread(inode->i_sb, blknr); +} + +static int isofs_readpage(struct file *file, struct page *page) +{ + return block_read_full_page(page,isofs_get_block); +} + +static sector_t _isofs_bmap(struct address_space *mapping, sector_t block) +{ + return generic_block_bmap(mapping,block,isofs_get_block); +} + +static struct address_space_operations isofs_aops = { + .readpage = isofs_readpage, + .sync_page = block_sync_page, + .bmap = _isofs_bmap +}; + +static inline void test_and_set_uid(uid_t *p, uid_t value) +{ + if(value) { + *p = value; + } +} + +static inline void test_and_set_gid(gid_t *p, gid_t value) +{ + if(value) { + *p = value; + } +} + +static int isofs_read_level3_size(struct inode * inode) +{ + unsigned long bufsize = ISOFS_BUFFER_SIZE(inode); + int high_sierra = ISOFS_SB(inode->i_sb)->s_high_sierra; + struct buffer_head * bh = NULL; + unsigned long block, offset, block_saved, offset_saved; + int i = 0; + int more_entries = 0; + struct iso_directory_record * tmpde = NULL; + struct iso_inode_info *ei = ISOFS_I(inode); + + inode->i_size = 0; + + /* The first 16 blocks are reserved as the System Area. Thus, + * no inodes can appear in block 0. We use this to flag that + * this is the last section. */ + ei->i_next_section_block = 0; + ei->i_next_section_offset = 0; + + block = ei->i_iget5_block; + offset = ei->i_iget5_offset; + + do { + struct iso_directory_record * de; + unsigned int de_len; + + if (!bh) { + bh = sb_bread(inode->i_sb, block); + if (!bh) + goto out_noread; + } + de = (struct iso_directory_record *) (bh->b_data + offset); + de_len = *(unsigned char *) de; + + if (de_len == 0) { + brelse(bh); + bh = NULL; + ++block; + 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; + if (!tmpde) { + tmpde = kmalloc(256, GFP_KERNEL); + if (!tmpde) + goto out_nomem; + } + memcpy(tmpde, de, slop); + offset &= bufsize - 1; + block++; + brelse(bh); + bh = NULL; + if (offset) { + bh = sb_bread(inode->i_sb, block); + if (!bh) + goto out_noread; + memcpy((void *) tmpde + slop, bh->b_data, offset); + } + de = tmpde; + } + + inode->i_size += isonum_733(de->size); + if (i == 1) { + ei->i_next_section_block = block_saved; + ei->i_next_section_offset = offset_saved; + } + + more_entries = de->flags[-high_sierra] & 0x80; + + i++; + if(i > 100) + goto out_toomany; + } while(more_entries); +out: + if (tmpde) + kfree(tmpde); + if (bh) + brelse(bh); + return 0; + +out_nomem: + if (bh) + brelse(bh); + return -ENOMEM; + +out_noread: + printk(KERN_INFO "ISOFS: unable to read i-node block %lu\n", block); + if (tmpde) + kfree(tmpde); + return -EIO; + +out_toomany: + printk(KERN_INFO "isofs_read_level3_size: " + "More than 100 file sections ?!?, aborting...\n" + "isofs_read_level3_size: inode=%lu\n", + inode->i_ino); + goto out; +} + +static void isofs_read_inode(struct inode * inode) +{ + struct super_block *sb = inode->i_sb; + struct isofs_sb_info *sbi = ISOFS_SB(sb); + unsigned long bufsize = ISOFS_BUFFER_SIZE(inode); + unsigned long block; + int high_sierra = sbi->s_high_sierra; + struct buffer_head * bh = NULL; + struct iso_directory_record * de; + struct iso_directory_record * tmpde = NULL; + unsigned int de_len; + unsigned long offset; + struct iso_inode_info *ei = ISOFS_I(inode); + + block = ei->i_iget5_block; + bh = sb_bread(inode->i_sb, block); + if (!bh) + goto out_badread; + + offset = ei->i_iget5_offset; + + de = (struct iso_directory_record *) (bh->b_data + offset); + de_len = *(unsigned char *) de; + + if (offset + de_len > bufsize) { + int frag1 = bufsize - offset; + + tmpde = kmalloc(de_len, GFP_KERNEL); + if (tmpde == NULL) { + printk(KERN_INFO "isofs_read_inode: out of memory\n"); + goto fail; + } + memcpy(tmpde, bh->b_data + offset, frag1); + brelse(bh); + bh = sb_bread(inode->i_sb, ++block); + if (!bh) + goto out_badread; + memcpy((char *)tmpde+frag1, bh->b_data, de_len - frag1); + de = tmpde; + } + + inode->i_ino = isofs_get_ino(ei->i_iget5_block, + ei->i_iget5_offset, + ISOFS_BUFFER_BITS(inode)); + + /* Assume it is a normal-format file unless told otherwise */ + ei->i_file_format = isofs_file_normal; + + if (de->flags[-high_sierra] & 2) { + inode->i_mode = S_IRUGO | S_IXUGO | S_IFDIR; + inode->i_nlink = 1; /* Set to 1. We know there are 2, but + the find utility tries to optimize + if it is 2, and it screws up. It is + easier to give 1 which tells find to + do it the hard way. */ + } else { + /* Everybody gets to read the file. */ + inode->i_mode = sbi->s_mode; + inode->i_nlink = 1; + inode->i_mode |= S_IFREG; + } + inode->i_uid = sbi->s_uid; + inode->i_gid = sbi->s_gid; + inode->i_blocks = inode->i_blksize = 0; + + ei->i_format_parm[0] = 0; + ei->i_format_parm[1] = 0; + ei->i_format_parm[2] = 0; + + ei->i_section_size = isonum_733 (de->size); + if(de->flags[-high_sierra] & 0x80) { + if(isofs_read_level3_size(inode)) goto fail; + } else { + ei->i_next_section_block = 0; + ei->i_next_section_offset = 0; + inode->i_size = isonum_733 (de->size); + } + + /* + * Some dipshit decided to store some other bit of information + * in the high byte of the file length. Truncate size in case + * this CDROM was mounted with the cruft option. + */ + + if (sbi->s_cruft == 'y') + inode->i_size &= 0x00ffffff; + + if (de->interleave[0]) { + printk("Interleaved files not (yet) supported.\n"); + inode->i_size = 0; + } + + /* I have no idea what file_unit_size is used for, so + we will flag it for now */ + if (de->file_unit_size[0] != 0) { + printk("File unit size != 0 for ISO file (%ld).\n", + inode->i_ino); + } + + /* I have no idea what other flag bits are used for, so + we will flag it for now */ +#ifdef DEBUG + if((de->flags[-high_sierra] & ~2)!= 0){ + printk("Unusual flag settings for ISO file (%ld %x).\n", + inode->i_ino, de->flags[-high_sierra]); + } +#endif + + inode->i_mtime.tv_sec = + inode->i_atime.tv_sec = + inode->i_ctime.tv_sec = iso_date(de->date, high_sierra); + inode->i_mtime.tv_nsec = + inode->i_atime.tv_nsec = + inode->i_ctime.tv_nsec = 0; + + ei->i_first_extent = (isonum_733 (de->extent) + + isonum_711 (de->ext_attr_length)); + + /* Set the number of blocks for stat() - should be done before RR */ + inode->i_blksize = PAGE_CACHE_SIZE; /* For stat() only */ + inode->i_blocks = (inode->i_size + 511) >> 9; + + /* + * Now test for possible Rock Ridge extensions which will override + * some of these numbers in the inode structure. + */ + + if (!high_sierra) { + parse_rock_ridge_inode(de, inode); + /* if we want uid/gid set, override the rock ridge setting */ + test_and_set_uid(&inode->i_uid, sbi->s_uid); + test_and_set_gid(&inode->i_gid, sbi->s_gid); + } + + /* Install the inode operations vector */ + if (S_ISREG(inode->i_mode)) { + inode->i_fop = &generic_ro_fops; + switch ( ei->i_file_format ) { +#ifdef CONFIG_ZISOFS + case isofs_file_compressed: + inode->i_data.a_ops = &zisofs_aops; + break; +#endif + default: + inode->i_data.a_ops = &isofs_aops; + break; + } + } else if (S_ISDIR(inode->i_mode)) { + inode->i_op = &isofs_dir_inode_operations; + inode->i_fop = &isofs_dir_operations; + } else if (S_ISLNK(inode->i_mode)) { + inode->i_op = &page_symlink_inode_operations; + inode->i_data.a_ops = &isofs_symlink_aops; + } else + /* XXX - parse_rock_ridge_inode() had already set i_rdev. */ + init_special_inode(inode, inode->i_mode, inode->i_rdev); + + out: + if (tmpde) + kfree(tmpde); + if (bh) + brelse(bh); + return; + + out_badread: + printk(KERN_WARNING "ISOFS: unable to read i-node block\n"); + fail: + make_bad_inode(inode); + goto out; +} + +struct isofs_iget5_callback_data { + unsigned long block; + unsigned long offset; +}; + +static int isofs_iget5_test(struct inode *ino, void *data) +{ + struct iso_inode_info *i = ISOFS_I(ino); + struct isofs_iget5_callback_data *d = + (struct isofs_iget5_callback_data*)data; + return (i->i_iget5_block == d->block) + && (i->i_iget5_offset == d->offset); +} + +static int isofs_iget5_set(struct inode *ino, void *data) +{ + struct iso_inode_info *i = ISOFS_I(ino); + struct isofs_iget5_callback_data *d = + (struct isofs_iget5_callback_data*)data; + i->i_iget5_block = d->block; + i->i_iget5_offset = d->offset; + return 0; +} + +/* Store, in the inode's containing structure, the block and block + * offset that point to the underlying meta-data for the inode. The + * code below is otherwise similar to the iget() code in + * include/linux/fs.h */ +struct inode *isofs_iget(struct super_block *sb, + unsigned long block, + unsigned long offset) +{ + unsigned long hashval; + struct inode *inode; + struct isofs_iget5_callback_data data; + + if (offset >= 1ul << sb->s_blocksize_bits) + return NULL; + + data.block = block; + data.offset = offset; + + hashval = (block << sb->s_blocksize_bits) | offset; + + inode = iget5_locked(sb, + hashval, + &isofs_iget5_test, + &isofs_iget5_set, + &data); + + if (inode && (inode->i_state & I_NEW)) { + sb->s_op->read_inode(inode); + unlock_new_inode(inode); + } + + return inode; +} + +#ifdef LEAK_CHECK +#undef malloc +#undef free_s +#undef sb_bread +#undef brelse + +void * leak_check_malloc(unsigned int size){ + void * tmp; + check_malloc++; + tmp = kmalloc(size, GFP_KERNEL); + return tmp; +} + +void leak_check_free_s(void * obj, int size){ + check_malloc--; + return kfree(obj); +} + +struct buffer_head * leak_check_bread(struct super_block *sb, int block){ + check_bread++; + return sb_bread(sb, block); +} + +void leak_check_brelse(struct buffer_head * bh){ + check_bread--; + return brelse(bh); +} + +#endif + +static struct super_block *isofs_get_sb(struct file_system_type *fs_type, + int flags, const char *dev_name, void *data) +{ + return get_sb_bdev(fs_type, flags, dev_name, data, isofs_fill_super); +} + +static struct file_system_type iso9660_fs_type = { + .owner = THIS_MODULE, + .name = "iso9660", + .get_sb = isofs_get_sb, + .kill_sb = kill_block_super, + .fs_flags = FS_REQUIRES_DEV, +}; + +static int __init init_iso9660_fs(void) +{ + int err = init_inodecache(); + if (err) + goto out; +#ifdef CONFIG_ZISOFS + err = zisofs_init(); + if (err) + goto out1; +#endif + err = register_filesystem(&iso9660_fs_type); + if (err) + goto out2; + return 0; +out2: +#ifdef CONFIG_ZISOFS + zisofs_cleanup(); +out1: +#endif + destroy_inodecache(); +out: + return err; +} + +static void __exit exit_iso9660_fs(void) +{ + unregister_filesystem(&iso9660_fs_type); +#ifdef CONFIG_ZISOFS + zisofs_cleanup(); +#endif + destroy_inodecache(); +} + +module_init(init_iso9660_fs) +module_exit(exit_iso9660_fs) +MODULE_LICENSE("GPL"); +/* Actual filesystem name is iso9660, as requested in filesystems.c */ +MODULE_ALIAS("iso9660"); diff --git a/fs/isofs/joliet.c b/fs/isofs/joliet.c new file mode 100644 index 000000000000..86c50e22fc87 --- /dev/null +++ b/fs/isofs/joliet.c @@ -0,0 +1,103 @@ +/* + * linux/fs/isofs/joliet.c + * + * (C) 1996 Gordon Chaffee + * + * Joliet: Microsoft's Unicode extensions to iso9660 + */ + +#include +#include +#include +#include +#include + +/* + * Convert Unicode 16 to UTF8 or ASCII. + */ +static int +uni16_to_x8(unsigned char *ascii, u16 *uni, int len, struct nls_table *nls) +{ + wchar_t *ip, ch; + unsigned char *op; + + ip = uni; + op = ascii; + + while ((ch = get_unaligned(ip)) && len) { + int llen; + ch = be16_to_cpu(ch); + if ((llen = nls->uni2char(ch, op, NLS_MAX_CHARSET_SIZE)) > 0) + op += llen; + else + *op++ = '?'; + ip++; + + len--; + } + *op = 0; + return (op - ascii); +} + +/* Convert big endian wide character string to utf8 */ +static int +wcsntombs_be(__u8 *s, const __u8 *pwcs, int inlen, int maxlen) +{ + const __u8 *ip; + __u8 *op; + int size; + __u16 c; + + op = s; + ip = pwcs; + while ((*ip || ip[1]) && (maxlen > 0) && (inlen > 0)) { + c = (*ip << 8) | ip[1]; + if (c > 0x7f) { + size = utf8_wctomb(op, c, maxlen); + if (size == -1) { + /* Ignore character and move on */ + maxlen--; + } else { + op += size; + maxlen -= size; + } + } else { + *op++ = (__u8) c; + } + ip += 2; + inlen--; + } + return (op - s); +} + +int +get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode) +{ + unsigned char utf8; + struct nls_table *nls; + unsigned char len = 0; + + utf8 = ISOFS_SB(inode->i_sb)->s_utf8; + nls = ISOFS_SB(inode->i_sb)->s_nls_iocharset; + + if (utf8) { + len = wcsntombs_be(outname, de->name, + de->name_len[0] >> 1, PAGE_SIZE); + } else { + len = uni16_to_x8(outname, (u16 *) de->name, + de->name_len[0] >> 1, nls); + } + if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1')) { + len -= 2; + } + + /* + * Windows doesn't like periods at the end of a name, + * so neither do we + */ + while (len >= 2 && (outname[len-1] == '.')) { + len--; + } + + return len; +} diff --git a/fs/isofs/namei.c b/fs/isofs/namei.c new file mode 100644 index 000000000000..9569fc44102d --- /dev/null +++ b/fs/isofs/namei.c @@ -0,0 +1,201 @@ +/* + * linux/fs/isofs/namei.c + * + * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem. + * + * (C) 1991 Linus Torvalds - minix filesystem + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include /* Joliet? */ +#include +#include +#include + +#include + +/* + * ok, we cannot use strncmp, as the name is not in our data space. + * Thus we'll have to use isofs_match. No big problem. Match also makes + * some sanity tests. + */ +static int +isofs_cmp(struct dentry * dentry, const char * compare, int dlen) +{ + struct qstr qstr; + + if (!compare) + return 1; + + /* check special "." and ".." files */ + if (dlen == 1) { + /* "." */ + if (compare[0] == 0) { + if (!dentry->d_name.len) + return 0; + compare = "."; + } else if (compare[0] == 1) { + compare = ".."; + dlen = 2; + } + } + + qstr.name = compare; + qstr.len = dlen; + return dentry->d_op->d_compare(dentry, &dentry->d_name, &qstr); +} + +/* + * isofs_find_entry() + * + * finds an entry in the specified directory with the wanted name. It + * returns the inode number of the found entry, or 0 on error. + */ +static unsigned long +isofs_find_entry(struct inode *dir, struct dentry *dentry, + unsigned long *block_rv, unsigned long* offset_rv, + char * tmpname, struct iso_directory_record * tmpde) +{ + unsigned long bufsize = ISOFS_BUFFER_SIZE(dir); + unsigned char bufbits = ISOFS_BUFFER_BITS(dir); + unsigned long block, f_pos, offset, block_saved, offset_saved; + struct buffer_head * bh = NULL; + struct isofs_sb_info *sbi = ISOFS_SB(dir->i_sb); + + if (!ISOFS_I(dir)->i_first_extent) + return 0; + + f_pos = 0; + offset = 0; + block = 0; + + while (f_pos < dir->i_size) { + struct iso_directory_record * de; + int de_len, match, i, dlen; + char *dpnt; + + if (!bh) { + bh = isofs_bread(dir, block); + if (!bh) + return 0; + } + + de = (struct iso_directory_record *) (bh->b_data + offset); + + de_len = *(unsigned char *) de; + if (!de_len) { + brelse(bh); + bh = NULL; + f_pos = (f_pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1); + block = f_pos >> bufbits; + offset = 0; + continue; + } + + block_saved = bh->b_blocknr; + offset_saved = offset; + offset += de_len; + f_pos += 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(dir, block); + if (!bh) + return 0; + memcpy((void *) tmpde + slop, bh->b_data, offset); + } + de = tmpde; + } + + dlen = de->name_len[0]; + dpnt = de->name; + + if (sbi->s_rock && + ((i = get_rock_ridge_filename(de, tmpname, dir)))) { + dlen = i; /* possibly -1 */ + dpnt = tmpname; +#ifdef CONFIG_JOLIET + } else if (sbi->s_joliet_level) { + dlen = get_joliet_filename(de, tmpname, dir); + dpnt = tmpname; +#endif + } else if (sbi->s_mapping == 'a') { + dlen = get_acorn_filename(de, tmpname, dir); + dpnt = tmpname; + } else if (sbi->s_mapping == 'n') { + dlen = isofs_name_translate(de, tmpname, dir); + dpnt = tmpname; + } + + /* + * Skip hidden or associated files unless unhide is set + */ + match = 0; + if (dlen > 0 && + (!(de->flags[-sbi->s_high_sierra] & 5) + || sbi->s_unhide == 'y')) + { + match = (isofs_cmp(dentry,dpnt,dlen) == 0); + } + if (match) { + isofs_normalize_block_and_offset(de, + &block_saved, + &offset_saved); + *block_rv = block_saved; + *offset_rv = offset_saved; + if (bh) brelse(bh); + return 1; + } + } + if (bh) brelse(bh); + return 0; +} + +struct dentry *isofs_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd) +{ + int found; + unsigned long block, offset; + struct inode *inode; + struct page *page; + + dentry->d_op = dir->i_sb->s_root->d_op; + + page = alloc_page(GFP_USER); + if (!page) + return ERR_PTR(-ENOMEM); + + lock_kernel(); + found = isofs_find_entry(dir, dentry, + &block, &offset, + page_address(page), + 1024 + page_address(page)); + __free_page(page); + + inode = NULL; + if (found) { + inode = isofs_iget(dir->i_sb, block, offset); + if (!inode) { + unlock_kernel(); + return ERR_PTR(-EACCES); + } + } + unlock_kernel(); + if (inode) + return d_splice_alias(inode, dentry); + d_add(dentry, inode); + return NULL; +} diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c new file mode 100644 index 000000000000..8bdd3e409543 --- /dev/null +++ b/fs/isofs/rock.c @@ -0,0 +1,565 @@ +/* + * linux/fs/isofs/rock.c + * + * (C) 1992, 1993 Eric Youngdale + * + * Rock Ridge Extensions to iso9660 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rock.h" + +/* These functions are designed to read the system areas of a directory record + * and extract relevant information. There are different functions provided + * depending upon what information we need at the time. One function fills + * out an inode structure, a second one extracts a filename, a third one + * returns a symbolic link name, and a fourth one returns the extent number + * for the file. */ + +#define SIG(A,B) ((A) | ((B) << 8)) /* isonum_721() */ + + +/* This is a way of ensuring that we have something in the system + use fields that is compatible with Rock Ridge */ +#define CHECK_SP(FAIL) \ + if(rr->u.SP.magic[0] != 0xbe) FAIL; \ + if(rr->u.SP.magic[1] != 0xef) FAIL; \ + ISOFS_SB(inode->i_sb)->s_rock_offset=rr->u.SP.skip; +/* We define a series of macros because each function must do exactly the + same thing in certain places. We use the macros to ensure that everything + is done correctly */ + +#define CONTINUE_DECLS \ + int cont_extent = 0, cont_offset = 0, cont_size = 0; \ + void *buffer = NULL + +#define CHECK_CE \ + {cont_extent = isonum_733(rr->u.CE.extent); \ + cont_offset = isonum_733(rr->u.CE.offset); \ + cont_size = isonum_733(rr->u.CE.size);} + +#define SETUP_ROCK_RIDGE(DE,CHR,LEN) \ + {LEN= sizeof(struct iso_directory_record) + DE->name_len[0]; \ + if(LEN & 1) LEN++; \ + CHR = ((unsigned char *) DE) + LEN; \ + LEN = *((unsigned char *) DE) - LEN; \ + if (LEN<0) LEN=0; \ + if (ISOFS_SB(inode->i_sb)->s_rock_offset!=-1) \ + { \ + LEN-=ISOFS_SB(inode->i_sb)->s_rock_offset; \ + CHR+=ISOFS_SB(inode->i_sb)->s_rock_offset; \ + if (LEN<0) LEN=0; \ + } \ +} + +#define MAYBE_CONTINUE(LABEL,DEV) \ + {if (buffer) { kfree(buffer); buffer = NULL; } \ + if (cont_extent){ \ + int block, offset, offset1; \ + struct buffer_head * pbh; \ + buffer = kmalloc(cont_size,GFP_KERNEL); \ + if (!buffer) goto out; \ + block = cont_extent; \ + offset = cont_offset; \ + offset1 = 0; \ + pbh = sb_bread(DEV->i_sb, block); \ + if(pbh){ \ + if (offset > pbh->b_size || offset + cont_size > pbh->b_size){ \ + brelse(pbh); \ + goto out; \ + } \ + memcpy(buffer + offset1, pbh->b_data + offset, cont_size - offset1); \ + brelse(pbh); \ + chr = (unsigned char *) buffer; \ + len = cont_size; \ + cont_extent = 0; \ + cont_size = 0; \ + cont_offset = 0; \ + goto LABEL; \ + } \ + printk("Unable to read rock-ridge attributes\n"); \ + }} + +/* return length of name field; 0: not found, -1: to be ignored */ +int get_rock_ridge_filename(struct iso_directory_record * de, + char * retname, struct inode * inode) +{ + int len; + unsigned char * chr; + CONTINUE_DECLS; + int retnamlen = 0, truncate=0; + + if (!ISOFS_SB(inode->i_sb)->s_rock) return 0; + *retname = 0; + + SETUP_ROCK_RIDGE(de, chr, len); + repeat: + { + struct rock_ridge * rr; + int sig; + + while (len > 2){ /* There may be one byte for padding somewhere */ + rr = (struct rock_ridge *) chr; + if (rr->len < 3) goto out; /* Something got screwed up here */ + sig = isonum_721(chr); + chr += rr->len; + len -= rr->len; + if (len < 0) goto out; /* corrupted isofs */ + + switch(sig){ + case SIG('R','R'): + if((rr->u.RR.flags[0] & RR_NM) == 0) goto out; + break; + case SIG('S','P'): + CHECK_SP(goto out); + break; + case SIG('C','E'): + CHECK_CE; + break; + case SIG('N','M'): + if (truncate) break; + if (rr->len < 5) break; + /* + * If the flags are 2 or 4, this indicates '.' or '..'. + * We don't want to do anything with this, because it + * screws up the code that calls us. We don't really + * care anyways, since we can just use the non-RR + * name. + */ + if (rr->u.NM.flags & 6) { + break; + } + + if (rr->u.NM.flags & ~1) { + printk("Unsupported NM flag settings (%d)\n",rr->u.NM.flags); + break; + } + if((strlen(retname) + rr->len - 5) >= 254) { + truncate = 1; + break; + } + strncat(retname, rr->u.NM.name, rr->len - 5); + retnamlen += rr->len - 5; + break; + case SIG('R','E'): + if (buffer) kfree(buffer); + return -1; + default: + break; + } + } + } + MAYBE_CONTINUE(repeat,inode); + if (buffer) kfree(buffer); + return retnamlen; /* If 0, this file did not have a NM field */ + out: + if(buffer) kfree(buffer); + return 0; +} + +static int +parse_rock_ridge_inode_internal(struct iso_directory_record *de, + struct inode *inode, int regard_xa) +{ + int len; + unsigned char * chr; + int symlink_len = 0; + CONTINUE_DECLS; + + if (!ISOFS_SB(inode->i_sb)->s_rock) return 0; + + SETUP_ROCK_RIDGE(de, chr, len); + if (regard_xa) + { + chr+=14; + len-=14; + if (len<0) len=0; + } + + repeat: + { + int cnt, sig; + struct inode * reloc; + struct rock_ridge * rr; + int rootflag; + + while (len > 2){ /* There may be one byte for padding somewhere */ + rr = (struct rock_ridge *) chr; + if (rr->len < 3) goto out; /* Something got screwed up here */ + sig = isonum_721(chr); + chr += rr->len; + len -= rr->len; + if (len < 0) goto out; /* corrupted isofs */ + + switch(sig){ +#ifndef CONFIG_ZISOFS /* No flag for SF or ZF */ + case SIG('R','R'): + if((rr->u.RR.flags[0] & + (RR_PX | RR_TF | RR_SL | RR_CL)) == 0) goto out; + break; +#endif + case SIG('S','P'): + CHECK_SP(goto out); + break; + case SIG('C','E'): + CHECK_CE; + break; + case SIG('E','R'): + ISOFS_SB(inode->i_sb)->s_rock = 1; + printk(KERN_DEBUG "ISO 9660 Extensions: "); + { int p; + for(p=0;pu.ER.len_id;p++) printk("%c",rr->u.ER.data[p]); + } + printk("\n"); + break; + case SIG('P','X'): + inode->i_mode = isonum_733(rr->u.PX.mode); + inode->i_nlink = isonum_733(rr->u.PX.n_links); + inode->i_uid = isonum_733(rr->u.PX.uid); + inode->i_gid = isonum_733(rr->u.PX.gid); + break; + case SIG('P','N'): + { int high, low; + high = isonum_733(rr->u.PN.dev_high); + low = isonum_733(rr->u.PN.dev_low); + /* + * The Rock Ridge standard specifies that if sizeof(dev_t) <= 4, + * then the high field is unused, and the device number is completely + * stored in the low field. Some writers may ignore this subtlety, + * and as a result we test to see if the entire device number is + * stored in the low field, and use that. + */ + if((low & ~0xff) && high == 0) { + inode->i_rdev = MKDEV(low >> 8, low & 0xff); + } else { + inode->i_rdev = MKDEV(high, low); + } + } + break; + case SIG('T','F'): + /* Some RRIP writers incorrectly place ctime in the TF_CREATE field. + Try to handle this correctly for either case. */ + cnt = 0; /* Rock ridge never appears on a High Sierra disk */ + if(rr->u.TF.flags & TF_CREATE) { + inode->i_ctime.tv_sec = iso_date(rr->u.TF.times[cnt++].time, 0); + inode->i_ctime.tv_nsec = 0; + } + if(rr->u.TF.flags & TF_MODIFY) { + inode->i_mtime.tv_sec = iso_date(rr->u.TF.times[cnt++].time, 0); + inode->i_mtime.tv_nsec = 0; + } + if(rr->u.TF.flags & TF_ACCESS) { + inode->i_atime.tv_sec = iso_date(rr->u.TF.times[cnt++].time, 0); + inode->i_atime.tv_nsec = 0; + } + if(rr->u.TF.flags & TF_ATTRIBUTES) { + inode->i_ctime.tv_sec = iso_date(rr->u.TF.times[cnt++].time, 0); + inode->i_ctime.tv_nsec = 0; + } + break; + case SIG('S','L'): + {int slen; + struct SL_component * slp; + struct SL_component * oldslp; + slen = rr->len - 5; + slp = &rr->u.SL.link; + inode->i_size = symlink_len; + while (slen > 1){ + rootflag = 0; + switch(slp->flags &~1){ + case 0: + inode->i_size += slp->len; + break; + case 2: + inode->i_size += 1; + break; + case 4: + inode->i_size += 2; + break; + case 8: + rootflag = 1; + inode->i_size += 1; + break; + default: + printk("Symlink component flag not implemented\n"); + } + slen -= slp->len + 2; + oldslp = slp; + slp = (struct SL_component *) (((char *) slp) + slp->len + 2); + + if(slen < 2) { + if( ((rr->u.SL.flags & 1) != 0) + && ((oldslp->flags & 1) == 0) ) inode->i_size += 1; + break; + } + + /* + * If this component record isn't continued, then append a '/'. + */ + if (!rootflag && (oldslp->flags & 1) == 0) + inode->i_size += 1; + } + } + symlink_len = inode->i_size; + break; + case SIG('R','E'): + printk(KERN_WARNING "Attempt to read inode for relocated directory\n"); + goto out; + case SIG('C','L'): + ISOFS_I(inode)->i_first_extent = isonum_733(rr->u.CL.location); + reloc = isofs_iget(inode->i_sb, ISOFS_I(inode)->i_first_extent, 0); + if (!reloc) + goto out; + inode->i_mode = reloc->i_mode; + inode->i_nlink = reloc->i_nlink; + inode->i_uid = reloc->i_uid; + inode->i_gid = reloc->i_gid; + inode->i_rdev = reloc->i_rdev; + inode->i_size = reloc->i_size; + inode->i_blocks = reloc->i_blocks; + inode->i_atime = reloc->i_atime; + inode->i_ctime = reloc->i_ctime; + inode->i_mtime = reloc->i_mtime; + iput(reloc); + break; +#ifdef CONFIG_ZISOFS + case SIG('Z','F'): + if ( !ISOFS_SB(inode->i_sb)->s_nocompress ) { + int algo; + algo = isonum_721(rr->u.ZF.algorithm); + if ( algo == SIG('p','z') ) { + int block_shift = isonum_711(&rr->u.ZF.parms[1]); + if ( block_shift < PAGE_CACHE_SHIFT || block_shift > 17 ) { + printk(KERN_WARNING "isofs: Can't handle ZF block size of 2^%d\n", block_shift); + } else { + /* Note: we don't change i_blocks here */ + ISOFS_I(inode)->i_file_format = isofs_file_compressed; + /* Parameters to compression algorithm (header size, block size) */ + ISOFS_I(inode)->i_format_parm[0] = isonum_711(&rr->u.ZF.parms[0]); + ISOFS_I(inode)->i_format_parm[1] = isonum_711(&rr->u.ZF.parms[1]); + inode->i_size = isonum_733(rr->u.ZF.real_size); + } + } else { + printk(KERN_WARNING "isofs: Unknown ZF compression algorithm: %c%c\n", + rr->u.ZF.algorithm[0], rr->u.ZF.algorithm[1]); + } + } + break; +#endif + default: + break; + } + } + } + MAYBE_CONTINUE(repeat,inode); + out: + if(buffer) kfree(buffer); + return 0; +} + +static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit) +{ + int slen; + int rootflag; + struct SL_component *oldslp; + struct SL_component *slp; + slen = rr->len - 5; + slp = &rr->u.SL.link; + while (slen > 1) { + rootflag = 0; + switch (slp->flags & ~1) { + case 0: + if (slp->len > plimit - rpnt) + return NULL; + memcpy(rpnt, slp->text, slp->len); + rpnt+=slp->len; + break; + case 2: + if (rpnt >= plimit) + return NULL; + *rpnt++='.'; + break; + case 4: + if (2 > plimit - rpnt) + return NULL; + *rpnt++='.'; + *rpnt++='.'; + break; + case 8: + if (rpnt >= plimit) + return NULL; + rootflag = 1; + *rpnt++='/'; + break; + default: + printk("Symlink component flag not implemented (%d)\n", + slp->flags); + } + slen -= slp->len + 2; + oldslp = slp; + slp = (struct SL_component *) ((char *) slp + slp->len + 2); + + if (slen < 2) { + /* + * If there is another SL record, and this component + * record isn't continued, then add a slash. + */ + if ((!rootflag) && (rr->u.SL.flags & 1) && + !(oldslp->flags & 1)) { + if (rpnt >= plimit) + return NULL; + *rpnt++='/'; + } + break; + } + + /* + * If this component record isn't continued, then append a '/'. + */ + if (!rootflag && !(oldslp->flags & 1)) { + if (rpnt >= plimit) + return NULL; + *rpnt++='/'; + } + } + return rpnt; +} + +int parse_rock_ridge_inode(struct iso_directory_record * de, + struct inode * inode) +{ + int result=parse_rock_ridge_inode_internal(de,inode,0); + /* if rockridge flag was reset and we didn't look for attributes + * behind eventual XA attributes, have a look there */ + if ((ISOFS_SB(inode->i_sb)->s_rock_offset==-1) + &&(ISOFS_SB(inode->i_sb)->s_rock==2)) + { + result=parse_rock_ridge_inode_internal(de,inode,14); + } + return result; +} + +/* readpage() for symlinks: reads symlink contents into the page and either + makes it uptodate and returns 0 or returns error (-EIO) */ + +static int rock_ridge_symlink_readpage(struct file *file, struct page *page) +{ + struct inode *inode = page->mapping->host; + struct iso_inode_info *ei = ISOFS_I(inode); + char *link = kmap(page); + unsigned long bufsize = ISOFS_BUFFER_SIZE(inode); + struct buffer_head *bh; + char *rpnt = link; + unsigned char *pnt; + struct iso_directory_record *raw_inode; + CONTINUE_DECLS; + unsigned long block, offset; + int sig; + int len; + unsigned char *chr; + struct rock_ridge *rr; + + if (!ISOFS_SB(inode->i_sb)->s_rock) + goto error; + + block = ei->i_iget5_block; + lock_kernel(); + bh = sb_bread(inode->i_sb, block); + if (!bh) + goto out_noread; + + offset = ei->i_iget5_offset; + pnt = (unsigned char *) bh->b_data + offset; + + raw_inode = (struct iso_directory_record *) pnt; + + /* + * If we go past the end of the buffer, there is some sort of error. + */ + if (offset + *pnt > bufsize) + goto out_bad_span; + + /* Now test for possible Rock Ridge extensions which will override + some of these numbers in the inode structure. */ + + SETUP_ROCK_RIDGE(raw_inode, chr, len); + + repeat: + while (len > 2) { /* There may be one byte for padding somewhere */ + rr = (struct rock_ridge *) chr; + if (rr->len < 3) + goto out; /* Something got screwed up here */ + sig = isonum_721(chr); + chr += rr->len; + len -= rr->len; + if (len < 0) + goto out; /* corrupted isofs */ + + switch (sig) { + case SIG('R', 'R'): + if ((rr->u.RR.flags[0] & RR_SL) == 0) + goto out; + break; + case SIG('S', 'P'): + CHECK_SP(goto out); + break; + case SIG('S', 'L'): + rpnt = get_symlink_chunk(rpnt, rr, + link + (PAGE_SIZE - 1)); + if (rpnt == NULL) + goto out; + break; + case SIG('C', 'E'): + /* This tells is if there is a continuation record */ + CHECK_CE; + default: + break; + } + } + MAYBE_CONTINUE(repeat, inode); + if (buffer) + kfree(buffer); + + if (rpnt == link) + goto fail; + brelse(bh); + *rpnt = '\0'; + unlock_kernel(); + SetPageUptodate(page); + kunmap(page); + unlock_page(page); + return 0; + + /* error exit from macro */ + out: + if (buffer) + kfree(buffer); + goto fail; + out_noread: + printk("unable to read i-node block"); + goto fail; + out_bad_span: + printk("symlink spans iso9660 blocks\n"); + fail: + brelse(bh); + unlock_kernel(); + error: + SetPageError(page); + kunmap(page); + unlock_page(page); + return -EIO; +} + +struct address_space_operations isofs_symlink_aops = { + .readpage = rock_ridge_symlink_readpage +}; diff --git a/fs/isofs/rock.h b/fs/isofs/rock.h new file mode 100644 index 000000000000..deaf5c8e8b4a --- /dev/null +++ b/fs/isofs/rock.h @@ -0,0 +1,119 @@ +/* These structs are used by the system-use-sharing protocol, in which the + Rock Ridge extensions are embedded. It is quite possible that other + extensions are present on the disk, and this is fine as long as they + all use SUSP */ + +struct SU_SP{ + unsigned char magic[2]; + unsigned char skip; +} __attribute__((packed)); + +struct SU_CE{ + char extent[8]; + char offset[8]; + char size[8]; +}; + +struct SU_ER{ + unsigned char len_id; + unsigned char len_des; + unsigned char len_src; + unsigned char ext_ver; + char data[0]; +} __attribute__((packed)); + +struct RR_RR{ + char flags[1]; +} __attribute__((packed)); + +struct RR_PX{ + char mode[8]; + char n_links[8]; + char uid[8]; + char gid[8]; +}; + +struct RR_PN{ + char dev_high[8]; + char dev_low[8]; +}; + + +struct SL_component{ + unsigned char flags; + unsigned char len; + char text[0]; +} __attribute__((packed)); + +struct RR_SL{ + unsigned char flags; + struct SL_component link; +} __attribute__((packed)); + +struct RR_NM{ + unsigned char flags; + char name[0]; +} __attribute__((packed)); + +struct RR_CL{ + char location[8]; +}; + +struct RR_PL{ + char location[8]; +}; + +struct stamp{ + char time[7]; +} __attribute__((packed)); + +struct RR_TF{ + char flags; + struct stamp times[0]; /* Variable number of these beasts */ +} __attribute__((packed)); + +/* Linux-specific extension for transparent decompression */ +struct RR_ZF{ + char algorithm[2]; + char parms[2]; + char real_size[8]; +}; + +/* These are the bits and their meanings for flags in the TF structure. */ +#define TF_CREATE 1 +#define TF_MODIFY 2 +#define TF_ACCESS 4 +#define TF_ATTRIBUTES 8 +#define TF_BACKUP 16 +#define TF_EXPIRATION 32 +#define TF_EFFECTIVE 64 +#define TF_LONG_FORM 128 + +struct rock_ridge{ + char signature[2]; + unsigned char len; + unsigned char version; + union{ + struct SU_SP SP; + struct SU_CE CE; + struct SU_ER ER; + struct RR_RR RR; + struct RR_PX PX; + struct RR_PN PN; + struct RR_SL SL; + struct RR_NM NM; + struct RR_CL CL; + struct RR_PL PL; + struct RR_TF TF; + struct RR_ZF ZF; + } u; +}; + +#define RR_PX 1 /* POSIX attributes */ +#define RR_PN 2 /* POSIX devices */ +#define RR_SL 4 /* Symbolic link */ +#define RR_NM 8 /* Alternate Name */ +#define RR_CL 16 /* Child link */ +#define RR_PL 32 /* Parent link */ +#define RR_RE 64 /* Relocation directory */ +#define RR_TF 128 /* Timestamps */ diff --git a/fs/isofs/util.c b/fs/isofs/util.c new file mode 100644 index 000000000000..3f6d9c1ac95a --- /dev/null +++ b/fs/isofs/util.c @@ -0,0 +1,83 @@ +/* + * linux/fs/isofs/util.c + */ + +#include +#include +#include + +/* + * We have to convert from a MM/DD/YY format to the Unix ctime format. + * We have to take into account leap years and all of that good stuff. + * Unfortunately, the kernel does not have the information on hand to + * take into account daylight savings time, but it shouldn't matter. + * The time stored should be localtime (with or without DST in effect), + * and the timezone offset should hold the offset required to get back + * to GMT. Thus we should always be correct. + */ + +int iso_date(char * p, int flag) +{ + int year, month, day, hour, minute, second, tz; + int crtime, days, i; + + year = p[0] - 70; + month = p[1]; + day = p[2]; + hour = p[3]; + minute = p[4]; + second = p[5]; + if (flag == 0) tz = p[6]; /* High sierra has no time zone */ + else tz = 0; + + if (year < 0) { + crtime = 0; + } else { + int monlen[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; + + days = year * 365; + if (year > 2) + days += (year+1) / 4; + for (i = 1; i < month; i++) + days += monlen[i-1]; + if (((year+2) % 4) == 0 && month > 2) + days++; + days += day - 1; + crtime = ((((days * 24) + hour) * 60 + minute) * 60) + + second; + + /* sign extend */ + if (tz & 0x80) + tz |= (-1 << 8); + + /* + * The timezone offset is unreliable on some disks, + * so we make a sanity check. In no case is it ever + * more than 13 hours from GMT, which is 52*15min. + * The time is always stored in localtime with the + * timezone offset being what get added to GMT to + * get to localtime. Thus we need to subtract the offset + * to get to true GMT, which is what we store the time + * as internally. On the local system, the user may set + * their timezone any way they wish, of course, so GMT + * gets converted back to localtime on the receiving + * system. + * + * NOTE: mkisofs in versions prior to mkisofs-1.10 had + * the sign wrong on the timezone offset. This has now + * been corrected there too, but if you are getting screwy + * results this may be the explanation. If enough people + * complain, a user configuration option could be added + * to add the timezone offset in with the wrong sign + * for 'compatibility' with older discs, but I cannot see how + * it will matter that much. + * + * Thanks to kuhlmav@elec.canterbury.ac.nz (Volker Kuhlmann) + * for pointing out the sign error. + */ + if (-52 <= tz && tz <= 52) + crtime -= tz * 15 * 60; + } + return crtime; +} + diff --git a/fs/isofs/zisofs.h b/fs/isofs/zisofs.h new file mode 100644 index 000000000000..d78485d101c2 --- /dev/null +++ b/fs/isofs/zisofs.h @@ -0,0 +1,21 @@ +/* ----------------------------------------------------------------------- * + * + * 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. + * + * ----------------------------------------------------------------------- */ + +/* + * Prototypes for functions exported from the compressed isofs subsystem + */ + +#ifdef CONFIG_ZISOFS +extern struct address_space_operations zisofs_aops; +extern int __init zisofs_init(void); +extern void zisofs_cleanup(void); +#endif -- cgit v1.2.3