# HG changeset patch # User Paul Boddie # Date 1640908585 -3600 # Node ID ac82aa98be4f037b666a5aea4f3c9d3e17ec6e98 # Parent cba174322825d39f9b97d3e9b138cc9311f17272 Test writing and initial file length reporting as well as file replacement. diff -r cba174322825 -r ac82aa98be4f libe2access/host/test_remove.c --- a/libe2access/host/test_remove.c Tue Dec 28 22:22:57 2021 +0100 +++ b/libe2access/host/test_remove.c Fri Dec 31 00:56:25 2021 +0100 @@ -142,6 +142,14 @@ return 1; } + sprintf(buf, "writing to file%04d", i); + + if (ext2fs_file_write(file, buf, strlen(buf), &transferred)) + { + printf("Could not write to file %s\n", basename); + return 1; + } + ext2fs_file_flush(file); files[i - 1] = file; @@ -172,7 +180,7 @@ for (i = 1; i <= FILES; i++) { sprintf(basename, "file%04d", i); - sprintf(buf, "writing to file%04d", i); + sprintf(buf, "; writing to file%04d", i); file = files[i - 1]; @@ -243,6 +251,60 @@ ext2fs_file_close(file); } + /* Create some more files with the same names as the original ones. */ + + for (i = 1; i <= FILES; i++) + { + sprintf(basename, "file%04d", i); + + retval = image_create_file(fs, EXT2_ROOT_INO, basename, 0644, + 1000, 1000, &ino); + + if (retval) + { + printf("Could not create file %s\n", basename); + return 1; + } + + if (ext2fs_file_open(fs, ino, EXT2_FILE_WRITE | EXT2_FILE_CREATE, &file)) + { + printf("Could not write file %s\n", basename); + return 1; + } + + ext2fs_file_flush(file); + ext2fs_file_close(file); + } + + image_list_dir(fs, "", image_list_dir_proc, fs); + printf("----\n"); + + /* Re-open the original files and read from them again. */ + + for (i = 1; i <= FILES; i++) + { + sprintf(basename, "file%04d", i); + + ino = inos[i - 1]; + + if (ext2fs_file_open(fs, ino, 0, &file)) + { + printf("Could not open file %s\n", basename); + return 1; + } + + if (ext2fs_file_read(file, buf, BUFSIZE, &transferred)) + { + printf("Could not read from file %s\n", basename); + return 1; + } + + buf[transferred] = '\0'; + printf("Read from %s: %s\n", basename, buf); + + ext2fs_file_close(file); + } + /* Close the filesystem image. */ retval = ext2fs_flush(fs);