Subject: Re: NTFS File Streams and EMACS...

From: Andrew Innes <[email-masked]>
Date: Wed, 31 Jul 1996 11:10:52 +0100

On Tue, 30 Jul 1996 22:45:54 -0700, Michael Hotchin <[email-masked]> said:
>Apparently, NTFS partitions support the notions of having multiple
>streams in a file, like so:

[ foo contains "Boo!" in primary stream, and "Hi There" in stream "bar" ]

>The file naming convention confuses EMACS, though.  It seems that a file
>name with a colon in it like this:
>
>e:\projects\OO7\tmp\foo:bar
>
>is interpreted as the file 'bar' on O:.  All the rest is thrown away.
>
>This is using EMACS 19.30.1 (i386-*-nt-3.50), running on NT 4.0 build
>1381.

I wasn't aware there was a simple syntax for accessing file streams
other than the primary one, but looking in the SDK docs it looks like
this is true.

The parsing of file names containing `:' was changed for 19.31 so that
`:' is only considered to be part of a drive specifier if it is preceded
by a single letter (either at the beginning of the string, or after a
directory separator in some cases).  So, from 19.31 onwards the file
name itself will not be truncated by Emacs.

It turns out that this is almost sufficient to allow Emacs to access
other streams in an NTFS file.  In fact, Emacs is able to *write* data
to alternate streams (which can then be seen using the "more < foo:bar"
trick in the shell), but Emacs seems unable to read alternate streams.

For example, if I open the file d:/tmp/foo:bar, I end up with a new file
which I can then save okay (and see the contents from the shell), but
when I reopen the file, Emacs again thinks it is a new file.

The reason is simply that Emacs first checks to see if the file exists
before attempting to open it and read its contents (as does
GetOpenFileName, apparently, since Notepad and other Win32 editors won't
load the alternate stream either).

More specifically, insert-file-contents calls stat() first to find out
things like the file modification timestamp and to check that it is an
ordinary file (this is more relevant for Unix, where the file might be a
named pipe say, but the code is called on NT as well).

I could modify the NT implementation of stat (Emacs has its own version
to fix bugs in the MSVC version, and fake inode numbers) to understand
the alternate stream syntax, but I'm not sure that pretending
`file:stream' is a normal file in its own right is the right thing to do
(it will still not appear in a directory listing, for instance).

If you want to be able to edit alternate streams, you could write a bit
of elisp that called (shell-command "more < file:stream" buffer), or
some variation, to read the contents of the stream, and then set up the
buffer file name etc as if the file had been loaded by find-file.
Saving the buffer would not require any special action.

AndrewI

---

From: Michael Hotchin <[email-masked]>
Date: Tue, 30 Jul 1996 22:45:54 -0700

E:\projects\OO7\tmp>echo Boo! > foo

E:\projects\OO7\tmp>echo Hi There >> foo:bar

E:\projects\OO7\tmp>ls
    E:\projects\OO7\tmp\*.*
foo
    7 (7) bytes in 1 files

E:\projects\OO7\tmp>more < foo
Boo!

E:\projects\OO7\tmp>more < foo:bar
Hi There

E:\projects\OO7\tmp>ls
    E:\projects\OO7\tmp\*.*
foo
    7 (7) bytes in 1 files

E:\projects\OO7\tmp>

	Mike H.