Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a8cff4f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Al Viro
Browse files

[PATCH] generic_file_llseek tidyups



Add kerneldoc for generic_file_llseek and generic_file_llseek_unlocked,
use sane variable names and unclutter the code.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent a518ab93
Loading
Loading
Loading
Loading
+40 −18
Original line number Diff line number Diff line
@@ -31,10 +31,18 @@ const struct file_operations generic_ro_fops = {

EXPORT_SYMBOL(generic_ro_fops);

/**
 * generic_file_llseek_unlocked - lockless generic llseek implementation
 * @file:	file structure to seek on
 * @offset:	file offset to seek to
 * @origin:	type of seek
 *
 * Updates the file offset to the value specified by @offset and @origin.
 * Locking must be provided by the caller.
 */
loff_t
generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
{
	loff_t retval;
	struct inode *inode = file->f_mapping->host;

	switch (origin) {
@@ -43,27 +51,41 @@ generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
		break;
	case SEEK_CUR:
		offset += file->f_pos;
		break;
	}
	retval = -EINVAL;
	if (offset>=0 && offset<=inode->i_sb->s_maxbytes) {

	if (offset < 0 || offset > inode->i_sb->s_maxbytes)
		return -EINVAL;

	/* Special lock needed here? */
	if (offset != file->f_pos) {
		file->f_pos = offset;
		file->f_version = 0;
	}
		retval = offset;
	}
	return retval;

	return offset;
}
EXPORT_SYMBOL(generic_file_llseek_unlocked);

/**
 * generic_file_llseek - generic llseek implementation for regular files
 * @file:	file structure to seek on
 * @offset:	file offset to seek to
 * @origin:	type of seek
 *
 * This is a generic implemenation of ->llseek useable for all normal local
 * filesystems.  It just updates the file offset to the value specified by
 * @offset and @origin under i_mutex.
 */
loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
{
	loff_t n;
	loff_t rval;

	mutex_lock(&file->f_dentry->d_inode->i_mutex);
	n = generic_file_llseek_unlocked(file, offset, origin);
	rval = generic_file_llseek_unlocked(file, offset, origin);
	mutex_unlock(&file->f_dentry->d_inode->i_mutex);
	return n;

	return rval;
}
EXPORT_SYMBOL(generic_file_llseek);