《操作系统》课程设计说明书UNIX、Linux文件系统分析_第1页
《操作系统》课程设计说明书UNIX、Linux文件系统分析_第2页
《操作系统》课程设计说明书UNIX、Linux文件系统分析_第3页
《操作系统》课程设计说明书UNIX、Linux文件系统分析_第4页
《操作系统》课程设计说明书UNIX、Linux文件系统分析_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、河南城建学院操作系统课程设计说明书 设计题目: unix/linux文件系统分析 专 业: 计算机科学与技术 指导教师: 班 级: 0614082 学 号: 061408261 姓 名: 同 组 人: 计算机科学与工程系2011年1月 7日前 言在现在计算机更新如此迅速的时代要学好计算机软件技术,特别是操作系统的学习,不仅要努力学好课本上的基础知识,还要经常在图书馆看些有关这方面的书籍,而更重要的是要有足够的实践经验,也要注重和同学的交流,经常尝试性的做些小的操作系统,对自己技术的提升会有很大的帮助。同时,学习计算机操作系统技术,除了需要刻苦努力外,还需要掌握软件和操作系统的原理与设计技巧。如

2、何学习和掌握操作系统技术的原理与实际技巧呢?除了听课和读书之外,最好的方法恐怕就是在实践中练习。例如,自己设计一个小型操作系统,多使用操作系统,多阅读和分析操作源代码等。但由于我们的条件和学时有限,在理论学习过程中没有给同学们提供更多的实验机会。本操作系统课程设计,是给同学提供一个集中实验的机会。希望同学们通过该设计加深对所学习课程的理解。本设计是基于课程中学到的unix系统调用,使用操作系统环境是red hat linux 9,言语开发环境是linux的gnu c或c+。我做的课程设计是:linux/unix文件系统分析。在linux系统下,使用与文件相关的系统调用实现对物理设备文件的读写,

3、参照linux系统源代码以及grub系统的源代码,对不同介质上的fat格式文件系统进行分析。要求在linux环境下设计出c语言程序,实现以下功能:1) 分析unix sysv/linux系统引导记录的作用;2) 分析unix sysv/linux的超级块及其结构,并建立相关数据结构,通过编程实现unix sysv/linux文件系统内各部分的定位。3) 至少要实现对给定i节点文件的只读访问目 录一系统环境51.1硬件环境51.2软件环境5二设计目的及要求5三总体设计7四详细设计8五调试与测试8六设计中遇到的问题及解决方法8七linux/unix文件系统分析源程序清单97.1 头文件97.2 示

4、例程序12八运行结果及分析188.1 linux文件系统读取188.2 unix文件系统读取20九心得体会21十参考文献22linux/unix文件系统分析一系统环境1.1硬件环境cpu为pentium4双线程技术,频率为2.8ghz,内存为256mb。1.2软件环境使用操作系统环境是red hat linux 9,言语开发环境是linux的 gnu c或c+。二设计目的及要求1、设计目的学习计算机软件技术,特别是计算机操作系统技术,除了需要刻苦努力外,还需要掌握软件和操作系统的原理与设计技巧。如何学习和掌握操作系统技术的原理与实际技巧呢?除了听课和读书之外,最好的方法恐怕就是在实践中练习。例

5、如,自己设计一个小型操作系统,多使用操作系统,多阅读和分析操作源代码等。但由于条件和学时有限,在理论学习过程中没有给提供更多的实验机会。本操作系统课程设计,是提供了一个集中实验的机会。应该通过该设计加深对所学习课程的理解。2、设计要求按软件工程的思想和方法进行设计,并把它作为一个工程来做。设计的每一步都有要形成文档,“成品”出来以后要有使用说明书和测试报告。最后按院方统一要求整理出软件实习“论文”,并分别以电子和书面文档的形式上交。最后,设计的程序要编译通过,并在验收时进行演示。本设计的内容是基于操作系统原理教材的,但同学们必须对以前的c语言程序设计和数据结构等内容进行认真的复习。本设计是基于

6、课程中学到的unix系统调用,使用操作系统环境是red hat linux 9,言语开发环境是linux的gnu c或c+。因此,要求课程设计者对linux操作系统和gnu c或c+有一定的了解。3、设计内容在linux系统下,使用与文件相关的系统调用实现对物理设备文件的读写,参照linux系统源代码以及grub系统的源代码,对不同介质上的fat格式文件系统进行分析。要求在linux环境下设计出c语言程序,实现以下功能:1)分析unix sysv/linux系统引导记录的作用;2)分析unix sysv/linux的超级块及其结构,并建立相关数据结构,通过编程实现unix sysv/linux

