summaryrefslogtreecommitdiffstats
path: root/linux-2.4.x/include/linux/mtd/compatmac.h
blob: 5433d1fa56ba1495daa973d563cfa0c8bf88dd21 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * $Id: compatmac.h,v 1.80 2005/11/07 11:14:54 gleixner Exp $
 *
 * Extensions and omissions from the normal 'linux/compatmac.h'
 * files. hopefully this will end up empty as the 'real' one
 * becomes fully-featured.
 */

#ifndef __LINUX_MTD_COMPATMAC_H__
#define __LINUX_MTD_COMPATMAC_H__

#include <linux/version.h>

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
#error "This kernel is too old: not supported by this file"
#endif

	/* O(1) scheduler stuff. */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,5) && !defined(__rh_config_h__)
#include <linux/sched.h>
static inline void __recalc_sigpending(void)
{
	recalc_sigpending(current);
}
#undef recalc_sigpending
#define recalc_sigpending() __recalc_sigpending ()

#define set_user_nice(tsk, n) do { (tsk)->nice = n; } while(0)
#endif



#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20)

#ifndef yield
#define yield() do { set_current_state(TASK_RUNNING); schedule(); } while(0)
#endif

#ifndef minor
#define major(d) (MAJOR(to_kdev_t(d)))
#define minor(d) (MINOR(to_kdev_t(d)))
#endif

#ifndef mk_kdev
#define mk_kdev(ma,mi) MKDEV(ma,mi)
#define kdev_t_to_nr(x)	(x)
#endif

#define need_resched() (current->need_resched)
#define cond_resched() do { if need_resched() { yield(); } } while(0)

#endif /* < 2.4.20 */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,73)
#define iminor(i) minor((i)->i_rdev)
#define imajor(i) major((i)->i_rdev)
#define old_encode_dev(d) ( (major(d)<<8) | minor(d) )
#define old_decode_dev(rdev)  (kdev_t_to_nr(mk_kdev((rdev)>>8, (rdev)&0xff)))
#define old_valid_dev(d) (1)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,61)

#include <linux/sched.h>

#ifdef __rh_config_h__
#define sigmask_lock sighand->siglock
#define sig sighand
#endif

static inline void __daemonize_modvers(void)
{
	daemonize();

	spin_lock_irq(&current->sigmask_lock);
	sigfillset(&current->blocked);
	recalc_sigpending();
	spin_unlock_irq(&current->sigmask_lock);
}
#undef daemonize
#define daemonize(fmt, ...) do {						\
	snprintf(current->comm, sizeof(current->comm), fmt ,##__VA_ARGS__);	\
	__daemonize_modvers();							\
	} while(0)

static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
{
	unsigned long flags;
	unsigned long ret;

	spin_lock_irqsave(&current->sigmask_lock, flags);
	ret = dequeue_signal(mask, info);
	spin_unlock_irqrestore(&current->sigmask_lock, flags);

	return ret;
}

static inline int allow_signal(int sig)
{
	if (sig < 1 || sig > _NSIG)
		return -EINVAL;

        spin_lock_irq(&current->sigmask_lock);
	sigdelset(&current->blocked, sig);
	recalc_sigpending();
	/* Make sure the kernel neither eats it now converts to SIGKILL */
	current->sig->action[sig-1].sa.sa_handler = (void *)2;
	spin_unlock_irq(&current->sigmask_lock);
	return 0;
}
static inline int disallow_signal(int sig)
{
	if (sig < 1 || sig > _NSIG)
		return -EINVAL;

	spin_lock_irq(&current->sigmask_lock);
	sigaddset(&current->blocked, sig);
	recalc_sigpending();

	current->sig->action[sig-1].sa.sa_handler = SIG_DFL;
	spin_unlock_irq(&current->sigmask_lock);
	return 0;
}

#define PF_FREEZE 0
#define refrigerator(x) do { ; } while(0)
#endif

	/* Module bits */


#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
#define try_module_get(m) try_inc_mod_count(m)
#define __module_get(m) do { if (!try_inc_mod_count(m)) BUG(); } while(0)
#define module_put(m) do { if (m) __MOD_DEC_USE_COUNT((struct module *)(m)); } while(0)
#define set_module_owner(x) do { x->owner = THIS_MODULE; } while(0)
#endif


	/* Random filesystem stuff, only for JFFS2 really */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,5)
#define parent_ino(d) ((d)->d_parent->d_inode->i_ino)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,12)
#define PageUptodate(x) Page_Uptodate(x)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,48)
#define get_seconds() CURRENT_TIME
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,53)
#define generic_file_readonly_mmap generic_file_mmap
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70)

#include <linux/kmod.h>
#include <linux/string.h>

static inline char *strlcpy(char *dest, const char *src, int len)
{
	dest[len-1] = 0;
	return strncpy(dest, src, len-1);
}

static inline int do_old_request_module(const char *mod)
{
	return request_module(mod);
}
#undef request_module
#define request_module(fmt, ...) \
 ({ char modname[32]; snprintf(modname, 31, fmt ,##__VA_ARGS__); do_old_request_module(modname); })

#endif /* 2.5.70 */

#ifndef container_of
#define container_of(ptr, type, member) ({		     \
	const typeof( ((type *)0)->member ) *__mptr = (ptr); \
	(type *)( (char *)__mptr - offsetof(type,member) );})
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7)
#define kvec iovec
#define __user
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,28)
#define msleep(x) \
	set_current_state(TASK_UNINTERRUPTIBLE); \
	schedule_timeout((x)*(HZ/1000));
#endif

#ifndef __iomem
#define __iomem
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
#define CURRENT_TIME_SEC ((struct timespec) { xtime.tv_sec, 0 })
#include <linux/sched.h>
#include <linux/suspend.h>
static inline int try_to_freeze(unsigned long refrigerator_flags)
{
	if (unlikely(current->flags & PF_FREEZE)) {
	        refrigerator(refrigerator_flags);
	        return 1;
	} else
	        return 0;
}
#endif

#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
#define try_to_freeze() try_to_freeze(0)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
typedef struct class_simple class;
#define class_device_create(cs, dev, device, fmt, ...) class_simple_device_add((struct class_simple *)cs, dev, device, fmt, __VA_ARGS__)
#define class_device_destroy(cs, dev) class_simple_device_remove(dev)
#define class_create(owner, name) (struct class *)class_simple_create(owner, name)
#define class_destroy(cs) class_simple_destroy((struct class_simple *)cs)
#endif

#ifndef list_for_each_entry_safe
/**
 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
 * @pos:	the type * to use as a loop counter.
 * @n:		another type * to use as temporary storage
 * @head:	the head for your list.
 * @member:	the name of the list_struct within the struct.
 */
#define list_for_each_entry_safe(pos, n, head, member)			\
	for (pos = list_entry((head)->next, typeof(*pos), member),	\
		n = list_entry(pos->member.next, typeof(*pos), member);	\
	     &pos->member != (head); 					\
	     pos = n, n = list_entry(n->member.next, typeof(*n), member))

#endif

#ifndef DEFINE_SPINLOCK
#define DEFINE_SPINLOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED
#endif
#ifndef DEFINE_RWLOCK
#define DEFINE_RWLOCK(x) rwlock_t x = RW_LOCK_UNLOCKED
#endif

#endif /* __LINUX_MTD_COMPATMAC_H__ */