#include <hallo.h>
David Kimdon wrote on Tue Feb 19, 2002 um 08:33:42PM:
> There is a note in choose_medium.c that indicates we are assuming this
> file ("/proc/sys/dev/cdrom/info") will not exist if there is no cdrom
> present. It appears as though we are wrong. I'll take a look at how
> to deal with this more gracefully than SIGSEGV.
Okay, I rewrote have_cdrom(), moving it to util.c and made other parts
that used the procfs file to trough have_cdrom first. Please test the
attached patch. I currently cannot because of the UTF8 trouble, and no
time to look how to fix it.
Gruss/Regards,
Eduard.
--
"Perfection is reached, not when is nothing more to add, but when
there is nothing more to take away." -- Antoine de Sainte Exupery.
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/choose_medium.c,v
retrieving revision 1.132
diff -u -r1.132 choose_medium.c
--- choose_medium.c 2002/02/07 04:00:25 1.132
+++ choose_medium.c 2002/02/20 22:12:55
@@ -664,44 +664,6 @@
}
-/*
- * "/proc/sys/dev/cdrom/info", on bittersweet, contains:
- * 8<------------------------------------------------->8
- * CD-ROM information, Id: cdrom.c 2.56 1999/09/09
- *
- * drive name: sr0 hdd
- * drive speed: 6 4
- * drive # of slots: 1 0
- * Can close tray: 1 1
- * Can open tray: 1 1
- * Can lock tray: 1 1
- * Can change speed: 1 1
- * Can select disk: 0 0
- * Can read multisession: 1 1
- * Can read MCN: 1 1
- * Reports media changed: 1 1
- * Can play audio: 1 1
- *
- *
- * 8<------------------------------------------------->8
- *
- * Note that there are actually tab characters in the file; I've
- * untabified so it stays lined up in this comment. I have verified
- * that this file does not exist on a machine with no CDROM attached.
- * - karlheg 2000.03.20
- * Linux bittersweet 2.2.14 #9 Fri Mar 17 00:50:19 PST 2000 i586 unknown
- */
-
-int
-have_cdrom ()
-{
- struct stat statbuf;
- int status;
- if ((status = stat("/proc/sys/dev/cdrom/info", &statbuf)) == 0)
- return 1;
- return 0;
-}
-
static
char *
get_cd_type_description (const char *dev)
@@ -755,7 +717,7 @@
/* Should be guaranteed on entry that the cd_info file exists - use have_cdrom() */
/* #### I get a warning here about assignment makes pointer from integer without a cast. Why?? */
- if ((cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) == NULL) {
+ if (have_cdrom() && (cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) == NULL) {
return; /* ¿ Shouldn't happen if I can stat it, right ? */
}
Index: reboot_system.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/reboot_system.c,v
retrieving revision 1.24
diff -u -r1.24 reboot_system.c
--- reboot_system.c 2001/12/21 07:54:45 1.24
+++ reboot_system.c 2002/02/20 22:12:55
@@ -33,7 +33,7 @@
char *p_line,*line = NULL;
size_t line_size = 0;
char bootmagic='\0';
- if ((cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) != NULL)
+ if (have_cdrom() && (cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) != NULL)
{
/* successfull, continuing */
Index: util.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/util.c,v
retrieving revision 1.69
diff -u -r1.69 util.c
--- util.c 2002/02/10 19:30:14 1.69
+++ util.c 2002/02/20 22:12:59
@@ -1115,5 +1115,52 @@
}
+/*
+ * "/proc/sys/dev/cdrom/info", on bittersweet, contains:
+ * 8<------------------------------------------------->8
+ * CD-ROM information, Id: cdrom.c 2.56 1999/09/09
+ *
+ * drive name: sr0 hdd
+ * drive speed: 6 4
+ * drive # of slots: 1 0
+ * Can close tray: 1 1
+ * Can open tray: 1 1
+ * Can lock tray: 1 1
+ * Can change speed: 1 1
+ * Can select disk: 0 0
+ * Can read multisession: 1 1
+ * Can read MCN: 1 1
+ * Reports media changed: 1 1
+ * Can play audio: 1 1
+ *
+ *
+ * 8<------------------------------------------------->8
+ *
+ * Note that there are actually tab characters in the file; I've
+ * untabified so it stays lined up in this comment. I have verified
+ * that this file does not exist on a machine with no CDROM attached.
+ * - karlheg 2000.03.20
+ * Linux bittersweet 2.2.14 #9 Fri Mar 17 00:50:19 PST 2000 i586 unknown
+ */
+int
+have_cdrom ()
+{
+ FILE *cd_info;
+ char *line = NULL;
+ size_t line_size = 0;
+ if ((cd_info = fopen ("/proc/sys/dev/cdrom/info", "r")) != NULL) {
+ /* Read the file and build a list of available CD devices. */
+ getline (&line, &line_size, cd_info);
+ getline (&line, &line_size, cd_info);
+ getline (&line, &line_size, cd_info);
+ if(strstr(line, " ") != NULL) {
+ /* leading spaces exist so the device names must follow in the line */
+ fclose(cd_info);
+ return 1;
+ }
+ fclose(cd_info);
+ }
+ return 0;
+}
Index: util.h
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/util.h,v
retrieving revision 1.26
diff -u -r1.26 util.h
--- util.h 2001/12/20 07:36:17 1.26
+++ util.h 2002/02/20 22:13:00
@@ -173,6 +173,9 @@
*/
extern int is_cdrom_image(void);
+/* Looks in the procfs whetever a cdrom drive does exist (1) or not (0) */
+extern int have_cdrom(void);
+
/* Is the partition on an NFS mountpoint? */
int is_nfs_partition(const char *);
Attachment:
pgpYmhA5FVHs6.pgp
Description: PGP signature