libvtreefs: convert to KNF

Change-Id: I81bdf05c9b630a0cbb0ac573d36d4f59f8137199
This commit is contained in:
David van Moolenbroek 2014-11-06 13:36:45 +00:00
parent f92baba71c
commit 693ad767e8
12 changed files with 300 additions and 324 deletions

View file

@ -32,23 +32,26 @@ struct fs_hooks {
int (*message_hook)(message *m); int (*message_hook)(message *m);
}; };
extern struct inode *add_inode(struct inode *parent, char *name, index_t index, extern struct inode *add_inode(struct inode *parent, const char *name,
struct inode_stat *stat, index_t nr_indexed_entries, cbdata_t cbdata); index_t index, const struct inode_stat *stat,
index_t nr_indexed_entries, cbdata_t cbdata);
extern void delete_inode(struct inode *inode); extern void delete_inode(struct inode *inode);
extern struct inode *get_inode_by_name(struct inode *parent, char *name); extern struct inode *get_inode_by_name(const struct inode *parent,
extern struct inode *get_inode_by_index(struct inode *parent, index_t index); const char *name);
extern struct inode *get_inode_by_index(const struct inode *parent,
index_t index);
extern char const *get_inode_name(struct inode *inode); extern const char *get_inode_name(const struct inode *inode);
extern index_t get_inode_index(struct inode *inode); extern index_t get_inode_index(const struct inode *inode);
extern cbdata_t get_inode_cbdata(struct inode *inode); extern cbdata_t get_inode_cbdata(const struct inode *inode);
extern struct inode *get_root_inode(void); extern struct inode *get_root_inode(void);
extern struct inode *get_parent_inode(struct inode *inode); extern struct inode *get_parent_inode(const struct inode *inode);
extern struct inode *get_first_inode(struct inode *parent); extern struct inode *get_first_inode(const struct inode *parent);
extern struct inode *get_next_inode(struct inode *previous); extern struct inode *get_next_inode(const struct inode *previous);
extern void get_inode_stat(struct inode *inode, struct inode_stat *stat); extern void get_inode_stat(const struct inode *inode, struct inode_stat *stat);
extern void set_inode_stat(struct inode *inode, struct inode_stat *stat); extern void set_inode_stat(struct inode *inode, struct inode_stat *stat);
extern void start_vtreefs(struct fs_hooks *hooks, unsigned int nr_inodes, extern void start_vtreefs(struct fs_hooks *hooks, unsigned int nr_inodes,

View file

@ -1,4 +1,4 @@
/* VTreeFS - inode.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - inode.c - inode management */
#include "inc.h" #include "inc.h"
@ -19,19 +19,17 @@ static LIST_HEAD(index_head, inode) *parent_index_head;
#define CHECK_INODE(node) \ #define CHECK_INODE(node) \
do { \ do { \
assert(node >= &inode[0] && node < &inode[nr_inodes]); \ assert(node >= &inode[0] && node < &inode[nr_inodes]); \
assert(node == &inode[0] || \ assert(node == &inode[0] || node->i_parent != NULL || \
node->i_parent != NULL || \
(node->i_flags & I_DELETED)); \ (node->i_flags & I_DELETED)); \
} while (0); } while (0);
/*===========================================================================* /*
* init_inodes * * Initialize the inode-related state.
*===========================================================================*/ */
void init_inodes(unsigned int inodes, struct inode_stat *stat, void
init_inodes(unsigned int inodes, struct inode_stat * stat,
index_t nr_indexed_entries) index_t nr_indexed_entries)
{ {
/* Initialize the inode-related state.
*/
struct inode *node; struct inode *node;
unsigned int i; unsigned int i;
@ -87,13 +85,12 @@ void init_inodes(unsigned int inodes, struct inode_stat *stat,
node->i_cbdata = NULL; node->i_cbdata = NULL;
} }
/*===========================================================================* /*
* cleanup_inodes * * Clean up the inode-related state.
*===========================================================================*/
void cleanup_inodes(void)
{
/* Clean up the inode-related state.
*/ */
void
cleanup_inodes(void)
{
/* Free the inode and hash tables. */ /* Free the inode and hash tables. */
free(parent_index_head); free(parent_index_head);
@ -101,18 +98,16 @@ void cleanup_inodes(void)
free(inode); free(inode);
} }
/*===========================================================================* /*
* parent_name_hash * * Return the hash value of <parent,name> tuple.
*===========================================================================*/
static int parent_name_hash(struct inode *parent, char *name)
{
/* Return the hash value of <parent,name> tuple.
*/ */
unsigned int name_hash; static int
unsigned long parent_hash; parent_name_hash(const struct inode * parent, const char *name)
{
unsigned int name_hash, parent_hash;
/* The parent hash is a simple array entry; find its index. */ /* The parent hash is a simple array entry; find its index. */
parent_hash = parent - &inode[0]; parent_hash = (unsigned int)(parent - &inode[0]);
/* Use the sdbm algorithm to hash the name. */ /* Use the sdbm algorithm to hash the name. */
name_hash = sdbm_hash(name, strlen(name)); name_hash = sdbm_hash(name, strlen(name));
@ -120,25 +115,24 @@ static int parent_name_hash(struct inode *parent, char *name)
return (parent_hash ^ name_hash) % nr_inodes; return (parent_hash ^ name_hash) % nr_inodes;
} }
/*===========================================================================* /*
* parent_index_hash * * Return the hash value of a <parent,index> tuple.
*===========================================================================*/
static int parent_index_hash(struct inode *parent, index_t index)
{
/* Return the hash value of a <parent,index> tuple.
*/ */
static int
parent_index_hash(const struct inode * parent, index_t index)
{
return ((parent - &inode[0]) ^ index) % nr_inodes; return ((int)(parent - &inode[0]) ^ index) % nr_inodes;
} }
/*===========================================================================* /*
* purge_inode * * Delete a deletable inode to make room for a new inode.
*===========================================================================*/
static void purge_inode(struct inode *parent)
{
/* Delete a deletable inode to make room for a new inode.
*/ */
/* An inode is deletable if: static void
purge_inode(struct inode * parent)
{
/*
* An inode is deletable if:
* - it is in use; * - it is in use;
* - it is indexed; * - it is indexed;
* - it is not the given parent inode; * - it is not the given parent inode;
@ -153,7 +147,8 @@ static void purge_inode(struct inode *parent)
assert(TAILQ_EMPTY(&unused_inodes)); assert(TAILQ_EMPTY(&unused_inodes));
/* This should not happen often enough to warrant an extra linked list, /*
* This should not happen often enough to warrant an extra linked list,
* especially as maintenance of that list would be rather error-prone.. * especially as maintenance of that list would be rather error-prone..
*/ */
for (count = 0; count < nr_inodes; count++) { for (count = 0; count < nr_inodes; count++) {
@ -172,15 +167,14 @@ static void purge_inode(struct inode *parent)
} }
} }
/*===========================================================================* /*
* add_inode * * Add an inode.
*===========================================================================*/ */
struct inode *add_inode(struct inode *parent, char *name, struct inode *
index_t index, struct inode_stat *stat, index_t nr_indexed_entries, add_inode(struct inode * parent, const char * name, index_t index,
const struct inode_stat * stat, index_t nr_indexed_entries,
cbdata_t cbdata) cbdata_t cbdata)
{ {
/* Add an inode.
*/
struct inode *newnode; struct inode *newnode;
int slot; int slot;
@ -229,64 +223,59 @@ struct inode *add_inode(struct inode *parent, char *name,
return newnode; return newnode;
} }
/*===========================================================================* /*
* get_root_inode * * Return the file system's root inode.
*===========================================================================*/
struct inode *get_root_inode(void)
{
/* Return the file system's root inode.
*/ */
struct inode *
get_root_inode(void)
{
/* The root node is always the first node in the inode table */ /* The root node is always the first node in the inode table. */
return &inode[0]; return &inode[0];
} }
/*===========================================================================* /*
* get_inode_name * * Return the name that an inode has in its parent directory.
*===========================================================================*/
char const *get_inode_name(struct inode *node)
{
/* Return the name that an inode has in its parent directory.
*/ */
const char *
get_inode_name(const struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
return node->i_name; return node->i_name;
} }
/*===========================================================================* /*
* get_inode_index * * Return the index that an inode has in its parent directory.
*===========================================================================*/
index_t get_inode_index(struct inode *node)
{
/* Return the index that an inode has in its parent directory.
*/ */
index_t
get_inode_index(const struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
return node->i_index; return node->i_index;
} }
/*===========================================================================* /*
* get_inode_cbdata * * Return the callback data associated with the given inode.
*===========================================================================*/
cbdata_t get_inode_cbdata(struct inode *node)
{
/* Return the callback data associated with the given inode.
*/ */
cbdata_t
get_inode_cbdata(const struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
return node->i_cbdata; return node->i_cbdata;
} }
/*===========================================================================* /*
* get_parent_inode * * Return an inode's parent inode.
*===========================================================================*/
struct inode *get_parent_inode(struct inode *node)
{
/* Return an inode's parent inode.
*/ */
struct inode *
get_parent_inode(const struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
@ -297,13 +286,12 @@ struct inode *get_parent_inode(struct inode *node)
return node->i_parent; return node->i_parent;
} }
/*===========================================================================* /*
* get_first_inode * * Return a directory's first (non-deleted) child inode.
*===========================================================================*/
struct inode *get_first_inode(struct inode *parent)
{
/* Return a directory's first (non-deleted) child inode.
*/ */
struct inode *
get_first_inode(const struct inode * parent)
{
struct inode *node; struct inode *node;
CHECK_INODE(parent); CHECK_INODE(parent);
@ -317,13 +305,12 @@ struct inode *get_first_inode(struct inode *parent)
return node; return node;
} }
/*===========================================================================* /*
* get_next_inode * * Return a directory's next (non-deleted) child inode.
*===========================================================================*/
struct inode *get_next_inode(struct inode *previous)
{
/* Return a directory's next (non-deleted) child inode.
*/ */
struct inode *
get_next_inode(const struct inode * previous)
{
struct inode *node; struct inode *node;
CHECK_INODE(previous); CHECK_INODE(previous);
@ -336,52 +323,48 @@ struct inode *get_next_inode(struct inode *previous)
return node; return node;
} }
/*===========================================================================* /*
* get_inode_number * * Return the inode number of the given inode.
*===========================================================================*/
int get_inode_number(struct inode *node)
{
/* Return the inode number of the given inode.
*/ */
int
get_inode_number(const struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
return (int) (node - &inode[0]) + 1; return (int)(node - &inode[0]) + 1;
} }
/*===========================================================================* /*
* get_inode_stat * * Retrieve an inode's status.
*===========================================================================*/
void get_inode_stat(struct inode *node, struct inode_stat *stat)
{
/* Retrieve an inode's status.
*/ */
void
get_inode_stat(const struct inode * node, struct inode_stat * stat)
{
CHECK_INODE(node); CHECK_INODE(node);
*stat = node->i_stat; *stat = node->i_stat;
} }
/*===========================================================================* /*
* set_inode_stat * * Set an inode's status.
*===========================================================================*/
void set_inode_stat(struct inode *node, struct inode_stat *stat)
{
/* Set an inode's status.
*/ */
void
set_inode_stat(struct inode * node, struct inode_stat * stat)
{
CHECK_INODE(node); CHECK_INODE(node);
node->i_stat = *stat; node->i_stat = *stat;
} }
/*===========================================================================* /*
* get_inode_by_name * * Look up an inode using a <parent,name> tuple.
*===========================================================================*/
struct inode *get_inode_by_name(struct inode *parent, char *name)
{
/* Look up an inode using a <parent,name> tuple.
*/ */
struct inode *
get_inode_by_name(const struct inode * parent, const char * name)
{
struct inode *node; struct inode *node;
int slot; int slot;
@ -399,13 +382,12 @@ struct inode *get_inode_by_name(struct inode *parent, char *name)
return NULL; return NULL;
} }
/*===========================================================================* /*
* get_inode_by_index * * Look up an inode using a <parent,index> tuple.
*===========================================================================*/
struct inode *get_inode_by_index(struct inode *parent, index_t index)
{
/* Look up an inode using a <parent,index> tuple.
*/ */
struct inode *
get_inode_by_index(const struct inode * parent, index_t index)
{
struct inode *node; struct inode *node;
int slot; int slot;
@ -423,13 +405,12 @@ struct inode *get_inode_by_index(struct inode *parent, index_t index)
return NULL; return NULL;
} }
/*===========================================================================* /*
* find_inode * * Retrieve an inode by inode number.
*===========================================================================*/
struct inode *find_inode(ino_t num)
{
/* Retrieve an inode by inode number.
*/ */
struct inode *
find_inode(ino_t num)
{
struct inode *node; struct inode *node;
node = &inode[num - 1]; node = &inode[num - 1];
@ -439,13 +420,12 @@ struct inode *find_inode(ino_t num)
return node; return node;
} }
/*===========================================================================* /*
* get_inode * * Retrieve an inode by inode number, and increase its reference count.
*===========================================================================*/
struct inode *get_inode(ino_t num)
{
/* Retrieve an inode by inode number, and increase its reference count.
*/ */
struct inode *
get_inode(ino_t num)
{
struct inode *node; struct inode *node;
if ((node = find_inode(num)) == NULL) if ((node = find_inode(num)) == NULL)
@ -455,46 +435,44 @@ struct inode *get_inode(ino_t num)
return node; return node;
} }
/*===========================================================================* /*
* put_inode * * Decrease an inode's reference count.
*===========================================================================*/
void put_inode(struct inode *node)
{
/* Decrease an inode's reference count.
*/ */
void
put_inode(struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
assert(node->i_count > 0); assert(node->i_count > 0);
node->i_count--; node->i_count--;
/* If the inode is scheduled for deletion, and has no more references, /*
* If the inode is scheduled for deletion, and has no more references,
* actually delete it now. * actually delete it now.
*/ */
if ((node->i_flags & I_DELETED) && node->i_count == 0) if ((node->i_flags & I_DELETED) && node->i_count == 0)
delete_inode(node); delete_inode(node);
} }
/*===========================================================================* /*
* ref_inode * * Increase an inode's reference count.
*===========================================================================*/
void ref_inode(struct inode *node)
{
/* Increase an inode's reference count.
*/ */
void
ref_inode(struct inode * node)
{
CHECK_INODE(node); CHECK_INODE(node);
node->i_count++; node->i_count++;
} }
/*===========================================================================* /*
* unlink_inode * * Unlink the given node from its parent, if it is still linked in.
*===========================================================================*/
static void unlink_inode(struct inode *node)
{
/* Unlink the given node from its parent, if it is still linked in.
*/ */
static void
unlink_inode(struct inode * node)
{
struct inode *parent; struct inode *parent;
assert(node->i_flags & I_DELETED); assert(node->i_flags & I_DELETED);
@ -513,25 +491,24 @@ static void unlink_inode(struct inode *node)
delete_inode(parent); delete_inode(parent);
} }
/*===========================================================================* /*
* delete_inode * * Delete the given inode. If its reference count is nonzero, or it still has
*===========================================================================*/ * children that cannot be deleted for the same reason, keep the inode around
void delete_inode(struct inode *node) * for the time being. If the node is a directory, keep around its parent so
{ * that we can still do a "cd .." out of it. For these reasons, this function
/* Delete the given inode. If its reference count is nonzero, or it * may be called on an inode more than once before it is actually deleted.
* still has children that cannot be deleted for the same reason, keep
* the inode around for the time being. If the node is a directory,
* keep around its parent so that we can still do a "cd .." out of it.
* For these reasons, this function may be called on an inode more than
* once before it is actually deleted.
*/ */
void
delete_inode(struct inode * node)
{
struct inode *cnode, *ctmp; struct inode *cnode, *ctmp;
CHECK_INODE(node); CHECK_INODE(node);
assert(node != &inode[0]); assert(node != &inode[0]);
/* If the inode was not already scheduled for deletion, /*
* partially remove the node. * If the inode was not already scheduled for deletion, partially
* remove the node.
*/ */
if (!(node->i_flags & I_DELETED)) { if (!(node->i_flags & I_DELETED)) {
/* Remove any children first (before I_DELETED is set!). */ /* Remove any children first (before I_DELETED is set!). */
@ -547,7 +524,8 @@ void delete_inode(struct inode *node)
node->i_flags |= I_DELETED; node->i_flags |= I_DELETED;
/* If this inode is not a directory, we don't care about being /*
* If this inode is not a directory, we don't care about being
* able to find its parent. Unlink it from the parent now. * able to find its parent. Unlink it from the parent now.
*/ */
if (!S_ISDIR(node->i_stat.mode)) if (!S_ISDIR(node->i_stat.mode))
@ -555,7 +533,8 @@ void delete_inode(struct inode *node)
} }
if (node->i_count == 0 && TAILQ_EMPTY(&node->i_children)) { if (node->i_count == 0 && TAILQ_EMPTY(&node->i_children)) {
/* If this inode still has a parent at this point, unlink it /*
* If this inode still has a parent at this point, unlink it
* now; noone can possibly refer to it anymore. * now; noone can possibly refer to it anymore.
*/ */
if (node->i_parent != NULL) if (node->i_parent != NULL)
@ -566,25 +545,23 @@ void delete_inode(struct inode *node)
} }
} }
/*===========================================================================* /*
* is_inode_deleted * * Return whether the given inode has been deleted.
*===========================================================================*/
int is_inode_deleted(struct inode *node)
{
/* Return whether the given inode has been deleted.
*/ */
int
is_inode_deleted(const struct inode * node)
{
return (node->i_flags & I_DELETED); return (node->i_flags & I_DELETED);
} }
/*===========================================================================* /*
* fs_putnode * * Find the inode specified by the request message, and decrease its reference
*===========================================================================*/ * count.
int fs_putnode(ino_t ino_nr, unsigned int count)
{
/* Find the inode specified by the request message, and decrease its
* reference count.
*/ */
int
fs_putnode(ino_t ino_nr, unsigned int count)
{
struct inode *node; struct inode *node;
/* Get the inode specified by its number. */ /* Get the inode specified by its number. */

View file

@ -1,7 +1,8 @@
#ifndef _VTREEFS_INODE_H #ifndef _VTREEFS_INODE_H
#define _VTREEFS_INODE_H #define _VTREEFS_INODE_H
/* The inodes that are active, form a fully connected tree. Each node except /*
* The inodes that are active, form a fully connected tree. Each node except
* the root node has a parent and a tail queue of children, where each child * the root node has a parent and a tail queue of children, where each child
* inode points to the "next" and "previous" inode with a common parent. * inode points to the "next" and "previous" inode with a common parent.
* *

View file

@ -1,14 +1,13 @@
/* VTreeFS - link.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - link.c - support for symbolic links */
#include "inc.h" #include "inc.h"
/*===========================================================================* /*
* fs_rdlink * * Retrieve symbolic link target.
*===========================================================================*/
ssize_t fs_rdlink(ino_t ino_nr, struct fsdriver_data *data, size_t bytes)
{
/* Retrieve symbolic link target.
*/ */
ssize_t
fs_rdlink(ino_t ino_nr, struct fsdriver_data * data, size_t bytes)
{
char path[PATH_MAX]; char path[PATH_MAX];
struct inode *node; struct inode *node;
size_t len; size_t len;
@ -17,7 +16,10 @@ ssize_t fs_rdlink(ino_t ino_nr, struct fsdriver_data *data, size_t bytes)
if ((node = find_inode(ino_nr)) == NULL) if ((node = find_inode(ino_nr)) == NULL)
return EINVAL; return EINVAL;
/* Call the rdlink hook. */ /*
* Call the rdlink hook. The hook must be non-NULL if the file system
* adds symlink nodes. If it doesn't, we will never get here.
*/
assert(vtreefs_hooks->rdlink_hook != NULL); assert(vtreefs_hooks->rdlink_hook != NULL);
assert(!is_inode_deleted(node)); /* symlinks cannot be opened */ assert(!is_inode_deleted(node)); /* symlinks cannot be opened */

View file

@ -1,22 +1,21 @@
/* VTreeFS - mount.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - mount.c - mounting and unmounting */
#include "inc.h" #include "inc.h"
#include <minix/vfsif.h> #include <minix/vfsif.h>
/*===========================================================================* /*
* fs_mount * * Mount the file system. Obtain the root inode and send back its details.
*===========================================================================*/
int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node,
unsigned int *res_flags)
{
/* This function gets the root inode and sends back its details.
*/ */
int
fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node * root_node,
unsigned int * res_flags)
{
struct inode *root; struct inode *root;
/* Get the device number, for stat requests. */ /* Get the device number, for stat requests. */
fs_dev = dev; fs_dev = dev;
/* The VTreeFS must not be mounted as a root file system. */ /* VTreeFS must not be mounted as a root file system. */
if (flags & REQ_ISROOT) if (flags & REQ_ISROOT)
return EINVAL; return EINVAL;
@ -41,13 +40,12 @@ int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node,
return OK; return OK;
} }
/*===========================================================================* /*
* fs_unmount * * Unmount the file system.
*===========================================================================*/
void fs_unmount(void)
{
/* Unmount the file system.
*/ */
void
fs_unmount(void)
{
struct inode *root; struct inode *root;
/* Decrease the count of the root inode. */ /* Decrease the count of the root inode. */

View file

@ -1,15 +1,14 @@
/* VTreeFS - path.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - path.c - name resolution */
#include "inc.h" #include "inc.h"
/*===========================================================================* /*
* fs_lookup * * Resolve a path string to an inode.
*===========================================================================*/
int fs_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node_details,
int *is_mountpt)
{
/* Resolve a path string to an inode.
*/ */
int
fs_lookup(ino_t dir_nr, char * name, struct fsdriver_node * node_details,
int * is_mountpt)
{
struct inode *node, *child; struct inode *node, *child;
int r; int r;

View file

@ -9,8 +9,8 @@ struct inode *find_inode(ino_t num);
struct inode *get_inode(ino_t num); struct inode *get_inode(ino_t num);
void put_inode(struct inode *node); void put_inode(struct inode *node);
void ref_inode(struct inode *node); void ref_inode(struct inode *node);
int get_inode_number(struct inode *node); int get_inode_number(const struct inode *node);
int is_inode_deleted(struct inode *node); int is_inode_deleted(const struct inode *node);
int fs_putnode(ino_t ino_nr, unsigned int count); int fs_putnode(ino_t ino_nr, unsigned int count);
/* link.c */ /* link.c */
@ -35,7 +35,7 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
off_t *pos); off_t *pos);
/* sdbm.c */ /* sdbm.c */
long sdbm_hash(char *str, int len); long sdbm_hash(const char *str, int len);
/* stadir.c */ /* stadir.c */
int fs_stat(ino_t ino_nr, struct stat *buf); int fs_stat(ino_t ino_nr, struct stat *buf);

View file

@ -1,18 +1,17 @@
/* VTreeFS - read.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - read.c - reading from files and directories */
#include "inc.h" #include "inc.h"
#include <dirent.h> #include <dirent.h>
#define GETDENTS_BUFSIZ 4096 #define GETDENTS_BUFSIZ 4096
/*===========================================================================* /*
* fs_read * * Read from a file.
*===========================================================================*/ */
ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, ssize_t
fs_read(ino_t ino_nr, struct fsdriver_data * data, size_t bytes,
off_t pos, int __unused call) off_t pos, int __unused call)
{ {
/* Read from a file.
*/
struct inode *node; struct inode *node;
size_t len; size_t len;
char *ptr; char *ptr;
@ -30,7 +29,8 @@ ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
if (!is_inode_deleted(node) && vtreefs_hooks->read_hook != NULL) { if (!is_inode_deleted(node) && vtreefs_hooks->read_hook != NULL) {
len = bytes; len = bytes;
/* On success, the read hook provides us with a pointer to the /*
* On success, the read hook provides us with a pointer to the
* resulting data. This avoids copying overhead. * resulting data. This avoids copying overhead.
*/ */
r = vtreefs_hooks->read_hook(node, pos, &ptr, &len, r = vtreefs_hooks->read_hook(node, pos, &ptr, &len,
@ -50,14 +50,13 @@ ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
return (r != OK) ? r : len; return (r != OK) ? r : len;
} }
/*===========================================================================* /*
* fs_getdents * * Retrieve directory entries.
*===========================================================================*/
ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
off_t *posp)
{
/* Retrieve directory entries.
*/ */
ssize_t
fs_getdents(ino_t ino_nr, struct fsdriver_data * data, size_t bytes,
off_t * posp)
{
struct fsdriver_dentry fsdentry; struct fsdriver_dentry fsdentry;
struct inode *node, *child; struct inode *node, *child;
const char *name; const char *name;
@ -78,7 +77,8 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
/* Call the getdents hook, if any, to "refresh" the directory. */ /* Call the getdents hook, if any, to "refresh" the directory. */
if (!is_inode_deleted(node) && vtreefs_hooks->getdents_hook != NULL) { if (!is_inode_deleted(node) && vtreefs_hooks->getdents_hook != NULL) {
r = vtreefs_hooks->getdents_hook(node, get_inode_cbdata(node)); r = vtreefs_hooks->getdents_hook(node, get_inode_cbdata(node));
if (r != OK) return r; if (r != OK)
return r;
} }
fsdriver_dentry_init(&fsdentry, data, bytes, buf, sizeof(buf)); fsdriver_dentry_init(&fsdentry, data, bytes, buf, sizeof(buf));
@ -91,29 +91,27 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
/* The "." entry. */ /* The "." entry. */
child = node; child = node;
name = "."; name = ".";
} } else if (pos == 1) {
else if (pos == 1) {
/* The ".." entry. */ /* The ".." entry. */
child = get_parent_inode(node); child = get_parent_inode(node);
if (child == NULL) if (child == NULL)
child = node; child = node;
name = ".."; name = "..";
} } else if (pos - 2 < indexed) {
else if (pos - 2 < indexed) {
/* All indexed entries. */ /* All indexed entries. */
child = get_inode_by_index(node, pos - 2); child = get_inode_by_index(node, pos - 2);
/* If there is no inode with this particular index, /*
* If there is no inode with this particular index,
* continue with the next index number. * continue with the next index number.
*/ */
if (child == NULL) continue; if (child == NULL) continue;
name = child->i_name; name = child->i_name;
} } else {
else {
/* All non-indexed entries. */ /* All non-indexed entries. */
/*
/* If this is the first loop iteration, first get to * If this is the first loop iteration, first get to
* the non-indexed child identified by the current * the non-indexed child identified by the current
* position. * position.
*/ */
@ -131,10 +129,8 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
child = get_next_inode(child); child = get_next_inode(child);
get_next = TRUE; get_next = TRUE;
} } else
else {
child = get_next_inode(child); child = get_next_inode(child);
}
/* No more children? Then stop. */ /* No more children? Then stop. */
if (child == NULL) if (child == NULL)
@ -147,7 +143,7 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
/* Add the directory entry to the output. */ /* Add the directory entry to the output. */
r = fsdriver_dentry_add(&fsdentry, r = fsdriver_dentry_add(&fsdentry,
(ino_t) get_inode_number(child), name, strlen(name), (ino_t)get_inode_number(child), name, strlen(name),
IFTODT(child->i_stat.mode)); IFTODT(child->i_stat.mode));
if (r < 0) if (r < 0)
return r; return r;

View file

@ -1,4 +1,4 @@
/* VTreeFS - sdbm.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - sdbm.c - sdbm hash function */
/* /*
* sdbm - ndbm work-alike hashed database library * sdbm - ndbm work-alike hashed database library
@ -10,6 +10,7 @@
*/ */
#include "inc.h" #include "inc.h"
/* /*
* polynomial conversion ignoring overflows * polynomial conversion ignoring overflows
* [this seems to work remarkably well, in fact better * [this seems to work remarkably well, in fact better
@ -17,7 +18,8 @@
* use: 65599 nice. * use: 65599 nice.
* 65587 even better. * 65587 even better.
*/ */
long sdbm_hash(char *str, int len) long
sdbm_hash(const char *str, int len)
{ {
unsigned long n = 0; unsigned long n = 0;

View file

@ -1,14 +1,13 @@
/* VTreeFS - stadir.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - stadir.c - file and file system status retrieval */
#include "inc.h" #include "inc.h"
/*===========================================================================* /*
* fs_stat * * Retrieve file status.
*===========================================================================*/
int fs_stat(ino_t ino_nr, struct stat *buf)
{
/* Retrieve file status.
*/ */
int
fs_stat(ino_t ino_nr, struct stat * buf)
{
char path[PATH_MAX]; char path[PATH_MAX];
time_t cur_time; time_t cur_time;
struct inode *node; struct inode *node;
@ -45,13 +44,12 @@ int fs_stat(ino_t ino_nr, struct stat *buf)
return OK; return OK;
} }
/*===========================================================================* /*
* fs_statvfs * * Retrieve file system statistics.
*===========================================================================*/
int fs_statvfs(struct statvfs *buf)
{
/* Retrieve file system statistics.
*/ */
int
fs_statvfs(struct statvfs * buf)
{
buf->f_flag = ST_NOTRUNC; buf->f_flag = ST_NOTRUNC;
buf->f_namemax = PNAME_MAX; buf->f_namemax = PNAME_MAX;

View file

@ -1,4 +1,4 @@
/* VTreeFS - table.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - table.c - file system driver callback table */
#define _TABLE #define _TABLE
#include "inc.h" #include "inc.h"

View file

@ -1,4 +1,4 @@
/* VTreeFS - vtreefs.c - by Alen Stojanov and David van Moolenbroek */ /* VTreeFS - vtreefs.c - initialization and message loop */
#include "inc.h" #include "inc.h"
@ -6,13 +6,12 @@ static unsigned int inodes;
static struct inode_stat *root_stat; static struct inode_stat *root_stat;
static index_t root_entries; static index_t root_entries;
/*===========================================================================* /*
* init_server * * Initialize internal state, and register with VFS.
*===========================================================================*/
static int init_server(int UNUSED(type), sef_init_info_t *UNUSED(info))
{
/* Initialize internal state, and register with VFS.
*/ */
static int
init_server(int __unused type, sef_init_info_t * __unused info)
{
/* Initialize the virtual tree. */ /* Initialize the virtual tree. */
init_inodes(inodes, root_stat, root_entries); init_inodes(inodes, root_stat, root_entries);
@ -20,13 +19,12 @@ static int init_server(int UNUSED(type), sef_init_info_t *UNUSED(info))
return OK; return OK;
} }
/*===========================================================================* /*
* got_signal * * We received a signal.
*===========================================================================*/
static void got_signal(int signal)
{
/* We received a signal.
*/ */
static void
got_signal(int signal)
{
if (signal != SIGTERM) if (signal != SIGTERM)
return; return;
@ -34,11 +32,13 @@ static void got_signal(int signal)
fsdriver_terminate(); fsdriver_terminate();
} }
/*===========================================================================* /*
* sef_local_startup * * SEF initialization.
*===========================================================================*/ */
static void sef_local_startup(void) static void
sef_local_startup(void)
{ {
sef_setcb_init_fresh(init_server); sef_setcb_init_fresh(init_server);
sef_setcb_init_restart(init_server); sef_setcb_init_restart(init_server);
@ -49,18 +49,18 @@ static void sef_local_startup(void)
sef_startup(); sef_startup();
} }
/*===========================================================================* /*
* fs_other * * We have received a message that is not a file system request from VFS.
*===========================================================================*/ * Call the message hook, if there is one.
void fs_other(const message *m_ptr, int __unused ipc_status)
{
/* We received a message that is not among the recognized file system
* requests. Call the message hook, if there is one.
*/ */
void
fs_other(const message * m_ptr, int __unused ipc_status)
{
message msg; message msg;
if (vtreefs_hooks->message_hook != NULL) { if (vtreefs_hooks->message_hook != NULL) {
/* Not all of vtreefs's users play nice with the message, so /*
* Not all of vtreefs's users play nice with the message, so
* make a copy to allow it to be modified. * make a copy to allow it to be modified.
*/ */
msg = *m_ptr; msg = *m_ptr;
@ -69,18 +69,18 @@ void fs_other(const message *m_ptr, int __unused ipc_status)
} }
} }
/*===========================================================================* /*
* start_vtreefs * * This is the main routine of this service. It uses the main loop as provided
*===========================================================================*/ * by the fsdriver library. The routine returns once the file system has been
void start_vtreefs(struct fs_hooks *hooks, unsigned int nr_inodes, * unmounted and the process is signaled to exit.
struct inode_stat *stat, index_t nr_indexed_entries)
{
/* This is the main routine of this service. It uses the main loop as
* provided by the fsdriver library. The routine returns once the file
* system has been unmounted and the process is signaled to exit.
*/ */
void
start_vtreefs(struct fs_hooks * hooks, unsigned int nr_inodes,
struct inode_stat * stat, index_t nr_indexed_entries)
{
/* Use global variables to work around the inability to pass parameters /*
* Use global variables to work around the inability to pass parameters
* through SEF to the initialization function.. * through SEF to the initialization function..
*/ */
vtreefs_hooks = hooks; vtreefs_hooks = hooks;