summaryrefslogtreecommitdiffstats
path: root/firmware/include
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-01-08 17:14:10 -0500
committerMichael Sevakis <jethead71@rockbox.org>2017-01-17 14:35:36 -0500
commita931c76b3a46d1884e985a3bfc82b947521dab97 (patch)
tree1141cf9a9a8c123bde3d76d147ee1e910c7c6045 /firmware/include
parent0056ea8a256af0e2daaf451af43c00708a31d4df (diff)
downloadrockbox-a931c76b3a46d1884e985a3bfc82b947521dab97.tar.gz
rockbox-a931c76b3a46d1884e985a3bfc82b947521dab97.tar.bz2
rockbox-a931c76b3a46d1884e985a3bfc82b947521dab97.zip
Do some debug and preparatory work for ramcache and playlist
The file system rework introduced incompatibility between dircache and the tagcache ramcache and playlist dircache path caching. This update makes changes to filesystem code to reintegrate all that. It also fixes a couple bugs that were found when vetting all the code. The filestream cache was being reset without regard to the stream even if it was shared in write mode (made work of .playlist_control). Better handling of unmounting gives files a better go at force-closing them without risk to disk integrity. Did some miscellaneous pedantic changes. Improved efficiency of testing a file's existence (a little) since the path parser will be shared between file code and parsing for the sake of finding dircache references, not duplicated as before. This commit doesn't reenable said items just for the sake of keeping changes separate and related. Plan for the next is to enable dircache again for the playlists (easy peasy) and reenable tagcache ramcache but *without* the dircache path caching because it's rather substantial to change in itself. The ramcache will still function without dircache. Change-Id: I7e2a9910b866251fa8333e1275f72fcfc8425d2d
Diffstat (limited to 'firmware/include')
-rw-r--r--firmware/include/dircache.h40
-rw-r--r--firmware/include/dircache_redirect.h19
-rw-r--r--firmware/include/file_internal.h91
-rw-r--r--firmware/include/fileobj_mgr.h5
4 files changed, 104 insertions, 51 deletions
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h
index 7e8c764e7f..d73c6f6e81 100644
--- a/firmware/include/dircache.h
+++ b/firmware/include/dircache.h
@@ -57,6 +57,15 @@
figure pessimistic */
typedef uint32_t dc_serial_t;
+/* these should agree with size of dc_serial_t */
+#define DC_SERHASH_START 0xffffffff
+
+/* I was originally using FNV hash but decided this is probably okay
+ (for now) */
+#define dc_hash_serialnum(s, h) \
+ ({ dc_serial_t __x = (s); crc_32(&(__x), sizeof(dc_serial_t), (h)); })
+#define DC_SERIAL_FMT "0x%08lX"
+
/**
****************************************************************************/
@@ -132,10 +141,33 @@ void dircache_fileop_sync(struct file_base_binding *infop,
const struct dirinfo_native *dinp);
-/** Dircache paths and files **/
-ssize_t dircache_get_path(const struct dircache_file *dcfilep, char *buf,
- size_t size);
-int dircache_get_file(const char *path, struct dircache_file *dcfilep);
+/** Dircache paths, files and shortcuts **/
+struct dircache_fileref
+{
+ struct dircache_file dcfile;
+ dc_serial_t serialhash; /* Hash of serialnumbers to root */
+};
+
+void dircache_fileref_init(struct dircache_fileref *dcfrefp);
+ssize_t dircache_get_fileref_path(const struct dircache_fileref *dcfrefp,
+ char *buf, size_t size);
+
+/* Bitflags for dircache_search() */
+enum dircache_search_flags
+{
+ DCS_FILEREF = 0x01, /* Check fileref existence and serial number */
+ _DCS_VERIFY_FLAG = 0x02, /* Internal: Only valid with DCS_FILEREF */
+ DCS_FILEREF_VERIFY = 0x03, /* Do DCS_FILEREF check + verify serial hash */
+ DCS_CACHED_PATH = 0x04, /* Check only cache for provided path */
+ _DCS_STORAGE_FLAG = 0x08, /* Internal: Only valid with DCS_CACHED_PATH */
+ DCS_STORAGE_PATH = 0x0c, /* Read-through if needed for provided path */
+ DCS_UPDATE_FILEREF = 0x10, /* If fileref is not valid but path is found or
+ searching a path, update the reference
+ information */
+};
+
+int dircache_search(unsigned int flags, struct dircache_fileref *dcfrefp,
+ const char *path);
/** Debug screen/info stuff **/
diff --git a/firmware/include/dircache_redirect.h b/firmware/include/dircache_redirect.h
index 15fb4bc38d..9fae16b551 100644
--- a/firmware/include/dircache_redirect.h
+++ b/firmware/include/dircache_redirect.h
@@ -24,6 +24,8 @@
/***
** Internal redirects that depend upon whether or not dircache is made
+ **
+ ** Some stuff deals with it, some doesn't right now. This is a nexus point..
**/
/** File binding **/
@@ -119,11 +121,6 @@ static inline void fileop_onsync_internal(struct filestr_base *stream)
#endif
}
-static inline void fileop_ontruncate_internal(struct filestr_base *stream)
-{
- fileobj_fileop_truncate(stream);
-}
-
static inline void volume_onmount_internal(IF_MV_NONVOID(int volume))
{
#ifdef HAVE_DIRCACHE
@@ -134,10 +131,20 @@ static inline void volume_onmount_internal(IF_MV_NONVOID(int volume))
static inline void volume_onunmount_internal(IF_MV_NONVOID(int volume))
{
- fileobj_mgr_unmount(IF_MV(volume));
#ifdef HAVE_DIRCACHE
+ /* First, to avoid update of something about to be destroyed anyway */
dircache_unmount(IF_MV(volume));
#endif
+ fileobj_mgr_unmount(IF_MV(volume));
+}
+
+static inline void fileop_onunmount_internal(struct filestr_base *stream)
+{
+
+ if (stream->flags & FD_WRITE)
+ force_close_writer_internal(stream); /* try to save stuff */
+ else
+ fileop_onclose_internal(stream); /* just readers, bye */
}
diff --git a/firmware/include/file_internal.h b/firmware/include/file_internal.h
index d1bb67406a..acec81206e 100644
--- a/firmware/include/file_internal.h
+++ b/firmware/include/file_internal.h
@@ -81,6 +81,7 @@
#define ATTR_NEW_FILE (ATTR_ARCHIVE)
#define ATTR_NEW_DIRECTORY (ATTR_DIRECTORY)
+#define ATTR_SYSTEM_ROOT (ATTR_SYSROOT | ATTR_DIRECTORY)
#define ATTR_MOUNT_POINT (ATTR_VOLUME | ATTR_DIRECTORY)
/** File sector cache **/
@@ -110,33 +111,35 @@ void file_cache_free(struct filestr_cache *cachep);
enum fildes_and_obj_flags
{
/* used in descriptor and common */
- FDO_BUSY = 0x0001, /* descriptor/object is in use */
+ FDO_BUSY = 0x0001, /* descriptor/object is in use */
/* only used in individual stream descriptor */
- FD_WRITE = 0x0002, /* descriptor has write mode */
- FD_WRONLY = 0x0004, /* descriptor is write mode only */
- FD_APPEND = 0x0008, /* descriptor is append mode */
+ FD_WRITE = 0x0002, /* descriptor has write mode */
+ FD_WRONLY = 0x0004, /* descriptor is write mode only */
+ FD_APPEND = 0x0008, /* descriptor is append mode */
+ FD_NONEXIST = 0x8000, /* closed but not freed (uncombined) */
/* only used as common flags */
- FO_DIRECTORY = 0x0010, /* fileobj is a directory */
- FO_TRUNC = 0x0020, /* fileobj is opened to be truncated */
- FO_REMOVED = 0x0040, /* fileobj was deleted while open */
- FO_SINGLE = 0x0080, /* fileobj has only one stream open */
+ FO_DIRECTORY = 0x0010, /* fileobj is a directory */
+ FO_TRUNC = 0x0020, /* fileobj is opened to be truncated */
+ FO_REMOVED = 0x0040, /* fileobj was deleted while open */
+ FO_SINGLE = 0x0080, /* fileobj has only one stream open */
FDO_MASK = 0x00ff,
- /* bitflags that instruct various 'open' functions how to behave */
- FF_FILE = 0x0000, /* expect file; accept file only */
- FF_DIR = 0x0100, /* expect dir; accept dir only */
- FF_ANYTYPE = 0x0200, /* succeed if either file or dir */
- FF_TYPEMASK = 0x0300, /* mask of typeflags */
- FF_CREAT = 0x0400, /* create if file doesn't exist */
- FF_EXCL = 0x0800, /* fail if creating and file exists */
- FF_CHECKPREFIX = 0x1000, /* detect if file is prefix of path */
- FF_NOISO = 0x2000, /* do not decode ISO filenames to UTF-8 */
- FF_MASK = 0x3f00,
- /* special values used in isolation */
- FV_NONEXIST = 0x8000, /* closed but not freed (unmounted) */
- FV_OPENSYSROOT = 0xc001, /* open sysroot, volume 0 not mounted */
+ FDO_CHG_MASK = FO_TRUNC, /* fileobj permitted external change */
+ /* bitflags that instruct various 'open' functions how to behave;
+ * saved in stream flags (only) but not used by manager */
+ FF_FILE = 0x00000000, /* expect file; accept file only */
+ FF_DIR = 0x00010000, /* expect dir; accept dir only */
+ FF_ANYTYPE = 0x00020000, /* succeed if either file or dir */
+ FF_TYPEMASK = 0x00030000, /* mask of typeflags */
+ FF_CREAT = 0x00040000, /* create if file doesn't exist */
+ FF_EXCL = 0x00080000, /* fail if creating and file exists */
+ FF_CHECKPREFIX = 0x00100000, /* detect if file is prefix of path */
+ FF_NOISO = 0x00200000, /* do not decode ISO filenames to UTF-8 */
+ FF_PROBE = 0x00400000, /* only test existence; don't open */
+ FF_CACHEONLY = 0x00800000, /* succeed only if in dircache */
+ FF_SELFINFO = 0x01000000, /* return info on self as well */
+ FF_MASK = 0x01ff0000,
};
-
/** Common data structures used throughout **/
/* basic file information about its location */
@@ -183,8 +186,7 @@ struct dirscan_info
struct filestr_base
{
struct ll_node node; /* list item node (first!) */
- uint16_t flags; /* FD_* bits of this stream */
- uint16_t unused; /* not used */
+ uint32_t flags; /* F[DF]_* bits of this stream */
struct filestr_cache cache; /* stream-local cache */
struct filestr_cache *cachep; /* the cache in use (local or shared) */
struct file_base_info *infop; /* base file information */
@@ -235,17 +237,25 @@ static inline void filestr_unlock(struct filestr_base *stream)
#define FILESTR_UNLOCK(type, stream) \
({ if (FILESTR_##type) filestr_unlock(stream); })
-#define ATTR_PREFIX (0x8000) /* out of the way of all ATTR_* bits */
+/* auxilliary attributes - out of the way of regular ATTR_* bits */
+#define ATTR_SYSROOT (0x8000)
+#define ATTR_PREFIX (0x4000)
/* structure to return detailed information about what you opened */
struct path_component_info
{
- const char *name; /* pointer to name within 'path' */
+ const char *name; /* pointer to name within 'path' (OUT) */
size_t length; /* length of component within 'path' */
file_size_t filesize; /* size of the opened file (0 if dir) */
unsigned int attr; /* attributes of this component */
- struct file_base_info *prefixp; /* base info to check as prefix (IN) */
- struct file_base_info parentinfo; /* parent directory info of file */
+ struct file_base_info *prefixp; /* base info to check as prefix
+ (IN if FF_CHECKPREFIX) */
+ union {
+ struct file_base_info parentinfo; /* parent directory base info of file
+ (if not FF_SELFINFO) */
+ struct file_base_info info; /* base info of file itself
+ (if FF_SELFINFO) */
+ };
};
int open_stream_internal(const char *path, unsigned int callflags,
@@ -261,6 +271,7 @@ int remove_stream_internal(const char *path, struct filestr_base *stream,
int test_stream_exists_internal(const char *path, unsigned int callflags);
int open_noiso_internal(const char *path, int oflag); /* file.c */
+void force_close_writer_internal(struct filestr_base *stream); /* file.c */
struct dirent;
int uncached_readdir_dirent(struct filestr_base *stream,
@@ -326,22 +337,26 @@ static inline void file_internal_unlock_WRITER(void)
* not in the macro
*/
+#define FILE_SET_CODE(_name, _keepcode, _value) \
+ ({ __builtin_constant_p(_value) ? \
+ ({ if ((_value) != (_keepcode)) _name = (_value); }) : \
+ ({ _name = (_value); }); })
+
/* set errno and rc and proceed to the "file_error:" label */
#define FILE_ERROR(_errno, _rc) \
- ({ __builtin_constant_p(_errno) ? \
- ({ if ((_errno) != ERRNO) errno = (_errno); }) : \
- ({ errno = (_errno); }); \
- __builtin_constant_p(_rc) ? \
- ({ if ((_rc) != RC) rc = (_rc); }) : \
- ({ rc = (_rc); }); \
+ ({ FILE_SET_CODE(errno, ERRNO, (_errno)); \
+ FILE_SET_CODE(rc, RC, (_rc)); \
goto file_error; })
/* set errno and return a value at the point of invocation */
#define FILE_ERROR_RETURN(_errno, _rc...) \
- ({ __builtin_constant_p(_errno) ? \
- ({ if ((_errno) != ERRNO) errno = (_errno); }) : \
- ({ errno = (_errno); }); \
- return _rc; })
+ ({ FILE_SET_CODE(errno, ERRNO, _errno); \
+ return _rc; })
+
+/* set errno and return code, no branching */
+#define FILE_ERROR_SET(_errno, _rc) \
+ ({ FILE_SET_CODE(errno, ERRNO, (_errno)); \
+ FILE_SET_CODE(rc, RC, (_rc)); })
/** Misc. stuff **/
diff --git a/firmware/include/fileobj_mgr.h b/firmware/include/fileobj_mgr.h
index c90a59bea0..627d2df341 100644
--- a/firmware/include/fileobj_mgr.h
+++ b/firmware/include/fileobj_mgr.h
@@ -41,12 +41,11 @@ void fileobj_fileop_rename(struct filestr_base *stream,
void fileobj_fileop_remove(struct filestr_base *stream,
const struct file_base_info *oldinfop);
void fileobj_fileop_sync(struct filestr_base *stream);
-void fileobj_fileop_truncate(struct filestr_base *stream);
-extern void ftruncate_internal_callback(struct filestr_base *stream,
- struct filestr_base *s);
file_size_t * fileobj_get_sizep(const struct filestr_base *stream);
unsigned int fileobj_get_flags(const struct filestr_base *stream);
+struct filestr_base * fileobj_get_next_stream(const struct filestr_base *stream,
+ const struct filestr_base *s);
void fileobj_change_flags(struct filestr_base *stream,
unsigned int flags, unsigned int mask);
void fileobj_mgr_unmount(IF_MV_NONVOID(int volume));