Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
/**
2
 * Marlin 3D Printer Firmware
3
 * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
 *
5
 * Based on Sprinter and grbl.
6
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
 
23
/**
24
 * \file
25
 * \brief FAT file structures
26
 */
27
 
28
/**
29
 * Arduino SdFat Library
30
 * Copyright (C) 2009 by William Greiman
31
 *
32
 * This file is part of the Arduino Sd2Card Library
33
 */
34
#ifndef SDFATSTRUCTS_H
35
#define SDFATSTRUCTS_H
36
 
37
#define PACKED __attribute__((__packed__))
38
 
39
/**
40
 * mostly from Microsoft document fatgen103.doc
41
 * http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
42
 */
43
 
44
uint8_t const BOOTSIG0 = 0x55,          // Value for byte 510 of boot block or MBR
45
              BOOTSIG1 = 0xAA,          // Value for byte 511 of boot block or MBR
46
              EXTENDED_BOOT_SIG = 0x29; // Value for bootSignature field int FAT/FAT32 boot sector
47
 
48
/**
49
 * \struct partitionTable
50
 * \brief MBR partition table entry
51
 *
52
 * A partition table entry for a MBR formatted storage device.
53
 * The MBR partition table has four entries.
54
 */
55
struct partitionTable {
56
  /**
57
   * Boot Indicator . Indicates whether the volume is the active
58
   * partition.  Legal values include: 0x00. Do not use for booting.
59
   * 0x80 Active partition.
60
   */
61
  uint8_t  boot;
62
  /**
63
   * Head part of Cylinder-head-sector address of the first block in
64
   * the partition. Legal values are 0-255. Only used in old PC BIOS.
65
   */
66
  uint8_t  beginHead;
67
  /**
68
   * Sector part of Cylinder-head-sector address of the first block in
69
   * the partition. Legal values are 1-63. Only used in old PC BIOS.
70
   */
71
  unsigned beginSector : 6;
72
  /** High bits cylinder for first block in partition. */
73
  unsigned beginCylinderHigh : 2;
74
  /**
75
   * Combine beginCylinderLow with beginCylinderHigh. Legal values
76
   * are 0-1023.  Only used in old PC BIOS.
77
   */
78
  uint8_t  beginCylinderLow;
79
  /**
80
   * Partition type. See defines that begin with PART_TYPE_ for
81
   * some Microsoft partition types.
82
   */
83
  uint8_t  type;
84
  /**
85
   * head part of cylinder-head-sector address of the last sector in the
86
   * partition.  Legal values are 0-255. Only used in old PC BIOS.
87
   */
88
  uint8_t  endHead;
89
  /**
90
   * Sector part of cylinder-head-sector address of the last sector in
91
   * the partition.  Legal values are 1-63. Only used in old PC BIOS.
92
   */
93
  unsigned endSector : 6;
94
  /** High bits of end cylinder */
95
  unsigned endCylinderHigh : 2;
96
  /**
97
   * Combine endCylinderLow with endCylinderHigh. Legal values
98
   * are 0-1023.  Only used in old PC BIOS.
99
   */
100
  uint8_t  endCylinderLow;
101
 
102
  uint32_t firstSector;   // Logical block address of the first block in the partition.
103
  uint32_t totalSectors;  // Length of the partition, in blocks.
104
} PACKED;
105
 
106
typedef struct partitionTable part_t; // Type name for partitionTable
107
 
108
/**
109
 * \struct masterBootRecord
110
 *
111
 * \brief Master Boot Record
112
 *
113
 * The first block of a storage device that is formatted with a MBR.
114
 */
115
struct masterBootRecord {
116
  uint8_t  codeArea[440]; // Code Area for master boot program.
117
  uint32_t diskSignature; // Optional Windows NT disk signature. May contain boot code.
118
  uint16_t usuallyZero;   // Usually zero but may be more boot code.
119
  part_t   part[4];       // Partition tables.
120
  uint8_t  mbrSig0;       // First MBR signature byte. Must be 0x55
121
  uint8_t  mbrSig1;       // Second MBR signature byte. Must be 0xAA
122
} PACKED;
123
/** Type name for masterBootRecord */
124
typedef struct masterBootRecord mbr_t;
125
 
