On Mon, Aug 14, 2006, EV wrote:
> > I already implemented this at the weekend. I haven't submitted
> > anything yet because I didn't know what you wanted to do about
> > ethernet files. The easiest and most reliable method would be
> > to create temporary files but I didn't know if you were happy
> > to settle for the extra overhead. I'll post some code this
> > evening.
>
> O.K. I wait for it, thanks. The patch is only for libkarma? or
> also for lkarmafs?
Here are the two patches.
I was going to implement the temporary file stuff for ethernet this
evening but was suprised to find that the fuse_file_info structure
doesn't have an entry for filesystem-specific data. I guess that
the filehandle could be pressed into action, but I'll leave it a
few days in case you find a better way from within FUSE.
Keith.
diff -ur lkarmafs-0.1.8.orig/lkarmafs.c lkarmafs-0.1.8/lkarmafs.c
--- lkarmafs-0.1.8.orig/lkarmafs.c 2006-08-01 20:10:00.000000000 +0100
+++ lkarmafs-0.1.8/lkarmafs.c 2006-08-14 20:32:02.000000000 +0100
@@ -70,6 +70,7 @@
static int writeNoTaxi=0; /* allow write under tune/ and playlist/
*/
static char *UnkName=UNK_NAME; /* Dummy name for missing properties
*/
static int writeSmalldb=1;
+static int isUsb=0;
static char *editPathStr1=NULL;
static char *editPathStr2=NULL;
@@ -916,6 +917,7 @@
uint32_t fid;
int res=0, timeout=0;
char *aux=NULL;
+ pathElementsType P;
FPRINTF(stderr, "==> FLUSH: %s %d %x\n",
path, (int)fi->fh & 0x7FFFFFFF, fi->flags);
(void) path;
@@ -930,12 +932,23 @@
}
if(fid > 255) { /* close WRITE open
*/
res = setProp(fid, "ctime", simple_itoa(time(NULL)));
+ if(res) return -EPROTO;
if((timeout = waitForIOlock())) return timeout;
- aux = lk_properties_export(fid);
- res += lk_karma_update_file_details(karma, fid, aux);
+ res = lk_rio_get_properties(karma, fid, NULL);
+ if(res) {
+ releaseIOlock();
+ return -EPROTO;
+ }
+ P = parsePath(path);
+ setPropCS (fid, "genre", P.genre);
+ setPropTRCS(fid, "artist", P.artist);
+ setPropTRCS(fid, "source", P.source);
+ setPropTRCS(fid, "title", P.title);
+ aux = lk_properties_export(fid);
+ res = lk_karma_update_file_details(karma, fid, aux);
+ free(aux);
releaseIOlock();
/* fprintf(stderr, "--> %d %d ***%s***\n", fid, res, aux); */
- free(aux);
if(res) return -EPROTO;
}
else return -ENOENT;
# HG changeset patch
# User Keith Bennett <[EMAIL PROTECTED]>
# Node ID 577257cb087d4a5ac02a458a0af46791371a792a
# Parent 2991132d6692032598f5d4f136464adc1bbd6d90
Added lk_rio_update_props_from_tags() call so that lkarmafs can
update a files properties based on its tags.
diff -r 2991132d6692 -r 577257cb087d src/karma.c
--- a/src/karma.c Sun Aug 13 18:21:07 2006
+++ b/src/karma.c Mon Aug 14 19:38:44 2006
@@ -58,6 +58,7 @@
set_usb_ptr(load_database),
set_unimpl_cast(update_database, void (*)()),
set_usb_ptr(write_smalldb),
+ set_usb_ptr(fidToPath),
};
static struct lk_ops lan_ops =
@@ -86,6 +87,7 @@
set_lan_ptr(load_database),
set_lan_ptr(update_database),
set_lan_ptr(write_smalldb),
+ set_lan_ptr(fidToPath),
};
struct lk_ops *lk_ops;
@@ -98,6 +100,11 @@
int lk_karma_write_smalldb(void)
{
return lk_ops->lk_karma_write_smalldb();
+}
+
+char *lk_karma_fidToPath(int rio, uint32_t file_id)
+{
+ return lk_ops->lk_karma_fidToPath(rio, file_id);
}
/* --------------------------------------------------------------------------
*/
diff -r 2991132d6692 -r 577257cb087d src/karma.h
--- a/src/karma.h Sun Aug 13 18:21:07 2006
+++ b/src/karma.h Mon Aug 14 19:38:44 2006
@@ -17,6 +17,8 @@
#ifdef __cplusplus
extern "C" {
#endif
+
+char *lk_karma_fidToPath(int rio, uint32_t file_id);
/*Help-Functions:*/
int lk_karma_send_request (int rio, uint32_t identifier,
@@ -76,6 +78,7 @@
void (*lk_karma_load_database)(int rio);
void (*lk_karma_update_database)(int rio);
int (*lk_karma_write_smalldb)(void);
+ char *(*lk_karma_fidToPath)(int rio, uint32_t file_id);
};
#ifdef __cplusplus
diff -r 2991132d6692 -r 577257cb087d src/karmaLan.c
--- a/src/karmaLan.c Sun Aug 13 18:21:07 2006
+++ b/src/karmaLan.c Mon Aug 14 19:38:44 2006
@@ -33,6 +33,11 @@
static int32_t recv_status(int rio);
static int32_t recv_properties(int rio, uint32_t identifier, uint32_t r_id,
char ** properties);
+
+char *lk_karmaLan_fidToPath(int rio, uint32_t file_id)
+{
+ return NULL;
+}
/*
Help-Functions
diff -r 2991132d6692 -r 577257cb087d src/karmaLan.h
--- a/src/karmaLan.h Sun Aug 13 18:21:07 2006
+++ b/src/karmaLan.h Mon Aug 14 19:38:44 2006
@@ -45,6 +45,8 @@
#define FORMAT_STORAGE 18
#define HANGUP 19
#define DEVICE_OPERATION 20
+
+char *lk_karmaLan_fidToPath(int rio, uint32_t file_id);
/*Help-Functions:*/
int lk_karmaLan_connect (char *ip);
diff -r 2991132d6692 -r 577257cb087d src/karmaUsb.c
--- a/src/karmaUsb.c Sun Aug 13 18:21:07 2006
+++ b/src/karmaUsb.c Mon Aug 14 19:38:44 2006
@@ -40,7 +40,7 @@
/* --------------------------------------------------------------------------
*/
/* Auxiliary Function */
/* --------------------------------------------------------------------------
*/
-static char *fidToPath(int rio, uint32_t file_id)
+char *lk_karmaUsb_fidToPath(int rio, uint32_t file_id)
{
int i, len;
char *path = NULL;
@@ -592,7 +592,7 @@
/* The first entry is always the fid */
fid = atoi(&props[4]);
- unlink(fidToPath(0, fid));
+ unlink(lk_karmaUsb_fidToPath(0, fid));
}
static int32_t read_properties_smalldb(char **properties)
@@ -772,7 +772,7 @@
int res;
char *path = NULL;
- path = fidToPath(rio, file_id);
+ path = lk_karmaUsb_fidToPath(rio, file_id);
fd = open(path, O_RDONLY);
free(path);
/*
@@ -811,7 +811,7 @@
int res, ret;
char *path = NULL;
- path = fidToPath(rio, file_id);
+ path = lk_karmaUsb_fidToPath(rio, file_id);
/*
if(offset==0)
fprintf(stderr, "--> %s %x %d\n", path, file_id, file_id);
@@ -863,7 +863,7 @@
return -1;
}
- path = fidToPath(rio, file_id);
+ path = lk_karmaUsb_fidToPath(rio, file_id);
path[strlen(path) - 1] = '1';
/* fprintf(stderr, "--> %s %x %d\n", path, file_id, file_id); */
@@ -906,7 +906,7 @@
int ret = 0;
char *path = NULL;
- path = fidToPath(rio, file_id);
+ path = lk_karmaUsb_fidToPath(rio, file_id);
/* fprintf(stderr, "--> %s %x %d\n", path, file_id, file_id); */
if(unlink(path))
ret = -1;
diff -r 2991132d6692 -r 577257cb087d src/karmaUsb.h
--- a/src/karmaUsb.h Sun Aug 13 18:21:07 2006
+++ b/src/karmaUsb.h Mon Aug 14 19:38:44 2006
@@ -17,6 +17,7 @@
extern "C" {
#endif
+char *lk_karmaUsb_fidToPath(int rio, uint32_t file_id);
/*Help-Functions:*/
int lk_karmaUsb_connect (char *ip);
diff -r 2991132d6692 -r 577257cb087d src/lkarma.h
--- a/src/lkarma.h Sun Aug 13 18:21:07 2006
+++ b/src/lkarma.h Mon Aug 14 19:38:44 2006
@@ -174,6 +174,7 @@
int lk_rio_read(int rio, uint32_t fid, const char * filename);
int lk_synchronize_necessary(int rio);
uint32_t lk_rio_write(int rio, const char * filename);
+int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname);
/*
diff -r 2991132d6692 -r 577257cb087d src/rio_rw.c
--- a/src/rio_rw.c Sun Aug 13 18:21:07 2006
+++ b/src/rio_rw.c Mon Aug 14 19:38:44 2006
@@ -24,6 +24,7 @@
#include "wav.h"
#include "lkarma.h"
+#include "karma.h"
#include "properties.h"
#include "util.h"
#include "rio_rw.h"
@@ -42,7 +43,7 @@
static int get_taxi_props(HASH *p);
static int get_wave_props(HASH *p, const char *filename);
static void add_tag(HASH *p, char *key, char *value);
-static void set_tag_props(HASH *p, const char *filename);
+static void set_tag_props(HASH *p, const char *filename, int type);
static int get_file_type(mp3info *mp3);
int lk_synchronize_necessary(int rio)
@@ -126,29 +127,29 @@
return 0;
}
-/*
- To use that function properly:
- 1. Get an IO Lock for Writing
- 2. call synchronize_necessary
- and synchronize the properties if necessary ;)
- 3. use rio_write as often as you need to :)
- 4. release the IO Lock.
-*/
-uint32_t lk_rio_write(int rio, const char * filename)
-{
- int got=-1,fd;
- uint32_t new_fid;
- uint64_t offs=0;
- const uint64_t siz=BLOCKSIZE;
- char * p, tmp[BLOCKSIZE], *rid;
+int lk_rio_update_props_from_tags(int rio, uint32_t fid, const char *fname)
+{
+ int got=-1, usb=0;
+ char *rid, *filename;
struct stat len;
HASH * props;
int type, rid_fd;
mp3info mp3;
uint32_t *fids;
- if(lstat(filename, &len)==-1)
- return -1;
+ if (fname == NULL) {
+ filename = lk_karma_fidToPath(rio, fid);
+ usb = 1;
+ } else
+ filename = fname;
+
+ if(lstat(filename, &len)==-1) {
+ if (usb) {
+ unlink(filename);
+ free(filename);
+ }
+ return -1;
+ }
memset(&mp3, 0, sizeof(mp3info));
mp3.filename = (char*)filename;
@@ -161,15 +162,22 @@
fids = lk_properties_andOrSearch(EXACT|ORS, NULL, "rid", rid);
if (fids != NULL) {
+ if (usb) {
+ unlink(filename);
+ free(filename);
+ }
free(fids);
printf("File already present. Skipping...\n");
return -1;
}
- new_fid=lk_properties_new_property();
/* uses lk_properties_getnextfid()...*/
- props=lk_properties_idsearch(new_fid);
+ props=lk_properties_idsearch(fid);
if(props==NULL){
+ if (usb) {
+ unlink(filename);
+ free(filename);
+ }
printf("huh, no hash found?\n");
return -1;
}
@@ -193,33 +201,64 @@
else
got=get_taxi_props(props);
- if(got==0){
- fd=open(filename, O_RDONLY);
- while((got=read(fd, &tmp, siz)) > 0){
- /*
- if(got < siz)
- memset(&tmp[got], 0, (siz-got)%4);
- if(lk_karma_write_file_chunk(rio, offs, got+((siz-got)%4),
- new_fid, 0, tmp) != 0)
- */
- if(lk_karma_write_file_chunk(rio, offs, got, new_fid, 0, tmp)!=0) {
- printf("lk_karma_write_file_chunk: %u of %llu\n", got, siz);
- lk_properties_del_property(new_fid);
- return -1;
- }
- offs+=got;
- }
+ if (usb)
+ free(filename);
+
+ if (got != 0)
+ lk_properties_del_property(fid);
+
+ return got;
+}
+
+/*
+ To use that function properly:
+ 1. Get an IO Lock for Writing
+ 2. call synchronize_necessary
+ and synchronize the properties if necessary ;)
+ 3. use rio_write as often as you need to :)
+ 4. release the IO Lock.
+*/
+uint32_t lk_rio_write(int rio, const char * filename)
+{
+ int got, fd;
+ uint32_t fid;
+ uint64_t offs=0;
+ char *p, tmp[BLOCKSIZE];
+ const uint64_t siz=BLOCKSIZE;
+
+ fd=open(filename, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ fid = lk_properties_new_property();
+ got = lk_rio_update_props_from_tags(rio, fid, filename);
+
+ if (got != 0) {
close(fd);
-
- p=lk_properties_export(new_fid);
- got=lk_karma_update_file_details(rio, new_fid, p);
- free(p);
-/* return got; */
- return new_fid;
- }else{
- lk_properties_del_property(new_fid);
- return -1;
- }
+ return -1;
+ }
+
+ while((got=read(fd, &tmp, siz)) > 0){
+ /*
+ if(got < siz)
+ memset(&tmp[got], 0, (siz-got)%4);
+ if(lk_karma_write_file_chunk(rio, offs, got+((siz-got)%4),
+ fid, 0, tmp) != 0)
+ */
+ if(lk_karma_write_file_chunk(rio, offs, got, fid, 0, tmp)!=0) {
+ printf("lk_karma_write_file_chunk: %u of %llu\n", got, siz);
+ lk_properties_del_property(fid);
+ return -1;
+ }
+ offs+=got;
+ }
+ close(fd);
+
+ p=lk_properties_export(fid);
+ got=lk_karma_update_file_details(rio, fid, p);
+ free(p);
+
+ return fid;
}
static void add_general(HASH * p, const char *filename)
@@ -248,7 +287,7 @@
lk_properties_set_property_hash(p, "codec", "vorbis");
lk_properties_set_property_hash(p, "type", "tune");
- set_tag_props(p, filename);
+ set_tag_props(p, filename, TagLib_File_OggVorbis);
return 0;
}
@@ -261,7 +300,7 @@
lk_properties_set_property_hash(p, "codec", "flac");
lk_properties_set_property_hash(p, "type", "tune");
- set_tag_props(p, filename);
+ set_tag_props(p, filename, TagLib_File_FLAC);
return 0;
}
@@ -275,7 +314,7 @@
lk_properties_set_property_hash(p, "artist", NOT_TAGGED);
lk_properties_set_property_hash(p, "source", NOT_TAGGED);
- set_tag_props(p, mp3->filename);
+ set_tag_props(p, mp3->filename, TagLib_File_MPEG);
if(!mp3->vbr){
strcpy(bitrate, "fs");
@@ -337,7 +376,7 @@
/*** You can use this with all tag-formats, which taglib supports.
*/
-static void set_tag_props(HASH *p, const char *filename)
+static void set_tag_props(HASH *p, const char *filename, int type)
{
TagLib_File *tl_file;
TagLib_Tag *tl_tag;
@@ -345,7 +384,7 @@
int i;
char bitrate[6];
- tl_file = taglib_file_new(filename);
+ tl_file = taglib_file_new_type(filename, type);
tl_tag = taglib_file_tag(tl_file);
tl_audio = taglib_file_audioproperties(tl_file);
-------------------------------------------------------------------------
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