Hi, I am resending below a message I sent last Suterday but for
some reason did reach the linux-karma list. Best, EV.

---------- Forwarded message ----------
Date: Sun, 3 Sep 2006 00:45:30 +0200 (CEST)
From: EV <[EMAIL PROTECTED]>
To: Frank Zschockelt <[EMAIL PROTECTED]>,
  Keith Bennett <[EMAIL PROTECTED]>
Cc: [email protected], EV <[EMAIL PROTECTED]>
Subject: Re: [linux-karma-devel] Upcoming lkarmafs-lkarmafs-0.1.9

2006-09-02: EV dixit:
[...]
2006-08-30: Keith Bennett dixit:
> [...]
> Note to Franky: you should probably hold off on applying this
> patch until EV gives the go-ahead. If libkarma has changed by
> then, I will post a new version.

I'll make some tests this evening and I'll let you know.

Hi Franky,

Keith's libkarma rids-libkarma-hg113.patch looks good to me (more tests still
pending).  It can be applied cleanly on top of the current HG tip (Changeset
114).

As mentioned some time ago, I find the error reported by fdb.c

/* E_NOPROP    21 */ "Libkarma warning: missing fid properties"

quite confusing, because E_NOPROP refers to missing /fids0/*/??1 files (USB
interface).  So I've added a new error to lkarma.h and errors.c (and used it
in fdb.c):

/* E_NOPATHPR  39 */ "* Libkarma warning: missing path properties"

I've also changed the string of E_NOPROP to:

/* E_NOPROP    21 */ "* Libkarma warning: missing properties file"

I attach a small patch (lk005-hg116.patch) with these changes.  So the
application order should be:

hg114 -> rids-libkarma-hg113.patch -> hg115
hg115 -> lk005-hg116.patch -> hg116

Best,
EV.
# HG changeset patch
# User Keith Bennett <[EMAIL PROTECTED]>
# Node ID 4b2368a8fd29fd06fb244329f63b2b060c092e45
# Parent  bf5a91c59d96c2333f543873d621bae7b7dddac9
Added support for calculating rids correctly in lkarmafs.

diff -r bf5a91c59d96 -r 4b2368a8fd29 src/errors.c
--- a/src/errors.c      Fri Sep  1 12:23:11 2006 +0100
+++ b/src/errors.c      Fri Sep  1 12:26:54 2006 +0100
@@ -54,7 +54,9 @@
     /* E_UNSUPTAG  35 */ "* Libkarma warning: unsupported tag type",
     /* E_NOTAGFILE 36 */ "* Libkarma warning: can't access tags file",
     /* E_BADFDB    37 */ "* Libkarma warning: unrecognised fdb file",
-    /* E_UNSUPFDB  38 */ "* Libkarma warning: unsupported fdb file"
+    /* E_UNSUPFDB  38 */ "* Libkarma warning: unsupported fdb file",
+    /* E_NOTMPDIR  39 */ "* Libkarma warning: no temporary directory found",
+    /* E_TMPCREAT  40 */ "** Libkarma error: can't create temporary tag file"
 };
 
 #define libkarmaErrorString lkerrorList[libkarmaError]
diff -r bf5a91c59d96 -r 4b2368a8fd29 src/karma.c
--- a/src/karma.c       Fri Sep  1 12:23:11 2006 +0100
+++ b/src/karma.c       Fri Sep  1 12:26:54 2006 +0100
@@ -9,6 +9,10 @@
  *
  */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -18,6 +22,9 @@
 #include "karmaUsb.h"
 #include "properties.h"
 #include "fdb.h"
+
+int using_usb = 0;
+char *karma_tmpdir = NULL;
 
 #ifdef __USE_ISOC99
 #define set_usb_ptr(x) .lk_karma_ ##x = lk_karmaUsb_ ##x
@@ -114,14 +121,43 @@
 
 /* -------------------------------------------------------------------------- 
*/
 /* Basic Protocol Functions */
+static int lk_karma_find_tmpdir(void)
+{
+    int fd;
+    char path[32];
+
+    memcpy(path, "/dev/shm/lkarmaXXXXXX", 22);
+    fd = mkstemp(path);
+    if (fd != -1) {
+        close(fd);
+        unlink(path);
+        karma_tmpdir = strdup("/dev/shm/");
+        return 0;
+    }
+    memcpy(path, "/tmp/lkarmaXXXXXX", 19);
+    fd = mkstemp(path);
+    if (fd != -1) {
+        close(fd);
+        unlink(path);
+        karma_tmpdir = strdup("/tmp/");
+        return 0;
+    }
+    lk_errors_set(E_NOTMPDIR);
+    return 1;
+}
+
 int lk_karma_connect(char *ipHostOrPath)
 {
-    int using_usb = (ipHostOrPath[0] == '/');
     int rio;
+    using_usb = (ipHostOrPath[0] == '/');
     lk_ops = using_usb ? &usb_ops : &lan_ops;
 
     rio = lk_ops->lk_karma_connect(ipHostOrPath);
     lk_fdb_set_device(rio);
+
+    if (rio >= 0 && using_usb == 0 && karma_tmpdir == NULL)
+        lk_karma_find_tmpdir();
+
     return rio;
 }
 
