File: proc_fs_compatibility.h

package info (click to toggle)
systemtap 2.6-0.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,220 kB
  • ctags: 10,944
  • sloc: cpp: 53,239; ansic: 50,615; exp: 33,694; sh: 9,906; xml: 7,665; perl: 2,089; python: 1,534; tcl: 1,236; makefile: 797; java: 148; lisp: 104; awk: 94; asm: 91; sed: 16
file content (79 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* -*- linux-c -*-
 *
 * procfs compatibility defines and functions
 * Copyright (C) 2013 Red Hat Inc.
 *
 * This file is part of systemtap, and is free software.  You can
 * redistribute it and/or modify it under the terms of the GNU General
 * Public License (GPL); either version 2, or (at your option) any
 * later version.
 */

#ifndef _STP_PROC_FS_COMPATIBILITY_H_
#define _STP_PROC_FS_COMPATIBILITY_H_

#include <linux/proc_fs.h>

/* If STAPCONF_PDE_DATA isn't defined, we're using the original /proc
 * interface (where 'struct proc_dir_entry' isn't opaque). Provide
 * some of the new interface's functions. */
#ifndef STAPCONF_PDE_DATA

#ifndef STAPCONF_LINUX_UIDGID_H
static void proc_set_user(struct proc_dir_entry *de, uid_t uid, gid_t gid)
{
	de->uid = uid;
	de->gid = gid;
}
#else
static void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid)
{
	de->uid = __kuid_val(uid);
	de->gid = __kgid_val(gid);
}
#endif

// 2.6.24 fixed proc_dir_entry refcounting.
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
#define LAST_ENTRY_COUNT 0
#else
#define LAST_ENTRY_COUNT 1
#endif

/* Notice that this proc_remove() compatibility function isn't
 * exactly like the original, since it can remove entire
 * subtrees. Since we don't call proc_remove() to remove subtrees,
 * this is OK. */
static void proc_remove(struct proc_dir_entry *de)
{
	if (de && de->subdir == NULL) {
		if (atomic_read(&de->count) != LAST_ENTRY_COUNT)
			printk(KERN_ERR "Removal of %s from /proc"
			       " is deferred until it is no longer in use.\n"
			       "Systemtap module removal will block.\n",
			       de->name);
		remove_proc_entry(de->name, de->parent);
	}
}

/* The 'proc_create_data()' function was present before the new /proc
 * interface make 'struct proc_dir_entry' opaque. */
#ifndef STAPCONF_PROC_CREATE_DATA
static struct proc_dir_entry *
proc_create_data(const char *name, umode_t mode,
		 struct proc_dir_entry *parent,
		 const struct file_operations *proc_fops, void *data)
{
	struct proc_dir_entry *de;
	de = proc_create(name, mode, parent, proc_fops);
	if (de)
		de->data = data;
	return de;
}
#endif  /* STAPCONF_PROC_CREATE_DATA */

#define PDE_DATA(inode) (PDE(inode)->data)

#endif  /* STAPCONF_PDE_DATA */

#endif	/* _STP_PROC_FS_COMPATIBILITY_H_ */