7、文件系统内各部分的定位。3)至少要实现对给定i节点文件的只读访问。4)建议根据文件读取文件。文件系统必须完成下列工作:1) 为了合理的存放文件,必须对磁盘等辅助空间(或称文件空间)进行统一管理。在用户创新新文件时为其分配空闲区,而在用户删除或修改某个文件时,回收和调整存储区。2) 为了实现按名存取,需要有一个用户可见的文件逻辑结构,用户按照文件逻辑结构所给定的方式进行信息的存取和加工。这种逻辑结构时独立于物理存储设备的。3) 为了便于存放和加工信息,文件在存储和设备上应按一定的顺序存放。这种存放方式被称为文件物理结构。4) 完成对存放在存储设备上的文件信息的查找。5) 完成文件的共享和提供保护

8、功能。三总体设计程序开始读取超级快内容到buff读取判断参数,打开文件系统,设置文件指针到超级快开头判断第二个参数unix超级快内容解释程序段linux超级快内容解释程序段显示超级快内部包含的文件系统信显示超级块内部包含的文件系统信息是否有第四参数是否有第四参数解释为i节点号i节点号解释为i节点号提示输入i节点号提示输入i节点号解释为i节点号根据i节点读i节点信息及i节点所指向盘快信息并显示根据i节点读i节点信息及i节点所指向盘快信息并显示 四详细设计分析unix sysv/linux系统引导记录的作用unix sysv/linux系统引导记录存放于整个硬盘的第一个扇区,即0柱面0磁头l扇区,

9、也叫做mbr(maserboot reoofd)扇区,即主引导记录。 主引导记录在计算机引导过程中起着举足轻重的作用,计算机在按下电源键以后,开始执行主板bi0s程序,进行完一系列检测和配置以后,开始按bi0s中设定的系统引导顺序引导系统。bios执行完自己的程序后如何把执行投交给硬盘呢。交给硬盘后叉执行存储在哪里的程序呢?其实,称为mbr的扇区中的一段代码起着举足轻重的作用。 mbr不随操作系统的不同而小同,即不同的操作系统町能会存在相同的mbr即使不同,mbr也不会夹带操作系统的性质,具有公共引导的特性。对文件系统的操作参看程序源代码。 实现对磁盘文件的访问,实现读写、查看文件系统的存取信

10、息,对应各个i节点的相关信息,以及各个i节点的排列情况,使用户能清楚的看到文件系统磁盘结构。更加了解计算机文件系统的工作流程。五调试与测试(1)通过输入命令cc chengxu.c将文件编译为可执行文件a.out,通过输入命令./a.out加参数执行文件。(2)判断命令行参数进行操作,当参数为./a.out u s51k .img时进行linux文件系统读取,当参数为./a.out x xenix.img时进行unix文件系统读取。(3)判断是否有第四个参数,若没有,则提示输入i节点号并实现对给定i节点文件的只读访问。六设计中遇到的问题及解决方法在设计程序时。我们按自己的理解编写了一个超级块和

11、inode节点的结构体。然后放在主程序中去读取信息,但是运行的结果大出我们的预料。没有按我们的预期读出文件系统的信息,而是输出了一堆乱码,我们有经过查资料最后终于解决了问题,程序输出正常。 七linux/unix文件系统分析源程序清单7.1 头文件#includetypedef _s16 s16;typedef _u16 u16;typedef _s32 s32;typedef _u32 u32;typedef u16 sysv_ino_t;/* block numbers are 24 bit, sometimes stored in 32 bit. on coherent fs, they

12、 are always stored in pdp-11 manner: the least significant 16 bits come last.*/typedef u32 sysv_zone_t;/* among the blocks . */* xenix fs, coherent fs: block 0 is the boot block, block 1 the super-block. systemv fs: block 0 contains both the boot sector and the super-block. */* the first inode zone

13、is sb-sv_firstinodezone (1 or 2). */* among the inodes . */* 0 is non-existent */#define sysv_badbl_ino1/* inode of bad blocks file */#define sysv_root_ino2/* inode of root directory */* xenix super-block data on disk */#define xenix_nicinod100/* number of inode cache entries */#define xenix_nicfree

14、100/* number of free block list chunk entries */struct xenix_super_block u16s_isize; /* index of first data zone */u32s_fsize;/ _packed2_; /* total number of zones of this fs */* the start of the free block list: */u16s_nfree;/* number of free blocks in s_free, = xenix_nicfree */u32s_freexenix_nicfr

