Re: e2fs block to physical block translation

From: Andreas Dilger (adilger@turbolinux.com)
Date: Tue Dec 12 2000 - 01:18:06 EST


Al Peat writes:
> Quick question about blocks:
>
> If I assume my hard drive uses 512 blocks, and my
> ext2 filesystem uses 4k blocks, can I assume the
> following formula for translation?
>
> physical block # / 8 = e2fs block #

It really depends on what you are calculating. Ext2 uses "fs blocksize"
blocks for most things (i.e. absolute block number in the filesystem,
filesystem size, blocks per group, etc) but not for the inode blocks count
(for a reason I don't understand). The inode i_blocks count is always
in 512-byte blocks from what I've seen. This value _may_ be in "sector"
sized blocks, but I've never tried ext2 on a non-512-byte sector device.
In any case, there is a lot of ">> 9" and "/ 512" stuff in the ext2
code and e2fsprogs, so it would probably break anyways. This limits
ext2 files to 2TB.

On that note, we need a patch to the ext2/ext3 code which limits the
file size to (2^32 - 1 filesystem block) 512-byte blocks (as imposed by
the i_blocks field). This is only a limitation for 4kB and 8kB block
ext2 filesystems. We currently don't have to worry about this limit
because the kernel block device layer imposes a 2TB limit on the whole
filesystem, but better to be correct now than bug hunt a rare case later.

Single File Limits (in GB, * = real limit) 1k 2k 4k 8k
========================================== ==== ==== ==== =====
By {,in,double-in,triple-in}direct blocks: 16* 256* 4100 65568
By i_blocks (2^32 - 1 fs block)*512 bytes: 2048 2048 2048* 2048*

The patch is for 2.4.0-test12, but is the same for 2.2.18 (excluding context).
Ted or Stephen, can you please forward to Linus and Alan, since they appear
never to accept patches from me directly.

Cheers, Andreas
==============================================================================
--- fs/ext2/file.c.orig Tue Jan 4 11:12:23 2000
+++ fs/ext2/file.c Mon Dec 11 21:08:43 2000
@@ -44,11 +44,11 @@
 static loff_t ext2_file_lseek(struct file *, loff_t, int);
 static int ext2_open_file (struct inode *, struct file *);
 
-#define EXT2_MAX_SIZE(bits) \
- (((EXT2_NDIR_BLOCKS + (1LL << (bits - 2)) + \
- (1LL << (bits - 2)) * (1LL << (bits - 2)) + \
- (1LL << (bits - 2)) * (1LL << (bits - 2)) * (1LL << (bits - 2))) * \
- (1LL << bits)) - 1)
+#define EXT2_MAX_SIZE(bits) \
+ MIN(((EXT2_NDIR_BLOCKS + (1LL << (bits - 2)) + \
+ (1LL << (bits - 2)) * (1LL << (bits - 2)) + \
+ (1LL << (bits - 2)) * (1LL << (bits - 2)) * (1LL << (bits - 2))) * \
+ (1LL << bits)) - 1, 512LL * ((1LL << 32) - (1LL << (bits - 9)))
 
 static long long ext2_max_sizes[] = {
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

-- 
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Dec 15 2000 - 21:00:23 EST