Created
January 31, 2020 11:45
-
-
Save tkhai/5514217f927c322d3cf00505a18fd7da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <stdint.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#define __u8 uint8_t | |
#define __u32 uint32_t | |
#define __u64 uint64_t | |
#pragma pack(push,1) | |
struct ploop_pvd_header | |
{ | |
__u8 m_Sig[16]; /* Signature */ | |
__u32 m_Type; /* Disk type */ | |
__u32 m_Heads; /* heads count */ | |
__u32 m_Cylinders; /* tracks count */ | |
__u32 m_Sectors; /* Sectors per track count */ | |
__u32 m_Size; /* Size of disk in tracks */ | |
union { /* Size of disk in 512-byte sectors */ | |
struct { | |
__u32 m_SizeInSectors_v1; | |
__u32 Unused; | |
}; | |
__u64 m_SizeInSectors_v2; | |
}; | |
__u32 m_DiskInUse; /* Disk in use */ | |
__u32 m_FirstBlockOffset; /* First data block offset (in sectors) */ | |
__u32 m_Flags; /* Misc flags */ | |
__u8 m_Reserved[8]; /* Reserved */ | |
}; | |
#pragma pack(pop) | |
main(int argc, char *argv[]) | |
{ | |
char version[17] = { 0 }; | |
struct ploop_pvd_header hdr; | |
unsigned long i; | |
int fd; | |
if (argc != 2) { | |
errno = -EINVAL; | |
perror("arguments"); | |
exit(1); | |
} | |
fd = open(argv[1], O_RDONLY); | |
if (fd < 0) { | |
perror("open"); | |
exit(1); | |
} | |
read(fd, &hdr, sizeof(hdr)); | |
memcpy(version, &hdr.m_Sig, 16); | |
printf("m_Type=%u, m_Sig=%s, m_Sectors=%u, m_Size=%u, m_SizeInSectors_v2=%lu, m_FirstBlockOffset=%u\n", | |
hdr.m_Type, version, hdr.m_Sectors, hdr.m_Size, le64toh(hdr.m_SizeInSectors_v2), hdr.m_FirstBlockOffset); | |
lseek(fd, 64, SEEK_SET); | |
for (i = 0; i < hdr.m_Size; i++) { | |
unsigned int blk; | |
read(fd, &blk, sizeof(blk)); | |
printf("%d->%d\n", i, blk); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment