Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libsa Make a bunch of backward-compatible changes to...



details:   https://anonhg.NetBSD.org/src/rev/a527ff3ad2f1
branches:  trunk
changeset: 467914:a527ff3ad2f1
user:      cgd <cgd%NetBSD.org@localhost>
date:      Wed Mar 31 01:50:25 1999 +0000

description:
Make a bunch of backward-compatible changes to the boot blocks which allow
size to be reduced substantially.  (backward compatibility verified
by compiling one of the alpha boot blocks which uses all of the code
before and after, diffing the object files, and manually verifying that
the differences were 'correct'.  some differences were "unavoidable,"
it wanting to avoid a double-commit, because e.g. local variables which
were previously used were no longer used.)  a README which describes
supported options (or at least the ones mentioned below) is forthcoming.

add support for the preprocessor macro LIBSA_NO_TWIDDLE, which
  causes calls to twiddle() to be omitted if it's defined.
add support for the preprocessor macros:
        LIBSA_NO_FS_CLOSE
        LIBSA_NO_FS_WRITE
        LIBSA_NO_FS_SEEK
  which, if defined, cause the corresponding file system operations
  in the individual file system implementations to be omitted.  (note
  that all of those macros are not supported by all file systems at
  this point.  comments were added to individual file system files
  to indicate lack of support, and should be cleaned up later.  Backward
  compatibility options e.g. UFS_NOCLOSE, etc., are supported.)
add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which
  removes support for symbolic links from the file system support
  functions.  (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which
  removes all subdirectory and symlink support from the file system
  support functions.  (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which
  causes code relating to libsa file descriptor checks (e.g. range
  checking and checking that a file descriptor is valid) to be
  omitted if it's defined.
add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which
  causes code relating to raw device access to be omitted if it's
  defined.
change some structure copies to use bcopy() instead.  that way
  use of bcopy vs. memcpy() can easily be selected by
  LIBSA_USE_MEMCPY.  (without changes like these, you could end up
  having both bcopy() and memcpy() included.  eventually, all
  calls to bcopy should be changed to calls to memcpy() or memmove()
  as appropriate -- hopefully never the latter -- with an option to
  use bcopy instead.)
add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which
  causes disklabel() to return '1' as msg rather than a string.  Can
  be used if the boot blocks don't care about the string, and need to
  save the space.
add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which
  if defined causes all of the file system switch code to be removed.
  Its value should be the name of the file system supported by the
  boot block, e.g. "ufs" for the FFS file system.  calls to the
  file system functions open, close, etc., which were previously
  done through a function switch are then done via direct invocation
  of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...).
add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which
  does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device
  switch table.  Device entry pointes are expected to be named
  <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE
  is set to 'disk' is diskstrategy.
make ufs.c f_nindir array be unsigned ints.  the fact that it was signed
  caused ufs.c to require signed division routines (which were otherwise
  unnecessary for a small boot block).

diffstat:

 sys/lib/libsa/cd9660.c    |  31 +++++++++++++--
 sys/lib/libsa/close.c     |  20 +++++++--
 sys/lib/libsa/cread.c     |   6 ++-
 sys/lib/libsa/disklabel.c |  12 +++++-
 sys/lib/libsa/fstat.c     |   8 +++-
 sys/lib/libsa/ioctl.c     |  10 ++++-
 sys/lib/libsa/lseek.c     |   8 +++-
 sys/lib/libsa/netif.c     |   6 ++-
 sys/lib/libsa/nfs.c       |  14 ++++++-
 sys/lib/libsa/nullfs.c    |  12 +++++-
 sys/lib/libsa/open.c      |  41 ++++++++++++++++----
 sys/lib/libsa/read.c      |  12 ++++-
 sys/lib/libsa/stand.h     |  92 ++++++++++++++++++++++++++++++++++++++++++++++-
 sys/lib/libsa/tftp.c      |  16 +++++++-
 sys/lib/libsa/ufs.c       |  78 +++++++++++++++++++++++++++++++--------
 sys/lib/libsa/ustarfs.c   |  17 +++++++-
 sys/lib/libsa/write.c     |  12 ++++-
 17 files changed, 339 insertions(+), 56 deletions(-)

diffs (truncated from 1060 to 300 lines):

diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/cd9660.c
--- a/sys/lib/libsa/cd9660.c    Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/cd9660.c    Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd9660.c,v 1.7 1999/03/26 15:41:38 dbj Exp $   */
+/*     $NetBSD: cd9660.c,v 1.8 1999/03/31 01:50:25 cgd Exp $   */
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -48,6 +48,13 @@
 #include "stand.h"
 #include "cd9660.h"
 
+/*
+ * XXX Does not currently implement:
+ * XXX
+ * XXX LIBSA_NO_FS_SYMLINK (does this even make sense?)
+ * XXX LIBSA_FS_SINGLECOMPONENT
+ */
+
 struct file {
        off_t off;                      /* Current offset within file */
        daddr_t bno;                    /* Starting block number  */
@@ -153,8 +160,10 @@
        buf = alloc(buf_size = ISO_DEFAULT_BLOCK_SIZE);
        vd = buf;
        for (bno = 16;; bno++) {
+#if !defined(LIBSA_NO_TWIDDLE)
                twiddle();
-               rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
+#endif
+               rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, cdb2devb(bno),
                                           ISO_DEFAULT_BLOCK_SIZE, buf, &read);
                if (rc)
                        goto out;
@@ -182,8 +191,10 @@
                buf = alloc(buf_size = roundup(psize, ISO_DEFAULT_BLOCK_SIZE));
        }
 
+#if !defined(LIBSA_NO_TWIDDLE)
        twiddle();
-       rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
+#endif
+       rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, cdb2devb(bno),
                                   buf_size, buf, &read);
        if (rc)
                goto out;
