local: Use new disk functions
This commit is contained in:
1 parent
e00331fb42
commit
e30e08136a
1 file changed
+35
-60
+35
-60
@@ -282,36 +282,22 @@ static struct nanddump_device nanddump[] = {
|
||||
|
||||
#undef NANDDUMP
|
||||
|
||||
int local_dump_image(enum image_type image, const char * file) {
|
||||
static void local_find_internal_mydocs(int * maj, int * min) {
|
||||
|
||||
int ret = -1;
|
||||
int fd = -1;
|
||||
unsigned char * addr = NULL;
|
||||
off_t nlen, len;
|
||||
int align;
|
||||
int fd;
|
||||
DIR * dir;
|
||||
DIR * dir2;
|
||||
FILE * f;
|
||||
struct dirent * dirent;
|
||||
struct dirent * dirent2;
|
||||
struct stat st;
|
||||
int maj, min;
|
||||
char buf[1024];
|
||||
char blk[1024];
|
||||
|
||||
printf("Dump %s image to file %s...\n", image_type_to_string(image), file);
|
||||
|
||||
if ( image == IMAGE_MMC ) {
|
||||
|
||||
maj = -1;
|
||||
min = -1;
|
||||
|
||||
/* Find block device in /dev/ for MyDocs (mmc device, partition 1) */
|
||||
/* Find min & maj id for block device MyDocs (mmc device, partition 1) */
|
||||
|
||||
dir = opendir("/sys/class/mmc_host/");
|
||||
if ( ! dir ) {
|
||||
ERROR("Cannot find MyDocs mmc device: Opening '/sys/class/mmc_host/' failed");
|
||||
goto clean;
|
||||
return;
|
||||
}
|
||||
|
||||
while ( ( dirent = readdir(dir) ) ) {
|
||||
@@ -327,6 +313,7 @@ int local_dump_image(enum image_type image, const char * file) {
|
||||
if ( read(fd, buf, sizeof(buf)-1) < 0 )
|
||||
buf[0] = 0;
|
||||
close(fd);
|
||||
fd = -1;
|
||||
|
||||
if ( strncmp(buf, "internal", sizeof("internal")-1) != 0 )
|
||||
continue;
|
||||
@@ -350,9 +337,9 @@ int local_dump_image(enum image_type image, const char * file) {
|
||||
if ( ! f )
|
||||
continue;
|
||||
|
||||
if ( fscanf(f, "%d:%d", &maj, &min) != 2 ) {
|
||||
maj = -1;
|
||||
min = -1;
|
||||
if ( fscanf(f, "%d:%d", maj, min) != 2 ) {
|
||||
*maj = -1;
|
||||
*min = -1;
|
||||
fclose(f);
|
||||
continue;
|
||||
}
|
||||
@@ -364,61 +351,49 @@ int local_dump_image(enum image_type image, const char * file) {
|
||||
|
||||
closedir(dir2);
|
||||
|
||||
if ( maj != -1 && min != -1 )
|
||||
if ( *maj != -1 && *min != -1 )
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
}
|
||||
|
||||
int local_dump_image(enum image_type image, const char * file) {
|
||||
|
||||
int ret = -1;
|
||||
int fd = -1;
|
||||
unsigned char * addr = NULL;
|
||||
off_t nlen, len;
|
||||
int align;
|
||||
int maj, min;
|
||||
|
||||
printf("Dump %s image to file %s...\n", image_type_to_string(image), file);
|
||||
|
||||
if ( image == IMAGE_MMC ) {
|
||||
|
||||
maj = -1;
|
||||
min = -1;
|
||||
|
||||
local_find_internal_mydocs(&maj, &min);
|
||||
if ( maj == -1 || min == -1 ) {
|
||||
ERROR("Cannot find MyDocs mmc device: Slot 'internal' was not found");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
VERBOSE("Detected internal mmc device: major=%d minor=%d\n", maj, min);
|
||||
VERBOSE("Detected internal MyDocs mmc device: major=%d minor=%d\n", maj, min);
|
||||
|
||||
blk[0] = 0;
|
||||
|
||||
dir = opendir("/dev/");
|
||||
if ( ! dir ) {
|
||||
ERROR("Cannot find MyDocs mmc device: Opening '/dev/' failed");
|
||||
fd = disk_open_dev(maj, min, 1, 1);
|
||||
if ( fd < 0 ) {
|
||||
ERROR("Cannot open MyDocs mmc device in /dev/");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
while ( ( dirent = readdir(dir) ) ) {
|
||||
ret = disk_dump_dev(fd, file);
|
||||
|
||||
if ( snprintf(buf, sizeof(buf), "/dev/%s", dirent->d_name) <= 0 )
|
||||
continue;
|
||||
|
||||
if ( stat(buf, &st) != 0 )
|
||||
continue;
|
||||
|
||||
if ( ! S_ISBLK(st.st_mode) )
|
||||
continue;
|
||||
|
||||
if ( makedev(maj, min) != st.st_rdev )
|
||||
continue;
|
||||
|
||||
strcpy(blk, buf);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
if ( ! blk[0] ) {
|
||||
ERROR("Cannot find MyDocs mmc device: Block device in /dev/ was not found");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
VERBOSE("Detected internal mmc device: '%s'\n", blk);
|
||||
|
||||
strncat(blk, "p1", sizeof(blk)-strlen(blk)-1);
|
||||
|
||||
printf("Using MyDocs mmc device: '%s'\n", blk);
|
||||
|
||||
ret = disk_dump_raw(blk, file);
|
||||
close(fd);
|
||||
fd = -1;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Reference in new issue
Block a user