From:     Digestifier <Linux-Activists-Request@senator-bedfellow.mit.edu>
To:       Linux-Activists@senator-bedfellow.mit.edu
Reply-To: Linux-Activists@senator-bedfellow.mit.edu
Date:     Thu, 22 Apr 93 14:45:45 EDT
Subject:  Linux-Activists Digest #922

Linux-Activists Digest #922, Volume #4           Thu, 22 Apr 93 14:45:45 EDT

Contents:
  Re: Missing F_ASYNC/SIGIO??? (Drew Eckhardt)
  Re: Colorado Memory JUMBO drivers? (Drew Eckhardt)
  Re:  Linux-Activists Digest #920 (Mike Behnam)
  Re: Suggestion for future SLS ftp distribution (tsx-11 probs) (william E Davidsen)
  Re: Unix CAN be used on a minimal system! (Re: Unix OS for 286) (william E Davidsen)
  Hack or rogue for linux (Jon Solworth)
  Re: Unix OS for 286 (Abolghassem Salahi)
  Re: Allowing others to mount ? (Peter Orbaek)
  Re: READ ME PLEASE (Re: Perl vs Iostream) (Nick Holloway)

----------------------------------------------------------------------------

From: drew@ladymacb.cs.colorado.edu (Drew Eckhardt)
Subject: Re: Missing F_ASYNC/SIGIO???
Date: Thu, 22 Apr 1993 14:21:11 GMT

In article <735463792.12259.0@unix3.andrew.cmu.edu> Frank T Lofaro <fl0p+@andrew.cmu.edu> writes:
>       It seems F_ASYNC (for fcntl) and SIGIO support is missing. Even 
>though SIGIO is defined, I can't find it sent anywhere in the kernel 
>(as of patch level 8), nor does it seems F_ASYNC is in any header files 
>or the kernel source. I looked at fs/fcntl.c, and it had a switch command 
>that handles a whole buch of cases, but did not include F_ASYNC, and had 
>a defualt clause (which other than a not relevant here special case for 
>sockets, returned an error, EINVAL from the system call). My attempt to 
>compile something using F_AYNC complained about it being undeclared.

>So, did I look hard enough, and it really isn't there?

Yep.

>Or is it there, and I've been missing it?

Nope.

>
>If it isn't there, are there any plans to implement it, how soon if so, 
>how hard is it, and how would I start going about implementing it myself?

IMHO, the code is fairly trivial, although you'll have a lot of 
similar code and replication when you do the asynch I/O for various
interrupt driven goodies.


Things that work well with F_ASYNC and SIGIO / SIGURG are event 
driven (ie, by a hardware interrupt, some other process sticking data
in a pipe, etc).  So, it's just a matter calling kill() for the 
process that was set to recieve these signals by FSETOWN.

Anyways, here's how I'd start it, read side, the tty devices.

First, you need a working fcntl that recofnizes the 
flags you want to use.  However, you don't want to 
do ASYNCH I/O on any file, just certain devices, etc, so
you need to add a fcntl() field to the file_operations 
structure to keep a clean implementation (there is a 
special case for SOCKETS in there, not good).


--- 1.1 1993/04/22 10:33:53
+++ ./include/linux/fs.h        1993/04/22 10:41:54
@@ -269,6 +269,8 @@
        int (*open) (struct inode *, struct file *);
        void (*release) (struct inode *, struct file *);
        int (*fsync) (struct inode *, struct file *);
