Linux 文件系统上是否有类似备用数据流的东西?

发布于 2024-07-06 11:24:19 字数 185 浏览 10 评论 0原文

在 Windows NTFS 上,有一个很好但大多未使用的功能,称为 我最近在一个业余爱好开发项目中使用了“备用数据流”(ADS)。

在 Mac HFS+ 上,还有一个类似的不错但大多未使用的功能,称为“命名分叉”。

我正在考虑将这个项目移植到Linux上,但我不知道Linux上的文件系统是否有这样的功能?

On Windows NTFS there is a nice but mostly unused feature called
"Alternate Data Streams" (ADS) which I recently used in a hobby-dev project.

On Mac HFS+ there is also a similarly nice but mostly unused feature called "named forks".

I am thinking of porting this project to Linux, but I do not know if any Filesystem on linux has such a feature?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

风追烟花雨 2024-07-13 11:24:19

Windows 和 Linux(以及其他操作系统)上都有支持扩展属性 (EA) 的文件系统。 Windows 支持是针对 OS/2 兼容性添加的,并且没有任何记录的接口,除了通过备份 API 的 hacky 方法(这就是 Cygwin 所做的)。 EA 旨在仅存储小值。 在 Windows 上,每个 EA 都有一个 ASCII 名称(而几乎所有其他名称都是 Unicode),并且文件上所有 EA 的总大小不能大于 64k。 EA 不是文件:您无法打开 EA 的文件句柄并像普通文件一样读取它。

备用数据流是 NTFS 提供的一项单独功能,它允许您在文件内提供备用子文件。 每个文件都有一个默认的未命名数据流,除非您指定备用数据流,否则该数据流会自动打开。 您可以打开 ADS 的句柄并像普通文件一样使用单个 (Unicode) 文件名读取(甚至执行)它。 ADS 可以与任何磁盘文件一样大。

据我所知,Linux 上没有 ADS 的精确模拟,但如果数据值很小,您也许可以在 Linux 端口上使用 EA。

There are file systems on both Windows and Linux (and other OSes) that support extended attributes (EAs). The Windows support was added for OS/2 compat and does not have any documented interface, except for a hacky method through the backup API (that's what Cygwin does). EAs are designed to store small values only. On Windows, each EA has an ASCII name (whereas almost all other names are Unicode) and the combined size of all EAs on a file can't be larger than 64k. EAs are not files: you can't open a file handle to an EA and read it like a normal file.

Alternate data streams are a separate feature provided by NTFS which allows you to provide alternate subfiles inside of a file. Every file has a default unnamed data stream that is automatically opened unless you specify an alternate one. You can open a handle to an ADS and read (even execute) it like a normal file, with a single (Unicode) filename. An ADS can be as large as any disk file.

There is no exact analog to ADSes on Linux that I know of, but you may be able to use EAs on the Linux port instead if the data values are small.

时光病人 2024-07-13 11:24:19

ADS 的问题是,Windows 在移动到任何非 NTFS 文件系统时就会“丢失”这些 ADS 流。 它并不认为这些流很重要,因此通常不会保留它们。 您会发现它们在通过网络共享、刻录到 CD、放入 USB 驱动器等时无法访问或消失……

总而言之,除非您对应用程序的关注范围非常狭窄(始终在 NTFS 上),我会完全避免 ADS 流。

The problem with ADS is that Windows will "lose" those ADS streams the second that it moves to any non-NTFS filesystem. It does not consider those streams important, so oftentimes they are not kept around. You'll find they aren't accessible or disappear when over a network share, when burned to CD, put on a USB drive, etc...

The long and short of it is, unless you have a very narrow focus for your application (always on NTFS), I would avoid ADS streams altogether.

吃兔兔 2024-07-13 11:24:19

一些文件系统支持扩展属性,特别是 XFS 和(我认为)JFS; 但大小有限(XFS 中为 64k)。 Reiser4支持任意大小的分叉; 但据我所知,任何发行版都不支持它。 另一个选择是 ZFS,同样不是很有用。

最后,使用目录可能是更明智的选择。

Extended attributes are supported some filesystems, particularly XFS, and (i think) JFS; but are limited in size (64k in XFS). Reiser4 supports arbitrary sized forks; but it's not supported by any distro i know of. Another option is ZFS, again not very usable.

In the end, it's probably wiser to just use a directory.

偏爱自由 2024-07-13 11:24:19

大多数 Linux 文件系统都有扩展属性。 我对NTFS流不熟悉,所以无法比较两者。 大多数文件系统需要使用标志来安装以启用扩展属性,因此这可能不适用于任何人的系统。 它们通常缩写为xattrxattrs

Most Linux file systems have extended attributes. I'm not familiar with NTFS streams, so I can't compare the two. Most file systems need to be mounted with flags to enable the extended attributes, so this may not work generically for anyone's system. They are usually abbreviated as xattr or xattrs.

别理我 2024-07-13 11:24:19

我唯一知道的是扩展属性,但从我的情况来看阅读有关 ADS 的内容,这是明确的。 不是同一件事。 你到底用它做什么?

The only thing I know, which goes somewhat into that direction are extended attributes, but from what I read about ADS it's def. not the same thing. What exactly are you using that for?

ι不睡觉的鱼゛ 2024-07-13 11:24:19

常用的 Linux 文件系统不支持这一点。 相反,您可以使用多个文件和合适的命名方案(也许只需将流索引附加到每个文件名),或者包含多个文件的存档; 无论如何,您会发现这种方法在其他方面更好 - 例如,如果有人想将 Windows 文件备份到具有非 NTFS 文件系统的介质,在 Windows 上会发生什么?

The commonly used Linux filesystems do not support this. Instead you could use multiple files and a suitable naming scheme (just append the stream index to each filename, perhaps), or an archive containing multiple files; you will find such an approach is better in other ways anyway - for instance, what happens on Windows if someone wants to back up the files Windows to a medium with a non-NTFS filesystem?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文