OS-homework-11.docx_第1页
OS-homework-11.docx_第2页
OS-homework-11.docx_第3页
OS-homework-11.docx_第4页
OS-homework-11.docx_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

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

文档简介

实验十一 实验名称:文件系统编程实验要求: 1. 编写一个程序,实现将一个目录的所有内容复制到另一个目录的功能。要求:源文件(目录)和目标文件(目录)的属主、权限等信息保持一致;每复制一个文件(目录),在屏幕提示相应信息;当遇到符号链接文件时,显示该文件为链接文件,不复制。创建目录是是是是否否是复制文件改变文件权限结束最后一个?下一个文件目录文件?否链接文件?普通文件?否开始复制输入目标目录是否存在?是否否开始输入源目录输入正确?流程图: 代码: #include #include #include #include #include #include #include char paths1000,patht1000,temp_paths1000,temp_patht1000; void Copy(char *spathname,char *tpathname) int sfd,tfd; struct stat s,t; char c; sfd=open(spathname,O_RDONLY); tfd=open(tpathname,O_RDWR|O_CREAT); while(read(sfd,&c,1)0) write(tfd,&c,1); fstat(sfd,&s); chown(tpathname,s.st_uid,s.st_gid); chmod(tpathname,s.st_mode); close(sfd); close(tfd); void d_copy(char *spathname,char *tpathname) struct stat s,t,temp_s,temp_t; struct dirent *s_p; DIR *dirs,*dirt; stat(spathname,&s); mkdir(tpathname,s.st_mode); chown(tpathname,s.st_uid,s.st_gid); dirt=opendir(tpathname); dirs=opendir(spathname); strcpy(temp_paths,spathname); strcpy(temp_patht,tpathname); while(s_p=readdir(dirs)!=NULL) if(strcmp(s_p-d_name,.)!=0&strcmp(s_p-d_name,.)!=0) strcat(temp_paths,/); strcat(temp_paths,s_p-d_name); strcat(temp_patht,/); strcat(temp_patht,s_p-d_name); lstat(temp_paths,&s); temp_s.st_mode=s.st_mode; if(S_ISLNK(temp_s.st_mode) printf(%s is a symbol link filen,temp_paths); else if(S_ISREG(temp_s.st_mode) printf(Copy file %s .n,temp_paths); Copy(temp_paths,temp_patht); strcpy(temp_paths,spathname); strcpy(temp_patht,tpathname); else if(S_ISDIR(temp_s.st_mode) printf(Copy directory %s .n,temp_paths); d_copy(temp_paths,temp_patht); strcpy(temp_paths,spathname); strcpy(temp_patht,tpathname); int main() struct dirent *sp,*tp; char spath1000,tpath1000,temp_spath1000,temp_tpath1000; struct stat sbuf,tbuf,temp_sbuf,temp_tbuf; char sdirect1000,tdirect1000,judge; DIR *dir_s,*dir_t; printf(Please input the sourse direct path and name :); scanf(%s,sdirect); dir_s=opendir(sdirect); if(dir_s=NULL) printf(This directory dont exist !n); return 0; if(stat(sdirect,&sbuf)!=0) printf(Get status error !n); return 0; printf(Please input the target direct path and name :); scanf(%s,tdirect); dir_t=opendir(tdirect); if(dir_t=NULL) mkdir(tdirect,sbuf.st_mode); chown(tdirect,sbuf.st_uid,sbuf.st_gid); dir_t=opendir(tdirect); else chmod(tdirect,sbuf.st_mode); chown(tdirect,sbuf.st_uid,sbuf.st_gid); strcpy(spath,sdirect); strcpy(tpath,tdirect); strcpy(temp_spath,sdirect); strcpy(temp_tpath,tdirect); printf(Begin copy .n); while(sp=readdir(dir_s)!=NULL) if(strcmp(sp-d_name,.)!=0&strcmp(sp-d_name,.)!=0) strcat(temp_spath,/); strcat(temp_spath,sp-d_name); strcat(temp_tpath,/); strcat(temp_tpath,sp-d_name); lstat(temp_spath,&sbuf); temp_sbuf.st_mode=sbuf.st_mode; if(S_ISLNK(temp_sbuf.st_mode) printf(%s is a symbolic link filen,temp_spath); else if(S_IFMT&temp_sbuf.st_mode)=S_IFREG) printf(Copy file %s .n,temp_spath); Copy(temp_spath,temp_tpath); strcpy(temp_tpath,tpath); strcpy(temp_spath,spath); else if(S_IFMT&temp_sbuf.st_mode)=S_IFDIR) printf(Copy directory %s .n,temp_spath)

温馨提示

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

评论

0/150

提交评论