summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/e2fsprogs
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2014-03-07 01:59:23 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-03-07 14:45:22 +0000
commitd8409f8f710c1f36d50ae8ef1cabc76bbdd0600c (patch)
tree342bc65ae4f6e91b12fda3350be2729d36be557f /meta/recipes-devtools/e2fsprogs
parent6779ab69fc8eea32a5abfbc0d0cc0efc6d4b86ff (diff)
downloadpoky-d8409f8f710c1f36d50ae8ef1cabc76bbdd0600c.tar.gz
e2fsprogs: mke2fs: copy files recursively
Use opendir() and readdir() to read the native directory, then use lstat() to identify the file type and call the corresponding function to add the file to the filesystem, call the populate_fs() recursively if it is a directory. NOTE: the libext2fs can't create the socket file. [YOCTO #4083] (From OE-Core rev: fd0d00dafcf497f23b1c3886d062c8a57e2aa515) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Reviewed-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/e2fsprogs')
-rw-r--r--meta/recipes-devtools/e2fsprogs/e2fsprogs/0002-misc-create_inode.c-copy-files-recursively.patch135
1 files changed, 135 insertions, 0 deletions
diff --git a/meta/recipes-devtools/e2fsprogs/e2fsprogs/0002-misc-create_inode.c-copy-files-recursively.patch b/meta/recipes-devtools/e2fsprogs/e2fsprogs/0002-misc-create_inode.c-copy-files-recursively.patch
new file mode 100644
index 0000000000..9bff644ea6
--- /dev/null
+++ b/meta/recipes-devtools/e2fsprogs/e2fsprogs/0002-misc-create_inode.c-copy-files-recursively.patch
@@ -0,0 +1,135 @@
1From 08dfbaf4e3f704232ff46d78c0758a6cfe3961c8 Mon Sep 17 00:00:00 2001
2From: Robert Yang <liezhi.yang@windriver.com>
3Date: Mon, 23 Dec 2013 02:59:10 -0500
4Subject: [PATCH 02/11] misc/create_inode.c: copy files recursively
5
6Use opendir() and readdir() to read the native directory, then use
7lstat() to identify the file type and call the corresponding function to
8add the file to the filesystem, call the populate_fs() recursively if it
9is a directory.
10
11NOTE: the libext2fs can't create the socket file.
12
13Upstream-Status: Backport
14
15Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
16Reviewed-by: Darren Hart <dvhart@linux.intel.com>
17---
18 misc/create_inode.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++
19 1 file changed, 97 insertions(+)
20
21diff --git a/misc/create_inode.c b/misc/create_inode.c
22index 46aaa60..b68b910 100644
23--- a/misc/create_inode.c
24+++ b/misc/create_inode.c
25@@ -1,5 +1,13 @@
26 #include "create_inode.h"
27
28+#if __STDC_VERSION__ < 199901L
29+# if __GNUC__ >= 2
30+# define __func__ __FUNCTION__
31+# else
32+# define __func__ "<unknown>"
33+# endif
34+#endif
35+
36 /* Make a special file which is block, character and fifo */
37 errcode_t do_mknod_internal(ext2_ino_t cwd, const char *name, struct stat *st)
38 {
39@@ -23,4 +31,93 @@ errcode_t do_write_internal(ext2_ino_t cwd, const char *src, const char *dest)
40 /* Copy files from source_dir to fs */
41 errcode_t populate_fs(ext2_ino_t parent_ino, const char *source_dir)
42 {
43+ const char *name;
44+ DIR *dh;
45+ struct dirent *dent;
46+ struct stat st;
47+ char ln_target[PATH_MAX];
48+ ext2_ino_t ino;
49+ errcode_t retval;
50+ int read_cnt;
51+
52+ root = EXT2_ROOT_INO;
53+
54+ if (chdir(source_dir) < 0) {
55+ com_err(__func__, errno,
56+ _("while changing working directory to \"%s\""), source_dir);
57+ return errno;
58+ }
59+
60+ if (!(dh = opendir("."))) {
61+ com_err(__func__, errno,
62+ _("while openning directory \"%s\""), source_dir);
63+ return errno;
64+ }
65+
66+ while((dent = readdir(dh))) {
67+ if((!strcmp(dent->d_name, ".")) || (!strcmp(dent->d_name, "..")))
68+ continue;
69+ lstat(dent->d_name, &st);
70+ name = dent->d_name;
71+
72+ switch(st.st_mode & S_IFMT) {
73+ case S_IFCHR:
74+ case S_IFBLK:
75+ case S_IFIFO:
76+ if ((retval = do_mknod_internal(parent_ino, name, &st))) {
77+ com_err(__func__, retval,
78+ _("while creating special file \"%s\""), name);
79+ return retval;
80+ }
81+ break;
82+ case S_IFSOCK:
83+ /* FIXME: there is no make socket function atm. */
84+ com_err(__func__, 0,
85+ _("ignoring socket file \"%s\""), name);
86+ continue;
87+ case S_IFLNK:
88+ if((read_cnt = readlink(name, ln_target, sizeof(ln_target))) == -1) {
89+ com_err(__func__, errno,
90+ _("while trying to readlink \"%s\""), name);
91+ return errno;
92+ }
93+ ln_target[read_cnt] = '\0';
94+ if ((retval = do_symlink_internal(parent_ino, name, ln_target))) {
95+ com_err(__func__, retval,
96+ _("while writing symlink\"%s\""), name);
97+ return retval;
98+ }
99+ break;
100+ case S_IFREG:
101+ if ((retval = do_write_internal(parent_ino, name, name))) {
102+ com_err(__func__, retval,
103+ _("while writing file \"%s\""), name);
104+ return retval;
105+ }
106+ break;
107+ case S_IFDIR:
108+ if ((retval = do_mkdir_internal(parent_ino, name, &st))) {
109+ com_err(__func__, retval,
110+ _("while making dir \"%s\""), name);
111+ return retval;
112+ }
113+ if ((retval = ext2fs_namei(current_fs, root, parent_ino, name, &ino))) {
114+ com_err(name, retval, 0);
115+ return retval;
116+ }
117+ /* Populate the dir recursively*/
118+ retval = populate_fs(ino, name);
119+ if (retval) {
120+ com_err(__func__, retval, _("while adding dir \"%s\""), name);
121+ return retval;
122+ }
123+ chdir("..");
124+ break;
125+ default:
126+ com_err(__func__, 0,
127+ _("ignoring entry \"%s\""), name);
128+ }
129+ }
130+ closedir(dh);
131+ return retval;
132 }
133--
1341.7.10.4
135