File: PORTING

package info (click to toggle)
xmcd 2.2p1-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,960 kB
  • ctags: 6,832
  • sloc: ansic: 39,709; makefile: 4,580; sh: 2,724; pascal: 104
file content (542 lines) | stat: -rw-r--r-- 20,555 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
#
# @(#)PORTING	6.17 97/06/02
#
# xmcd  - Motif(tm) CD Audio Player
# cda   - Command-line CD Audio Player
# libdi - CD Audio Player Device Interface Library
# cddb  - CD Database Management Library
#
# by Ti Kan
#

Porting Information
-------------------


INTRODUCTION

A truly portable application should compile and run without modification
on different OS and hardware platforms.  Any CD Audio player software,
especially under UNIX, is typically not easily portable.  This is because
of the two following reasons:

    1. The CD player software is not merely an application.  It is
       also a device driver of sorts, since it controls the CD-ROM
       drive.  Different OS variants provide different means of
       interfacing with the CD-ROM drives.

    2. Although there is an increasing number of CD-ROM drives
       that implement the audio-related commands as documented
       in the SCSI-2 specifications, many non-SCSI-2 conformant
       CD-ROM drives exist, and support audio operations only
       via incompatible vendor-unique commands.  Moreover, there
       are detail differences between "SCSI-2 compliant" drives
       that must be taken into account in order to use them
       effectively.  A similar situation exists for IDE/ATAPI
       drives.  Finally, there are a number of non-SCSI CD-ROM
       drives that operate via proprietary controller boards.

Xmcd and cda strives to be as portable as possible by taking the
following design approach:

    1. For xmcd, harness the inherent portability advantages of the
       X Window System, and the increasing popularity of the
       OSF/Motif GUI.  The X Window System gives us device-independent
       graphics and network-extensibility, and Motif is rapidly becoming
       the de facto standard UNIX GUI, and will soon be supported
       on virtually every vendor's port of UNIX as well as UNIX-like
       operating systems.

    2. For both xmcd and cda, minimize the use of non-portable
       OS-specific features where possible.

    3. Strict adherence to ANSI C standards.

    4. Modularize the internals architecture, such that the user
       interface portion, the OS-interface portion, and the CD-ROM
       vendor-unique support portions are each a separate and
       replaceable entity.

    5. The OS-specific and device-specific portions are made as small
       and self-contained as possible, so that changes to support
       a new OS or new CD-ROM drive are not scattered about.

Currently xmcd/cda already supports a wide array of CD-ROM drives
and OS environments.  You are welcome to help expand that support,
as others have done.  If you would like to add support of additional
CD-ROM devices, port xmcd/cda to run on another OS, or to add other
enhancements to xmcd/cda, the internal architecture overview below
should prove to be beneficial.

Xmcd and cda currently contain code that assumes POSIX-compliant
UNIX C library and headers.  Examples of these are:

	- Uses "struct dirent" rather than "struct direct"
	- Assumes existence of types such as "uid_t" and "mode_t".
	- etc...

Also, cda assumes a System V compatible curses library implementation
for its visual mode support.  Most systems today (even non-SYSV
platforms) supply a compatible library (e.g., ncurses).  If the OS
you're porting to does not support such a library, you can specify
-DNOVISUAL in the cda_d/Imakefile to exclude cda's visual mode
code.

Please note that this application is released as free software under
the GNU General Public License agreement, except the portion under
the libdi_d subdirectory; which are under the GNU Library General
Public License.  These license agreements guarantees your right
to modify it for yourself and others (please see the misc_d/COPYING
and misc_d/COPYING.LIB files for details).  I do ask, however, that
if you add new functionality or port it to a new platform, please
send all changes to me so I can merge it into the main source code
and include it in the next release.  All proper credit will be given,
of course, in the form of copyright notices in the source file banners.
This avoids diverging versions and makes your enhancements accessible
to more people.



XMCD/CDA ARCHITECTURE

