PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/firmware/src/Motherboard/lib_sd/fat.h

http://github.com/makerbot/G3Firmware
C Header | 129 lines | 58 code | 22 blank | 49 comment | 0 complexity | bf5e669ebe4dd92f5fa0df7d43098d19 MD5 | raw file
  1
  2/*
  3 * Copyright (c) 2006-2010 by Roland Riegel <feedback@roland-riegel.de>
  4 *
  5 * This file is free software; you can redistribute it and/or modify
  6 * it under the terms of either the GNU General Public License version 2
  7 * or the GNU Lesser General Public License version 2.1, both as
  8 * published by the Free Software Foundation.
  9 */
 10
 11#ifndef FAT_H
 12#define FAT_H
 13
 14#include <stdint.h>
 15#include "fat_config.h"
 16
 17#ifdef __cplusplus
 18extern "C"
 19{
 20#endif
 21
 22/**
 23 * \addtogroup fat
 24 *
 25 * @{
 26 */
 27/**
 28 * \file
 29 * FAT header (license: GPLv2 or LGPLv2.1)
 30 *
 31 * \author Roland Riegel
 32 */
 33
 34/**
 35 * \addtogroup fat_file
 36 * @{
 37 */
 38
 39/** The file is read-only. */
 40#define FAT_ATTRIB_READONLY (1 << 0)
 41/** The file is hidden. */
 42#define FAT_ATTRIB_HIDDEN (1 << 1)
 43/** The file is a system file. */
 44#define FAT_ATTRIB_SYSTEM (1 << 2)
 45/** The file is empty and has the volume label as its name. */
 46#define FAT_ATTRIB_VOLUME (1 << 3)
 47/** The file is a directory. */
 48#define FAT_ATTRIB_DIR (1 << 4)
 49/** The file has to be archived. */
 50#define FAT_ATTRIB_ARCHIVE (1 << 5)
 51
 52/** The given offset is relative to the beginning of the file. */
 53#define FAT_SEEK_SET 0
 54/** The given offset is relative to the current read/write position. */
 55#define FAT_SEEK_CUR 1
 56/** The given offset is relative to the end of the file. */
 57#define FAT_SEEK_END 2
 58
 59/**
 60 * @}
 61 */
 62
 63struct partition_struct;
 64struct fat_fs_struct;
 65struct fat_file_struct;
 66struct fat_dir_struct;
 67
 68/**
 69 * \ingroup fat_file
 70 * Describes a directory entry.
 71 */
 72struct fat_dir_entry_struct
 73{
 74    /** The file's name, truncated to 31 characters. */
 75    char long_name[32];
 76    /** The file's attributes. Mask of the FAT_ATTRIB_* constants. */
 77    uint8_t attributes;
 78#if FAT_DATETIME_SUPPORT
 79    /** Compressed representation of modification time. */
 80    uint16_t modification_time;
 81    /** Compressed representation of modification date. */
 82    uint16_t modification_date;
 83#endif
 84    /** The cluster in which the file's first byte resides. */
 85    cluster_t cluster;
 86    /** The file's size. */
 87    uint32_t file_size;
 88    /** The total disk offset of this directory entry. */
 89    offset_t entry_offset;
 90};
 91
 92struct fat_fs_struct* fat_open(struct partition_struct* partition);
 93void fat_close(struct fat_fs_struct* fs);
 94
 95struct fat_file_struct* fat_open_file(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
 96void fat_close_file(struct fat_file_struct* fd);
 97intptr_t fat_read_file(struct fat_file_struct* fd, uint8_t* buffer, uintptr_t buffer_len);
 98intptr_t fat_write_file(struct fat_file_struct* fd, const uint8_t* buffer, uintptr_t buffer_len);
 99uint8_t fat_seek_file(struct fat_file_struct* fd, int32_t* offset, uint8_t whence);
100uint8_t fat_resize_file(struct fat_file_struct* fd, uint32_t size);
101
102struct fat_dir_struct* fat_open_dir(struct fat_fs_struct* fs, const struct fat_dir_entry_struct* dir_entry);
103void fat_close_dir(struct fat_dir_struct* dd);
104uint8_t fat_read_dir(struct fat_dir_struct* dd, struct fat_dir_entry_struct* dir_entry);
105uint8_t fat_reset_dir(struct fat_dir_struct* dd);
106
107uint8_t fat_create_file(struct fat_dir_struct* parent, const char* file, struct fat_dir_entry_struct* dir_entry);
108uint8_t fat_delete_file(struct fat_fs_struct* fs, struct fat_dir_entry_struct* dir_entry);
109uint8_t fat_create_dir(struct fat_dir_struct* parent, const char* dir, struct fat_dir_entry_struct* dir_entry);
110#define fat_delete_dir fat_delete_file
111
112void fat_get_file_modification_date(const struct fat_dir_entry_struct* dir_entry, uint16_t* year, uint8_t* month, uint8_t* day);
113void fat_get_file_modification_time(const struct fat_dir_entry_struct* dir_entry, uint8_t* hour, uint8_t* min, uint8_t* sec);
114
115uint8_t fat_get_dir_entry_of_path(struct fat_fs_struct* fs, const char* path, struct fat_dir_entry_struct* dir_entry);
116
117offset_t fat_get_fs_size(const struct fat_fs_struct* fs);
118offset_t fat_get_fs_free(const struct fat_fs_struct* fs);
119
120/**
121 * @}
122 */
123
124#ifdef __cplusplus
125}
126#endif
127
128#endif
129