Samba does not update ctime (last Change time) on either CIFS or SMB3 when creating a hard link while Windows servers do (and obviously Linux local file systems too). It works with POSIX Extensions but not with CIFS or SMB3 to Samba. Following is output from a simple demonstration (/mnt is a cifs mount to Samba, /mnt1 is a cifs mount to Windows 8.1). root@ubuntu:~/cifs-2.6# touch /mnt/file1 root@ubuntu:~/cifs-2.6# touch /mnt1/file1 root@ubuntu:~/cifs-2.6# stat /mnt/file1 ; ln /mnt/file1 /mnt/file2 File: ‘/mnt/file1’ Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 1dh/29d Inode: 395051 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-10-17 16:33:59.538897300 -0500 Modify: 2014-10-17 16:33:59.538897300 -0500 Change: 2014-10-17 16:33:59.538897300 -0500 Birth: - root@ubuntu:~/cifs-2.6# stat /mnt/file2 File: ‘/mnt/file2’ Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 1dh/29d Inode: 395051 Links: 2 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-10-17 16:33:59.538897300 -0500 Modify: 2014-10-17 16:33:59.538897300 -0500 Change: 2014-10-17 16:33:59.538897300 -0500 Birth: - /* NOTE ctime HAS NOT CHANGED LIKE IT SHOULD */ /* Now repeat experiment to Windows 8.1 */ root@ubuntu:~/cifs-2.6# stat /mnt1/file1 ; ln /mnt1/file1 /mnt1/file2 File: ‘/mnt1/file1’ Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 1eh/30d Inode: 2251799813699648 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-10-17 16:34:02.982897300 -0500 Modify: 2014-10-17 16:34:02.982897300 -0500 Change: 2014-10-17 16:34:02.982897300 -0500 Birth: - root@ubuntu:~/cifs-2.6# stat /mnt1/file2 File: ‘/mnt1/file2’ Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 1eh/30d Inode: 2251799813699648 Links: 2 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2014-10-17 16:34:02.982897300 -0500 Modify: 2014-10-17 16:34:02.982897300 -0500 Change: 2014-10-17 16:38:28.726949400 -0500 /* NOTE ctime HAS CHANGED */ Birth: -
Created attachment 10355 [details] wireshark trace showing samba not updating change time on hardlinks but showing windows is updating change time 127.0.0.1 target is samba server (4.1 server, but also fails to 4.2-rc2) (note 192.168.93.159 target is Windows 8.1 server Compare frame 45 (bad change time) to frame 83 (change time updated)
Note that this was discovered with xfstests generic/236 running on SMB3 Linux mount
Looks like this is XFS specific. Hardlink creation and updation of ctime works fine with ext4 for me. ==== anubhav@citadel:~$ stat notes.txt File: `notes.txt' Size: 11456 Blocks: 24 IO Block: 4096 regular file Device: 801h/2049d Inode: 9706103 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ anubhav) Gid: ( 1000/ anubhav) Access: 2015-06-18 17:08:18.655020928 +0530 Modify: 2014-06-25 20:09:58.594835586 +0530 Change: 2014-06-25 20:09:58.648784072 +0530 smb: \> hardlink notes.txt notes1.txt anubhav@citadel:~$ stat notes1.txt File: `notes1.txt' Size: 11456 Blocks: 24 IO Block: 4096 regular file Device: 801h/2049d Inode: 9706103 Links: 2 Access: (0644/-rw-r--r--) Uid: ( 1000/ anubhav) Gid: ( 1000/ anubhav) Access: 2015-06-18 17:08:18.655020928 +0530 Modify: 2014-06-25 20:09:58.594835586 +0530 Change: 2015-07-08 14:59:03.383769118 +0530 anubhav@citadel:~$ sudo blkid /dev/sda1 /dev/sda1: UUID="16a10327-c4ba-4a36-866d-d67a775fcb57" TYPE="ext4" anubhav@citadel:~$ /usr/local/samba/sbin/smbd -V Version 4.3.0pre1-GIT-e3373e9 ====
It also fails on ext4 (at least with current Samba Version 4.21.0pre1-GIT-73e3ffb8418 and Samba 4.18 as well) Just tried it to ext4 mount as well (see below, remove vs. local - local reports the ctime correctly, ie updated after hardlink, but Samba remotes it wrong) root@smfrench-ThinkPad-P52:/shares/test# stat /mnt1/smallfile File: /mnt1/smallfile Size: 10 Blocks: 8 IO Block: 1048576 regular file Device: 0,72 Inode: 1831427 Links: 2 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2024-04-28 14:25:57.615181400 -0500 Modify: 2024-04-28 14:25:57.615181400 -0500 Change: 2024-04-28 14:25:57.615181400 -0500 Birth: 2024-04-28 14:25:57.602181400 -0500 root@smfrench-ThinkPad-P52:/shares/test# stat /boot/tmpshare/smallfile File: /boot/tmpshare/smallfile Size: 10 Blocks: 8 IO Block: 4096 regular file Device: 259,3 Inode: 1831427 Links: 2 Access: (0766/-rwxrw-rw-) Uid: (65534/ nobody) Gid: (65534/ nogroup) Access: 2024-04-28 14:25:57.602181433 -0500 Modify: 2024-04-28 14:25:57.615181400 -0500 Change: 2024-04-28 14:27:14.942326150 -0500 Birth: 2024-04-28 14:25:57.602181433 -0500 I also verified it is broken for Samba over XFS and btrfs. The reproduction scenario is trivial: 1) mount to Samba from Linux 2) do "ln /mnt1/target /mnt1/sysmlinktotarget" 3) stat /mnt1/target and you will see ctime was not updated when hardlink created (but this works fine to Windows, ksmbd and other servers). ctime reported locally on the Samba server does show ctime updated
The only way I can see to get this to work is to mount with "posix" on the Linux client - and then the server reports ctime correctly. Note that Windows updates ctime when new hardlink created, so Samba server should be as well, with or without posix extensions.
This does not look like samba issue at all. More, it is filesystem-specific, - some filesystems change ctime when creating hardlink, some don't. Samba definitely should not do anything extra besides link(2).