You are not logged in.

#1 2014-02-23 16:51:26

sw8511
Member
Registered: 2005-06-09
Posts: 11

Influencing generic scsi /dev/sgX node allocation (Kingston DT USB)

Hello,

I have a Kingston USB memory stick which has an encrypted partition and CD-ROM partition containing the Kingston linux scripts (dt4000_*) to initialise/login/logout the encrypted partition. These Kingston scripts expect the encrypted partition to appear as device /dev/sg[0-7]. When I load the sg module, /dev/sg[0-6] are allocated to my hard drives, DVD drive and card reader, and /dev/sg[7,8] to the encrypted partition and the CD-ROM partition as shown below:

[steve@giraffe linux32]$ lsscsi -g
[0:0:0:0]    disk    ATA      WDC WD3000HLFS-0 04.0  /dev/sda   /dev/sg0
[1:0:0:0]    cd/dvd  PBDS     DVD+-RW DH-16W1S 2D14  /dev/sr0   /dev/sg1
[2:0:0:0]    disk    ATA      ST3500418AS      CC34  /dev/sdb   /dev/sg2 
[4:0:0:0]    disk    TEAC     USB   HS-CF Card 4.08  /dev/sdc   /dev/sg3 
[4:0:0:1]    disk    TEAC     USB   HS-xD/SM   4.08  /dev/sdd   /dev/sg4 
[4:0:0:2]    disk    TEAC     USB   HS-MS Card 4.08  /dev/sde   /dev/sg5 
[4:0:0:3]    disk    TEAC     USB   HS-SD Card 4.08  /dev/sdf   /dev/sg6 
[6:0:0:0]    disk    Kingston DT 4000          PMAP  /dev/sdg   /dev/sg7 
[6:0:0:1]    cd/dvd  Kingston DT 4000          PMAP  /dev/sr1   /dev/sg8

Despite the encrypted partition being allocated /dev/sg7, the Kingston script cannot find the partition as shown by strace output below:

