[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


previous: >>108323183

#define __NR_rename                82
#define __NR_renameat 264
#define __NR_renameat2 316

https://man7.org/linux/man-pages/man2/rename.2.html

tl;dr:
rename a file

mostly a pretty cut and dry syscall. it's only with renameat2 that things start to get interesting, since you can add flags to the call.
RENAME_EXCHANGE
and
RENAME_NOREPLACE
both make sense intuitively and seem like the type of flags that ought to exist.
RENAME_WHITEOUT
is a bit more confusing imo, but that's probably just because i have no experience with overlay/union filesystem implementations. anyone ever used one of those? want to explain to the class wtf is going on? it sort of seems equivalent to bind mounting a null file overtop of it? or something along those lines. the filesystem concept seems pretty interesting in general
aside from that, there are lots of interesting caveats, e.g.
>... there will probably be a window in which both oldpath and newpath refer to the file being renamed.
what do you think, anon? are any of the caveats particularly interesting to you?

relevant resources:
man man

man syscalls

https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
>>
bampu
>>
i want private lessons on syscalls from syscall anon
>>
>>108329890
>grep -rn "rename" mydir
Yep I have called it to rename filenames of porn videos downloaded from pornhub that contains spaces in them to filenames with no space.
>>
Funny how they mention in a side sentence that it used to move files between directories, even though this is the only way you can move files in Linux.
>>
>>108332356
You can also make a new file, copy the contents, and delete the old one. In fact, you have to do this when copying to a different filesystem because rename will fail.
>>108329890
>rename
>renameat
>renameat2
More unix braindamage. They should've gotten it right the first time and only had renameat2, but no, they had to mess it up twice first.
>>
File: 23732972.gif (403 KB, 500x250)
403 KB
403 KB GIF
>>108333195
>ren a meat
>>
>>108330697
i assume this is meant to be a lewd joke, but in case it is serious, i don't mind taking to anyone from this thread on some third party platform, whether it's helping with syscalls or just discussing them
but it's probably just a lewd joke
>>108330873
lol
glad you've found it useful, anon
>>108333195
it's actually horrifying how many times they have done things like this
and you just know it's never going away at this point
god they should really have just made all syscalls take an extra argument, and then used it as an api version flag so we could avoid this sort of monstrosity
>>
>On NFS filesystems, you can not assume that if the operation failed, the file was not renamed
>>
>>108334644
that's an issue with basically any async or remote operation, unfortunately
how can you differentiate between a failure of the operation and a failure of the communication?
>>
bampu
>>
>>108334620
no it wasn't a lewd joke
>>
>>108334644
Try copying a file on a NFS and see how it goes.
The file is copied once to your computer, then once to the server again. You have to use specific sycalls (not just read+write) to get it done.
https://sourceware.org/glibc/manual/2.43/html_mono/libc.html#Copying-File-Data
>>
>>108336281
Of note copy_file_range() will also make reflink copies if possible, so it's a good idea to use it even on local filesystems.
>>
File: cow.png (20 KB, 733x113)
20 KB
20 KB PNG
>>108337317
the glibc documentation doesn't mention it, but the copy_file_range syscall doc mentions it.

the downside of using copy_file_range is that you have to handle EXDEV when you want to copy from two different filesystems
>>
>>108336090
oh, sure then i'm fine with it
>>
>>108337762
how was your day, syscall anon?
>>
>>108337789
well i just woke up, but if you mean yesterday, then it was good. was a bit tired, but i slept more last night
>>
>>108337750
Checking for EXDEV and falling back to sendfile() is your best bet. Then falling back from sendfile() to doing read/write manually, if your program might need to go back in time and run on the handful of 2.6.X kernel revisions where sendfile() was broken (I think that raised EINVAL? But I don't have the docs to hand for such an old kernel).
>>
File: plot.png (211 KB, 3106x1346)
211 KB
211 KB PNG
>>108337984
yeah that's usually the best course of action, but it always fall back to read+write, since it's the most portable. but for NFS (or other fuse fs) it's really bad
>>
>>108337897
sorry, i'm retarded
i just forgot negative UTC time zones exist
>>
>>108338112
my timezone is the only one in the world that matters B-)



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.