diff -r bf5a91c59d96 -r 4b2368a8fd29 src/karma.h
--- a/src/karma.h       Fri Sep  1 12:23:11 2006 +0100
+++ b/src/karma.h       Fri Sep  1 12:26:54 2006 +0100
@@ -12,6 +12,9 @@
 #define _KARMA_H
 
 #include <inttypes.h>
+
+extern int using_usb;
+extern char *karma_tmpdir;
 
 char *   lk_karma_fidToPath              (int rio, uint32_t file_id);
 
diff -r bf5a91c59d96 -r 4b2368a8fd29 src/lkarma.h
--- a/src/lkarma.h      Fri Sep  1 12:23:11 2006 +0100
+++ b/src/lkarma.h      Fri Sep  1 12:26:54 2006 +0100
@@ -152,8 +152,10 @@
 #define E_NOTAGFILE 36  /* warning: can't access tags file    */  /* RIO_RW */
 #define E_BADFDB    37  /* warning: unrecognised fdb file     */  /* FDB    */
 #define E_UNSUPFDB  38  /* warning: unsupported fdb file      */  /* FDB    */
-
-#define MAXLKERRORS 38
+#define E_NOTMPDIR  39  /* warning: no temporary directory found   */
+#define E_TMPCREAT  40  /* error: can't create temporary tag file  */
+
+#define MAXLKERRORS 40
 
 
 /*
@@ -190,7 +192,7 @@
 int lk_synchronize_necessary(int rio);
 uint32_t lk_rio_write(int rio, const char * filename);
 void lk_karma_write_dupes(int set);
-int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname);
+int lk_rio_update_props_from_tags(int rio, uint32_t fid);
 
 
 /*
diff -r bf5a91c59d96 -r 4b2368a8fd29 src/rio_rw.c
--- a/src/rio_rw.c      Fri Sep  1 12:23:11 2006 +0100
+++ b/src/rio_rw.c      Fri Sep  1 12:26:54 2006 +0100
@@ -125,60 +125,31 @@
     return 0;
 }
 
-int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
-{
-    int got=-1, usb=0;
+static int lk_rio_do_update_props_from_tags(int rio, uint32_t fid,
+                                            const char *filename)
+{
+    int got=-1;
     struct stat len;
     HASH * props;
     mp3info mp3;
-    char *rid, *filename;
+    char *rid;
     int type, rid_fd;
 /** uint32_t *fids; **/
 
-    if (fname == NULL) {
-        filename = lk_karma_fidToPath(rio, fid);
-        usb = 1;
-    } else
-        filename = (char *)fname;
-
-    if(lstat(filename, &len)==-1) {
-        if (usb) {
-            unlink(filename);
-            free(filename);
-        }
+    if(lstat(filename, &len)==-1)
         return -1;
-    }
 
     memset(&mp3, 0, sizeof(mp3info));
-    mp3.filename = filename;
+    mp3.filename = (char *)filename;
     type = get_file_type(&mp3);
 
     rid_fd = open(filename, O_RDONLY);
     rid = (char*)lk_generate_rid(rid_fd, mp3.offset, mp3.datasize);
     close(rid_fd);
 
-/* This doesn't belong to update_props_from_tags: moved to lk_rio_do_write() */
-/** if (write_dupes == 0 && fdb == 0) {
-        fids = lk_properties_andOrSearch(EXACT|ORS, NULL, "rid", rid);
-
-        if (fids != NULL) {
-            if (usb) {
-                unlink(filename);
-                free(filename);
-            }
-            free(fids);
-            lk_errors_set(E_DUPE);
-            return -1;
-        }
-    } **/
-
     /* uses lk_properties_getnextfid()...*/
     props=lk_properties_idsearch(fid);
     if(props==NULL){
-        if (usb) {
-            unlink(filename);
-            free(filename);
-        }
         lk_errors_set(E_NOHASH);
 /*      printf("huh, no hash found?\n"); */
         return -1;
@@ -202,17 +173,130 @@
     else
         got=get_taxi_props(props);
 
-    if (usb)
-        free(filename);
-
     return got;
 }
 
