cregit-Linux how code gets into the kernel

Release 4.7 drivers/oprofile/oprofilefs.c

Directory: drivers/oprofile
/**
 * @file oprofilefs.c
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon
 *
 * A simple filesystem for configuration and
 * access of oprofile.
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/oprofile.h>
#include <linux/fs.h>
#include <linux/pagemap.h>
#include <asm/uaccess.h>

#include "oprof.h"


#define OPROFILEFS_MAGIC 0x6f70726f


DEFINE_RAW_SPINLOCK(oprofilefs_lock);


static struct inode *oprofilefs_get_inode(struct super_block *sb, int mode) { struct inode *inode = new_inode(sb); if (inode) { inode->i_ino = get_next_ino(); inode->i_mode = mode; inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; } return inode; }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon5588.71%150.00%
christoph hellwigchristoph hellwig711.29%150.00%
Total62100.00%2100.00%

static const struct super_operations s_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, };
ssize_t oprofilefs_str_to_user(char const *str, char __user *buf, size_t count, loff_t *offset) { return simple_read_from_buffer(buf, count, offset, str, strlen(str)); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon2974.36%133.33%
al viroal viro1025.64%266.67%
Total39100.00%3100.00%

#define TMPBUFSIZE 50
ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user *buf, size_t count, loff_t *offset) { char tmpbuf[TMPBUFSIZE]; size_t maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val); if (maxlen > TMPBUFSIZE) maxlen = TMPBUFSIZE; return simple_read_from_buffer(buf, count, offset, tmpbuf, maxlen); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon5686.15%133.33%
al viroal viro913.85%266.67%
Total65100.00%3100.00%

/* * Note: If oprofilefs_ulong_from_user() returns 0, then *val remains * unchanged and might be uninitialized. This follows write syscall * implementation when count is zero: "If count is zero ... [and if] * no errors are detected, 0 will be returned without causing any * other effect." (man 2 write) */
int oprofilefs_ulong_from_user(unsigned long *val, char const __user *buf, size_t count) { char tmpbuf[TMPBUFSIZE]; unsigned long flags; if (!count) return 0; if (count > TMPBUFSIZE - 1) return -EINVAL; memset(tmpbuf, 0x0, TMPBUFSIZE); if (copy_from_user(tmpbuf, buf, count)) return -EFAULT; raw_spin_lock_irqsave(&oprofilefs_lock, flags); *val = simple_strtoul(tmpbuf, NULL, 0); raw_spin_unlock_irqrestore(&oprofilefs_lock, flags); return count; }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon9288.46%233.33%
jiri kosinajiri kosina87.69%116.67%
thomas gleixnerthomas gleixner21.92%116.67%
al viroal viro10.96%116.67%
robert richterrobert richter10.96%116.67%
Total104100.00%6100.00%


static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset) { unsigned long *val = file->private_data; return oprofilefs_ulong_to_user(*val, buf, count, offset); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon4497.78%266.67%
al viroal viro12.22%133.33%
Total45100.00%3100.00%


static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) { unsigned long value; int retval; if (*offset) return -EINVAL; retval = oprofilefs_ulong_from_user(&value, buf, count); if (retval <= 0) return retval; retval = oprofile_set_ulong(file->private_data, value); if (retval) return retval; return count; }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon6073.17%125.00%
robert richterrobert richter2125.61%250.00%
al viroal viro11.22%125.00%
Total82100.00%4100.00%

