Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144361723
D52120.id160839.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D52120.id160839.diff
View Options
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
@@ -591,6 +591,55 @@
return (fsopts->fd);
}
+static void
+ffs_add_size(fsinfo_t *fsopts, size_t file_len)
+{
+ ffs_opt_t *ffs_opts = fsopts->fs_specific;
+ size_t indir_blocks, nindir;
+ int indir_level;
+
+ /* (UFS_NDADDR - 1) full blocks + 1 fragment at most */
+ if (file_len < ffs_opts->fsize +
+ (UFS_NDADDR - 1) * (size_t)ffs_opts->bsize) {
+ fsopts->size += roundup(file_len, ffs_opts->fsize);
+ return;
+
+ /* Up to UFS_NDADDR full blocks */
+ } else if (file_len < UFS_NDADDR * (size_t)ffs_opts->bsize) {
+ fsopts->size += roundup(file_len, ffs_opts->bsize);
+ return;
+ }
+
+ /* Count space consumed by indirecttion blocks. */
+
+ indir_blocks = howmany(file_len, ffs_opts->bsize);
+ /* Indirect link count per block */
+ if (ffs_opts->version <= 1) {
+ nindir = (size_t)ffs_opts->bsize / sizeof(struct ufs1_dinode);
+ } else {
+ nindir = (size_t)ffs_opts->bsize / sizeof(struct ufs2_dinode);
+ }
+
+ 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)file_len, indir_level);
+ }
+ /*
+ * If the file is big enough to use indirect blocks,
+ * we allocate bsize block for trailing data.
+ */
+ fsopts->size += roundup(file_len, ffs_opts->bsize);
+}
static void
ffs_size_dir(fsnode *root, fsinfo_t *fsopts)
@@ -622,20 +671,6 @@
e, tmpdir.d_namlen, this, curdirsize); \
} while (0);
-#define ADDSIZE(x) do { \
- if ((size_t)(x) < UFS_NDADDR * (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. \
- */ \
- fsopts->size += roundup((x), ffs_opts->bsize); \
- } \
-} while (0);
curdirsize = 0;
for (node = root; node != NULL; node = node->next) {
@@ -652,7 +687,7 @@
(long long)node->inode->st.st_size);
fsopts->inodes++;
if (node->type == S_IFREG)
- ADDSIZE(node->inode->st.st_size);
+ ffs_add_size(fsopts, node->inode->st.st_size);
if (node->type == S_IFLNK) {
size_t slen;
@@ -660,13 +695,13 @@
if (slen >= (ffs_opts->version == 1 ?
UFS1_MAXSYMLINKLEN :
UFS2_MAXSYMLINKLEN))
- ADDSIZE(slen);
+ ffs_add_size(fsopts, slen);
}
}
if (node->type == S_IFDIR)
ffs_size_dir(node->child, fsopts);
}
- ADDSIZE(curdirsize);
+ ffs_add_size(fsopts, curdirsize);
if (debug & DEBUG_FS_SIZE_DIR)
printf("ffs_size_dir: exit: size %lld inodes %lld\n",
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Feb 9, 1:25 AM (17 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28520695
Default Alt Text
D52120.id160839.diff (3 KB)
Attached To
Mode
D52120: makefs: Calculate indirect block count properly for large files on ffs
Attached
Detach File
Event Timeline
Log In to Comment