[root@giraffe linux32]# strace ./dt4000_about
execve("./dt4000_about", ["./dt4000_about"], [/* 47 vars */]) = 0
brk(0)                                  = 0x955b000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7777000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=151198, ...}) = 0
mmap2(NULL, 151198, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7752000
close(3)                                = 0
open("/usr/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0p]\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=136814, ...}) = 0
mmap2(NULL, 111276, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7736000
mmap2(0xb774e000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0xb774e000
mmap2(0xb7750000, 4780, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7750000
close(3)                                = 0
open("/usr/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260e\4\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=926216, ...}) = 0
mmap2(NULL, 955936, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb764c000
mprotect(0xb7729000, 4096, PROT_NONE)   = 0
mmap2(0xb772a000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xdd000) = 0xb772a000
mmap2(0xb772f000, 26144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb772f000
close(3)                                = 0
open("/usr/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\0F\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=280100, ...}) = 0
mmap2(NULL, 282784, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7606000
mmap2(0xb764a000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x43000) = 0xb764a000
close(3)                                = 0
open("/usr/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\240 \0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=108480, ...}) = 0
mmap2(NULL, 111572, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb75ea000
mmap2(0xb7605000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a000) = 0xb7605000
close(3)                                = 0
open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\0\233\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=2016129, ...}) = 0
mmap2(NULL, 1768004, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb743a000
mprotect(0xb75e3000, 4096, PROT_NONE)   = 0
mmap2(0xb75e4000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a9000) = 0xb75e4000
mmap2(0xb75e7000, 10820, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb75e7000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7439000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7438000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7438700, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xb75e4000, 8192, PROT_READ)   = 0
mprotect(0xb764a000, 4096, PROT_READ)   = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7437000
mprotect(0xb772a000, 16384, PROT_READ)  = 0
mprotect(0xb774e000, 4096, PROT_READ)   = 0
mprotect(0x8082000, 4096, PROT_READ)    = 0
mprotect(0xb7799000, 4096, PROT_READ)   = 0
munmap(0xb7752000, 151198)              = 0
set_tid_address(0xb7438768)             = 1401
set_robust_list(0xb7438770, 12)         = 0
rt_sigaction(SIGRTMIN, {0xb773b7f0, [], SA_SIGINFO}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0xb773b870, [], SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
uname({sys="Linux", node="giraffe", ...}) = 0
time(NULL)                              = 1393169089
brk(0)                                  = 0x955b000
brk(0x957c000)                          = 0x957c000
open("/dev/sg0", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\0\5\2[\0\0\0ATA     WDC WD3000HLFS-0"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg1", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\5\200\0052\213\0\0\0PBDS    DVD+-RW DH-16W1S"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg2", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\0\5\2[\0\0\0ATA     ST3500418AS     "...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg3", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-CF Card"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg4", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-xD/SM  "...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=6, info=0}) = 0
close(3)                                = 0
open("/dev/sg5", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-MS Card"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=4, info=0}) = 0
close(3)                                = 0
open("/dev/sg6", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-SD Card"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=3, info=0}) = 0
close(3)                                = 0
open("/dev/sg7", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\1\37\0\0\0KingstonDT 4000         "...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=3, info=0}) = 0
close(3)                                = 0
open("/dev/sg0", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\0\5\2[\0\0\0ATA     WDC WD3000HLFS-0"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg1", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\5\200\0052\213\0\0\0PBDS    DVD+-RW DH-16W1S"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg2", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\0\5\2[\0\0\0ATA     ST3500418AS     "...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=0, info=0}) = 0
close(3)                                = 0
open("/dev/sg3", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-CF Card"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=3, info=0}) = 0
close(3)                                = 0
open("/dev/sg4", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-xD/SM  "...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=4, info=0}) = 0
close(3)                                = 0
open("/dev/sg5", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-MS Card"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=3, info=0}) = 0
close(3)                                = 0
open("/dev/sg6", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\2 \0\0\0TEAC    USB   HS-SD Card"...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=8, duration=3, info=0}) = 0
close(3)                                = 0
open("/dev/sg7", O_RDWR)                = 3
ioctl(3, SG_IO, {'S', SG_DXFER_FROM_DEV, cmd[12]=[12, 00, 00, 00, 2c, 00, 00, 00, 00, 00, 00, 00], mx_sb_len=32, iovec_count=0, dxfer_len=44, timeout=10000, flags=0x3, data[44]=["\0\200\0\1\37\0\0\0KingstonDT 4000         "...], status=00, masked_status=00, sb[0]=[], host_status=0, driver_status=0, resid=0, duration=4, info=0}) = 0
close(3)                                = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 9), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7776000
write(1, "Can not detect DT4000 device !! "..., 33Can not detect DT4000 device !!
) = 33
exit_group(3)                           = ?
+++ exited with 3 +++

I can remove /dev/sg[0,1] and re-create the nodes as symbolic links to /dev/sg[7,8], and then the Kingston scripts correctly find the encrypted partition:

[root@giraffe linux32]# rm /dev/sg0
[root@giraffe linux32]# rm /dev/sg1
[root@giraffe linux32]# ln -s /dev/sg7 /dev/sg0
[root@giraffe linux32]# ln -s /dev/sg8 /dev/sg1
[steve@giraffe linux32]$ ./dt4000_about
DT4000 SN: 000FFEC511DCBCA0B00007D2
Firmware: 03.01.10
Application: 2.0.0.3

I tried to use udev rules to rename the device nodes when the USB memory is plugged in, but udev only allows renaming network interfaces so udevadm test warns me that it is not permitted to rename kernel devices.

Is there a way of instructing the kernel to use /dev/sg2 and above when the sg module is loaded, so that /dev/sg[0,1] are free to symlink using a udev rule when the Kingston USB memory is plugged in?

Thanks,
Steve

Offline

Board footer

Powered by FluxBB