previous: >>108301681
#define __NR_getdents 78
#define __NR_getdents64 217
https://man7.org/linux/man-pages/man2/getdents.2.html
https://man7.org/linux/man-pages/man3/readdir.3.html
tl;dr:
retrieve information about entries in a directory
honestly what the fuck even is this syscall? first of all, let's take a peek at the manpage
> These are not the interfaces you are interested in.
thank you, obi-wan. very cool
and what the fuuuuuck is this api? you provide it a buffer of length count (but in the non-64 one, you have to cast to either struct linux_dirent *
(which you'd have to define yourself, since it isn't included in any standard headers), or void *)
and look at this struct???
struct linux_dirent {
unsigned long d_ino; /* Inode number */
unsigned long d_off; /* Not an offset; see below */
unsigned short d_reclen; /* Length of this linux_dirent */
char d_name[]; /* Filename (null-terminated) */
/* length is actually */
/* (d_reclen - 2 - offsetof(struct linux_dirent, d_name)) */
/*
char pad; // Zero padding byte
char d_type; // File type (only since Linux 2.6.4);
// offset is (d_reclen - 1)
*/
}
genuinely i have no idea what these zany fucks were thinking with some of these.
you can also see an unhinged ternary chain in the example program, since C for some reason refuses to implement switch assignments. that's one of my biggest gripes with the language
anyway, yeah, this one is icky. pic related is how i feel looking at some of these syscalls that were clearly not ever meant to actually see the light of day
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/