Xmcd and cda are divided into four main subsystems, the Application
Code Subsystem, the CD Database Management Subsystem, the Device Interface
Subsystem and the Utility Routines Subsystem (These are hereafter referred
to as ACS, CDDB, LIBDI and LIBUTIL, respectively).

The diagram below shows the general xmcd/cda architecture, and
identifies where the various libraries (Motif, Xt, X11, socket,
curses and the C library) interface with the main xmcd/cda bodies
of code.


			General Internal Architecture
			-----------------------------

                              User Interface
  +-------------------------------------------------------------------------+
  |                                                                         |
  |                 Motif (xmcd only) / curses (cda only)                   |
  |                                                                         |
  |   +----------------+----------------------------------------------------+
  |   |  Xt            |                                                    |
  |   |  Intrinsics    |     Xmcd/cda Application Code Subsystem (ACS)      |
  |   |  (xmcd only)   |                                                    |
  |   | +--------------+                                                    |
  |   | |  X11         |                                                    |
  |   | |  (xmcd only) |                                                    |
  |   | |              |                                                    |
  |   | | +------------+----------+-----------+-----------+                 |
  |   | | | socket/nsl |          |           |           |                 |
  |   | | |            | CD       | Device    | Utility   |                 |
  |   | | |            | Database | Interface | Functions |                 |
  |   | | |            | Mgmt     | Subsystem | (LIBUTIL) |                 |
  |   | | |            | (CDDB)   | (LIBDI)   |           |                 |
  |   | | |            |          |           |           |                 |
  +---+-+-+------------+----------+-----------+-----------+-----------------+
  |                                                                         |
  |                  C Library / System Calls                               |
  |                                                                         |
  +-------------------------------------------------------------------------+
                                OS Kernel



The ACS is the layer that deals with the user interface.  In xmcd, it
mostly uses Motif for that purpose.  It provides the look-and-feel of the
application and manages all user events.  All calls and other references
to the Motif and X window system are restricted to this module only.

The CDDB module contains support for CD database management functions.

The LIBDI module interfaces the application code to the operating
system environment and hardware.

The LIBDI can be hardware and OS dependent.  The interface from the
ACS layer to the LIBDI is very high-level, consisting of function
calls like di_play_pause(), di_stop(), di_rew(), di_ff(),
and so on (see libdi.h for the full list).  This gives the LIBDI a lot
of flexibility in how to implement the actual functionalities.
Furthermore, the LIBDI physically resides in a library archive.
Although it is currently linked into xmcd statically, if the need
arises it can be modified to be dynamically bound.

LIBDI also relies on service routines in the ACS and LIBUTIL to carry
out its functionality.  The ACS provides those functions that
that cause changes on the user interface (display popup messages,
change widget state, etc.), and LIBUTIL provides general service
routines (perform byte-swapping, BCD to integer conversion, etc).
This layer is hardware platform and OS independent and should require
virtually no modifications to port to other environments.

The LIBDI module that is supplied with this distribution implements
several methods of controlling a CD-ROM drive:

	0. SCSI pass-through method (SCSIPT)
	1. SunOS/Solaris/Linux/QNX ioctl method (SLIOC)
	2. FreeBSD ioctl method (FBIOC)
	3. IBM AIX IDE ioctl method (AIXIOC)

Some of these methods can coexist in a given xmcd/cda binary.
The actual method used is determined at run time via the
deviceInterfaceMethod parameter, which is configured in the
XMCDLIB/config/device.cfg file.  The entry points into LIBDI
is the same regardless of the method used.  A LIBDI internal jump
table (array of di_tbl_t) is used to select the appropriate method
function for each CD audio operation.



		   SCSI Pass-through Method LIBDI Detail
		   -------------------------------------

                 +----------------- LIBDI ----------------+
                 |                                        |
                 |     Generic SCSI Pass-through          |
                 |     Module (SCSIPT)                    |
                 |                                        |
                 |   +-----------------+------------------+
                 |   |                 |                  |
                 |   | OS Interface    | CD-ROM           |
                 |   | Module          | Vendor-unique    |
                 |   | (OS_XXX)        | Modules (VU_XXX) |
                 |   |                 |                  |
                 +---+-----------------+------------------+


