2 /* Toybox infrastructure.
4 * Copyright 2006 Rob Landley <rob@landley.net>
7 #include "generated/config.h"
9 #include "lib/portability.h"
26 #include <sys/ioctl.h>
28 #include <sys/mount.h>
30 #include <sys/statvfs.h>
31 #include <sys/types.h>
37 #define _XOPEN_SOURCE 600
41 #include "toys/e2fs.h"
43 // Get list of function prototypes for all enabled command_main() functions.
45 #define NEWTOY(name, opts, flags) void name##_main(void);
46 #define OLDTOY(name, oldname, opts, flags)
47 #include "generated/newtoys.h"
48 #include "generated/globals.h"
50 // These live in main.c
52 struct toy_list *toy_find(char *name);
53 void toy_init(struct toy_list *which, char *argv[]);
54 void toy_exec(char *argv[]);
56 // Flags describing applet behavior.
58 #define TOYFLAG_USR (1<<0)
59 #define TOYFLAG_BIN (1<<1)
60 #define TOYFLAG_SBIN (1<<2)
61 #define TOYMASK_LOCATION ((1<<4)-1)
63 // This is a shell built-in function, running in the same process context.
64 #define TOYFLAG_NOFORK (1<<4)
66 // Start applet with a umask of 0 (saves old umask in this.old_umask)
67 #define TOYFLAG_UMASK (1<<5)
69 // This applet runs as root.
70 #define TOYFLAG_STAYROOT (1<<6)
71 #define TOYFLAG_NEEDROOT (1<<7)
72 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
74 // Array of available applets
76 extern struct toy_list {
78 void (*toy_main)(void);
83 // Global context shared by all applets.
85 extern struct toy_context {
86 struct toy_list *which; // Which entry in toy_list is this one?
87 int exitval; // Value error_exit feeds to exit()
88 char **argv; // Original command line arguments
89 unsigned optflags; // Command line option flags from get_optflags()
90 char **optargs; // Arguments left over from get_optflags()
91 int optc; // Count of optargs
92 int exithelp; // Should error_exit print a usage message first?
93 int old_umask; // Old umask preserved by TOYFLAG_UMASK
96 // One big temporary buffer, for use by applets (not library functions).
98 extern char toybuf[4096];
100 #define DEFINE_GLOBALS(...)