[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 06/11] iso9660: Implement .fs_probe



Cc: cdi-devel@xxxxxxxxxx
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/cdi/iso9660/init.c        | 25 +++++++++++++++++++++++++
 src/modules/cdi/iso9660/iso9660_cdi.h |  1 +
 src/modules/cdi/iso9660/main.c        |  1 +
 3 files changed, 27 insertions(+)

diff --git a/src/modules/cdi/iso9660/init.c b/src/modules/cdi/iso9660/init.c
index 641d4f3..f2e8a0d 100644
--- a/src/modules/cdi/iso9660/init.c
+++ b/src/modules/cdi/iso9660/init.c
@@ -17,6 +17,7 @@
 */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "cdi/fs.h"
 #include "cdi/cache.h"
@@ -25,6 +26,30 @@
 
 #include "volume_descriptor.h"
 
+int iso9660_fs_probe(struct cdi_fs_filesystem* cdi_fs, char** volname)
+{
+    struct iso9660_voldesc_prim voldesc;
+    size_t len;
+    int ret;
+
+    ret = iso9660_voldesc_load(cdi_fs, ISO9660_VOLDESC_PRIM, &voldesc);
+    if (ret != 0) {
+        return 0;
+    }
+
+    len = sizeof(voldesc.volume_identifier);
+    *volname = malloc(len + 1);
+    memcpy(*volname, voldesc.volume_identifier, len);
+    (*volname)[len] = '\0';
+
+    /* Remove padding */
+    while (--len && (*volname)[len] == ' ') {
+        (*volname)[len] = '\0';
+    }
+
+    return 1;
+}
+
 /**
  * Initializes a ISO9660 filesystem
  *  @param fs Filesystem to initialize
diff --git a/src/modules/cdi/iso9660/iso9660_cdi.h b/src/modules/cdi/iso9660/iso9660_cdi.h
index 25a4a14..483d506 100644
--- a/src/modules/cdi/iso9660/iso9660_cdi.h
+++ b/src/modules/cdi/iso9660/iso9660_cdi.h
@@ -59,6 +59,7 @@ struct iso9660_fs_res {
 };
 
 // init.c
+int iso9660_fs_probe(struct cdi_fs_filesystem* cdi_fs, char** volname);
 int iso9660_fs_init(struct cdi_fs_filesystem *fs);
 int iso9660_fs_destroy(struct cdi_fs_filesystem *fs);
 
diff --git a/src/modules/cdi/iso9660/main.c b/src/modules/cdi/iso9660/main.c
index 1e81779..56930d0 100644
--- a/src/modules/cdi/iso9660/main.c
+++ b/src/modules/cdi/iso9660/main.c
@@ -76,6 +76,7 @@ static struct cdi_fs_driver iso9660_driver = {
     },
     .fs_init            = iso9660_fs_init,
     .fs_destroy         = iso9660_fs_destroy,
+    .fs_probe           = iso9660_fs_probe,
 };
 
 CDI_DRIVER(DRIVER_NAME, iso9660_driver)
-- 
2.1.4