SCSI PASS-THROUGH METHOD

The SCSI pass-through method module supplied is a conglomerate of
a Generic SCSI pass-through sub-module (SCSIPT), an OS Interface
sub-module (OS_XXX), and several Vendor-unique sub-modules (VU_XXX).
These are illustrated in the diagram below.  This method module
implements all the non-user-interface aspects of CD audio
functionality and operates the CD-ROM drive by delivering SCSI
commands directly to the CD-ROM drive via a kernel-supported SCSI
pass-through interface.

This distribution supplies several OS_XXX sub-modules, each
supporting a different operating system platform; as well as a
"demo" sub-module that provides a demo environment, but does not
actually operate a real CD-ROM drive (a CD-ROM simulator is invoked
instead, mimicking the behavior of a SCSI-2 CD-ROM drive).  Several
VU_XXX sub-modules for Chinon, Hitachi, NEC, Pioneer, Sony and
Toshiba CD-ROM drives are also supplied.  Only one OS Interface
sub-module can be compiled in at a time (controlled by pre-processor
directives), but multiple vendor-unique sub-modules can coexist.

The SCSIPT sub-module contains all the basic non-OS-dependent code
that implements delivering SCSI commands to a CD-ROM drive.  It
relies on the next layer, the OS_XXX sub-module, to actually perform
the SCSI command delivery.  The SCSIPT sub-module "knows" about the
SCSI-2 set of audio-related commands, and sends these down to the
OS_XXX layer.  Which SCSI-2 commands to send are user-configurable
via device-dependent configuration files.  This is important because
many CD-ROM drives support some, but not all of the SCSI-2 audio
commands.  Alternatively, if so configured, the SCSI Pass-through
module can call the VU_XXX sub-module to deliver non-SCSI-2
vendor-unique commands to the CD-ROM drive.

All entry points to the OS_XXX module are named in the form of
pthru_xxx().  See below.

The most important OS_XXX sub-module entry point is pthru_send(),
which is used by the SCSIPT and VU_XXX sub-modules to deliver SCSI
commands to the drive.  pthru_send() takes a number of arguments
that are used to construct a SCSI CDB, among other things.  The
SCSI CDB is actually allocated and filled in the OS_XXX sub-module,
and delivered using the appropriate SCSI pass-through mechanism.



		   OS-specific Ioctl Methods LIBDI Detail
		   --------------------------------------

                 +----------------- LIBDI ----------------+
                 |                                        |
                 |                                        |
                 |       OS-specific Ioctl Method         |
                 |       (FBIOC, SLIOC, etc.)             |
                 |                                        |
                 |                                        |
                 |                                        |
                 |                                        |
                 |                                        |
                 |                                        |
                 +----------------------------------------+


SUNOS/SOLARIS/LINUX/QNX IOCTL METHOD

The SunOS/Solaris/Linux/QNX ioctl method is intended primarily for use
on Linux and SunOS/Solaris platforms which are equipped with non-SCSI
CD-ROM drives operating via an ATAPI interface or a proprietary
interface card.  Although this method will also work with many SCSI
CD-ROM drives on the Linux, SunOS 4.1.x (Solaris 1.x) and SunOS 5.x
(Solaris 2.x) platforms, it offers less features than the SCSI
pass-through method and is thus not recommended for SCSI drives.  For
the QNX platform, this method should be used for all drive types
because the SCSI pass-through method is not available.

The SunOS/Solaris/Linux/QNX ioctl method can also serve as a reference
when porting xmcd/cda to an OS platform that does not support a SCSI
pass-through interface.

The SunOS/Solaris/Linux/QNX ioctl method module has similar high-level
operating code as the SCSI pass-through method, except it is monolithic
and does not have sub-modules.  It operates the CD-ROM audio functions
via ioctl interfaces to the CD-ROM device driver.



