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

📄 fatfs.h

📁 一个小型的操作系统,采用gcc进行开发,几千行的代码,方便初学者学习
💻 H
字号:
/**  Snixos Project version 1.0, 2003.6*  (C) Copyright 2003,2004,2005 Jockeyson,KeqiangGao <Snallie@tom.com>*  All Rights Reserved.*  Distributed under the terms of the GNU General Public License.**  This program is a free and open source software and you can redistribute *  it and/or modify it under the terms of the GNU General Public License as*  published by the Free Software Foundation. As no any liablity is assumed *  for any incidental or consequential damages in connection with the *  information or program fragments contained herein,so any exception arised*  is at your own risk. It is ABSOLUTELY WITHOUT ANY WARRANTY.*  Bug report please send to Snallie@tom.com .*//*  fatfs.h: header file for FAT file system implemented in fatfs.c for Snixos Project  Author : Snallie@tom.com  Time   : 2003.6*/#ifndef _FATFS_H#define _FATFS_H#define BLKSIZE 512#define BLKCOUNT 1024*2#define VACANT_FAT_ITEM 0X00#define EOF_FAT_ITEM -1#define ERASED 0XE5#define ROOTSIZE 20#define FILE_NAME_LENGTH 32typedef struct {    char filename[FILE_NAME_LENGTH];    int filesize;    int firstfat;    int datetime;} direntry;char *diskspace;int *fat_tab;direntry *dir_tab;void initfat_tab(int *fat);void initdir_tab(direntry * dir);void listdir(direntry * dir);int seekfat(int *fat);int seekdir_tab(direntry * dir);int wrdir_tab(direntry * dirs, char *fnames, int fsizes, int firstfat);int getfilefromos(char *fname, char *buf);int wrfile(char *fnames, char *bufs, int flen);int readdir(char *fnames, direntry * dirs);void wrsect(char *data, int sectno, int bytes);void fillfat_tab(int *fat_tab, int fatno, int fatdata);int rdfile(char *fnames, char *outputbuf);int rdsect(int sectno, int cnt, char *outputbuf);char *strlwr(char *str);char *strupr(char *str);void freefat(int firstfat);int freedir(char *fname);int nextfat(int prevfat);void initFileSystem();void listFat();int copyFile(char *srcFileName, char *dstFileName);void fsver();/*open read write close */// unbuffered file ioint errno;                      // global variable to save errno number while any error occured in operationtypedef enum errNums {    ENAMETOOLONG,    ENAMEVACANT,    ENOSUCHFILE,    EMALLOC,    ENOFILEDESC} errNum;typedef enum openModes {    READONLY, WRITEONLY, READWRITE, CREATEWRITE} openMode;typedef enum seekFrom {    SEEK_SET1, SEEK_CUR1, SEEK_END1} seekWhence;#define OPEN_MAX 20#define FREED 0#define OCCUPIED 1typedef struct fileDesc {    int fileHdl;                // file handler ,a mutual exclusive positive integer    char fileName[FILE_NAME_LENGTH];    int curPosition;            // r/w pointer    char *IObuffer;             // buffer for file    int fileLen;                // file size    int eof;                    // flag of EOF, 1,reach EOF    int IOMode;                 //readonly, writeonly, read/write    int status;                 // 0 freed, 1 occupied} fileDescriptor;// end of unbuffered file io/////////////////////////////////////////////// standard file IO function based above ones// fopen fclose getc putc////////////////////////////////////////////typedef struct files {    fileDescriptor *fd;} MFILE;int Mopen(char *pathname, openMode oflags);int Mclose(int fds);int Mread(int fds, char *buff, int nbytes);int Mseek(int fds, int offset, int whence);int Mwrite(int fds, char *buff, int nbytes);void perrstr();MFILE *Mfopen(char *fileName, char *mode);int Mfclose(MFILE * fstream);char Mfgetc(MFILE * fstream);int Mfeof(MFILE * fstream);int Mfputc(char c, MFILE * fstream);int Mfseek(MFILE * fstream, int offset, int whence);void testread(char *fname);void testas(char *fileName);#define fopen Mfopen#define fclose Mfclose#define fgetc Mfgetc#define feof Mfeof#define fputc Mfputc#define fseek Mfseek#define FILE MFILE#define getc fgetc#define putc fputc/* end of open read write close */#endif

⌨️ 快捷键说明

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