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

//----------------------------------------------------------------------
//      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.
//
// ENUMS:
//  ErrorCodeType
// CLASSES:
//  Error
//  
//----------------------------------------------------------------------
// $Source: /projects/HMS/nsr/udfCore/sys/nsrError.h,v $
// $Revision: 1.70 $    $Author: hmgr $
// $State: Exp $        $Locker:  $
// $Date: 96/06/27 02:58:26 $

//----------------------------------------------------------------------
// ENUM: ErrorCodeType
//
//  These are the enums which are used to set and test errors. See
//  Error class. 
//
// DEFINITIONS:
//  error_None   - This is set to zero, so that automatic casting to
//                 INT16 will work properly, allowing the optional
//                 simpler syntax to be used:
//
//                 Complex Form             Simple Form
//                 -----------------------  -----------
//                 (errCode != error_None)  (errCode)
//                 (errCode == error_None)  (!errCode)
//
// USES:
//  These are THE way to set and test the values in the Error class.
//
// NOTES:
//  See Error class.
//
//----------------------------------------------------------------------
enum ErrorCodeType {

    error_None                          = 0,
    error_No_free_store                 = 1,
    error_Bad_ICB_table                 = 2,
    error_Bad_volume_label              = 3,
    error_Bad_tag_checksum              = 4,
    error_Bad_tag_location              = 5,
    error_Bad_tag_descriptor_version    = 6,
    error_Bad_descr_CRC                 = 7,
    error_Bad_tag_descriptor_type       = 8,
    error_UnrecognizedIUVolDesc         = 9,

    error_Unknown_path_component        = 10,
    error_Empty_path_element            = 11,
    error_Drive_read                    = 12,
    error_Drive_write                   = 13,
    error_Drive_load                    = 14,
    error_Invalid_LBN                   = 15,
    error_Invalid_sector                = 16,
    error_Invalid_volume                = 17,
    error_Wrong_volume_set              = 18,
    error_Directory_not_found           = 19,

    error_File_not_found                = 20,
    error_Not_root_volume               = 21,
    error_Name_not_unique               = 22,
    error_No_free_space                 = 23,
    error_Directory_dirty               = 24,
    error_Missing_volume                = 25,
    error_Invalid_function              = 26,
    error_End_of_ICB_table              = 27,
    error_End_of_directory              = 28,
    error_Index_out_of_bounds           = 29,

    error_Volume_set_integrity_open     = 30,
    error_Volume_set_integrity_closed   = 31,
    error_Improper_file_type            = 32,
    error_Invalid_extentlist            = 33,
    error_Invalid_pathelementlist       = 34,

    error_Non_UDF_volume_set            = 40,
    error_UDF_volume_set_not_supported  = 41,
    error_VDS_mirror_bad                = 42,
    error_Empty_volume_set              = 43,
    error_Bad_volume_recog_sequence     = 44,
    error_No_room_in_VDS                = 45,

    error_Invalid_ICB_table             = 50,
    error_Wrong_FSDS_extent_length      = 51,
    error_End_of_Sequence_space         = 52,
    error_End_of_buffer                 = 53,
    error_Unexpected_EA_icb             = 54,

    error_Null_pointer                  = 60,
    error_Root_EA_FileEntry_full        = 61,
    error_Root_not_found                = 62,
    error_Invalid_labelLimit            = 63,
    error_Invalid_number_of_volumes     = 64,
    error_Protected_logical_volume      = 65,
    error_Cant_change_hard_writeProtect = 66,
    error_WORM_file_sets_not_protected  = 67,
    error_Protected_file_set            = 68,
    error_File_set_not_found            = 69,

    error_Wrong_block_size_in_LVD       = 70,
    error_Too_many_file_sets            = 71,
    error_Cant_overwrite_file_set       = 72,
    error_Wrong_sector_size             = 73,
    error_Wrong_media_type              = 74,
    error_Volume_already_labeled        = 75,
    error_Volume_not_labeled            = 76,
    error_Duplicate_volume_number       = 77,

    error_Invalid_function_for_media    = 80,
    error_Invalid_parameter_for_media   = 81,
    error_Invalid_surface_id            = 82,

