DragonFlyBSD Kernel Audit
DF-2910 / probe.c
← back to finding ↓ download raw
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main(int argc, char **argv) {
    const char *dev = argv[1];
    off_t off = argc > 2 ? strtoull(argv[2], NULL, 0) : 0;
    char buf[512];
    int fd = open(dev, O_RDONLY);
    if (fd < 0) { printf("open %s: %s\n", dev, strerror(errno)); return 1; }
    if (lseek(fd, off, SEEK_SET) < 0) printf("lseek %lld: %s\n", (long long)off, strerror(errno));
    memset(buf, 0, sizeof(buf));
    ssize_t n = read(fd, buf, sizeof(buf));
    printf("read(%s, off=%lld) = %zd errno=%d (%s)\n", dev, (long long)off, n, n < 0 ? errno : 0, n < 0 ? strerror(errno) : "ok");
    if (n > 0) printf("  bytes: %.32s\n", buf);
    return 0;
}