Hi Franky,
On Thu, Aug 31, 2006, Frank Zschockelt wrote:
> * Keith Bennett <[EMAIL PROTECTED]> [060830 18:49]:
> > As discussed previously, this work should all be done in a separate
> > libkarma-1.0.0 branch. As far as I can tell, mercurial branches are
> > just separate copies of the repository. Would it be possible to
> > set one up, please?
>
> Sure.
> http://www.freakysoft.de/repos/libkarma-1.0
Thanks for that. I'll start work when I get back.
I've just noticed that I managed to mess up the last patch. That's
what happens when you try to submit too many things at the same time.
I've attached a patch which fixes it.
There is also an updated rids patch to account for these changes. As
before, this should wait until EV gives the go-ahead before applying.
Thanks,
Keith.
# HG changeset patch
# User Keith Bennett <[EMAIL PROTECTED]>
# Node ID bf5a91c59d96c2333f543873d621bae7b7dddac9
# Parent d53799c131b5afaae7866cd52d7d2ad39ff4e776
Fixed errors introduced by previous patch.
diff -r d53799c131b5 -r bf5a91c59d96 src/karma.c
--- a/src/karma.c Wed Aug 30 15:26:36 2006 +0100
+++ b/src/karma.c Fri Sep 1 12:23:11 2006 +0100
@@ -8,6 +8,9 @@
* the GNU GPL, version 2 or later.
*
*/
+
+#include <stdlib.h>
+#include <string.h>
#include "lkarma.h"
#include "karma.h"
diff -r d53799c131b5 -r bf5a91c59d96 src/lkarma.h
--- a/src/lkarma.h Wed Aug 30 15:26:36 2006 +0100
+++ b/src/lkarma.h Fri Sep 1 12:23:11 2006 +0100
@@ -190,7 +190,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);
+int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname);
/*
# 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);
-------------------------------------------------------------------------
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