Skip to content

Commit

Permalink
diskdump: Introduce read_pd()
Browse files Browse the repository at this point in the history
Standalone function for reading of page descriptors is needed later for
of expected core size and detection of incomplete dumps.

Signed-off-by: Roman Bolshakov <[email protected]>
  • Loading branch information
Roman Bolshakov authored and k-hagio committed Jul 28, 2021
1 parent 1425b05 commit 881f33d
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions diskdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,27 @@ arm_kdump_header_adjust(int header_version)
}
#endif /* __i386__ && (ARM || MIPS) */

/*
* Read page descriptor.
*/
static int
read_pd(int fd, off_t offset, page_desc_t *pd)
{
const off_t failed = (off_t)-1;

if (FLAT_FORMAT()) {
if (!read_flattened_format(fd, offset, pd, sizeof(*pd)))
return READ_ERROR;
} else {
if (lseek(fd, offset, SEEK_SET) == failed)
return SEEK_ERROR;
if (read(fd, pd, sizeof(*pd)) != sizeof(*pd))
return READ_ERROR;
}

return 0;
}

static int
read_dump_header(char *file)
{
Expand Down Expand Up @@ -1130,15 +1151,9 @@ cache_page(physaddr_t paddr)
+ (off_t)(desc_pos - 1)*sizeof(page_desc_t);

/* read page descriptor */
if (FLAT_FORMAT()) {
if (!read_flattened_format(dd->dfd, seek_offset, &pd, sizeof(pd)))
return READ_ERROR;
} else {
if (lseek(dd->dfd, seek_offset, SEEK_SET) == failed)
return SEEK_ERROR;
if (read(dd->dfd, &pd, sizeof(pd)) != sizeof(pd))
return READ_ERROR;
}
ret = read_pd(dd->dfd, seek_offset, &pd);
if (ret)
return ret;

/* sanity check */
if (pd.size > block_size)
Expand Down

0 comments on commit 881f33d

Please sign in to comment.