1

/cygdrive/d/ is a USB hard disk formatted as ext2 and mounted with ext2fsd.

When I try cp -al /cygdrive/d/X /cygdrive/d/Y where X is a file, I get the error in the title.

Things I've Tried/Verified

I did chmod -R 777 /cygdrive/d but I still get the same result.

I am running as local administrator, who is the owner of /cygdrive/d.

X is a file, not a directory.

Windows Server 2012 R2 running cygwin64 current as of today.

It's ext2 because I can, for example, touch /cygdrive/d/filename_with_a_colon:in_it and it works and I can see it with ls. Not to mention, it says so in ext2fsd and the Windows Disk Manager.

Ironically, the same syntax on an NTFS drive works fine and creates an NTFS hardlink.

I've also tried reformatting the drive as ext3, with the same results. I had figured on ext2 being more likely to be fully supported on account of it being older than ext3/4, but I guess it doesn't make a difference.

The question

How can I create simple ext2 hardlinks with cygwin?

Kev
  • 1,142
  • 2
  • 14
  • 37
  • Does `ln` work? – DavidPostill Mar 26 '15 at 07:24
  • @DavidPostill it says the exact same thing. – Kev Mar 26 '15 at 11:58
  • 1
    Cygwin probably wants to create a NTFS hard link, much like `mklink`. If neither of those programs work, the driver doesn’t support it. – Daniel B Mar 26 '15 at 12:46
  • @DanielB I guess I got the sense it might support ext fses based on the fact that it could format them via mke2fs from the e2fsprogs cygwin package. You might be right. – Kev Mar 26 '15 at 12:48
  • 1
    @Kev Cygwin relies on Windows facilities (ie. filesystem drivers) to access files. Tools in the e2fsprogs package operate on raw disks. – Daniel B Mar 26 '15 at 13:05
  • @DanielB, IOW ext2fsd would need to support the creation of hard links, but cygwin would also need to detect that and make use of it? – Kev Mar 26 '15 at 13:17
  • If cygwin underneath uses Windows' `mklink` I guess it's hopeless: `W:\>mklink /H testlink test` gives `Local NTFS volumes are required to complete the operation.` so I guess ext2fsd doesn't support it by overriding this. – Kev Mar 26 '15 at 13:35

1 Answers1

3

Windows does indeed support hard links. However, the documentation on CreateHardLink says it all:

This function is only supported on the NTFS file system

This limitation is probably hard-coded. Because ext2fsd is clearly not NTFS, Windows will refuse to create hard links on it.

Cygwin provides POSIX API compatibility (of sorts) on top of Windows APIs. This means that it ultimately also calls CreateHardLink and is subject to the same limitations like mklink and other Windows software.

Many tools of the e2fsprogs package (like mke2fs, e2fsck, resize2fs, ...) operate directly on the disk, without relying on filesystem drivers. That’s why the filesystem has to be unmounted before using them to change stuff. This is also why they can work without Windows (natively) being able to access ext2/3/4 at all.

Daniel B
  • 60,360
  • 9
  • 122
  • 163
  • Ultimately, this means plugging an ext2 drive into a Windows box when you want to use hard links (for rsnapshot, for example) is fruitless, unless you want to avoid cygwin and make it pass through to a VM, which is another can of worms. – Kev Mar 26 '15 at 13:37
  • @Kev Yes, that’s correct. Reading existing hard links should be possible without issues, though. – Daniel B Mar 26 '15 at 13:38