Linux下的文件访问方法
在课本上看到文件访问方式主要有两种;顺序和直接。我们在 Linux 中使用的是哪一种?
在读取命令中,我们给出要读取的字节数以及读取到哪个缓冲区。那么我们在 Linux 中可以进行顺序访问吗?
但是物理上我们存储的文件是块吗?我无法理解它。
Linux下能否直接访问?
我在 Galvin 的《操作系统概念》中读到了有关这些访问模型的内容
Read in text books that there are mainly two file access methods; sequential and direct. Which one we are using in Linux?
In read command we are giving the how much bytes to read and to which buffer. So we are having sequential access in Linux?
But physically we have files stored is blocks? I couldnt relate to it.
Whether direct access possible in Linux?
I read about these access models in Operating System Concepts by Galvin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两者皆有可能。
当您对普通文件执行
读取
时,它会按顺序读取文件,每次都会将文件指针前进适当的量。但您也可以使用
seek
移动到文件中的任意点。并非所有文件都支持随机/直接访问。例如,管道通常只能顺序访问(不能倒带或快进)。
所以几乎一切皆有可能,但某些文件类型有限制。
(使用直接 I/O(
O_DIRECT
标志)进行文件访问是完全不同的概念。)Both are possible.
When you do a
read
on an ordinary file, it does read the file sequentially, advancing the file pointer each time by the right amount.But you can also use
seek
to move to an arbitrary point in the file.Not all files support random/direct access. Pipes for instance are typically only sequential access (you can't rewind or skip forward).
So pretty much everything is possible, but some file types have restrictions.
(File access with direct I/O (
O_DIRECT
flag) is a different concept altogether.)您当然可以从打开的(光盘)文件中的任意位置读取/写入。
有多种执行随机 IO 的方法,这些方法针对不同类型的用途进行了优化。
You can certainly read/write from an arbitrary position in an open (disc) file.
There are a number of methods of doing random IO, which are optimised for different kinds of usage.