操作系統(tǒng)試驗(yàn)5文件系統(tǒng)Linux文件管理_第1頁
操作系統(tǒng)試驗(yàn)5文件系統(tǒng)Linux文件管理_第2頁
操作系統(tǒng)試驗(yàn)5文件系統(tǒng)Linux文件管理_第3頁
操作系統(tǒng)試驗(yàn)5文件系統(tǒng)Linux文件管理_第4頁
操作系統(tǒng)試驗(yàn)5文件系統(tǒng)Linux文件管理_第5頁
免費(fèi)預(yù)覽已結(jié)束,剩余10頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、操作系統(tǒng)實(shí)驗(yàn)5文件系統(tǒng):Linux 文件管理實(shí)驗(yàn)5文件系統(tǒng);Linux文件管理1 .實(shí)驗(yàn)?zāi)康模?)掌握Linux提供的文件系統(tǒng)調(diào)用的使用方 法;(2)熟悉文件和目錄操作的系統(tǒng)調(diào)用用戶接口;(3) 了解操作系統(tǒng)文件系統(tǒng)的工作原理和工作 方式。2 .實(shí)驗(yàn)內(nèi)容(1)利用Linux有關(guān)系統(tǒng)調(diào)用函數(shù)編寫一個文 件工具filetools,要求具有下列功能: 0.退出1 .創(chuàng)建新文件2 .寫文件3 .讀文件4 .復(fù)制文件5 .修改文件權(quán)限6 .查看文件權(quán)限7 .創(chuàng)建子目錄8 .刪除子目錄9 .改變當(dāng)前目錄到指定目錄10 .鏈接操作*代碼:#include<stdio.h> #include<

2、;sys/types.h> #include<unistd.h> #include<fcntl.h> #include<sys/stat.h> #include<syslog.h> #include<string.h> #include<stdlib.h> void menu(void);void openfile(void); void writefile(void); void readfile(void); void copyfile(void); void chmd(void);void ckqx(void)