15、ee; /* first free block list chunk */* the cache of free inodes: */u16s_ninode; /* number of free inodes in s_inode, = xenix_nicinod */sysv_ino_ts_inodexenix_nicinod; /* some free inodes */* locks, not used by linux: */chars_flock;/* lock during free block list manipulation */chars_ilock;/* lock dur

16、ing inode cache manipulation */chars_fmod;/* super-block modified flag */chars_ronly;/* flag whether fs is mounted read-only */u32s_time;/_packed2_;/*time of last super block update*/u32s_tfree;/ _packed2_; /* total number of free zones */u16s_tinode;/* total number of free inodes */s16s_dinfo4;/* d

17、evice information ? */chars_fname6;/* file system volume name */chars_fpack6;/* file system pack name */chars_clean;/* set to 0x46 when filesystem is properly unmounted */chars_fill371;s32s_magic;/* version of file system */s32s_type;/* type of file system: 1 for 512 byte blocks2 for 1024 byte block

18、s3 for 2048 byte blocks */;/* systemv fs comes in two variants: * sysv2: system v release 2 (e.g. microport), structure elements aligned(2). * sysv4: system v release 4 (e.g. consensys), structure elements aligned(4). */#define sysv_nicinod100/* number of inode cache entries */#define sysv_nicfree50

19、/* number of free block list chunk entries */* systemv4 super-block data on disk */struct sysv4_super_block u16s_isize;/* index of first data zone */u16s_pad0;u32s_fsize;/* total number of zones of this fs */* the start of the free block list: */u16s_nfree;/* number of free blocks in s_free, = sysv_

20、nicfree */u16s_pad1;u32s_freesysv_nicfree; /* first free block list chunk */* the cache of free inodes: */u16s_ninode;/* number of free inodes in s_inode, = sysv_nicinod */u16s_pad2;sysv_ino_t s_inodesysv_nicinod; /* some free inodes */* locks, not used by linux: */chars_flock;/* lock during free bl

21、ock list manipulation */chars_ilock;/* lock during inode cache manipulation */chars_fmod;/* super-block modified flag */chars_ronly;/* flag whether fs is mounted read-only */u32s_time;/* time of last super block update */s16s_dinfo4;/* device information ? */u32s_tfree;/* total number of free zones

22、*/u16s_tinode;/* total number of free inodes */u16s_pad3;chars_fname6;/* file system volume name */chars_fpack6;/* file system pack name */s32s_fill12;s32s_state;/* file system state: 0x7c269d38-s_time means clean */s32s_magic;/* version of file system */s32s_type;/* type of file system: 1 for 512 b

23、yte blocks2 for 1024 byte blocks */;/* systemv/coherent inode data on disk */struct sysv_inode u16 i_mode;u16 i_nlink;u16 i_uid;u16 i_gid;u32 i_size;union /* directories, regular files, . */unsigned char i_addb3*(10+1+1+1)+1; /* zone numbers: max. 10 data blocks, * then 1 indirection block, * then 1

24、 double indirection block, * then 1 triple indirection block. * then maybe a file generation number ? */* named pipes on coherent */struct char p_addp30;s16 p_pnc;s16 p_prx;s16 p_pwx; i_p; i_a;u32 i_atime;/* time of last access */u32 i_mtime;/* time of last modification */u32 i_ctime;/* time of crea

25、tion */;/* * systemv/v7/coherent fs inode data in memory */struct sysv_inode_info u32 i_data10+1+1+1;/* zone numbers: max. 10 data blocks, * then 1 indirection block, * then 1 double indirection block, * then 1 triple indirection block. */;7.2 示例程序#include#include#include#include#include#includesysv

26、fs.h#includemain(int argc, char *argv)inti,j,k,typ,fd,l=5;char*file_sys,*tmp,buff1024,buff_i1025;struct sysv4_super_block *sbu;struct xenix_super_block *sbx;struct sysv_inode *inode;intinode_size, inode_no,blk_size;inti_start,d_start;longll;ulongi_add13;if(argcs_isize);printf(s_pad0:%xn, sbu-s_pad0)

27、;printf(total number of zones of this fs:%xn,sbu-s_fsize);printf(/* the start of the free block list: */n);printf(number of free blocks in s_free, s_nfree);printf(s_pad1:%xt%udn, sbu-s_pad1, sbu-s_pad1);printf(/* the cache of free inodes: */n);printf(number of free inodes in s_inode, s_ninode);print

