/*
* Initialize.
*/
if (width > 32) {
atf_tc_skip("fsck_lfs does not yet understand LFS64");
return;
}
atf_tc_expect_fail("roll-forward not yet implemented");
/* Create filesystem, note superblock locations */
fprintf(stderr, "* Create file system\n");
sprintf(cmd, "newfs_lfs -D -F -s 10000 -w%d ./%s > %s",
width, IMGNAME, LOGFILE);
if (system(cmd) == -1)
atf_tc_fail_errno("newfs failed");
pipe = fopen(LOGFILE, "r");
if (pipe == NULL)
atf_tc_fail_errno("newfs failed to execute");
while (fgets(buf, MAXLINE, pipe) != NULL) {
if (sscanf(buf, "%lld,%lld", sbaddr, sbaddr + 1) == 2)
break;
}
while (fgets(buf, MAXLINE, pipe) != NULL)
;
fclose(pipe);
if (sbaddr[0] < 0 || sbaddr[1] < 0)
atf_tc_fail("superblock not found");
fprintf(stderr, "* Superblocks at %lld and %lld\n",
sbaddr[0], sbaddr[1]);
/* Set up rump */
rump_init();
if (rump_sys_mkdir(MP, 0777) == -1)
atf_tc_fail_errno("cannot create mountpoint");
rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK);
/*
* Create initial filesystem state, from which
* we will attempt to roll forward.
*/
/* Mount filesystem */
fprintf(stderr, "* Mount fs [1, initial]\n");
memset(&args, 0, sizeof(args));
args.fspec = __UNCONST(FAKEBLK);
if (rump_sys_mount(MOUNT_LFS, MP, 0, &args, sizeof(args)) == -1)
atf_tc_fail_errno("rump_sys_mount failed");
/* Payload */
fprintf(stderr, "* Initial payload\n");
write_file(UNCHANGED_CONTROL, CHUNKSIZE);
write_file(TO_BE_DELETED, CHUNKSIZE);
write_file(TO_BE_APPENDED, CHUNKSIZE);
rump_sys_sync();
rump_sys_sync();
sleep(1); /* XXX yuck - but we need the superblocks dirty */
/* Make copies of superblocks */
for (i = 0; i < 2; i++) {
sprintf(buf, "dd if=%s of=%s bs=512 iseek=%lld"
" count=16 conv=sync", IMGNAME, sblock[i], sbaddr[i]);
system(buf);
}
/* Unmount */
rump_sys_unmount(MP, 0);
if (fsck())
atf_tc_fail_errno("fsck found errors after first unmount");
/*
* Make changes which we will attempt to roll forward.
*/
/* Reconfigure and mount filesystem again */
fprintf(stderr, "* Mount fs [2, after changes]\n");
if (rump_sys_mount(MOUNT_LFS, MP, 0, &args, sizeof(args)) == -1)
atf_tc_fail_errno("rump_sys_mount failed [2]");
fprintf(stderr, "* Update payload\n");
/* Add new file */
write_file(NEWLY_CREATED, CHUNKSIZE);
/* Append to existing file */
write_file(TO_BE_APPENDED, CHUNKSIZE);
/* Delete file */
rump_sys_unlink(TO_BE_DELETED);
/* Done with payload, unmount fs */
rump_sys_unmount(MP, 0);
if (fsck())
atf_tc_fail_errno("fsck found errors after second unmount");
#ifndef FORCE_SUCCESS
fprintf(stderr, "* Revert superblocks\n");
/*
* Copy back old superblocks, reverting FS to old state
*/
for (i = 0; i < 2; i++) {
sprintf(buf, "dd of=%s if=%s bs=512 oseek=%lld count=16"
" conv=sync,notrunc", IMGNAME, sblock[i], sbaddr[i]);
system(buf);
}
if (fsck())
atf_tc_fail_errno("fsck found errors with old superblocks");
#endif
dumplfs();
/*
* Roll forward.
*/
/* Mount filesystem; this will roll forward. */
fprintf(stderr, "* Mount fs [3, to roll forward]\n");
if (rump_sys_mount(MOUNT_LFS, MP, 0, &args, sizeof(args)) == -1)
atf_tc_fail_errno("rump_sys_mount failed [3]");
/* Unmount filesystem */
if (rump_sys_unmount(MP, 0) != 0)
atf_tc_fail_errno("rump_sys_umount failed after roll-forward");
/*
* Use fsck_lfs to look for consistency errors.
*/
fprintf(stderr, "* Fsck after roll-forward\n");
if (fsck()) {
fprintf(stderr, "*** FAILED FSCK ***\n");
atf_tc_fail("fsck found errors after roll forward");
}
dumplfs();
/*
* Check file system contents
*/
/* Mount filesystem one last time */
fprintf(stderr, "* Mount fs [4, after roll forward complete]\n");
if (rump_sys_mount(MOUNT_LFS, MP, 0, &args, sizeof(args)) == -1)
atf_tc_fail_errno("rump_sys_mount failed [4]");
if (check_file(UNCHANGED_CONTROL, CHUNKSIZE) != 0)
atf_tc_fail("Unchanged control file differs(!)");
if (rump_sys_access(TO_BE_DELETED, F_OK) == 0)
atf_tc_fail("Removed file still present");
else
fprintf(stderr, "%s: no problem\n", TO_BE_DELETED);
if (check_file(TO_BE_APPENDED, 2 * CHUNKSIZE) != 0)
atf_tc_fail("Appended file differs");
if (rump_sys_access(NEWLY_CREATED, F_OK) != 0)
atf_tc_fail("Newly added file missing");
if (check_file(NEWLY_CREATED, CHUNKSIZE) != 0)
atf_tc_fail("Newly added file differs");
/* Umount filesystem */
rump_sys_unmount(MP, 0);
/* Final fsck to double check */
fprintf(stderr, "* Fsck after final unmount\n");
if (fsck()) {
fprintf(stderr, "*** FAILED FSCK ***\n");
atf_tc_fail("fsck found errors after final unmount");
}
}
/* Write some data into a file */
int write_file(const char *filename, int add)
{
int fd, size, i;
struct stat statbuf;
unsigned char b;
int flags = O_CREAT|O_WRONLY;