[PATCH] mount udf UDF_PART_FLAG_READ_ONLY partitions with MS_RDONLY
[pandora-kernel.git] / fs / seq_file.c
index 650c43b..555b9ac 100644 (file)
  */
 int seq_open(struct file *file, struct seq_operations *op)
 {
-       struct seq_file *p = kmalloc(sizeof(*p), GFP_KERNEL);
-       if (!p)
-               return -ENOMEM;
+       struct seq_file *p = file->private_data;
+
+       if (!p) {
+               p = kmalloc(sizeof(*p), GFP_KERNEL);
+               if (!p)
+                       return -ENOMEM;
+               file->private_data = p;
+       }
        memset(p, 0, sizeof(*p));
-       sema_init(&p->sem, 1);
+       mutex_init(&p->lock);
        p->op = op;
-       file->private_data = p;
 
        /*
         * Wrappers around seq_open(e.g. swaps_open) need to be
@@ -51,7 +55,10 @@ EXPORT_SYMBOL(seq_open);
 
 /**
  *     seq_read -      ->read() method for sequential files.
- *     @file, @buf, @size, @ppos: see file_operations method
+ *     @file: the file to read from
+ *     @buf: the buffer to read to
+ *     @size: the maximum number of bytes to read
+ *     @ppos: the current position in the file
  *
  *     Ready-made ->f_op->read()
  */
@@ -64,7 +71,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
        void *p;
        int err = 0;
 
-       down(&m->sem);
+       mutex_lock(&m->lock);
        /*
         * seq_file->op->..m_start/m_stop/m_next may do special actions
         * or optimisations based on the file->f_version, so we want to
@@ -157,7 +164,7 @@ Done:
        else
                *ppos += copied;
        file->f_version = m->version;
-       up(&m->sem);
+       mutex_unlock(&m->lock);
        return copied;
 Enomem:
        err = -ENOMEM;
@@ -219,7 +226,9 @@ Eoverflow:
 
 /**
  *     seq_lseek -     ->llseek() method for sequential files.
- *     @file, @offset, @origin: see file_operations method
+ *     @file: the file in question
+ *     @offset: new position
+ *     @origin: 0 for absolute, 1 for relative position
  *
  *     Ready-made ->f_op->llseek()
  */
@@ -228,7 +237,7 @@ loff_t seq_lseek(struct file *file, loff_t offset, int origin)
        struct seq_file *m = (struct seq_file *)file->private_data;
        long long retval = -EINVAL;
 
-       down(&m->sem);
+       mutex_lock(&m->lock);
        m->version = file->f_version;
        switch (origin) {
                case 1:
@@ -251,7 +260,7 @@ loff_t seq_lseek(struct file *file, loff_t offset, int origin)
                                }
                        }
        }
-       up(&m->sem);
+       mutex_unlock(&m->lock);
        file->f_version = m->version;
        return retval;
 }