LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-25-2012, 05:21 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
udev symbolically create link from sdf* to sdf


Hi, I have some usb devices that have several internal partitions (I believe is due to the internal software for additional hidden partitions). But I want the top layer, that is either sdf1 or sdg1 rather than sdf or sdg. I have attempted to write this rule into /etc/udev/rules.d/local.rules:
Code:
BUS="scsi", KERNEL="sdf*", SYMLINK+="sdf"
BUS="scsi", KERNEL="sdg*", SYMLINK+="sdg"
BUS="scsi", KERNEL="sdh*", SYMLINK+="sdh"
BUS="scsi", KERNEL="sdi*", SYMLINK+="sdi"
Code:
root:# tail -f /var/log/messages
Aug 26 05:48:50 vector kernel: [ 3045.169767] EXT3-fs (sdg): error: can't find ext3 filesystem on dev sdg.
Aug 26 05:48:50 vector kernel: [ 3045.182658] FAT-fs (sdg): Can't find a valid FAT filesystem
Aug 26 05:48:50 vector kernel: [ 3045.186768] FAT-fs (sdg): Can't find a valid FAT filesystem
Aug 26 05:49:31 vector kernel: [ 3086.114691] EXT3-fs (sdg): error: can't find ext3 filesystem on dev sdg.
Aug 26 05:49:31 vector kernel: [ 3086.126569] FAT-fs (sdg): Can't find a valid FAT filesystem
Aug 26 05:49:31 vector kernel: [ 3086.130580] FAT-fs (sdg): Can't find a valid FAT filesystem
Aug 26 05:52:30 vector sudo:     root : TTY=pts/0 ; PWD=/dev ; USER=root ; COMMAND=/bin/chmod 755 /etc/rc.d/rc.udev
Aug 26 05:53:49 vector kernel: [ 3343.992712] EXT3-fs (sdg): error: can't find ext3 filesystem on dev sdg.
Aug 26 05:53:49 vector kernel: [ 3344.005594] FAT-fs (sdg): Can't find a valid FAT filesystem
Aug 26 05:53:49 vector kernel: [ 3344.009592] FAT-fs (sdg): Can't find a valid FAT filesystem


Aug 26 06:04:16 vector kernel: [ 3971.204976] usb 1-3: USB disconnect, device number 6
Aug 26 06:04:40 vector kernel: [ 3994.473053] usb 1-3: new high speed USB device number 7 using ehci_hcd
Aug 26 06:04:40 vector kernel: [ 3994.587897] usb 1-3: New USB device found, idVendor=071b, idProduct=3203
Aug 26 06:04:40 vector kernel: [ 3994.587905] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Aug 26 06:04:40 vector kernel: [ 3994.587910] usb 1-3: Product: ROCK MP3
Aug 26 06:04:40 vector kernel: [ 3994.587914] usb 1-3: Manufacturer: RockChip
Aug 26 06:04:40 vector kernel: [ 3994.587917] usb 1-3: SerialNumber: USBV1.00
Aug 26 06:04:40 vector kernel: [ 3994.591361] usb-storage 1-3:1.0: Quirks match for vid 071b pid 3203: 80600
Aug 26 06:04:40 vector kernel: [ 3994.591431] scsi10 : usb-storage 1-3:1.0
Aug 26 06:04:41 vector kernel: [ 3995.597775] scsi 10:0:0:0: Direct-Access     RockChip USBDISK  User    1.00 PQ: 0 ANSI: 0
Aug 26 06:04:41 vector kernel: [ 3995.598291] sd 10:0:0:0: Attached scsi generic sg6 type 0
Aug 26 06:04:41 vector kernel: [ 3995.601448] scsi 10:0:0:1: Direct-Access     RockChip USBDISK    SD    1.00 PQ: 0 ANSI: 0
Aug 26 06:04:41 vector kernel: [ 3995.602808] sd 10:0:0:0: [sdf] 31944704 512-byte logical blocks: (16.3 GB/15.2 GiB)
Aug 26 06:04:41 vector kernel: [ 3995.602817] sd 10:0:0:0: [sdf] Assuming Write Enabled
Aug 26 06:04:41 vector kernel: [ 3995.604417] sd 10:0:0:1: Attached scsi generic sg7 type 0
Aug 26 06:04:41 vector kernel: [ 3995.604652] sd 10:0:0:0: [sdf] Assuming Write Enabled
Aug 26 06:04:41 vector kernel: [ 3995.605973]  sdf:
Aug 26 06:04:41 vector kernel: [ 3995.607793] sd 10:0:0:0: [sdf] Assuming Write Enabled
Aug 26 06:04:41 vector kernel: [ 3995.607806] sd 10:0:0:0: [sdf] Attached SCSI removable disk
Aug 26 06:04:41 vector kernel: [ 3995.609157] sd 10:0:0:1: [sdg] 8054784 512-byte logical blocks: (4.12 GB/3.84 GiB)
Aug 26 06:04:41 vector kernel: [ 3995.609166] sd 10:0:0:1: [sdg] Assuming Write Enabled
Aug 26 06:04:41 vector kernel: [ 3995.612140] sd 10:0:0:1: [sdg] Assuming Write Enabled
Aug 26 06:04:41 vector kernel: [ 3995.615434]  sdg: sdg1
Aug 26 06:04:41 vector kernel: [ 3995.617412] sd 10:0:0:1: [sdg] Assuming Write Enabled
Aug 26 06:04:41 vector kernel: [ 3995.617424] sd 10:0:0:1: [sdg] Attached SCSI removable disk
But I can't get it to work, in addition, is there other parameters that I can specify to make this more specific to the exact mp3 player?
Thanks,
Ted
 
