You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/07 13:10:50 UTC

[incubator-nuttx] 01/07: Split common_ioctl to telnet_ioctl and factory_ioctl

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr215
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 2e6de18c403801ebca6f60221310fb6e522f9141
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Feb 5 16:12:53 2020 +0800

    Split common_ioctl to telnet_ioctl and factory_ioctl
    
    and remove the wrong telnet_poll from g_factory_fops
    
    Change-Id: I39f278763ff279d464c5be6728b9936c6cab16eb
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/net/telnet.c | 109 +++++++++++++++++++++++++++++----------------------
 1 file changed, 62 insertions(+), 47 deletions(-)

diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c
index 206349f..92e6b05 100644
--- a/drivers/net/telnet.c
+++ b/drivers/net/telnet.c
@@ -215,6 +215,8 @@ static ssize_t telnet_read(FAR struct file *filep, FAR char *buffer,
                  size_t len);
 static ssize_t telnet_write(FAR struct file *filep, FAR const char *buffer,
                  size_t len);
+static int     telnet_ioctl(FAR struct file *filep, int cmd,
+                 unsigned long arg);
 static int     telnet_poll(FAR struct file *filep, FAR struct pollfd *fds,
                  bool setup);
 
@@ -228,7 +230,7 @@ static ssize_t factory_read(FAR struct file *filep, FAR char *buffer,
                  size_t buflen);
 static ssize_t factory_write(FAR struct file *filep, FAR const char *buffer,
                  size_t buflen);
-static int     common_ioctl(FAR struct file *filep, int cmd,
+static int     factory_ioctl(FAR struct file *filep, int cmd,
                  unsigned long arg);
 
 /****************************************************************************
@@ -242,7 +244,7 @@ static const struct file_operations g_telnet_fops =
   telnet_read,   /* read */
   telnet_write,  /* write */
   NULL,          /* seek */
-  common_ioctl,  /* ioctl */
+  telnet_ioctl,  /* ioctl */
   telnet_poll    /* poll */
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   , NULL         /* unlink */
@@ -256,8 +258,8 @@ static const struct file_operations g_factory_fops =
   factory_read,  /* read */
   factory_write, /* write */
   NULL,          /* seek */
-  common_ioctl,  /* ioctl */
-  telnet_poll    /* poll */
+  factory_ioctl, /* ioctl */
+  NULL           /* poll */
 #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
   , NULL         /* unlink */
 #endif
@@ -1215,6 +1217,58 @@ static ssize_t factory_write(FAR struct file *filep, FAR const char *buffer,
 }
 
 /****************************************************************************
+ * Name: telnet_ioctl
+ ****************************************************************************/
+
+static int telnet_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode *inode = filep->f_inode;
+  FAR struct telnet_dev_s *priv = inode->i_private;
+  int ret = OK;
+
+  switch (cmd)
+    {
+#ifdef HAVE_SIGNALS
+      /* Make the given terminal the controlling terminal of the calling process */
+
+    case TIOCSCTTY:
+      {
+        /* Check if the ISIG flag is set in the termios c_lflag to enable
+         * this feature.  This flag is set automatically for a serial console
+         * device.
+         */
+
+        /* Save the PID of the recipient of the SIGINT signal. */
+
+        priv->td_pid = (pid_t)arg;
+        DEBUGASSERT((unsigned long)(priv->td_pid) == arg);
+      }
+      break;
+#endif
+
+#ifdef CONFIG_TELNET_SUPPORT_NAWS
+      case TIOCGWINSZ:
+        {
+          FAR struct winsize *pw = (FAR struct winsize *)((uintptr_t)arg);
+
+          /* Get row/col from the private data */
+
+          pw->ws_row = priv->td_rows;
+          pw->ws_col = priv->td_cols;
+        }
+      break;
+#endif
+
+    default:
+      ret = -ENOTTY;
+      break;
+    }
+
+  UNUSED(priv);  /* Avoid warning if not used */
+  return ret;
+}
+
+/****************************************************************************
  * Name: telnet_poll
  *
  * Description:
@@ -1383,15 +1437,12 @@ static int telnet_io_main(int argc, FAR char** argv)
 }
 
 /****************************************************************************
- * Name: common_ioctl
+ * Name: factory_ioctl
  ****************************************************************************/
 
-static int common_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+static int factory_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
 {
-  FAR struct inode *inode = filep->f_inode;
-  FAR struct telnet_dev_s *priv = inode->i_private;
-
-  int ret;
+  int ret = OK;
 
   switch (cmd)
     {
@@ -1405,7 +1456,7 @@ static int common_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
     case SIOCTELNET:
       {
         FAR struct telnet_session_s *session =
-            (FAR struct telnet_session_s *)((uintptr_t) arg);
+            (FAR struct telnet_session_s *)((uintptr_t)arg);
 
         if (session == NULL)
           {
@@ -1418,47 +1469,11 @@ static int common_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
       }
       break;
 
-#ifdef HAVE_SIGNALS
-      /* Make the given terminal the controlling terminal of the calling process */
-
-    case TIOCSCTTY:
-      {
-        /* Check if the ISIG flag is set in the termios c_lflag to enable
-         * this feature.  This flag is set automatically for a serial console
-         * device.
-         */
-
-        /* Save the PID of the recipient of the SIGINT signal. */
-
-        priv->pid = (pid_t)arg;
-        DEBUGASSERT((unsigned long)(priv->pid) == arg);
-
-        ret = OK;
-      }
-      break;
-#endif
-
-#ifdef CONFIG_TELNET_SUPPORT_NAWS
-      case TIOCGWINSZ:
-        {
-          FAR struct winsize *pw = (FAR struct winsize *)((uintptr_t)arg);
-
-          /* Get row/col from the private data */
-
-          pw->ws_row = priv->td_rows;
-          pw->ws_col = priv->td_cols;
-
-          ret = OK;
-        }
-      break;
-#endif
-
     default:
       ret = -ENOTTY;
       break;
     }
 
-  UNUSED(priv);  /* Avoid warning if not used */
   return ret;
 }