[libbluray-devel] Split udfread_file_lba()

Petri Hintukainen git at videolan.org
Tue Jun 21 22:32:02 CEST 2016


libudfread | branch: master | Petri Hintukainen <phintuka at gmail.com> | Sat Jun 18 15:49:21 2016 +0300| [d2a977a9c4aee383a067802d3cbb101574a62579] | committer: Petri Hintukainen

Split udfread_file_lba()

> http://git.videolan.org/gitweb.cgi/libudfread.git/?a=commit;h=d2a977a9c4aee383a067802d3cbb101574a62579
---

 src/udfread.c |   41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/udfread.c b/src/udfread.c
index 4f4cb2c..73947d7 100644
--- a/src/udfread.c
+++ b/src/udfread.c
@@ -1339,21 +1339,13 @@ void udfread_file_close(UDFFILE *p)
  * block access
  */
 
-uint32_t udfread_file_lba(UDFFILE *p, uint32_t file_block)
+static uint32_t _file_lba(UDFFILE *p, uint32_t file_block)
 {
     const struct file_entry *fe;
     unsigned int i;
     uint32_t     ad_size;
 
-    if (!p) {
-        return 0;
-    }
-
     fe = p->fe;
-    if (fe->content_inline) {
-        udf_error("can't map lba for inline file\n");
-        return 0;
-    }
 
     for (i = 0; i < fe->num_ad; i++) {
         const struct long_ad *ad = &fe->data.ad[0];
@@ -1384,16 +1376,43 @@ uint32_t udfread_file_lba(UDFFILE *p, uint32_t file_block)
     return 0;
 }
 
+static int _file_lba_exists(UDFFILE *p)
+{
+    if (!p) {
+        return 0;
+    }
+
+    if (p->fe->content_inline) {
+        udf_error("can't map lba for inline file\n");
+        return 0;
+    }
+
+    return 1;
+}
+
+uint32_t udfread_file_lba(UDFFILE *p, uint32_t file_block)
+{
+    if (!_file_lba_exists(p)) {
+        return 0;
+    }
+
+    return _file_lba(p, file_block);
+}
+
 uint32_t udfread_read_blocks(UDFFILE *p, void *buf, uint32_t file_block, uint32_t num_blocks, int flags)
 {
     uint32_t i;
 
-    if (!p || !num_blocks || !buf) {
+    if (!num_blocks || !buf) {
+        return 0;
+    }
+
+    if (!_file_lba_exists(p)) {
         return 0;
     }
 
     for (i = 0; i < num_blocks; i++) {
-        uint32_t lba = udfread_file_lba(p, file_block + i);
+        uint32_t lba = _file_lba(p, file_block + i);
         uint8_t *block = (uint8_t *)buf + UDF_BLOCK_SIZE * i;
         udf_trace("map block %u to lba %u\n", file_block + i, lba);
         if (!lba) {



More information about the libbluray-devel mailing list