int ext2_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) { ext2_log_trace("dirState %p, filename %p, filestat %p\n", dirState, filename, filestat); if(!dirState) { r->_errno = EINVAL; return -1; } ext2_dir_state* dir = STATE(dirState); ext2_inode_t *ni = NULL; // Sanity check if (!dir || !dir->vd || !dir->ni) { r->_errno = EBADF; return -1; } // Lock ext2Lock(dir->vd); // Check that there is a entry waiting to be fetched if (!dir->current) { ext2Unlock(dir->vd); r->_errno = ENOENT; return -1; } // Fetch the current entry strcpy(filename, dir->current->name); if(filestat != NULL) { if(strcmp(dir->current->name, ".") == 0 || strcmp(dir->current->name, "..") == 0) { memset(filestat, 0, sizeof(struct stat)); filestat->st_mode = S_IFDIR; } else { ni = ext2OpenEntry(dir->vd, dir->current->name); if (ni) { ext2Stat(dir->vd, ni, filestat); ext2CloseEntry(dir->vd, ni); } } } // Move to the next entry in the directory dir->current = dir->current->next; // Update directory times ext2UpdateTimes(dir->vd, dir->ni, EXT2_UPDATE_ATIME); // Unlock ext2Unlock(dir->vd); return 0; }
int ext2_stat_r (struct _reent *r, const char *path, struct stat *st) { // Short circuit cases were we don't actually have to do anything if (!st || !path) return 0; ext2_log_trace("path %s, st %p\n", path, st); ext2_vd *vd = NULL; ext2_inode_t *ni = NULL; // Get the volume descriptor for this path vd = ext2GetVolume(path); if (!vd) { r->_errno = ENODEV; return -1; } if(strcmp(path, ".") == 0 || strcmp(path, "..") == 0) { memset(st, 0, sizeof(struct stat)); st->st_mode = S_IFDIR; return 0; } // Lock ext2Lock(vd); // Find the entry ni = ext2OpenEntry(vd, path); if (!ni) { r->_errno = errno; ext2Unlock(vd); return -1; } // Get the entry stats int ret = ext2Stat(vd, ni, st); if (ret) r->_errno = errno; // Close the entry ext2CloseEntry(vd, ni); ext2Unlock(vd); return 0; }
int ext2_fstat_r (struct _reent *r, int fd, struct stat *st) { ext2_log_trace("fd %p\n", (void *) fd); ext2_file_state* file = STATE(fd); int ret = 0; // Sanity check if (!file || !file->vd || !file->ni || !file->fd) { r->_errno = EINVAL; return -1; } // Short circuit cases were we don't actually have to do anything if (!st) return 0; // Get the file stats ret = ext2Stat(file->vd, file->ni, st); if (ret) r->_errno = errno; return ret; }