blob: 8d111a6c9c24253e0705d5c897640a2479451e89 [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>
29#include <string.h>
30#include <unistd.h>
31#include <sys/stat.h>
Eric Andersen29d2e361999-11-06 06:07:27 +000032#include <mntent.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000033
34
35/* Some useful definitions */
Eric Andersencc8ed391999-10-05 16:24:54 +000036#define STDIN 0
37#define STDOUT 1
Eric Andersenf811e071999-10-09 00:25:00 +000038#define FALSE ((int) 1)
39#define TRUE ((int) 0)
Eric Andersencc8ed391999-10-05 16:24:54 +000040
41#define PATH_LEN 1024
42#define BUF_SIZE 8192
43#define EXPAND_ALLOC 1024
44
45#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
46#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
47#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
48#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
49
50
Eric Andersencc8ed391999-10-05 16:24:54 +000051struct Applet {
52 const char* name;
53 int (*main)(int argc, char** argv);
54};
55
Eric Andersencc8ed391999-10-05 16:24:54 +000056extern int busybox_main(int argc, char** argv);
57extern int block_device_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +000058extern int cat_main(int argc, char** argv);
Eric Andersen4bea32a1999-10-06 00:30:51 +000059extern int more_main(int argc, char** argv);
Eric Andersenf811e071999-10-09 00:25:00 +000060extern int cp_main(int argc, char** argv);
Eric Andersen1b61f411999-10-13 18:56:42 +000061extern int chmod_chown_chgrp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000062extern int chroot_main(int argc, char** argv);
63extern int clear_main(int argc, char** argv);
64extern int date_main(int argc, char** argv);
65extern int dd_main(int argc, char** argv);
66extern int df_main(int argc, char** argv);
67extern int dmesg_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +000068extern int dutmp_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000069extern int false_main(int argc, char** argv);
70extern int fdisk_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000071extern int fdflush_main(int argc, char **argv);
Eric Andersene494fdd1999-10-19 20:23:03 +000072extern int fsck_minix_main(int argc, char **argv);
73extern int mkfs_minix_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000074extern int find_main(int argc, char** argv);
75extern int grep_main(int argc, char** argv);
76extern int halt_main(int argc, char** argv);
77extern int init_main(int argc, char** argv);
78extern int kill_main(int argc, char** argv);
79extern int length_main(int argc, char** argv);
80extern int ln_main(int argc, char** argv);
Eric Andersen3e0fbae1999-10-19 06:02:44 +000081extern int loadfont_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000082extern int loadkmap_main(int argc, char** argv);
83extern int losetup_main(int argc, char** argv);
84extern int ls_main(int argc, char** argv);
Eric Andersen0460ff21999-10-25 23:32:44 +000085extern int chvt_main(int argc, char** argv);
86extern int deallocvt_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000087extern int makedevs_main(int argc, char** argv);
88extern int math_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +000089extern int mkdir_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000090extern int mknod_main(int argc, char** argv);
91extern int mkswap_main(int argc, char** argv);
92extern int mnc_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000093extern int mount_main(int argc, char** argv);
94extern int mt_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +000095extern int mv_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000096extern int printf_main(int argc, char** argv);
Eric Andersenef8b6c71999-10-20 08:05:35 +000097extern int ps_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +000098extern int pwd_main(int argc, char** argv);
99extern int reboot_main(int argc, char** argv);
Eric Andersenf6be9441999-10-13 21:12:06 +0000100extern int rmdir_main(int argc, char **argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000101extern int rm_main(int argc, char** argv);
102extern int scan_partitions_main(int argc, char** argv);
103extern int sh_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000104extern int sfdisk_main(int argc, char** argv);
Eric Andersenc1525e81999-10-29 00:07:31 +0000105extern int sed_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000106extern int sleep_main(int argc, char** argv);
Eric Andersen87590061999-10-18 21:22:59 +0000107extern int swap_on_off_main(int argc, char** argv);
Eric Andersene77ae3a1999-10-19 20:03:34 +0000108extern int sync_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000109extern int tar_main(int argc, char** argv);
Eric Andersen596e5461999-10-07 08:30:23 +0000110extern int touch_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000111extern int tput_main(int argc, char** argv);
112extern int true_main(int argc, char** argv);
113extern int tryopen_main(int argc, char** argv);
114extern int umount_main(int argc, char** argv);
115extern int update_main(int argc, char** argv);
Eric Andersen0460ff21999-10-25 23:32:44 +0000116extern int uname_main(int argc, char** argv);
Eric Andersencc8ed391999-10-05 16:24:54 +0000117extern int zcat_main(int argc, char** argv);
118extern int gzip_main(int argc, char** argv);
119
Eric Andersen2b69c401999-10-05 22:58:32 +0000120
121const char *modeString(int mode);
122const char *timeString(time_t timeVal);
Eric Andersenf811e071999-10-09 00:25:00 +0000123int isDirectory(const char *name);
124int isDevice(const char *name);
125int copyFile(const char *srcName, const char *destName, int setModes,
126 int followLinks);
127char *buildName(const char *dirName, const char *fileName);
128int makeString(int argc, const char **argv, char *buf, int bufLen);
Eric Andersen2b69c401999-10-05 22:58:32 +0000129char *getChunk(int size);
130char *chunkstrdup(const char *str);
131void freeChunks(void);
132int fullWrite(int fd, const char *buf, int len);
133int fullRead(int fd, char *buf, int len);
Eric Andersen63a0e531999-10-22 05:12:14 +0000134int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
Eric Andersen9b587181999-10-17 05:43:39 +0000135 int (*fileAction) (const char *fileName, struct stat* statbuf),
136 int (*dirAction) (const char *fileName, struct stat* statbuf));
Eric Andersen17d49ef1999-10-06 20:25:32 +0000137const char* timeString(time_t timeVal);
Eric Andersencc8ed391999-10-05 16:24:54 +0000138
Eric Andersenf6be9441999-10-13 21:12:06 +0000139extern void createPath (const char *name, int mode);
140extern int parse_mode( const char* s, mode_t* theMode);
Eric Andersenb0e9a701999-10-18 22:28:26 +0000141extern volatile void usage(const char *usage);
142
Eric Andersend23f9ba1999-10-20 19:18:15 +0000143extern uid_t my_getpwnam(char *name);
144extern gid_t my_getgrnam(char *name);
145extern void my_getpwuid(char* name, uid_t uid);
146extern void my_getgrgid(char* group, gid_t gid);
147extern int get_kernel_revision();
Eric Andersen0460ff21999-10-25 23:32:44 +0000148extern int get_console_fd(char* tty_name);
Eric Andersen29d2e361999-11-06 06:07:27 +0000149extern struct mntent *findMountPoint(const char *name, const char *table);
Eric Andersend0246fb1999-11-04 21:18:07 +0000150extern void write_mtab(char* blockDevice, char* directory,
151 char* filesystemType, long flags, char* string_flags);
152extern void erase_mtab(const char * name);
153
Eric Andersene674eb71999-10-19 20:52:57 +0000154
Eric Andersen29d2e361999-11-06 06:07:27 +0000155#if defined BB_MTAB
156#define whine_if_fstab_is_missing() {}
157#else
158extern void whine_if_fstab_is_missing();
159#endif
160
161
Eric Andersene674eb71999-10-19 20:52:57 +0000162#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
163
164static inline int bit(char * addr,unsigned int nr)
165{
166 return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
167}
168
169static inline int setbit(char * addr,unsigned int nr)
170{
171 int __res = bit(addr, nr);
172 addr[nr >> 3] |= (1<<(nr & 7));
173 return __res != 0; \
174}
175
176static inline int clrbit(char * addr,unsigned int nr)
177{
178 int __res = bit(addr, nr);
179 addr[nr >> 3] &= ~(1<<(nr & 7));
180 return __res != 0;
181}
182
Eric Andersenaa0765e1999-10-22 04:30:20 +0000183#endif /* inline bitops junk */
Eric Andersene674eb71999-10-19 20:52:57 +0000184
185
Eric Andersenaa0765e1999-10-22 04:30:20 +0000186
187#endif /* _INTERNAL_H_ */
Eric Andersencc8ed391999-10-05 16:24:54 +0000188