Newer
Older
;;; -*- Package: UNIX -*-
;;;
;;; **********************************************************************
;;; This code was written as part of the CMU Common Lisp project at
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
"$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unix.lisp,v 1.133 2010/12/22 02:15:39 rtoy Exp $")
;;;
;;; **********************************************************************
;;;
;;; This file contains the UNIX low-level support.
;;;
(in-package "UNIX")
(use-package "ALIEN")
(use-package "C-CALL")
(use-package "SYSTEM")
(use-package "EXT")
(intl:textdomain "cmucl-unix")
;; Check the G_BROKEN_FILENAMES environment variable; if set the encoding
;; is locale-dependent...else use :utf-8 on Unicode Lisps. On 8 bit Lisps
;; it must be set to :iso8859-1 (or left as NIL), making files with
;; non-Latin-1 characters "mojibake", but otherwise they'll be inaccessible.
;; Must be set to NIL initially to enable building Lisp!
(defvar *filename-encoding* nil)
(export '(daddr-t caddr-t ino-t swblk-t size-t time-t dev-t off-t uid-t gid-t
timeval tv-sec tv-usec timezone tz-minuteswest tz-dsttime
itimerval it-interval it-value tchars t-intrc t-quitc t-startc
t-stopc t-eofc t-brkc ltchars t-suspc t-dsuspc t-rprntc t-flushc
t-werasc t-lnextc sgttyb sg-ispeed sg-ospeed sg-erase sg-kill
sg-flags winsize ws-row ws-col ws-xpixel ws-ypixel
direct d-off d-ino d-reclen #-(or linux svr4) d-namlen d-name
stat st-dev st-mode st-nlink st-uid st-gid st-rdev st-size
st-atime st-mtime st-ctime st-blksize st-blocks
s-ifmt s-ifdir s-ifchr s-ifblk s-ifreg s-iflnk s-ifsock
s-isuid s-isgid s-isvtx s-iread s-iwrite s-iexec
ruseage ru-utime ru-stime ru-maxrss ru-ixrss ru-idrss
ru-isrss ru-minflt ru-majflt ru-nswap ru-inblock ru-oublock
ru-msgsnd ru-msgrcv ru-nsignals ru-nvcsw ru-nivcsw
prot_read prot_write prot_exec prot_none
map_shared map_private map_fixed map_anonymous
ms_async ms_sync ms_invalidate
unix-mmap unix-munmap unix-msync
unix-access r_ok w_ok x_ok f_ok unix-chdir unix-chmod setuidexec
setgidexec savetext readown writeown execown readgrp writegrp
execgrp readoth writeoth execoth unix-fchmod unix-chown unix-fchown
unix-getdtablesize unix-close unix-creat unix-dup unix-dup2
unix-fcntl f-dupfd f-getfd f-setfd f-getfl f-setfl f-getown f-setown
fndelay fappend fasync fcreat ftrunc fexcl unix-link unix-lseek
l_set l_incr l_xtnd unix-mkdir unix-open o_rdonly o_wronly o_rdwr
#+(or hpux svr4 bsd linux) o_ndelay
#+(or hpux svr4 bsd linux) o_noctty #+(or hpux svr4 bsd) o_nonblock
o_append o_creat o_trunc o_excl unix-pipe unix-read unix-readlink
unix-rename unix-rmdir unix-fast-select fd-setsize fd-set fd-clr
fd-isset fd-zero unix-select unix-sync unix-fsync unix-truncate
unix-ftruncate unix-symlink
#+(and sparc svr4) unix-times
unix-unlink unix-write unix-ioctl
tcsetpgrp tcgetpgrp tty-process-group
terminal-speeds tty-raw tty-crmod tty-echo tty-lcase
#+(or hpux svr4 linux bsd) termios
#+(or hpux svr4 linux bsd) c-lflag
#+(or hpux svr4 linux bsd) c-iflag
#+(or hpux svr4 linux bsd) c-oflag
#+(or hpux svr4 linux bsd) tty-icrnl
#+(or hpux svr4 bsd) vdsusp #+(or hpux svr4 linux bsd) veof
#+(or hpux svr4 linux bsd) vintr
#+(or hpux svr4 linux bsd) vquit
#+(or hpux svr4 linux bsd) vstart
#+(or hpux svr4 linux bsd) vstop
#+(or hpux svr4 linux bsd) vsusp
#+(or hpux svr4 linux bsd) c-cflag
#+(or hpux svr4 linux bsd) c-cc
#+(or bsd osf1) c-ispeed
#+(or bsd osf1) c-ospeed
#+(or hpux svr4 linux bsd) tty-icanon
#+(or hpux svr4 linux bsd) vmin
#+(or hpux svr4 linux bsd) vtime
#+(or hpux svr4 linux bsd) tty-ixon
#+(or hpux svr4 linux bsd) tcsanow
#+(or hpux svr4 linux bsd) tcsadrain
#+(or hpux svr4 linux bsd) tciflush
#+(or hpux svr4 linux bsd) tcoflush
#+(or hpux svr4 linux bsd) tcioflush
#+(or hpux svr4 linux bsd) tcsaflush
#+(or hpux svr4 linux bsd) unix-tcgetattr
#+(or hpux svr4 linux bsd) unix-tcsetattr
#+(or hpux svr4 bsd) unix-cfgetospeed
#+(or hpux svr4 bsd) unix-cfsetospeed
#+(or hpux svr4 bsd) unix-cfgetispeed
#+(or hpux svr4 bsd) unix-cfsetispeed
#+(or hpux svr4 linux bsd) tty-ignbrk
#+(or hpux svr4 linux bsd) tty-brkint
#+(or hpux svr4 linux bsd) tty-ignpar
#+(or hpux svr4 linux bsd) tty-parmrk
#+(or hpux svr4 linux bsd) tty-inpck
#+(or hpux svr4 linux bsd) tty-istrip
#+(or hpux svr4 linux bsd) tty-inlcr
#+(or hpux svr4 linux bsd) tty-igncr
#+(or hpux svr4 linux bsd) tty-ixany
#+(or hpux svr4 linux bsd) tty-ixoff
#+(or hpux irix solaris linux bsd) tty-imaxbel
#+(or hpux svr4 linux bsd) tty-opost
#+(or hpux svr4 linux bsd) tty-onlcr
#+(or hpux svr4 linux) tty-onocr
#+(or hpux svr4 linux) tty-onlret
#+(or hpux svr4 linux) tty-ofill
#+(or hpux svr4 linux) tty-ofdel
#+(or hpux svr4 linux bsd) tty-isig
#+(or hpux svr4 linux bsd) tty-echoe
#+(or hpux svr4 linux bsd) tty-echok
#+(or hpux svr4 linux bsd) tty-echonl
#+(or hpux svr4 linux bsd) tty-noflsh
#+(or hpux svr4 linux bsd) tty-iexten
#+(or hpux svr4 linux bsd) tty-tostop
#+(or hpux irix solaris linux bsd) tty-echoctl
#+(or hpux irix solaris linux bsd) tty-echoprt
#+(or hpux irix solaris linux bsd) tty-echoke
#+(or hpux irix solaris bsd) tty-flusho
#+(or hpux irix solaris linux bsd) tty-pendin
#+(or hpux svr4 linux bsd) tty-cstopb
#+(or hpux svr4 linux bsd) tty-cread
#+(or hpux svr4 linux bsd) tty-parenb
#+(or hpux svr4 linux bsd) tty-parodd
#+(or hpux svr4 linux bsd) tty-hupcl
#+(or hpux svr4 linux bsd) tty-clocal
#+(or irix solaris) rcv1en
#+(or irix solaris) xmt1en
#+(or hpux irix solaris) tty-loblk
#+(or hpux svr4 linux bsd) vintr
#+(or hpux svr4 linux bsd) verase
#+(or hpux svr4 linux bsd) vkill
#+(or hpux svr4 linux bsd) veol
#+(or hpux irix solaris linux bsd) veol2
#+(or hpux svr4 bsd) tty-csize #+(or hpux svr4 bsd) tty-cs5
#+(or hpux svr4 bsd) tty-cs6 #+(or hpux svr4 bsd) tty-cs7
#+(or hpux svr4 bsd) tty-cs8
#+(or hpux svr4 bsd) unix-tcsendbreak
#+(or hpux svr4 bsd) unix-tcdrain
#+(or hpux svr4 bsd) unix-tcflush
#+(or hpux svr4 bsd) unix-tcflow
TIOCGETP TIOCSETP TIOCFLUSH TIOCSETC TIOCGETC TIOCSLTC
KBDSCLICK FIONREAD #+(or hpux bsd) siocspgrp
unix-exit unix-stat unix-lstat unix-fstat
unix-getrusage unix-fast-getrusage rusage_self rusage_children
unix-gettimeofday
#-hpux unix-utimes #-(or svr4 hpux) unix-setreuid
#-(or svr4 hpux) unix-setregid
unix-getpid unix-getppid
#+(or svr4 bsd)unix-setpgid
unix-getgid unix-getegid unix-getpgrp unix-setpgrp unix-getuid
unix-getpagesize unix-gethostname unix-gethostid unix-fork
unix-current-directory unix-isatty unix-ttyname unix-execve
unix-socket unix-connect unix-bind unix-listen unix-accept
unix-recv unix-send unix-getpeername unix-getsockname
unix-getsockopt unix-setsockopt unix-openpty
unix-recvfrom unix-sendto unix-shutdown
unix-getpwnam unix-getpwuid unix-getgrnam unix-getgrgid
user-info user-info-name user-info-password user-info-uid
user-info-gid user-info-gecos user-info-dir user-info-shell
group-info group-info-name group-info-gid group-info-members
unix-uname))
(eval-when (:compile-toplevel)
(defmacro %name->file (string)
`(if *filename-encoding*
(string-encode ,string *filename-encoding*)
,string))
(defmacro %file->name (string)
`(if *filename-encoding*
(string-decode ,string *filename-encoding*)
,string)))
;;;; Common machine independent structures.
;;; From sys/types.h
(def-alien-type int64-t (signed 64))
(def-alien-type u-int64-t (unsigned 64))
(def-alien-type daddr-t
#-(or linux alpha) long
#+(or linux alpha) int)
(def-alien-type ino-t
#-alpha unsigned-long
#+alpha unsigned-int)
(def-alien-type size-t
#-(or linux alpha) long
#+linux unsigned-int
#+alpha unsigned-long)
(def-alien-type time-t
#-(or bsd linux alpha) unsigned-long
#+bsd long
#+alpha unsigned-int)
(def-alien-type dev-t
#-(or alpha svr4 bsd linux) short
#+linux unsigned-short
#+alpha int
#+(and (not linux) (or bsd svr4)) unsigned-long)
(progn
(deftype file-offset () '(signed-byte 32))
(def-alien-type off-t
#-alpha long
#+alpha unsigned-long) ;??? very dubious
(def-alien-type uid-t
#-(or alpha svr4) unsigned-short
#+alpha unsigned-int
#+svr4 long)
(def-alien-type gid-t
#-(or alpha svr4) unsigned-short
#+alpha unsigned-int
#+svr4 long))
(progn
(deftype file-offset () '(signed-byte 64))
(def-alien-type off-t int64-t)
(def-alien-type uid-t unsigned-long)
(def-alien-type gid-t unsigned-long))
;;; Large file support for Solaris. Define some of the 64-bit types
;;; we need. Unlike unix-glibc's large file support, Solaris's
;;; version is a little simpler because all of the 64-bit versions of
;;; the functions actually exist as functions. So instead of calling
;;; the 32-bit versions of the functions, we call the 64-bit versions.
;;;
;;; These functions are: creat64, open64, truncate64, ftruncate64,
;;; stat64, lstat64, fstat64, readdir64.
;;;
;;; There are also some new structures for large file support:
;;; dirent64, stat64.
;;;
;;; FIXME: We should abstract this better, but I (rtoy) don't have any
;;; other system to test this out on, so it's a Solaris hack for now.
#+solaris
(progn
(deftype file-offset64 () '(signed-byte 64))
(def-alien-type off64-t int64-t)
(def-alien-type ino64-t u-int64-t)
(def-alien-type blkcnt64-t u-int64-t))
(def-alien-type mode-t
#-(or alpha svr4) unsigned-short
#+alpha unsigned-int
#+svr4 unsigned-long)
(def-alien-type nlink-t
#-svr4 unsigned-short
#+svr4 unsigned-long)
(defconstant FD-SETSIZE
#-(or hpux alpha linux FreeBSD) 256
#+hpux 2048 #+alpha 4096 #+(or linux FreeBSD) 1024)
(fds-bits (array #-alpha unsigned-long #+alpha int #.(/ fd-setsize 32)))))
(setf (deref (slot ,fd-set 'fds-bits) ,word)
(logior (truly-the (unsigned-byte 32) (ash 1 ,bit))
(deref (slot ,fd-set 'fds-bits) ,word))))))
(setf (deref (slot ,fd-set 'fds-bits) ,word)
(logand (deref (slot ,fd-set 'fds-bits) ,word)
(32bit-logical-not
(truly-the (unsigned-byte 32) (ash 1 ,bit))))))))
(defmacro fd-isset (offset fd-set)
(let ((word (gensym))
(bit (gensym)))
`(multiple-value-bind (,word ,bit) (floor ,offset 32)
(logbitp ,bit (deref (slot ,fd-set 'fds-bits) ,word)))))
`(progn
,@(loop for index upfrom 0 below (/ fd-setsize 32)
collect `(setf (deref (slot ,fd-set 'fds-bits) ,index) 0))))
;;; From sys/time.h
(def-alien-type nil
(struct timeval
(tv-sec #-linux time-t #+linux int) ; seconds
(tv-usec #-linux time-t #+linux int))) ; and microseconds
(def-alien-type nil
(struct timezone
(tz-minuteswest int) ; minutes west of Greenwich
(tz-dsttime ; type of dst correction
#-linux (enum nil :none :usa :aust :wet :met :eet :can)
#+linux int)))
(def-alien-type nil
(struct itimerval
(it-interval (struct timeval)) ; timer interval
(it-value (struct timeval)))) ; current value
; High-res time. Actually posix definition under svr4 name.
(def-alien-type nil
(struct timestruc-t
(tv-sec time-t)
(tv-nsec long)))
#+(or linux BSD)
(def-alien-type nil
(struct timespec-t
(ts-sec long)
(ts-nsec long)))
(def-alien-type nil
(struct tchars
(t-intrc char) ; interrupt
(t-quitc char) ; quit
(t-startc char) ; start output
(t-stopc char) ; stop output
(t-suspc char) ; stop process signal
(t-dsuspc char) ; delayed stop process signal
(t-rprntc char) ; reprint line
(t-flushc char) ; flush output (toggles)
#+linux (sg-flags #+mach short #-mach int) ; mode flags
(sg-ispeed char) ; input speed.
(sg-ospeed char) ; output speed
(sg-erase char) ; erase character
#-linux (sg-kill char) ; kill character
#-linux (sg-flags #+mach short #-mach int) ; mode flags
#+linux (sg-kill char)
#+linux (t (struct termios))
#+linux (check int)))
(def-alien-type nil
(struct winsize
(ws-row unsigned-short) ; rows, in characters
(ws-col unsigned-short) ; columns, in characters
(ws-xpixel unsigned-short) ; horizontal size, pixels
(ws-ypixel unsigned-short))) ; veritical size, pixels
;;; NOTE: There is both a termio (SYSV) and termios (POSIX)
;;; structure with similar but incompatible definitions. It may be that
;;; the non-BSD variant of termios below is really a termio but I (pw)
;;; can't verify. The BSD variant uses the Posix termios def. Some systems
;;; (Ultrix and OSF1) seem to support both if used independently.
;;; The 17f version of this seems a bit confused wrt the conditionals.
;;; Please check these defs for your system.
;;; TSM: from what I can tell looking at the 17f definition, my guess is that it
;;; was originally a termio for sunos (nonsolaris) (because it had the c-line
;;; member for sunos only), and then was mutated into the termios definition for
;;; later systems. The definition here is definitely not an IRIX termio because
;;; it doesn't have c-line. In any case, the functions tcgetattr, etc.,
;;; definitely take a termios, and termios seems to be the more standard
;;; standard now, so my suggestion is to just go with termios and forget about
;;; termio. Note the SVID says NCCS not NCC for the constant here, so I've
;;; changed it (which means you need to bootstrap it to avoid a reader error).
;;; On top of all that, SGI decided to change the termios structure on irix
;;; 6.[34] (but NOT 6.2), left the old routines named the same in the library,
;;; but introduced static functions in termios.h to redirect new calls to the
;;; new library--which means it's important not to #include termios.h before
;;; undefineds.h when building lisp.
(defconstant +NCCS+
#+hpux 16
#+irix 23
#+(and sunos (not svr4)) 17
_N"Size of control character vector.")
(c-iflag unsigned-int)
(c-oflag unsigned-int)
(c-cflag unsigned-int)
(c-lflag unsigned-int)
#+(or linux hpux (and sunos (not svr4)))
(c-reserved #-(or linux (and sunos (not svr4))) unsigned-int
#+(or linux (and sunos (not svr4))) unsigned-char)
(c-cc (array unsigned-char #.+NCCS+))
#+(or bsd osf1) (c-ispeed unsigned-int)
#+(or bsd osf1) (c-ospeed unsigned-int)))
;;;
;;; (For Solaris, this is not struct direct, but struct dirent!)
#+(and sunos (not svr4)) (d-off long) ; offset of next disk directory entry
(d-namlen unsigned-short) ; length of string in d-name
(d-name (array char 256)))) ; name must be no longer than this
#+bsd
(def-alien-type nil
(struct direct
(d-fileno unsigned-long)
(d-reclen unsigned-short)
(d-type unsigned-char)
(d-namlen unsigned-char) ; length of string in d-name
(d-name (array char 256)))) ; name must be no longer than this
;;; The 64-bit version of struct dirent.
#+solaris
(def-alien-type nil
(struct dirent64
(d-ino ino64-t); inode number of entry
(d-off off64-t) ; offset of next disk directory entry
(d-reclen unsigned-short) ; length of this record
(d-name (array char 256)))) ; name must be no longer than this
#-(or svr4 bsd linux) ; eg hpux and alpha
(def-alien-type nil
(struct stat
(st-dev dev-t)
(st-ino ino-t)
(st-uid uid-t)
(st-gid gid-t)
(st-rdev dev-t)
(st-size off-t)
(st-atime time-t)
(st-spare1 int)
(st-mtime time-t)
(st-spare2 int)
(st-ctime time-t)
(st-spare3 int)
(st-blksize #-alpha long #+alpha unsigned-int)
(st-blocks #-alpha long #+alpha int)
(def-alien-type nil
(struct stat
(st-dev dev-t)
(st-ino ino-t)
(st-atime (struct timespec-t))
(st-mtime (struct timespec-t))
(st-ctime (struct timespec-t))
(st-size off-t)
(st-blocks off-t)
(st-blksize unsigned-long)
(st-flags unsigned-long)
(st-gen unsigned-long)
(st-lspare long)
(st-qspare (array long 4))))
#+(or linux svr4)
(def-alien-type nil
(struct stat
(st-dev dev-t)
(st-pad1 #-linux (array long 3) #+linux unsigned-short)
(st-ino ino-t)
(st-mode #-linux unsigned-long #+linux unsigned-short)
(st-nlink #-linux short #+linux unsigned-short)
(st-uid #-linux uid-t #+linux unsigned-short)
(st-gid #-linux gid-t #+linux unsigned-short)
(st-rdev dev-t)
(st-pad2 #-linux (array long 2) #+linux unsigned-short)
#-linux (st-pad3 long)
#+linux (st-blksize unsigned-long)
#+linux (st-blocks unsigned-long)
#-linux (st-atime (struct timestruc-t))
#+linux (st-atime unsigned-long)
#+linux (unused-1 unsigned-long)
#-linux (st-mtime (struct timestruc-t))
#+linux (st-mtime unsigned-long)
#+linux (unused-2 unsigned-long)
#-linux (st-ctime (struct timestruc-t))
#+linux (st-ctime unsigned-long)
#+linux (unused-3 unsigned-long)
#+linux (unused-4 unsigned-long)
#+linux (unused-5 unsigned-long)
#-linux(st-blksize long)
#-linux (st-blocks long)
#-linux (st-fstype (array char 16))
#-linux (st-pad4 (array long 8))))
;;; 64-bit stat for Solaris
#+solaris
(def-alien-type nil
(struct stat64
(st-dev dev-t)
(st-pad1 (array long 3)) ; Pad so ino is 64-bit aligned
(st-ino ino64-t)
(st-mode unsigned-long)
(st-nlink short)
(st-uid uid-t)
(st-gid gid-t)
(st-rdev dev-t)
(st-pad2 (array long 3)) ; Pad so size is 64-bit aligned
(st-size off64-t)
(st-atime (struct timestruc-t))
(st-mtime (struct timestruc-t))
(st-ctime (struct timestruc-t))
(st-blksize long)
(st-pad3 (array long 1)) ; Pad so blocks is 64-bit aligned
(st-blocks blkcnt64-t)
(st-fstype (array char 16))
(st-pad4 (array long 8))))
(defconstant s-ifmt #o0170000)
(defconstant s-ifdir #o0040000)
(defconstant s-ifchr #o0020000)
#+linux (defconstant s-ififo #x0010000)
(defconstant s-ifblk #o0060000)
(defconstant s-ifreg #o0100000)
(defconstant s-iflnk #o0120000)
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
(defconstant s-ifsock #o0140000)
(defconstant s-isuid #o0004000)
(defconstant s-isgid #o0002000)
(defconstant s-isvtx #o0001000)
(defconstant s-iread #o0000400)
(defconstant s-iwrite #o0000200)
(defconstant s-iexec #o0000100)
;;; From sys/resource.h
(def-alien-type nil
(struct rusage
(ru-utime (struct timeval)) ; user time used
(ru-stime (struct timeval)) ; system time used.
(ru-maxrss long)
(ru-ixrss long) ; integral sharded memory size
(ru-idrss long) ; integral unsharded data "
(ru-isrss long) ; integral unsharded stack "
(ru-minflt long) ; page reclaims
(ru-majflt long) ; page faults
(ru-nswap long) ; swaps
(ru-inblock long) ; block input operations
(ru-oublock long) ; block output operations
(ru-msgsnd long) ; messages sent
(ru-msgrcv long) ; messages received
(ru-nsignals long) ; signals received
(ru-nvcsw long) ; voluntary context switches
(ru-nivcsw long))) ; involuntary "
(def-alien-type nil
(struct rlimit
(rlim-cur #-(or linux alpha) int #+linux long #+alpha unsigned-int) ; current (soft) limit
(rlim-max #-(or linux alpha) int #+linux long #+alpha unsigned-int))); maximum value for rlim-cur
;;;; Errno stuff.
(eval-when (compile eval)
(defparameter *compiler-unix-errors* nil)
(defmacro def-unix-error (name number description)
`(progn
(eval-when (compile eval)
(push (cons ,number ,description) *compiler-unix-errors*))
(defconstant ,name ,number ,description)
(export ',name)))
(defmacro emit-unix-errors ()
(let* ((max (apply #'max (mapcar #'car *compiler-unix-errors*)))
(array (make-array (1+ max) :initial-element nil)))
(dolist (error *compiler-unix-errors*)
(setf (svref array (car error)) (cdr error)))
`(progn
(defvar *unix-errors* ',array)
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
(def-unix-error ESUCCESS 0 _N"Successful")
(def-unix-error EPERM 1 _N"Operation not permitted")
(def-unix-error ENOENT 2 _N"No such file or directory")
(def-unix-error ESRCH 3 _N"No such process")
(def-unix-error EINTR 4 _N"Interrupted system call")
(def-unix-error EIO 5 _N"I/O error")
(def-unix-error ENXIO 6 _N"Device not configured")
(def-unix-error E2BIG 7 _N"Arg list too long")
(def-unix-error ENOEXEC 8 _N"Exec format error")
(def-unix-error EBADF 9 _N"Bad file descriptor")
(def-unix-error ECHILD 10 _N"No child process")
#+bsd(def-unix-error EDEADLK 11 _N"Resource deadlock avoided")
#-bsd(def-unix-error EAGAIN 11 #-linux _N"No more processes" #+linux _N"Try again")
(def-unix-error ENOMEM 12 _N"Out of memory")
(def-unix-error EACCES 13 _N"Permission denied")
(def-unix-error EFAULT 14 _N"Bad address")
(def-unix-error ENOTBLK 15 _N"Block device required")
(def-unix-error EBUSY 16 _N"Device or resource busy")
(def-unix-error EEXIST 17 _N"File exists")
(def-unix-error EXDEV 18 _N"Cross-device link")
(def-unix-error ENODEV 19 _N"No such device")
(def-unix-error ENOTDIR 20 _N"Not a director")
(def-unix-error EISDIR 21 _N"Is a directory")
(def-unix-error EINVAL 22 _N"Invalid argument")
(def-unix-error ENFILE 23 _N"File table overflow")
(def-unix-error EMFILE 24 _N"Too many open files")
(def-unix-error ENOTTY 25 _N"Inappropriate ioctl for device")
(def-unix-error ETXTBSY 26 _N"Text file busy")
(def-unix-error EFBIG 27 _N"File too large")
(def-unix-error ENOSPC 28 _N"No space left on device")
(def-unix-error ESPIPE 29 _N"Illegal seek")
(def-unix-error EROFS 30 _N"Read-only file system")
(def-unix-error EMLINK 31 _N"Too many links")
(def-unix-error EPIPE 32 _N"Broken pipe")
(def-unix-error EDOM 33 _N"Numerical argument out of domain")
(def-unix-error ERANGE 34 #-linux _N"Result too large" #+linux _N"Math result not representable")
(def-unix-error EWOULDBLOCK 35 _N"Operation would block")
#-bsd(def-unix-error EDEADLK 35 _N"Operation would block") ; Ditto
#+bsd(def-unix-error EAGAIN 35 _N"Resource temporarily unavailable")
(def-unix-error EINPROGRESS 36 _N"Operation now in progress")
(def-unix-error EALREADY 37 _N"Operation already in progress")
(def-unix-error ENOTSOCK 38 _N"Socket operation on non-socket")
(def-unix-error EDESTADDRREQ 39 _N"Destination address required")
(def-unix-error EMSGSIZE 40 _N"Message too long")
(def-unix-error EPROTOTYPE 41 _N"Protocol wrong type for socket")
(def-unix-error ENOPROTOOPT 42 _N"Protocol not available")
(def-unix-error EPROTONOSUPPORT 43 _N"Protocol not supported")
(def-unix-error ESOCKTNOSUPPORT 44 _N"Socket type not supported")
(def-unix-error EOPNOTSUPP 45 _N"Operation not supported on socket")
(def-unix-error EPFNOSUPPORT 46 _N"Protocol family not supported")
(def-unix-error EAFNOSUPPORT 47 _N"Address family not supported by protocol family")
(def-unix-error EADDRINUSE 48 _N"Address already in use")
(def-unix-error EADDRNOTAVAIL 49 _N"Can't assign requested address")
(def-unix-error ENETDOWN 50 _N"Network is down")
(def-unix-error ENETUNREACH 51 _N"Network is unreachable")
(def-unix-error ENETRESET 52 _N"Network dropped connection on reset")
(def-unix-error ECONNABORTED 53 _N"Software caused connection abort")
(def-unix-error ECONNRESET 54 _N"Connection reset by peer")
(def-unix-error ENOBUFS 55 _N"No buffer space available")
(def-unix-error EISCONN 56 _N"Socket is already connected")
(def-unix-error ENOTCONN 57 _N"Socket is not connected")
(def-unix-error ESHUTDOWN 58 _N"Can't send after socket shutdown")
(def-unix-error ETOOMANYREFS 59 _N"Too many references: can't splice")
(def-unix-error ETIMEDOUT 60 _N"Connection timed out")
(def-unix-error ECONNREFUSED 61 _N"Connection refused")
(def-unix-error ELOOP 62 _N"Too many levels of symbolic links")
(def-unix-error ENAMETOOLONG 63 _N"File name too long")
(def-unix-error EHOSTDOWN 64 _N"Host is down")
(def-unix-error EHOSTUNREACH 65 _N"No route to host")
(def-unix-error ENOTEMPTY 66 _N"Directory not empty")
(def-unix-error EPROCLIM 67 _N"Too many processes")
(def-unix-error EUSERS 68 _N"Too many users")
(def-unix-error EDQUOT 69 _N"Disc quota exceeded")
(def-unix-error ELOCAL 126 _N"namei should continue locally")
(def-unix-error EREMOTE 127 _N"namei was handled remotely")
(def-unix-error EVICEERR 70 _N"Remote file system error _N")
(def-unix-error EVICEOP 71 _N"syscall was handled by Vice")
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
(def-unix-error ENOMSG 35 _N"No message of desired type")
(def-unix-error EIDRM 36 _N"Identifier removed")
(def-unix-error ECHRNG 37 _N"Channel number out of range")
(def-unix-error EL2NSYNC 38 _N"Level 2 not synchronized")
(def-unix-error EL3HLT 39 _N"Level 3 halted")
(def-unix-error EL3RST 40 _N"Level 3 reset")
(def-unix-error ELNRNG 41 _N"Link number out of range")
(def-unix-error EUNATCH 42 _N"Protocol driver not attached")
(def-unix-error ENOCSI 43 _N"No CSI structure available")
(def-unix-error EL2HLT 44 _N"Level 2 halted")
(def-unix-error EDEADLK 45 _N"Deadlock situation detected/avoided")
(def-unix-error ENOLCK 46 _N"No record locks available")
(def-unix-error ECANCELED 47 _N"Error 47")
(def-unix-error ENOTSUP 48 _N"Error 48")
(def-unix-error EBADE 50 _N"Bad exchange descriptor")
(def-unix-error EBADR 51 _N"Bad request descriptor")
(def-unix-error EXFULL 52 _N"Message tables full")
(def-unix-error ENOANO 53 _N"Anode table overflow")
(def-unix-error EBADRQC 54 _N"Bad request code")
(def-unix-error EBADSLT 55 _N"Invalid slot")
(def-unix-error EDEADLOCK 56 _N"File locking deadlock")
(def-unix-error EBFONT 57 _N"Bad font file format")
(def-unix-error ENOSTR 60 _N"Not a stream device")
(def-unix-error ENODATA 61 _N"No data available")
(def-unix-error ETIME 62 _N"Timer expired")
(def-unix-error ENOSR 63 _N"Out of stream resources")
(def-unix-error ENONET 64 _N"Machine is not on the network")
(def-unix-error ENOPKG 65 _N"Package not installed")
(def-unix-error EREMOTE 66 _N"Object is remote")
(def-unix-error ENOLINK 67 _N"Link has been severed")
(def-unix-error EADV 68 _N"Advertise error")
(def-unix-error ESRMNT 69 _N"Srmount error")
(def-unix-error ECOMM 70 _N"Communication error on send")
(def-unix-error EPROTO 71 _N"Protocol error")
(def-unix-error EMULTIHOP 74 _N"Multihop attempted")
(def-unix-error EBADMSG 77 _N"Not a data message")
(def-unix-error ENAMETOOLONG 78 _N"File name too long")
(def-unix-error EOVERFLOW 79 _N"Value too large for defined data type")
(def-unix-error ENOTUNIQ 80 _N"Name not unique on network")
(def-unix-error EBADFD 81 _N"File descriptor in bad state")
(def-unix-error EREMCHG 82 _N"Remote address changed")
(def-unix-error ELIBACC 83 _N"Can not access a needed shared library")
(def-unix-error ELIBBAD 84 _N"Accessing a corrupted shared library")
(def-unix-error ELIBSCN 85 _N".lib section in a.out corrupted")
(def-unix-error ELIBMAX 86 _N"Attempting to link in more shared libraries than system limit")
(def-unix-error ELIBEXEC 87 _N"Can not exec a shared library directly")
(def-unix-error EILSEQ 88 _N"Error 88")
(def-unix-error ENOSYS 89 _N"Operation not applicable")
(def-unix-error ELOOP 90 _N"Number of symbolic links encountered during path name traversal exceeds MAXSYMLINKS")
(def-unix-error ERESTART 91 _N"Error 91")
(def-unix-error ESTRPIPE 92 _N"Error 92")
(def-unix-error ENOTEMPTY 93 _N"Directory not empty")
(def-unix-error EUSERS 94 _N"Too many users")
(def-unix-error ENOTSOCK 95 _N"Socket operation on non-socket")
(def-unix-error EDESTADDRREQ 96 _N"Destination address required")
(def-unix-error EMSGSIZE 97 _N"Message too long")
(def-unix-error EPROTOTYPE 98 _N"Protocol wrong type for socket")
(def-unix-error ENOPROTOOPT 99 _N"Option not supported by protocol")
(def-unix-error EPROTONOSUPPORT 120 _N"Protocol not supported")
(def-unix-error ESOCKTNOSUPPORT 121 _N"Socket type not supported")
(def-unix-error EOPNOTSUPP 122 _N"Operation not supported on transport endpoint")
(def-unix-error EPFNOSUPPORT 123 _N"Protocol family not supported")
(def-unix-error EAFNOSUPPORT 124 _N"Address family not supported by protocol family")
(def-unix-error EADDRINUSE 125 _N"Address already in use")
(def-unix-error EADDRNOTAVAIL 126 _N"Cannot assign requested address")
(def-unix-error ENETDOWN 127 _N"Network is down")
(def-unix-error ENETUNREACH 128 _N"Network is unreachable")
(def-unix-error ENETRESET 129 _N"Network dropped connection because of reset")
(def-unix-error ECONNABORTED 130 _N"Software caused connection abort")
(def-unix-error ECONNRESET 131 _N"Connection reset by peer")
(def-unix-error ENOBUFS 132 _N"No buffer space available")
(def-unix-error EISCONN 133 _N"Transport endpoint is already connected")
(def-unix-error ENOTCONN 134 _N"Transport endpoint is not connected")
(def-unix-error ESHUTDOWN 143 _N"Cannot send after socket shutdown")
(def-unix-error ETOOMANYREFS 144 _N"Too many references: cannot splice")
(def-unix-error ETIMEDOUT 145 _N"Connection timed out")
(def-unix-error ECONNREFUSED 146 _N"Connection refused")
(def-unix-error EHOSTDOWN 147 _N"Host is down")
(def-unix-error EHOSTUNREACH 148 _N"No route to host")
(def-unix-error EWOULDBLOCK 11 _N"Resource temporarily unavailable")
(def-unix-error EALREADY 149 _N"Operation already in progress")
(def-unix-error EINPROGRESS 150 _N"Operation now in progress")
(def-unix-error ESTALE 151 _N"Stale NFS file handle")
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
(def-unix-error EDEADLK 35 _N"Resource deadlock would occur")
(def-unix-error ENAMETOOLONG 36 _N"File name too long")
(def-unix-error ENOLCK 37 _N"No record locks available")
(def-unix-error ENOSYS 38 _N"Function not implemented")
(def-unix-error ENOTEMPTY 39 _N"Directory not empty")
(def-unix-error ELOOP 40 _N"Too many symbolic links encountered")
(def-unix-error EWOULDBLOCK 11 _N"Operation would block")
(def-unix-error ENOMSG 42 _N"No message of desired type")
(def-unix-error EIDRM 43 _N"Identifier removed")
(def-unix-error ECHRNG 44 _N"Channel number out of range")
(def-unix-error EL2NSYNC 45 _N"Level 2 not synchronized")
(def-unix-error EL3HLT 46 _N"Level 3 halted")
(def-unix-error EL3RST 47 _N"Level 3 reset")
(def-unix-error ELNRNG 48 _N"Link number out of range")
(def-unix-error EUNATCH 49 _N"Protocol driver not attached")
(def-unix-error ENOCSI 50 _N"No CSI structure available")
(def-unix-error EL2HLT 51 _N"Level 2 halted")
(def-unix-error EBADE 52 _N"Invalid exchange")
(def-unix-error EBADR 53 _N"Invalid request descriptor")
(def-unix-error EXFULL 54 _N"Exchange full")
(def-unix-error ENOANO 55 _N"No anode")
(def-unix-error EBADRQC 56 _N"Invalid request code")
(def-unix-error EBADSLT 57 _N"Invalid slot")
(def-unix-error EDEADLOCK EDEADLK _N"File locking deadlock error")
(def-unix-error EBFONT 59 _N"Bad font file format")
(def-unix-error ENOSTR 60 _N"Device not a stream")
(def-unix-error ENODATA 61 _N"No data available")
(def-unix-error ETIME 62 _N"Timer expired")
(def-unix-error ENOSR 63 _N"Out of streams resources")
(def-unix-error ENONET 64 _N"Machine is not on the network")
(def-unix-error ENOPKG 65 _N"Package not installed")
(def-unix-error EREMOTE 66 _N"Object is remote")
(def-unix-error ENOLINK 67 _N"Link has been severed")
(def-unix-error EADV 68 _N"Advertise error")
(def-unix-error ESRMNT 69 _N"Srmount error")
(def-unix-error ECOMM 70 _N"Communication error on send")
(def-unix-error EPROTO 71 _N"Protocol error")
(def-unix-error EMULTIHOP 72 _N"Multihop attempted")
(def-unix-error EDOTDOT 73 _N"RFS specific error")
(def-unix-error EBADMSG 74 _N"Not a data message")
(def-unix-error EOVERFLOW 75 _N"Value too large for defined data type")
(def-unix-error ENOTUNIQ 76 _N"Name not unique on network")
(def-unix-error EBADFD 77 _N"File descriptor in bad state")
(def-unix-error EREMCHG 78 _N"Remote address changed")
(def-unix-error ELIBACC 79 _N"Can not access a needed shared library")
(def-unix-error ELIBBAD 80 _N"Accessing a corrupted shared library")
(def-unix-error ELIBSCN 81 _N".lib section in a.out corrupted")
(def-unix-error ELIBMAX 82 _N"Attempting to link in too many shared libraries")
(def-unix-error ELIBEXEC 83 _N"Cannot exec a shared library directly")
(def-unix-error EILSEQ 84 _N"Illegal byte sequence")
(def-unix-error ERESTART 85 _N"Interrupted system call should be restarted _N")
(def-unix-error ESTRPIPE 86 _N"Streams pipe error")
(def-unix-error EUSERS 87 _N"Too many users")
(def-unix-error ENOTSOCK 88 _N"Socket operation on non-socket")
(def-unix-error EDESTADDRREQ 89 _N"Destination address required")
(def-unix-error EMSGSIZE 90 _N"Message too long")
(def-unix-error EPROTOTYPE 91 _N"Protocol wrong type for socket")
(def-unix-error ENOPROTOOPT 92 _N"Protocol not available")
(def-unix-error EPROTONOSUPPORT 93 _N"Protocol not supported")
(def-unix-error ESOCKTNOSUPPORT 94 _N"Socket type not supported")
(def-unix-error EOPNOTSUPP 95 _N"Operation not supported on transport endpoint")
(def-unix-error EPFNOSUPPORT 96 _N"Protocol family not supported")
(def-unix-error EAFNOSUPPORT 97 _N"Address family not supported by protocol")
(def-unix-error EADDRINUSE 98 _N"Address already in use")
(def-unix-error EADDRNOTAVAIL 99 _N"Cannot assign requested address")
(def-unix-error ENETDOWN 100 _N"Network is down")
(def-unix-error ENETUNREACH 101 _N"Network is unreachable")
(def-unix-error ENETRESET 102 _N"Network dropped connection because of reset")
(def-unix-error ECONNABORTED 103 _N"Software caused connection abort")
(def-unix-error ECONNRESET 104 _N"Connection reset by peer")
(def-unix-error ENOBUFS 105 _N"No buffer space available")
(def-unix-error EISCONN 106 _N"Transport endpoint is already connected")
(def-unix-error ENOTCONN 107 _N"Transport endpoint is not connected")
(def-unix-error ESHUTDOWN 108 _N"Cannot send after transport endpoint shutdown")
(def-unix-error ETOOMANYREFS 109 _N"Too many references: cannot splice")
(def-unix-error ETIMEDOUT 110 _N"Connection timed out")
(def-unix-error ECONNREFUSED 111 _N"Connection refused")
(def-unix-error EHOSTDOWN 112 _N"Host is down")
(def-unix-error EHOSTUNREACH 113 _N"No route to host")
(def-unix-error EALREADY 114 _N"Operation already in progress")
(def-unix-error EINPROGRESS 115 _N"Operation now in progress")
(def-unix-error ESTALE 116 _N"Stale NFS file handle")
(def-unix-error EUCLEAN 117 _N"Structure needs cleaning")
(def-unix-error ENOTNAM 118 _N"Not a XENIX named type file")
(def-unix-error ENAVAIL 119 _N"No XENIX semaphores available")
(def-unix-error EISNAM 120 _N"Is a named type file")
(def-unix-error EREMOTEIO 121 _N"Remote I/O error")
(def-unix-error EDQUOT 122 _N"Quota exceeded")
;;;
;;; And now for something completely different ...
(emit-unix-errors)
(def-alien-routine ("os_get_errno" unix-get-errno) int)
(def-alien-routine ("os_set_errno" unix-set-errno) int (newvalue int))
(defun unix-errno () (unix-get-errno))
(defun (setf unix-errno) (newvalue) (unix-set-errno newvalue))
(defun get-unix-error-msg (&optional (error-number (unix-errno)))
_N"Returns a string describing the error number which was returned by a
UNIX system call."
(declare (type integer error-number))
(if (array-in-bounds-p *unix-errors* error-number)
(svref *unix-errors* error-number)
(format nil _"Unknown error [~d]" error-number)))
;;;; Lisp types used by syscalls.
(deftype unix-pathname () 'simple-string)
(deftype unix-fd () `(integer 0 ,most-positive-fixnum))
(deftype unix-file-mode () '(unsigned-byte 32))
(deftype unix-pid () '(unsigned-byte 32))
(deftype unix-uid () '(unsigned-byte 32))
(deftype unix-gid () '(unsigned-byte 32))
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
;;;; User and group database structures
(defstruct user-info
(name "" :type string)
(password "" :type string)
(uid 0 :type unix-uid)
(gid 0 :type unix-gid)
#+solaris (age "" :type string)
#+solaris (comment "" :type string)
#+freebsd (change -1 :type fixnum)
(gecos "" :type string)
(dir "" :type string)
(shell "" :type string))
(defstruct group-info
(name "" :type string)
(password "" :type string)
(gid 0 :type unix-gid)
(members nil :type list)) ; list of logins as strings
;; see <pwd.h>
#+solaris
(def-alien-type nil
(struct passwd
(pw-name (* char)) ; user's login name
(pw-passwd (* char)) ; no longer used
(pw-uid uid-t) ; user id
(pw-gid gid-t) ; group id
(pw-age (* char)) ; password age (not used)
(pw-comment (* char)) ; not used
(pw-gecos (* char)) ; typically user's full name
(pw-dir (* char)) ; user's home directory
(pw-shell (* char)))) ; user's login shell