+2003-05-21 Theodore Ts'o <tytso@mit.edu>
+
+ * getsectsize.c (ext2fs_get_device_sectsize): New function which
+ returns the hardware sector size (if it is available).
+
2003-05-13 Theodore Ts'o <tytso@mit.edu>
* unix_io.c: Add #ifdef NO_IO_CACHE which disables all userspace
gen_bitmap.o \
get_pathname.o \
getsize.o \
+ getsectsize.o \
icount.o \
initialize.o \
inline.o \
$(srcdir)/gen_bitmap.c \
$(srcdir)/get_pathname.c \
$(srcdir)/getsize.c \
+ $(srcdir)/getsectsize.c \
$(srcdir)/icount.c \
$(srcdir)/imager.c \
$(srcdir)/initialize.c \
$(CC) -o tst_bitops tst_bitops.o inline.o \
$(STATIC_LIBEXT2FS) $(LIBCOM_ERR)
+tst_getsectsize: tst_getsectsize.o getsectsize.o $(STATIC_LIBEXT2FS)
+ $(CC) -o tst_sectgetsize tst_getsectsize.o getsectsize.o \
+ -DDEBUG $(STATIC_LIBEXT2FS) $(LIBCOM_ERR)
+
mkjournal: mkjournal.c $(STATIC_LIBEXT2FS)
$(CC) -o mkjournal $(srcdir)/mkjournal.c -DDEBUG $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(ALL_CFLAGS)
extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
blk_t *retblocks);
+/* getsectsize.c */
+errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize);
+
/* imager.c */
extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
--- /dev/null
+/*
+ * getsectsize.c --- get the sector size of a device.
+ *
+ * Copyright (C) 1995, 1995 Theodore Ts'o.
+ * Copyright (C) 2003 VMware, Inc.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#define _LARGEFILE_SOURCE
+#define _LARGEFILE64_SOURCE
+
+#include <stdio.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <fcntl.h>
+#ifdef HAVE_LINUX_FD_H
+#include <sys/ioctl.h>
+#include <linux/fd.h>
+#endif
+
+#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
+#define BLKSSZGET _IO(0x12,104)/* get block device sector size */
+#endif
+
+#include "ext2_fs.h"
+#include "ext2fs.h"
+
+/*
+ * Returns the number of blocks in a partition
+ */
+errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
+{
+ int fd;
+
+#ifdef HAVE_OPEN64
+ fd = open64(file, O_RDONLY);
+#else
+ fd = open(file, O_RDONLY);
+#endif
+ if (fd < 0)
+ return errno;
+
+#ifdef BLKSSZGET
+ if (ioctl(fd, BLKSSZGET, sectsize) >= 0) {
+ close(fd);
+ return 0;
+ }
+#endif
+ *sectsize = 0;
+ close(fd);
+ return 0;
+}
--- /dev/null
+/*
+ * tst_getsize.c --- this function tests the getsize function
+ *
+ * Copyright (C) 1997 by Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#include <string.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <fcntl.h>
+#include <time.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include "ext2_fs.h"
+#include "ext2fs.h"
+
+int main(int argc, char **argv)
+{
+ int sectsize;
+ int retval;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s device\n", argv[0]);
+ exit(1);
+ }
+
+ retval = ext2fs_get_device_sectsize(argv[1], §size);
+ if (retval) {
+ com_err(argv[0], retval,
+ "while calling ext2fs_get_device_sectsize");
+ exit(1);
+ }
+ printf("Device %s has a hardware sector size of %d.\n",
+ argv[1], sectsize);
+ exit(0);
+}
+2003-05-21 Theodore Ts'o <tytso@mit.edu>
+
+ * mke2fs.c (PRS, set_fs_defaults): If the sector size of the
+ device is larger than the default block size, then use the
+ sector size of the device as the default block size.
+
2003-05-18 Theodore Ts'o <tytso@mit.edu>
* badblocks.c: Use an unsigned integer to support 4-byte test
static void set_fs_defaults(const char *fs_type,
struct ext2_super_block *super,
- int blocksize, int *inode_ratio)
+ int blocksize, int sector_size,
+ int *inode_ratio)
{
int megs;
int ratio = 0;
blocksize : p->inode_ratio;
use_bsize = p->blocksize;
}
+ if (use_bsize < sector_size)
+ use_bsize = sector_size;
if (blocksize <= 0) {
if (use_bsize == DEF_MAX_BLOCKSIZE)
use_bsize = sys_page_size;
int inode_ratio = 0;
int inode_size = 0;
int reserved_ratio = 5;
+ int sector_size = 0;
ext2_ino_t num_inodes = 0;
errcode_t retval;
char * oldpath = getenv("PATH");
((tmp = getenv("MKE2FS_FIRST_META_BG"))))
param.s_first_meta_bg = atoi(tmp);
- set_fs_defaults(fs_type, ¶m, blocksize, &inode_ratio);
+ /* Get the hardware sector size, if available */
+ retval = ext2fs_get_device_sectsize(device_name, §or_size);
+ if (retval) {
+ com_err(program_name, retval,
+ _("while trying to determine hardware sector size"));
+ exit(1);
+ }
+
+ set_fs_defaults(fs_type, ¶m, blocksize, sector_size, &inode_ratio);
blocksize = EXT2_BLOCK_SIZE(¶m);
if (param.s_blocks_per_group) {