
Everything's a File Descriptor Josh Triplett [email protected] Linux Plumbers Conference 2015 \Everything's a file” I /etc/hostname I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/1/environ I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/1/environ I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/1/environ I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/null I /dev/zero I /tmp/.X11-unix/X0 I /proc/1/environ I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /proc/1/environ I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/1/environ I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/1/environ I /proc/cmdline I /home/josh/doc/presentations/lpc-2015/fd/fd.pdf I /etc/hostname I /dev/null I /dev/zero I /dev/ttyS0 I /dev/dri/card0 I /dev/cpu/0/cpuid I /tmp/.X11-unix/X0 I /proc/1/environ I /proc/cmdline I /sys/class/block/sda/queue/rotational I /sys/firmware/acpi/tables/DSDT Everything has a filename? Everything has a filename? Everything//////////////////////////////// has a filename? I Pipes I Sockets I epoll I memfd I KVM virtual machines and CPUs I ... Everything's a file descriptor I What is a file descriptor, really? I What can you do with a file descriptor? I What interesting file descriptors exist? I How do you build a new type of file descriptors? I What interesting file descriptors don't exist? I What is a file descriptor, really? I What can you do with a file descriptor? I What interesting file descriptors exist? I How do you build a new type of file descriptors? I What interesting file descriptors don't exist yet? What is a file descriptor, really? I struct fd, struct fdtable I struct file read(x, &c, 1); putchar(c); read(xdup, &c, 1); putchar(c); read(y, &c, 1); putchar(c); struct fd versus struct file testfile contains \0123456789" x = open("testfile", O_RDONLY); xdup = dup(x); y = open("testfile", O_RDONLY); struct fd versus struct file testfile contains \0123456789" x = open("testfile", O_RDONLY); xdup = dup(x); y = open("testfile", O_RDONLY); read(x, &c, 1); putchar(c); read(xdup, &c, 1); putchar(c); read(y, &c, 1); putchar(c); struct fd versus struct file testfile contains \0123456789" x = open("testfile", O_RDONLY); xdup = dup(x); y = open("testfile", O_RDONLY); read(x, &c, 1); putchar(c); /* Prints '0' */ read(xdup, &c, 1); putchar(c); read(y, &c, 1); putchar(c); struct fd versus struct file testfile contains \0123456789" x = open("testfile", O_RDONLY); xdup = dup(x); y = open("testfile", O_RDONLY); read(x, &c, 1); putchar(c); /* Prints '0' */ read(xdup, &c, 1); putchar(c); /* Prints '1' */ read(y, &c, 1); putchar(c); struct fd versus struct file testfile contains \0123456789" x = open("testfile", O_RDONLY); xdup = dup(x); y = open("testfile", O_RDONLY); read(x, &c, 1); putchar(c); /* Prints '0' */ read(xdup, &c, 1); putchar(c); /* Prints '1' */ read(y, &c, 1); putchar(c); /* Prints '0' */ x f pos: f count: f pos: 0 xdup f count: 1 y userspace int kernel object driver-specific struct fd struct file testfile 0 1 2 3 . f pos: 0 xdup f count: 1 y userspace int kernel object driver-specific struct fd struct file testfile f pos: 0 x 0 f count: 1 1 2 3 . f pos: 0 f count: 1 y userspace int kernel object driver-specific struct fd struct file testfile f pos: 0 x 0 f count:2 1 xdup 2 3 . userspace int kernel object driver-specific struct fd struct file testfile f pos: 0 x 0 f count:2 1 f pos: 0 xdup f count: 1 2 y 3 . userspace int kernel object driver-specific struct fd struct file testfile f pos:1 x 0 f count:2 1 f pos: 0 xdup f count: 1 2 y 3 . userspace int kernel object driver-specific struct fd struct file testfile f pos:2 x 0 f count:2 1 f pos: 0 xdup f count: 1 2 y 3 . userspace int kernel object driver-specific struct fd struct file testfile f pos:2 x 0 f count:2 1 f pos:1 xdup f count: 1 2 y 3 . kernel object driver-specific struct fd struct file testfile f pos:2 x 0 f count:2 1 f pos:1 xdup f count: 1 2 y 3 . userspace int driver-specific struct fd struct file testfile f pos:2 x 0 f count:2 1 f pos:1 xdup f count: 1 2 y 3 . userspace int kernel object struct fd struct file testfile f pos:2 x 0 f count:2 1 f pos:1 xdup f count: 1 2 y 3 . userspace int kernel object driver-specific File descriptor: Userspace reference to kernel object What can you do with a file descriptor? I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Inherited over exec I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I mmap I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I sendfile, splice, tee I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I openat I ... I ioctl I read, write I seek I preadv, pwritev I stat I Blocking or non-blocking I poll, select, epoll I dup, dup2 I Send over a UNIX socket via SCM_RIGHTS I Inherited over exec I mmap I sendfile, splice, tee I ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages140 Page
-
File Size-