[U-Boot] [PATCH 6/8] EXT2: Rework ext2fs_find_file1()

Marek Vasut
2012-06-08T17:31:51Z

* Fix indent
* Pull variables defined deep in the code at the begining

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
---
fs/ext2/ext2fs.c | 101 +++++++++++++++++++++++++++---------------------------
1 file changed, 50 insertions(+), 51 deletions(-)

diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
index 22cc9c2..10745f6 100644
--- a/fs/ext2/ext2fs.c
+++ b/fs/ext2/ext2fs.c
@@ -490,108 +490,107 @@ static char *ext2fs_read_symlink(struct ext2fs_node *node)
return symlink;
}

-int ext2fs_find_file1
- (const char *currpath, struct ext2fs_node *currroot,
- struct ext2fs_node **currfound, int *foundtype)
+static int ext2fs_find_file1(const char *currpath, struct ext2fs_node *currroot,
+ struct ext2fs_node **currfound, int *foundtype)
{
- char fpath[strlen (currpath) + 1];
+ char fpath[strlen(currpath) + 1];
char *name = fpath;
char *next;
int status;
int type = FILETYPE_DIRECTORY;
+ int found;
+ char *symlink;
struct ext2fs_node *currnode = currroot;
struct ext2fs_node *oldnode = currroot;

- strncpy (fpath, currpath, strlen (currpath) + 1);
+ strncpy(fpath, currpath, strlen(currpath) + 1);

- /* Remove all leading slashes. */
- while (*name == '/') {
+ /* Remove all leading slashes. */
+ while (*name == '/')
name++;
- }
+
if (!*name) {
*currfound = currnode;
- return (1);
+ return 1;
}

for (;;) {
- int found;
-
- /* Extract the actual part from the pathname. */
- next = strchr (name, '/');
+ /* Extract the actual part from the pathname. */
+ next = strchr(name, '/');
if (next) {
- /* Remove all leading slashes. */
- while (*next == '/') {
+ /* Remove all leading slashes. */
+ while (*next == '/')
*(next++) = '\0';
- }
}

- /* At this point it is expected that the current node is a directory, check if this is true. */
+ /*
+ * At this point it is expected that the current node is a
+ * directory, check if this is true.
+ */
if (type != FILETYPE_DIRECTORY) {
- ext2fs_free_node (currnode, currroot);
- return (0);
+ ext2fs_free_node(currnode, currroot);
+ return 0;
}

oldnode = currnode;

- /* Iterate over the directory. */
- found = ext2fs_iterate_dir (currnode, name, &currnode, &type);
- if (found == 0) {
- return (0);
- }
- if (found == -1) {
+ /* Iterate over the directory. */
+ found = ext2fs_iterate_dir(currnode, name, &currnode, &type);
+ if (found == 0)
+ return 0;
+
+ if (found == -1)
break;
- }

- /* Read in the symlink and follow it. */
+ /* Read in the symlink and follow it. */
if (type == FILETYPE_SYMLINK) {
- char *symlink;
+ symlink = NULL;

- /* Test if the symlink does not loop. */
+ /* Test if the symlink does not loop. */
if (++symlinknest == 8) {
- ext2fs_free_node (currnode, currroot);
- ext2fs_free_node (oldnode, currroot);
- return (0);
+ ext2fs_free_node(currnode, currroot);
+ ext2fs_free_node(oldnode, currroot);
+ return 0;
}

- symlink = ext2fs_read_symlink (currnode);
- ext2fs_free_node (currnode, currroot);
+ symlink = ext2fs_read_symlink(currnode);
+ ext2fs_free_node(currnode, currroot);

if (!symlink) {
- ext2fs_free_node (oldnode, currroot);
- return (0);
+ ext2fs_free_node(oldnode, currroot);
+ return 0;
}
-#ifdef DEBUG
- printf ("Got symlink >%s<\n", symlink);
-#endif /* of DEBUG */
- /* The symlink is an absolute path, go back to the root inode. */
+
+ debug("EXT2: Got symlink >%s<\n", symlink);
+
if (symlink[0] == '/') {
- ext2fs_free_node (oldnode, currroot);
+ ext2fs_free_node(oldnode, currroot);
oldnode = &ext2fs_root->diropen;
}

- /* Lookup the node the symlink points to. */
- status = ext2fs_find_file1 (symlink, oldnode,
- &currnode, &type);
+ /* Lookup the node the symlink points to. */
+ status = ext2fs_find_file1(symlink, oldnode,
+ &currnode, &type);

- free (symlink);
+ free(symlink);

if (status == 0) {
- ext2fs_free_node (oldnode, currroot);
- return (0);
+ ext2fs_free_node(oldnode, currroot);
+ return 0;
}
}

- ext2fs_free_node (oldnode, currroot);
+ ext2fs_free_node(oldnode, currroot);

- /* Found the node! */
+ /* Found the node! */
if (!next || *next == '\0') {
*currfound = currnode;
*foundtype = type;
- return (1);
+ return 1;
}
name = next;
}
- return (-1);
+ return -1;
}

static int ext2fs_find_file(const char *path, struct ext2fs_node *rootnode,
--
1.7.10