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

📄 main.c

📁 此版本是在网上广为流传的 二级文件系统 基础上制作的.重新编写了块操作等模块,修正了N多BUG. 实现的命令有 ls-列目录 md-创建目录 cd-进入子目录 mf-创建文件 cat-显示文件内
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "filesys.h"
struct hinode hinode[NHINO];
struct dir dir;
struct file sys_ofile[SYSOPENFILE];
struct filsys filsys;
struct user user[USERNUM];
FILE *fd;
struct inode *cur_path_inode;
int user_id,file_block;
int user_id; 
char usr_id[6]; 

char usr_p[12]; 
char sel; 
char temp_dir[12];
char cur_path[10][32];
unsigned short dir_lv;


main()
{
  unsigned short ab_fd1,ab_fd2,ab_fd3,ab_fd4;
  unsigned short bhy_fd1;  
  char *buf;
  int i;
  int done = 0;
  char cmd[10];
  
 /* if ( (fd=fopen("filesystem","r")) == NULL ) {
      printf("This is your first time to start mini file system !\n");
      printf("Format will erase all context on the disk !\n");
      printf("Formating...\n");
      format();
  }*/
      format();
  
      printf("Starting the fillsystem,please wait...\n"); 
      install(); 
      //printf("%s, %s\n", user[0].u_name, user[0].password);
      printf("\n----Login----\nPlease input your userid:"); 
      scanf("%s",usr_id); 
      printf("Please input your password:"); 
      scanf("%s",usr_p); 
      //usr_id = 2118;
      //strcpy(usr_p, "abcd");
      //getch();
      if(!login(usr_id,usr_p)) 
            return;                  

  done = 1;
  while(done)
  {
      sel = -1;
      cmd[0] = 0;
      printf("\nUser %s  ", usr_id);
      for ( i = 0; i < dir_lv ; ++i)
            printf("%s/", cur_path[i]);
      printf("\n$ ", usr_id);
      
      scanf("%s", cmd);
      if (!strcmp(cmd, "ls")) sel = '1';
      if (!strcmp(cmd, "md")) sel = '2';
      if (!strcmp(cmd, "cd")) sel = '3';
      if (!strcmp(cmd, "mf")) sel = '4';
      if (!strcmp(cmd, "cat")) sel = '5';
      if (!strcmp(cmd, "del")) sel = '6';
      if (!strcmp(cmd, "help")) sel = '7';
      if (!strcmp(cmd, "vi")) sel = '8';
      if (!strcmp(cmd, "reg")) sel = '9';
      if (!strcmp(cmd, "q")) sel = '0'; 

      switch(sel) 
      { 
            case '1': 
                        _dir(); 
                        break; 
            case '2': 
                        printf(">please input dir name:"); 
                        scanf("%s",temp_dir); 
                        mkdir(temp_dir); 
                        break; 
            case '3': 
                        printf(">please input dir name:"); 
                        scanf("%s",temp_dir); 
                        chdir(temp_dir); 
                        //dirlt(2);
                        break; 
            case '4': 
                        printf(">please input file name:"); 
                        scanf("%s",temp_dir); 
                        file_block = BLOCKSIZ*6;
                        ab_fd1=creat(user_id,temp_dir,file_block,01777); 
                        buf=(char *)malloc(file_block*2);
                        //for (i = 0; i < file_block/2; ++i) buf[i] = "-";
                        //for (i = file_block/2; i < file_block; ++i) buf[i] = "+";
                        write(ab_fd1,buf,2*file_block); 
                        close(user_id,ab_fd1); 
                        free(buf);
                        break; 
            case '5':
                        printf(">please input dir name:"); 
                        scanf("%s", temp_dir);    
                        cat(temp_dir);
                        break;
            case '6': 
                        printf(">please input dir name:"); 
                        scanf("%s",temp_dir); 
                        delete(temp_dir);
                        break; 
            case '7':   
                        printf(" -ls----list files\n -md----make dir\n -cd----change dir\n -mf----make file\n -q----Quit\n\n");
                        break;
            case '8':
                        printf(">please input dir name:"); 
                        scanf("%s",temp_dir); 
                        vi(temp_dir);
                        break; 
            case '9':
                        regist(user_id);
                        break;                
            case '0': 
                        logout(user_id); 
                        halt(); 
                        done = 0; 
                        break;
            default:
                        printf(">No such command,please try again.\n"); 
                        break;                        
      }
  } 
  printf(">User canseled\nGood Bye\n"); 
  
}

⌨️ 快捷键说明

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