6 #include <sys/unistd.h>
7 #include <sys/inttypes.h>
9 int main(int argc
, char **argv
)
17 printf("seektest filename\n");
20 fd
= open(argv
[1], 0, O_RDONLY
);
22 printf("can't open `%s` : %s\n", argv
[1], strerror(errno
));
26 printf("Statting file\n");
27 error
= fstat(fd
, &st
);
29 printf("can't stat file\n");
32 printf("fstat() returns %"PRIi64
" as size\n", st
.st_size
);
34 error
= stat(argv
[1], &st
);
36 printf("can't stat file\n");
39 printf("stat() returns %"PRIi64
" as size\n", st
.st_size
);
41 error
= lstat(argv
[1], &st
);
43 printf("can't lstat file\n");
46 printf("lstat() returns %"PRIi64
" as size\n", st
.st_size
);
48 printf("\nTesting normal seeking\n");
49 printf("get initial position\n");
50 cur
= lseek(fd
, 0, SEEK_CUR
);
51 printf("seek start %"PRIi64
"\n", cur
);
53 printf("seek initial position wrong\n");
57 printf("seeking end (filesize = %"PRIi64
")\n", st
.st_size
);
58 cur
= lseek(fd
, 0, SEEK_END
);
59 printf("seek now %"PRIi64
"\n", cur
);
60 if (cur
!= st
.st_size
) {
61 printf("seek to the end went wrong\n");
65 printf("seeking backwards filesize-150 steps\n");
66 cur
= lseek(fd
, -(st
.st_size
- 150), SEEK_CUR
);
67 printf("seek now %"PRIi64
"\n", cur
);
69 printf("relative seek from end to 150 failed\n");
73 printf("seek set 1000\n");
74 cur
= lseek(fd
, 1000, SEEK_SET
);
75 printf("seek now %"PRIi64
"\n", cur
);
77 printf("seek 1000 went wrong\n");
82 printf("\nOne piece non sparse file checking:\n");
83 printf("seeking for sparse file data offset\n");
84 cur
= lseek(fd
, 0, SEEK_DATA
);
86 printf("Not getting start of data segment at 0\n");
90 printf("if seek_data returns a 2nd part on a non-sparse file\n");
91 cur
= lseek(fd
, st
.st_size
, SEEK_DATA
);
93 printf("Seek data gave 2nd part at end of file\n");
97 printf( "Seek data on the end of file didn't"
102 printf( "if seek_data in the file's last block of a non-sparse file "
103 "returns the current position\n");
104 cur
= lseek(fd
, st
.st_size
-50, SEEK_DATA
);
105 if (cur
!= st
.st_size
- 50) {
106 printf("Seek data didn't give passed seek position back\n");
107 printf("%"PRIi64
" should be %"PRIi64
"\n", cur
, st
.st_size
-50);
111 printf( "if seek_data in the middle of the of a non-sparse file "
112 "returns the current position\n");
113 cur
= lseek(fd
, st
.st_size
-100*1024, SEEK_DATA
);
114 if (cur
!= st
.st_size
- 100*1024) {
115 printf("Seek data didn't give passed seek position back\n");
116 printf("%"PRIi64
" should be %"PRIi64
"\n", cur
,
117 st
.st_size
-100*1024);
121 printf("seeking for hole\n");
122 cur
= lseek(fd
, 0, SEEK_HOLE
);
123 if (cur
!= st
.st_size
) {
124 printf("Seek hole didn't return end of file\n");
128 printf("seeking if the end of the file is a hole\n");
129 cur
= lseek(fd
, st
.st_size
, SEEK_HOLE
);
130 if (cur
!= st
.st_size
) {
131 printf("At the end of the file, no virtual hole is returned\n");
135 printf("seeking if a 2nd hole is returned outside the file range\n");
136 cur
= lseek(fd
, st
.st_size
+ 1, SEEK_HOLE
);
138 printf( "Past the end of file, seek hole returned another hole "
139 "instead of raising an error\n");
142 if (errno
!= ENXIO
) {
143 printf("Seek hole past the end of file didn't raise ENXIO\n");