+       int (*fcntl) (struct inode *, struct file *, unsigned int cmd, 
+               unsigned long arg);
 };
 
 struct inode_operations {

Fcntl needs to be changed so that it can recognize the 
new field too.  Doing the VFS call before the normal fcntl() 
lets you overload things that are also defined in sys_fcntl().

--- 1.1 1993/04/22 10:27:10
+++ ./fs/fcntl.c        1993/04/22 11:43:25
@@ -68,8 +68,15 @@
        struct file * filp;
        extern int sock_fcntl (struct file *, unsigned int cmd,
                               unsigned long arg);
+       int retval;
+
        if (fd >= NR_OPEN || !(filp = current->filp[fd]))
                return -EBADF;
+
+        if (file->fops.fcntl && ((retval = filp->fops.fcntl(filp->f_inode, 
+               filp, cmd, arg)) != -EINVAL))
+               return retval;
+
        switch (cmd) {
                case F_DUPFD:
                        return dupfd(fd,arg);

Of course, we need some devices that do fcntl(fd, FASYNC), 
F_SOWN, etc.

The tty devices are a nice place to illustrate this, since they 
have the fcntl() routine in common, and you have a simple 
interrupt handler (keyboard.c), split interrupt handler (serial.c), 
and producer/consumer sort of thing (pty.c) -

Anyways, the BSD systems that I've played with only set one 
process or pgid (some only accept pgid) per device, not 
file descriptor - so you stick it in the tty struct or 
socket struct or whatever.  

You need to use a pid instead of a task_struct* because 
the pid you've chosen as an owner could have died by the
time an I/O signal is ready. 

And, you probably want to use sys_kill() for signal delivery 
because it will translate either a pgid or a pid into 
what's in the task struct, and all that other good stuff.

--- 1.1 1993/04/22 03:26:52
+++ ./include/linux/tty.h       1993/04/22 10:15:45
@@ -201,6 +201,13 @@
        struct termios *termios;
        int pgrp;
        int session;
+/*
+ * proc is the process (positive), process group (negative)
+ * which SIGIO / SIGURG signals get sent.
+ */
+
+       int proc;
+
        unsigned char stopped:1, status_changed:1, packet:1, lnext:1;
        unsigned char char_error:2;
        unsigned char ctrl_status;
@@ -293,6 +300,7 @@
 #define TTY_SQ_THROTTLED 3
 #define TTY_RQ_THROTTLED 4
 #define TTY_IO_ERROR 5
+#define TTY_ASYNC 6

 /*
  * When a break, frame error, or parity error happens, these codes are

Of course, you need the actual fcntl call to set things up 

--- 1.1 1993/04/22 03:26:40
+++ ./kernel/chr_drv/tty_io.c   1993/04/22 13:09:33
@@ -74,7 +74,86 @@
 static int tty_select(struct inode *, struct file *, int, select_table *);
 static int tty_open(struct inode *, struct file *);
 static void tty_release(struct inode *, struct file *);
+static int int tty_fcntl (struct inode *, struct file *, unsigned int cmd,
+  unsigned long arg);

+
+/*
+ * can_kill will return 0 if the current process could kill the indicated
+ * pid, -EPERM if permissions prohibit this, and -ESRCH if the process does
+ * not exist in the process table.
+ *
+ * can_kill will let the super luser kill swaper.
+ */
+
+int can_kill (pid_t pid) {
+  struct task_struct **p;
+
+  if (!pid)
+    return -EPERM;
+
+  for (p = &LAST_TASK; p >= &FIRST_TASK ; --p)
+    if (*p && (((pid >= 0) && ((*p)->pid == pid)) || ((*p)->pgrp == pid)))
+      if (((*p)->euid == current->euid) || ((*p)->uid == current->uid) ||
+       suser())
+         return 0;
+      else
+         return -EPERM;
+
+  return -ESRCH;
+}
+
+
+static int tty_fcntl (struct inode *ino, struct file *file, unsigned int cmd,
+       unsigned int arg);
+  int tmp;
+  struct tty_struct * tty;
+  dev_t dev;
+
+  dev = file->f_rdev;
+
+  if (MAJOR(dev) != 4) {
+    printk("tty_fcntl: bad pseudo-major nr #%d\n", MAJOR(dev));
+    return -EINVAL;
+  }
+
+  dev = MINOR(dev);
+  tty = TTY_TABLE(dev);
+  if (!tty || (tty->flags & (1 << TTY_IO_ERROR)))
+    return -EIO;
+
+  switch(cmd) {
+  case F_SETOWN:
+    tmp = can_kill ((pid_t) arg);
+    if (!tmp)
+       tty->proc = (pid_t) arg;
+    return tmp;
+
+  case F_GETOWN:
+    return tty->proc;
+
+  case F_SETFL:
+    filp->f_flags &= ~(O_APPEND | O_NONBLOCK | FASYNC);
+    filp->f_flags |= arg & (O_APPEND | O_NONBLOCK | FASYNC);
+
+    if (!(filp->f_flags & FASYNC)) {
+      clear_bit(TTY_ASYNC, (void *) tty->flags;
+      return 0;
+    }
+
+/* fall through */
+  case F_ASYNC:
+    set_bit(TTY_ASYNC, (void *) tty->flags);
+    filp->f_flags &= ~
+    return 0;
+
+  default:
+    return -EINVAL;
+  }
+}
+
+
+
 int tty_register_ldisc(int disc, struct tty_ldisc *new)
 {
        if (disc < N_TTY || disc >= NR_LDISCS)
@@ -1216,7 +1295,12 @@
            tty->session==0) {
                current->tty = minor;
                tty->session = current->session;
-               tty->pgrp = current->pgrp;
+/*
+ * All of the BSD systems I played with set the owning PID (for purposes
+ * of fcntl(fd, F_GETOWN)) to -process group, so I'll try that.
+ */
+
+               tty->proc = -(tty->pgrp = current->pgrp);
        }
        filp->f_rdev = 0x0400 | minor; /* Set it to something normal */
        return 0;

So, now your other code knows that it's doing asynchronous things - 

Basically, you want to send a SIGIO whenever you have a 
FULL(tty_queue)->!FULL or !EMPTY->EMPTY transition.  here are 
two simple examples for keyboard.c and pty.c

--- 1.1 1993/04/22 13:11:53
+++ ./kernel/chr_drv/keyboard.c 1993/04/22 13:14:24
@@ -140,16 +140,22 @@
 {
        struct tty_queue *qp;
        unsigned long new_head;
+       int was_empty;

        wake_up(&keypress_wait);
        if (!tty)
                return;
        qp = &tty->read_q;
+       was_empty = EMPTY(qp);

        qp->buf[qp->head]=ch;
        if ((new_head=(qp->head+1)&(TTY_BUF_SIZE-1)) != qp->tail)
                qp->head=new_head;
        wake_up_interruptible(&qp->proc_list);
+
+       if ((tty->flags & (1 << TTY_ASYNC) && was_empty && !EMPTY(qp)
+               && sys_kill(tty->proc, SIGIO))
+               clear_bit(TTY_ASYNC, &tty->flags);
 }
--- 1.1 1993/04/22 12:26:58
+++ ./kernel/chr_drv/pty.c      1993/04/22 12:45:35
@@ -64,11 +64,26 @@
  * This routine gets called when tty_write has put something into
  * the write_queue. It copies the input to the output-queue of it's
  * slave.
+ *
+ * ASYNCHRONOUS I/O is also supported.  If the other half of the
+ * pty pair had ASYNC set, and the buffer transitioned from an
+ * empty state, a SIGIO is sent to the appropriate proccess / group.
+ *
+ * If the signal failed, because the other process no longer existed,
+ * etc, the ASYNC bit is cleared so we don't waste any more time.
  */
-static void pty_write(struct tty_struct * tty)
-{
-       if (tty->link)
-               pty_copy(tty,tty->link);
+
+static void pty_write(struct tty_struct * tty) {
+  tty_struct *link = tty->link;
+  int was_ready;
+  if (link) {
+    was_empty = EMPTY(link->read_q);
+    pty_copy(tty,link);
+    if ((link->flags & (1 << TTY_ASYNC)) && was_empty &&
+      !EMPTY(link->read_q)
+        if (sys_kill(link->proc, SIGIO))
+         clear_bit (TTY_ASYNC, (void *) &(tty->link->flags));
+  }
 }

 int pty_open(struct tty_struct *tty, struct file * filp)


And finally, the serial code.  The Linux serial driver uses a two-tiered
interrupt system, with a fast bottom half that runs with interrupts 
disabled and a slow top half that can take its time with interrupts on.

Obviously, you don't want to be doing a time consuming grope through
the process table, signal delivery, etc from within the fast 
half!

--- 1.1 1993/04/22 13:00:20
+++ ./include/linux/serial.h    1993/04/22 13:01:05
@@ -47,7 +47,9 @@
 #define RS_EVENT_HANGUP                2
 #define RS_EVENT_BREAK         3
 #define RS_EVENT_OPEN_WAKEUP   4
+#define RS_EVENT_SEND_SIGIO    5

+
 /*
  * These are the UART port assignments, expressed as offsets from the base
  * register.  These assignments should hold for any serial port based on$
--- 1.1 1993/04/22 12:26:58
+++ ./kernel/chr_drv/serial.c   1993/04/22 13:09:07
@@ -202,7 +202,7 @@
                                 int *status)
 {
        struct tty_queue * queue;
-       int head, tail, ch;
+       int head, tail, ch, was_empty;

 /*
  * Just like the LEFT(x) macro, except it uses the loal tail
@@ -211,6 +211,7 @@
 #define VLEFT ((tail-head-1)&(TTY_BUF_SIZE-1))

        queue = &info->tty->read_q;
+       was_empty = EMPTY(queue);
        head = queue->head;
        tail = queue->tail;
        do {
@@ -240,6 +241,8 @@
                                                  &info->tty->flags))
                rs_throttle(info->tty, TTY_THROTTLE_RQ_FULL);
        rs_sched_event(info, RS_EVENT_READ_PROCESS);
+       if (was_empty && !EMPTY(queue) && (info->tty->flags & (1 << TTY_ASYNC)))
+               rs_sched_event(info, RS_EVENT_SEND_SIGIO);
 }

 static inline void transmit_chars(struct async_struct *info, int *done_work)
@@ -439,6 +442,10 @@
                        if (!clear_bit(RS_EVENT_OPEN_WAKEUP, &info->event)) {
                                wake_up_interruptible(&info->open_wait);
                        }
+                       if (!clear_bit(RS_EVENT_SEND_SIGIO, &info->event)) {
+                               if (sys_kill (info->tty->proc, SIGIO))
+                                       info->tty->flags &= ~(1 << TTY_ASYNC);
+                       }
                }
        }
 }

There are a few uglies that need resolving (ie, tty_close() or whatever
should clear the TTY_ASYNC flag in tty->flags)m some other files need 
the fcntl field in the file_operations structures, and it's only 
half done but something like this is probably where you want to head.

As far as having asynch I/O for normal files (ie, if you 
want to do a tail or something) - it can be done, no 
one else does it, and you'll have to go through the file 
descriptor tables when ever you do writes, track what 
descriptors are waiting for I/O on what inodes and link them
together, etc.  

Messy, and probably not worth the effort.

-- 
Boycott USL/Novell for their absurd anti-BSDI lawsuit. | Drew Eckhardt
Condemn Colorado for Amendment Two.                    | drew@cs.Colorado.EDU
Use Linux, the fast, flexible, and free 386 unix       |  

------------------------------

From: drew@ladymacb.cs.colorado.edu (Drew Eckhardt)
Subject: Re: Colorado Memory JUMBO drivers?
Date: Thu, 22 Apr 1993 14:29:36 GMT

In article <1993Apr20.200608.27091@ttinews.tti.com> bsmart@bsmart.TTI.COM (Bob Smart) writes:
>Has anyone put together drivers to support the Colorado Memory Systems
>JUMBO tape cartrige drives?  Under DOS, the only way I know to get to
>the drive is to run the interface program that CMS ships with the drive;
>I haven't been successful at getting CMS to describe the software
>interface to their gadget.  Is there a way to use this drive under LINUX?

I've been told that the CMS qic floppy port tapes conform to the standard 
AFTER you use a propriety code to "unlock" them.  A while back, some 
one over in comp.os.bsd ran a scope or logic analyzer on one and posted 
code, you might be able to dif it up someplace.



-- 
Boycott USL/Novell for their absurd anti-BSDI lawsuit. | Drew Eckhardt
Condemn Colorado for Amendment Two.                    | drew@cs.Colorado.EDU
Use Linux, the fast, flexible, and free 386 unix       |  

------------------------------

From: behnam@micromask.com (Mike Behnam)
Subject: Re:  Linux-Activists Digest #920
Date: 22 Apr 1993 14:20:15 -0400
Reply-To: behnam@micromask.com (Mike Behnam)

x-mn-admin: leave normal

please someone help to discontinue my subscription .... I'll be out of state..

------------------------------

From: davidsen@ariel.crd.GE.COM (william E Davidsen)
Subject: Re: Suggestion for future SLS ftp distribution (tsx-11 probs)
Date: 21 Apr 93 19:17:25 GMT
Reply-To: davidsen@crd.ge.com (bill davidsen)

In article <1r3c93$7su@wsinfo10.info.win.tue.nl>, devet@wsinfo10.info.win.tue.nl (Arjan de Vet) writes:

| It's a good idea too, but I don't know whether the tsx-11 administration
| gives accounts to people unknown to them. Our sysops wouldn't even think
| about it!
| 
| I'll wait for an answer from Peter and the tsx-11 maintainers.

  For ftp? Not a huge hole there, since anonymous is not the only user
who can be restricted.

  I'm unhappy because I just made three copies of SLS which I updated
on the 15th, and before I send them out they are outdated. I make them
pretty fast though, I have the SLS on my V.4 machine, exporting the
directory to my Linux and SCO machines. Then I run a bash script on the
Linux machine and a ksh script on the commercial machines, which
formats, verifies the format, copies the data (yes it knows about a1
and a2), and then verifies the data. It emits clear prompts and asks
for another disk of one fails either of the verify steps.

  At $1.50/disk I'm not going to offer to recopy the whole set, you can
bet on that, but I will get the latest soon and use it for the next
bunch. I was offering the whole thing on tape (SLS+TAMU) on tape for
$30, but there was not much demand.

-- 
bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
    Last year I worried that Bush would die and let Quayle take over.
    This year I worry that Hillary will die and let Bill take over.

------------------------------

From: davidsen@ariel.crd.GE.COM (william E Davidsen)
Crossposted-To: comp.os.coherent,comp.os.minix,comp.os.386bsd.questions,comp.os.misc
Subject: Re: Unix CAN be used on a minimal system! (Re: Unix OS for 286)
Date: 21 Apr 93 19:19:18 GMT
Reply-To: davidsen@crd.ge.com (bill davidsen)

In article <1r39huINN2mk@srvr1.engin.umich.edu>, scottl@engin.umich.edu (scott allen long) writes:

| You people are all masochists!  Next we'll be hearing from a guy who is "doing
| just fine" running Unix on an Altair 8800 with 64k of memory and an 8" floppy!
| What do you guys do, read Great Novels while your computer boots up?

  No, change floppy disks! It adds a whole new meaning to the term
"swapping."

-- 
bill davidsen, GE Corp. R&D Center; Box 8; Schenectady NY 12345
    Last year I worried that Bush would die and let Quayle take over.
    This year I worry that Hillary will die and let Bill take over.

------------------------------

From: solworth@parsys.eecs.uic.edu (Jon Solworth)
Subject: Hack or rogue for linux
Date: Thu, 22 Apr 1993 16:53:41 GMT


Where can I get Hack or Rogue for Linux?  I tried the rogue on tsx-11,
but it didn't compile under 99.8a.

thanks,
Jon
--
______________________________________________________________________________
Jon A. Solworth                         internet:  solworth@parsys.eecs.uic.edu
Dept. of EECS (M/C 154)                 telephone: (312) 996-0955
University of Illinois at Chicago       FAX:       (312) 413-0024
851 S. Morgan Rm 1120 SEO
Chicago, IL 60607-7053

------------------------------

Crossposted-To: comp.os.coherent,comp.os.minix,comp.os.386bsd.questions,comp.os.misc
From: pse5327@siemens.co.at (Abolghassem Salahi)
Subject: Re: Unix OS for 286
Date: Wed, 21 Apr 1993 10:07:04 GMT

hendrik@vedge.com (Hendrik Boom) writes:

>sable@halcyon.com (Scott Philip Sable) writes:
>:   I am in desperate need of any and all help!!! I am currently trying to
>:   find a Unix OS for an Intel 286 machine. I have tried a number of

>While we are on the topic of old machines, I have an old 640K 8088-based
>PC clone -- no hard disk even, and one can't be added -- THis is OLD --
>Does anyone know a Unix that will run on it?

Not sure if if works on a 286, but it works in an 8088: Venix 2.0. It is 
very old, had no TCP/IP support, no manual pages, but it had a compiler and 
/bin and /usr/bin were pretty full. I had a second terminal (an old BBC
running kermit :-) attached fine , but configuring the devices for a modem
proved too much, though looking at the device names I would say it is possible.

If you want more information then ask. I did see an advert for Venix in Byte
a couple of years ago. I *think* the firm was 'Venturcom.'

Alexis

------------------------------

From: poe@daimi.aau.dk (Peter Orbaek)
Subject: Re: Allowing others to mount ?
Date: Thu, 22 Apr 93 14:39:41 GMT

I have actually implemented a version of mount that is designed to be
setuid, and allow ordinary users to mount filesystems such as floppies.

The program uses a special /etc/ufstab (for user-filesystem-table) to
determine what mounts are allowed for non-priviledged users.

I you want a look at it, ftp it from 

        ftp.daimi.aau.dk:/pub/Linux-source/usermount-0.1.tar.Z

I cannot guarantee that there are *NO* security holes with this, but 
I have made an affort to avoid them.

Comments are welcome.

        - Peter.
-- 
Peter Orbaek <poe@daimi.aau.dk>
Hasle Ringvej 122, DK-8200 Aarhus N, DENMARK

------------------------------

Crossposted-To: comp.lang.perl
From: alfie@dcs.warwick.ac.uk (Nick Holloway)
Subject: Re: READ ME PLEASE (Re: Perl vs Iostream)
Date: Thu, 22 Apr 1993 15:00:13 GMT

In <1993Apr21.201126.12263@serval.net.wsu.edu> hlu@eecs.wsu.edu (HJ Lu) writes:
> |> What should I be campaigning for:
> |>   o Iostream to do what I want it to ?
> |>   o Perl to have a 'syslseek' ?
> |>   o People to tell me why I didn't just use 'read' and 'write' anyway ?
> 
> When you report a possible bug, you should always say which version of
> libc you are using. At least, post
> 
> ls -l /lib
> 
> Please try libc 4.3.3. It fixed lots of stdio bugs.

I have received one reply by e-mail that convinced me what I was doing was
strictly non-portable.  That was the general conclusion I had come to.
You either use stdio or syscalls -- don't expect a mixture of them
to work.

I wasn't thinking of it as being a fault of the library, which is my
excuse for not including the version.  If somebody had said that it
should have worked, _then_ I'd have made a bug report on the library.
The cross post to comp.os.linux was an afterthought, and probably
a mistake.  (BTW it was 4.3.3 I was using -- life on the bleeding edge :-)

Anyway, I shall update my script to use "sub lseek { syscall ... }"
and please make this my vote for 'sysl?seek' to be added to Perl 5!

[Followup-To: comp.lang.perl]

--
Nick Holloway |  `O O'  | alfie@dcs.warwick.ac.uk, alfie@warwick.UUCP,
[aka `Alfie'] | // ^ \\ | ..!uunet!mcsun!uknet!warwick!alfie

------------------------------


** FOR YOUR REFERENCE **

The service address, to which questions about the list itself and requests
to be added to or deleted from it should be directed, is:

    Internet: Linux-Activists-Request@NEWS-DIGESTS.MIT.EDU

You can send mail to the entire list (and comp.os.linux) via:

    Internet: Linux-Activists@NEWS-DIGESTS.MIT.EDU

Linux may be obtained via one of these FTP sites:
    nic.funet.fi				pub/OS/Linux
    tsx-11.mit.edu				pub/linux
    tupac-amaru.informatik.rwth-aachen.de	pub/msdos/replace

The current version of Linux is 0.99pl6 released on February 23, 1993

End of Linux-Activists Digest
******************************
