summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Farrugia <mark.farrugia@fiberdyne.com.au>2018-10-31 13:39:39 +1100
committerMark Farrugia <mark.farrugia@fiberdyne.com.au>2018-10-31 13:39:39 +1100
commitc00f1a39706a208b73f9a4ae46c2db11fac0450c (patch)
tree0dfed5d02d7eb3221aef19bffc8b8f62cfbd275b
parent691f74d3bb6a06e56f895a5b844ad7dad297a860 (diff)
Add macro to check if configfs is mounted
We cannot configure AVIRT without configfs being mounted on the filesystem Signed-off-by: Mark Farrugia <mark.farrugia@fiberdyne.com.au>
-rw-r--r--src/avirt-config.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/avirt-config.c b/src/avirt-config.c
index e1b60b9..cbdd857 100644
--- a/src/avirt-config.c
+++ b/src/avirt-config.c
@@ -44,15 +44,30 @@
fprintf(stderr, "[%s]: AVIRT DEBUG: " fmt "\n", __func__, ##args);
#endif
-#define WRITE_TO_PATH(path, fmt, args...) \
- do { \
- FILE *fd = fopen(path, "w"); \
- if (!fd) { \
+/**
+ * Checks whether the configfs filesystem is mounted
+ */
+#define IS_CONFIGFS_MOUNTED() \
+ do { \
+ int err; \
+ if (!configfs_mounted) { \
+ err = mount_configfs(); \
+ if (err < 0) return err; \
+ } \
+ } while (0)
+
+/**
+ * Write the given formatted string to a file given by path
+ */
+#define WRITE_TO_PATH(path, fmt, args...) \
+ do { \
+ FILE *fd = fopen(path, "w"); \
+ if (!fd) { \
AVIRT_ERROR_V("Failed to open file at '%s'", path); \
- return -EPERM; \
- } \
- fprintf(fd, fmt, ##args); \
- fclose(fd); \
+ return -EPERM; \
+ } \
+ fprintf(fd, fmt, ##args); \
+ fclose(fd); \
} while (0)
static bool configfs_mounted = false;
@@ -108,13 +123,7 @@ int snd_avirt_stream_new(const char *name, unsigned int channels, int direction,
char path_attr[AVIRT_CONFIGFS_PATH_MAXLEN];
FILE *fd;
- // Check whether the configfs filesystem is mounted
- if (!configfs_mounted)
- {
- err = mount_configfs();
- if (err < 0)
- return err;
- }
+ IS_CONFIGFS_MOUNTED();
// Check if card is already sealed
if (card_sealed)
@@ -170,7 +179,6 @@ int snd_avirt_stream_new(const char *name, unsigned int channels, int direction,
int snd_avirt_card_seal()
{
- int err;
char path_sealed[AVIRT_CONFIGFS_PATH_MAXLEN];
FILE *fd;
@@ -181,12 +189,7 @@ int snd_avirt_card_seal()
return -EPERM;
}
- if (!configfs_mounted)
- {
- err = mount_configfs();
- if (err < 0)
- return err;
- }
+ IS_CONFIGFS_MOUNTED();
strcpy(path_sealed, AVIRT_CONFIGFS_PATH_STREAMS);
strcat(path_sealed, "/sealed");