- while ((ent=readdir(dir))!=NULL){
- if (lstat64(ent->d_name,&st)==-1){
- fprintf (stderr,"Can't stat %s/%s\n",path,ent->d_name);
- warning("lstat failed");
- continue;
- }
-
- dirinodes ++;
-
- if (S_ISREG(st.st_mode)){
- if (st.st_nlink > 1){
- struct stat64 *val;
- int nlink;
-
- /* Check hash table if we've seen this inode
- * before. Note that the hash maintains a
- * (inode,struct stat) key value pair.
- */
-
- val = &st;
-
- (void) INOPut(&tbl,&st.st_ino,&val);
-
- /* Note that after the INOPut call "val" refers to the
- * value entry in the hash table --- not &st. This
- * means that if the inode has been put into the hash
- * table before, val will refer to the first st that
- * was put into the hashtable. Otherwise, if it is
- * the first time it is put into the hash table, then
- * val will be equal to this &st.
- */
- nlink = val->st_nlink;
- nlink --;
-
- /* val refers to value in hash tbale */
- if (nlink == 0) {
-
- /* We saw all hard links to this particular inode
- * as part of this sweep of vdu. So account for
- * the size and blocks required by the file.
- */
-
- dirsize += val->st_size;
- dirblocks += val->st_blocks;
-
- /* Do not delete the (ino,val) tuple from the tbl,
- * as we need to handle the case when we are
- * double counting a file due to a bind mount.
- */
- val->st_nlink = 0;
-
- } else if (nlink > 0) {
- val->st_nlink = nlink;
- } else /* if(nlink < 0) */ {
- /* We get here when we are double counting nlinks
- due a bind mount. */
-
- /* DO NOTHING */
- }
- } else {
- dirsize += st.st_size;
- dirblocks += st.st_blocks;
- }
-
- } else if (S_ISDIR(st.st_mode)) {
- if ((st.st_dev == dirst.st_dev) &&
- (strcmp(ent->d_name,".")!=0) &&
- (strcmp(ent->d_name,"..")!=0)) {
-
- dirsize += st.st_size;
- dirblocks += st.st_blocks;
-
- name = strdup(ent->d_name);
- if (name==0) {
- panic("Out of memory\n");
- }
- vdu_onedir(name);
- free(name);
- fchdir(dirfd);
- }
- } else {
- // dirsize += st.st_size;
- // dirblocks += st.st_blocks;
- }
- }
- closedir (dir);
- close (dirfd);
- if (verbose)
- printf("%16lld %16lld %16lld %s\n",dirinodes, dirblocks, dirsize,foo);
- inodes += dirinodes;
- blocks += dirblocks;
- size += dirsize;