X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F06A5385E02D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1704723058;
	bh=xuY2Sx7qQm1S0e7TNC9VxtTxHWHE8oq2kSKvZgBJBPY=;
	h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
	 From;
	b=QGr5X/AbaQKpobC9ZVmtwg9lagvyQtRlvsGv4qaIMx9M3sKEZzQRQ54TzoDIhmjB6
	 pwriuLvcbo8H8s77wGC1YYdDWs6EaqwHbopvYgxqiyMRH7YipHaD+WB0jxifgX3a7Y
	 jG5DbhiIOLeJBYr4gI5jQcaIdb8JNLWTurlW7Yt0=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50508385E44B
Date: Mon, 8 Jan 2024 15:09:38 +0100
To: cygwin@cygwin.com
Subject: Re: Cygwin tools to read/write NTFS alternate data streams?
Message-ID: <ZZwCIjfdP6Qh-y5d@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <CANH4o6N7UONfYy1ir7WZXpOnthSxF=fcqaPe37dPsdU_AoPoLw@mail.gmail.com>
 <ZWmsvW0bmko_9Qcc@calimero.vinschen.de>
 <CANH4o6M7s1h8+atQVdr+uAOgUHKPyomP4zoobvvbW97ebSR=sw@mail.gmail.com>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <CANH4o6M7s1h8+atQVdr+uAOgUHKPyomP4zoobvvbW97ebSR=sw@mail.gmail.com>
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Corinna Vinschen <corinna-cygwin@cygwin.com>
Content-Type: text/plain; charset="utf-8"
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 408EAwcr006391

On Dec 18 18:47, Martin Wege via Cygwin wrote:
> On Fri, Dec 1, 2023 at 10:52 AM Corinna Vinschen via Cygwin
> <cygwin@cygwin.com> wrote:
> >
> > On Nov 30 04:55, Martin Wege via Cygwin wrote:
> > > Hello,
> > >
> > > Does Cygwin have tools (modified /usr/bin/dd ?) to read/write NTFS
> > > alternate data streams?
> >
> > No.  As you know, the colon is translated to a normal filename
> > character, and there's no POSIX-like API to expose ADS raw to user
> > space.
> >
> > There is, however, an old function we still expose to user space
> > for backward compat:
> >
> >   #include <sys/cygwin.h>
> >
> >   int cygwin_attach_handle_to_fd (char *name,
> >                                   int fd,
> >                                   HANDLE handle,
> >                                   mode_t bin,
> >                                   DWORD myaccess);
> >
> > This allows to sneak in a HANDLE into a Cygwin file descriptor
> > representation, kind of like this:
> >
> >   HANDLE h;
> >   int fd;
> >
> >   h = CreateFile ("foo:bar", GENERIC_READ, FILE_SHARE_VALID_FLAGS,
> >                   NULL, OPEN_EXISTING, 0, NULL);
> >   if (h != INVALID_HANDLE_VALUE)
> >     {
> >       fd = cygwin_attach_handle_to_fd ("foo", -1, h, 0, GENERIC_READ);
> >       if (fd < 0)
> >         bail_out;
> >     }
> >
> > For the bin parameter, only 0, O_BINARY or O_TEXT are acceptable,
> > for myaccess, only GENERIC_READ and/or GENERIC_WRITE are acceptable.
> 
> Could this be abstracted into O_XATTR support, i.e. openat() file with
> O_XATTR, and then have access to the alternate data streams in a
> (virtual) subdir?

I'm not too hot on adding more open(2) flags, the reason being,
that we have room left for only 7 more flags in the 32 bit mode.
Nobody knows what comes along officially in future.

Apart from that, this sounds like a nice idea for Cygwin 3.6,
provided somebody implements it, https://cygwin.com/acronyms/#SHTDI

Assuming we can live without actually having a subdir and just
allowing to open and create a file with the O_XATTR flag, it might be
pretty simple to implement.  The path handling code would just have to
drop the colon from the list of characters converted to the private-use
Unicode area.

Implementing the subdir is a bit more complicated, especially when
taking opendir/readdir of that virtual subdir into account, but it
would certainly be doable.


Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

