diff options
author | atinm <atin.malaviya@gmail.com> | 2011-05-17 11:12:26 -0400 |
---|---|---|
committer | atinm <atin.malaviya@gmail.com> | 2011-05-17 11:12:26 -0400 |
commit | 93a7e5951c8dfcdf609161875493ef6925f68ca7 (patch) | |
tree | 4f6a18bc3d66a41021e627412a54bb80567264c3 /bmlutils/bmlwrite.c | |
parent | 306e030c5772b1cd1d38a4801db2bc128021003a (diff) | |
download | device_samsung_aries-common-93a7e5951c8dfcdf609161875493ef6925f68ca7.zip device_samsung_aries-common-93a7e5951c8dfcdf609161875493ef6925f68ca7.tar.gz device_samsung_aries-common-93a7e5951c8dfcdf609161875493ef6925f68ca7.tar.bz2 |
moved to device/samsung/aries-common
Diffstat (limited to 'bmlutils/bmlwrite.c')
-rw-r--r-- | bmlutils/bmlwrite.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bmlutils/bmlwrite.c b/bmlutils/bmlwrite.c new file mode 100644 index 0000000..74860c6 --- /dev/null +++ b/bmlutils/bmlwrite.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +#define BML_UNLOCK_ALL 0x8A29 ///< unlock all partition RO -> RW + +int main(int argc, char** argv) { + char buf[4096]; + int dstfd, srcfd, bytes_read, bytes_written, total_read = 0; + if (argc != 3) + return 1; + if (argv[1][0] == '-' && argv[1][1] == 0) + srcfd = 0; + else { + srcfd = open(argv[1], O_RDONLY | O_LARGEFILE); + if (srcfd < 0) + return 2; + } + dstfd = open(argv[2], O_RDWR | O_LARGEFILE); + if (dstfd < 0) + return 3; + if (ioctl(dstfd, BML_UNLOCK_ALL, 0)) + return 4; + do { + total_read += bytes_read = read(srcfd, buf, 4096); + if (!bytes_read) + break; + if (bytes_read < 4096) + memset(&buf[bytes_read], 0, 4096 - bytes_read); + if (write(dstfd, buf, 4096) < 4096) + return 5; + } while(bytes_read == 4096); + return 0; +} |