Koushik Dutta | 68df48c | 2010-09-13 15:04:54 -0700 | [diff] [blame] | 1 | #include <ctype.h> |
| 2 | #include <errno.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <getopt.h> |
| 5 | #include <limits.h> |
| 6 | #include <linux/input.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | #include <sys/reboot.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <time.h> |
| 13 | #include <unistd.h> |
| 14 | |
| 15 | #include <sys/wait.h> |
| 16 | #include <sys/limits.h> |
| 17 | #include <dirent.h> |
| 18 | #include <sys/stat.h> |
| 19 | |
| 20 | #include <signal.h> |
| 21 | #include <sys/wait.h> |
| 22 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 23 | extern int __system(const char *command); |
Koushik Dutta | 02c3605 | 2010-12-12 02:52:44 -0800 | [diff] [blame] | 24 | #define BML_UNLOCK_ALL 0x8A29 ///< unlock all partition RO -> RW |
Koushik Dutta | 68df48c | 2010-09-13 15:04:54 -0700 | [diff] [blame] | 25 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 26 | int cmd_bml_restore_raw_partition(const char *partition, const char *filename) |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 27 | { |
Koushik Dutta | 03a4f5b | 2010-12-12 12:24:02 -0800 | [diff] [blame^] | 28 | char *bml; |
| 29 | if (strcmp(partition, "boot") == 0 || strcmp(partition, "recovery") == 0) |
| 30 | bml = "/dev/block/bml7"; |
| 31 | else |
| 32 | return 6; |
| 33 | |
| 34 | char buf[4096]; |
| 35 | int dstfd, srcfd, bytes_read, bytes_written, total_read = 0; |
| 36 | if (filename == NULL) |
| 37 | srcfd = 0; |
| 38 | else { |
| 39 | srcfd = open(filename, O_RDONLY | O_LARGEFILE); |
| 40 | if (srcfd < 0) |
| 41 | return 2; |
| 42 | } |
| 43 | dstfd = open(bml, O_RDWR | O_LARGEFILE); |
| 44 | if (dstfd < 0) |
| 45 | return 3; |
| 46 | if (ioctl(dstfd, BML_UNLOCK_ALL, 0)) |
| 47 | return 4; |
| 48 | do { |
| 49 | total_read += bytes_read = read(srcfd, buf, 4096); |
| 50 | if (!bytes_read) |
| 51 | break; |
| 52 | if (bytes_read < 4096) |
| 53 | memset(&buf[bytes_read], 0, 4096 - bytes_read); |
| 54 | if (write(dstfd, buf, 4096) < 4096) |
| 55 | return 5; |
| 56 | } while(bytes_read == 4096); |
| 57 | |
| 58 | return 0; |
Koushik Dutta | 68df48c | 2010-09-13 15:04:54 -0700 | [diff] [blame] | 59 | } |
Koushik Dutta | 56c1b3b | 2010-09-13 15:08:49 -0700 | [diff] [blame] | 60 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 61 | int cmd_bml_backup_raw_partition(const char *partition, const char *filename) |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 62 | { |
Koushik Dutta | 56c1b3b | 2010-09-13 15:08:49 -0700 | [diff] [blame] | 63 | char tmp[PATH_MAX]; |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 64 | sprintf("dd of=%s if=/dev/block/bml7 bs=4096", filename); |
Koushik Dutta | 56c1b3b | 2010-09-13 15:08:49 -0700 | [diff] [blame] | 65 | return __system(tmp); |
| 66 | } |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 67 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 68 | int cmd_bml_erase_raw_partition(const char *partition) |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 69 | { |
| 70 | // TODO: implement raw wipe |
| 71 | return 0; |
| 72 | } |
| 73 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 74 | int cmd_bml_erase_partition(const char *partition, const char *filesystem) |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 75 | { |
| 76 | return -1; |
| 77 | } |
| 78 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 79 | int cmd_bml_mount_partition(const char *partition, const char *mount_point, const char *filesystem, int read_only) |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 80 | { |
| 81 | return -1; |
| 82 | } |
| 83 | |
Steve Kondik | 4123b58 | 2010-11-14 03:18:40 -0500 | [diff] [blame] | 84 | int cmd_bml_get_partition_device(const char *partition, char *device) |
Koushik Dutta | e5c7e0e | 2010-11-11 01:19:10 -0800 | [diff] [blame] | 85 | { |
| 86 | return -1; |
| 87 | } |