VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / oprofile / oprofilefs.c
index 2824c24..d9746f1 100644 (file)
@@ -47,23 +47,7 @@ static struct super_operations s_ops = {
 
 ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset)
 {
-       size_t len = strlen(str);
-
-       if (!count)
-               return 0;
-
-       if (*offset > len)
-               return 0;
-
-       if (count > len - *offset)
-               count = len - *offset;
-
-       if (copy_to_user(buf, str + *offset, count))
-               return -EFAULT;
-
-       *offset += count;
-
-       return count;
+       return simple_read_from_buffer(buf, count, offset, str, strlen(str));
 }
 
 
@@ -72,29 +56,10 @@ ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count
 ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset)
 {
        char tmpbuf[TMPBUFSIZE];
-       size_t maxlen;
-
-       if (!count)
-               return 0;
-
-       spin_lock(&oprofilefs_lock);
-       maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val);
-       spin_unlock(&oprofilefs_lock);
+       size_t maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val);
        if (maxlen > TMPBUFSIZE)
                maxlen = TMPBUFSIZE;
-
-       if (*offset > maxlen)
-               return 0;
-
-       if (count > maxlen - *offset)
-               count = maxlen - *offset;
-
-       if (copy_to_user(buf, tmpbuf + *offset, count))
-               return -EFAULT;
-
-       *offset += count;
-
-       return count;
+       return simple_read_from_buffer(buf, count, offset, tmpbuf, maxlen);
 }
 
 
@@ -165,7 +130,8 @@ static struct file_operations ulong_ro_fops = {
 
 
 static struct dentry * __oprofilefs_create_file(struct super_block * sb,
-       struct dentry * root, char const * name, struct file_operations * fops)
+       struct dentry * root, char const * name, struct file_operations * fops,
+       int perm)
 {
        struct dentry * dentry;
        struct inode * inode;
@@ -175,11 +141,11 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
        qname.hash = full_name_hash(qname.name, qname.len);
        dentry = d_alloc(root, &qname);
        if (!dentry)
-               return 0;
-       inode = oprofilefs_get_inode(sb, S_IFREG | 0644);
+               return NULL;
+       inode = oprofilefs_get_inode(sb, S_IFREG | perm);
        if (!inode) {
                dput(dentry);
-               return 0;
+               return NULL;
        }
        inode->i_fop = fops;
        d_add(dentry, inode);
@@ -190,7 +156,8 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
        char const * name, unsigned long * val)
 {
-       struct dentry * d = __oprofilefs_create_file(sb, root, name, &ulong_fops);
+       struct dentry * d = __oprofilefs_create_file(sb, root, name,
+                                                    &ulong_fops, 0644);
        if (!d)
                return -EFAULT;
 
@@ -202,7 +169,8 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
        char const * name, unsigned long * val)
 {
-       struct dentry * d = __oprofilefs_create_file(sb, root, name, &ulong_ro_fops);
+       struct dentry * d = __oprofilefs_create_file(sb, root, name,
+                                                    &ulong_ro_fops, 0444);
        if (!d)
                return -EFAULT;
 
@@ -227,7 +195,8 @@ static struct file_operations atomic_ro_fops = {
 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
        char const * name, atomic_t * val)
 {
-       struct dentry * d = __oprofilefs_create_file(sb, root, name, &atomic_ro_fops);
+       struct dentry * d = __oprofilefs_create_file(sb, root, name,
+                                                    &atomic_ro_fops, 0444);
        if (!d)
                return -EFAULT;
 
@@ -239,7 +208,16 @@ int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
        char const * name, struct file_operations * fops)
 {
-       if (!__oprofilefs_create_file(sb, root, name, fops))
+       if (!__oprofilefs_create_file(sb, root, name, fops, 0644))
+               return -EFAULT;
+       return 0;
+}
+
+
+int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
+       char const * name, struct file_operations * fops, int perm)
+{
+       if (!__oprofilefs_create_file(sb, root, name, fops, perm))
                return -EFAULT;
        return 0;
 }
@@ -256,11 +234,11 @@ struct dentry * oprofilefs_mkdir(struct super_block * sb,
        qname.hash = full_name_hash(qname.name, qname.len);
        dentry = d_alloc(root, &qname);
        if (!dentry)
-               return 0;
+               return NULL;
        inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
        if (!inode) {
                dput(dentry);
-               return 0;
+               return NULL;
        }
        inode->i_op = &simple_dir_inode_operations;
        inode->i_fop = &simple_dir_operations;