fsw_iso9660.c revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/* $Id$ */
/** @file
* fsw_iso9660.c - ISO9660 file system driver code.
*
* Current limitations:
* - Files must be in one extent (i.e. Level 2)
* - No Joliet or Rock Ridge extensions
* - No interleaving
* - inode number generation strategy fails on volumes > 2 GB
* - No blocksizes != 2048
* - No High Sierra or anything else != 'CD001'
* - No volume sets with directories pointing at other volumes
* - No extended attribute records
*/
/*
* Copyright (C) 2010-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*-
* This code is based on:
*
* Copyright (c) 2006 Christoph Pfisterer
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* distribution.
*
* * Neither the name of Christoph Pfisterer nor the names of the
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "fsw_iso9660.h"
// functions
static fsw_status_t fsw_iso9660_volume_stat(struct fsw_iso9660_volume *vol, struct fsw_volume_stat *sb);
static fsw_status_t fsw_iso9660_dnode_fill(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno);
static fsw_status_t fsw_iso9660_dnode_stat(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
struct fsw_dnode_stat *sb);
static fsw_status_t fsw_iso9660_get_extent(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
struct fsw_extent *extent);
static fsw_status_t fsw_iso9660_dir_lookup(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
static fsw_status_t fsw_iso9660_dir_read(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
static fsw_status_t fsw_iso9660_read_dirrec(struct fsw_iso9660_volume *vol, struct fsw_shandle *shand, struct iso9660_dirrec_buffer *dirrec_buffer);
static fsw_status_t fsw_iso9660_readlink(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
struct fsw_string *link);
static fsw_status_t rr_find_nm(struct fsw_iso9660_volume *vol, struct iso9660_dirrec *dirrec, int off, struct fsw_string *str);
static fsw_status_t rr_read_ce(struct fsw_iso9660_volume *vol, union fsw_rock_ridge_susp_ce *ce, fsw_u8 *begin);
//
// Dispatch Table
//
sizeof(struct fsw_iso9660_volume),
sizeof(struct fsw_iso9660_dnode),
};
{
fsw_u8 *r;
int off = 0;
struct fsw_rock_ridge_susp_sp *sp;
{
if (*r == 'S')
{
sp = (struct fsw_rock_ridge_susp_sp *)r;
{
return FSW_SUCCESS;
}
}
r++;
}
return FSW_NOT_FOUND;
}
static fsw_status_t rr_find_nm(struct fsw_iso9660_volume *vol, struct iso9660_dirrec *dirrec, int off, struct fsw_string *str)
{
int fCe = 0;
struct fsw_rock_ridge_susp_nm *nm;
{
if (r[0] == 'C' && r[1] == 'E' && r[2] == 28)
{
int rc;
int ce_off;
union fsw_rock_ridge_susp_ce *ce;
if (fCe == 0)
fCe = 1;
ce = (union fsw_rock_ridge_susp_ce *)r;
if (rc != FSW_SUCCESS)
{
return rc;
}
r = begin;
}
if (r[0] == 'N' && r[1] == 'M')
{
nm = (struct fsw_rock_ridge_susp_nm *)r;
{
int len = 0;
{
goto done;
}
{
goto done;
}
{
}
goto done;
}
}
r++;
}
if(fCe == 1)
return FSW_NOT_FOUND;
done:
if(fCe == 1)
return FSW_SUCCESS;
}
static fsw_status_t rr_read_ce(struct fsw_iso9660_volume *vol, union fsw_rock_ridge_susp_ce *ce, fsw_u8 *begin)
{
int rc;
if (rc != FSW_SUCCESS)
return rc;
return FSW_SUCCESS;
}
/**
* Mount an ISO9660 volume. Reads the superblock and constructs the
* root directory dnode.
*/
{
void *buffer;
struct iso9660_volume_descriptor *voldesc;
int i;
struct fsw_string s;
struct iso9660_dirrec rootdir;
int sua_pos;
char *sig;
int skip;
struct fsw_rock_ridge_susp_entry *entry;
// read through the Volume Descriptor Set
do {
if (status)
return status;
// descriptor follows ISO 9660 standard
// suitable Primary Volume Descriptor found
if (vol->primary_voldesc) {
}
}
// completely alien standard identifier, stop reading
voldesc_type = 255;
}
blockno++;
if (status)
return status;
// get information from Primary Volume Descriptor
return FSW_UNSUPPORTED;
return FSW_UNSUPPORTED;
// get volume name
for (i = 32; i > 0; i--)
break;
if (status)
return status;
// setup the root dnode
status = fsw_dnode_create_root(vol, ISO9660_SUPERBLOCK_BLOCKNO << ISO9660_BLOCKSIZE_BITS, &vol->g.root);
if (status)
return status;
{
}
sua_pos = (sizeof(struct iso9660_dirrec)) + rootdir.file_identifier_length + (rootdir.file_identifier_length % 2) - 2;
//int sua_size = rootdir.dirrec_length - rootdir.file_identifier_length;
//FSW_MSG_DEBUG((FSW_MSGSTR("fsw_iso9660_volume_mount: success (SUA(pos:%x, sz:%d)!!!)\n"), sua_pos, sua_size));
#if 1
skip = 0;
{
{
} else {
}
}
#endif
// release volume descriptors
return FSW_SUCCESS;
}
/**
* Free the volume data structure. Called by the core after an unmount or after
* an unsuccessful mount to release the memory used by the file system type specific
* part of the volume structure.
*/
{
if (vol->primary_voldesc)
}
/**
* Get in-depth information on a volume.
*/
static fsw_status_t fsw_iso9660_volume_stat(struct fsw_iso9660_volume *vol, struct fsw_volume_stat *sb)
{
sb->free_bytes = 0;
return FSW_SUCCESS;
}
/**
* Get full information on a dnode from disk. This function is called by the core
* whenever it needs to access fields in the dnode structure that may not
* be filled immediately upon creation of the dnode. In the case of iso9660, we
* delay fetching of the inode structure until dnode_fill is called. The size and
* type fields are invalid until this function has been called.
*/
static fsw_status_t fsw_iso9660_dnode_fill(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno)
{
// get info from the directory record
else
return FSW_SUCCESS;
}
/**
* Free the dnode data structure. Called by the core when deallocating a dnode
* structure to release the memory used by the file system type specific part
* of the dnode structure.
*/
{
}
/**
* Get in-depth information on a dnode. The core makes sure that fsw_iso9660_dnode_fill
* has been called on the dnode before this function is called. Note that some
* data is not directly stored into the structure, but passed to a host-specific
* callback that converts it to the host-specific format.
*/
static fsw_status_t fsw_iso9660_dnode_stat(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
struct fsw_dnode_stat *sb)
{
/*
sb->store_time_posix(sb, FSW_DNODE_STAT_CTIME, dno->raw->i_ctime);
sb->store_time_posix(sb, FSW_DNODE_STAT_ATIME, dno->raw->i_atime);
sb->store_time_posix(sb, FSW_DNODE_STAT_MTIME, dno->raw->i_mtime);
sb->store_attr_posix(sb, dno->raw->i_mode);
*/
return FSW_SUCCESS;
}
/**
* Retrieve file data mapping information. This function is called by the core when
* fsw_shandle_read needs to know where on the disk the required piece of the file's
* data can be found. The core makes sure that fsw_iso9660_dnode_fill has been called
* on the dnode before. Our task here is to get the physical disk block number for
* the requested logical block number.
*/
static fsw_status_t fsw_iso9660_get_extent(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
struct fsw_extent *extent)
{
// Preconditions: The caller has checked that the requested logical block
// is within the file's size. The dnode has complete information, i.e.
// fsw_iso9660_dnode_read_info was called successfully on it.
extent->log_count = (ISOINT(dno->dirrec.data_length) + (ISO9660_BLOCKSIZE-1)) >> ISO9660_BLOCKSIZE_BITS;
return FSW_SUCCESS;
}
/**
* Lookup a directory's child dnode by name. This function is called on a directory
* to retrieve the directory entry with the given name. A dnode is constructed for
* this entry and returned. The core makes sure that fsw_iso9660_dnode_fill has been called
* and the dnode is actually a directory.
*/
static fsw_status_t fsw_iso9660_dir_lookup(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
{
struct fsw_shandle shand;
struct iso9660_dirrec_buffer dirrec_buffer;
// Preconditions: The caller has checked that dno is a directory node.
// setup handle to read the directory
if (status)
return status;
// scan the directory for the file
while (1) {
// read next entry
if (status)
goto errorexit;
if (dirrec->dirrec_length == 0) {
// end of directory reached
goto errorexit;
}
// skip . and ..
continue;
// compare name
break;
}
// setup a dnode for the child item
status = fsw_dnode_create(dno, dirrec_buffer.ino, FSW_DNODE_TYPE_UNKNOWN, &dirrec_buffer.name, child_dno_out);
if (status == FSW_SUCCESS)
return status;
}
/**
* Get the next directory entry when reading a directory. This function is called during
* directory iteration to retrieve the next directory entry. A dnode is constructed for
* the entry and returned. The core makes sure that fsw_iso9660_dnode_fill has been called
* and the dnode is actually a directory. The shandle provided by the caller is used to
* record the position in the directory between calls.
*/
static fsw_status_t fsw_iso9660_dir_read(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
{
struct iso9660_dirrec_buffer dirrec_buffer;
// Preconditions: The caller has checked that dno is a directory node. The caller
// has opened a storage handle to the directory's storage and keeps it around between
// calls.
/* (vasily) directory nodes are 4096 bytes that is two logical blocks so read dir operation
* should read both blocks.
*/
while (1) {
// read next entry
return FSW_NOT_FOUND; // end of directory
if (status)
return status;
if (dirrec->dirrec_length == 0)
{
// try the next block
continue;
}
// skip . and ..
continue;
break;
}
// setup a dnode for the child item
status = fsw_dnode_create(dno, dirrec_buffer.ino, FSW_DNODE_TYPE_UNKNOWN, &dirrec_buffer.name, child_dno_out);
if (status == FSW_SUCCESS)
return status;
}
/**
* Read a directory entry from the directory's raw data. This internal function is used
* to read a raw iso9660 directory entry into memory. The shandle's position pointer is adjusted
* to point to the next entry.
*/
static fsw_status_t fsw_iso9660_read_dirrec(struct fsw_iso9660_volume *vol, struct fsw_shandle *shand, struct iso9660_dirrec_buffer *dirrec_buffer)
{
int sp_off;
int rc;
// read fixed size part of directory record
buffer_size = 33;
if (status)
{
return status;
}
// end of directory reached
fsw_u8 *r;
for(i = 0; i < buffer_size; ++i)
{
}
dirrec->dirrec_length = 0;
return FSW_SUCCESS;
}
return FSW_VOLUME_CORRUPTED;
// read variable size part of directory record
if (status)
return status;
if (buffer_size < remaining_size)
return FSW_VOLUME_CORRUPTED;
if (vol->fRockRidge)
{
if ( rc == FSW_SUCCESS
{
}
if (rc == FSW_SUCCESS)
return FSW_SUCCESS;
}
// setup name
for (i = name_len - 1; i > 0; i--) {
name_len = i; // cut the ISO9660 version number off
break;
}
}
name_len--; // also cut the extension separator if the extension is empty
DEBUG((DEBUG_INFO, "%a:%d: dirrec_buffer->name.data:%a\n", __FILE__, __LINE__, dirrec_buffer->name.data));
return FSW_SUCCESS;
}
/**
* Get the target path of a symbolic link. This function is called when a symbolic
* link needs to be resolved. The core makes sure that the fsw_iso9660_dnode_fill has been
* called on the dnode and that it really is a symlink.
*
* For iso9660, the target path can be stored inline in the inode structure (in the space
* otherwise occupied by the block pointers) or in the inode's data. There is no flag
* indicating this, only the number of blocks entry (i_blocks) can be used as an
* indication. The check used here comes from the Linux kernel.
*/
static fsw_status_t fsw_iso9660_readlink(struct fsw_iso9660_volume *vol, struct fsw_iso9660_dnode *dno,
struct fsw_string *link_target)
{
return FSW_VOLUME_CORRUPTED;
return status;
}
// EOF