plugins/ext2/ext2.c
/* Create the per-connection handle. */
Create the per-connection handle.
Create the per - connection handle .
static void *
ext2_open (int readonly)
{
  struct handle *h;
  errcode_t err;
  int fs_flags;
  int file_flags;
  struct ext2_inode inode;
  h = malloc (sizeof *h);
  if (h == NULL) {
    nbdkit_error ("malloc: %m");
    return NULL;
  }
  fs_flags = 0;
#ifdef EXT2_FLAG_64BITS
  fs_flags |= EXT2_FLAG_64BITS;
#endif
  if (!readonly)
    fs_flags |= EXT2_FLAG_RW;
  err = ext2fs_open (disk, fs_flags, 0, 0, unix_io_manager, &h->fs);
  if (err != 0) {
    nbdkit_error ("%s: open: %s", disk, error_message (err));
    goto err0;
  }
  if (strcmp (file, "/") == 0)
    h->ino = EXT2_ROOT_INO;
  else {
    err = ext2fs_namei (h->fs, EXT2_ROOT_INO, EXT2_ROOT_INO,
                        &file[1], &h->ino);
    if (err != 0) {
      nbdkit_error ("%s: %s: namei: %s", disk, file, error_message (err));
      goto err1;
    }
  }
  err = ext2fs_read_inode (h->fs, h->ino, &inode);
  if (err != 0) {
    nbdkit_error ("%s: %s: inode: %s", disk, file, error_message (err));
    goto err1;
  }
  if (!LINUX_S_ISREG (inode.i_mode)) {
    nbdkit_error ("%s: %s: must be a regular file in the disk image",
                  disk, file);
    goto err1;
  }
  file_flags = 0;
  if (!readonly)
    file_flags |= EXT2_FILE_WRITE;
  err = ext2fs_file_open2 (h->fs, h->ino, NULL, file_flags, &h->file);
  if (err != 0) {
    nbdkit_error ("%s: %s: open: %s", disk, file, error_message (err));
    goto err1;
  }
  return h;
 err1:
  ext2fs_close (h->fs);
 err0:
  free (h);
  return NULL;
}
static void * ext2_open ( int readonly ) { struct handle * h ; errcode_t err ; int fs_flags ; int file_flags ; struct ext2_inode inode ; h = malloc ( sizeof * h ) ; if ( h == NULL ) { nbdkit_error ( " " ) ; return NULL ; } fs_flags = 0 ; #ifdef EXT2_FLAG_64BITS fs_flags |= EXT2_FLAG_64BITS ; #endif if ( ! readonly ) fs_flags |= EXT2_FLAG_RW ; err = ext2fs_open ( disk , fs_flags , 0 , 0 , unix_io_manager , & h -> fs ) ; if ( err != 0 ) { nbdkit_error ( " " , disk , error_message ( err ) ) ; goto err0 ; } if ( strcmp ( file , " " ) == 0 ) h -> ino = EXT2_ROOT_INO ; else { err = ext2fs_namei ( h -> fs , EXT2_ROOT_INO , EXT2_ROOT_INO , & file [ 1 ] , & h -> ino ) ; if ( err != 0 ) { nbdkit_error ( " " , disk , file , error_message ( err ) ) ; goto err1 ; } } err = ext2fs_read_inode ( h -> fs , h -> ino , & inode ) ; if ( err != 0 ) { nbdkit_error ( " " , disk , file , error_message ( err ) ) ; goto err1 ; } if ( ! LINUX_S_ISREG ( inode . i_mode ) ) { nbdkit_error ( " " , disk , file ) ; goto err1 ; } file_flags = 0 ; if ( ! readonly ) file_flags |= EXT2_FILE_WRITE ; err = ext2fs_file_open2 ( h -> fs , h -> ino , NULL , file_flags , & h -> file ) ; if ( err != 0 ) { nbdkit_error ( " " , disk , file , error_message ( err ) ) ; goto err1 ; } return h ; err1 : ext2fs_close ( h -> fs ) ; err0 : free ( h ) ; return NULL ; }
Create the per-connection handle.
Create the per - connection handle .
/* probably gonna fail, but we'll catch it later */ /* Check the file is a regular file.
   * XXX This won't follow symlinks, we'd have to do that manually.
   */