Skip to content

Commit

Permalink
VFS: Respect -C flag
Browse files Browse the repository at this point in the history
VFS feature uses the same -C flag as the overlays system.
  • Loading branch information
trungnt2910 committed Mar 8, 2023
1 parent 0cc2b6c commit a97a8dc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
16 changes: 12 additions & 4 deletions blink/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ _Alignas(1) static const char USAGE[] =
" -Z print internal statistics on exit\n"
" -L PATH log filename (default is blink.log)\n"
#endif
#ifndef DISABLE_OVERLAYS
#if !defined(DISABLE_OVERLAYS) || !defined(DISABLE_VFS)
" -C PATH sets chroot dir or overlay spec [default \":o\"]\n"
#endif
#if !defined(DISABLE_OVERLAYS) || !defined(NDEBUG)
Expand All @@ -121,6 +121,9 @@ _Alignas(1) static const char USAGE[] =
#ifndef DISABLE_OVERLAYS
" $BLINK_OVERLAYS file system roots [default \":o\"]\n"
#endif
#ifndef DISABLE_VFS
" $BLINK_PREFIX file system root [default \"/\"]\n"
#endif
#ifndef NDEBUG

" $BLINK_LOG_FILENAME log filename (same as -L flag)\n"
Expand Down Expand Up @@ -256,6 +259,9 @@ static void GetOpts(int argc, char *argv[]) {
FLAG_overlays = getenv("BLINK_OVERLAYS");
if (!FLAG_overlays) FLAG_overlays = DEFAULT_OVERLAYS;
#endif
#ifndef DISABLE_VFS
FLAG_prefix = getenv("BLINK_PREFIX");
#endif
#if LOG_ENABLED
FLAG_logpath = getenv("BLINK_LOG_FILENAME");
#endif
Expand Down Expand Up @@ -289,10 +295,12 @@ static void GetOpts(int argc, char *argv[]) {
FLAG_logpath = optarg_;
break;
case 'C':
#ifndef DISABLE_OVERLAYS
#if !defined(DISABLE_OVERLAYS)
FLAG_overlays = optarg_;
#elif !defined(DISABLE_VFS)
FLAG_prefix = optarg_;
#else
WriteErrorString("error: overlays support was disabled\n");
WriteErrorString("error: overlays and vfs support were both disabled\n");
#endif
break;
case 'v':
Expand Down Expand Up @@ -367,7 +375,7 @@ int main(int argc, char *argv[]) {
}
#endif
#ifndef DISABLE_VFS
if (VfsInit()) {
if (VfsInit(FLAG_prefix)) {
WriteErrorString("error: vfs initialization failed\n");
exit(1);
}
Expand Down
9 changes: 7 additions & 2 deletions blink/blinkenlights.c
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,9 @@ static void GetOpts(int argc, char *argv[]) {
#ifndef DISABLE_OVERLAYS
FLAG_overlays = getenv("BLINK_OVERLAYS");
if (!FLAG_overlays) FLAG_overlays = DEFAULT_OVERLAYS;
#endif
#ifndef DISABLE_VFS
FLAG_prefix = getenv("BLINK_PREFIX");
#endif
while ((opt = GetOpt(argc, argv, "0hjmvVtrzRNsZb:Hw:L:C:")) != -1) {
switch (opt) {
Expand Down Expand Up @@ -3854,8 +3857,10 @@ static void GetOpts(int argc, char *argv[]) {
FLAG_logpath = optarg_;
break;
case 'C':
#ifndef DISABLE_OVERLAYS
#if !defined(DISABLE_OVERLAYS)
FLAG_overlays = optarg_;
#elif !defined(DISABLE_VFS)
FLAG_prefix = optarg_;
#else
WriteErrorString("error: overlays support was disabled\n");
#endif
Expand Down Expand Up @@ -4042,7 +4047,7 @@ int main(int argc, char *argv[]) {
}
#endif
#ifndef DISABLE_VFS
if (VfsInit()) {
if (VfsInit(FLAG_prefix)) {
WriteErrorString("error: vfs initialization failed\n");
exit(1);
}
Expand Down
3 changes: 3 additions & 0 deletions blink/flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ const char *FLAG_logpath;
#ifndef DISABLE_OVERLAYS
const char *FLAG_overlays;
#endif
#ifndef DISABLE_VFS
const char *FLAG_prefix;
#endif
1 change: 1 addition & 0 deletions blink/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ extern u64 FLAG_dyninterpaddr;

extern const char *FLAG_logpath;
extern const char *FLAG_overlays;
extern const char *FLAG_prefix;

#endif /* BLINK_FLAG_H_ */
8 changes: 6 additions & 2 deletions blink/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static struct Vfs g_vfs = {
.mapslock = PTHREAD_MUTEX_INITIALIZER_,
};

int VfsInit(void) {
int VfsInit(const char *prefix) {
struct stat st;
char *cwd, hostcwd[PATH_MAX], *bprefix = NULL;
struct VfsInfo *info;
Expand All @@ -108,13 +108,17 @@ int VfsInit(void) {

// Initialize the root directory
unassert(!VfsAcquireInfo(&g_initialrootinfo, &g_rootinfo));
bprefix = realpath(getenv("BLINK_PREFIX"), NULL);
if (prefix) {
bprefix = realpath(prefix, NULL);
}
if (bprefix) {
if (stat(bprefix, &st) == -1) {
ERRF("Failed to stat BLINK_PREFIX %s, %s", bprefix, strerror(errno));
free(bprefix);
bprefix = NULL;
} else if (!S_ISDIR(st.st_mode)) {
ERRF("BLINK_PREFIX %s is not a directory", bprefix);
free(bprefix);
bprefix = NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion blink/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int VfsMunmap(void *, size_t);
int VfsMprotect(void *, size_t, int);
int VfsMsync(void *, size_t, int);

int VfsInit(void);
int VfsInit(const char *);
int VfsRegister(struct VfsSystem *);
int VfsTraverse(const char *, struct VfsInfo **, bool);
int VfsCreateInfo(struct VfsInfo **);
Expand Down

0 comments on commit a97a8dc

Please sign in to comment.