summaryrefslogtreecommitdiff
path: root/src/test.c (plain)
blob: caf6aecc8da65510b8a10119fc6c76e97553a73f
1#include <stdio.h>
2#include <string.h>
3
4//#include <sys/types.h>
5#include <unistd.h>
6#include <errno.h>
7#include <fcntl.h>
8
9//#define O_RDWR 00000000
10//#define __u64 unsigned long long
11
12
13#define BUFFERSIZE 16
14
15
16/*****************************************
17*
18* /bin/test /media/usba1/
19*
20*****************************************/
21
22int main(int argc,char* argv[])
23{
24 char *filestr = argv[1];
25 int fd ;
26 __s64 start= 0;
27 __s32 total=0;
28 __u32 start_h= 0;//, total_h=0;
29 __u32 start_l= 0;//, total_l=0;
30 __u8 buffer[BUFFERSIZE];
31
32 if(argc < 4)
33 {
34 printf("< 4 args\n");
35 printf("format:filestr start_h(0x):start_l size(0x)\n");
36 return -1;
37 }
38
39 fd =open(filestr,O_RDWR|O_LARGEFILE,0);
40 if(fd < 0)
41 {
42 printf("open %s fail\n",filestr);
43 return -1;
44 }
45
46 sscanf(argv[2],"0x%x:%x",&start_h,&start_l);
47 sscanf(argv[3],"0x%x",&total);
48
49 start=((__s64)start_h<<32)+start_l;
50 if(start < 0 || total< 0 )
51 {
52 printf("start or total <0 \n");
53 return -1;
54 }
55
56 if(start!=lseek64(fd,start,SEEK_SET))
57 {
58 printf("lseek64 fail \n");
59 return -1;
60 }
61
62 printf("read start from 0x%x:%x\n",start_h ,start_l );
63 printf("total= 0x%x bytes\n",total );
64
65 for ( ;total>0 ; total-=BUFFERSIZE)
66 {
67 int i;
68 memset(buffer,0,BUFFERSIZE);
69 if(read(fd,buffer,BUFFERSIZE)<0)
70 {
71 printf("read at 0x%x%x fail\n", (__u32)(start>>32),(__u32)(start&0xffffffff));
72 printf("errno=%d\n",errno);
73 break;
74 }
75
76 for(i=0;i<BUFFERSIZE;i++)
77 {
78 printf("%02x ",buffer[i]);
79 }
80 printf("\n");
81
82////////////////add you code here////////////////////////////
83
84 }
85 close(fd);
86 return 0;
87}
88
89