~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/um/drivers/fd.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
  4  */
  5 
  6 #include <stdio.h>
  7 #include <stdlib.h>
  8 #include <unistd.h>
  9 #include <errno.h>
 10 #include <termios.h>
 11 #include "chan_user.h"
 12 #include <os.h>
 13 #include <um_malloc.h>
 14 
 15 struct fd_chan {
 16         int fd;
 17         int raw;
 18         struct termios tt;
 19         char str[sizeof("1234567890\0")];
 20 };
 21 
 22 static void *fd_init(char *str, int device, const struct chan_opts *opts)
 23 {
 24         struct fd_chan *data;
 25         char *end;
 26         int n;
 27 
 28         if (*str != ':') {
 29                 printk(UM_KERN_ERR "fd_init : channel type 'fd' must specify a "
 30                        "file descriptor\n");
 31                 return NULL;
 32         }
 33         str++;
 34         n = strtoul(str, &end, 0);
 35         if ((*end != '\0') || (end == str)) {
 36                 printk(UM_KERN_ERR "fd_init : couldn't parse file descriptor "
 37                        "'%s'\n", str);
 38                 return NULL;
 39         }
 40 
 41         data = uml_kmalloc(sizeof(*data), UM_GFP_KERNEL);
 42         if (data == NULL)
 43                 return NULL;
 44 
 45         *data = ((struct fd_chan) { .fd         = n,
 46                                     .raw        = opts->raw });
 47         return data;
 48 }
 49 
 50 static int fd_open(int input, int output, int primary, void *d, char **dev_out)
 51 {
 52         struct fd_chan *data = d;
 53         int err;
 54 
 55         if (data->raw && isatty(data->fd)) {
 56                 CATCH_EINTR(err = tcgetattr(data->fd, &data->tt));
 57                 if (err)
 58                         return err;
 59 
 60                 err = raw(data->fd);
 61                 if (err)
 62                         return err;
 63         }
 64         sprintf(data->str, "%d", data->fd);
 65         *dev_out = data->str;
 66         return data->fd;
 67 }
 68 
 69 static void fd_close(int fd, void *d)
 70 {
 71         struct fd_chan *data = d;
 72         int err;
 73 
 74         if (!data->raw || !isatty(fd))
 75                 return;
 76 
 77         CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt));
 78         if (err)
 79                 printk(UM_KERN_ERR "Failed to restore terminal state - "
 80                        "errno = %d\n", -err);
 81         data->raw = 0;
 82 }
 83 
 84 const struct chan_ops fd_ops = {
 85         .type           = "fd",
 86         .init           = fd_init,
 87         .open           = fd_open,
 88         .close          = fd_close,
 89         .read           = generic_read,
 90         .write          = generic_write,
 91         .console_write  = generic_console_write,
 92         .window_size    = generic_window_size,
 93         .free           = generic_free,
 94         .winch          = 1,
 95 };
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php