?? open.c
字號:
#include<stdio.h>
#include "filesys.h"
unsigned short open(user_id,filename,openmode)
int user_id;
char *filename;
unsigned short openmode;
{
unsigned int dinodeid;
struct inode *inode;
int i,j;
dinodeid=namei(filename);
if(dinodeid == NULL) /*no such file */
{
printf("\nfile does not existed!!!\n");
return NULL;
}
inode=iget(dinodeid);
if(!access(user_id,inode,openmode)) /* access denled*/
{
printf("\nfile open has not access!!!");
iput(inode);
return NULL;
}
/* alloc the sys_ofile item */
for(i=0; i<SYSOPENFILE;i++)
if(sys_ofile[i].f_count==0) break;
if(i==SYSOPENFILE)
{
printf("\nsystem open file too much\n");
iput(inode);
return NULL;
}
sys_ofile[i].f_inode=inode;
sys_ofile[i].f_flag=openmode;
sys_ofile[i].f_count=1;
if(openmode & FAPPEND)
sys_ofile[i].f_off=inode->di_size;
else
sys_ofile[i].f_off=0;
/*alloc the user open file item*/
for(j=0;j<NOFILE;j++)
if(user[user_id].u_ofile[j]==SYSOPENFILE+1) break;
if(j==NOFILE)
{
printf("\nuser open file too much!!!\n");
sys_ofile[i].f_count=0;
iput(inode);
return NULL;
}
user[user_id].u_ofile[j]=1;
/* if APPEND,free the block of the file before */
if(!(openmode & FAPPEND))
{
for(i=0;i<inode->di_size/BLOCKSIZ+1;i++)
bfree(inode->di_addr[i]);
inode->di_size=0;
}
printf("\ni=%d,dinodeid=%d\n",i,dinodeid);
printf("\nj=%d,sys_ofile[i].f_off=%d\n",j,sys_ofile[i].f_off);
return j;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -