summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/e2fsprogs
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2014-03-07 01:59:31 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-03-07 14:45:23 +0000
commit8f0ef728f9a058fa86b0a1bcac0426f32ed319f2 (patch)
tree1ce5ab5cbe501934f090e2e0d29065d391527585 /meta/recipes-devtools/e2fsprogs
parentb489b945bd7718092185ccbcc32de4abcead8132 (diff)
downloadpoky-8f0ef728f9a058fa86b0a1bcac0426f32ed319f2.tar.gz
e2fsprogs: debugfs: use the functions in misc/create_inode.c
* Use the functions in misc/create_inode.c, and remove the duplicated code. * The CREATE_INODE_DEPS in the debugfs/Makefile.in is used for recording create_inode.o's depends which is from misc/Makefile.in, we have to recompile create_inode.o because we need it to print more messages when it is used by debugfs, just like we recompile e2freefrag.o, but it seems that the e2freefrag.o's depends in debugfs/Makefile.in is incorrect, it would not rebuild when its depends (e.g.: lib/config.h) is changed, which would cause unexpected errors. Make duplicated code in debugfs/Makefile.in and misc/Makefile.in is not a good idea, maybe we'd better define CREATE_INODE_DEPS in the top Makefile, I'd like to send another patch and fix the e2freefrag if you are fine with it. [YOCTO #4083] (From OE-Core rev: 460f577379ef2ecf42fb8b7f855c21400c276d4f) 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/0010-debugfs-use-the-functions-in-misc-create_inode.c.patch496
1 files changed, 496 insertions, 0 deletions
diff --git a/meta/recipes-devtools/e2fsprogs/e2fsprogs/0010-debugfs-use-the-functions-in-misc-create_inode.c.patch b/meta/recipes-devtools/e2fsprogs/e2fsprogs/0010-debugfs-use-the-functions-in-misc-create_inode.c.patch
new file mode 100644
index 0000000000..2a6ca8f9a3
--- /dev/null
+++ b/meta/recipes-devtools/e2fsprogs/e2fsprogs/0010-debugfs-use-the-functions-in-misc-create_inode.c.patch
@@ -0,0 +1,496 @@
1From db89992fab2215f52dce4c595a39271b4ff3000b Mon Sep 17 00:00:00 2001
2From: Robert Yang <liezhi.yang@windriver.com>
3Date: Mon, 23 Dec 2013 04:22:22 -0500
4Subject: [PATCH 10/11] debugfs: use the functions in misc/create_inode.c
5
6* Use the functions in misc/create_inode.c, and remove the duplicated
7 code.
8
9* The CREATE_INODE_DEPS in the debugfs/Makefile.in is used for recording
10 create_inode.o's depends which is from misc/Makefile.in, we have to
11 recompile create_inode.o because we need it to print more messages when
12 it is used by debugfs, just like we recompile e2freefrag.o, but it seems
13 that the e2freefrag.o's depends in debugfs/Makefile.in is incorrect, it
14 would not rebuild when its depends (e.g.: lib/config.h) is changed,
15 which would cause unexpected errors. Make duplicated code in
16 debugfs/Makefile.in and misc/Makefile.in is not a good idea, maybe we'd
17 better define CREATE_INODE_DEPS in the top Makefile, I'd like to send
18 another patch and fix the e2freefrag if you are fine with it.
19
20Upstream-Status: Backport
21
22Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
23Reviewed-by: Darren Hart <dvhart@linux.intel.com>
24---
25 debugfs/Makefile.in | 17 ++-
26 debugfs/debugfs.c | 305 +++------------------------------------------------
27 debugfs/debugfs.h | 1 +
28 3 files changed, 31 insertions(+), 292 deletions(-)
29
30diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in
31index bf037e0..f51b78e 100644
32--- a/debugfs/Makefile.in
33+++ b/debugfs/Makefile.in
34@@ -18,7 +18,7 @@ MK_CMDS= _SS_DIR_OVERRIDE=../lib/ss ../lib/ss/mk_cmds
35
36 DEBUG_OBJS= debug_cmds.o debugfs.o util.o ncheck.o icheck.o ls.o \
37 lsdel.o dump.o set_fields.o logdump.o htree.o unused.o e2freefrag.o \
38- filefrag.o extent_cmds.o extent_inode.o zap.o
39+ filefrag.o extent_cmds.o extent_inode.o zap.o create_inode.o
40
41 RO_DEBUG_OBJS= ro_debug_cmds.o ro_debugfs.o util.o ncheck.o icheck.o ls.o \
42 lsdel.o logdump.o htree.o e2freefrag.o filefrag.o extent_cmds.o \
43@@ -28,7 +28,13 @@ SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \
44 $(srcdir)/ncheck.c $(srcdir)/icheck.c $(srcdir)/lsdel.c \
45 $(srcdir)/dump.c $(srcdir)/set_fields.c ${srcdir}/logdump.c \
46 $(srcdir)/htree.c $(srcdir)/unused.c ${srcdir}/../misc/e2freefrag.c \
47- $(srcdir)/filefrag.c $(srcdir)/extent_inode.c $(srcdir)/zap.c
48+ $(srcdir)/filefrag.c $(srcdir)/extent_inode.c $(srcdir)/zap.c \
49+ $(srcdir)/../misc/create_inode.c
50+
51+CREATE_INODE_DEPS= $(srcdir)/../misc/create_inode.h \
52+ $(srcdir)/../misc/create_inode.c $(top_builddir)/lib/config.h \
53+ $(srcdir)/../lib/ext2fs/ext2fs.h $(srcdir)/../lib/et/com_err.h \
54+ $(srcdir)/../lib/e2p/e2p.h $(srcdir)/../misc/nls-enable.h
55
56 LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
57 $(LIBUUID)
58@@ -81,6 +87,11 @@ e2freefrag.o: $(srcdir)/../misc/e2freefrag.c
59 $(E) " CC $@"
60 $(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) $< -DDEBUGFS -o $@
61
62+create_inode.o: $(CREATE_INODE_DEPS)
63+ $(E) " CC $@"
64+ $(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) \
65+ $(srcdir)/../misc/create_inode.c -DDEBUGFS -o $@
66+
67 debugfs.8: $(DEP_SUBSTITUTE) $(srcdir)/debugfs.8.in
68 $(E) " SUBST $@"
69 $(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/debugfs.8.in debugfs.8
70@@ -142,7 +153,7 @@ debugfs.o: $(srcdir)/debugfs.c $(top_srcdir)/lib/et/com_err.h \
71 $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
72 $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/version.h $(srcdir)/jfs_user.h \
73 $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
74- $(top_srcdir)/lib/ext2fs/kernel-list.h
75+ $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/misc/util.h
76 util.o: $(srcdir)/util.c $(srcdir)/debugfs.h \
77 $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
78 $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
79diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
80index 9c215f7..62e9f44 100644
81--- a/debugfs/debugfs.c
82+++ b/debugfs/debugfs.c
83@@ -25,8 +25,6 @@ extern char *optarg;
84 #include <errno.h>
85 #endif
86 #include <fcntl.h>
87-#include <sys/types.h>
88-#include <sys/stat.h>
89
90 #include "debugfs.h"
91 #include "uuid/uuid.h"
92@@ -41,22 +39,11 @@ extern char *optarg;
93 #define BUFSIZ 8192
94 #endif
95
96-/* 64KiB is the minimium blksize to best minimize system call overhead. */
97-#ifndef IO_BUFSIZE
98-#define IO_BUFSIZE 64*1024
99-#endif
100-
101-/* Block size for `st_blocks' */
102-#ifndef S_BLKSIZE
103-#define S_BLKSIZE 512
104-#endif
105-
106 ss_request_table *extra_cmds;
107 const char *debug_prog_name;
108 int sci_idx;
109
110-ext2_filsys current_fs = NULL;
111-ext2_ino_t root, cwd;
112+ext2_ino_t cwd;
113
114 static void open_filesystem(char *device, int open_flags, blk64_t superblock,
115 blk64_t blocksize, int catastrophic,
116@@ -1576,189 +1563,24 @@ void do_find_free_inode(int argc, char *argv[])
117 }
118
119 #ifndef READ_ONLY
120-static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_holes)
121-{
122- ext2_file_t e2_file;
123- errcode_t retval;
124- int got;
125- unsigned int written;
126- char *buf;
127- char *ptr;
128- char *zero_buf;
129- int cmp;
130-
131- retval = ext2fs_file_open(current_fs, newfile,
132- EXT2_FILE_WRITE, &e2_file);
133- if (retval)
134- return retval;
135-
136- retval = ext2fs_get_mem(bufsize, &buf);
137- if (retval) {
138- com_err("copy_file", retval, "can't allocate buffer\n");
139- return retval;
140- }
141-
142- /* This is used for checking whether the whole block is zero */
143- retval = ext2fs_get_memzero(bufsize, &zero_buf);
144- if (retval) {
145- com_err("copy_file", retval, "can't allocate buffer\n");
146- ext2fs_free_mem(&buf);
147- return retval;
148- }
149-
150- while (1) {
151- got = read(fd, buf, bufsize);
152- if (got == 0)
153- break;
154- if (got < 0) {
155- retval = errno;
156- goto fail;
157- }
158- ptr = buf;
159-
160- /* Sparse copy */
161- if (make_holes) {
162- /* Check whether all is zero */
163- cmp = memcmp(ptr, zero_buf, got);
164- if (cmp == 0) {
165- /* The whole block is zero, make a hole */
166- retval = ext2fs_file_lseek(e2_file, got, EXT2_SEEK_CUR, NULL);
167- if (retval)
168- goto fail;
169- got = 0;
170- }
171- }
172-
173- /* Normal copy */
174- while (got > 0) {
175- retval = ext2fs_file_write(e2_file, ptr,
176- got, &written);
177- if (retval)
178- goto fail;
179-
180- got -= written;
181- ptr += written;
182- }
183- }
184- ext2fs_free_mem(&buf);
185- ext2fs_free_mem(&zero_buf);
186- retval = ext2fs_file_close(e2_file);
187- return retval;
188-
189-fail:
190- ext2fs_free_mem(&buf);
191- ext2fs_free_mem(&zero_buf);
192- (void) ext2fs_file_close(e2_file);
193- return retval;
194-}
195-
196-
197 void do_write(int argc, char *argv[])
198 {
199- int fd;
200- struct stat statbuf;
201- ext2_ino_t newfile;
202 errcode_t retval;
203- struct ext2_inode inode;
204- int bufsize = IO_BUFSIZE;
205- int make_holes = 0;
206
207 if (common_args_process(argc, argv, 3, 3, "write",
208 "<native file> <new file>", CHECK_FS_RW))
209 return;
210
211- fd = open(argv[1], O_RDONLY);
212- if (fd < 0) {
213- com_err(argv[1], errno, 0);
214- return;
215- }
216- if (fstat(fd, &statbuf) < 0) {
217- com_err(argv[1], errno, 0);
218- close(fd);
219- return;
220- }
221-
222- retval = ext2fs_namei(current_fs, root, cwd, argv[2], &newfile);
223- if (retval == 0) {
224- com_err(argv[0], 0, "The file '%s' already exists\n", argv[2]);
225- close(fd);
226- return;
227- }
228-
229- retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile);
230- if (retval) {
231+ if ((retval = do_write_internal(cwd, argv[1], argv[2])))
232 com_err(argv[0], retval, 0);
233- close(fd);
234- return;
235- }
236- printf("Allocated inode: %u\n", newfile);
237- retval = ext2fs_link(current_fs, cwd, argv[2], newfile,
238- EXT2_FT_REG_FILE);
239- if (retval == EXT2_ET_DIR_NO_SPACE) {
240- retval = ext2fs_expand_dir(current_fs, cwd);
241- if (retval) {
242- com_err(argv[0], retval, "while expanding directory");
243- close(fd);
244- return;
245- }
246- retval = ext2fs_link(current_fs, cwd, argv[2], newfile,
247- EXT2_FT_REG_FILE);
248- }
249- if (retval) {
250- com_err(argv[2], retval, 0);
251- close(fd);
252- return;
253- }
254- if (ext2fs_test_inode_bitmap2(current_fs->inode_map,newfile))
255- com_err(argv[0], 0, "Warning: inode already set");
256- ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0);
257- memset(&inode, 0, sizeof(inode));
258- inode.i_mode = (statbuf.st_mode & ~LINUX_S_IFMT) | LINUX_S_IFREG;
259- inode.i_atime = inode.i_ctime = inode.i_mtime =
260- current_fs->now ? current_fs->now : time(0);
261- inode.i_links_count = 1;
262- inode.i_size = statbuf.st_size;
263- if (current_fs->super->s_feature_incompat &
264- EXT3_FEATURE_INCOMPAT_EXTENTS) {
265- int i;
266- struct ext3_extent_header *eh;
267-
268- eh = (struct ext3_extent_header *) &inode.i_block[0];
269- eh->eh_depth = 0;
270- eh->eh_entries = 0;
271- eh->eh_magic = ext2fs_cpu_to_le16(EXT3_EXT_MAGIC);
272- i = (sizeof(inode.i_block) - sizeof(*eh)) /
273- sizeof(struct ext3_extent);
274- eh->eh_max = ext2fs_cpu_to_le16(i);
275- inode.i_flags |= EXT4_EXTENTS_FL;
276- }
277- if (debugfs_write_new_inode(newfile, &inode, argv[0])) {
278- close(fd);
279- return;
280- }
281- if (LINUX_S_ISREG(inode.i_mode)) {
282- if (statbuf.st_blocks < statbuf.st_size / S_BLKSIZE) {
283- make_holes = 1;
284- /*
285- * Use I/O blocksize as buffer size when
286- * copying sparse files.
287- */
288- bufsize = statbuf.st_blksize;
289- }
290- retval = copy_file(fd, newfile, bufsize, make_holes);
291- if (retval)
292- com_err("copy_file", retval, 0);
293- }
294- close(fd);
295 }
296
297 void do_mknod(int argc, char *argv[])
298 {
299 unsigned long mode, major, minor;
300- ext2_ino_t newfile;
301 errcode_t retval;
302- struct ext2_inode inode;
303 int filetype, nr;
304+ struct stat st;
305
306 if (check_fs_open(argv[0]))
307 return;
308@@ -1767,115 +1589,50 @@ void do_mknod(int argc, char *argv[])
309 com_err(argv[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]");
310 return;
311 }
312+
313 mode = minor = major = 0;
314 switch (argv[2][0]) {
315 case 'p':
316- mode = LINUX_S_IFIFO;
317- filetype = EXT2_FT_FIFO;
318+ st.st_mode = S_IFIFO;
319 nr = 3;
320 break;
321 case 'c':
322- mode = LINUX_S_IFCHR;
323- filetype = EXT2_FT_CHRDEV;
324+ st.st_mode = S_IFCHR;
325 nr = 5;
326 break;
327 case 'b':
328- mode = LINUX_S_IFBLK;
329- filetype = EXT2_FT_BLKDEV;
330+ st.st_mode = S_IFBLK;
331 nr = 5;
332 break;
333 default:
334- filetype = 0;
335 nr = 0;
336 }
337+
338 if (nr == 5) {
339 major = strtoul(argv[3], argv+3, 0);
340 minor = strtoul(argv[4], argv+4, 0);
341 if (major > 65535 || minor > 65535 || argv[3][0] || argv[4][0])
342 nr = 0;
343 }
344+
345 if (argc != nr)
346 goto usage;
347- if (check_fs_read_write(argv[0]))
348- return;
349- retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile);
350- if (retval) {
351+
352+ st.st_rdev = makedev(major, minor);
353+ if ((retval = do_mknod_internal(cwd, argv[1], &st)))
354 com_err(argv[0], retval, 0);
355- return;
356- }
357- printf("Allocated inode: %u\n", newfile);
358- retval = ext2fs_link(current_fs, cwd, argv[1], newfile, filetype);
359- if (retval == EXT2_ET_DIR_NO_SPACE) {
360- retval = ext2fs_expand_dir(current_fs, cwd);
361- if (retval) {
362- com_err(argv[0], retval, "while expanding directory");
363- return;
364- }
365- retval = ext2fs_link(current_fs, cwd, argv[1], newfile,
366- filetype);
367- }
368- if (retval) {
369- com_err(argv[1], retval, 0);
370- return;
371- }
372- if (ext2fs_test_inode_bitmap2(current_fs->inode_map,newfile))
373- com_err(argv[0], 0, "Warning: inode already set");
374- ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0);
375- memset(&inode, 0, sizeof(inode));
376- inode.i_mode = mode;
377- inode.i_atime = inode.i_ctime = inode.i_mtime =
378- current_fs->now ? current_fs->now : time(0);
379- if ((major < 256) && (minor < 256)) {
380- inode.i_block[0] = major*256+minor;
381- inode.i_block[1] = 0;
382- } else {
383- inode.i_block[0] = 0;
384- inode.i_block[1] = (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
385- }
386- inode.i_links_count = 1;
387- if (debugfs_write_new_inode(newfile, &inode, argv[0]))
388- return;
389 }
390
391 void do_mkdir(int argc, char *argv[])
392 {
393- char *cp;
394- ext2_ino_t parent;
395- char *name;
396 errcode_t retval;
397
398 if (common_args_process(argc, argv, 2, 2, "mkdir",
399 "<filename>", CHECK_FS_RW))
400 return;
401
402- cp = strrchr(argv[1], '/');
403- if (cp) {
404- *cp = 0;
405- parent = string_to_inode(argv[1]);
406- if (!parent) {
407- com_err(argv[1], ENOENT, 0);
408- return;
409- }
410- name = cp+1;
411- } else {
412- parent = cwd;
413- name = argv[1];
414- }
415-
416-try_again:
417- retval = ext2fs_mkdir(current_fs, parent, 0, name);
418- if (retval == EXT2_ET_DIR_NO_SPACE) {
419- retval = ext2fs_expand_dir(current_fs, parent);
420- if (retval) {
421- com_err(argv[0], retval, "while expanding directory");
422- return;
423- }
424- goto try_again;
425- }
426- if (retval) {
427- com_err("ext2fs_mkdir", retval, 0);
428- return;
429- }
430+ if ((retval = do_mkdir_internal(cwd, argv[1], NULL)))
431+ com_err(argv[0], retval, 0);
432
433 }
434
435@@ -2270,44 +2027,14 @@ void do_punch(int argc, char *argv[])
436
437 void do_symlink(int argc, char *argv[])
438 {
439- char *cp;
440- ext2_ino_t parent;
441- char *name, *target;
442 errcode_t retval;
443
444 if (common_args_process(argc, argv, 3, 3, "symlink",
445 "<filename> <target>", CHECK_FS_RW))
446 return;
447
448- cp = strrchr(argv[1], '/');
449- if (cp) {
450- *cp = 0;
451- parent = string_to_inode(argv[1]);
452- if (!parent) {
453- com_err(argv[1], ENOENT, 0);
454- return;
455- }
456- name = cp+1;
457- } else {
458- parent = cwd;
459- name = argv[1];
460- }
461- target = argv[2];
462-
463-try_again:
464- retval = ext2fs_symlink(current_fs, parent, 0, name, target);
465- if (retval == EXT2_ET_DIR_NO_SPACE) {
466- retval = ext2fs_expand_dir(current_fs, parent);
467- if (retval) {
468- com_err(argv[0], retval, "while expanding directory");
469- return;
470- }
471- goto try_again;
472- }
473- if (retval) {
474- com_err("ext2fs_symlink", retval, 0);
475- return;
476- }
477+ if ((retval = do_symlink_internal(cwd, argv[1], argv[2])))
478+ com_err(argv[0], retval, 0);
479
480 }
481
482diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
483index 6b4f6ef..2d464c1 100644
484--- a/debugfs/debugfs.h
485+++ b/debugfs/debugfs.h
486@@ -5,6 +5,7 @@
487 #include "ss/ss.h"
488 #include "ext2fs/ext2_fs.h"
489 #include "ext2fs/ext2fs.h"
490+#include "../misc/create_inode.h"
491
492 #ifdef __STDC__
493 #define NOARGS void
494--
4951.7.10.4
496