Skip to content

Commit b5ceb2c

Browse files
author
guhl
committed
misc_version 0.5 - added the -p option for an alternative backup path
1 parent f8f4763 commit b5ceb2c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

guhl/misc_version/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = 0.01
1+
VERSION = 0.5
22
CC = /usr/bin/arm-linux-gnueabi-gcc
33
CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\"
44
INCDIR = -I/usr/arm-linux-gnueabi/usr/include/ -I.

guhl/misc_version/misc_version.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
#define INFILE "/dev/block/mmcblk0p17"
2525
#define OUTFILE "/dev/block/mmcblk0p17"
26-
#define BACKUPFILE "/sdcard/part17backup-%lu.bin"
26+
#define PATH_FOR_BACKUP "/sdcard"
2727

2828
//#define INFILE "/opt/install/g2/my_dump/p17/mmcblk0p17.img"
2929
//#define OUTFILE "/opt/install/g2/my_dump/p17/mmcblk0p17-new.img"
3030
//#define BACKUPFILE "/opt/install/g2/my_dump/p17/part17backup-%lu.bin"
3131

3232
#define VERSION_A 0
33-
#define VERSION_B 4
33+
#define VERSION_B 5
3434

3535
int main(int argc, const char **argv) {
3636

@@ -39,6 +39,7 @@ int main(int argc, const char **argv) {
3939
const char* s_cid;
4040
const char* s_ruu_flag;
4141
const char s_ruu_string[15] = "SetRuuNbhUpdate";
42+
const char* s_backupPath;
4243

4344
if (argc>1) {
4445

@@ -47,6 +48,7 @@ int main(int argc, const char **argv) {
4748
gopt_option( 'v', 0, gopt_shorts( 'v' ), gopt_longs( "version" )),
4849
gopt_option( 'c', GOPT_ARG, gopt_shorts('c'), gopt_longs("cid")),
4950
gopt_option( 'r', GOPT_ARG, gopt_shorts( 'r' ), gopt_longs( "setRUUflag" )),
51+
gopt_option( 'p', GOPT_ARG, gopt_shorts( 'p' ), gopt_longs("path")),
5052
gopt_option( 's', GOPT_ARG, gopt_shorts( 's' ), gopt_longs( "set_version" ))));
5153

5254
if( gopt( options, 'h' ) ){
@@ -102,6 +104,12 @@ int main(int argc, const char **argv) {
102104
}
103105
}
104106

107+
if(gopt_arg(options, 'p', &s_backupPath))
108+
{
109+
// if -p or --path was specified, set backup path
110+
printf("--path set. backups will be stored in: %s instead of %s \n", s_backupPath, PATH_FOR_BACKUP);
111+
}
112+
105113
} else {
106114
help = 1;
107115
}
@@ -114,16 +122,20 @@ int main(int argc, const char **argv) {
114122
fprintf( stdout, "\t-v | --version: display program version\n" );
115123
fprintf( stdout, "\t-c | --cid <CID>: set the CID in misc to the 8-char long CID\n");
116124
fprintf( stdout, "\t-s | --set_version <VERSION>: set the version in misc to the 10-char long VERSION\n" );
125+
fprintf( stdout, "\t-p | --path: <backup path>: create backup files in directory <backup path>\n");
117126
fprintf( stdout, "\t-r | --setRUUflag <on|off>. Set of clear the RUU flag\n" );
118127
exit(0);
119128
}
120129

130+
if (s_backupPath == NULL)
131+
s_backupPath = PATH_FOR_BACKUP;
132+
121133
char *backupFile;
122134
time_t ourTime;
123135

124136
ourTime = time(0);
125-
backupFile = malloc(snprintf(0, 0, BACKUPFILE, ourTime) + 1);
126-
sprintf(backupFile, BACKUPFILE, ourTime);
137+
backupFile = malloc(snprintf(0, 0, "%s/part17backup-%lu.bin", s_backupPath, ourTime) + 1);
138+
sprintf(backupFile, "%s/part17backup-%lu.bin", s_backupPath, ourTime);
127139

128140
FILE *fdin, *fdout;
129141
char ch;

0 commit comments

Comments
 (0)