From: Karel Zak Date: Wed, 6 Dec 2006 23:26:16 +0000 (+0100) Subject: Imported from util-linux-2.12b tarball. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c129767e063c5c9839cc9d94c34fd88dac3fb9a6;p=util-linux Imported from util-linux-2.12b tarball. --- diff --git a/HISTORY b/HISTORY index 50635cda..dc378266 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,25 @@ +util-linux 2.12b + +* chsh: improved error message +* dmesg: ask kernel proper buffer size +* losetup: handle 64-bit offsets +* blockdev: also report BLKGETSIZE64 result +* blockdev, elvtune, fdisk: handle new kernel _IOR,_IOW defines +* fdisk: remove strange "ends in a digit" heuristic +* fdisk: also list Solaris as possible type for 0x82 +* mount: added --rbind option +* mount: use blkid library +* mount: support reiserfs mount by label +* mount: attempt to use the right definition of dev_t in struct loopinfo +* mount.8: jfs mount options added +* readprofile: new -s option +* rename.1: added ref to mmv.1 +* replay: renamed to scriptreplay; correct typos +* script: do not use locale for time delay floating point number format +* sfdisk: error messages to stderr +* New Catalan, Dutch, Finnish, French, German, Spanish, Swedish, Turkish, + Ukrainian messages + util-linux 2.12a * chfn, chsh, login, vipw: SElinux support diff --git a/VERSION b/VERSION index e36bb395..0841085a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.12a +2.12b diff --git a/configure b/configure index 45ba906a..354a4079 100755 --- a/configure +++ b/configure @@ -42,6 +42,7 @@ # 12. For hwclock.c: does struct tm have a field tm_gmtoff? # 13. For nfsmount: does the output of rpcgen compile? # 14. For fsck.cramfs, mkfs.cramfs: do we have libz? +# 15. For mount, do we have blkid? rm -f make_include defines.h @@ -710,3 +711,21 @@ else fi rm -f conftest conftest.c +# +# 15. For mount, do we have blkid? +# +echo ' +#include +int main(){ exit(0); blkid_known_fstype("ext2"); } +' > conftest.c +LIBS="-lblkid -luuid" +eval $compile +LIBS= +if test -s conftest; then + echo "HAVE_BLKID=yes" >> make_include + echo "You have blkid" +else + echo "HAVE_BLKID=no" >> make_include + echo "You don't have blkid" +fi +rm -f conftest conftest.c diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index b1422a82..bb11981d 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -24,8 +24,9 @@ #define BLKRASET _IO(0x12,98) #define BLKRAGET _IO(0x12,99) #define BLKSSZGET _IO(0x12,104) -#define BLKBSZGET _IOR(0x12,112,sizeof(int)) -#define BLKBSZSET _IOW(0x12,113,sizeof(int)) +#define BLKBSZGET _IOR(0x12,112,size_t) +#define BLKBSZSET _IOW(0x12,113,size_t) +#define BLKGETSIZE64 _IOR(0x12,114,size_t) #endif /* Maybe could be included */ @@ -52,6 +53,7 @@ struct bdc { #define ARGINTP 3 #define ARGINTG 4 #define ARGLINTG 5 +#define ARGLLINTG 6 long argval; char *argname; char *help; @@ -73,7 +75,10 @@ struct bdc { { "--setbsz", "BLKBSZSET", BLKBSZSET, ARGINTAP, 0, "BLOCKSIZE", N_("set blocksize") }, #endif #ifdef BLKGETSIZE - { "--getsize", "BLKGETSIZE", BLKGETSIZE, ARGLINTG, -1, NULL, N_("get size") }, + { "--getsize", "BLKGETSIZE", BLKGETSIZE, ARGLINTG, -1, NULL, N_("get 32-bit sector count") }, +#endif +#ifdef BLKGETSIZE64 + { "--getsize64", "BLKGETSIZE64", BLKGETSIZE64, ARGLLINTG, -1, NULL, N_("get size in bytes") }, #endif #ifdef BLKRASET { "--setra", "BLKRASET", BLKRASET, ARGINTA, 0, "READAHEAD", N_("set readahead") }, @@ -100,6 +105,7 @@ usage(void) { fprintf(stderr, _(" %s --report [devices]\n"), progname); fprintf(stderr, _(" %s [-v|-q] commands devices\n"), progname); fprintf(stderr, _("Available commands:\n")); + fprintf(stderr, "\t--getsz\t(%s)\n", "get size in 512-byte sectors"); for (i = 0; i < SIZE(bdcms); i++) { fprintf(stderr, "\t%s", bdcms[i].name); if (bdcms[i].argname) @@ -121,6 +127,23 @@ find_cmd(char *s) { return -1; } +static int +getsize(int fd, long long *sectors) { + int err; + long sz; + long long b; + + err = ioctl (fd, BLKGETSIZE, &sz); + if (err) + return err; + err = ioctl(fd, BLKGETSIZE64, &b); + if (err || b == 0 || b == sz) + *sectors = sz; + else + *sectors = (b >> 9); + return 0; +} + void do_commands(int fd, char **argv, int d); void report_header(void); void report_device(char *device, int quiet); @@ -174,6 +197,8 @@ main(int argc, char **argv) { d++; continue; } + if (!strcmp(argv[d], "--getsz")) + continue; if (!strcmp(argv[d], "--")) { d++; break; @@ -202,6 +227,7 @@ do_commands(int fd, char **argv, int d) { int res, i, j; int iarg; long larg; + long long llarg; int verbose = 0; for (i = 1; i < d; i++) { @@ -214,6 +240,15 @@ do_commands(int fd, char **argv, int d) { continue; } + if (!strcmp(argv[i], "--getsz")) { + res = getsize(fd, &llarg); + if (res == 0) + printf("%lld\n", llarg); + else + exit(1); + continue; + } + j = find_cmd(argv[i]); if (j == -1) { fprintf(stderr, _("%s: Unknown command: %s\n"), @@ -253,6 +288,10 @@ do_commands(int fd, char **argv, int d) { larg = bdcms[j].argval; res = ioctl(fd, bdcms[j].ioc, &larg); break; + case ARGLLINTG: + llarg = bdcms[j].argval; + res = ioctl(fd, bdcms[j].ioc, &llarg); + break; } if (res == -1) { perror(bdcms[j].iocname); @@ -273,6 +312,12 @@ do_commands(int fd, char **argv, int d) { else printf("%ld\n", larg); break; + case ARGLLINTG: + if (verbose) + printf("%s: %lld\n", _(bdcms[j].help), llarg); + else + printf("%lld\n", llarg); + break; default: if (verbose) printf(_("%s succeeded.\n"), _(bdcms[j].help)); @@ -312,7 +357,8 @@ void report_device(char *device, int quiet) { int fd; int ro, ssz, bsz; - long ra, sz, ss; + long ra, ss; + long long bytes; struct hd_geometry g; fd = open(device, O_RDONLY | O_NONBLOCK); @@ -324,15 +370,15 @@ report_device(char *device, int quiet) { } ro = ssz = bsz = 0; - g.start = ra = sz = ss = 0; + g.start = ra = ss = 0; if (ioctl (fd, BLKROGET, &ro) == 0 && ioctl (fd, BLKRAGET, &ra) == 0 && ioctl (fd, BLKSSZGET, &ssz) == 0 && ioctl (fd, BLKBSZGET, &bsz) == 0 && - ioctl (fd, BLKGETSIZE, &sz) == 0 && - ioctl (fd, HDIO_GETGEO, &g) == 0) { - printf("%s %5ld %5d %5d %10ld %10ld %s\n", - ro ? "ro" : "rw", ra, ssz, bsz, g.start, sz, device); + ioctl (fd, HDIO_GETGEO, &g) == 0 && + getsize (fd, &bytes) == 0) { + printf("%s %5ld %5d %5d %10ld %10lld %s\n", + ro ? "ro" : "rw", ra, ssz, bsz, g.start, bytes, device); } else { if (!quiet) fprintf(stderr, _("%s: ioctl error on %s\n"), diff --git a/disk-utils/elvtune.c b/disk-utils/elvtune.c index 2c49b444..a727745c 100644 --- a/disk-utils/elvtune.c +++ b/disk-utils/elvtune.c @@ -37,8 +37,8 @@ typedef struct blkelv_ioctl_arg_s { int max_bomb_segments; } blkelv_ioctl_arg_t; -#define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t)) -#define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t)) +#define BLKELVGET _IOR(0x12,106,size_t) +#define BLKELVSET _IOW(0x12,107,size_t) static void usage(void) { diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c index 2a109b84..808ae22c 100644 --- a/disk-utils/fsck.minix.c +++ b/disk-utils/fsck.minix.c @@ -99,10 +99,6 @@ #include "minix.h" #include "nls.h" -#ifdef MINIX2_SUPER_MAGIC2 -#define HAVE_MINIX2 1 -#endif - #ifndef __linux__ #define volatile #endif @@ -111,13 +107,9 @@ #define UPPER(size,n) ((size+((n)-1))/(n)) #define INODE_SIZE (sizeof(struct minix_inode)) -#ifdef HAVE_MINIX2 #define INODE_SIZE2 (sizeof(struct minix2_inode)) #define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ : MINIX_INODES_PER_BLOCK)) -#else -#define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK)) -#endif #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) #define BITS_PER_BLOCK (BLOCK_SIZE<<3) @@ -152,11 +144,7 @@ static char * inode_buffer = NULL; static char super_block_buffer[BLOCK_SIZE]; #define Super (*(struct minix_super_block *)super_block_buffer) #define INODES ((unsigned long)Super.s_ninodes) -#ifdef HAVE_MINIX2 #define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones)) -#else -#define ZONES ((unsigned long)(Super.s_nzones)) -#endif #define IMAPS ((unsigned long)Super.s_imap_blocks) #define ZMAPS ((unsigned long)Super.s_zmap_blocks) #define FIRSTZONE ((unsigned long)Super.s_firstdatazone) @@ -172,9 +160,7 @@ static unsigned char * inode_count = NULL; static unsigned char * zone_count = NULL; static void recursive_check(unsigned int ino); -#ifdef HAVE_MINIX2 static void recursive_check2(unsigned int ino); -#endif #include "bitops.h" @@ -345,7 +331,6 @@ check_zone_nr(unsigned short * nr, int * corrected) { return 0; } -#ifdef HAVE_MINIX2 static int check_zone_nr2 (unsigned int *nr, int *corrected) { if (!*nr) @@ -368,7 +353,6 @@ check_zone_nr2 (unsigned int *nr, int *corrected) { } return 0; } -#endif /* * read-block reads block nr into the buffer at addr. @@ -456,7 +440,6 @@ map_block(struct minix_inode * inode, unsigned int blknr) { return result; } -#ifdef HAVE_MINIX2 static int map_block2 (struct minix2_inode *inode, unsigned int blknr) { unsigned int ind[BLOCK_SIZE >> 2]; @@ -513,7 +496,6 @@ map_block2 (struct minix2_inode *inode, unsigned int blknr) { write_block (block, (char *) ind); return result; } -#endif static void write_super_block(void) { @@ -554,11 +536,9 @@ get_dirsize (void) { char blk[BLOCK_SIZE]; int size; -#if HAVE_MINIX2 if (version2) block = Inode2[ROOT_INO].i_zone[0]; else -#endif block = Inode[ROOT_INO].i_zone[0]; read_block (block, blk); for (size = 16; size < BLOCK_SIZE; size <<= 1) { @@ -585,7 +565,6 @@ read_superblock(void) { namelen = 30; dirsize = 32; version2 = 0; -#ifdef HAVE_MINIX2 } else if (MAGIC == MINIX2_SUPER_MAGIC) { namelen = 14; dirsize = 16; @@ -594,7 +573,6 @@ read_superblock(void) { namelen = 30; dirsize = 32; version2 = 1; -#endif } else die(_("bad magic number in super-block")); if (ZONESIZE != 0 || BLOCK_SIZE != 1024) @@ -697,7 +675,6 @@ get_inode(unsigned int nr) { return inode; } -#ifdef HAVE_MINIX2 static struct minix2_inode * get_inode2 (unsigned int nr) { struct minix2_inode *inode; @@ -745,7 +722,6 @@ get_inode2 (unsigned int nr) { } return inode; } -#endif static void check_root(void) { @@ -755,7 +731,6 @@ check_root(void) { die(_("root inode isn't a directory")); } -#ifdef HAVE_MINIX2 static void check_root2 (void) { struct minix2_inode *inode = Inode2 + ROOT_INO; @@ -763,7 +738,6 @@ check_root2 (void) { if (!inode || !S_ISDIR (inode->i_mode)) die ("root inode isn't a directory"); } -#endif static int add_zone(unsigned short * znr, int * corrected) { @@ -798,7 +772,6 @@ add_zone(unsigned short * znr, int * corrected) { return block; } -#ifdef HAVE_MINIX2 static int add_zone2 (unsigned int *znr, int *corrected) { int result; @@ -831,7 +804,6 @@ add_zone2 (unsigned int *znr, int *corrected) { zone_count[block]--; return block; } -#endif static void add_zone_ind(unsigned short * znr, int * corrected) { @@ -849,7 +821,6 @@ add_zone_ind(unsigned short * znr, int * corrected) { write_block(block, blk); } -#ifdef HAVE_MINIX2 static void add_zone_ind2 (unsigned int *znr, int *corrected) { static char blk[BLOCK_SIZE]; @@ -865,7 +836,6 @@ add_zone_ind2 (unsigned int *znr, int *corrected) { if (chg_blk) write_block (block, blk); } -#endif static void add_zone_dind(unsigned short * znr, int * corrected) { @@ -883,7 +853,6 @@ add_zone_dind(unsigned short * znr, int * corrected) { write_block(block, blk); } -#ifdef HAVE_MINIX2 static void add_zone_dind2 (unsigned int *znr, int *corrected) { static char blk[BLOCK_SIZE]; @@ -915,7 +884,6 @@ add_zone_tind2 (unsigned int *znr, int *corrected) { if (blk_chg) write_block (block, blk); } -#endif static void check_zones(unsigned int i) { @@ -935,7 +903,6 @@ check_zones(unsigned int i) { add_zone_dind(8 + inode->i_zone, &changed); } -#ifdef HAVE_MINIX2 static void check_zones2 (unsigned int i) { struct minix2_inode *inode; @@ -954,7 +921,6 @@ check_zones2 (unsigned int i) { add_zone_dind2 (8 + inode->i_zone, &changed); add_zone_tind2 (9 + inode->i_zone, &changed); } -#endif static void check_file(struct minix_inode * dir, unsigned int offset) { @@ -1023,7 +989,6 @@ check_file(struct minix_inode * dir, unsigned int offset) { return; } -#ifdef HAVE_MINIX2 static void check_file2 (struct minix2_inode *dir, unsigned int offset) { static char blk[BLOCK_SIZE]; @@ -1090,7 +1055,6 @@ check_file2 (struct minix2_inode *dir, unsigned int offset) { name_depth--; return; } -#endif static void recursive_check(unsigned int ino) { @@ -1110,7 +1074,6 @@ recursive_check(unsigned int ino) { check_file(dir,offset); } -#ifdef HAVE_MINIX2 static void recursive_check2 (unsigned int ino) { struct minix2_inode *dir; @@ -1128,7 +1091,6 @@ recursive_check2 (unsigned int ino) { for (offset = 0; offset < dir->i_size; offset += dirsize) check_file2 (dir, offset); } -#endif static int bad_zone(int i) { @@ -1194,7 +1156,6 @@ check_counts(void) { } } -#ifdef HAVE_MINIX2 static void check_counts2 (void) { int i; @@ -1249,7 +1210,6 @@ check_counts2 (void) { i, zone_count[i]); } } -#endif static void check(void) { @@ -1260,7 +1220,6 @@ check(void) { check_counts(); } -#ifdef HAVE_MINIX2 static void check2 (void) { memset (inode_count, 0, (INODES + 1) * sizeof (*inode_count)); @@ -1269,7 +1228,6 @@ check2 (void) { recursive_check2 (ROOT_INO); check_counts2 (); } -#endif int main(int argc, char ** argv) { @@ -1294,10 +1252,9 @@ main(int argc, char ** argv) { if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) die(_("bad inode size")); -#ifdef HAVE_MINIX2 if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) die(_("bad v2 inode size")); -#endif + while (argc-- > 1) { argv++; if (argv[0][0] != '-') { @@ -1360,13 +1317,10 @@ main(int argc, char ** argv) { termios_set = 1; } -#if HAVE_MINIX2 if (version2) { check_root2 (); check2 (); - } else -#endif - { + } else { check_root(); check(); } diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index f399684a..14cf6fa6 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -79,10 +79,6 @@ #define BLKGETSIZE _IO(0x12,96) /* return device size */ #endif -#ifdef MINIX2_SUPER_MAGIC2 -#define HAVE_MINIX2 1 -#endif - #ifndef __GNUC__ #error "needs gcc for the bitop-__asm__'s" #endif @@ -95,13 +91,10 @@ #define UPPER(size,n) ((size+((n)-1))/(n)) #define INODE_SIZE (sizeof(struct minix_inode)) -#ifdef HAVE_MINIX2 + #define INODE_SIZE2 (sizeof(struct minix2_inode)) #define INODE_BLOCKS UPPER(INODES, (version2 ? MINIX2_INODES_PER_BLOCK \ : MINIX_INODES_PER_BLOCK)) -#else -#define INODE_BLOCKS UPPER(INODES, (MINIX_INODES_PER_BLOCK)) -#endif #define INODE_BUFFER_SIZE (INODE_BLOCKS * BLOCK_SIZE) #define BITS_PER_BLOCK (BLOCK_SIZE<<3) @@ -122,18 +115,13 @@ static char root_block[BLOCK_SIZE] = "\0"; static char * inode_buffer = NULL; #define Inode (((struct minix_inode *) inode_buffer)-1) -#ifdef HAVE_MINIX2 #define Inode2 (((struct minix2_inode *) inode_buffer)-1) -#endif + static char super_block_buffer[BLOCK_SIZE]; static char boot_block_buffer[512]; #define Super (*(struct minix_super_block *)super_block_buffer) #define INODES ((unsigned long)Super.s_ninodes) -#ifdef HAVE_MINIX2 #define ZONES ((unsigned long)(version2 ? Super.s_zones : Super.s_nzones)) -#else -#define ZONES ((unsigned long)(Super.s_nzones)) -#endif #define IMAPS ((unsigned long)Super.s_imap_blocks) #define ZMAPS ((unsigned long)Super.s_zmap_blocks) #define FIRSTZONE ((unsigned long)Super.s_firstdatazone) @@ -368,7 +356,6 @@ end_bad: write_block(dind, (char *) dind_block); } -#ifdef HAVE_MINIX2 static void make_bad_inode2 (void) { struct minix2_inode *inode = &Inode2[MINIX_BAD_INO]; @@ -417,7 +404,6 @@ make_bad_inode2 (void) { if (dind) write_block (dind, (char *) dind_block); } -#endif static void make_root_inode(void) { @@ -441,7 +427,6 @@ make_root_inode(void) { write_block(inode->i_zone[0],root_block); } -#ifdef HAVE_MINIX2 static void make_root_inode2 (void) { struct minix2_inode *inode = &Inode2[MINIX_ROOT_INO]; @@ -463,7 +448,6 @@ make_root_inode2 (void) { inode->i_gid = getgid(); write_block (inode->i_zone[0], root_block); } -#endif static void setup_tables(void) { @@ -472,10 +456,13 @@ setup_tables(void) { memset(super_block_buffer,0,BLOCK_SIZE); memset(boot_block_buffer,0,512); - MAGIC = magic; - ZONESIZE = 0; - MAXSIZE = version2 ? 0x7fffffff : (7+512+512*512)*1024; - ZONES = BLOCKS; + Super.s_magic = magic; + Super.s_log_zone_size = 0; + Super.s_max_size = version2 ? 0x7fffffff : (7+512+512*512)*1024; + if (version2) + Super.s_zones = BLOCKS; + else + Super.s_nzones = BLOCKS; /* some magic nrs: 1 inode / 3 blocks */ if ( req_nr_inodes == 0 ) @@ -483,26 +470,27 @@ setup_tables(void) { else inodes = req_nr_inodes; /* Round up inode count to fill block size */ -#ifdef HAVE_MINIX2 if (version2) inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) & ~(MINIX2_INODES_PER_BLOCK - 1)); else -#endif inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) & ~(MINIX_INODES_PER_BLOCK - 1)); if (inodes > 65535) inodes = 65535; - INODES = inodes; - IMAPS = UPPER(INODES + 1,BITS_PER_BLOCK); - ZMAPS = UPPER(BLOCKS - (1+IMAPS+INODE_BLOCKS), BITS_PER_BLOCK+1); + Super.s_ninodes = inodes; + /* The old code here * ZMAPS = 0; * while (ZMAPS != UPPER(BLOCKS - NORM_FIRSTZONE + 1,BITS_PER_BLOCK)) * ZMAPS = UPPER(BLOCKS - NORM_FIRSTZONE + 1,BITS_PER_BLOCK); * was no good, since it may loop. - aeb */ - FIRSTZONE = NORM_FIRSTZONE; + Super.s_imap_blocks = UPPER(INODES + 1, BITS_PER_BLOCK); + Super.s_zmap_blocks = UPPER(BLOCKS - (1+IMAPS+INODE_BLOCKS), + BITS_PER_BLOCK+1); + Super.s_firstdatazone = NORM_FIRSTZONE; + inode_map = malloc(IMAPS * BLOCK_SIZE); zone_map = malloc(ZMAPS * BLOCK_SIZE); if (!inode_map || !zone_map) @@ -641,10 +629,9 @@ main(int argc, char ** argv) { if (INODE_SIZE * MINIX_INODES_PER_BLOCK != BLOCK_SIZE) die(_("bad inode size")); -#ifdef HAVE_MINIX2 if (INODE_SIZE2 * MINIX2_INODES_PER_BLOCK != BLOCK_SIZE) die(_("bad inode size")); -#endif + opterr = 0; while ((i = getopt(argc, argv, "ci:l:n:v")) != -1) switch (i) { @@ -669,12 +656,6 @@ main(int argc, char ** argv) { dirsize = i+2; break; case 'v': -#ifndef HAVE_MINIX2 - fprintf(stderr, - _("%s: not compiled with minix v2 support\n"), - program_name); - exit(-1); -#endif version2 = 1; break; default: @@ -700,14 +681,12 @@ main(int argc, char ** argv) { if (!device_name || BLOCKS<10) { usage(); } -#ifdef HAVE_MINIX2 if (version2) { if (namelen == 14) magic = MINIX2_SUPER_MAGIC; else magic = MINIX2_SUPER_MAGIC2; } else -#endif if (BLOCKS > 65535) BLOCKS = 65535; check_mount(); /* is it already mounted? */ @@ -734,16 +713,13 @@ main(int argc, char ** argv) { check_blocks(); else if (listfile) get_list_blocks(listfile); -#ifdef HAVE_MINIX2 if (version2) { make_root_inode2 (); make_bad_inode2 (); - } else -#endif - { + } else { make_root_inode(); make_bad_inode(); - } + } mark_good_blocks(); write_tables(); return 0; diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 31ddd7e7..9be1c707 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -2574,13 +2574,14 @@ draw_screen(void) { mvaddstr(HEADER_START+2, (COLS-strlen(line))/2, line); { long long bytes = actual_size*(long long) SECTOR_SIZE; - long long megabytes = bytes/1000000; + long long megabytes = bytes/(K*K); + if (megabytes < 10000) sprintf(line, _("Size: %lld bytes, %lld MB"), bytes, megabytes); else sprintf(line, _("Size: %lld bytes, %lld.%lld GB"), - bytes, megabytes/1000, (megabytes/100)%10); + bytes, megabytes/K, (10*megabytes/K)%10); } mvaddstr(HEADER_START+3, (COLS-strlen(line))/2, line); sprintf(line, _("Heads: %d Sectors per Track: %d Cylinders: %lld"), diff --git a/fdisk/common.h b/fdisk/common.h index f3886395..a2b9f1cd 100644 --- a/fdisk/common.h +++ b/fdisk/common.h @@ -6,7 +6,7 @@ #define BLKGETSIZE _IO(0x12,96) /* return device size */ #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ #define BLKSSZGET _IO(0x12,104) /* get block device sector size */ -#define BLKGETSIZE64 _IOR(0x12,114,8) /* 8 = sizeof(u64) */ +#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* size in bytes */ /* including also fails */ struct hd_geometry { diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 9ef071ca..bf2cdded 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -766,6 +766,26 @@ get_kernel_geometry(int fd) { #endif } +static int +is_probably_full_disk(char *name) { +#ifdef HDIO_GETGEO + struct hd_geometry geometry; + int fd, i = 0; + + fd = open(name, O_RDONLY); + if (fd >= 0) { + i = ioctl(fd, HDIO_GETGEO, &geometry); + close(fd); + } + return (fd >= 0 && i == 0 && geometry.start == 0); +#else + /* silly heuristic */ + while (*name) + name++; + return !isdigit(name[-1]); +#endif +} + static void get_partition_table_geometry(void) { unsigned char *bufp = MBRbuffer; @@ -862,6 +882,8 @@ get_boot(enum action what) { int i; partitions = 4; + ext_index = 0; + extended_offset = 0; for (i = 0; i < 4; i++) { struct pte *pe = &ptes[i]; @@ -1044,8 +1066,8 @@ read_hex(struct systypes *sys) } /* - * Print the message MESG, then read an integer between LOW and HIGH (inclusive). - * If the user hits Enter, DFLT is returned. + * Print the message MESG, then read an integer in LOW..HIGH. + * If the user hits Enter, DFLT is returned, provided that is in LOW..HIGH. * Answers like +10 are interpreted as offsets from BASE. * * There is no default if DFLT is not between LOW and HIGH. @@ -2359,23 +2381,17 @@ try(char *device, int user_specified) { return; if ((fd = open(disk_device, type_open)) >= 0) { gb = get_boot(try_only); - if (gb > 0) { /* I/O error */ - close(fd); + if (gb > 0) { /* I/O error */ } else if (gb < 0) { /* no DOS signature */ list_disk_geometry(); - if (aix_label) - return; - if (btrydev(device) < 0) + if (!aix_label && btrydev(device) < 0) fprintf(stderr, _("Disk %s doesn't contain a valid " "partition table\n"), device); - close(fd); } else { - close(fd); list_table(0); - if (!sun_label && partitions > 4) - delete_partition(ext_index); } + close(fd); } else { /* Ignore other errors, since we try IDE and SCSI hard disks which may not be @@ -2387,12 +2403,14 @@ try(char *device, int user_specified) { } } -/* for fdisk -l: try all things in /proc/partitions - that look like a partition name (do not end in a digit) */ +/* + * for fdisk -l: + * try all things in /proc/partitions that look like a full disk + */ static void tryprocpt(void) { FILE *procpt; - char line[100], ptname[100], devname[120], *s; + char line[100], ptname[100], devname[120]; int ma, mi, sz; procpt = fopen(PROC_PARTITIONS, "r"); @@ -2405,11 +2423,9 @@ tryprocpt(void) { if (sscanf (line, " %d %d %d %[^\n ]", &ma, &mi, &sz, ptname) != 4) continue; - for (s = ptname; *s; s++); - if (isdigit(s[-1])) - continue; snprintf(devname, sizeof(devname), "/dev/%s", ptname); - try(devname, 0); + if (is_probably_full_disk(devname)) + try(devname, 0); } fclose(procpt); } @@ -2504,11 +2520,11 @@ main(int argc, char **argv) { variable `k' might be clobbered by `longjmp' */ dummy(&k); listing = 1; - for (k=optind; k