usrsbinexec_PROGRAMS = addpart delpart partx
partx_SOURCES = bsd.c dos.c partx.c solaris.c unixware.c gpt.c crc32.c \
- efi.h gpt.h crc32.h partx.h dos.h
+ efi.h gpt.h crc32.h partx.h dos.h ../lib/blkdev.c
+
+if LINUX
+partx_SOURCES += ../lib/linux_version.c
+endif
dist_man_MANS = addpart.8 delpart.8 partx.8
#include <stdio.h>
+
+#include "blkdev.h"
+
#include "partx.h"
#include "dos.h"
static int
read_extended_partition(int fd, struct partition *ep,
- struct slice *sp, int ns)
+ struct slice *sp, int ns, int ssf)
{
struct partition *p;
unsigned long start, here;
if (partition_size(p) == 0 || is_extended(p->sys_type))
continue;
if (n < ns) {
- sp[n].start = here + partition_start(p);
- sp[n].size = partition_size(p);
+ sp[n].start = (here + partition_start(p)) * ssf;
+ sp[n].size = partition_size(p) * ssf;
n++;
} else {
fprintf(stderr,
unsigned long offset = all.start;
int i, n=0;
unsigned char *bp;
+ int ssf;
bp = getblock(fd, offset);
if (bp == NULL)
if (bp[510] != 0x55 || bp[511] != 0xaa)
return -1;
+ /* msdos PT depends sector size... */
+ if (blkdev_get_sector_size(fd, &ssf) != 0)
+ ssf = DEFAULT_SECTOR_SIZE;
+
+ /* ... but partx counts everything in 512-byte sectors */
+ ssf /= 512;
+
p = (struct partition *) (bp + 0x1be);
for (i=0; i<4; i++) {
if (is_gpt(p->sys_type))
for (i=0; i<4; i++) {
/* always add, even if zero length */
if (n < ns) {
- sp[n].start = partition_start(p);
- sp[n].size = partition_size(p);
+ sp[n].start = partition_start(p) * ssf;
+ sp[n].size = partition_size(p) * ssf;
n++;
} else {
fprintf(stderr,
p = (struct partition *) (bp + 0x1be);
for (i=0; i<4; i++) {
if (is_extended(p->sys_type))
- n += read_extended_partition(fd, p, sp+n, ns-n);
+ n += read_extended_partition(fd, p, sp+n, ns-n, ssf);
p++;
}
return n;