【问题标题】:golang read directly from blocksgolang 直接从块中读取
【发布时间】:2020-06-22 17:29:57
【问题描述】:

我有一个大约 300MB 的文件。我在 Linux 上运行以下命令:

sudo debugfs -R "stat /home/user1/Documents/test.csv" /dev/sda2

我得到以下输出:

Inode: 16913580   Type: regular    Mode:  0644   Flags: 0x80000
Generation: 3920968942    Version: 0x00000000:00000001
User:  1000   Group:  1000   Project:     0   Size: 301526706
File ACL: 0
Links: 1   Blockcount: 588928
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x5df9e6c2:7636fdcc -- Wed Dec 18 14:13:46 2019
 atime: 0x5e67b696:d6bfb018 -- Tue Mar 10 21:17:34 2020
 mtime: 0x5df11990:00000000 -- Wed Dec 11 22:00:08 2019
crtime: 0x5df9e6c0:63257940 -- Wed Dec 18 14:13:44 2019
Size of extra inode fields: 32
Inode checksum: 0x35f4d147
EXTENTS:
(ETB0):67695655, (0-8191):162652160-162660351, (8192-40959):165953536-165986303, (40960-57343):165986304-166002687, (57344-61439):166129664-166133759, (61440-65535):166135808-166139903, (65536-67583):166164480-166166527, (67584-71679):166168576-166172671, (71680-73614):166207623-166209557

我认为EXTENTS: 显示了文件的物理块。

我的问题是,是否可以直接从 golang 中的这些块号中读取为字节数组?

【问题讨论】:

  • 您可以将/dev/sda2作为二进制文件打开并查找/读取
  • 如果你想做这种事情你应该使用日志结构化存储文件系统

标签: linux file go operating-system filesystems


【解决方案1】:

我的问题是,是否可以直接从 golang 中的这些块号中读取为字节数组?

没有。

【讨论】:

  • @spiralarchitect 不支持。
  • @Volker 以 root 身份运行的 C 程序可以打开 /dev/sda2 并读写字节数组。为什么 Go 程序不能做到这一点?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-22
  • 2011-08-24
  • 1970-01-01
  • 1970-01-01
  • 2015-08-09
  • 2012-05-15
  • 1970-01-01
相关资源
最近更新 更多