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

📄 accmode.c

📁 T-kernel 的extension源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* Obtain the file owner name. */	fmpConvEndianHs((UH*)name, (UH*)fh->own, UserNameLen, fsinfo);	if ( name[0] == 0 ) {		/* Owner name undefined: User of level 0 can change. */		if ( getUserLevel(pinfo) != 0 ) {			return E_FACV;		}	} else {		/* Changeable when owner name matches. */		BOOL	match;		LOCK_PINFO_SECTION(			match = fmNameCmp(pinfo->user->user.usr_name, name);		);		if ( !match ) {			return E_FACV;		}	}	return E_OK;}/* * Change the file access mode. *	Return MD_WRITE when writing is performed to fh. *	Otherwise, return MD_RDONLY. */EXPORT UW fmpChangeFileAccessMode( FmCmdPkt *pkt, DfFileHeader *fh,							FsInfo *fsinfo ){	FM_CHG_FMD_PARA	*cmdPara = (FM_CHG_FMD_PARA*)pkt->cmd.para;	A_MODE		*mode = cmdPara->mode;	PINFO		*pinfo = pkt->wrk.pinfo;	UW		mflag = MD_RDONLY;	ER		err;	/* Parameter check */	err = CheckSpaceR(mode, sizeof(A_MODE));	if ( err < E_OK ) {		goto err_ret;	}	if ( ( ((mode->f_ownacc & F_NOCHG) == 0U)		&& ((mode->f_ownacc & ~F_OWNACC) != 0U) )	  || ( ((mode->f_grpacc & F_NOCHG) == 0U)		&& ((mode->f_grpacc & ~TSD_FCF_MSK_0X0FFF) != 0U) )	  || ( ((mode->f_pubacc & F_NOCHG) == 0U)		&& ((mode->f_pubacc & ~TSD_FCF_MSK_0X0FFF) != 0U) )	  || ( mode->f_grpno > TSD_FCF_VAL_4 ) ) {		err = E_PAR;		goto err_ret;	}	/* Check the access right of the attribute being changed. */	err = checkAttrAccess(pinfo, fh, F_RONLY, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	/* Mode change */	if ( (mode->f_ownacc & F_NOCHG) == 0 ) {		UH	ftype;		ftype = fmpConvEndianH(fh->ftype, fsinfo);		ftype = (ftype & ~F_OWNACC) | mode->f_ownacc;		fh->ftype = fmpConvEndianH(ftype, fsinfo);	}	if ( (mode->f_grpacc & F_NOCHG) == 0 ) {		fh->gacclv = fmpConvEndianH(mode->f_grpacc, fsinfo);	}	if ( (mode->f_pubacc & F_NOCHG) == 0 ) {		fh->pacclv = fmpConvEndianH(mode->f_pubacc, fsinfo);	}	if ( mode->f_grpno >= 0 ) {		TC	*gname;		P_USER	*user;		LOCK_PINFO_SECTION(			user = &pinfo->user->user;			switch ( mode->f_grpno ) {			  case TSD_FCF_CAS_1:				gname = user->grp_name1;				break;			  case TSD_FCF_CAS_2:				gname = user->grp_name2;				break;			  case TSD_FCF_CAS_3:				gname = user->grp_name3;				break;			  case TSD_FCF_CAS_4:				gname = user->grp_name4;				break;			  default:				gname = NULL;				break;			}			if ( gname == NULL ) {				memset(fh->grp, 0, (size_t)sizeof(UserName));			} else {				fmpConvEndianHs((UH*)fh->grp, (UH*)gname,							UserNameLen, fsinfo);			}		);	}	mflag = MD_WRITE;	err = fmpCheckDiskError(NULL, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	/* Update the time stamp (Date/Time of access). */	err = fmpSetTimeStampFh(fh, F_READ, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = E_OK;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;err_ret:	DEBUG_PRINT(("fmpChangeFileAccessMode err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;}/* * Change the access attribute of the file. *	Return MD_WRITE when writing is performed to fh. *	Otherwise, return MD_RDONLY. */EXPORT UW fmpChangeFileAttribute( FmCmdPkt *pkt, DfFileHeader *fh,							FsInfo *fsinfo ){	FM_CHG_FAT_PARA	*cmdPara = (FM_CHG_FAT_PARA*)pkt->cmd.para;	UH		ftype;	UH		chkatr;	UW		mflag = MD_RDONLY;	ER		err;	/* Only F_RSTRONLY can be executed when write protected. */	chkatr = ( cmdPara->attr == (W)F_RSTRONLY )? (UH)0: (UH)F_RONLY;	/* Check the access right of the attribute being changed. */	err = checkAttrAccess(pkt->wrk.pinfo, fh, chkatr, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	/* Fetch the current attribute. */	ftype = fmpConvEndianH(fh->ftype, fsinfo);	/* Attribute change */	switch ( cmdPara->attr ) {	  case F_SETRONLY:	/* Set the write protect attribute. */		ftype |= F_RONLY;		break;	  case F_RSTRONLY:	/* Reset the write protect attribute. */		ftype &= ~F_RONLY;		break;	  case F_SETPERM:	/* Set the delete protect attribute. */		ftype |= F_PERM;		break;	  case F_RSTPERM:	/* Reset the delete protect attribute. */		ftype &= ~F_PERM;		break;	  case F_SETA1:		/* Set the application attribute 1. */		ftype |= F_APLATR1;		break;	  case F_RSTA1:		/* Reset the application attribute 1. */		ftype &= ~F_APLATR1;		break;	  case F_SETA2:		/* Set the application attribute 2. */		ftype |= F_APLATR2;		break;	  case F_RSTA2:		/* Reset the application attribute 2. */		ftype &= ~F_APLATR2;		break;	  default:		err = E_PAR;		goto err_ret;	}	/* Set the changed attribute. */	fh->ftype = fmpConvEndianH(ftype, fsinfo);	mflag = MD_WRITE;	err = fmpCheckDiskError(NULL, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	/* Update the time stamp (Date/Time of access). */	err = fmpSetTimeStampFh(fh, F_READ, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = E_OK;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;err_ret:	DEBUG_PRINT(("fmpChangeFileAttribute err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;}/* * Change the file name. *	Return MD_WRITE when writing is performed to fh. *	Otherwise, return MD_RDONLY. */EXPORT UW fmpChangeFileName( FmCmdPkt *pkt, FID fid, DfFileHeader *fh,							FsInfo *fsinfo ){	FM_CHG_FNM_PARA	*cmdPara = (FM_CHG_FNM_PARA*)pkt->cmd.para;	FileName	fnm, oldname;	UW		mflag = MD_RDONLY;	ER		err;	/* Fetch/Check the new file name. */	memset(fnm, 0, (size_t)sizeof(FileName));	err = fmGetAplStr(fnm, cmdPara->name, FileNameLen);	if ( err < E_OK ) {		goto err_ret1;	}	err = fmCheckFileName(fnm, FileNameLen);	if ( err < E_OK ) {		goto err_ret1;	}	/* Check the access right of the attribute being changed. */	err = checkAttrAccess(pkt->wrk.pinfo, fh, F_RONLY|F_PERM, fsinfo);	if ( err < E_OK ) {		goto err_ret1;	}	/* Save the current file name. */	memcpy(oldname, fh->name, (size_t)sizeof(FileName));	/* Change the file name/abbreviated name. */	fmpConvEndianHs((UH*)fh->name, (UH*)fnm, FileNameLen, fsinfo);	mflag = MD_WRITE;	err = fmpCheckDiskError(NULL, fsinfo);	if ( err < E_OK ) {		goto err_ret1;	}	err = fmpSetShortFileName(fid, fnm, fsinfo);	if ( err < E_OK ) {		goto err_ret1;	}	if ( !isSameFS(cmdPara->lnk->fs_name, fsinfo) ) {		/* Reference by the link file.: 		   Change the file name of the link file too. */		err = fmIChangeLinkFileName(cmdPara->lnk, fnm);		if ( err < E_OK ) {			goto err_ret2;		}	}	/* Update the time stamp (Date/Time of access). */	err = fmpSetTimeStampFh(fh, F_READ, fsinfo);	if ( err < E_OK ) {		goto err_ret1;	}	pkt->cmd.ret = E_OK;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;err_ret2:	/* Restore the file name. */	memcpy(fh->name, oldname, (size_t)sizeof(FileName));	(void)fmpSetShortFileName(fid, oldname, fsinfo);err_ret1:	DEBUG_PRINT(("fmpChangeFileName err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;}/* * Change the file date/time. *	Return MD_WRITE when writing is performed to fh. *	Otherwise, return MD_RDONLY. */EXPORT UW fmpChangeFileTime( FmCmdPkt *pkt, DfFileHeader *fh, FsInfo *fsinfo ){	FM_CHG_FTM_PARA	*cmdPara = (FM_CHG_FTM_PARA*)pkt->cmd.para;	F_TIME		tm;	UW		mflag = MD_RDONLY;	ER		err;	/* Parameter check */	if ( cmdPara->times != NULL ) {		err = CheckSpaceR(cmdPara->times, sizeof(F_TIME));		if ( err < E_OK ) {			goto err_ret;		}		tm = *cmdPara->times;	} else {		/* Set the current time. */		tm.f_ltime = tm.f_atime = tm.f_mtime = fmGetTime();	}	/* Check the access right of the attribute being changed. */	err = checkAttrAccess(pkt->wrk.pinfo, fh, F_RONLY, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	/* Change the date/time. */	if ( tm.f_ltime > 0 ) {		fh->ltime = (W)fmpConvEndianW((UW)tm.f_ltime, fsinfo);	}	if ( tm.f_atime > 0 ) {		fh->atime = (W)fmpConvEndianW((UW)tm.f_atime, fsinfo);	}	if ( tm.f_mtime > 0 ) {		fh->mtime = (W)fmpConvEndianW((UW)tm.f_mtime, fsinfo);	}	mflag = MD_WRITE;	err = fmpCheckDiskError(NULL, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = E_OK;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;err_ret:	DEBUG_PRINT(("fmpChangeFileTime err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_FSTSK, fsinfo);	return mflag;}/* ======================================================================== *//* * Change the link file name. (Service command in the file management) */EXPORT void fmpIChangeLinkFileName( FmCmdPkt *pkt, FsInfo *fsinfo ){	FMI_ChangeLinkFileName_PARA	*cmdPara		= (FMI_ChangeLinkFileName_PARA*)pkt->cmd.para;	DfFileHeaderBlock	*fh;	ID			mid;	ER			err;	/* Map the file header. */	fh = fmpMapFileHeader(cmdPara->lnk->f_id, NULL, &mid, fsinfo);	if ( fh == NULL ) {		err = (ER)mid;		goto err_ret;	}	/* Change the file name. */	fmpConvEndianHs((UH*)fh->head.name, (UH*)cmdPara->fname,						FileNameLen, fsinfo);	fmpUnmapDisk(mid, MD_WRITE);	err = fmpCheckDiskError(NULL, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	/* Change the abbreviated name. */	err = fmpSetShortFileName(cmdPara->lnk->f_id, cmdPara->fname, fsinfo);	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = E_OK;	setSyncAtExit(SAE_FSTSK, fsinfo);	return;err_ret:	DEBUG_PRINT(("fmpIChangeLinkFileName err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_FSTSK, fsinfo);	return;}

⌨️ 快捷键说明

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