Develop and Download Open Source Software

Browse CVS Repository

Contents of /enbanfukusyaya/EnbanFukusyaYa/DriveAccess/scan.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download) (as text)
Fri Nov 5 17:24:03 2010 UTC (13 years, 5 months ago) by bananajinn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +5 -5 lines
File MIME type: text/x-csrc
*** empty log message ***

1 /*
2 * @file scan.c
3 * @brief 装置検索
4 * @author BananaJinn
5 * @version $Id: scan.c,v 1.14 2010/01/17 09:26:25 bananajinn Exp $
6 * 円盤複写屋
7 * Copyright (C) 2004-2006 BananaJinn<banana@mxh.mesh.ne.jp>.
8 */
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12
13 #include "mem.h"
14 #include "aspi.h"
15 #include "cmd.h"
16 #include "scan.h"
17 #include "log.h"
18
19
20 #define MAX_SCAN 16*6
21
22 #if !defined(MACOSX)
23 static BOOL IsWriterDrive(CMDDRIVE *drive)
24 {
25 int ret;
26 struct _MODEPAGE2A *mp2a;
27
28 ret = SendModeSense(drive, MSPC_CURRENT, 0x2a);
29 if(ret!=RET_OK)
30 return FALSE;
31 mp2a = (struct _MODEPAGE2A *)
32 (drive->data_buf + (drive->cmd_type==CMDDRVCTYPE_ATAPI ? 8:16));
33 DebugLog("CDR:%d CDRW:%d DVDR:%d\n",
34 mp2a->cd_r_write,
35 mp2a->cd_rw_write,
36 mp2a->dvd_r_write);
37 if(mp2a->cd_r_write || mp2a->cd_rw_write || mp2a->dvd_r_write)
38 return TRUE;
39
40 /* GetConfig.も見ないとダメかも */
41 return FALSE;
42 }
43 #endif
44
45
46 SCAN_t *ScanDrive(BOOL bWriter)
47 {
48 #if !defined(MACOSX)
49 const BYTE inqcmd[12]={CMD_INQUIRY, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0};
50 DWORD timeout=0;
51 BYTE device_type;
52 int ret;
53 #endif
54 int num_drive=0;
55 int hid, tid, max_hid, max_tid;
56 SCAN_t *drives;
57 CMDDRIVE drive;
58
59 drives = (SCAN_t *)MemNew(sizeof(SCAN_t)*MAX_SCAN);
60
61 #if defined(WIN32) || defined(linux)
62 max_hid = GetHostAdapterCount();
63 max_tid = GetMaxTarget();
64 #else
65 /* MacOSX */
66 max_hid = 1;
67 max_tid = GetDriveCount();
68 #endif
69
70 memset(&drive, 0, sizeof(CMDDRIVE));
71 InitializeCmdDrive(&drive, 0x10000, 0, CMDDRVTYPE_DRIVE);
72
73 for(hid=0; hid<max_hid; hid++){
74 for(tid=0; tid<max_tid; tid++){
75 if(num_drive>=MAX_SCAN-1){
76 break;
77 }
78 DebugLog("[%d:%d]\n", hid, tid);
79 #ifdef MACOSX
80 if(GetInquiryString(tid, drive.data_buf, drive.bufsize)){
81 continue;
82 }
83 sprintf(drives[num_drive].inqdata, "[%d:%d] ", hid, tid);
84 strcpy(drives[num_drive].inqdata+strlen(drives[num_drive].inqdata),
85 drive.data_buf);
86 #else
87 DebugLog("[%d:%d] SetAspiSetting Start\n", hid, tid);
88 if(SetDriveAspiSetting(&drive, &hid, &tid, &timeout)!=RET_OK){
89 DebugLog("[%d:%d] select error\n", hid, tid);
90 continue;
91 }
92 DebugLog("[%d:%d] SetAspiSetting End\n", hid, tid);
93 # ifdef WIN32
94 if(CheckDiscDevice(&drive.u.drive)==0){
95 DebugLog("[%d:%d] not a disc device\n", hid, tid);
96 continue;
97 }
98 # endif
99 memset(drive.data_buf, 0, 96*2);
100 ret = SendCmd(&drive, (BYTE *)inqcmd, 96, REQ_DATAIN);
101 if(ret!=RET_OK){
102 /*DebugLog("[%d:%d] inquiry command error(%d:%d)\n", hid, tid, ret, drive.srb->SRB_Status);*/
103 continue;
104 }
105 #if 0
106 if(!memcmp(drive.data_buf, drive.data_buf+96, 96)){
107 DebugLog("[%d:%d] no inquiry data\n", hid, tid);
108 continue;
109 }
110 /* 何かデータを受信していればOKとする */
111 #endif
112 device_type = drive.data_buf[0]&0x1f;
113 if(device_type!=4 && device_type!=5){
114 DebugLog("[%d:%d] device=%d\n", hid, tid, device_type);
115 continue;
116 }
117 #if defined(WIN32)
118 if(UsingSPTI())
119 sprintf(drives[num_drive].inqdata, "[%c:] ", tid+'C');
120 else
121 #endif
122 sprintf((char *)drives[num_drive].inqdata, "[%d:%d] ", hid, tid);
123 drives[num_drive].inqdata[strlen((char *)drives[num_drive].inqdata)+40]='\0';
124 strncpy((char *)drives[num_drive].inqdata+strlen((char *)drives[num_drive].inqdata),
125 (char *)drive.data_buf+8, 40);
126 #endif
127 drives[num_drive].hid = hid;
128 drives[num_drive].tid = tid;
129 DebugLog("[%d:%d] %s OK\n", hid, tid, drives[num_drive].inqdata);
130 if(bWriter){
131 #ifdef MACOSX
132 if(MMCIsWriterDrive(tid, drive.data_buf, drive.bufsize)==FALSE){
133 continue;
134 }
135 #else
136 if(IsWriterDrive(&drive)==FALSE){
137 continue;
138 }
139 #endif
140 }
141 num_drive++;
142 }
143 }
144
145 drives[num_drive].inqdata[0] = '\0';
146
147 FreeCmdDrive(&drive);
148 return drives;
149 }
150

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26