文件系统代码|请有各位大虾帮我分析下面关于LINUX文件系统编程的代码然后回答几个问题

文件系统代码|请有各位大虾帮我分析下面关于LINUX文件系统编程的代码然后回答几个问题的第1张示图

㈠ 求模拟实现单级目录,单级索引的索引文件系统的源代码

1.文件系统应具有的基本功能(1)多用户:usr1,usr2,usr3,……,usr8(1-8个用户)(2)多级目录:可有多级子目录;(3)具有login(用户登录)(4)系统初始化(建文件卷、提供登录模块)(5)文件的创建:create(6)文件的打开:open(7)文件的读:read(8)文件的写:write(9)文件关闭:close(10)删除文件:delete(11)创建目录(建立子目录):mkdir(12)改变当前目录:cd(13)列出文件目录:dir(14)退出:logout2.选用程序设计语言:C++、C等。四、提示1.本次课程设计为模拟UNIX文件系统来设计一个多用户多目录的文件系统。1)课程设计所利用的空间为1M的内存。这1M内存分成512块,每块为512个字节,这512块就是文件系统的可用块数,文件系统的分配就是以块为单位来分配的,空闲块的管理利用位示图的方法来管理。申请1M的内存的方法可以利用malloc()或calloc().2)磁盘I节点可以利用在内存中生成链表或者数组的方法来生成,并且限制磁盘节点数的最大值。同样内存I节点也可以利用链表的方法在内存中生成。3)在往文件中写或者读的时候我们都是对内存中内容进行读写。例如你在文件中写的时候,其实是对分配的文件块中对应的内存赋值。当程序运行结束的时候,文件的内容都会丢失。我们这个文件系统只是一个模拟文件系统功能的虚拟文件系统。

㈡ 请问uboot内为什么要有文件系统支持的代码nand write指令烧录镜像会涉及到文件系统么

第一问就像你猜的那样。Uboot在nandwrite时是用不到文件系统的,那时没有“文件”的概念,只是写了内存中指定地址和长度的一段内容到nand。但是在读的时候为了方便读取而加入文件系统。假设从SD中读取,如果把Uboot.bin、kernel、rootfs都写入SD卡的确定地址,那么Uboot在读kernel、rootfs时不需要文件系统,但需要你记住这些地址和长度。所以还是需要文件系统的。至于nandwrite.jffs2和nandwrite的不同,直接参看源代码,因为参数不同而执行不同代码。jffs2用的还多吗?

㈢ 操作系统大型实验,求个用C++实现的文件系统代码+实验报告,

不就是文件管理功能嘛!!!我也做过…以前网上荡的代码…不知道适不适合你

㈣ 操作系统课上做一个文件系统管理,谁能提供下代码供参考

