Skip to content

Instantly share code, notes, and snippets.

@duedal

duedal/blocksize.c

Created May 21, 2012
Embed
What would you like to do?
Solaris Drive Blocksize Inspect
/*
* 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
You can’t perform that action at this time.