126
/**
127
 * \struct fat_boot
128
 *
129
 * \brief Boot sector for a FAT12/FAT16 volume.
130
 *
131
 */
132
struct fat_boot {
133
  /**
134
   * The first three bytes of the boot sector must be valid,
135
   * executable x 86-based CPU instructions. This includes a
136
   * jump instruction that skips the next nonexecutable bytes.
137
   */
138
  uint8_t jump[3];
139
  /**
140
   * This is typically a string of characters that identifies
141
   * the operating system that formatted the volume.
142
   */
143
  char    oemId[8];
144
  /**
145
   * The size of a hardware sector. Valid decimal values for this
146
   * field are 512, 1024, 2048, and 4096. For most disks used in
147
   * the United States, the value of this field is 512.
148
   */
149
  uint16_t bytesPerSector;
150
  /**
151
   * Number of sectors per allocation unit. This value must be a
152
   * power of 2 that is greater than 0. The legal values are
153
   * 1, 2, 4, 8, 16, 32, 64, and 128.  128 should be avoided.
154
   */
155
  uint8_t  sectorsPerCluster;
156
  /**
157
   * The number of sectors preceding the start of the first FAT,
158
   * including the boot sector. The value of this field is always 1.
159
   */
160
  uint16_t reservedSectorCount;
161
  /**
162
   * The number of copies of the FAT on the volume.
163
   * The value of this field is always 2.
164
   */
165
  uint8_t  fatCount;
166
  /**
167
   * For FAT12 and FAT16 volumes, this field contains the count of
168
   * 32-byte directory entries in the root directory. For FAT32 volumes,
169
   * this field must be set to 0. For FAT12 and FAT16 volumes, this
170
   * value should always specify a count that when multiplied by 32
171
   * results in a multiple of bytesPerSector.  FAT16 volumes should
172
   * use the value 512.
173
   */
174
  uint16_t rootDirEntryCount;
175
  /**
176
   * This field is the old 16-bit total count of sectors on the volume.
177
   * This count includes the count of all sectors in all four regions
178
   * of the volume. This field can be 0; if it is 0, then totalSectors32
179
   * must be nonzero.  For FAT32 volumes, this field must be 0. For
180
   * FAT12 and FAT16 volumes, this field contains the sector count, and
181
   * totalSectors32 is 0 if the total sector count fits
182
   * (is less than 0x10000).
183
   */
184
  uint16_t totalSectors16;
185
  /**
186
   * This dates back to the old MS-DOS 1.x media determination and is
187
   * no longer usually used for anything.  0xF8 is the standard value
188
   * for fixed (nonremovable) media. For removable media, 0xF0 is
189
   * frequently used. Legal values are 0xF0 or 0xF8-0xFF.
190
   */
191
  uint8_t  mediaType;
192
  /**
193
   * Count of sectors occupied by one FAT on FAT12/FAT16 volumes.
194
   * On FAT32 volumes this field must be 0, and sectorsPerFat32
195
   * contains the FAT size count.
196
   */
197
  uint16_t sectorsPerFat16;
198
 
199
  uint16_t sectorsPerTrack; // Sectors per track for interrupt 0x13. Not used otherwise.
200
  uint16_t headCount;       // Number of heads for interrupt 0x13. Not used otherwise.
201
 
202
  /**
203
   * Count of hidden sectors preceding the partition that contains this
204
   * FAT volume. This field is generally only relevant for media
205
   * visible on interrupt 0x13.
206
   */
207
  uint32_t hidddenSectors;
208
  /**
209
   * This field is the new 32-bit total count of sectors on the volume.
210
   * This count includes the count of all sectors in all four regions
211
   * of the volume.  This field can be 0; if it is 0, then
212
   * totalSectors16 must be nonzero.
213
   */
214
  uint32_t totalSectors32;
215
  /**
216
   * Related to the BIOS physical drive number. Floppy drives are
217
   * identified as 0x00 and physical hard disks are identified as
218
   * 0x80, regardless of the number of physical disk drives.
219
   * Typically, this value is set prior to issuing an INT 13h BIOS
220
   * call to specify the device to access. The value is only
221
   * relevant if the device is a boot device.
222
   */
223
  uint8_t  driveNumber;
224
 
225
  uint8_t  reserved1;       // used by Windows NT - should be zero for FAT
226
  uint8_t  bootSignature;   // 0x29 if next three fields are valid
227
 
228
  /**
229
   * A random serial number created when formatting a disk,
230
   * which helps to distinguish between disks.
231
   * Usually generated by combining date and time.
232
   */
233
  uint32_t volumeSerialNumber;
234
  /**
235
   * A field once used to store the volume label. The volume label
236
   * is now stored as a special file in the root directory.
237
   */
238
  char     volumeLabel[11];
239
  /**
240
   * A field with a value of either FAT, FAT12 or FAT16,
241
   * depending on the disk format.
242
   */
243
  char     fileSystemType[8];
244
 
245
  uint8_t  bootCode[448];   // X86 boot code
246
  uint8_t  bootSectorSig0;  // must be 0x55
247
  uint8_t  bootSectorSig1;  // must be 0xAA
248
} PACKED;
249
 
