Page MenuHomeFreeBSD

D52120.id160811.diff
No OneTemporary

D52120.id160811.diff

diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -623,18 +623,40 @@
} while (0);
#define ADDSIZE(x) do { \
- if ((size_t)(x) < UFS_NDADDR * (size_t)ffs_opts->bsize) { \
+ /* (UFS_NDADDR - 1) full blocks + 1 fragment at most */ \
+ if ((size_t)(x) < ffs_opts->fsize + \
+ (UFS_NDADDR - 1) * (size_t)ffs_opts->bsize) { \
fsopts->size += roundup((x), ffs_opts->fsize); \
- } else { \
- /* Count space consumed by indirecttion blocks. */ \
- fsopts->size += ffs_opts->bsize * \
- (howmany((x), UFS_NDADDR * ffs_opts->bsize) - 1); \
- /* \
- * If the file is big enough to use indirect blocks, \
- * we allocate bsize block for trailing data. \
- */ \
+ break; \
+ /* Up to UFS_NDADDR full blocks */ \
+ } else if ((size_t)(x) < UFS_NDADDR * (size_t)ffs_opts->bsize) {\
fsopts->size += roundup((x), ffs_opts->bsize); \
+ break; \
} \
+ /* Count space consumed by indirecttion blocks. */ \
+ size_t indir_blocks = howmany((x), ffs_opts->bsize); \
+ /* Indirect link count per block */ \
+ size_t nindir = (size_t)ffs_opts->bsize / \
+ (ffs_opts->version <= 1 ? sizeof(struct ufs1_dinode) \
+ : sizeof(struct ufs2_dinode)); \
+ int indir_level = 0; \
+ while (indir_blocks > 1 && indir_level < 3) { \
+ indir_blocks = howmany(indir_blocks, nindir); \
+ fsopts->size += ffs_opts->bsize * indir_blocks; \
+ indir_level++; \
+ } \
+ /* Top-level indirection block */ \
+ assert(indir_blocks == 1); \
+ fsopts->size += ffs_opts->bsize; \
+ if (debug & DEBUG_FS_SIZE_DIR_NODE) \
+ printf("ffs_size_dir: size %lld, using %d levels of " \
+ "indirect blocks\n", \
+ (long long)(x), indir_level); \
+ /* \
+ * If the file is big enough to use indirect blocks, \
+ * we allocate bsize block for trailing data. \
+ */ \
+ fsopts->size += roundup((x), ffs_opts->bsize); \
} while (0);
curdirsize = 0;

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 9, 5:07 AM (21 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28540663
Default Alt Text
D52120.id160811.diff (1 KB)

Event Timeline