blob: b77feabad6fbd0a4379cad3f381b4dc6545a1ce9 [file] [log] [blame]
Eric Andersen2b69c401999-10-05 22:58:32 +00001/*
Eric Andersenc4996011999-10-20 22:08:37 +00002 * Busybox main internal header file
Eric Andersen2b69c401999-10-05 22:58:32 +00003 *
Eric Andersen2b69c401999-10-05 22:58:32 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but 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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Based in part on code from sash, Copyright (c) 1999 by David I. Bell
20 * Permission has been granted to redistribute this code under the GPL.
21 *
22 */
Eric Andersencc8ed391999-10-05 16:24:54 +000023#ifndef _INTERNAL_H_
24#define _INTERNAL_H_
25
26#include "busybox.def.h"
27
28#include <stdlib.h>
Erik Andersen5509af72000-01-23 18:19:02 +000029#include <stdarg.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000030#include <string.h>
31#include <unistd.h>
32#include <sys/stat.h>
Eric Andersen29d2e361999-11-06 06:07:27 +000033#include <mntent.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000034
35
36/* Some useful definitions */
Eric Andersenf811e071999-10-09 00:25:00 +000037#define FALSE ((int) 1)
38#define TRUE ((int) 0)
Eric Andersencc8ed391999-10-05 16:24:54 +000039
40#define PATH_LEN 1024
41#define BUF_SIZE 8192
42#define EXPAND_ALLOC 1024
43
44#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
45#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
46#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
47#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
48
49
Eric Andersencc8ed391999-10-05 16:24:54 +000050struct Applet {
51 const char* name;
52 int (*main)(int argc, char** argv);
53};
54
Eric Andersencc8ed391999-10-05 16:24:54 +000055extern int busybox_main(int argc, char** argv);
56extern int block_device_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +000057extern int cat_main(int argc, char** argv);
Eric Andersenf811e071999-10-09 00:25:00 +000058extern int cp_main(int argc, char** argv);
Eric Andersen1b61f411999-10-13 18:56:42 +000059extern int chmod_chown_chgrp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000060extern int chroot_main(int argc, char** argv);
Erik Andersen6f23cec1999-12-15 22:14:12 +000061extern int chvt_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000062extern int clear_main(int argc, char** argv);
63extern int date_main(int argc, char** argv);
64extern int dd_main(int argc, char** argv);
Erik Andersen6f23cec1999-12-15 22:14:12 +000065extern int deallocvt_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000066extern int df_main(int argc, char** argv);
67extern int dmesg_main(int argc, char** argv);
John Beppu7a986061999-12-09 18:29:29 +000068extern int du_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +000069extern int dutmp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000070extern int false_main(int argc, char** argv);
Erik Andersen1c5b2581999-12-16 20:59:36 +000071extern int fbset_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000072extern int fdisk_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000073extern int fdflush_main(int argc, char **argv);
Eric Andersene494fdd1999-10-19 20:23:03 +000074extern int fsck_minix_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000075extern int find_main(int argc, char** argv);
Eric Andersenabc0f4f1999-12-08 23:19:36 +000076extern int free_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000077extern int grep_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +000078extern int gunzip_main (int argc, char** argv);
79extern int gzip_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000080extern int halt_main(int argc, char** argv);
John Beppu3157b1f1999-12-10 07:42:50 +000081extern int head_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +000082extern int hostid_main(int argc, char** argv);
Eric Andersen485b9551999-12-07 23:14:59 +000083extern int hostname_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000084extern int init_main(int argc, char** argv);
Erik Andersen6da0ae81999-12-17 01:08:27 +000085extern int insmod_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000086extern int kill_main(int argc, char** argv);
87extern int length_main(int argc, char** argv);
88extern int ln_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +000089extern int loadacm_main(int argc, char** argv);
Eric Andersen3e0fbae1999-10-19 06:02:44 +000090extern int loadfont_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000091extern int loadkmap_main(int argc, char** argv);
92extern int losetup_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +000093extern int logger_main(int argc, char **argv);
94extern int logname_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000095extern int ls_main(int argc, char** argv);
Erik Andersen6f23cec1999-12-15 22:14:12 +000096extern int lsmod_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000097extern int makedevs_main(int argc, char** argv);
98extern int math_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000099extern int mkdir_main(int argc, char** argv);
Eric Andersen19db07b1999-12-11 08:41:28 +0000100extern int mkfifo_main(int argc, char **argv);
101extern int mkfs_minix_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000102extern int mknod_main(int argc, char** argv);
103extern int mkswap_main(int argc, char** argv);
104extern int mnc_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000105extern int more_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000106extern int mount_main(int argc, char** argv);
107extern int mt_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +0000108extern int mv_main(int argc, char** argv);
Eric Andersen485b9551999-12-07 23:14:59 +0000109extern int ping_main(int argc, char **argv);
Eric Andersen2cb55071999-12-10 08:25:07 +0000110extern int poweroff_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000111extern int printf_main(int argc, char** argv);
Eric Andersenef8b6c71999-10-20 08:05:35 +0000112extern int ps_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000113extern int pwd_main(int argc, char** argv);
114extern int reboot_main(int argc, char** argv);
115extern int rm_main(int argc, char** argv);
Erik Andersen3d7e3411999-12-16 23:04:20 +0000116extern int rmdir_main(int argc, char **argv);
117extern int rmmod_main(int argc, char** argv);
Eric Andersenc1525e81999-10-29 00:07:31 +0000118extern int sed_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000119extern int sfdisk_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000120extern int sleep_main(int argc, char** argv);
John Beppu019513a1999-12-22 17:57:31 +0000121extern int sort_main(int argc, char** argv);
Eric Andersen87590061999-10-18 21:22:59 +0000122extern int swap_on_off_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000123extern int sync_main(int argc, char** argv);
Eric Andersen3843e961999-11-25 07:30:46 +0000124extern int syslogd_main(int argc, char **argv);
Eric Andersenabc0f4f1999-12-08 23:19:36 +0000125extern int tail_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000126extern int tar_main(int argc, char** argv);
John Beppu059f1521999-12-10 05:27:16 +0000127extern int tee_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +0000128extern int touch_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000129extern int true_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000130extern int tput_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000131extern int tryopen_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000132extern int tty_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000133extern int umount_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000134extern int uname_main(int argc, char** argv);
John Beppuabb47722000-01-06 00:48:21 +0000135extern int uniq_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000136extern int update_main(int argc, char** argv);
Erik Andersen31638212000-01-15 22:28:50 +0000137extern int wc_main(int argc, char** argv);
138extern int whoami_main(int argc, char** argv);
139extern int yes_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000140
Eric Andersen2b69c401999-10-05 22:58:32 +0000141
142const char *modeString(int mode);
143const char *timeString(time_t timeVal);
Eric Andersenf811e071999-10-09 00:25:00 +0000144int isDirectory(const char *name);
145int isDevice(const char *name);
146int copyFile(const char *srcName, const char *destName, int setModes,
147 int followLinks);
148char *buildName(const char *dirName, const char *fileName);
149int makeString(int argc, const char **argv, char *buf, int bufLen);
Eric Andersen2b69c401999-10-05 22:58:32 +0000150char *getChunk(int size);
151char *chunkstrdup(const char *str);
152void freeChunks(void);
153int fullWrite(int fd, const char *buf, int len);
154int fullRead(int fd, char *buf, int len);
Eric Andersen63a0e531999-10-22 05:12:14 +0000155int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
Eric Andersen9b587181999-10-17 05:43:39 +0000156 int (*fileAction) (const char *fileName, struct stat* statbuf),
157 int (*dirAction) (const char *fileName, struct stat* statbuf));
Eric Andersen17d49ef1999-10-06 20:25:32 +0000158const char* timeString(time_t timeVal);
Eric Andersencc8ed391999-10-05 16:24:54 +0000159
Erik Andersen06936df2000-01-23 02:14:20 +0000160extern int createPath (const char *name, int mode);
Eric Andersenf6be9441999-10-13 21:12:06 +0000161extern int parse_mode( const char* s, mode_t* theMode);
Eric Andersend73dc5b1999-11-10 23:13:02 +0000162extern void usage(const char *usage) __attribute__ ((noreturn));
Eric Andersenb0e9a701999-10-18 22:28:26 +0000163
Eric Andersend23f9ba1999-10-20 19:18:15 +0000164extern uid_t my_getpwnam(char *name);
165extern gid_t my_getgrnam(char *name);
166extern void my_getpwuid(char* name, uid_t uid);
167extern void my_getgrgid(char* group, gid_t gid);
168extern int get_kernel_revision();
Eric Andersen0460ff21999-10-25 23:32:44 +0000169extern int get_console_fd(char* tty_name);
Eric Andersen29d2e361999-11-06 06:07:27 +0000170extern struct mntent *findMountPoint(const char *name, const char *table);
Eric Andersend0246fb1999-11-04 21:18:07 +0000171extern void write_mtab(char* blockDevice, char* directory,
172 char* filesystemType, long flags, char* string_flags);
173extern void erase_mtab(const char * name);
Eric Andersenb186d981999-12-03 09:19:54 +0000174extern int check_wildcard_match(const char* text, const char* pattern);
Eric Andersen1792f8c1999-12-09 06:11:36 +0000175extern long getNum (const char *cp);
John Beppuf95ca971999-12-09 22:10:18 +0000176extern pid_t findInitPid();
Eric Andersend0246fb1999-11-04 21:18:07 +0000177
Erik Andersen5509af72000-01-23 18:19:02 +0000178#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
Erik Andersen7dc16072000-01-04 01:10:25 +0000179extern int vdprintf(int d, const char *format, va_list ap);
180#endif
Eric Andersene674eb71999-10-19 20:52:57 +0000181
Eric Andersena9c95ea1999-11-15 17:33:30 +0000182#if defined BB_NFSMOUNT
183int nfsmount(const char *spec, const char *node, unsigned long *flags,
184 char **extra_opts, char **mount_opts, int running_bg);
185#endif
Eric Andersen29d2e361999-11-06 06:07:27 +0000186
Eric Andersene674eb71999-10-19 20:52:57 +0000187#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
188
189static inline int bit(char * addr,unsigned int nr)
190{
191 return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
192}
193
194static inline int setbit(char * addr,unsigned int nr)
195{
196 int __res = bit(addr, nr);
197 addr[nr >> 3] |= (1<<(nr & 7));
198 return __res != 0; \
199}
200
201static inline int clrbit(char * addr,unsigned int nr)
202{
203 int __res = bit(addr, nr);
204 addr[nr >> 3] &= ~(1<<(nr & 7));
205 return __res != 0;
206}
207
Eric Andersenaa0765e1999-10-22 04:30:20 +0000208#endif /* inline bitops junk */
Eric Andersene674eb71999-10-19 20:52:57 +0000209
210
Erik Andersen31638212000-01-15 22:28:50 +0000211#ifndef RB_POWER_OFF
212/* Stop system and switch power off if possable. */
213#define RB_POWER_OFF 0x4321fedc
214#endif
215
Eric Andersenaa0765e1999-10-22 04:30:20 +0000216
217#endif /* _INTERNAL_H_ */
Eric Andersencc8ed391999-10-05 16:24:54 +0000218