From 5ef28cccf92f5eada6d502fa4b0e16a13e94be5b Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 3 Feb 2017 17:13:58 -0500 Subject: Allow mounting of any directory as the root directory. Provide definitions for the macros: * RB_ROOT_VOL_HIDDEN(v) to exclude certain items from the root. * RB_ROOT_CONTENTS to return a string with the name of the directory to mount in the root. Defaults are in export/rbpaths.h It's a bit much for those that don't need the full functionality. Some conditional define can cut it back a lot to cut out things only needed if alternate root mounts are required. I'm just not bothering yet. The basic concept would be applied to all targets to keep file code from forking too much. Change-Id: I90b5c0a1c949283d3102c16734b0b6ac73901a30 --- firmware/include/rb_namespace.h | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 firmware/include/rb_namespace.h (limited to 'firmware/include/rb_namespace.h') diff --git a/firmware/include/rb_namespace.h b/firmware/include/rb_namespace.h new file mode 100644 index 0000000000..4d7a125c7b --- /dev/null +++ b/firmware/include/rb_namespace.h @@ -0,0 +1,79 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2017 by Michael Sevakis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef RB_NAMESPACE_H +#define RB_NAMESPACE_H + +#include "file_internal.h" + +enum ns_item_flags +{ + NSITEM_MOUNTED = 0x01, /* item is mounted */ + NSITEM_HIDDEN = 0x02, /* item is not enumerated */ + NSITEM_CONTENTS = 0x04, /* contents enumerate */ +}; + +struct ns_scan_info +{ + struct dirscan_info scan; /* dirscan info - first! */ + int item; /* current item in parent */ +}; + +/* root functions */ +int root_mount_path(const char *path, unsigned int flags); +void root_unmount_volume(IF_MV_NONVOID(int volume)); +int root_readdir_dirent(struct filestr_base *stream, + struct ns_scan_info *scanp, + struct dirent *entry); + +/* namespace functions */ +int ns_parse_root(const char *path, const char **pathp, uint16_t *lenp); +int ns_open_root(IF_MV(int volume,) unsigned int *callflagsp, + struct file_base_info *infop, uint16_t *attrp); +int ns_open_stream(const char *path, unsigned int callflags, + struct filestr_base *stream, struct ns_scan_info *scanp); + +/* closes the namespace stream */ +static inline int ns_close_stream(struct filestr_base *stream) +{ + return close_stream_internal(stream); +} + +#include "dircache_redirect.h" + +static inline void ns_dirscan_rewind(struct ns_scan_info *scanp) +{ + rewinddir_dirent(&scanp->scan); + if (scanp->item != -1) + scanp->item = 0; +} + +static inline int ns_readdir_dirent(struct filestr_base *stream, + struct ns_scan_info *scanp, + struct dirent *entry) + +{ + if (scanp->item == -1) + return readdir_dirent(stream, &scanp->scan, entry); + else + return root_readdir_dirent(stream, scanp, entry); +} + +#endif /* RB_NAMESPACE_H */ -- cgit v1.2.3