⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 core.h

📁 是一个手机功能的模拟程序
💻 H
📖 第 1 页 / 共 2 页
字号:
    age_t     age_max;         // Max block age found by blocks_fsck()
    iref_t    block_files_max; // max number of files in a block
	iref_t	  block_files_reserved;    // Reserved for journals
    uint16    format;          // FFS version as formatted in flash blocks
    uint16    sequence;        // Object sequence number (for debug only)
    effs_t    initerror;       // ffs_initialize() return code
    uint8     lost_threshold;  // Threshold percentage for data block reclaim
    uint8     flags;           // Global FFS options/flags
    uint8     filename_max;    // Max length of a filename
    uint8     path_depth_max;  // Max path componenents allowed
    uint8     numfds;          // Mumber of available file descriptors
    uint8     testflags;
    int8      journal_depth;   // Current journal nesting depth (0 or 1)
    iref_t    ijournal;        // iref of journal file
    uint32    journal_size;    // Byte size of journal file
    uint32    journal_pos;     // Byte offset to first free entry in journal file
    struct journal_s journal;
    uint8     fd_max;          // number of max available file descriptors
    int       fd_buf_size;     // size of stream buffer
    struct file_descriptor_s fd[FFS_FD_MAX];
    struct journal_s ojournal; // "Old" journal
    int       link_child;      // Link child in journal or not
    iref_t    i_backup;        // Used by ffs_file_write()
    int       chunk_size_max;  // Max size of one chunk
    int       chunk_size_min;  // Min size of one chunk 
    uint32    debug[4];
};

// This is the layout of the FFS performance statistics file. The file is
// created with the name ".statistics" in the root directory at format. It
// is updated after each data and inodes reclaim (after writing the file
// that provoked the reclaim). The file is only updated if it exists, so if
// the user does not want the file, she can erase it after the initial
// format. FIXME: The use of the .statistics file is not yet implemented
struct ffs_stats_s {
    uint32 data_allocated;   // implemented

    struct {                 // Not yet implemented
        uint32 created;
        uint32 updated;
        uint32 read;
    } files;
    struct {                 // Not yet implemented
        uint32 written[2];
        uint32 read[2];
    } bytes;
    struct {
        uint32 most_lost;    // Block candidate
        uint32 most_unused;  // Block candidate
        uint32 youngest;     // Block candidate
        uint32 valid[2];     // Amount of valid reclaimed data 
        uint32 lost[2];      // Amount of lost reclaimed data 
    } drec;
    struct { 
        uint32 num;          // Number of inode reclaims
        uint32 valid;        // Number of valid reclaimed inodes
        uint32 lost;         // Number of lost reclaimed inodes
    } irec;
};
extern struct ffs_stats_s stats;


/******************************************************************************
 * Miscellaneous types
 ******************************************************************************/

// only used with (FFS_TEST == 1)
enum TEST_RECOVERY {
	JOURNAL_TEST_BASE       = 0x10,
    JOURNAL_TEST_EMPTY,
    JOURNAL_TEST_WRITING,
    JOURNAL_TEST_READY,
    JOURNAL_TEST_COMMITTING,
    JOURNAL_TEST_COMMITTED,
    JOURNAL_TEST_DONE,
	BLOCK_COMMIT_BASE       = 0x20,
    BLOCK_COMMIT_BEFORE,
	BLOCK_COMMIT_NO_VALID,
    BLOCK_COMMIT_OLD_FREE,
    BLOCK_COMMIT_AFTER,
	BLOCK_RECLAIM_BASE      = 0x40,
	BLOCK_RECLAIM_ALLOC,
	BLOCK_RECLAIM_CLEANING,
	BLOCK_RECLAIM_NO_CLEAN,
	BLOCK_RECOVER_OBJECTS
};

enum FLASH_DATA {
    FLASH_NULL8  = 0xFF,
    FLASH_NULL16 = 0xFFFF,
    FLASH_NULL32 = 0xFFFFFFFFL,
    IREF_NULL    = FLASH_NULL16
 };


// This enum MUST be in sync with the one in ffs.h.
enum OBJECT_CONTROL {
    // remaining object control codes are in ffs.h
    OC_FS_FLAGS       =  80,
    OC_TRACE_INIT     =  82,
    OC_DEV_MANUFACT   =  88,
    OC_DEV_DEVICE     =  89,

    OC_DEBUG_FIRST    = 120,
    OC_DEBUG_0        = 120,
    OC_DEBUG_1        = 121,
    OC_DEBUG_2        = 122,
    OC_DEBUG_3        = 123,
    OC_DEBUG_LAST     = 123,

    OC_FS_TESTFLAGS   = 127
};

enum FS_FLAGS {
    FS_DIR_DATA   = 0x01   // allow directory objects to contain data.
};

enum RECLAIM_CANDIDATE {
    MOST_LOST,
    MOST_UNUSED,
    YOUNGEST
};

/******************************************************************************
 * Macros
 ******************************************************************************/

// Convert between location and offset
#define location2offset(location) ((location) << dev.atomlog2)
#define offset2location(offset) (((uint32) offset) >> dev.atomlog2)

// test if object is of a specific type
#define is_object(objp, type) (((objp)->flags & OT_MASK) == (type))

