memset(bhfi, 0, sizeof(*bhfi));
h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (h == INVALID_HANDLE_VALUE)
return (0);
r = GetFileInformationByHandle(h, bhfi);
fclose(in);
}
+int
+is_LargeInode(const char *file)
+{
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ BY_HANDLE_FILE_INFORMATION bhfi;
+ int r;
+
+ r = my_GetFileInformationByName(file, &bhfi);
+ if (r != 0)
+ return (0);
+ return (bhfi.nFileIndexHigh & 0x0000FFFFUL);
+#else
+ struct stat st;
+ int64_t ino;
+
+ if (stat(file, &st) < 0)
+ return (0);
+ ino = (int64_t)st.st_ino;
+ return (ino > 0xffffffff);
+#endif
+}
/*
*
* TEST management
basic_cpio(const char *target,
const char *pack_options,
const char *unpack_options,
- const char *se)
+ const char *se, const char *se2)
{
int r;
/* Verify stderr. */
failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target);
- assertTextFileContents(se, "unpack.err");
+ assertTextFileContents(se2, "unpack.err");
verify_files(pack_options);
{
FILE *filelist;
const char *msg;
+ char result[1024];
assertUmask(0);
* Create an assortment of files on disk.
*/
filelist = fopen("filelist", "w");
+ memset(result, 0, sizeof(result));
/* File with 10 bytes content. */
assertMakeFile("file", 0644, "1234567890");
fprintf(filelist, "file\n");
+ if (is_LargeInode("file"))
+ strncat(result,
+ "bsdcpio: file: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result));
/* hardlink to above file. */
assertMakeHardlink("linkfile", "file");
fprintf(filelist, "linkfile\n");
+ if (is_LargeInode("linkfile"))
+ strncat(result,
+ "bsdcpio: linkfile: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result));
/* Symlink to above file. */
if (canSymlink()) {
assertMakeSymlink("symlink", "file");
fprintf(filelist, "symlink\n");
+ if (is_LargeInode("symlink"))
+ strncat(result,
+ "bsdcpio: symlink: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result));
}
/* Another file with different permissions. */
assertMakeFile("file2", 0777, "1234567890");
fprintf(filelist, "file2\n");
+ if (is_LargeInode("file2"))
+ strncat(result,
+ "bsdcpio: file2: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result));
/* Directory. */
assertMakeDir("dir", 0775);
fprintf(filelist, "dir\n");
+ if (is_LargeInode("dir"))
+ strncat(result,
+ "bsdcpio: dir: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result));
+ strncat(result, "2 blocks\n", sizeof(result) - strlen(result));
+
/* All done. */
fclose(filelist);
/* Archive/dearchive with a variety of options. */
msg = canSymlink() ? "2 blocks\n" : "1 block\n";
- basic_cpio("copy", "", "", msg);
- basic_cpio("copy_odc", "--format=odc", "", msg);
- basic_cpio("copy_newc", "-H newc", "", "2 blocks\n");
- basic_cpio("copy_cpio", "-H odc", "", msg);
+ basic_cpio("copy", "", "", msg, msg);
+ basic_cpio("copy_odc", "--format=odc", "", msg, msg);
+ basic_cpio("copy_newc", "-H newc", "", result, "2 blocks\n");
+ basic_cpio("copy_cpio", "-H odc", "", msg, msg);
msg = canSymlink() ? "9 blocks\n" : "8 blocks\n";
- basic_cpio("copy_ustar", "-H ustar", "", msg);
+ basic_cpio("copy_ustar", "-H ustar", "", msg, msg);
/* Copy in one step using -p */
passthrough("passthrough");
time_t t, t2, now;
char *p, *e;
size_t s, fs, ns;
+ char result[1024];
assertUmask(0);
assertMakeDir("dir", 0775);
fprintf(list, "dir\n");
+ /* Setup result message. */
+ memset(result, 0, sizeof(result));
+ if (is_LargeInode("file1"))
+ strncat(result,
+ "bsdcpio: file1: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result) -1);
+ if (canSymlink() && is_LargeInode("symlink"))
+ strncat(result,
+ "bsdcpio: symlink: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result) -1);
+ if (is_LargeInode("dir"))
+ strncat(result,
+ "bsdcpio: dir: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result) -1);
+ if (is_LargeInode("hardlink"))
+ strncat(result,
+ "bsdcpio: hardlink: large inode number truncated: "
+ "Numerical result out of range\n",
+ sizeof(result) - strlen(result) -1);
+
/* Record some facts about what we just created: */
now = time(NULL); /* They were all created w/in last two seconds. */
/* Verify that nothing went to stderr. */
if (canSymlink()) {
- assertTextFileContents("2 blocks\n", "newc.err");
+ strncat(result, "2 blocks\n", sizeof(result) - strlen(result));
} else {
- assertTextFileContents("1 block\n", "newc.err");
+ strncat(result, "1 block\n", sizeof(result) - strlen(result));
}
+ assertTextFileContents(result, "newc.err");
/* Verify that stdout is a well-formed cpio file in "newc" format. */
p = slurpfile(&s, "newc.out");