[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]


File: Tumblr_l_53001038701499.png (2.49 MB, 1500x1500)
2.49 MB
2.49 MB PNG
previous: >>108329890

#define __NR_mkdir                83
#define __NR_rmdir 84
#define __NR_mkdirat 258

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

tl;dr:
make or remove a directory

these are pretty much exactly the same as their command-line counterparts. it's actually kind of neat how close they are.
otherwise, though, there's not really much to discuss about these lol. they do what they say on the tin. maybe now is a good opportunity to discuss https://man7.org/linux/man-pages/man7/inode.7.html
filesystems are wickedly complicated, but so interesting. if you haven't ever looked into them before, i really recommend it. it's quite an engaging subject

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/
>>
>>108337962
best paired with ftw
>>
>>108337962
Since the directory must be empty for rmdir, what's the difference between rmdir and unlink (remove)? is it simply that it fails if the path is not a directory?
>>
>>108338081
Oh, unlink doesn't work for directories unless flag contains AT_REMOVEDIR. Why.
>>
can someone explain the me the point of mkdirat and why it was added?
>>
>>108338270
> See openat(2) for an explanation of the need for mkdirat().
:)
https://man7.org/linux/man-pages/man2/openat.2.html
> Rationale for openat() and other directory file descriptor APIs
tl;dr: working directory shenanigans
>>
>>108337962
it seems to me like many syscalls (I know 0 of em just been seeing your threads) are mirrored by bash/shell, is that so?
>>
>>108338325
a lot of the filesystem ones are, yeah. because those are the sorts of operations you'd generally want to perform from the shell
>>
>>108337962
the last time I've dealt with file systems was in operating systems in uni... I have not dealt with since them besides being happy they're there and working
>>
>>108337962
Fun fact: the mkdir syscall didn't exist until V9 Unix. Before then you had to call mknod with the directory bit set and manually link the . and .. entries. If you did this wrong it screwed up the filesystem, so it required root, so the mkdir command had to be setuid.
https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/mkdir.c
>>
>>108337962
do all these syscalls exist in minix?
>>
>>108338332
that's super cool
>>
>>108337962
How to break almost every filesystem scanning tool:
#define _GNU_SOURCE
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main() {
int fd = open("/tmp", O_PATH | O_DIRECTORY | O_CLOEXEC);
if (fd == -1) {
perror("open");
return 1;
}
for (int i = 0; i < 1000000; i++) {
int res = mkdirat(fd, "a", 0755);
if (res == -1) {
perror("mkdirat");
return 1;
}
int nfd = openat(fd, "a", O_PATH | O_DIRECTORY | O_CLOEXEC);
if (nfd == -1) {
perror("openat");
return 1;
}
close(fd);
fd = nfd;
}
return 0;
}
>>
>>108340335
IIRC Minix is POSIX-compliant, so the basic ones like mkdir should be there for sure.
>>
>>108341139
Oh, so it's partially to work around MAX_PATH. Interesting.
>>
>>108341139
I'm curious as to what actually happens. I've run it with a 1000 subdirs just now, and that works just fine. What's the biggest number you've tried?
>>
>>108341674
For me, it quits at i=1,048,557 on /tmp and I'm not brave enough to try on my SSD.
TIL, there's a such thing as an inode limit: https://stackoverflow.com/a/8238973
$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
...
tmpfs 1048576 1048574 2 100% /tmp
...
>>
>>108341708
>IUse%
>100%
lmao. Well, I've done the same just now and now my poor compiler cannot output its intermediate assembly anywhere...
Interestingly, gcc doesn't seem to mind, even though I do happen to be aware that it does tend to output intermediary assembly files into /tmp as well... hoo knows.
>>
bampu
>>
>>108340256
this is the kind of psychotic dirty laundry i just love to learn about
>>108341139
this is also really neat
>>
bampu
>>
>>108338270
You get race conditions for files outside your pwd without the *at syscalls.

The only correct way to emulate the behavior often involves forking/chdiring/passing fds over a socket.

I've had to port network software to older OSes that don't have these and it's not fun.
>>
bampu



[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.