Linux - 我如何知道给定文件的块映射和/或分区的可用空间映射 [英] Linux - How do i know the block map of the given file and/or the free space map of the partition

查看:146
本文介绍了Linux - 我如何知道给定文件的块映射和/或分区的可用空间映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上,需要知道以下两种情况之一:
$ b $ 1)如果我有一个在Linux下的分区上的某个文件系统上的常规文件是有一种方法来知道这个文件在用户空间驱动器上占用的物理块的集合吗?或者至少是文件系统集群的集合?

2)有没有办法获得有关给定文件系统的整个空闲空间的相同信息?

在这两种情况下,我明白,如果有任何可能的方式来提取这个信息,它可能是完全不安全和活泼(任何事情可能发生在这些时间之间的一组块看到他们,并以某种方式对他们采取行动)。我真的不希望一个实现,必须知道很多关于每个文件系统。

解决方案

这是不可能的以文件系统无关的方式。文件系统甚至不一定是建立在块设备(简单的例子:NFS)之上的。

对于 ext2 ext3 ext4 您可以使用 ext2fslib 库,包含在 e2fsprogs 发行版中。


I am on Linux and need to know either of the two things:

1) If i have a regular file on some file system on a partition under Linux is there a way to know the set of the physical blocks that this file occupies on the drive from user space? Or at least the set of the file system's clusters?

2) Is there a way to get the same information about the whole free space of the given file system?

In both cases i understand that if there is any possible way to extract this info it will probably be totally unsafe and racy (anything could happen to these set of blocks between the time i see them and act on them somehow). I also really don't want an implementation that will have to know a lot about every filesystem.

解决方案

It isn't possible in a filesystem-independent way. Filesystems aren't necessarily even built on top of block devices (simple example: NFS).

For ext2, ext3 and ext4 you can use the ext2fslib library, which is included in the e2fsprogs distribution.

这篇关于Linux - 我如何知道给定文件的块映射和/或分区的可用空间映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