1/*
2 * wrapping of libc features and kernel interfaces
3 *
4 * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
5 *
6 *	This program is free software; you can redistribute it and/or modify it
7 *	under the terms of the GNU General Public License as published by the
8 *	Free Software Foundation version 2 of the License.
9 *
10 *	This program is distributed in the hope that it will be useful, but
11 *	WITHOUT ANY WARRANTY; without even the implied warranty of
12 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *	General Public License for more details.
14 *
15 *	You should have received a copy of the GNU General Public License along
16 *	with this program; if not, write to the Free Software Foundation, Inc.,
17 *	51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 *
19 */
20
21#ifndef _UDEV_SYSDEPS_H_
22#define _UDEV_SYSDEPS_H_
23
24#include <string.h>
25#include <unistd.h>
26#include <stdint.h>
27
28/* needed until Inotify! syscalls reach glibc */
29#include <sys/syscall.h>
30#ifndef __NR_inotify_init
31#if defined(__i386__)
32# define __NR_inotify_init	291
33# define __NR_inotify_add_watch	292
34# define __NR_inotify_rm_watch	293
35#elif defined(__x86_64__)
36# define __NR_inotify_init	253
37# define __NR_inotify_add_watch	254
38# define __NR_inotify_rm_watch	255
39#elif defined(__powerpc__) || defined(__powerpc64__)
40# define __NR_inotify_init	275
41# define __NR_inotify_add_watch	276
42# define __NR_inotify_rm_watch	277
43#elif defined(__ia64__)
44# define __NR_inotify_init	1277
45# define __NR_inotify_add_watch	1278
46# define __NR_inotify_rm_watch	1279
47#elif defined(__s390__)
48# define __NR_inotify_init	284
49# define __NR_inotify_add_watch	285
50# define __NR_inotify_rm_watch	286
51#elif defined(__alpha__)
52# define __NR_inotify_init	444
53# define __NR_inotify_add_watch	445
54# define __NR_inotify_rm_watch	446
55#elif defined(__sparc__) || defined(__sparc64__)
56# define __NR_inotify_init	151
57# define __NR_inotify_add_watch	152
58# define __NR_inotify_rm_watch	156
59#elif defined(__arm__)
60# define __NR_inotify_init	__NR_SYSCALL_BASE+316
61# define __NR_inotify_add_watch	__NR_SYSCALL_BASE+317
62# define __NR_inotify_rm_watch	__NR_SYSCALL_BASE+318
63#elif defined(__sh__)
64# define __NR_inotify_init	290
65# define __NR_inotify_add_watch	291
66# define __NR_inotify_rm_watch	292
67#elif defined(__m32r__)
68# define __NR_inotify_init	290
69# define __NR_inotify_add_watch	291
70# define __NR_inotify_rm_watch	292
71#elif defined(__hppa__)
72# define __NR_inotify_init      269
73# define __NR_inotify_add_watch 270
74# define __NR_inotify_rm_watch  271
75#elif defined(__mips__)
76# include <sgidefs.h>
77# if _MIPS_SIM == _MIPS_SIM_ABI32
78#  define __NR_Linux             4000
79#  define __NR_inotify_init      (__NR_Linux + 284)
80#  define __NR_inotify_add_watch (__NR_Linux + 285)
81#  define __NR_inotify_rm_watch  (__NR_Linux + 286)
82# elif _MIPS_SIM == _MIPS_SIM_ABI64
83#  define __NR_Linux             5000
84#  define __NR_inotify_init      (__NR_Linux + 243)
85#  define __NR_inotify_add_watch (__NR_Linux + 244)
86#  define __NR_inotify_rm_watch  (__NR_Linux + 245)
87# elif _MIPS_SIM == _MIPS_SIM_NABI32
88#  define __NR_Linux             6000
89#  define __NR_inotify_init      (__NR_Linux + 247)
90#  define __NR_inotify_add_watch (__NR_Linux + 248)
91#  define __NR_inotify_rm_watch  (__NR_Linux + 249)
92# endif
93#else
94#warning "inotify unsupported on this architecture!"
95#endif
96#endif /* __NR_inotify_init */
97
98/* dummy if we don't have the syscalls defined */
99#ifndef __NR_inotify_init
100static inline int inotify_init(void)
101{
102	return -1;
103}
104
105static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
106{
107	return -1;
108}
109#else
110/* needed until /usr/include/sys/inotify.h is working */
111#ifndef __GLIBC__
112#include <sys/inotify.h>
113#else
114static inline int inotify_init(void)
115{
116	return syscall(__NR_inotify_init);
117}
118
119static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
120{
121	return syscall(__NR_inotify_add_watch, fd, name, mask);
122}
123#endif /* __GLIBC__ */
124#endif /* __NR_inotify_init */
125
126#ifndef IN_CREATE
127#define IN_CREATE		0x00000100	/* Subfile was created */
128#define IN_MOVED_FROM		0x00000040	/* File was moved from X */
129#define IN_MOVED_TO		0x00000080	/* File was moved to Y */
130#define IN_DELETE		0x00000200	/* Subfile was deleted */
131#define IN_CLOSE_WRITE		0x00000008	/* Writtable file was closed */
132#define IN_MOVE			(IN_MOVED_FROM | IN_MOVED_TO) /* moves */
133#endif /* IN_CREATE */
134
135/* needed for our signal handlers to work */
136#undef asmlinkage
137#ifdef __i386__
138#define asmlinkage	__attribute__((regparm(0)))
139#else
140#define asmlinkage
141#endif /* __i386__ */
142
143/* headers are broken on some architectures */
144#ifndef __FD_SET
145#define __FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
146#endif
147#ifndef __FD_CLR
148#define __FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d))
149#endif
150#ifndef __FD_ISSET
151#define __FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0)
152#endif
153#ifndef __FD_ZERO
154#define __FD_ZERO(set) ((void) memset ((void*) (set), 0, sizeof (fd_set)))
155#endif
156
157#ifndef NETLINK_KOBJECT_UEVENT
158#define NETLINK_KOBJECT_UEVENT	15
159#endif
160
161#ifndef SO_RCVBUFFORCE
162#if defined(__alpha__) || defined(__hppa__) || defined(__sparc__) || \
163	defined(__sparc_v9__)
164#define SO_RCVBUFFORCE 0x100b
165#else
166#define SO_RCVBUFFORCE 33
167#endif
168#endif
169
170extern size_t strlcpy(char *dst, const char *src, size_t size);
171extern size_t strlcat(char *dst, const char *src, size_t size);
172
173#endif
174