int (*message_hook)(message *m);
};
-extern struct inode *add_inode(struct inode *parent, char *name, index_t index,
- struct inode_stat *stat, index_t nr_indexed_entries, cbdata_t cbdata);
+extern struct inode *add_inode(struct inode *parent, const char *name,
+ index_t index, const struct inode_stat *stat,
+ index_t nr_indexed_entries, cbdata_t cbdata);
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_index(struct inode *parent, index_t index);
+extern struct inode *get_inode_by_name(const struct inode *parent,
+ 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 index_t get_inode_index(struct inode *inode);
-extern cbdata_t get_inode_cbdata(struct inode *inode);
+extern const char *get_inode_name(const struct inode *inode);
+extern index_t get_inode_index(const struct inode *inode);
+extern cbdata_t get_inode_cbdata(const struct inode *inode);
extern struct inode *get_root_inode(void);
-extern struct inode *get_parent_inode(struct inode *inode);
-extern struct inode *get_first_inode(struct inode *parent);
-extern struct inode *get_next_inode(struct inode *previous);
+extern struct inode *get_parent_inode(const struct inode *inode);
+extern struct inode *get_first_inode(const struct inode *parent);
+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 start_vtreefs(struct fs_hooks *hooks, unsigned int nr_inodes,
-/* VTreeFS - inode.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - inode.c - inode management */
#include "inc.h"
#define CHECK_INODE(node) \
do { \
assert(node >= &inode[0] && node < &inode[nr_inodes]); \
- assert(node == &inode[0] || \
- node->i_parent != NULL || \
- (node->i_flags & I_DELETED)); \
+ assert(node == &inode[0] || node->i_parent != NULL || \
+ (node->i_flags & I_DELETED)); \
} while (0);
-/*===========================================================================*
- * init_inodes *
- *===========================================================================*/
-void init_inodes(unsigned int inodes, struct inode_stat *stat,
+/*
+ * Initialize the inode-related state.
+ */
+void
+init_inodes(unsigned int inodes, struct inode_stat * stat,
index_t nr_indexed_entries)
{
- /* Initialize the inode-related state.
- */
struct inode *node;
unsigned int i;
#if DEBUG
printf("VTREEFS: allocated %d+%d+%d bytes\n",
- nr_inodes * sizeof(inode[0]),
- nr_inodes * sizeof(parent_name_head[0]),
- nr_inodes * sizeof(parent_index_head[0]));
+ nr_inodes * sizeof(inode[0]),
+ nr_inodes * sizeof(parent_name_head[0]),
+ nr_inodes * sizeof(parent_index_head[0]));
#endif
/* Initialize the free/unused list. */
TAILQ_INIT(&unused_inodes);
- /* Add free inodes to the unused/free list. Skip the root inode. */
+ /* Add free inodes to the unused/free list. Skip the root inode. */
for (i = 1; i < nr_inodes; i++) {
node = &inode[i];
node->i_cbdata = NULL;
}
-/*===========================================================================*
- * cleanup_inodes *
- *===========================================================================*/
-void cleanup_inodes(void)
+/*
+ * Clean up the inode-related state.
+ */
+void
+cleanup_inodes(void)
{
- /* Clean up the inode-related state.
- */
/* Free the inode and hash tables. */
free(parent_index_head);
free(inode);
}
-/*===========================================================================*
- * parent_name_hash *
- *===========================================================================*/
-static int parent_name_hash(struct inode *parent, char *name)
+/*
+ * Return the hash value of <parent,name> tuple.
+ */
+static int
+parent_name_hash(const struct inode * parent, const char *name)
{
- /* Return the hash value of <parent,name> tuple.
- */
- unsigned int name_hash;
- unsigned long parent_hash;
+ unsigned int name_hash, parent_hash;
/* 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. */
name_hash = sdbm_hash(name, strlen(name));
return (parent_hash ^ name_hash) % nr_inodes;
}
-/*===========================================================================*
- * parent_index_hash *
- *===========================================================================*/
-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 the hash value of a <parent,index> tuple.
- */
- return ((parent - &inode[0]) ^ index) % nr_inodes;
+ return ((int)(parent - &inode[0]) ^ index) % nr_inodes;
}
-/*===========================================================================*
- * purge_inode *
- *===========================================================================*/
-static void purge_inode(struct inode *parent)
+/*
+ * 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:
+ /*
+ * An inode is deletable if:
* - it is in use;
* - it is indexed;
* - it is not the given parent inode;
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..
*/
for (count = 0; count < nr_inodes; count++) {
last_checked = (last_checked + 1) % nr_inodes;
if (node != parent && node->i_index != NO_INDEX &&
- node->i_count == 0 && TAILQ_EMPTY(&node->i_children)) {
+ node->i_count == 0 && TAILQ_EMPTY(&node->i_children)) {
assert(!(node->i_flags & I_DELETED));
}
}
-/*===========================================================================*
- * add_inode *
- *===========================================================================*/
-struct inode *add_inode(struct inode *parent, char *name,
- index_t index, struct inode_stat *stat, index_t nr_indexed_entries,
+/*
+ * Add an inode.
+ */
+struct inode *
+add_inode(struct inode * parent, const char * name, index_t index,
+ const struct inode_stat * stat, index_t nr_indexed_entries,
cbdata_t cbdata)
{
- /* Add an inode.
- */
struct inode *newnode;
int slot;
assert(nr_indexed_entries >= 0);
assert(get_inode_by_name(parent, name) == NULL);
- /* Get a free inode. Free one up if necessary. */
+ /* Get a free inode. Free one up if necessary. */
if (TAILQ_EMPTY(&unused_inodes))
purge_inode(parent);
return newnode;
}
-/*===========================================================================*
- * get_root_inode *
- *===========================================================================*/
-struct inode *get_root_inode(void)
+/*
+ * Return the file system's root inode.
+ */
+struct inode *
+get_root_inode(void)
{
- /* Return the file system's root inode.
- */
- /* 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];
}
-/*===========================================================================*
- * get_inode_name *
- *===========================================================================*/
-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)
{
- /* Return the name that an inode has in its parent directory.
- */
CHECK_INODE(node);
return node->i_name;
}
-/*===========================================================================*
- * get_inode_index *
- *===========================================================================*/
-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)
{
- /* Return the index that an inode has in its parent directory.
- */
CHECK_INODE(node);
return node->i_index;
}
-/*===========================================================================*
- * get_inode_cbdata *
- *===========================================================================*/
-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)
{
- /* Return the callback data associated with the given inode.
- */
CHECK_INODE(node);
return node->i_cbdata;
}
-/*===========================================================================*
- * get_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)
{
- /* Return an inode's parent inode.
- */
CHECK_INODE(node);
return node->i_parent;
}
-/*===========================================================================*
- * get_first_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)
{
- /* Return a directory's first (non-deleted) child inode.
- */
struct inode *node;
CHECK_INODE(parent);
return node;
}
-/*===========================================================================*
- * get_next_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)
{
- /* Return a directory's next (non-deleted) child inode.
- */
struct inode *node;
CHECK_INODE(previous);
return node;
}
-/*===========================================================================*
- * get_inode_number *
- *===========================================================================*/
-int get_inode_number(struct inode *node)
+/*
+ * Return the inode number of the given inode.
+ */
+int
+get_inode_number(const struct inode * node)
{
- /* Return the inode number of the given inode.
- */
CHECK_INODE(node);
- return (int) (node - &inode[0]) + 1;
+ return (int)(node - &inode[0]) + 1;
}
-/*===========================================================================*
- * get_inode_stat *
- *===========================================================================*/
-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)
{
- /* Retrieve an inode's status.
- */
CHECK_INODE(node);
*stat = node->i_stat;
}
-/*===========================================================================*
- * set_inode_stat *
- *===========================================================================*/
-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)
{
- /* Set an inode's status.
- */
CHECK_INODE(node);
node->i_stat = *stat;
}
-/*===========================================================================*
- * get_inode_by_name *
- *===========================================================================*/
-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)
{
- /* Look up an inode using a <parent,name> tuple.
- */
struct inode *node;
int slot;
return NULL;
}
-/*===========================================================================*
- * get_inode_by_index *
- *===========================================================================*/
-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)
{
- /* Look up an inode using a <parent,index> tuple.
- */
struct inode *node;
int slot;
return NULL;
}
-/*===========================================================================*
- * find_inode *
- *===========================================================================*/
-struct inode *find_inode(ino_t num)
+/*
+ * Retrieve an inode by inode number.
+ */
+struct inode *
+find_inode(ino_t num)
{
- /* Retrieve an inode by inode number.
- */
struct inode *node;
node = &inode[num - 1];
return node;
}
-/*===========================================================================*
- * get_inode *
- *===========================================================================*/
-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)
{
- /* Retrieve an inode by inode number, and increase its reference count.
- */
struct inode *node;
if ((node = find_inode(num)) == NULL)
return node;
}
-/*===========================================================================*
- * put_inode *
- *===========================================================================*/
-void put_inode(struct inode *node)
+/*
+ * Decrease an inode's reference count.
+ */
+void
+put_inode(struct inode * node)
{
- /* Decrease an inode's reference count.
- */
CHECK_INODE(node);
assert(node->i_count > 0);
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.
*/
if ((node->i_flags & I_DELETED) && node->i_count == 0)
delete_inode(node);
}
-/*===========================================================================*
- * ref_inode *
- *===========================================================================*/
-void ref_inode(struct inode *node)
+/*
+ * Increase an inode's reference count.
+ */
+void
+ref_inode(struct inode * node)
{
- /* Increase an inode's reference count.
- */
CHECK_INODE(node);
node->i_count++;
}
-/*===========================================================================*
- * unlink_inode *
- *===========================================================================*/
-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)
{
- /* Unlink the given node from its parent, if it is still linked in.
- */
struct inode *parent;
assert(node->i_flags & I_DELETED);
delete_inode(parent);
}
-/*===========================================================================*
- * delete_inode *
- *===========================================================================*/
-void delete_inode(struct inode *node)
+/*
+ * 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
+ * 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)
{
- /* 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 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.
- */
struct inode *cnode, *ctmp;
CHECK_INODE(node);
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)) {
/* Remove any children first (before I_DELETED is set!). */
node->i_flags |= I_DELETED;
- /* If this inode is not a directory, we don't care about being
- * able to find its parent. Unlink it from the parent now.
+ /*
+ * If this inode is not a directory, we don't care about being
+ * able to find its parent. Unlink it from the parent now.
*/
if (!S_ISDIR(node->i_stat.mode))
unlink_inode(node);
}
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.
*/
if (node->i_parent != NULL)
}
}
-/*===========================================================================*
- * is_inode_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 whether the given inode has been deleted.
- */
return (node->i_flags & I_DELETED);
}
-/*===========================================================================*
- * fs_putnode *
- *===========================================================================*/
-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)
{
- /* Find the inode specified by the request message, and decrease its
- * reference count.
- */
struct inode *node;
/* Get the inode specified by its number. */
#ifndef _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
* inode points to the "next" and "previous" inode with a common parent.
*
* <parent,name> -> inode hashtable, and if it has an index into the parent,
* is part of a <parent,index> -> inode hashtable.
*
- * Inodes that are not active, are either deleted or free. A deleted inode is
+ * Inodes that are not active, are either deleted or free. A deleted inode is
* in use as long as it still has a nonzero reference count, even though it is
- * no longer part of the tree. Inodes that are free, are part of the list of
+ * no longer part of the tree. Inodes that are free, are part of the list of
* unused inodes.
*/
struct inode {
-/* VTreeFS - link.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - link.c - support for symbolic links */
#include "inc.h"
-/*===========================================================================*
- * fs_rdlink *
- *===========================================================================*/
-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)
{
- /* Retrieve symbolic link target.
- */
char path[PATH_MAX];
struct inode *node;
size_t len;
if ((node = find_inode(ino_nr)) == NULL)
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(!is_inode_deleted(node)); /* symlinks cannot be opened */
r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path),
- get_inode_cbdata(node));
+ get_inode_cbdata(node));
if (r != OK) return r;
len = strlen(path);
-/* VTreeFS - mount.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - mount.c - mounting and unmounting */
#include "inc.h"
#include <minix/vfsif.h>
-/*===========================================================================*
- * fs_mount *
- *===========================================================================*/
-int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node,
- unsigned int *res_flags)
+/*
+ * 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.
- */
struct inode *root;
/* Get the device number, for stat requests. */
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)
return EINVAL;
root = get_root_inode();
ref_inode(root);
- /* The system is now mounted. Call the initialization hook. */
+ /* The system is now mounted. Call the initialization hook. */
if (vtreefs_hooks->init_hook != NULL)
vtreefs_hooks->init_hook();
return OK;
}
-/*===========================================================================*
- * fs_unmount *
- *===========================================================================*/
-void fs_unmount(void)
+/*
+ * Unmount the file system.
+ */
+void
+fs_unmount(void)
{
- /* Unmount the file system.
- */
struct inode *root;
/* Decrease the count of the root inode. */
put_inode(root);
- /* The system is unmounted. Call the cleanup hook. */
+ /* The system is unmounted. Call the cleanup hook. */
if (vtreefs_hooks->cleanup_hook != NULL)
vtreefs_hooks->cleanup_hook();
}
-/* VTreeFS - path.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - path.c - name resolution */
#include "inc.h"
-/*===========================================================================*
- * fs_lookup *
- *===========================================================================*/
-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)
{
- /* Resolve a path string to an inode.
- */
struct inode *node, *child;
int r;
if ((child = get_parent_inode(node)) == NULL)
return ENOENT; /* deleted? should not be possible */
} else {
- /* Progress into a directory entry. Call the lookup hook, if
+ /* Progress into a directory entry. Call the lookup hook, if
* present, before doing the actual lookup.
*/
if (!is_inode_deleted(node) &&
vtreefs_hooks->lookup_hook != NULL) {
r = vtreefs_hooks->lookup_hook(node, name,
- get_inode_cbdata(node));
+ get_inode_cbdata(node));
if (r != OK) return r;
}
struct inode *get_inode(ino_t num);
void put_inode(struct inode *node);
void ref_inode(struct inode *node);
-int get_inode_number(struct inode *node);
-int is_inode_deleted(struct inode *node);
+int get_inode_number(const struct inode *node);
+int is_inode_deleted(const struct inode *node);
int fs_putnode(ino_t ino_nr, unsigned int count);
/* link.c */
off_t *pos);
/* sdbm.c */
-long sdbm_hash(char *str, int len);
+long sdbm_hash(const char *str, int len);
/* stadir.c */
int fs_stat(ino_t ino_nr, struct stat *buf);
-/* VTreeFS - read.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - read.c - reading from files and directories */
#include "inc.h"
#include <dirent.h>
#define GETDENTS_BUFSIZ 4096
-/*===========================================================================*
- * fs_read *
- *===========================================================================*/
-ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
+/*
+ * Read from a file.
+ */
+ssize_t
+fs_read(ino_t ino_nr, struct fsdriver_data * data, size_t bytes,
off_t pos, int __unused call)
{
- /* Read from a file.
- */
struct inode *node;
size_t len;
char *ptr;
if (!is_inode_deleted(node) && vtreefs_hooks->read_hook != NULL) {
len = bytes;
- /* On success, the read hook provides us with a pointer to the
- * resulting data. This avoids copying overhead.
+ /*
+ * On success, the read hook provides us with a pointer to the
+ * resulting data. This avoids copying overhead.
*/
r = vtreefs_hooks->read_hook(node, pos, &ptr, &len,
get_inode_cbdata(node));
return (r != OK) ? r : len;
}
-/*===========================================================================*
- * fs_getdents *
- *===========================================================================*/
-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)
{
- /* Retrieve directory entries.
- */
struct fsdriver_dentry fsdentry;
struct inode *node, *child;
const char *name;
/* Call the getdents hook, if any, to "refresh" the directory. */
if (!is_inode_deleted(node) && vtreefs_hooks->getdents_hook != NULL) {
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));
/* The "." entry. */
child = node;
name = ".";
- }
- else if (pos == 1) {
+ } else if (pos == 1) {
/* The ".." entry. */
child = get_parent_inode(node);
if (child == NULL)
child = node;
name = "..";
- }
- else if (pos - 2 < indexed) {
+ } else if (pos - 2 < indexed) {
/* All indexed entries. */
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.
*/
if (child == NULL) continue;
name = child->i_name;
- }
- else {
+ } else {
/* 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
* position.
*/
/* Skip indexed children. */
while (child != NULL &&
- child->i_index != NO_INDEX)
+ child->i_index != NO_INDEX)
child = get_next_inode(child);
/* Skip to the right position. */
child = get_next_inode(child);
get_next = TRUE;
- }
- else {
+ } else
child = get_next_inode(child);
- }
/* No more children? Then stop. */
if (child == NULL)
/* Add the directory entry to the output. */
r = fsdriver_dentry_add(&fsdentry,
- (ino_t) get_inode_number(child), name, strlen(name),
- IFTODT(child->i_stat.mode));
+ (ino_t)get_inode_number(child), name, strlen(name),
+ IFTODT(child->i_stat.mode));
if (r < 0)
return r;
} while (r > 0);
-/* VTreeFS - sdbm.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - sdbm.c - sdbm hash function */
/*
* sdbm - ndbm work-alike hashed database library
*/
#include "inc.h"
+
/*
* polynomial conversion ignoring overflows
* [this seems to work remarkably well, in fact better
* use: 65599 nice.
* 65587 even better.
*/
-long sdbm_hash(char *str, int len)
+long
+sdbm_hash(const char *str, int len)
{
unsigned long n = 0;
-/* VTreeFS - stadir.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - stadir.c - file and file system status retrieval */
#include "inc.h"
-/*===========================================================================*
- * fs_stat *
- *===========================================================================*/
-int fs_stat(ino_t ino_nr, struct stat *buf)
+/*
+ * Retrieve file status.
+ */
+int
+fs_stat(ino_t ino_nr, struct stat * buf)
{
- /* Retrieve file status.
- */
char path[PATH_MAX];
time_t cur_time;
struct inode *node;
/* If it is a symbolic link, return the size of the link target. */
if (S_ISLNK(node->i_stat.mode) && vtreefs_hooks->rdlink_hook != NULL) {
r = vtreefs_hooks->rdlink_hook(node, path, sizeof(path),
- get_inode_cbdata(node));
+ get_inode_cbdata(node));
if (r == OK)
buf->st_size = strlen(path);
return OK;
}
-/*===========================================================================*
- * fs_statvfs *
- *===========================================================================*/
-int fs_statvfs(struct statvfs *buf)
+/*
+ * Retrieve file system statistics.
+ */
+int
+fs_statvfs(struct statvfs * buf)
{
- /* Retrieve file system statistics.
- */
buf->f_flag = ST_NOTRUNC;
buf->f_namemax = PNAME_MAX;
-/* VTreeFS - table.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - table.c - file system driver callback table */
#define _TABLE
#include "inc.h"
-/* VTreeFS - vtreefs.c - by Alen Stojanov and David van Moolenbroek */
+/* VTreeFS - vtreefs.c - initialization and message loop */
#include "inc.h"
static struct inode_stat *root_stat;
static index_t root_entries;
-/*===========================================================================*
- * init_server *
- *===========================================================================*/
-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 internal state, and register with VFS.
- */
/* Initialize the virtual tree. */
init_inodes(inodes, root_stat, root_entries);
return OK;
}
-/*===========================================================================*
- * got_signal *
- *===========================================================================*/
-static void got_signal(int signal)
+/*
+ * We received a signal.
+ */
+static void
+got_signal(int signal)
{
- /* We received a signal.
- */
if (signal != SIGTERM)
return;
fsdriver_terminate();
}
-/*===========================================================================*
- * sef_local_startup *
- *===========================================================================*/
-static void sef_local_startup(void)
+/*
+ * SEF initialization.
+ */
+static void
+sef_local_startup(void)
{
+
sef_setcb_init_fresh(init_server);
sef_setcb_init_restart(init_server);
sef_startup();
}
-/*===========================================================================*
- * fs_other *
- *===========================================================================*/
-void fs_other(const message *m_ptr, int __unused ipc_status)
+/*
+ * 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.
- */
message msg;
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.
*/
msg = *m_ptr;
}
}
-/*===========================================================================*
- * start_vtreefs *
- *===========================================================================*/
-void start_vtreefs(struct fs_hooks *hooks, unsigned int nr_inodes,
- 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)
{
- /* 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.
- */
- /* 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..
*/
vtreefs_hooks = hooks;