3、; void cjml(void); void scml(void); void ggml(void); void ylj(void);int main()int choose;int suliangjin=1;menu();scanf("%d”,&choose);while(choose!=0)switch(choose)(case 1:openfile();break;case 2:writefile();break;case 3:readfile();break;case 4:copyfile();break;case 5:chmd();break;case 6:ckq

4、x();break;case 7:cjml();break;case 8:scml();break;case 9:ggml();break;case 10:ylj();break;menu();scanf("%d",&choose);return 0;)void menu(void)(printf("文件系統(tǒng) n");printf("1.創(chuàng)建新文件n");printf("2.寫文件 n");printf("3.讀文件 n");printf("4.復(fù)制文件 n");pr

5、intf("5.修改文件權(quán)限n");printf("6.查看文件權(quán)限n");printf("7.創(chuàng)建子目錄n");printf("8.刪除子目錄n");printf("9.改變目前目錄到指定目錄n");printf("10.鏈接操作 n");printf("0.退出 n");printf("請輸入您的選擇.n");)void openfile(void)(int fd;if(fd=open("/tmp/hello.c"

6、;,O_CREAT|O_TRUN C|O_RDWR,0666)<0)perror("open");elseprintf("open file:hileo.c %dn",fd);if(close(fd)<0)perror("close");elseprintf("Close ");void writefile(void)int fd,size,len;char *buf="Hello!I'm writing to this file!"len=strlen(bu

7、f);if(fd=open("/tmp/hello.c",O_CREAT|O_TRUN C|O_RDWR,0666)<0)perror("open");elseprintf("open file:hileo.c %dn",fd); if(size=write(fd,buf,len)<0) perror("write");elseprintf("Write:%sn",buf);if(close(fd)<0) perror("close");else print

8、f("Close hello.c n");void readfile(void)int fd,size;char b10;if(fd=open("/tmp/hello.c",O_CREAT|O_TRUN C|O_RDWR,0666)<0) perror("open");elseprintf("open file:hileo.c %dn",fd); lseek(fd,0,SEEK_SET);if(size=read(fd,b,10)<0) perror("read");elseprin

9、tf("read from file:%sn",b);if(close(fd)<0) perror("close");elseprintf("Close ");void copyfile(void)if(fork()=0)execlp("/bin/cp","cp","/tmp/hello.c","/tmp/he.c ”,NULL);elsewait(0);printf("將 hello.c 復(fù)制 he.c");void ch

10、md(void)int a;printf("1.文件主可讀可寫可執(zhí)行n");printf("2.文件主可讀n");printf("3.文件主可寫n");printf("4.文件主可執(zhí)行n");printf("請輸入您的選項(xiàng)n");scanf("%d",&a);switch(a)(casen");break;casen");break;casen");break;casen");break;default:printf("

11、;您選擇有誤 n");)void ckqx(void)(char *path="/bin/ls”;char *argv4="ls","-l",NULL;if(fork()=0)execv(path,argv);elsewait(0);void cjml(void)if(mkdir("/tmp/a",S_IRWXU)<0) perror("Mkdir");elseprintf("創(chuàng)建成功 n");void scml(void)if(rmdir("/tmp/a&q

12、uot;)<0) perror("Rmdir");else printf("刪除成功 n");)void ggml(void)(if(chdir("/tmp/bc")<0) perror("chdir");else printf("更改目錄成功n");)void ylj(void)(if(link("hello.c","h.c")<0) perror("Link");else printf("建立硬連接n&q

13、uot;);)打開文件:1)id openf ilc( v h J)ini fd;if(fd=open( Vinp/tiP I lo. c' fO_CKEr|O_TRirC i per ror tr opcn');e Jsepr in I ft ' open I i I p: h i Lo. c jdnT, fd):iftcJoseCrdKO)perror(4')jprinif(4Close beJJ")!open f i le i ti i Den tr MC|a<:e he I tcI 1» rnl. K ¥

14、71;寫文件:i ii u rd .、i 工/(> 1 f*ii -:h«a v *bu f-w Eir 1 Iij ! I 1 m wt i L i mg l u t h i 事 F i I Ic n = a t r lc n( hu t )工i f< C fd=open< = / t npZ tie I Iq .七一 CJCKEAT | OTR pe r ri*i ( *<)pe ri* > ielsep r mt t C open 1 i I c : h i It 口 =七 %dl 丁 i f C C c i *電=u»r i 1 eC

15、f d <Hu f r ><O >口. r r*i < i If*):e Ipr io t f ( " W, i t c : X n J . bu r3 *i ft r<<1)<>pr i r or ( c lose :<? I 5Cpr in 1 f( * Close I I o B.、工rdJopen fiIe:hileo.c 3W i it : Ft I lu! 1 m iv i L ing to this file ! trim ha I In/讀文件:va i d readf i I e ( v。id )chji

16、b101:i r(<fd=opcn(VLiip/ht llo.cT fO.CREAT pex ror ( bopcrt");c 1 SEprint f ( cpen I i Ie : h i Le o . cI seek< Fd 川.SEHK_EEl hi f( t fl i ze =r*adC fdtb h 10> ><f>>porr»r('rcadT);pr in 1 f ( ' read f rom f i 1nv »b)i 1(closefd)<0>pe r ri)i C close&q

17、uot; > :f supr intfCCIo&e lie I Io. cA n') iopenf iIe;h i leoread from f i Ie : ;iiS R 1 111Cloiic復(fù)制文件:),d cupyf i le(u id)if(fork: )=0)cxcc Ip, */bin/tp' /cp , 7inp/tie I lo»c' / /inp/tie .c'11 SfMii(O):pr int f: T he Ho .c旦制.c');修改權(quán)限:flunt' »print f*1 .IT.T

18、tpJipJtipJ|MTn'); pr in L f *上,% 件上 F L£ In');pt inlf L J. c J| 'l I ' ;J.pr 1制”,文件主可執(zhí)行/"*;5I .亶件主可反盯寫可執(zhí) 2 .文件生可讀3 .年件主可寫4 .W件主可執(zhí)行 請輸入您的選項(xiàng) 2ok!pr intf請曲由二艱tTh'% ,. ct. 3 !du & Li1tchmklv7 LJip/lw llu.c'eS_IRMLI):pi JtJtlf(*uLl Vn') ;Ltll工打2 LChrrDd' f I

19、mr /he I Io - ca.S_lltllbR); p r in 11'"okJ n*) shrtL .! rlimiil" /1 ii| I hr 'kS_HWSR):U tn IP'H11 Vh" ): L” i口4rclimid,Hnfptie llgfccr,S IXJLSR);pr i:nlF(TafcBn,) shrcakidr曠小 pin”烷在樣有工"月查看權(quán)限:卜 u id ck1|x.( , n id)chur *pa tk=' /bin/ I s'/h;ir *a rg4= T Is1 ,

20、Ir, MLL!; if( fark( )-0)txccv( pa lh tai gv ;e 14eMB tMJ i ;j wxr-xr-xIruotTOOL493Wfl2416:18c 1 ieik 1 .-jvkr*kr-sc1ruulroot15748uq2722: S4fi lei-t wiv- rw-IrootrootJ1H2Kf i Ic . rT3rootToot4)八月2812 : 46h . cTMM1rootrootflil月2g12 : 47he +c卜T3r4?QlJOQt011月2S12用he I Ig . c創(chuàng)建目錄:b o id c j ml< vi: L.i)jf(nidir( + 7inrp/aS_IRWa)> 31pe r r o r (* Md i i:e I se舊刪小香m班pr irH(也理成.八n') ;7創(chuàng)建成功刪除目錄:丫力 id semi (iU rirdiN*八叩/XO)用im八

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論