0

我们有一个嵌入式 Linux 版本,它从处于睡眠模式(硬件)的 HDD 开始。然后软件启动并启用驱动器的电源。Linux 检测到驱动器正常:

ata1: exception Emask 0x10 SAct 0x0 SErr 0x4050000 action 0x42 frozen
ata1: soft resetting port
ata1: SATA link up 1.5 Gbps (SStatus 113 SControl F0000)
ata1.00: ATA-8, max UDMA/133, 976773168 sectors: LBA48 NCQ (depth 0/32)
ata1.00: ata1: dev 0 multi count 0
ata1.00: configured for UDMA/133
ata1: EH complete
  Vendor: ATA       Model: Hitachi HCS5C105  Rev: JC2O
  Type:   Direct-Access                      ANSI SCSI revision: 05
SCSI device sda: 976773168 512-byte hdwr sectors (500108 MB)
sda: Write Protect is off
SCSI device sda: drive cache: write back
SCSI device sda: 976773168 512-byte hdwr sectors (500108 MB)
sda: Write Protect is off
SCSI device sda: drive cache: write back
 sda: sda1 sda2
sd 0:0:0:0: Attached scsi disk sda
sd 0:0:0:0: Attached scsi generic sg0 type 0

不幸的是,软件会在上述 SCSI 检测发生之前尝试访问驱动器。我们可以添加一个睡眠,但这不是一个可靠的机制,因为我们注意到检测所花费的时间是不确定的。

有什么方法可以获取内核/热插拔/等。系统在检测到 HDD 时报告?

谢谢。

4

3 回答 3

3

我认为答案在udev设备管理器(维基百科页面)中的某个地方。它在嵌入式环境中完全可用。

它允许您编写能够在检测到某些设备时启动脚本/程序的规则。

像这样的东西可以做的事情:

KERNEL=="sda", RUN+="/usr/bin/my_program"

如果你有一个旧内核,你可能激活了热插拔系统。

最后的机会是inotify工具,它可以让您监控文件系统中的任何内容(甚至 /dev 目录:))。

于 2011-09-07T13:51:38.613 回答
2

您有一组选项可以做到这一点,从最简单到最复杂:

  • 手动轮询。只需编写一个 shell 脚本,在实际使用之前轮询硬盘,直到硬盘可用。当然,这不是最好的解决方案,但它有效且简单。
  • mdev. If your embedded Linux system is Busybox based (which I hope it is!), then Busybox integrates the mdev program. Its usage is very simple and is documented at http://git.buildroot.net/busybox/tree/docs/mdev.txt. mdev will very easily allow you to run a shell script when a device gets detected. If you already have Busybox in your embedded Linux system, this is definitely the solution I would recommend.
  • udev, as proposed by others. This is the solution used in full blown desktop/server systems. It has more dependencies than mdev and is a bit harder to setup. If you only have your hard disk detection problem to solve, I'd say that using udev is a bit overkill, but if you intend to use it for other purposes, why not.
  • udev + udisks + dbus,这实际上是在成熟的系统上使用的。udisks是一个守护进程,用于udev通知系统中出现新的存储设备,它获取一些关于它们的附加信息,然后通过 D-Bus 发送消息。它允许提供 D-Bus 服务来操作存储设备。

我希望这能让您大致了解可能的解决方案。

于 2011-09-08T07:26:17.037 回答
0

您可以收听 uevent netlink 套接字 - 您将获得与 udevd 相同的事件

http://lwn.net/Articles/242046/

于 2011-09-22T01:54:54.133 回答