250
typedef struct fat_boot fat_boot_t;   // Type name for FAT Boot Sector
251
 
252
/**
253
 * \struct fat32_boot
254
 *
255
 * \brief Boot sector for a FAT32 volume.
256
 */
257
struct fat32_boot {
258
  /**
259
   * The first three bytes of the boot sector must be valid,
260
   * executable x 86-based CPU instructions. This includes a
261
   * jump instruction that skips the next nonexecutable bytes.
262
   */
263
  uint8_t jump[3];
264
  /**
265
   * This is typically a string of characters that identifies
266
   * the operating system that formatted the volume.
267
   */
268
  char    oemId[8];
269
  /**
270
   * The size of a hardware sector. Valid decimal values for this
271
   * field are 512, 1024, 2048, and 4096. For most disks used in
272
   * the United States, the value of this field is 512.
273
   */
274
  uint16_t bytesPerSector;
275
  /**
276
   * Number of sectors per allocation unit. This value must be a
277
   * power of 2 that is greater than 0. The legal values are
278
   * 1, 2, 4, 8, 16, 32, 64, and 128.  128 should be avoided.
279
   */
280
  uint8_t  sectorsPerCluster;
281
  /**
282
   * The number of sectors preceding the start of the first FAT,
283
   * including the boot sector. Must not be zero
284
   */
285
  uint16_t reservedSectorCount;
286
  /**
287
   * The number of copies of the FAT on the volume.
288
   * The value of this field is always 2.
289
   */
290
  uint8_t  fatCount;
291
  /**
292
   * FAT12/FAT16 only. For FAT32 volumes, this field must be set to 0.
293
   */
294
  uint16_t rootDirEntryCount;
295
  /**
296
   * For FAT32 volumes, this field must be 0.
297
   */
298
  uint16_t totalSectors16;
299
  /**
300
   * This dates back to the old MS-DOS 1.x media determination and is
301
   * no longer usually used for anything.  0xF8 is the standard value
302
   * for fixed (nonremovable) media. For removable media, 0xF0 is
303
   * frequently used. Legal values are 0xF0 or 0xF8-0xFF.
304
   */
305
  uint8_t  mediaType;
306
  /**
307
   * On FAT32 volumes this field must be 0, and sectorsPerFat32
308
   * contains the FAT size count.
309
   */
310
  uint16_t sectorsPerFat16;
311
 
312
  uint16_t sectorsPerTrack; // Sectors per track for interrupt 0x13. Not used otherwise.
313
  uint16_t headCount;       // Number of heads for interrupt 0x13. Not used otherwise.
314
 
315
  /**
316
   * Count of hidden sectors preceding the partition that contains this
317
   * FAT volume. This field is generally only relevant for media
318
   * visible on interrupt 0x13.
319
   */
320
  uint32_t hidddenSectors;
321
  /**
322
   * Contains the total number of sectors in the FAT32 volume.
323
   */
324
  uint32_t totalSectors32;
325
  /**
326
   * Count of sectors occupied by one FAT on FAT32 volumes.
327
   */
328
  uint32_t sectorsPerFat32;
329
  /**
330
   * This field is only defined for FAT32 media and does not exist on
331
   * FAT12 and FAT16 media.
332
   * Bits 0-3 -- Zero-based number of active FAT.
333
   *             Only valid if mirroring is disabled.
334
   * Bits 4-6 -- Reserved.
335
   * Bit 7  -- 0 means the FAT is mirrored at runtime into all FATs.
336
   *        -- 1 means only one FAT is active; it is the one referenced
337
   *             in bits 0-3.
338
   * Bits 8-15  -- Reserved.
339
   */
340
  uint16_t fat32Flags;
341
  /**
342
   * FAT32 version. High byte is major revision number.
343
   * Low byte is minor revision number. Only 0.0 define.
344
   */
345
  uint16_t fat32Version;
346
  /**
347
   * Cluster number of the first cluster of the root directory for FAT32.
348
   * This usually 2 but not required to be 2.
349
   */
350
  uint32_t fat32RootCluster;
351
  /**
352
   * Sector number of FSINFO structure in the reserved area of the
353
   * FAT32 volume. Usually 1.
354
   */
355
  uint16_t fat32FSInfo;
356
  /**
357
   * If nonzero, indicates the sector number in the reserved area
358
   * of the volume of a copy of the boot record. Usually 6.
359
   * No value other than 6 is recommended.
360
   */
361
  uint16_t fat32BackBootBlock;
362
  /**
363
   * Reserved for future expansion. Code that formats FAT32 volumes
364
   * should always set all of the bytes of this field to 0.
365
   */
366
  uint8_t  fat32Reserved[12];
367
  /**
368
   * Related to the BIOS physical drive number. Floppy drives are
369
   * identified as 0x00 and physical hard disks are identified as
370
   * 0x80, regardless of the number of physical disk drives.
371
   * Typically, this value is set prior to issuing an INT 13h BIOS
372
   * call to specify the device to access. The value is only
373
   * relevant if the device is a boot device.
374
   */
375
  uint8_t  driveNumber;
376
 
377
  uint8_t  reserved1;       // Used by Windows NT - should be zero for FAT
378
  uint8_t  bootSignature;   // 0x29 if next three fields are valid
379
 
380
  /**
381
   * A random serial number created when formatting a disk,
382
   * which helps to distinguish between disks.
383
   * Usually generated by combining date and time.
384
   */
385
  uint32_t volumeSerialNumber;
386
  /**
387
   * A field once used to store the volume label. The volume label
388
   * is now stored as a special file in the root directory.
389
   */
390
  char     volumeLabel[11];
391
  /**
392
   * A text field with a value of FAT32.
393
   */
394
  char     fileSystemType[8];
395
 
396
  uint8_t  bootCode[420];   // X86 boot code
397
  uint8_t  bootSectorSig0;  // must be 0x55
398
  uint8_t  bootSectorSig1;  // must be 0xAA
399
 
400
} PACKED;
401
 
