📄 inode.c
字号:
/* *---------------------------------------------------------------------- * 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. * *---------------------------------------------------------------------- *//* * @(#)inode.c (seio) * * Standard input-output * File reference node management */#include "sfmgr.h"/* * Initilization of file reference node connection queue */EXPORT void inode_QueInit( FS *fs ){ W i; /* Standard FS has no queue */ if ( fs == (FS*)&STD_FS ) { return; } /* Initialization of queue */ for ( i = 0; i < NQUE; i++ ) { QueInit(&fs->iqtbl[i]); } return;}/* * Check of file reference node connection queue. * Confirm the queue to be empty. And, return error if it isn't empty. */EXPORT ER inode_CheckEmpty( FS *fs ){ W i; /* Standard FS has no queue */ if ( fs == (FS*)&STD_FS ) { return E_OK; } /* Check of queue */ for ( i = 0; i < NQUE; i++ ) { if ( !isQueEmpty(&fs->iqtbl[i]) ) { return E_BUSY; } } return E_OK;}/* * Registration of file reference node */EXPORT void inode_Register( FS *fs, INODE *inode, UB omode ){ UW qnum; /* Stop the root directory and standard input-output */ if ( inode == NULL ) { return; } /* Update of the number of references */ if ( (omode & O_ACCMODE) != O_RDONLY ) { ++inode->wrefcnt; } if ( ++inode->refcnt > 1 ) { return; } /* Insert into queue */ if ( fs != (FS*)&STD_FS ) { qnum = (UW)inode->ino & (UW)QUEMSK; QueInsert(&inode->q, &fs->iqtbl[qnum]); } return;}/* * Deletion of file reference node */EXPORT void inode_Free( FS *fs, INODE *inode ){ /* Stop root directory and standard input-output */ if ( inode == NULL ) { return; } /* Delete if there is no reference */ if ( inode->refcnt <= 0 ) { if ( inode->exinf != NULL ) { Vfree(inode->exinf); } Vfree(inode); } return;}/* * Release of file reference node * Stop the reference, and delete the unused file reference node. */EXPORT ER inode_Release( FS *fs, INODE *inode, UB omode, BOOL force ){ ER err = E_OK; /* Stop root directory and standard input-output */ if ( inode == NULL ) { return err; } /* Stop writing reference */ if (( fs != (FS*)&STD_FS )&&( (omode & O_ACCMODE) != O_RDONLY )) { if ( --inode->wrefcnt <= 0 ) { /* Synchronization */ (void)SyncFS(fs->diskid, (VW)inode); err = CheckDiskError(fs, inode); if (( err < E_OK )&& !force ) { return err; } } } /* Stop reference */ if ( inode->refcnt > 1 ) { inode->refcnt--; return err; /* In-use */ } /* Delete from queue */ if ( fs != (FS*)&STD_FS ) { QueRemove(&inode->q); } /* Release of file reference node */ if ( inode->exinf != NULL ) { Vfree(inode->exinf); } Vfree(inode); return err;}/* --------------------------------------------------------------------------- *//* * Search of file reference node */EXPORT INODE* inode_Search( FS *fs, ino_t ino ){ QUEUE *q; UW qnum; INODE *inode; /* Selection of queue */ qnum = (UW)ino & (UW)QUEMSK; /* Search */ for ( q = fs->iqtbl[qnum].next; q != &fs->iqtbl[qnum]; q = q->next ) { inode = (INODE*)q; if ( inode->ino == ino ) { return inode; } } return NULL;}/* * Queue transfer of file reference node */EXPORT void inode_ChangeQue( FS *fs, INODE *inode ){ UW qnum; /* Stop the tentative reference */ if ( inode->refcnt <= 0 ) { return; } /* Selection of queue */ qnum = (UW)inode->ino & (UW)QUEMSK; /* Queue remove */ QueRemove(&inode->q); QueInsert(&inode->q, &fs->iqtbl[qnum]); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -