sách gpt4 ai đã đi

Kích thước tối đa của xattr trong OS X

In lại 作者:行者123 更新时间:2023-12-05 01:01:00 28 4
mua khóa gpt4 Nike

我想使用 xattr 将一些元数据直接存储在我的文件上。这些本质上是我在搜索文件时用于文件分类的标签。我的目标是通过将更多信息与每个标签相关联来扩展通常的 Mac OS X 标签,例如添加该标签的日期以及可能的其他信息。

我正在考虑使用 xattr -w 将 xattr 添加到文件中。我的第一个猜测是在这个 xattr 值中存储类似 JSON 的东西,但我想知道

1) 我可以在 xattr 中存储的大小限制是多少? (xattr 的人是 vauge,指的是我无法在任何地方找到的名为 _PC_XATTR_SIZE_BITS 的东西)

2) 将 JSON 格式的字符串存储为 xattr 有什么问题吗?

1 Câu trả lời

theoman pathconf,有一个名为_PC_XATTR_SIZE_BITS的“可配置系统限制或选项变量”

the number of bits used to store maximum extended attribute size in bytes. For example, if the maximum attribute size supported by a file system is 128K, the value returned will be 18. However a value 18 can mean that the maximum attribute size can be anywhere from (256KB - 1) to 128KB. As a special case, the resource fork can have much larger size, and some file system specific extended attributes can have smaller and preset size; for example, Finder Info is always 32 bytes.

您可以使用这个用 Swift 4 编写的小型命令行工具来确定该参数的值:

import Foundation

let args = CommandLine.arguments.dropFirst()

guard let pathArg = args.first else {
print ("File path argument missing!")
exit (EXIT_FAILURE)
}

let v = pathconf(pathArg, _PC_XATTR_SIZE_BITS)

print ("_PC_XATTR_SIZE_BITS: \(v)")

exit (EXIT_SUCCESS)

我明白了:

  • 31 位用于 OS X 10.11 上的 HFS+
  • macOS 10.13 上的 APFS 为 64 位

作为用于存储最大扩展属性大小的位数。这意味着实际的最大 xattr 大小在范围内

  • 对于 OS X 10.11 上的 HFS+,1 GiB ≤ 最大值 < 2 GiB
  • 8 EiB ≤ 最大值 < 16 EiB 用于 macOS 10.13 上的 APFS

关于json - OS X 中 xattr 的最大大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47352805/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com