All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: Alex Elder <aelder@sgi.com>
Cc: xfs mailing list <xfs@oss.sgi.com>
Subject: Re: [PATCH V2] mkfs: fix mkfs.xfs -dfile,name=$NAME for new files
Date: Fri, 15 Jan 2010 16:44:22 -0600	[thread overview]
Message-ID: <4B50EFC6.6050804@sandeen.net> (raw)
In-Reply-To: <1AB9A794DBDDF54A8A81BE2296F7BDFE012A697D@cf--amer001e--3.americas.sgi.com>

Alex Elder wrote:
> Eric Sandeen wrote:
>> # /sbin/mkfs.xfs -dfile,name=grrr,size=100g
>> mkfs.xfs: Use the -f option to force overwrite.
>>
>> check_overwrite is failing, because  blkid_new_probe_from_filename()
>> is failing, because the (new) image file is 0 length.
>>
>> It's easy to test for 0 length, and if found, there is
>> nothing to overwrite so return 0.
>>
>> Also, if testing itself failed for some reason, print
>> a message to that effect:
>>
>> # mkfs/mkfs.xfs -dfile,name=newfile,size=1g
>> mkfs.xfs: probe of newfile failed, cannot detect existing filesystem.
>> mkfs.xfs: Use the -f option to force overwrite.
> 
> This looks good.

except of course that st_size for devices is 0.

Oh, I suck lately :/

Ok, will send fixup patch later.  And then I'm gonna stop ;)

-Eric

>> Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
>> ---
> 
> Reviewed-by: Alex Elder <aelder@sgi.com>
> 
>> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
>> index faaafed..b6801dd 100644
>> --- a/mkfs/xfs_mkfs.c
>> +++ b/mkfs/xfs_mkfs.c
>> @@ -283,27 +283,47 @@ calc_stripe_factors(
>>  }
>>
>>  #ifdef ENABLE_BLKID
>> +/*
>> + * Check for existing filesystem or partition table on device.
>> + * Returns:
>> + *	 1 for existing fs or partition
>> + *	 0 for nothing found
>> + *	-1 for internal error
>> + */
>>  static int
>>  check_overwrite(
>>  	char		*device)
>>  {
>>  	const char	*type;
>> -	blkid_probe	pr;
>> -	int		ret = 0;
>> +	blkid_probe	pr = NULL;
>> +	int		ret;
>> +	struct stat	statbuf;
>>
>>  	if (!device || !*device)
>>  		return 0;
>>
>> +	ret = -1; /* will reset on success of all setup calls */
>> +
>> +	if (stat(device, &statbuf) < 0)
>> +		goto out;
>> +
>> +	/* nothing to overwrite on a 0-length device */
>> +	if (statbuf.st_size == 0) {
>> +		ret = 0;
>> +		goto out;
>> +	}
>> +
>>  	pr = blkid_new_probe_from_filename(device);
>>  	if (!pr)
>> -		return -1;
>> +		goto out;
>>
>>  	if (blkid_probe_enable_partitions(pr, 1))
>> -		goto out_free_probe;
>> +		goto out;
>>
>>  	if (blkid_do_fullprobe(pr))
>> -		goto out_free_probe;
>> +		goto out;
>>
>> +	ret = 0;
>>  	if (!blkid_probe_lookup_value(pr, "TYPE", &type, NULL)) {
>>  		fprintf(stderr,
>>  			_("%s: %s appears to contain an existing "
>> @@ -316,8 +336,13 @@ check_overwrite(
>>  		ret = 1;
>>  	}
>>
>> -out_free_probe:
>> -	blkid_free_probe(pr);
>> +out:
>> +	if (pr)
>> +		blkid_free_probe(pr);
>> +	if (ret == -1)
>> +		fprintf(stderr,
>> +			_("%s: probe of %s failed, cannot detect "
>> +			  "existing filesystem.\n"), progname, device);
>>  	return ret;
>>  }
>>
>>
>> _______________________________________________
>> xfs mailing list
>> xfs@oss.sgi.com
>> http://oss.sgi.com/mailman/listinfo/xfs
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
> 

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

      reply	other threads:[~2010-01-15 22:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-14 21:53 [PATCH] mkfs: fix mkfs.xfs -dfile,name=$NAME for new files Eric Sandeen
2010-01-15 18:01 ` Alex Elder
2010-01-15 18:47 ` [PATCH V2] " Eric Sandeen
2010-01-15 19:11   ` Alex Elder
2010-01-15 22:44     ` Eric Sandeen [this message]

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=4B50EFC6.6050804@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=aelder@sgi.com \
    --cc=xfs@oss.sgi.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.