-/** No longer needed !! **/
-/** int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
-{
-    return lk_rio_do_update_props_from_tags(0, rio, fid, fname);
-} **/
+/*
+ * Create a temporary file containing the head, tail and middle 64k
+ * of data needed for finding the tags and rid.
+ */
+static char *lk_rio_create_temp_file(int rio, uint32_t fid)
+{
+#define RID_BLOCKS 65536
+    int fd, ret;
+    int64_t len;
+    uint64_t blk, got, off, length;
+    char *filename = NULL, *tmp;
+    mp3info mp3;
+
+    tmp = lk_properties_get_property(fid, "length");
+    if (tmp == NULL)
+        goto err;
+
+    length = strtoull(tmp, NULL, 10);
+
+    /* 4k should be enough for the header in most cases */
+    blk = RID_BLOCKS + 4096;
+    off = 0;
+    ret = lk_karma_read_file_chunk(rio, off, blk, fid, &tmp, &got);
+    if (ret != 0 || got != blk)
+        goto err;
+
+    len = strlen(karma_tmpdir) + strlen(simple_itoa(fid)) + 8;
+    filename = malloc(len);
+    snprintf(filename, len, "%s/lkarma%d", karma_tmpdir, fid);
+
+    fd = open(filename, O_WRONLY|O_CREAT|O_EXCL, 0600);
+    if (fd == -1)
+        goto err;
+
+    ret = write(fd, tmp, got);
+    free(tmp);
+    close(fd);
+
+    memset(&mp3, 0, sizeof(mp3));
+    mp3.filename = filename;
+    get_file_type(&mp3);
+
+    fd = open(filename, O_WRONLY);
+
+    /* read the rest of the header if 4k wasnt enough */
+    len = mp3.offset + RID_BLOCKS - blk;
+    if (len > 0) {
+        off = blk;
+        blk = len;
+        ret = lk_karma_read_file_chunk(rio, off, blk, fid, &tmp, &got);
+        if (ret != 0 || got != blk)
+            goto err;
+        ret = lseek(fd, off, SEEK_SET);
+        ret = write(fd, tmp, got);
+        free(tmp);
+    }
+
+    /* tail */
+    blk = RID_BLOCKS + 128;
+    off = length - blk;
+    ret = lk_karma_read_file_chunk(rio, off, blk, fid, &tmp, &got);
+    if (ret != 0 || got != blk)
+        goto err;
+
+    ret = lseek(fd, (mp3.offset + 2*RID_BLOCKS), SEEK_SET);
+    if (memcmp(tmp+got-128, "TAG", 3) == 0) {
+        ret = write(fd, tmp, got);
+        length -= 128;
+    } else
+        ret = write(fd, tmp+128, got-128);
+    free(tmp);
+
+    /* middle 64k */
+    blk = RID_BLOCKS;
+    off = (mp3.offset + length - RID_BLOCKS)/2;
+    ret = lk_karma_read_file_chunk(rio, off, blk, fid, &tmp, &got);
+    if (ret != 0 || got != blk)
+        goto err;
+    ret = lseek(fd, (mp3.offset + RID_BLOCKS), SEEK_SET);
+    ret = write(fd, tmp, got);
+    free(tmp);
+
+    close(fd);
+
+    mp3.datasize = mp3.offset + 3*RID_BLOCKS;
+
+    return filename;
+
+  err:
+    if (filename) {
+        close(fd);
+        unlink(filename);
+    }
+    if (tmp)
+        free(tmp);
+    lk_errors_set(E_TMPCREAT);
+    return NULL;
+}
+
+int lk_rio_update_props_from_tags(int rio, uint32_t fid)
+{
+    int ret;
+    char *filename;
+
+    if (using_usb)
+        filename = lk_karma_fidToPath(rio, fid);
+    else
+        filename = lk_rio_create_temp_file(rio, fid);
+
+    if (!filename)
+        return -1;
+
+    ret = lk_rio_do_update_props_from_tags(rio, fid, filename);
+
+    if (using_usb == 0 || ret)
+        unlink(filename);
+
+    free(filename);
+
+    return ret;
+}
 
 /*
      To use that function properly:
@@ -248,7 +332,7 @@
     if (!fid)
         fid = lk_properties_new_property(); 
 
-    got = lk_rio_update_props_from_tags(rio, fid, filename);
+    got = lk_rio_do_update_props_from_tags(rio, fid, filename);
     if (got != 0) {
         lk_properties_del_property(fid);
         close(fd);
# HG changeset patch
# User [EMAIL PROTECTED]
# Node ID 55504467ace5be77c808c9174911e42af4bfb36e
# Parent  bfa5c6fb3448bcdcfc5b44dcfe0ae133d263bfff
Added an error for fdb.c and changed the string of E_NOPROP

diff -r bfa5c6fb3448 -r 55504467ace5 ChangeLog
--- a/ChangeLog Sat Sep  2 22:09:41 2006
+++ b/ChangeLog Sat Sep  2 22:36:09 2006
@@ -1,4 +1,7 @@
 0.0.6:
+       * Added support for calculating rids correctly in lkarmafs
+       * Changed sorting tracks by artist to match "Rescan music" functionality
+       * Changed device settings: don't use properties not held in smalldb
         * Re-implemented fdb support and made it functional
         * Fixed rio_rw error handling and several other bugs
         * Added lk_rio_update_props_from_tags() to help lkarmafs file upload
diff -r bfa5c6fb3448 -r 55504467ace5 src/errors.c
--- a/src/errors.c      Sat Sep  2 22:09:41 2006
+++ b/src/errors.c      Sat Sep  2 22:36:09 2006
@@ -37,7 +37,7 @@
     /* E_MKDIR     18 */ "** Libkarma error: mkdir() failed",
     /* E_UTIME     19 */ "** Libkarma error: utime() failed",
     /* E_NODIR     20 */ "** Libkarma error: unexisting directory",
