libbb.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Busybox main internal header file
  4. *
  5. * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
  6. * Permission has been granted to redistribute this code under the GPL.
  7. *
  8. * Licensed under the GPL version 2, see the file LICENSE in this tarball.
  9. */
  10. #ifndef __LIBBUSYBOX_H__
  11. #define __LIBBUSYBOX_H__ 1
  12. #include "platform.h"
  13. #include <ctype.h>
  14. #include <dirent.h>
  15. #include <errno.h>
  16. #include <fcntl.h>
  17. #include <inttypes.h>
  18. #include <malloc.h>
  19. #include <netdb.h>
  20. #include <setjmp.h>
  21. #include <signal.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <stdarg.h>
  25. #include <string.h>
  26. #include <strings.h>
  27. #include <sys/ioctl.h>
  28. #include <sys/mman.h>
  29. #include <sys/socket.h>
  30. #include <sys/stat.h>
  31. #include <sys/statfs.h>
  32. #include <sys/time.h>
  33. #include <sys/types.h>
  34. #include <sys/wait.h>
  35. #include <termios.h>
  36. #include <time.h>
  37. #include <unistd.h>
  38. #include <utime.h>
  39. #ifdef CONFIG_SELINUX
  40. #include <selinux/selinux.h>
  41. #endif
  42. #ifdef CONFIG_LOCALE_SUPPORT
  43. #include <locale.h>
  44. #else
  45. #define setlocale(x,y) ((void)0)
  46. #endif
  47. #include "pwd_.h"
  48. #include "grp_.h"
  49. /* ifdef it out, because it may include <shadow.h> */
  50. /* and we may not even _have_ <shadow.h>! */
  51. #if ENABLE_FEATURE_SHADOWPASSWDS
  52. #include "shadow_.h"
  53. #endif
  54. /* Try to pull in PATH_MAX */
  55. #include <limits.h>
  56. #include <sys/param.h>
  57. #ifndef PATH_MAX
  58. #define PATH_MAX 256
  59. #endif
  60. /* Tested to work correctly (IIRC :]) */
  61. #define MAXINT(T) (T)( \
  62. ((T)-1) > 0 \
  63. ? (T)-1 \
  64. : (T)~((T)1 << (sizeof(T)*8-1)) \
  65. )
  66. #define MININT(T) (T)( \
  67. ((T)-1) > 0 \
  68. ? (T)0 \
  69. : ((T)1 << (sizeof(T)*8-1)) \
  70. )
  71. /* Large file support */
  72. /* Note that CONFIG_LFS forces bbox to be built with all common ops
  73. * (stat, lseek etc) mapped to "largefile" variants by libc.
  74. * Practically it means that open() automatically has O_LARGEFILE added
  75. * and all filesize/file_offset parameters and struct members are "large"
  76. * (in today's world - signed 64bit). For full support of large files,
  77. * we need a few helper #defines (below) and careful use of off_t
  78. * instead of int/ssize_t. No lseek64(), O_LARGEFILE etc necessary */
  79. #if ENABLE_LFS
  80. /* CONFIG_LFS is on */
  81. # if ULONG_MAX > 0xffffffff
  82. /* "long" is long enough on this system */
  83. # define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
  84. /* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
  85. # define BB_STRTOOFF bb_strtoul
  86. # define STRTOOFF strtoul
  87. /* usage: printf("size: %"OFF_FMT"d (%"OFF_FMT"x)\n", sz, sz); */
  88. # define OFF_FMT "l"
  89. # else
  90. /* "long" is too short, need "long long" */
  91. # define XATOOFF(a) xatoull_range(a, 0, LLONG_MAX)
  92. # define BB_STRTOOFF bb_strtoull
  93. # define STRTOOFF strtoull
  94. # define OFF_FMT "ll"
  95. # endif
  96. #else
  97. /* CONFIG_LFS is off */
  98. # if UINT_MAX == 0xffffffff
  99. /* While sizeof(off_t) == sizeof(int), off_t is typedef'ed to long anyway.
  100. * gcc will throw warnings on printf("%d", off_t). Crap... */
  101. # define XATOOFF(a) xatoi_u(a)
  102. # define BB_STRTOOFF bb_strtou
  103. # define STRTOOFF strtol
  104. # define OFF_FMT "l"
  105. # else
  106. # define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
  107. # define BB_STRTOOFF bb_strtoul
  108. # define STRTOOFF strtol
  109. # define OFF_FMT "l"
  110. # endif
  111. #endif
  112. /* scary. better ideas? (but do *test* them first!) */
  113. #define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
  114. /* Some useful definitions */
  115. #undef FALSE
  116. #define FALSE ((int) 0)
  117. #undef TRUE
  118. #define TRUE ((int) 1)
  119. #undef SKIP
  120. #define SKIP ((int) 2)
  121. /* for mtab.c */
  122. #define MTAB_GETMOUNTPT '1'
  123. #define MTAB_GETDEVICE '2'
  124. #define BUF_SIZE 8192
  125. #define EXPAND_ALLOC 1024
  126. /* Macros for min/max. */
  127. #ifndef MIN
  128. #define MIN(a,b) (((a)<(b))?(a):(b))
  129. #endif
  130. #ifndef MAX
  131. #define MAX(a,b) (((a)>(b))?(a):(b))
  132. #endif
  133. /* buffer allocation schemes */
  134. #ifdef CONFIG_FEATURE_BUFFERS_GO_ON_STACK
  135. #define RESERVE_CONFIG_BUFFER(buffer,len) char buffer[len]
  136. #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char buffer[len]
  137. #define RELEASE_CONFIG_BUFFER(buffer) ((void)0)
  138. #else
  139. #ifdef CONFIG_FEATURE_BUFFERS_GO_IN_BSS
  140. #define RESERVE_CONFIG_BUFFER(buffer,len) static char buffer[len]
  141. #define RESERVE_CONFIG_UBUFFER(buffer,len) static unsigned char buffer[len]
  142. #define RELEASE_CONFIG_BUFFER(buffer) ((void)0)
  143. #else
  144. #define RESERVE_CONFIG_BUFFER(buffer,len) char *buffer=xmalloc(len)
  145. #define RESERVE_CONFIG_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
  146. #define RELEASE_CONFIG_BUFFER(buffer) free (buffer)
  147. #endif
  148. #endif
  149. #if (__GLIBC__ < 2)
  150. int vdprintf(int d, const char *format, va_list ap);
  151. #endif
  152. // This is declared here rather than #including <libgen.h> in order to avoid
  153. // confusing the two versions of basename. See the dirname/basename man page
  154. // for details.
  155. char *dirname(char *path);
  156. /* Include our own copy of struct sysinfo to avoid binary compatibility
  157. * problems with Linux 2.4, which changed things. Grumble, grumble. */
  158. struct sysinfo {
  159. long uptime; /* Seconds since boot */
  160. unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
  161. unsigned long totalram; /* Total usable main memory size */
  162. unsigned long freeram; /* Available memory size */
  163. unsigned long sharedram; /* Amount of shared memory */
  164. unsigned long bufferram; /* Memory used by buffers */
  165. unsigned long totalswap; /* Total swap space size */
  166. unsigned long freeswap; /* swap space still available */
  167. unsigned short procs; /* Number of current processes */
  168. unsigned short pad; /* Padding needed for m68k */
  169. unsigned long totalhigh; /* Total high memory size */
  170. unsigned long freehigh; /* Available high memory size */
  171. unsigned int mem_unit; /* Memory unit size in bytes */
  172. char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
  173. };
  174. extern int sysinfo(struct sysinfo* info);
  175. extern void chomp(char *s);
  176. extern void trim(char *s);
  177. extern char *skip_whitespace(const char *);
  178. extern const char *bb_mode_string(int mode);
  179. extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
  180. extern int remove_file(const char *path, int flags);
  181. extern int copy_file(const char *source, const char *dest, int flags);
  182. extern int recursive_action(const char *fileName, int recurse,
  183. int followLinks, int depthFirst,
  184. int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
  185. int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData, int depth),
  186. void* userData, int depth);
  187. extern int device_open(const char *device, int mode);
  188. extern int get_console_fd(void);
  189. extern char *find_block_device(char *path);
  190. extern off_t bb_copyfd_size(int fd1, int fd2, off_t size);
  191. extern off_t bb_copyfd_eof(int fd1, int fd2);
  192. extern char bb_process_escape_sequence(const char **ptr);
  193. extern char *bb_get_last_path_component(char *path);
  194. extern int ndelay_on(int fd);
  195. extern DIR *xopendir(const char *path);
  196. extern DIR *warn_opendir(const char *path);
  197. char *xgetcwd(char *cwd);
  198. char *xreadlink(const char *path);
  199. extern void xstat(char *filename, struct stat *buf);
  200. extern pid_t spawn(char **argv);
  201. extern pid_t xspawn(char **argv);
  202. extern int wait4pid(int pid);
  203. extern void xsetgid(gid_t gid);
  204. extern void xsetuid(uid_t uid);
  205. extern void xdaemon(int nochdir, int noclose);
  206. extern void xchdir(const char *path);
  207. extern void xsetenv(const char *key, const char *value);
  208. extern int xopen(const char *pathname, int flags);
  209. extern int xopen3(const char *pathname, int flags, int mode);
  210. extern off_t xlseek(int fd, off_t offset, int whence);
  211. extern off_t fdlength(int fd);
  212. extern int xsocket(int domain, int type, int protocol);
  213. extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
  214. extern void xlisten(int s, int backlog);
  215. extern void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
  216. extern int xconnect_tcp_v4(struct sockaddr_in *s_addr);
  217. extern struct hostent *xgethostbyname(const char *name);
  218. extern struct hostent *xgethostbyname2(const char *name, int af);
  219. extern int xsocket_stream_ip4or6(sa_family_t *fp);
  220. typedef union {
  221. struct sockaddr sa;
  222. struct sockaddr_in sin;
  223. #if ENABLE_FEATURE_IPV6
  224. struct sockaddr_in6 sin6;
  225. #endif
  226. } sockaddr_inet;
  227. extern int dotted2sockaddr(const char *dotted, struct sockaddr* sp, int socklen);
  228. extern int create_and_bind_socket_ip4or6(const char *hostaddr, int port);
  229. extern int setsockopt_reuseaddr(int fd);
  230. extern int setsockopt_broadcast(int fd);
  231. extern char *xstrdup(const char *s);
  232. extern char *xstrndup(const char *s, int n);
  233. extern char *safe_strncpy(char *dst, const char *src, size_t size);
  234. extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
  235. /* dmalloc will redefine these to it's own implementation. It is safe
  236. * to have the prototypes here unconditionally. */
  237. extern void *xmalloc(size_t size);
  238. extern void *xrealloc(void *old, size_t size);
  239. extern void *xzalloc(size_t size);
  240. extern ssize_t safe_read(int fd, void *buf, size_t count);
  241. extern ssize_t full_read(int fd, void *buf, size_t count);
  242. extern void xread(int fd, void *buf, size_t count);
  243. extern unsigned char xread_char(int fd);
  244. extern char *reads(int fd, char *buf, size_t count);
  245. extern ssize_t read_close(int fd, void *buf, size_t count);
  246. extern ssize_t open_read_close(const char *filename, void *buf, size_t count);
  247. extern void *xmalloc_open_read_close(const char *filename, size_t *sizep);
  248. extern ssize_t safe_write(int fd, const void *buf, size_t count);
  249. extern ssize_t full_write(int fd, const void *buf, size_t count);
  250. extern void xwrite(int fd, const void *buf, size_t count);
  251. /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */
  252. extern void xprint_and_close_file(FILE *file);
  253. extern char *xmalloc_fgets(FILE *file);
  254. /* Read up to (and including) TERMINATING_STRING: */
  255. extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string);
  256. /* Chops off '\n' from the end, unlike fgets: */
  257. extern char *xmalloc_getline(FILE *file);
  258. extern char *bb_get_chunk_from_file(FILE *file, int *end);
  259. extern void die_if_ferror(FILE *file, const char *msg);
  260. extern void die_if_ferror_stdout(void);
  261. extern void xfflush_stdout(void);
  262. extern void fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
  263. extern int fclose_if_not_stdin(FILE *file);
  264. extern FILE *xfopen(const char *filename, const char *mode);
  265. /* Prints warning to stderr and returns NULL on failure: */
  266. extern FILE *fopen_or_warn(const char *filename, const char *mode);
  267. /* "Opens" stdin if filename is special, else just opens file: */
  268. extern FILE *fopen_or_warn_stdin(const char *filename);
  269. extern void smart_ulltoa5(unsigned long long ul, char buf[5]);
  270. extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
  271. extern char *utoa(unsigned n);
  272. extern void itoa_to_buf(int n, char *buf, unsigned buflen);
  273. extern char *itoa(int n);
  274. struct suffix_mult {
  275. const char *suffix;
  276. unsigned mult;
  277. };
  278. #include "xatonum.h"
  279. /* Specialized: */
  280. /* Using xatoi() instead of naive atoi() is not always convenient -
  281. * in many places people want *non-negative* values, but store them
  282. * in signed int. Therefore we need this one:
  283. * dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */
  284. int xatoi_u(const char *numstr);
  285. /* Useful for reading port numbers */
  286. uint16_t xatou16(const char *numstr);
  287. /* These parse entries in /etc/passwd and /etc/group. This is desirable
  288. * for BusyBox since we want to avoid using the glibc NSS stuff, which
  289. * increases target size and is often not needed on embedded systems. */
  290. extern long bb_xgetpwnam(const char *name);
  291. extern long bb_xgetgrnam(const char *name);
  292. /*extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);*/
  293. extern char *bb_getpwuid(char *name, long uid, int bufsize);
  294. extern char *bb_getgrgid(char *group, long gid, int bufsize);
  295. /* from chpst */
  296. struct bb_uidgid_t {
  297. uid_t uid;
  298. gid_t gid;
  299. };
  300. extern unsigned uidgid_get(struct bb_uidgid_t*, const char* /*, unsigned*/);
  301. enum { BB_GETOPT_ERROR = 0x80000000 };
  302. extern const char *opt_complementary;
  303. #if ENABLE_GETOPT_LONG
  304. extern const struct option *applet_long_options;
  305. #endif
  306. extern uint32_t option_mask32;
  307. extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
  308. typedef struct llist_s {
  309. char *data;
  310. struct llist_s *link;
  311. } llist_t;
  312. extern void llist_add_to(llist_t **old_head, void *data);
  313. extern void llist_add_to_end(llist_t **list_head, void *data);
  314. extern void *llist_pop(llist_t **elm);
  315. extern void llist_free(llist_t *elm, void (*freeit)(void *data));
  316. extern llist_t* rev_llist(llist_t *list);
  317. enum {
  318. LOGMODE_NONE = 0,
  319. LOGMODE_STDIO = 1<<0,
  320. LOGMODE_SYSLOG = 1<<1,
  321. LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
  322. };
  323. extern const char *msg_eol;
  324. extern int logmode;
  325. extern int die_sleep;
  326. extern int xfunc_error_retval;
  327. extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
  328. extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
  329. extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
  330. extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
  331. extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
  332. extern void bb_vherror_msg(const char *s, va_list p);
  333. extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
  334. extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
  335. extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN;
  336. extern void bb_perror_nomsg(void);
  337. extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
  338. /* These are used internally -- you shouldn't need to use them */
  339. extern void bb_verror_msg(const char *s, va_list p, const char *strerr);
  340. extern void bb_vperror_msg(const char *s, va_list p);
  341. extern void bb_vinfo_msg(const char *s, va_list p);
  342. extern int bb_echo(int argc, char** argv);
  343. extern int bb_test(int argc, char** argv);
  344. #ifndef BUILD_INDIVIDUAL
  345. extern struct BB_applet *find_applet_by_name(const char *name);
  346. extern void run_applet_by_name(const char *name, int argc, char **argv);
  347. #endif
  348. extern struct mntent *find_mount_point(const char *name, const char *table);
  349. extern void erase_mtab(const char * name);
  350. extern unsigned int tty_baud_to_value(speed_t speed);
  351. extern speed_t tty_value_to_baud(unsigned int value);
  352. extern void bb_warn_ignoring_args(int n);
  353. extern int get_linux_version_code(void);
  354. extern char *query_loop(const char *device);
  355. extern int del_loop(const char *device);
  356. extern int set_loop(char **device, const char *file, unsigned long long offset);
  357. const char *make_human_readable_str(unsigned long long size,
  358. unsigned long block_size, unsigned long display_unit);
  359. char *bb_askpass(int timeout, const char * prompt);
  360. int bb_ask_confirmation(void);
  361. int klogctl(int type, char * b, int len);
  362. extern int bb_parse_mode(const char* s, mode_t* theMode);
  363. char *concat_path_file(const char *path, const char *filename);
  364. char *concat_subpath_file(const char *path, const char *filename);
  365. char *last_char_is(const char *s, int c);
  366. int execable_file(const char *name);
  367. char *find_execable(const char *filename);
  368. int exists_execable(const char *filename);
  369. USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
  370. int inflate(int in, int out);
  371. int create_icmp_socket(void);
  372. int create_icmp6_socket(void);
  373. unsigned short bb_lookup_port(const char *port, const char *protocol, unsigned short default_port);
  374. void bb_lookup_host(struct sockaddr_in *s_in, const char *host);
  375. int bb_make_directory(char *path, long mode, int flags);
  376. int get_signum(const char *name);
  377. const char *get_signame(int number);
  378. char *bb_simplify_path(const char *path);
  379. #define FAIL_DELAY 3
  380. extern void bb_do_delay(int seconds);
  381. extern void change_identity(const struct passwd *pw);
  382. extern const char *change_identity_e2str(const struct passwd *pw);
  383. extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args);
  384. #ifdef CONFIG_SELINUX
  385. extern void renew_current_security_context(void);
  386. extern void set_current_security_context(security_context_t sid);
  387. #endif
  388. extern int restricted_shell(const char *shell);
  389. extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw);
  390. extern int correct_password(const struct passwd *pw);
  391. extern char *pw_encrypt(const char *clear, const char *salt);
  392. extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
  393. extern int index_in_str_array(const char * const string_array[], const char *key);
  394. extern int index_in_substr_array(const char * const string_array[], const char *key);
  395. extern void print_login_issue(const char *issue_file, const char *tty);
  396. extern void print_login_prompt(void);
  397. #ifdef BB_NOMMU
  398. extern void vfork_daemon(int nochdir, int noclose);
  399. extern void vfork_daemon_rexec(int nochdir, int noclose,
  400. int argc, char **argv, char *foreground_opt);
  401. #endif
  402. extern int get_terminal_width_height(int fd, int *width, int *height);
  403. extern unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *));
  404. int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
  405. void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
  406. void reset_ino_dev_hashtable(void);
  407. #ifdef __GLIBC__
  408. /* At least glibc has horrendously large inline for this, so wrap it */
  409. extern unsigned long long bb_makedev(unsigned int major, unsigned int minor);
  410. #undef makedev
  411. #define makedev(a,b) bb_makedev(a,b)
  412. #endif
  413. #ifndef COMM_LEN
  414. #ifdef TASK_COMM_LEN
  415. enum { COMM_LEN = TASK_COMM_LEN };
  416. #else
  417. /* synchronize with sizeof(task_struct.comm) in /usr/include/linux/sched.h */
  418. enum { COMM_LEN = 16 };
  419. #endif
  420. #endif
  421. typedef struct {
  422. DIR *dir;
  423. /* Fields are set to 0/NULL if failed to determine (or not requested) */
  424. char *cmd;
  425. unsigned long rss;
  426. unsigned long stime, utime;
  427. unsigned pid;
  428. unsigned ppid;
  429. unsigned pgid;
  430. unsigned sid;
  431. unsigned uid;
  432. unsigned gid;
  433. /* basename of executable file in call to exec(2), size from */
  434. /* sizeof(task_struct.comm) in /usr/include/linux/sched.h */
  435. char state[4];
  436. char comm[COMM_LEN];
  437. // user/group? - use passwd/group parsing functions
  438. } procps_status_t;
  439. enum {
  440. PSSCAN_PID = 1 << 0,
  441. PSSCAN_PPID = 1 << 1,
  442. PSSCAN_PGID = 1 << 2,
  443. PSSCAN_SID = 1 << 3,
  444. PSSCAN_UIDGID = 1 << 4,
  445. PSSCAN_COMM = 1 << 5,
  446. PSSCAN_CMD = 1 << 6,
  447. PSSCAN_STATE = 1 << 7,
  448. PSSCAN_RSS = 1 << 8,
  449. PSSCAN_STIME = 1 << 9,
  450. PSSCAN_UTIME = 1 << 10,
  451. /* These are all retrieved from proc/NN/stat in one go: */
  452. PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID
  453. | PSSCAN_COMM | PSSCAN_STATE
  454. | PSSCAN_RSS | PSSCAN_STIME | PSSCAN_UTIME,
  455. };
  456. procps_status_t* alloc_procps_scan(int flags);
  457. void free_procps_scan(procps_status_t* sp);
  458. procps_status_t* procps_scan(procps_status_t* sp, int flags);
  459. pid_t *find_pid_by_name(const char* procName);
  460. pid_t *pidlist_reverse(pid_t *pidList);
  461. void clear_username_cache(void);
  462. const char* get_cached_username(uid_t uid);
  463. const char* get_cached_groupname(gid_t gid);
  464. extern const char bb_uuenc_tbl_base64[];
  465. extern const char bb_uuenc_tbl_std[];
  466. void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl);
  467. typedef struct sha1_ctx_t {
  468. uint32_t count[2];
  469. uint32_t hash[5];
  470. uint32_t wbuf[16];
  471. } sha1_ctx_t;
  472. void sha1_begin(sha1_ctx_t *ctx);
  473. void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx);
  474. void *sha1_end(void *resbuf, sha1_ctx_t *ctx);
  475. typedef struct md5_ctx_t {
  476. uint32_t A;
  477. uint32_t B;
  478. uint32_t C;
  479. uint32_t D;
  480. uint64_t total;
  481. uint32_t buflen;
  482. char buffer[128];
  483. } md5_ctx_t;
  484. void md5_begin(md5_ctx_t *ctx);
  485. void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
  486. void *md5_end(void *resbuf, md5_ctx_t *ctx);
  487. uint32_t *crc32_filltable(int endian);
  488. enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */
  489. FILEUTILS_PRESERVE_STATUS = 1,
  490. FILEUTILS_DEREFERENCE = 2,
  491. FILEUTILS_RECUR = 4,
  492. FILEUTILS_FORCE = 8,
  493. FILEUTILS_INTERACTIVE = 0x10,
  494. FILEUTILS_MAKE_HARDLINK = 0x20,
  495. FILEUTILS_MAKE_SOFTLINK = 0x40,
  496. };
  497. #define FILEUTILS_CP_OPTSTR "pdRfils"
  498. extern const char *applet_name;
  499. extern const char BB_BANNER[];
  500. extern const char bb_msg_full_version[];
  501. extern const char bb_msg_memory_exhausted[];
  502. extern const char bb_msg_invalid_date[];
  503. extern const char bb_msg_read_error[];
  504. extern const char bb_msg_write_error[];
  505. extern const char bb_msg_unknown[];
  506. extern const char bb_msg_can_not_create_raw_socket[];
  507. extern const char bb_msg_perm_denied_are_you_root[];
  508. extern const char bb_msg_requires_arg[];
  509. extern const char bb_msg_invalid_arg[];
  510. extern const char bb_msg_standard_input[];
  511. extern const char bb_msg_standard_output[];
  512. extern const char bb_str_default[];
  513. extern const char bb_path_mtab_file[];
  514. extern const char bb_path_nologin_file[];
  515. extern const char bb_path_passwd_file[];
  516. extern const char bb_path_shadow_file[];
  517. extern const char bb_path_gshadow_file[];
  518. extern const char bb_path_group_file[];
  519. extern const char bb_path_securetty_file[];
  520. extern const char bb_path_motd_file[];
  521. extern const char bb_path_wtmp_file[];
  522. extern const char bb_dev_null[];
  523. #ifndef BUFSIZ
  524. #define BUFSIZ 4096
  525. #endif
  526. extern char bb_common_bufsiz1[BUFSIZ+1];
  527. /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
  528. * use bb_default_login_shell and following defines.
  529. * If you change LIBBB_DEFAULT_LOGIN_SHELL,
  530. * don't forget to change increment constant. */
  531. #define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh"
  532. extern const char bb_default_login_shell[];
  533. /* "/bin/sh" */
  534. #define DEFAULT_SHELL (bb_default_login_shell+1)
  535. /* "sh" */
  536. #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
  537. #ifdef CONFIG_FEATURE_DEVFS
  538. # define CURRENT_VC "/dev/vc/0"
  539. # define VC_1 "/dev/vc/1"
  540. # define VC_2 "/dev/vc/2"
  541. # define VC_3 "/dev/vc/3"
  542. # define VC_4 "/dev/vc/4"
  543. # define VC_5 "/dev/vc/5"
  544. #if defined(__sh__) || defined(__H8300H__) || defined(__H8300S__)
  545. /* Yes, this sucks, but both SH (including sh64) and H8 have a SCI(F) for their
  546. respective serial ports .. as such, we can't use the common device paths for
  547. these. -- PFM */
  548. # define SC_0 "/dev/ttsc/0"
  549. # define SC_1 "/dev/ttsc/1"
  550. # define SC_FORMAT "/dev/ttsc/%d"
  551. #else
  552. # define SC_0 "/dev/tts/0"
  553. # define SC_1 "/dev/tts/1"
  554. # define SC_FORMAT "/dev/tts/%d"
  555. #endif
  556. # define VC_FORMAT "/dev/vc/%d"
  557. # define LOOP_FORMAT "/dev/loop/%d"
  558. # define LOOP_NAME "/dev/loop/"
  559. # define FB_0 "/dev/fb/0"
  560. #else
  561. # define CURRENT_VC "/dev/tty0"
  562. # define VC_1 "/dev/tty1"
  563. # define VC_2 "/dev/tty2"
  564. # define VC_3 "/dev/tty3"
  565. # define VC_4 "/dev/tty4"
  566. # define VC_5 "/dev/tty5"
  567. #if defined(__sh__) || defined(__H8300H__) || defined(__H8300S__)
  568. # define SC_0 "/dev/ttySC0"
  569. # define SC_1 "/dev/ttySC1"
  570. # define SC_FORMAT "/dev/ttySC%d"
  571. #else
  572. # define SC_0 "/dev/ttyS0"
  573. # define SC_1 "/dev/ttyS1"
  574. # define SC_FORMAT "/dev/ttyS%d"
  575. #endif
  576. # define VC_FORMAT "/dev/tty%d"
  577. # define LOOP_FORMAT "/dev/loop%d"
  578. # define LOOP_NAME "/dev/loop"
  579. # define FB_0 "/dev/fb0"
  580. #endif
  581. /* The following devices are the same on devfs and non-devfs systems. */
  582. #define CURRENT_TTY "/dev/tty"
  583. #define CONSOLE_DEV "/dev/console"
  584. #ifndef RB_POWER_OFF
  585. /* Stop system and switch power off if possible. */
  586. #define RB_POWER_OFF 0x4321fedc
  587. #endif
  588. /* Make sure we call functions instead of macros. */
  589. #undef isalnum
  590. #undef isalpha
  591. #undef isascii
  592. #undef isblank
  593. #undef iscntrl
  594. #undef isgraph
  595. #undef islower
  596. #undef isprint
  597. #undef ispunct
  598. #undef isspace
  599. #undef isupper
  600. #undef isxdigit
  601. /* This one is more efficient - we save ~400 bytes */
  602. #undef isdigit
  603. #define isdigit(a) ((unsigned)((a) - '0') <= 9)
  604. #ifdef DMALLOC
  605. #include <dmalloc.h>
  606. #endif
  607. #endif /* __LIBBUSYBOX_H__ */