From: David van Moolenbroek Date: Thu, 6 Nov 2014 13:36:45 +0000 (+0000) Subject: libvtreefs: convert to KNF X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F84%2F2884%2F2;p=minix.git libvtreefs: convert to KNF Change-Id: I81bdf05c9b630a0cbb0ac573d36d4f59f8137199 --- diff --git a/minix/include/minix/vtreefs.h b/minix/include/minix/vtreefs.h index 9a7473ece..5ab27b863 100644 --- a/minix/include/minix/vtreefs.h +++ b/minix/include/minix/vtreefs.h @@ -32,23 +32,26 @@ struct fs_hooks { 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, diff --git a/minix/lib/libvtreefs/inode.c b/minix/lib/libvtreefs/inode.c index 9aaef3233..98eac18e4 100644 --- a/minix/lib/libvtreefs/inode.c +++ b/minix/lib/libvtreefs/inode.c @@ -1,4 +1,4 @@ -/* VTreeFS - inode.c - by Alen Stojanov and David van Moolenbroek */ +/* VTreeFS - inode.c - inode management */ #include "inc.h" @@ -19,19 +19,17 @@ static LIST_HEAD(index_head, inode) *parent_index_head; #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; @@ -51,15 +49,15 @@ void init_inodes(unsigned int inodes, struct inode_stat *stat, #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]; @@ -87,13 +85,12 @@ void init_inodes(unsigned int inodes, struct inode_stat *stat, 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); @@ -101,18 +98,16 @@ void cleanup_inodes(void) free(inode); } -/*===========================================================================* - * parent_name_hash * - *===========================================================================*/ -static int parent_name_hash(struct inode *parent, char *name) +/* + * Return the hash value of tuple. + */ +static int +parent_name_hash(const struct inode * parent, const char *name) { - /* Return the hash value of 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)); @@ -120,25 +115,24 @@ static int parent_name_hash(struct inode *parent, char *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 tuple. + */ +static int +parent_index_hash(const struct inode * parent, index_t index) { - /* Return the hash value of a 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; @@ -153,7 +147,8 @@ static void purge_inode(struct inode *parent) 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++) { @@ -161,7 +156,7 @@ static void purge_inode(struct inode *parent) 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)); @@ -172,15 +167,14 @@ static void purge_inode(struct inode *parent) } } -/*===========================================================================* - * 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; @@ -193,7 +187,7 @@ struct inode *add_inode(struct inode *parent, char *name, 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); @@ -229,64 +223,59 @@ struct inode *add_inode(struct inode *parent, char *name, 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); @@ -297,13 +286,12 @@ struct inode *get_parent_inode(struct 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); @@ -317,13 +305,12 @@ struct inode *get_first_inode(struct 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); @@ -336,52 +323,48 @@ struct inode *get_next_inode(struct 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 tuple. + */ +struct inode * +get_inode_by_name(const struct inode * parent, const char * name) { - /* Look up an inode using a tuple. - */ struct inode *node; int slot; @@ -399,13 +382,12 @@ struct inode *get_inode_by_name(struct inode *parent, char *name) return NULL; } -/*===========================================================================* - * get_inode_by_index * - *===========================================================================*/ -struct inode *get_inode_by_index(struct inode *parent, index_t index) +/* + * Look up an inode using a tuple. + */ +struct inode * +get_inode_by_index(const struct inode * parent, index_t index) { - /* Look up an inode using a tuple. - */ struct inode *node; int slot; @@ -423,13 +405,12 @@ struct inode *get_inode_by_index(struct inode *parent, index_t index) 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]; @@ -439,13 +420,12 @@ struct inode *find_inode(ino_t num) 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) @@ -455,46 +435,44 @@ struct inode *get_inode(ino_t num) 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); @@ -513,25 +491,24 @@ static void unlink_inode(struct inode *node) 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!). */ @@ -547,15 +524,17 @@ void delete_inode(struct inode *node) 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) @@ -566,25 +545,23 @@ void delete_inode(struct inode *node) } } -/*===========================================================================* - * 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. */ diff --git a/minix/lib/libvtreefs/inode.h b/minix/lib/libvtreefs/inode.h index 6160ac771..a1788ecd7 100644 --- a/minix/lib/libvtreefs/inode.h +++ b/minix/lib/libvtreefs/inode.h @@ -1,7 +1,8 @@ #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. * @@ -9,9 +10,9 @@ * -> inode hashtable, and if it has an index into the parent, * is part of a -> 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 { diff --git a/minix/lib/libvtreefs/link.c b/minix/lib/libvtreefs/link.c index 61711b228..5637ba658 100644 --- a/minix/lib/libvtreefs/link.c +++ b/minix/lib/libvtreefs/link.c @@ -1,14 +1,13 @@ -/* 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; @@ -17,12 +16,15 @@ ssize_t fs_rdlink(ino_t ino_nr, struct fsdriver_data *data, size_t bytes) 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); diff --git a/minix/lib/libvtreefs/mount.c b/minix/lib/libvtreefs/mount.c index e9bfeaf6d..c94becc7c 100644 --- a/minix/lib/libvtreefs/mount.c +++ b/minix/lib/libvtreefs/mount.c @@ -1,22 +1,21 @@ -/* VTreeFS - mount.c - by Alen Stojanov and David van Moolenbroek */ +/* VTreeFS - mount.c - mounting and unmounting */ #include "inc.h" #include -/*===========================================================================* - * 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; @@ -24,7 +23,7 @@ int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node, 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(); @@ -41,13 +40,12 @@ int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node, 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. */ @@ -55,7 +53,7 @@ void fs_unmount(void) 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(); } diff --git a/minix/lib/libvtreefs/path.c b/minix/lib/libvtreefs/path.c index 686a79e3a..23b8d68c8 100644 --- a/minix/lib/libvtreefs/path.c +++ b/minix/lib/libvtreefs/path.c @@ -1,15 +1,14 @@ -/* 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; @@ -30,13 +29,13 @@ int fs_lookup(ino_t dir_nr, char *name, struct fsdriver_node *node_details, 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; } diff --git a/minix/lib/libvtreefs/proto.h b/minix/lib/libvtreefs/proto.h index 6bc5083b1..683daea7a 100644 --- a/minix/lib/libvtreefs/proto.h +++ b/minix/lib/libvtreefs/proto.h @@ -9,8 +9,8 @@ struct inode *find_inode(ino_t num); 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 */ @@ -35,7 +35,7 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, 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); diff --git a/minix/lib/libvtreefs/read.c b/minix/lib/libvtreefs/read.c index 85b99262c..7d510c3db 100644 --- a/minix/lib/libvtreefs/read.c +++ b/minix/lib/libvtreefs/read.c @@ -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 #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; @@ -30,8 +29,9 @@ 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) { 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)); @@ -50,14 +50,13 @@ ssize_t fs_read(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, 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; @@ -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. */ 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)); @@ -91,29 +91,27 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, /* 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. */ @@ -123,7 +121,7 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, /* 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. */ @@ -131,10 +129,8 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, child = get_next_inode(child); get_next = TRUE; - } - else { + } else child = get_next_inode(child); - } /* No more children? Then stop. */ if (child == NULL) @@ -147,8 +143,8 @@ ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes, /* 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); diff --git a/minix/lib/libvtreefs/sdbm.c b/minix/lib/libvtreefs/sdbm.c index 951143b5f..3212c856d 100644 --- a/minix/lib/libvtreefs/sdbm.c +++ b/minix/lib/libvtreefs/sdbm.c @@ -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 @@ -10,6 +10,7 @@ */ #include "inc.h" + /* * polynomial conversion ignoring overflows * [this seems to work remarkably well, in fact better @@ -17,7 +18,8 @@ * 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; diff --git a/minix/lib/libvtreefs/stadir.c b/minix/lib/libvtreefs/stadir.c index 6bb7a0a99..6eba24ead 100644 --- a/minix/lib/libvtreefs/stadir.c +++ b/minix/lib/libvtreefs/stadir.c @@ -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" -/*===========================================================================* - * 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; @@ -30,7 +29,7 @@ int fs_stat(ino_t ino_nr, struct stat *buf) /* 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); @@ -45,13 +44,12 @@ int fs_stat(ino_t ino_nr, struct stat *buf) 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; diff --git a/minix/lib/libvtreefs/table.c b/minix/lib/libvtreefs/table.c index 193d89660..17370bcfd 100644 --- a/minix/lib/libvtreefs/table.c +++ b/minix/lib/libvtreefs/table.c @@ -1,4 +1,4 @@ -/* VTreeFS - table.c - by Alen Stojanov and David van Moolenbroek */ +/* VTreeFS - table.c - file system driver callback table */ #define _TABLE #include "inc.h" diff --git a/minix/lib/libvtreefs/vtreefs.c b/minix/lib/libvtreefs/vtreefs.c index ebdd0e9d2..e433a736a 100644 --- a/minix/lib/libvtreefs/vtreefs.c +++ b/minix/lib/libvtreefs/vtreefs.c @@ -1,4 +1,4 @@ -/* VTreeFS - vtreefs.c - by Alen Stojanov and David van Moolenbroek */ +/* VTreeFS - vtreefs.c - initialization and message loop */ #include "inc.h" @@ -6,13 +6,12 @@ static unsigned int inodes; 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); @@ -20,13 +19,12 @@ static int init_server(int UNUSED(type), sef_init_info_t *UNUSED(info)) 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; @@ -34,11 +32,13 @@ static void got_signal(int signal) 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); @@ -49,18 +49,18 @@ static void sef_local_startup(void) 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; @@ -69,18 +69,18 @@ void fs_other(const message *m_ptr, int __unused ipc_status) } } -/*===========================================================================* - * 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;