]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/read_write.c
Linux 2.6.28-rc1
[linux-2.6-omap-h63xx.git] / fs / read_write.c
index f0d1240a5c6990c7639948fd9e2ce56f613cda2f..969a6d9c020ba01644578b04c86043b15e98b53a 100644 (file)
@@ -31,57 +31,63 @@ const struct file_operations generic_ro_fops = {
 
 EXPORT_SYMBOL(generic_ro_fops);
 
-loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
+/**
+ * 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;
 
-       mutex_lock(&inode->i_mutex);
        switch (origin) {
-               case SEEK_END:
-                       offset += inode->i_size;
-                       break;
-               case SEEK_CUR:
-                       offset += file->f_pos;
+       case SEEK_END:
+               offset += inode->i_size;
+               break;
+       case SEEK_CUR:
+               offset += file->f_pos;
+               break;
        }
-       retval = -EINVAL;
-       if (offset>=0 && offset<=inode->i_sb->s_maxbytes) {
-               if (offset != file->f_pos) {
-                       file->f_pos = offset;
-                       file->f_version = 0;
-               }
-               retval = offset;
+
+       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;
        }
-       mutex_unlock(&inode->i_mutex);
-       return retval;
-}
 
-EXPORT_SYMBOL(generic_file_llseek);
+       return offset;
+}
+EXPORT_SYMBOL(generic_file_llseek_unlocked);
 
-loff_t remote_llseek(struct file *file, loff_t offset, int origin)
+/**
+ * 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 retval;
+       loff_t rval;
 
-       lock_kernel();
-       switch (origin) {
-               case SEEK_END:
-                       offset += i_size_read(file->f_path.dentry->d_inode);
-                       break;
-               case SEEK_CUR:
-                       offset += file->f_pos;
-       }
-       retval = -EINVAL;
-       if (offset>=0 && offset<=file->f_path.dentry->d_inode->i_sb->s_maxbytes) {
-               if (offset != file->f_pos) {
-                       file->f_pos = offset;
-                       file->f_version = 0;
-               }
-               retval = offset;
-       }
-       unlock_kernel();
-       return retval;
+       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;
 }
-EXPORT_SYMBOL(remote_llseek);
+EXPORT_SYMBOL(generic_file_llseek);
 
 loff_t no_llseek(struct file *file, loff_t offset, int origin)
 {