Home | History | Annotate | Download | only in module
      1 /**
      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 
     22 extern uint op_dname_top;
     23 extern struct qstr **op_dname_stack;
     24 extern char * op_pool_pos;
     25 extern char * op_pool_start;
     26 extern char * op_pool_end;
     27 
     28 uint do_hash(struct dentry * dentry, struct vfsmount * vfsmnt, struct dentry * root, struct vfsmount * rootmnt);
     29 
     30 inline static uint alloc_in_pool(char const * str, uint len);
     31 inline static int add_hash_entry(struct op_hash_index * entry, uint parent, char const * name, uint len);
     32 inline static uint name_hash(char const * name, uint len, uint parent);
     33 
     34 inline 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 */
     45 inline 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 
     54 inline 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 
     62 inline 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 
     73 inline static char * get_from_pool(uint index)
     74 {
     75 	return op_pool_start + index;
     76 }
     77 
     78 inline 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 */
     88