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

📄 pcdisk.h

📁 嵌入式操作系统Nucleus Plus中使用的文件系统
💻 H
📖 第 1 页 / 共 3 页
字号:
	UCOUNT  driveno;            /* Driveno. Set when open succeeds */
	UCOUNT  maxfindex;          /* Last element in the fat */
	BLOCKT  fatblock;           /* First block in fat */
	UCOUNT  secproot;           /* blocks in root dir */
	BOOL    fat_is_dirty;
	BOOL    use_fatbuf;
	FATSWAP fat_swap_structure; /* Fat swap structure if swapping */
	UTINY   *pf;                /* Fat array goes here */
	UTINY   *pdirty;            /* Array to hold what fat blocks to flush*/
	ULONG   bootaddr;
	TEXT    oemname[9];
	UCOUNT  bytspsector;        /* Must be 512 for this implementation */
	UTINY   secpalloc;          /* Sectors per cluster */
	UCOUNT  log2_secpalloc;     /* Log of sectors per cluster */
	UCOUNT  secreserved;        /* Reserved sectors before the FAT */
	UTINY   numfats;            /* Number of FATS on the disk */
	UCOUNT  numroot;            /* Maximum # of root dir entries */
	BLOCKT  numsecs;            /* Total # sectors on the disk */
	UTINY   mediadesc;          /* Media descriptor byte */
	UCOUNT  secpfat;            /* Size of each fat */
	UCOUNT  secptrk;            /* sectors per track */
	UCOUNT  numhead;            /* number of heads */
	BLOCKT  numhide;            /* # hidden sectors */
	UCOUNT  free_contig_base;   /* Guess of where file data would most */
	UCOUNT  free_contig_pointer;/* Efficiently stored */  
	UCOUNT  known_free_clusters;/* If non-zero pc_free may use this value */
	} DDRIVE;

/* Dos Directory Entry Memory Image of Disk Entry */
#define INOPBLOCK 16                /* 16 of these fit in a block */
typedef struct dosinode {
	UTINY    fname[8];
	UTINY    fext[3];
	UTINY   fattribute;         /* File attributes */
	UTINY    resarea[10];
	UCOUNT  ftime;              /* time & date lastmodified */
	UCOUNT  fdate;
	UCOUNT  fcluster;           /* Cluster for data file */
	ULONG   fsize;              /* File size */
	} DOSINODE;


#define x86_SIZEOF_DOSINODE		32	/* sizeof( DOSINODE ) on x86 */

/* x86 buffer version of a DOSINODE */

typedef UTINY x86_DOSINODE_UTINY_BUFFER[x86_SIZEOF_DOSINODE];

    /* Internal representation of DOS entry */
typedef struct finode {
	UTINY   fname[8];
	UTINY   fext[3];
	UTINY   fattribute;         /* File attributes */
	UTINY   resarea[10];
	UCOUNT  ftime;              /* time & date lastmodified */
	UCOUNT  fdate;
	UCOUNT  fcluster;           /* Cluster for data file */
	ULONG   fsize;              /* File size */
	ULONG   alloced_size;       /* Size rounded up to the hearest cluster 
				       (only maintained for files */
	COUNT   opencount;

/* If the finode is an open file the following flags control the sharing.
   they are maintained by po__open                                      */
#define OF_WRITE            0x01    /* File is open for write by someone */
#define OF_WRITEEXCLUSIVE   0x02    /* File is open for write by someone 
				       they wish exclusive write access */ 
#define OF_EXCLUSIVE        0x04    /* File is open with exclusive access not
				       sharing write or read */
	COUNT   openflags;          /* For Files. Track how files have it open */
	DDRIVE  *my_drive;
	BLOCKT  my_block;
	COUNT   my_index;
#if (LOCK_METHOD == 2)
	LOCKOBJ lock_object;        /* for locking during critical sections */
#endif
	struct finode *pnext;       
	struct finode *pprev;
	} FINODE;


/* contain location information for a directory */
typedef struct dirblk {
	BLOCKT  my_frstblock;       /* First block in this directory */
	BLOCKT  my_block;           /* Current block number */
	UCOUNT  my_index;           /* dirent number in my cluster   */
    } DIRBLK;


/* Block buffer */
typedef struct blkbuff {
	struct blkbuff *pnext;
	ULONG lru;
	COUNT locked;       
	DDRIVE *pdrive;
	BLOCKT blockno;
	COUNT  use_count;
	BOOL   io_pending;
	BOOL   io_error;
	UTINY  data[512];
	} BLKBUFF;

