home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8709 / 13 < prev    next >
Encoding:
Internet Message Format  |  1990-07-13  |  23.8 KB

  1. Path: uunet!seismo!sundc!pitstop!sun!decwrl!decvax!ima!necntc!ncoast!allbery
  2. From: eric@ms.uky.edu@mandrill.CWRU.Edu (Eric Herrin)
  3. Newsgroups: comp.sources.misc
  4. Subject: Working Pty Driver for UnixPC
  5. Keywords: loadable drivers, unixpc, pty
  6. Message-ID: <4556@ncoast.UUCP>
  7. Date: 24 Sep 87 00:45:52 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Organization: U of Ky, Math. Sciences, Lexington KY
  10. Lines: 866
  11. Approved: allbery@ncoast.UUCP
  12. X-Archive: comp.sources.misc/8709/13
  13.  
  14. Mr. Moderator:
  15.  
  16. The pty driver which I posted earlier this week was the wrong version,
  17. ie. it didn't work.  This one does, so if you have not yet sent
  18. the earlier one out, please replace it with this one.
  19.  
  20. Sorry for the inconvenience.
  21.  
  22.             eric
  23.  
  24.  
  25. |                                          | 
  26. |    Eric Herrin II                         cbosgd!ukma!eric      |
  27. |    "'tis better to be silent                             eric@UKMA.BITNET      |
  28. |     and be THOUGHT a fool, than to open                  eric@ms.uky.csnet     |
  29. |     one's mouth and remove all doubt."                eric@ms.uky.edu       |
  30.  
  31. ___________________________cut here___________________________________
  32.  
  33. #! /bin/sh
  34. : This is a shell archive, meaning:
  35. : 1. Remove everything above the '#! /bin/sh' line.
  36. : 2. Save the resulting text in a file.
  37. : 3. Execute the file with /bin/sh '(not csh)' to create the files:
  38. :    'Install'
  39. :    'MakeFloppy'
  40. :    'MakePtys'
  41. :    'Name'
  42. :    'PTSCNT'
  43. :    'README.3b1'
  44. :    'READ_ME'
  45. :    'Remove'
  46. :    'Size'
  47. :    'pty.c'
  48. :    'pty.mk'
  49. : This archive created: 'Sun Sep 20 11:44:39 1987
  50. '
  51. export PATH; PATH=/bin:$PATH
  52. echo shar: extracting "'Install'" '(1558 characters)'
  53. if test -f 'Install'
  54. then
  55.     echo shar: will not over-write existing file "'Install'"
  56. else
  57. sed 's/^X//'  >'Install' <<'SHAR_EOF'
  58. X# Eric H. Herrin II
  59. X# University of Kentucky Mathematical Sciences
  60. X# eric@ms.uky.edu, eric@ms.uky.csnet, !cbosgd!ukma!eric
  61. X#
  62. X# Install script for System V Pty driver
  63. XMODULE=pty
  64. X# put the module in the appropriate place
  65. Xcp ${MODULE}.o /etc/lddrv/${MODULE}.o
  66. X# add the entry to the /etc/master file
  67. X/etc/masterupd -a char open release close read write ioctl ${MODULE}
  68. X# get the assigned device number
  69. XMODULEDEVNO=`/etc/masterupd -c ${MODULE}`
  70. Xif [  ! ${MODULEDEVNO} ]
  71. Xthen 
  72. X    echo "${MODULEDEVNO} cannot be added to the /etc/master file"
  73. X    exit 1
  74. Xfi
  75. X# NOTE!!!!!!!!!!!!!!
  76. X# To change the number of ptys, change the value in PTSCNT
  77. X# VVVVVVV
  78. XPTSCNT=`cat PTSCNT`
  79. X# make the pty device files
  80. Xcnt=0
  81. Xfor x in p q r s t u v w x y z
  82. Xdo
  83. X    for y in 0 1 2 3 4 5 6 7 8 9 a b c d e f
  84. X    do
  85. X        i=$x$y
  86. X        if [ $cnt -ge ${PTSCNT} ] 
  87. X        then 
  88. X            break
  89. X        fi
  90. X        /etc/mknod /dev/pty$i c ${MODULEDEVNO}\
  91. X `expr $cnt + $PTSCNT`
  92. X        /etc/mknod /dev/tty$i c ${MODULEDEVNO} $cnt
  93. X        cnt=`expr $cnt + 1`
  94. X    done
  95. Xdone
  96. X
  97. X# put an entry in /etc/lddrv/InstDrv for ${MODULE}
  98. Xecho "Name=${MODULE} driver"                 >> /etc/lddrv/InstDrv
  99. Xecho "File=${MODULE}"                     >> /etc/lddrv/InstDrv
  100. Xecho "Comment=Pseudo tty (pty) driver (Slave & Master side)"     >> /etc/lddrv/InstDrv
  101. Xcd /etc/lddrv
  102. X# allocate and load the module
  103. X./lddrv -av -o ${MODULE}.o ${MODULE}
  104. Xif [ $? -eq 0 ]
  105. Xthen
  106. X    echo "Driver ${MODULE} successfully loaded"
  107. Xelse
  108. X    echo "Error: Driver ${MODULE} failed loading stage"
  109. X    exit 1
  110. Xfi
  111. X
  112. X# load the ${MODULE} at boot time
  113. Xecho ${MODULE} >> /etc/lddrv/drivers
  114. X
  115. Xecho "Pseudo tty drivers are now installed"
  116. Xexit 0
  117. SHAR_EOF
  118. if test 1558 -ne "`wc -c < 'Install'`"
  119. then
  120.     echo shar: error transmitting "'Install'" '(should have been 1558 characters)'
  121. fi
  122. chmod +x 'Install'
  123. fi # end of overwriting check
  124. echo shar: extracting "'MakeFloppy'" '(139 characters)'
  125. if test -f 'MakeFloppy'
  126. then
  127.     echo shar: will not over-write existing file "'MakeFloppy'"
  128. else
  129. sed 's/^X//'  >'MakeFloppy' <<'SHAR_EOF'
  130. Xecho "Insert floppy disk and press return"
  131. Xread junk
  132. X/usr/bin/fdfmt.nl
  133. Xfind Size Name Remove Install pty.o -print | cpio -oBc > /dev/fp021
  134. SHAR_EOF
  135. if test 139 -ne "`wc -c < 'MakeFloppy'`"
  136. then
  137.     echo shar: error transmitting "'MakeFloppy'" '(should have been 139 characters)'
  138. fi
  139. fi # end of overwriting check
  140. echo shar: extracting "'MakePtys'" '(133 characters)'
  141. if test -f 'MakePtys'
  142. then
  143.     echo shar: will not over-write existing file "'MakePtys'"
  144. else
  145. sed 's/^X//'  >'MakePtys' <<'SHAR_EOF'
  146. XPTYCNT=`cat ./PTSCNT`
  147. XDEFS=" -DKERNEL -Ddefined_io -DUNIXPC -UDEBUG -DNOSTREAMS -D\"PTSCNT=$PTYCNT\""
  148. Xmake -f pty.mk "DEFS=$DEFS" $*
  149. SHAR_EOF
  150. if test 133 -ne "`wc -c < 'MakePtys'`"
  151. then
  152.     echo shar: error transmitting "'MakePtys'" '(should have been 133 characters)'
  153. fi
  154. fi # end of overwriting check
  155. echo shar: extracting "'Name'" '(78 characters)'
  156. if test -f 'Name'
  157. then
  158.     echo shar: will not over-write existing file "'Name'"
  159. else
  160. sed 's/^X//'  >'Name' <<'SHAR_EOF'
  161. XPty Driver (Modified for the UNIX-PC by University of Kentucky Math Sciences)
  162. SHAR_EOF
  163. if test 78 -ne "`wc -c < 'Name'`"
  164. then
  165.     echo shar: error transmitting "'Name'" '(should have been 78 characters)'
  166. fi
  167. fi # end of overwriting check
  168. echo shar: extracting "'PTSCNT'" '(3 characters)'
  169. if test -f 'PTSCNT'
  170. then
  171.     echo shar: will not over-write existing file "'PTSCNT'"
  172. else
  173. sed 's/^X//'  >'PTSCNT' <<'SHAR_EOF'
  174. X32
  175. SHAR_EOF
  176. if test 3 -ne "`wc -c < 'PTSCNT'`"
  177. then
  178.     echo shar: error transmitting "'PTSCNT'" '(should have been 3 characters)'
  179. fi
  180. fi # end of overwriting check
  181. echo shar: extracting "'README.3b1'" '(4121 characters)'
  182. if test -f 'README.3b1'
  183. then
  184.     echo shar: will not over-write existing file "'README.3b1'"
  185. else
  186. sed 's/^X//'  >'README.3b1' <<'SHAR_EOF'
  187. XREADME: Eric H. Herrin II
  188. X    University of Kentucky Mathematical Sciences Laboratories
  189. X     915 Patterson Office Tower
  190. X    University of Kentucky
  191. X    Lexington, KY 40506
  192. X    eric@ms.uky.edu, eric@ms.uky.csnet, !cbosgd!ukma!eric 
  193. X
  194. XThis directory contains the PD pty driver for System V, modified for
  195. Xuse with the AT&T UnixPC or Convergent Technologies Safari 4 computers,
  196. Xrunning Version 3.51 of the UNIX System V OS (it may also work on
  197. Xearlier versions, but I have no way of verifying this).  Anyone using
  198. Xthis driver should have no problems, but I will provide no support.
  199. XQuestions should be sent to the above address, either with ground mail
  200. Xor real (e-)mail.
  201. X
  202. X
  203. XThis README is intended to mark the changes made to the PD pty driver to
  204. Xsatisfy the author's request.  It was not easy or feasible to clearly mark
  205. Xevery change in the code, thus it was decided that an explanation of the
  206. Xprocedure would probably be enough.  A brief introduction to UnixPC 
  207. Xdevice drivers is followed by the list of changes made.  A couple of
  208. Xhacks will also be explained.
  209. X
  210. XNOTE: The #ifdef DEBUG statements use eprintf() instead of printf().
  211. X      This puts any messages into the queue of system errors of
  212. X      the error icon at the top of the console.
  213. X
  214. X
  215. XUnixPC device drivers:
  216. X
  217. X    The UnixPC has a different kind of device driver from other 
  218. XSystem V machines.  They can be loaded while the machine is running or
  219. Xat boot time, but are always linked into the OS while the kernel is
  220. Xactive.  However nice this may be, there ARE some problems.  
  221. X
  222. X    1.  Loadable device drivers CANNOT communicate with one another.
  223. X        That is, one driver cannot use a data structure defined in 
  224. X        another driver.  
  225. X    2.  Conf.c doesn't exist, it is redone by the /etc/lddrv -av 
  226. X        program and relinked into the kernel.  Thus, one can't
  227. X        declare common structures this way.
  228. X    
  229. X
  230. XChanges to the PD pty driver:
  231. X
  232. X    The following changes (hacks?) were made to the PD pty driver for
  233. Xthe purpose of making it usable on the UnixPC.
  234. X
  235. X       Problem 1 & 2 influenced me to try to make a single driver
  236. X       (there were two, ptm and pts).  How could one do this?
  237. X       My solution (and I would be very interested if you can
  238. X       think of a better one) was to create the slave devices
  239. X       /dev/tty[p-z][0-f] with minor numbers 0-(PTSCNT/2-1) and
  240. X       master devices /dev/pty[p-z][0-f] with minor numbers 
  241. X       (PTSCNT/2)-(PTSCNT-1).  Major numbers of both types of devices
  242. X       are the same. I can then simply define a macro to determine 
  243. X       whether the dev_t passed to the driver was a slave or master 
  244. X       pty.  Once determined, I can perform the appropriate duties.  
  245. X       Also, it was more readable to merge the ptm and pts modules 
  246. X       into a single set of pty[open, close, ioctl, read, write]
  247. X       routines.  I added a release routine so that the kernel will
  248. X       think the device has properly released if one deallocates
  249. X       the driver. 
  250. X
  251. XMaking alterations to the number of ptys, etc.
  252. X       The number of ptys is defined in the file PTSCNT.  This number
  253. X       should not exceed the maximum minor device number divided by
  254. X       two.  Ie. a maximum minor device number of 128 would allow
  255. X       a maximum of 64 ptys.  It is currently defined at 32, but
  256. X       I believe this is quite liberal.
  257. X
  258. XPty driver generation and installation procedure.
  259. X       Put the number of ptys you want in the file PTSCNT.
  260. X       Type "/bin/sh MakePty"
  261. X       Insert a floppy diskette.
  262. X       Type "/bin/sh MakeFloppy"
  263. X       Use the UA to install the diskette.
  264. X       (you can skip the floppy part and simply run the Install script 
  265. X       in the same directory the pty.o object is located)
  266. X
  267. XAcknowledgement:  I realize the usage of a single major device number is
  268. Xa severe hack, and I welcome any improvements/solutions.  I do not assume
  269. Xany responsibility for the changes I have made, nor do I imply any 
  270. Xliability on the part of the original author.  I include a complete set
  271. Xof {Install, Remove, etc, etc} scripts so that binary floppies may be
  272. Xmade to be installed by the UnixPC user agent.  I do not assume any
  273. Xresponsibility for these either.
  274. X
  275. X        Eric H. Herrin II
  276. X        University of Kentucky Mathematical Sciences Laboratories
  277. SHAR_EOF
  278. if test 4121 -ne "`wc -c < 'README.3b1'`"
  279. then
  280.     echo shar: error transmitting "'README.3b1'" '(should have been 4121 characters)'
  281. fi
  282. fi # end of overwriting check
  283. echo shar: extracting "'READ_ME'" '(1624 characters)'
  284. if test -f 'READ_ME'
  285. then
  286.     echo shar: will not over-write existing file "'READ_ME'"
  287. else
  288. sed 's/^X//'  >'READ_ME' <<'SHAR_EOF'
  289. XThis is a pseudo tty driver for system V machines. It works very
  290. Xsimilar to ptys on BSD, for instance emacs works fine. To install this
  291. Xdriver you will need to modify your `master' and `dfile' file which
  292. Xcontains your driver specifications. As these vary from machine to machine,
  293. Xyou will have to look up in your manual how to do that. Here is an example
  294. Xfor a sperry s5050 alias ncr tower 32 :
  295. X
  296. XAdd the following two lines to the driver description section in master:
  297. Xpts    0    237    244    pts    0    0    28    32    0    tty
  298. Xptm    0    37    344    ptm    0    0    29    0    0
  299. X
  300. XThis says there are max 32 pts devices at major number 28 having associated
  301. Xtty structures and 0 ptm devices having major number 29 with no associated
  302. Xdata. The number of ptm devices is not configurable, as this depends on the
  303. Xnumber of pts's.
  304. X
  305. XThe following two lines go in the dfile:
  306. Xpts    0    0    0
  307. Xptm    0    0    0
  308. X
  309. XProbably you will also want to increase the NCLIST parameter.
  310. X
  311. XIf your configuration procedure is different, you must change the shell
  312. Xscript mkpty, which is used to create the device nodes in /dev.
  313. X
  314. XThe ptm devices (/dev/pty[p-z][0-9a-f]) are the controlling ones, everything
  315. Xwritten there will show up at the associated pts device
  316. X(/dev/tty[p-z][0-9a-f]), as well as erverything which is written on the pts
  317. Xdevice will show up on the ptm device. The pts side will accept the usual
  318. Xtermio ioctl calls. The master side is a bit different, as ioctl calls which
  319. Xnormally wait for output to drain flush output. The reason for this funny
  320. Xbehaviour is that otherwise the master side will hang. Also the master side
  321. Xmay be opened only once, further open calls will result in an EBUSY error.
  322. SHAR_EOF
  323. if test 1624 -ne "`wc -c < 'READ_ME'`"
  324. then
  325.     echo shar: error transmitting "'READ_ME'" '(should have been 1624 characters)'
  326. fi
  327. fi # end of overwriting check
  328. echo shar: extracting "'Remove'" '(943 characters)'
  329. if test -f 'Remove'
  330. then
  331.     echo shar: will not over-write existing file "'Remove'"
  332. else
  333. sed 's/^X//'  >'Remove' <<'SHAR_EOF'
  334. X#
  335. X# Eric H. Herrin II
  336. X# University of Kentucky Mathematical Sciences
  337. X# eric@ms.uky.edu, eric@ms.uky.csnet, !cbosgd!ukma!eric
  338. X#
  339. X# Remove script for pty driver.
  340. XMODULE=pty
  341. X/etc/lddrv/lddrv -d ${MODULE}
  342. X/etc/masterupd -d ${MODULE}
  343. XPTSCNT=`cat PTSCNT`
  344. X# remove the pty device files
  345. Xcnt=0
  346. Xfor x in p q r s t u v w x y z
  347. Xdo
  348. X    for y in 0 1 2 3 4 5 6 7 8 9 a b c d e f
  349. X    do
  350. X        i=$x$y
  351. X        if [ ${cnt} -ge ${PTSCNT} ] 
  352. X        then 
  353. X            break
  354. X        fi
  355. X        /bin/rm -f /dev/pty$i
  356. X        /bin/rm -f /dev/tty$i
  357. X        cnt=`expr ${cnt} + 1`
  358. X    done
  359. Xdone
  360. X# get rid of stuff in /etc/lddrv
  361. X/bin/rm -f /etc/lddrv/${MODULE}.o /etc/lddrv/${MODULE} \
  362. X    /etc/lddrv/ifile.${MODULE}
  363. Xgrep -v "^${MODULE}" /etc/lddrv/drivers > /tmp/XXX$$
  364. Xmv /tmp/XXX$$ /etc/lddrv/drivers
  365. Xgrep -v "${MODULE}" /etc/lddrv/InstDrv > /tmp/XXX$$
  366. Xmv /tmp/XXX$$ /etc/lddrv/InstDrv
  367. Xchmod +r /etc/lddrv/drivers /etc/lddrv/InstDrv
  368. Xchmod go-w /etc/lddrv/drivers /etc/lddrv/InstDrv
  369. Xchown root /etc/lddrv/drivers /etc/lddrv/InstDrv
  370. SHAR_EOF
  371. if test 943 -ne "`wc -c < 'Remove'`"
  372. then
  373.     echo shar: error transmitting "'Remove'" '(should have been 943 characters)'
  374. fi
  375. fi # end of overwriting check
  376. echo shar: extracting "'Size'" '(3 characters)'
  377. if test -f 'Size'
  378. then
  379.     echo shar: will not over-write existing file "'Size'"
  380. else
  381. sed 's/^X//'  >'Size' <<'SHAR_EOF'
  382. X83
  383. SHAR_EOF
  384. if test 3 -ne "`wc -c < 'Size'`"
  385. then
  386.     echo shar: error transmitting "'Size'" '(should have been 3 characters)'
  387. fi
  388. fi # end of overwriting check
  389. echo shar: extracting "'pty.c'" '(9592 characters)'
  390. if test -f 'pty.c'
  391. then
  392.     echo shar: will not over-write existing file "'pty.c'"
  393. else
  394. sed 's/^X//'  >'pty.c' <<'SHAR_EOF'
  395. X
  396. X
  397. X/*
  398. X * pty.c - Berkeley style pseudo tty driver for system V
  399. X *
  400. X * Copyright (c) 1987, Jens-Uwe Mager, FOCUS Computer GmbH
  401. X * Not derived from licensed software.
  402. X *
  403. X * Permission is granted to freely use, copy, modify, and redistribute
  404. X * this software, provided that no attempt is made to gain profit from it,
  405. X * the author is not construed to be liable for any results of using the
  406. X * software, alterations are clearly marked as such, and this notice is
  407. X * not modified.
  408. X */
  409. X
  410. X/*
  411. X * Modified for use on the UnixPC by:
  412. X * Eric H. Herrin II
  413. X * University of Kentucky Mathematical Sciences Laboratories
  414. X * eric@ms.uky.edu, eric@ms.uky.csnet, !cbosgd!ukma!eric
  415. X *
  416. X * See README.3b1 for details of port and installation.
  417. X */
  418. X
  419. X/*
  420. X * the following are arbitrary 3 unused bits from t_state
  421. X * in sys/tty.h
  422. X */
  423. X/* The UnixPC does not have any extra bits in t_state, thus
  424. X * one must provide other means of storing the state.
  425. X */
  426. X#define MRWAIT    01    /* master waiting in read */
  427. X#define t_rloc    t_cc[0]        /* wchannel */
  428. X#define MWWAIT    02    /* master waiting in write */
  429. X#define t_wloc    t_cc[1]        /* wchannel */
  430. X#define MOPEN    04    /* master is open */
  431. X
  432. X#include "sys/param.h"
  433. X#include "sys/types.h"
  434. X#include "sys/sysmacros.h"
  435. X#include "sys/systm.h"
  436. X#include "sys/file.h"
  437. X#include "sys/conf.h"
  438. X#include "sys/proc.h"
  439. X#include "sys/dir.h"
  440. X#include "sys/tty.h"
  441. X#include "sys/signal.h"
  442. X#include "sys/user.h"
  443. X#include "sys/errno.h"
  444. X#include "sys/termio.h"
  445. X#include "sys/ttold.h"
  446. X
  447. X#define True  (1 == 1)
  448. X#define False (0 == 1)
  449. X
  450. X/* This number comes from the file PTSCNT in the current directory 
  451. X */
  452. X#define PTYCNT (dev_t)PTSCNT
  453. X/* The tty structures must be local to this driver.  One doesn't have
  454. X * conf.c
  455. X */
  456. Xstruct tty pts_tty[PTYCNT];
  457. Xint pts_cnt = PTYCNT;
  458. Xint ptystate[PTYCNT];
  459. X/* This macro returns True if the parameter is a major device number,
  460. X * False otherwise.
  461. X */
  462. X#define Master( dev )    (minor(dev) >= PTYCNT)
  463. Xextern int ptsproc();
  464. X
  465. Xptyopen(dev, flag)
  466. X    dev_t        dev;
  467. X    int        flag;
  468. X{
  469. X    register struct tty *tp;
  470. X
  471. X    dev = minor(dev);
  472. X    if (Master(dev) == True) {
  473. X#        ifdef DEBUG
  474. X        eprintf("open(master): \n");
  475. X#        endif
  476. X        dev -= PTYCNT; 
  477. X        tp = &pts_tty[dev];
  478. X        if (dev >= pts_cnt) {
  479. X            u.u_error = ENXIO;
  480. X            return;
  481. X        }
  482. X        /*
  483. X         * allow only one controlling process
  484. X         */
  485. X        if (ptystate[dev] & MOPEN) {
  486. X            u.u_error = EBUSY;
  487. X            return;
  488. X        }
  489. X        if (tp->t_state & WOPEN)
  490. X            wakeup((caddr_t)&tp->t_canq);
  491. X        tp->t_state |= CARR_ON;
  492. X        ptystate[dev] |= MOPEN;
  493. X    } else {
  494. X#        ifdef DEBUG
  495. X        eprintf("open(slave): \n");
  496. X#        endif
  497. X        tp = &pts_tty[dev];
  498. X        if (dev >= pts_cnt) {
  499. X            u.u_error = ENXIO;
  500. X            return;
  501. X        }
  502. X        if ((tp->t_state & (ISOPEN|WOPEN)) == 0) {
  503. X            ttinit(tp);
  504. X            tp->t_proc = ptsproc;
  505. X        }
  506. X        /*
  507. X           * if master is still open, don't wait for carrier
  508. X          */
  509. X        if (ptystate[dev] & MOPEN)
  510. X            tp->t_state |= CARR_ON;
  511. X        if (!(flag & FNDELAY)) {
  512. X            while ((tp->t_state & CARR_ON) == 0) {
  513. X                tp->t_state |= WOPEN;
  514. X                sleep((caddr_t)&tp->t_canq, TTIPRI);
  515. X            }
  516. X        }
  517. X        (*linesw[tp->t_line].l_open)(tp);
  518. X    }
  519. X}
  520. X
  521. Xptyclose(dev, flag)
  522. X    dev_t        dev;
  523. X    int        flag;
  524. X{
  525. X    register struct tty *tp;
  526. X
  527. X    dev = minor(dev);
  528. X    if (Master(dev) == True) {
  529. X#        ifdef DEBUG
  530. X        eprintf("close(master): \n");
  531. X#        endif
  532. X        dev -= PTYCNT;
  533. X        tp = &pts_tty[dev];
  534. X        if (tp->t_state & ISOPEN) {
  535. X            signal(tp->t_pgrp, SIGHUP);
  536. X            ttyflush(tp, FREAD|FWRITE);
  537. X        }
  538. X        /*
  539. X          * virtual carrier gone
  540. X          */
  541. X        tp->t_state &= ~(CARR_ON);
  542. X        ptystate[dev] &= ~MOPEN;
  543. X    } else {
  544. X#        ifdef DEBUG
  545. X        eprintf("close(slave): \n");
  546. X#        endif
  547. X        tp = &pts_tty[dev];
  548. X        (*linesw[tp->t_line].l_close)(tp);
  549. X        tp->t_state &= ~CARR_ON;
  550. X    }
  551. X}
  552. X
  553. Xptyread(dev)
  554. X    dev_t        dev;
  555. X{
  556. X    register struct tty *tp;
  557. X    register n;
  558. X
  559. X    dev = minor(dev);
  560. X    if (Master(dev) == True) {
  561. X#        ifdef DEBUG
  562. X        eprintf("read(master): \n");
  563. X#        endif
  564. X        dev -= PTYCNT;
  565. X        tp = &pts_tty[dev];
  566. X        if ((tp->t_state & ISOPEN) == 0) {
  567. X            u.u_error = EIO;
  568. X            return;
  569. X        }
  570. X        while (u.u_count) {
  571. X            ptsproc(tp, T_OUTPUT);
  572. X            if ((tp->t_state & (TTSTOP|TIMEOUT))
  573. X                || tp->t_tbuf.c_ptr == NULL || tp->t_tbuf.c_count == 0) {
  574. X                if (u.u_fmode & FNDELAY)
  575. X                    break;
  576. X#                ifdef DEBUG
  577. X                eprintf("read(master): master going to sleep\n");
  578. X#                endif
  579. X                ptystate[dev] |= MRWAIT;
  580. X                sleep((caddr_t)&tp->t_rloc, TTIPRI);
  581. X#                ifdef DEBUG
  582. X                eprintf("read(master): master woke up\n");
  583. X#                endif
  584. X
  585. X                continue;
  586. X            }
  587. X            n = min(u.u_count, tp->t_tbuf.c_count);
  588. X            if (n) {
  589. X#                ifdef DEBUG
  590. X                eprintf("read(master): got some stuff\n");
  591. X#                endif
  592. X                if (copyout(tp->t_tbuf.c_ptr, u.u_base, n)) {
  593. X                    u.u_error = EFAULT;
  594. X                    break;
  595. X                }
  596. X                tp->t_tbuf.c_count -= n;
  597. X                tp->t_tbuf.c_ptr += n;
  598. X                u.u_base += n;
  599. X                u.u_count -= n;
  600. X            }
  601. X        }
  602. X    } else {
  603. X#        ifdef DEBUG
  604. X        eprintf("read(slave): \n");
  605. X#        endif
  606. X        tp = &pts_tty[dev];
  607. X#        ifdef DEBUG
  608. X        eprintf("read(slave): got some stuff\n");
  609. X#        endif
  610. X        (*linesw[tp->t_line].l_read)(tp);
  611. X    }
  612. X}
  613. X    
  614. Xptywrite(dev)
  615. X    dev_t        dev;
  616. X{
  617. X    register struct tty *tp;
  618. X    register n;
  619. X
  620. X    dev = minor(dev);
  621. X    if (Master(dev) == True) {
  622. X#        ifdef DEBUG
  623. X        eprintf("write(master): \n");
  624. X#        endif
  625. X        dev -= PTYCNT;
  626. X        tp = &pts_tty[dev];
  627. X        if ((tp->t_state & ISOPEN) == 0) {
  628. X            u.u_error = EIO;
  629. X            return;
  630. X        }
  631. X        while (u.u_count) {
  632. X            if ((tp->t_state & TBLOCK) || tp->t_rbuf.c_ptr == NULL) {
  633. X                if (u.u_fmode & FNDELAY)
  634. X                    break;
  635. X                ptystate[dev] |= MWWAIT;
  636. X#                ifdef DEBUG
  637. X                eprintf("write(master): going to sleep\n");
  638. X#                endif
  639. X
  640. X                sleep((caddr_t)&tp->t_wloc, TTOPRI);
  641. X
  642. X#                ifdef DEBUG
  643. X                eprintf("write: waking up\n");
  644. X#                endif
  645. X
  646. X                continue;
  647. X            }
  648. X            n = min(u.u_count, tp->t_rbuf.c_count);
  649. X            if (n) {
  650. X#                ifdef DEBUG
  651. X                eprintf("write(master): sending some stuff\n");
  652. X#                endif
  653. X                if (copyin(u.u_base,tp->t_rbuf.c_ptr, n)) {
  654. X                    u.u_error = EFAULT;
  655. X                    break;
  656. X                }
  657. X                tp->t_rbuf.c_count -= n;
  658. X                u.u_base += n;
  659. X                u.u_count -= n;
  660. X            }
  661. X            (*linesw[tp->t_line].l_input)(tp);
  662. X        }
  663. X    } else {
  664. X#        ifdef DEBUG
  665. X        eprintf("write(slave): \n");
  666. X#        endif
  667. X        tp = &pts_tty[dev];
  668. X#        ifdef DEBUG
  669. X        eprintf("write(slave): sending some stuff\n");
  670. X#        endif
  671. X        (*linesw[tp->t_line].l_write)(tp);
  672. X    }
  673. X}
  674. X
  675. Xptyioctl(dev, cmd, arg, mode)
  676. X    dev_t        dev;
  677. X    int        cmd, arg, mode;
  678. X{
  679. X    register struct tty *tp;
  680. X
  681. X    dev = minor(dev);
  682. X    if (Master(dev) == True) {
  683. X#        ifdef DEBUG
  684. X        eprintf("ioctl(master): \n");
  685. X#        endif
  686. X        dev -= PTYCNT;
  687. X        tp = &pts_tty[dev];
  688. X        /*
  689. X          * sorry, but we can't fiddle with the tty struct without
  690. X          * having done LDOPEN
  691. X          */
  692. X        if (tp->t_state & ISOPEN) {
  693. X            if (cmd == TCSBRK && arg ==  NULL) {
  694. X                signal(tp->t_pgrp, SIGINT);
  695. X                if ((tp->t_iflag & NOFLSH) == 0)
  696. X                    ttyflush(tp, FREAD|FWRITE);
  697. X            } else {
  698. X                /*
  699. X                  * we must flush output to avoid hang in ttywait
  700. X                  */
  701. X                if (cmd == TCSETAW || cmd == TCSETAF || 
  702. X                   cmd == TCSBRK || cmd == TIOCSETP)
  703. X                    ttyflush(tp, FWRITE);
  704. X                ttiocom(tp, cmd, arg, mode);
  705. X            }
  706. X        }
  707. X    } else {
  708. X#        ifdef DEBUG
  709. X        eprintf("ioctl(slave): \n");
  710. X#        endif
  711. X        tp = &pts_tty[dev];
  712. X        ttiocom(tp, cmd, arg, mode);
  713. X    }
  714. X}
  715. X
  716. Xptsproc(tp, cmd)
  717. Xregister struct tty *tp;
  718. X{
  719. X    register struct ccblock *tbuf;
  720. X    extern ttrstrt();
  721. X
  722. X    switch (cmd) {
  723. X    case T_TIME:
  724. X#        ifdef DEBUG
  725. X        eprintf("ptsproc: T_TIME:\n");
  726. X#        endif
  727. X        tp->t_state &= ~TIMEOUT;
  728. X        goto start;
  729. X    case T_WFLUSH:
  730. X#        ifdef DEBUG
  731. X        eprintf("ptsproc: T_WFLUSH:\n");
  732. X#        endif
  733. X        tp->t_tbuf.c_size  -= tp->t_tbuf.c_count;
  734. X        tp->t_tbuf.c_count = 0;
  735. X        /* fall through */
  736. X    case T_RESUME:
  737. X#        ifdef DEBUG
  738. X        eprintf("ptsproc: T_RESUME:\n");
  739. X#        endif
  740. X        tp->t_state &= ~TTSTOP;
  741. X        /* fall through */
  742. X    case T_OUTPUT:
  743. Xstart:
  744. X#        ifdef DEBUG
  745. X        eprintf("ptsproc: T_OUTPUT:\n");
  746. X#        endif
  747. X        if (tp->t_state & (TTSTOP|TIMEOUT))
  748. X            break;
  749. X#        ifdef DEBUG
  750. X        eprintf("ptsproc: T_OUTPUT: past(TTSTOP|TIMEOUT)");
  751. X#        endif
  752. X        tbuf = &tp->t_tbuf;
  753. X        if (tbuf->c_ptr == NULL || tbuf->c_count == 0) {
  754. X#        ifdef DEBUG
  755. X        eprintf("ptsproc: T_OUTPUT: tbuf empty, may break\n");
  756. X#        endif
  757. X            if (tbuf->c_ptr)
  758. X                tbuf->c_ptr -= tbuf->c_size;
  759. X            if (!(CPRES & (*linesw[tp->t_line].l_output)(tp)))
  760. X                break;
  761. X        }
  762. X        if (tbuf->c_count && (ptystate[tp-pts_tty] & MRWAIT)) {
  763. X#        ifdef DEBUG
  764. X        eprintf("ptsproc: T_OUTPUT: waking up master\n");
  765. X#        endif
  766. X            ptystate[tp-pts_tty] &= ~MRWAIT;
  767. X            wakeup((caddr_t)&tp->t_rloc);
  768. X        }
  769. X#        ifdef DEBUG
  770. X        eprintf("ptsproc: T_OUTPUT: leaving end\n");
  771. X#        endif
  772. X        break;
  773. X    case T_SUSPEND:
  774. X#        ifdef DEBUG
  775. X        eprintf("ptsproc: T_SUSPEND:\n");
  776. X#        endif
  777. X        tp->t_state |= TTSTOP;
  778. X        break;
  779. X    case T_BLOCK:
  780. X#        ifdef DEBUG
  781. X        eprintf("ptsproc: T_BLOCK:\n");
  782. X#        endif
  783. X        /*
  784. X         * the check for ICANON appears to be neccessary
  785. X         * to avoid a hang when overflowing input
  786. X         */
  787. X        if ((tp->t_iflag & ICANON) == 0)
  788. X            tp->t_state |= TBLOCK;
  789. X        break;
  790. X    case T_BREAK:
  791. X#        ifdef DEBUG
  792. X        eprintf("ptsproc: T_BREAK:\n");
  793. X#        endif
  794. X        tp->t_state |= TIMEOUT;
  795. X        timeout(ttrstrt, tp, HZ/4);
  796. X        break;
  797. X#ifdef T_LOG_FLUSH
  798. X    case T_LOG_FLUSH:
  799. X#endif
  800. X    case T_RFLUSH:
  801. X#        ifdef DEBUG
  802. X        eprintf("ptsproc: T_RFLUSH:\n");
  803. X#        endif
  804. X        if (!(tp->t_state & TBLOCK))
  805. X            break;
  806. X        /* fall through */
  807. X    case T_UNBLOCK:
  808. X#        ifdef DEBUG
  809. X        eprintf("ptsproc: T_UNBLOCK:\n");
  810. X#        endif
  811. X        tp->t_state &= ~(TTXOFF|TBLOCK);
  812. X        /* fall through */
  813. X    case T_INPUT:
  814. X#        ifdef DEBUG
  815. X        eprintf("ptsproc: T_INPUT:\n");
  816. X#        endif
  817. X        if (ptystate[tp-pts_tty] & MWWAIT) {
  818. X            ptystate[tp-pts_tty] &= ~MWWAIT;
  819. X#            ifdef DEBUG
  820. X            eprintf("ptsproc: T_INPUT: waking up master\n");
  821. X#            endif
  822. X            wakeup((caddr_t)&tp->t_wloc);
  823. X        }
  824. X        break;
  825. X    default:
  826. X#        ifdef DEBUG
  827. X        eprintf("ptsproc: default:\n");
  828. X#        else
  829. X        ;
  830. X#        endif
  831. X    }
  832. X}
  833. X    
  834. X/* this routine is a silly stub to allow /etc/lddrv to believe the
  835. X * release of the 'device' was performed without error.  If this is
  836. X * not done, the driver will not unload properly (ie. ya gotta reboot).
  837. X */
  838. Xptyrelease()
  839. X{
  840. X#    ifdef DEBUG
  841. X    eprintf("ptyrelease:\n");
  842. X#    endif
  843. X    /* stub for /etc/lddrv */
  844. X}
  845. SHAR_EOF
  846. if test 9592 -ne "`wc -c < 'pty.c'`"
  847. then
  848.     echo shar: error transmitting "'pty.c'" '(should have been 9592 characters)'
  849. fi
  850. fi # end of overwriting check
  851. echo shar: extracting "'pty.mk'" '(129 characters)'
  852. if test -f 'pty.mk'
  853. then
  854.     echo shar: will not over-write existing file "'pty.mk'"
  855. else
  856. sed 's/^X//'  >'pty.mk' <<'SHAR_EOF'
  857. XCFLAGS= -O -c ${DEFS}
  858. X
  859. X.c.o:
  860. X    ${CC} ${CFLAGS} $<
  861. X
  862. Xall: pty.o
  863. X
  864. Xinstall: all
  865. X    /bin/sh Install
  866. X
  867. Xclean: 
  868. X    rm pty.o
  869. X
  870. Xclobber: clean
  871. X    
  872. SHAR_EOF
  873. if test 129 -ne "`wc -c < 'pty.mk'`"
  874. then
  875.     echo shar: error transmitting "'pty.mk'" '(should have been 129 characters)'
  876. fi
  877. fi # end of overwriting check
  878. :    End of shell archive
  879. exit 0
  880.