1.1 --- a/libe2access/host/test_remove.c Tue Dec 28 22:22:57 2021 +0100
1.2 +++ b/libe2access/host/test_remove.c Fri Dec 31 00:56:25 2021 +0100
1.3 @@ -142,6 +142,14 @@
1.4 return 1;
1.5 }
1.6
1.7 + sprintf(buf, "writing to file%04d", i);
1.8 +
1.9 + if (ext2fs_file_write(file, buf, strlen(buf), &transferred))
1.10 + {
1.11 + printf("Could not write to file %s\n", basename);
1.12 + return 1;
1.13 + }
1.14 +
1.15 ext2fs_file_flush(file);
1.16
1.17 files[i - 1] = file;
1.18 @@ -172,7 +180,7 @@
1.19 for (i = 1; i <= FILES; i++)
1.20 {
1.21 sprintf(basename, "file%04d", i);
1.22 - sprintf(buf, "writing to file%04d", i);
1.23 + sprintf(buf, "; writing to file%04d", i);
1.24
1.25 file = files[i - 1];
1.26
1.27 @@ -243,6 +251,60 @@
1.28 ext2fs_file_close(file);
1.29 }
1.30
1.31 + /* Create some more files with the same names as the original ones. */
1.32 +
1.33 + for (i = 1; i <= FILES; i++)
1.34 + {
1.35 + sprintf(basename, "file%04d", i);
1.36 +
1.37 + retval = image_create_file(fs, EXT2_ROOT_INO, basename, 0644,
1.38 + 1000, 1000, &ino);
1.39 +
1.40 + if (retval)
1.41 + {
1.42 + printf("Could not create file %s\n", basename);
1.43 + return 1;
1.44 + }
1.45 +
1.46 + if (ext2fs_file_open(fs, ino, EXT2_FILE_WRITE | EXT2_FILE_CREATE, &file))
1.47 + {
1.48 + printf("Could not write file %s\n", basename);
1.49 + return 1;
1.50 + }
1.51 +
1.52 + ext2fs_file_flush(file);
1.53 + ext2fs_file_close(file);
1.54 + }
1.55 +
1.56 + image_list_dir(fs, "", image_list_dir_proc, fs);
1.57 + printf("----\n");
1.58 +
1.59 + /* Re-open the original files and read from them again. */
1.60 +
1.61 + for (i = 1; i <= FILES; i++)
1.62 + {
1.63 + sprintf(basename, "file%04d", i);
1.64 +
1.65 + ino = inos[i - 1];
1.66 +
1.67 + if (ext2fs_file_open(fs, ino, 0, &file))
1.68 + {
1.69 + printf("Could not open file %s\n", basename);
1.70 + return 1;
1.71 + }
1.72 +
1.73 + if (ext2fs_file_read(file, buf, BUFSIZE, &transferred))
1.74 + {
1.75 + printf("Could not read from file %s\n", basename);
1.76 + return 1;
1.77 + }
1.78 +
1.79 + buf[transferred] = '\0';
1.80 + printf("Read from %s: %s\n", basename, buf);
1.81 +
1.82 + ext2fs_file_close(file);
1.83 + }
1.84 +
1.85 /* Close the filesystem image. */
1.86
1.87 retval = ext2fs_flush(fs);