-
Notifications
You must be signed in to change notification settings - Fork 14
/
td.cpp
57 lines (44 loc) · 895 Bytes
/
td.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <string.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/loop.h> /* ioctl_list */
int main(int argc, char *argv[])
{
char *path, cache_type;
if (argc != 2) {
fprintf(stderr, "usage: %s /dev/minibd0 \n", argv[0]);
return 1;
}
path = argv[1];
int fd = open(path, O_RDWR);
printf("opened\n");
if (fd < 0) {
perror("Failed to open device");
return 1;
}
for( int idx = 0 ; idx < 5 ; idx ++ )
{
const int buffer_size = 512;
char buf[buffer_size +1];
int n = read( fd, buf, buffer_size );
printf(" read idx = %d, n = %d\n",idx,n);
}
// int cmd = LOOP_SET_FD;
/* enable cache with type */
/*
if (ioctl(fd, cmd, cache_type)) {
perror("ioctl");
return 1;
}
*/
printf("closed\n");
if (close(fd) < 0) {
perror("close");
return 1;
}
return 0;
}