utils_common = ../lib/blkdev.c
if LINUX
-utils_common += ../lib/linux_version.c
+utils_common += ../lib/linux_version.c
endif
-dist_man_MANS = blockdev.8 isosize.8 mkfs.8 mkswap.8 \
+dist_man_MANS = isosize.8 mkfs.8 mkswap.8 \
fsck.minix.8 mkfs.minix.8 mkfs.bfs.8
-sbin_PROGRAMS = mkfs mkswap blockdev fsck.minix mkfs.minix mkfs.bfs
+sbin_PROGRAMS = mkfs mkswap fsck.minix mkfs.minix mkfs.bfs
fsck_minix_SOURCES = fsck.minix.c bitops.h minix.h
mkfs_minix_SOURCES = mkfs.minix.c bitops.h minix.h $(utils_common)
-mkfs_bfs_SOURCES = mkfs.bfs.c
+mkfs_bfs_SOURCES = mkfs.bfs.c $(utils_common)
mkswap_SOURCES = mkswap.c swapheader.h $(utils_common)
-blockdev_SOURCES = blockdev.c $(utils_common)
usrbinexec_PROGRAMS = isosize
usrsbinexec_PROGRAMS =
if LINUX
-dist_man_MANS += fdformat.8
+dist_man_MANS += fdformat.8 blockdev.8
+sbin_PROGRAMS += blockdev
usrsbinexec_PROGRAMS += fdformat
+blockdev_SOURCES = blockdev.c $(utils_common)
endif
if BUILD_ELVTUNE
if BUILD_CRAMFS
sbin_PROGRAMS += fsck.cramfs mkfs.cramfs
-fsck_cramfs_SOURCES = fsck.cramfs.c cramfs.h
-mkfs_cramfs_SOURCES = mkfs.cramfs.c cramfs.h ../lib/md5.c
+fsck_cramfs_SOURCES = fsck.cramfs.c cramfs.h $(utils_common)
+mkfs_cramfs_SOURCES = mkfs.cramfs.c cramfs.h ../lib/md5.c $(utils_common)
fsck_cramfs_LDADD = -lz
mkfs_cramfs_LDADD = -lz
endif
#include "cramfs.h"
#include "nls.h"
-
-#define BLKGETSIZE _IO(0x12,96) /* return device size */
+#include "blkdev.h"
static const char *progname = "cramfsck";
die(FSCK_ERROR, 1, "open failed: %s", filename);
}
if (S_ISBLK(st.st_mode)) {
- if (ioctl(fd, BLKGETSIZE, length) < 0) {
+ unsigned long long bytes;
+ if (blkdev_get_size(fd, &bytes)) {
die(FSCK_ERROR, 1, "ioctl failed: unable to determine device size: %s", filename);
}
- *length = *length * 512;
+ *length = bytes;
}
else if (S_ISREG(st.st_mode)) {
*length = st.st_size;
#include <string.h>
#include <time.h>
#include "nls.h"
-
-/* cannot include <linux/fs.h> */
-#ifndef BLKGETSIZE
-#define BLKGETSIZE _IO(0x12,96) /* return device size */
-#endif
+#include "blkdev.h"
#define BFS_ROOT_INO 2
#define BFS_NAMELEN 14
main(int argc, char *argv[]) {
char *device, *volume, *fsname;
int inodes;
- unsigned long total_blocks, ino_bytes, ino_blocks, data_blocks;
- unsigned long user_specified_total_blocks = 0;
+ unsigned long long total_blocks, ino_bytes, ino_blocks, data_blocks;
+ unsigned long long user_specified_total_blocks = 0;
int verbose = 0;
int fd;
struct bfssb sb;
}
if (optind == argc-1)
- user_specified_total_blocks = atoi(argv[optind]);
+ user_specified_total_blocks = atoll(argv[optind]);
else if (optind != argc)
usage();
- if (ioctl(fd, BLKGETSIZE, &total_blocks) == -1) {
+ if (blkdev_get_sectors(fd, &total_blocks) == -1) {
if (!user_specified_total_blocks) {
- perror("BLKGETSIZE");
+ perror("blkdev_get_sectors");
fatal(_("cannot get size of %s"), device);
}
total_blocks = user_specified_total_blocks;
} else if (user_specified_total_blocks) {
if (user_specified_total_blocks > total_blocks)
- fatal(_("blocks argument too large, max is %lu"),
+ fatal(_("blocks argument too large, max is %llu"),
total_blocks);
total_blocks = user_specified_total_blocks;
}
/* mimic the behaviour of SCO's mkfs - maybe this limit is needed */
if (data_blocks < 32)
- fatal(_("not enough space, need at least %lu blocks"),
+ fatal(_("not enough space, need at least %llu blocks"),
ino_blocks + 33);
memset(&sb, 0, sizeof(sb));
fprintf(stderr, _("Inodes: %d (in 1 block)\n"),
inodes);
else
- fprintf(stderr, _("Inodes: %d (in %ld blocks)\n"),
+ fprintf(stderr, _("Inodes: %d (in %lld blocks)\n"),
inodes, ino_blocks);
- fprintf(stderr, _("Blocks: %ld\n"), total_blocks);
+ fprintf(stderr, _("Blocks: %lld\n"), total_blocks);
fprintf(stderr, _("Inode end: %d, Data end: %d\n"),
sb.s_start-1, sb.s_end);
}
printf(_("%lu bad pages\n"), badpages);
}
-static long
-valid_offset (int fd, off_t offset) {
- char ch;
-
- if (lseek (fd, offset, 0) < 0)
- return 0;
- if (read (fd, &ch, 1) < 1)
- return 0;
- return 1;
-}
-
-static off_t
-find_size (int fd) {
- off_t high, low;
-
- low = 0;
- for (high = 1; high > 0 && valid_offset (fd, high); high *= 2)
- low = high;
- while (low < high - 1) {
- const off_t mid = (low + high) / 2;
-
- if (valid_offset (fd, mid))
- low = mid;
- else
- high = mid;
- }
- return (low + 1);
-}
-
/* return size in pages, to avoid integer overflow */
static unsigned long
get_size(const char *file) {
if (blkdev_get_size(fd, &size) == 0)
size /= pagesize;
else
- size = find_size(fd) / pagesize;
+ size = blkdev_find_size(fd) / pagesize;
close(fd);
return size;