// test if object is valid (directory, file or symlink)
#define is_object_valid(ip) ((ip->flags & OT_MASK) <= OT_MAX && (ip->flags & OT_MASK) != OT_ERASED)

// test if block is in a specific state
#define is_block(block, state) (bstat[block].flags == (uint16) (state))

// test if block has certain flags set
#define is_block_flag(block, bits) (IS_BIT_SET(bstat[block].flags, (bits)))

// convert an object's data address to the address of the object's name
#define addr2name(addr) (addr)

// Convert a size to an aligned size
#define atomalign(size) (((size) + dev.atomsize-1) & ~dev.atomnotmask)
#define wordalign(size) (((size) + 3) & ~3)
#define halfwordalign(size) (((size) + 1) & ~1)

#define inode_addr(i)   (fs.inodes_addr + i)

#define JOURNAL_POS_INITIAL (wordalign(2 + sizeof(FFS_JOURNAL_NAME) + 1))


/******************************************************************************
 * Function prototypes
 ******************************************************************************/

// Helper functions

effs_t is_filename(const char *s);
int ffs_strlen(const char *s);
int ffs_strcmp(const char *s, const char *p);
char *addr2data(const char *addr, const struct inode_s *ip);

int object_datasize(iref_t i);
iref_t is_readonly(iref_t i, const char *name);
iref_t dir_traverse(iref_t i, iref_t *entries);

bref_t block_alloc(bref_t n, uint16 flags);
bref_t block_alloc_try(bref_t *n);
void block_flags_write(uint8 block, uint8 flags);

offset_t data_alloc(int size);
offset_t data_alloc_try(int size);
offset_t data_reserved_alloc(int size);

iref_t inode_alloc(void);

effs_t is_fd_valid(fd_t fdi);
effs_t is_offset_in_buf(int offset, fd_t fdi);

iref_t chunk_alloc(int realsize, int is_journal, offset_t *offset);  

iref_t inode_alloc_try(void);
fd_t get_fdi(iref_t i);

offset_t data_prealloc(int realsize);

// Functions used by API

effs_t object_update(iref_t oldi);
iref_t object_create(const char *name, const char *buf, int size,
                         iref_t dir);
int file_read(const char *name, void *addr, int size);
int stream_read(fd_t fdi, void *src, int size);
int object_read(const char *name, char *buf, int size, int linkflag);

iref_t object_stat(const char *name, struct xstat_s *stat,
                       int linkflag, int fdi, int extended);
effs_t object_remove(iref_t i);
iref_t object_rename(iref_t oldi, const char *newname, iref_t newdir);
effs_t object_control(iref_t i, int8 action, int value);
int object_truncate(const char *pathname, fd_t fdi, offset_t length);
iref_t object_lookup(const char *path, char **leaf, iref_t *dir);
iref_t object_lookup_once(const char *path, char **leaf, iref_t *dir);
iref_t dir_open(const char *name);
iref_t dir_next (iref_t dir, iref_t i, char *name, int8 size);


// Journalling

void journal_begin(iref_t oldi);
void journal_end(uint8 type);
void journal_commit(uint8 type);
int journal_push(void);
int journal_pop(void);
iref_t journal_create(iref_t oldi);
effs_t journal_init(iref_t i);


// Format, Init and Reclaim

void block_preformat(bref_t b, age_t age);
effs_t fs_preformat(void);
effs_t is_formattable(int8 flag);
effs_t fs_format(const char *fsname_and_options);

effs_t ffs_initialize(void);
void fs_params_init(const char *p);
blocksize_t block_used(bref_t b);

effs_t ffs_begin(void);
int ffs_end(int error);

int block_reclaim(bref_t b);
int blocks_reclaim(void);
void block_commit(void);

iref_t data_reclaim(int space);
int data_reclaim_try(int space);
iref_t data_block_reclaim(bref_t b, int reclaim_candidate);
iref_t object_relocate(iref_t oldi);
iref_t block_clean(bref_t b);

void block_free(bref_t block);

void inodes_set(iref_t i);
effs_t inodes_reclaim(void);

int reclaim(void);

// Internally used functions

effs_t file_read_int(const char *path, void *src, int size);
effs_t file_update(const char *path, void *src, int size);

int statistics_file_create(void);
int statistics_write(void);
void statistics_init(void);
void statistics_update_drec(int valid, int lost, int candidate);
void statistics_update_irec(int valid, int lost);

// Chunk Operations
iref_t segment_create(const char *buf, int size, iref_t dir);
int segment_datasize(const struct inode_s *ip);
int segment_read(iref_t i, char *buf, int size, int offset);
iref_t segment_next(iref_t i);
iref_t segment_traverse(iref_t i, iref_t *entries);
int segfile_seek(iref_t in_i, int in_pos, 
                     iref_t *out_i, int *out_pos_i);
iref_t chunk_traverse(iref_t i);
effs_t datasync(fd_t fdi);
// debug/test functions

void tr_bstat(void);
void tr_fd(fd_t fdi);

// These prototypes really belong in ffs.h but as they have not been
// implemented, we will not show these prototypes to application
// programmers.
effs_t fcntl(fd_t fd, int8 action, uint32 *param);










⌨️ 快捷键说明

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