1

Когда я делаю ls любого из dir, их содержимое очень похоже

/ SYS / класс / блок

$ ls /sys/class/block
dm-0  dm-3   loop1  loop4  loop7  ram10  ram13  ram2  ram5  ram8  sda1  sda4
dm-1  dm-4   loop2  loop5  ram0   ram11  ram14  ram3  ram6  ram9  sda2  sda5
dm-2  loop0  loop3  loop6  ram1   ram12  ram15  ram4  ram7  sda   sda3  sda6

ls -lah /sys/class/block/
total 0
drwxr-xr-x  2 root root 0 Apr 23 16:08 .
drwxr-xr-x 52 root root 0 Apr 23 16:08 ..
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-0 -> ../../devices/virtual/block/dm-0
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-1 -> ../../devices/virtual/block/dm-1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-2 -> ../../devices/virtual/block/dm-2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-3 -> ../../devices/virtual/block/dm-3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-4 -> ../../devices/virtual/block/dm-4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop0 -> ../../devices/virtual/block/loop0
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop1 -> ../../devices/virtual/block/loop1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop2 -> ../../devices/virtual/block/loop2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop3 -> ../../devices/virtual/block/loop3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop4 -> ../../devices/virtual/block/loop4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop5 -> ../../devices/virtual/block/loop5
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop6 -> ../../devices/virtual/block/loop6
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop7 -> ../../devices/virtual/block/loop7
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram0 -> ../../devices/virtual/block/ram0
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram1 -> ../../devices/virtual/block/ram1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram10 -> ../../devices/virtual/block/ram10
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram11 -> ../../devices/virtual/block/ram11
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram12 -> ../../devices/virtual/block/ram12
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram13 -> ../../devices/virtual/block/ram13
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram14 -> ../../devices/virtual/block/ram14
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram15 -> ../../devices/virtual/block/ram15
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram2 -> ../../devices/virtual/block/ram2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram3 -> ../../devices/virtual/block/ram3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram4 -> ../../devices/virtual/block/ram4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram5 -> ../../devices/virtual/block/ram5
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram6 -> ../../devices/virtual/block/ram6
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram7 -> ../../devices/virtual/block/ram7
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram8 -> ../../devices/virtual/block/ram8
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram9 -> ../../devices/virtual/block/ram9
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda1 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda2 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda3 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda4 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda5 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda5
lrwxrwxrwx  1 r

/ SYS / блок /

$ ls /sys/block/
dm-0  dm-3   loop1  loop4  loop7  ram10  ram13  ram2  ram5  ram8
dm-1  dm-4   loop2  loop5  ram0   ram11  ram14  ram3  ram6  ram9
dm-2  loop0  loop3  loop6  ram1   ram12  ram15  ram4  ram7  sda

$ ls -lah /sys/block/
drwxr-xr-x  2 root root 0 Apr 23 16:08 .
dr-xr-xr-x 13 root root 0 Apr 23 16:08 ..
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-0 -> ../devices/virtual/block/dm-0
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-1 -> ../devices/virtual/block/dm-1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-2 -> ../devices/virtual/block/dm-2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-3 -> ../devices/virtual/block/dm-3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 dm-4 -> ../devices/virtual/block/dm-4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop0 -> ../devices/virtual/block/loop0
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop1 -> ../devices/virtual/block/loop1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop2 -> ../devices/virtual/block/loop2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop3 -> ../devices/virtual/block/loop3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop4 -> ../devices/virtual/block/loop4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop5 -> ../devices/virtual/block/loop5
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop6 -> ../devices/virtual/block/loop6
lrwxrwxrwx  1 root root 0 Apr 23 16:08 loop7 -> ../devices/virtual/block/loop7
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram0 -> ../devices/virtual/block/ram0
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram1 -> ../devices/virtual/block/ram1
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram10 -> ../devices/virtual/block/ram10
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram11 -> ../devices/virtual/block/ram11
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram12 -> ../devices/virtual/block/ram12
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram13 -> ../devices/virtual/block/ram13
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram14 -> ../devices/virtual/block/ram14
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram15 -> ../devices/virtual/block/ram15
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram2 -> ../devices/virtual/block/ram2
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram3 -> ../devices/virtual/block/ram3
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram4 -> ../devices/virtual/block/ram4
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram5 -> ../devices/virtual/block/ram5
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram6 -> ../devices/virtual/block/ram6
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram7 -> ../devices/virtual/block/ram7
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram8 -> ../devices/virtual/block/ram8
lrwxrwxrwx  1 root root 0 Apr 23 16:08 ram9 -> ../devices/virtual/block/ram9
lrwxrwxrwx  1 root root 0 Apr 23 16:08 sda -> ../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda

Они оба имеют многочисленные символические ссылки на одно и то же место. Единственное отличие, которое я вижу, это /sys/class/block/ имеет sda и sda1 через sda6 то время как /sys/block/ имеет только sda .

В чем основное различие между /sys/block/ и /sys/class/block?

1 ответ1

3

Последнее существует по причинам совместимости, потому что sysfs изначально имел выделенный код для блочных устройств, но позже они стали просто еще одним "классом". Смотрите коммит v2.6.24-158-gedfaa7c36574:

Ядро драйвера: конвертировать блок из необработанных kobjects в основные устройства

Это перемещает блочные устройства в /sys /class /block. Он создаст плоский список всех блочных устройств с дисками и разделами в одном каталоге. Для совместимости /sys /block создан и содержит символические ссылки на диски.

(Найдено с помощью tig blame drivers/base/class.c)

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .