linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: "Theodore Ts'o" <tytso@mit.edu>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 4/7] mke2fs: create a regular file if necessary
Date: Mon, 05 May 2014 10:17:30 -0500	[thread overview]
Message-ID: <5367AB8A.8000408@redhat.com> (raw)
In-Reply-To: <1398556834-31913-4-git-send-email-tytso@mit.edu>

On 4/26/14, 7:00 PM, Theodore Ts'o wrote:
> This is useful when creating a filesystem for use with a VM, for
> example.

Ok, backing up to here from the "print if we're creating a file" thread.

Considering the questions about typos in /dev/$FOO etc, why is it desirable
to create the file within mke2fs?  If you're making it for a VM, wouldn't
you want to control the creation (i.e. fallocated vs. sparse, for example,
as well as permissions) and not just have things magically happen?

fallocate -l 8g myfile; mkfs.ext4 myfile
or
truncate -s 8589934592 myfile; mkfs.ext4 myfile

doesn't seem all that onerous.

-Eric

> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> ---
>  misc/mke2fs.c |  3 ++-
>  misc/util.c   | 20 ++++++++++++++++----
>  misc/util.h   |  1 +
>  3 files changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index fa61e7b..a2b1f65 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -1749,7 +1749,8 @@ profile_error:
>  	if (optind < argc)
>  		usage();
>  
> -	if (!check_plausibility(device_name, 0, &is_device) && !force)
> +	if (!check_plausibility(device_name, CREATE_FILE,
> +				&is_device) && !force)
>  		proceed_question();
>  
>  	check_mount(device_name, force, _("filesystem"));
> diff --git a/misc/util.c b/misc/util.c
> index 08ec761..f85942e 100644
> --- a/misc/util.c
> +++ b/misc/util.c
> @@ -13,6 +13,7 @@
>  #define _LARGEFILE64_SOURCE
>  
>  #include "config.h"
> +#include <fcntl.h>
>  #include <stdio.h>
>  #include <string.h>
>  #ifdef HAVE_ERRNO_H
> @@ -21,6 +22,7 @@
>  #ifdef HAVE_LINUX_MAJOR_H
>  #include <linux/major.h>
>  #endif
> +#include <sys/types.h>
>  #ifdef HAVE_SYS_STAT_H
>  #include <sys/stat.h>
>  #endif
> @@ -85,19 +87,29 @@ void proceed_question(void)
>   */
>  int check_plausibility(const char *device, int flags, int *ret_is_dev)
>  {
> -	int val, is_dev = 0;
> +	int fd, is_dev = 0;
>  	ext2fs_struct_stat s;
> +	int fl = O_RDONLY;
>  
> -	val = ext2fs_stat(device, &s);
> +	if (flags & CREATE_FILE)
> +		fl |= O_CREAT;
>  
> -	if(val == -1) {
> -		fprintf(stderr, _("Could not stat %s --- %s\n"),
> +	fd = open(device, fl, 0666);
> +	if (fd < 0) {
> +		fprintf(stderr, _("Could not open %s: %s\n"),
>  			device, error_message(errno));
>  		if (errno == ENOENT)
>  			fputs(_("\nThe device apparently does not exist; "
>  				"did you specify it correctly?\n"), stderr);
>  		exit(1);
>  	}
> +
> +	if (ext2fs_fstat(fd, &s) < 0) {
> +		perror("stat");
> +		exit(1);
> +	}
> +	close(fd);
> +
>  	if (S_ISBLK(s.st_mode))
>  		is_dev = 1;
>  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
> diff --git a/misc/util.h b/misc/util.h
> index 867f4b0..b80d489 100644
> --- a/misc/util.h
> +++ b/misc/util.h
> @@ -19,6 +19,7 @@ extern char	*journal_location_string;
>   * Flags for check_plausibility()
>   */
>  #define CHECK_BLOCK_DEV	0x0001
> +#define CREATE_FILE	0x0002
>  
>  #ifndef HAVE_STRCASECMP
>  extern int strcasecmp (char *s1, char *s2);
> 


  parent reply	other threads:[~2014-05-05 15:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-27  0:00 [PATCH 1/7] mke2fs: don't ask the proceed question using a regular file Theodore Ts'o
2014-04-27  0:00 ` [PATCH 2/7] mke2fs, tune2fs: call proceed_question() from check_plausibility()'s caller Theodore Ts'o
2014-04-27  0:00 ` [PATCH 3/7] mke2fs: don't complain if the regular file is too small Theodore Ts'o
2014-04-28 15:26   ` Eric Sandeen
2014-04-27  0:00 ` [PATCH 4/7] mke2fs: create a regular file if necessary Theodore Ts'o
2014-04-30 12:21   ` Lukáš Czerner
2014-04-30 14:06     ` Theodore Ts'o
2014-04-30 14:14       ` Lukáš Czerner
2014-04-30 14:18         ` Theodore Ts'o
2014-04-30 14:35           ` Lukáš Czerner
2014-04-30 15:26             ` Theodore Ts'o
2014-05-05 15:17   ` Eric Sandeen [this message]
2014-04-27  0:00 ` [PATCH 5/7] mke2fs: proceed if the user doesn't type anything after 5 seconds Theodore Ts'o
2014-04-28 15:33   ` Eric Sandeen
2014-04-28 15:36     ` Eric Sandeen
2014-04-28 23:26     ` Theodore Ts'o
2014-04-29  0:32       ` Eric Sandeen
2014-04-30  6:53         ` Lukáš Czerner
2014-04-27  0:00 ` [PATCH 6/7] mke2fs: check for pre-existing file system Theodore Ts'o
2014-04-30 11:50   ` Lukáš Czerner
2014-04-30 13:44     ` Lukáš Czerner
2014-04-30 14:10     ` Theodore Ts'o
2014-04-27  0:00 ` [PATCH 7/7] mke2fs: only print the low-level file system stats in verbose mode Theodore Ts'o
2014-04-30 11:22   ` Lukáš Czerner
2014-04-30 14:01     ` Theodore Ts'o
2014-04-30 14:25       ` Lukáš Czerner
2014-04-28 15:24 ` [PATCH 1/7] mke2fs: don't ask the proceed question using a regular file Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5367AB8A.8000408@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).