Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 104683 - Hdparm does not set CD/DVD drive parameters if disc not inserted
Summary: Hdparm does not set CD/DVD drive parameters if disc not inserted
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 105018 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-09-03 02:17 UTC by Antti Mäkelä
Modified: 2006-03-09 16:59 UTC (History)
9 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch (hdparm-init-7.diff,617 bytes, patch)
2006-03-09 06:48 UTC, Matthias Foerste
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Mäkelä 2005-09-03 02:17:20 UTC
Setting up hdparm (DMA, UDMA mode, multicount etc) modes with the initscript
fails if configuring an empty CD/DVD drive. The problem stems from this check at
the end of the /etc/init.d/hdparm:

(Using the non-devfs since udev068 has gotten rid of devfs compatibility)

                # non-devfs compatible system
                for device in /dev/hd?
                do
                        # check that the block device really exists
                        # by opening it for reading
                        if [ -b $device ] && ( : <$device ) 2>/dev/null
                        then
                                eval args=\${`basename $device`_args}
                                do_hdparm
                        fi
                done

When addressing a DVD drive the test fails, and the do_hdparm is never executed.
I can set the hdparm parameters manually just fine, but due to this test the
setting up does not work during bootup. 

When accessing a CD/DVD drive without media in, "cat" produces this error
# cat /dev/hdc
cat: /dev/hdc: No medium found

  Suggested fix: Replace the test with something a bit more robust or remove it
entirely.
Comment 1 Joseph Roback 2005-09-06 03:35:28 UTC
Yes, I experience the same problem. udev-068 and hdparm-5.9 
Comment 2 Jakub Moc (RETIRED) gentoo-dev 2005-09-06 07:26:59 UTC
*** Bug 105018 has been marked as a duplicate of this bug. ***
Comment 3 Rodney Gordon II 2005-10-27 23:08:31 UTC
This is still a problem, any fix anytime soon?
Comment 4 SpanKY gentoo-dev 2005-10-28 16:28:21 UTC
heaven forbid you suggest a fix rather than just complain someone else hasnt
done it yet

how does this work for people:
-  if [ -b $device ] && ( : <$device ) 2>/dev/null
+  errmsg=$(head -c 1 $device 2>&1)
+  if [[ -b $device ]] && [[ $? == 0 || ${errmsg} == *: No medium found ]]
Comment 5 Rodney Gordon II 2005-10-28 16:39:58 UTC
I wasn't complaining, just wondering.. Your insulting reply wasn't very
warranted anyways.

For a fix, I have just been commenting out the check. If you really need me to
generate a patch of commenting out a few lines, sure.. But there is probably a
more elegant way to fix this.

This bug has been lingering here for a month and nothing has been changed, just
giving a "heads up".. Nice to see one of my first posts here was replied to like
this...
Comment 6 Stefan Illner 2005-10-31 01:26:20 UTC
(In reply to comment #4)

> how does this work for people:
> -  if [ -b $device ] && ( : <$device ) 2>/dev/null
> +  errmsg=$(head -c 1 $device 2>&1)
> +  if [[ -b $device ]] && [[ $? == 0 || ${errmsg} == *: No medium found ]]

Taking this approach, you should probably unset LANG/LC_* or whatever affects
the output language, because otherwise on a german system this will fail because
the message is 'Kein Medium gefunden'. (Not sure whether the language settings
are active during execution of boot-scripts per default, but someone might have
done so individually.)
Comment 7 Heiko Baums 2005-12-09 14:33:14 UTC
This version works at least for me: 
 
-  if [ -b $device ] && ( : <$device ) 2>/dev/null 
+ errmsg=$(: <$device 2>&1) 
+ if [[ -b $device ]] && [[ $? == 0 || $(errmsg) == "*: No medium found" ]] 
 
The language should not be a problem, at least for now, because also with 
LC_MESSAGES=de_DE `: <$device 2` gives the English error message. 
 
There's only one defective appearance. 
If there's no medium in the drive the line "errmsg=$(: <$device 2>&1)" prints 
the error message "/etc/init.d/hdparm: line 125: /dev/hdc: No medium found" on 
the screen. The hdparm settings are done for this drive anyhow. 
Comment 8 Heiko Baums 2005-12-09 14:35:49 UTC
Forgot to say that line 125 in the error message could also be 124 because I 
didn't delete the original line in my script but just commented it out. ;-) 
Comment 9 Heiko Baums 2005-12-11 16:33:17 UTC
Now I found the solution without having the error message printed on the 
screen: 
 
- if [ -b $device ] && ( : <$device ) 2>/dev/null 
+ errmsg=$( : 2>/dev/null <$device ) 
+ if [[ -b $device ]] && [[ $? == 0 || $(errmsg) == "*: No medium found" ]] 
 
This works as long as the dummy command : only gives English error messages 
regardless of the LC_MESSAGES value. 
Comment 10 SpanKY gentoo-dev 2005-12-28 12:49:26 UTC
thanks Heiko and Stefan for actual testing / feedback ... should be fixed with hdparm-6.3 now
Comment 11 SpanKY gentoo-dev 2006-02-14 08:05:34 UTC
*** Bug 69284 has been marked as a duplicate of this bug. ***
Comment 12 Matthias Foerste 2006-03-09 06:42:22 UTC
latest fix causes annoying error messages and red question marks for me when it tries to run hdparm on nonexistant devices (/dev/hdd - /dev/hdh) while booting. 

this applied to the current init script works for me:

-			local errmsg=$( : 2>/dev/null <$device )
-			if [[ -b $device ]] && [[ $? == 0 || $(errmsg) == "*: No medium found" ]]
+			local errmsg status
+			errmsg=$( : 2>&1 <$device )
+			status=$?
+			if [[ -b $device ]] && [[ ${status} == 0 || ${errmsg:$((-25))} == "${device}: No medium found" ]]

i noticed because i remerged hdparm (5.9) some days ago. maybe the test should be removed entirely as already suggested here and in another bugreport.
Comment 13 Matthias Foerste 2006-03-09 06:48:09 UTC
Created attachment 81767 [details, diff]
patch

linebreak issues in previous comment
Comment 14 SpanKY gentoo-dev 2006-03-09 16:59:03 UTC
> latest fix causes annoying error messages and red question marks for me when it
> tries to run hdparm on nonexistant devices (/dev/hdd - /dev/hdh) while booting. 

file a new bug in the future

> maybe the test should be removed entirely as already suggested here and in
> another bugreport.

no

applied your fixes to current init.d script