src/bm_usb/fat_directory_entry.h
/*
* Copyright (c) 2013, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_FAT_DIRECTORY_ENTRY_H_)
#define _FAT_DIRECTORY_ENTRY_H_
#include "bootloader_common.h"
#include <wchar.h>
// Definitions
enum _fat_directory_attributes
{
kReadOnlyAttribute = 0x01,
kHiddenAttribute = 0x02,
kSystemAttribute = 0x04,
kVolumeIdAttribute = 0x08,
kDirectoryAttribute = 0x10,
kArchiveAttribute = 0x20,
kLongNameAttribute = kReadOnlyAttribute | kHiddenAttribute | kSystemAttribute | kVolumeIdAttribute,
kLastLongNameEntry = 0x40,
kFreeEntryMarkerByte = 0xe5
};
#pragma pack(push)
#pragma pack(1)
typedef union FatDirectoryEntry
{
struct
{
uint8_t name[11];
uint8_t attributes;
uint8_t ntReserved;
uint8_t creationTimeTenths;
uint16_t creationTime;
uint16_t creationDate;
uint16_t lastAccessDate;
uint16_t firstClusterHigh;
uint16_t writeTime;
uint16_t writeDate;
uint16_t firstClusterLow;
uint32_t fileSize;
} entry;
struct
{
uint8_t order;
wchar_t name1[5];
uint8_t attributes;
uint8_t entryType;
uint8_t checksum;
wchar_t name2[6];
uint16_t firstClusterLow;
wchar_t name3[2];
} longName;
} fat_directory_entry_t;
#pragma pack(pop)
#define MAKE_FAT_VOLUME_LABEL(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, t, d) \
{ \
.entry = { \
.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
.attributes = kVolumeIdAttribute, \
.writeTime = (t), \
.writeDate = (d), \
} \
}
#define MAKE_FAT_DIR_ENTRY(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, a, t, d, cluster, s) \
{ \
.entry = {.name = { (c1), (c2), (c3), (c4), (c5), (c6), (c7), (c8), (c9), (c10), (c11) }, \
.attributes = (a), \
.creationTime = (t), \
.creationDate = (d), \
.lastAccessDate = (d), \
.writeTime = (t), \
.writeDate = (d), \
.firstClusterLow = (cluster), \
.fileSize = (s) } \
}
#define MAKE_FAT_LONG_NAME(o, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, k, l) \
{ \
.longName = {.order = (o) | (l), \
.name1 = { (c1), (c2), (c3), (c4), (c5) }, \
.attributes = kLongNameAttribute, \
.checksum = (k), \
.name2 = { (c6), (c7), (c8), (c9), (c10), (c11) }, \
.name3 = { (c12), (c13) } } \
}
#define MAKE_FAT_DATE(d, m, y) ((uint16_t)(((((y)-1980) & 0x7f) << 9) | (((m)&0xf) << 5) | ((d)&0x1f)))
#define MAKE_FAT_TIME(h, m, s) ((uint16_t)((((h)&0x1f) << 11) | (((m)&0x3f) << 5) | (((s) / 2) & 0x1f)))
#endif // _FAT_DIRECTORY_ENTRY_H_
// EOF
kReadOnlyAttribute
Read only.
Definition: src/bm_usb/fat_directory_entry.h:46
kFreeEntryMarkerByte
The first name byte is set to this value to mark a directory entry as free.
Definition: src/bm_usb/fat_directory_entry.h:60
fat_directory_entry_t
FAT filesystem directory entry.
Definition: src/bm_usb/fat_directory_entry.h:84
kDirectoryAttribute
Directory.
Definition: src/bm_usb/fat_directory_entry.h:50
kLongNameAttribute
Attribute value to identify a long file name entry.
Definition: src/bm_usb/fat_directory_entry.h:54
kSystemAttribute
System.
Definition: src/bm_usb/fat_directory_entry.h:48
kVolumeIdAttribute
Volume ID.
Definition: src/bm_usb/fat_directory_entry.h:49
kArchiveAttribute
Archive.
Definition: src/bm_usb/fat_directory_entry.h:51
_fat_directory_attributes
_fat_directory_attributes
FAT filesystem directory entry attributes.
Definition: src/bm_usb/fat_directory_entry.h:44
kHiddenAttribute
Hidden.
Definition: src/bm_usb/fat_directory_entry.h:47
kLastLongNameEntry
Marker flag for long name entry order field to indicate the final long name entry.
Definition: src/bm_usb/fat_directory_entry.h:57