分类: LINUX
2013-02-04 16:05:05
下面这段代码就涉及到这个。以后还可以好好看看。
void searchvDisk(const char *path) { cleanvDiskArray(); DIR * dp; struct dirent* entry; struct stat statbuf; if((dp = opendir(path)) == NULL) { return; } chdir(path); while((entry=readdir(dp)) != NULL) { stat(entry->d_name,&statbuf); if (S_ISDIR(statbuf.st_mode)) { if(strcmp( ". ",entry->d_name)==0||strcmp( ".. ",entry->d_name)==0) { continue; } //printf( "%*s%s/\n ",depth, " ",entry -> d_name); //showdir(entry -> d_name,depth+4); } else { char buffer[BUFLEN]; memset(buffer,0,BUFLEN); if(readlink(entry->d_name,buffer,BUFLEN-1)) //buffer is ../sdx { char *p=NULL; p=strchr(buffer,'/'); p++; char devname[20]={0}; memcpy(devname,p,strlen(buffer)-(p-buffer)); setvDiskArray(devname,entry->d_name); } } } chdir( ".. "); closedir(dp); }
参考连接:
http://www.cnblogs.com/sonic4x/archive/2011/08/05/2128543.html
http://www.cnblogs.com/joeblackzqq/archive/2011/03/20/1989625.html