Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 33873
Collapse All | Expand All

(-)lilo-22.5.8/Makefile (-1 / +7 lines)
Lines 53-59 Link Here
53
#   XL_SECS=n	  Support for extra large (non-standard) floppies.
53
#   XL_SECS=n	  Support for extra large (non-standard) floppies.
54
54
55
CONFIG=-DBDATA -DDSECS=3 -DEVMS -DIGNORECASE -DLVM -DONE_SHOT -DPASS160 \
55
CONFIG=-DBDATA -DDSECS=3 -DEVMS -DIGNORECASE -DLVM -DONE_SHOT -DPASS160 \
56
   -DREISERFS -DREWRITE_TABLE -DSOLO_CHAIN -DVERSION -DVIRTUAL
56
   -DREISERFS -DREWRITE_TABLE -DSOLO_CHAIN -DVERSION -DVIRTUAL -DDEVMAPPER
57
57
58
# set the compiler optimization level
58
# set the compiler optimization level
59
59
Lines 88-93 Link Here
88
LDFLAGS=#-Xlinker -qmagic
88
LDFLAGS=#-Xlinker -qmagic
89
LIBS=
89
LIBS=
90
90
91
DEVMAPPER=-ldevmapper
92
91
OBJS=lilo.o raid.o map.o geometry.o boot.o device.o common.o bsect.o cfg.o \
93
OBJS=lilo.o raid.o map.o geometry.o boot.o device.o common.o bsect.o cfg.o \
92
  temp.o partition.o identify.o probe.o shs2.o loader.o edit.o
94
  temp.o partition.o identify.o probe.o shs2.o loader.o edit.o
93
95
Lines 241-247 Link Here
241
		cp -p dparam.S dparam.s
243
		cp -p dparam.S dparam.s
242
244
243
lilo:		$(OBJS)
245
lilo:		$(OBJS)
246
ifneq (,$(findstring DEVMAPPER,$(CONFIG)))
247
		$(CC) -o lilo $(LDFLAGS) $(DEVMAPPER) $(OBJS) $(LIBS)
248
else
244
		$(CC) -o lilo $(LDFLAGS) $(OBJS) $(LIBS)
249
		$(CC) -o lilo $(LDFLAGS) $(OBJS) $(LIBS)
250
endif
245
251
246
boot-text.b:	first.b second.b
252
boot-text.b:	first.b second.b
247
		(dd if=first.b bs=512 conv=sync; dd if=second.b) >boot-text.b
253
		(dd if=first.b bs=512 conv=sync; dd if=second.b) >boot-text.b
