\hypertarget{snp_8c_source}{}\doxysection{snp.\+c}
\label{snp_8c_source}\index{dev/snp/snp.c@{dev/snp/snp.c}}
\mbox{\hyperlink{snp_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00005}00005 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00006}00006 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00007}00007 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00008}00008 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00009}00009 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00010}00010 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00012}00012 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00013}00013 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00014}00014 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00015}00015 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00016}00016 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00017}00017 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00018}00018 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00019}00019 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00020}00020 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00021}00021 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00022}00022 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00023}00023 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00024}00024 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00025}00025 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00026}00026 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00027}00027 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00028}00028 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00029}00029 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00030}\mbox{\hyperlink{snp_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00030}} \mbox{\hyperlink{snp_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00031}00031 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00033}00033 \textcolor{preprocessor}{\#include <sys/conf.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <sys/fcntl.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <sys/filio.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00037}00037 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00038}00038 \textcolor{preprocessor}{\#include <sys/module.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <sys/poll.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00040}00040 \textcolor{preprocessor}{\#include <sys/proc.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <sys/snoop.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <sys/sx.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <sys/tty.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <sys/uio.h>}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00046}00046 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00047}\mbox{\hyperlink{snp_8c_a21e16f8416b309d568d87f8c6f2b46c9}{00047}} \textcolor{keyword}{static} \textcolor{keyword}{struct }cdev      *\mbox{\hyperlink{snp_8c_a21e16f8416b309d568d87f8c6f2b46c9}{snp\_dev}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00048}\mbox{\hyperlink{snp_8c_a5299a5f28a4b0bc49ef7935ecdda59a1}{00048}} \textcolor{keyword}{static} \mbox{\hyperlink{snp_8c_a5299a5f28a4b0bc49ef7935ecdda59a1}{MALLOC\_DEFINE}}(M\_SNP, \textcolor{stringliteral}{"{}snp"{}}, \textcolor{stringliteral}{"{}tty snoop device"{}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00049}00049 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00050}00050 \textcolor{comment}{/* XXX: should be mtx, but TTY can be locked by Giant. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00051}00051 \textcolor{preprocessor}{\#if 0}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00052}00052 \textcolor{keyword}{static} \textcolor{keyword}{struct }mtx       \mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{snp\_register\_lock}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00053}00053 MTX\_SYSINIT(\mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{snp\_register\_lock}}, \&\mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{snp\_register\_lock}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00054}00054     \textcolor{stringliteral}{"{}tty snoop registration"{}}, MTX\_DEF);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00055}00055 \textcolor{preprocessor}{\#define SNP\_LOCK()      mtx\_lock(\&snp\_register\_lock)}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00056}00056 \textcolor{preprocessor}{\#define SNP\_UNLOCK()    mtx\_unlock(\&snp\_register\_lock)}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00057}00057 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00058}\mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{00058}} \textcolor{keyword}{static} \textcolor{keyword}{struct }sx        \mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{snp\_register\_lock}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00059}\mbox{\hyperlink{snp_8c_ab9c66e5c0b7e8213847b861b669ab4b3}{00059}} \mbox{\hyperlink{snp_8c_ab9c66e5c0b7e8213847b861b669ab4b3}{SX\_SYSINIT}}(\mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{snp\_register\_lock}}, \&\mbox{\hyperlink{snp_8c_aac19dc15df7d928a9bc94aafaf7e26f1}{snp\_register\_lock}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00060}00060     \textcolor{stringliteral}{"{}tty snoop registration"{}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00061}\mbox{\hyperlink{snp_8c_a66d18b7ed0415bb0a283b5717d2093f0}{00061}} \textcolor{preprocessor}{\#define SNP\_LOCK()      sx\_xlock(\&snp\_register\_lock)}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00062}\mbox{\hyperlink{snp_8c_a6a0c599d6b61a46db913f3a5d8d9ee4b}{00062}} \textcolor{preprocessor}{\#define SNP\_UNLOCK()    sx\_xunlock(\&snp\_register\_lock)}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00063}00063 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00064}00064 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00065}\mbox{\hyperlink{snp_8c_ac33e655af6b8cda2a24541047cecdfa3}{00065}} \textcolor{preprocessor}{\#define SNPGTYY\_32DEV   \_IOR('T', 89, uint32\_t)}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00066}00066 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00067}00067 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00068}00068 \textcolor{comment}{ * There is no need to have a big input buffer. In most typical setups,}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00069}00069 \textcolor{comment}{ * we won't inject much data into the TTY, because users can't type}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00070}00070 \textcolor{comment}{ * really fast.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00071}00071 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00072}\mbox{\hyperlink{snp_8c_a28337f2bdc9ac092dbb0e6da3599daba}{00072}} \textcolor{preprocessor}{\#define SNP\_INPUT\_BUFSIZE       16}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00073}00073 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00074}00074 \textcolor{comment}{ * The output buffer has to be really big. Right now we don't support}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00075}00075 \textcolor{comment}{ * any form of flow control, which means we lost any data we can't}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00076}00076 \textcolor{comment}{ * accept. We set the output buffer size to about twice the size of a}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00077}00077 \textcolor{comment}{ * pseudo-\/terminal/virtual console's output buffer.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00078}00078 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00079}\mbox{\hyperlink{snp_8c_ac7296de6fbb2cc61f4ea7210bdfa4697}{00079}} \textcolor{preprocessor}{\#define SNP\_OUTPUT\_BUFSIZE      16384}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00080}00080 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00081}\mbox{\hyperlink{snp_8c_a44e0cf06b01819a5e6c2d10c0f0d6dc5}{00081}} \textcolor{keyword}{static} d\_open\_t         \mbox{\hyperlink{snp_8c_a44e0cf06b01819a5e6c2d10c0f0d6dc5}{snp\_open}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00082}\mbox{\hyperlink{snp_8c_a85effd15d23324918895d06f3ced4c33}{00082}} \textcolor{keyword}{static} d\_read\_t         \mbox{\hyperlink{snp_8c_a85effd15d23324918895d06f3ced4c33}{snp\_read}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00083}\mbox{\hyperlink{snp_8c_af87d2f9f1f9eb3de0e0f2cf9f8415f0d}{00083}} \textcolor{keyword}{static} d\_write\_t        \mbox{\hyperlink{snp_8c_af87d2f9f1f9eb3de0e0f2cf9f8415f0d}{snp\_write}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00084}\mbox{\hyperlink{snp_8c_a364187115e952bf11c7d77e090e97fa4}{00084}} \textcolor{keyword}{static} d\_ioctl\_t        \mbox{\hyperlink{snp_8c_a364187115e952bf11c7d77e090e97fa4}{snp\_ioctl}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00085}\mbox{\hyperlink{snp_8c_adb66194f687454132f9164723b823fa4}{00085}} \textcolor{keyword}{static} d\_poll\_t         \mbox{\hyperlink{snp_8c_adb66194f687454132f9164723b823fa4}{snp\_poll}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00086}00086 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00087}\mbox{\hyperlink{snp_8c_a6a1acb3a9a42942706085aebaf79c23f}{00087}} \textcolor{keyword}{static} \textcolor{keyword}{struct }cdevsw \mbox{\hyperlink{snp_8c_a6a1acb3a9a42942706085aebaf79c23f}{snp\_cdevsw}} = \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00088}00088         .d\_version      = D\_VERSION,}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00089}00089         .d\_open         = \mbox{\hyperlink{snp_8c_a44e0cf06b01819a5e6c2d10c0f0d6dc5}{snp\_open}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00090}00090         .d\_read         = \mbox{\hyperlink{snp_8c_a85effd15d23324918895d06f3ced4c33}{snp\_read}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00091}00091         .d\_write        = \mbox{\hyperlink{snp_8c_af87d2f9f1f9eb3de0e0f2cf9f8415f0d}{snp\_write}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00092}00092         .d\_ioctl        = \mbox{\hyperlink{snp_8c_a364187115e952bf11c7d77e090e97fa4}{snp\_ioctl}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00093}00093         .d\_poll         = \mbox{\hyperlink{snp_8c_adb66194f687454132f9164723b823fa4}{snp\_poll}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00094}00094         .d\_name         = \textcolor{stringliteral}{"{}snp"{}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00095}00095 \};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00096}00096 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00097}\mbox{\hyperlink{snp_8c_abe7f4c430b4e6d6b7e9c3707356a7ec4}{00097}} \textcolor{keyword}{static} th\_getc\_capture\_t        \mbox{\hyperlink{snp_8c_abe7f4c430b4e6d6b7e9c3707356a7ec4}{snp\_getc\_capture}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00098}00098 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00099}\mbox{\hyperlink{snp_8c_a9ac559390b0cc07d7ed5c12d7a54b01a}{00099}} \textcolor{keyword}{static} \textcolor{keyword}{struct }ttyhook \mbox{\hyperlink{snp_8c_a9ac559390b0cc07d7ed5c12d7a54b01a}{snp\_hook}} = \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00100}00100         .th\_getc\_capture        = \mbox{\hyperlink{snp_8c_abe7f4c430b4e6d6b7e9c3707356a7ec4}{snp\_getc\_capture}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00101}00101 \};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00102}00102 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00103}00103 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00104}00104 \textcolor{comment}{ * Per-\/instance structure.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00105}00105 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00106}00106 \textcolor{comment}{ * List of locks}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00107}00107 \textcolor{comment}{ * (r)  locked by snp\_register\_lock on assignment}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00108}00108 \textcolor{comment}{ * (t)  locked by tty\_lock}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00109}00109 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00110}\mbox{\hyperlink{structsnp__softc}{00110}} \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00111}\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{00111}}         \textcolor{keyword}{struct }tty      *\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};        \textcolor{comment}{/* (r) TTY we're snooping. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00112}\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{00112}}         \textcolor{keyword}{struct }ttyoutq  \mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}};       \textcolor{comment}{/* (t) Output queue. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00113}\mbox{\hyperlink{structsnp__softc_aea576a9a4e71181af74ed2efe050bfc5}{00113}}         \textcolor{keyword}{struct }cv       \mbox{\hyperlink{structsnp__softc_aea576a9a4e71181af74ed2efe050bfc5}{snp\_outwait}}; \textcolor{comment}{/* (t) Output wait queue. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00114}\mbox{\hyperlink{structsnp__softc_ae05c5fdd32d356699af99fd98c324337}{00114}}         \textcolor{keyword}{struct }selinfo  \mbox{\hyperlink{structsnp__softc_ae05c5fdd32d356699af99fd98c324337}{snp\_outpoll}}; \textcolor{comment}{/* (t) Output polling. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00115}00115 \};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00116}00116 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00117}00117 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00118}\mbox{\hyperlink{snp_8c_a4a1f7c56fde1c2a8fa7c4459b04737b7}{00118}} \mbox{\hyperlink{snp_8c_a4a1f7c56fde1c2a8fa7c4459b04737b7}{snp\_dtor}}(\textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00119}00119 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00120}00120         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss = data;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00121}00121         \textcolor{keyword}{struct }tty *tp;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00122}00122 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00123}00123         tp = ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00124}00124         \textcolor{keywordflow}{if} (tp != NULL) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00125}00125                 tty\_lock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00126}00126                 ttyoutq\_free(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00127}00127                 ttyhook\_unregister(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00128}00128         \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00129}00129 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00130}00130         cv\_destroy(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea576a9a4e71181af74ed2efe050bfc5}{snp\_outwait}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00131}00131         free(ss, M\_SNP);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00132}00132 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00133}00133 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00134}00134 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00135}00135 \textcolor{comment}{ * Snoop device node routines.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00136}00136 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00137}00137 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00138}00138 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00139}\mbox{\hyperlink{snp_8c_a1b9de401df8b473e446e3f65fe425817}{00139}} \mbox{\hyperlink{snp_8c_a44e0cf06b01819a5e6c2d10c0f0d6dc5}{snp\_open}}(\textcolor{keyword}{struct} cdev *dev, \textcolor{keywordtype}{int} flag, \textcolor{keywordtype}{int} mode, \textcolor{keyword}{struct} thread *td)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00140}00140 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00141}00141         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00142}00142 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00143}00143         \textcolor{comment}{/* Allocate per-\/snoop data. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00144}00144         ss = malloc(\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} \mbox{\hyperlink{structsnp__softc}{snp\_softc}}), M\_SNP, M\_WAITOK|M\_ZERO);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00145}00145         cv\_init(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea576a9a4e71181af74ed2efe050bfc5}{snp\_outwait}}, \textcolor{stringliteral}{"{}snp out"{}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00146}00146 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00147}00147         devfs\_set\_cdevpriv(ss, \mbox{\hyperlink{snp_8c_a4a1f7c56fde1c2a8fa7c4459b04737b7}{snp\_dtor}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00148}00148 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00149}00149         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00150}00150 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00151}00151 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00152}00152 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00153}\mbox{\hyperlink{snp_8c_ad74551081050ad60d988fcd815c60a95}{00153}} \mbox{\hyperlink{snp_8c_a85effd15d23324918895d06f3ced4c33}{snp\_read}}(\textcolor{keyword}{struct} cdev *dev, \textcolor{keyword}{struct} uio *uio, \textcolor{keywordtype}{int} flag)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00154}00154 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00155}00155         \textcolor{keywordtype}{int} error, oresid = uio-\/>uio\_resid;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00156}00156         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00157}00157         \textcolor{keyword}{struct }tty *tp;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00158}00158 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00159}00159         \textcolor{keywordflow}{if} (uio-\/>uio\_resid == 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00160}00160                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00161}00161 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00162}00162         error = devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&ss);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00163}00163         \textcolor{keywordflow}{if} (error != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00164}00164                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00165}00165 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00166}00166         tp = ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00167}00167         \textcolor{keywordflow}{if} (tp == NULL || tty\_gone(tp))}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00168}00168                 \textcolor{keywordflow}{return} (EIO);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00169}00169 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00170}00170         tty\_lock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00171}00171         \textcolor{keywordflow}{for} (;;) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00172}00172                 error = ttyoutq\_read\_uio(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}}, tp, uio);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00173}00173                 \textcolor{keywordflow}{if} (error != 0 || uio-\/>uio\_resid != oresid)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00174}00174                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00175}00175 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00176}00176                 \textcolor{comment}{/* Wait for more data. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00177}00177                 \textcolor{keywordflow}{if} (flag \& O\_NONBLOCK) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00178}00178                         error = EWOULDBLOCK;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00179}00179                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00180}00180                 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00181}00181                 error = cv\_wait\_sig(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea576a9a4e71181af74ed2efe050bfc5}{snp\_outwait}}, tty\_getlock(tp));}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00182}00182                 \textcolor{keywordflow}{if} (error != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00183}00183                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00184}00184                 \textcolor{keywordflow}{if} (tty\_gone(tp)) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00185}00185                         error = EIO;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00186}00186                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00187}00187                 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00188}00188         \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00189}00189         tty\_unlock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00190}00190 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00191}00191         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00192}00192 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00193}00193 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00194}00194 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00195}\mbox{\hyperlink{snp_8c_a79e8402f5cd58f26d7d3e22242faa62b}{00195}} \mbox{\hyperlink{snp_8c_af87d2f9f1f9eb3de0e0f2cf9f8415f0d}{snp\_write}}(\textcolor{keyword}{struct} cdev *dev, \textcolor{keyword}{struct} uio *uio, \textcolor{keywordtype}{int} flag)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00196}00196 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00197}00197         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00198}00198         \textcolor{keyword}{struct }tty *tp;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00199}00199         \textcolor{keywordtype}{int} error, len;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00200}00200         \textcolor{keywordtype}{char} in[\mbox{\hyperlink{snp_8c_a28337f2bdc9ac092dbb0e6da3599daba}{SNP\_INPUT\_BUFSIZE}}];}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00201}00201 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00202}00202         error = devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&ss);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00203}00203         \textcolor{keywordflow}{if} (error != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00204}00204                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00205}00205 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00206}00206         tp = ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00207}00207         \textcolor{keywordflow}{if} (tp == NULL || tty\_gone(tp))}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00208}00208                 \textcolor{keywordflow}{return} (EIO);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00209}00209 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00210}00210         \textcolor{keywordflow}{while} (uio-\/>uio\_resid > 0) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00211}00211                 \textcolor{comment}{/* Read new data. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00212}00212                 len = imin(uio-\/>uio\_resid, \textcolor{keyword}{sizeof} in);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00213}00213                 error = uiomove(in, len, uio);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00214}00214                 \textcolor{keywordflow}{if} (error != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00215}00215                         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00216}00216 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00217}00217                 tty\_lock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00218}00218 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00219}00219                 \textcolor{comment}{/* Driver could have abandoned the TTY in the mean time. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00220}00220                 \textcolor{keywordflow}{if} (tty\_gone(tp)) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00221}00221                         tty\_unlock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00222}00222                         \textcolor{keywordflow}{return} (ENXIO);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00223}00223                 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00224}00224 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00225}00225                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00226}00226 \textcolor{comment}{                 * Deliver data to the TTY. Ignore errors for now,}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00227}00227 \textcolor{comment}{                 * because we shouldn't bail out when we're running}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00228}00228 \textcolor{comment}{                 * close to the watermarks.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00229}00229 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00230}00230                 ttydisc\_rint\_simple(tp, in, len);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00231}00231                 ttydisc\_rint\_done(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00232}00232 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00233}00233                 tty\_unlock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00234}00234         \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00235}00235 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00236}00236         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00237}00237 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00238}00238 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00239}00239 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00240}\mbox{\hyperlink{snp_8c_a2121320d2263217291650b076d19b4ff}{00240}} \mbox{\hyperlink{snp_8c_a364187115e952bf11c7d77e090e97fa4}{snp\_ioctl}}(\textcolor{keyword}{struct} cdev *dev, u\_long cmd, caddr\_t data, \textcolor{keywordtype}{int} flags,}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00241}00241     \textcolor{keyword}{struct} thread *td)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00242}00242 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00243}00243         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00244}00244         \textcolor{keyword}{struct }tty *tp;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00245}00245         \textcolor{keywordtype}{int} error;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00246}00246 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00247}00247         error = devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&ss);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00248}00248         \textcolor{keywordflow}{if} (error != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00249}00249                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00250}00250 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00251}00251         \textcolor{keywordflow}{switch} (cmd) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00252}00252         \textcolor{keywordflow}{case} SNPSTTY:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00253}00253                 \textcolor{comment}{/* Bind TTY to snoop instance. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00254}00254                 \mbox{\hyperlink{snp_8c_a66d18b7ed0415bb0a283b5717d2093f0}{SNP\_LOCK}}();}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00255}00255                 \textcolor{keywordflow}{if} (ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}} != NULL) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00256}00256                         \mbox{\hyperlink{snp_8c_a6a0c599d6b61a46db913f3a5d8d9ee4b}{SNP\_UNLOCK}}();}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00257}00257                         \textcolor{keywordflow}{return} (EBUSY);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00258}00258                 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00259}00259                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00260}00260 \textcolor{comment}{                 * XXXRW / XXXJA: no capability check here.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00261}00261 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00262}00262                 error = ttyhook\_register(\&ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}}, td-\/>td\_proc,}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00263}00263                     *(\textcolor{keywordtype}{int} *)data, \&\mbox{\hyperlink{snp_8c_a9ac559390b0cc07d7ed5c12d7a54b01a}{snp\_hook}}, ss);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00264}00264                 \mbox{\hyperlink{snp_8c_a6a0c599d6b61a46db913f3a5d8d9ee4b}{SNP\_UNLOCK}}();}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00265}00265                 \textcolor{keywordflow}{if} (error != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00266}00266                         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00267}00267 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00268}00268                 \textcolor{comment}{/* Now that went okay, allocate a buffer for the queue. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00269}00269                 tp = ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00270}00270                 tty\_lock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00271}00271                 ttyoutq\_setsize(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}}, tp, \mbox{\hyperlink{snp_8c_ac7296de6fbb2cc61f4ea7210bdfa4697}{SNP\_OUTPUT\_BUFSIZE}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00272}00272                 tty\_unlock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00273}00273 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00274}00274                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00275}00275         \textcolor{keywordflow}{case} SNPGTTY:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00276}00276                 \textcolor{comment}{/* Obtain device number of associated TTY. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00277}00277                 \textcolor{keywordflow}{if} (ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}} == NULL)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00278}00278                         *(dev\_t *)data = NODEV;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00279}00279                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00280}00280                         *(dev\_t *)data = tty\_udev(ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00281}00281                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00282}00282         \textcolor{keywordflow}{case} \mbox{\hyperlink{snp_8c_ac33e655af6b8cda2a24541047cecdfa3}{SNPGTYY\_32DEV}}:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00283}00283                 \textcolor{keywordflow}{if} (ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}} == NULL)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00284}00284                         *(uint32\_t *)data = -\/1;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00285}00285                 \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00286}00286                         *(uint32\_t *)data = tty\_udev(ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}}); \textcolor{comment}{/* trunc */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00287}00287                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00288}00288         \textcolor{keywordflow}{case} FIONREAD:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00289}00289                 tp = ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00290}00290                 \textcolor{keywordflow}{if} (tp != NULL) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00291}00291                         tty\_lock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00292}00292                         *(\textcolor{keywordtype}{int} *)data = ttyoutq\_bytesused(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00293}00293                         tty\_unlock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00294}00294                 \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00295}00295                         *(\textcolor{keywordtype}{int} *)data = 0;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00296}00296                 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00297}00297                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00298}00298         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00299}00299                 \textcolor{keywordflow}{return} (ENOTTY);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00300}00300         \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00301}00301 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00302}00302 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00303}00303 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00304}\mbox{\hyperlink{snp_8c_a18b3c7eff3182a211cb504cfd9deabb5}{00304}} \mbox{\hyperlink{snp_8c_adb66194f687454132f9164723b823fa4}{snp\_poll}}(\textcolor{keyword}{struct} cdev *dev, \textcolor{keywordtype}{int} events, \textcolor{keyword}{struct} thread *td)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00305}00305 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00306}00306         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00307}00307         \textcolor{keyword}{struct }tty *tp;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00308}00308         \textcolor{keywordtype}{int} revents;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00309}00309 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00310}00310         \textcolor{keywordflow}{if} (devfs\_get\_cdevpriv((\textcolor{keywordtype}{void} **)\&ss) != 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00311}00311                 \textcolor{keywordflow}{return} (events \&}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00312}00312                     (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM));}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00313}00313 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00314}00314         revents = 0;}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00315}00315 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00316}00316         \textcolor{keywordflow}{if} (events \& (POLLIN | POLLRDNORM)) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00317}00317                 tp = ss-\/>\mbox{\hyperlink{structsnp__softc_ae6f4d61c91b409b81731e513171d3b2d}{snp\_tty}};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00318}00318                 \textcolor{keywordflow}{if} (tp != NULL) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00319}00319                         tty\_lock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00320}00320                         \textcolor{keywordflow}{if} (ttyoutq\_bytesused(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}}) > 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00321}00321                                 revents |= events \& (POLLIN | POLLRDNORM);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00322}00322                         tty\_unlock(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00323}00323                 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00324}00324         \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00325}00325 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00326}00326         \textcolor{keywordflow}{if} (revents == 0)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00327}00327                 selrecord(td, \&ss-\/>\mbox{\hyperlink{structsnp__softc_ae05c5fdd32d356699af99fd98c324337}{snp\_outpoll}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00328}00328 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00329}00329         \textcolor{keywordflow}{return} (revents);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00330}00330 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00331}00331 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00332}00332 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00333}00333 \textcolor{comment}{ * TTY hook events.}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00334}00334 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00335}00335 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00336}00336 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00337}\mbox{\hyperlink{snp_8c_a0b54701d498c7c6c6c5b96b260c5574a}{00337}} \mbox{\hyperlink{snp_8c_a0b54701d498c7c6c6c5b96b260c5574a}{snp\_modevent}}(module\_t mod, \textcolor{keywordtype}{int} type, \textcolor{keywordtype}{void} *data)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00338}00338 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00339}00339 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00340}00340         \textcolor{keywordflow}{switch} (type) \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00341}00341         \textcolor{keywordflow}{case} MOD\_LOAD:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00342}00342                 \mbox{\hyperlink{snp_8c_a21e16f8416b309d568d87f8c6f2b46c9}{snp\_dev}} = make\_dev(\&\mbox{\hyperlink{snp_8c_a6a1acb3a9a42942706085aebaf79c23f}{snp\_cdevsw}}, 0,}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00343}00343                     UID\_ROOT, GID\_WHEEL, 0600, \textcolor{stringliteral}{"{}snp"{}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00344}00344                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00345}00345         \textcolor{keywordflow}{case} MOD\_UNLOAD:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00346}00346                 \textcolor{comment}{/* XXX: Make existing users leave. */}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00347}00347                 destroy\_dev(\mbox{\hyperlink{snp_8c_a21e16f8416b309d568d87f8c6f2b46c9}{snp\_dev}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00348}00348                 \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00349}00349         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00350}00350                 \textcolor{keywordflow}{return} (EOPNOTSUPP);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00351}00351         \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00352}00352 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00353}00353 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00354}00354 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00355}\mbox{\hyperlink{snp_8c_a168fdf5ec92de59b948f14dbc0819a7b}{00355}} \mbox{\hyperlink{snp_8c_abe7f4c430b4e6d6b7e9c3707356a7ec4}{snp\_getc\_capture}}(\textcolor{keyword}{struct} tty *tp, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *buf, \textcolor{keywordtype}{size\_t} len)}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00356}00356 \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00357}00357         \textcolor{keyword}{struct }\mbox{\hyperlink{structsnp__softc}{snp\_softc}} *ss = ttyhook\_softc(tp);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00358}00358 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00359}00359         ttyoutq\_write(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea49baad648cff9da22afcdf8ad56cbb}{snp\_outq}}, buf, len);}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00360}00360 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00361}00361         cv\_broadcast(\&ss-\/>\mbox{\hyperlink{structsnp__softc_aea576a9a4e71181af74ed2efe050bfc5}{snp\_outwait}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00362}00362         selwakeup(\&ss-\/>\mbox{\hyperlink{structsnp__softc_ae05c5fdd32d356699af99fd98c324337}{snp\_outpoll}});}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00363}00363 \}}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00364}00364 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00365}\mbox{\hyperlink{snp_8c_a152be0403161112f47de2d080744f6bc}{00365}} \textcolor{keyword}{static} moduledata\_t \mbox{\hyperlink{snp_8c_a152be0403161112f47de2d080744f6bc}{snp\_mod}} = \{}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00366}00366         \textcolor{stringliteral}{"{}snp"{}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00367}00367         \mbox{\hyperlink{snp_8c_a0b54701d498c7c6c6c5b96b260c5574a}{snp\_modevent}},}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00368}00368         NULL}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00369}00369 \};}
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00370}00370 }
\DoxyCodeLine{\Hypertarget{snp_8c_source_l00371}\mbox{\hyperlink{snp_8c_a600e94de8842d012dc613c7af08cddb5}{00371}} \mbox{\hyperlink{snp_8c_a600e94de8842d012dc613c7af08cddb5}{DECLARE\_MODULE}}(snp, \mbox{\hyperlink{snp_8c_a152be0403161112f47de2d080744f6bc}{snp\_mod}}, SI\_SUB\_DRIVERS, SI\_ORDER\_MIDDLE);}

\end{DoxyCode}
