Imported Upstream version 24.0
[rrq/maintain_lilo.git] / src / geometry.c
index 006dcc07f7d20f8a4da3d36d60405855c380651e..37db4552a1452af033b729facf5a32af759ef363 100644 (file)
@@ -1,14 +1,13 @@
-/* geometry.c  -  Device and file geometry computation */
-/*
-Copyright 1992-1998 Werner Almesberger.
-Copyright 1999-2005 John Coffman.
-All rights reserved.
-
-Licensed under the terms contained in the file 'COPYING' in the 
-source directory.
-
-*/
-/* Patched for linux-2.4.0 - Glibc-2.2 by Sergey Ostrovsky 11/16/2000 */
+/* geometry.c  -  Device and file geometry computation
+ * 
+ * Copyright 1992-1998 Werner Almesberger
+ * Copyright 1999-2005 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>
@@ -64,7 +63,7 @@ source directory.
  /* (*(__u32 *)"R4Sb"); */
 #endif
 #ifndef REISER4_IOC_UNPACK
-#define REISER4_IOC_UNPACK              _IOW(0xCD,1,long)
+#define REISER4_IOC_UNPACK      _IOW(0xCD,1,long)
 #endif
 #endif
 
@@ -172,7 +171,7 @@ void geo_init(char *name)
            if (strspn(line," \t") != strlen(line)) {
                entry = alloc_t(DT_ENTRY);
                items = sscanf(line,"0x%x 0x%x %d %d %d %d",&entry->device,
-                 &entry->bios,&entry->sectors,&entry->heads,&entry->cylinders,
+                 (unsigned int*)&entry->bios,&entry->sectors,&entry->heads,&entry->cylinders,
                  &entry->start);
                if (items == 5) entry->start = -1;
                if (items < 5)
@@ -298,10 +297,11 @@ int has_partitions_beta(dev_t dev)
       (major >= MAJOR_SMART2 && major <= MAJOR_SMART2+7) ||
       (major >= MAJOR_CISS && major <= MAJOR_CISS+7) ||
       major == MAJOR_FTL || major == MAJOR_NFTL || major == MAJOR_DOC ||
-      (major >= MAJOR_SD9 && major <= MAJOR_SD16)
+      (major >= MAJOR_SD9 && major <= MAJOR_SD16) ||
+      (major >= MAJOR_SATA1 && major <= MAJOR_SATA2)
         ) return 0xFFFFFFF0;   /* 4 bit partition mask */
 
