// FS.cpp : Defines the entry point for the console application.
//
#include <stdafx.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct file{
char name[10];
struct file *next;
FILE *fp;
}File;
typedef struct content{
char name[10];
File *fileHead;
int f_num;
struct content *next;
}Content;
typedef struct user{
char name[10];
char psw[10];
Content *conHead;
int c_num;
struct user *next;
}User;
User *user_head,*cur_user;
Content *cur_con;
int user_num;
//step0
void registe()
{
if(user_num>=10)
{
printf("Has 10 users.You have no access to register\n");
return;
}
//allocate new memory block for new user
User *add,*last;
add=(User *)malloc(sizeof(User));
add->next=NULL;
if(user_head==NULL)
user_head=add;
else
{
last=user_head;
while(last->next!=NULL)
last=last->next;
last->next=add;
}
user_num++;
//fulfill the new user
char name[10],psw[10];
User *check;
char buffer[2];
fgets(buffer,2,stdin);
unr:printf("now create a new user:\nuser name(9,only alphabet and number can be used):\n");
scanf("%s",name);
check=user_head;
while(check!=add)
{
if(strcmp(name,check->name)==0)
{
printf("username exist.please re-input:\n");
goto unr;
}
check=check->next;
}
strcpy(add->name,name);
fgets(buffer,2,stdin);
printf("password(10):\n");
fgets(psw,10,stdin);
strcpy(add->psw,psw);
add->conHead=NULL;
add->c_num=0;
//success
printf("success\n");
return;
}
//step0
int login()
{
if(user_head==NULL)
{
printf("system has no user\n");
return 0;
}
char buffer[2];
fgets(buffer,2,stdin);
char name[10],psw[10];
User *check;
printf("press \"#\" if you wanna quit\n");
unl:printf("username:\n");
scanf("%s",name);
if(name[0]=='#')
return 0;
check=user_head;
while(check!=NULL)
{
if(!strcmp(check->name,name))
break;
else
check=check->next;
}
if(check==NULL)
{
printf("no such user..\nplease re-input:\n");
goto unl;
}
//match password
fgets(buffer,2,stdin);
printf("password:\n");
fgets(psw,11,stdin);
if(strcmp(psw,check->psw)!=0)
{
printf("wrong password\n");
goto unl;
}
printf("\n\n*********welcome back!%s*******\n\n",check->name);
cur_user=check;
return 1;
}
//step0-1
void MenuUser()
{
void FolderCreate();
void FolderDelete();
void FolderViewAllFiles();
void FolderIntoFolder();
void absolutePathFileController();
User *current;
Content *goThrough;
current=cur_user;
goThrough=current->conHead;
for(;;)
{
printf("*********%s's Content************\n",cur_user->name);
printf("1.create a folder\n");
printf("2.get in to a folder\n");
printf("3.delete a folder\n");
printf("4.view all files\n");
printf("5.read a file directly by absolute path\n");
printf("6.log out\n");
printf("0.shut down FILE_SYSTEM\n");
printf(" view all your folders below: %d folders total\n",current->c_num);
if(current->conHead==NULL)
printf(" |\n no folder.\n");
else
{
goThrough=current->conHead;
while(goThrough!=NULL)
{
printf(" |\n %s\n",goThrough->name);
goThrough=goThrough->next;
}
}
printf("*******************************************");
printf("\ninput your choice:\n");
int choice;
scanf("%d",&choice);
switch(choice)
{
case 1:FolderCreate();continue;
case 2:FolderIntoFolder();continue;
case 3:FolderDelete();continue;
case 4:FolderViewAllFiles();continue;
case 5:absolutePathFileController();continue;
case 6:printf("\nThanks for using\n\n");return;
case 0:printf("\nThanks for using\n");cur_user=NULL;cur_con=NULL;exit(0);
default:printf("wrong input!\n");
}
}
}
//step1
void FolderCreate()
{
User *user;
user=cur_user;
//allocate new memory block for new folder
Content *add,*last;
add=(Content *)malloc(sizeof(Content));
add->next=NULL;
if(user->conHead==NULL)
user->conHead=add;
else
{
last=user->conHead;
while(last->next!=NULL)
last=last->next;
last->next=add;
}
user->c_num++;
add->fileHead=NULL;
add->f_num=0;
//fulfill the new folder name
char name[10];
Content *check;
char buffer[2];
fgets(buffer,2,stdin);
con_r:printf("now create a new folder:\nfolder name(9,only alphabet and number can be used):\n");
scanf("%s",name);
check=user->conHead;
while(check!=add)
{
if(strcmp(name,check->name)==0)
{
printf("folder name exist.please re-input:\n");
goto con_r;
}
check=check->next;
}
//check legality of the name
int i=0;
for(;i<=9;i++)
{
if(name[i]>=97&&name[i]<=122)//lower
continue;
else
if(name[i]>=48&&name[i]<=57)//num
continue;
else
if(name[i]>=65&&name[i]<=90)//upper
continue;
else
if(name[i]=='\0')
break;
else
{
printf("<%c>is a illegal input!\nplease re-input:\n",name[i]);
goto con_r;
}
}
strcpy(add->name,name);
printf("DONE\n\n");
return;
}
//step1
void FolderDelete()
{
if(cur_user->conHead==NULL)
{
printf("NO Folder\n\n");
return;
}
Content *front,*current;
char name[10];
printf("press \"#\" if you wanna quit\n");
con_d:printf("folder name:\n");
scanf("%s",name);
if(name[0]=='#')
return;
//seek folder name
current=cur_user->conHead;
while(current!=NULL)
{
if(!strcmp(current->name,name))
break;
else
current=current->next;
}
if(current==NULL)
{
printf("no such folder..\nplease re-input:\n");
goto con_d;
}
//if has any files
while(current->fileHead!=NULL)
{
char buffer[2];
fgets(buffer,2,stdin);
printf("folder not empty!!!IF you sure you wanna delete?(Y/N)\n");
char judge;
scanf("%c",&judge);
if(judge=='n'||judge=='y'||judge=='N'||judge=='Y')
if(judge=='n'||judge=='N')
return;
else
break;
else
{
printf("Please input \"Y\" OR \"N\"\n");
continue;
}
}
//user recognise
char psw[10];
printf("input your user password to recognise:");
char buffer[2];
fgets(buffer,2,stdin);
fgets(psw,10,stdin);
if(strcmp(cur_user->psw,psw)!=0)
{
printf("WRONG PASSWORD!\nDELETE FUNCTION FAILLED\n");
return;
}
//execute delete operation
front=cur_user->conHead;
if(front==current) //if curren is the head file
{
cur_user->conHead=current->next;
free(current);
printf("Has been deleted\n1\n");
return;
}
while(front->next!=current)
front=front->next;
front->next=current->next;
free(current);
cur_user->c_num--;
printf("Has been deleted\n2\n");
return;
}
//step1
void FolderViewAllFiles()
{
printf("\nscan all your file:\n");
Content *con;
con=cur_user->conHead;
int fi_num=0;
while(con!=NULL)
{
printf("| %s-----------------\n",con->name);
File *fi;
fi=con->fileHead;
while(fi!=NULL)
{
printf("| | %s\n",fi->name);
printf("| | |\n");
fi=fi->next;
}
fi_num+=con->f_num;
con=con->next;
}
printf("total:%d Folders,%d Files\n\n",cur_user->c_num,fi_num);
return;
}
//step1
void FolderIntoFolder()
{
void MenuFolder();
if(cur_user->conHead==NULL)
{
printf("You has no Folder\n");
return;
}
printf("now get into a Folder:\nFolder name(9):\n");
char name[10];
char buffer[2];
fgets(buffer,2,stdin);
Content *check;
printf("type \"#\" if you wanna quit\n");
con_g:printf("folder name:\ncd ");
scanf("%s",name);
if(name[0]=='#')
return;
check=cur_user->conHead;
while(check!=NULL)
{
if(!strcmp(check->name,name))
break;
else
check=check->next;
}
if(check==NULL)
{
printf("no such folder..\nplease re-input:\n");
goto con_g;
}
//success
cur_con=check;
MenuFolder();
没有合适的资源?快使用搜索试试~ 我知道了~
fs.zip_简单文件系统
共1个文件
c:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2022-09-22
21:57:34
上传
评论
收藏 4KB ZIP 举报
温馨提示
简单模拟linux文件系统,由用户登录后进行操作,是很多高校OS课程设计偏爱的题目。
资源推荐
资源详情
资源评论
收起资源包目录
fs.zip (1个子文件)
fs.c 19KB
共 1 条
- 1
资源评论
钱亚锋
- 粉丝: 88
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功