#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 = strtoull(argv[2], NULL, 0) * 512;   /* sector arg */
    char msg[] = "PWNED-PARTITION-WRITE\n";
    char buf[512];
    int fd = open(dev, O_WRONLY);
    if (fd < 0) { printf("open %s: %s\n", dev, strerror(errno)); return 1; }
    if (lseek(fd, off, SEEK_SET) < 0) printf("lseek: %s\n", strerror(errno));
    memset(buf, 'W', sizeof(buf));
    memcpy(buf, msg, strlen(msg));
    ssize_t n = write(fd, buf, sizeof(buf));
    printf("write(%s, sec=%lld) = %zd errno=%d (%s)\n", dev, (long long)(off/512), n, n<0?errno:0, n<0?strerror(errno):"ok");
    return 0;
}