(-)lilo-22.5.8/geometry.c (-27 / +290 lines)
Lines 14-19 Link Here
14
#include <stdio.h>
14
#include <stdio.h>
15
#include <fcntl.h>
15
#include <fcntl.h>
16
#include <errno.h>
16
#include <errno.h>
17
#include <stdlib.h>
18
#include <limits.h>
19
#include <ctype.h>
17
#include <sys/types.h>
20
#include <sys/types.h>
18
21
19
#ifdef LCF_REISERFS
22
#ifdef LCF_REISERFS
Lines 26-31 Link Here
26
29
27
#include <string.h>
30
#include <string.h>
28
31
32
#ifdef LCF_DEVMAPPER
33
#include <libdevmapper.h>
34
#endif
35
29
#include "config.h"
36
#include "config.h"
30
#include "lilo.h"
37
#include "lilo.h"
31
#include "common.h"
38
#include "common.h"
Lines 60-65 Link Here
60
#endif
67
#endif
61
#endif
68
#endif
62
69
70
#ifdef LCF_DEVMAPPER
71
typedef struct _dm_target {
72
    struct _dm_target *next;
73
    uint64_t start,length,offset;
74
    int device;
75
} DM_TARGET;
76
77
typedef struct _dm_table {
78
    struct _dm_table *next;
79
    int device;
80
    struct _dm_target *target;
81
} DM_TABLE;
82
83
int dm_version_nr = 0;
84
int dm_major_list[16];
85
int dm_major_nr = 0;
86
DM_TABLE *dmtab = NULL;
87
#endif
88
63
#ifdef LCF_LVM
89
#ifdef LCF_LVM
64
struct lv_bmap {
90
struct lv_bmap {
65
    __u32 lv_block;
91
    __u32 lv_block;
Lines 114-119 Link Here
114
{
140
{
115
    FILE *file;
141
    FILE *file;
116
    char line[MAX_LINE+1];
142
    char line[MAX_LINE+1];
143
#ifdef LCF_DEVMAPPER
144
    struct dm_task *dmt;
145
    char major_name[32];
146
    char dm_version[32];
147
    int major;
148
#endif
117
    char *here;
149
    char *here;
118
    DT_ENTRY *entry;
150
    DT_ENTRY *entry;
119
    int disk_section,items;
151
    int disk_section,items;
Lines 122-150 Link Here
122
	if ((file = fopen(name,"r")) == NULL)
154
	if ((file = fopen(name,"r")) == NULL)
123
	    die("open %s: %s",name,strerror(errno));
155
	    die("open %s: %s",name,strerror(errno));
124
    }
156
    }
125
    else if ((file = fopen(DFL_DISKTAB,"r")) == NULL) return;
157
    if (name || (file = fopen(DFL_DISKTAB,"r")) != NULL) {
126
    disk_section = !!disktab;
158
	disk_section = !!disktab;
127
    while (fgets(line,MAX_LINE,file)) {
159
	while (fgets(line,MAX_LINE,file)) {
128
	here = strchr(line,'\n');
160
	    here = strchr(line,'\n');
129
	if (here) *here = 0;
161
	    if (here) *here = 0;
130
	here = strchr(line,'#');
162
	    here = strchr(line,'#');
131
	if (here) *here = 0;
163
	    if (here) *here = 0;
132
	if (strspn(line," \t") != strlen(line)) {
164
	    if (strspn(line," \t") != strlen(line)) {
133
	    entry = alloc_t(DT_ENTRY);
165
		entry = alloc_t(DT_ENTRY);
134
	    items = sscanf(line,"0x%x 0x%x %d %d %d %d",&entry->device,
166
		items = sscanf(line,"0x%x 0x%x %d %d %d %d",&entry->device,
135
	      &entry->bios,&entry->sectors,&entry->heads,&entry->cylinders,
167
		  &entry->bios,&entry->sectors,&entry->heads,&entry->cylinders,
136
	      &entry->start);
168
		  &entry->start);
137
	    if (items == 5) entry->start = -1;
169
		if (items == 5) entry->start = -1;
138
	    if (items < 5)
170
		if (items < 5)
139
		die("Invalid line in %s:\n\"%s\"",name ? name : DFL_DISKTAB,
171
		    die("Invalid line in %s:\n\"%s\"",name ? name : DFL_DISKTAB,
140
		  line);
172
		      line);
141
	    entry->next = disktab;
173
		entry->next = disktab;
142
	    disktab = entry;
174
		disktab = entry;
143
	    if (disk_section) die("DISKTAB and DISK are mutually exclusive");
175
		if (disk_section) die("DISKTAB and DISK are mutually exclusive");
144
	    old_disktab = 1;
176
		old_disktab = 1;
177
	    }
145
	}
178
	}
179
	(void) fclose(file);
146
    }
180
    }
181
182
#ifdef LCF_DEVMAPPER
183
    if (!(dmt = dm_task_create(DM_DEVICE_VERSION)))
184
	return;
185
    if (!dm_task_run(dmt))
186
	return;
187
    if (!dm_task_get_driver_version(dmt, dm_version, sizeof dm_version))
188
	return;
189
190
    /*
191
     * to not confuse returned device number formats %02x:%02x and %d:%d
192
     * we assume here that the %02x:%02x format is only found in the ioctl
193
     * interface version < 4 (this is really getting ugly...)
194
     */
195
    dm_version_nr = atoi(dm_version);
196
197
    dm_task_destroy(dmt);
198
199
    dm_major_nr = 0;
200
    file = fopen("/proc/devices", "r");
201
    if (!file) return;
202
203
    do {
204
	if (!fgets(line, (sizeof line)-1, file)) {
205
	    (void) fclose(file);
206
	    return;
207
	}
208
	line[(sizeof line)-1] = 0;
209
    } while(strncmp(line, "Block", 5) != 0);
210
211
    while(fgets(line, (sizeof line)-1, file)) {
212
	if (sscanf(line, "%d %31s\n", &major, major_name) != 2) continue;
213
	if (strcmp(major_name, "device-mapper") != 0) continue;
214
	dm_major_list[dm_major_nr] = major;
215
	if (++dm_major_nr > (sizeof dm_major_list)/(sizeof dm_major_list[0])) break;
216
    }
217
147
    (void) fclose(file);
218
    (void) fclose(file);
219
#endif
148
}
220
}
149
221
150
222
Lines 768-773 Link Here
768
{
840
{
769
    DT_ENTRY *walk;
841
    DT_ENTRY *walk;
770
    int inherited,keep_cyls,is_raid=0;
842
    int inherited,keep_cyls,is_raid=0;
843
#ifdef LCF_DEVMAPPER
844
    int i;
845
846
    for(i = 0; i < dm_major_nr; i++)
847
	if (MAJOR(device) == dm_major_list[i])
848
	    break;
849
    while (i < dm_major_nr) {
850
	DM_TABLE *dm_table;
851
852
	for(dm_table = dmtab; dm_table; dm_table = dm_table->next)
853
	    if (dm_table->device == device)
854
		break;
855
856
	if (dm_table) {
857
	    DM_TARGET *target;
858
859
	     device = 0;
860
	    for(target = dm_table->target; target; target = target->next)
861
		device = target->device;
862
	} else {
863
	    DEVICE dev;
864
	    struct dm_task *dmt;
865
	    void *next = NULL;
866
	    char dmdev[PATH_MAX+1];
867
	    char buf[PATH_MAX+1];
868
	    char *slash;
869
	    int result;
870
871
	    dev_open(&dev, device, -1);
872
	    strncpy(dmdev, dev.name, PATH_MAX);
873
	    dmdev[PATH_MAX] = 0;
874
	    do {
875
		if ((result = readlink(dmdev, buf, PATH_MAX)) < 0 && errno != EINVAL)
876
		    die("device-mapper: readlink(\"%s\") failed with: %s",buf,
877
			strerror(errno));
878
		if (result >= 0) {
879
		    buf[PATH_MAX] = 0;
880
		    if (buf[0] != '/' && (slash = strrchr(dmdev, '/')) != NULL)
881
			slash++;
882
		    else
883
			slash = dmdev;
884
		    strncpy(slash, buf, PATH_MAX - (slash-dmdev));
885
		}
886
		if (realpath(dmdev, buf) == NULL)
887
		    die("device-mapper: realpath(\"%s\") failed with: %s",dmdev,
888
			strerror(errno));
889
		strncpy(dmdev, buf, PATH_MAX);
890
	    } while (result >= 0);
891
	    dmdev[PATH_MAX] = 0;
892
893
	    if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
894
		die("device-mapper: dm_task_create(DM_DEVICE_TABLE) failed");
895
	    slash = strrchr(dmdev, '/');
896
		if (slash)
897
	    slash++;
898
		else
899
	    slash = dmdev;
900
	    if (!dm_task_set_name(dmt, slash))
901
		die("device-mapper: dm_task_set_name(\"%s\") failed",dmdev);
902
	    if (!dm_task_run(dmt))
903
		die("device-mapper: dm_task_run(DM_DEVICE_TABLE) failed");
904
905
	    dm_table = alloc_t(DM_TABLE);
906
	    dm_table->device = device;
907
	    dm_table->target = NULL;
908
	    dm_table->next = dmtab;
909
	    dmtab = dm_table;
910
911
	    device = 0;
912
913
	    do {
914
		DM_TARGET *target;
915
		uint64_t start,length;
916
		int major,minor;
917
		char *target_type,*params;
918
		char *p;
919
920
		next = dm_get_next_target(dmt, next, &start, &length,
921
		  &target_type, &params);
922
923
		if (!target_type) continue;
924
925
		if (strcmp(target_type, "linear") != 0)
926
		    die("device-mapper: only linear boot device supported");
927
928
		target = alloc_t(DM_TARGET);
929
		target->start = start;
930
		target->length = length;
931
		if (dm_version_nr < 4 &&
932
		    isxdigit(params[0]) &&
933
		    isxdigit(params[1]) &&
934
		    params[2] == ':' &&
935
		    isxdigit(params[3]) &&
936
		    isxdigit(params[4])) { /* old 2.4 format */
937
		    if (sscanf(params, "%02x:%02x %"PRIu64, &major, &minor, &target->offset) != 3)
938
			die("device-mapper: parse error in linear params (\"%s\")", params);
939
		} else if (isdigit(params[0]) &&
940
			   strchr(params, ':')) { /* dm_bdevname/format_dev_t (>= 2.6.0-test4?) format */
941
		    if (sscanf(params, "%u:%u %"PRIu64, &major, &minor, &target->offset) != 3)
942
			die("device-mapper: parse error in linear params (\"%s\")", params);
943
		} else { /* >= 2.5.69 format, this should go away soon */
944
		    struct stat st;
945
		    FILE *file;
946
947
		    p = strrchr(params, ' ');
948
		    if (p == NULL)
949
			die("device-mapper: parse error in linear params (\"%s\")", params);
950
		    *p = 0;
951
		    sprintf(buf, "/dev/%s", params);	/* let's hope it's there */
952
		    if (stat(buf, &st) == 0) {
953
			if (!S_ISBLK(st.st_mode))
954
			    die("device-mapper: %s is not a valid block device", buf);
955
			major = MAJOR(st.st_rdev);
956
			minor = MINOR(st.st_rdev);
957
		    } else {				/* let's try sysfs */
958
			int dev;
959
			sprintf(buf, "/sys/block/%s/dev", params);
960
			file = fopen(buf, "r");
961
 			if (!file)
962
			    die("device-mapper: \"%s\" could not be opened. /sys mounted?", buf);
963
			if (!fgets(buf, PATH_MAX, file))
964
			    die("device-mapper: read error from \"/sys/block/%s/dev\"", params);
965
			if (sscanf(buf, "%u:%u", &major, &minor) != 2) {
966
			    if (sscanf(buf, "%x", &dev) != 1)
967
				die("device-mapper: error getting device from \"%s\"", buf);
968
			    major = MAJOR(dev);
969
			    minor = MINOR(dev);
970
			}
971
			(void) fclose(file);
972
		    }
973
		    *p = ' ';
974
		    if (sscanf(p+1, "%"PRIu64, &target->offset) != 1)
975
			die("device-mapper: parse error in linear params (\"%s\")", params);
976
		}
977
		target->device = (major << 8) | minor;
978
		if (!device)
979
		    device = target->device;
980
		target->next = dm_table->target;
981
		dm_table->target = target;
982
	    } while(next);
983
984
	    dm_task_destroy(dmt);
985
986
	    dev_close(&dev);
987
	}
988
989
	if (!device)
990
	    die("device-mapper: Error finding real device");
991
	geo->base_dev = device;
992
993
	for(i = 0; i < dm_major_nr; i++)
994
	    if (MAJOR(device) == dm_major_list[i])
995
		break;
996
    }
997
#endif
771
998
772
    if (verbose>=5) printf("geo_get: device %04X, all=%d\n", device, all);
999
    if (verbose>=5) printf("geo_get: device %04X, all=%d\n", device, all);
773
#ifdef LCF_LVM
1000
#ifdef LCF_LVM
Lines 1130-1143 Link Here
1130
            die("EVMS boot volume cannot be on multiple disks.\n");
1357
            die("EVMS boot volume cannot be on multiple disks.\n");
1131
        sector = ebm.rsector + ((offset/SECTOR_SIZE) % geo->spb) + geo->start;
1358
        sector = ebm.rsector + ((offset/SECTOR_SIZE) % geo->spb) + geo->start;
1132
    }
1359
    }