/* Object used to find a dirent on a disk and its parent's */
typedef struct drobj {
	DDRIVE  *pdrive;
	FINODE  *finode;
	DIRBLK  blkinfo;
	BOOL    isroot;         /* True if this is the root */
	BLKBUFF *pblkbuff;
	} DROBJ;

/* Date stamping buffer */
typedef struct datestr {
	UCOUNT date;        
	UCOUNT time;
	} DATESTR;

/* Internal file representation */
typedef struct pc_file {
    DROBJ   *pobj;           /* Info for getting at the inode */
    UCOUNT  flag;            /* Acces flags from po_open(). */
    ULONG   fptr;            /* Current file pointer */
    UCOUNT  fptr_cluster;    /* Current cluster boundary for fptr */
    ULONG   fptr_block;      /* Block address at boundary of fprt_cluster */
    BOOL    is_free;         /* If YES this FILE may be used (see pc_memry.c) */
    BOOL    at_eof;          /* True if fptr was > alloced size last time we set
				it. If so synch_file pointers will fix it if the
				file has expanded. */
    } PC_FILE;

/* Structure for use by pc_stat and pc_gfirst, pc_gnext */
typedef struct dstat {
	TEXT    fname[9];           /* Null terminated file and extension */
	TEXT    fext[4];
	UTINY   fattribute;         /* File attributes */
	UCOUNT  ftime;              /* time & date lastmodified. See date */
	UCOUNT  fdate;              /* and time handlers for getting info */
	ULONG   fsize;              /* File size */

	/* INTERNAL */
	UTEXT    pname[9];           /* Pattern. */
	UTEXT    pext[4];
	TEXT    path[EMAXPATH];
	DROBJ   *pobj;                  /* Info for getting at the inode */
	DROBJ   *pmom;                  /* Info for getting at parent inode */
	} DSTAT;


/* User supplied parameter block for formatting: Use with 
   usr/pc_mkfs and tools/pcmkfs.c */
typedef struct fmtparms {
	TEXT    oemname[9];         /* Only first 8 bytes are used */
	UTINY   secpalloc;          /* Sectors per cluster */
	UCOUNT  secreserved;        /* Reserved sectors before the FAT */
	UTINY   numfats;            /* Number of FATS on the disk */
	UCOUNT  secpfat;            /* Sectors per fat */
	UCOUNT  numroot;            /* Maximum # of root dir entries */
	UTINY   mediadesc;          /* Media descriptor byte */
	UCOUNT  secptrk;            /* sectors per track */
	UCOUNT  numhead;            /* number of heads */
	UCOUNT  numcyl;             /* number of cylinders */
	UTINY physical_drive_no;
	ULONG binary_volume_label;
	TEXT  text_volume_label[11];
	} FMTPARMS;


/* INTERNAL !! */
/* Structure to contain block 0 image from the disk */
struct pcblk0 {
	UTINY   jump;               /* Should be E9 or EB on formatted disk */
	TEXT    oemname[9];
	UCOUNT  bytspsector;        /* Must be 512 for this implementation */
	UTINY   secpalloc;          /* Sectors per cluster */
	UCOUNT  secreserved;        /* Reserved sectors before the FAT */
	UTINY   numfats;            /* Number of FATS on the disk */
	UCOUNT  numroot;            /* Maximum # of root dir entries */
	UCOUNT  numsecs;            /* Total # sectors on the disk */
	UTINY   mediadesc;          /* Media descriptor byte */
	UCOUNT  secpfat;            /* Size of each fat */
	UCOUNT  secptrk;            /* sectors per track */
	UCOUNT  numhead;            /* number of heads */
	UCOUNT  numhide;            /* # hidden sectors High word if DOS4 */
	UCOUNT  numhide2;           /* # hidden sectors Low word if DOS 4 */
	ULONG   numsecs2;           /* # secs if numhid+numsec > 32M (4.0) */
	UTINY   physdrv;            /* Physical Drive No. (4.0) */
	UTINY   filler;             /* Reserved (4.0) */
	UTINY   xtbootsig;          /* Extended signt 29H if 4.0 stuf valid */
	ULONG   volid;              /* Unique number per volume (4.0) */
	TEXT    vollabel[11];       /* Volume label (4.0) */
	UTINY   filler2[8];         /* Reserved (4.0) */
	};