    error_FileEntry_full                = 90,
    error_AllocExtentDesc_full          = 91,
    error_UnallocatedSpaceEntry_full    = 92,
    error_Required_object_not_present   = 93,
        
#ifdef NSR_VERIFY
    error_VerifyTag                     = 100,
    error_VerifyIUVD                    = 101,
    error_VerifyAVD                     = 102,
    error_VerifyPVD                     = 103,
    error_VerifyPD                      = 104,
    error_VerifyLVD                     = 105,
    error_VerifyUSD                     = 106,
    error_VerifyFSD                     = 107,
    error_VerifyLVID                    = 108,
    error_VerifyFE                      = 109,

    error_VerifyAED                     = 110,
    error_VerifyIE                      = 111,
    error_VerifyTE                      = 112,
    error_VerifyFID                     = 113,
    error_VerifyUSE                     = 114,
    error_VerifySBD                     = 115,
    error_VerifyPC                      = 116,
    error_VerifyEAHD                    = 117,

// ISO EAs
    error_VerifyFileTimesEA             = 118,

// UDF EAs
    error_VerifyFreeEASpaceEA           = 120,

// UDF / OS/2
    error_VerifyOS2EA                   = 121,
    error_VerifyOS2EALengthEA           = 122,

// UDF / Mac
    error_VerifyMacVolumeInfoEA         = 125,
    error_VerifyMacDirFinderInfoEA      = 126,
    error_VerifyMacFileFinderInfoEA     = 127,
    error_VerifyMacUniqueIDTableEA      = 128,
    error_VerifyMacResourceForkEA       = 129,

// HP EAs
// HP / Novell    
    error_VerifyNovellAttrEA            = 130,
    error_VerifyNovellTrusteeEA         = 132,
// HP / Archive
    error_VerifyICBTableEA              = 140,
#endif

// Error codes for bad input parameters
    error_Bad_Parameter_Extent          = 150,
    error_Bad_Parameter_Extent_List     = 151,
    error_Bad_Parameter_EA_List         = 152,
    error_Bad_Parameter_Byte_Array      = 153,
    error_Bad_Parameter_File_Entry      = 154,
    error_Bad_Parameter_ADTable         = 155,
    error_Bad_Parameter_Space_Resource  = 156,
    error_Bad_Parameter_EASpace         = 157,
   
// Error codes for invalid SSVolume objects
    error_DriveDevice_invalid           = 200,
    error_PhysicalVolume_invalid        = 201,
    error_Partition_invalid             = 202,
    error_LogicalVolume_invalid         = 203,
    error_FileSet_invalid               = 204,

// nsrExt
    error_PE_beyond_physical_volume     = 250,
    error_LE_beyond_partition           = 251,
    error_InfoLen_illegal               = 252,
    error_Invalid_write_length          = 253,
    error_Cant_write_imaginary_extent   = 254,
    error_Cant_grow_null_extent         = 255,

// nsrDir 
    error_DIR_Bad_dir_extent_type       = 300,
    error_DIR_Parent_and_not_dir        = 301,
    error_DIR_null_DirEntry             = 302,

// nsrNode
    error_NODE_Bad_AD_type_in_icbtag          = 350,
    error_NODE_InfoLen_mismatch               = 351,
    error_NODE_LogBlocksRecorded_mismatch     = 352,
    error_NODE_State_Violation                = 353,
    error_NODE_AED_Read_Failure               = 354,
    error_NODE_Bad_Continuation_Extent        = 355,

    error_NODE_EmbeddedEASpace_Not_Multiple_4 = 356,
    error_NODE_Embedded_Data_Set              = 357,
    error_NODE_ADs_Set                        = 358,
    error_NODE_No_Unique_ID                   = 359,
    error_NODE_Descriptor_Overflow            = 360,