@@ -225,8 +236,10 @@
        for (psize = 0; psize < dsize;) {
                if (!(psize % ISO_DEFAULT_BLOCK_SIZE)) {
                        bno++;
+#if !defined(LIBSA_NO_TWIDDLE)
                        twiddle();
-                       rc = f->f_dev->dv_strategy(f->f_devdata, F_READ,
+#endif
+                       rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
                                                   cdb2devb(bno),
                                                   ISO_DEFAULT_BLOCK_SIZE,
                                                   buf, &read);
@@ -278,6 +291,7 @@
        return rc;
 }
 
+#if !defined(LIBSA_NO_FS_CLOSE)
 int
 cd9660_close(f)
        struct open_file *f;
@@ -289,6 +303,7 @@
        
        return 0;
 }
+#endif /* !defined(LIBSA_NO_FS_CLOSE) */
 
 int
 cd9660_read(f, start, size, resid)
@@ -313,8 +328,10 @@
                        dp = buf;
                else
                        dp = start;
+#if !defined(LIBSA_NO_TWIDDLE)
                twiddle();      
-               rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
+#endif
+               rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, cdb2devb(bno),
                                           ISO_DEFAULT_BLOCK_SIZE, dp, &read);
                if (rc)
                        return rc;
@@ -340,6 +357,7 @@
        return rc;
 }
 
+#if !defined(LIBSA_NO_FS_WRITE)
 int
 cd9660_write(f, start, size, resid)
        struct open_file *f;
@@ -349,7 +367,9 @@
 {
        return EROFS;
 }
+#endif /* !defined(LIBSA_NO_FS_WRITE) */
 
+#if !defined(LIBSA_NO_FS_SEEK)
 off_t
 cd9660_seek(f, offset, where)
        struct open_file *f;
@@ -373,6 +393,7 @@
        }
        return fp->off;
 }
+#endif /* !defined(LIBSA_NO_FS_SEEK) */
 
 int
 cd9660_stat(f, sb)
diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/close.c
--- a/sys/lib/libsa/close.c     Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/close.c     Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: close.c,v 1.7 1997/01/22 00:38:09 cgd Exp $    */
+/*     $NetBSD: close.c,v 1.8 1999/03/31 01:50:25 cgd Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -77,14 +77,24 @@
        register struct open_file *f = &files[fd];
        int err1 = 0, err2 = 0;
 
+#if !defined(LIBSA_NO_FD_CHECKING)
        if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
                errno = EBADF;
                return (-1);
        }
-       if (!(f->f_flags & F_RAW) && f->f_ops)
-               err1 = (f->f_ops->close)(f);
-       if (!(f->f_flags & F_NODEV) && f->f_dev)
-               err2 = (f->f_dev->dv_close)(f);
+#endif
+#if !defined(LIBSA_NO_RAW_ACCESS)
+       if (!(f->f_flags & F_RAW))
+#endif
+#if !defined(LIBSA_SINGLE_FILESYSTEM)
+               if (f->f_ops != NULL)
+#endif
+                       err1 = FS_CLOSE(f->f_ops)(f);
+       if (!(f->f_flags & F_NODEV))
+#if !defined(LIBSA_SINGLE_DEVICE)
+               if (f->f_dev != NULL)
+#endif
+                       err2 = DEV_CLOSE(f->f_dev)(f);
        f->f_flags = 0;
        if (err1) {
                errno = err1;
diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/cread.c
--- a/sys/lib/libsa/cread.c     Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/cread.c     Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cread.c,v 1.8 1999/02/12 10:44:07 drochner Exp $       */
+/*     $NetBSD: cread.c,v 1.9 1999/03/31 01:50:25 cgd Exp $    */
 
 /*
  * Copyright (c) 1996
@@ -277,10 +277,12 @@
        struct open_file *f;
        struct sd *s;
 
+#if !defined(LIBSA_NO_FD_CHECKING)
        if ((unsigned)fd >= SOPEN_MAX) {
                errno = EBADF;
                return (-1);
        }
+#endif
        f = &files[fd];
 
        if ((f->f_flags & F_READ) == 0)
@@ -396,10 +398,12 @@
        struct open_file *f;
        struct sd *s;
 
+#if !defined(LIBSA_NO_FD_CHECKING)
        if ((unsigned)fd >= SOPEN_MAX) {
                errno = EBADF;
                return (-1);
        }
+#endif
        f = &files[fd];;
 
        if ((f->f_flags & F_READ) == 0)
diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/disklabel.c
--- a/sys/lib/libsa/disklabel.c Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/disklabel.c Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.4 1996/01/13 22:25:36 leo Exp $        */
+/*     $NetBSD: disklabel.c,v 1.5 1999/03/31 01:50:25 cgd Exp $        */
 
 /*-
  * Copyright (c) 1993
@@ -51,13 +51,21 @@
        for (dlp = (struct disklabel *)buf; dlp <= elp;
            dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
                if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
+#if defined(LIBSA_NO_DISKLABEL_MSGS)
+                       msg = (char *)1;
+#else
                        if (msg == (char *)0)
                                msg = "no disk label";
+#endif
                } else if (dlp->d_npartitions > MAXPARTITIONS ||
                           dkcksum(dlp) != 0)
+#if defined(LIBSA_NO_DISKLABEL_MSGS)
+                       msg = (char *)1;
+#else
                        msg = "disk label corrupted";
+#endif
                else {
-                       *lp = *dlp;
+                       bcopy(dlp, lp, sizeof *lp);
                        msg = (char *)0;
                        break;
                }
diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/fstat.c
--- a/sys/lib/libsa/fstat.c     Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/fstat.c     Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fstat.c,v 1.1 1996/01/13 22:25:38 leo Exp $    */
+/*     $NetBSD: fstat.c,v 1.2 1999/03/31 01:50:25 cgd Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -44,17 +44,21 @@
 {
        register struct open_file *f = &files[fd];
 
+#if !defined(LIBSA_NO_FD_CHECKING)
        if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
                errno = EBADF;
                return (-1);
        }
+#endif
 
+#if !defined(LIBSA_NO_RAW_ACCESS)
        /* operation not defined on raw devices */
        if (f->f_flags & F_RAW) {
                errno = EOPNOTSUPP;
                return (-1);
        }
+#endif
 
-       errno = (f->f_ops->stat)(f, sb);
+       errno = FS_STAT(f->f_ops)(f, sb);       /* XXX no point setting errno */
        return (0);
 }
diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/ioctl.c
--- a/sys/lib/libsa/ioctl.c     Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/ioctl.c     Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ioctl.c,v 1.4 1994/10/30 21:48:24 cgd Exp $    */
+/*     $NetBSD: ioctl.c,v 1.5 1999/03/31 01:50:25 cgd Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -72,18 +72,24 @@
        u_long cmd;
        char *arg;
 {
+#if !defined(LIBSA_NO_FD_CHECKING) || !defined(LIBSA_NO_RAW_ACCESS)
        register struct open_file *f = &files[fd];
+#endif
 
+#if !defined(LIBSA_NO_FD_CHECKING)
        if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
                errno = EBADF;
                return (-1);
        }
+#endif
+#if !defined(LIBSA_NO_RAW_ACCESS)
        if (f->f_flags & F_RAW) {
-               errno = (f->f_dev->dv_ioctl)(f, cmd, arg);
+               errno = DEV_IOCTL(f->f_dev)(f, cmd, arg);
                if (errno)
                        return (-1);
                return (0);
        }
+#endif
        errno = EIO;
        return (-1);
 }
diff -r 6782162d6b5e -r a527ff3ad2f1 sys/lib/libsa/lseek.c
--- a/sys/lib/libsa/lseek.c     Wed Mar 31 01:39:16 1999 +0000
+++ b/sys/lib/libsa/lseek.c     Wed Mar 31 01:50:25 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lseek.c,v 1.4 1997/01/22 00:38:10 cgd Exp $    */
+/*     $NetBSD: lseek.c,v 1.5 1999/03/31 01:50:25 cgd Exp $    */
 
 /*-
  * Copyright (c) 1993
@@ -78,11 +78,14 @@
 {
        register struct open_file *f = &files[fd];
 
+#if !defined(LIBSA_NO_FD_CHECKING)
        if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {



Home | Main Index | Thread Index | Old Index