fsw_posix.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/**
* \file fsw_posix.c
* POSIX user space host environment code.
*/
/*-
* 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_posix.h"
#ifndef FSTYPE
/** The file system type name to use. */
#endif
// function prototypes
struct fsw_shandle *shand);
/**
* Dispatch table for our FSW host driver.
*/
struct fsw_host_table fsw_posix_host_table = {
};
/**
* Mount function.
*/
{
struct fsw_posix_volume *pvol;
// allocate volume structure
if (status)
return NULL;
return NULL;
}
// mount the filesystem
if (fstype_table == NULL)
if (status) {
return NULL;
}
return pvol;
}
/**
* Unmount function.
*/
{
return 0;
}
/**
* Open a named regular file.
*/
struct fsw_posix_file * fsw_posix_open(struct fsw_posix_volume *pvol, const char *path, int flags, mode_t mode)
{
struct fsw_posix_file *file;
// TODO: check flags for unwanted values
// allocate file structure
if (status)
return NULL;
// open the file
if (status) {
return NULL;
}
return file;
}
/**
* Read data from a regular file.
*/
{
if (status)
return -1;
return buffer_size;
}
/**
* Change position within a regular file.
*/
{
fsw_u64 base_offset = 0;
// get base offset
base_offset = 0;
// calculate new offset, prevent seeks before the start of the file
else
}
/**
* Close a regular file.
*/
{
return 0;
}
/**
* Open a directory for iteration.
*/
{
struct fsw_posix_dir *dir;
// allocate file structure
if (status)
return NULL;
// open the directory
if (status) {
return NULL;
}
return dir;
}
/**
* Read the next entry from a directory.
*/
{
// get next entry from file system
if (status) {
if (status != 4)
return NULL;
}
if (status) {
return NULL;
}
// fill dirent structure
case FSW_DNODE_TYPE_FILE:
break;
case FSW_DNODE_TYPE_DIR:
break;
case FSW_DNODE_TYPE_SYMLINK:
break;
default:
break;
}
#if 0
#endif
return &dent;
}
/**
* Rewind a directory to the start.
*/
{
}
/**
* Close a directory.
*/
{
return 0;
}
/**
* Open a shand of a required type by path.
*/
fsw_status_t fsw_posix_open_dno(struct fsw_posix_volume *pvol, const char *path, int required_type, struct fsw_shandle *shand)
{
struct fsw_dnode *target_dno;
struct fsw_string lookup_path;
// resolve the path (symlinks along the way are automatically resolved)
if (status) {
return status;
}
// if the final node is a symlink, also resolve it
if (status) {
return status;
}
dno = target_dno;
// check that it is a regular file
if (status) {
return status;
}
return FSW_UNSUPPORTED;
}
// open shandle
if (status) {
}
return status;
}
/**
* FSW interface function for block size changes. This function is called by the FSW core
* when the file system driver changes the block sizes for the volume.
*/
{
// nothing to do
}
/**
* FSW interface function to read data blocks. This function is called by the FSW core
* to read a block of data from the device. The buffer is allocated by the core code.
*/
{
// read from disk
if (seek_result != block_offset)
return FSW_IO_ERROR;
return FSW_IO_ERROR;
return FSW_SUCCESS;
}
/**
* Time mapping callback for the fsw_dnode_stat call. This function converts
* a Posix style timestamp into an EFI_TIME structure and writes it to the
* appropriate member of the EFI_FILE_INFO structure that we're filling.
*/
/*
static void fsw_posix_store_time_posix(struct fsw_dnode_stat *sb, int which, fsw_u32 posix_time)
{
EFI_FILE_INFO *FileInfo = (EFI_FILE_INFO *)sb->host_data;
if (which == FSW_DNODE_STAT_CTIME)
fsw_posix_decode_time(&FileInfo->CreateTime, posix_time);
else if (which == FSW_DNODE_STAT_MTIME)
fsw_posix_decode_time(&FileInfo->ModificationTime, posix_time);
else if (which == FSW_DNODE_STAT_ATIME)
fsw_posix_decode_time(&FileInfo->LastAccessTime, posix_time);
}
*/
/**
* Mode mapping callback for the fsw_dnode_stat call. This function looks at
* the Posix mode passed by the file system driver and makes appropriate
* adjustments to the EFI_FILE_INFO structure that we're filling.
*/
/*
static void fsw_posix_store_attr_posix(struct fsw_dnode_stat *sb, fsw_u16 posix_mode)
{
EFI_FILE_INFO *FileInfo = (EFI_FILE_INFO *)sb->host_data;
if ((posix_mode & S_IWUSR) == 0)
FileInfo->Attribute |= EFI_FILE_READ_ONLY;
}
*/
/**
* Common function to fill an EFI_FILE_INFO with information about a dnode.
*/
/*
EFI_STATUS fsw_posix_dnode_fill_FileInfo(IN FSW_VOLUME_DATA *Volume,
IN struct fsw_dnode *dno,
IN OUT UINTN *BufferSize,
OUT VOID *Buffer)
{
EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
UINTN RequiredSize;
struct fsw_dnode_stat sb;
// make sure the dnode has complete info
Status = fsw_posix_map_status(fsw_dnode_fill(dno), Volume);
if (EFI_ERROR(Status))
return Status;
// check buffer size
RequiredSize = SIZE_OF_EFI_FILE_INFO + fsw_posix_strsize(&dno->name);
if (*BufferSize < RequiredSize) {
// TODO: wind back the directory in this case
*BufferSize = RequiredSize;
return EFI_BUFFER_TOO_SMALL;
}
// fill structure
ZeroMem(Buffer, RequiredSize);
FileInfo = (EFI_FILE_INFO *)Buffer;
FileInfo->Size = RequiredSize;
FileInfo->FileSize = dno->size;
FileInfo->Attribute = 0;
if (dno->type == FSW_DNODE_TYPE_DIR)
FileInfo->Attribute |= EFI_FILE_DIRECTORY;
fsw_posix_strcpy(FileInfo->FileName, &dno->name);
// get the missing info from the fs driver
ZeroMem(&sb, sizeof(struct fsw_dnode_stat));
sb.store_time_posix = fsw_posix_store_time_posix;
sb.store_attr_posix = fsw_posix_store_attr_posix;
sb.host_data = FileInfo;
Status = fsw_posix_map_status(fsw_dnode_stat(dno, &sb), Volume);
if (EFI_ERROR(Status))
return Status;
FileInfo->PhysicalSize = sb.used_bytes;
// prepare for return
*BufferSize = RequiredSize;
return EFI_SUCCESS;
}
*/
// EOF