Created
May 21, 2012 11:38
-
-
Save cypres/2761946 to your computer and use it in GitHub Desktop.
Solaris Drive Blocksize Inspect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Credit goes to: | |
| * http://solaris.kuehnke.de/archives/18-Checking-physical-sector-size-of-disks-on-Solaris.html | |
| * Compile: gcc blocksize.c -o blocksize | |
| * Use: ie. ./blocksize /dev/rdsk/c0t5000C5004A918814d0 | |
| */ | |
| #include <sys/types.h> | |
| #include <fcntl.h> | |
| #include <sys/ioctl.h> | |
| #include <sys/dkio.h> | |
| #include <sys/vtoc.h> | |
| #include <unistd.h> | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <errno.h> | |
| void | |
| mediainfo(char *path) | |
| { | |
| struct dk_minfo dkmp; | |
| struct dk_minfo_ext dkmp_ext; | |
| int fd; | |
| fd = open(path, O_RDONLY); | |
| if (fd < 0) { | |
| fprintf(stderr, "getsize: open %s: %s\n", path, strerror(errno)); | |
| exit(1); | |
| } | |
| if (ioctl(fd, DKIOCGMEDIAINFO, &dkmp) < 0) { | |
| fprintf(stderr, "getsize: ioctl DKIOCGMEDIAINFO %s: %s\n", path, | |
| strerror(errno)); | |
| exit(1); | |
| } | |
| printf ("dkmp.dki_capacity = %llu\n", dkmp.dki_capacity); | |
| printf ("dkmp.dki_lbsize = %u\n", dkmp.dki_lbsize); | |
| if (ioctl(fd, DKIOCGMEDIAINFOEXT, &dkmp_ext) < 0) { | |
| fprintf(stderr, "getsize: ioctl DKIOCGMEDIAINFOEXT %s: %s\n", path, | |
| strerror(errno)); | |
| exit(1); | |
| } | |
| printf ("dkmp_ext.dki_capacity = %llu\n", dkmp_ext.dki_capacity); | |
| printf ("dkmp_ext.dki_lbsize = %u\n", dkmp_ext.dki_lbsize); | |
| printf ("dkmp_ext.dki_pbsize = %u\n", dkmp_ext.dki_pbsize); | |
| (void)close(fd); | |
| } | |
| int | |
| main(int argc, char *argv[]) | |
| { | |
| if (argc != 2) | |
| { | |
| fprintf(stderr, "getsize: usage: getsize <Raw Device>\n"); | |
| exit(1); | |
| } | |
| mediainfo(argv[1]); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment