msdos.h

来自「AMLOGIC DPF source code」· C头文件 代码 · 共 528 行 · 第 1/2 页

H
528
字号
/*******************************************************************
 * 
 *  Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
 *
 *  Description: 
 *
 *  Author: Amlogic Software
 *  Created: Fri Nov 11 00:23:04 2005
 *
 *******************************************************************/
/*
 *  msdos.h
 *
 *  The MSDOS filesystem constants/data structures/prototypes
 *
 *  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.
 *
 *  @(#) msdos.h,v 1.2.2.5 2003/09/04 18:47:02 joel Exp
 */
#ifndef __DOSFS_MSDOS_H__
#define __DOSFS_MSDOS_H__

#ifdef __cplusplus
extern "C" {
#endif

//#include <avfs.h>
//#include <avfs/libio_.h>

#include "fat.h"
#include "fat_file.h"
 
#define RESOURCE_CHECK_TIME 20

#ifndef RC_OK
#define RC_OK 0x00000000
#endif

#define MSDOS_NAME_NOT_FOUND_ERR  0xDD000001 

/*
 * This structure identifies the instance of the filesystem on the MSDOS 
 * level. 
 */
typedef struct msdos_fs_info_s
{
    fat_fs_info_t                     fat;                /* 
                                                           * volume 
                                                           * description
                                                           */
    avfs_filesystem_file_handlers_r *directory_handlers; /* 
                                                           * a set of routines
                                                           * that handles the 
                                                           * nodes of directory 
                                                           * type
                                                           */
    avfs_filesystem_file_handlers_r *file_handlers;      /* 
                                                           * a set of routines
                                                           * that handles the 
                                                           * nodes of file 
                                                           * type
                                                           */
    avfs_id                          vol_sema;           /* 
                                                           * semaphore 
                                                           * associated with 
                                                           * the volume
                                                           */
    avfs_id                          vol_resource;           /* 
                                                           *  semaphore
                                                           * associated with 
                                                           * the volume
                                                           */

    unsigned8                        *cl_buf;              /* 
                                                            * just placeholder
                                                            * for anything 
                                                            */ 
} msdos_fs_info_t;

/* a set of routines that handle the nodes which are directories */
extern avfs_filesystem_file_handlers_r  msdos_dir_handlers;

/* a set of routines that handle the nodes which are files */
extern avfs_filesystem_file_handlers_r  msdos_file_handlers;

/* Volume semaphore timeout value. This value can be changed to a number
 * of ticks to help debugging or if you need such a  */
#define MSDOS_VOLUME_SEMAPHORE_TIMEOUT    AVFS_NO_TIMEOUT

/* Node types */
#define MSDOS_DIRECTORY     AVFS_FILESYSTEM_DIRECTORY
#define MSDOS_REGULAR_FILE  AVFS_FILESYSTEM_MEMORY_FILE
#define MSDOS_HARD_LINK     AVFS_FILESYSTEM_HARD_LINK /* pseudo type */
   
typedef avfs_filesystem_node_types_t msdos_node_type_t;

/* 
 * Macros for fetching fields from 32 bytes long FAT Directory Entry 
 * Structure
 */
#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE    32 /* 32 bytes */

#if 0
//porting
#define MSDOS_DIR_NAME(x)                 (unsigned8 *)((x) + 0)
#else
#define MSDOS_DIR_NAME(x)                 (char *)((x) + 0)
#endif
#define MSDOS_DIR_ATTR(x)                 (unsigned8 *)((x) + 11)
#define MSDOS_DIR_NT_RES(x)               (unsigned8 *)((x) + 12)
#define MSDOS_DIR_CRT_TIME_TENTH(x)       (unsigned8 *)((x) + 13)
#define MSDOS_DIR_CRT_TIME(x)             (unsigned16 *)((x) + 14)
#define MSDOS_DIR_CRT_DATE(x)             (unsigned16 *)((x) + 16)
#define MSDOS_DIR_LAST_ACCESS_DATE(x)     (unsigned16 *)((x) + 18)
#define MSDOS_DIR_FIRST_CLUSTER_HI(x)     (unsigned16 *)((x) + 20)
#define MSDOS_DIR_WRITE_TIME(x)           (unsigned16 *)((x) + 22)
#define MSDOS_DIR_WRITE_DATE(x)           (unsigned16 *)((x) + 24)
#define MSDOS_DIR_FIRST_CLUSTER_LOW(x)    (unsigned16 *)((x) + 26)
#define MSDOS_DIR_FILE_SIZE(x)            (unsigned32 *)((x) + 28)

#define MSDOS_DIR_LONG_NAME_ORD(x)		  (unsigned8 *)((x) + 0)	
#define MSDOS_DIR_LONG_NAME_PART1(x)      (unsigned16 *)((x) + 1)
#define MSDOS_DIR_LONG_NAME_ATTR(x)       (unsigned8 *)((x) + 11)
#define MSDOS_DIR_LONG_NAME_TYPE(x)       (unsigned8 *)((x) + 12)
#define MSDOS_DIR_LONG_NAME_CHK_SUM(x)    (unsigned8 *)((x) + 13)
#define MSDOS_DIR_LONG_NAME_PART2(x)      (unsigned16 *)((x) + 14)
#define MSDOS_DIR_LONG_NAME_PART3(x)      (unsigned16 *)((x) + 28)

#define MSDOS_EXTRACT_CLUSTER_NUM(p)                                         \
            (unsigned32)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) |       \
                          ((unsigned32)(CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) )

/*
 * Fields offset in 32 bytes long FAT Directory Entry
 * Structure
 */
#define MSDOS_FILE_SIZE_OFFSET            28
#define MSDOS_FILE_NAME_OFFSET             0
#define MSDOS_FIRST_CLUSTER_HI_OFFSET     20
#define MSDOS_FIRST_CLUSTER_LOW_OFFSET    26
#define MSDOS_FILE_WDATE_OFFSET           24
#define MSDOS_FILE_WTIME_OFFSET           22
#define MSDOS_FILE_NT_RES_OFFSET          12
/*
 * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry
 * Structure
 */
#define MSDOS_ATTR_READ_ONLY    0x01
#define MSDOS_ATTR_HIDDEN       0x02
#define MSDOS_ATTR_SYSTEM       0x04
#define MSDOS_ATTR_VOLUME_ID    0x08
#define MSDOS_ATTR_EXTEND    0x0F
	/* bits that are used by the Windows 95/Windows NT extended FAT */
#define MSDOS_ATTR_DIRECTORY    0x10
#define MSDOS_ATTR_ARCHIVE      0x20

#define MSDOS_DT_2SECONDS_MASK        0x1F    /* seconds divided by 2 */
#define MSDOS_DT_2SECONDS_SHIFT       0
#define MSDOS_DT_MINUTES_MASK         0x7E0   /* minutes */
#define MSDOS_DT_MINUTES_SHIFT        5
#define MSDOS_DT_HOURS_MASK           0xF800  /* hours */
#define MSDOS_DT_HOURS_SHIFT          11

#define MSDOS_DD_DAY_MASK             0x1F    /* day of month */
#define MSDOS_DD_DAY_SHIFT            0
#define MSDOS_DD_MONTH_MASK           0x1E0   /* month */
#define MSDOS_DD_MONTH_SHIFT          5
#define MSDOS_DD_YEAR_MASK            0xFE00  /* year - 1980 */
#define MSDOS_DD_YEAR_SHIFT           9


/*
 * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry
 * Structure
 */
#define MSDOS_THIS_DIR_ENTRY_ILLEGAL		0x20
#define MSDOS_THIS_DIR_ENTRY_EMPTY             0xE5
#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY    0x00
#define MSDOS_DIR_ENTRY_LONG_NAME_FLAG    0x40


#pragma Pack(1)
/* Up to 13 characters of the name */
typedef  struct msdos_dir_slot {
	unsigned8    id;		/* sequence number for slot */
	unsigned16    name0_4[5];	/* first 5 characters in name */
	unsigned8    attr;		/* attribute byte */
	unsigned8    reserved;	/* always 0 */
	unsigned8    alias_checksum;	/* checksum for 8.3 alias */
	unsigned16   name5_10[6];	/* 6 more characters in name */
	unsigned16   start;		/* starting cluster number, 0 in long slots */
	unsigned16    name11_12[2];	/* last 2 characters in name */
}msdos_dir_slot_t;

#pragma Pack()
typedef struct vfat_slot_info {
	unsigned8 long_slots;		       /* number of long slots in filename */
	unsigned32 longname_offset;	       /* dir offset for longname start */
	unsigned32 i_pos;		       /* on-disk position of directory entry */
}vfat_slot_info_t;


/*
 *  Macros for names parsing and formatting
 */
#define msdos_is_valid_name_char(_ch)    (1)
#define msdos_is_separator(_ch)          avfs_filesystem_is_separator(_ch)

#define MSDOS_SHORT_BASE_LEN             8  /* 8 characters */
#define MSDOS_SHORT_EXT_LEN              3  /* 3 characters */
#define MSDOS_SHORT_NAME_LEN             (MSDOS_SHORT_BASE_LEN+\
                                          MSDOS_SHORT_EXT_LEN) /* 11 chars */
#define MSDOS_NAME_MAX                   MSDOS_SHORT_NAME_LEN
#define MSDOS_NAME_MAX_WITH_DOT          (MSDOS_NAME_MAX + 1)
#define MSDOS_LONG_NAME_MAX				 255
#define MSDOS_LONG_NAME_MAX_ENTRY_NUM	 20

#define MSDOS_DOT_NAME     ".          " /* ".", padded to MSDOS_NAME chars */
#define MSDOS_DOTDOT_NAME  "..         " /* "..", padded to MSDOS_NAME chars */

typedef enum msdos_token_types_e 
{
    MSDOS_NO_MORE_PATH,
    MSDOS_CURRENT_DIR,
    MSDOS_UP_DIR,
    MSDOS_NAME,
    MSDOS_INVALID_TOKEN,
    MSDOS_LONG_NAME
} msdos_token_types_t;

/* Others macros */
#define MSDOS_RES_NT_VALUE     0x00
#define MSDOS_INIT_DIR_SIZE    0x00

/* "dot" entry offset in a directory */
#define MSDOS_DOT_DIR_ENTRY_OFFSET       0x00 /* first entry in directory */

/* "dotdot" entry offset in a directory */
#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET    0x20 /* second entry in directory */

/* 'p' should be char* */
#define DOT_NODE_P(p)     ((char *)(p))
#define DOTDOT_NODE_P(p)  ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE))

/* Size limits for files and directories */
#define MSDOS_MAX_DIR_LENGHT               0x200000   /* 2,097,152 bytes */
#define MSDOS_MAX_FILE_SIZE                0xFFFFFFFF /* 4 Gb */

/* 
 * The number of 32 bytes long FAT Directory Entry
 * Structures per 512 bytes sector 
 */ 
#define MSDOS_DPS512_NUM    16

/* Prototypes */
int 
msdos_initialize(avfs_filesystem_mount_table_entry_t *temp_mt_entry);

int 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?