1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/* vi: set ts=4 :*/
/* Toybox infrastructure.
*
* Copyright 2006 Rob Landley <rob@landley.net>
*/
// Provide function declarations and structs. Note that main.c #includes this
// file twice (with different macros) to populate toy_list[].
#ifndef NEWTOY
#define NEWTOY(name, opts, flags) void name##_main(void);
#define OLDTOY(name, oldname, opts, flags)
struct df_data {
struct arg_list *fstype;
long units;
};
// Still to go: "E:jJ:L:m:O:"
#define MKE2FS_OPTSTRING "<1>2g:Fnqm#N#i#b#"
struct dmesg_data {
long level;
long size;
};
struct mke2fs_data {
// Command line arguments.
long blocksize;
long bytes_per_inode;
long inodes; // Total inodes in filesystem.
long reserved_percent; // Integer precent of space to reserve for root.
char *gendir; // Where to read dirtree from.
// Internal data.
struct dirtree *dt; // Tree of files to copy into the new filesystem.
unsigned treeblocks; // Blocks used by dt
unsigned treeinodes; // Inodes used by dt
unsigned blocks; // Total blocks in the filesystem.
unsigned freeblocks; // Free blocks in the filesystem.
unsigned inodespg; // Inodes per group
unsigned groups; // Total number of block groups.
unsigned blockbits; // Bits per block. (Also blocks per group.)
// For gene2fs
unsigned nextblock; // Next data block to allocate
unsigned nextgroup; // Next group we'll be allocating from
int fsfd; // File descriptor of filesystem (to output to).
struct ext2_superblock sb;
};
struct netcat_data {
char *filename; // -f read from filename instead of network
long quit_delay; // -q Exit after EOF from stdin after # seconds.
char *source_address; // -s Bind to a specific source address.
long port; // -p Bind to a specific source port.
long listen; // -l Listen for connection instead of dialing out.
long wait; // -w Wait # seconds for a connection.
long delay; // -i delay between lines sent
};
struct oneit_data {
char *console;
};
struct patch_data {
char *infile;
long prefix;
struct double_list *plines, *flines;
long oldline, oldlen, newline, newlen, linenum;
int context, state, filein, fileout, filepatch;
char *tempname, *oldname;
};
struct sleep_data {
long seconds;
};
struct touch_data {
char *ref_file;
char *time;
long length;
};
struct toysh_data {
char *command;
};
struct mkfifo_data {
char *mode;
};
extern union toy_union {
struct dmesg_data dmesg;
struct df_data df;
struct mke2fs_data mke2fs;
struct mkfifo_data mkfifo;
struct netcat_data netcat;
struct oneit_data oneit;
struct patch_data patch;
struct sleep_data sleep;
struct touch_data touch;
struct toysh_data toysh;
} toy;
#define TOYFLAG_USR (1<<0)
#define TOYFLAG_BIN (1<<1)
#define TOYFLAG_SBIN (1<<2)
#define TOYMASK_LOCATION ((1<<4)-1)
#define TOYFLAG_NOFORK (1<<4)
extern struct toy_list {
char *name;
void (*toy_main)(void);
char *options;
int flags;
} toy_list[];
#endif
// List of all the applets toybox can provide.
// This one is out of order on purpose: it's the first element in the array.
NEWTOY(toybox, NULL, 0)
// The rest of these are alphabetical, for binary search.
USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_BIN))
USE_BZCAT(NEWTOY(bzcat, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_CATV(NEWTOY(catv, "vte", TOYFLAG_USR|TOYFLAG_BIN))
USE_CHROOT(NEWTOY(chroot, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_TOYSH(NEWTOY(cd, NULL, TOYFLAG_NOFORK))
USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN))
USE_DIRNAME(NEWTOY(dirname, "<1>1", TOYFLAG_BIN))
USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN))
USE_ECHO(NEWTOY(echo, "+en", TOYFLAG_BIN))
USE_TOYSH(NEWTOY(exit, NULL, TOYFLAG_NOFORK))
USE_FALSE(NEWTOY(false, NULL, TOYFLAG_BIN))
USE_HELLO(NEWTOY(hello, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
USE_MKE2FS(NEWTOY(mke2fs, MKE2FS_OPTSTRING, TOYFLAG_SBIN))
USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN))
USE_NETCAT(OLDTOY(nc, netcat, "i#w#l@p#s:q#f:e", TOYFLAG_BIN))
USE_NETCAT(NEWTOY(netcat, "i#w#l@p#s:q#f:e", TOYFLAG_BIN))
USE_ONEIT(NEWTOY(oneit, "+<1c:p", TOYFLAG_SBIN))
USE_PATCH(NEWTOY(patch, "up#i:R", TOYFLAG_USR|TOYFLAG_BIN))
USE_PWD(NEWTOY(pwd, NULL, TOYFLAG_BIN))
USE_READLINK(NEWTOY(readlink, "<1f", TOYFLAG_BIN))
USE_TOYSH(OLDTOY(sh, toysh, "c:i", TOYFLAG_BIN))
USE_SHA1SUM(NEWTOY(sha1sum, NULL, TOYFLAG_USR|TOYFLAG_BIN))
USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN))
USE_SYNC(NEWTOY(sync, NULL, TOYFLAG_BIN))
USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN))
USE_TOYSH(NEWTOY(toysh, "c:i", TOYFLAG_BIN))
USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN))
USE_TTY(NEWTOY(tty, "s", TOYFLAG_BIN))
USE_WHICH(NEWTOY(which, "a", TOYFLAG_USR|TOYFLAG_BIN))
USE_YES(NEWTOY(yes, NULL, TOYFLAG_USR|TOYFLAG_BIN))
|