9
#define FILENAME "test.dat"
16
uint32_t deadbeef = 0xdeadbeef;
17
uint32_t baadf00d = 0xbaadf00d;
22
printf("Verifying that lseek() doesn't change the file size\n");
24
fd = open(FILENAME, (O_CREAT | O_EXCL| O_WRONLY));
26
printf("Error attempting to create new file [%s]\n", FILENAME);
30
size = lseek(fd, 4096, SEEK_END);
32
printf("Expected 4096 from lseek; got [%lld]\n", size);
37
rc = stat(FILENAME, &s);
39
printf("Error attempting to stat file [%s]\n", FILENAME);
44
printf("Filesize is [%lld]; expected 0\n", s.st_size);
50
printf("Verifying that intermediate regions of the file are "
51
"initialized to 0 on lseek() and write() events\n");
52
fd = open(FILENAME, (O_CREAT | O_EXCL| O_RDWR), S_IRWXU);
54
printf("Error attempting to create new file [%s]\n", FILENAME);
58
if ((size = lseek(fd, 4096, SEEK_END)) != 4096) {
59
printf("Expected 4096 from lseek; got [%lld]\n", size);
63
if ((size = write(fd, (char *)&deadbeef, 4)) != 4) {
64
printf("Expected a write of 4 bytes; got [%lld] instead\n",
69
if ((size = lseek(fd, 5120, SEEK_SET)) != 5120) {
70
printf("Expected 5120 from lseek; got [%lld]\n", size);
74
if ((size = write(fd, (char *)&baadf00d, 4)) != 4) {
75
printf("Expected a write of 4 bytes; got [%lld] instead\n",
80
if ((size = lseek(fd, 4096, SEEK_SET)) != 4096) {
81
printf("Expected 4096 from lseek; got [%lld]\n", size);
85
if ((size = read(fd, buf, 4)) != 4) {
86
printf("Error attempting to read data. Expected [%lld] bytes; "
87
"read [%lld] instead\n", 4, size);
91
if (memcmp((char *)&deadbeef, buf, 4) != 0) {
92
printf("deadbeef data mismatch on initial write\n");
96
if ((size = read(fd, buf, 1020)) != 1020) {
97
printf("Error attempting to read data. Expected [%lld] bytes; "
98
"read [%lld] instead\n", 1020, size);
102
for (i = 0; i < 1020; i++)
103
if (buf[i] != 0x00) {
104
printf("Byte [%d] is [0x%.2x]; expected [0x00]\n", i,
109
if ((size = read(fd, buf, 4)) != 4) {
110
printf("Error attempting to read data. Expected [%lld] bytes; "
111
"read [%lld] instead\n", 4, size);
115
if (memcmp((char *)&baadf00d, buf, 4) != 0) {
116
printf("baadf00d data mismatch on initial write\n");
120
if ((size = read(fd, buf, 1)) != 0) {
121
printf("Error attempting to read data. Expected [%lld] bytes; "
122
"read [%lld] instead\n", 0, size);
126
if ((size = lseek(fd, 0, SEEK_SET)) != 0) {
127
printf("Expected 0 from lseek; got [%lld]\n", size);
131
if ((size = read(fd, buf, 4096)) != 4096) {
132
printf("Error attempting to read data. Expected [%lld] bytes; "
133
"read [%lld] instead\n", 4096, size);
137
for (i = 0; i < 4096; i++)
138
if (buf[i] != 0x00) {
139
printf("Byte [%d] is [0x%.2x]; expected [0x00]\n", i,
145
rc = stat(FILENAME, &s);
147
printf("Error attempting to stat file [%s]\n", FILENAME);
151
if (s.st_size != 5124) {
152
printf("Filesize is [%lld]; expected 5124\n", s.st_size);
156
fd = open(FILENAME, (O_RDONLY));
158
printf("Error attempting to create new file [%s]\n", FILENAME);
162
if ((size = read(fd, buf, 4096)) != 4096) {
163
printf("Error attempting to read data. Expected [%lld] bytes; "
164
"read [%lld] instead\n", 4096, size);
168
for (i = 0; i < 4096; i++)
169
if (buf[i] != 0x00) {
170
printf("Byte [%d] is [0x%.2x]; expected [0x00]\n", i,
175
if ((size = read(fd, buf, 4)) != 4) {
176
printf("Error attempting to read data. Expected [%lld] bytes; "
177
"read [%lld] instead\n", 4, size);
181
if (memcmp((char *)&deadbeef, buf, 4) != 0) {
182
printf("deadbeef data mismatch after initial write\n");
186
if ((size = read(fd, buf, 1020)) != 1020) {
187
printf("Error attempting to read data. Expected [%lld] bytes; "
188
"read [%lld] instead\n", 1020, size);
192
for (i = 0; i < 1020; i++)
193
if (buf[i] != 0x00) {
194
printf("Byte [%d] is [0x%.2x]; expected [0x00]\n", i,
199
if ((size = read(fd, buf, 4)) != 4) {
200
printf("Error attempting to read data. Expected [%lld] bytes; "
201
"read [%lld] instead\n", 4, size);
205
if (memcmp((char *)&baadf00d, buf, 4) != 0) {
206
printf("baadf00d data mismatch after initial write\n");
210
if ((size = read(fd, buf, 1)) != 0) {
211
printf("Error attempting to read data. Expected [%lld] bytes; "
212
"read [%lld] instead\n", 0, size);