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

📄 filesys.c

📁 T-kernel 的extension源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		/* Already connected: Obtain the connection information from FsInfo. */		err = CheckFS(dev, omode, pinfo);		if ( err < E_OK ) {			goto err_ret1;		}		/* It must work in exclusive of the file system task. */		Lock(&(*fs)->lock);		diskid    = (*fs)->dskid;		*diskinfo = (*fs)->dskInfo;	}	return diskid;err_ret2:	(void)DetachFS(diskid, NULL, FALSE);err_ret1:	DEBUG_PRINT(("attachDevice err = %d\n", err));	return err;}/* * Disconnect the disk device. *	When fs != NULL, perform only the lock release of the file system task. */LOCAL ER detachDevice( ID diskid, FsInfo *fs ){	ER	err;	if ( fs == NULL ) {		/* Disconnect */		err = DetachFS(diskid, NULL, FALSE);		if ( err < E_OK ) {			goto err_ret;		}	} else {		/* Lock release */		Unlock(&fs->lock);	}	return E_OK;err_ret:	DEBUG_PRINT(("detachDevice err = %d\n", err));	return err;}/* * Check the file header ID of the root file. */LOCAL ER checkRootFileHeaderID( DfSystemHeader *sh, DiskMapInfo *dmInfo ){	DfFileHeader	*fh;	ID		mid;	W		chk;	ER		err;	/* Map the header of the root file. */	fh = fmcMapRootFileHeader(sh, dmInfo, &mid);	if ( fh == NULL ) {		err = (ER)mid;		goto err_ret;	}	/* Check the file header ID. */	chk = ( (fmConvEndianW(fh->startid, dmInfo->big) == FileHeaderTopID)	     && (fmConvEndianW(fh->endid,   dmInfo->big) == FileHeaderEndID) )?							E_OK: E_ILFMT;	err = fmcUnmapDisk(mid, MD_RDONLY);	if ( err < E_OK ) {		goto err_ret;	}	return chk;err_ret:	DEBUG_PRINT(("checkRootFileHeaderID err = %d\n", err));	return err;}/* * Read the file system management information. */LOCAL void getFileSystemStatus( FS_STATE *fs, DfSystemHeader *sh, BOOL big ){	/* Obtain the management information. */	fs->fs_bsize = fmConvEndianH(sh->sblk, big);	fs->fs_nfile = fmConvEndianH(sh->nfmax, big);	fs->fs_lang  = (H)fmConvEndianH((UH)sh->lang, big);	fs->fs_level = (H)fmConvEndianH((UH)sh->acclv, big);	fs->fs_nblk  = (W)fmConvEndianW((UW)sh->nlb, big);	fs->fs_nfree = (W)fmConvEndianW((UW)sh->nflb, big);	fs->fs_mtime = (W)fmConvEndianW((UW)sh->mtime, big);	fs->fs_ctime = (W)fmConvEndianW((UW)sh->ctime, big);	(void)fmConvEndianTC(fs->fs_name,  (TC*)sh->fsnm,  L_FSNM, big);	(void)fmConvEndianTC(fs->fs_locat, (TC*)sh->devnm, L_DLNM, big);}/* * fls_sts: Obtain the file system management information. */EXPORT void fmcGetFileSystemStatus( FmCmdPkt *pkt ){	FM_FLS_STS_PARA	*cmdPara = (FM_FLS_STS_PARA*)pkt->cmd.para;	DiskMapInfo	dmInfo;	FsInfo		*fs;	DfSystemHeader	*sh;	ID		mid;	ER		err;	/* Parameter check */	err = CheckStrSpaceR(cmdPara->dev, DevNameLen);	if ( err < E_OK ) {		goto err_ret1;	}	err = CheckSpaceRW(cmdPara->buff, sizeof(FS_STATE));	if ( err < E_OK ) {		goto err_ret1;	}	/* Connect the file system. */	err = attachDevice(cmdPara->dev, D_ATTACH|D_WEXCL, pkt->wrk.pinfo,							&dmInfo.dskInfo, &fs);	if ( err < E_OK ) {		goto err_ret1;	}	dmInfo.dskid = (ID)err;	/* Map the system header. */	sh = fmcMapFileSystemHeader(&dmInfo, fs, &mid);	if ( sh == NULL ) {		err = (ER)mid;		goto err_ret2;	}	/* Check the file header ID of the root file. */	err = checkRootFileHeaderID(sh, &dmInfo);	if ( err < E_OK ) {		goto err_ret3;	}	/* Obtain the management information. */	getFileSystemStatus(cmdPara->buff, sh, (BOOL)dmInfo.big);	err = fmcUnmapDisk(mid, MD_RDONLY);	if ( err < E_OK ) {		goto err_ret2;	}	/* Disconnect the file system. */	err = detachDevice(dmInfo.dskid, fs);	if ( err < E_OK ) {		goto err_ret1;	}	pkt->cmd.ret = ( dmInfo.dskInfo.protect != 0 )? 1: 0;	return;err_ret3:	(void)fmcUnmapDisk(mid, MD_RDONLY);err_ret2:	(void)detachDevice(dmInfo.dskid, fs);err_ret1:	DEBUG_PRINT(("fmcGetFileSystemStatus err = %d\n", err));	pkt->cmd.ret = err;	return;}/* * Change the root file name. */LOCAL ER changeRootFileName( FileName fname,				DfSystemHeader *sh, DiskMapInfo *dmInfo ){	DfFileHeader	*fh;	DfShortName	*sn;	STIME		now;	ID		mid;	ER		err;	/* Map the header of the root file. */	fh = fmcMapRootFileHeader(sh, dmInfo, &mid);	if ( fh == NULL ) {		err = (ER)mid;		goto err_ret;	}	/* Change the file name. */	(void)fmConvEndianTC((TC*)fh->name, fname, FileNameLen, dmInfo->big);	/* Update the date/time of access. */	now = fmGetTime();	fh->atime = (W)fmConvEndianW((UW)now, dmInfo->big);	err = fmcUnmapDisk(mid, MD_WRITE);	if ( err < E_OK ) {		goto err_ret;	}	/* Map the root file abbreviated name. */	sn = fmcMapRootFileShortName(sh, dmInfo, &mid);	if ( sn == NULL ) {		err = (ER)mid;		goto err_ret;	}	/* Change the file abbreviated name. */	*sn = fmConvEndianW(fmShortFileName(fname), dmInfo->big);	err = fmcUnmapDisk(mid, MD_WRITE);	if ( err < E_OK ) {		goto err_ret;	}	return E_OK;err_ret:	DEBUG_PRINT(("changeRootFileName err = %d\n", err));	return err;}/* * Change the file system information. *	When the system block is changed (written), return MD_WRITE to *mdflg. *	If not changed, the contents of *mdflg are not changed. */LOCAL ER changeFileSystemInfo( TC *fsnm, TC *dlnm, FsInfo *fs,			DfSystemHeader *sh, DiskMapInfo *dmInfo, UW *mdflg ){	UW		mflag = MD_RDONLY;	STIME		now;	ER		err;	/* File system name */	if ( fsnm != NULL ) {		FsInfo	*p;		/* Check the file system name. */		err = CheckStrSpaceR(fsnm, L_FSNM);		if ( err < E_OK ) {			goto err_ret;		}		err = fmCheckFileName(fsnm, L_FSNM);		if ( err < E_OK ) {			goto err_ret;		}		/* Whether the file system of the same name is connected. */		p = fmSelectFileSystemOfFsName(fsnm);		if ( (p != NULL) && (p != fs) ) {			err = E_OBJ;			goto err_ret;		}		/* Change the root file name. */		err = changeRootFileName(fsnm, sh, dmInfo);		if ( err < E_OK ) {			goto err_ret;		}		/* Change file system name. */		(void)fmConvEndianTC((TC*)sh->fsnm, fsnm, L_FSNM, dmInfo->big);		if ( fs != NULL ) {			tc_strncpy(fs->fsName, fsnm, L_FSNM);		}		mflag = MD_WRITE;	}	/* Device location name */	if ( dlnm != NULL ) {		/* Check the device location name. */		err = CheckStrSpaceR(dlnm, L_DLNM);		if ( err < E_OK ) {			goto err_ret;		}		/* Change the device location name. */		(void)fmConvEndianTC((TC*)sh->devnm, dlnm, L_DLNM, dmInfo->big);		mflag = MD_WRITE;	}	if ( mflag != MD_RDONLY ) {		/* Update the date/time of system block update. */		now = fmGetTime();		sh->mtime = (W)fmConvEndianW((UW)now, dmInfo->big);		*mdflg = mflag;	}	return E_OK;err_ret:	if ( mflag != MD_RDONLY ) {		*mdflg = mflag;	}	DEBUG_PRINT(("changeFileSystemInfo err = %d\n", err));	return err;}/* * chg_fls: Change the file system information. */EXPORT void fmcChangeFileSystemInfo( FmCmdPkt *pkt ){	FM_CHG_FLS_PARA	*cmdPara = (FM_CHG_FLS_PARA*)pkt->cmd.para;	DiskMapInfo	dmInfo;	FsInfo		*fs;	DfSystemHeader	*sh;	ID		mid;	UW		mflag = MD_RDONLY;	ER		err;	/* Parameter check */	err = CheckStrSpaceR(cmdPara->dev, DevNameLen);	if ( err < E_OK ) {		goto err_ret1;	}	/* Connect the file system. */	err = attachDevice(cmdPara->dev, D_ATTACH|D_WRITE|D_WEXCL,					pkt->wrk.pinfo, &dmInfo.dskInfo, &fs);	if ( err < E_OK ) {		goto err_ret1;	}	dmInfo.dskid = (ID)err;	/* Whether it is write protected. */	if ( dmInfo.dskInfo.protect != 0 ) {		err = E_RONLY;		goto err_ret2;	}	/* Map the system header. */	sh = fmcMapFileSystemHeader(&dmInfo, fs, &mid);	if ( sh == NULL ) {		err = (ER)mid;		goto err_ret2;	}	/* Check the file header ID of the root file. */	err = checkRootFileHeaderID(sh, &dmInfo);	if ( err < E_OK ) {		goto err_ret3;	}	/* Change the file system information. */	err = changeFileSystemInfo(cmdPara->fs_name, cmdPara->fs_locate, fs,							sh, &dmInfo, &mflag);	if ( err < E_OK ) {		goto err_ret3;	}	err = fmcUnmapDisk(mid, mflag);	if ( err < E_OK ) {		goto err_ret2;	}	/* Disconnect the file system. */	err = detachDevice(dmInfo.dskid, fs);	if ( err < E_OK ) {		goto err_ret1;	}	pkt->cmd.ret = E_OK;	return;err_ret3:	(void)fmcUnmapDisk(mid, mflag);err_ret2:	(void)detachDevice(dmInfo.dskid, fs);err_ret1:	DEBUG_PRINT(("fmcChangeFileSystemInfo err =%d\n", err));	pkt->cmd.ret = err;	return;}

⌨️ 快捷键说明

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