我有以前用过的,应该可以和用 你可以参考下 代码太长我分两部分发吧 ***********文 件管理系统***********/ #include <stdio.h> #include <stdlib.h> /*不容易归类的标准函数库*/ #include <conio.h> #include <string.h> #include <sys\stat.h> #include <fcntl.h> /*非标准文件输入输出操作的代码符号属性*/ #include <dos.h> #include <io.h> int init() /*初始化操作界面函数*/ {int i; clrscr(); gotoxy(23,3);printf("* * * * * * * * * * * * * *"); gotoxy(27,4);printf("FILE MANAGE SYSTEM"); gotoxy(23,5);printf("* * * * * * * * * * * * * *"); gotoxy(23,7);printf("NETWORK033 Cai Guiquan NO.1"); gotoxy(28,9);printf("1–Creat File"); gotoxy(28,10);printf("2–Delete File"); gotoxy(28,11);printf("3–OPen File"); gotoxy(28,12);printf("4–Write File"); gotoxy(28,13);printf("5–Locate File"); gotoxy(28,14);printf("6–Modify File"); gotoxy(28,15);printf("7–Copy File"); gotoxy(28,16);printf("8–Move File"); gotoxy(28,17);printf("9–Cataloge Manage"); gotoxy(28,18);printf("10–Exit File"); gotoxy(25,21); printf("Please Choice:"); scanf("%d",&i); return(i); /*选择相应的序号,执行相应的操作*/ } main() {int x,i,j,flag=1; char name[15],name1[15],name2[40]; char choice,ch; int handle,status; /*定义文件的指针和状态*/ FILE *fp; while(flag) /*初始化系统界面*/ {i=init(); getchar(); switch(i) { case 1:label1: /*创建文件操作*/ clrscr(); gotoxy(27,5);printf("CREAT FILE\n"); for(j=0;j<40;j++) printf("= "); printf("\n\nPlease input the creating file name and routine:\n"); scanf("%s",name); getchar(); handle=creatnew(name,0);/*按指定的文件方式创建文件,若有同名文件返回错误代码*/ if(handle==-1) { printf("\nSorry,the file already exists."); getchar(); printf("\nInput again?(Y or N)"); scanf("%c",&choice);getchar(); if(choice=='Y'||choice=='y') goto label1; } else { printf("\nThe file is created."); printf("Do you now input contentof the file?(Y or N):"); while(1) /*输入创建文件的内容*/ { scanf("%c",&choice); if(choice=='y'||choice=='n'||choice=='Y'||choice=='N') break; else printf("\nError!Please input again!"); } if(choice=='y'||choice=='Y') { printf("\nNow input content to the file(End with '#'):\n\n"); fp=fopen(name,"w");/*把内容存放到fp指向的文件中去*/ ch=getchar(); while(ch!='#') { fputc(ch,fp); ch=getchar(); } fclose(fp);getchar();/*关闭文件*/ } getchar(); break; case 2:label2: /*删除文件的操作*/ clrscr(); gotoxy(25,5);printf("DELETE FILE\n"); for(j=0;j<40;j++) printf("= "); printf("\n\nPlease input the deleting file name and routine:\n"); scanf("%s",name); /*输入要删除的文件名*/ getchar(); printf("\n Are you sure?(Y or N):"); while(1) { scanf("%c",&choice); if(choice=='y'||choice=='n'||choice=='Y'||choice=='N') break; else printf("\nError!Please input again!"); } if(choice=='y'||choice=='Y') {status=access(name,0);/*获取文件的状态,是否存在*/ if(status!=0) {printf("\nSorry the file doesn't exist!"); getchar(); printf("\n\nInput again?(Y or N)"); scanf("%c",&choice);getchar(); if(choice=='Y'||choice=='y') goto label2; } else { status=access(name,02);/*获取文件的状态,是否存在并且是否只读*/ if(status!=0) { printf("\nSorry the file is only read!"); getchar(); } else {unlink(name); /*从目录中删除一个文件函数,该函数在dos.h中*/ printf("\n\ndelete succefully!"); getchar(); } } } getchar(); break; case 3:label3: /*打开文件操作*/ clrscr(); gotoxy(27,5);printf("OPEN FILE\n"); for(j=0;j<40;j++) printf("= "); printf("\n\nPlease input the opening file name and routine:\n"); scanf("%s",name); status=access(name,0);/*获取文件的状态*/ if(status!=0) {printf("\nSorry the file doesn't exist!"); getchar(); printf("\n\nInput again?(Y or N)"); scanf("%c",&choice);getchar(); if(choice=='Y'||choice=='y') goto label3; } else { printf("\nNow begin to read the file:\n"); fp=fopen(name,"r"); ch=fgetc(fp); /*读出文件到内存*/ while(ch!=EOF) {printf("%c",ch); ch=fgetc(fp);j++; } fclose(fp);getchar();/*关闭文件*/ } getchar(); break; case 4:label4: /*写文件操作*/ clrscr(); gotoxy(27,5);printf("WRITE FILE\n"); for(j=0;j<40;j++) printf("= "); printf("\n\nPlease input the writing file name and routine:\n"); scanf("%s",name); status=access(name,0);/*获取name指向的文件状态*/ if(status!=0) {printf("\nSorry the file doesn't exist!"); getchar(); printf("\n\nInput again?(Y or N)"); scanf("%c",&choice);getchar(); if(choice=='Y'||choice=='y') goto label4; } else {fp=fopen(name,"w");/*以写入方式打开name 指向的文件*/ printf("\nPlease input the information(end with '#'):\n"); ch=getchar(); /*重写文件*/ while(ch!='#') { fputc(ch,fp); ch=getchar(); } fclose(fp);getchar();/*关闭文件*/ } getchar(); break; case 5:label5: /*定位文件操作*/ clrscr(); gotoxy(27,5);printf("LOCATE FILE\n"); for(j=0;j<40;j++) printf("= "); printf("\n\nPlease input the locating file name and routine:\n"); scanf("%s",name); status=access(name,0);/*获取name文件指向的文件的状态*/ if(status!=0) {printf("\nSorry the file doesn't exist!"); getchar(); printf("\n\nInput again?(Y or N)"); scanf("%c",&choice);getchar(); if(choice=='Y'||choice=='y') goto label5; } else {printf("\nPlease input the location:"); scanf("%d",&x); handle=open(name,O_CREAT|O_RDWR,S_IREAD|S_IWRITE);/*打开由name指定的文件,name既可以是简单的文件名*/

