/*! \brief Rewinds the directory iterator. \return - \c B_OK: Everything went fine. - \c B_PERMISSION_DENIED: Directory permissions didn't allow operation. - \c B_NO_MEMORY: Insufficient memory for operation. - \c B_LINK_LIMIT: Indicates a cyclic loop within the file system. - \c B_BUSY: A node was busy. - \c B_FILE_ERROR: A general file error. - \c B_NO_MORE_FDS: The application has run out of file descriptors. \see GetNextEntry(), GetNextRef(), GetNextDirents(), CountEntries() */ status_t BDirectory::Rewind() { if (InitCheck() != B_OK) return B_FILE_ERROR; return _kern_rewind_dir(fDirFd); }
/*! \brief Resets the object's attribute pointer to the first attribute in the list. \return - \c B_OK: Everything went fine. - \c B_FILE_ERROR: Some error occured. */ status_t BNode::RewindAttrs() { if (InitAttrDir() != B_OK) return B_FILE_ERROR; return _kern_rewind_dir(fAttrFd); }
static int do_seek_dir(DIR* dir) { if (dir->seek_position == dir->current_position) return 0; // If the seek position lies before the current position (the usual case), // rewind to the beginning. if (dir->seek_position < dir->current_position) { status_t status = _kern_rewind_dir(dir->fd); if (status < 0) { __set_errno(status); return -1; } dir->current_position = 0; dir->entries_left = 0; } // Now skip entries until we have reached seek_position. while (dir->seek_position > dir->current_position) { ssize_t count; long toSkip = dir->seek_position - dir->current_position; if (toSkip == dir->entries_left) { // we have to skip exactly all of the currently buffered entries dir->current_position = dir->seek_position; dir->entries_left = 0; return 0; } if (toSkip < dir->entries_left) { // we have to skip only some of the buffered entries for (; toSkip > 0; toSkip--) { struct dirent* entry = (struct dirent*) ((uint8*)&dir->first_entry + dir->next_entry); dir->entries_left--; dir->next_entry += entry->d_reclen; } dir->current_position = dir->seek_position; return 0; } // we have to skip more than the currently buffered entries dir->current_position += dir->entries_left; dir->entries_left = 0; count = _kern_read_dir(dir->fd, &dir->first_entry, (char*)dir + DIR_BUFFER_SIZE - (char*)&dir->first_entry, USHRT_MAX); if (count <= 0) { if (count < 0) __set_errno(count); // end of directory return -1; } dir->next_entry = 0; dir->entries_left = count; } return 0; }