Blame test/testisocd_joliet.c

Packit dd8086
/*
Packit dd8086
  Copyright (C) 2013, 2017 Rocky Bernstein
Packit dd8086
  <rocky@gnu.org>
Packit dd8086
Packit dd8086
  This program is free software: you can redistribute it and/or modify
Packit dd8086
  it under the terms of the GNU General Public License as published by
Packit dd8086
  the Free Software Foundation, either version 3 of the License, or
Packit dd8086
  (at your option) any later version.
Packit dd8086
Packit dd8086
  This program is distributed in the hope that it will be useful,
Packit dd8086
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit dd8086
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit dd8086
  GNU General Public License for more details.
Packit dd8086
Packit dd8086
  You should have received a copy of the GNU General Public License
Packit dd8086
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit dd8086
*/
Packit dd8086
Packit dd8086
/* Tests reading ISO 9660 info from an ISO 9660 image.  */
Packit dd8086
#include "portable.h"
Packit dd8086
#include "cdio_assert.h"
Packit dd8086
Packit dd8086
#ifdef HAVE_CONFIG_H
Packit dd8086
# include "config.h"
Packit dd8086
#endif
Packit dd8086
Packit dd8086
#ifdef HAVE_SYS_TYPES_H
Packit dd8086
#include <sys/types.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_STDLIB_H
Packit dd8086
#include <stdlib.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_STDIO_H
Packit dd8086
#include <stdio.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_ERRNO_H
Packit dd8086
#include <errno.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_STRING_H
Packit dd8086
#include <string.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_UNISTD_H
Packit dd8086
#include <unistd.h>
Packit dd8086
#endif
Packit dd8086
Packit dd8086
#include <cdio/cdio.h>
Packit dd8086
#include <cdio/iso9660.h>
Packit dd8086
#include <cdio/cd_types.h>
Packit dd8086
#include "filemode.h"
Packit dd8086
Packit dd8086
#ifndef DATA_DIR
Packit dd8086
#define DATA_DIR "./data"
Packit dd8086
#endif
Packit dd8086
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
Packit dd8086
#define ISO9660_IMAGE_PATH DATA_DIR "/"
Packit dd8086
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "joliet.iso"
Packit dd8086
Packit dd8086
#define SKIP_TEST_RC 77
Packit dd8086
Packit dd8086
int
Packit dd8086
main(int argc, const char *argv[])
Packit dd8086
{
Packit dd8086
  iso9660_t *p_iso;
Packit dd8086
  iso9660_stat_t *p_statbuf;
Packit dd8086
Packit dd8086
  p_iso = iso9660_open(ISO9660_IMAGE);
Packit dd8086
  if (!p_iso) {
Packit dd8086
    fprintf(stderr, "Sorry, couldn't open ISO9660 image %s\n",
Packit dd8086
	    ISO9660_IMAGE);
Packit dd8086
    return 1;
Packit dd8086
  } else {
Packit dd8086
    uint8_t joliet_level = iso9660_ifs_get_joliet_level(p_iso);
Packit dd8086
    if ( joliet_level != 0) {
Packit dd8086
      printf("Expecting joliet level to be 0, got %d\n", joliet_level);
Packit dd8086
      exit(10);
Packit dd8086
    } else {
Packit dd8086
      printf("-- joliet level 0, as expected.\n");
Packit dd8086
    }
Packit dd8086
Packit dd8086
#ifdef HAVE_JOLIET
Packit dd8086
    iso9660_close(p_iso);
Packit dd8086
    p_iso = iso9660_open_ext(ISO9660_IMAGE, ISO_EXTENSION_ALL);
Packit dd8086
    joliet_level = iso9660_ifs_get_joliet_level(p_iso);
Packit dd8086
    if ( joliet_level != 3) {
Packit dd8086
      printf("Expecting joliet level to be 3, got %d\n", joliet_level);
Packit dd8086
      exit(11);
Packit dd8086
    } else {
Packit dd8086
      printf("-- joliet level 3, as expected.\n");
Packit dd8086
    }
Packit dd8086
#endif
Packit dd8086
Packit dd8086
    /* You make get different results looking up "/" versus "/." and the
Packit dd8086
       latter may give more complete information. "/" will take information
Packit dd8086
       from the PVD only, whereas "/." will force a directory read of "/" and
Packit dd8086
       find "." and in that Rock-Ridge information might be found which fills
Packit dd8086
       in more stat information that iso9660_fs_find_lsn also will find.
Packit dd8086
       . Ideally iso9660_fs_stat should be fixed. */
Packit dd8086
    p_statbuf = iso9660_ifs_stat (p_iso, "/.");
Packit dd8086
Packit dd8086
    if (NULL == p_statbuf) {
Packit dd8086
      fprintf(stderr,
Packit dd8086
	      "Could not get ISO-9660 file information for file /.\n");
Packit dd8086
      iso9660_close(p_iso);
Packit dd8086
      exit(2);
Packit dd8086
    } else {
Packit dd8086
      /* Now try getting the statbuf another way */
Packit dd8086
      char buf[ISO_BLOCKSIZE];
Packit dd8086
      char *psz_path = NULL;
Packit dd8086
      const lsn_t i_lsn = p_statbuf->lsn;
Packit dd8086
      iso9660_stat_t *p_statbuf2 = iso9660_ifs_find_lsn (p_iso, i_lsn);
Packit dd8086
      iso9660_stat_t *p_statbuf3 =
Packit dd8086
	iso9660_ifs_find_lsn_with_path (p_iso, i_lsn, &psz_path);
Packit dd8086
      int rc=0;
Packit dd8086
      const unsigned int statbuf_test_size = 100;
Packit dd8086
Packit dd8086
      /* Compare the two statbufs. */
Packit dd8086
      if (p_statbuf->lsn != p_statbuf2->lsn ||
Packit dd8086
	  p_statbuf->size != p_statbuf2->size ||
Packit dd8086
	  p_statbuf->type != p_statbuf2->type) {
Packit dd8086
Packit dd8086
	  fprintf(stderr, "File stat information between fs_stat and "
Packit dd8086
		  "iso9660_ifs_find_lsn isn't the same\n");
Packit dd8086
	  printf("statbuf  lsn: %d, size: %d, type: %d\n",
Packit dd8086
		 p_statbuf->lsn, p_statbuf->size, p_statbuf->type);
Packit dd8086
	  printf("statbuf2 lsn: %d, size: %d, type: %d\n",
Packit dd8086
		 p_statbuf2->lsn, p_statbuf2->size, p_statbuf2->type);
Packit dd8086
	  rc=3;
Packit dd8086
	  goto exit;
Packit dd8086
      }
Packit dd8086
Packit dd8086
      cdio_assert(statbuf_test_size < sizeof(iso9660_stat_t));
Packit dd8086
      if (0 != memcmp(p_statbuf3, p_statbuf2, statbuf_test_size)) {
Packit dd8086
	  fprintf(stderr, "File stat information between fs_find_lsn and "
Packit dd8086
		  "fs_find_lsn_with_path isn't the same\n");
Packit dd8086
	  rc=4;
Packit dd8086
	  goto exit;
Packit dd8086
      }
Packit dd8086
Packit dd8086
      if (psz_path != NULL) {
Packit dd8086
	if (0 != strncmp("/./", psz_path, strlen("/./"))) {
Packit dd8086
	  fprintf(stderr, "Path returned for ifs_find_lsn_with_path "
Packit dd8086
		  "is not correct should be /./, is %s\n", psz_path);
Packit dd8086
	  free(psz_path);
Packit dd8086
	  rc=5;
Packit dd8086
	  goto exit;
Packit dd8086
	}
Packit dd8086
	free(psz_path);
Packit dd8086
      } else {
Packit dd8086
	fprintf(stderr, "Path returned for fs_find_lsn_with_path is NULL\n");
Packit dd8086
	free(psz_path);
Packit dd8086
	rc=6;
Packit dd8086
	goto exit;
Packit dd8086
      }
Packit dd8086
Packit dd8086
      /* Try reading from the directory. */
Packit dd8086
      memset (buf, 0, ISO_BLOCKSIZE);
Packit dd8086
      if ( ISO_BLOCKSIZE != iso9660_iso_seek_read (p_iso, buf, i_lsn, 1) )
Packit dd8086
	{
Packit dd8086
	  fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n",
Packit dd8086
		  (long unsigned int) p_statbuf->lsn);
Packit dd8086
	  rc=7;
Packit dd8086
	}
Packit dd8086
    exit:
Packit dd8086
      iso9660_stat_free(p_statbuf);
Packit dd8086
      iso9660_stat_free(p_statbuf2);
Packit dd8086
      iso9660_stat_free(p_statbuf3);
Packit dd8086
      iso9660_close(p_iso);
Packit dd8086
      exit(rc);
Packit dd8086
    }
Packit dd8086
  }
Packit dd8086
Packit dd8086
  exit(0);
Packit dd8086
}