From: enh <enh@google.com>
To: musl@lists.openwall.com
Cc: Tony Ambardar <tony.ambardar@gmail.com>
Subject: Re: [musl] [PATCH v1] add renameat2 linux syscall wrapper
Date: Tue, 23 Apr 2024 07:49:47 -0700 [thread overview]
Message-ID: <CAJgzZoqNgZkWNwz-wP3ZGG0hM+brt65h9r0oZ_jDrLMa4s+Xyw@mail.gmail.com> (raw)
In-Reply-To: <20240422224726.GL4163@brightrain.aerifal.cx>
fwiw, i wrote out the constants with shifts in bionic because that's
what the uapi headers do (<linux/fs.h> iirc), and the preprocessor
won't get upset if someone includes both this way.
On Mon, Apr 22, 2024 at 3:47 PM Rich Felker <dalias@libc.org> wrote:
>
> On Sun, Apr 21, 2024 at 08:36:40AM -0700, Tony Ambardar wrote:
> > This syscall is available since Linux 3.15 and also implemented in glibc
> > from version 2.28. It is commonly used in filesystem or security contexts.
> >
> > Defines RENAME_NOREPLACE, RENAME_EXCHANGE, RENAME_WHITEOUT are guarded by
> > _GNU_SOURCE as with glibc.
> >
> > Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
> > ---
> > include/stdio.h | 7 +++++++
> > src/linux/renameat2.c | 8 ++++++++
> > 2 files changed, 15 insertions(+)
> > create mode 100644 src/linux/renameat2.c
> >
> > diff --git a/include/stdio.h b/include/stdio.h
> > index cb858618..8312c3bf 100644
> > --- a/include/stdio.h
> > +++ b/include/stdio.h
> > @@ -158,6 +158,13 @@ char *ctermid(char *);
> > #define L_ctermid 20
> > #endif
> >
> > +#if defined(_GNU_SOURCE)
> > +#define RENAME_NOREPLACE (1 << 0)
> > +#define RENAME_EXCHANGE (1 << 1)
> > +#define RENAME_WHITEOUT (1 << 2)
> > +
> > +int renameat2(int, const char *, int, const char *, unsigned int);
> > +#endif
>
> s/unsigned int/unsigned/ and maybe just write out the constants? I
> think that's the style musl uses most places.
>
> > #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
> > || defined(_BSD_SOURCE)
> > diff --git a/src/linux/renameat2.c b/src/linux/renameat2.c
> > new file mode 100644
> > index 00000000..3062aa15
> > --- /dev/null
> > +++ b/src/linux/renameat2.c
> > @@ -0,0 +1,8 @@
> > +#define _GNU_SOURCE
> > +#include <stdio.h>
> > +#include "syscall.h"
> > +
> > +int renameat2(int oldfd, const char *old, int newfd, const char *new, unsigned int flags)
> > +{
> > + return syscall(SYS_renameat2, oldfd, old, newfd, new, flags);
> > +}
> > --
> > 2.34.1
>
> This probably at least needs to support flags==0 on kernels without
> SYS_renameat2 by calling renameat in that case. Then I'm not sure if
> ENOSYS should be kept if the new syscall is missing, or just EINVAL or
> whatever is used to report unsupported flags.
>
> Rich
next prev parent reply other threads:[~2024-04-23 14:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-21 15:36 Tony Ambardar
2024-04-22 22:47 ` Rich Felker
2024-04-23 4:39 ` Tony Ambardar
2024-04-23 15:51 ` Rich Felker
2024-04-23 14:49 ` enh [this message]
2024-04-23 15:48 ` Rich Felker
2024-04-23 23:43 ` [musl] [PATCH v2] " Tony Ambardar
2024-05-06 14:50 ` Rich Felker
2024-05-06 23:42 ` Tony Ambardar
2024-05-07 0:01 ` Rich Felker
2024-05-07 3:28 ` [musl] [PATCH v3] " Tony Ambardar
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=CAJgzZoqNgZkWNwz-wP3ZGG0hM+brt65h9r0oZ_jDrLMa4s+Xyw@mail.gmail.com \
--to=enh@google.com \
--cc=musl@lists.openwall.com \
--cc=tony.ambardar@gmail.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).