diff options
author | Koushik Dutta <koushd@gmail.com> | 2010-12-21 15:14:40 -0800 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2010-12-21 15:14:40 -0800 |
commit | 1e6d772f3558d21e7f15e2cadcb0dbc5c8809869 (patch) | |
tree | eeb82b5fd101cb1978a87e001ac8b4a235b545ee /bmlutils | |
parent | 03cf72a4f5897807da89cb06c03396cb892d457b (diff) | |
parent | cdb433af66539eaf56e7f2e0a918f445d2f666fb (diff) | |
download | bootable_recovery-1e6d772f3558d21e7f15e2cadcb0dbc5c8809869.zip bootable_recovery-1e6d772f3558d21e7f15e2cadcb0dbc5c8809869.tar.gz bootable_recovery-1e6d772f3558d21e7f15e2cadcb0dbc5c8809869.tar.bz2 |
Merge remote branch 'github/gingerbread' into gingerbread
Diffstat (limited to 'bmlutils')
-rw-r--r-- | bmlutils/bmlutils.c | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/bmlutils/bmlutils.c b/bmlutils/bmlutils.c index f63bc78..2f152c4 100644 --- a/bmlutils/bmlutils.c +++ b/bmlutils/bmlutils.c @@ -74,9 +74,62 @@ int cmd_bml_restore_raw_partition(const char *partition, const char *filename) int cmd_bml_backup_raw_partition(const char *partition, const char *filename) { - char tmp[PATH_MAX]; - sprintf(tmp, "dd of=%s if=/dev/block/bml7 bs=4096", filename); - return __system(tmp); + char* bml; + if (strcmp("boot", partition) == 0) + bml = "/dev/block/bml7"; + else if (strcmp("recovery", partition) == 0) + bml = "/dev/block/bml8"; + else { + printf("Invalid partition.\n"); + return -1; + } + + int ch; + FILE *in; + FILE *out; + int val = 0; + char buf[512]; + unsigned sz = 0; + unsigned i; + int ret = -1; + char *in_file = bml; + + in = fopen ( in_file, "r" ); + if (in == NULL) + goto ERROR3; + + out = fopen ( out_file, "w" ); + if (out == NULL) + goto ERROR2; + + fseek(in, 0L, SEEK_END); + sz = ftell(in); + fseek(in, 0L, SEEK_SET); + + if (sz % 512) + { + while ( ( ch = fgetc ( in ) ) != EOF ) + fputc ( ch, out ); + } + else + { + for (i=0; i< (sz/512); i++) + { + if ((fread(buf, 512, 1, in)) != 1) + goto ERROR1; + if ((fwrite(buf, 512, 1, out)) != 1) + goto ERROR1; + } + } + + fsync(out); + ret = 0; +ERROR1: + fclose ( out ); +ERROR2: + fclose ( in ); +ERROR3: + return ret; } int cmd_bml_erase_raw_partition(const char *partition) |