fsw_core.h revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
* fsw_core.h - Core file system wrapper abstraction layer header.
*/
/*
* Copyright (C) 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
* Portions Copyright (c) The Regents of the University of California.
* Portions Copyright (c) UNIX System Laboratories, Inc.
*
* 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.
*/
#ifndef _FSW_CORE_H_
#define _FSW_CORE_H_
#include "fsw_base.h"
/** Maximum size for a path, specifically symlink target paths. */
#ifndef VBOX
#define FSW_PATH_MAX (4096)
#else
/* Too big allocations are handled with alloca() */
#define FSW_PATH_MAX (2048)
#endif
/** Helper macro for token concatenation. */
#define FSW_CONCAT3(a,b,c) a##b##c
/** Expands to the name of a fstype dispatch table (fsw_fstype_table) for a named file system type. */
/** Indicates that the block cache entry is empty. */
#define FSW_INVALID_BNO (~0U)
//
// Byte-swapping macros
//
/**
* \name Byte Order Macros
* Implements big endian vs. little endian awareness and conversion.
*/
/*@{*/
typedef fsw_u16 fsw_u16_le;
typedef fsw_u16 fsw_u16_be;
typedef fsw_u32 fsw_u32_le;
typedef fsw_u32 fsw_u32_be;
typedef fsw_u64 fsw_u64_le;
typedef fsw_u64 fsw_u64_be;
#ifdef FSW_LITTLE_ENDIAN
#define fsw_u16_le_swap(v) (v)
#define fsw_u16_be_swap(v) FSW_SWAPVALUE_U16(v)
#define fsw_u32_le_swap(v) (v)
#define fsw_u32_be_swap(v) FSW_SWAPVALUE_U32(v)
#define fsw_u64_le_swap(v) (v)
#define fsw_u64_be_swap(v) FSW_SWAPVALUE_U64(v)
#define fsw_u16_le_sip(var)
#define fsw_u32_le_sip(var)
#define fsw_u64_le_sip(var)
#else
#ifdef FSW_BIG_ENDIAN
#define fsw_u16_le_swap(v) FSW_SWAPVALUE_U16(v)
#define fsw_u16_be_swap(v) (v)
#define fsw_u32_le_swap(v) FSW_SWAPVALUE_U32(v)
#define fsw_u32_be_swap(v) (v)
#define fsw_u64_le_swap(v) FSW_SWAPVALUE_U64(v)
#define fsw_u64_be_swap(v) (v)
#define fsw_u16_be_sip(var)
#define fsw_u32_be_sip(var)
#define fsw_u64_be_sip(var)
#else
#endif
#endif
/*@}*/
//
// The following evil hack avoids a lot of casts between generic and fstype-specific
// structures.
//
#ifndef VOLSTRUCTNAME
#define VOLSTRUCTNAME fsw_volume
#else
struct VOLSTRUCTNAME;
#endif
#ifndef DNODESTRUCTNAME
#define DNODESTRUCTNAME fsw_dnode
#else
struct DNODESTRUCTNAME;
#endif
/**
* Status code type, returned from all functions that can fail.
*/
typedef int fsw_status_t;
/**
* Possible status codes.
*/
enum {
};
/**
* Core: A string with explicit length and encoding information.
*/
struct fsw_string {
int type; //!< Encoding of the string - empty, ISO-8859-1, UTF8, UTF16
int len; //!< Length in characters
int size; //!< Total data size in bytes
void *data; //!< Data pointer (may be NULL if type is EMPTY or len is zero)
};
/**
* Possible string types / encodings. In the case of FSW_STRING_TYPE_EMPTY,
* all other members of the fsw_string structure may be invalid.
*/
enum {
};
#ifdef FSW_LITTLE_ENDIAN
#else
#endif
/** Static initializer for an empty string. */
/* forward declarations */
struct fsw_dnode;
struct fsw_host_table;
struct fsw_fstype_table;
struct fsw_blockcache {
void *data; //!< Block data buffer
};
/**
* Core: Represents a mounted volume.
*/
struct fsw_volume {
void *host_data; //!< Hook for a host-specific data structure
int host_string_type; //!< String type used by the host environment
};
/**
* Core: Represents a "directory node" - a file, directory, symlink, whatever.
*/
struct fsw_dnode {
int type; //!< Type of the dnode - file, dir, symlink, special
};
/**
* Possible dnode types. FSW_DNODE_TYPE_UNKNOWN may only be used before
* fsw_dnode_fill has been called on the dnode.
*/
enum {
};
/**
* Core: Stores the mapping of a region of a file to the data on disk.
*/
struct fsw_extent {
int type; //!< Type of extent specification
void *buffer; //!< Allocated buffer pointer (for FSW_EXTENT_TYPE_BUFFER only)
};
/**
* Possible extent representation types. FSW_EXTENT_TYPE_INVALID is for shandle's
* internal use only, it must not be returned from a get_extent function.
*/
enum {
};
/**
* Core: An access structure to a dnode's raw data. There can be multiple
* shandles per dnode, each of them has its own position pointer.
*/
struct fsw_shandle {
};
/**
* Core: Used in gathering detailed information on a volume.
*/
struct fsw_volume_stat {
};
/**
* Core: Used in gathering detailed information on a dnode.
*/
struct fsw_dnode_stat {
void (*store_time_posix)(struct fsw_dnode_stat *sb, int which, fsw_u32 posix_time); //!< Callback for storing a Posix-style timestamp
void (*store_attr_posix)(struct fsw_dnode_stat *sb, fsw_u16 posix_mode); //!< Callback for storing a Posix-style file mode
void *host_data; //!< Hook for a host-specific data structure
};
/**
* Type of the timestamp passed into store_time_posix.
*/
enum {
};
/**
* Core: Function table for a host environment.
*/
struct fsw_host_table
{
int native_string_type; //!< String type used by the host environment
};
/**
* Core: Function table for a file system driver.
*/
struct fsw_fstype_table
{
struct fsw_dnode_stat *sb);
struct fsw_extent *extent);
struct fsw_string *link_target);
};
/**
* \name Volume Functions
*/
/*@{*/
struct fsw_host_table *host_table,
struct fsw_fstype_table *fstype_table,
struct fsw_volume **vol_out);
fsw_status_t fsw_block_get(struct VOLSTRUCTNAME *vol, fsw_u32 phys_bno, fsw_u32 cache_level, void **buffer_out);
/*@}*/
/**
* \name dnode Functions
*/
/*@{*/
fsw_status_t fsw_dnode_create_root(struct VOLSTRUCTNAME *vol, fsw_u32 dnode_id, struct DNODESTRUCTNAME **dno_out);
struct fsw_dnode **child_dno_out);
/*@}*/
/**
* \name shandle Functions
*/
/*@{*/
/*@}*/
/**
* \name Memory Functions
*/
/*@{*/
/*@}*/
/**
* \name String Functions
*/
/*@{*/
int fsw_strlen(struct fsw_string *s);
void fsw_strfree(struct fsw_string *s);
/*@}*/
/**
* \name Posix Mode Macros
* These macros can be used globally to test fields and bits in
* Posix-style modes.
*
*/
/*@{*/
#ifndef S_IRWXU
#endif
/*@}*/
#endif