Author: Bernie Innocenti <bernie@codewiz.org>

Make amiga-fdisk work with disks larger than 2GB

diff -up amiga-fdisk-0.04.debian/amigastuff.c amiga-fdisk_0.04-12.new/amigastuff.c
--- amiga-fdisk-0.04.debian/amigastuff.c	2009-03-29 18:10:25.341476587 +0200
+++ amiga-fdisk_0.04-12.new/amigastuff.c	2009-03-29 18:07:21.166521465 +0200
@@ -19,6 +19,8 @@
  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
  */
 
+#define _LARGEFILE64_SOURCE 1
+
 #include <fcntl.h>
 #include <unistd.h>
 #include <linux/hdreg.h>
@@ -80,13 +82,12 @@ char *get_block(block)
 
 	if (list_only)
 	{
-		if ((l=open(disk_device,O_RDONLY))<0) {
+		if ((l=open(disk_device,O_RDONLY|O_LARGEFILE))<0) {
 			if (get_dev)
 				fprintf (stderr,"Cannot open device %s\n",disk_device);
 				return NULL;
 		}
-
-		if (lseek(l,(block*SECTOR_SIZE),SEEK_SET)<0) {
+		if (lseek64(l,((off64_t)block*SECTOR_SIZE),SEEK_SET)<0) {
 			close(l);
 			fprintf (stderr,"Seek error occured while reading block %d.\n",block);
 			return NULL;
@@ -321,7 +322,7 @@ int get_rdb(void)
 		return -1;
 	}
 
-	if ((f=open(disk_device,O_RDONLY))<0) {
+	if ((f=open(disk_device,O_RDONLY|O_LARGEFILE))<0) {
 		if (!list_only || get_dev)
 			fprintf (stderr,"Cannot open device %s\n",disk_device);
 		free((char *)rdb);
@@ -332,7 +333,7 @@ int get_rdb(void)
 	firstblock=-1;
 	while ((i<RDB_LOCATION_LIMIT)&&(firstblock==-1)) {
 
-		if (lseek(f,(i*SECTOR_SIZE),SEEK_SET)<0) {
+		if (lseek64(f,((off64_t)i*SECTOR_SIZE),SEEK_SET)<0) {
 			close(f);
 			free((char *)rdb);
 			fprintf (stderr,"Seek error occured while reading RDB.\n");
@@ -377,7 +378,7 @@ int get_rdb(void)
 			return -1;
 		}
 
-		if (lseek(f,0,SEEK_SET)<0) {
+		if (lseek64(f,0,SEEK_SET)<0) {
 			close(f); free(initsectors);
 			fprintf (stderr,"Seek error occured while reading partition table.\n");
 			return -1;
@@ -676,10 +677,10 @@ int rigiddisk_correct(void)
 int rigiddisk_new(int first)
 {
 	struct hd_geometry geo={-1,};
-	long long hdsize;
+	off64_t hdsize;
 	int i,f;
 
-	if ((f=open(disk_device,O_RDONLY))<0) {
+	if ((f=open(disk_device,O_RDONLY|O_LARGEFILE))<0) {
 		fprintf (stderr,"Cannot open device %s\n",disk_device);
 		return -1;
 	}
@@ -689,7 +690,7 @@ int rigiddisk_new(int first)
 	if (ioctl(f,HDIO_GETGEO,&geo)!=0) {
 		printf("Can't get geometry data. Trying lseek/trivial mapping.\n");
 
-		hdsize=lseek(f,0,SEEK_END);
+		hdsize=lseek64(f,0,SEEK_END);
 		if (hdsize != -1) {
 			if (hdsize==0) {
 				printf("LSEEK: Could not lseek (Floppy?). Exit.\n");
@@ -915,12 +916,12 @@ int rigiddisk_save(void)
 
 	rigiddisk_correct();
 
-	if ((f=open(disk_device,O_WRONLY))<0) {
+	if ((f=open(disk_device,O_WRONLY|O_LARGEFILE))<0) {
 		fprintf (stderr,"Cannot open device %s\n",disk_device);
 		return -1;
 	}
 
-	if (lseek(f,0,SEEK_SET)<0) {
+	if (lseek64(f,0,SEEK_SET)<0) {
 		close(f); fprintf (stderr,"Seek error occured while writing partition table.\n");
 		return -1;
 	}