FREEBSD IOCTL METHOD

The FreeBSD ioctl method is intended primarily for use on FreeBSD
platforms which are equipped with non-SCSI CD-ROM drives operating via
an ATAPI interface or a proprietary interface card.  Although this
method will also work with many SCSI-2 drives on the FreeBSD platforms,
it offers less features than the SCSI pass-through method and is thus
not recommended for SCSI drives.

The FreeBSD ioctl method can also serve as a reference when porting
xmcd/cda to an OS platform that does not support a SCSI pass-through
interface.

The FreeBSD ioctl method module has similar high-level operating code
as the SCSI pass-through method, except it is monolithic and does not
have sub-modules.  It operates the CD-ROM audio functions via ioctl
interfaces to the CD-ROM device driver.



AIX IDE IOCTL METHOD

The AIX IDE ioctl method is intended primarily for use on IBM AIX 4.x
platforms which are equipped with IDE CD-ROM drives.

The AIX IDE ioctl method can also serve as a reference when porting
xmcd/cda to an OS platform that does not support a SCSI pass-through
interface.

The AIX IDE ioctl method module has similar high-level operating code
as the SCSI pass-through method, except it is monolithic and does not
have sub-modules.  It operates the CD-ROM audio functions via ioctl
interfaces to the CD-ROM device driver.



XMCD/CDA SOURCE CODE FILES

The following is a list of the files in the xmcd/cda source code
distribution and the category they fall under:

General Release files:
	CHANGES
	FAQ
	INSTALL
	INSTALL.VMS
	PORTING
	README
	Imakefile
	Makefile.std
	Makevms.com
	install.sh
	make.inc
	makedgux.inc

LIBUTIL and other common files:
	common_d/Imakefile
	common_d/Makefile.std
	common_d/Makevms.com
	common_d/appenv.h
	common_d/patchlevel.h
	common_d/util.c
	common_d/util.h

CDDB files:
	cddb_d/Imakefile
	cddb_d/Makefile.std
	cddb_d/Makevms.com
	cddb_d/cddb.c
	cddb_d/cddb.h

LIBDI files:
	libdi_d/Imakefile
	libdi_d/Makefile.std
	libdi_d/Makevms.com
	libdi_d/libdi.c
	libdi_d/libdi.h
	libdi_d/config.sh
	libdi_d/common.cfg
	libdi_d/device.cfg
	libdi_d/cfgtbl/XXX

	SCSI pass-through method files:
		libdi_d/scsipt.c
		libdi_d/scsipt.h
		libdi_d/os_XXX.c
		libdi_d/os_XXX.h
		libdi_d/vu_XXX.c
		libdi_d/vu_XXX.h

	SunOS/Solaris/Linux/QNX ioctl method files:
		libdi_d/slioc.c
		libdi_d/slioc.h

	FreeBSD ioctl method files:
		libdi_d/fbioc.c
		libdi_d/fbioc.h

	AIX IDE ioctl method files:
		libdi_d/aixioc.c
		libdi_d/aixioc.h

ACS for cda:
	cda_d/Imakefile
	cda_d/Makefile.std
	cda_d/cda.c
	cda_d/cda.h
	cda_d/visual.c
	cda_d/visual.h
	cda_d/cda.man

