From 8a729f8dc2796b6f6b8e38b7e7377f50e2ed6a2d Mon Sep 17 00:00:00 2001 From: Mark Farrugia Date: Thu, 11 Oct 2018 12:35:30 +1100 Subject: Numerous improvements Add additional card_sealed checks, format braces, add comments Signed-off-by: Mark Farrugia --- src/avirt-config.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/avirt-config.c b/src/avirt-config.c index 5056da8..167bcc2 100644 --- a/src/avirt-config.c +++ b/src/avirt-config.c @@ -81,12 +81,22 @@ int AVIRT_CreateStream(const char *name, unsigned int channels, int direction) char path_chans[AVIRT_CONFIGFS_PATH_MAXLEN]; FILE *fd; - if (!configfs_mounted) { + // Check whether the configfs filesystem is mounted + if (!configfs_mounted) + { err = mount_configfs(); if (err < 0) return err; } + // Check if card is already sealed + if (card_sealed) + { + AVIRT_ERROR("Card is already sealed!"); + return -EPERM; + } + + // This indicates to AVIRT the direction of the stream strcpy(path, AVIRT_CONFIGFS_PATH_STREAMS); switch (direction) { case SND_PCM_STREAM_PLAYBACK: @@ -113,6 +123,7 @@ int AVIRT_CreateStream(const char *name, unsigned int channels, int direction) return err; } + // Open file and write to it strcpy(path_chans, path); strcat(path_chans, "/channels"); fd = fopen(path_chans, "w"); @@ -134,13 +145,15 @@ int AVIRT_SealCard() char path_sealed[AVIRT_CONFIGFS_PATH_MAXLEN]; FILE *fd; + // Check if card is already sealed if (card_sealed) { AVIRT_ERROR("Card is already sealed!"); - return -1; + return -EPERM; } - if (!configfs_mounted) { + if (!configfs_mounted) + { err = mount_configfs(); if (err < 0) return err; -- cgit 1.2.3-korg