2 /* Toybox infrastructure.
4 * Copyright 2006 Rob Landley <rob@landley.net>
7 #include "generated/config.h"
9 #include "lib/portability.h"
33 #include <sys/ioctl.h>
35 #include <sys/mount.h>
36 #include <sys/resource.h>
38 #include <sys/statvfs.h>
39 #include <sys/sysinfo.h>
41 #include <sys/times.h>
42 #include <sys/types.h>
43 #include <sys/utsname.h>
54 #include "toys/e2fs.h"
56 // Get list of function prototypes for all enabled command_main() functions.
58 #define NEWTOY(name, opts, flags) void name##_main(void);
59 #define OLDTOY(name, oldname, opts, flags)
60 #include "generated/newtoys.h"
61 #include "generated/globals.h"
63 // These live in main.c
65 struct toy_list *toy_find(char *name);
66 void toy_init(struct toy_list *which, char *argv[]);
67 void toy_exec(char *argv[]);
69 // Flags describing command behavior.
71 #define TOYFLAG_USR (1<<0)
72 #define TOYFLAG_BIN (1<<1)
73 #define TOYFLAG_SBIN (1<<2)
74 #define TOYMASK_LOCATION ((1<<4)-1)
76 // This is a shell built-in function, running in the same process context.
77 #define TOYFLAG_NOFORK (1<<4)
79 // Start command with a umask of 0 (saves old umask in this.old_umask)
80 #define TOYFLAG_UMASK (1<<5)
82 // This command runs as root.
83 #define TOYFLAG_STAYROOT (1<<6)
84 #define TOYFLAG_NEEDROOT (1<<7)
85 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
87 // Array of available applets
89 extern struct toy_list {
91 void (*toy_main)(void);
96 // Global context shared by all commands.
98 extern struct toy_context {
99 struct toy_list *which; // Which entry in toy_list is this one?
100 int exitval; // Value error_exit feeds to exit()
101 char **argv; // Original command line arguments
102 unsigned optflags; // Command line option flags from get_optflags()
103 char **optargs; // Arguments left over from get_optflags()
104 int optc; // Count of optargs
105 int exithelp; // Should error_exit print a usage message first?
106 int old_umask; // Old umask preserved by TOYFLAG_UMASK
109 // One big temporary buffer, for use by commands (not library functions).
111 extern char toybuf[4096];
115 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))