aboutsummaryrefslogtreecommitdiff
path: root/util-linux/fdisk.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-08-06 09:07:37 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-08-06 09:07:37 +0000
commit6920acd7cee9d7de653db6c02c72a4cfce9e5a37 (patch)
tree0e9044ad9f7e6abe0b395c86e93169aacf514a6a /util-linux/fdisk.c
parent676f87b92336f3b31fd629d3f628afd3414d0f12 (diff)
downloadbusybox-w32-6920acd7cee9d7de653db6c02c72a4cfce9e5a37.tar.gz
busybox-w32-6920acd7cee9d7de653db6c02c72a4cfce9e5a37.tar.bz2
busybox-w32-6920acd7cee9d7de653db6c02c72a4cfce9e5a37.zip
Patch from vodz:
I wrote: >>I think, fdisk have special ext2lseek special for: >>disk can have size > 4Gb, but all any partitions have < 4Gb and lseek64 >>not require. >>May be best create new configure option for set DOLFS for fdisk applet >>if global DOLFS unset? > Erik Andersen wrote: >Agreed. Using an extra configure option when ! DOLFS >would be a good idea. Ok. Patch attached. git-svn-id: svn://busybox.net/trunk/busybox@7174 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r--util-linux/fdisk.c96
1 files changed, 86 insertions, 10 deletions
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 4fecbbb89..a8e1ac857 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -88,12 +88,14 @@
88#define cround(n) (display_in_cyl_units ? ((n)/units_per_sector)+1 : (n)) 88#define cround(n) (display_in_cyl_units ? ((n)/units_per_sector)+1 : (n))
89#define scround(x) (((x)+units_per_sector-1)/units_per_sector) 89#define scround(x) (((x)+units_per_sector-1)/units_per_sector)
90 90
91#if defined(__GNUC__) || defined(HAS_LONG_LONG) 91
92typedef long long ext2_loff_t; 92#if defined(CONFIG_LFS) || defined(FDISK_SUPPORT_LARGE_DISKS) || defined(__alpha__) || defined(__ia64__) || defined(__s390x__)
93typedef long long fdisk_loff_t;
93#else 94#else
94typedef long ext2_loff_t; 95typedef long fdisk_loff_t;
95#endif 96#endif
96 97
98
97/* including <linux/hdreg.h> also fails */ 99/* including <linux/hdreg.h> also fails */
98struct hd_geometry { 100struct hd_geometry {
99 unsigned char heads; 101 unsigned char heads;
@@ -840,6 +842,80 @@ typedef struct {
840#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \ 842#define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) \
841 : (uint32_t)(x)) 843 : (uint32_t)(x))
842 844
845#if defined(FDISK_SUPPORT_LARGE_DISKS)
846/*
847 * llseek.c -- stub calling the llseek system call
848 *
849 * Copyright (C) 1994 Remy Card. This file may be redistributed
850 * under the terms of the GNU Public License.
851 */
852
853
854#include <syscall.h>
855
856
857#if defined(__alpha__) || defined(__ia64__) || defined(__s390x__)
858
859#define my_llseek lseek
860
861#else
862
863static int _llseek (unsigned int, unsigned long,
864 unsigned long, fdisk_loff_t *, unsigned int);
865
866static _syscall5(int,_llseek,unsigned int,f_d,unsigned long,offset_high,
867 unsigned long, offset_low,fdisk_loff_t *,result,
868 unsigned int, origin)
869
870static fdisk_loff_t my_llseek (unsigned int f_d, fdisk_loff_t offset,
871 unsigned int origin)
872{
873 fdisk_loff_t result;
874 int retval;
875
876 retval = _llseek (f_d, ((unsigned long long) offset) >> 32,
877 ((unsigned long long) offset) & 0xffffffff,
878 &result, origin);
879 return (retval == -1 ? (fdisk_loff_t) retval : result);
880}
881
882#endif /* __alpha__ */
883
884
885static fdisk_loff_t fdisk_llseek (unsigned int f_d, fdisk_loff_t offset,
886 unsigned int origin)
887{
888 fdisk_loff_t result;
889 static int do_compat = 0;
890
891 if (!do_compat) {
892 result = my_llseek (f_d, offset, origin);
893 if (!(result == -1 && errno == ENOSYS))
894 return result;
895
896 /*
897 * Just in case this code runs on top of an old kernel
898 * which does not support the llseek system call
899 */
900 do_compat = 1;
901 /*
902 * Now try ordinary lseek.
903 */
904 }
905
906 if ((sizeof(off_t) >= sizeof(fdisk_loff_t)) ||
907 (offset < ((fdisk_loff_t) 1 << ((sizeof(off_t)*8) -1))))
908 return lseek(f_d, (off_t) offset, origin);
909
910 errno = EINVAL;
911 return -1;
912}
913#else
914# define fdisk_llseek lseek
915#endif /* FDISK_SUPPORT_LARGE_DISKS */
916
917
918
843#ifdef CONFIG_FEATURE_OSF_LABEL 919#ifdef CONFIG_FEATURE_OSF_LABEL
844/* 920/*
845 Changes: 921 Changes:
@@ -1365,7 +1441,7 @@ xbsd_write_bootstrap (void)
1365 sector = get_start_sect(xbsd_part); 1441 sector = get_start_sect(xbsd_part);
1366#endif 1442#endif
1367 1443
1368 if (lseek (fd, (ext2_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1) 1444 if (fdisk_llseek (fd, (fdisk_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
1369 fdisk_fatal (unable_to_seek); 1445 fdisk_fatal (unable_to_seek);
1370 if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE)) 1446 if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
1371 fdisk_fatal (unable_to_write); 1447 fdisk_fatal (unable_to_write);
@@ -1533,7 +1609,7 @@ xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d)
1533 sector = 0; 1609 sector = 0;
1534#endif 1610#endif
1535 1611
1536 if (lseek (fd, (ext2_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1) 1612 if (fdisk_llseek (fd, (fdisk_loff_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
1537 fdisk_fatal (unable_to_seek); 1613 fdisk_fatal (unable_to_seek);
1538 if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE)) 1614 if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE))
1539 fdisk_fatal (unable_to_read); 1615 fdisk_fatal (unable_to_read);
@@ -1579,12 +1655,12 @@ xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d)
1579 1655
1580#if defined (__alpha__) && BSD_LABELSECTOR == 0 1656#if defined (__alpha__) && BSD_LABELSECTOR == 0
1581 alpha_bootblock_checksum (disklabelbuffer); 1657 alpha_bootblock_checksum (disklabelbuffer);
1582 if (lseek (fd, (ext2_loff_t) 0, SEEK_SET) == -1) 1658 if (fdisk_llseek (fd, (fdisk_loff_t) 0, SEEK_SET) == -1)
1583 fdisk_fatal (unable_to_seek); 1659 fdisk_fatal (unable_to_seek);
1584 if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE)) 1660 if (BSD_BBSIZE != write (fd, disklabelbuffer, BSD_BBSIZE))
1585 fdisk_fatal (unable_to_write); 1661 fdisk_fatal (unable_to_write);
1586#else 1662#else
1587 if (lseek (fd, (ext2_loff_t) sector * SECTOR_SIZE + BSD_LABELOFFSET, 1663 if (fdisk_llseek (fd, (fdisk_loff_t) sector * SECTOR_SIZE + BSD_LABELOFFSET,
1588 SEEK_SET) == -1) 1664 SEEK_SET) == -1)
1589 fdisk_fatal (unable_to_seek); 1665 fdisk_fatal (unable_to_seek);
1590 if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel))) 1666 if (sizeof (struct xbsd_disklabel) != write (fd, d, sizeof (struct xbsd_disklabel)))
@@ -2007,7 +2083,7 @@ sgi_write_table(void) {
2007 */ 2083 */
2008 sgiinfo *info = fill_sgiinfo(); 2084 sgiinfo *info = fill_sgiinfo();
2009 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start); 2085 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start);
2010 if (lseek(fd, (long long)infostartblock* 2086 if (fdisk_llseek(fd, (long long)infostartblock*
2011 SECTOR_SIZE, SEEK_SET) < 0) 2087 SECTOR_SIZE, SEEK_SET) < 0)
2012 fdisk_fatal(unable_to_seek); 2088 fdisk_fatal(unable_to_seek);
2013 if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE) 2089 if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE)
@@ -3390,8 +3466,8 @@ static void fdisk_fatal(enum failure why) {
3390 3466
3391static void 3467static void
3392seek_sector(uint secno) { 3468seek_sector(uint secno) {
3393 ext2_loff_t offset = (ext2_loff_t) secno * sector_size; 3469 fdisk_loff_t offset = (fdisk_loff_t) secno * sector_size;
3394 if (lseek(fd, offset, SEEK_SET) == (ext2_loff_t) -1) 3470 if (fdisk_llseek(fd, offset, SEEK_SET) == (fdisk_loff_t) -1)
3395 fdisk_fatal(unable_to_seek); 3471 fdisk_fatal(unable_to_seek);
3396} 3472}
3397 3473