/* Code to read ufs superblock */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>

struct ufs_super_block
{
  u_char     s_dummy[0x55c];
  u_char     s_magic[4];
  u_char     s_pad[160];
};

int
main(int argc, char **argv)
{
  off_t seekpos;
  ssize_t rbytes;
  char *device;
  int fd;
  char *progname = argv[0];
  struct ufs_super_block ufs_sblock;
  char buf[1024];

  if (argc != 2) {
    fprintf(stderr, "Usage: %s partition\n", progname);
    exit(EXIT_FAILURE);
  }
  device = argv[1];
  fd = open(device, O_RDONLY);
  if (fd < 0) {
    perror(progname);
    exit(EXIT_FAILURE);
  }

  /* seek to reiserfs offset */
  seekpos = lseek(fd, 8192, SEEK_SET);
  /* Trying for a regular ufs partition */
  rbytes = read(fd, (char *)&ufs_sblock, sizeof(ufs_sblock));

  if (rbytes < 0)
    perror(argv[0]);
  printf("Data read\n\n%s\n", ufs_sblock.s_magic);
  return 0;
}
