Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 1 | /* |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 2 | * Busybox main internal header file |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 3 | * |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 4 | * |
| 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 Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 23 | #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 Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 32 | #include <mntent.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | /* Some useful definitions */ |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 36 | #define FALSE ((int) 1) |
| 37 | #define TRUE ((int) 0) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 38 | |
| 39 | #define PATH_LEN 1024 |
| 40 | #define BUF_SIZE 8192 |
| 41 | #define EXPAND_ALLOC 1024 |
| 42 | |
| 43 | #define isBlank(ch) (((ch) == ' ') || ((ch) == '\t')) |
| 44 | #define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9')) |
| 45 | #define isOctal(ch) (((ch) >= '0') && ((ch) <= '7')) |
| 46 | #define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '[')) |
| 47 | |
| 48 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 49 | struct Applet { |
| 50 | const char* name; |
| 51 | int (*main)(int argc, char** argv); |
| 52 | }; |
| 53 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 54 | extern int busybox_main(int argc, char** argv); |
| 55 | extern int block_device_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 56 | extern int cat_main(int argc, char** argv); |
Eric Andersen | 4bea32a | 1999-10-06 00:30:51 +0000 | [diff] [blame] | 57 | extern int more_main(int argc, char** argv); |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 58 | extern int cp_main(int argc, char** argv); |
Eric Andersen | 1b61f41 | 1999-10-13 18:56:42 +0000 | [diff] [blame] | 59 | extern int chmod_chown_chgrp_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 60 | extern int chroot_main(int argc, char** argv); |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 61 | extern int chvt_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 62 | extern int clear_main(int argc, char** argv); |
| 63 | extern int date_main(int argc, char** argv); |
| 64 | extern int dd_main(int argc, char** argv); |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 65 | extern int deallocvt_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 66 | extern int df_main(int argc, char** argv); |
| 67 | extern int dmesg_main(int argc, char** argv); |
John Beppu | 7a98606 | 1999-12-09 18:29:29 +0000 | [diff] [blame] | 68 | extern int du_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 69 | extern int dutmp_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 70 | extern int false_main(int argc, char** argv); |
Erik Andersen | 1c5b258 | 1999-12-16 20:59:36 +0000 | [diff] [blame] | 71 | extern int fbset_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 72 | extern int fdisk_main(int argc, char** argv); |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 73 | extern int fdflush_main(int argc, char **argv); |
Eric Andersen | e494fdd | 1999-10-19 20:23:03 +0000 | [diff] [blame] | 74 | extern int fsck_minix_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 75 | extern int find_main(int argc, char** argv); |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 76 | extern int free_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 77 | extern int grep_main(int argc, char** argv); |
| 78 | extern int halt_main(int argc, char** argv); |
John Beppu | 3157b1f | 1999-12-10 07:42:50 +0000 | [diff] [blame] | 79 | extern int head_main(int argc, char** argv); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 80 | extern int hostname_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 81 | extern int init_main(int argc, char** argv); |
Erik Andersen | 6da0ae8 | 1999-12-17 01:08:27 +0000 | [diff] [blame] | 82 | extern int insmod_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 83 | extern int kill_main(int argc, char** argv); |
| 84 | extern int length_main(int argc, char** argv); |
| 85 | extern int ln_main(int argc, char** argv); |
Eric Andersen | 3e0fbae | 1999-10-19 06:02:44 +0000 | [diff] [blame] | 86 | extern int loadfont_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 87 | extern int loadkmap_main(int argc, char** argv); |
| 88 | extern int losetup_main(int argc, char** argv); |
| 89 | extern int ls_main(int argc, char** argv); |
Erik Andersen | 6f23cec | 1999-12-15 22:14:12 +0000 | [diff] [blame] | 90 | extern int lsmod_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 91 | extern int makedevs_main(int argc, char** argv); |
| 92 | extern int math_main(int argc, char** argv); |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 93 | extern int mkdir_main(int argc, char** argv); |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 94 | extern int mkfifo_main(int argc, char **argv); |
| 95 | extern int mkfs_minix_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 96 | extern int mknod_main(int argc, char** argv); |
| 97 | extern int mkswap_main(int argc, char** argv); |
| 98 | extern int mnc_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 99 | extern int mount_main(int argc, char** argv); |
| 100 | extern int mt_main(int argc, char** argv); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 101 | extern int mv_main(int argc, char** argv); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 102 | extern int ping_main(int argc, char **argv); |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 103 | extern int poweroff_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 104 | extern int printf_main(int argc, char** argv); |
Eric Andersen | ef8b6c7 | 1999-10-20 08:05:35 +0000 | [diff] [blame] | 105 | extern int ps_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 106 | extern int pwd_main(int argc, char** argv); |
| 107 | extern int reboot_main(int argc, char** argv); |
| 108 | extern int rm_main(int argc, char** argv); |
Erik Andersen | 3d7e341 | 1999-12-16 23:04:20 +0000 | [diff] [blame] | 109 | extern int rmdir_main(int argc, char **argv); |
| 110 | extern int rmmod_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 111 | extern int scan_partitions_main(int argc, char** argv); |
| 112 | extern int sh_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 113 | extern int sfdisk_main(int argc, char** argv); |
Eric Andersen | c1525e8 | 1999-10-29 00:07:31 +0000 | [diff] [blame] | 114 | extern int sed_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 115 | extern int sleep_main(int argc, char** argv); |
Eric Andersen | 8759006 | 1999-10-18 21:22:59 +0000 | [diff] [blame] | 116 | extern int swap_on_off_main(int argc, char** argv); |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 117 | extern int sync_main(int argc, char** argv); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 118 | extern int syslogd_main(int argc, char **argv); |
| 119 | extern int logger_main(int argc, char **argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 120 | extern int tar_main(int argc, char** argv); |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 121 | extern int tail_main(int argc, char** argv); |
John Beppu | 059f152 | 1999-12-10 05:27:16 +0000 | [diff] [blame] | 122 | extern int tee_main(int argc, char** argv); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 123 | extern int touch_main(int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 124 | extern int tput_main(int argc, char** argv); |
| 125 | extern int true_main(int argc, char** argv); |
| 126 | extern int tryopen_main(int argc, char** argv); |
| 127 | extern int umount_main(int argc, char** argv); |
| 128 | extern int update_main(int argc, char** argv); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 129 | extern int uname_main(int argc, char** argv); |
Eric Andersen | d80e851 | 1999-11-16 00:46:00 +0000 | [diff] [blame] | 130 | extern int gunzip_main (int argc, char** argv); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 131 | extern int gzip_main(int argc, char** argv); |
| 132 | |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 133 | |
| 134 | const char *modeString(int mode); |
| 135 | const char *timeString(time_t timeVal); |
Eric Andersen | f811e07 | 1999-10-09 00:25:00 +0000 | [diff] [blame] | 136 | int isDirectory(const char *name); |
| 137 | int isDevice(const char *name); |
| 138 | int copyFile(const char *srcName, const char *destName, int setModes, |
| 139 | int followLinks); |
| 140 | char *buildName(const char *dirName, const char *fileName); |
| 141 | int makeString(int argc, const char **argv, char *buf, int bufLen); |
Eric Andersen | 2b69c40 | 1999-10-05 22:58:32 +0000 | [diff] [blame] | 142 | char *getChunk(int size); |
| 143 | char *chunkstrdup(const char *str); |
| 144 | void freeChunks(void); |
| 145 | int fullWrite(int fd, const char *buf, int len); |
| 146 | int fullRead(int fd, char *buf, int len); |
Eric Andersen | 63a0e53 | 1999-10-22 05:12:14 +0000 | [diff] [blame] | 147 | int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst, |
Eric Andersen | 9b58718 | 1999-10-17 05:43:39 +0000 | [diff] [blame] | 148 | int (*fileAction) (const char *fileName, struct stat* statbuf), |
| 149 | int (*dirAction) (const char *fileName, struct stat* statbuf)); |
Eric Andersen | 17d49ef | 1999-10-06 20:25:32 +0000 | [diff] [blame] | 150 | const char* timeString(time_t timeVal); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 151 | |
Eric Andersen | f6be944 | 1999-10-13 21:12:06 +0000 | [diff] [blame] | 152 | extern void createPath (const char *name, int mode); |
| 153 | extern int parse_mode( const char* s, mode_t* theMode); |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 154 | extern void usage(const char *usage) __attribute__ ((noreturn)); |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 155 | |
Eric Andersen | d23f9ba | 1999-10-20 19:18:15 +0000 | [diff] [blame] | 156 | extern uid_t my_getpwnam(char *name); |
| 157 | extern gid_t my_getgrnam(char *name); |
| 158 | extern void my_getpwuid(char* name, uid_t uid); |
| 159 | extern void my_getgrgid(char* group, gid_t gid); |
| 160 | extern int get_kernel_revision(); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 161 | extern int get_console_fd(char* tty_name); |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 162 | extern struct mntent *findMountPoint(const char *name, const char *table); |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 163 | extern void write_mtab(char* blockDevice, char* directory, |
| 164 | char* filesystemType, long flags, char* string_flags); |
| 165 | extern void erase_mtab(const char * name); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 166 | extern int check_wildcard_match(const char* text, const char* pattern); |
Eric Andersen | 1792f8c | 1999-12-09 06:11:36 +0000 | [diff] [blame] | 167 | extern long getNum (const char *cp); |
John Beppu | f95ca97 | 1999-12-09 22:10:18 +0000 | [diff] [blame] | 168 | extern pid_t findInitPid(); |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 169 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 170 | |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 171 | #if defined BB_MTAB |
| 172 | #define whine_if_fstab_is_missing() {} |
| 173 | #else |
| 174 | extern void whine_if_fstab_is_missing(); |
| 175 | #endif |
| 176 | |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 177 | #if defined BB_NFSMOUNT |
| 178 | int nfsmount(const char *spec, const char *node, unsigned long *flags, |
| 179 | char **extra_opts, char **mount_opts, int running_bg); |
| 180 | #endif |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 181 | |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 182 | #if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX) |
| 183 | |
| 184 | static inline int bit(char * addr,unsigned int nr) |
| 185 | { |
| 186 | return (addr[nr >> 3] & (1<<(nr & 7))) != 0; |
| 187 | } |
| 188 | |
| 189 | static inline int setbit(char * addr,unsigned int nr) |
| 190 | { |
| 191 | int __res = bit(addr, nr); |
| 192 | addr[nr >> 3] |= (1<<(nr & 7)); |
| 193 | return __res != 0; \ |
| 194 | } |
| 195 | |
| 196 | static inline int clrbit(char * addr,unsigned int nr) |
| 197 | { |
| 198 | int __res = bit(addr, nr); |
| 199 | addr[nr >> 3] &= ~(1<<(nr & 7)); |
| 200 | return __res != 0; |
| 201 | } |
| 202 | |
Eric Andersen | aa0765e | 1999-10-22 04:30:20 +0000 | [diff] [blame] | 203 | #endif /* inline bitops junk */ |
Eric Andersen | e674eb7 | 1999-10-19 20:52:57 +0000 | [diff] [blame] | 204 | |
| 205 | |
Eric Andersen | aa0765e | 1999-10-22 04:30:20 +0000 | [diff] [blame] | 206 | |
| 207 | #endif /* _INTERNAL_H_ */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 208 | |