㈤ 请有各位大虾帮我分析下面关于LINUX文件系统编程的代码,然后回答几个问题

(1)num=read(0,buffer,MAX); write(fd,buffer,num);表示从标准输入设备中(键盘输入) 读取数据放入buffer 再写到“file1”中 0代表标准输入设备, 1代表标准输出设备 , 2,代表错误输出设备(2)execv( path , argv ) 用来执行path字符串所代表的文件路径文 argv是执行命令 总的来说就是执行 ls -l file1这个命令 这个命令执行后 会列出file1的文件属性 包括访问权限

㈥ 文件系统检查退出代码为8 怎么解决

开终端sudo sudf 确认 disk3 的分区没有被 mount,然后用 dd 给磁盘写上500M的空白数据试试:dd bs=1m count=500 if=/dev/zero of=/dev/disk3若顺利执行完版毕,你再重新对此盘分权区格式化看看。

㈦ 文件系统错误-2147219200解决办法

文件系统错误-2147219200的解决办法如下:

需要工具:电脑。

1、首先我们右键开始菜单,选择打开“Windows PowerShell(管理员)”选项。

㈧ 什么是文件系统

文件系统 注1:操作系统中负责管理和存储文件信息的软件机构称为文件管理系统,简称文件系统。文件系统由三部分组成:与文件管理有关的软件、被管理的文件以及实施文件管理所需的数据结构。从系统角度来看,文件系统是对文件存储器空间进行组织和分配,负责文件的存储并对存入的文件进行保护和检索的系统。具体地说,它负责为用户建立文件,存入、读出、修改、转储文件,控制文件的存取,当用户不再使用时撤销文件等。 文件系统是操作系统用于明确磁盘或分区上的文件的方法和数据结构;即在磁盘上组织文件的方法。也指用于存储文件的磁盘或分区,或文件系统种类。因此,可以说"我有2个文件系统"意思是他有2个分区,一个存文件,或他用 "扩展文件系统",意思是文件系统的种类。 磁盘或分区和它所包括的文件系统的不同是很重要的。少数程序(包括最有理由的产生文件系统的程序)直接对磁盘或分区的原始扇区进行操作;这可能破坏一个存在的文件系统。大部分程序基于文件系统进行操作,在不同种文件系统上不能工作。 一个分区或磁盘能作为文件系统使用前,需要初始化,并将记录数据结构写到磁盘上。这个过程就叫建立文件系统。 大部分UNIX文件系统种类具有类似的通用结构,即使细节有些变化。其中心概念是超级块superblock, i节点inode, 数据块data block,目录块directory block, 和间接块indirection block。超级块包括文件系统的总体信息,比如大小(其准确信息依赖文件系统)。 i节点包括除了名字外的一个文件的所有信息,名字与i节点数目一起存在目录中,目录条目包括文件名和文件的i节点数目。 i节点包括几个数据块的数目,用于存储文件的数据。 i节点中只有少量数据块数的空间,如果需要更多,会动态分配指向数据块的指针空间。这些动态分配的块是间接块;为了找到数据块,这名字指出它必须先找到间接块的号码。 UNIX文件系统通常允许在文件中产生孔(hole) (用lseek ; 请看手册), 意思是文件系统假装文件中有一个特殊的位置只有0字节,但没有为这文件的这个位置保留实际的磁盘空间(这意味着这个文件将少用一些磁盘空间)。这对小的二进制文件经常发生,Linux共享库、一些数据库和其他一些特殊情况。 (孔由存储在间接块或i节点中的作为数据块地址的一个特殊值实现,这个特殊地址说明没有为文件的这个部分分配数据块,即,文件中有一个孔。) 孔有一定的用处。在笔者的系统中,一个简单的测量工具显示在200MB使用的磁盘空间中,由于孔,节约了大约4MB。在这个系统中,程序相对较少,没有数据库文件。 下面是文件系统的代码,根据这个代码我们可以更好地了解文件系统的工作流程 1. main.cpp #include "head.h" #include "blockinodesuperblock.h" #include "initial.h" #include "userop.h" #include "file.h" #include "dir.h" #include "command.h" #include "chsome.h" // by ctu_85 http://blog.csdn.net/ctu_85/archive/2008/02/29/2135420.aspx ///////////////////////////////////////////////////////////////////////////////////////// void main() { control.open("control.txt",ios::in | ios::out | ios::nocreate); int i; control>>i; control.close(); if(i!=0)//不为0就初始化 { initial(); } control.open("control.txt",ios::in | ios::out | ios::nocreate); control.seekp(0); control<<0;//默认是上次基础上继续下去不用再初始化 control.close(); strcpy(curname,"root");//当前目录文件名为root road[0]=0;//当前目录路径(存放从根目录到这里的结点号) num=1;//最后位road[num-1]为当前目录文件i结点号 cout<<"请登陆系统\n"; while( !login() )//登陆为止 cout<<"wrong !!!\n"; cout<<" login success"<<endl; cout<<"******Welcome "<<auser<<"******"; readsuper(); getcommand();//命令解析函数 writesuper(); } 2. blockinodesuperblock.h ///////////////////////////////////////////////////////////////////////////////////////// int ialloc()//申请一个i结点 返回结点号 否则返回-1 { if(superblock.fiptr>0) { int temp=superblock.fistack[80-superblock.fiptr];//当前可用 superblock.fistack[80-superblock.fiptr]=-1; superblock.fiptr–; return temp; } return -1; } ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// void ifree(int index)//指定一个结点号,回收一个i结点 { disk.open("disk.txt",ios::in | ios::out | ios::nocreate );//清空结点 disk.seekp(514+64*index+2*(index/8)); disk<<setw(64)<<' '; disk.close(); for(int i=80-superblock.fiptr;i<80;i++)//结点号找到合适位置插入空闲结点号栈 { if(superblock.fistack<index)//小于它的前移一位 { superblock.fistack[i-1]=superblock.fistack; } else//放在第一个大于它的结点号前面 { superblock.fistack[i-1]=index; break; } } superblock.fiptr++; } ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// /*成组链接法*/ int balloc()//申请一个盘块 返回盘块号 否则返回-1 { int temp=superblock.fbstack[10-superblock.fbptr]; if(superblock.fbptr==1)//是栈底了==>是记录盘块了 { //是最后记录盘块最后号0(保留作栈底 分配不成功) if(temp==0) { return -1; } superblock.fbstack[10-superblock.fbptr]=-1; superblock.fbptr=0; //盘块内容读入栈 for(int i=0;i<10;i++) { int id,num=0; disk.open("disk.txt",ios::in | ios::out | ios::nocreate ); //先计算盘块内容个数num(最多10),最后盘块可能不到10个 disk.seekg(514*temp); for(int i=0;i<10;i++) { disk>>id; num++; if(id==0) break; } disk.seekg(514*temp);//盘块内容读入栈 for(int j=10-num;j<10;j++) { disk>>id; superblock.fbstack[j]=id; } superblock.fbptr=num; disk.close(); } disk.open("disk.txt",ios::in | ios::out | ios::nocreate );//清空回收盘块 disk.seekp(514*temp); disk<<setw(512)<<' '; disk.close(); //盘块使用掉 return temp; } else//不是记录盘块==>盘块使用掉 { superblock.fbstack[10-superblock.fbptr]=-1; superblock.fbptr–; return temp; } } /////////////////////////////////////////////////////////////////////////////////////////