Old 08-26-2012, 01:19 PM   #2
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Hi, I got udev to work finally, but now I am trying to customize the name in the dev rather than sdf, sdg...etc. I have the following in /etc/udev/rules.d/local.rules:
Code:
KERNEL=="sd*", SUBSYSTEM=="block", ATTR{size}=="7700432", ATTRS{vendor}=="Lexar   ", ATTRS{model}=="USB Flash Drive ", SYMLINK+="lexar"
KERNEL=="sd*", SUBSYSTEM=="block", ATTR{size}=="625137282", ATTRS{vendor}=="FUJITSU ", ATTRS{model}=="MHZ2320BH G2    ", SYMLINK+="fujitsu320g"
KERNEL=="sd*", SUBSYSTEM=="block", ATTR{size}=="976766976", ATTRS{vendor}=="Seagate ", ATTRS{model}=="Expansion       ", SYMLINK+="seagate500g"
KERNEL=="sd*", SUBSYSTEM=="block", ATTR{size}=="31944704", ATTRS{vendor}=="RockChip", ATTRS{model}=="USBDISK  User   ", SYMLINK+="mp3"
KERNEL=="sd*", SUBSYSTEM=="block", RUN+="/mnt/main/script/udev.sh %k"
The following is the error shows in syslog:
Code:
Aug 27 02:12:18 vector kernel: [   73.146245] sd 7:0:0:0: [sdf] No Caching mode page present
Aug 27 02:12:18 vector kernel: [   73.146252] sd 7:0:0:0: [sdf] Assuming drive cache: write through
Aug 27 02:12:19 vector udevd-work[2535]: exec of program '/mnt/main/script/udev.sh' failed 
Aug 27 02:12:19 vector udevd-work[2539]: exec of program '/mnt/main/script/udev.sh' failed 
Here is my script, I have tested it quite a few times and it gives the right response:
Code:
ted:$ cat /mnt/main/script/udev.sh
string="$1" ; name="${string:0:3}" ; number="${string:3}"
echo "$(date) $string" > "/mnt/main/report.log"
if [ -z "$number" ] && [ ! -e "/dev/${name}1" ] ; then
	mname="$name"
elif [ ! -e "/dev/${name:0:3}$((number+1))" ] ; then
	mname="${name:0:3}/${name:0:3}$number"
fi
if [ ! -z "$mname" ] ; then
	size=$(udevadm info -a -p /sys/block/$mname | grep "ATTR{size}==")
	size=$(echo "$size" | sed "s:\"::g")
	size=$(echo "$size" | sed "s:ATTR{size}==::g")
	if [ $size -lt 20000000 ] && [ $size != 0 ] ; then
		for each in "/dev/pendrive"* ; do
			max=$(echo "$each" | sed 's:/dev/pendrive::g')
		done
		if [ -z "$max" ] || [ "$max" == "*" ] ; then
			echo "pendrive"
		else
			echo "pendrive$((max+1))"
		fi
	fi
