预览加载中,请您耐心等待几秒...
1/2
2/2
在线预览结束,喜欢就下载吧,查找使用更方便
如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
操作系统实验报告11级计科三班张剑阁2011221104210115//-----------Linux简单的文件系统-----------//#include<stdio.h>#include<unistd.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>#include<errno.h>#include<dirent.h>#include<stdlib.h>#include<string.h>#include<time.h>main(){charpath[100];chartext[100];printf("pleaseinputpathname:");scanf("%s",path);ints;s=mkdir(path,S_IRWXU);if(s==0)printf("DONE!");elseprintf("UNDONE!");char*textname1;char*textname2;char*textname;printf("pleaseinputtextname:");scanf("%s",text);textname1=text;textname2=strcat(path,"/");textname=strcat(textname2,textname1);//目录建立成功intfd;//打开文件fd=open(textname,O_RDWR|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);if(fd!=-1)printf("openthefilesucceed!\n");elseprintf("openthefilefailed!\n")charmessage[100];printf("pleaseinputthecontent:\n");scanf("%s",message);//写内容到message中write(fd,message,strlen(message));//把message中的内容写到文件中close(fd);structstatbuf;stat(textname,&buf);staticcharmtime[]="0000-00-0000:00";time_tt1=time((time_t*)&(buf.st_mtime));structtm*t1=localtime(&t1);printf("NODENUM:%d\n",buf.st_ino);printf("TYPEANDQUAN:%d\n",buf.st_mode);printf("SIZE:%d\n",buf.st_size);printf("thelastchangedtimeis:%.4d-%.2d-%.2d%.2d:%.2d:%.2d\n",t1->tm_year+1900,t1->tm_mon+1,t1->tm_mday,t1->tm_hour,t1->tm_min,t1->tm_sec);//显示最后一修改时间}