make_ext4fs: explicitly call setlocale() before creating image
[project/make_ext4fs.git] / make_ext4fs.c
index edfa25c..dd4d0d3 100644 (file)
@@ -33,6 +33,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <locale.h>
 
 /* TODO: Not implemented:
    Allocating blocks in the same block group as the file inode
@@ -44,27 +45,6 @@ static int filter_dot(const struct dirent *d)
        return (strcmp(d->d_name, "..") && strcmp(d->d_name, "."));
 }
 
-static u32 build_default_directory_structure(const char *dir_path)
-{
-       u32 inode;
-       u32 root_inode;
-       struct dentry dentries = {
-                       .filename = "lost+found",
-                       .file_type = EXT4_FT_DIR,
-                       .mode = S_IRWXU,
-                       .uid = 0,
-                       .gid = 0,
-                       .mtime = 0,
-       };
-       root_inode = make_directory(0, 1, &dentries, 1);
-       inode = make_directory(root_inode, 0, NULL, 0);
-       *dentries.inode = inode;
-       inode_set_permissions(inode, dentries.mode,
-               dentries.uid, dentries.gid, dentries.mtime);
-
-       return root_inode;
-}
-
 /* Read a local directory and create the same tree in the generated filesystem.
    Calls itself recursively with each directory in the given directory.
    full_path is an absolute or relative path, with a trailing slash, to the
@@ -87,6 +67,9 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
        u32 dirs = 0;
        bool needs_lost_and_found = false;
 
+       /* alphasort is locale-dependent; let's fix the locale to some sane value */
+       setlocale(LC_COLLATE, "C");
+
        if (full_path) {
                entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort);
                if (entries < 0) {