~ubuntu-branches/ubuntu/edgy/libcdio/edgy-updates

« back to all changes in this revision

Viewing changes to example/scsi-mmc1.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-11-15 16:53:23 UTC
  • mfrom: (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20051115165323-peroku75syl2j36u
Tags: 0.76-1ubuntu1
* Sync to new Debian version, manually apply Ubuntu patches:
  - debian/control: Remove dpkg-awk build dependency.
  - debian/rules: hardcode $LIBCDEV. This keeps the diff small (compared to
    the original patch of changing every ${libcdev} occurence).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  $Id: scsi-mmc1.c,v 1.2 2004/11/13 20:38:41 rocky Exp $
3
 
 
4
 
  Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
5
 
  
6
 
  This program is free software; you can redistribute it and/or modify
7
 
  it under the terms of the GNU General Public License as published by
8
 
  the Free Software Foundation; either version 2 of the License, or
9
 
  (at your option) any later version.
10
 
  
11
 
  This program is distributed in the hope that it will be useful,
12
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
  GNU General Public License for more details.
15
 
  
16
 
  You should have received a copy of the GNU General Public License
17
 
  along with this program; if not, write to the Free Software
18
 
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
*/
20
 
 
21
 
/* Simple program to show use of SCSI MMC interface. Is basically the
22
 
   the libdio scsi_mmc_get_hwinfo() routine.
23
 
*/
24
 
#ifdef HAVE_CONFIG_H
25
 
# include "config.h"
26
 
#endif
27
 
#include <stdio.h>
28
 
#include <sys/types.h>
29
 
#include <cdio/cdio.h>
30
 
#include <cdio/scsi_mmc.h>
31
 
#include <string.h>
32
 
 
33
 
/* Set how long do wto wait for SCSI-MMC commands to complete */
34
 
#define DEFAULT_TIMEOUT_MS 10000
35
 
 
36
 
int
37
 
main(int argc, const char *argv[])
38
 
{
39
 
  CdIo *p_cdio;
40
 
 
41
 
  p_cdio = cdio_open (NULL, DRIVER_UNKNOWN);
42
 
 
43
 
  if (NULL == p_cdio) {
44
 
    printf("Couldn't find CD\n");
45
 
    return 1;
46
 
  } else {
47
 
    int i_status;                  /* Result of SCSI MMC command */
48
 
    char buf[36] = { 0, };         /* Place to hold returned data */
49
 
    scsi_mmc_cdb_t cdb = {{0, }};  /* Command Descriptor Block */
50
 
 
51
 
    CDIO_MMC_SET_COMMAND(cdb.field, CDIO_MMC_GPCMD_INQUIRY);
52
 
    cdb.field[4] = sizeof(buf);
53
 
 
54
 
    i_status = scsi_mmc_run_cmd(p_cdio, DEFAULT_TIMEOUT_MS, 
55
 
                                &cdb, SCSI_MMC_DATA_READ, 
56
 
                                sizeof(buf), &buf);
57
 
    if (i_status == 0) {
58
 
      char psz_vendor[CDIO_MMC_HW_VENDOR_LEN+1];
59
 
      char psz_model[CDIO_MMC_HW_MODEL_LEN+1];
60
 
      char psz_rev[CDIO_MMC_HW_REVISION_LEN+1];
61
 
      
62
 
      memcpy(psz_vendor, buf + 8, sizeof(psz_vendor)-1);
63
 
      psz_vendor[sizeof(psz_vendor)-1] = '\0';
64
 
      memcpy(psz_model,
65
 
             buf + 8 + CDIO_MMC_HW_VENDOR_LEN, 
66
 
             sizeof(psz_model)-1);
67
 
      psz_model[sizeof(psz_model)-1] = '\0';
68
 
      memcpy(psz_rev,
69
 
             buf + 8 + CDIO_MMC_HW_VENDOR_LEN +CDIO_MMC_HW_MODEL_LEN,
70
 
             sizeof(psz_rev)-1);
71
 
      psz_rev[sizeof(psz_rev)-1] = '\0';
72
 
 
73
 
      printf("Vendor: %s\nModel: %s\nRevision: %s\n",
74
 
             psz_vendor, psz_model, psz_rev);
75
 
    } else {
76
 
      printf("Couldn't get INQUIRY data (vendor, model, and revision).\n");
77
 
    }
78
 
  }
79
 
  
80
 
  cdio_destroy(p_cdio);
81
 
  
82
 
  return 0;
83
 
}