#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, newchar = 'a'; struct blkdev_ioctl_param ioctl_param; if( argc > 1 ) newchar = argv[1][0]; 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 + 2 ); ioctl_param.content_length = blksz ; printf(" block size appears to be %d\n", blksz ); memset( lastblock, newchar, blksz + 2 ); ioctl_param.block_contents = lastblock; rc = ioctl(filedes, BLKSETLASTSECT, &ioctl_param) ; printf(" last sect ioctl rc: %d\n", rc); return 0; }