ACS for xmcd:
	xmcd_d/Imakefile
	xmcd_d/Makefile.std
	xmcd_d/Makevms.com
	xmcd_d/XKeysymDB
	xmcd_d/XMcd.ad
	xmcd_d/cdfunc.c
	xmcd_d/cdfunc.h
	xmcd_d/dbprog.c
	xmcd_d/dbprog.h
	xmcd_d/geom.c
	xmcd_d/geom.h
	xmcd_d/help.c
	xmcd_d/help.h
	xmcd_d/hotkey.c
	xmcd_d/hotkey.h
	xmcd_d/main.c
	xmcd_d/resource.h
	xmcd_d/widget.c
	xmcd_d/widget.h
	xmcd_d/xmcd.h
	xmcd_d/xmcd.man
	xmcd_d/bitmaps/*
	xmcd_d/hlpfiles/*

Miscellaneous utilities and files:
	misc_d/COPYING
	misc_d/COPYING.LIB
	misc_d/BINLIST
	misc_d/SRCLIST
	misc_d/makerel.sh
	misc_d/makeshar.sh
	misc_d/makesrc.sh
	misc_d/demo.db
	misc_d/xmcd.icon
	misc_d/xmcd.xpm
	misc_d/xmcd_a.px
	misc_d/xmcd_b.px

CD database format converter utility:
	dbconv_d/Imakefile
	dbconv_d/Makefile.std
	dbconv_d/wm2xmcd.c
	dbconv_d/wm2xmcd.man



PORTING HINTS

To port xmcd/cda to a different OS, two alternatives can be
considered:

1. Use the existing SCSI pass-through method, but write a new
   OS_XXX sub-module.
2. Write a whole new method module.

The first choice is the obvious answer if the target OS supports a
SCSI pass-through interface.  This choice is also quite easy to
implement, as the OS_XXX sub-module is typically fairly small
and self-contained.  The existing OS_XXX sub-modules can be used
as a reference when writing a new one.  In the current implementation,
each SCSI pass-through OS_XXX sub-module must contains these four
routines:

	pthru_send()
	pthru_open()
	pthru_close()
	pthru_vers()

The second choice is feasible if the platform does not supply a
SCSI pass-through mechanism, or if non-SCSI drives are to be used.
If this is the approach taken, the OS-specific ioctl method modules
can be used as a reference, and much of its code can be copied,
modified and re-used.

If you are writing an SCSI pass-through OS_XXX sub-module, keep in
mind that you will need to deal with any special DMA address
alignment limitations present in your OS and/or hardware.  The I/O
data buffers allocated within the existing SCSI pass-through method
are guaranteed to be 32-bit word-aligned, but if your OS/hardware
has different requirements (such as page-alignment) then you will
need to deal with this in the OS interface sub-module.

For maximum portability, please use the bswapxx() and lswapxx()
routines provided in util.c (#include "common_d/util.h") to
perform byte swapping, whenever multi-byte quantities (that must
be interpreted as a value) are being transferred between the CD-ROM
drive and the host.  This is necessary because multi-byte
quantities in SCSI commands and data is in general big-endian,
but xmcd/cda is designed to run on host CPUs that are big-endian
or little-endian.  The swap routines should be used regarless of
whether your main CPU endianess matches that of the SCSI device.
Whether swapping actually takes place is controlled via the
_BYTE_ORDER_ #define (see common_d/appenv.h).

There are also some minor OS-specific code you need to add in
config.sh.  This is mainly to set up the correct default device
node path name and mailer program.



ADDING SUPPORT OF NON-SCSI-2 CD-ROMS

To support additional SCSI (not SCSI-2) CD-ROM drives via vendor-
unique pass-through commands, you will need to add a VU_XXX sub-module
to the SCSI pass-through method.  Each VU_XXX sub-module can implement
some or all of the following routines (where xx is the name of the
VU_XXX module):

	xx_playaudio()
	xx_pause_resume()
	xx_start_stop()
	xx_get_playstatus()
	xx_volume()
	xx_route()
	xx_mute()
	xx_get_toc()
	xx_eject()
	xx_start()
	xx_halt()

These routines, if implemented, is then registered in the xx_init()
routine by filling in the appropriate vu_tbl_t array entry (see
scsipt.[ch] and the existing VU_XXX sub-modules for examples).

Depending upon the operating mode of xmcd, vendor-unique functionality
is invoked from the scsipt.c module via the vu_tbl_t jump table.

You will also need to add a vendor-unique configuration file entry 
to the libdi_d/cfgtbl subdirectory.



QUESTIONS?

If you are working on enhancing xmcd/cda and need information, help
or advice, please send e-mail to me at "xmcd@amb.org".  Likewise,
suggestions are also very welcome.