blob: b2034da5e46fe3412ff2f6c5f428d429e9b5e64f [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen2b69c401999-10-05 22:58:32 +00002/*
Eric Andersenc4996011999-10-20 22:08:37 +00003 * Busybox main internal header file
Eric Andersen2b69c401999-10-05 22:58:32 +00004 *
Eric Andersen2b69c401999-10-05 22:58:32 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
21 * Permission has been granted to redistribute this code under the GPL.
22 *
23 */
Erik Andersenfac10d72000-02-07 05:29:42 +000024#ifndef _BB_INTERNAL_H_
25#define _BB_INTERNAL_H_ 1
Eric Andersencc8ed391999-10-05 16:24:54 +000026
27#include "busybox.def.h"
28
Eric Andersenae6eae02000-07-19 17:35:54 +000029#ifdef DMALLOC
30#include "dmalloc.h"
31#endif
32
Eric Andersencc8ed391999-10-05 16:24:54 +000033#include <stdlib.h>
Erik Andersen5509af72000-01-23 18:19:02 +000034#include <stdarg.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000035#include <string.h>
36#include <unistd.h>
Eric Andersen10dc9d42000-06-26 10:45:52 +000037#include <errno.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000038#include <sys/stat.h>
Erik Andersen4f3f7572000-04-28 00:18:56 +000039#include <sys/param.h>
Eric Andersen29d2e361999-11-06 06:07:27 +000040#include <mntent.h>
Mark Whitleydf5f6ba2000-07-11 16:53:56 +000041#include <regex.h>
Eric Andersenbe909b12000-07-11 17:52:22 +000042/* for the _syscall() macros */
43#include <sys/syscall.h>
44#include <linux/unistd.h>
45
Eric Andersencc8ed391999-10-05 16:24:54 +000046
47/* Some useful definitions */
Eric Andersenf811e071999-10-09 00:25:00 +000048#define FALSE ((int) 1)
49#define TRUE ((int) 0)
Eric Andersencc8ed391999-10-05 16:24:54 +000050
Erik Andersenfac10d72000-02-07 05:29:42 +000051/* for mtab.c */
52#define MTAB_GETMOUNTPT '1'
53#define MTAB_GETDEVICE '2'
54
Eric Andersencc8ed391999-10-05 16:24:54 +000055#define BUF_SIZE 8192
56#define EXPAND_ALLOC 1024
57
Erik Andersen298854f2000-03-23 01:09:18 +000058
Eric Andersencc8ed391999-10-05 16:24:54 +000059#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
60#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
61#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
62#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
63
Erik Andersen4f3f7572000-04-28 00:18:56 +000064/* Macros for min/max. */
65#ifndef MIN
66#define MIN(a,b) (((a)<(b))?(a):(b))
67#endif
68
69#ifndef MAX
70#define MAX(a,b) (((a)>(b))?(a):(b))
71#endif
72
73
74/* I don't like nested includes, but the string and io functions are used
75 * too often
76 */
77#include <stdio.h>
78#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
79# include <string.h>
80# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
81# include <memory.h>
82# endif
83# define memzero(s, n) memset ((void *)(s), 0, (n))
84#else
85# include <strings.h>
86# define strchr index
87# define strrchr rindex
88# define memcpy(d, s, n) bcopy((s), (d), (n))
89# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
90# define memzero(s, n) bzero((s), (n))
91#endif
92
93
Erik Andersend75af992000-03-16 08:09:09 +000094enum Location {
95 _BB_DIR_ROOT = 0,
96 _BB_DIR_BIN,
97 _BB_DIR_SBIN,
98 _BB_DIR_USR_BIN,
99 _BB_DIR_USR_SBIN
100};
Eric Andersencc8ed391999-10-05 16:24:54 +0000101
Erik Andersenbcd61772000-05-13 06:33:19 +0000102struct BB_applet {
Eric Andersencc8ed391999-10-05 16:24:54 +0000103 const char* name;
104 int (*main)(int argc, char** argv);
Erik Andersend75af992000-03-16 08:09:09 +0000105 enum Location location;
Matt Kraai27a80422000-07-19 19:24:01 +0000106 const char* usage;
Eric Andersencc8ed391999-10-05 16:24:54 +0000107};
Erik Andersenbcd61772000-05-13 06:33:19 +0000108/* From busybox.c */
109extern const struct BB_applet applets[];
Eric Andersencc8ed391999-10-05 16:24:54 +0000110
Eric Andersen86ab8a32000-06-02 03:21:42 +0000111extern int ar_main(int argc, char **argv);
Erik Andersene2729152000-02-18 21:34:17 +0000112extern int basename_main(int argc, char **argv);
Eric Andersen1b355eb2000-09-05 17:37:48 +0000113extern int bogomips_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000114extern int busybox_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000115extern int cat_main(int argc, char** argv);
Eric Andersen1b61f411999-10-13 18:56:42 +0000116extern int chmod_chown_chgrp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000117extern int chroot_main(int argc, char** argv);
Erik Andersen6f23cec1999-12-15 22:14:12 +0000118extern int chvt_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000119extern int clear_main(int argc, char** argv);
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000120extern int cp_mv_main(int argc, char** argv);
121extern int cut_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000122extern int date_main(int argc, char** argv);
John Beppu00216792000-06-21 19:06:16 +0000123extern int dc_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000124extern int dd_main(int argc, char** argv);
Erik Andersenfb002d02000-03-05 08:07:00 +0000125extern int dirname_main(int argc, char** argv);
Erik Andersen6f23cec1999-12-15 22:14:12 +0000126extern int deallocvt_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000127extern int df_main(int argc, char** argv);
128extern int dmesg_main(int argc, char** argv);
John Beppu7a986061999-12-09 18:29:29 +0000129extern int du_main(int argc, char** argv);
Eric Andersen61dc0572000-07-11 17:29:36 +0000130extern int dumpkmap_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000131extern int dutmp_main(int argc, char** argv);
Erik Andersend75af992000-03-16 08:09:09 +0000132extern int echo_main(int argc, char** argv);
Eric Andersen1b355eb2000-09-05 17:37:48 +0000133extern int expr_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000134extern int false_main(int argc, char** argv);
Erik Andersen1c5b2581999-12-16 20:59:36 +0000135extern int fbset_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000136extern int fdisk_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +0000137extern int fdflush_main(int argc, char **argv);
Eric Andersene494fdd1999-10-19 20:23:03 +0000138extern int fsck_minix_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000139extern int find_main(int argc, char** argv);
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000140extern int free_main(int argc, char** argv);
Erik Andersen64371702000-03-04 22:23:27 +0000141extern int freeramdisk_main(int argc, char** argv);
Eric Andersena1f16bb2000-08-21 22:02:34 +0000142extern int getopt_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000143extern int grep_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000144extern int gunzip_main (int argc, char** argv);
145extern int gzip_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000146extern int halt_main(int argc, char** argv);
John Beppu3157b1f1999-12-10 07:42:50 +0000147extern int head_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000148extern int hostid_main(int argc, char** argv);
Eric Andersen485b9551999-12-07 23:14:59 +0000149extern int hostname_main(int argc, char** argv);
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000150extern int id_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000151extern int init_main(int argc, char** argv);
Erik Andersen6da0ae81999-12-17 01:08:27 +0000152extern int insmod_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000153extern int kill_main(int argc, char** argv);
154extern int length_main(int argc, char** argv);
155extern int ln_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000156extern int loadacm_main(int argc, char** argv);
Eric Andersen3e0fbae1999-10-19 06:02:44 +0000157extern int loadfont_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000158extern int loadkmap_main(int argc, char** argv);
159extern int losetup_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000160extern int logger_main(int argc, char **argv);
161extern int logname_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000162extern int ls_main(int argc, char** argv);
Erik Andersen6f23cec1999-12-15 22:14:12 +0000163extern int lsmod_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000164extern int makedevs_main(int argc, char** argv);
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000165extern int md5sum_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +0000166extern int mkdir_main(int argc, char** argv);
Eric Andersen19db07b1999-12-11 08:41:28 +0000167extern int mkfifo_main(int argc, char **argv);
168extern int mkfs_minix_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000169extern int mknod_main(int argc, char** argv);
170extern int mkswap_main(int argc, char** argv);
Erik Andersen227a59b2000-04-25 23:24:55 +0000171extern int mktemp_main(int argc, char **argv);
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000172extern int nc_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000173extern int more_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000174extern int mount_main(int argc, char** argv);
175extern int mt_main(int argc, char** argv);
Erik Andersenfac10d72000-02-07 05:29:42 +0000176extern int nslookup_main(int argc, char **argv);
Eric Andersen485b9551999-12-07 23:14:59 +0000177extern int ping_main(int argc, char **argv);
Eric Andersen2cb55071999-12-10 08:25:07 +0000178extern int poweroff_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000179extern int printf_main(int argc, char** argv);
Eric Andersenef8b6c71999-10-20 08:05:35 +0000180extern int ps_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000181extern int pwd_main(int argc, char** argv);
Eric Andersen918507e2000-08-21 22:46:33 +0000182extern int rdate_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000183extern int reboot_main(int argc, char** argv);
Eric Andersenbf960f52000-07-21 21:32:12 +0000184extern int renice_main(int argc, char** argv);
Eric Andersenfa405d02000-08-21 21:18:52 +0000185extern int reset_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000186extern int rm_main(int argc, char** argv);
Erik Andersen3d7e3411999-12-16 23:04:20 +0000187extern int rmdir_main(int argc, char **argv);
188extern int rmmod_main(int argc, char** argv);
Eric Andersenc1525e81999-10-29 00:07:31 +0000189extern int sed_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000190extern int sfdisk_main(int argc, char** argv);
Erik Andersen4f3f7572000-04-28 00:18:56 +0000191extern int setkeycodes_main(int argc, char** argv);
Erik Andersen3522eb12000-03-12 23:49:18 +0000192extern int shell_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000193extern int sleep_main(int argc, char** argv);
John Beppu019513a1999-12-22 17:57:31 +0000194extern int sort_main(int argc, char** argv);
Eric Andersen87590061999-10-18 21:22:59 +0000195extern int swap_on_off_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000196extern int sync_main(int argc, char** argv);
Eric Andersen3843e961999-11-25 07:30:46 +0000197extern int syslogd_main(int argc, char **argv);
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000198extern int tail_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000199extern int tar_main(int argc, char** argv);
John Beppu059f1521999-12-10 05:27:16 +0000200extern int tee_main(int argc, char** argv);
Erik Andersend75af992000-03-16 08:09:09 +0000201extern int test_main(int argc, char** argv);
Erik Andersenf7c49ef2000-02-22 17:17:45 +0000202extern int telnet_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +0000203extern int touch_main(int argc, char** argv);
Erik Andersenfb002d02000-03-05 08:07:00 +0000204extern int tr_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000205extern int true_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000206extern int tput_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000207extern int tryopen_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000208extern int tty_main(int argc, char** argv);
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000209extern int uuencode_main(int argc, char** argv);
210extern int uudecode_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000211extern int umount_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000212extern int uname_main(int argc, char** argv);
Erik Andersen66be5e72000-03-05 07:52:05 +0000213extern int uptime_main(int argc, char** argv);
John Beppuabb47722000-01-06 00:48:21 +0000214extern int uniq_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000215extern int update_main(int argc, char** argv);
Erik Andersenb99ca132000-04-04 18:49:18 +0000216extern int usleep_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000217extern int wc_main(int argc, char** argv);
Eric Andersen96700832000-09-04 15:15:55 +0000218extern int wget_main(int argc, char** argv);
Erik Andersen330fd2b2000-05-19 05:35:19 +0000219extern int which_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000220extern int whoami_main(int argc, char** argv);
221extern int yes_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000222
Matt Kraaibf181b92000-07-16 20:57:15 +0000223extern const char ar_usage[];
224extern const char basename_usage[];
225extern const char cat_usage[];
226extern const char chgrp_usage[];
227extern const char chmod_usage[];
228extern const char chown_usage[];
229extern const char chroot_usage[];
230extern const char chvt_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000231extern const char clear_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000232extern const char cp_usage[];
233extern const char cut_usage[];
234extern const char date_usage[];
235extern const char dc_usage[];
236extern const char dd_usage[];
237extern const char deallocvt_usage[];
238extern const char df_usage[];
239extern const char dirname_usage[];
240extern const char dmesg_usage[];
241extern const char du_usage[];
242extern const char dumpkmap_usage[];
243extern const char dutmp_usage[];
244extern const char echo_usage[];
Eric Andersen1b355eb2000-09-05 17:37:48 +0000245extern const char expr_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000246extern const char false_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000247extern const char fdflush_usage[];
248extern const char find_usage[];
249extern const char free_usage[];
250extern const char freeramdisk_usage[];
251extern const char fsck_minix_usage[];
252extern const char grep_usage[];
253extern const char gunzip_usage[];
254extern const char gzip_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000255extern const char halt_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000256extern const char head_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000257extern const char hostid_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000258extern const char hostname_usage[];
259extern const char id_usage[];
260extern const char insmod_usage[];
261extern const char kill_usage[];
262extern const char killall_usage[];
263extern const char length_usage[];
264extern const char ln_usage[];
265extern const char loadacm_usage[];
266extern const char loadfont_usage[];
267extern const char loadkmap_usage[];
268extern const char logger_usage[];
269extern const char logname_usage[];
270extern const char ls_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000271extern const char lsmod_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000272extern const char makedevs_usage[];
273extern const char md5sum_usage[];
274extern const char mkdir_usage[];
275extern const char mkfifo_usage[];
276extern const char mkfs_minix_usage[];
277extern const char mknod_usage[];
278extern const char mkswap_usage[];
279extern const char mktemp_usage[];
280extern const char more_usage[];
281extern const char mount_usage[];
282extern const char mt_usage[];
283extern const char mv_usage[];
284extern const char nc_usage[];
285extern const char nslookup_usage[];
286extern const char ping_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000287extern const char poweroff_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000288extern const char printf_usage[];
289extern const char ps_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000290extern const char pwd_usage[];
Eric Andersen918507e2000-08-21 22:46:33 +0000291extern const char rdate_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000292extern const char reboot_usage[];
Eric Andersenbf960f52000-07-21 21:32:12 +0000293extern const char renice_usage[];
Eric Andersenfa405d02000-08-21 21:18:52 +0000294extern const char reset_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000295extern const char rm_usage[];
296extern const char rmdir_usage[];
297extern const char rmmod_usage[];
298extern const char sed_usage[];
299extern const char setkeycodes_usage[];
300extern const char shell_usage[];
301extern const char sleep_usage[];
302extern const char sort_usage[];
303extern const char swapoff_usage[];
304extern const char swapon_usage[];
305extern const char sync_usage[];
306extern const char syslogd_usage[];
307extern const char tail_usage[];
308extern const char tar_usage[];
309extern const char tee_usage[];
310extern const char telnet_usage[];
311extern const char test_usage[];
312extern const char touch_usage[];
313extern const char tr_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000314extern const char true_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000315extern const char tty_usage[];
316extern const char umount_usage[];
317extern const char uname_usage[];
318extern const char uniq_usage[];
319extern const char update_usage[];
Matt Kraai86905722000-07-19 18:20:02 +0000320extern const char uptime_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000321extern const char usleep_usage[];
322extern const char uudecode_usage[];
323extern const char uuencode_usage[];
324extern const char wc_usage[];
Eric Andersen96700832000-09-04 15:15:55 +0000325extern const char wget_usage[];
Matt Kraaibf181b92000-07-16 20:57:15 +0000326extern const char which_usage[];
327extern const char whoami_usage[];
328extern const char yes_usage[];
329
Eric Andersen501c88b2000-07-28 15:14:45 +0000330extern const char *applet_name;
Eric Andersen2b69c401999-10-05 22:58:32 +0000331
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000332extern void usage(const char *usage) __attribute__ ((noreturn));
Erik Andersen93d65132000-04-06 08:06:36 +0000333extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
334extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000335
Eric Andersen2b69c401999-10-05 22:58:32 +0000336const char *modeString(int mode);
337const char *timeString(time_t timeVal);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000338int isDirectory(const char *name, const int followLinks, struct stat *statBuf);
Eric Andersenf811e071999-10-09 00:25:00 +0000339int isDevice(const char *name);
Erik Andersen029011b2000-03-04 21:19:32 +0000340
341typedef struct ino_dev_hash_bucket_struct {
342 struct ino_dev_hash_bucket_struct *next;
343 ino_t ino;
344 dev_t dev;
345 char name[1];
346} ino_dev_hashtable_bucket_t;
347int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
348void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
349void reset_ino_dev_hashtable(void);
350
Erik Andersen59b9e872000-05-10 05:05:45 +0000351int copyFile(const char *srcName, const char *destName,
352 int setModes, int followLinks, int forceFlag);
Glenn L McGrath06aeb6c2000-08-25 03:50:10 +0000353int copySubFile(int srcFd, int dstFd, size_t remaining);
Eric Andersenf811e071999-10-09 00:25:00 +0000354char *buildName(const char *dirName, const char *fileName);
355int makeString(int argc, const char **argv, char *buf, int bufLen);
Eric Andersen2b69c401999-10-05 22:58:32 +0000356char *getChunk(int size);
357char *chunkstrdup(const char *str);
358void freeChunks(void);
359int fullWrite(int fd, const char *buf, int len);
360int fullRead(int fd, char *buf, int len);
Eric Andersen63a0e531999-10-22 05:12:14 +0000361int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
Erik Andersen3364d782000-03-28 00:58:14 +0000362 int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
363 int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
364 void* userData);
Eric Andersencc8ed391999-10-05 16:24:54 +0000365
Erik Andersen06936df2000-01-23 02:14:20 +0000366extern int createPath (const char *name, int mode);
Eric Andersenf6be9441999-10-13 21:12:06 +0000367extern int parse_mode( const char* s, mode_t* theMode);
Eric Andersenb0e9a701999-10-18 22:28:26 +0000368
Erik Andersen1ad302a2000-03-24 00:54:46 +0000369extern int get_kernel_revision(void);
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000370
Eric Andersen0460ff21999-10-25 23:32:44 +0000371extern int get_console_fd(char* tty_name);
Eric Andersen29d2e361999-11-06 06:07:27 +0000372extern struct mntent *findMountPoint(const char *name, const char *table);
Eric Andersend0246fb1999-11-04 21:18:07 +0000373extern void write_mtab(char* blockDevice, char* directory,
374 char* filesystemType, long flags, char* string_flags);
375extern void erase_mtab(const char * name);
Erik Andersenfac10d72000-02-07 05:29:42 +0000376extern void mtab_read(void);
Erik Andersenfac10d72000-02-07 05:29:42 +0000377extern char *mtab_first(void **iter);
378extern char *mtab_next(void **iter);
379extern char *mtab_getinfo(const char *match, const char which);
Eric Andersenb186d981999-12-03 09:19:54 +0000380extern int check_wildcard_match(const char* text, const char* pattern);
Eric Andersen1792f8c1999-12-09 06:11:36 +0000381extern long getNum (const char *cp);
Erik Andersen825aead2000-04-07 06:00:07 +0000382extern pid_t* findPidByName( char* pidName);
Erik Andersenec5bd902000-03-22 07:12:05 +0000383extern int find_real_root_device_name(char* name);
Mark Whitley1ca41772000-06-28 22:15:26 +0000384extern char *get_line_from_file(FILE *file);
Pavel Roskincc8a66b2000-07-17 20:18:42 +0000385extern void print_file(FILE *file);
386extern int print_file_by_name(char *filename);
Eric Andersenf7cf2f72000-07-05 17:26:35 +0000387extern char process_escape_sequence(char **ptr);
Eric Andersen0b4551f2000-07-10 16:44:03 +0000388extern char *get_last_path_component(char *path);
Mark Whitleyc41e8c82000-07-12 23:35:21 +0000389extern void xregcomp(regex_t *preg, const char *regex, int cflags);
John Beppu5a728cf2000-04-17 04:22:09 +0000390
Eric Andersenae6eae02000-07-19 17:35:54 +0000391#ifndef DMALLOC
Eric Andersenda1d1e72000-07-10 23:39:44 +0000392extern void *xmalloc (size_t size);
Matt Kraai86905722000-07-19 18:20:02 +0000393extern void *xrealloc(void *old, size_t size);
Eric Andersen501c88b2000-07-28 15:14:45 +0000394extern void *xcalloc(size_t nmemb, size_t size);
Eric Andersenda1d1e72000-07-10 23:39:44 +0000395extern char *xstrdup (const char *s);
Eric Andersenae6eae02000-07-19 17:35:54 +0000396#endif
Eric Andersenda1d1e72000-07-10 23:39:44 +0000397extern char *xstrndup (const char *s, int n);
398
399
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000400/* These parse entries in /etc/passwd and /etc/group. This is desirable
401 * for BusyBox since we want to avoid using the glibc NSS stuff, which
402 * increases target size and is often not needed embedded systems. */
Eric Andersenfad04fd2000-07-14 06:49:52 +0000403extern long my_getpwnam(char *name);
404extern long my_getgrnam(char *name);
405extern void my_getpwuid(char *name, long uid);
406extern void my_getgrgid(char *group, long gid);
407extern long my_getpwnamegid(char *name);
Erik Andersen94f5e0b2000-05-01 19:10:52 +0000408
Erik Andersend0480c22000-02-07 20:35:14 +0000409extern int device_open(char *device, int mode);
Pavel Roskin21ddb382000-07-17 19:31:54 +0000410
Erik Andersen5cbdd712000-01-26 20:06:48 +0000411#if defined BB_FEATURE_MOUNT_LOOP
412extern int del_loop(const char *device);
Erik Andersende7965c2000-01-26 23:49:21 +0000413extern int set_loop(const char *device, const char *file, int offset, int *loopro);
414extern char *find_unused_loop_device (void);
Erik Andersen5cbdd712000-01-26 20:06:48 +0000415#endif
416
Erik Andersen3fe39dc2000-01-25 18:13:53 +0000417
Erik Andersen5509af72000-01-23 18:19:02 +0000418#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
Erik Andersen7dc16072000-01-04 01:10:25 +0000419extern int vdprintf(int d, const char *format, va_list ap);
420#endif
Eric Andersene674eb71999-10-19 20:52:57 +0000421
Eric Andersena9c95ea1999-11-15 17:33:30 +0000422#if defined BB_NFSMOUNT
Eric Andersene7413a92000-07-14 06:19:41 +0000423int nfsmount(const char *spec, const char *node, int *flags,
424 char **extra_opts, char **mount_opts, int running_bg);
Eric Andersena9c95ea1999-11-15 17:33:30 +0000425#endif
Eric Andersen29d2e361999-11-06 06:07:27 +0000426
Erik Andersen31638212000-01-15 22:28:50 +0000427#ifndef RB_POWER_OFF
Eric Andersen74c66ad2000-06-16 19:57:44 +0000428/* Stop system and switch power off if possible. */
Erik Andersen31638212000-01-15 22:28:50 +0000429#define RB_POWER_OFF 0x4321fedc
430#endif
431
Eric Andersen10dc9d42000-06-26 10:45:52 +0000432/* Include our own copy of struct sysinfo to avoid binary compatability
433 * problems with Linux 2.4, which changed things. Grumble, grumble. */
434struct sysinfo {
435 long uptime; /* Seconds since boot */
436 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
437 unsigned long totalram; /* Total usable main memory size */
438 unsigned long freeram; /* Available memory size */
439 unsigned long sharedram; /* Amount of shared memory */
440 unsigned long bufferram; /* Memory used by buffers */
441 unsigned long totalswap; /* Total swap space size */
442 unsigned long freeswap; /* swap space still available */
443 unsigned short procs; /* Number of current processes */
444 unsigned long totalhigh; /* Total high memory size */
445 unsigned long freehigh; /* Available high memory size */
446 unsigned int mem_unit; /* Memory unit size in bytes */
447 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
448};
449extern int sysinfo (struct sysinfo* info);
Eric Andersenaa0765e1999-10-22 04:30:20 +0000450
Eric Andersenbd4a75f2000-06-19 20:03:48 +0000451/* Bit map related macros -- libc5 doens't provide these... sigh. */
Eric Andersen10dc9d42000-06-26 10:45:52 +0000452#ifndef setbit
Eric Andersenbd4a75f2000-06-19 20:03:48 +0000453#define NBBY CHAR_BIT
454#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
455#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
456#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
457#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
458#endif
459
Erik Andersenfac10d72000-02-07 05:29:42 +0000460#endif /* _BB_INTERNAL_H_ */