mirror of https://github.com/vitalif/e2fsprogs
mke2fs: print a message when creating a regular file
We've added the ability to automatically recreate a file if it doesn't exist prior to creating the file system, since this is often used (for example) when managing file system images for use in virtual machines. We should at least notify the user that this is going on to avoid surprises in the case of misspelled device/file names. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>maint-test
parent
cd84e9a337
commit
a11ccebd89
|
@ -103,6 +103,7 @@ static int quotatype = -1; /* Initialize both user and group quotas by default
|
||||||
static __u64 offset;
|
static __u64 offset;
|
||||||
static blk64_t journal_location = ~0LL;
|
static blk64_t journal_location = ~0LL;
|
||||||
static int proceed_delay = -1;
|
static int proceed_delay = -1;
|
||||||
|
static blk64_t dev_size;
|
||||||
|
|
||||||
static struct ext2_super_block fs_param;
|
static struct ext2_super_block fs_param;
|
||||||
static char *fs_uuid = NULL;
|
static char *fs_uuid = NULL;
|
||||||
|
@ -1402,7 +1403,6 @@ static void PRS(int argc, char *argv[])
|
||||||
char * extended_opts = 0;
|
char * extended_opts = 0;
|
||||||
char * fs_type = 0;
|
char * fs_type = 0;
|
||||||
char * usage_types = 0;
|
char * usage_types = 0;
|
||||||
blk64_t dev_size;
|
|
||||||
/*
|
/*
|
||||||
* NOTE: A few words about fs_blocks_count and blocksize:
|
* NOTE: A few words about fs_blocks_count and blocksize:
|
||||||
*
|
*
|
||||||
|
@ -1768,6 +1768,8 @@ profile_error:
|
||||||
flags = CREATE_FILE;
|
flags = CREATE_FILE;
|
||||||
if (isatty(0) && isatty(1))
|
if (isatty(0) && isatty(1))
|
||||||
flags |= CHECK_FS_EXIST;
|
flags |= CHECK_FS_EXIST;
|
||||||
|
if (!quiet)
|
||||||
|
flags |= VERBOSE_CREATE;
|
||||||
if (!check_plausibility(device_name, flags, &is_device) && !force)
|
if (!check_plausibility(device_name, flags, &is_device) && !force)
|
||||||
proceed_question(proceed_delay);
|
proceed_question(proceed_delay);
|
||||||
|
|
||||||
|
@ -2573,7 +2575,7 @@ int main (int argc, char *argv[])
|
||||||
journal_blocks = figure_journal_size(journal_size, fs);
|
journal_blocks = figure_journal_size(journal_size, fs);
|
||||||
|
|
||||||
/* Can't undo discard ... */
|
/* Can't undo discard ... */
|
||||||
if (!noaction && discard && (io_ptr != undo_io_manager)) {
|
if (!noaction && discard && dev_size && (io_ptr != undo_io_manager)) {
|
||||||
retval = mke2fs_discard_device(fs);
|
retval = mke2fs_discard_device(fs);
|
||||||
if (!retval && io_channel_discard_zeroes_data(fs->io)) {
|
if (!retval && io_channel_discard_zeroes_data(fs->io)) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
|
11
misc/util.c
11
misc/util.c
|
@ -106,7 +106,7 @@ void proceed_question(int delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return 1 if the device looks plausible
|
* return 1 if the device looks plausible, creating the file if necessary
|
||||||
*/
|
*/
|
||||||
int check_plausibility(const char *device, int flags, int *ret_is_dev)
|
int check_plausibility(const char *device, int flags, int *ret_is_dev)
|
||||||
{
|
{
|
||||||
|
@ -117,10 +117,13 @@ int check_plausibility(const char *device, int flags, int *ret_is_dev)
|
||||||
char *fs_type = NULL;
|
char *fs_type = NULL;
|
||||||
char *fs_label = NULL;
|
char *fs_label = NULL;
|
||||||
|
|
||||||
if (flags & CREATE_FILE)
|
|
||||||
fl |= O_CREAT;
|
|
||||||
|
|
||||||
fd = open(device, fl, 0666);
|
fd = open(device, fl, 0666);
|
||||||
|
if ((fd < 0) && (errno == ENOENT) && (flags & CREATE_FILE)) {
|
||||||
|
fl |= O_CREAT;
|
||||||
|
fd = open(device, fl, 0666);
|
||||||
|
if (fd >= 0 && (flags & VERBOSE_CREATE))
|
||||||
|
printf(_("Creating regular file %s\n"), device);
|
||||||
|
}
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, _("Could not open %s: %s\n"),
|
fprintf(stderr, _("Could not open %s: %s\n"),
|
||||||
device, error_message(errno));
|
device, error_message(errno));
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern char *journal_location_string;
|
||||||
#define CHECK_BLOCK_DEV 0x0001
|
#define CHECK_BLOCK_DEV 0x0001
|
||||||
#define CREATE_FILE 0x0002
|
#define CREATE_FILE 0x0002
|
||||||
#define CHECK_FS_EXIST 0x0004
|
#define CHECK_FS_EXIST 0x0004
|
||||||
|
#define VERBOSE_CREATE 0x0008
|
||||||
|
|
||||||
#ifndef HAVE_STRCASECMP
|
#ifndef HAVE_STRCASECMP
|
||||||
extern int strcasecmp (char *s1, char *s2);
|
extern int strcasecmp (char *s1, char *s2);
|
||||||
|
|
Loading…
Reference in New Issue