linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Merillat <dan.merillat@gmail.com>
To: David Sterba <dsterba@suse.cz>,
	Dan Merillat <dan.merillat@gmail.com>,
	BTRFS <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 2/3] btrfs-progs: separate the overwrite check.
Date: Sat, 25 Apr 2015 14:19:47 -0400	[thread overview]
Message-ID: <CAPL5yKetu1whj4ON+NQPJk6Z06Jnqz3MQGf6Dx=3nKqAB8Vw-g@mail.gmail.com> (raw)
In-Reply-To: <20150424152428.GS4996@twin.jikos.cz>

It's a good question.  If path_name is absolute, the file descriptor
is ignored.  I used -1 (EBADF) instead of AT_FDCWD  there so if a
non-absolute path gets in there it errors out instead of attempting to
use a relative path off the current directory.

I'm not entirely sure if it's the best way, so if anyone else has
ideas let me know.

On Fri, Apr 24, 2015 at 11:24 AM, David Sterba <dsterba@suse.cz> wrote:
> On Thu, Apr 23, 2015 at 12:51:33PM -0400, Dan Merillat wrote:
>> +/* returns:
>> + *  0 if the file exists and should be skipped.
>> + *  1 if the file does NOT exist
>> + *  2 if the file exists but is OK to overwrite
>> + */
>> +
>> +static int overwrite_ok(const char * path)
>> +{
>> +     static int warn = 0;
>> +     struct stat st;
>> +     int ret;
>> +
>> +     /* don't be fooled by symlinks */
>> +     ret = fstatat(-1, path_name, &st, AT_SYMLINK_NOFOLLOW);
>
> Is the filedescriptor -1 correct? Previously, stat was used that uses
> AT_FDCWD for the dirfd, which is -100. -1 could be intepreted as a bad
> filedescriptor (EBADF).

  reply	other threads:[~2015-04-25 18:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23 16:47 [PATCH 0/3] btrfs-progs: restore symlinks Dan Merillat
2015-04-23 16:50 ` [PATCH 1/3] btrfs-progs: restore: document metadata restore Dan Merillat
2015-04-23 16:51 ` [PATCH 2/3] btrfs-progs: separate the overwrite check Dan Merillat
2015-04-24 15:24   ` David Sterba
2015-04-25 18:19     ` Dan Merillat [this message]
2015-04-29 15:38       ` David Sterba
2015-04-23 16:52 ` [PATCH 3/3] btrfs-progs: optionally restore symlinks Dan Merillat
2015-04-24  4:38 ` [PATCH 0/3] btrfs-progs: " Duncan
2015-04-25 18:16   ` Dan Merillat

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='CAPL5yKetu1whj4ON+NQPJk6Z06Jnqz3MQGf6Dx=3nKqAB8Vw-g@mail.gmail.com' \
    --to=dan.merillat@gmail.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /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).