-    if ( major == MAJOR_SATA || major == MAJOR_SATA2
+    if ( major == MAJOR_CARM1 || major == MAJOR_CARM2
         )  return 0xFFFFFFE0;  /* 5 bit partition mask */
 
     if ( major == MAJOR_IBM_iSER ||
@@ -394,13 +394,13 @@ void do_disk(void)
     maxpart = cfg_get_strg(cf_disk,"max-partitions");
     if (maxpart) {
       if (major<nelem(max_partno)) {
-       int i = to_number(maxpart);
-       if (max_partno[major] && max_partno[major]!=i) die("Cannot alter 'max-partitions' for known disk  %s", disk);
-       max_partno[major] = i;
-       if (i!=7 && i!=15 && i!=31 && i!=63) die("disk=%s:  illegal value for max-partitions(%d)", disk, i);
+        int i = to_number(maxpart);
+          if (max_partno[major] && max_partno[major]!=i) die("Cannot alter 'max-partitions' for known disk  %s", disk);
+          max_partno[major] = i;
+          if (i!=7 && i!=15 && i!=31 && i!=63 && i!=128) die("disk=%s:  illegal value for max-partitions(%d)", disk, i);
       }
       else {
-        die("Implementation restriction: max-partitions on major device > %d", nelem(max_partno)-1);
+        die("Implementation restriction: max-partitions on major device > %d", (int)nelem(max_partno)-1);
       }
     }
     entry->bios = bios ? to_number(bios) : -1;
@@ -492,21 +492,17 @@ static int scan_last_dev(ST_BUF *next,char *parent,int major,int increment)
 static int last_dev(int major,int increment)
 {
 /*
- * In version 12 to 18, LILO only relied on scan_last_dev (or last_dev). This
- * obviously didn't work if entries in /dev were missing. Versions 18 and 19
- * added the probe loop, which seems to be okay, but which may probe for
- * invalid minor numbers. The IDE driver objects to that. Since last_dev is
- * only used to count IDE drives anyway, we try now only the first two devices
- * and forget about scan_last_dev.
+ * Since last_dev is only used to count IDE drives anyway, we try 
+ * now only the first two devices and forget about scan_last_dev.
  */
+    DEVICE dev;
+    int devs;
     static int cached_major=-1, cached_increment=-1, cached_result=-1;
     if(major == cached_major && increment == cached_increment)
         return cached_result;
     cached_major = major;
     cached_increment = increment;
 
-    DEVICE dev;
-    int devs;
 
     for (devs = 0;
        devs < 2 && dev_open(&dev,MKDEV(major,increment*devs),O_BYPASS);
@@ -547,7 +543,7 @@ void lvm_bmap(struct lv_bmap *lbm)
 
        lvmfd = dev_open(&dev, lbm->lv_dev, O_RDONLY);
        if (lvmfd < 0)
-           die("can't open LVM block device %#x\n", lbm->lv_dev);
+           die("can't open LVM block device %#x\n", (int)lbm->lv_dev);
        last_dev = lbm->lv_dev;
     }
     if (ioctl(lvmfd, LV_BMAP, lbm) < 0) {
@@ -610,13 +606,9 @@ void geo_query_dev(GEOMETRY *geo,int device,int all)
     struct hd_geometry hdprm;
 
     if (verbose>=5) printf("geo_query_dev: device=%04X\n", device);
-#if 0
-/*  Werner's original */
-    get_all = all || MAJOR(device) != MAJOR_FD; */
-#else
-/* simplify the condition -- JRC 2003-06-04 */
+    /* simplified condition -- JRC 2003-06-04 */
     get_all = all;
-#endif
+
     if (!MAJOR(device))
        die("Trying to map files from unnamed device 0x%04x (NFS/RAID mirror down ?)",device);
     if (device == MAJMIN_RAM)
@@ -692,6 +684,14 @@ void geo_query_dev(GEOMETRY *geo,int device,int all)
            geo->sectors = hdprm.sectors;
            geo->start = hdprm.start;
            break;
+       case MAJOR_SATA1:
+       case MAJOR_SATA2:
+               printf("WARNING: SATA partition in the high region (>15):\n");
+               printf("LILO needs the kernel in one of the first 15 SATA partitions. If \n");
+               printf("you need support for kernel in SATA partitions of the high region \n");
+               printf("than try grub2 for this purpose! \n");
+               die("Sorry, cannot handle device 0x%04x",device);
+           break;
        MASK31:
            geo->device = 0x80 + last_dev(MAJOR_HD,64) + (MINOR(device) >> 5);
            if (!get_all) break;
@@ -785,7 +785,7 @@ void geo_query_dev(GEOMETRY *geo,int device,int all)
            
            if ((MAJOR(device)>=120 && MAJOR(device)<=127)  ||
                (MAJOR(device)>=240 && MAJOR(device)<=254) )
-               die("Linux experimental device 0x04x needs to be defined.\n"
+               die("Linux experimental device 0x%04x needs to be defined.\n"
                    "Check 'man lilo.conf' under 'disk=' and 'max-partitions='", device);
            else die("Sorry, don't know how to handle device 0x%04x",device);
     }
@@ -1282,7 +1282,7 @@ int pass;
 } /* end of geo_get */
 
 
-int geo_open(GEOMETRY *geo,char *name,int flags)
+int geo_open(GEOMETRY *geo,const char *name,int flags)
 {
     char *here;
     int user_dev,block_size;
@@ -1480,7 +1480,7 @@ int geo_comp_addr(GEOMETRY *geo,int offset,SECTOR_ADDR *addr)
                    break;
            if (!dm_target)
                die("device-mapper: Sector outside mapped device? (%d: %u/%"PRIu64")",
-                   geo->base_dev, sector, (uint64_t)(dm_table->target ?
+                   (int) geo->base_dev, sector, (uint64_t)(dm_table->target ?
                      (dm_table->target->start+dm_table->target->length) : 0));
 
            dev = dm_target->device;