metalsvm/include/metalsvm/fs.h
Jacek Galowicz 6c6d77cfa6 Committed the rest. There is only few stuff missing.
Embedded nice pictures.
2011-04-05 14:44:42 +02:00

201 lines
5.9 KiB
C

/*
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
/**
* @author Stefan Lankes
* @file include/metalsvm/fs.h
* @brief Filesystem related functions and structures
*/
#ifndef __FS_H__
#define __FS_H__
#include <metalsvm/stddef.h>
#include <metalsvm/spinlock.h>
#define FS_FILE 0x01
#define FS_DIRECTORY 0x02
#define FS_CHARDEVICE 0x03
//#define FS_BLOCKDEVICE 0x04
//#define FS_PIPE 0x05
//#define FS_SYMLINK 0x06
//#define FS_MOUNTPOINT 0x08 // Is the file an active mountpoint?
struct vfs_node;
/** @defgroup fsprototypes FS access function prototypes
*
* These typedefs define the type of callbacks - called when read/write/open/close are called.\n
* They aren't as well documented as the read_fs and so on functions. Just look there for further information.
*
* @{
*/
/** @brief Read function pointer */
typedef ssize_t (*read_type_t) (struct vfs_node *, uint8_t*, size_t, off_t);
/** @brief Write function pointer */
typedef ssize_t (*write_type_t) (struct vfs_node *, uint8_t*, size_t, off_t);
/** @brief Open function pointer */
typedef int (*open_type_t) (struct vfs_node *);
/** @brief Close function pointer */
typedef int (*close_type_t) (struct vfs_node *);
/** @brief Read directory function pointer */
typedef struct dirent *(*readdir_type_t) (struct vfs_node *, uint32_t);
/** @brief Find directory function pointer */
typedef struct vfs_node *(*finddir_type_t) (struct vfs_node *, const char *name);
/** @brief Make directory function pointer */
typedef struct vfs_node *(*mkdir_type_t) (struct vfs_node *, const char *name);
/** @} */
#define MAX_DATABLOCKS 12
#define MAX_DIRENTRIES 32
/** @brief Block list structure. VFS nodes keep those in a list */
typedef struct block_list {
/// Array with pointers to data blocks
void* data[MAX_DATABLOCKS];
/// Pointer to the next block_list in the list
struct block_list* next;
} block_list_t;
typedef struct vfs_node {
/// The permissions mask.
uint32_t mask;
/// The owning user.
uint32_t uid;
/// The owning group.
uint32_t gid;
/// Includes the node type. See #defines above.
uint32_t type;
/// Open handler function pointer
open_type_t open;
/// Close handler function pointer
close_type_t close;
/// Read handler function pointer
read_type_t read;
/// Write handler function pointer
write_type_t write;
/// Read dir handler function pointer
readdir_type_t readdir;
/// Find dir handler function pointer
finddir_type_t finddir;
/// Make dir handler function pointer
mkdir_type_t mkdir;
/// Lock variable to thread-protect this structure
spinlock_t lock;
/// Block size
size_t block_size;
/// List of blocks
block_list_t block_list;
} vfs_node_t;
/** @brief Directory entry structure */
typedef struct dirent{
/// Directory name
char name[MAX_FNAME];
/// Corresponding VFS node pointer
vfs_node_t* vfs_node;
} dirent_t;
/** @brief Dir block structure which will keep directory entries */
typedef struct {
/// Array of directory entries
dirent_t entries[MAX_DIRENTRIES];
} dir_block_t;
extern vfs_node_t* fs_root; // The root of the filesystem.
/** @defgroup fsfunc FS related functions
*
* Standard read/write/open/close/mkdir functions. Note that these are all suffixed with
* _fs to distinguish them from the read/write/open/close which deal with file descriptors,
* not file nodes.
*
* @{
*/
/** @brief Read from file system into the buffer
* @param node Pointer to the node to read from
* @param buffer Pointer to buffer to write into
* @param size Number of bytes to read
* @param offset Offset position of the source range
* @return
* - number of bytes copied (size)
* - 0 on error
*/
ssize_t read_fs(vfs_node_t * node, uint8_t* buffer, size_t size, off_t offset);
/** @brief Write into the file system from the buffer
* @param node Pointer to the node to write to
* @param buffer Pointer to buffer to read from
* @param size Number of bytes to read
* @param offset Offset position of the destination range
* @return
* - number of bytes copied (size)
* - 0 on error
*/
ssize_t write_fs(vfs_node_t * node, uint8_t* buffer, size_t size, off_t offset);
/** @brief Yet to be documented */
int open_fs(vfs_node_t * node, uint8_t read, uint8_t write);
/** @brief Yet to be documented */
int close_fs(vfs_node_t * node);
/** @brief Get dir entry at index
* @param node VFS node to get dir entry from
* @param index Index position of desired dir entry
* @return
* - The desired dir entry
* - NULL on failure
*/
struct dirent *readdir_fs(vfs_node_t * node, uint32_t index);
/** @brief Find a directory by looking for the dir name
* @param node The node where to start the search from
* @param name The dir name string
* @return
* - a VFS node pointer
* - NULL on failure
*/
vfs_node_t* finddir_fs(vfs_node_t * node, const char *name);
/** @brief Make a new directory in a VFS node
* @param node Pointer to the node where the dir is to create in
* @param name Name of the new directory
* @return
* - new VFS node pointer
* - NULL on failure
*/
vfs_node_t* mkdir_fs(vfs_node_t* node, const char* name);
/** @brief Find a node within root file system
* @param name The node name
* @return
* - VFS node pointer
* - NULL on failure
*/
vfs_node_t* findnode_fs(const char* name);
/* @} */
int null_init(vfs_node_t* node, const char* name);
int initrd_init(void);
#endif