Whamcloud - gitweb
filefrag: Lustre changes to filefrag FIEMAP handling
[tools/e2fsprogs.git] / misc / create_inode.c
index c00d545..a3a34cd 100644 (file)
@@ -150,6 +150,8 @@ static errcode_t set_inode_xattr(ext2_filsys fs, ext2_ino_t ino,
 
        size = llistxattr(filename, NULL, 0);
        if (size == -1) {
+               if (errno == ENOTSUP)
+                       return 0;
                retval = errno;
                com_err(__func__, retval, _("while listing attributes of \"%s\""),
                        filename);
@@ -763,39 +765,33 @@ static int scandir(const char *dir_name, struct dirent ***name_list,
                        size_t new_list_size = temp_list_size + 32;
                        struct dirent **new_list = (struct dirent**)realloc(
                                temp_list, new_list_size * sizeof(struct dirent*));
-                       if (new_list == NULL) {
-                               goto out;
-                       }
+                       if (new_list == NULL)
+                               goto out_err;
                        temp_list_size = new_list_size;
                        temp_list = new_list;
                }
                // add the copy of dirent to the list
                temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
                if (!temp_list[num_dent])
-                       goto out;
+                       goto out_err;
                memcpy(temp_list[num_dent], dent, dent->d_reclen);
                num_dent++;
        }
+       closedir(dir);
 
        if (compar != NULL) {
                qsort(temp_list, num_dent, sizeof(struct dirent*),
                      (int (*)(const void*, const void*))compar);
        }
-
-        // release the temp list
        *name_list = temp_list;
-       temp_list = NULL;
+       return num_dent;
 
-out:
-       if (temp_list != NULL) {
-               while (num_dent > 0) {
-                       free(temp_list[--num_dent]);
-               }
-               free(temp_list);
-               num_dent = -1;
-       }
+out_err:
        closedir(dir);
-       return num_dent;
+       while (num_dent > 0)
+               free(temp_list[--num_dent]);
+       free(temp_list);
+       return -1;
 }
 
 static int alphasort(const struct dirent **a, const struct dirent **b) {
@@ -813,11 +809,9 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
        const char      *name;
        struct dirent   **dent;
        struct stat     st;
-       char            *ln_target = NULL;
        unsigned int    save_inode;
        ext2_ino_t      ino;
        errcode_t       retval = 0;
-       int             read_cnt;
        int             hdlink;
        size_t          cur_dir_path_len;
        int             i, num_dents;
@@ -900,7 +894,10 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                                goto out;
                        }
                        break;
-               case S_IFLNK:
+               case S_IFLNK: {
+                       char *ln_target;
+                       int read_cnt;
+
                        ln_target = malloc(st.st_size + 1);
                        if (ln_target == NULL) {
                                com_err(__func__, retval,
@@ -935,7 +932,8 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                                goto out;
                        }
                        break;
-#endif
+               }
+#endif /* !_WIN32 */
                case S_IFREG:
                        retval = do_write_internal(fs, parent_ino, name, name,
                                                   root);