static const struct file_operations ulong_fops = { .read = ulong_read_file, .write = ulong_write_file, .open = simple_open, .llseek = default_llseek, }; static const struct file_operations ulong_ro_fops = { .read = ulong_read_file, .open = simple_open, .llseek = default_llseek, };
static int __oprofilefs_create_file(struct dentry *root, char const *name, const struct file_operations *fops, int perm, void *priv) { struct dentry *dentry; struct inode *inode; inode_lock(d_inode(root)); dentry = d_alloc_name(root, name); if (!dentry) { inode_unlock(d_inode(root)); return -ENOMEM; } inode = oprofilefs_get_inode(root->d_sb, S_IFREG | perm); if (!inode) { dput(dentry); inode_unlock(d_inode(root)); return -ENOMEM; } inode->i_fop = fops; inode->i_private = priv; d_add(dentry, inode); inode_unlock(d_inode(root)); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon8157.04%111.11%
al viroal viro2920.42%333.33%
robert richterrobert richter139.15%111.11%
david howellsdavid howells128.45%111.11%
andrew mortonandrew morton42.82%111.11%
james morrisjames morris21.41%111.11%
arjan van de venarjan van de ven10.70%111.11%
Total142100.00%9100.00%


int oprofilefs_create_ulong(struct dentry *root, char const *name, unsigned long *val) { return __oprofilefs_create_file(root, name, &ulong_fops, 0644, val); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon3085.71%133.33%
robert richterrobert richter38.57%133.33%
andrew mortonandrew morton25.71%133.33%
Total35100.00%3100.00%


int oprofilefs_create_ro_ulong(struct dentry *root, char const *name, unsigned long *val) { return __oprofilefs_create_file(root, name, &ulong_ro_fops, 0444, val); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon3085.71%133.33%
robert richterrobert richter38.57%133.33%
andrew mortonandrew morton25.71%133.33%
Total35100.00%3100.00%


static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset) { atomic_t *val = file->private_data; return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon4597.83%266.67%
al viroal viro12.17%133.33%
Total46100.00%3100.00%

static const struct file_operations atomic_ro_fops = { .read = atomic_read_file, .open = simple_open, .llseek = default_llseek, };
int oprofilefs_create_ro_atomic(struct dentry *root, char const *name, atomic_t *val) { return __oprofilefs_create_file(root, name, &atomic_ro_fops, 0444, val); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon2985.29%133.33%
robert richterrobert richter38.82%133.33%
andrew mortonandrew morton25.88%133.33%
Total34100.00%3100.00%


int oprofilefs_create_file(struct dentry *root, char const *name, const struct file_operations *fops) { return __oprofilefs_create_file(root, name, fops, 0644, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon2674.29%125.00%
andrew mortonandrew morton514.29%125.00%
robert richterrobert richter38.57%125.00%
arjan van de venarjan van de ven12.86%125.00%
Total35100.00%4100.00%


int oprofilefs_create_file_perm(struct dentry *root, char const *name, const struct file_operations *fops, int perm) { return __oprofilefs_create_file(root, name, fops, perm, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton3181.58%125.00%
robert richterrobert richter37.89%125.00%
john levonjohn levon37.89%125.00%
arjan van de venarjan van de ven12.63%125.00%
Total38100.00%4100.00%


struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name) { struct dentry *dentry; struct inode *inode; inode_lock(d_inode(parent)); dentry = d_alloc_name(parent, name); if (!dentry) { inode_unlock(d_inode(parent)); return NULL; } inode = oprofilefs_get_inode(parent->d_sb, S_IFDIR | 0755); if (!inode) { dput(dentry); inode_unlock(d_inode(parent)); return NULL; } inode->i_op = &simple_dir_inode_operations; inode->i_fop = &simple_dir_operations; d_add(dentry, inode); inode_unlock(d_inode(parent)); return dentry; }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon8766.92%114.29%
al viroal viro2720.77%342.86%
david howellsdavid howells129.23%114.29%
james morrisjames morris21.54%114.29%
mika kukkonenmika kukkonen21.54%114.29%
Total130100.00%7100.00%


static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent) { struct inode *root_inode; sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; sb->s_magic = OPROFILEFS_MAGIC; sb->s_op = &s_ops; sb->s_time_gran = 1; root_inode = oprofilefs_get_inode(sb, S_IFDIR | 0755); if (!root_inode) return -ENOMEM; root_inode->i_op = &simple_dir_inode_operations; root_inode->i_fop = &simple_dir_operations; sb->s_root = d_make_root(root_inode); if (!sb->s_root) return -ENOMEM; oprofile_create_files(sb->s_root); // FIXME: verify kill_litter_super removes our dentries return 0; }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon10285.71%120.00%
al viroal viro97.56%240.00%
andi kleenandi kleen65.04%120.00%
kirill a. shutemovkirill a. shutemov21.68%120.00%
Total119100.00%5100.00%


static struct dentry *oprofilefs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { return mount_single(fs_type, flags, data, oprofilefs_fill_super); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon3183.78%133.33%
al viroal viro513.51%133.33%
andries brouwerandries brouwer12.70%133.33%
Total37100.00%3100.00%

static struct file_system_type oprofilefs_type = { .owner = THIS_MODULE, .name = "oprofilefs", .mount = oprofilefs_mount, .kill_sb = kill_litter_super, }; MODULE_ALIAS_FS("oprofilefs");
int __init oprofilefs_register(void) { return register_filesystem(&oprofilefs_type); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon15100.00%1100.00%
Total15100.00%1100.00%


void __exit oprofilefs_unregister(void) { unregister_filesystem(&oprofilefs_type); }

Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon14100.00%1100.00%
Total14100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
john levonjohn levon95577.20%514.71%
al viroal viro957.68%926.47%
robert richterrobert richter514.12%38.82%
andrew mortonandrew morton463.72%12.94%
david howellsdavid howells241.94%12.94%
arnd bergmannarnd bergmann151.21%12.94%
jiri kosinajiri kosina80.65%12.94%
christoph hellwigchristoph hellwig70.57%12.94%
andi kleenandi kleen60.49%12.94%
thomas gleixnerthomas gleixner60.49%25.88%
arjan van de venarjan van de ven60.49%25.88%
eric w. biedermaneric w. biederman50.40%12.94%
james morrisjames morris40.32%12.94%
stephen boydstephen boyd30.24%12.94%
kirill a. shutemovkirill a. shutemov20.16%12.94%
mika kukkonenmika kukkonen20.16%12.94%
andries brouwerandries brouwer10.08%12.94%
alexey dobriyanalexey dobriyan10.08%12.94%
Total1237100.00%34100.00%
Directory: drivers/oprofile
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}