    error_EANODE_EANodeAddr_Set               = 375,
    error_EANODE_Embedded_EASpace_Set         = 376,
    error_EANODE_Linkcount_Set                = 377,

// SSVol
    error_SSVOL_Desc_too_long                 = 400,
    error_SSVOL_Illegal_desc_in_VDS           = 401,
    error_SSVOL_No_LVD_before_PD_yet          = 402,
    error_SSVOL_No_multiple_VDS_extents_yet   = 403,
    error_SSVOL_Unknown_desc_in_VDS           = 404,
    error_SSVOL_No_disk_initialization_yet    = 405,
    
// Partition    
    error_PART_Both_space_bitmap_and_table    = 500,
    error_PART_Mixed_space_tables_and_bitmaps = 501,
    error_PART_No_extent_for_SpaceResource    = 502,

// SpaceResource
    error_SR_No_Bitmap_support_yet            = 600,
    error_SR_Feature_not_implemented          = 601,
    error_SR_Incorrect_logical_volume         = 602,
    error_SR_Incompatible_extent_type         = 603,  
    error_SR_Extent_from_wrong_logVolume      = 604,
    error_SR_Cannot_mix_space_types           = 605,
    error_SR_has_no_descriptor_space          = 606,
    error_SR_Debug_code                       = 607,
    error_SR_Bad_partition                    = 608,
    error_SR_Bad_volume                       = 609,
    error_SR_Bad_descriptor                   = 610,
    error_SR_Bad_type                         = 611,
    error_SR_Bitmap_read                      = 612,
    error_SR_Bitmap_write                     = 613,
    error_SR_Bitmap_corrupt                   = 614,
    error_SR_Insufficient_space               = 615,
    error_SR_Page_overrun                     = 616,
    error_SR_Bad_extent_length                = 617,
    error_SR_Bitmap_too_large                 = 618,
    error_SR_Incomplete                       = 619,
    error_SR_Bad_extent                       = 620,
    error_SR_Cannot_free_space                = 621,
    error_SR_No_valid_space_resource          = 622,

// ExtendedAttributes
    error_EA_Bad_file_times_type                = 700,
    error_EA_No_imaginary_SmallADs              = 701,
    error_EA_Not_found                          = 702,
    error_EA_Unknown_EA_type                    = 703,
    error_EA_Invalid_EA_type                    = 704,
    error_EA_Invalid_EA_subtype                 = 705,
    error_EA_Invalid_EA_length                  = 706,
    error_EA_Bad_checksum                       = 707,
    error_EA_Invalid_EA_in_src_LEL              = 708,
    error_EA_Invalid_EA_in_src_BA               = 709,
    error_EA_Invalid_multiple_occurences_of_EA  = 710,
    error_EA_Invalid_EA_placement               = 711,
    error_EA_Invalid_empty_EA_list              = 712,
    error_EA_Invalid_EA_ordering                = 713,
    error_EA_Invalid_EA_padding                 = 714,
    error_EA_Invalid_offset_in_EA_header        = 715,
    error_EA_Invalid_call                       = 716,
    
// Extended Attribute Registry
    error_REGISTRY_Invalid_key                  = 750,
    error_REGISTRY_Duplicate_key                = 751,
    error_REGISTRY_Entry_not_found              = 752,
    
#ifdef TRUSTEES
// Trustees
    error_TrusteeRename_invalid      = 800,
    error_TrusteeCreate_fail         = 801,
    error_TrusteeWrite_fail          = 802,
    error_TrusteeAlloc_fail          = 803,
    error_TrusteeOpen_fail           = 804,
    error_TrusteeRead_fail           = 805,
    error_TrusteeTerm_fail           = 806,
    error_TrusteeSeqErr              = 807,
    error_TrusteeDirOpen_fail        = 808,
#endif // TRUSTEES

// DriveDevice

    error_Capacity_failed            = 900,
    error_Drive_blank_check          = 901,
    error_Read_EOM                   = 902,
    error_Read_EOLM                  = 903,
    error_Write_EOM                  = 904,
    error_Write_EOLM                 = 905,
    error_Erase_failed               = 906,
    error_Bad_erase_size             = 907,
    error_Set_verify_failed          = 908,

// hpACDevice

