Click
Loading...
Searching...
No Matches
ino.hh
1// -*- c-basic-offset: 4; related-file-name: "../../lib/ino.cc" -*-
2#ifndef CLICK_INO_HH
3#define CLICK_INO_HH
4#include <click/router.hh>
5CLICK_DECLS
6
7#define INO_DEBUG 0
8
9// /click: .e > .h > element names > global handlers [dt_global]
10// /click/.e: element numbers [dt_u]
11// /click/.e/NUM: handlers [dt_hu]
12// /click/.h: global handlers [dt_hh]
13// /click/ELEMENTNAME: .h > element names > element handlers [dt_hn]
14// /click/ELEMENTNAME/.h: element handlers [dt_hh]
15
16class ClickIno { public:
17
18 void initialize();
19 void cleanup();
20
21 uint32_t generation() const { return _generation; }
22
23 // NB: inode number 0 is reserved for the system.
24 enum { dt_u = 1U, dt_hh = 2U, dt_hu = 3U, dt_hn = 4U, dt_global = 5U };
25 enum { ino_globaldir = (unsigned) (dt_global << 28),
26 ino_enumdir = (unsigned) (dt_u << 28) };
27 static bool is_handler(unsigned ino) { return (int32_t) ino < 0; }
28 static unsigned dirtype(unsigned ino) { return ino >> 28; }
29 static bool has_element(unsigned ino) { return ino & 0xFFFFU; }
30 static bool has_handlers(unsigned ino) { return ino > (dt_u << 28); }
31 static bool has_names(unsigned ino) { return ino >= (dt_hn << 28); }
32 static int ino_element(unsigned ino) { return (int) (ino & 0xFFFFU) - 1; }
33 static int ino_handler(unsigned ino) {
34 return (has_element(ino) ? 0 : Router::FIRST_GLOBAL_HANDLER)
35 + ((ino >> 16) & 0x7FFFU);
36 }
37
38 static unsigned make_handler(int e, int hi) {
39 return 0x80000000U | ((hi & 0x7FFFU) << 16) | ((e + 1) & 0xFFFFU);
40 }
41 static unsigned make_dir(unsigned dtype, int e) {
42 return (dtype << 28) | ((e + 1) & 0xFFFFU);
43 }
44
45
46 // These operations should be called with a configuration lock held.
47 inline int prepare(Router *router, uint32_t generation);
48 int nlink(ino_t ino);
49 ino_t lookup(ino_t dir, const String &component);
50
51 // readdir handles '..' (f_pos 0) and '.' (f_pos 1).
52 // It returns the number of things stored.
53 typedef bool (*filldir_t)(const char *name, int name_len, ino_t ino, int dirtype, loff_t f_pos, void *user_data);
54 int readdir(ino_t dir, loff_t &f_pos, filldir_t fd, void *user_data);
55
56#if INO_DEBUG
57 String info() const;
58#endif
59
60 struct Entry {
61 // Name of this entry.
62 String name;
63
64 // Corresponding eindex plus 1. Might be larger than the number of
65 // elements in the router, because of fake directories added for
66 // compound "elements".
67 uint16_t elementno_plus1;
68
69 // '_x[i].xindex' equals the index in _x of the entry for element
70 // number 'i - 1'.
71 uint16_t xindex;
72
73 // Number of child entries. 'name' is guaranteed to be a prefix of
74 // every child entry.
75 uint16_t skip;
76
77 // See enum below. X_FAKE is true on fake directories added for
78 // compound elements.
79 uint16_t flags;
80 };
81
82 private:
83 enum { X_FAKE = 1 };
84
85 Entry* _x;
86 int _nentries;
87 int _cap;
88 Router* _router;
89 uint32_t _generation;
90
91 inline int xindex(int elementno) const;
92 inline int next_xindex(int elementno) const;
93 inline int elementno(int xindex) const;
94
95 int name_search(const String &n, int first_xi, int last_xi, int name_offset) const;
96 int element_name_search(const String &n, int elementno) const;
97
98 int grow(int min_size);
99 int true_prepare(Router*, uint32_t);
100};
101
102
103inline int
104ClickIno::prepare(Router* router, uint32_t generation)
105{
106 if (generation != _generation)
107 return true_prepare(router, generation);
108 else
109 return 0;
110}
111
112inline int
113ClickIno::xindex(int elementno) const
114{
115 assert(elementno >= -1 && elementno < _nentries - 1);
116 return _x[elementno + 1].xindex;
117}
118
119inline int
120ClickIno::next_xindex(int elementno) const
121{
122 int xi = xindex(elementno);
123 return xi + _x[xi].skip + 1;
124}
125
126inline int
127ClickIno::elementno(int xindex) const
128{
129 return _x[xindex].elementno_plus1 - 1;
130}
131
132CLICK_ENDDECLS
133#endif
A router configuration.
Definition router.hh:28
A string of characters.
Definition string.hh:22
The Router class implementing a router configuration.