-
Notifications
You must be signed in to change notification settings - Fork 7
/
FAT.h
executable file
·60 lines (50 loc) · 2.03 KB
/
FAT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (c) 2010 by Suan-Aik Yeo <yeosuanaik@gmail.com>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*/
#ifndef __FAT_H
#define __FAT_H
#include "SD.h"
#include <String.h>
#include "util.h"
#define PARTENTRY1 0x1be // offset of 1st partition entry
#define NEW_FILE_ATTR 0x20 // only set the archive bit when creating a new file
// partition info
typedef struct
{
word bytes_per_sec; //bytes per sector
word FAT_size;
dword FAT_addr; //FAT address
word clus_size; //size of a cluster in bytes
word root_dir_size; /* size of root directory */
dword root_dir_addr; //root dir address
dword data_addr; // address of start of data blocks
} partition_info_t;
extern partition_info_t prtn;
extern byte g_block_buf[512];
typedef struct
{
char filename[12]; /** The file's name and extension, total 11 chars padded with spaces. */
byte attributes; /** The file's attributes. Mask of the FAT_ATTRIB_* constants. */
byte unused_attr[14]; /** Attributes in direntry which are unused or unsupported */
word first_cluster; /** The cluster in which the file's first byte resides. */
dword filesize; /** The file's size. */
dword entry_addr; /** The total disk offset of this directory entry. */
} dir_entry_t;
dword get_sec_addr(word cluster, dword position);
word next_clus(word clus, byte *buf);
byte initFAT(byte* buf);
word get_unused_cluster(byte* buf);
dword get_empty_dir_entry(byte* buf);
byte create_dir_entry(dir_entry_t* de, char* filename, byte fn_length, byte* buf);
byte write_dir_entry(dir_entry_t* de, byte* buf);
byte invalidate_dir_entry(dir_entry_t* de, byte* buf);
word clear_FAT(byte* buf, word cluster);
byte update_FAT(byte* buf, word cluster, word value);
void prtn_set_addr(byte* bootSec, dword partition_addr);
byte getFile(dir_entry_t* de, byte* buf, char* filename, byte length);
byte create_file(dir_entry_t* de, char* filename, byte fn_length, byte* buf);
#endif