Author: avg
Date: Sun May 13 17:10:38 2012
New Revision: 235407
URL: http://svn.freebsd.org/changeset/base/235407

Log:
  MFC r228633,228634,228638,228642,228643: introduce cngets,
  a method for kernel to read a string from console

Deleted:
  stable/9/sys/libkern/gets.c
Modified:
  stable/9/sys/conf/files
  stable/9/sys/geom/eli/g_eli.c
  stable/9/sys/kern/kern_cons.c
  stable/9/sys/kern/vfs_mountroot.c
  stable/9/sys/sys/cons.h
  stable/9/sys/sys/libkern.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)
  stable/9/sys/fs/   (props changed)
  stable/9/sys/fs/ntfs/   (props changed)
  stable/9/sys/i386/conf/XENHVM   (props changed)
  stable/9/sys/kern/subr_witness.c   (props changed)

Modified: stable/9/sys/conf/files
==============================================================================
--- stable/9/sys/conf/files     Sun May 13 17:05:54 2012        (r235406)
+++ stable/9/sys/conf/files     Sun May 13 17:10:38 2012        (r235407)
@@ -2541,7 +2541,6 @@ libkern/bcd.c                     standard
 libkern/bsearch.c              standard
 libkern/crc32.c                        standard
 libkern/fnmatch.c              standard
-libkern/gets.c                 standard
 libkern/iconv.c                        optional libiconv
 libkern/iconv_converter_if.m   optional libiconv
 libkern/iconv_ucs.c            optional libiconv

Modified: stable/9/sys/geom/eli/g_eli.c
==============================================================================
--- stable/9/sys/geom/eli/g_eli.c       Sun May 13 17:05:54 2012        
(r235406)
+++ stable/9/sys/geom/eli/g_eli.c       Sun May 13 17:10:38 2012        
(r235407)
@@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/cons.h>
 #include <sys/kernel.h>
 #include <sys/linker.h>
 #include <sys/module.h>
@@ -1089,7 +1090,7 @@ g_eli_taste(struct g_class *mp, struct g
                /* Ask for the passphrase if defined. */
                if (md.md_iterations >= 0) {
                        printf("Enter passphrase for %s: ", pp->name);
-                       gets(passphrase, sizeof(passphrase),
+                       cngets(passphrase, sizeof(passphrase),
                            g_eli_visible_passphrase);
                }
 

Modified: stable/9/sys/kern/kern_cons.c
==============================================================================
--- stable/9/sys/kern/kern_cons.c       Sun May 13 17:05:54 2012        
(r235406)
+++ stable/9/sys/kern/kern_cons.c       Sun May 13 17:10:38 2012        
(r235407)
@@ -1,6 +1,9 @@
 /*-
  * Copyright (c) 1988 University of Utah.
  * Copyright (c) 1991 The Regents of the University of California.
+ * Copyright (c) 1999 Michael Smith
+ * Copyright (c) 2005 Pawel Jakub Dawidek <p...@freebsd.org>
+ *
  * All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
@@ -408,6 +411,55 @@ cncheckc(void)
 }
 
 void
+cngets(char *cp, size_t size, int visible)
+{
+       char *lp, *end;
+       int c;
+
+       cngrab();
+
+       lp = cp;
+       end = cp + size - 1;
+       for (;;) {
+               c = cngetc() & 0177;
+               switch (c) {
+               case '\n':
+               case '\r':
+                       cnputc(c);
+                       *lp = '\0';
+                       cnungrab();
+                       return;
+               case '\b':
+               case '\177':
+                       if (lp > cp) {
+                               if (visible) {
+                                       cnputc(c);
+                                       cnputs(" \b");
+                               }
+                               lp--;
+                       }
+                       continue;
+               case '\0':
+                       continue;
+               default:
+                       if (lp < end) {
+                               switch (visible) {
+                               case GETS_NOECHO:
+                                       break;
+                               case GETS_ECHOPASS:
+                                       cnputc('*');
+                                       break;
+                               default:
+                                       cnputc(c);
+                                       break;
+                               }
+                               *lp++ = c;
+                       }
+               }
+       }
+}
+
+void
 cnputc(int c)
 {
        struct cn_device *cnd;

Modified: stable/9/sys/kern/vfs_mountroot.c
==============================================================================
--- stable/9/sys/kern/vfs_mountroot.c   Sun May 13 17:05:54 2012        
(r235406)
+++ stable/9/sys/kern/vfs_mountroot.c   Sun May 13 17:10:38 2012        
(r235407)
@@ -42,10 +42,10 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/conf.h>
+#include <sys/cons.h>
 #include <sys/fcntl.h>
 #include <sys/jail.h>
 #include <sys/kernel.h>
-#include <sys/libkern.h>
 #include <sys/malloc.h>
 #include <sys/mdioctl.h>
 #include <sys/mount.h>
@@ -486,7 +486,7 @@ parse_dir_ask(char **conf)
        do {
                error = EINVAL;
                printf("\nmountroot> ");
-               gets(name, sizeof(name), GETS_ECHO);
+               cngets(name, sizeof(name), GETS_ECHO);
                if (name[0] == '\0')
                        break;
                if (name[0] == '?' && name[1] == '\0') {

Modified: stable/9/sys/sys/cons.h
==============================================================================
--- stable/9/sys/sys/cons.h     Sun May 13 17:05:54 2012        (r235406)
+++ stable/9/sys/sys/cons.h     Sun May 13 17:10:38 2012        (r235407)
@@ -86,6 +86,11 @@ struct consdev {
 #define        CN_FLAG_NODEBUG 0x00000001      /* Not supported with debugger. 
*/
 #define        CN_FLAG_NOAVAIL 0x00000002      /* Temporarily not available. */
 
+/* Visibility of characters in cngets() */
+#define        GETS_NOECHO     0       /* Disable echoing of characters. */
+#define        GETS_ECHO       1       /* Enable echoing of characters. */
+#define        GETS_ECHOPASS   2       /* Print a * for every character. */
+
 #ifdef _KERNEL
 
 extern struct msgbuf consmsgbuf; /* Message buffer for constty. */
@@ -121,6 +126,7 @@ void        cngrab(void);
 void   cnungrab(void);
 int    cncheckc(void);
 int    cngetc(void);
+void   cngets(char *, size_t, int);
 void   cnputc(int);
 void   cnputs(char *);
 int    cnunavailable(void);

Modified: stable/9/sys/sys/libkern.h
==============================================================================
--- stable/9/sys/sys/libkern.h  Sun May 13 17:05:54 2012        (r235406)
+++ stable/9/sys/sys/libkern.h  Sun May 13 17:10:38 2012        (r235407)
@@ -90,7 +90,6 @@ int    fls(int);
 int     flsl(long);
 #endif
 int     fnmatch(const char *, const char *, int);
-void    gets(char *, size_t, int);
 int     locc(int, char *, u_int);
 void   *memchr(const void *s, int c, size_t n);
 int     memcmp(const void *b1, const void *b2, size_t len);
@@ -188,9 +187,4 @@ strrchr(const char *p, int ch)
 #define        FNM_IGNORECASE  FNM_CASEFOLD
 #define        FNM_FILE_NAME   FNM_PATHNAME
 
-/* Visibility of characters in gets() */
-#define        GETS_NOECHO     0       /* Disable echoing of characters. */
-#define        GETS_ECHO       1       /* Enable echoing of characters. */
-#define        GETS_ECHOPASS   2       /* Print a * for every character. */
-
 #endif /* !_SYS_LIBKERN_H_ */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to