Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apa_dump_header: discard usage of osal_xxx function #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions apa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,29 +1268,34 @@ char *ppa_files_name[] = {
NULL,
};

int apa_dump_header(hio_t *hio, u_int32_t starting_partition_sector)
int apa_dump_header(const char *path, u_int32_t starting_partition_sector)
{
int index = 0;
ppaa_partition_t *head;
int index = 0, result;
char *buffer;
u_int32_t bytes_read;
size_t bytes_read, bytes_to_read;
FILE *fd;
long int offset = PPAA_START + starting_partition_sector * 512;

buffer = osal_alloc(4 _MB);
result = hio->read(hio, starting_partition_sector + PPAA_START / 512, 4 _MB / 512, buffer, &bytes_read);
if (result != RET_OK)
return (result);
if ((fd = fopen(path, "r")) == NULL)
return -1;

head = (ppaa_partition_t *)buffer;
bytes_to_read = sizeof(ppaa_partition_t);
head = malloc(bytes_to_read);
fseek(fd, offset, SEEK_SET);
bytes_read = fread((void *)head, bytes_to_read, 1, fd);
if (!bytes_read)
return -1;

if (strncmp(head->magic, PPAA_MAGIC, sizeof(head->magic)))
return RET_BAD_APA;

while (index < 62) {
ssize_t bytes_to_read = head->file[index].size;
char *filename, genname[10];

if (bytes_to_read == 0)
break;
do {
FILE *fdump;
char *buffer, *filename, genname[10];
bytes_to_read = head->file[index].size;
if (bytes_to_read == 0) {
continue;
}

if (ppa_files_name[index])
filename = ppa_files_name[index];
Expand All @@ -1299,13 +1304,20 @@ int apa_dump_header(hio_t *hio, u_int32_t starting_partition_sector)
sprintf(genname, "HEADER_%d", index);
}

fprintf(stdout, "%-10s offset=0x%-10x size=%lu\n", filename, head->file[index].offset, bytes_to_read);
result = write_file(filename, buffer + head->file[index].offset, bytes_to_read);
if (result != RET_OK)
return (result);
index++;
}
buffer = malloc(bytes_to_read);
fseek(fd, offset + head->file[index].offset, SEEK_SET);
bytes_read = fread((void *)buffer, bytes_to_read, 1, fd);
if (!bytes_read)
return -1;

osal_free(buffer);
fprintf(stdout, "%-10s offset=0x%-10x size=%lu\n", filename, head->file[index].offset, bytes_to_read);
fdump = fopen(filename, "wb");
bytes_read = fwrite(buffer, bytes_to_read, 1, fdump);
fclose(fdump);
free(buffer);
} while (++index < 62);

fclose(fd);
free(head);
return 0;
}
2 changes: 1 addition & 1 deletion apa.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int apa_initialize_ex(hio_t *hio, const char *file_name);
int apa_dump_mbr(const dict_t *config,
const char *device, const char *file_name);

int apa_dump_header(hio_t *hio, u_int32_t starting_partition_sector);
int apa_dump_header(const char *path, u_int32_t starting_partition_sector);

C_END

Expand Down
2 changes: 1 addition & 1 deletion hdl_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ dump_header(const dict_t *config,

if (result == RET_OK) {
u_int32_t start_sector = get_u32(&toc->slice[slice_index].parts[partition_index].header.start);
result = apa_dump_header(hio, start_sector);
result = apa_dump_header(device, start_sector);
}

apa_toc_free(toc), toc = NULL;
Expand Down