Whamcloud - gitweb
Supplied changelog for resize inode patch.
[tools/e2fsprogs.git] / lib / ext2fs / finddev.c
index 7609f0c..2e9d70a 100644 (file)
@@ -31,6 +31,9 @@
 #include <sys/mkdev.h>
 #endif
 
+#include "ext2_fs.h"
+#include "ext2fs.h"
+
 struct dir_list {
        char    *name;
        struct dir_list *next;
@@ -39,7 +42,7 @@ struct dir_list {
 /*
  * This function adds an entry to the directory list
  */
-static void add_to_dirlist(char *name, struct dir_list **list)
+static void add_to_dirlist(const char *name, struct dir_list **list)
 {
        struct dir_list *dp;
 
@@ -89,7 +92,7 @@ static int scan_dir(char *dirname, dev_t device, struct dir_list **list,
                        goto skip_to_next;
                if (dp->d_name[0] == '.' &&
                    ((dp->d_name[1] == 0) ||
-                    (dp->d_name[1] == '.') && (dp->d_name[2] == 0)))
+                    ((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
                        goto skip_to_next;
                sprintf(path, "%s/%s", dirname, dp->d_name);
                if (stat(path, &st) < 0)
@@ -98,15 +101,18 @@ static int scan_dir(char *dirname, dev_t device, struct dir_list **list,
                        add_to_dirlist(path, list);
                if (S_ISBLK(st.st_mode) && st.st_rdev == device) {
                        cp = malloc(strlen(path)+1);
-                       if (!cp)
+                       if (!cp) {
+                               closedir(dir);
                                return ENOMEM;
+                       }
                        strcpy(cp, path);
                        *ret_path = cp;
-                       return 0;
+                       goto success;
                }
        skip_to_next:
                dp = readdir(dir);
        }
+success:
        closedir(dir);
        return 0;
 }
@@ -149,7 +155,6 @@ char *ext2fs_find_block_device(dev_t device)
                        new_list = 0;
                }
        }
-found_it:
        free_dirlist(&list);
        free_dirlist(&new_list);
        return ret_path;