summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:26:16 +0100
committerKarel Zak2006-12-07 00:26:16 +0100
commitc129767e063c5c9839cc9d94c34fd88dac3fb9a6 (patch)
tree13dd85577b43ec1be3cf51a8d913282c2a92259c /disk-utils
parentImported from util-linux-2.12a tarball. (diff)
downloadkernel-qcow2-util-linux-c129767e063c5c9839cc9d94c34fd88dac3fb9a6.tar.gz
kernel-qcow2-util-linux-c129767e063c5c9839cc9d94c34fd88dac3fb9a6.tar.xz
kernel-qcow2-util-linux-c129767e063c5c9839cc9d94c34fd88dac3fb9a6.zip
Imported from util-linux-2.12b tarball.
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/blockdev.c64
-rw-r--r--disk-utils/elvtune.c4
-rw-r--r--disk-utils/fsck.minix.c50
-rw-r--r--disk-utils/mkfs.minix.c62
4 files changed, 78 insertions, 102 deletions
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index b1422a823..bb11981db 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 <linux/hdreg.h> 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 2c49b4440..a727745c9 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 2a109b84e..808ae22cf 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 f399684af..14cf6fa65 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;