1 #include "create_inode.h"
3 #if __STDC_VERSION__ < 199901L
5 # define __func__ __FUNCTION__
7 # define __func__ "<unknown>"
11 /* Make a special file which is block, character and fifo */
12 errcode_t do_mknod_internal(ext2_ino_t cwd, const char *name, struct stat *st)
16 /* Make a symlink name -> target */
17 errcode_t do_symlink_internal(ext2_ino_t cwd, const char *name, char *target)
21 /* Make a directory in the fs */
22 errcode_t do_mkdir_internal(ext2_ino_t cwd, const char *name, struct stat *st)
26 /* Copy the native file to the fs */
27 errcode_t do_write_internal(ext2_ino_t cwd, const char *src, const char *dest)
31 /* Copy files from source_dir to fs */
32 errcode_t populate_fs(ext2_ino_t parent_ino, const char *source_dir)
38 char ln_target[PATH_MAX];
45 if (chdir(source_dir) < 0) {
46 com_err(__func__, errno,
47 _("while changing working directory to \"%s\""), source_dir);
51 if (!(dh = opendir("."))) {
52 com_err(__func__, errno,
53 _("while openning directory \"%s\""), source_dir);
57 while((dent = readdir(dh))) {
58 if((!strcmp(dent->d_name, ".")) || (!strcmp(dent->d_name, "..")))
60 lstat(dent->d_name, &st);
63 switch(st.st_mode & S_IFMT) {
67 if ((retval = do_mknod_internal(parent_ino, name, &st))) {
68 com_err(__func__, retval,
69 _("while creating special file \"%s\""), name);
74 /* FIXME: there is no make socket function atm. */
76 _("ignoring socket file \"%s\""), name);
79 if((read_cnt = readlink(name, ln_target, sizeof(ln_target))) == -1) {
80 com_err(__func__, errno,
81 _("while trying to readlink \"%s\""), name);
84 ln_target[read_cnt] = '\0';
85 if ((retval = do_symlink_internal(parent_ino, name, ln_target))) {
86 com_err(__func__, retval,
87 _("while writing symlink\"%s\""), name);
92 if ((retval = do_write_internal(parent_ino, name, name))) {
93 com_err(__func__, retval,
94 _("while writing file \"%s\""), name);
99 if ((retval = do_mkdir_internal(parent_ino, name, &st))) {
100 com_err(__func__, retval,
101 _("while making dir \"%s\""), name);
104 if ((retval = ext2fs_namei(current_fs, root, parent_ino, name, &ino))) {
105 com_err(name, retval, 0);
108 /* Populate the dir recursively*/
109 retval = populate_fs(ino, name);
111 com_err(__func__, retval, _("while adding dir \"%s\""), name);
118 _("ignoring entry \"%s\""), name);