1133
    else {
1360
    else
1134
        sector = block*geo->spb+((offset/SECTOR_SIZE) % geo->spb);
1361
#endif
1135
        sector += geo->start;
1362
    {
1136
    }
1363
#ifdef LCF_DEVMAPPER 
1137
#else
1364
	int dev = geo->dev;
1138
    sector = block*geo->spb+((offset/SECTOR_SIZE) % geo->spb);
1365
	int i;
1139
    sector += geo->start;
1366
#endif
1367
	sector = block*geo->spb+((offset/SECTOR_SIZE) % geo->spb);
1368
#ifdef LCF_DEVMAPPER 
1369
	for(i = 0; i < dm_major_nr; i++)
1370
	    if (MAJOR(dev) == dm_major_list[i])
1371
		break;
1372
	while (i < dm_major_nr) {
1373
	    DM_TABLE *dm_table;
1374
	    DM_TARGET *dm_target;
1375
1376
	    for(dm_table = dmtab; dm_table; dm_table = dm_table->next)
1377
		if (dm_table->device == dev)
1378
		    break;
1379
	    if (!dm_table)
1380
		die("device-mapper: Mapped device suddenly lost? (%d)", dev);
1381
1382
	    for(dm_target = dm_table->target; dm_target; dm_target = dm_target->next)
1383
		if (dm_target->start <= sector && sector < (dm_target->start+dm_target->length))
1384
		    break;
1385
	    if (!dm_target)
1386
		die("device-mapper: Sector outside mapped device? (%d: %u/%"PRIu64")",
1387
		    geo->base_dev, sector, (uint64_t)(dm_table->target ?
1388
		      (dm_table->target->start+dm_table->target->length) : 0));
1389
1390
	    dev = dm_target->device;
1391
	    sector = dm_target->offset+(sector-dm_target->start);
1392
1393
	    for(i = 0; i < dm_major_nr; i++)
1394
		if (MAJOR(dev) == dm_major_list[i])
1395
		    break;
1396
	}
1397
1398
	if (dev != geo->dev && dev != geo->base_dev)
1399
	    die("device-mapper: mapped boot device cannot be on multiple real devices\n");
1140
#endif
1400
#endif
1401
	sector += geo->start;
1402
    }
1403
1141
 /*   DON'T always use CHS addressing on floppies:     JRC   */
1404
 /*   DON'T always use CHS addressing on floppies:     JRC   */
1142
/*    if ((geo->device & 0x80) && (linear || lba32)) {	*/
1405
/*    if ((geo->device & 0x80) && (linear || lba32)) {	*/
1143
    if ((linear || lba32)) {
1406
    if ((linear || lba32)) {

Return to bug 33873