Imported Upstream version 24.0
[rrq/maintain_lilo.git] / src / device.c
index fb7a9f77d50c413501d4eb0eb85cd50d6a12a745..93d3039a13ab153c366ce31b22afe69826870e20 100644 (file)
@@ -1,13 +1,13 @@
-/* device.c  -  Device access */
-/*
-Copyright 1992-1997 Werner Almesberger.
-Copyright 1999-2006 John Coffman.
-All rights reserved.
-
-Licensed under the terms contained in the file 'COPYING' in the 
-source directory.
-
-*/
+/* device.c  -  Device access
+ * 
+ * Copyright 1992-1997 Werner Almesberger
+ * Copyright 1999-2006 John Coffman
+ * Copyright 2009-2011 Joachim Wiedorn
+ * All rights reserved.
+ * 
+ * Licensed under the terms contained in the file 'COPYING'
+ * in the source directory.
+ */
 
 #define _GNU_SOURCE
 #include <unistd.h>
@@ -197,6 +197,7 @@ int dev_open(DEVICE *dev,int number,int flags)
     char name[PATH_MAX];
     ST_BUF st;
     int count;
+    int err;
 
     if (lookup_dev(name,dev,number)) dev->delete = 0;
     else {
@@ -235,11 +236,12 @@ int dev_open(DEVICE *dev,int number,int flags)
 #endif
     if (flags == O_BYPASS) dev->fd = -1;
     else if ((dev->fd = open(name,flags)) < 0) {
-            fprintf (errstd, "Cannot proceed. Maybe you need to add "
+        err = errno;
+        fprintf (errstd, "Cannot proceed. Maybe you need to add "
                         "this to your lilo.conf:\n"
                          "\tdisk=%s inaccessible\n"
                         "(real error shown below)\n", name);
-           die("open %s: %s",name,strerror(errno));
+           die("open %s: %s",name,strerror(err));
     }
     dev->name = stralloc(name);
     return dev->fd;
@@ -639,7 +641,7 @@ unsigned int register_bios(int bios, int device)
 
                *(int*)&buff.sector[PART_TABLE_OFFSET-6] = serial;
                if (*(short*)&buff.sector[PART_TABLE_OFFSET - 2] == 0)
-                   *(short*)&buff.sector[PART_TABLE_OFFSET - 2] = MAGIC_SERIAL;
+                   *(unsigned short*)&buff.sector[PART_TABLE_OFFSET - 2] = MAGIC_SERIAL;
                if (verbose)
                    printf("Assigning new Volume ID to (%04X) '%s'  ID = %08X\n",
                                        device, dev.name, (int)serial);
@@ -655,7 +657,7 @@ unsigned int register_bios(int bios, int device)
                if (device_code[i]==device)
                    die("register_bios: device code duplicated: %04X", device);
                if (serial_no[i]==serial)
-                   die("register_bios: volume ID serial no. duplicated: %08lX", serial);
+                   die("register_bios: volume ID serial no. duplicated: %08X", serial);
            }
            device_code[bios] = device;
            serial_no[bios] = serial;
@@ -714,11 +716,11 @@ static int volid_get_set(int device, int vol_in, int option)
        
     fd = dev_open(&dev, device, option ? O_RDWR : O_RDONLY);
     if (read(fd, &buf, sizeof(buf)) != sizeof(buf)) {
-       fprintf (errstd, "Cannot proceed. Maybe you need to add "
+      fprintf (errstd, "Cannot proceed. Maybe you need to add "
                         "this to your lilo.conf:\n"
                          "\tdisk=%s inaccessible\n"
                         "(real error shown below)\n", dev.name);
-       die("VolumeID read error: sector 0 of %s not readable", dev.name);
+      die("VolumeID read error: sector 0 of %s not readable", dev.name);
     }
     if (option==ID_SET) {
        make_backup(NULL, 0, &buf, device,