/* User structure: Each task that accesses the file system may have one of 
   these structures. The pointer fs_user points to the current user. In 
   a real time exec you might put this in the process control block or
   have an array of them an change the fs_user pointer at task switch time

   Note: Having one of these structures per task is NOT absolutely necessary.
	 If you do not these properties are simply system globals. 

   Code in pc_memory.c and pc_user.c provide a plausible way of managing the
   user structure.
*/

typedef struct file_system_user
{
    INT     p_errno;                 /* error number */
    COUNT   dfltdrv;                 /* Default drive to use if no drive specified */
    DROBJ   *lcwd[NDRIVES];          /* current working dirs */
    CONTEXT_HANDLE_TYPE context_handle;
} FILE_SYSTEM_USER;

typedef FILE_SYSTEM_USER *PFILE_SYSTEM_USER;


/* Error codes */

#define PCERR_FAT_FLUSH 0 /*Cant flush FAT */
#define PCERR_FAT_NULLP 1 /*flushfat called with null pointer */
#define PCERR_FMTCSIZE  2 /*Cluster Size too small for HUGE partition., Can't Format */
#define PCERR_FMTFSIZE  3 /*File allocation Table Too Small, Can't Format */
#define PCERR_FMTRSIZE  4 /*Numroot must be an even multiple of INOPBLOCK */
#define PCERR_FMTWBZERO 5 /*Failed writing block 0  */
#define PCERR_FMTWFAT   6 /*Failed writing FAT block */
#define PCERR_FMTWROOT  7 /*Failed writing root block */
#define PCERR_FMT2BIG   8 /*Total sectors may not exceed 64k.  */
#define PCERR_FSTOPEN   9 /*pc_free_all freeing a file */
#define PCERR_INITMEDI 10 /*Not a DOS disk:pc_dskinit */
#define PCERR_INITDRNO 11 /*Invalid driveno to pc_dskinit */
#define PCERR_INITCORE 12 /*Out of core:pc_dskinit */
#define PCERR_INITDEV  13 /*Can't initialize device:pc_dskinit */
#define PCERR_INITREAD 14 /*Can't read block 0:pc_dskinit */
#define PCERR_BLOCKCLAIM 15 /*PANIC: Buffer Claim */
#define PCERR_INITALLOC  16 /*Fatal error: Not enough core at startup */
#define PCERR_BLOCKLOCK  17 /*Warning: freeing a locked buffer */
#define PCERR_FREEINODE  18 /*Bad free call to freei */
#define PCERR_FREEDROBJ  19 /*Bad free call to freeobj */
#define PCERR_REMINODE   20 /*Trying to remove inode with open > 1 */
#define PCERR_FATCORE    21 /* "Not Enough Core To Load FAT" */
#define PCERR_FATREAD    22 /* "IO Error While Failed Reading FAT" */
#define PCERR_BLOCKALLOC 23 /* "Block Alloc Failure Memory Not Initialized" */
#define PCERR_DROBJALLOC 24 /* "Memory Failure: Out of DROBJ Structures" */
#define PCERR_FINODEALLOC 25  /* "Memory Failure: Out of FINODE Structures" */
/* The next two are only relavent in a multi tasking environment */
#define PCERR_USERS      26  /* Out of User structures increase NUM_USERS */
#define PCERR_BAD_USER   27  /* Trying to use the API without calling 
				pc_rtfs_become_user() first */

/* File creation permissions for open */
/* Note: OCTAL */
#define PS_IWRITE 0000400       /* Write permitted      */
#define PS_IREAD  0000200       /* Read permitted. (Always true anyway)*/


/* File access flags */
#define PO_RDONLY 0x0000                /* Open for read only*/
#define PO_WRONLY 0x0001                /* Open for write only*/
#define PO_RDWR   0x0002                /* Read/write access allowed.*/
#define PO_APPEND 0x0008                /* Seek to eof on each write*/
#define PO_CREAT  0x0100                /* Create the file if it does not exist.*/
#define PO_TRUNC  0x0200                /* Truncate the file if it already exists*/
#define PO_EXCL   0x0400                /* Fail if creating and already exists*/
#define PO_TEXT   0x4000                /* Ignored*/
#define PO_BINARY 0x8000                /* Ignored. All file access is binary*/
#define PO_NOSHAREANY   0x0004          /* Wants this open to fail if already
                                           open.  Other opens will fail while
                                           this open is active */
#define PO_NOSHAREWRITE 0x0800          /* Wants this opens to fail if already
                                           open for write. Other open for
                                           write calls will fail while this

⌨️ 快捷键说明

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