ports/53379: New port: sysutils/linuxfdisk

Valentin Nechayev netch at netch.kiev.ua
Mon Jun 16 16:00:34 UTC 2003


>Number:         53379
>Category:       ports
>Synopsis:       New port: sysutils/linuxfdisk
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 16 09:00:29 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Valentin Nechayev
>Release:        FreeBSD 4.8-RELEASE, 5.1-RELEASE i386
>Organization:
Home sweet home
>Environment:

>Description:

This adds port of standard Linux fdisk from util-linux package.
For now, FreeBSD has no tools working with full MS-DOS partition scheme,
only for primary partitions (slices), even in ports.

>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Makefile
#	distinfo
#	files/
#	files/patch-aa
#	files/Makefile
#	files/patch-ab
#	files/sys_bsd.c
#	pkg-descr
#	pkg-plist
#
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X# New ports collection makefile for:    linuxfdisk
X# Date created:         Mon Jun 16 14:52:38 UTC 2003
X# Whom:                 netch at netch.kiev.ua
X#
X# $FreeBSD$
X#
X
XPORTNAME=	linuxfdisk
XPORTVERSION=	2.11z
XCATEGORIES=	sysutils
XMASTER_SITES=	ftp://ftp.kernel.org/pub/linux/utils/
XDISTNAME=	util-linux-${PORTVERSION}
XEXTRACT_SUFX=	.tar.bz2
X
XMAINTAINER=	netch at netch.kiev.ua
XCOMMENT=	Fdisk, a partition tables manipulator, from util-linux
X
XWRKSRC=		${WRKDIR}/linuxfdisk-${PORTVERSION}
XUSE_BZIP2=	yes
XMAN8=		linuxfdisk.8
X
Xpost-extract:
X	@cd ${WRKDIR} && ${LN} -sf util-linux-${PORTVERSION}/fdisk linuxfdisk-${PORTVERSION}
X
Xpre-patch:
X	@rm -f ${WRKSRC}/Makefile
X	@cp ${FILESDIR}/Makefile ${WRKSRC}/
X	@cp ${FILESDIR}/sys_bsd.c ${WRKSRC}/
X	@cp -p ${WRKSRC}/fdisk.8 ${WRKSRC}/linuxfdisk.8
X
X.include <bsd.port.mk>
END-of-Makefile
echo x - distinfo
sed 's/^X//' >distinfo << 'END-of-distinfo'
XMD5 (util-linux-2.11z.tar.bz2) = abaab0a441233d6b7763b89ea5ab4078
END-of-distinfo
echo c - files/
mkdir -p files/ > /dev/null 2>&1
echo x - files/patch-aa
sed 's/^X//' >files/patch-aa << 'END-of-files/patch-aa'
Xdiff -rNu common.h common.h
X--- common.h	Thu May  9 02:50:35 2002
X+++ common.h	Mon Jun 16 17:30:59 2003
X@@ -1,11 +1,10 @@
X /* common stuff for fdisk, cfdisk, sfdisk */
X 
X-/* including <linux/fs.h> fails */
X-#include <sys/ioctl.h>
X-#define BLKRRPART  _IO(0x12,95)    /* re-read partition table */
X-#define BLKGETSIZE _IO(0x12,96)    /* return device size */
X-#define BLKFLSBUF  _IO(0x12,97)    /* flush buffer cache */
X-#define BLKSSZGET  _IO(0x12,104)   /* get block device sector size */
X+#include <sys/types.h>
X+typedef u_int16_t __u16;
X+typedef u_int32_t __u32;
X+typedef int16_t __s16;
X+typedef u_int8_t __u8;
X 
X /* including <linux/hdreg.h> also fails */
X struct hd_geometry {
X@@ -15,9 +14,6 @@
X       unsigned long start;
X };
X 
X-#define HDIO_GETGEO		0x0301	/* get device geometry */
X-
X-
X struct systypes {
X 	unsigned char type;
X 	char *name;
X@@ -26,3 +22,8 @@
X extern struct systypes i386_sys_types[];
X 
X extern char *partname(char *dev, int pno, int lth);
X+
X+unsigned int sys_bsd_sectorsize(int fd);
X+int sys_bsd_getsectors(int fd, unsigned long* s);
X+int sys_bsd_ptsync(int fd);
X+int sys_bsd_getgeometry(int, struct hd_geometry*);
Xdiff -rNu fdisk.c fdisk.c
X--- fdisk.c	Sat Nov 23 18:05:24 2002
X+++ fdisk.c	Mon Jun 16 17:37:33 2003
X@@ -37,11 +37,6 @@
X #include "fdisksgilabel.h"
X #include "fdiskaixlabel.h"
X 
X-#include "../defines.h"
X-#ifdef HAVE_blkpg_h
X-#include <linux/blkpg.h>
X-#endif
X-
X static void delete_partition(int i);
X 
X #define hex_val(c)	({ \
X@@ -198,8 +193,8 @@
X "       fdisk -l [-b SSZ] [-u] DISK  List partition table(s)\n"
X "       fdisk -s PARTITION           Give partition size(s) in blocks\n"
X "       fdisk -v                     Give fdisk version\n"
X-"Here DISK is something like /dev/hdb or /dev/sda\n"
X-"and PARTITION is something like /dev/hda7\n"
X+"Here DISK is something like /dev/ad1 or /dev/da0\n"
X+"and PARTITION is something like /dev/ad0s7\n"
X "-u: give Start and End in sector (instead of cylinder) units\n"
X "-b 2048: (for certain MO disks) use 2048-byte sectors\n");
X 			break;
X@@ -207,10 +202,8 @@
X 		  /* msg in cases where fdisk used to probe */
X 			message = _(
X "Usage: fdisk [-l] [-b SSZ] [-u] device\n"
X-"E.g.: fdisk /dev/hda  (for the first IDE disk)\n"
X-"  or: fdisk /dev/sdc  (for the third SCSI disk)\n"
X-"  or: fdisk /dev/eda  (for the first PS/2 ESDI drive)\n"
X-"  or: fdisk /dev/rd/c0d0  or: fdisk /dev/ida/c0d0  (for RAID devices)\n"
X+"E.g.: fdisk /dev/ad0  (for the first IDE disk)\n"
X+"  or: fdisk /dev/da0  (for the third SCSI disk)\n"
X "  ...\n");
X 			break;
X 		case unable_to_open:
X@@ -231,7 +224,7 @@
X 			break;
X 		case ioctl_error:
X 			snprintf(error, sizeof(error),
X-				 _("BLKGETSIZE ioctl failed on %s\n"),
X+				 _("DIOCGDINFO ioctl failed on %s\n"),
X 				disk_device);
X 			break;
X 		case out_of_memory:
X@@ -248,8 +241,8 @@
X 
X static void
X seek_sector(int fd, uint secno) {
X-	ext2_loff_t offset = (ext2_loff_t) secno * sector_size;
X-	if (ext2_llseek(fd, offset, SEEK_SET) == (ext2_loff_t) -1)
X+	off_t offset = (off_t) secno * sector_size;
X+	if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
X 		fatal(unable_to_seek);
X }
X 
X@@ -725,53 +718,23 @@
X 	get_boot(create_empty_dos);
X }
X 
X-#include <sys/utsname.h>
X-#define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
X-
X-static int
X-linux_version_code(void) {
X-	static int kernel_version = 0;
X-        struct utsname my_utsname;
X-        int p, q, r;
X-
X-        if (!kernel_version && uname(&my_utsname) == 0) {
X-                p = atoi(strtok(my_utsname.release, "."));
X-                q = atoi(strtok(NULL, "."));
X-                r = atoi(strtok(NULL, "."));
X-                kernel_version = MAKE_VERSION(p,q,r);
X-        }
X-        return kernel_version;
X-}
X-
X static void
X get_sectorsize(int fd) {
X-#if defined(BLKSSZGET)
X-	if (!user_set_sector_size &&
X-	    linux_version_code() >= MAKE_VERSION(2,3,3)) {
X-		int arg;
X-		if (ioctl(fd, BLKSSZGET, &arg) == 0)
X-			sector_size = arg;
X-		if (sector_size != DEFAULT_SECTOR_SIZE)
X-			printf(_("Note: sector size is %d (not %d)\n"),
X-			       sector_size, DEFAULT_SECTOR_SIZE);
X-	}
X-#else
X-	/* maybe the user specified it; and otherwise we still
X-	   have the DEFAULT_SECTOR_SIZE default */
X-#endif
X+	unsigned int r = sys_bsd_sectorsize(fd);
X+	if (r)
X+		sector_size = r;
X+	if (sector_size != DEFAULT_SECTOR_SIZE)
X+		printf(_("Note: sector size is %d (not %d)\n"),
X+		       sector_size, DEFAULT_SECTOR_SIZE);
X }
X 
X static void
X get_kernel_geometry(int fd) {
X-#ifdef HDIO_GETGEO
X-	struct hd_geometry geometry;
X-
X-	if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
X-		kern_heads = geometry.heads;
X-		kern_sectors = geometry.sectors;
X-		/* never use geometry.cylinders - it is truncated */
X+	struct hd_geometry h;
X+	if (!sys_bsd_getgeometry(fd, &h)) {
X+		kern_heads = h.heads;
X+		kern_sectors = h.sectors;
X 	}
X-#endif
X }
X 
X static void
X@@ -813,7 +776,7 @@
X 
X 	get_sectorsize(fd);
X 	sec_fac = sector_size / 512;
X-	guess_device_type(fd);
X+	//guess_device_type(fd);
X 	heads = cylinders = sectors = 0;
X 	kern_heads = kern_sectors = 0;
X 	pt_heads = pt_sectors = 0;
X@@ -828,8 +791,11 @@
X 		pt_sectors ? pt_sectors :
X 		kern_sectors ? kern_sectors : 63;
X 
X-	if (ioctl(fd, BLKGETSIZE, &longsectors))
X-		longsectors = 0;
X+	;{
X+		unsigned long r;
X+		if (sys_bsd_getsectors(fd, &r) == 0)
X+			longsectors = r;
X+	}
X 
X 	sector_offset = 1;
X 	if (dos_compatible_flag)
X@@ -1404,7 +1370,7 @@
X  * Jan.  1990 (version 1.2.1 by Gordon W. Ross Aug. 1990; Modified by S.
X  * Lubkin Oct.  1991). */
X 
X-static void long2chs(ulong ls, uint *c, uint *h, uint *s) {
X+static void long2chs(unsigned long ls, uint *c, uint *h, uint *s) {
X 	int	spc = heads * sectors;
X 
X 	*c = ls / spc;
X@@ -2102,16 +2068,8 @@
X 	printf(_("Calling ioctl() to re-read partition table.\n"));
X 	sync();
X 	sleep(2);
X-	if ((i = ioctl(fd, BLKRRPART)) != 0) {
X+	if ((i = sys_bsd_ptsync(fd)) != 0) {
X                 error = errno;
X-        } else {
X-                /* some kernel versions (1.2.x) seem to have trouble
X-                   rereading the partition table, but if asked to do it
X-		   twice, the second time works. - biro at yggdrasil.com */
X-                sync();
X-                sleep(2);
X-                if ((i = ioctl(fd, BLKRRPART)) != 0)
X-                        error = errno;
X         }
X 
X 	if (i) {
X@@ -2403,9 +2361,11 @@
X 	int j, c;
X 	int optl = 0, opts = 0;
X 
X+#if 0
X 	setlocale(LC_ALL, "");
X 	bindtextdomain(PACKAGE, LOCALEDIR);
X 	textdomain(PACKAGE);
X+#endif
X 
X 	/*
X 	 * Calls:
X@@ -2455,7 +2415,7 @@
X 			break;
X 		case 'V':
X 		case 'v':
X-			printf("fdisk v" UTIL_LINUX_VERSION "\n");
X+			printf("fdisk v" "2.11z" "-freebsd-portbld" "\n");
X 			exit(0);
X 		default:
X 			fatal(usage);
X@@ -2504,7 +2464,7 @@
X 			disk_device = argv[j];
X 			if ((fd = open(disk_device, type_open)) < 0)
X 				fatal(unable_to_open);
X-			if (ioctl(fd, BLKGETSIZE, &size))
X+			if (sys_bsd_getsectors(fd, &size))
X 				fatal(ioctl_error);
X 			close(fd);
X 			if (opts == 1)
Xdiff -rNu fdiskaixlabel.c fdiskaixlabel.c
X--- fdiskaixlabel.c	Tue Apr 18 15:21:28 2000
X+++ fdiskaixlabel.c	Mon Jun 16 16:46:01 2003
X@@ -8,7 +8,7 @@
X #include <string.h>             /* strstr */
X #include <unistd.h>             /* write */
X 
X-#include <endian.h>
X+#include <sys/endian.h>
X 
X #include "common.h"
X #include "fdisk.h"
Xdiff -rNu fdiskaixlabel.h fdiskaixlabel.h
X--- fdiskaixlabel.h	Sun Feb 20 18:50:51 2000
X+++ fdiskaixlabel.h	Mon Jun 16 16:46:01 2003
X@@ -1,4 +1,3 @@
X-#include <linux/types.h>   /* for __u32 etc */
X /*
X  * Copyright (C) Andreas Neuper, Sep 1998.
X  *	This file may be redistributed under
Xdiff -rNu fdiskbsdlabel.c fdiskbsdlabel.c
X--- fdiskbsdlabel.c	Thu Oct 31 15:43:42 2002
X+++ fdiskbsdlabel.c	Mon Jun 16 16:46:01 2003
X@@ -566,7 +566,7 @@
X   sector = get_start_sect(xbsd_part);
X #endif
X 
X-  if (ext2_llseek (fd, (ext2_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
X+  if (lseek (fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
X     fatal (unable_to_seek);
X   if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
X     fatal (unable_to_write);
X@@ -735,7 +735,7 @@
X 	sector = 0;
X #endif
X 
X-	if (ext2_llseek (fd, (ext2_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
X+	if (lseek (fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
X 		fatal (unable_to_seek);
X 	if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE))
X 		fatal (unable_to_read);
X@@ -781,12 +781,12 @@
X 
X #if defined (__alpha__) && BSD_LABELSECTOR == 0
X   alpha_bootblock_checksum (disklabelbuffer);
X-  if (ext2_llseek (fd, (ext2_loff_t) 0, SEEK_SET) == -1)
X+  if (lseek (fd, (off_t) 0, SEEK_SET) == -1)
X     fatal (unable_to_seek);
X   if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
X     fatal (unable_to_write);
X #else
X-  if (ext2_llseek (fd, (ext2_loff_t) sector * SECTOR_SIZE + BSD_LABELOFFSET,
X+  if (lseek (fd, (off_t) sector * SECTOR_SIZE + BSD_LABELOFFSET,
X 		   SEEK_SET) == -1)
X     fatal (unable_to_seek);
X   if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel)))
Xdiff -rNu fdiskbsdlabel.h fdiskbsdlabel.h
X--- fdiskbsdlabel.h	Thu Oct 31 15:45:34 2002
X+++ fdiskbsdlabel.h	Mon Jun 16 16:46:01 2003
X@@ -31,8 +31,6 @@
X  * SUCH DAMAGE.
X  */
X 
X-#include <linux/types.h>	/* for __u32, __u16, __u8, __s16 */
X-
X #ifndef BSD_DISKMAGIC
X #define BSD_DISKMAGIC     ((__u32) 0x82564557)
X #endif
Xdiff -rNu fdisksgilabel.c fdisksgilabel.c
X--- fdisksgilabel.c	Thu May  9 02:51:31 2002
X+++ fdisksgilabel.c	Mon Jun 16 17:31:32 2003
X@@ -17,9 +17,8 @@
X #include <sys/stat.h>           /* stat */
X #include <assert.h>             /* assert */
X 
X-#include <endian.h>
X+#include <sys/endian.h>
X #include "nls.h"
X-#include <linux/major.h>        /* FLOPPY_MAJOR */
X 
X #include "common.h"
X #include "fdisk.h"
X@@ -382,7 +381,7 @@
X 	 */
X 	sgiinfo*info = fill_sgiinfo();	/* fills the block appropriately */
X 	int infostartblock = SSWAP32( sgilabel->directory[0].vol_file_start );
X-	if( ext2_llseek(fd, (ext2_loff_t)infostartblock*
X+	if( lseek(fd, (off_t)infostartblock*
X 	    SECTOR_SIZE, SEEK_SET) < 0 )
X 	    fatal(unable_to_seek);
X 	if( write(fd, info, SECTOR_SIZE) != SECTOR_SIZE )
X@@ -735,11 +734,7 @@
X 
X     other_endian = (BYTE_ORDER == LITTLE_ENDIAN);
X 
X-#ifdef HDIO_REQ
X-    if (!ioctl(fd, HDIO_REQ, &geometry))
X-#else
X-    if (!ioctl(fd, HDIO_GETGEO, &geometry))
X-#endif
X+    if (!sys_bsd_getgeometry(fd, &geometry))
X     {
X 	heads = geometry.heads;
X 	sectors = geometry.sectors;
Xdiff -rNu fdisksgilabel.h fdisksgilabel.h
X--- fdisksgilabel.h	Tue Feb 20 12:26:53 2001
X+++ fdisksgilabel.h	Mon Jun 16 16:46:01 2003
X@@ -1,4 +1,3 @@
X-#include <linux/types.h>   /* for __u32 etc */
X /*
X  * Copyright (C) Andreas Neuper, Sep 1998.
X  *	This file may be modified and redistributed under
Xdiff -rNu fdisksunlabel.c fdisksunlabel.c
X--- fdisksunlabel.c	Fri Nov  1 03:55:25 2002
X+++ fdisksunlabel.c	Mon Jun 16 17:30:38 2003
X@@ -16,18 +16,18 @@
X #include <unistd.h>		/* write */
X #include <sys/ioctl.h>		/* ioctl */
X #include <sys/stat.h>		/* stat */
X-#include <sys/sysmacros.h>	/* major */
X+//#include <sys/sysmacros.h>	/* major */
X 
X #include "nls.h"
X 
X-#include <endian.h>
X-#include "../defines.h"		/* for HAVE_scsi_h */
X+#include <sys/endian.h>
X+//#include "../defines.h"		/* for HAVE_scsi_h */
X #ifdef HAVE_scsi_h
X #define u_char	unsigned char
X #include <scsi/scsi.h>		/* SCSI_IOCTL_GET_IDLUN */
X #undef u_char
X #endif
X-#include <linux/major.h>	/* FLOPPY_MAJOR */
X+//#include <linux/major.h>	/* FLOPPY_MAJOR */
X 
X #include "common.h"
X #include "fdisk.h"
X@@ -71,6 +71,7 @@
X 	return SSWAP32(p.num_sectors);
X }
X 
X+#if 0
X #ifndef IDE0_MAJOR
X #define IDE0_MAJOR 3
X #endif
X@@ -97,6 +98,7 @@
X                 floppy = 0;
X 	}
X }
X+#endif
X 
X static void
X set_sun_partition(int i, uint start, uint stop, int sysid) {
X@@ -296,11 +298,7 @@
X 	    }
X 	}
X 	if (!p || floppy) {
X-#ifdef HDIO_REQ
X-	    if (!ioctl(fd, HDIO_REQ, &geometry)) {
X-#else
X-	    if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
X-#endif
X+	    if (!sys_bsd_getgeometry(fd, &geometry)) {
X 	        heads = geometry.heads;
X 	        sectors = geometry.sectors;
X 	        cylinders = geometry.cylinders;
Xdiff -rNu fdisksunlabel.h fdisksunlabel.h
X--- fdisksunlabel.h	Tue Oct  3 00:42:10 2000
X+++ fdisksunlabel.h	Mon Jun 16 16:46:01 2003
X@@ -1,4 +1,3 @@
X-#include <linux/types.h>   /* for __u16, __u32 */
X 
X typedef struct {
X 	unsigned char info[128];   /* Informative text string */
Xdiff -rNu nls.h nls.h
X--- nls.h	Thu Jan  1 03:00:00 1970
X+++ nls.h	Mon Jun 16 16:46:01 2003
X@@ -0,0 +1,2 @@
X+#define _(x) (x)
X+#define N_(x) (x)
Xdiff -rNu partname.c partname.c
X--- partname.c	Sun Jul  7 15:16:43 2002
X+++ partname.c	Mon Jun 16 16:46:02 2003
X@@ -21,14 +21,16 @@
X 	p = "";
X 
X 	if (isdigit(dev[w-1]))
X-		p = "p";
X+		p = "s";
X 
X+#if 0
X 	/* devfs kludge - note: fdisk partition names are not supposed
X 	   to equal kernel names, so there is no reason to do this */
X 	if (strcmp (dev + w - 4, "disc") == 0) {
X 		w -= 4;
X 		p = "part";
X 	}
X+#endif
X 
X 	wp = strlen(p);
X 		
END-of-files/patch-aa
echo x - files/Makefile
sed 's/^X//' >files/Makefile << 'END-of-files/Makefile'
Xall: linuxfdisk
X
XOBJS = fdisk.o i386_sys_types.o partname.o \
X	fdiskbsdlabel.o fdisksunlabel.o fdiskaixlabel.o fdisksgilabel.o \
X	sys_bsd.o
XINSTALL?=	install -c
X## Debug
X#CFLAGS+=	-O0 -g -Wall
X
Xlinuxfdisk: $(OBJS)
X	$(CC) -o linuxfdisk $(OBJS)
X
Xinstall:
X	$(INSTALL) -c -m 0555 -s linuxfdisk ${DESTDIR}${PREFIX}/sbin/linuxfdisk
X	cat linuxfdisk.8 >${DESTDIR}${PREFIX}/man/man8/linuxfdisk.8
END-of-files/Makefile
echo x - files/patch-ab
sed 's/^X//' >files/patch-ab << 'END-of-files/patch-ab'
X--- linuxfdisk.8.orig	Tue Aug  6 17:33:33 2002
X+++ linuxfdisk.8	Mon Jun 16 18:52:50 2003
X@@ -5,14 +5,14 @@
X .SH NAME
X fdisk \- Partition table manipulator for Linux
X .SH SYNOPSIS
X-.BI "fdisk [\-u] [\-b " sectorsize ]
X+.BI "linuxfdisk [\-u] [\-b " sectorsize ]
X .BI "[\-C " cyls "] [\-H " heads "] [\-S " sects "] " device
X .sp
X-.BI "fdisk \-l [\-u] [" "device ..." ]
X+.BI "linuxfdisk \-l [\-u] [" "device ..." ]
X .sp
X-.BI "fdisk \-s " "partition ..."
X+.BI "linuxfdisk \-s " "partition ..."
X .sp
X-.BI "fdisk \-v
X+.BI "linuxfdisk \-v
X .SH DESCRIPTION
X Hard disks can be divided into one or more logical disks called
X .IR partitions .
X@@ -54,8 +54,7 @@
X /dev/sdb
X .RE
X .fi
X-(/dev/hd[a-h] for IDE disks, /dev/sd[a-p] for SCSI disks,
X-/dev/ed[a-d] for ESDI disks, /dev/xd[ab] for XT disks).
X+(/dev/adN for IDE disks, /dev/daN for SCSI disks, N=0,1,2...)
X A device name refers to the entire disk.
X 
X The
X@@ -63,11 +62,9 @@
X is a
X .I device
X name followed by a partition number.  For example,
X-.B /dev/hda1
X+.B /dev/ad0s1
X is the first partition on the first IDE hard disk in the system.
X IDE disks can have up to 63 partitions, SCSI disks up to 15.
X-See also
X-.IR /usr/src/linux/Documentation/devices.txt .
X 
X A BSD/SUN type disklabel can describe 8 partitions,
X the third of which should be a `whole disk' partition.
END-of-files/patch-ab
echo x - files/sys_bsd.c
sed 's/^X//' >files/sys_bsd.c << 'END-of-files/sys_bsd.c'
X#include <sys/param.h>
X#include <sys/disklabel.h>
X#if __FreeBSD_version < 500000
X#include <sys/diskslice.h>
X#else
X#include <sys/disk.h>
X#include <errno.h>
X#endif
X#include <stddef.h>
X#include "common.h"
X
Xunsigned int
Xsys_bsd_sectorsize(int fd)
X{
X#ifdef DIOCGSECTORSIZE
X	unsigned int d;
X	if (ioctl(fd, DIOCGSECTORSIZE, &d) == 0)
X		return d;
X#else
X	struct disklabel dl;
X	if (ioctl(fd, DIOCGDINFO, &dl) == 0)
X		return dl.d_secsize;
X#endif
X	return 0;
X}
X
Xint
Xsys_bsd_getsectors(int fd, unsigned long *s)
X{
X	/* XXX */
X#if defined(DIOCGMEDIASIZE) && defined(DIOCGSECTORSIZE)
X	off_t fullsize;
X	unsigned sectsize;
X	if (ioctl(fd, DIOCGMEDIASIZE, &fullsize) ||
X	    ioctl(fd, DIOCGSECTORSIZE, &sectsize))
X		return -1;
X	*s = fullsize / sectsize;
X	return 0;
X#else
X	struct disklabel dl;
X	if (ioctl(fd, DIOCGDINFO, &dl) < 0)
X		return -1;
X	*s = (unsigned long) dl.d_ncylinders *
X		(unsigned long) dl.d_ntracks *
X		(unsigned long) dl.d_nsectors;
X	return 0;
X#endif
X}
X
Xint
Xsys_bsd_ptsync(int fd)
X{
X#ifdef DIOCSYNCSLICEINFO
X	return ioctl(fd, DIOCSYNCSLICEINFO, NULL);
X#else
X	errno = EINVAL;
X	return -1;
X#endif
X}
X
Xint
Xsys_bsd_getgeometry(int fd, struct hd_geometry *g)
X{
X	/* XXX */
X	struct disklabel dl;
X	if (ioctl(fd, DIOCGDINFO, &dl) < 0)
X		return -1;
X	g->cylinders = dl.d_ncylinders;
X	g->heads = dl.d_ntracks;
X	g->sectors = dl.d_nsectors;
X	return 0;
X}
END-of-files/sys_bsd.c
echo x - pkg-descr
sed 's/^X//' >pkg-descr << 'END-of-pkg-descr'
XThis is fdisk from util-linux package, common on Linux systems.
XIt allows interactive manipulation of partitions including logical ones
Xfrom MS-DOS partitioning scheme.
END-of-pkg-descr
echo x - pkg-plist
sed 's/^X//' >pkg-plist << 'END-of-pkg-plist'
Xsbin/linuxfdisk
END-of-pkg-plist
exit



More information about the freebsd-ports-bugs mailing list