#include #include #include #include #include #define BLKGETLASTSECT _IO(0x12,108) /* get last sector of block device */ #define BLKSETLASTSECT _IO(0x12,109) /* get last sector of block device */ #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ struct blkdev_ioctl_param { unsigned int block; size_t content_length; char * block_contents; }; main(int argc, char *argv[]) { int filedes, rc=0, blksz=0; char *lastblock; struct blkdev_ioctl_param ioctl_param; ioctl_param.block = 0; filedes = open("/dev/sdb", O_RDONLY ); printf(" open filedes: %d\n", filedes); rc = ioctl(filedes, BLKSSZGET, &blksz) ; lastblock = (char *) malloc( blksz + 8 ); ioctl_param.content_length = blksz; printf(" block size appears to be %d\n", blksz); memset( lastblock, 'z', blksz + 8 ); ioctl_param.block_contents = lastblock; rc = ioctl(filedes, BLKGETLASTSECT, &ioctl_param) ; printf(" last sect ioctl rc: %d\n", rc); lastblock[blksz + 1] = '\0'; printf(" Last Block: \n%s<--\n", lastblock); return 0; }