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

📄 log.c

📁 操作系统课程设计
💻 C
字号:
#include <stdio.h>
#include "filesys.h"

int login (uid, passwd,current,all_user)
unsigned short uid;
char	*passwd;
int current;
int *all_user;
{
	int i,j,temp;
	for(j=0;j<USERNUM; j++)
		if(user[j].u_uid==uid){
			printf("用户切换成功。\n");
			temp=all_user[j];
		    for(i=j;i<current;i++)all_user[i]=all_user[i+1];
			all_user[current]=temp;
			return 0;
		}
	for(i=0;i<PWDNUM;i++)
	{
	if((uid==pwd[i].p_uid)&&(!strcmp(passwd,pwd[i].password))) //~~~~edited
	{
	  for(j=0;j<USERNUM; j++)
	  if(user[j].u_uid==0) break;
	  if(j==USERNUM)
		{
		  printf("\nToo much user in the System, waited to login\n");
		  return 0;
		}
	     else
		{
			user[j].u_uid=uid;
			user[j].u_gid=pwd[i].p_gid; //~~~~edited
			user[j].u_default_mode=DEFAULTMODE;
			all_user[++current]=j;
		   }
		break;
		}
	}

	if(i==PWDNUM)
	  {
             printf("\n用户名或密码错误\n");
	     return 0;
	    }
	   else
		return 1;
}
int logout(uid)
	unsigned short uid;
{
	int i,j,sys_no;
	struct inode *inode;
	for(i=0; i<USERNUM; i++)
	if(uid==user[i].u_uid) break;
if (i==USERNUM)
{
	printf("\nno such a user\n");
	return NULL;
}

for (j=0;j<NOFILE; j++)
{
	if (user[i].u_ofile[j]!=SYSOPENFILE+1)
{
/* iput the mode free the sys_ofile and clear the user-ofile */
sys_no=user[i].u_ofile[j];
inode = sys_ofile[sys_no].f_inode;
iput(inode);
sys_ofile[sys_no].f_count--;
user[i].u_ofile[j] = SYSOPENFILE+ 1;
}
}
return 1;
}

⌨️ 快捷键说明

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