1 | /* 2 | blktest.c 3 | --------- 4 | Test driver for the block device simulator. 5 | 6 | $Id: blktest.c,v 1.3 2003/07/06 12:28:03 stewart Exp $ 7 | 8 | (C)2003 Stewart Smith 9 | Distributed under the GNU Public License 10 | */ 11 | 12 | #include "block_dev.h" 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | 17 | int main(int argc,char* argv[]) 18 | { 19 | struct block_device b; 20 | struct buffer_head* bh; 21 | int a; 22 | int i; 23 | int bsize = atoi(argv[2]); 24 | 25 | if(argc<3) 26 | { 27 | fprintf(stderr,"Usage:\n\t./blktest device blocksize blockcount\n\n"); 28 | exit(0); 29 | } 30 | 31 | block_dev_init(); 32 | block_dev_new(&b,argv[1],atoi(argv[2]),atoi(argv[3])); 33 | 34 | for(i=0;i<atoi(argv[3])/2;i++) 35 | { 36 | bh = bread(&b,i,atoi(argv[2])); 37 | a = write(STDOUT_FILENO,bh->b_data,bh->b_size); 38 | } 39 | 40 | for(i=atoi(argv[3])/4;i<atoi(argv[3])/2;i++) 41 | { 42 | bh = bread(&b,i,atoi(argv[2])); 43 | a = write(STDOUT_FILENO,bh->b_data,bh->b_size); 44 | } 45 | 46 | for(i=0;i<atoi(argv[3]);i++) 47 | { 48 | bh = bread(&b,i,atoi(argv[2])); 49 | a = write(STDOUT_FILENO,bh->b_data,bh->b_size); 50 | } 51 | 52 | for(i=atoi(argv[3])/4;i<atoi(argv[3])/2;i++) 53 | { 54 | bh = bread(&b,i,atoi(argv[2])); 55 | a = write(STDOUT_FILENO,bh->b_data,bh->b_size); 56 | } 57 | 58 | bh = bread(&b,0,bsize); 59 | set_buffer_dirty(bh); 60 | strcpy(bh->b_data,"Shut your fucking face, Uncle Fucker."); 61 | submit_bh(WRITE,bh); 62 | 63 | return 0; 64 | }