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

📄 log.c

📁 操作系统实验,文件系统,c语言实现的
💻 C
字号:
#include <stdio.h>
#include "filesys.h"

int login(uid,passwd)
unsigned short uid;
char * passwd;
{
	int i,j;
	for(i=0;i<PWDNUM;i++)
	{
		if((uid==pwd[i].p_uid)&&(!strcmp(passwd,pwd[i].password)))
		{
			for(j=0;j<USERNUM;j++)
				if(user[j].u_uid==0)
					break;
				if(j==USERNUM)
				{
					printf("\ntoo much user in the system,walted to login\n");
					return 0;
				}
				else
				{
					user[j].u_uid=uid;
					user[j].u_gid=pwd[i].p_gid;
					user[j].u_default_mode=DEFAULTMODE;
					user_id=j;
				}
				break;
		}
	}
	if(i==PWDNUM)
	{
		printf("\nincorrect password\n");
		printf("log---->out\n");
		return 0;
	}
	else
	{ 
		printf("\nyour uid:%d\n",uid);
		printf("your password:%s\n",passwd);
		printf("log---->out\n");
		return 1;
	}
}
int logout(uid)    /* logout */
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 file\n");
			return NULL;
		}
		for(j=0;j<NOFILE;j++)
		{
			if(user[i].u_ofile[j]!=SYSOPENFILE+1)
			{
				/* iput the inode 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 + -