Symlinks under /proc
Igor Pechtchanski
pechtcha@cs.nyu.edu
Wed Feb 2 17:03:00 GMT 2005
On Tue, 1 Feb 2005, Christopher Faylor wrote:
> On Tue, Feb 01, 2005 at 02:07:28PM -0500, Igor Pechtchanski wrote:
> >On Tue, 1 Feb 2005, Christopher Faylor wrote:
> >
> >> On Mon, Jan 31, 2005 at 03:48:32PM -0500, Christopher Faylor wrote:
> >> >On Mon, Jan 31, 2005 at 09:30:25PM +0100, Corinna Vinschen wrote:
> >> >>On Jan 31 21:23, Corinna Vinschen wrote:
> >> >>> On Jan 31 15:11, Christopher Faylor wrote:
> >> >>>>On Mon, Jan 31, 2005 at 09:04:57PM +0100, Corinna Vinschen wrote:
> >> >>>>Have we reached the point yet where we can just get rid of
> >> >>>>special /dev handling entirely? Maybe we could just add /dev
> >> >>>>population to setup.exe or even have cygwin1.dll itself run a
> >> >>>>program if it detects an unpopulated /dev, sort of like how udev
> >> >>>>is handled in linux now.
> >> >>>>
> >> >>>>My only reservation with doing things this way is that we'd be
> >> >>>>making cygwin perform a disk lookup every time someone wanted to
> >> >>>>get to open /dev/tty.
> >> >>>
> >> >>>I would not like to change that yet. So far, the DLL is still
> >> >>>basically self-sufficient. If you require on-disk devices, you
> >> >>>can't use the DLL anymore without having a minimal installation
> >> >>>process. I can see the point where I'm getting convinced that
> >> >>>exactly that is a good idea, but right now...
> >> >>
> >> >>Actually, couldn't we just keep /dev/console, /dev/tty* and
> >> >>/dev/null handled internally? Everything else seems rather
> >> >>non-critical.
> >> >
> >> >You don't even have to do that. AFAICT, there is no reason for the
> >> >DLL to have to parse "/dev/tty*" or "/dev/null" when it could just
> >> >be relying on using major and minor device numbers.
> >> >
> >> >I just quickly hacked cygwin to stop parsing /dev entirely and it
> >> >seems to work ok, for the most part. The one puzzler is that while
> >> >it deals ok with /dev/tty, it does not handle /dev/null correctly,
> >> >even after a /dev/null has been created.
> >>
> >> With the latest checkins, it seems to be possible to remove the /dev
> >> parsing entirely and rely on an on-disk populated /dev.
> >>
> >> Igor, could you repost your script for populating /dev?
Attached.
> >> I don't remember how intelligent it was but I suspect that it doesn't
> >> actually query the system to figure out what devices are available,
> >> right?
> >
> >No, it doesn't -- it just has a hard-coded list. *Is* there a way to
> >query the devices available?
>
> I'm sure there is -- via some windows api or other.
Actually, at least the hard drive partitions are listed in
/proc/partitions. However, I doubt it's the job of the script to do this.
In fact, I don't think it's necessary in any case, since attaching a new
device to the system shouldn't require re-populating /dev. We should just
create a pre-defined set of devices that'd work on most systems (like
Linux does), and let advanced users tweak the script if necessary.
> >It would be good to test it first, though -- does the CVS HEAD still treat
> >/dev as a virtual directory?
>
> Yes. You can turn this off with the (temporary) patch below.
It seems to work with non-virtual /dev populated by the attached script.
There are a few problems, though:
a) mknod cannot set the mode of many devices.
Even though I run "mknod -m666" for all of them, everything except fd*,
mem, port, sd*, and scd* has mode 600. I've compared strace outputs
for "mem" and "kmem", and chmod succeeds in both cases, but the mode
for kmem is not changed. Weird.
b) mkfifo doesn't work, so /dev/pipe isn't created.
c) The script cannot create /dev/com* (except /dev/com0). Should /dev be
a managed mount to boot, or do we just drop support for /dev/com1, etc?
d) (minor) Should the script try to change the owner of the device files?
Once the four problems above are resolved, I think this is good to go.
FWIW, however, I agree with Corinna's reservations about Cygwin requiring
a populated /dev to work...
Igor
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT
-------------- next part --------------
#!/bin/bash
# Create devices
# Author: Igor Pechtchanski <pechtcha@cs.nyu.edu>
# Version: 1.2
#
# Note: This version creates *real* device files using mknod and mkfifo
#
# Script parameters
# Number of devices of a certain type to be created - change if more needed
# ttys
CREATE_TTY=32
# serial ttys
CREATE_TTYS=16
# floppy drives
CREATE_FD=3
# compact disks
CREATE_SCD=3
# hard drives
CREATE_SD=3
# hard drive partitions
CREATE_SD_PART=3
# tape drives
CREATE_ST=3
# Parameters end here -- you shouldn't have to change anything below this line
usage() {
echo "Usage: $0 [--verbose|-v]"
echo " or $0 --debug|-n"
echo " or $0 --help|-h"
echo " or $0 --version|-V"
echo ""
echo "--verbose, -v Print commands as they are executed"
echo "--debug, -n Don't execute commands, just print what will be done"
echo "--help, -h Print this message and exit"
echo "--version, -V Print the program version and exit"
}
if [ "x$1" = "x--debug" -o "x$1" = "x-n" ]; then
mknod() { echo mknod "$@"; }
mkfifo() { echo mkfifo "$@"; }
ln() { echo ln "$@"; }
mkdir() { echo mkdir "$@"; }
cd() { echo cd "$@"; }
shift
elif [ "x$1" = "x--help" -o "x$1" = "x-h" ]; then
usage
exit 0
elif [ "x$1" = "x--version" -o "x$1" = "x-V" ]; then
echo -n "$0, "
sed -n '/^# Version: /{s/^# // p}' "$0"
exit 0
elif [ "x$1" = "x--verbose" -o "x$1" = "x-v" ]; then
set -x
elif [ "x$1" != "x" ]; then
echo "Invalid parameter: $1"
usage
exit 1
fi
error() { echo "$@" && exit 1; }
# Maximum number of tty devices
NUM_TTY=64
[ -z "$CREATE_TTY" ] && CREATE_TTY="$NUM_TTY"
[ "$CREATE_TTY" -le "$NUM_TTY" ] || error "Too many ttys: $CREATE_TTY"
# Maximum number of ttyS (serial tty) devices
NUM_TTYS=16
[ -z "$CREATE_TTYS" ] && CREATE_TTYS="$NUM_TTYS"
[ "$CREATE_TTYS" -le "$NUM_TTYS" ] || \
error "Too many serial ttys: $CREATE_TTYS"
# Maximum number of st (tape) devices
NUM_ST=16
[ -z "$CREATE_ST" ] && CREATE_ST="$NUM_ST"
[ "$CREATE_ST" -le "$NUM_ST" ] || error "Too many tape devices: $CREATE_ST"
# Maximum number of fd (floppy drive) devices
NUM_FD=16
[ -z "$CREATE_FD" ] && CREATE_FD="$NUM_FD"
[ "$CREATE_FD" -le "$NUM_FD" ] || error "Too many floppy drives: $CREATE_FD"
# Maximum number of scd (compact disk) devices
NUM_SCD=16
[ -z "$CREATE_SCD" ] && CREATE_SCD="$NUM_SCD"
[ "$CREATE_SCD" -le "$NUM_SCD" ] || error "Too many compact disks: $CREATE_SCD"
# Maximum number of sd (hard disk) physical devices
NUM_SD=16
[ -z "$CREATE_SD" ] && CREATE_SD="$NUM_SD"
[ "$CREATE_SD" -le "$NUM_SD" ] || error "Too many hard drives: $CREATE_SD"
# Maximum number of sd (hard disk) partition devices
NUM_SD_PART=16
[ -z "$CREATE_SD_PART" ] && CREATE_SD_PART="$NUM_SD_PART"
[ "$CREATE_SD_PART" -le "$NUM_SD_PART" ] || \
error "Too many hard drive partitions: $CREATE_SD_PART"
# Sequence of numbers from $2(0) to $1-1
NUMS() {
[ -z "$2" ] && set -- "$1" 0;
seq -s " " $2 1 $(expr $1 - 1) 2>/dev/null;
}
# Sequence of letters from 'a' to 'a'+$1-1
LTRS() {
/bin/echo -e $(printf '\\%o ' $(seq -s " " 97 1 $(expr 96 + $1) 2>/dev/null));
}
# Actual /dev directory
[ -z "$DEVDIR" ] && DEVDIR="/dev"
[ -e "$DEVDIR" -a ! -d "$DEVDIR" ] && \
error "$DEVDIR exists and is not a directory"
[ ! -e "$DEVDIR" ] && \
(mkdir "$DEVDIR" || error "Unable to create $DEVDIR")
[ ! -e "$DEVDIR" -o -w "$DEVDIR" ] || \
error "$DEVDIR exists, but isn't writeable"
cd "$DEVDIR" || error "Unable to cd to $DEVDIR"
# Major device numbers
DEVNO_FIFO=0
DEVNO_MEM=1
DEVNO_FD=2
DEVNO_CONSOLE=5
DEVNO_SD=8
DEVNO_ST=9
DEVNO_SCD=11
DEVNO_WINDOWS=13
DEVNO_DSP=14
DEVNO_TTYS=117
DEVNO_TTYM=128
DEVNO_TTY=136
# - (0,252): fifo
mknod -m666 fifo c $DEVNO_FIFO 252
# - (1,*): mem kmem null zero port random urandom
mknod -m666 mem c $DEVNO_MEM 1
mknod -m666 kmem c $DEVNO_MEM 2
mknod -m666 null c $DEVNO_MEM 3
mknod -m666 zero c $DEVNO_MEM 4
mknod -m666 port c $DEVNO_MEM 5
mknod -m666 random c $DEVNO_MEM 8
mknod -m666 urandom c $DEVNO_MEM 9
# - (2,*): floppies
for i in $(NUMS $CREATE_FD); do
mknod -m666 "fd$i" b $DEVNO_FD $i
done
# - (5,*): tty console ptmx conout conin
mknod -m666 tty c $DEVNO_CONSOLE 0
mknod -m666 console c $DEVNO_CONSOLE 1
mknod -m666 ptmx c $DEVNO_CONSOLE 2
mknod -m666 conout c $DEVNO_CONSOLE 254
mknod -m666 conin c $DEVNO_CONSOLE 255
# - (8,*): hard disks
MINOR=0
for j in $(LTRS $CREATE_SD); do
mknod -m666 "sd$j" b $DEVNO_SD $MINOR
for i in $(NUMS $CREATE_SD_PART 1); do
mknod -m666 "sd$j$i" b $DEVNO_SD $(($MINOR+$i))
done
MINOR=$(($MINOR+16))
done
# - (9,*) tape drives (rewind/no rewind)
for i in $(NUMS $CREATE_ST); do
mknod -m666 "st$i" c $DEVNO_ST $i
mknod -m666 "nst$i" c $DEVNO_ST $((128+$i))
done
# - (11,*) compact disks
for i in $(NUMS $CREATE_SCD); do
mknod -m666 "scd$i" b $DEVNO_SCD $i
ln -s "scd$i" "sr$i"
done
# - (13,*) clipboard windows
mknod -m666 clipboard c $DEVNO_WINDOWS 254
mknod -m666 windows c $DEVNO_WINDOWS 255
# - (14,3) dsp
mknod -m666 dsp c $DEVNO_DSP 3
# - (117,*) serial
for i in $(NUMS $CREATE_TTYS); do
mknod -m666 "ttyS$i" c $DEVNO_TTYS $(($i+1))
# TODO: how do we deal with com*?
#mknod -m666 "com$i" c $DEVNO_TTYS $i
done
# TODO: how do we deal with the other com*?
mknod -m666 com0 c $DEVNO_TTYS 0
# - (128,0) tty master
mknod -m666 ttym c $DEVNO_TTYM 0
# - (136,*) tty
for i in $(NUMS $CREATE_TTY); do
mknod -m666 "tty$i" c $DEVNO_TTY $i
done
# Create pipes
# TODO: UNIMPLEMENTED
mkfifo -m666 pipe
# Create symbolic links
[ ! -e floppy ] && ln -s fd0 ./floppy
[ ! -e cdrom ] && ln -s scd0 ./cdrom
[ ! -e tape ] && ln -s st0 ./tape
[ ! -e audio ] && ln -s dsp ./audio
[ ! -e stdin ] && ln -s /proc/self/fd/0 ./stdin
[ ! -e stdout ] && ln -s /proc/self/fd/1 ./stdout
[ ! -e stderr ] && ln -s /proc/self/fd/2 ./stderr
More information about the Cygwin-developers
mailing list