#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>

#define SCSI_IOCTL_SET_CAPACITY 0x5388          /* set capacity */
#define SCSI_IOCTL_GET_CAPACITY 0x5389          /* get capacity */

int main(int argc, char **argv)
{
	int r;
	int fd;	
	if(argc < 2 || argc > 3) {
		printf("Usage: capacity <dev> [new-capacity]\n");
		return -1;
	}
	fd=open(argv[1],O_RDWR);
	if(argc==2) {
		int res;
		r = ioctl(fd,SCSI_IOCTL_GET_CAPACITY,&res);
		if(r<0) return -1;
		printf("%s size: %d\n",argv[0],res);
	} else if(argc==3) {
		int newsize=atoi(argv[2]);
		printf("setting to %d\n",newsize);
		r=ioctl(fd,SCSI_IOCTL_SET_CAPACITY,&newsize);
		printf("ioctl returned: %d\n",r);
	}
}