402
typedef struct fat32_boot fat32_boot_t; // Type name for FAT32 Boot Sector
403
 
404
uint32_t const FSINFO_LEAD_SIG   = 0x41615252,  // 'AaRR' Lead signature for a FSINFO sector
405
               FSINFO_STRUCT_SIG = 0x61417272;  // 'aArr' Struct signature for a FSINFO sector
406
 
407
/**
408
 * \struct fat32_fsinfo
409
 *
410
 * \brief FSINFO sector for a FAT32 volume.
411
 *
412
 */
413
struct fat32_fsinfo {
414
  uint32_t  leadSignature;    // must be 0x52, 0x52, 0x61, 0x41 'RRaA'
415
  uint8_t  reserved1[480];    // must be zero
416
  uint32_t  structSignature;  // must be 0x72, 0x72, 0x41, 0x61 'rrAa'
417
          /**
418
           * Contains the last known free cluster count on the volume.
419
           * If the value is 0xFFFFFFFF, then the free count is unknown
420
           * and must be computed. Any other value can be used, but is
421
           * not necessarily correct. It should be range checked at least
422
           * to make sure it is <= volume cluster count.
423
           */
424
  uint32_t freeCount;
425
          /**
426
           * This is a hint for the FAT driver. It indicates the cluster
427
           * number at which the driver should start looking for free clusters.
428
           * If the value is 0xFFFFFFFF, then there is no hint and the driver
429
           * should start looking at cluster 2.
430
           */
431
  uint32_t nextFree;
432
 
433
  uint8_t  reserved2[12];     // must be zero
434
  uint8_t  tailSignature[4];  // must be 0x00, 0x00, 0x55, 0xAA
435
} PACKED;
436
 
