系统调用的意义:
- mkdir:创建目录
- rmdir:删除空目录
- unlink:删除一个链接
- link:创建一个新链接
- rename:重命名或者删除一个链接
- chdir:切换所调用进程的当前目录
1 #include <sys/types.h> 2 #include <sys/stat.h> 3 #include <unistd.h> 4 #include <stdio.h> 5 #include <dirent.h> 6 #include <stdlib.h> // Just in case of some calls 7 8 ino_t get_inode(char *) ; 9 void printpathto(ino_t) ; 10 void inum_to_name(ino_t , char * , int ) ; 11 12 int main() 13 { 14 printpathto(get_inode(".")); 15 putchar(' '); 16 return 0 ; 17 } 18 19 void printpathto(ino_t this_inode) 20 { 21 ino_t my_inode ; 22 char its_name[BUFSIZ] ; 23 if(get_inode("..") != this_inode) 24 { 25 chdir("..") ; 26 inum_to_name(this_inode , its_name , BUFSIZ) ; 27 my_inode = get_inode("."); 28 printpathto( my_inode ) ; 29 printf("/%s", its_name ); 30 } 31 } 32 33 void inum_to_name(ino_t inode_to_find , char namebuf[] , int buflen) 34 { 35 DIR * dir_ptr ; 36 struct dirent * direntp ; 37 dir_ptr = opendir(".") ; 38 if(dir_ptr == NULL ) 39 { 40 perror("."); 41 exit(1); 42 } 43 while( (direntp = readdir(dir_ptr)) != NULL ) 44 { 45 if(direntp -> d_ino == inode_to_find ) 46 { 47 strncpy(namebuf , direntp -> d_name , buflen ); 48 namebuf[buflen - 1 ] = '