fivector:/~
This is the error log for the debug mode, I don't understand why, my code runs perfectly, but it keeps give me error feedback:
Code:
.052872 [7141] udev_node_mknod: set permissions /dev/sdg1, 060660, uid=0, gid=83
1346012453.053078 [7141] node_symlink: preserve already existing symlink '/dev/block/8:97' to '../sdg1'
1346012453.053220 [7141] link_update: creating link '/dev/disk/by-id/usb-USB_Mass_Storage_Device_812320090519-0:0-part1' to '/dev/sdg1'
1346012453.053284 [7141] node_symlink: creating symlink '/dev/disk/by-id/usb-USB_Mass_Storage_Device_812320090519-0:0-part1' to '../../sdg1'
1346012453.053414 [7141] link_update: creating link '/dev/disk/by-path/pci-0000:00:1d.7-usb-0:4:1.0-scsi-0:0:0:0-part1' to '/dev/sdg1'
1346012453.053474 [7141] node_symlink: creating symlink '/dev/disk/by-path/pci-0000:00:1d.7-usb-0:4:1.0-scsi-0:0:0:0-part1' to '../../sdg1'
1346012453.053577 [7141] link_update: creating link '/dev/disk/by-uuid/F84E-1690' to '/dev/sdg1'
1346012453.053705 [7141] node_symlink: creating symlink '/dev/disk/by-uuid/F84E-1690' to '../../sdg1'
1346012453.054098 [7141] udev_device_update_db: created db file '/dev/.udev/db/b8:97' for '/devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4:1.0/host20/target20:0:0/20:0:0:0/block/sdg/sdg1'
1346012453.054247 [7141] util_run_program: '/mnt/main/script/udev.sh sdg1' started
1346012453.058529 [7141] util_run_program: '/mnt/main/script/udev.sh' (stderr) '1346012453.058372 [7161] util_run_program: exec of program '/mnt/main/script/udev.sh' failed'
1346012453.059124 [7141] util_run_program: '/mnt/main/script/udev.sh sdg1' returned with exitcode 1
1346012453.059236 [7141] udev_watch_begin: adding watch on '/dev/sdg1'
1346012453.059748 [7141] udev_device_update_db: created db file '/dev/.udev/db/b8:97' for '/devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4:1.0/host20/target20:0:0/20:0:0:0/block/sdg/sdg1'
1346012453.059900 [7141] udev_monitor_send_device: passed -1 bytes to netlink monitor 0x80756a0
I made it write into report.log file to make sure it was ran, but no luck.
I am not sure how I can pass the kernel variable to my script.
Thanks,
Ted

Last edited by ted_chou12; 08-26-2012 at 03:26 PM.
 
Old 08-27-2012, 11:42 AM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
I guess no one has the idea,but I GOT it. I hope this helps someone someday somehow somewhere...anyway:
Code:
#!/bin/bash
string="$1" ; name="${string:0:3}" ; number="${string:3}"
if [ -z "$number" ] && [ ! -e "/dev/${name}1" ] ; then
	mname="$name"
elif [ ! -e "/dev/${name:0:3}$((number+1))" ] ; then
	mname="${name:0:3}/${name:0:3}$number"
fi
if [ ! -z "$mname" ] ; then
	size=$(/sbin/udevadm info -a -p /sys/block/$mname | /bin/grep "ATTR{size}==")
	size=$(echo "$size" | /bin/sed "s:\"::g")
	size=$(echo "$size" | /bin/sed "s:ATTR{size}==::g")
	if [ $size -lt 40000000 ] && [ $size != 0 ] ; then
		if [ ! -e "/dev/pendrive" ] ; then
			echo -n "pendrive"
		else
			i=1
			while [ -e "/dev/pendrive$i" ] ; do
				i=$((i+1))
			done
			echo -n "pendrive$i"
		fi
	fi
fi
I have no clue why shebang is so important here, cause I never added them in any of my scripts so far, in addition, adding absolute path to the function is for a additional measure to avoid errors.
in rules:
Code:
KERNEL=="sd*", SUBSYSTEM=="block", PROGRAM+="/mnt/main/script/udev.sh %k", NAME+="%c"
SYMLINK should work too, but i figure out Name looks better for me.
Ted
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting epoch time to human readable format SDF nano2 Programming 4 01-26-2012 04:15 AM
Question on Linux sdf BJT Linux - Newbie 1 08-15-2011 11:43 AM
SDF Public Access Unix Sytem Turns 20 schentor Linux - News 0 06-12-2007 02:29 PM
AC 97 SDF Modem with Smart CP compatible with Ubuntu Linux Dial up connection subrapatra Linux - Hardware 1 12-12-2006 02:10 AM
What language to talk to sdf database file ginda Programming 0 06-13-2006 04:03 AM


All times are GMT -5. The time now is 06:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration