File: testimage.c

package info (click to toggle)
vcdimager 0.7.23-4
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 4,232 kB
  • ctags: 1,864
  • sloc: ansic: 18,143; sh: 9,372; xml: 317; makefile: 288
file content (97 lines) | stat: -rw-r--r-- 2,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
    $Id: testimage.c,v 1.3 2005/02/02 00:37:38 rocky Exp $

    Copyright (C) 2001, 2005 Herbert Valerio Riedel <hvr@gnu.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <cdio/cdio.h>

/* Public headers */
#include <libvcd/logging.h>

/* Private headers */
#include "vcd_assert.h"
#include "util.h"


int
main (int argc, const char *argv[])
{
  CdIo_t *img = NULL;
  lsn_t lsn = 0;

  vcd_assert (argc == 4);

  if (!strcmp ("nrg", argv[1]))
    img = cdio_open_nrg (argv[2]);
  else if (!strcmp ("bincue", argv[1]))
    img = cdio_open_bincue (argv[2]) /* src, NULL, false) */; 
  else if (!strcmp ("cd", argv[1]))
    img = cdio_open_cd (argv[2]) /* argv[2]) */;
  else 
    vcd_error ("unrecognized img type");

  vcd_assert (img != NULL);

  {
    uint32_t n = cdio_stat_size (img);
    char buf[M2RAW_SECTOR_SIZE];
    lsn = atoi (argv[3]);

    vcd_debug ("size = %lu", (unsigned long int) n);

    vcd_debug ("reading sector %lu to testimage.out", (unsigned long int) lsn);
    
    if (!cdio_read_mode2_sector (img, buf, lsn, true))
      {
	struct m2f2sector
	{
	  uint8_t subheader[8];
	  uint8_t data[2324];
	  uint8_t spare[4];
	}
	*_sect = (void *) buf;
	FILE *fd;

	vcd_debug ("fn = %d, cn = %d, sm = 0x%x, ci = 0x%x",
		   _sect->subheader[0],
		   _sect->subheader[1],
		   _sect->subheader[2],
		   _sect->subheader[3]);

	fd = fopen ("testimage.out", "wb");
	fwrite (buf, sizeof (buf), 1, fd);
	fclose (fd);

	/* vcd_assert_not_reached (); */
      }
    else
      vcd_error ("failed...");

    
  }

  return 0;
}