Repetier-Firmware  0.91
src/ArduinoAVR/Repetier/FatStructs.h
Go to the documentation of this file.
00001 /* Arduino SdFat Library
00002  * Copyright (C) 2009 by William Greiman
00003  *
00004  * This file is part of the Arduino SdFat Library
00005  *
00006  * This Library is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with the Arduino SdFat Library.  If not, see
00018  * <http://www.gnu.org/licenses/>.
00019  */
00020 #ifndef FatStructs_h
00021 #define FatStructs_h
00022 
00026 /*
00027  * mostly from Microsoft document fatgen103.doc
00028  * http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
00029  */
00030 //------------------------------------------------------------------------------
00032 uint8_t const BOOTSIG0 = 0X55;
00034 uint8_t const BOOTSIG1 = 0XAA;
00035 //------------------------------------------------------------------------------
00043 struct partitionTable {
00049   uint8_t  boot;
00054   uint8_t  beginHead;
00059   unsigned beginSector : 6;
00061   unsigned beginCylinderHigh : 2;
00066   uint8_t  beginCylinderLow;
00071   uint8_t  type;
00076   uint8_t  endHead;
00081   unsigned endSector : 6;
00083   unsigned endCylinderHigh : 2;
00088   uint8_t  endCylinderLow;
00090   uint32_t firstSector;
00092   uint32_t totalSectors;
00093 };
00095 typedef struct partitionTable part_t;
00096 //------------------------------------------------------------------------------
00104 struct masterBootRecord {
00106   uint8_t  codeArea[440];
00108   uint32_t diskSignature;
00110   uint16_t usuallyZero;
00112   part_t   part[4];
00114   uint8_t  mbrSig0;
00116   uint8_t  mbrSig1;
00117 };
00119 typedef struct masterBootRecord mbr_t;
00120 //------------------------------------------------------------------------------
00128 struct biosParmBlock {
00133   uint16_t bytesPerSector;
00139   uint8_t  sectorsPerCluster;
00144   uint16_t reservedSectorCount;
00148   uint8_t  fatCount;
00157   uint16_t rootDirEntryCount;
00167   uint16_t totalSectors16;
00174   uint8_t  mediaType;
00180   uint16_t sectorsPerFat16;
00182   uint16_t sectorsPerTrtack;
00184   uint16_t headCount;
00190   uint32_t hidddenSectors;
00197   uint32_t totalSectors32;
00201   uint32_t sectorsPerFat32;
00212   uint16_t fat32Flags;
00217   uint16_t fat32Version;
00222   uint32_t fat32RootCluster;
00227   uint16_t fat32FSInfo;
00233   uint16_t fat32BackBootBlock;
00238   uint8_t  fat32Reserved[12];
00239 };
00241 typedef struct biosParmBlock bpb_t;
00242 //------------------------------------------------------------------------------
00249 struct fat32BootSector {
00251   uint8_t  jmpToBootCode[3];
00253   char     oemName[8];
00255   bpb_t    bpb;
00257   uint8_t  driveNumber;
00259   uint8_t  reserved1;
00261   uint8_t  bootSignature;
00263   uint32_t volumeSerialNumber;
00265   char     volumeLabel[11];
00267   char     fileSystemType[8];
00269   uint8_t  bootCode[420];
00271   uint8_t  bootSectorSig0;
00273   uint8_t  bootSectorSig1;
00274 };
00275 //------------------------------------------------------------------------------
00276 // End Of Chain values for FAT entries
00278 uint16_t const FAT16EOC = 0XFFFF;
00280 uint16_t const FAT16EOC_MIN = 0XFFF8;
00282 uint32_t const FAT32EOC = 0X0FFFFFFF;
00284 uint32_t const FAT32EOC_MIN = 0X0FFFFFF8;
00286 uint32_t const FAT32MASK = 0X0FFFFFFF;
00287 
00289 typedef struct fat32BootSector fbs_t;
00290 //------------------------------------------------------------------------------
00321 struct directoryEntry {
00327   uint8_t  name[11];
00334   uint8_t  attributes;
00339   uint8_t  reservedNT;
00345   uint8_t  creationTimeTenths;
00347   uint16_t creationTime;
00349   uint16_t creationDate;
00355   uint16_t lastAccessDate;
00360   uint16_t firstClusterHigh;
00362   uint16_t lastWriteTime;
00364   uint16_t lastWriteDate;
00366   uint16_t firstClusterLow;
00368   uint32_t fileSize;
00369 };
00370 //------------------------------------------------------------------------------
00371 // Definitions for directory entries
00372 //
00374 typedef struct directoryEntry dir_t;
00376 uint8_t const DIR_NAME_0XE5 = 0X05;
00378 uint8_t const DIR_NAME_DELETED = 0XE5;
00380 uint8_t const DIR_NAME_FREE = 0X00;
00382 uint8_t const DIR_ATT_READ_ONLY = 0X01;
00384 uint8_t const DIR_ATT_HIDDEN = 0X02;
00386 uint8_t const DIR_ATT_SYSTEM = 0X04;
00388 uint8_t const DIR_ATT_VOLUME_ID = 0X08;
00390 uint8_t const DIR_ATT_DIRECTORY = 0X10;
00392 uint8_t const DIR_ATT_ARCHIVE = 0X20;
00395 uint8_t const DIR_ATT_LONG_NAME = 0X0F;
00397 uint8_t const DIR_ATT_LONG_NAME_MASK = 0X3F;
00399 uint8_t const DIR_ATT_DEFINED_BITS = 0X3F;
00401 static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
00402   return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
00403 }
00405 uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);
00407 static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
00408   return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
00409 }
00411 static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
00412   return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
00413 }
00415 static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
00416   return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
00417 }
00418 #endif  // FatStructs_h
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Defines