Skip to contentSkip to conversation

e2fs block to physical block translation

DISCUSSION Al Peat 3 participants 3 messages Dec 12, 2000

lore
Share & tools
lore

Al Peat

author
#0 lore raw

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 #

Thanks,
Al

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw

[Al Peat]

Quoted 7 lines

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 #

Not if you have a partition table. If you take into account the individual partition offset, I think your formula is ok.

On a floppy (no partition table) you'd be fine.

It's not always that easy, of course. Think of RAID (logical block mapping can be a complex formula), LVM (the mapping is stored in a table in the volume group metadata), CD-ROMs (what exactly do you mean by "block"...?) and other such.

Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
In reply to Al Peat
Quoted 7 lines · Al Peat

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
==============================================================================

ext2/file.c renamed from ext2/file.c.orig +5 -5
@@ -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, 
Signature · 7 lines
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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/