mirror of
https://github.com/sheumann/hush.git
synced 2024-08-21 11:28:57 +00:00
excellent shrinkage patch by Tito
This commit is contained in:
parent
9134dff078
commit
7f782da048
@ -40,7 +40,7 @@
|
|||||||
#define ZAP_BOOTBLOCK
|
#define ZAP_BOOTBLOCK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char * device_name /* = NULL */;
|
static const char * device_name;
|
||||||
|
|
||||||
/* Command line options */
|
/* Command line options */
|
||||||
static int cflag;
|
static int cflag;
|
||||||
@ -57,7 +57,7 @@ static struct ext2_super_block param;
|
|||||||
static char *creator_os;
|
static char *creator_os;
|
||||||
static char *volume_label;
|
static char *volume_label;
|
||||||
static char *mount_dir;
|
static char *mount_dir;
|
||||||
static char *journal_device;
|
static char *journal_device = NULL;
|
||||||
static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
|
static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
|
||||||
|
|
||||||
static int sys_page_size = 4096;
|
static int sys_page_size = 4096;
|
||||||
@ -166,6 +166,56 @@ static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Busybox stuff
|
||||||
|
*/
|
||||||
|
static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...)__attribute__ ((format (printf, 2, 3)));
|
||||||
|
static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if (retval) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
bb_fprintf(stderr,"\nCould not ");
|
||||||
|
bb_vfprintf(stderr, fmt, ap);
|
||||||
|
bb_fprintf(stderr, "\n");
|
||||||
|
va_end(ap);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mke2fs_verbose(const char *fmt, ...)__attribute__ ((format (printf, 1, 2)));
|
||||||
|
static void mke2fs_verbose(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if (!quiet) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
bb_vfprintf(stdout, fmt, ap);
|
||||||
|
fflush(stdout);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mke2fs_verbose_done(void)
|
||||||
|
{
|
||||||
|
mke2fs_verbose("done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mke2fs_warning_msg(int retval, char *fmt, ... )__attribute__ ((format (printf, 2, 3)));
|
||||||
|
static void mke2fs_warning_msg(int retval, char *fmt, ... )
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
if (retval) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
bb_fprintf(stderr,"\nWarning: ");
|
||||||
|
bb_vfprintf(stderr, fmt, ap);
|
||||||
|
bb_fprintf(stderr, "\n");
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads the bad blocks list from a file
|
* Reads the bad blocks list from a file
|
||||||
*/
|
*/
|
||||||
@ -175,15 +225,10 @@ static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
|
|
||||||
f = fopen(bad_blocks_file, "r");
|
f = bb_xfopen(bad_blocks_file, "r");
|
||||||
if (!f) {
|
|
||||||
bb_perror_msg_and_die("Could not read bad blocks file %s", bad_blocks_file);
|
|
||||||
}
|
|
||||||
retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
|
retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "read bad blocks from list");
|
||||||
bb_error_msg_and_die("Could not read bad blocks list");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -198,18 +243,14 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
|
|||||||
sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
|
sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
|
||||||
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
|
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
|
||||||
fs->device_name, fs->super->s_blocks_count);
|
fs->device_name, fs->super->s_blocks_count);
|
||||||
if (!quiet)
|
mke2fs_verbose("Running command: %s\n", buf);
|
||||||
printf("Running command: %s\n", buf);
|
|
||||||
f = popen(buf, "r");
|
f = popen(buf, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
bb_perror_msg_and_die("Could not run '%s'", buf);
|
bb_perror_msg_and_die("Could not run '%s'", buf);
|
||||||
}
|
}
|
||||||
retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
|
retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
|
||||||
pclose(f);
|
pclose(f);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "read bad blocks from program");
|
||||||
bb_error_msg_and_die(
|
|
||||||
"Could not get list of bad blocks from program");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
|
static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
|
||||||
@ -254,10 +295,9 @@ static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
|
|||||||
for (j=0; j < fs->desc_blocks+1; j++) {
|
for (j=0; j < fs->desc_blocks+1; j++) {
|
||||||
if (ext2fs_badblocks_list_test(bb_list,
|
if (ext2fs_badblocks_list_test(bb_list,
|
||||||
group_block + j)) {
|
group_block + j)) {
|
||||||
if (!group_bad)
|
mke2fs_warning_msg(!group_bad,
|
||||||
bb_error_msg(
|
"the backup superblock/group descriptors at block %d contain\n"
|
||||||
"Warning: the backup superblock/group descriptors at block %d contain\n"
|
"bad blocks\n", group_block);
|
||||||
" bad blocks\n", group_block);
|
|
||||||
group_bad++;
|
group_bad++;
|
||||||
group = ext2fs_group_of_blk(fs, group_block+j);
|
group = ext2fs_group_of_blk(fs, group_block+j);
|
||||||
fs->group_desc[group].bg_free_blocks_count++;
|
fs->group_desc[group].bg_free_blocks_count++;
|
||||||
@ -271,9 +311,8 @@ static void handle_bad_blocks(ext2_filsys fs, badblocks_list bb_list)
|
|||||||
* Mark all the bad blocks as used...
|
* Mark all the bad blocks as used...
|
||||||
*/
|
*/
|
||||||
retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
|
retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "mark bad blocks as used");
|
||||||
bb_error_msg_and_die("while marking bad blocks as used");
|
|
||||||
}
|
|
||||||
while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
|
while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
|
||||||
ext2fs_mark_block_bitmap(fs->block_map, blk);
|
ext2fs_mark_block_bitmap(fs->block_map, blk);
|
||||||
ext2fs_badblocks_list_iterate_end(bb_iter);
|
ext2fs_badblocks_list_iterate_end(bb_iter);
|
||||||
@ -329,7 +368,7 @@ static void progress_close(struct progress_struct *progress)
|
|||||||
{
|
{
|
||||||
if (progress->format[0] == 0)
|
if (progress->format[0] == 0)
|
||||||
return;
|
return;
|
||||||
fputs("done \n", stdout);
|
printf("%-28s\n", "done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -409,12 +448,9 @@ static void write_inode_tables(ext2_filsys fs)
|
|||||||
num = fs->inode_blocks_per_group;
|
num = fs->inode_blocks_per_group;
|
||||||
|
|
||||||
retval = zero_blocks(fs, blk, num, 0, &blk, &num);
|
retval = zero_blocks(fs, blk, num, 0, &blk, &num);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval,
|
||||||
bb_error_msg_and_die(
|
"write %d blocks in inode table starting at %d.",
|
||||||
"\nCould not write %d blocks "
|
num, blk);
|
||||||
"in inode table starting at %d.",
|
|
||||||
num, blk);
|
|
||||||
}
|
|
||||||
if (sync_kludge) {
|
if (sync_kludge) {
|
||||||
if (sync_kludge == 1)
|
if (sync_kludge == 1)
|
||||||
sync();
|
sync();
|
||||||
@ -432,21 +468,15 @@ static void create_root_dir(ext2_filsys fs)
|
|||||||
struct ext2_inode inode;
|
struct ext2_inode inode;
|
||||||
|
|
||||||
retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
|
retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, 0);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "create root dir");
|
||||||
bb_error_msg_and_die("Could not create root dir");
|
|
||||||
}
|
|
||||||
if (geteuid()) {
|
if (geteuid()) {
|
||||||
retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
|
retval = ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "read root inode");
|
||||||
bb_error_msg_and_die("Could not read root inode");
|
|
||||||
}
|
|
||||||
inode.i_uid = getuid();
|
inode.i_uid = getuid();
|
||||||
if (inode.i_uid)
|
if (inode.i_uid)
|
||||||
inode.i_gid = getgid();
|
inode.i_gid = getgid();
|
||||||
retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
|
retval = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "set root inode ownership");
|
||||||
bb_error_msg_and_die("Could not set root inode ownership");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,27 +485,29 @@ static void create_lost_and_found(ext2_filsys fs)
|
|||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
ext2_ino_t ino;
|
ext2_ino_t ino;
|
||||||
const char *name = "lost+found";
|
const char *name = "lost+found";
|
||||||
int i;
|
int i = 1;
|
||||||
|
char *msg = "create";
|
||||||
int lpf_size = 0;
|
int lpf_size = 0;
|
||||||
|
|
||||||
fs->umask = 077;
|
fs->umask = 077;
|
||||||
retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
|
retval = ext2fs_mkdir(fs, EXT2_ROOT_INO, 0, name);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
bb_error_msg_and_die("Could not create lost+found");
|
goto CREATE_LOST_AND_FOUND_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
|
retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name, strlen(name), 0, &ino);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
bb_error_msg_and_die("Could not look up lost+found");
|
msg = "lookup";
|
||||||
|
goto CREATE_LOST_AND_FOUND_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=1; i < EXT2_NDIR_BLOCKS; i++) {
|
for (; i < EXT2_NDIR_BLOCKS; i++) {
|
||||||
if ((lpf_size += fs->blocksize) >= 16*1024)
|
if ((lpf_size += fs->blocksize) >= 16*1024)
|
||||||
break;
|
break;
|
||||||
retval = ext2fs_expand_dir(fs, ino);
|
retval = ext2fs_expand_dir(fs, ino);
|
||||||
if (retval) {
|
msg = "expand";
|
||||||
bb_error_msg_and_die("Could not expand lost+found");
|
CREATE_LOST_AND_FOUND_ERROR:
|
||||||
}
|
mke2fs_error_msg_and_die(retval, "%s %s", msg, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,10 +519,7 @@ static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
|
|||||||
fs->group_desc[0].bg_free_inodes_count--;
|
fs->group_desc[0].bg_free_inodes_count--;
|
||||||
fs->super->s_free_inodes_count--;
|
fs->super->s_free_inodes_count--;
|
||||||
retval = ext2fs_update_bb_inode(fs, bb_list);
|
retval = ext2fs_update_bb_inode(fs, bb_list);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "set bad block inode");
|
||||||
bb_error_msg_and_die("Could not set bad block inode");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reserve_inodes(ext2_filsys fs)
|
static void reserve_inodes(ext2_filsys fs)
|
||||||
@ -514,6 +543,7 @@ static void reserve_inodes(ext2_filsys fs)
|
|||||||
static void zap_sector(ext2_filsys fs, int sect, int nsect)
|
static void zap_sector(ext2_filsys fs, int sect, int nsect)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
char *fmt = "could not %s %d";
|
||||||
int retval;
|
int retval;
|
||||||
unsigned int *magic;
|
unsigned int *magic;
|
||||||
|
|
||||||
@ -523,7 +553,7 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
|
|||||||
/* Check for a BSD disklabel, and don't erase it if so */
|
/* Check for a BSD disklabel, and don't erase it if so */
|
||||||
retval = io_channel_read_blk(fs->io, 0, -512, buf);
|
retval = io_channel_read_blk(fs->io, 0, -512, buf);
|
||||||
if (retval)
|
if (retval)
|
||||||
bb_error_msg("Warning: could not read block 0");
|
mke2fs_warning_msg(retval, fmt, "read block", 0);
|
||||||
else {
|
else {
|
||||||
magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
|
magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
|
||||||
if ((*magic == BSD_DISKMAGIC) ||
|
if ((*magic == BSD_DISKMAGIC) ||
|
||||||
@ -537,8 +567,7 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
|
|||||||
retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
|
retval = io_channel_write_blk(fs->io, sect, -512*nsect, buf);
|
||||||
io_channel_set_blksize(fs->io, fs->blocksize);
|
io_channel_set_blksize(fs->io, fs->blocksize);
|
||||||
free(buf);
|
free(buf);
|
||||||
if (retval)
|
mke2fs_warning_msg(retval, fmt, "erase sector", sect);
|
||||||
bb_error_msg("Warning: could not erase sector %d", sect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_journal_dev(ext2_filsys fs)
|
static void create_journal_dev(ext2_filsys fs)
|
||||||
@ -546,14 +575,13 @@ static void create_journal_dev(ext2_filsys fs)
|
|||||||
struct progress_struct progress;
|
struct progress_struct progress;
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
char *fmt = "%s journal superblock";
|
||||||
blk_t blk;
|
blk_t blk;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
retval = ext2fs_create_journal_superblock(fs,
|
retval = ext2fs_create_journal_superblock(fs,
|
||||||
fs->super->s_blocks_count, 0, &buf);
|
fs->super->s_blocks_count, 0, &buf);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, fmt, "init");
|
||||||
bb_error_msg_and_die("Could not init journal superblock");
|
|
||||||
}
|
|
||||||
if (quiet)
|
if (quiet)
|
||||||
memset(&progress, 0, sizeof(progress));
|
memset(&progress, 0, sizeof(progress));
|
||||||
else
|
else
|
||||||
@ -562,66 +590,58 @@ static void create_journal_dev(ext2_filsys fs)
|
|||||||
|
|
||||||
retval = zero_blocks(fs, 0, fs->super->s_blocks_count,
|
retval = zero_blocks(fs, 0, fs->super->s_blocks_count,
|
||||||
&progress, &blk, &count);
|
&progress, &blk, &count);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "zero journal device (block %u, count %d)",
|
||||||
bb_error_msg_and_die("Could not zero journal device (block %u, count %d)",
|
|
||||||
blk, count);
|
blk, count);
|
||||||
}
|
|
||||||
zero_blocks(0, 0, 0, 0, 0, 0);
|
zero_blocks(0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
retval = io_channel_write_blk(fs->io,
|
retval = io_channel_write_blk(fs->io,
|
||||||
fs->super->s_first_data_block+1,
|
fs->super->s_first_data_block+1,
|
||||||
1, buf);
|
1, buf);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, fmt, "write");
|
||||||
bb_error_msg_and_die("Could not write journal superblock");
|
|
||||||
}
|
|
||||||
progress_close(&progress);
|
progress_close(&progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_stats(ext2_filsys fs)
|
static void show_stats(ext2_filsys fs)
|
||||||
{
|
{
|
||||||
struct ext2_super_block *s = fs->super;
|
struct ext2_super_block *s = fs->super;
|
||||||
char buf[80];
|
|
||||||
char *os;
|
char *os;
|
||||||
blk_t group_block;
|
blk_t group_block;
|
||||||
dgrp_t i;
|
dgrp_t i;
|
||||||
int need, col_left;
|
int need, col_left;
|
||||||
|
|
||||||
if (param.s_blocks_count != s->s_blocks_count)
|
mke2fs_warning_msg((param.s_blocks_count != s->s_blocks_count),
|
||||||
bb_error_msg("warning: %d blocks unused\n",
|
"%d blocks unused\n", param.s_blocks_count - s->s_blocks_count);
|
||||||
param.s_blocks_count - s->s_blocks_count);
|
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
|
|
||||||
printf("Filesystem label=%s\n", buf);
|
|
||||||
fputs("OS type: ", stdout);
|
|
||||||
os = e2p_os2string(fs->super->s_creator_os);
|
os = e2p_os2string(fs->super->s_creator_os);
|
||||||
fputs(os, stdout);
|
printf( "Filesystem label=%.*s\n"
|
||||||
|
"OS type: %s\n"
|
||||||
|
"Block size=%u (log=%u)\n"
|
||||||
|
"Fragment size=%u (log=%u)\n"
|
||||||
|
"%u inodes, %u blocks\n"
|
||||||
|
"%u blocks (%2.2f%%) reserved for the super user\n"
|
||||||
|
"First data block=%u\n",
|
||||||
|
(int) sizeof(s->s_volume_name),
|
||||||
|
s->s_volume_name,
|
||||||
|
os,
|
||||||
|
fs->blocksize, s->s_log_block_size,
|
||||||
|
fs->fragsize, s->s_log_frag_size,
|
||||||
|
s->s_inodes_count, s->s_blocks_count,
|
||||||
|
s->s_r_blocks_count, 100.0 * s->s_r_blocks_count / s->s_blocks_count,
|
||||||
|
s->s_first_data_block);
|
||||||
free(os);
|
free(os);
|
||||||
printf("\nBlock size=%u (log=%u)\n", fs->blocksize,
|
if (s->s_reserved_gdt_blocks) {
|
||||||
s->s_log_block_size);
|
|
||||||
printf("Fragment size=%u (log=%u)\n", fs->fragsize,
|
|
||||||
s->s_log_frag_size);
|
|
||||||
printf("%u inodes, %u blocks\n", s->s_inodes_count,
|
|
||||||
s->s_blocks_count);
|
|
||||||
printf("%u blocks (%2.2f%%) reserved for the super user\n",
|
|
||||||
s->s_r_blocks_count,
|
|
||||||
100.0 * s->s_r_blocks_count / s->s_blocks_count);
|
|
||||||
printf("First data block=%u\n", s->s_first_data_block);
|
|
||||||
if (s->s_reserved_gdt_blocks)
|
|
||||||
printf("Maximum filesystem blocks=%lu\n",
|
printf("Maximum filesystem blocks=%lu\n",
|
||||||
(s->s_reserved_gdt_blocks + fs->desc_blocks) *
|
(s->s_reserved_gdt_blocks + fs->desc_blocks) *
|
||||||
(fs->blocksize / sizeof(struct ext2_group_desc)) *
|
(fs->blocksize / sizeof(struct ext2_group_desc)) *
|
||||||
s->s_blocks_per_group);
|
s->s_blocks_per_group);
|
||||||
if (fs->group_desc_count > 1)
|
}
|
||||||
printf("%u block groups\n", fs->group_desc_count);
|
printf( "%u block group%s\n"
|
||||||
else
|
"%u blocks per group, %u fragments per group\n"
|
||||||
printf("%u block group\n", fs->group_desc_count);
|
"%u inodes per group\n",
|
||||||
printf("%u blocks per group, %u fragments per group\n",
|
fs->group_desc_count, (fs->group_desc_count > 1) ? "s" : "",
|
||||||
s->s_blocks_per_group, s->s_frags_per_group);
|
s->s_blocks_per_group, s->s_frags_per_group,
|
||||||
printf("%u inodes per group\n", s->s_inodes_per_group);
|
s->s_inodes_per_group);
|
||||||
|
|
||||||
if (fs->group_desc_count == 1) {
|
if (fs->group_desc_count == 1) {
|
||||||
printf("\n");
|
puts("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +662,7 @@ static void show_stats(ext2_filsys fs)
|
|||||||
col_left -= need;
|
col_left -= need;
|
||||||
printf("%u", group_block);
|
printf("%u", group_block);
|
||||||
}
|
}
|
||||||
printf("\n\n");
|
puts("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -651,22 +671,18 @@ static void show_stats(ext2_filsys fs)
|
|||||||
*/
|
*/
|
||||||
static int set_os(struct ext2_super_block *sb, char *os)
|
static int set_os(struct ext2_super_block *sb, char *os)
|
||||||
{
|
{
|
||||||
if (isdigit (*os))
|
if (isdigit (*os)) {
|
||||||
sb->s_creator_os = atoi (os);
|
sb->s_creator_os = atoi (os);
|
||||||
else if (strcasecmp(os, "linux") == 0)
|
return 1;
|
||||||
sb->s_creator_os = EXT2_OS_LINUX;
|
}
|
||||||
else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
|
|
||||||
sb->s_creator_os = EXT2_OS_HURD;
|
|
||||||
else if (strcasecmp(os, "masix") == 0)
|
|
||||||
sb->s_creator_os = EXT2_OS_MASIX;
|
|
||||||
else if (strcasecmp(os, "freebsd") == 0)
|
|
||||||
sb->s_creator_os = EXT2_OS_FREEBSD;
|
|
||||||
else if (strcasecmp(os, "lites") == 0)
|
|
||||||
sb->s_creator_os = EXT2_OS_LITES;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return 1;
|
if((sb->s_creator_os = e2p_string2os(os)) >= 0) {
|
||||||
|
return 1;
|
||||||
|
} else if (!strcasecmp("GNU", os)) {
|
||||||
|
sb->s_creator_os = EXT2_OS_HURD;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PATH_SET "PATH=/sbin"
|
#define PATH_SET "PATH=/sbin"
|
||||||
@ -772,7 +788,6 @@ static __u32 ok_features[3] = {
|
|||||||
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
|
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int PRS(int argc, char *argv[])
|
static int PRS(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int b, c;
|
int b, c;
|
||||||
@ -832,26 +847,25 @@ static int PRS(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argc && *argv) {
|
/* If called as mkfs.ext3, create a journal inode */
|
||||||
/* If called as mkfs.ext3, create a journal inode */
|
if (last_char_is(bb_applet_name, '3'))
|
||||||
if (!strcmp(*argv + strlen(*argv) - 9, "mkfs.ext3"))
|
journal_size = -1;
|
||||||
journal_size = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((c = getopt (argc, argv,
|
while ((c = getopt (argc, argv,
|
||||||
"b:cE:f:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) {
|
"b:cE:f:g:i:jl:m:no:qr:R:s:tvI:J:ST:FL:M:N:O:V")) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
blocksize = strtol(optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &blocksize))
|
||||||
|
goto BLOCKSIZE_ERROR;
|
||||||
b = (blocksize > 0) ? blocksize : -blocksize;
|
b = (blocksize > 0) ? blocksize : -blocksize;
|
||||||
if (b < EXT2_MIN_BLOCK_SIZE ||
|
if (b < EXT2_MIN_BLOCK_SIZE ||
|
||||||
b > EXT2_MAX_BLOCK_SIZE || *tmp) {
|
b > EXT2_MAX_BLOCK_SIZE) {
|
||||||
|
BLOCKSIZE_ERROR:
|
||||||
bb_error_msg_and_die("bad block size - %s", optarg);
|
bb_error_msg_and_die("bad block size - %s", optarg);
|
||||||
}
|
}
|
||||||
if (blocksize > 4096)
|
mke2fs_warning_msg((blocksize > 4096),
|
||||||
bb_error_msg(
|
"blocksize %d not usable on most systems",
|
||||||
"Warning: blocksize %d not usable on most systems",
|
blocksize);
|
||||||
blocksize);
|
|
||||||
if (blocksize > 0)
|
if (blocksize > 0)
|
||||||
param.s_log_block_size =
|
param.s_log_block_size =
|
||||||
int_log2(blocksize >>
|
int_log2(blocksize >>
|
||||||
@ -862,20 +876,15 @@ static int PRS(int argc, char *argv[])
|
|||||||
cflag++;
|
cflag++;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
size = strtoul(optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &size) || size < EXT2_MIN_BLOCK_SIZE || size > EXT2_MAX_BLOCK_SIZE ){
|
||||||
if (size < EXT2_MIN_BLOCK_SIZE ||
|
|
||||||
size > EXT2_MAX_BLOCK_SIZE || *tmp) {
|
|
||||||
bb_error_msg_and_die("bad fragment size - %s", optarg);
|
bb_error_msg_and_die("bad fragment size - %s", optarg);
|
||||||
}
|
}
|
||||||
param.s_log_frag_size =
|
param.s_log_frag_size =
|
||||||
int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE);
|
int_log2(size >> EXT2_MIN_BLOCK_LOG_SIZE);
|
||||||
bb_error_msg(
|
mke2fs_warning_msg(1, "fragments not supported. Ignoring -f option");
|
||||||
"Warning: fragments not supported. "
|
|
||||||
"Ignoring -f option");
|
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
|
if (safe_strtoi(optarg, ¶m.s_blocks_per_group)) {
|
||||||
if (*tmp) {
|
|
||||||
bb_error_msg_and_die("Illegal number for blocks per group");
|
bb_error_msg_and_die("Illegal number for blocks per group");
|
||||||
}
|
}
|
||||||
if ((param.s_blocks_per_group % 8) != 0) {
|
if ((param.s_blocks_per_group % 8) != 0) {
|
||||||
@ -883,14 +892,13 @@ static int PRS(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
inode_ratio = strtoul(optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &inode_ratio)
|
||||||
if (inode_ratio < EXT2_MIN_BLOCK_SIZE ||
|
|| inode_ratio < EXT2_MIN_BLOCK_SIZE
|
||||||
inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024 ||
|
|| inode_ratio > EXT2_MAX_BLOCK_SIZE * 1024) {
|
||||||
*tmp) {
|
bb_error_msg_and_die("bad inode ratio %s (min %d/max %d)",
|
||||||
bb_error_msg_and_die("bad inode ratio %s (min %d/max %d",
|
|
||||||
optarg, EXT2_MIN_BLOCK_SIZE,
|
optarg, EXT2_MIN_BLOCK_SIZE,
|
||||||
EXT2_MAX_BLOCK_SIZE);
|
EXT2_MAX_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'J':
|
case 'J':
|
||||||
parse_journal_opts(&journal_device, &journal_flags, &journal_size, optarg);
|
parse_journal_opts(&journal_device, &journal_flags, &journal_size, optarg);
|
||||||
@ -905,8 +913,7 @@ static int PRS(int argc, char *argv[])
|
|||||||
bad_blocks_filename = optarg;
|
bad_blocks_filename = optarg;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
reserved_ratio = strtoul(optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &reserved_ratio) || reserved_ratio > 50 ) {
|
||||||
if (reserved_ratio > 50 || *tmp) {
|
|
||||||
bb_error_msg_and_die("bad reserved blocks percent - %s", optarg);
|
bb_error_msg_and_die("bad reserved blocks percent - %s", optarg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -934,8 +941,7 @@ static int PRS(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
#ifdef EXT2_DYNAMIC_REV
|
#ifdef EXT2_DYNAMIC_REV
|
||||||
case 'I':
|
case 'I':
|
||||||
inode_size = strtoul(optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &inode_size)) {
|
||||||
if (*tmp) {
|
|
||||||
bb_error_msg_and_die("bad inode size - %s", optarg);
|
bb_error_msg_and_die("bad inode size - %s", optarg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -983,19 +989,18 @@ static int PRS(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
/* Print version number and exit */
|
/* Print version number and exit */
|
||||||
show_version_only++;
|
show_version_only = 1;
|
||||||
|
quiet = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((optind == argc) && !show_version_only)
|
if ((optind == argc) /*&& !show_version_only*/)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
device_name = argv[optind++];
|
device_name = argv[optind++];
|
||||||
|
|
||||||
if (!quiet || show_version_only)
|
mke2fs_verbose("mke2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
|
||||||
bb_error_msg("mke2fs %s (%s)", E2FSPROGS_VERSION,
|
|
||||||
E2FSPROGS_DATE);
|
|
||||||
|
|
||||||
if (show_version_only) {
|
if (show_version_only) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -1018,9 +1023,7 @@ static int PRS(int argc, char *argv[])
|
|||||||
retval = ext2fs_open(journal_device,
|
retval = ext2fs_open(journal_device,
|
||||||
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
||||||
0, io_ptr, &jfs);
|
0, io_ptr, &jfs);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "open journal device %s", journal_device);
|
||||||
bb_error_msg_and_die("Could not open journal device %s", journal_device);
|
|
||||||
}
|
|
||||||
if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
|
if ((blocksize < 0) && (jfs->blocksize < (unsigned) (-blocksize))) {
|
||||||
bb_error_msg_and_die(
|
bb_error_msg_and_die(
|
||||||
"Journal dev blocksize (%d) smaller than "
|
"Journal dev blocksize (%d) smaller than "
|
||||||
@ -1034,29 +1037,23 @@ static int PRS(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (blocksize > sys_page_size) {
|
if (blocksize > sys_page_size) {
|
||||||
|
mke2fs_warning_msg(1, "%d-byte blocks too big for system (max %d)",
|
||||||
|
blocksize, sys_page_size);
|
||||||
if (!force) {
|
if (!force) {
|
||||||
bb_error_msg("%d-byte blocks too big for system (max %d)",
|
|
||||||
blocksize, sys_page_size);
|
|
||||||
proceed_question();
|
proceed_question();
|
||||||
}
|
}
|
||||||
bb_error_msg(
|
bb_error_msg("Forced to continue");
|
||||||
"Warning: %d-byte blocks too big for system "
|
|
||||||
"(max %d), forced to continue",
|
|
||||||
blocksize, sys_page_size);
|
|
||||||
}
|
}
|
||||||
if ((blocksize > 4096) &&
|
mke2fs_warning_msg(((blocksize > 4096) &&
|
||||||
(param.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL))
|
(param.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL)),
|
||||||
bb_error_msg(
|
"some 2.4 kernels do not support "
|
||||||
"\nWarning: some 2.4 kernels do not support "
|
"blocksizes greater than 4096 using ext3.\n"
|
||||||
"blocksizes greater than 4096 \n\tusing ext3."
|
"Use -b 4096 if this is an issue for you\n");
|
||||||
" Use -b 4096 if this is an issue for you\n");
|
|
||||||
|
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
param.s_blocks_count = parse_num_blocks(argv[optind++],
|
param.s_blocks_count = parse_num_blocks(argv[optind++],
|
||||||
param.s_log_block_size);
|
param.s_log_block_size);
|
||||||
if (!param.s_blocks_count) {
|
mke2fs_error_msg_and_die(!param.s_blocks_count, "bad blocks count - %s", argv[optind - 1]);
|
||||||
bb_error_msg_and_die("bad blocks count - %s", argv[optind - 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
@ -1074,8 +1071,7 @@ static int PRS(int argc, char *argv[])
|
|||||||
param.s_feature_incompat))
|
param.s_feature_incompat))
|
||||||
param.s_rev_level = 1; /* Create a revision 1 filesystem */
|
param.s_rev_level = 1; /* Create a revision 1 filesystem */
|
||||||
|
|
||||||
if (!force)
|
check_plausibility(device_name , force);
|
||||||
check_plausibility(device_name);
|
|
||||||
check_mount(device_name, force, "filesystem");
|
check_mount(device_name, force, "filesystem");
|
||||||
|
|
||||||
param.s_log_frag_size = param.s_log_block_size;
|
param.s_log_frag_size = param.s_log_block_size;
|
||||||
@ -1097,13 +1093,12 @@ static int PRS(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
|
mke2fs_error_msg_and_die((retval && (retval != EXT2_ET_UNIMPLEMENTED)),"determine filesystem size");
|
||||||
bb_error_msg_and_die("Could not determine filesystem size");
|
|
||||||
}
|
|
||||||
if (!param.s_blocks_count) {
|
if (!param.s_blocks_count) {
|
||||||
if (retval == EXT2_ET_UNIMPLEMENTED) {
|
if (retval == EXT2_ET_UNIMPLEMENTED) {
|
||||||
bb_error_msg_and_die(
|
mke2fs_error_msg_and_die(1,
|
||||||
"Couldn't determine device size; you "
|
"determine device size; you "
|
||||||
"must specify\nthe size of the "
|
"must specify\nthe size of the "
|
||||||
"filesystem");
|
"filesystem");
|
||||||
} else {
|
} else {
|
||||||
@ -1145,9 +1140,7 @@ static int PRS(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Get the hardware sector size, if available */
|
/* Get the hardware sector size, if available */
|
||||||
retval = ext2fs_get_device_sectsize(device_name, §or_size);
|
retval = ext2fs_get_device_sectsize(device_name, §or_size);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "determine hardware sector size");
|
||||||
bb_error_msg_and_die("Could not determine hardware sector size");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
|
if ((tmp = getenv("MKE2FS_DEVICE_SECTSIZE")) != NULL)
|
||||||
sector_size = atoi(tmp);
|
sector_size = atoi(tmp);
|
||||||
@ -1182,10 +1175,9 @@ static int PRS(int argc, char *argv[])
|
|||||||
inode_size, EXT2_GOOD_OLD_INODE_SIZE,
|
inode_size, EXT2_GOOD_OLD_INODE_SIZE,
|
||||||
blocksize);
|
blocksize);
|
||||||
}
|
}
|
||||||
if (inode_size != EXT2_GOOD_OLD_INODE_SIZE)
|
mke2fs_warning_msg((inode_size != EXT2_GOOD_OLD_INODE_SIZE),
|
||||||
bb_error_msg(
|
"%d-byte inodes not usable on most systems",
|
||||||
"Warning: %d-byte inodes not usable on most systems",
|
inode_size);
|
||||||
inode_size);
|
|
||||||
param.s_inode_size = inode_size;
|
param.s_inode_size = inode_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1203,16 +1195,22 @@ static int PRS(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clean_up(void)
|
||||||
|
{
|
||||||
|
if (ENABLE_FEATURE_CLEAN_UP && journal_device) free(journal_device);
|
||||||
|
}
|
||||||
|
|
||||||
int mke2fs_main (int argc, char *argv[])
|
int mke2fs_main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
ext2_filsys fs;
|
ext2_filsys fs;
|
||||||
badblocks_list bb_list = 0;
|
badblocks_list bb_list = 0;
|
||||||
int journal_blocks;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int val;
|
int val;
|
||||||
io_manager io_ptr;
|
io_manager io_ptr;
|
||||||
|
|
||||||
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
|
atexit(clean_up);
|
||||||
if(!PRS(argc, argv))
|
if(!PRS(argc, argv))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1228,9 +1226,7 @@ int mke2fs_main (int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
retval = ext2fs_initialize(device_name, 0, ¶m,
|
retval = ext2fs_initialize(device_name, 0, ¶m,
|
||||||
io_ptr, &fs);
|
io_ptr, &fs);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "set up superblock");
|
||||||
bb_error_msg_and_die("Could not set up superblock");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wipe out the old on-disk superblock
|
* Wipe out the old on-disk superblock
|
||||||
@ -1277,20 +1273,14 @@ int mke2fs_main (int argc, char *argv[])
|
|||||||
* Set the volume label...
|
* Set the volume label...
|
||||||
*/
|
*/
|
||||||
if (volume_label) {
|
if (volume_label) {
|
||||||
memset(fs->super->s_volume_name, 0,
|
snprintf(fs->super->s_volume_name, sizeof(fs->super->s_volume_name), "%s", volume_label);
|
||||||
sizeof(fs->super->s_volume_name));
|
|
||||||
strncpy(fs->super->s_volume_name, volume_label,
|
|
||||||
sizeof(fs->super->s_volume_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the last mount directory
|
* Set the last mount directory
|
||||||
*/
|
*/
|
||||||
if (mount_dir) {
|
if (mount_dir) {
|
||||||
memset(fs->super->s_last_mounted, 0,
|
snprintf(fs->super->s_last_mounted, sizeof(fs->super->s_last_mounted), "%s", mount_dir);
|
||||||
sizeof(fs->super->s_last_mounted));
|
|
||||||
strncpy(fs->super->s_last_mounted, mount_dir,
|
|
||||||
sizeof(fs->super->s_last_mounted));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!quiet || noaction)
|
if (!quiet || noaction)
|
||||||
@ -1313,9 +1303,7 @@ int mke2fs_main (int argc, char *argv[])
|
|||||||
handle_bad_blocks(fs, bb_list);
|
handle_bad_blocks(fs, bb_list);
|
||||||
fs->stride = fs_stride;
|
fs->stride = fs_stride;
|
||||||
retval = ext2fs_allocate_tables(fs);
|
retval = ext2fs_allocate_tables(fs);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "allocate filesystem tables");
|
||||||
bb_error_msg_and_die("Could not allocate filesystem tables");
|
|
||||||
}
|
|
||||||
if (super_only) {
|
if (super_only) {
|
||||||
fs->super->s_state |= EXT2_ERROR_FS;
|
fs->super->s_state |= EXT2_ERROR_FS;
|
||||||
fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
|
fs->flags &= ~(EXT2_FLAG_IB_DIRTY|EXT2_FLAG_BB_DIRTY);
|
||||||
@ -1342,9 +1330,7 @@ int mke2fs_main (int argc, char *argv[])
|
|||||||
retval = zero_blocks(fs, start, blocks - start,
|
retval = zero_blocks(fs, start, blocks - start,
|
||||||
NULL, &ret_blk, NULL);
|
NULL, &ret_blk, NULL);
|
||||||
|
|
||||||
if (retval) {
|
mke2fs_warning_msg(retval, "could not zero block %u at end of filesystem", ret_blk);
|
||||||
bb_error_msg("Could not zero block %u at end of filesystem", ret_blk);
|
|
||||||
}
|
|
||||||
write_inode_tables(fs);
|
write_inode_tables(fs);
|
||||||
create_root_dir(fs);
|
create_root_dir(fs);
|
||||||
create_lost_and_found(fs);
|
create_lost_and_found(fs);
|
||||||
@ -1353,72 +1339,22 @@ int mke2fs_main (int argc, char *argv[])
|
|||||||
if (fs->super->s_feature_compat &
|
if (fs->super->s_feature_compat &
|
||||||
EXT2_FEATURE_COMPAT_RESIZE_INODE) {
|
EXT2_FEATURE_COMPAT_RESIZE_INODE) {
|
||||||
retval = ext2fs_create_resize_inode(fs);
|
retval = ext2fs_create_resize_inode(fs);
|
||||||
if (retval) {
|
mke2fs_error_msg_and_die(retval, "reserve blocks for online resize");
|
||||||
bb_error_msg_and_die("Could not reserve blocks for online resize");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (journal_device) {
|
if (journal_device) {
|
||||||
ext2_filsys jfs;
|
make_journal_device(journal_device, fs, quiet, force);
|
||||||
|
|
||||||
if (!force)
|
|
||||||
check_plausibility(journal_device);
|
|
||||||
check_mount(journal_device, force, "journal");
|
|
||||||
|
|
||||||
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
|
|
||||||
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
|
||||||
fs->blocksize, unix_io_manager, &jfs);
|
|
||||||
if (retval) {
|
|
||||||
bb_error_msg_and_die("Could not open journal device %s", journal_device);
|
|
||||||
}
|
|
||||||
if (!quiet) {
|
|
||||||
printf("Adding journal to device %s: ", journal_device);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
retval = ext2fs_add_journal_device(fs, jfs);
|
|
||||||
if(retval) {
|
|
||||||
bb_error_msg_and_die("Could not add journal to device %s", journal_device);
|
|
||||||
}
|
|
||||||
if (!quiet)
|
|
||||||
printf("done\n");
|
|
||||||
ext2fs_close(jfs);
|
|
||||||
free(journal_device);
|
|
||||||
} else if (journal_size) {
|
} else if (journal_size) {
|
||||||
journal_blocks = figure_journal_size(journal_size, fs);
|
make_journal_blocks(fs, journal_size, journal_flags, quiet);
|
||||||
|
|
||||||
if (!journal_blocks) {
|
|
||||||
fs->super->s_feature_compat &=
|
|
||||||
~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
|
|
||||||
goto no_journal;
|
|
||||||
}
|
|
||||||
if (!quiet) {
|
|
||||||
printf("Creating journal (%d blocks): ",
|
|
||||||
journal_blocks);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
retval = ext2fs_add_journal_inode(fs, journal_blocks,
|
|
||||||
journal_flags);
|
|
||||||
if (retval) {
|
|
||||||
bb_error_msg_and_die("Could not create journal");
|
|
||||||
}
|
|
||||||
if (!quiet)
|
|
||||||
printf("done\n");
|
|
||||||
}
|
}
|
||||||
no_journal:
|
|
||||||
|
|
||||||
if (!quiet)
|
mke2fs_verbose("Writing superblocks and filesystem accounting information: ");
|
||||||
printf("Writing superblocks and "
|
|
||||||
"filesystem accounting information: ");
|
|
||||||
retval = ext2fs_flush(fs);
|
retval = ext2fs_flush(fs);
|
||||||
if (retval) {
|
mke2fs_warning_msg(retval, "had trouble writing out superblocks");
|
||||||
bb_error_msg("\nWarning, had trouble writing out superblocks");
|
mke2fs_verbose_done();
|
||||||
}
|
if (!quiet && !getenv("MKE2FS_SKIP_CHECK_MSG"))
|
||||||
if (!quiet) {
|
print_check_message(fs);
|
||||||
printf("done\n\n");
|
|
||||||
if (!getenv("MKE2FS_SKIP_CHECK_MSG"))
|
|
||||||
print_check_message(fs);
|
|
||||||
}
|
|
||||||
val = ext2fs_close(fs);
|
val = ext2fs_close(fs);
|
||||||
return (retval || val) ? 1 : 0;
|
return (retval || val) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ extern int optind;
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "blkid/blkid.h"
|
#include "blkid/blkid.h"
|
||||||
|
|
||||||
static char * device_name;
|
static char * device_name = NULL;
|
||||||
static char * new_label, *new_last_mounted, *new_UUID;
|
static char * new_label, *new_last_mounted, *new_UUID;
|
||||||
static char * io_options;
|
static char * io_options;
|
||||||
static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
|
static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
|
||||||
@ -66,7 +66,7 @@ static char *features_cmd;
|
|||||||
static char *mntopts_cmd;
|
static char *mntopts_cmd;
|
||||||
|
|
||||||
static int journal_size, journal_flags;
|
static int journal_size, journal_flags;
|
||||||
static char *journal_device;
|
static char *journal_device = NULL;
|
||||||
|
|
||||||
static const char *please_fsck = "Please run e2fsck on the filesystem\n";
|
static const char *please_fsck = "Please run e2fsck on the filesystem\n";
|
||||||
|
|
||||||
@ -188,26 +188,36 @@ static void remove_journal_inode(ext2_filsys fs)
|
|||||||
struct ext2_inode inode;
|
struct ext2_inode inode;
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
ino_t ino = fs->super->s_journal_inum;
|
ino_t ino = fs->super->s_journal_inum;
|
||||||
|
char *msg = "to read";
|
||||||
|
char *s = "journal inode";
|
||||||
|
|
||||||
retval = ext2fs_read_inode(fs, ino, &inode);
|
retval = ext2fs_read_inode(fs, ino, &inode);
|
||||||
if (retval)
|
if (retval)
|
||||||
bb_error_msg_and_die("Failed to read journal inode");
|
goto REMOVE_JOURNAL_INODE_ERROR;
|
||||||
if (ino == EXT2_JOURNAL_INO) {
|
if (ino == EXT2_JOURNAL_INO) {
|
||||||
retval = ext2fs_read_bitmaps(fs);
|
retval = ext2fs_read_bitmaps(fs);
|
||||||
if (retval)
|
if (retval) {
|
||||||
bb_error_msg_and_die("Failed to read bitmaps");
|
msg = "to read bitmaps";
|
||||||
|
s = "";
|
||||||
|
goto REMOVE_JOURNAL_INODE_ERROR;
|
||||||
|
}
|
||||||
retval = ext2fs_block_iterate(fs, ino, 0, NULL,
|
retval = ext2fs_block_iterate(fs, ino, 0, NULL,
|
||||||
release_blocks_proc, NULL);
|
release_blocks_proc, NULL);
|
||||||
if (retval)
|
if (retval) {
|
||||||
bb_error_msg_and_die("Failed clearing journal inode");
|
msg = "clearing";
|
||||||
|
goto REMOVE_JOURNAL_INODE_ERROR;
|
||||||
|
}
|
||||||
memset(&inode, 0, sizeof(inode));
|
memset(&inode, 0, sizeof(inode));
|
||||||
ext2fs_mark_bb_dirty(fs);
|
ext2fs_mark_bb_dirty(fs);
|
||||||
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
||||||
} else
|
} else
|
||||||
inode.i_flags &= ~EXT2_IMMUTABLE_FL;
|
inode.i_flags &= ~EXT2_IMMUTABLE_FL;
|
||||||
retval = ext2fs_write_inode(fs, ino, &inode);
|
retval = ext2fs_write_inode(fs, ino, &inode);
|
||||||
if (retval)
|
if (retval) {
|
||||||
bb_error_msg_and_die("Failed writing journal inode");
|
msg = "writing";
|
||||||
|
REMOVE_JOURNAL_INODE_ERROR:
|
||||||
|
bb_error_msg_and_die("Failed %s %s", msg, s);
|
||||||
|
}
|
||||||
fs->super->s_journal_inum = 0;
|
fs->super->s_journal_inum = 0;
|
||||||
ext2fs_mark_super_dirty(fs);
|
ext2fs_mark_super_dirty(fs);
|
||||||
}
|
}
|
||||||
@ -269,8 +279,8 @@ static void update_feature_set(ext2_filsys fs, char *features)
|
|||||||
EXT3_FEATURE_INCOMPAT_RECOVER) {
|
EXT3_FEATURE_INCOMPAT_RECOVER) {
|
||||||
bb_error_msg_and_die(
|
bb_error_msg_and_die(
|
||||||
"The needs_recovery flag is set. "
|
"The needs_recovery flag is set. "
|
||||||
"Please run e2fsck before clearing\n"
|
"%s before clearing the has_journal flag.",
|
||||||
"the has_journal flag.");
|
please_fsck);
|
||||||
}
|
}
|
||||||
if (sb->s_journal_inum) {
|
if (sb->s_journal_inum) {
|
||||||
remove_journal_inode(fs);
|
remove_journal_inode(fs);
|
||||||
@ -317,48 +327,14 @@ static void update_feature_set(ext2_filsys fs, char *features)
|
|||||||
*/
|
*/
|
||||||
static void add_journal(ext2_filsys fs)
|
static void add_journal(ext2_filsys fs)
|
||||||
{
|
{
|
||||||
unsigned long journal_blocks;
|
|
||||||
errcode_t retval;
|
|
||||||
ext2_filsys jfs;
|
|
||||||
io_manager io_ptr;
|
|
||||||
|
|
||||||
if (fs->super->s_feature_compat &
|
if (fs->super->s_feature_compat &
|
||||||
EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
|
||||||
bb_error_msg("The filesystem already has a journal");
|
bb_error_msg_and_die("The filesystem already has a journal");
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
if (journal_device) {
|
if (journal_device) {
|
||||||
check_plausibility(journal_device);
|
make_journal_device(journal_device, fs, 0, 0);
|
||||||
check_mount(journal_device, 0, "journal");
|
|
||||||
io_ptr = unix_io_manager;
|
|
||||||
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
|
|
||||||
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
|
||||||
fs->blocksize, io_ptr, &jfs);
|
|
||||||
if (retval) {
|
|
||||||
bb_error_msg("Failed to open journal on %s", journal_device);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
printf("Creating journal on device %s: ", journal_device);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
retval = ext2fs_add_journal_device(fs, jfs);
|
|
||||||
ext2fs_close(jfs);
|
|
||||||
if (retval) {
|
|
||||||
bb_error_msg("Failed to add filesystem to journal on %s", journal_device);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
puts("done");
|
|
||||||
} else if (journal_size) {
|
} else if (journal_size) {
|
||||||
fputs("Creating journal inode: ", stdout);
|
make_journal_blocks(fs, journal_size, journal_flags, 0);
|
||||||
fflush(stdout);
|
|
||||||
journal_blocks = figure_journal_size(journal_size, fs);
|
|
||||||
|
|
||||||
retval = ext2fs_add_journal_inode(fs, journal_blocks,
|
|
||||||
journal_flags);
|
|
||||||
if (retval)
|
|
||||||
bb_error_msg_and_die("Failed to create journal file");
|
|
||||||
else
|
|
||||||
puts("done");
|
|
||||||
/*
|
/*
|
||||||
* If the filesystem wasn't mounted, we need to force
|
* If the filesystem wasn't mounted, we need to force
|
||||||
* the block group descriptors out.
|
* the block group descriptors out.
|
||||||
@ -368,11 +344,18 @@ static void add_journal(ext2_filsys fs)
|
|||||||
}
|
}
|
||||||
print_check_message(fs);
|
print_check_message(fs);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
/*
|
||||||
if (journal_device)
|
* Busybox stuff
|
||||||
free(journal_device);
|
*/
|
||||||
exit(1);
|
static char * x_blkid_get_devname(const char *token)
|
||||||
|
{
|
||||||
|
char * dev_name;
|
||||||
|
|
||||||
|
if (!(dev_name = blkid_get_devname(NULL, token, NULL)))
|
||||||
|
bb_error_msg_and_die("Unable to resolve '%s'", token);
|
||||||
|
return dev_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_E2LABEL
|
#ifdef CONFIG_E2LABEL
|
||||||
@ -383,9 +366,7 @@ static void parse_e2label_options(int argc, char ** argv)
|
|||||||
io_options = strchr(argv[1], '?');
|
io_options = strchr(argv[1], '?');
|
||||||
if (io_options)
|
if (io_options)
|
||||||
*io_options++ = 0;
|
*io_options++ = 0;
|
||||||
device_name = blkid_get_devname(NULL, argv[1], NULL);
|
device_name = x_blkid_get_devname(argv[1]);
|
||||||
if (!device_name)
|
|
||||||
bb_error_msg_and_die("Unable to resolve '%s'", argv[1]);
|
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK;
|
open_flag = EXT2_FLAG_RW | EXT2_FLAG_JOURNAL_DEV_OK;
|
||||||
L_flag = 1;
|
L_flag = 1;
|
||||||
@ -393,6 +374,8 @@ static void parse_e2label_options(int argc, char ** argv)
|
|||||||
} else
|
} else
|
||||||
print_label++;
|
print_label++;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define parse_e2label_options(x,y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static time_t parse_time(char *str)
|
static time_t parse_time(char *str)
|
||||||
@ -425,17 +408,14 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
char * tmp;
|
char * tmp;
|
||||||
struct group * gr;
|
|
||||||
struct passwd * pw;
|
|
||||||
|
|
||||||
printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
|
printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
|
||||||
while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) != EOF)
|
while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:J:L:M:O:T:U:")) != EOF)
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'c':
|
case 'c':
|
||||||
max_mount_count = strtol (optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &max_mount_count) || max_mount_count > 16000) {
|
||||||
if (*tmp || max_mount_count > 16000) {
|
goto MOUNTS_COUNT_ERROR;
|
||||||
bb_error_msg_and_die("bad mounts count - %s", optarg);
|
|
||||||
}
|
}
|
||||||
if (max_mount_count == 0)
|
if (max_mount_count == 0)
|
||||||
max_mount_count = -1;
|
max_mount_count = -1;
|
||||||
@ -443,8 +423,8 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
open_flag = EXT2_FLAG_RW;
|
open_flag = EXT2_FLAG_RW;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
mount_count = strtoul (optarg, &tmp, 0);
|
if (safe_strtoi(optarg, &mount_count) || mount_count > 16000) {
|
||||||
if (*tmp || mount_count > 16000) {
|
MOUNTS_COUNT_ERROR:
|
||||||
bb_error_msg_and_die("bad mounts count - %s", optarg);
|
bb_error_msg_and_die("bad mounts count - %s", optarg);
|
||||||
}
|
}
|
||||||
C_flag = 1;
|
C_flag = 1;
|
||||||
@ -467,19 +447,8 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
f_flag = 1;
|
f_flag = 1;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
resgid = strtoul (optarg, &tmp, 0);
|
if (safe_strtoul(optarg, &resgid))
|
||||||
if (*tmp) {
|
resgid = bb_xgetgrnam(optarg);
|
||||||
gr = getgrnam (optarg);
|
|
||||||
if (gr == NULL)
|
|
||||||
tmp = optarg;
|
|
||||||
else {
|
|
||||||
resgid = gr->gr_gid;
|
|
||||||
*tmp =0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*tmp) {
|
|
||||||
bb_error_msg_and_die("bad gid/group name - %s", optarg);
|
|
||||||
}
|
|
||||||
g_flag = 1;
|
g_flag = 1;
|
||||||
open_flag = EXT2_FLAG_RW;
|
open_flag = EXT2_FLAG_RW;
|
||||||
break;
|
break;
|
||||||
@ -532,8 +501,7 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
EXT2_FLAG_JOURNAL_DEV_OK;
|
EXT2_FLAG_JOURNAL_DEV_OK;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
reserved_ratio = strtoul (optarg, &tmp, 0);
|
if(safe_strtoul(optarg, &reserved_ratio) || reserved_ratio > 50) {
|
||||||
if (*tmp || reserved_ratio > 50) {
|
|
||||||
bb_error_msg_and_die("bad reserved block ratio - %s", optarg);
|
bb_error_msg_and_die("bad reserved block ratio - %s", optarg);
|
||||||
}
|
}
|
||||||
m_flag = 1;
|
m_flag = 1;
|
||||||
@ -560,8 +528,7 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
open_flag = EXT2_FLAG_RW;
|
open_flag = EXT2_FLAG_RW;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
reserved_blocks = strtoul (optarg, &tmp, 0);
|
if(safe_strtoul(optarg, &reserved_blocks)) {
|
||||||
if (*tmp) {
|
|
||||||
bb_error_msg_and_die("bad reserved blocks count - %s", optarg);
|
bb_error_msg_and_die("bad reserved blocks count - %s", optarg);
|
||||||
}
|
}
|
||||||
r_flag = 1;
|
r_flag = 1;
|
||||||
@ -577,19 +544,8 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
open_flag = EXT2_FLAG_RW;
|
open_flag = EXT2_FLAG_RW;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
resuid = strtoul (optarg, &tmp, 0);
|
if (safe_strtoul(optarg, &resuid))
|
||||||
if (*tmp) {
|
resuid = bb_xgetpwnam(optarg);
|
||||||
pw = getpwnam (optarg);
|
|
||||||
if (pw == NULL)
|
|
||||||
tmp = optarg;
|
|
||||||
else {
|
|
||||||
resuid = pw->pw_uid;
|
|
||||||
*tmp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*tmp) {
|
|
||||||
bb_error_msg_and_die("bad uid/user name - %s", optarg);
|
|
||||||
}
|
|
||||||
u_flag = 1;
|
u_flag = 1;
|
||||||
open_flag = EXT2_FLAG_RW;
|
open_flag = EXT2_FLAG_RW;
|
||||||
break;
|
break;
|
||||||
@ -609,48 +565,45 @@ static void parse_tune2fs_options(int argc, char **argv)
|
|||||||
io_options = strchr(argv[optind], '?');
|
io_options = strchr(argv[optind], '?');
|
||||||
if (io_options)
|
if (io_options)
|
||||||
*io_options++ = 0;
|
*io_options++ = 0;
|
||||||
device_name = blkid_get_devname(NULL, argv[optind], NULL);
|
device_name = x_blkid_get_devname(argv[optind]);
|
||||||
if (!device_name)
|
|
||||||
bb_error_msg_and_die("Unable to resolve '%s'", argv[optind]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_FINDFS
|
#ifdef CONFIG_FINDFS
|
||||||
static attribute_noreturn void do_findfs(int argc, char **argv)
|
static attribute_noreturn void do_findfs(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *dev;
|
|
||||||
|
|
||||||
if ((argc != 2) ||
|
if ((argc != 2) ||
|
||||||
(strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5)))
|
(strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5)))
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
dev = blkid_get_devname(NULL, argv[1], NULL);
|
device_name = x_blkid_get_devname(argv[1]);
|
||||||
if (!dev)
|
puts(device_name);
|
||||||
bb_error_msg_and_die("Unable to resolve '%s'", argv[1]);
|
|
||||||
puts(dev);
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define do_findfs(x, y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void clean_up(void)
|
||||||
|
{
|
||||||
|
if (ENABLE_FEATURE_CLEAN_UP && device_name) free(device_name);
|
||||||
|
if (ENABLE_FEATURE_CLEAN_UP && journal_device) free(journal_device);
|
||||||
|
}
|
||||||
|
|
||||||
int tune2fs_main(int argc, char **argv)
|
int tune2fs_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
errcode_t retval;
|
errcode_t retval;
|
||||||
ext2_filsys fs;
|
ext2_filsys fs;
|
||||||
struct ext2_super_block *sb;
|
struct ext2_super_block *sb;
|
||||||
io_manager io_ptr;
|
io_manager io_ptr;
|
||||||
#if defined(CONFIG_FINDFS) || defined(CONFIG_E2LABEL)
|
|
||||||
char *program_name = basename(argv[0]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_FINDFS
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
if (strcmp(program_name, "findfs") == 0)
|
atexit(clean_up);
|
||||||
do_findfs(argc, argv);
|
|
||||||
#endif
|
if (ENABLE_FINDFS && (bb_applet_name[0] == 'f')) /* findfs */
|
||||||
|
do_findfs(argc, argv); /* no return */
|
||||||
#ifdef CONFIG_E2LABEL
|
else if (ENABLE_E2LABEL && (bb_applet_name[0] == 'e')) /* e2label */
|
||||||
if (strcmp(program_name, "e2label") == 0)
|
|
||||||
parse_e2label_options(argc, argv);
|
parse_e2label_options(argc, argv);
|
||||||
else
|
else
|
||||||
#endif
|
parse_tune2fs_options(argc, argv); /* tune2fs */
|
||||||
parse_tune2fs_options(argc, argv);
|
|
||||||
|
|
||||||
io_ptr = unix_io_manager;
|
io_ptr = unix_io_manager;
|
||||||
retval = ext2fs_open2(device_name, io_options, open_flag,
|
retval = ext2fs_open2(device_name, io_options, open_flag,
|
||||||
@ -662,7 +615,7 @@ int tune2fs_main(int argc, char **argv)
|
|||||||
/* For e2label emulation */
|
/* For e2label emulation */
|
||||||
printf("%.*s\n", (int) sizeof(sb->s_volume_name),
|
printf("%.*s\n", (int) sizeof(sb->s_volume_name),
|
||||||
sb->s_volume_name);
|
sb->s_volume_name);
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
retval = ext2fs_check_if_mounted(device_name, &mount_flags);
|
retval = ext2fs_check_if_mounted(device_name, &mount_flags);
|
||||||
if (retval)
|
if (retval)
|
||||||
|
@ -29,7 +29,7 @@ void proceed_question(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_plausibility(const char *device)
|
void check_plausibility(const char *device, int force)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
#ifdef CONFIG_LFS
|
#ifdef CONFIG_LFS
|
||||||
@ -39,7 +39,8 @@ void check_plausibility(const char *device)
|
|||||||
struct stat s;
|
struct stat s;
|
||||||
val = stat(device, &s);
|
val = stat(device, &s);
|
||||||
#endif
|
#endif
|
||||||
|
if (force)
|
||||||
|
return;
|
||||||
if(val == -1)
|
if(val == -1)
|
||||||
bb_perror_msg_and_die("Could not stat %s", device);
|
bb_perror_msg_and_die("Could not stat %s", device);
|
||||||
if (!S_ISBLK(s.st_mode)) {
|
if (!S_ISBLK(s.st_mode)) {
|
||||||
@ -205,3 +206,50 @@ void print_check_message(ext2_filsys fs)
|
|||||||
fs->super->s_max_mnt_count,
|
fs->super->s_max_mnt_count,
|
||||||
(double)fs->super->s_checkinterval / (3600 * 24));
|
(double)fs->super->s_checkinterval / (3600 * 24));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void make_journal_device(char *journal_device, ext2_filsys fs, int quiet, int force)
|
||||||
|
{
|
||||||
|
errcode_t retval;
|
||||||
|
ext2_filsys jfs;
|
||||||
|
io_manager io_ptr;
|
||||||
|
|
||||||
|
check_plausibility(journal_device, force);
|
||||||
|
check_mount(journal_device, force, "journal");
|
||||||
|
io_ptr = unix_io_manager;
|
||||||
|
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
|
||||||
|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
||||||
|
fs->blocksize, io_ptr, &jfs);
|
||||||
|
if (retval)
|
||||||
|
bb_error_msg_and_die("Could not journal device %s", journal_device);
|
||||||
|
if(!quiet)
|
||||||
|
printf("Adding journal to device %s: ", journal_device);
|
||||||
|
fflush(stdout);
|
||||||
|
retval = ext2fs_add_journal_device(fs, jfs);
|
||||||
|
if(retval)
|
||||||
|
bb_error_msg_and_die("\nFailed to add journal to device %s", journal_device);
|
||||||
|
if(!quiet)
|
||||||
|
puts("done");
|
||||||
|
ext2fs_close(jfs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void make_journal_blocks(ext2_filsys fs, int journal_size, int journal_flags, int quiet)
|
||||||
|
{
|
||||||
|
unsigned long journal_blocks;
|
||||||
|
errcode_t retval;
|
||||||
|
|
||||||
|
journal_blocks = figure_journal_size(journal_size, fs);
|
||||||
|
if (!journal_blocks) {
|
||||||
|
fs->super->s_feature_compat &=
|
||||||
|
~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!quiet)
|
||||||
|
printf("Creating journal (%ld blocks): ", journal_blocks);
|
||||||
|
fflush(stdout);
|
||||||
|
retval = ext2fs_add_journal_inode(fs, journal_blocks,
|
||||||
|
journal_flags);
|
||||||
|
if(retval)
|
||||||
|
bb_error_msg_and_die("Could not create journal");
|
||||||
|
if(!quiet)
|
||||||
|
puts("done");
|
||||||
|
}
|
||||||
|
@ -11,8 +11,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
extern void proceed_question(void);
|
extern void proceed_question(void);
|
||||||
extern void check_plausibility(const char *device);
|
extern void check_plausibility(const char *device, int force);
|
||||||
extern void parse_journal_opts(char **, int *, int *, const char *opts);
|
extern void parse_journal_opts(char **, int *, int *, const char *opts);
|
||||||
extern void check_mount(const char *device, int force, const char *type);
|
extern void check_mount(const char *device, int force, const char *type);
|
||||||
extern int figure_journal_size(int size, ext2_filsys fs);
|
extern int figure_journal_size(int size, ext2_filsys fs);
|
||||||
extern void print_check_message(ext2_filsys fs);
|
extern void print_check_message(ext2_filsys fs);
|
||||||
|
extern void make_journal_device(char *journal_device, ext2_filsys fs, int quiet, int force);
|
||||||
|
extern void make_journal_blocks(ext2_filsys fs, int journal_size, int journal_flags, int quiet);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user