/* -*- Mode: Linux-C -*-
 *
 * Reads a 1K block from a device by lseeking.
 */

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int
main(int argc, char* argv[])
{
    char buf[1024];
    unsigned long blocknr;
    int fd, i;
    
    if (argc != 3) {
	fprintf(stderr, "usage: %s <block> <special>\n", argv[0]);
	exit(1);
    }

    blocknr = strtol(argv[1], NULL, 0);
    fprintf(stderr, "blocknr = %ld\n", blocknr);

    if ((fd = open(argv[2], O_RDONLY)) < 0) {
	perror("open failed");
	exit(1);
    }

    if (lseek(fd, blocknr * sizeof(buf), SEEK_SET) < 0) {
	perror("lseek failed");
	close(fd);
	exit(1);
    }

    if (read(fd, buf, sizeof(buf)) < 0) {
	perror("read failed");
	close(fd);
	exit(1);
    }

    close(fd);

    for (i = 0; i < sizeof(buf); ++i)
	fputc(buf[i], stdout);

    return 0;
}

