File: hardware.c

package info (click to toggle)
cdtool 2.1.4-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 156 kB
  • ctags: 105
  • sloc: ansic: 1,210; makefile: 135; sh: 99
file content (105 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download
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
98
99
100
101
102
103
104
105
/* "hardware.c" copyright 1994 thomas insel 
 *              copyrighy 1995 sven oliver moll */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pwd.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>

#ifdef sun
#  include <sundev/srreg.h>
#elif defined linux
#  include <linux/cdrom.h>
#else
#  errror Please fix includes for your system in hardware.c
#endif

#include "config.h"
#include "database.h"
#include "hardware.h"

/* WWH hack to get rid of malloc/free's */
#ifdef CDCTRL
cdhw_t strHW;
#endif

cdhw_t *
read_hw(char *progname, int cdfile)
{
  int i;
#ifdef CDCTRL
  cdhw_t *hw = &strHW;
#else
  cdhw_t *hw = malloc(sizeof(cdhw_t));
#endif

#ifdef DEBUG
  fprintf (stderr, "read_hw buffer=%ld\n", (void *)hw);
#endif

  /* read header */
  if ( ioctl(cdfile, CDROMREADTOCHDR, &(hw->tochdr)) == -1 ) 
    {
      fprintf(stderr, "%s: ioctl cdromreadtochdr\n", progname);
#ifdef CDCTRL
      hw->subchnl.cdsc_audiostatus = CDROM_AUDIO_ERROR;
      return (hw);
#else
      EXIT(1);
#endif
    }

  /* read individual tracks */
  for (i=hw->tochdr.cdth_trk0-1; i<=hw->tochdr.cdth_trk1; i++) 
    {
      hw->tocentries[i].cdte_track=
	(i==hw->tochdr.cdth_trk1) ? CDROM_LEADOUT : i+1;
      
      hw->tocentries[i].cdte_format = CDROM_MSF;
      if ( ioctl(cdfile, CDROMREADTOCENTRY, &(hw->tocentries[i])) == -1 )
	{
	  fprintf(stderr, "%s: ioctl cdromreadtocentry\n", progname);
#ifdef CDCTRL
	  hw->subchnl.cdsc_audiostatus = CDROM_AUDIO_ERROR;
	  return (hw);
#else
	  EXIT(1);
#endif
        }
    }

  /* read subchannel info */
  hw->subchnl.cdsc_format = CDROM_MSF;
  if ( ioctl(cdfile, CDROMSUBCHNL, &(hw->subchnl)) == -1 ) 
    {
      fprintf(stderr, "%s: ioctl cdromsubchnl\n", progname);
#ifdef CDCTRL
      hw->subchnl.cdsc_audiostatus = CDROM_AUDIO_ERROR;
      return (hw);
#else
      EXIT(1);
#endif
    }

  return hw;

}

void free_hw_buf(cdhw_t *pHw)
{

#ifdef DEBUG
    fprintf (stderr,"free_hw_buf:  bufp=0x%lx\n", (char *)pHw);
#endif

#ifndef CDCTRL

    if ((void *)pHw != NULL)
	free ((void *)pHw);
#endif
}