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

(-)a/kpartx/devmapper.c (-1 / +3 lines)
Lines 4-13 Link Here
4
#include <stdio.h>
4
#include <stdio.h>
5
#include <stdlib.h>
5
#include <stdlib.h>
6
#include <string.h>
6
#include <string.h>
7
#include <stdint.h>
7
#include <libdevmapper.h>
8
#include <libdevmapper.h>
8
#include <ctype.h>
9
#include <ctype.h>
9
#include <linux/kdev_t.h>
10
#include <linux/kdev_t.h>
10
#include <errno.h>
11
#include <errno.h>
12
#include "devmapper.h"
11
13
12
#define UUID_PREFIX "part%d-"
14
#define UUID_PREFIX "part%d-"
13
#define MAX_PREFIX_LEN 8
15
#define MAX_PREFIX_LEN 8
Lines 72-78 dm_simplecmd (int task, const char *name) { Link Here
72
74
73
extern int
75
extern int
74
dm_addmap (int task, const char *name, const char *target,
76
dm_addmap (int task, const char *name, const char *target,
75
	   const char *params, unsigned long size, const char *uuid, int part) {
77
	   const char *params, uint64_t size, const char *uuid, int part) {
76
	int r = 0;
78
	int r = 0;
77
	struct dm_task *dmt;
79
	struct dm_task *dmt;
78
	char *prefixed_uuid = NULL;
80
	char *prefixed_uuid = NULL;
(-)a/kpartx/devmapper.h (-2 / +2 lines)
Lines 1-7 Link Here
1
int dm_prereq (char *, int, int, int);
1
int dm_prereq (char *, int, int, int);
2
int dm_simplecmd (int, const char *);
2
int dm_simplecmd (int, const char *);
3
int dm_addmap (int, const char *, const char *, const char *, unsigned long,
3
int dm_addmap (int, const char *, const char *, const char *, uint64_t,
4
	       char *, int);
4
	       const char *, int);
5
int dm_map_present (char *);
5
int dm_map_present (char *);
6
char * dm_mapname(int major, int minor);
6
char * dm_mapname(int major, int minor);
7
dev_t dm_get_first_dep(char *devname);
7
dev_t dm_get_first_dep(char *devname);
(-)a/kpartx/gpt.c (-13 / +22 lines)
Lines 36-41 Link Here
36
#include <errno.h>
36
#include <errno.h>
37
#include <endian.h>
37
#include <endian.h>
38
#include <byteswap.h>
38
#include <byteswap.h>
39
#include <linux/fs.h>
39
#include "crc32.h"
40
#include "crc32.h"
40
41
41
#if BYTE_ORDER == LITTLE_ENDIAN
42
#if BYTE_ORDER == LITTLE_ENDIAN
Lines 50-59 Link Here
50
#  define __cpu_to_le32(x) bswap_32(x)
51
#  define __cpu_to_le32(x) bswap_32(x)
51
#endif
52
#endif
52
53
54
#ifndef BLKGETLASTSECT
53
#define BLKGETLASTSECT  _IO(0x12,108)   /* get last sector of block device */
55
#define BLKGETLASTSECT  _IO(0x12,108)   /* get last sector of block device */
56
#endif
57
#ifndef BLKGETSIZE
54
#define BLKGETSIZE _IO(0x12,96)	        /* return device size */
58
#define BLKGETSIZE _IO(0x12,96)	        /* return device size */
59
#endif
60
#ifndef BLKSSZGET
55
#define BLKSSZGET  _IO(0x12,104)	/* get block device sector size */
61
#define BLKSSZGET  _IO(0x12,104)	/* get block device sector size */
62
#endif
63
#ifndef BLKGETSIZE64
56
#define BLKGETSIZE64 _IOR(0x12,114,sizeof(uint64_t))	/* return device size in bytes (u64 *arg) */
64
#define BLKGETSIZE64 _IOR(0x12,114,sizeof(uint64_t))	/* return device size in bytes (u64 *arg) */
65
#endif
57
66
58
struct blkdev_ioctl_param {
67
struct blkdev_ioctl_param {
59
        unsigned int block;
68
        unsigned int block;
Lines 143-162 get_sector_size(int filedes) Link Here
143
static uint64_t
152
static uint64_t
144
_get_num_sectors(int filedes)
153
_get_num_sectors(int filedes)
145
{
154
{
146
	unsigned long sectors=0;
147
	int rc;
155
	int rc;
148
#if 0
156
	uint64_t bytes=0;
149
        uint64_t bytes=0;
150
157
151
 	rc = ioctl(filedes, BLKGETSIZE64, &bytes);
158
	rc = ioctl(filedes, BLKGETSIZE64, &bytes);
152
	if (!rc)
159
	if (!rc)
153
		return bytes / get_sector_size(filedes);
160
		return bytes / get_sector_size(filedes);
154
#endif
161
155
        rc = ioctl(filedes, BLKGETSIZE, &sectors);
162
	return 0;
156
        if (rc)
157
                return 0;
158
        
159
	return sectors;
160
}
163
}
161
164
162
/************************************************************
165
/************************************************************
Lines 193-199 last_lba(int filedes) Link Here
193
		sectors = 1;
196
		sectors = 1;
194
	}
197
	}
195
198
196
	return sectors - 1;
199
	return sectors ? sectors - 1 : 0;
197
}
200
}
198
201
199
202
Lines 220-236 read_lba(int fd, uint64_t lba, void *buffer, size_t bytes) Link Here
220
{
223
{
221
	int sector_size = get_sector_size(fd);
224
	int sector_size = get_sector_size(fd);
222
	off_t offset = lba * sector_size;
225
	off_t offset = lba * sector_size;
226
	uint64_t lastlba;
223
        ssize_t bytesread;
227
        ssize_t bytesread;
224
228
225
	lseek(fd, offset, SEEK_SET);
229
	lseek(fd, offset, SEEK_SET);
226
	bytesread = read(fd, buffer, bytes);
230
	bytesread = read(fd, buffer, bytes);
227
231
232
	lastlba = last_lba(fd);
233
	if (!lastlba)
234
		return bytesread;
235
228
        /* Kludge.  This is necessary to read/write the last
236
        /* Kludge.  This is necessary to read/write the last
229
           block of an odd-sized disk, until Linux 2.5.x kernel fixes.
237
           block of an odd-sized disk, until Linux 2.5.x kernel fixes.
230
           This is only used by gpt.c, and only to read
238
           This is only used by gpt.c, and only to read
231
           one sector, so we don't have to be fancy.
239
           one sector, so we don't have to be fancy.
232
        */
240
        */
233
        if (!bytesread && !(last_lba(fd) & 1) && lba == last_lba(fd)) {
241
        if (!bytesread && !(lastlba & 1) && lba == lastlba) {
234
                bytesread = read_lastoddsector(fd, lba, buffer, bytes);
242
                bytesread = read_lastoddsector(fd, lba, buffer, bytes);
235
        }
243
        }
236
        return bytesread;
244
        return bytesread;
Lines 505-511 find_valid_gpt(int fd, gpt_header ** gpt, gpt_entry ** ptes) Link Here
505
	if (!gpt || !ptes)
513
	if (!gpt || !ptes)
506
		return 0;
514
		return 0;
507
515
508
	lastlba = last_lba(fd);
516
	if (!(lastlba = last_lba(fd)))
517
		return 0;
509
	good_pgpt = is_gpt_valid(fd, GPT_PRIMARY_PARTITION_TABLE_LBA,
518
	good_pgpt = is_gpt_valid(fd, GPT_PRIMARY_PARTITION_TABLE_LBA,
510
				 &pgpt, &pptes);
519
				 &pgpt, &pptes);
511
        if (good_pgpt) {
520
        if (good_pgpt) {
(-)a/kpartx/kpartx.c (-12 / +13 lines)
Lines 25-30 Link Here
25
#include <stdlib.h>
25
#include <stdlib.h>
26
#include <string.h>
26
#include <string.h>
27
#include <unistd.h>
27
#include <unistd.h>
28
#include <stdint.h>
28
#include <sys/stat.h>
29
#include <sys/stat.h>
29
#include <sys/types.h>
30
#include <sys/types.h>
30
#include <ctype.h>
31
#include <ctype.h>
Lines 366-381 main(int argc, char **argv){ Link Here
366
367
367
				slices[j].minor = m++;
368
				slices[j].minor = m++;
368
369
369
				printf("%s%s%d : 0 %lu %s %lu\n",
370
				printf("%s%s%d : 0 %" PRIu64 " %s %" PRIu64"\n",
370
				       mapname, delim, j+1,
371
				       mapname, delim, j+1,
371
				       (unsigned long) slices[j].size, device,
372
				       slices[j].size, device,
372
				       (unsigned long) slices[j].start);
373
				       slices[j].start);
373
			}
374
			}
374
			/* Loop to resolve contained slices */
375
			/* Loop to resolve contained slices */
375
			d = c;
376
			d = c;
376
			while (c) {
377
			while (c) {
377
				for (j = 0; j < n; j++) {
378
				for (j = 0; j < n; j++) {
378
					unsigned long start;
379
					uint64_t start;
379
					int k = slices[j].container - 1;
380
					int k = slices[j].container - 1;
380
381
381
					if (slices[j].size == 0)
382
					if (slices[j].size == 0)
Lines 387-395 main(int argc, char **argv){ Link Here
387
					slices[j].minor = m++;
388
					slices[j].minor = m++;
388
389
389
					start = slices[j].start - slices[k].start;
390
					start = slices[j].start - slices[k].start;
390
					printf("%s%s%d : 0 %lu /dev/dm-%d %lu\n",
391
					printf("%s%s%d : 0 %" PRIu64 " /dev/dm-%d %" PRIu64 "\n",
391
					       mapname, delim, j+1,
392
					       mapname, delim, j+1,
392
					       (unsigned long) slices[j].size,
393
					       slices[j].size,
393
					       slices[k].minor, start);
394
					       slices[k].minor, start);
394
					c--;
395
					c--;
395
				}
396
				}
Lines 448-455 main(int argc, char **argv){ Link Here
448
				}
449
				}
449
				strip_slash(partname);
450
				strip_slash(partname);
450
451
451
				if (safe_sprintf(params, "%s %lu", device,
452
				if (safe_sprintf(params, "%s %" PRIu64 ,
452
					     (unsigned long)slices[j].start)) {
453
						 device, slices[j].start)) {
453
					fprintf(stderr, "params too small\n");
454
					fprintf(stderr, "params too small\n");
454
					exit(1);
455
					exit(1);
455
				}
456
				}
Lines 468-474 main(int argc, char **argv){ Link Here
468
					&slices[j].minor);
469
					&slices[j].minor);
469
470
470
				if (verbose)
471
				if (verbose)
471
					printf("add map %s (%d:%d): 0 %lu %s %s\n",
472
					printf("add map %s (%d:%d): 0 %" PRIu64 " %s %s\n",
472
					       partname, slices[j].major,
473
					       partname, slices[j].major,
473
					       slices[j].minor, slices[j].size,
474
					       slices[j].minor, slices[j].size,
474
					       DM_TARGET, params);
475
					       DM_TARGET, params);
Lines 502-511 main(int argc, char **argv){ Link Here
502
					}
503
					}
503
					strip_slash(partname);
504
					strip_slash(partname);
504
505
505
					if (safe_sprintf(params, "%d:%d %lu",
506
					if (safe_sprintf(params, "%d:%d %" PRIu64,
506
							 slices[k].major,
507
							 slices[k].major,
507
							 slices[k].minor,
508
							 slices[k].minor,
508
							 (unsigned long)slices[j].start)) {
509
							 slices[j].start)) {
509
						fprintf(stderr, "params too small\n");
510
						fprintf(stderr, "params too small\n");
510
						exit(1);
511
						exit(1);
511
					}
512
					}
Lines 524-530 main(int argc, char **argv){ Link Here
524
						&slices[j].minor);
525
						&slices[j].minor);
525
526
526
					if (verbose)
527
					if (verbose)
527
						printf("add map %s : 0 %lu %s %s\n",
528
						printf("add map %s : 0 %" PRIu64 " %s %s\n",
528
						       partname, slices[j].size,
529
						       partname, slices[j].size,
529
						       DM_TARGET, params);
530
						       DM_TARGET, params);
530
					c--;
531
					c--;
(-)a/kpartx/kpartx.h (-2 / +4 lines)
Lines 1-6 Link Here
1
#ifndef _KPARTX_H
1
#ifndef _KPARTX_H
2
#define _KPARTX_H
2
#define _KPARTX_H
3
3
4
#include <stdint.h>
5
4
/*
6
/*
5
 * For each partition type there is a routine that takes
7
 * For each partition type there is a routine that takes
6
 * a block device and a range, and returns the list of
8
 * a block device and a range, and returns the list of
Lines 20-27 Link Here
20
 * units: 512 byte sectors
22
 * units: 512 byte sectors
21
 */
23
 */
22
struct slice {
24
struct slice {
23
	unsigned long start;
25
	uint64_t start;
24
	unsigned long size;
26
	uint64_t size;
25
	int container;
27
	int container;
26
	int major;
28
	int major;
27
	int minor;
29
	int minor;

Return to bug 245615