blob: 26560e1425636e3e4081e6f0010781870011d77d [file] [log] [blame]
Mike Dodd8cfa7022010-11-17 11:12:26 -08001/**
2 * @file op_dcache.h
3 * Compatibility functions for dcache lookups
4 *
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author Philippe Elie
9 * @author John Levon
10 */
11
12#ifndef OP_DCACHE_H
13#define OP_DCACHE_H
14
15#include <linux/sched.h>
16#include <linux/unistd.h>
17#include <linux/mman.h>
18#include <linux/file.h>
19
20#include "oprofile.h"
21
22extern uint op_dname_top;
23extern struct qstr **op_dname_stack;
24extern char * op_pool_pos;
25extern char * op_pool_start;
26extern char * op_pool_end;
27
28uint do_hash(struct dentry * dentry, struct vfsmount * vfsmnt, struct dentry * root, struct vfsmount * rootmnt);
29
30inline static uint alloc_in_pool(char const * str, uint len);
31inline static int add_hash_entry(struct op_hash_index * entry, uint parent, char const * name, uint len);
32inline static uint name_hash(char const * name, uint len, uint parent);
33
34inline static uint name_hash(char const * name, uint len, uint parent)
35{
36 uint hash=0;
37
38 while (len--)
39 hash = (hash + (name[len] << 4) + (name[len] >> 4)) * 11;
40
41 return (hash ^ parent) % OP_HASH_MAP_NR;
42}
43
44/* empty ascending dname stack */
45inline static void push_dname(struct qstr * dname)
46{
47 op_dname_stack[op_dname_top] = dname;
48 if (op_dname_top != DNAME_STACK_MAX)
49 op_dname_top++;
50 else
51 printk(KERN_ERR "oprofile: overflowed dname stack !\n");
52}
53
54inline static struct qstr * pop_dname(void)
55{
56 if (op_dname_top == 0)
57 return NULL;
58
59 return op_dname_stack[--op_dname_top];
60}
61
62inline static uint alloc_in_pool(char const * str, uint len)
63{
64 char * place = op_pool_pos;
65 if (op_pool_pos + len + 1 >= op_pool_end)
66 return 0;
67
68 strcpy(place, str);
69 op_pool_pos += len + 1;
70 return place - op_pool_start;
71}
72
73inline static char * get_from_pool(uint index)
74{
75 return op_pool_start + index;
76}
77
78inline static int add_hash_entry(struct op_hash_index * entry, uint parent, char const * name, uint len)
79{
80 entry->name = alloc_in_pool(name, len);
81 if (!entry->name)
82 return -1;
83 entry->parent = parent;
84 return 0;
85}
86
87#endif /* OP_DCACHE_H */