]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbtorture: move hardlink test in test_ntrename() to its own test
authorRalph Boehme <slow@samba.org>
Fri, 8 Nov 2024 13:13:28 +0000 (14:13 +0100)
committerAnoop C S <anoopcs@samba.org>
Mon, 11 Nov 2024 12:53:05 +0000 (12:53 +0000)
Some filesystems may not support hardlinks.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source4/torture/raw/rename.c

index 16945615587be73c06d3fcc4a61edae01b4e4d6e..92b4d1e7838d9a941a59cd4f2ec996c8ae9101f0 100644 (file)
@@ -303,39 +303,6 @@ static bool test_ntrename(struct torture_context *tctx,
 
        torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_NORMAL);
 
-       torture_comment(tctx, "Checking hard link\n");
-       io.ntrename.in.old_name = fname1;
-       io.ntrename.in.new_name = fname2;
-       io.ntrename.in.attrib = 0;
-       io.ntrename.in.flags = RENAME_FLAG_HARD_LINK;
-       status = smb_raw_rename(cli->tree, &io);
-       CHECK_STATUS(status, NT_STATUS_OK);
-
-       torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_SYSTEM);
-
-       finfo.generic.level = RAW_FILEINFO_ALL_INFO;
-       finfo.generic.in.file.path = fname2;
-       status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(finfo.all_info.out.nlink, 2);
-       CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM);
-
-       finfo.generic.in.file.path = fname1;
-       status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(finfo.all_info.out.nlink, 2);
-       CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM);
-
-       torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_NORMAL);
-
-       smbcli_unlink(cli->tree, fname2);
-
-       finfo.generic.in.file.path = fname1;
-       status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(finfo.all_info.out.nlink, 1);
-       CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_NORMAL);
-
        torture_comment(tctx, "Checking copy\n");
        io.ntrename.in.old_name = fname1;
        io.ntrename.in.new_name = fname2;
@@ -500,6 +467,68 @@ done:
        return ret;
 }
 
+/*
+  test SMBntrename ops
+*/
+static bool test_nthardlink(struct torture_context *tctx,
+                           struct smbcli_state *cli)
+{
+       union smb_rename io = {};
+       NTSTATUS status;
+       bool ret = true;
+       int fnum;
+       const char *fname1 = BASEDIR "\\test1.txt";
+       const char *fname2 = BASEDIR "\\test2.txt";
+       union smb_fileinfo finfo = {};
+
+       torture_comment(tctx, "Testing SMBnthardlink\n");
+
+       torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR);
+
+       fnum = create_complex_file(cli, tctx, fname1);
+       status = smbcli_close(cli->tree, fnum);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       torture_comment(tctx, "Checking hard link\n");
+       io.generic.level = RAW_RENAME_NTRENAME;
+       io.ntrename.in.old_name = fname1;
+       io.ntrename.in.new_name = fname2;
+       io.ntrename.in.attrib = 0;
+       io.ntrename.in.flags = RENAME_FLAG_HARD_LINK;
+       status = smb_raw_rename(cli->tree, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_SYSTEM);
+
+       finfo.generic.level = RAW_FILEINFO_ALL_INFO;
+       finfo.generic.in.file.path = fname2;
+       status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(finfo.all_info.out.nlink, 2);
+       CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM);
+
+       finfo.generic.in.file.path = fname1;
+       status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(finfo.all_info.out.nlink, 2);
+       CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM);
+
+       torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_NORMAL);
+
+       smbcli_unlink(cli->tree, fname2);
+
+       finfo.generic.in.file.path = fname1;
+       status = smb_raw_pathinfo(cli->tree, tctx, &finfo);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(finfo.all_info.out.nlink, 1);
+       CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_NORMAL);
+
+done:
+       smb_raw_exit(cli->session);
+       smbcli_deltree(cli->tree, BASEDIR);
+       return ret;
+}
+
 /*
   test dir rename.
 */
@@ -685,6 +714,7 @@ struct torture_suite *torture_raw_rename(TALLOC_CTX *mem_ctx)
        torture_suite_add_2smb_test(suite, "trans2rename", test_trans2rename);
        torture_suite_add_1smb_test(suite, "nttransrename", test_nttransrename);
        torture_suite_add_1smb_test(suite, "ntrename", test_ntrename);
+       torture_suite_add_1smb_test(suite, "nthardlink", test_nthardlink);
        torture_suite_add_1smb_test(suite, "osxrename", test_osxrename);
        torture_suite_add_1smb_test(suite, "directory rename", test_dir_rename);