㈨ 文件系统程序设计 要求用C语言在TC环境下运行的代码!代码!代码!

#include <stdio.h>#include <malloc.h>#include <memory.h>#define RIGHT 1#define DOWN 2#define LEFT 3#define UP 4int f=RIGHT;int getNextF(void) //获取下一个方向{ if (UP==f) f=RIGHT; else f++; return f;}int main(){ int n; printf("请输入螺旋的宽度:\n"); scanf("%d", &n); int *i; i=(int *)malloc(sizeof(int)*n*n); //数据存放区 if (NULL==i) { printf("申请内存失败!\n"); return (-1); } int k; for (k=0; k<n*n; k++) //所有地方都设置成-1,表示该地方没有被使用过 i[k]=-1; int j; int nStart; nStart=-1; //起始位置 for(j=0; j<n*n; j++) { l: if (RIGHT==f) { if ((-1==nStart || (nStart+1)%n!=0) && i[nStart+1]==-1) i[++nStart]=j+1; else { getNextF(); goto l; } } else if (DOWN==f) { if (((nStart+1)/n +1<=n) && i[nStart+n]==-1) { nStart+=n; i[nStart]=j+1; } else { getNextF(); goto l; } } else if (LEFT==f) { if (nStart%n !=0 && i[nStart-1]==-1) { i[–nStart]=j+1; } else { getNextF(); goto l; } } else if (UP==f) { if (i[nStart-n]==-1) { nStart-=n; i[nStart]=j+1; } else { getNextF(); goto l; } } } for (j=0; j<n; j++) { for (k=0; k<n; k++) printf("%3d ", i[j*n+k]); putchar('\n'); } free(i); return 0; }

未经允许不得转载:山九号 » 文件系统代码|请有各位大虾帮我分析下面关于LINUX文件系统编程的代码然后回答几个问题

赞 (0)