* Rewritten 8/98 by Conrad Minshall.
*
* Small changes to work under Linux -- davej.
+ *
+ * Checks for mmap last-page zero fill.
*/
#include "global.h"
exit(67);
}
if (lite) {
- off_t size_by_seek = lseek(fd, (off_t)0, L_XTND);
+ off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
if (size_by_seek == (off_t)-1)
prterr("save_buffer: lseek eof");
else if (bufferlength > size_by_seek) {
- warn("save_buffer: .fsxgood file too short... will save 0x%qx bytes instead of 0x%qx\n", (unsigned long long)size_by_seek,
+ warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
(unsigned long long)bufferlength);
bufferlength = size_by_seek;
}
if (byteswritten == -1)
prterr("save_buffer write");
else
- warn("save_buffer: short write, 0x%x bytes instead of 0x%qx\n",
+ warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
(unsigned)byteswritten,
(unsigned long long)bufferlength);
}
unsigned op = 0;
unsigned bad = 0;
- if (bcmp(good_buf + offset, temp_buf, size) != 0) {
+ if (memcmp(good_buf + offset, temp_buf, size) != 0) {
prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
offset, size, fname);
prt("OFFSET\tGOOD\tBAD\tRANGE\n");
prterr("check_size: fstat");
statbuf.st_size = -1;
}
- size_by_seek = lseek(fd, (off_t)0, L_XTND);
+ size_by_seek = lseek(fd, (off_t)0, SEEK_END);
if (file_size != statbuf.st_size || file_size != size_by_seek) {
- prt("Size error: expected 0x%qx stat 0x%qx seek 0x%qx\n",
+ prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
(unsigned long long)file_size,
(unsigned long long)statbuf.st_size,
(unsigned long long)size_by_seek);
}
+void
+check_eofpage(char *s, unsigned offset, char *p, int size)
+{
+ unsigned long last_page, should_be_zero;
+
+ if (offset + size <= (file_size & ~page_mask))
+ return;
+ /*
+ * we landed in the last page of the file
+ * test to make sure the VM system provided 0's
+ * beyond the true end of the file mapping
+ * (as required by mmap def in 1996 posix 1003.1)
+ */
+ last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask;
+
+ for (should_be_zero = last_page + (file_size & page_mask);
+ should_be_zero < last_page + page_size;
+ should_be_zero++)
+ if (*(char *)should_be_zero) {
+ prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
+ s, file_size - 1, should_be_zero & page_mask,
+ short_at(should_be_zero));
+ report_failure(205);
+ }
+}
+
+
void
domapread(unsigned offset, unsigned size)
{
report_failure(190);
}
memcpy(temp_buf, p + pg_offset, size);
+
+ check_eofpage("Read", offset, p, size);
+
if (munmap(p, map_size) != 0) {
prterr("domapread: munmap");
report_failure(191);
gendata(original_buf, good_buf, offset, size);
if (file_size < offset + size) {
if (file_size < offset)
- bzero(good_buf + file_size, offset - file_size);
+ memset(good_buf + file_size, '\0', offset - file_size);
file_size = offset + size;
if (lite) {
warn("Lite file size bug in fsx!");
gendata(original_buf, good_buf, offset, size);
if (file_size < offset + size) {
if (file_size < offset)
- bzero(good_buf + file_size, offset - file_size);
+ memset(good_buf + file_size, '\0', offset - file_size);
file_size = offset + size;
if (lite) {
warn("Lite file size bug in fsx!");
prterr("domapwrite: msync");
report_failure(203);
}
+
+ check_eofpage("Write", offset, p, size);
+
if (munmap(p, map_size) != 0) {
prterr("domapwrite: munmap");
report_failure(204);
log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
if (size > file_size)
- bzero(good_buf + file_size, size - file_size);
+ memset(good_buf + file_size, '\0', size - file_size);
file_size = size;
if (testcalls <= simulatedopcount)
if (iret == -1)
prterr("writefileimage: write");
else
- prt("short write: 0x%x bytes instead of 0x%qx\n",
+ prt("short write: 0x%x bytes instead of 0x%llx\n",
iret, (unsigned long long)file_size);
report_failure(172);
}
if (lite ? 0 : ftruncate(fd, file_size) == -1) {
- prt("ftruncate2: %qx\n", (unsigned long long)file_size);
+ prt("ftruncate2: %llx\n", (unsigned long long)file_size);
prterr("writefileimage: ftruncate");
report_failure(173);
}
if (lite) {
off_t ret;
- file_size = maxfilelen = lseek(fd, (off_t)0, L_XTND);
+ file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
if (file_size == (off_t)-1) {
prterr(fname);
warn("main: lseek eof");
original_buf[i] = random() % 256;
good_buf = (char *) malloc(maxfilelen + writebdy);
good_buf = round_up(good_buf, writebdy, 0);
- bzero(good_buf, maxfilelen);
+ memset(good_buf, '\0', maxfilelen);
temp_buf = (char *) malloc(maxoplen + readbdy);
temp_buf = round_up(temp_buf, readbdy, 0);
- bzero(temp_buf, maxoplen);
+ memset(temp_buf, '\0', maxoplen);
if (lite) { /* zero entire existing file */
ssize_t written;