Whamcloud - gitweb
mke2fs.c (PRS, set_fs_defaults): If the sector size of the
authorTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2003 21:28:29 +0000 (17:28 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2003 21:28:29 +0000 (17:28 -0400)
device is larger than the default block size, then use the
sector size of the device as the default block size.

getsectsize.c (ext2fs_get_device_sectsize): New function which
    returns the hardware sector size (if it is available).

lib/ext2fs/ChangeLog
lib/ext2fs/Makefile.in
lib/ext2fs/ext2fs.h
lib/ext2fs/getsectsize.c [new file with mode: 0644]
lib/ext2fs/tst_getsectsize.c [new file with mode: 0644]
misc/ChangeLog
misc/mke2fs.c

index 5153d71..d9a5019 100644 (file)
@@ -1,3 +1,8 @@
+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
index 679d0d1..c99537a 100644 (file)
@@ -40,6 +40,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \
        gen_bitmap.o \
        get_pathname.o \
        getsize.o \
+       getsectsize.o \
        icount.o \
        initialize.o \
        inline.o \
@@ -91,6 +92,7 @@ SRCS= ext2_err.c \
        $(srcdir)/gen_bitmap.c \
        $(srcdir)/get_pathname.c \
        $(srcdir)/getsize.c \
+       $(srcdir)/getsectsize.c \
        $(srcdir)/icount.c \
        $(srcdir)/imager.c \
        $(srcdir)/initialize.c \
@@ -203,6 +205,10 @@ tst_bitops: tst_bitops.o inline.o $(STATIC_LIBEXT2FS)
        $(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)
 
index 926d5af..cd9344d 100644 (file)
@@ -720,6 +720,9 @@ extern void ext2fs_u32_list_free(ext2_u32_list bb);
 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);
diff --git a/lib/ext2fs/getsectsize.c b/lib/ext2fs/getsectsize.c
new file mode 100644 (file)
index 0000000..66c6df6
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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;
+}
diff --git a/lib/ext2fs/tst_getsectsize.c b/lib/ext2fs/tst_getsectsize.c
new file mode 100644 (file)
index 0000000..9967b61
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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], &sectsize);
+       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);
+}
index 22e94b2..3f94898 100644 (file)
@@ -1,3 +1,9 @@
+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
index d30729a..545ec96 100644 (file)
@@ -147,7 +147,8 @@ struct mke2fs_defaults {
 
 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;
@@ -170,6 +171,8 @@ static void set_fs_defaults(const char *fs_type,
                                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;
@@ -799,6 +802,7 @@ static void PRS(int argc, char *argv[])
        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");
@@ -1187,7 +1191,15 @@ static void PRS(int argc, char *argv[])
            ((tmp = getenv("MKE2FS_FIRST_META_BG"))))
                param.s_first_meta_bg = atoi(tmp);
 
-       set_fs_defaults(fs_type, &param, blocksize, &inode_ratio);
+       /* Get the hardware sector size, if available */
+       retval = ext2fs_get_device_sectsize(device_name, &sector_size);
+       if (retval) {
+               com_err(program_name, retval,
+                       _("while trying to determine hardware sector size"));
+               exit(1);
+       }
+       
+       set_fs_defaults(fs_type, &param, blocksize, sector_size, &inode_ratio);
        blocksize = EXT2_BLOCK_SIZE(&param);
        
        if (param.s_blocks_per_group) {