Logo Search packages:      
Sourcecode: makebootfat version File versions  Download package

fat.h

/*
 * This file is part of the Advance project.
 *
 * Copyright (C) 2004, 2005 Andrea Mazzoleni
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __FAT_H
#define __FAT_H

#include "disk.h"

#define FAT_CLUSTER_SIZE (SECTOR_SIZE*128)

#define FAT_TABLE_FREE 0
#define FAT_TABLE_EOC 0xFFFFFFFF
#define FAT_TABLE_BAD 0xFFFFFFF7

/**
 * FAT information.
 */
00035 struct fat_info {
00036       unsigned fat_bit; /**< Number of bit in the fat. */
00037       unsigned fat_num; /**< Number of fat table. */
00038       unsigned fat_pos; /**< Fat table position (in sectors). */
00039       unsigned fat_size; /**< Fat size (in sectors). */
00040       unsigned data_pos; /**< Data position (in sectors). */
00041       unsigned data_size; /**< Data size (in sectors). */
00042       unsigned cluster_num; /**< Number of clusters. */
00043       unsigned cluster_size; /**< Number of sectors per cluster. */
00044       unsigned root_pos; /**< Root dir position (in sectors). */
00045       unsigned root_size; /**< Root dir size (in sectors). */
};

/**
 * FAT internal context.
 */
00051 struct fat_context {
00052       struct disk_handle* h; ///< Handle of the device.
00053       unsigned h_pos; ///< Offset in the device (in sectors).
00054       unsigned h_size; ///< Size in the device (in sectors).

00056       unsigned char* table; /**< Fat table. */

00058       unsigned char tmp[FAT_CLUSTER_SIZE]; /**< Temporary data. */

00060       struct fat_info info; /**< Fat information. */

00062       struct disk_geometry geometry; /**< Disk geometry. */

00064       unsigned first_free; /**< First free cluster. */
};

00067 struct fat_boot_sector {
      unsigned char BS_JumpBoot[3];
      char BS_OemName[8];
      unsigned char BPB_BytesPerSec[2];
      unsigned char BPB_SecPerClus;
      unsigned char BPB_RsvdSecCnt[2];
      unsigned char BPB_NumFATs;
      unsigned char BPB_RootEntCnt[2];
      unsigned char BPB_TotSec16[2];
      unsigned char BPB_Media;
      unsigned char BPB_FATSz16[2];
      unsigned char BPB_SecPerTrk[2];
      unsigned char BPB_NumHeads[2];
      unsigned char BPB_HiddSec[4];
      unsigned char BPB_TotSec32[4];
      union {
            struct {
                  unsigned char BS_DrvNum;
                  unsigned char BS_Reserved1;
                  unsigned char BS_BootSig;
                  unsigned char BS_VolID[4];
                  char BS_VolLab[11];
                  char BS_FilSysType[8];
                  unsigned char BS_Code[448];
            } fat16;
            struct {
                  unsigned char BPB_FATSz32[4];
                  unsigned char BPB_ExtFlags[2];
                  unsigned char BPB_FSVer[2];
                  unsigned char BPB_RootClus[4];
                  unsigned char BPB_FSInfo[2];
                  unsigned char BPB_BkBootSec[2];
                  unsigned char BPB_Reserved[12];
                  unsigned char BS_DrvNum;
                  unsigned char BS_Reserved1;
                  unsigned char BS_BootSig;
                  unsigned char BS_VolID[4];
                  char BS_VolLab[11];
                  char BS_FilSysType[8];
                  unsigned char BS_Code[420];
            } fat32;
      } bit;
      unsigned char BS_Sign[2];
};

00112 struct fat_fsinfo {
      unsigned char FSI_LeadSig[4];
      unsigned char FSI_Reserved1[480];
      unsigned char FSI_StrucSig[4];
      unsigned char FSI_Free_Count[4];
      unsigned char FSI_Nxt_Free[4];
      unsigned char FSI_Reserved2[12];
      unsigned char FSI_TrailSig[4];
};

#define FAT_ATTRIB_READONLY 0x01 
#define FAT_ATTRIB_HIDDEN 0x02 
#define FAT_ATTRIB_SYSTEM 0x04 
#define FAT_ATTRIB_VOLUME 0x08 
#define FAT_ATTRIB_DIRECTORY 0x10
#define FAT_ATTRIB_ARCHIVE 0x20
#define FAT_ATTRIB_LONGNAME (FAT_ATTRIB_READONLY | FAT_ATTRIB_HIDDEN | FAT_ATTRIB_SYSTEM | FAT_ATTRIB_VOLUME)

#define FAT_DIRENTRY_SIZE 32

/**
 * FAT directory entry.
 */
00135 struct fat_direntry {
      char DE_Name[11];
      unsigned char DE_Attributes;
      unsigned char DE_Reserved;
      unsigned char DE_CrtTimeTenth;
      unsigned char DE_CrtTime[2];
      unsigned char DE_CrtDate[2];
      unsigned char DE_LstAccDate[2];
      unsigned char DE_ClusterH[2];
      unsigned char DE_WrtTime[2];
      unsigned char DE_WrtDate[2];
      unsigned char DE_ClusterL[2];
      unsigned char DE_FileSize[4];
};

/**
 * FAT directory entry for long names.
 */
00153 struct fat_longentry {
      unsigned char DE_Ordinal;
      unsigned char DE_Name0[2];
      unsigned char DE_Name1[2];
      unsigned char DE_Name2[2];
      unsigned char DE_Name3[2];
      unsigned char DE_Name4[2];
      unsigned char DE_Attributes;
      unsigned char DE_Reserved;
      unsigned char DE_CheckSum;
      unsigned char DE_Name5[2];
      unsigned char DE_Name6[2];
      unsigned char DE_Name7[2];
      unsigned char DE_Name8[2];
      unsigned char DE_Name9[2];
      unsigned char DE_Name10[2];
      unsigned char DE_ClusterL[2];
      unsigned char DE_Name11[2];
      unsigned char DE_Name12[2];
};

struct fat_context* fat_open(struct disk_handle* h, unsigned pos, unsigned size, const struct disk_geometry* geometry);
int fat_close(struct fat_context* fat);
int fat_format(struct fat_context* fat, unsigned size, unsigned bit, unsigned sector_per_cluster, const char* oem, const char* label, unsigned serial, const struct disk_geometry* geometry);
int fat_entry_add(struct fat_context* fat, unsigned dir_cluster, const char* file_name, unsigned file_cluster, unsigned file_size, unsigned file_attrib, time_t file_time);
int fat_cluster_dir(struct fat_context* fat, unsigned root_cluster, unsigned* cluster, time_t time);
int fat_cluster_file(struct fat_context* fat, const char* file, unsigned* cluster, unsigned* size);
int fat_cluster_chain(struct fat_context* fat, unsigned cluster, unsigned* cluster_map, unsigned cluster_max);
int fat_sector_chain(struct fat_context* fat, unsigned cluster, unsigned* sector_map, unsigned sector_max);
int fat_boot_setup(unsigned char* boot, const unsigned char* code, unsigned bit);

#endif


Generated by  Doxygen 1.6.0   Back to index