Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/makefs/ffs.c
Show First 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | printf("Calculated size of `%s': %lld bytes, %lld inodes\n", | ||||
image, (long long)fsopts->size, (long long)fsopts->inodes); | image, (long long)fsopts->size, (long long)fsopts->inodes); | ||||
/* create image */ | /* create image */ | ||||
TIMER_START(start); | TIMER_START(start); | ||||
if (ffs_create_image(image, fsopts) == -1) | if (ffs_create_image(image, fsopts) == -1) | ||||
errx(1, "Image file `%s' not created.", image); | errx(1, "Image file `%s' not created.", image); | ||||
TIMER_RESULTS(start, "ffs_create_image"); | TIMER_RESULTS(start, "ffs_create_image"); | ||||
fsopts->curinode = ROOTINO; | fsopts->curinode = UFS_ROOTINO; | ||||
if (debug & DEBUG_FS_MAKEFS) | if (debug & DEBUG_FS_MAKEFS) | ||||
putchar('\n'); | putchar('\n'); | ||||
/* populate image */ | /* populate image */ | ||||
printf("Populating `%s'\n", image); | printf("Populating `%s'\n", image); | ||||
TIMER_START(start); | TIMER_START(start); | ||||
if (! ffs_populate_dir(dir, root, fsopts)) | if (! ffs_populate_dir(dir, root, fsopts)) | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | if (fsopts->maxsize > 0 && | ||||
errx(1, "`%s' minsize of %lld rounded up to ffs bsize of %d " | errx(1, "`%s' minsize of %lld rounded up to ffs bsize of %d " | ||||
"exceeds maxsize %lld. Lower bsize, or round the minimum " | "exceeds maxsize %lld. Lower bsize, or round the minimum " | ||||
"and maximum sizes to bsize.", dir, | "and maximum sizes to bsize.", dir, | ||||
(long long)fsopts->minsize, ffs_opts->bsize, | (long long)fsopts->minsize, ffs_opts->bsize, | ||||
(long long)fsopts->maxsize); | (long long)fsopts->maxsize); | ||||
/* calculate size of tree */ | /* calculate size of tree */ | ||||
ffs_size_dir(root, fsopts); | ffs_size_dir(root, fsopts); | ||||
fsopts->inodes += ROOTINO; /* include first two inodes */ | fsopts->inodes += UFS_ROOTINO; /* include first two inodes */ | ||||
if (debug & DEBUG_FS_VALIDATE) | if (debug & DEBUG_FS_VALIDATE) | ||||
printf("ffs_validate: size of tree: %lld bytes, %lld inodes\n", | printf("ffs_validate: size of tree: %lld bytes, %lld inodes\n", | ||||
(long long)fsopts->size, (long long)fsopts->inodes); | (long long)fsopts->size, (long long)fsopts->inodes); | ||||
/* add requested slop */ | /* add requested slop */ | ||||
fsopts->size += fsopts->freeblocks; | fsopts->size += fsopts->freeblocks; | ||||
fsopts->inodes += fsopts->freefiles; | fsopts->inodes += fsopts->freefiles; | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | printf("mkfs returned %p; fs_time %s", | ||||
fsopts->superblock, ctime(&t)); | fsopts->superblock, ctime(&t)); | ||||
printf("fs totals: nbfree %lld, nffree %lld, nifree %lld, ndir %lld\n", | printf("fs totals: nbfree %lld, nffree %lld, nifree %lld, ndir %lld\n", | ||||
(long long)fs->fs_cstotal.cs_nbfree, | (long long)fs->fs_cstotal.cs_nbfree, | ||||
(long long)fs->fs_cstotal.cs_nffree, | (long long)fs->fs_cstotal.cs_nffree, | ||||
(long long)fs->fs_cstotal.cs_nifree, | (long long)fs->fs_cstotal.cs_nifree, | ||||
(long long)fs->fs_cstotal.cs_ndir); | (long long)fs->fs_cstotal.cs_ndir); | ||||
} | } | ||||
if (fs->fs_cstotal.cs_nifree + ROOTINO < fsopts->inodes) { | if (fs->fs_cstotal.cs_nifree + UFS_ROOTINO < fsopts->inodes) { | ||||
warnx( | warnx( | ||||
"Image file `%s' has %lld free inodes; %lld are required.", | "Image file `%s' has %lld free inodes; %lld are required.", | ||||
image, | image, | ||||
(long long)(fs->fs_cstotal.cs_nifree + ROOTINO), | (long long)(fs->fs_cstotal.cs_nifree + UFS_ROOTINO), | ||||
(long long)fsopts->inodes); | (long long)fsopts->inodes); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
return (fsopts->fd); | return (fsopts->fd); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (node == root) { /* we're at "." */ | ||||
fsopts->inodes++; | fsopts->inodes++; | ||||
if (node->type == S_IFREG) | if (node->type == S_IFREG) | ||||
ADDSIZE(node->inode->st.st_size); | ADDSIZE(node->inode->st.st_size); | ||||
if (node->type == S_IFLNK) { | if (node->type == S_IFLNK) { | ||||
int slen; | int slen; | ||||
slen = strlen(node->symlink) + 1; | slen = strlen(node->symlink) + 1; | ||||
if (slen >= (ffs_opts->version == 1 ? | if (slen >= (ffs_opts->version == 1 ? | ||||
MAXSYMLINKLEN_UFS1 : | UFS1_MAXSYMLINKLEN : | ||||
MAXSYMLINKLEN_UFS2)) | UFS2_MAXSYMLINKLEN)) | ||||
ADDSIZE(slen); | ADDSIZE(slen); | ||||
} | } | ||||
} | } | ||||
if (node->type == S_IFDIR) | if (node->type == S_IFDIR) | ||||
ffs_size_dir(node->child, fsopts); | ffs_size_dir(node->child, fsopts); | ||||
} | } | ||||
ADDSIZE(curdirsize); | ADDSIZE(curdirsize); | ||||
Show All 36 Lines | if (cur == root) { /* "."; write dirbuf */ | ||||
membuf = dbufp->buf; | membuf = dbufp->buf; | ||||
dinp->di_size = dbufp->size; | dinp->di_size = dbufp->size; | ||||
} else if (S_ISBLK(cur->type) || S_ISCHR(cur->type)) { | } else if (S_ISBLK(cur->type) || S_ISCHR(cur->type)) { | ||||
dinp->di_size = 0; /* a device */ | dinp->di_size = 0; /* a device */ | ||||
dinp->di_rdev = | dinp->di_rdev = | ||||
ufs_rw32(cur->inode->st.st_rdev, fsopts->needswap); | ufs_rw32(cur->inode->st.st_rdev, fsopts->needswap); | ||||
} else if (S_ISLNK(cur->type)) { /* symlink */ | } else if (S_ISLNK(cur->type)) { /* symlink */ | ||||
slen = strlen(cur->symlink); | slen = strlen(cur->symlink); | ||||
if (slen < MAXSYMLINKLEN_UFS1) { /* short link */ | if (slen < UFS1_MAXSYMLINKLEN) { /* short link */ | ||||
memcpy(dinp->di_db, cur->symlink, slen); | memcpy(dinp->di_db, cur->symlink, slen); | ||||
} else | } else | ||||
membuf = cur->symlink; | membuf = cur->symlink; | ||||
dinp->di_size = slen; | dinp->di_size = slen; | ||||
} | } | ||||
return membuf; | return membuf; | ||||
} | } | ||||
Show All 35 Lines | if (cur == root) { /* "."; write dirbuf */ | ||||
membuf = dbufp->buf; | membuf = dbufp->buf; | ||||
dinp->di_size = dbufp->size; | dinp->di_size = dbufp->size; | ||||
} else if (S_ISBLK(cur->type) || S_ISCHR(cur->type)) { | } else if (S_ISBLK(cur->type) || S_ISCHR(cur->type)) { | ||||
dinp->di_size = 0; /* a device */ | dinp->di_size = 0; /* a device */ | ||||
dinp->di_rdev = | dinp->di_rdev = | ||||
ufs_rw64(cur->inode->st.st_rdev, fsopts->needswap); | ufs_rw64(cur->inode->st.st_rdev, fsopts->needswap); | ||||
} else if (S_ISLNK(cur->type)) { /* symlink */ | } else if (S_ISLNK(cur->type)) { /* symlink */ | ||||
slen = strlen(cur->symlink); | slen = strlen(cur->symlink); | ||||
if (slen < MAXSYMLINKLEN_UFS2) { /* short link */ | if (slen < UFS2_MAXSYMLINKLEN) { /* short link */ | ||||
memcpy(dinp->di_db, cur->symlink, slen); | memcpy(dinp->di_db, cur->symlink, slen); | ||||
} else | } else | ||||
membuf = cur->symlink; | membuf = cur->symlink; | ||||
dinp->di_size = slen; | dinp->di_size = slen; | ||||
} | } | ||||
return membuf; | return membuf; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 428 Lines • Show Last 20 Lines |