📄 xilmfs.h
字号:
//////////////////////////////////////////////////////////////////////////////////// Copyright (c) 2002 Xilinx, Inc. All rights reserved.//// Xilinx, Inc.// // File : xilmfs.h// Date : 2002, March 20.// Company: Xilinx// Group : Emerging Software Technologies//// Description : //// $Header: /devl/xcs/repo/env/Jobs/MDT/sw/os/xilmfs/src/xilmfs.h,v 1.1 2002/04/08 20:40:54 sid Exp $//////////////////////////////////////////////////////////////////////////////////#ifndef MFS_FILESYS_H#define MFS_FILESYS_H// Increase the number of blocks to increase the size of the filesystem#define MFS_MAX_FILE_BLOCKS 5/* MFS_BLOCK_DATA_SIZE and MFS_MAX_LOCAL_ENT are related. see block_data union */#define MFS_BLOCK_DATA_SIZE 512#define MFS_MAX_LOCAL_ENT 8#define MFS_BLOCK_TYPE_DIR 2#define MFS_BLOCK_TYPE_FILE 1#define MFS_BLOCK_TYPE_EMPTY 0#define MFS_MAX_FILENAME_LENGTH 15/** * dir entry contains file name and index of first file block * mfs_dir_entry_blocks are contained in a mfs_dir_block */struct mfs_dir_ent_block { char name[MFS_MAX_FILENAME_LENGTH]; char deleted; /* value ='y' for deleted files and dirs, 'n' otherwise */ unsigned int index;};/** * a mfs_dir_block is contained within a mfs_file_block * each mfs_dir_block contains at least 1 entry (its parent dir) * each dir block can contain at most MFS_MAX_LOCAL_ENT physical entries * If num_entries > MFS_MAX_LOCAL_ENT, there must be some * continuation blocks indexed by the next_block entry of the mfs_file_block */struct mfs_dir_block { short num_entries; short num_deleted; struct mfs_dir_ent_block dir_ent[MFS_MAX_LOCAL_ENT];};/** * mfs_file_block is the basic unit of the file system * each block has a type identifier to identify the block as * being part of a file a directory or empty * each block has pointers to the next and prev blocks if any, * in the file/dir/free-list */struct mfs_file_block { unsigned short block_size; /* has meaning for data files only */ unsigned short block_type; /* 0 = dir, 1 = file, 2 = empty */ unsigned int next_block; /* points to (index of) next block if any */ unsigned int prev_block; /* points to (index of) previous block if any */ unsigned int index; /* index of this block */ union { unsigned char block_data[MFS_BLOCK_DATA_SIZE]; struct mfs_dir_block dir_data; }u;} ;#define MFS_MAX_OPEN_FILES 20#define MFS_MODE_READ 0#define MFS_MODE_WRITE 1/* MFS_MODE_CREATE creates a new file and opens it with MFS_MODE_WRITE */#define MFS_MODE_CREATE 3#define MFS_MODE_FREE 8struct mfs_open_file_struct { unsigned int first_block; /* first block of file */ unsigned int current_block; /* currently accessed block */ unsigned short offset; /* current offset within block */ unsigned short mode ; /* read or write */} ;extern struct mfs_file_block mfs_file_system[MFS_MAX_FILE_BLOCKS];extern int mfs_free_block_list;extern int mfs_current_dir;extern struct mfs_open_file_struct mfs_open_files[MFS_MAX_OPEN_FILES];extern int mfs_num_open_files; /* the number of open_files *//** * initialize the file system; * this function must be called before any file system operations */void mfs_init_fs() ;/** * modify mfs_current_dir to index of newdir if it exists * mfs_current_dir is not modified otherwise * return 1 for success and 0 for failure */int mfs_change_dir(const char *newdir) ;/** * delete the data blocks corresponding to the file and then delete the * file entry from its directory * return 1 on success, 0 on failure * delete will not work on a directory unless the directory is empty */int mfs_delete_file (char *filename) ;/** * create a new empty directory inside the current directory * return index of new directory in file system if success, 0 if failure */int mfs_create_dir(char *newdir);/** * delete the directory named newdir if it exists, and is empty * return 1 on success, 0 on failure * cannot delete . or .. */int mfs_delete_dir (char *newdir) ;/** * rename from_file to to_file * works for dirs as well as files * cannot rename to something that already exists * return 1 on success, 0 on failure */int mfs_rename_file(char *from_file, char *to_file);/** * return 0 if filename is not a file in the current directory * return 1 if filename is a file in the current directory * return 2 if filename is a directory in the current directory */int mfs_exists_file(char *filename);/** * return the name of the current directory * in a pre_allocated buffer of at least 16 chars * return 1 if success, 0 if failure */int mfs_get_current_dir_name(char *dirname);/** * get the number of used blocks and the number of free blocks in the file system through pointers * the return value is 1 (for success) and 0 for failure to obtain the numbers */int mfs_get_usage(int *num_blocks_used, int *num_blocks_free); /** * mode can be MODE_READ/MODE_WRITE/MODE_CREATE * this function should be used for FILEs and not DIRs * no error checking (is this FILE and not DIR?) is done for MODE_READ * MODE_CREATE automatically creates a FILE and not a DIR * MODE_WRITE fails if the specified file is a DIR * return index of file in array open_files or -1 */int mfs_file_open(const char *filename, int mode) ;/** * fd should be a valid index in open_files array * Works only if fd points to a file and not a dir * buf should be a pointer to a pre-allocated buffer of size buflen or more * buflen chars are read and placed in buf * if fewer than buflen chars are available then only that many chars are read * return num bytes read or 0 for error=no bytes read */int mfs_file_read(int fd, char *buf, int buflen) ;/** * fd should be a valid index in open_files array * buf should be a pointer to a pre-allocated buffer of size buflen or more * buflen chars are read from buf and written to 1 or more blocks of the file * return 1 for success or 0 for error=unable to write to file*/ int mfs_file_write (int fd, const char *buf, int buflen) ;/** * recover the file table entry in open_files corresponding to the fd * if the fd is not valid, return 0 * fd is not valid if the index in open_files is out of range, or * if the corresponding entry is not an open file * return 1 on success */int mfs_file_close(int fd);#define MFS_SEEK_SET 0#define MFS_SEEK_CUR 1#define MFS_SEEK_END 2/** * seek to a given offset within the file * if MFS_SEEK_END is specified, the offset can be either 0 or negative * otherwise offset should be positive or 0 * return 0 on failure, 1 on success * it is an error to seek before beginning of file or after the end of file */long mfs_file_lseek(int fd, long offset, int whence);#endif MFS_FILESYS_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -