int ntfs_fstat_r(struct _reent *r, int fd, struct stat *st) { ntfs_log_trace("fd %p\n", (void *) fd); ntfs_file_state* file = STATE(((intptr_t)(s64)fd)); //ntfs_file_state* file = STATE(((s64) fd)); int ret = 0; // Sanity check if (!file || !file->vd || !file->ni || !file->data_na) { 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 = ntfsStat(file->vd, file->ni, st); if (ret) r->_errno = errno; return ret; }
int ntfs_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) { ntfs_log_trace("dirState %p, filename %p, filestat %p\n", dirState, filename, filestat); ntfs_dir_state* dir = STATE(dirState); ntfs_inode *ni = NULL; // Sanity check if (!dir || !dir->vd || !dir->ni) { r->_errno = EBADF; return -1; } // Lock ntfsLock(dir->vd); // Check that there is a entry waiting to be fetched if (!dir->current) { ntfsUnlock(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 = ntfsOpenEntry(dir->vd, dir->current->name); if (ni) { ntfsStat(dir->vd, ni, filestat); ntfsCloseEntry(dir->vd, ni); } } } // Move to the next entry in the directory dir->current = dir->current->next; // Update directory times ntfsUpdateTimes(dir->vd, dir->ni, NTFS_UPDATE_ATIME); // Unlock ntfsUnlock(dir->vd); return 0; }
int ntfs_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; ntfs_log_trace("path %s, st %p\n", path, st); ntfs_vd *vd = NULL; ntfs_inode *ni = NULL; // Get the volume descriptor for this path vd = ntfsGetVolume(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 ntfsLock(vd); // Find the entry ni = ntfsOpenEntry(vd, path); if (!ni) { r->_errno = errno; ntfsUnlock(vd); return -1; } // Get the entry stats int ret = ntfsStat(vd, ni, st); if (ret) r->_errno = errno; // Close the entry ntfsCloseEntry(vd, ni); ntfsUnlock(vd); return 0; }