437
typedef struct fat32_fsinfo fat32_fsinfo_t; // Type name for FAT32 FSINFO Sector
438
 
439
// End Of Chain values for FAT entries
440
uint16_t const FAT12EOC = 0xFFF,          // FAT12 end of chain value used by Microsoft.
441
               FAT12EOC_MIN = 0xFF8,      // Minimum value for FAT12 EOC.  Use to test for EOC.
442
               FAT16EOC = 0xFFFF,         // FAT16 end of chain value used by Microsoft.
443
               FAT16EOC_MIN = 0xFFF8;     // Minimum value for FAT16 EOC.  Use to test for EOC.
444
uint32_t const FAT32EOC = 0x0FFFFFFF,     // FAT32 end of chain value used by Microsoft.
445
               FAT32EOC_MIN = 0x0FFFFFF8, // Minimum value for FAT32 EOC.  Use to test for EOC.
446
               FAT32MASK = 0x0FFFFFFF;    // Mask a for FAT32 entry. Entries are 28 bits.
447
 
448
/**
449
 * \struct directoryEntry
450
 * \brief FAT short directory entry
451
 *
452
 * Short means short 8.3 name, not the entry size.
453
 *
454
 * Date Format. A FAT directory entry date stamp is a 16-bit field that is
455
 * basically a date relative to the MS-DOS epoch of 01/01/1980. Here is the
456
 * format (bit 0 is the LSB of the 16-bit word, bit 15 is the MSB of the
457
 * 16-bit word):
458
 *
459
 * Bits 9-15: Count of years from 1980, valid value range 0-127
460
 * inclusive (1980-2107).
461
 *
462
 * Bits 5-8: Month of year, 1 = January, valid value range 1-12 inclusive.
463
 *
464
 * Bits 0-4: Day of month, valid value range 1-31 inclusive.
465
 *
466
 * Time Format. A FAT directory entry time stamp is a 16-bit field that has
467
 * a granularity of 2 seconds. Here is the format (bit 0 is the LSB of the
468
 * 16-bit word, bit 15 is the MSB of the 16-bit word).
469
 *
470
 * Bits 11-15: Hours, valid value range 0-23 inclusive.
471
 *
472
 * Bits 5-10: Minutes, valid value range 0-59 inclusive.
473
 *
474
 * Bits 0-4: 2-second count, valid value range 0-29 inclusive (0 - 58 seconds).
475
 *
476
 * The valid time range is from Midnight 00:00:00 to 23:59:58.
477
 */
478
struct directoryEntry {
479
  /**
480
   * Short 8.3 name.
481
   *
482
   * The first eight bytes contain the file name with blank fill.
483
   * The last three bytes contain the file extension with blank fill.
484
   */
485
  uint8_t  name[11];
486
  /**
487
   * Entry attributes.
488
   *
489
   * The upper two bits of the attribute byte are reserved and should
490
   * always be set to 0 when a file is created and never modified or
491
   * looked at after that.  See defines that begin with DIR_ATT_.
492
   */
493
  uint8_t  attributes;
494
  /**
495
   * Reserved for use by Windows NT. Set value to 0 when a file is
496
   * created and never modify or look at it after that.
497
   */
498
  uint8_t  reservedNT;
499
  /**
500
   * The granularity of the seconds part of creationTime is 2 seconds
501
   * so this field is a count of tenths of a second and it's valid
502
   * value range is 0-199 inclusive. (WHG note - seems to be hundredths)
503
   */
504
  uint8_t  creationTimeTenths;
505
 
506
  uint16_t creationTime;    // Time file was created.
507
  uint16_t creationDate;    // Date file was created.
508
 
509
  /**
510
   * Last access date. Note that there is no last access time, only
511
   * a date.  This is the date of last read or write. In the case of
512
   * a write, this should be set to the same date as lastWriteDate.
513
   */
514
  uint16_t lastAccessDate;
515
  /**
516
   * High word of this entry's first cluster number (always 0 for a
517
   * FAT12 or FAT16 volume).
518
   */
519
  uint16_t firstClusterHigh;
520
 
521
  uint16_t lastWriteTime;   // Time of last write. File creation is considered a write.
522
  uint16_t lastWriteDate;   // Date of last write. File creation is considered a write.
523
  uint16_t firstClusterLow; // Low word of this entry's first cluster number.
524
  uint32_t fileSize;        // 32-bit unsigned holding this file's size in bytes.
525
} PACKED;
526
 
