Add APIs to the incomplete Mass Storage bootloader.
[pub/USBasp.git] / Bootloaders / Incomplete / MassStorage / Lib / VirtualFAT.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2013.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2013 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #ifndef _VIRTUALFAT_H_
32 #define _VIRTUALFAT_H_
33
34 /* Includes: */
35 #include <avr/io.h>
36 #include <avr/pgmspace.h>
37
38 #include <LUFA/Drivers/USB/USB.h>
39
40 /* Macros: */
41 #define VIRTUAL_MEMORY_BLOCK_SIZE 512
42 #define ALLOCATION_UNIT_BLOCKS 4
43 #define LUN_MEDIA_BLOCKS ((FLASHEND + 1) / VIRTUAL_MEMORY_BLOCK_SIZE) + 16
44
45 /* Type Definitions: */
46 typedef struct
47 {
48 uint8_t Bootstrap[3];
49 uint8_t Description[8];
50 uint16_t BlockSize;
51 uint8_t BlocksPerAllocationUnit;
52 uint16_t ReservedBlocks;
53 uint8_t FATCopies;
54 uint16_t RootDirectoryEntries;
55 uint16_t TotalBlocks16;
56 uint8_t MediaDescriptor;
57 uint16_t BlocksPerFAT;
58 uint16_t BlocksPerTrack;
59 uint16_t Heads;
60 uint32_t HiddenBlocks;
61 uint32_t TotalBlocks32;
62 uint16_t PhysicalDriveNum;
63 uint8_t ExtendedBootRecordSig;
64 uint32_t VolumeSerialNumber;
65 uint8_t VolumeLabel[11];
66 uint8_t FilesystemIdentifier[8];
67 uint8_t BootstrapProgram[448];
68 uint16_t MagicSignature;
69 } FATBootBlock_t;
70
71 typedef struct
72 {
73 uint8_t Filename[8];
74 uint8_t Extension[3];
75 uint8_t Attributes;
76 uint8_t Reserved[10];
77 uint16_t CreationTime;
78 uint16_t CreationDate;
79 uint16_t StartingCluster;
80 uint32_t FileSize;
81 } FATDirectoryEntry_t;
82
83 /* Function Prototypes: */
84 void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
85 const uint32_t BlockAddress,
86 uint16_t TotalBlocks);
87
88 void VirtualFAT_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
89 const uint32_t BlockAddress,
90 uint16_t TotalBlocks);
91 #endif