linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Incorrect handling of . and .. files
Date: Mon, 27 Sep 2021 12:19:48 +0100	[thread overview]
Message-ID: <20210927111948.GA16257@gofer.mess.org> (raw)

Hi,

Windows allows files and directories called "." and ".." to be created
using UNC paths, i.e. "\\?\D:\..". Now this is totally insane behaviour,
but when an exfat filesytem with such a file is mounted on Linux, those
files show up as another directory and its contents is inaccessible.

I can replicate this using exfat filesystems, but not ntfs.

This is what I did on Windows using rust:

	use std::fs::File;
	use std::io::Write;

	fn main() {
	    let mut file =
		File::create(r"\\?\D:\..").expect("create dot file");
	    file.write_all(b"Hello, world!").expect("write dot file");
	}

Now on Linux (I also created a file called ".").

[root@xywoleh tmp]# mount -t exfat /dev/loop0p1 /mnt
[root@xywoleh tmp]# cd /mnt
[root@xywoleh mnt]# ls -la
total 20
drwxr-xr-x. 5 root root 4096 Sep 27 11:47  .
drwxr-xr-x. 5 root root 4096 Sep 27 11:47  .
dr-xr-xr-x. 1 root root  176 Sep 21 11:05  ..
dr-xr-xr-x. 1 root root  176 Sep 21 11:05  ..
drwxr-xr-x. 2 root root 4096 Sep 27  2021 '$RECYCLE.BIN'
drwxr-xr-x. 2 root root 4096 Sep 27  2021 'System Volume Information'

Microsoft says this:

https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-file-namespaces

	Because it turns off automatic expansion of the path string, the
	"\\?\" prefix also allows the use of ".." and "." in the path names,
	which can be useful if you are attempting to perform operations on a
	file with these otherwise reserved relative path specifiers as part of
	the fully qualified path.

So, in Linux cannot read "." or ".." (i.e., I can't see "Hello, World!"). I
don't know what the correct handling should be, but having two "." and two
".." files does not seem right at all.

Thanks,
Sean

             reply	other threads:[~2021-09-27 11:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 11:19 Sean Young [this message]
2021-12-11  2:04 ` Incorrect handling of . and .. files Pali Rohár
2021-12-13  6:47   ` Adam Borowski
2021-12-13 11:39     ` Pali Rohár
2021-12-13 14:09       ` Namjae Jeon
2022-06-02  9:53       ` Pali Rohár

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210927111948.GA16257@gofer.mess.org \
    --to=sean@mess.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).