-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
74 lines (61 loc) · 1.62 KB
/
test.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdlib.h>
#include <stdio.h>
#include "extmem.h"
int main(int argc, char **argv)
{
Buffer buf; /* A buffer */
unsigned char *blk; /* A pointer to a block */
int i = 0;
/* Initialize the buffer */
if (!initBuffer(520, 64, &buf))
{
perror("Buffer Initialization Failed!\n");
return -1;
}
/* Get a new block in the buffer */
blk = getNewBlockInBuffer(&buf);
/* Fill data into the block */
for (i = 0; i < 8; i++)
*(blk + i) = 'a' + i;
/* Write the block to the hard disk */
if (writeBlockToDisk(blk, 0, &buf) != 0)
{
perror("Writing Block Failed!\n");
return -1;
}
/* Read the block from the hard disk */
if ((blk = readBlockFromDisk(0, &buf)) == NULL)
{
perror("Reading Block Failed!\n");
return -1;
}
/* Process the data in the block */
int X = -1;
int Y = -1;
int addr = -1;
char str[5];
printf("block 1:\n");
for (i = 0; i < 7; i++) //一个blk存7个元组加一个地址
{
for (int k = 0; k < 4; k++)
{
str[k] = *(blk + i*8 + k);
}
X = atoi(str);
for (int k = 0; k < 4; k++)
{
str[k] = *(blk + i*8 + 4 + k);
}
Y = atoi(str);
printf("(%d, %d) ", X, Y);
}
for (int k = 0; k < 4; k++)
{
str[k] = *(blk + i*8 + k);
}
addr = atoi(str);
printf("\nnext address = %d \n", addr);
printf("\n");
printf("IO's is %d\n", buf.numIO); /* Check the number of IO's */
return 0;
}