/*
    exDOS - Experimental 32 Bit protected mode scripted operating system
    (C) 2005 Jason Hunt
    
    This program 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.

    This program 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.

    Contact: nulluser@gmail.com

    File: fat12.h
*/


#ifndef FAT12_H
#define FAT12_H

#define FAT12_ERROR -1

/* Volume information for current disk */
typedef struct 
{
    word bytes_per_sect;
    byte sect_per_cluster;
    word num_reserved;
    byte num_fats;
    word max_root;
    word num_sectors;
    word sect_per_fat;
    word sect_per_track;
    word num_heads;
    dword num_hidden;
} __attribute__ ((packed)) fat12_param_type;
/* End of fat12_param */


/* Dir entry information */
typedef struct
{
    byte name[8];               // Filename, padded with spaces
    byte ext[3];                // Extention, also padded if size < 3
    byte file_attr;             // File attributes
    byte reserved1;             // Unused in fat 32
    byte fine_res;              // Fine resolution for creation time
    dword create_time;          // Creation time
    word acces_time;            // Last accessed time
    word reserved2;             // I have no idea ea-index?
    dword modified_time;        // Last modified time
    word cluster_start;         // Starting cluster
    dword file_size;            // File size
} __attribute__ ((packed)) dir_entry_type; 
/* This must be packed or it will exceed 32 bytes */


/* Filesystem base type */
typedef struct
{
    fat12_param_type param;  // Data from the bios param block
    word data_start;         // Starting LBA of data
    byte *root_dir;          // The root directory
    byte *fat;               // The entire FAT
    byte *cur_dir;           // Current directory data
} fat12_type;
/* End of fat12_type */




/* File attribute flags */
#define FAT12_READ_ONLY 	0x01 
#define FAT12_HIDDEN  	        0x02 	
#define FAT12_SYSTEM           	0x04 
#define FAT12_VOLUME_LABEL	0x08 
#define FAT12_SUB_DIRECTORY  	0x10 
#define FAT12_ARCHIVE    	0x20 


/* these are used internally */
void fat12_read_fat( fat12_type *fs );
void fat12_read_root( fat12_type *fs );
void fat12_read_param( fat12_type *filesystem );
void fat12_dump_file(fat12_type *fs, char *filename);
void fat12_list_dir( fat12_type *fs, char * param );
dir_entry_type* fat12_locate_object(fat12_type *fs, char *obname);
byte * fat12_read_file(fat12_type *fs, dir_entry_type *dir_entry);


/* these workon and allocatte the current filesystem */

void fat12_mount( void );
void fat12_unmount( void );
int fat12_cat(byte *filename);
void fat12_ls( char *param );
void fat12_cd( char *param);

#endif












