如何计算松弛空间?

发布于 2025-01-11 15:22:47 字数 72 浏览 0 评论 0原文

大小为 12,500 字节的文件将存储在扇区大小为 512 字节的硬盘驱动器上,簇由 8 个扇区组成。文件保存后还有多少剩余空间?

A file of size 12,500 bytes is to be stored on a hard disk drive where the sector size is 512 bytes, and a cluster consists of 8 sectors. How much slack space is there once the file has been saved?

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

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

发布评论

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

评论(1

只是在用心讲痛 2025-01-18 15:22:47

有几点需要了解:

  • 闲置空间是集群分配中剩余的扇区和字节。
  • 硬盘驱动器识别扇区,并且就逻辑块寻址而言几乎普遍为 512 字节。
  • OS(操作系统)理解集群,即扇区组。扇区数量因操作系统和文件系统而异。
  • 操作系统不理解扇区。硬盘驱动器不理解集群。但它们都是计算松弛空间所需的术语。

示例 1

给定:

  • 扇区大小:512 字节(基本上是当今唯一的扇区大小)
  • 簇大小:8 个扇区
  • 文件大小:2560 字节

在这种情况下,当分配磁盘空间来存储文件时,操作系统可以读取的最小量/write 必须是 8 个扇区或 4096 字节。
要查找松弛空间:

  1. 首先查找簇大小(以字节为单位)。簇 == 8 个扇区。

    ∴配额为4096

  2. 然后查找文件大小是否大于或小于该分配大小。
    2560字节< 4096.
    ∴只需要一个簇来保存此文件

  3. 从簇大小中减去文件大小,您就有了空闲空间。
    4096 - 2560 == 1536 字节(或 3 个扇区)的闲置空间。

示例 2

给定:

  • 扇区大小:512 字节
  • 簇大小:16 个扇区
  • 文件大小:61440 字节

在这种情况下,当磁盘空间为分配用于存储文件的操作系统可以读/写的最小数量必须是 16 个扇区或 8192 字节。
让我们完成相同的过程:

  1. 首先找到集群大小(以字节为单位)。簇 == 16 个扇区。

    ∴配额为8192

  2. 然后查找文件大小是否大于或小于该分配大小。
    61440字节> 8192.

    需要几个簇来保存此文件。

  3. 由于此文件较大,请将其除以簇大小(以字节为单位)。

    61440 / 8192 == 保存此文件需要 7.5 个簇

    这不是一个很好的舍入数字,因此我们必须向上舍入。回想一下,操作系统不能写入少于整个集群的数据,如果我们分配的整个集群少于必要的数量,我们将不会保存文件。

    ∴我们需要8个集群

  4. 查找您的分配大小(以字节为单位)。

    8 个簇 * 8192 == 65536

  5. 从集群分配中减去文件大小,就得到了闲置空间。

    65536 - 61440 == 4096 字节(或 4 个扇区)的闲置空间

尝试一下。

A few things to know:

  • Slack space is the leftover sectors and bytes from a cluster allocation.
  • Hard drives understand sectors and are nearly universally 512 bytes as far as logical block addressing goes.
  • OS (operating systems) understand clusters, which are groups of sectors. This amount of sectors can vary between OS and file system.
  • The OS DOES NOT understand sectors. The hard drive DOES NOT understand clusters. But they are both terms needed for calculating slack space.

Example 1

Given:

  • Sector Size: 512 bytes (basically the ONLY sector size these days)
  • cluster size: 8 sectors
  • file size: 2560 bytes

In this scenario, when disk space is allocated to store the file, the smallest amount that the OS can read/write MUST be 8 sectors or 4096 bytes.
To find slack space:

  1. first find your cluster size in bytes. Cluster == 8 sectors.

    ∴ allotment is 4096.

  2. then find if the file size is larger or smaller than that allotment size.
    2560 bytes < 4096.
    ∴ only one cluster is needed to save this file

  3. subtract the file size from the cluster size and you have slack space.
    4096 - 2560 == 1536 bytes (or 3 sectors) of slack space.

Example 2

Given:

  • Sector Size: 512 bytes
  • cluster size: 16 sectors
  • file size: 61440 bytes

In this scenario, when disk space is allocated to store the file, the smallest amount that the OS can read/write MUST be 16 sectors or 8192 bytes.
Let's work through the same process:

  1. first find your cluster size in bytes. Cluster == 16 sectors.

    ∴ allotment is 8192.

  2. then find if the file size is larger or smaller than that allotment size.
    61440 bytes > 8192.

    several clusters are needed to save this file.

  3. since this file is larger, divide it by the cluster size in bytes.

    61440 / 8192 == 7.5 clusters required to save this file.

    This isn't a nice round number, so we will have to round up. Recall that the OS cannot write LESS than a whole cluster and if we allot less whole clusters than necessary, we won't save the file.

    ∴ we require 8 clusters.

  4. find the size in bytes of your allotment size.

    8 clusters * 8192 == 65536.

  5. subtract the file size from the cluster allotment and you have slack space.

    65536 - 61440 == 4096 bytes (or 4 sectors) of slack space.

Try it.

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