zoukankan      html  css  js  c++  java
  • linux下/proc/partitions中block的size

    引自:https://unix.stackexchange.com/questions/512945/what-units-are-the-values-in-proc-partitions-and-sys-dev-block-block-size

    /proc/partitions shows the size in 1024-byte blocks.

    /sys/dev/block/*/*/size shows the size in 512-byte sectors.

    Both irrespective of the logical/physical block/sector size of the device.


    For the 1st, you can look in the proc(5) manpage:

    /proc/partitions

    Contains the major and minor numbers of each partition as well as the number of 1024-byte blocks and the partition name.

    For the 2nd, it certainly should be documented somewhere but you can also look directly at the Linux source code in block/partition-generic.c:

    ssize_t part_size_show(struct device *dev,
                           struct device_attribute *attr, char *buf)
    {
            struct hd_struct *p = dev_to_part(dev);
            return sprintf(buf, "%llu
    ",(unsigned long long)part_nr_sects_read(p));
    ...
    static DEVICE_ATTR(size, 0444, part_size_show, NULL);
    

    and how it relates to the code which generates the /proc/partitions info in block/genhd.c:

    static int show_partition(struct seq_file *seqf, void *v)
    {
            ...
            while ((part = disk_part_iter_next(&piter)))
                    seq_printf(seqf, "%4d  %7d %10llu %s
    ",
                               MAJOR(part_devt(part)), MINOR(part_devt(part)),
                               (unsigned long long)part_nr_sects_read(part) >> 1,
                               disk_name(sgp, part->partno, buf));
            disk_part_iter_exit(&piter);
    ...
    static const struct seq_operations partitions_op = {
            ...
            .show   = show_partition
    

    Both are using part_nr_sects_read() which for the case of /proc/partitions is divided by 2 (with >> 1).

    part_nr_sects_read() retrieves the nr_sects field of the struct hd_struct, which is always in 512-byte sectors, irrespective of the sector/block size of the device. For instance, you can look at how drivers/block/nbd.c uses the set_capacity() function (which sets the same nr_sects field) with the byte size divided by 512 (with >> 9):

    static void nbd_size_update(struct nbd_device *nbd)
    {
            ...
            set_capacity(nbd->disk, config->bytesize >> 9);
  • 相关阅读:
    HDFS文件操作(基本文件命令)
    <a> 标签
    css text-overflow
    zepto.js 打包自定义模块
    CSS3 box-sizing
    CSS3 Filter
    JQ 导出 Excel
    outline css2
    iphone 操作手势种类
    动手写一个简单的Web框架(模板渲染)
  • 原文地址:https://www.cnblogs.com/amoy9812/p/12360396.html
Copyright © 2011-2022 走看看