|
From: Linus W. <lin...@gm...> - 2010-12-07 20:17:40
|
2010/12/7 <la...@no...>:
> # Autoprobe PTP devices
> ENV{ID_MTP_DEVICE}!="1", ATTR{bDeviceClass}=="06",
> PROGRAM="/lib/udev/mtp-probe /sys$env{DEVPATH} $attr{busnum}
> $attr{devnum}", RESULT=="1", SYMLINK+="libmtp-%k", MODE="666",
> ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
>
> # Autoprobe vendor-specific devices
> ENV{ID_MTP_DEVICE}!="1", ATTR{bDeviceClass}=="ff",
> PROGRAM="/lib/udev/mtp-probe /sys$env{DEVPATH} $attr{busnum}
> $attr{devnum}", RESULT=="1", SYMLINK+="libmtp-%k", MODE="666",
> ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
>
> 1. So for devices that already in device database, it will matched by other
> rules .It seems to me that the env variable 'ID_MTP_DEVICE' is a new one,
> So maybe this variable is NOT set to value "1" when a known device match a
> rule, am I right? If yes, then I am afraid above rule will be executed for
> every device, even this device has already in the database.
If you look at the libmtp.rules that is generated when you compile
libmtp you will see that it now adds ENV{ID_MTP_DEVICE}="1"
to all known devices by default.
ENV{ID_MTP_DEVICE}!="1" means "execute the rest of the line if this
variable is *not* set to "1". And if one of the other rules match, it will
be set to "1" and this will not be executed. I have tested this, so it
should work.
> 2. could you please add another rule for the case that
> ATTR{bDeviceClass}=="00"?
> Our implementation will set 'bDeviceClass' as 0x00, which means, according
> to the spec, each interface specifies its own class code.
Aha yeah that makes sense. I actually merged all three cases into
one:
# Autoprobe vendor-specific and PTP devices
ENV{ID_MTP_DEVICE}!="1", ATTR{bDeviceClass}=="00|06|ff",
PROGRAM="/lib/udev/mtp-probe /sys$env{DEVPATH} $attr{busnum}
$attr{devnum}", RESULT=="1", SYMLINK+="libmtp-%k", MODE="666",
ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
> 3. what does "RESULT=="1"" means, the exit code of program mtp_probe?
No it is a string emitted by the program. printf("1");
If it is not an MTP device it emits "0" with printf("0");
> I have written a c
> program, which will use info under sysfs, to check the string descriptor of
> a device , to see if it is a mtp device. If yes, when this program exit with
> code 1, the above rule does not take effect. If I miss something, please
> tell me.
I don't know if you can use the exit code at all. I think you have to
emit a string. The other udev programs I have seen only use
strings to pass to udev rules.
> Attached is the c program, we talked a earlier, to re-write the bash script
> as a c program, for your kindly review. I have added following rule to test
> it, and it works on my Ubuntu. Any concern, please contact me.
But I have already written a C program, it's in the libmtp
CVS... It uses libusb to examine the device. Very simple, check it
out! (And it works fine for me, can you test it? You need to install
it into /lib/udev/mtp-probe of course).
Yours,
Linus Walleij
|