Keep the audio file open when mmapping.
authorAndre Noll <maan@systemlinux.org>
Sun, 29 Jun 2008 13:06:48 +0000 (15:06 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 29 Jun 2008 13:06:48 +0000 (15:06 +0200)
libid3tag needs an open fd. So call () with a
non-NULL pointer which results in the file still being open
after mmap_full_file() returns. Pass the file descriptor
to compute_afhi() and to get_file_info() so that libid3tag
can use it.

aac_afh.c
afh.c
afh.h
afh_common.c
aft.c
mp3_afh.c
ogg_afh.c

index fa09accb496c28bf822483e603d29294a29598cf..a4166d1aeedd2b2cf761b7b81180860a9eac781f 100644 (file)
--- a/aac_afh.c
+++ b/aac_afh.c
@@ -92,7 +92,7 @@ static int aac_set_chunk_tv(struct afh_info *afhi,
 /*
  * Init m4a file and write some tech data to given pointers.
  */
-static int aac_get_file_info(char *map, size_t numbytes,
+static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd,
                struct afh_info *afhi)
 {
        int i;
diff --git a/afh.c b/afh.c
index 4c5ddae51499984c02da75ae2898517c5d6e24fe..454517f40601e8e19421ed993e17b16a57ae900f 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -122,7 +122,7 @@ static int cat_file(void *audio_file_data, struct afh_info *afhi)
 
 int main(int argc, char **argv)
 {
-       int ret, audio_format_num;
+       int ret, audio_format_num, fd;
        void *audio_file_data;
        size_t audio_file_size;
        struct afh_info afhi;
@@ -134,10 +134,11 @@ int main(int argc, char **argv)
                goto out;
        afh_init();
        ret = mmap_full_file(conf.inputs[0], O_RDONLY, &audio_file_data,
-               &audio_file_size, NULL);
+               &audio_file_size, &fd);
        if (ret < 0)
                goto out;
-       ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size, &afhi);
+       ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size,
+               fd, &afhi);
        if (ret < 0)
                goto out;
        audio_format_num = ret;
diff --git a/afh.h b/afh.h
index 66adfd61c2006a86ea1d1e0fa79f8e11080fe140..fbc0ba6f2bc5089b0e6f254dee042794aeec7f4c 100644 (file)
--- a/afh.h
+++ b/afh.h
@@ -91,14 +91,14 @@ struct audio_format_handler {
         *
         * \sa struct afh_info
         */
-       int (*get_file_info)(char *map, size_t numbytes,
+       int (*get_file_info)(char *map, size_t numbytes, int fd,
                struct afh_info *afi);
 };
 
 void afh_init(void);
 int guess_audio_format(const char *name);
 int compute_afhi(const char *path, char *data, size_t size,
-       struct afh_info *afhi);
+       int fd, struct afh_info *afhi);
 const char *audio_format_name(int);
 void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
                void *map, const char **buf, size_t *len);
index f57ca89fb4b4afc8d7387269d97c0dd1630fddd5..6f6e832484f1c7f2021885e9b2cab144789da27f 100644 (file)
@@ -128,6 +128,7 @@ int guess_audio_format(const char *name)
  * \param path The full path of the audio file.
  * \param data Pointer to the contents of the (mapped) file.
  * \param size The file size in bytes.
+ * \param fd The open file descriptor.
  * \param afhi Result pointer.
  *
  * \return The number of the audio format on success, \p -E_AUDIO_FORMAT if no
@@ -140,7 +141,7 @@ int guess_audio_format(const char *name)
  * path. If this doesn't work, all other audio format handlers are tried until
  * one is found that can handle the file.
  */
-int compute_afhi(const char *path, char *data, size_t size,
+int compute_afhi(const char *path, char *data, size_t size, int fd,
                struct afh_info *afhi)
 {
        int ret, i, format;
@@ -150,14 +151,14 @@ int compute_afhi(const char *path, char *data, size_t size,
        format = guess_audio_format(path);
 
        if (format >= 0) {
-               ret = afl[format].get_file_info(data, size, afhi);
+               ret = afl[format].get_file_info(data, size, fd, afhi);
                if (ret >= 0)
                        return format;
        }
        FOR_EACH_AUDIO_FORMAT(i) {
                if (i == format) /* we already tried this one to no avail */
                        continue;
-               ret = afl[i].get_file_info(data, size, afhi);
+               ret = afl[i].get_file_info(data, size, fd, afhi);
                if (ret >= 0)
                        return i;
                PARA_WARNING_LOG("%s\n", para_strerror(-ret));
diff --git a/aft.c b/aft.c
index 5bedc9281b4f23872ac329e01cce16452d786cc3..3d10ced25949d61e370eae617950dd7ff316b7e6 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1740,7 +1740,7 @@ static int get_row_pointer_from_result(struct osl_object *result, void *private)
 
 static int add_one_audio_file(const char *path, void *private_data)
 {
-       int ret, send_ret = 1;
+       int ret, send_ret = 1, fd;
        uint8_t format_num = -1;
        struct private_add_data *pad = private_data;
        struct afh_info afhi, *afhi_ptr = NULL;
@@ -1764,7 +1764,7 @@ static int add_one_audio_file(const char *path, void *private_data)
                goto out_free;
        }
        /* We still want to add this file. Compute its hash. */
-       ret = mmap_full_file(path, O_RDONLY, &map.data, &map.size, NULL);
+       ret = mmap_full_file(path, O_RDONLY, &map.data, &map.size, &fd);
        if (ret < 0)
                goto out_free;
        hash_function(map.data, map.size, hash);
@@ -1789,7 +1789,7 @@ static int add_one_audio_file(const char *path, void *private_data)
         * there is a hash sister and FORCE was not given.
         */
        if (!hs || (pad->flags & ADD_FLAG_FORCE)) {
-               ret = compute_afhi(path, map.data, map.size, &afhi);
+               ret = compute_afhi(path, map.data, map.size, fd, &afhi);
                if (ret < 0)
                        goto out_unmap;
                format_num = ret;
@@ -1807,6 +1807,7 @@ static int add_one_audio_file(const char *path, void *private_data)
        goto out_free;
 
 out_unmap:
+       close(fd);
        munmap(map.data, map.size);
 out_free:
        if (ret < 0 && send_ret >= 0)
index 927620748d19c0c0949d8e596aa2e4ca34ba6b98..f3f95d486daff1799d23d390557d68775a7135c7 100644 (file)
--- a/mp3_afh.c
+++ b/mp3_afh.c
@@ -373,7 +373,7 @@ err_out:
 /*
  * Read mp3 information from audio file
  */
-static int mp3_get_file_info(char *map, size_t numbytes,
+static int mp3_get_file_info(char *map, size_t numbytes, int fd,
                struct afh_info *afhi)
 {
        int ret;
index b57e0bddc55bc4ef623387e9c2c1bb15a2d7a443..2b934ddd1de9438039cee7990101ad6064e8e5b0 100644 (file)
--- a/ogg_afh.c
+++ b/ogg_afh.c
@@ -238,7 +238,7 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of,
 /*
  * Init oggvorbis file and write some tech data to given pointers.
  */
-static int ogg_get_file_info(char *map, size_t numbytes,
+static int ogg_get_file_info(char *map, size_t numbytes, __a_unused int fd,
                struct afh_info *afhi)
 {
        int ret;