I know my question has the answer here: QFile to look for performance . But I'm not quite happy with the answer. Even after considering the next implementation of generic_file_llseek() for ext4, I cannot figure out how to measure complexity.
loff_t generic_file_llseek(struct file *file, loff_t offset, int origin) { loff_t rval; mutex_lock(&file->f_dentry->d_inode->i_mutex); rval = generic_file_llseek_unlocked(file, offset, origin); mutex_unlock(&file->f_dentry->d_inode->i_mutex); return rval; } loff_t generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin) { struct inode *inode = file->f_mapping->host; switch (origin) { case SEEK_END: offset += inode->i_size; break; case SEEK_CUR: if (offset == 0) return file->f_pos; break; } if (offset < 0 || offset > inode->i_sb->s_maxbytes) return -EINVAL; if (offset != file->f_pos) { file->f_pos = offset; file->f_version = 0; } return offset; }
Say, for example, I have a 4 GB file and I know the offset for the middle part of the file, how exactly does lseek() get me there without crossing the whole file? Does the OS mean where every byte of the file is?
source share