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

📄 filemgr.h

📁 T-kernel 的extension源代码
💻 H
字号:
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	filemgr.h (file) * *	File management *	Common definition */#ifndef _FM_FILEMGR_H_#define _FM_FILEMGR_H_#define DEBUG_MODULE	"(file)"#include <basic.h>#include <tk/tkernel.h>#include <tk/util.h>#include <extension/errno.h>#include <extension/file.h>#include <extension/device.h>#include <sys/diskform.h>#include <sys/pinfo.h>#include <sys/util.h>#include <device/disk.h>#include <libstr.h>#include <tstring.h>#include <sys/queue.h>#include <sys/debug.h>#include "defproc.h"typedef	UH		FID;				/* File ID */typedef	WER		ID_ERR;				/* ID or error code */#define InvalidID		(0)			/* Invalid ID */#define	TC_NULL			( (TC*)"\0" )		/* TC null character string */#ifdef GHS#define	NIL			{0}			/* No/Zero */#else#define	NIL			{}			/* No/Zero */#endif#define	KB			1024			/* Unit: KB *//* * Error code related */#define	EC_MASK			(0xffff0000)#define	ED_MASK			(0x0000ffff)#define	toERR(class,detail)	((ER)(((UW)(class) << 16) | ((UW)(detail) & 0x0000ffffU)))/* Error code for the internal processing of the file management */#define	EC_FMGR			0x8000			/* File management error class */#define	EFM_RETRY		toERR(EC_FMGR, 1)	/* Retry *//* * Device name */#define	DevNameLen		(L_DEVNM)typedef	TC		DevName[DevNameLen];/* * Connection name */#define	ConNameLen		(L_CONNM)typedef TC		ConName[ConNameLen];/* * File system name */#define	FsNameLen		(L_FSNM)typedef TC		FsName[FsNameLen];/* * File name */#define	FileNameLen		(L_FNM)typedef TC		FileName[FileNameLen];/* * Path name */#define	PathNameLen		(L_PATHNM)typedef TC		PathName[PathNameLen];#define	PathTokenLen		(L_FNM + 1 + 5)	/* File name : Occurrence order */typedef TC		PathToken[PathTokenLen+1];/* * Password */#define	PassWordLen		(12)typedef TC		PassWord[PassWordLen];/* * User name/Group name/Hidden name */#define	UserNameLen		(L_USRNM)typedef	TC		UserName[UserNameLen];#define	HideNameLen		(2)typedef TC		HideName[HideNameLen];#define	OpenNameLen		(UserNameLen - HideNameLen)/* * Disk address *	offset is the offset from the start of the logical block of lblk, *	and it may exceed the logical block size. *	However, it is not located before the logical block of lblk (Minus value). * *	lblk == 0 shows that it is a invalid address. *	Note: offset == 0 (NULL) shows that it is a valid address. */typedef struct {	VP	offset;		/* Offset from the start of the logical block */	UW	lblk;		/* Logical block number */} DskAdr;/* * Comparison of the disk addresses *	It is assumed that the disk address is normalized (offset is under the logical block size). */Inline W CmpDskAdr( DskAdr a, DskAdr b ){	W i = a.lblk - b.lblk;	if ( i == 0 ) {		i = (W)a.offset - (W)b.offset;	}	return i;}/* * Disk short address *	The byte position from the start of the disk (Logical block 0) *	(Disk address) / (Logical block size) *		= (Logical block number)   Remainder (Byte offset in the block) * *	Only the range of 4GB from the start of the disk can be specified. *	Therefore, use it only for the management information at the start of the disk *	(System file header, used block bit map, file ID table, and *	file abbreviated name table) */typedef VP	DskAdrS;/* * Address of the record index. */typedef struct IdxAdr {	DskAdr	ridx;			/* Location of the record index */	DskAdr	iidx[MaxIndexLevel];	/* Location of the indirect index */} IdxAdr;/* * Logical block address + Offset */typedef struct LogAdr {	UW	blk;	/* Block number */	UW	offset;	/* Offset in the block */} LogAdr;/* * Try/Retrieve the next boot block size. *	In the real storage system, it is supported by the segment management. *	The maximum logical block size is restricted to 4KB or less. */#if VIRTUAL_ADDRESS#define	StdBootBlkSizeList	{ 1 * KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB, 32 * KB }#else#define	StdBootBlkSizeList	{ 1 * KB, 2 * KB, 4 * KB }#endif/* * 1 when supporting boot block size != logical block size. */#define	MisalignLogBlk		1/* * File system format */typedef enum {	DiskForm_A	= 0x0000,	/* STDFS Standard format */	DiskForm_B	= 0x0001,	/* STDFS Extended format 1 */	DiskForm_C	= 0x0002	/* STDFS Extended format 2 */} DiskForm;/* * File type */#define	isLinkFile(ftype)	( ((ftype) & 0xf000U) == 0 )#define	isNormFile(ftype)	( ((ftype) & 0xf000U) == F_FILE )/* * Record type */#define	isLinkRecord(rtype)	( (rtype) == 0 )#define	isDataRecord(rtype)	( (rtype) != 0 )/* * TRUE when LINK is not defined. */#define	isUndefLink(lnk)	( (lnk)->fs_name[0] == 0 )#define	setUndefLink(lnk)	( (lnk)->fs_name[0] = (TC)0 )/* * Byte swap */Inline UH swapH( UH x ){	return (x << 8) | (x >> 8);}Inline UW swapW( UW x ){	return ((UW)swapH((UH)x) << 16) | swapH((UH)(x >> 16));}Inline UW swap3B( UW x )	/* Swap of 3Byte (24bit) */{	return ((x & 0x0000ff) << 16) | (x & 0x00ff00) | ((x & 0xff0000) >> 16);}/* * Access the misalignment data. */Inline UW getMisalignW( UH d[2] ){#if ALLOW_MISALIGN	return *(UW*)d;#else	UW	x;#if BIGENDIAN	x = ((UW)d[0] << 16) | d[1];#else	x = ((UW)d[1] << 16) | d[0];#endif	return x;#endif}Inline void setMisalignW( UH d[2], UW x ){#if ALLOW_MISALIGN	*(UW*)d = x;#else#if BIGENDIAN	d[0] = x >> 16;	d[1] = x;#else	d[1] = x >> 16;	d[0] = x;#endif#endif}Inline UH getMisalignH( UB d[2] ){#if ALLOW_MISALIGN	return *(UH*)d;#else	UH	x;#if BIGENDIAN	x = ((UH)d[0] << 8) | d[1];#else	x = ((UH)d[1] << 8) | d[0];#endif	return x;#endif}Inline void setMisalignH( UB d[2], UH x ){#if ALLOW_MISALIGN	*(UH*)d = x;#else#if BIGENDIAN	d[0] = x >> 8;	d[1] = x;#else	d[1] = x >> 8;	d[0] = x;#endif#endif}/* * Rotate shift one bit to right */Inline UW ROR1( UW x ){	/* You don't need to use the inline assembler.	   Compiler generates the rotate command. */	return (x >> 1) | (x << 31);}/* * And all the rest */#define	max(a,b)	(( (a) > (b) )? (a): (b))#define	min(a,b)	(( (a) < (b) )? (a): (b))#define xchg(t,a,b)	{ t _tmp; _tmp = (a); (a) = (b); (b) = _tmp; }/* ------------------------------------------------------------------------ *//* * Task priority *	(*) Default value *	   Actually, it is obtained from the system configuration information. */typedef enum {	FmMgrTaskPriority	= 100,	FmFsTaskPriority	= 100} FmPriority;/* * Manager task (Common section task) attribute */Inline void SetMgrTaskAttr( T_CTSK *ctsk, PRI itskpri ){	IMPORT void fmcMgrTask( UINT calptn );	SetOBJNAME(ctsk->exinf, "FMgr");	ctsk->task    = fmcMgrTask;	ctsk->itskpri = itskpri;	ctsk->stksz   = 3*1024;	ctsk->sstksz  = 0;	ctsk->tskatr  = TA_HLNG|TA_RNG0;}/* * File system task (Individual section task) attribute */Inline void SetFsTaskAttr( T_CTSK *ctsk, VP fsinfo, PRI itskpri ){	IMPORT void fmpFsTask( ID port, VP fsinfo );	ctsk->exinf   = fsinfo;	ctsk->task    = fmpFsTask;	ctsk->itskpri = itskpri;	ctsk->stksz   = 3*1024;	ctsk->sstksz  = 0;	ctsk->tskatr  = TA_HLNG|TA_RNG0;}/* ------------------------------------------------------------------------ */#endif

⌨️ 快捷键说明

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