fat.h
来自「AMLOGIC DPF source code」· C头文件 代码 · 共 671 行 · 第 1/2 页
H
671 行
/*******************************************************************
*
* Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
*
* Description:
*
* Author: Amlogic Software
* Created: Fri Nov 11 00:22:37 2005
*
*******************************************************************/
/*
* fat.h
*
* Constants/data structures/prototypes for low-level operations on a volume
* with FAT filesystem
*
* Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
* Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.avfs.com/license/LICENSE.
*
* @(#) fat.h,v 1.3.2.3 2003/09/04 18:47:02 joel Exp
*/
#ifndef __DOSFS_FAT_H__
#define __DOSFS_FAT_H__
#undef FAT_PROTECT_SUPPORT
#define FAT_PRE_CHECK
#ifdef __cplusplus
extern "C" {
#endif
#if 0
//porting
typedef struct disk_device {
dev_t dev; /* Device ID (major + minor) */
struct disk_device *phys_dev; /* Physical device ID (the same
as dev if this entry specifies
the physical device) */
char *name; /* Disk device name */
int uses; /* Use counter. Device couldn't be
removed if it is in use. */
int start; /* Starting block number (0 for
physical devices, block offset
on the related physical device
for logical device) */
int size; /* Size of physical or logical disk
in disk blocks */
int block_size; /* Size of device block (minimum
transfer unit) in bytes
(must be power of 2) */
int block_size_log2; /* log2 of block_size */
// avfs_bdpool_id pool; /* Buffer pool assigned to this
// device */
//block_device_ioctl ioctl; /* ioctl handler for this block
// device */
} disk_device;
#if 0
//cancled by rain, it has been defined in bdbuf.h
typedef struct bdbuf_buffer {
Chain_Node link; /* Link in the lru, mod or free chains */
struct bdbuf_avl_node {
signed char cache; /* Cache */
struct bdbuf_buffer* left; /* Left Child */
struct bdbuf_buffer* right; /* Right Child */
signed char bal; /* The balance of the sub-tree */
} avl;
dev_t dev; /* device number */
// blkdev_bnum block; /* block number on the device */
char *buffer; /* Pointer to the buffer memory area */
// avfs_status_code status; /* Last I/O operation completion status */
int error; /* If status != AVFS_SUCCESSFUL, this field contains
errno value which can be used by user later */
boolean modified:1; /* =1 if buffer was modified */
boolean in_progress:1; /* =1 if exchange with disk is in progress;
need to wait on semaphore */
boolean actual:1; /* Buffer contains actual data */
int use_count; /* Usage counter; incremented when somebody use
this buffer; decremented when buffer released
without modification or when buffer is flushed
by swapout task */
// avfs_bdpool_id pool; /* Identifier of buffer pool to which this buffer
// belongs */
// CORE_mutex_Control transfer_sema;
/* Transfer operation semaphore */
} bdbuf_buffer;
#else
//by rain, need alignment
typedef struct bdbuf_buffer {
Chain_Node link; /* Link in the lru, mod or free chains */
char *buffer; /* Pointer to the buffer memory area */
struct bdbuf_avl_node {
struct bdbuf_buffer* left; /* Left Child */
struct bdbuf_buffer* right; /* Right Child */
signed char cache; /* Cache */
signed char bal; /* The balance of the sub-tree */
unsigned short reserved;
} avl;
dev_t dev; /* device number */
avfs_unsigned32 block; /* block number on the device */
int error; /* If status != AVFS_SUCCESSFUL, this field contains
errno value which can be used by user later */
int use_count; /* Usage counter; incremented when somebody use
this buffer; decremented when buffer released
without modification or when buffer is flushed
by swapout task */
unsigned int modified_map; /* give which blocks (in bdbuf) are modified, valid only when modified is true */
int pool; /* Identifier of buffer pool to which this buffer
// belongs */
avfs_status_code status; /* Last I/O operation completion status */
// boolean modified:1; /* =1 if buffer was modified */
// boolean in_progress:1; /* =1 if exchange with disk is in progress;
// need to wait on semaphore */
// boolean actual:1; /* Buffer contains actual data */
boolean modified;
boolean in_progress;
boolean actual;
// CORE_mutex_Control transfer_sema;
/* Transfer operation semaphore */
} bdbuf_buffer;
#endif
#endif
//#include <string.h>
//#include <avfs/seterr.h>
/* XXX: temporary hack :(( */
#ifndef set_errno_and_return_minus_one
#define set_errno_and_return_minus_one avfs_set_errno_and_return_minus_one
#endif /* set_errno_and_return_minus_one */
//#include <avfs/score/cpu.h>
//#include <errno.h>
//#include <avfs/bdbuf.h>
#ifndef RC_OK
#define RC_OK 0x00000000
#endif
/*
* Remember that all FAT file system on disk data structure is
* "little endian"!
* (derived from linux)
*/
/*
* Conversion from and to little-endian byte order. (no-op on i386/i486)
*
* Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
* BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
*/
#if (CPU_BIG_ENDIAN == TRUE)
# define CF_LE_W(v) CPU_swap_u16((unsigned16)v)
# define CF_LE_L(v) CPU_swap_u32((unsigned32)v)
# define CT_LE_W(v) CPU_swap_u16((unsigned16)v)
# define CT_LE_L(v) CPU_swap_u32((unsigned32)v)
#else
# define CF_LE_W(v) (v)
# define CF_LE_L(v) (v)
# define CT_LE_W(v) (v)
# define CT_LE_L(v) (v)
#endif
#define FAT_HASH_SIZE 2
#define FAT_HASH_MODULE FAT_HASH_SIZE
#define FAT_SECTOR512_SIZE 512 /* sector size (bytes) */
#define FAT_SECTOR512_BITS 9 /* log2(SECTOR_SIZE) */
/* maximum + 1 number of clusters for FAT12 */
#define FAT_FAT12_MAX_CLN 4085
/* maximum + 1 number of clusters for FAT16 */
#define FAT_FAT16_MAX_CLN 65525
#define FAT_FAT12 0x01
#define FAT_FAT16 0x02
#define FAT_FAT32 0x04
#define FAT_UNDEFINED_VALUE (unsigned32)0xFFFFFFFF
#define FAT_FAT12_EOC 0x0FF8
#define FAT_FAT16_EOC 0xFFF8
#define FAT_FAT32_EOC (unsigned32)0x0FFFFFF8
#define FAT_FAT12_FREE 0x0000
#define FAT_FAT16_FREE 0x0000
#define FAT_FAT32_FREE 0x00000000
#define FAT_GENFAT_EOC (unsigned32)0xFFFFFFFF
#define FAT_GENFAT_FREE (unsigned32)0x00000000
#define FAT_FAT12_SHIFT 0x04
#define FAT_FAT12_MASK 0x00000FFF
#define FAT_FAT16_MASK 0x0000FFFF
#define FAT_FAT32_MASK (unsigned32)0x0FFFFFFF
#define FAT_MAX_BPB_SIZE 90
/* size of useful information in FSInfo sector */
#define FAT_USEFUL_INFO_SIZE 12
#define FAT_VAL8(x, ofs) (unsigned8)(*((unsigned8 *)(x) + (ofs)))
#define FAT_VAL16(x, ofs) \
(unsigned16)( (*((unsigned8 *)(x) + (ofs))) | \
((*((unsigned8 *)(x) + (ofs) + 1)) << 8) )
#define FAT_VAL32(x, ofs) \
(unsigned32)( (unsigned32)(*((unsigned8 *)(x) + (ofs))) | \
((unsigned32)(*((unsigned8 *)(x) + (ofs) + 1)) << 8) | \
((unsigned32)(*((unsigned8 *)(x) + (ofs) + 2)) << 16) | \
((unsigned32)(*((unsigned8 *)(x) + (ofs) + 3)) << 24) )
/* macros to access boot sector fields */
#define FAT_BR_BYTES_PER_SECTOR(x) FAT_VAL16(x, 11)
#define FAT_BR_SECTORS_PER_CLUSTER(x) FAT_VAL8(x, 13)
#define FAT_BR_RESERVED_SECTORS_NUM(x) FAT_VAL16(x, 14)
#define FAT_BR_FAT_NUM(x) FAT_VAL8(x, 16)
#define FAT_BR_FILES_PER_ROOT_DIR(x) FAT_VAL16(x, 17)
#define FAT_BR_TOTAL_SECTORS_NUM16(x) FAT_VAL16(x, 19)
#define FAT_BR_MEDIA(x) FAT_VAL8(x, 21)
#define FAT_BR_SECTORS_PER_FAT(x) FAT_VAL16(x, 22)
#define FAT_BR_TOTAL_SECTORS_NUM32(x) FAT_VAL32(x, 32)
#define FAT_BR_SECTORS_PER_FAT32(x) FAT_VAL32(x, 36)
#define FAT_BR_EXT_FLAGS(x) FAT_VAL16(x, 40)
#define FAT_BR_FAT32_ROOT_CLUSTER(x) FAT_VAL32(x, 44)
#define FAT_BR_FAT32_FS_INFO_SECTOR(x) FAT_VAL16(x, 48)
#define FAT_FSINFO_LEAD_SIGNATURE(x) FAT_VAL32(x, 0)
#define FAT_BR_FAT12_FAT16_LABEL_OFFSET 43
#define FAT_BR_FAT32_LABEL_OFFET 71
/*
* I read FSInfo sector from offset 484 to access the information, so offsets
* of these fields a relative
*/
#define FAT_FSINFO_FREE_CLUSTER_COUNT(x) FAT_VAL32(x, 4)
#define FAT_FSINFO_NEXT_FREE_CLUSTER(x) FAT_VAL32(x, 8)
#define FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET 488
#define FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET 492
#define FAT_RSRVD_CLN 0x02
#define FAT_FSINFO_LEAD_SIGNATURE_VALUE 0x41615252
#define FAT_FSI_LEADSIG_SIZE 0x04
#define FAT_FSI_INFO 484
#define MS_BYTES_PER_CLUSTER_LIMIT_512 0x10000 /* 64K */
#define MS_BYTES_PER_CLUSTER_LIMIT_N512 0x40000 /*256K*/
#define FAT_BR_EXT_FLAGS_MIRROR 0x0080
#define FAT_BR_EXT_FLAGS_FAT_NUM 0x000F
#define FAT_DIRENTRY_SIZE 32
#define FAT_DIRENTRIES_PER_SEC512 16
/*
* Volume descriptor
* Description of the volume the FAT filesystem is located on - generally
* the fields of the structure corresponde to Boot Sector and BPB Srtucture
* fields
*/
typedef struct fat_vol_s
{
unsigned16 bps; /* bytes per sector */
unsigned16 sec_log2; /* log2 of bps */
unsigned8 sec_mul; /* log2 of 512bts sectors number per sector */
unsigned16 spc; /* sectors per cluster */
unsigned16 spc_log2; /* log2 of spc */
unsigned32 bpc; /* bytes per cluster */
unsigned16 bpc_log2; /* log2 of bytes per cluster */
unsigned8 fats; /* number of FATs */
unsigned8 type; /* FAT type */
unsigned32 mask;
unsigned32 eoc_val;
unsigned16 fat_loc; /* FAT start */
unsigned32 fat_length; /* sectors per FAT */
unsigned32 rdir_loc; /* root directory start */
unsigned16 rdir_entrs; /* files per root directory */
unsigned32 rdir_secs; /* sectors per root directory */
unsigned32 rdir_size; /* root directory size in bytes */
unsigned32 tot_secs; /* total count of sectors */
unsigned32 data_fsec; /* first data sector */
unsigned32 data_cls; /* count of data clusters */
unsigned32 rdir_cl; /* first cluster of the root directory */
unsigned16 info_sec; /* FSInfo Sector Structure location */
unsigned32 free_cls; /* last known free clusters count */
unsigned32 next_cl; /* next free cluster number */
unsigned8 mirror; /* mirroring enabla/disable */
unsigned32 afat_loc; /* active FAT location */
unsigned8 afat; /* the number of active FAT */
dev_t dev; /* device ID */
disk_device *dd; /* disk device (see libblock) */
unsigned32 last_read_sec; /* last read sec no. add by Andrew */
unsigned32 last_write_sec; /* last write sec no. add by Andrew */
signed8 label[12]; /* FAT Volume Label (8.3+1) */
void *private_data; /* reserved */
} fat_vol_t;
typedef struct fat_cache_s
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?