Transmission des événements du noyau à une interface graphique comme Nautilus (d'après ce que j'ai compris) :

  1. Génération d'un uevent dans le noyau ;
  2. Génération d'un uevent dans udev ;
  3. Génération d'un signal D-BUS par udisks ;
  4. Dans Gnome, transmission à gvfs.

Gestionnaire de périphériques udev

udev est le gestionnaire de périphériques du noyau Linux. Il construit dynamiquement l'arborescence /dev en fonction des périphériques détectés sur le système.

Page de udev sur Wikipédia EN.

Pour afficher des infos sur un disque (sda en l'occurrence) :

# udevadm info --query=all --name=sda

P: /devices/pci0000:00/0000:00:11.1/host0/target0:0:0/0:0:0:0/block/sda
N: sda
S: block/8:0
S: disk/by-id/scsi-SATA_Maxtor_6L250R0_L5012QZG
S: disk/by-id/ata-Maxtor_6L250R0_L5012QZG
S: disk/by-path/pci-0000:00:11.1-scsi-0:0:0:0
E: UDEV_LOG=3
E: DEVPATH=/devices/pci0000:00/0000:00:11.1/host0/target0:0:0/0:0:0:0/block/sda
E: MAJOR=8
E: MINOR=0
E: DEVNAME=/dev/sda
E: DEVTYPE=disk
E: SUBSYSTEM=block
E: ID_ATA=1
E: ID_TYPE=disk
E: ID_BUS=ata
E: ID_MODEL=Maxtor_6L250R0
E: ID_MODEL_ENC=Maxtor\x206L250R0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_REVISION=BAH41G01
E: ID_SERIAL=Maxtor_6L250R0_L5012QZG
E: ID_SERIAL_SHORT=L5012QZG
E: ID_ATA_WRITE_CACHE=1
E: ID_ATA_WRITE_CACHE_ENABLED=1
E: ID_ATA_FEATURE_SET_HPA=1
E: ID_ATA_FEATURE_SET_HPA_ENABLED=1
E: ID_ATA_FEATURE_SET_PM=1
E: ID_ATA_FEATURE_SET_PM_ENABLED=1
E: ID_ATA_FEATURE_SET_SECURITY=1
E: ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=0
E: ID_ATA_FEATURE_SET_SMART=1
E: ID_ATA_FEATURE_SET_SMART_ENABLED=0
E: ID_ATA_FEATURE_SET_AAM=1
E: ID_ATA_FEATURE_SET_AAM_ENABLED=1
E: ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE=192
E: ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE=254
E: ID_ATA_FEATURE_SET_APM=1
E: ID_ATA_FEATURE_SET_APM_ENABLED=0
E: ID_ATA_DOWNLOAD_MICROCODE=1
E: ID_SCSI_COMPAT=SATA_Maxtor_6L250R0_L5012QZG
E: ID_PATH=pci-0000:00:11.1-scsi-0:0:0:0
E: ID_PART_TABLE_TYPE=dos
E: UDISKS_PRESENTATION_NOPOLICY=0
E: UDISKS_PARTITION_TABLE=1
E: UDISKS_PARTITION_TABLE_SCHEME=mbr
E: UDISKS_PARTITION_TABLE_COUNT=4
E: UDISKS_ATA_SMART_IS_AVAILABLE=1
E: DEVLINKS=/dev/block/8:0 /dev/disk/by-id/scsi-SATA_Maxtor_6L250R0_L5012QZG /dev/disk/by-id/ata-Maxtor_6L250R0_L5012QZG /dev/disk/by-path/pci-0000:00:11.1-scsi-0:0:0:0

Exemple : périphérique loopback non utilisé :

# udevadm info --query=all --name=loop2

P: /devices/virtual/block/loop2
N: loop2
S: block/7:2
E: UDEV_LOG=3
E: DEVPATH=/devices/virtual/block/loop2
E: MAJOR=7
E: MINOR=2
E: DEVNAME=/dev/loop2
E: DEVTYPE=disk
E: SUBSYSTEM=block
E: UDISKS_PRESENTATION_NOPOLICY=1
E: DEVLINKS=/dev/block/7:2

Exemple : périphérique loopback utilisé pour monter un volume chiffré :

# udevadm info --query=all --name=loop1

P: /devices/virtual/block/loop1
N: loop1
S: block/7:1
S: disk/by-uuid/36d147b0-cc17-4f42-84ed-df57927bf783
E: UDEV_LOG=3
E: DEVPATH=/devices/virtual/block/loop1
E: MAJOR=7
E: MINOR=1
E: DEVNAME=/dev/loop1
E: DEVTYPE=disk
E: SUBSYSTEM=block
E: ID_FS_UUID=36d147b0-cc17-4f42-84ed-df57927bf783
E: ID_FS_UUID_ENC=36d147b0-cc17-4f42-84ed-df57927bf783
E: ID_FS_VERSION=256
E: ID_FS_TYPE=crypto_LUKS
E: ID_FS_USAGE=crypto
E: UDISKS_PRESENTATION_NOPOLICY=1
E: DEVLINKS=/dev/block/7:1 /dev/disk/by-uuid/36d147b0-cc17-4f42-84ed-df57927bf783

Génération d'un événement "changement" pour les interfaces loopback :

# udevadm trigger --verbose --action=change --sysname-match=loop*

/sys/devices/virtual/block/loop0
/sys/devices/virtual/block/loop1
/sys/devices/virtual/block/loop2
/sys/devices/virtual/block/loop3
/sys/devices/virtual/block/loop4
/sys/devices/virtual/block/loop5
/sys/devices/virtual/block/loop6
/sys/devices/virtual/block/loop7

Gestionnaire de stockage udisks

L'interface udisks permet de dresser la liste des périphériques de stockage du système et de les manipuler.

Page de udisks sur Freedesktop.org.

Pour afficher la liste des périphériques :

$ udisks --dump | more

Showing information for /org/freedesktop/UDisks/devices/dm_2d0
  native-path:                 /sys/devices/virtual/block/dm-0
  device:                      253:0
  device-file:                 /dev/dm-0
    presentation:              /dev/dm-0
  detected at:                 ven. 16 déc. 2011 13:23:35 CET
  system internal:             1
  removable:                   0
  has media:                   1 (detected at ven. 16 déc. 2011 13:23:35 CET)
    detects change:            0
    detection by polling:      0
    detection inhibitable:     0
    detection inhibited:       0
  is read only:                0
  is mounted:                  1
  mount paths:             /
  mounted by uid:              0
  presentation hide:           0
  presentation nopolicy:       1
  presentation name:           
  presentation icon:           
(...)

Pour surveiller les événements :

udisks --monitor-detail
Monitoring activity from the disks daemon. Press Ctrl+C to cancel.

Evénements qui suivent la connexion d'une clef USB :

added:     /org/freedesktop/UDisks/devices/sdd
Showing information for /org/freedesktop/UDisks/devices/sdd
  native-path:                 /sys/devices/pci0000:00/0000:00:10.2/usb4/4-2/4-2:1.0/host5/target5:0:0/5:0:0:0/block/sdd
  device:                      8:48
  device-file:                 /dev/sdd
    presentation:              /dev/sdd
    by-id:                     /dev/disk/by-id/usb-Corsair_Voyager_30000000377285-0:0
    by-path:                   /dev/disk/by-path/pci-0000:00:10.2-usb-0:2:1.0-scsi-0:0:0:0
  detected at:                 ven. 16 déc. 2011 18:27:13 CET
  system internal:             0
  removable:                   1
  has media:                   1 (detected at ven. 16 déc. 2011 18:27:13 CET)
    detects change:            1
    detection by polling:      1
    detection inhibitable:     1
    detection inhibited:       0
  is read only:                0
  is mounted:                  0
  mount paths:             
  mounted by uid:              0
  presentation hide:           0
  presentation nopolicy:       0
  presentation name:           
  presentation icon:           
  size:                        8076132352
  block size:                  512
  job underway:                no
  usage:                       
  type:                        
  version:                     
  uuid:                        
  label:                       
  partition table:
    scheme:                    mbr
    count:                     1
  drive:
    vendor:                    Corsair
    model:                     Voyager
    revision:                  0.00
    serial:                    30000000377285
    WWN:                       
    detachable:                1
    can spindown:              0
    rotational media:          Yes, unknown rate
    write-cache:               unknown
    ejectable:                 0
    adapter:                   Unknown
    ports:
    similar devices:
    media:                     
      compat:                 
    interface:                 usb
    if speed:                  12000000 bits/s
    ATA SMART:                 not available

added:     /org/freedesktop/UDisks/devices/sdd1
Showing information for /org/freedesktop/UDisks/devices/sdd1
  native-path:                 /sys/devices/pci0000:00/0000:00:10.2/usb4/4-2/4-2:1.0/host5/target5:0:0/5:0:0:0/block/sdd/sdd1
  device:                      8:49
  device-file:                 /dev/sdd1
    presentation:              /dev/sdd1
    by-id:                     /dev/disk/by-id/usb-Corsair_Voyager_30000000377285-0:0-part1
    by-id:                     /dev/disk/by-uuid/24E9-F695
    by-path:                   /dev/disk/by-path/pci-0000:00:10.2-usb-0:2:1.0-scsi-0:0:0:0-part1
  detected at:                 ven. 16 déc. 2011 18:27:14 CET
  system internal:             0
  removable:                   0
  has media:                   1 (detected at ven. 16 déc. 2011 18:27:14 CET)
    detects change:            0
    detection by polling:      0
    detection inhibitable:     0
    detection inhibited:       0
  is read only:                0
  is mounted:                  0
  mount paths:             
  mounted by uid:              0
  presentation hide:           0
  presentation nopolicy:       0
  presentation name:           
  presentation icon:           
  size:                        8075083776
  block size:                  512
  job underway:                no
  usage:                       filesystem
  type:                        vfat
  version:                     FAT32
  uuid:                        24E9-F695
  label:                       8-Go-1
  partition:
    part of:                   /org/freedesktop/UDisks/devices/sdd
    scheme:                    mbr
    number:                    1
    type:                      0x0c
    flags:                    
    offset:                    1048576
    alignment offset:          0
    size:                      8075083776
    label:                     
    uuid:                      

job-changed: /org/freedesktop/UDisks/devices/sdd1
  job underway:                FilesystemMount, initiated by uid 1000
changed:     /org/freedesktop/UDisks/devices/sdd
Showing information for /org/freedesktop/UDisks/devices/sdd
  native-path:                 /sys/devices/pci0000:00/0000:00:10.2/usb4/4-2/4-2:1.0/host5/target5:0:0/5:0:0:0/block/sdd
  device:                      8:48
  device-file:                 /dev/sdd
    presentation:              /dev/sdd
    by-id:                     /dev/disk/by-id/usb-Corsair_Voyager_30000000377285-0:0
    by-path:                   /dev/disk/by-path/pci-0000:00:10.2-usb-0:2:1.0-scsi-0:0:0:0
  detected at:                 ven. 16 déc. 2011 18:27:13 CET
  system internal:             0
  removable:                   1
  has media:                   1 (detected at ven. 16 déc. 2011 18:27:13 CET)
    detects change:            1
    detection by polling:      1
    detection inhibitable:     1
    detection inhibited:       0
  is read only:                0
  is mounted:                  0
  mount paths:             
  mounted by uid:              0
  presentation hide:           0
  presentation nopolicy:       0
  presentation name:           
  presentation icon:           
  size:                        8076132352
  block size:                  512
  job underway:                no
  usage:                       
  type:                        
  version:                     
  uuid:                        
  label:                       
  partition table:
    scheme:                    mbr
    count:                     1
  drive:
    vendor:                    Corsair
    model:                     Voyager
    revision:                  0.00
    serial:                    30000000377285
    WWN:                       
    detachable:                1
    can spindown:              0
    rotational media:          Yes, unknown rate
    write-cache:               unknown
    ejectable:                 0
    adapter:                   Unknown
    ports:
    similar devices:
    media:                     
      compat:                 
    interface:                 usb
    if speed:                  12000000 bits/s
    ATA SMART:                 not available

changed:     /org/freedesktop/UDisks/devices/sdd1
Showing information for /org/freedesktop/UDisks/devices/sdd1
  native-path:                 /sys/devices/pci0000:00/0000:00:10.2/usb4/4-2/4-2:1.0/host5/target5:0:0/5:0:0:0/block/sdd/sdd1
  device:                      8:49
  device-file:                 /dev/sdd1
    presentation:              /dev/sdd1
    by-id:                     /dev/disk/by-id/usb-Corsair_Voyager_30000000377285-0:0-part1
    by-id:                     /dev/disk/by-uuid/24E9-F695
    by-path:                   /dev/disk/by-path/pci-0000:00:10.2-usb-0:2:1.0-scsi-0:0:0:0-part1
  detected at:                 ven. 16 déc. 2011 18:27:14 CET
  system internal:             0
  removable:                   0
  has media:                   1 (detected at ven. 16 déc. 2011 18:27:14 CET)
    detects change:            0
    detection by polling:      0
    detection inhibitable:     0
    detection inhibited:       0
  is read only:                0
  is mounted:                  1
  mount paths:             /media/8-Go-1
  mounted by uid:              1000
  presentation hide:           0
  presentation nopolicy:       0
  presentation name:           
  presentation icon:           
  size:                        8075083776
  block size:                  512
  job underway:                no
  usage:                       filesystem
  type:                        vfat
  version:                     FAT32
  uuid:                        24E9-F695
  label:                       8-Go-1
  partition:
    part of:                   /org/freedesktop/UDisks/devices/sdd
    scheme:                    mbr
    number:                    1
    type:                      0x0c
    flags:                    
    offset:                    1048576
    alignment offset:          0
    size:                      8075083776
    label:                     
    uuid:                      

job-changed: /org/freedesktop/UDisks/devices/sdd1
  job underway:                no

GVFS

GVGS est le système de fichiers virtuel de GNOME.

Page de GVFS sur Wikipédia EN.

Pour suivre les événements :

$ gvfs-mount -io
Monitoring events. Press Ctrl+C to quit.

Evénéments qui suivent la déconnexion d'une clef USB :

Mount pre-unmount:  '8-Go-1'
  Mount(0): 8-Go-1 -> file:///media/8-Go-1
    Type: GProxyMount (GProxyVolumeMonitorGdu)
    default_location=file:///media/8-Go-1
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    can_unmount=1
    can_eject=1
    is_shadowed=0

Volume changed:     '8-Go-1'
  Volume(0): 8-Go-1
    Type: GProxyVolume (GProxyVolumeMonitorGdu)
    ids:
     uuid: '24E9-F695'
     unix-device: '/dev/sdd1'
     label: '8-Go-1'
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    can_mount=1
    can_eject=1
    should_automount=0
    Mount(0): 8-Go-1 -> file:///media/8-Go-1
      Type: GProxyMount (GProxyVolumeMonitorGdu)
      default_location=file:///media/8-Go-1
      themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
      can_unmount=1
      can_eject=1
      is_shadowed=0

Volume changed:     '8-Go-1'
  Volume(0): 8-Go-1
    Type: GProxyVolume (GProxyVolumeMonitorGdu)
    ids:
     uuid: '24E9-F695'
     unix-device: '/dev/sdd1'
     label: '8-Go-1'
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    can_mount=1
    can_eject=1
    should_automount=0

Mount changed: '8-Go-1'
  Mount(0): 8-Go-1 -> file:///media/8-Go-1
    Type: GProxyMount (GProxyVolumeMonitorGdu)
    default_location=file:///media/8-Go-1
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    can_unmount=1
    can_eject=0
    is_shadowed=0

Mount removed: '8-Go-1'
  Mount(0): 8-Go-1 -> file:///media/8-Go-1
    Type: GProxyMount (GProxyVolumeMonitorGdu)
    default_location=file:///media/8-Go-1
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    can_unmount=1
    can_eject=0
    is_shadowed=0

Drive changed:      'Corsair Voyager'
  Drive(0): Corsair Voyager
    Type: GProxyDrive (GProxyVolumeMonitorGdu)
    ids:
     unix-device: '/dev/sdd'
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    is_media_removable=1
    has_media=0
    is_media_check_automatic=1
    can_poll_for_media=1
    can_eject=0
    can_start=0
    can_stop=1
    start_stop_type=shutdown
    Volume(0): 8-Go-1
      Type: GProxyVolume (GProxyVolumeMonitorGdu)
      ids:
       uuid: '24E9-F695'
       unix-device: '/dev/sdd1'
       label: '8-Go-1'
      themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
      can_mount=1
      can_eject=0
      should_automount=0

Drive changed:      'Corsair Voyager'
  Drive(0): Corsair Voyager
    Type: GProxyDrive (GProxyVolumeMonitorGdu)
    ids:
     unix-device: '/dev/sdd'
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    is_media_removable=1
    has_media=0
    is_media_check_automatic=1
    can_poll_for_media=1
    can_eject=0
    can_start=0
    can_stop=1
    start_stop_type=shutdown

Volume removed:     '8-Go-1'
  Volume(0): 8-Go-1
    Type: GProxyVolume (GProxyVolumeMonitorGdu)
    ids:
     uuid: '24E9-F695'
     unix-device: '/dev/sdd1'
     label: '8-Go-1'
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    can_mount=1
    can_eject=0
    should_automount=0

Drive disconnected: 'Corsair Voyager'
  Drive(0): Corsair Voyager
    Type: GProxyDrive (GProxyVolumeMonitorGdu)
    ids:
     unix-device: '/dev/sdd'
    themed icons:  [drive-removable-media-usb]  [drive-removable-media]  [drive-removable]  [drive]
    is_media_removable=1
    has_media=0
    is_media_check_automatic=1
    can_poll_for_media=1
    can_eject=0
    can_start=0
    can_stop=1
    start_stop_type=shutdown

Bus PCI et USB

$ lspci | more

00:00.0 Host bridge: VIA Technologies, Inc. VT8377 [KT400/KT600 AGP] Host Bridge
 (rev 80)
00:01.0 PCI bridge: VIA Technologies, Inc. VT8237/VX700 PCI Bridge
00:0a.0 Multimedia audio controller: Creative Labs SB Live! EMU10k1 (rev 07)
00:0a.1 Input device controller: Creative Labs SB Live! Game Port (rev 07)
00:0b.0 SCSI storage controller: Adaptec AIC-7892B U160/m (rev 02)
00:10.0 USB controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller
 (rev 80)
00:10.1 USB controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller
 (rev 80)
00:10.2 USB controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller
 (rev 80)
00:10.3 USB controller: VIA Technologies, Inc. USB 2.0 (rev 82)
00:11.0 ISA bridge: VIA Technologies, Inc. VT8235 ISA Bridge
00:11.1 IDE interface: VIA Technologies, Inc. VT82C586A/B/VT82C686/A/B/VT823x/A/
C PIPC Bus Master IDE (rev 06)
00:11.5 Multimedia audio controller: VIA Technologies, Inc. VT8233/A/8235/8237 A
C97 Audio Controller (rev 50)
00:12.0 Ethernet controller: VIA Technologies, Inc. VT6102 [Rhine-II] (rev 74)
01:00.0 VGA compatible controller: Matrox Graphics, Inc. MGA G400/G450 (rev 05)
$ lsusb | more

Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0bc2:3300 Seagate RSS LLC 
Bus 001 Device 002: ID 152d:2336 JMicron Technology Corp. / JMicron USA Technolo
gy Corp. Hard Disk Drive
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Arborescence /proc

Liste des périphériques montés :

$ cat /proc/self/mounts

rootfs / rootfs rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
none /proc proc rw,nosuid,nodev,noexec,relatime 0 0
none /dev devtmpfs rw,relatime,size=256104k,nr_inodes=64026,mode=755 0 0
none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620 0 0
/dev/mapper/debian-root / reiserfs rw,relatime 0 0
tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0
/dev/mapper/debian-boot /boot reiserfs rw,relatime,notail 0 0
/dev/mapper/debian-home /home reiserfs rw,relatime 0 0
/dev/mapper/debian-data /mnt/data reiserfs rw,relatime 0 0
/dev/mapper/debian-tmp /tmp reiserfs rw,relatime 0 0
/dev/mapper/debian-var /var reiserfs rw,relatime 0 0
/dev/sdb1 /media/data_rw fuseblk rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/sda3 /media/Données2 ext4 rw,relatime,barrier=1,data=ordered 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0