Qual é a diferença entre / sys / class / block e / sys / block

1

Quando eu faço um ls de um dos dois diretórios, o conteúdo deles é muito parecido

/ sys / class / block

$ 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 / block /

$ 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

Ambos possuem vários links simbólicos para o mesmo lugar. A única diferença que vejo é /sys/class/block/ tem sda e sda1 até sda6 , enquanto /sys/block/ tem apenas sda .

Qual é a principal diferença entre /sys/block/ e /sys/class/block ?

    
por Wimateeka 24.04.2018 / 15:06

1 resposta

3

O último existe por razões de compatibilidade, porque o sysfs originalmente tinha código dedicado para dispositivos de bloco, mas depois eles se tornaram apenas outra "classe". Veja commit v2.6.24-158-gedfaa7c36574 :

Driver core: convert block from raw kobjects to core devices

This moves the block devices to /sys/class/block. It will create a flat list of all block devices, with the disks and partitions in one directory. For compatibility /sys/block is created and contains symlinks to the disks.

(encontrado usando tig blame drivers/base/class.c )

    
por 24.04.2018 / 15:18