/* cc -o readlabel sun_read_disk_label.c * * A simple program to read disk labels on Sun systems . * usage: readlabel /dev/rdsk/cNtXdYsZ * * Author: Paul Farrall pfarrall@brains2bytes.com * Copyright 2001, 2002 Paul Farrall * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * */ #include #include #include #include #include #include #define MAXLEN 20 /* enough to hold "/dev/rdsk/cXtYdZsN" */ #define PROGNAME "readlabel" /* Name of this program */ void usage() { printf("Usage:\n\t%s (Device name like \"/dev/rdsk/c0t0d0s0\")\n", PROGNAME); return; } void err_exit(char * str) { perror(str); exit(1); } int main(int argc, char * argv[]) { char fname[MAXLEN]; int fd; struct dk_label label; /* from */ if (argc < 2) { usage(); exit(1); } if (geteuid() != 0) err_exit("You must be root to run this program"); if (snprintf(fname, MAXLEN, "%s", argv[1]) < strlen(argv[1])) err_exit("There was a problem reading arg1"); if ( (fd = open(fname, O_RDONLY)) < 0) err_exit("Problem opening file"); if (lseek(fd, DK_LABEL_LOC, SEEK_SET) != DK_LABEL_LOC) err_exit("Problem with lseek"); if (read(fd, &label, sizeof(label)) != sizeof(label)) err_exit("Problem reading file"); printf("%s => %s\n", fname, label.dkl_asciilabel); return(0); }