From: Ted Ts'o <tytso@mit.edu>
To: Round Robinjp <roundrobinjp@yahoo.co.jp>
Cc: linux-ext4@vger.kernel.org
Subject: Re: flashing large eMMC partitions with ext4
Date: Mon, 25 Jul 2011 14:10:43 -0400 [thread overview]
Message-ID: <20110725181043.GK3469@thunk.org> (raw)
In-Reply-To: <20110722154936.30251.qmail@web4208.mail.ogk.yahoo.co.jp>
[-- Attachment #1: Type: text/plain, Size: 1316 bytes --]
On Sat, Jul 23, 2011 at 12:49:28AM +0900, Round Robinjp wrote:
> Hi
>
> I have a question regarding making ext4 image for
> large eMMC partition.
>
> We have a 4G partition in our embedded device
> in which we want to use ext4 filesystem.
> But for that we have to create a 4G image.
> flashing this 4G image to the eMMC takes a long
> time. Is there any way to reduce this time?
>
> For vfat, you can truncate the image leaving only
> non zero-filled blocks which makes the image very
> short and the time for flashing is reduced.
> Is something similar to that possible for ext4?
OK, so it's not obvious what problem you are trying to ask here.
It sounds like Andreas was trying to help you solve the problem of
minimizing the number of blocks written by mke2fs.
I'm guessing the problem is you've already created a file system image
which is 4G, and for which a large number of the blocks are not used,
and you're trying to optimize the amount of time it takes to flash the
image. Is that right?
The way to do that is to use a program like zerofree.c (google it, or
see attached) to make sure the non-used blocks are zero-filled, and
then use a program like make-sparse.c (see the e2fsprogs sources, in
the contrib directory) to only write the non-zero blocks to the flash
device.
Regards,
- Ted
[-- Attachment #2: zerofree.c --]
[-- Type: text/x-csrc, Size: 3530 bytes --]
/*
* zerofree - a tool to zero free blocks in an ext2 filesystem
*
* Copyright (C) 2004 R M Yorston
*
* This file may be redistributed under the terms of the GNU General Public
* License.
*
* Changes:
*
* 2007-08-12 Allow use on filesystems mounted read-only. Patch from
* Jan Krämer.
*/
#include <ext2fs/ext2fs.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define USAGE "usage: %s [-n] [-v] filesystem\n"
int main(int argc, char **argv)
{
errcode_t ret ;
int flags ;
int superblock = 0 ;
int open_flags = EXT2_FLAG_RW ;
int blocksize = 0 ;
ext2_filsys current_fs = NULL;
unsigned long blk ;
unsigned char *buf;
unsigned char *empty;
int i, c ;
unsigned int free, nonzero ;
double percent ;
int old_percent ;
int verbose = 0 ;
int dryrun = 0 ;
while ( (c=getopt(argc, argv, "nv")) != -1 ) {
switch (c) {
case 'n' :
dryrun = 1 ;
break ;
case 'v' :
verbose = 1 ;
break ;
default :
fprintf(stderr, USAGE, argv[0]) ;
return 1 ;
}
}
if ( argc != optind+1 ) {
fprintf(stderr, USAGE, argv[0]) ;
return 1 ;
}
ret = ext2fs_check_if_mounted(argv[optind], &flags) ;
if ( ret ) {
fprintf(stderr, "%s: failed to determine filesystem mount state %s\n",
argv[0], argv[optind]) ;
return 1 ;
}
if ( (flags & EXT2_MF_MOUNTED) && !(flags & EXT2_MF_READONLY) ) {
fprintf(stderr, "%s: filesystem %s is mounted rw\n",
argv[0], argv[optind]) ;
return 1 ;
}
ret = ext2fs_open(argv[optind], open_flags, superblock, blocksize,
unix_io_manager, ¤t_fs);
if ( ret ) {
fprintf(stderr, "%s: failed to open filesystem %s\n",
argv[0], argv[optind]) ;
return 1 ;
}
empty = (unsigned char *)calloc(1, current_fs->blocksize) ;
buf = (unsigned char *)malloc(current_fs->blocksize) ;
if ( empty == NULL || buf == NULL ) {
fprintf(stderr, "%s: out of memory (surely not?)\n", argv[0]) ;
return 1 ;
}
ret = ext2fs_read_inode_bitmap(current_fs);
if ( ret ) {
fprintf(stderr, "%s: error while reading inode bitmap\n", argv[0]);
return 1 ;
}
ret = ext2fs_read_block_bitmap(current_fs);
if ( ret ) {
fprintf(stderr, "%s: error while reading block bitmap\n", argv[0]);
return 1 ;
}
free = nonzero = 0 ;
percent = 0.0 ;
old_percent = -1 ;
if ( verbose ) {
fprintf(stderr, "\r%4.1f%%", percent) ;
}
for ( blk=current_fs->super->s_first_data_block;
blk < current_fs->super->s_blocks_count; blk++ ) {
if ( ext2fs_test_block_bitmap(current_fs->block_map, blk) ) {
continue ;
}
++free ;
percent = 100.0 * (double)free/
(double)current_fs->super->s_free_blocks_count ;
if ( verbose && (int)(percent*10) != old_percent ) {
fprintf(stderr, "\r%4.1f%%", percent) ;
old_percent = (int)(percent*10) ;
}
ret = io_channel_read_blk(current_fs->io, blk, 1, buf);
if ( ret ) {
fprintf(stderr, "%s: error while reading block\n", argv[0]) ;
return 1 ;
}
for ( i=0; i < current_fs->blocksize; ++i ) {
if ( buf[i] ) {
break ;
}
}
if ( i == current_fs->blocksize ) {
continue ;
}
++nonzero ;
if ( !dryrun ) {
ret = io_channel_write_blk(current_fs->io, blk, 1, empty) ;
if ( ret ) {
fprintf(stderr, "%s: error while writing block\n", argv[0]) ;
return 1 ;
}
}
}
if ( verbose ) {
printf("\r%u/%u/%u\n", nonzero, free,
current_fs->super->s_blocks_count) ;
}
ret = ext2fs_close(current_fs) ;
if ( ret ) {
fprintf(stderr, "%s: error while closing filesystem\n", argv[0]) ;
return 1 ;
}
return 0 ;
}
next prev parent reply other threads:[~2011-07-25 18:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-22 15:49 flashing large eMMC partitions with ext4 Round Robinjp
2011-07-22 16:35 ` Andreas Dilger
2011-07-25 16:34 ` Round Robinjp
2011-07-25 16:55 ` Andreas Dilger
2011-07-25 18:10 ` Ted Ts'o [this message]
2011-07-25 18:36 ` Amir Goldstein
2011-07-26 1:39 ` Yongqiang Yang
2011-07-26 4:07 ` Andreas Dilger
2011-07-26 4:13 ` Theodore Tso
2011-07-26 17:38 ` Round Robinjp
2011-07-27 1:21 ` Ted Ts'o
2011-07-27 16:40 ` Round Robinjp
2011-07-27 17:16 ` Andreas Dilger
2011-07-27 18:05 ` Amir Goldstein
2011-07-29 19:05 ` Round Robinjp
2011-07-29 19:46 ` Amir Goldstein
2011-08-01 17:43 ` Round Robinjp
2011-08-01 18:57 ` Ted Ts'o
2011-08-01 19:44 ` Amir Goldstein
2011-08-02 6:53 ` Round Robinjp
2011-08-02 7:42 ` Amir Goldstein
2011-08-02 16:07 ` Round Robinjp
2011-08-02 16:57 ` Ted Ts'o
2011-08-02 17:52 ` Amir Goldstein
2011-08-03 15:15 ` Round Robinjp
2011-08-02 17:44 ` Amir Goldstein
2011-08-03 8:40 ` Amir Goldstein
2011-08-09 16:05 ` Round Robinjp
2011-08-09 19:55 ` Amir Goldstein
2011-07-27 18:08 ` Round Robinjp
2011-07-27 19:28 ` Andreas Dilger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110725181043.GK3469@thunk.org \
--to=tytso@mit.edu \
--cc=linux-ext4@vger.kernel.org \
--cc=roundrobinjp@yahoo.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.