libscsi

A Library for Direct SCSI Device Access

For version {No value for ‘VERSION’}, {No value for ‘UPDATED’}

Dieter Baron
Armin Obersteiner

Copyright © 1996 Dieter Baron and Armin Obersteiner



This is a draft edition of the libscsi documentation,
and is consistent with libscsi {No value for ‘VERSION’}.



Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 Introduction

Some applications (such as cd players and cd writers) need direct access to SCSI devices. Although most operating system provide such services, each does so in a different way; writing portable software is painfull.

One goal of libscsi is to encapsulate these system dependencies and to provide a uniform interface to the application. See section Low Level Functions.

The other is to provide convenience functions for SCSI commands, to avoid programming errors and to render programs more readable. These are grouped according to the sections of X3.131 (the ANSI standard for SCSI II) or devices for vendor specific commands.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2 Low Level Functions

Function: SCSI * sc_open (char *device)
Function: int sc_close (SCSI *sdev)

sc_close closes device sdev, deallocating all resources associated with it. sdev must not be passed to any libscsi function afterwards.

Function: int sc_send (SCSI *sdev, int direction, int cmdlen, char *cmd, int datalen, char *data)

The sc_send function sends a command to device sdev.

cmd is the command descriptor block (CDB) of the command, cmdlen its length (in bytes).

Set direction to SC_READ if data will be transferred from the device to the host in the data in phase; to SC_WRITE if data will be transferred to the device during data out phase; or to 0 if no data (besides the CDB) will be transferred.

If this is a write command (SC_WRITE), data points to datalen bytes to be transferred. If it is a read command (SC_READ), up to datalen bytes will be placed in data.

On success, sc_send return 0 for write and transferless commands and the number of bytes read on read commands. On error, -1 is returend and the error indicator and sense data in sdev are set.

Function: int sc_set_timeout (SCSI *sdev, u_long timeout)

On systems that timeout commands, sc_set_timeout is used to specify a timeout of timeout milliseconds for command completion on device sdev.

If the timeout cannot be set as specified, -1 is returned. However, if the system does not timeout commands, this function is a noop, and 0 is returned.

If the underlying system supports only one global timeout value for all devices, it is expected of the interface functions to set it appropriatly for each device before sending a command.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3 Extending libscsi

You have to create the files 'lib/xx_????.c' and 'scsi/xx.h' (or just
add prototypes to it).

  xx   - command type OR device type OR product
  ???? - command name

If you've included more commands or support for other devices please
contact us for inclusion in our distribution.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4 Porting libscsi to other platforms

To port libscsi to a new platform, you have to provide definitions for the SCSI structure and the low level functions sc_open, sc_close, sc_send, and sc_set_timeout. They should behave as documented in See section Low Level Functions. Look at the provided interfaces (scsi/os_{netbsd,amiga}.h and lib/os_{netbsd,amiga}.c) for examples.

Remove the symbolic links scsi/os.h and lib/os.c, and place your header and soruce files there.

If you want to make your interface part of the distribution, pick a name and place it in the files scsi/os_name.h and lib/os_name.c. Also, edit configure.in to recognize systems supporting your interface.

Also, send us your new interface, so we can include it in future releases.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5 Notes on the Interfaces

This section contains interface specific notes, such as the syntax and semantics of device names or constraints.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 AmigaDOS


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2 NetBSD


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Index

Jump to:   A   E   I   N   P  
Index Entry  Section

A
AmigaDOS 5.1 AmigaDOS

E
extending 3 Extending libscsi

I
interfaces 5 Notes on the Interfaces
introduction 1 Introduction

N
NetBSD 5.2 NetBSD

P
porting 4 Porting libscsi to other platforms

Jump to:   A   E   I   N   P  

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Index of Functions

Jump to:   S  
Index Entry  Section

S
sc_close 2 Low Level Functions
sc_open 2 Low Level Functions
sc_send 2 Low Level Functions
sc_set_timeout 2 Low Level Functions

Jump to:   S  

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Index of Variables and Types


[Top] [Contents] [Index] [ ? ]

Table of Contents


[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on March 28, 2025 using texi2html 5.0.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated on March 28, 2025 using texi2html 5.0.