527
/**
528
 * \struct directoryVFATEntry
529
 * \brief VFAT long filename directory entry
530
 *
531
 * directoryVFATEntries are found in the same list as normal directoryEntry.
532
 * But have the attribute field set to DIR_ATT_LONG_NAME.
533
 *
534
 * Long filenames are saved in multiple directoryVFATEntries.
535
 * Each entry containing 13 UTF-16 characters.
536
 */
537
struct directoryVFATEntry {
538
  /**
539
   * Sequence number. Consists of 2 parts:
540
   *  bit 6:   indicates first long filename block for the next file
541
   *  bit 0-4: the position of this long filename block (first block is 1)
542
   */
543
  uint8_t  sequenceNumber;
544
 
545
  uint16_t name1[5];        // First set of UTF-16 characters
546
  uint8_t  attributes;      // attributes (at the same location as in directoryEntry), always 0x0F
547
  uint8_t  reservedNT;      // Reserved for use by Windows NT. Always 0.
548
  uint8_t  checksum;        // Checksum of the short 8.3 filename, can be used to checked if the file system as modified by a not-long-filename aware implementation.
549
  uint16_t name2[6];        // Second set of UTF-16 characters
550
  uint16_t firstClusterLow; // firstClusterLow is always zero for longFilenames
551
  uint16_t name3[2];        // Third set of UTF-16 characters
552
} PACKED;
553
 
554
// Definitions for directory entries
555
//
556
typedef struct directoryEntry dir_t;          // Type name for directoryEntry
557
typedef struct directoryVFATEntry vfat_t;     // Type name for directoryVFATEntry
558
 
559
uint8_t const DIR_NAME_0xE5     = 0x05,       // escape for name[0] = 0xE5
560
              DIR_NAME_DELETED  = 0xE5,       // name[0] value for entry that is free after being "deleted"
561
              DIR_NAME_FREE     = 0x00,       // name[0] value for entry that is free and no allocated entries follow
562
              DIR_ATT_READ_ONLY = 0x01,       // file is read-only
563
              DIR_ATT_HIDDEN    = 0x02,       // File should hidden in directory listings
564
              DIR_ATT_SYSTEM    = 0x04,       // Entry is for a system file
565
              DIR_ATT_VOLUME_ID = 0x08,       // Directory entry contains the volume label
566
              DIR_ATT_DIRECTORY = 0x10,       // Entry is for a directory
567
              DIR_ATT_ARCHIVE   = 0x20,       // Old DOS archive bit for backup support
568
              DIR_ATT_LONG_NAME = 0x0F,       // Test value for long name entry.  Test is (d->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME.
569
              DIR_ATT_LONG_NAME_MASK = 0x3F,  // Test mask for long name entry
570
              DIR_ATT_DEFINED_BITS = 0x3F;    // defined attribute bits
571
 
572
/**
573
 * Directory entry is part of a long name
574
 * \param[in] dir Pointer to a directory entry.
575
 *
576
 * \return true if the entry is for part of a long name else false.
577
 */
578
static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
579
  return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
580
}
581
 
582
/** Mask for file/subdirectory tests */
583
uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);
584
 
585
/**
586
 * Directory entry is for a file
587
 * \param[in] dir Pointer to a directory entry.
588
 *
589
 * \return true if the entry is for a normal file else false.
590
 */
591
static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
592
  return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
593
}
594
 
595
/**
596
 * Directory entry is for a subdirectory
597
 * \param[in] dir Pointer to a directory entry.
598
 *
599
 * \return true if the entry is for a subdirectory else false.
600
 */
601
static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
602
  return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
603
}
604
 
605
/**
606
 * Directory entry is for a file or subdirectory
607
 * \param[in] dir Pointer to a directory entry.
608
 *
609
 * \return true if the entry is for a normal file or subdirectory else false.
610
 */
611
static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
612
  return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
613
}
614
 
615
#endif // SDFATSTRUCTS_H