Print this page
    
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    9259 libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/boot/lib/libstand/cd9660.c
          +++ new/usr/src/boot/lib/libstand/cd9660.c
   1    1  /*      $NetBSD: cd9660.c,v 1.5 1997/06/26 19:11:33 drochner Exp $      */
   2    2  
   3    3  /*
   4    4   * Copyright (C) 1996 Wolfgang Solfrank.
   5    5   * Copyright (C) 1996 TooLs GmbH.
   6    6   * All rights reserved.
   7    7   *
   8    8   * Redistribution and use in source and binary forms, with or without
   9    9   * modification, are permitted provided that the following conditions
  10   10   * are met:
  11   11   * 1. Redistributions of source code must retain the above copyright
  12   12   *    notice, this list of conditions and the following disclaimer.
  13   13   * 2. Redistributions in binary form must reproduce the above copyright
  14   14   *    notice, this list of conditions and the following disclaimer in the
  15   15   *    documentation and/or other materials provided with the distribution.
  16   16   * 3. All advertising materials mentioning features or use of this software
  17   17   *    must display the following acknowledgement:
  18   18   *      This product includes software developed by TooLs GmbH.
  19   19   * 4. The name of TooLs GmbH may not be used to endorse or promote products
  20   20   *    derived from this software without specific prior written permission.
  21   21   *
  22   22   * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
  23   23   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24   24   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  
    | 
      ↓ open down ↓ | 
    24 lines elided | 
    
      ↑ open up ↑ | 
  
  25   25   * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26   26   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27   27   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  28   28   * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29   29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  30   30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  31   31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32   32   */
  33   33  
  34   34  #include <sys/cdefs.h>
  35      -__FBSDID("$FreeBSD$");
  36   35  
  37   36  /*
  38   37   * Stand-alone ISO9660 file reading package.
  39   38   *
  40   39   * Note: This doesn't support Rock Ridge extensions, extended attributes,
  41   40   * blocksizes other than 2048 bytes, multi-extent files, etc.
  42   41   */
  43   42  #include <sys/param.h>
  44   43  #include <string.h>
  45   44  #include <sys/dirent.h>
  46   45  #include <isofs/cd9660/iso.h>
  47   46  #include <isofs/cd9660/cd9660_rrip.h>
  48   47  
  49   48  #include "stand.h"
  50   49  
  51   50  #define SUSP_CONTINUATION       "CE"
  52   51  #define SUSP_PRESENT            "SP"
  53   52  #define SUSP_STOP               "ST"
  54   53  #define SUSP_EXTREF             "ER"
  55   54  #define RRIP_NAME               "NM"
  56   55  
  57   56  typedef struct {
  58   57          ISO_SUSP_HEADER         h;
  
    | 
      ↓ open down ↓ | 
    13 lines elided | 
    
      ↑ open up ↑ | 
  
  59   58          u_char signature        [ISODCL (  5,    6)];
  60   59          u_char len_skp          [ISODCL (  7,    7)]; /* 711 */
  61   60  } ISO_SUSP_PRESENT;
  62   61          
  63   62  static int      buf_read_file(struct open_file *f, char **buf_p,
  64   63                      size_t *size_p);
  65   64  static int      cd9660_open(const char *path, struct open_file *f);
  66   65  static int      cd9660_close(struct open_file *f);
  67   66  static int      cd9660_read(struct open_file *f, void *buf, size_t size,
  68   67                      size_t *resid);
  69      -static int      cd9660_write(struct open_file *f, void *buf, size_t size,
  70      -                    size_t *resid);
  71   68  static off_t    cd9660_seek(struct open_file *f, off_t offset, int where);
  72   69  static int      cd9660_stat(struct open_file *f, struct stat *sb);
  73   70  static int      cd9660_readdir(struct open_file *f, struct dirent *d);
  74   71  static int      dirmatch(struct open_file *f, const char *path,
  75   72                      struct iso_directory_record *dp, int use_rrip, int lenskip);
  76   73  static int      rrip_check(struct open_file *f, struct iso_directory_record *dp,
  77   74                      int *lenskip);
  78   75  static char     *rrip_lookup_name(struct open_file *f,
  79   76                      struct iso_directory_record *dp, int lenskip, size_t *len);
  80   77  static ISO_SUSP_HEADER *susp_lookup_record(struct open_file *f,
  81   78                      const char *identifier, struct iso_directory_record *dp,
  82   79                      int lenskip);
  83   80  
  84   81  struct fs_ops cd9660_fsops = {
  85   82          "cd9660",
  86   83          cd9660_open,
  87   84          cd9660_close,
  88   85          cd9660_read,
  89      -        cd9660_write,
       86 +        null_write,
  90   87          cd9660_seek,
  91   88          cd9660_stat,
  92   89          cd9660_readdir
  93   90  };
  94   91  
  95   92  #define F_ISDIR         0x0001          /* Directory */
  96   93  #define F_ROOTDIR       0x0002          /* Root directory */
  97   94  #define F_RR            0x0004          /* Rock Ridge on this volume */
  98   95  
  99   96  struct file {
 100   97          int             f_flags;        /* file flags */
 101   98          off_t           f_off;          /* Current offset within file */
 102   99          daddr_t         f_bno;          /* Starting block number */
 103  100          off_t           f_size;         /* Size of file */
 104  101          daddr_t         f_buf_blkno;    /* block number of data block */        
 105  102          char            *f_buf;         /* buffer for data block */
 106  103          int             f_susp_skip;    /* len_skip for SUSP records */
 107  104  };
 108  105  
 109  106  struct ptable_ent {
 110  107          char namlen     [ISODCL( 1, 1)];        /* 711 */
 111  108          char extlen     [ISODCL( 2, 2)];        /* 711 */
 112  109          char block      [ISODCL( 3, 6)];        /* 732 */
 113  110          char parent     [ISODCL( 7, 8)];        /* 722 */
 114  111          char name       [1];
 115  112  };
 116  113  #define PTFIXSZ         8
 117  114  #define PTSIZE(pp)      roundup(PTFIXSZ + isonum_711((pp)->namlen), 2)
 118  115  
 119  116  #define cdb2devb(bno)   ((bno) * ISO_DEFAULT_BLOCK_SIZE / DEV_BSIZE)
 120  117  
 121  118  static ISO_SUSP_HEADER *
 122  119  susp_lookup_record(struct open_file *f, const char *identifier,
 123  120      struct iso_directory_record *dp, int lenskip)
 124  121  {
 125  122          static char susp_buffer[ISO_DEFAULT_BLOCK_SIZE];
 126  123          ISO_SUSP_HEADER *sh;
 127  124          ISO_RRIP_CONT *shc;
 128  125          char *p, *end;
 129  126          int error;
 130  127          size_t read;
 131  128  
 132  129          p = dp->name + isonum_711(dp->name_len) + lenskip;
 133  130          /* Names of even length have a padding byte after the name. */
 134  131          if ((isonum_711(dp->name_len) & 1) == 0)
 135  132                  p++;
 136  133          end = (char *)dp + isonum_711(dp->length);
 137  134          while (p + 3 < end) {
 138  135                  sh = (ISO_SUSP_HEADER *)p;
 139  136                  if (bcmp(sh->type, identifier, 2) == 0)
 140  137                          return (sh);
 141  138                  if (bcmp(sh->type, SUSP_STOP, 2) == 0)
 142  139                          return (NULL);
 143  140                  if (bcmp(sh->type, SUSP_CONTINUATION, 2) == 0) {
 144  141                          shc = (ISO_RRIP_CONT *)sh;
 145  142                          error = f->f_dev->dv_strategy(f->f_devdata, F_READ,
 146  143                              cdb2devb(isonum_733(shc->location)),
 147  144                              ISO_DEFAULT_BLOCK_SIZE, susp_buffer, &read);
 148  145  
 149  146                          /* Bail if it fails. */
 150  147                          if (error != 0 || read != ISO_DEFAULT_BLOCK_SIZE)
 151  148                                  return (NULL);
 152  149                          p = susp_buffer + isonum_733(shc->offset);
 153  150                          end = p + isonum_733(shc->length);
 154  151                  } else {
 155  152                          /* Ignore this record and skip to the next. */
 156  153                          p += isonum_711(sh->length);
 157  154  
 158  155                          /* Avoid infinite loops with corrupted file systems */
 159  156                          if (isonum_711(sh->length) == 0)
 160  157                                  return (NULL);
 161  158                  }
 162  159          }
 163  160          return (NULL);
 164  161  }
 165  162  
 166  163  static char *
 167  164  rrip_lookup_name(struct open_file *f, struct iso_directory_record *dp,
 168  165      int lenskip, size_t *len)
 169  166  {
 170  167          ISO_RRIP_ALTNAME *p;
 171  168  
 172  169          if (len == NULL)
 173  170                  return (NULL);
 174  171  
 175  172          p = (ISO_RRIP_ALTNAME *)susp_lookup_record(f, RRIP_NAME, dp, lenskip);
 176  173          if (p == NULL)
 177  174                  return (NULL);
 178  175          switch (*p->flags) {
 179  176          case ISO_SUSP_CFLAG_CURRENT:
 180  177                  *len = 1;
 181  178                  return (".");
 182  179          case ISO_SUSP_CFLAG_PARENT:
 183  180                  *len = 2;
 184  181                  return ("..");
 185  182          case 0:
 186  183                  *len = isonum_711(p->h.length) - 5;
 187  184                  return ((char *)p + 5);
 188  185          default:
 189  186                  /*
 190  187                   * We don't handle hostnames or continued names as they are
 191  188                   * too hard, so just bail and use the default name.
 192  189                   */
 193  190                  return (NULL);
 194  191          }
 195  192  }
 196  193  
 197  194  static int
 198  195  rrip_check(struct open_file *f, struct iso_directory_record *dp, int *lenskip)
 199  196  {
 200  197          ISO_SUSP_PRESENT *sp;
 201  198          ISO_RRIP_EXTREF *er;
 202  199          char *p;
 203  200  
 204  201          /* First, see if we can find a SP field. */
 205  202          p = dp->name + isonum_711(dp->name_len);
 206  203          if (p > (char *)dp + isonum_711(dp->length))
 207  204                  return (0);
 208  205          sp = (ISO_SUSP_PRESENT *)p;
 209  206          if (bcmp(sp->h.type, SUSP_PRESENT, 2) != 0)
 210  207                  return (0);
 211  208          if (isonum_711(sp->h.length) != sizeof(ISO_SUSP_PRESENT))
 212  209                  return (0);
 213  210          if (sp->signature[0] != 0xbe || sp->signature[1] != 0xef)
 214  211                  return (0);
 215  212          *lenskip = isonum_711(sp->len_skp);
 216  213  
 217  214          /*
 218  215           * Now look for an ER field.  If RRIP is present, then there must
 219  216           * be at least one of these.  It would be more pedantic to walk
 220  217           * through the list of fields looking for a Rock Ridge ER field.
 221  218           */
 222  219          er = (ISO_RRIP_EXTREF *)susp_lookup_record(f, SUSP_EXTREF, dp, 0);
 223  220          if (er == NULL)
 224  221                  return (0);
 225  222          return (1);
 226  223  }
 227  224  
 228  225  static int
 229  226  dirmatch(struct open_file *f, const char *path, struct iso_directory_record *dp,
 230  227      int use_rrip, int lenskip)
 231  228  {
 232  229          size_t len;
 233  230          char *cp;
 234  231          int i, icase;
 235  232  
 236  233          if (use_rrip)
 237  234                  cp = rrip_lookup_name(f, dp, lenskip, &len);
 238  235          else
 239  236                  cp = NULL;
 240  237          if (cp == NULL) {
 241  238                  len = isonum_711(dp->name_len);
 242  239                  cp = dp->name;
 243  240                  icase = 1;
 244  241          } else
 245  242                  icase = 0;
 246  243          for (i = len; --i >= 0; path++, cp++) {
 247  244                  if (!*path || *path == '/')
 248  245                          break;
 249  246                  if (*path == *cp)
 250  247                          continue;
 251  248                  if (!icase && toupper(*path) == *cp)
 252  249                          continue;
 253  250                  return 0;
 254  251          }
 255  252          if (*path && *path != '/')
 256  253                  return 0;
 257  254          /*
 258  255           * Allow stripping of trailing dots and the version number.
 259  256           * Note that this will find the first instead of the last version
 260  257           * of a file.
 261  258           */
 262  259          if (i >= 0 && (*cp == ';' || *cp == '.')) {
 263  260                  /* This is to prevent matching of numeric extensions */
 264  261                  if (*cp == '.' && cp[1] != ';')
 265  262                          return 0;
 266  263                  while (--i >= 0)
 267  264                          if (*++cp != ';' && (*cp < '0' || *cp > '9'))
 268  265                                  return 0;
 269  266          }
 270  267          return 1;
 271  268  }
 272  269  
 273  270  static int
 274  271  cd9660_open(const char *path, struct open_file *f)
 275  272  {
 276  273          struct file *fp = NULL;
 277  274          void *buf;
 278  275          struct iso_primary_descriptor *vd;
 279  276          size_t buf_size, read, dsize, off;
 280  277          daddr_t bno, boff;
 281  278          struct iso_directory_record rec;
 282  279          struct iso_directory_record *dp = NULL;
 283  280          int rc, first, use_rrip, lenskip;
 284  281  
 285  282          /* First find the volume descriptor */
 286  283          buf = malloc(buf_size = ISO_DEFAULT_BLOCK_SIZE);
 287  284          vd = buf;
 288  285          for (bno = 16;; bno++) {
 289  286                  twiddle(1);
 290  287                  rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
 291  288                      ISO_DEFAULT_BLOCK_SIZE, buf, &read);
 292  289                  if (rc)
 293  290                          goto out;
 294  291                  if (read != ISO_DEFAULT_BLOCK_SIZE) {
 295  292                          rc = EIO;
 296  293                          goto out;
 297  294                  }
 298  295                  rc = EINVAL;
 299  296                  if (bcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0)
 300  297                          goto out;
 301  298                  if (isonum_711(vd->type) == ISO_VD_END)
 302  299                          goto out;
 303  300                  if (isonum_711(vd->type) == ISO_VD_PRIMARY)
 304  301                          break;
 305  302          }
 306  303          if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE)
 307  304                  goto out;
 308  305  
 309  306          rec = *(struct iso_directory_record *) vd->root_directory_record;
 310  307          if (*path == '/') path++; /* eat leading '/' */
 311  308  
 312  309          first = 1;
 313  310          use_rrip = 0;
 314  311          while (*path) {
 315  312                  bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
 316  313                  dsize = isonum_733(rec.size);
 317  314                  off = 0;
 318  315                  boff = 0;
 319  316  
 320  317                  while (off < dsize) {
 321  318                          if ((off % ISO_DEFAULT_BLOCK_SIZE) == 0) {
 322  319                                  twiddle(1);
 323  320                                  rc = f->f_dev->dv_strategy
 324  321                                          (f->f_devdata, F_READ,
 325  322                                           cdb2devb(bno + boff),
 326  323                                           ISO_DEFAULT_BLOCK_SIZE,
 327  324                                           buf, &read);
 328  325                                  if (rc)
 329  326                                          goto out;
 330  327                                  if (read != ISO_DEFAULT_BLOCK_SIZE) {
 331  328                                          rc = EIO;
 332  329                                          goto out;
 333  330                                  }
 334  331                                  boff++;
 335  332                                  dp = (struct iso_directory_record *) buf;
 336  333                          }
 337  334                          if (isonum_711(dp->length) == 0) {
 338  335                              /* skip to next block, if any */
 339  336                              off = boff * ISO_DEFAULT_BLOCK_SIZE;
 340  337                              continue;
 341  338                          }
 342  339  
 343  340                          /* See if RRIP is in use. */
 344  341                          if (first)
 345  342                                  use_rrip = rrip_check(f, dp, &lenskip);
 346  343  
 347  344                          if (dirmatch(f, path, dp, use_rrip,
 348  345                                  first ? 0 : lenskip)) {
 349  346                                  first = 0;
 350  347                                  break;
 351  348                          } else
 352  349                                  first = 0;
 353  350  
 354  351                          dp = (struct iso_directory_record *)
 355  352                                  ((char *) dp + isonum_711(dp->length));
 356  353                          /* If the new block has zero length, it is padding. */
 357  354                          if (isonum_711(dp->length) == 0) {
 358  355                                  /* Skip to next block, if any. */
 359  356                                  off = boff * ISO_DEFAULT_BLOCK_SIZE;
 360  357                                  continue;
 361  358                          }
 362  359                          off += isonum_711(dp->length);
 363  360                  }
 364  361                  if (off >= dsize) {
 365  362                          rc = ENOENT;
 366  363                          goto out;
 367  364                  }
 368  365  
 369  366                  rec = *dp;
 370  367                  while (*path && *path != '/') /* look for next component */
 371  368                          path++;
 372  369                  if (*path) path++; /* skip '/' */
 373  370          }
 374  371  
 375  372          /* allocate file system specific data structure */
 376  373          fp = malloc(sizeof(struct file));
 377  374          bzero(fp, sizeof(struct file));
 378  375          f->f_fsdata = (void *)fp;
 379  376  
 380  377          if ((isonum_711(rec.flags) & 2) != 0) {
 381  378                  fp->f_flags = F_ISDIR;
 382  379          }
 383  380          if (first) {
 384  381                  fp->f_flags |= F_ROOTDIR;
 385  382  
 386  383                  /* Check for Rock Ridge since we didn't in the loop above. */
 387  384                  bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
 388  385                  twiddle(1);
 389  386                  rc = f->f_dev->dv_strategy(f->f_devdata, F_READ, cdb2devb(bno),
 390  387                      ISO_DEFAULT_BLOCK_SIZE, buf, &read);
 391  388                  if (rc)
 392  389                          goto out;
 393  390                  if (read != ISO_DEFAULT_BLOCK_SIZE) {
 394  391                          rc = EIO;
 395  392                          goto out;
 396  393                  }
 397  394                  dp = (struct iso_directory_record *)buf;
 398  395                  use_rrip = rrip_check(f, dp, &lenskip);
 399  396          }
 400  397          if (use_rrip) {
 401  398                  fp->f_flags |= F_RR;
 402  399                  fp->f_susp_skip = lenskip;
 403  400          }
 404  401          fp->f_off = 0;
 405  402          fp->f_bno = isonum_733(rec.extent) + isonum_711(rec.ext_attr_length);
 406  403          fp->f_size = isonum_733(rec.size);
 407  404          free(buf);
 408  405  
 409  406          return 0;
 410  407  
 411  408  out:
 412  409          if (fp)
 413  410                  free(fp);
 414  411          free(buf);
 415  412  
 416  413          return rc;
 417  414  }
 418  415  
 419  416  static int
 420  417  cd9660_close(struct open_file *f)
 421  418  {
 422  419          struct file *fp = (struct file *)f->f_fsdata;
 423  420  
 424  421          f->f_fsdata = NULL;
 425  422          free(fp);
 426  423  
 427  424          return 0;
 428  425  }
 429  426  
 430  427  static int
 431  428  buf_read_file(struct open_file *f, char **buf_p, size_t *size_p)
 432  429  {
 433  430          struct file *fp = (struct file *)f->f_fsdata;
 434  431          daddr_t blkno, blkoff;
 435  432          int rc = 0;
 436  433          size_t read;
 437  434  
 438  435          blkno = fp->f_off / ISO_DEFAULT_BLOCK_SIZE + fp->f_bno;
 439  436          blkoff = fp->f_off % ISO_DEFAULT_BLOCK_SIZE;
 440  437  
 441  438          if (blkno != fp->f_buf_blkno) {
 442  439                  if (fp->f_buf == (char *)0)
 443  440                          fp->f_buf = malloc(ISO_DEFAULT_BLOCK_SIZE);
 444  441  
 445  442                  twiddle(16);
 446  443                  rc = f->f_dev->dv_strategy(f->f_devdata, F_READ,
 447  444                      cdb2devb(blkno), ISO_DEFAULT_BLOCK_SIZE,
 448  445                      fp->f_buf, &read);
 449  446                  if (rc)
 450  447                          return (rc);
 451  448                  if (read != ISO_DEFAULT_BLOCK_SIZE)
 452  449                          return (EIO);
 453  450  
 454  451                  fp->f_buf_blkno = blkno;
 455  452          }
 456  453  
 457  454          *buf_p = fp->f_buf + blkoff;
 458  455          *size_p = ISO_DEFAULT_BLOCK_SIZE - blkoff;
 459  456  
 460  457          if (*size_p > fp->f_size - fp->f_off)
 461  458                  *size_p = fp->f_size - fp->f_off;
 462  459          return (rc);
 463  460  }
 464  461  
 465  462  static int
 466  463  cd9660_read(struct open_file *f, void *start, size_t size, size_t *resid)
 467  464  {
 468  465          struct file *fp = (struct file *)f->f_fsdata;
 469  466          char *buf, *addr;
 470  467          size_t buf_size, csize;
 471  468          int rc = 0;
 472  469  
 473  470          addr = start;
 474  471          while (size) {
 475  472                  if (fp->f_off < 0 || fp->f_off >= fp->f_size)
 476  473                          break;
 477  474  
 478  475                  rc = buf_read_file(f, &buf, &buf_size);
 479  476                  if (rc)
 480  477                          break;
 481  478  
 482  479                  csize = size > buf_size ? buf_size : size;
 483  480                  bcopy(buf, addr, csize);
 484  481  
 485  482                  fp->f_off += csize;
 486  483                  addr += csize;
 487  484                  size -= csize;
 488  485          }
 489  486          if (resid)
 490  487                  *resid = size;
 491  488          return (rc);
 492  489  }
 493  490  
 494  491  static int
 495  492  cd9660_readdir(struct open_file *f, struct dirent *d)
 496  493  {
 497  494          struct file *fp = (struct file *)f->f_fsdata;
 498  495          struct iso_directory_record *ep;
 499  496          size_t buf_size, reclen, namelen;
 500  497          int error = 0;
 501  498          int lenskip;
 502  499          char *buf, *name;
 503  500  
 504  501  again:
 505  502          if (fp->f_off >= fp->f_size)
 506  503                  return (ENOENT);
 507  504          error = buf_read_file(f, &buf, &buf_size);
 508  505          if (error)
 509  506                  return (error);
 510  507          ep = (struct iso_directory_record *)buf;
 511  508  
 512  509          if (isonum_711(ep->length) == 0) {
 513  510                  daddr_t blkno;
 514  511                  
 515  512                  /* skip to next block, if any */
 516  513                  blkno = fp->f_off / ISO_DEFAULT_BLOCK_SIZE;
 517  514                  fp->f_off = (blkno + 1) * ISO_DEFAULT_BLOCK_SIZE;
 518  515                  goto again;
 519  516          }
 520  517  
 521  518          if (fp->f_flags & F_RR) {
 522  519                  if (fp->f_flags & F_ROOTDIR && fp->f_off == 0)
 523  520                          lenskip = 0;
 524  521                  else
 525  522                          lenskip = fp->f_susp_skip;
 526  523                  name = rrip_lookup_name(f, ep, lenskip, &namelen);
 527  524          } else
 528  525                  name = NULL;
 529  526          if (name == NULL) {
 530  527                  namelen = isonum_711(ep->name_len);
 531  528                  name = ep->name;
 532  529                  if (namelen == 1) {
 533  530                          if (ep->name[0] == 0)
 534  531                                  name = ".";
 535  532                          else if (ep->name[0] == 1) {
 536  533                                  namelen = 2;
 537  534                                  name = "..";
 538  535                          }
 539  536                  }
 540  537          }
 541  538          reclen = sizeof(struct dirent) - (MAXNAMLEN+1) + namelen + 1;
 542  539          reclen = (reclen + 3) & ~3;
 543  540  
 544  541          d->d_fileno = isonum_733(ep->extent);
 545  542          d->d_reclen = reclen;
 546  543          if (isonum_711(ep->flags) & 2)
 547  544                  d->d_type = DT_DIR;
 548  545          else
  
    | 
      ↓ open down ↓ | 
    449 lines elided | 
    
      ↑ open up ↑ | 
  
 549  546                  d->d_type = DT_REG;
 550  547          d->d_namlen = namelen;
 551  548  
 552  549          bcopy(name, d->d_name, d->d_namlen);
 553  550          d->d_name[d->d_namlen] = 0;
 554  551  
 555  552          fp->f_off += isonum_711(ep->length);
 556  553          return (0);
 557  554  }
 558  555  
 559      -static int
 560      -cd9660_write(struct open_file *f __unused, void *start __unused, size_t size __unused, size_t *resid __unused)
 561      -{
 562      -        return EROFS;
 563      -}
 564      -
 565  556  static off_t
 566  557  cd9660_seek(struct open_file *f, off_t offset, int where)
 567  558  {
 568  559          struct file *fp = (struct file *)f->f_fsdata;
 569  560  
 570  561          switch (where) {
 571  562          case SEEK_SET:
 572  563                  fp->f_off = offset;
 573  564                  break;
 574  565          case SEEK_CUR:
 575  566                  fp->f_off += offset;
 576  567                  break;
 577  568          case SEEK_END:
 578  569                  fp->f_off = fp->f_size - offset;
 579  570                  break;
 580  571          default:
 581  572                  return -1;
 582  573          }
 583  574          return fp->f_off;
 584  575  }
 585  576  
 586  577  static int
 587  578  cd9660_stat(struct open_file *f, struct stat *sb)
 588  579  {
 589  580          struct file *fp = (struct file *)f->f_fsdata;
 590  581  
 591  582          /* only important stuff */
 592  583          sb->st_mode = S_IRUSR | S_IRGRP | S_IROTH;
 593  584          if (fp->f_flags & F_ISDIR)
 594  585                  sb->st_mode |= S_IFDIR;
 595  586          else
 596  587                  sb->st_mode |= S_IFREG;
 597  588          sb->st_uid = sb->st_gid = 0;
 598  589          sb->st_size = fp->f_size;
 599  590          return 0;
 600  591  }
  
    | 
      ↓ open down ↓ | 
    26 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX