#ifndef _HPREALSSDEV_    //-*-c++-*-
#define _HPREALSSDEV_

#include <nsrLib.h>
#include <nsrscsi.h>
#include <fcntl.h>
#include <unistd.h>

//----------------------------------------------------------------------
//  nsrRSSdv.h
//   This is the definition of the Real SS device class.
//
//      Unpublished Confidential Information of Hewlett-Packard
//      Company. Do not disclose.  Copyright (c) Hewlett-Packard
//      Company 1995. All rights reserved
// 
// The contents of this software are proprietary and confidential to
// the Hewlett- Packard Company, and are limited in distribution to
// those with a direct need to know.  Individuals having access to
// this software are responsible for maintaining the confidentiality
// of the content and for keeping the software secure when not in use.
// Transfer to any party is strictly forbidden other than as expressly
// permitted in writing by Hewlett-Packard Company.  Unauthorized
// transfer to or possession by any unauthorized party may be a
// criminal offense.
//
//                  RESTRICTED RIGHTS LEGEND
//
//      Use,  duplication,  or disclosure by the U. S. Government is
//      subject to restrictions as set forth in subparagraph (c) (1)
//      (ii) in the Rights in Technical Data and Computer Software
//      clause in DFARS 252.227-7013 or any other successor clause.
//
//                      HEWLETT-PACKARD COMPANY
//                      3000 Hanover St.
//                      Palo Alto, CA  94304 U.S.A.
//
//      Rights for non-DOD U.S. Government Departments and Agencies
//      are as set forth in FAR 52.227-19 (c) (1,2) or any other
//      successor clause.
//
//  CLASSES:
//   DriveDevice
//  
//----------------------------------------------------------------------
// $Source: /projects/HMS/nsr/udfCore/devs/nsrRSSdv.h,v $
// $Revision: 1.13 $    $Author: hmgr $
// $State: Exp $        $Locker:  $
// $Date: 96/05/07 16:13:28 $
//

//----------------------------------------------------------------------
// CLASS: DriveDevice     --JKH
//
//  The DriveDevice class handles the low-level details for reading
//  and writing sectors to and from a disk device.
//
//  This class is NOT in the NSR scope!
//
// PUBLIC METHODS:
//
//   DriveDevice()   - Constructor.  Takes device file pathname as
//                     argument. 
//   ~DriveDevice()  - Destructor.  Closes device.
//   numSectors()    - Returns the number of sectors on the device.
//   sectorSize()    - Returns the size, in bytes, of a sector on the
//                     device.
//   read()          - Read bytes into argument ByteArray from the
//                     given ExtentList. 
//   write()         - Write bytes from argument ByteArray into the
//                     given ExtentList. 
//   writeWOE()      - As write, but does a write-without-erase.
//   verifyMode()    - Setter: puts DriveDevice in write-with-verify
//                     mode. 
//   verifyMode()    - Getter: returns write-with-verify mode flag.
//   erase()         - Erases the sectors specified by the given
//                     PhysExtent. 
//   checkValidity() - Returns whether the DriveDevice is in a valid
//                     state. 
//   error()         - Returns the error state of the DriveDevice
//                     object. 
//
// USAGE NOTES:
//  none yet.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  none.
//
// PRIVATE METHODS:
//  isBlankCheck() - checks for blank
//  setWWOE()      - sets Write without erase
//  setVMode()     - sets verify mode
//
// IMPLEMENTATION NOTES:
//  none here.
//
//----------------------------------------------------------------------

class DriveDevice : public NSR::SSDevice 
{

protected:

    NSR::INT32          fd_;            // File descriptor for drive device
    NSR::ErrorCodeType  dderror_;       // Error state
    NSR::UINT32         sectorSize_;    // Size of a sector in bytes
    NSR::UINT32         numSectors_;    // Number of sectors in device
    NSR::INT32          verifyMode_;    // If non-zero, use write-with-verify

    NSR::Boolean        isBlankCheck(void);
    void                setWWOE(NSR::INT32 which);
    NSR::INT32          setVMode(NSR::INT32 which);

public:

                        DriveDevice(const NSR::String& devfile);        
    virtual             ~DriveDevice();                 
    virtual NSR::UINT32 numSectors() const { return numSectors_; }
    virtual NSR::UINT32 sectorSize() const { return sectorSize_; }
    virtual NSR::INT32  read(NSR::UINT32 startsector,NSR::UINT32 nsectors,
                             const NSR::ByteArrayRef& arr,NSR::Error& err);
    virtual NSR::INT32  read(NSR::UINT32 startsector,NSR::UINT32 nbytes,
                             NSR::BYTE_PTR buf,NSR::Error& err);
    virtual NSR::INT32  write(NSR::UINT32 startsector,NSR::UINT32 nsectors,
                              const NSR::ByteArrayRef& arr,NSR::Error& err);
    virtual NSR::INT32  write(NSR::UINT32 startsector,NSR::UINT32 nbytes,
                              NSR::CONST_BYTE_PTR buf,NSR::Error& err);
    virtual NSR::INT32  writeWOE(NSR::UINT32 startsector,NSR::UINT32 nsectors,
                                 const NSR::ByteArrayRef& arr,NSR::Error& err);
    virtual NSR::INT32  writeWOE(NSR::UINT32 startsector,NSR::UINT32 nbytes,
                                 NSR::CONST_BYTE_PTR buf,NSR::Error& err);
    virtual NSR::INT32  verifyMode(NSR::INT32 newmode) {
                            NSR::INT32 oldmode = verifyMode_;
                            verifyMode_ = (newmode ? 1 : 0);
                            return oldmode;
                        }
    virtual NSR::INT32  verifyMode(void) {
                            return verifyMode_;
                        }
    virtual NSR::INT32  erase(NSR::UINT32 start,NSR::UINT32 nsectors,
                              NSR::Error& err);
    virtual NSR::Error  error(void) const;
    virtual NSR::Error  checkValidity(void) const;
    virtual NSR::MediaType      mediaType(void);
    virtual NSR::Boolean        verifyBlank(NSR::UINT32 start,
                                            NSR::UINT32 nsectors,
                                            NSR::UINT32 *where);
};

#endif // _HPREALSSDEV_