    error_Elt_addresses_failed       = 1000,
    error_Element_status_failed      = 1001,
    error_Transport_element_full     = 1002,
    error_Invalid_sid                = 1003,
    error_Drive_not_available        = 1004,
    error_Move_failed                = 1005,
    error_Exchange_failed            = 1006,
    error_Argument_not_found         = 1007,
    error_Slot_empty                 = 1008,
    error_Passthru_ioctl_failed      = 1009,

    error_Cant_make_disk_device_file = 1010,
    error_Surface_in_use             = 1011,
    error_Autochanger_not_ready      = 1012,
    error_Autochanger_not_supported  = 1013,
    error_All_drives_spared          = 1014,

    // The following section is reserved for 3rd party applications

#ifdef _THIRD_PARTY_ERROR_CODES_

    error_Null_acrc_file             = 10000,
    error_Cannot_access_acrc_file    = 10001,
    error_Syntax_error_in_acrc_file  = 10002,
    error_Cannot_stat_acrc_file      = 10003,
    error_Bad_AC_device_file         = 10004,
    error_Null_status_file           = 10005,
    error_Cannot_access_status_file  = 10006,
    error_Status_file_syntax_error   = 10007,
    error_Invalid_surface            = 10008,
    error_Null_volume_set_name       = 10009,
 
    error_Name_not_found             = 10011,
    error_No_working_volume_set      = 10012,
    error_No_free_volume             = 10013,
    error_Unknown_fileset_name       = 10014,
    error_Null_volume_name           = 10015,
    error_Invalid_operation          = 10016,
    error_No_freespace_information   = 10017,

#endif  // _THIRD_PARTY_ERROR_CODES_

    // This absolutely must be the last entry in this table !!!!!
    // It acts like a sentinal in the algorithm to find the error message.
    error_Unknown
};

struct errorTableItem {
    enum ErrorCodeType error;
    CONST_CHAR_PTR errorMessage;
};

//----------------------------------------------------------------------
// CLASS: Error                         --JD,DVM,AP
//
//  This is the container for ALL error information.
//
//  This should be treated just like an Enum, so that it allows
//  assignment into it from an ErrorCodeType, as well as a casting
//  operator back to an ErrorCodeType. The benefit of this class is
//  that it also supports a message() method. Thus, all coding is done
//  as though it is an Enum, and yet it may be printed out in Ascii
//  form at will.
//
// PUBLIC METHODS:
//  Error()      (inline) - Constructor from ErrorCodeType.
//                          Default is error_None.
//  operator=()  (inline) - Assigns from ErrorCodeType.
//  operator==() (inline) - Compares with ErrorCodeType.
//  message()             - Returns a CHAR_PTR for error message
//  Casting operators:
//   INT32()         (inline) - Only needed by G++.
//   ErrorCodeType() (inline) - Enough for most compilers
//
// USAGE NOTES:
//  Cast to INT32 allows very simple testing for any error and no
//  error. See notes for ErrorCodeType enum.
// 
//----------------------------------------------------------------------
// COLLABORATORS:  
//  ErrorCodeType  (enum)
//  errorTableItem (struct)
//
// IMPLEMENTATION NOTES:
//  Internal Notes go here (special cases, algorithm issues, etc.)
//
//----------------------------------------------------------------------
class Error {

    ErrorCodeType           errorCode;

public:

    Error( const ErrorCodeType ec = error_None ) : errorCode( ec ) {}

    Error &operator=( const ErrorCodeType ec ) { 
        errorCode=ec; 
        return *this; 
    }

    operator ErrorCodeType() const { return errorCode; }

    Boolean operator==( const ErrorCodeType ec ) const { 
        return (errorCode==ec) ? True : False; 
    }

    Boolean operator!=( const ErrorCodeType ec ) const { 
        return (errorCode==ec) ? False : True; 
    }

#if defined _COMPILER_BUG_ERROR_TO_INT_CAST_
    // See config/nsrCfg.h for documentation of this compiler
    // workaround.
    // Since error_None is equal to 0, this conversion is trivial.
    operator int() const { return ( (int)((ErrorCodeType) errorCode)); }
#endif

    CONST_CHAR_PTR message() const;
};

#endif  /* NSRERROR */


