/* Copyright (C) 2004 Stefan Bellon <sbellon@sbellon.de>
 *
 * This file is part of RemotePrinterFS.
 *
 * RemotePrinterFS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * RemotePrinterFS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#ifndef __VENEERS_H__
#define __VENEERS_H__

#include <kernel.h>

typedef int YesNoAnswer;
#define No (0)
#define Yes (!No)

typedef int FileSwitchHandle;
typedef int FileSystemHandle;

typedef union Information_Fields
{
    struct
    {
        char            *load_address;
        char            *execute_address;
    } load_exec;
    struct
    {
        int             part_1;
        int             part_2;
    } date_type;
} Information_Fields;

typedef enum FSEntry_Open_Reason
{
    FSEntry_Open_Reason_OpenRead = 0,
    FSEntry_Open_Reason_CreateUpdate = 1,
    FSEntry_Open_Reason_Update = 2
} FSEntry_Open_Reason;

#define InformationWord_WritePermitted              0x80000000
#define InformationWord_ReadPermitted               0x40000000
#define InformationWord_ObjectIsDirectory           0x20000000
#define InformationWord_UnbufferedOS_GBPBSupported  0x10000000
#define InformationWord_StreamIsInteractive         0x08000000

typedef union FSEntry_Open_Parameter
{
    struct open_definition
    {
        FSEntry_Open_Reason     reason;
        char                    *filename;
        int                     padding_1;
        FileSwitchHandle        handle;
        int                     padding_4;
        int                     padding_5;
        char                    *special_field;
    } open_definition;
    struct open_result
    {
        unsigned int            information_word;
        FileSystemHandle        handle;
        int                     buffer_size;
        int                     file_extent;
        int                     allocated_space;
    } open_result;
} FSEntry_Open_Parameter;
typedef _kernel_oserror *(FSEntry_Open_Function)(FSEntry_Open_Parameter *);

typedef union FSEntry_GetBytes_Parameter
{
    struct
    {
        int                 filler;
        FileSystemHandle    handle;
        char                *destination_start;
        int                 bytes_to_read;
        int                 file_offset_to_get_data_from;
    } getbytes_definition;
    struct
    {
        char                byte_got;
        char                filler_1;
        char                filler_2;
        char                filler_3;
        YesNoAnswer         got_the_byte;
    } getbytes_result;
} FSEntry_GetBytes_Parameter;
typedef _kernel_oserror *(FSEntry_GetBytes_Function)(FSEntry_GetBytes_Parameter *);

typedef struct FSEntry_PutBytes_Parameter
{
    char                byte_to_put;
    char                filler_1;
    char                filler_2;
    char                filler_3;
    FileSystemHandle    handle;
    char                *source_start;
    int                 bytes_to_write;
    int                 file_offset_to_put_data_to;
} FSEntry_PutBytes_Parameter;
typedef _kernel_oserror *(FSEntry_PutBytes_Function)(FSEntry_PutBytes_Parameter *);

typedef enum FSEntry_Args_Reason
{
    FSEntry_Args_Reason_ReadSequentialFilePointer = 0,
    FSEntry_Args_Reason_WriteSequentialFilePointer = 1,
    FSEntry_Args_Reason_ReadFileExtent = 2,
    FSEntry_Args_Reason_WriteFileExtent = 3,
    FSEntry_Args_Reason_ReadSizeAllocatedToFile = 4,
    FSEntry_Args_Reason_EOFCheck = 5,
    FSEntry_Args_Reason_FlushFileBuffer = 6,
    FSEntry_Args_Reason_EnsureFileSize = 7,
    FSEntry_Args_Reason_WriteZerosToFile = 8,
    FSEntry_Args_Reason_ReadFileDateStamp = 9
} FSEntry_Args_Reason;

typedef struct FSEntry_Args_Parameter
{
    FSEntry_Args_Reason     reason;
    FileSystemHandle        handle;
    union
    {
        int                 sequential_pointer;
        int                 extent;
        int                 allocation_size;
        YesNoAnswer         EOF_Has_Been_Reached;
        Information_Fields  info;
        struct
        {
            int             start;
            int             number;
        } write_zeros;
    } arg;
} FSEntry_Args_Parameter;
typedef _kernel_oserror *(FSEntry_Args_Function)(FSEntry_Args_Parameter *);

typedef struct FSEntry_Close_Parameter
{
    int                 padding;
    FileSystemHandle    handle;
    Information_Fields  info;
} FSEntry_Close_Parameter;
typedef _kernel_oserror *(FSEntry_Close_Function)(FSEntry_Close_Parameter *);

typedef enum FSEntry_File_Reason
{
    FSEntry_File_Reason_LoadFile = 0xff,
    FSEntry_File_Reason_SaveFile = 0,
    FSEntry_File_Reason_WriteCatalogueInformation = 1,
    FSEntry_File_Reason_WriteLoadAddress = 2,
    FSEntry_File_Reason_WriteExecutionAddress = 3,
    FSEntry_File_Reason_WriteAttributes = 4,
    FSEntry_File_Reason_ReadCatalogueInformation = 5,
    FSEntry_File_Reason_DeleteObject = 6,
    FSEntry_File_Reason_CreateFile = 7,
    FSEntry_File_Reason_CreateDirectory = 8,
    FSEntry_File_Reason_ReadCatalogueInformationNoLength = 9
} FSEntry_File_Reason;

typedef struct FSEntry_File_Parameter
{
    FSEntry_File_Reason reason;
    char                *name;
    Information_Fields  info;
    union
    {
        struct
        {
            int         length;
            int         attributes;
        } info;
        struct
        {
            char        *start;
            char        *end;
        } location;
    } extras;
    char                *special_field;
} FSEntry_File_Parameter;
typedef _kernel_oserror *(FSEntry_File_Function)(FSEntry_File_Parameter *);

typedef enum FSEntry_Func_Reason
{
    FSEntry_Func_Reason_SetCurrentDirectory = 0,
    FSEntry_Func_Reason_SetLibraryDirectory = 1,
    FSEntry_Func_Reason_CatalogueDirectory = 2,
    FSEntry_Func_Reason_ExamineCurrentDirectory = 3,
    FSEntry_Func_Reason_CatalogueLibraryDirectory = 4,
    FSEntry_Func_Reason_ExamineLibraryDirectory = 5,
    FSEntry_Func_Reason_ExamineObjects = 6,
    FSEntry_Func_Reason_SetFilingSystemOptions = 7,
    FSEntry_Func_Reason_RenameObject = 8,
    FSEntry_Func_Reason_AccessObjects = 9,
    FSEntry_Func_Reason_BootFilingSystem = 10,
    FSEntry_Func_Reason_ReadNameAndBootOptionOfDisc = 11,
    FSEntry_Func_Reason_ReadCurrentDirectoryNameAndPrivilegeByte = 12,
    FSEntry_Func_Reason_ReadLibraryDirectoryNameAndPrivilegeByte = 13,
    FSEntry_Func_Reason_ReadDirectoryEntries = 14,
    FSEntry_Func_Reason_ReadDirectoriesAndInformation = 15,
    FSEntry_Func_Reason_ShutDown = 16,
    FSEntry_Func_Reason_PrintStartUpBanner = 17,
    FSEntry_Func_Reason_SetDirectoryContexts = 18,
    FSEntry_Func_Reason_ReadDirectoryEntriesAndInformation = 19,
    FSEntry_Func_Reason_OutputFullInformationOnObjects = 20
} FSEntry_Func_Reason;

typedef struct FSEntry_Func_Parameter
{
    FSEntry_Func_Reason     reason;
    union
    {
        char                *name_1;
        FileSystemHandle    csd;
        YesNoAnswer         rename_invalid;
    } first_parameter;
    union
    {
        char                *name_2;
        int                 parameter;
        char                *access_string;
        char                *destination_address;
        FileSystemHandle    urd;
    } second_parameter;
    union
    {
        int                 read_number;
        FileSystemHandle    library;
    } third_parameter;
    int                     read_offset;
    int                     buffer_length;
    char                    *special_field_1;
    char                    *special_field_2;
} FSEntry_Func_Parameter;
typedef _kernel_oserror *(FSEntry_Func_Function)(FSEntry_Func_Parameter *);

typedef enum FSEntry_GBPB_Reason
{
    FSEntry_GBPB_Reason_PutMultipleBytesHere = 1,
    FSEntry_GBPB_Reason_PutMultipleBytes = 2,
    FSEntry_GBPB_Reason_GetMultipleBytesHere = 3,
    FSEntry_GBPB_Reason_GetMultipleBytes = 4
} FSEntry_GBPB_Reason;

typedef struct FSEntry_GBPB_Paratemer
{
    FSEntry_GBPB_Reason reason;
    FileSystemHandle    handle;
    char                *address;
    int                 number;
    int                 sequential_file_pointer;
} FSEntry_GBPB_Parameter;
typedef _kernel_oserror *(FSEntry_GBPB_Function)(FSEntry_GBPB_Parameter *);

#endif