-    /* E_NOPROP    21 */ "* Libkarma warning: missing fid properties",
+    /* E_NOPROP    21 */ "* Libkarma warning: missing properties file",
     /* E_READ      22 */ "* Libkarma warning: read error",
     /* E_WRITE     23 */ "** Libkarma error: write error",
     /* E_DELETE    24 */ "** Libkarma error: delete error",
@@ -55,8 +55,9 @@
     /* E_NOTAGFILE 36 */ "* Libkarma warning: can't access tags file",
     /* E_BADFDB    37 */ "* Libkarma warning: unrecognised fdb file",
     /* E_UNSUPFDB  38 */ "* Libkarma warning: unsupported fdb file",
-    /* E_NOTMPDIR  39 */ "* Libkarma warning: no temporary directory found",
-    /* E_TMPCREAT  40 */ "** Libkarma error: can't create temporary tag file"
+    /* E_NOPATHPR  39 */ "* Libkarma warning: missing path properties",
+    /* E_NOTMPDIR  40 */ "* Libkarma warning: no temporary directory found",
+    /* E_TMPCREAT  41 */ "** Libkarma error: can't create temporary tag file"
 };
 
 #define libkarmaErrorString lkerrorList[libkarmaError]
diff -r bfa5c6fb3448 -r 55504467ace5 src/fdb.c
--- a/src/fdb.c Sat Sep  2 22:09:41 2006
+++ b/src/fdb.c Sat Sep  2 22:36:09 2006
@@ -220,7 +220,7 @@
                             continue;
                     }
 
-                    lk_errors_set(E_NOPROP);
+                    lk_errors_set(E_NOPATHPR);
                     first = 0;
                 }
                 continue;
diff -r bfa5c6fb3448 -r 55504467ace5 src/lkarma.h
--- a/src/lkarma.h      Sat Sep  2 22:09:41 2006
+++ b/src/lkarma.h      Sat Sep  2 22:36:09 2006
@@ -132,7 +132,7 @@
 #define E_UTIME     19  /* error:   utime() failed            */  /* Sys */
 
 #define E_NODIR     20  /* error:   unexisting directory      */  /* USB */
-#define E_NOPROP    21  /* warning: missing prop file         */  /* USB */
+#define E_NOPROP    21  /* warning: missing properties file   */  /* USB */
 #define E_READ      22  /* error:   read error                */  /* USB */
 #define E_WRITE     23  /* error:   write error               */  /* USB */
 #define E_DELETE    24  /* warning: delete error              */  /* USB */
@@ -150,12 +150,15 @@
 #define E_SMALLMP3  34  /* error:   tune file is too small    */  /* RIO_RW */
 #define E_UNSUPTAG  35  /* warning: unsupported tag type      */  /* RIO_RW */
 #define E_NOTAGFILE 36  /* warning: can't access tags file    */  /* RIO_RW */
-#define E_BADFDB    37  /* warning: unrecognised fdb file     */  /* FDB    */
-#define E_UNSUPFDB  38  /* warning: unsupported fdb file      */  /* FDB    */
-#define E_NOTMPDIR  39  /* warning: no temporary directory found   */
-#define E_TMPCREAT  40  /* error: can't create temporary tag file  */
-
-#define MAXLKERRORS 40
+
+#define E_BADFDB    37  /* warning: unrecognised fdb file     */  /* FDB */
+#define E_UNSUPFDB  38  /* warning: unsupported fdb file      */  /* FDB */
+#define E_NOPATHPR  39  /* warning: missing path properties   */  /* FDB */
+
+#define E_NOTMPDIR  40  /* warning: no temporary directory found  */
+#define E_TMPCREAT  41  /* error: can't create temporary tag file */
+
+#define MAXLKERRORS 41
 
 
 /*
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-karma-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-karma-devel

Reply via email to