28、f(s_pad2:%xn ,sbu-s_pad2);printf(some free inodes:n);printf(/* locks, not used by linux: */n);printf(time of last super block update:%xn ,sbu-s_time);printf(total number of free zones:%xn ,sbu-s_tfree);printf(total number of free inodes:%xn ,sbu-s_tinode);printf(file system volume name:%xn ,sbu-s_fn

29、ame);chars_fpack6;/* file system pack name */printf(s_state:%xn ,sbu-s_state);/* file system state: 0x7c269d38-s_time means clean */printf(s_magic:%xn ,sbu-s_magic);/* version of file system */* type of file system: 1 for 512 byte blocks */blk_size=512*sbu-s_type;i_start=2;d_start=sbu-s_isize;/+i_st

30、art-1;printf(inode_from:%xn,2*512*i_start);printf(data_from:%xn,2*512*d_start);inode_size=sizeof(struct sysv_inode);printf(size of inode struct= %dn,inode_size);/get inode_noif(argc=4)if(!isnum(argv3) inode_no=atoi(argv3);elsefprintf(stderr,%s is not a int);close(fd);exit(9);else printf(nntplease in

31、put inode_no:);scanf(%d,&inode_no);printf(= inode=%d =n,inode_no);-inode_no;j=inode_no*inode_size/1024;k=(inode_no*inode_size/*-1*/)%1024;j+=i_start;if(ll=lseek(fd,blk_size*j,seek_set)!=blk_size*j)fprintf(stderr,file system %s seek error!an,file_sys);close(fd);exit(5);printf(ll=%dln,ll);if(read(fd,b

32、uff_i,blk_size)!=blk_size)fprintf(stderr,file system %s read error!an,file_sys);close(fd);exit(6);tmp=buff_i+k;inode=(struct sysv_inode *)tmp;printf(i_mode=%xn ,inode-i_mode);printf(i_link=%xn ,inode-i_nlink);printf(i_addr:n);for(i=0;ii_a.i_addbi);printf(i_addr_all:n);for(i=0;i64;i+) printf(%x| ,tmp

33、i);printf(n);i=0;for(j=0;ji_a.i_addbj+256*inode-i_a.i_addbj+1+256*256*inode-i_a.i_addbj+2;+i;for(i=0;i13;i+) printf(i_add%d=%d |, i,i_addi);printf(n);/ direct blockfor(i=0;is_isize;tmp+=2;ul=(ulong *)tmp;fsize=*ul;printf(index of first data zone:%xn,sbx-s_isize);printf(total number of zones of this

34、fs:%lxn,fsize);printf(/* the start of the free block list: */n);tmp=buff;tmp+=6;nfree=tmp0+256*tmp1;printf(number of free blocks in s_free, s_isize;/+i_start-1;printf(inode_from:%xn,2*512*i_start);printf(data_from:%xn,2*512*d_start);inode_size=sizeof(struct sysv_inode);printf(size of inode struct= %

35、dn,inode_size);/get inode_noif(argc=4)if(!isnum(argv3) inode_no=atoi(argv3);elsefprintf(stderr,%s is not a int);close(fd);exit(9);else printf(nntplease input inode_no:);scanf(%d,&inode_no);printf(= inode=%d =n,inode_no);-inode_no;j=inode_no*inode_size/1024;k=(inode_no*inode_size)%1024;j+=i_start;if(

36、ll=lseek(fd,blk_size*j,seek_set)!=blk_size*j)fprintf(stderr,file system %s seek error!an,file_sys);close(fd);exit(5);printf(ll=%dln,ll);if(read(fd,buff_i,blk_size)!=blk_size)fprintf(stderr,file system %s read error!an,file_sys);close(fd);exit(6);tmp=buff_i+k;printf(nn);for(i=0;ii_mode);printf(i_link

37、=%xn ,inode-i_nlink);printf(i_addr:n);for(i=0;ii_a.i_addbi);printf(i_addr_all:n);for(i=0;i64;i+) printf(%x| ,tmpi);printf(n);i=0;for(j=0;ji_a.i_addbj+256*inode-i_a.i_addbj+1+256*256*inode-i_a.i_addbj+2;+i;for(i=0;i13;i+) printf(i_add%d=%d |, i,i_addi);printf(n);/ direct blockfor(i=0;i10;i+)if(ll=lse

38、ek(fd,blk_size*i_addi,seek_set)!=blk_size*i_addi)fprintf(stderr,file system %s seek error!an,file_sys);close(fd);exit(7);if(read(fd,buff_i,blk_size)!=blk_size)fprintf(stderr,file system %s read error!an,file_sys);close(fd);exit(8);fprintf(stderr,%s,buff_i); / maybe write to a fileclose(fd);exit(x);is

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论