From 135282539b83f33735746939cd0c4fb99f78db3b Mon Sep 17 00:00:00 2001 From: antona Date: Fri, 3 Feb 2006 23:11:35 +0000 Subject: [PATCH] Fixes to previous commit. --- include/ntfs/device.h | 5 +++++ libntfs/device.c | 9 ++++++--- libntfs/unix_io.c | 5 ++++- ntfsprogs/mkntfs.c | 11 ++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/ntfs/device.h b/include/ntfs/device.h index 304445ff..eeadf13e 100644 --- a/include/ntfs/device.h +++ b/include/ntfs/device.h @@ -40,6 +40,7 @@ typedef enum { ND_Open, /* 1: Device is open. */ ND_ReadOnly, /* 1: Device is read-only. */ ND_Dirty, /* 1: Device is dirty, needs sync. */ + ND_Block, /* 1: Device is a block device. */ } ntfs_device_state_bits; #define test_ndev_flag(nd, flag) test_bit(ND_##flag, (nd)->d_state) @@ -58,6 +59,10 @@ typedef enum { #define NDevSetDirty(nd) set_ndev_flag(nd, Dirty) #define NDevClearDirty(nd) clear_ndev_flag(nd, Dirty) +#define NDevBlock(nd) test_ndev_flag(nd, Block) +#define NDevSetBlock(nd) set_ndev_flag(nd, Block) +#define NDevClearBlock(nd) clear_ndev_flag(nd, Block) + /** * struct ntfs_device - * diff --git a/libntfs/device.c b/libntfs/device.c index 968c2076..27bdf5e0 100644 --- a/libntfs/device.c +++ b/libntfs/device.c @@ -671,7 +671,8 @@ int ntfs_device_sector_size_get(struct ntfs_device *dev) int sect_size = 0; if (!dev->d_ops->ioctl(dev, BLKSSZGET, §_size)) { - ntfs_log_debug("BLKSSZGET sector size = %d bytes\n", sect_size); + ntfs_log_debug("BLKSSZGET sector size = %d bytes\n", + sect_size); return sect_size; } } @@ -705,13 +706,15 @@ int ntfs_device_block_size_set(struct ntfs_device *dev, int block_size) size_t s_block_size = block_size; if (!dev->d_ops->ioctl(dev, BLKBSZSET, &s_block_size)) { ntfs_log_debug("Used BLKBSZSET to set block size to " - "%d bytes\n", block_size); + "%d bytes.\n", block_size); return 0; } + /* If not a block device, pretend it was successful. */ + if (!NDevBlock(dev)) + return 0; } #else errno = EOPNOTSUPP; #endif return -1; } - diff --git a/libntfs/unix_io.c b/libntfs/unix_io.c index 6ff72e2b..5cfbeee0 100644 --- a/libntfs/unix_io.c +++ b/libntfs/unix_io.c @@ -79,6 +79,7 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) { struct flock flk; + struct stat sbuf; int err; if (NDevOpen(dev)) { @@ -116,6 +117,9 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) "close %s", dev->d_name); goto err_out; } + /* Determine if device is a block device or not, ignoring errors. */ + if (!fstat(DEV_FD(dev), &sbuf) && S_ISBLK(sbuf.st_mode)) + NDevSetBlock(dev); /* Set our open flag. */ NDevSetOpen(dev); return 0; @@ -317,4 +321,3 @@ struct ntfs_device_operations ntfs_device_unix_io_ops = { .stat = ntfs_device_unix_io_stat, .ioctl = ntfs_device_unix_io_ioctl, }; - diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index ce8d08ae..7a5afd05 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -3745,8 +3745,8 @@ static BOOL mkntfs_override_vol_params(ntfs_volume *vol) * "inode size" can be specified on other Linux/Unix file systems. */ vol->mft_record_size = 1024; - if (vol->mft_record_size < vol->sector_size) - vol->mft_record_size = vol->sector_size; + if (vol->mft_record_size < opts.sector_size) + vol->mft_record_size = opts.sector_size; if (vol->mft_record_size > (unsigned long)page_size) ntfs_log_warning("Mft record size (%u bytes) exceeds system " "page size (%li bytes). You will not be able " @@ -3763,8 +3763,8 @@ static BOOL mkntfs_override_vol_params(ntfs_volume *vol) * FIXME: Should we make the index record size to be user specifiable? */ vol->indx_record_size = 4096; - if (vol->indx_record_size < vol->sector_size) - vol->indx_record_size = vol->sector_size; + if (vol->indx_record_size < opts.sector_size) + vol->indx_record_size = opts.sector_size; if (vol->indx_record_size > (unsigned long)page_size) ntfs_log_warning("Index record size (%u bytes) exceeds system " "page size (%li bytes). You will not be able " @@ -3893,7 +3893,8 @@ static BOOL mkntfs_initialize_rl_mft(void) g_mft_zone_end = g_mft_zone_end >> 3; /* 12.5% */ break; } - ntfs_log_debug("MFT zone size = %lldkiB\n", g_mft_zone_end / 1024); + ntfs_log_debug("MFT zone size = %lldkiB\n", g_mft_zone_end << + g_vol->cluster_size_bits >> 10 /* >> 10 == / 1024 */); /* * The mft zone begins with the mft data attribute, not at the beginning * of the device.