Enlightenment CVS committal
Author : cpk
Project : e17
Module : apps/efsd
Dir : e17/apps/efsd/efsd
Modified Files:
Makefile.am efsd.h efsd_commands.c efsd_commands.h
efsd_filetype.c efsd_io.c efsd_list.c efsd_main.c efsd_meta.c
efsd_meta.h efsd_misc.c efsd_misc.h efsd_monitor.c
efsd_monitor.h efsd_stack.c efsd_types.c libefsd.c libefsd.h
libefsd_misc.c
Added Files:
efsd_meta_monitor.c efsd_meta_monitor.h
Log Message:
* Here's metadata monitoring. Details are in the manual and in libefsd's
header file.
* I'm using getpwuid() now instead of using $HOME to find a user's home
directory.
* The metadata access convenience calls in libefsd now behave as the manual
says, i.e. they do not duplicate memory. Keep this in mind when you want
to keep the data you receive around.
* Updated doco accordingly.
* Fixlets I cannot remember right now :)
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/Makefile.am,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -3 -r1.27 -r1.28
--- Makefile.am 2001/10/12 17:31:47 1.27
+++ Makefile.am 2001/11/26 01:06:38 1.28
@@ -32,6 +32,7 @@
efsd_main.h efsd_main.c \
efsd_macros.h \
efsd_meta.c efsd_meta.h \
+ efsd_meta_monitor.c efsd_meta_monitor.h \
efsd_monitor.h efsd_monitor.c \
efsd_queue.h efsd_queue.c \
efsd_list.h efsd_list.c \
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -3 -r1.21 -r1.22
--- efsd.h 2001/08/02 22:43:39 1.21
+++ efsd.h 2001/11/26 01:06:38 1.22
@@ -36,28 +36,30 @@
typedef enum efsd_filechange_type
{
- EFSD_FILE_CHANGED = 1,
- EFSD_FILE_DELETED = 2,
- EFSD_FILE_START_EXEC = 3,
- EFSD_FILE_STOP_EXEC = 4,
- EFSD_FILE_CREATED = 5,
- EFSD_FILE_MOVED = 6,
- EFSD_FILE_ACKNOWLEDGE = 7,
- EFSD_FILE_EXISTS = 8,
- EFSD_FILE_END_EXISTS = 9
+ EFSD_FILE_CHANGED = 1,
+ EFSD_FILE_DELETED = 2,
+ EFSD_FILE_START_EXEC = 3,
+ EFSD_FILE_STOP_EXEC = 4,
+ EFSD_FILE_CREATED = 5,
+ EFSD_FILE_MOVED = 6,
+ EFSD_FILE_ACKNOWLEDGE = 7,
+ EFSD_FILE_EXISTS = 8,
+ EFSD_FILE_END_EXISTS = 9,
+ EFSD_FILE_METADATA_CHANGED = 10
}
EfsdFilechangeType;
typedef enum efsd_event_type
{
EFSD_EVENT_FILECHANGE,
+ EFSD_EVENT_METADATA_CHANGE,
EFSD_EVENT_REPLY
}
EfsdEventType;
typedef enum efsd_command_type
{
- EFSD_CMD_REMOVE,
+ EFSD_CMD_REMOVE,
EFSD_CMD_MOVE,
EFSD_CMD_COPY,
EFSD_CMD_SYMLINK,
@@ -68,8 +70,10 @@
EFSD_CMD_GETMETA,
EFSD_CMD_STARTMON_FILE,
EFSD_CMD_STARTMON_DIR,
+ EFSD_CMD_STARTMON_META,
EFSD_CMD_STOPMON_FILE,
EFSD_CMD_STOPMON_DIR,
+ EFSD_CMD_STOPMON_META,
EFSD_CMD_STAT,
EFSD_CMD_LSTAT,
EFSD_CMD_READLINK,
@@ -206,6 +210,21 @@
EfsdFileChangeEvent;
+/* Metadata change event.
+ */
+typedef struct efsd_metachange_event
+{
+ EfsdEventType type;
+ EfsdCmdId id;
+ char *key;
+ char *file;
+ EfsdDatatype datatype;
+ int data_len;
+ void *data;
+}
+EfsdMetadataChangeEvent;
+
+
/* General reply to commands, contains
entire command as well
*/
@@ -230,9 +249,10 @@
/* General event structure */
typedef union efsd_event
{
- EfsdEventType type;
- EfsdFileChangeEvent efsd_filechange_event;
- EfsdReplyEvent efsd_reply_event;
+ EfsdEventType type;
+ EfsdFileChangeEvent efsd_filechange_event;
+ EfsdMetadataChangeEvent efsd_metachange_event;
+ EfsdReplyEvent efsd_reply_event;
}
EfsdEvent;
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_commands.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- efsd_commands.c 2001/11/16 16:44:15 1.12
+++ efsd_commands.c 2001/11/26 01:06:38 1.13
@@ -48,10 +48,12 @@
#include <efsd_filetype.h>
#include <efsd_main.h>
#include <efsd_meta.h>
+#include <efsd_meta_monitor.h>
#include <efsd_misc.h>
#include <efsd_event_queue.h>
#include <efsd_statcache.h>
#include <efsd_types.h>
+#include <efsd_meta_monitor.h>
static void
@@ -378,6 +380,36 @@
D_ENTER;
if (efsd_monitor_stop(cmd, client, dir_mode) < 0)
+ {
+ errno_check(__LINE__, __FUNCTION__);
+ D_RETURN_(send_reply(cmd, errno, 0, NULL, client));
+ }
+
+ D_RETURN_(send_reply(cmd, 0, 0, NULL, client));
+}
+
+
+int
+efsd_command_start_monitor_metadata(EfsdCommand *cmd, int client)
+{
+ D_ENTER;
+
+ if (!efsd_meta_monitor_add(cmd, client))
+ {
+ errno_check(__LINE__, __FUNCTION__);
+ D_RETURN_(send_reply(cmd, errno, 0, NULL, client));
+ }
+
+ D_RETURN_(send_reply(cmd, 0, 0, NULL, client));
+}
+
+
+int
+efsd_command_stop_monitor_metadata(EfsdCommand *cmd, int client)
+{
+ D_ENTER;
+
+ if (!efsd_meta_monitor_del(cmd, client))
{
errno_check(__LINE__, __FUNCTION__);
D_RETURN_(send_reply(cmd, errno, 0, NULL, client));
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_commands.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- efsd_commands.h 2001/07/27 13:09:29 1.3
+++ efsd_commands.h 2001/11/26 01:06:38 1.4
@@ -38,6 +38,8 @@
int efsd_command_listdir(EfsdCommand *cmd, int client);
int efsd_command_start_monitor(EfsdCommand *cmd, int client, int dir_mode);
int efsd_command_stop_monitor(EfsdCommand *cmd, int client, int dir_mode);
+int efsd_command_start_monitor_metadata(EfsdCommand *cmd, int client);
+int efsd_command_stop_monitor_metadata(EfsdCommand *cmd, int client);
int efsd_command_stat(EfsdCommand *cmd, int client, char use_lstat);
int efsd_command_readlink(EfsdCommand *cmd, int client);
int efsd_command_get_filetype(EfsdCommand *cmd, int client);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_filetype.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -3 -r1.33 -r1.34
--- efsd_filetype.c 2001/11/16 16:44:15 1.33
+++ efsd_filetype.c 2001/11/26 01:06:38 1.34
@@ -60,6 +60,10 @@
#undef DEBUG
#endif
+#ifdef DEBUG_NEST
+#undef DEBUG_NEST
+#endif
+
#include <efsd.h>
#include <efsd_debug.h>
#include <efsd_lock.h>
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_io.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -3 -r1.40 -r1.41
--- efsd_io.c 2001/09/30 18:35:07 1.40
+++ efsd_io.c 2001/11/26 01:06:38 1.41
@@ -82,6 +82,7 @@
static int read_set_metadata_cmd(int sockfd, EfsdCommand *cmd);
static int read_get_metadata_cmd(int sockfd, EfsdCommand *cmd);
static int read_filechange_event(int sockfd, EfsdEvent *ee);
+static int read_metadata_change_event(int sockfd, EfsdEvent *ee);
static int read_reply_event(int sockfd, EfsdEvent *ee);
static int read_getmeta_op(int sockfd, EfsdOption *eo);
@@ -91,6 +92,7 @@
static void fill_get_metadata_cmd(EfsdIOV *iov, EfsdCommand *ec);
static void fill_close_cmd(EfsdIOV *iov, EfsdCommand *ec);
static void fill_filechange_event(EfsdIOV *iov, EfsdEvent *ee);
+static void fill_metadata_change_event(EfsdIOV *iov, EfsdEvent *ee);
static void fill_reply_event(EfsdIOV *iov, EfsdEvent *ee);
static void fill_event(EfsdIOV *iov, EfsdEvent *ee);
static void fill_command(EfsdIOV *iov, EfsdCommand *ec);
@@ -109,7 +111,10 @@
D_ENTER;
if (sockfd < 0)
- D_RETURN_(-1);
+ {
+ D("Socket < 0 ???\n");
+ D_RETURN_(-1);
+ }
tv.tv_sec = 1;
tv.tv_usec = 0;
@@ -387,6 +392,53 @@
static int
+read_metadata_change_event(int sockfd, EfsdEvent *ee)
+{
+ int count, count2;
+
+ D_ENTER;
+
+ if ((count = read_int(sockfd, &(ee->efsd_metachange_event.id))) < 0)
+ D_RETURN_(-1);
+ count2 = count;
+
+ if ((count = read_string(sockfd, &(ee->efsd_metachange_event.key))) < 0)
+ D_RETURN_(-1);
+ count2 += count;
+
+ if ((count = read_string(sockfd, &(ee->efsd_metachange_event.file))) < 0)
+ D_RETURN_(-1);
+ count2 += count;
+
+ if ((count = read_int(sockfd, (int*)&(ee->efsd_metachange_event.datatype))) < 0)
+ D_RETURN_(-1);
+ count2 += count;
+
+ if ((count = read_int(sockfd, (int*)&(ee->efsd_metachange_event.data_len))) < 0)
+ D_RETURN_(-1);
+ count2 += count;
+
+ if (ee->efsd_metachange_event.data_len > 0)
+ {
+ ee->efsd_metachange_event.data =
+ malloc(ee->efsd_metachange_event.data_len);
+
+ if ((count = read_data(sockfd, (ee->efsd_metachange_event.data),
+ ee->efsd_metachange_event.data_len)) < 0)
+ D_RETURN_(-1);
+ count2 += count;
+ }
+ else
+ {
+ ee->efsd_metachange_event.data_len = 0;
+ ee->efsd_metachange_event.data = NULL;
+ }
+
+ D_RETURN_(count2);
+}
+
+
+static int
read_reply_event(int sockfd, EfsdEvent *ee)
{
int count = 0, count2;
@@ -614,6 +666,46 @@
}
+static void
+fill_metadata_change_event(EfsdIOV *iov, EfsdEvent *ee)
+{
+ D_ENTER;
+
+ iov->dat[iov->d] = strlen(ee->efsd_metachange_event.key) + 1;
+ iov->dat[iov->d+1] = strlen(ee->efsd_metachange_event.file) + 1;
+
+ iov->vec[iov->v].iov_base = &ee->type;
+ iov->vec[iov->v].iov_len = sizeof(EfsdEventType);
+
+ iov->vec[++iov->v].iov_base = &ee->efsd_metachange_event.id;
+ iov->vec[iov->v].iov_len = sizeof(EfsdCmdId);
+
+ iov->vec[++iov->v].iov_base = &(iov->dat[iov->d]);
+ iov->vec[iov->v].iov_len = sizeof(int);
+ iov->vec[++iov->v].iov_base = ee->efsd_metachange_event.key;
+ iov->vec[iov->v].iov_len = iov->dat[iov->d];
+
+ iov->vec[++iov->v].iov_base = &(iov->dat[iov->d+1]);
+ iov->vec[iov->v].iov_len = sizeof(int);
+ iov->vec[++iov->v].iov_base = ee->efsd_metachange_event.file;
+ iov->vec[iov->v].iov_len = iov->dat[iov->d+1];
+
+ iov->vec[++iov->v].iov_base = &ee->efsd_metachange_event.datatype;
+ iov->vec[iov->v].iov_len = sizeof(int);
+
+ iov->vec[++iov->v].iov_base = &ee->efsd_metachange_event.data_len;
+ iov->vec[iov->v].iov_len = sizeof(int);
+
+ iov->vec[++iov->v].iov_base = ee->efsd_metachange_event.data;
+ iov->vec[iov->v].iov_len = ee->efsd_metachange_event.data_len;
+
+ iov->d += 2;
+ iov->v++;
+
+ D_RETURN;
+}
+
+
static void
fill_reply_event(EfsdIOV *iov, EfsdEvent *ee)
{
@@ -625,7 +717,7 @@
fill_command(iov, &ee->efsd_reply_event.command);
- iov->vec[iov->v].iov_base = &ee->efsd_reply_event.errorcode;
+ iov->vec[iov->v].iov_base = &ee->efsd_reply_event.errorcode;
iov->vec[iov->v].iov_len = sizeof(int);
iov->vec[++iov->v].iov_base = &ee->efsd_reply_event.data_len;
iov->vec[iov->v].iov_len = sizeof(int);
@@ -649,6 +741,9 @@
case EFSD_EVENT_FILECHANGE:
fill_filechange_event(iov, ee);
break;
+ case EFSD_EVENT_METADATA_CHANGE:
+ fill_metadata_change_event(iov, ee);
+ break;
case EFSD_EVENT_REPLY:
fill_reply_event(iov, ee);
break;
@@ -672,8 +767,10 @@
case EFSD_CMD_LISTDIR:
case EFSD_CMD_STARTMON_FILE:
case EFSD_CMD_STARTMON_DIR:
+ case EFSD_CMD_STARTMON_META:
case EFSD_CMD_STOPMON_FILE:
case EFSD_CMD_STOPMON_DIR:
+ case EFSD_CMD_STOPMON_META:
case EFSD_CMD_STAT:
case EFSD_CMD_LSTAT:
case EFSD_CMD_READLINK:
@@ -795,8 +892,10 @@
case EFSD_CMD_LISTDIR:
case EFSD_CMD_STARTMON_FILE:
case EFSD_CMD_STARTMON_DIR:
+ case EFSD_CMD_STARTMON_META:
case EFSD_CMD_STOPMON_FILE:
case EFSD_CMD_STOPMON_DIR:
+ case EFSD_CMD_STOPMON_META:
case EFSD_CMD_STAT:
case EFSD_CMD_LSTAT:
case EFSD_CMD_READLINK:
@@ -874,6 +973,9 @@
{
case EFSD_EVENT_FILECHANGE:
result = read_filechange_event(sockfd, ee);
+ break;
+ case EFSD_EVENT_METADATA_CHANGE:
+ result = read_metadata_change_event(sockfd, ee);
break;
case EFSD_EVENT_REPLY:
result = read_reply_event(sockfd, ee);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_list.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- efsd_list.c 2001/09/30 18:35:07 1.6
+++ efsd_list.c 2001/11/26 01:06:38 1.7
@@ -29,6 +29,14 @@
#include <stdio.h>
#include <stdlib.h>
+#ifdef DEBUG
+#undef DEBUG
+#endif
+
+#ifdef DEBUG_NEST
+#undef DEBUG_NEST
+#endif
+
#include <efsd_macros.h>
#include <efsd_debug.h>
#include <efsd_misc.h>
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_main.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -3 -r1.50 -r1.51
--- efsd_main.c 2001/11/16 16:44:15 1.50
+++ efsd_main.c 2001/11/26 01:06:38 1.51
@@ -58,6 +58,7 @@
#include <efsd_macros.h>
#include <efsd_main.h>
#include <efsd_meta.h>
+#include <efsd_meta_monitor.h>
#include <efsd_misc.h>
#include <efsd_event_queue.h>
#include <efsd_types.h>
@@ -257,6 +258,10 @@
D("Handling STARTMON_DIR\n");
efsd_command_start_monitor(command, client, TRUE);
break;
+ case EFSD_CMD_STARTMON_META:
+ D("Handling STARTMON_META\n");
+ efsd_command_start_monitor_metadata(command, client);
+ break;
case EFSD_CMD_STOPMON_FILE:
D("Handling STOPMON_FILE\n");
efsd_command_stop_monitor(command, client, FALSE);
@@ -265,6 +270,10 @@
D("Handling STOPMON_DIR\n");
efsd_command_stop_monitor(command, client, TRUE);
break;
+ case EFSD_CMD_STOPMON_META:
+ D("Handling STOPMON_META\n");
+ efsd_command_stop_monitor_metadata(command, client);
+ break;
case EFSD_CMD_STAT:
D("Handling STAT on %s\n", command->efsd_file_cmd.files[0]);
efsd_command_stat(command, client, FALSE);
@@ -659,7 +668,8 @@
fd_set *fdwset_ptr = NULL;
char have_fam_thread = FALSE;
struct timeval tv;
-
+ int rebuild_fdset = FALSE;
+
D_ENTER;
ev_q = efsd_queue_new();
@@ -711,7 +721,8 @@
for ( ; ; )
{
- can_accept = 0;
+ rebuild_fdset = FALSE;
+ can_accept = FALSE;
FD_ZERO(&fdrset);
FD_ZERO(&fdwset);
fdwset_ptr = NULL;
@@ -736,7 +747,7 @@
fdsize = clientfd[i];
}
else
- can_accept = 1;
+ can_accept = TRUE;
}
/* listen for new connections */
@@ -774,13 +785,21 @@
}
else
{
- fprintf(stderr, __FUNCTION__ ": select error -- exiting.\n");
- exit(-1);
+ D("Select error: %s.\n", strerror(errno));
+
+ /* FIXME -- if we get a bad descriptor here, we need to close
+ that connection properly and rebuild the fdset. */
+
+ rebuild_fdset = TRUE;
}
tv.tv_sec = 1;
tv.tv_usec = 0;
}
+ /* If something went wrong with the select, start over. */
+ if (rebuild_fdset)
+ continue;
+
/* if we timed out - ie 0 fd's available */
if (n == 0)
efsd_meta_idle();
@@ -816,7 +835,6 @@
}
else
{
- efsd_main_close_connection(i);
efsd_cmd_free(ecmd);
}
}
@@ -1001,7 +1019,7 @@
{
D("Cleaning up client %i, fd %i\n", i, clientfd[i]);
close(clientfd[i]);
- clientfd[i] = 0;
+ clientfd[i] = -1;
}
}
@@ -1184,17 +1202,18 @@
efsd_main_close_connection(int client)
{
D_ENTER;
- D("Closing connection %i\n", client);
if (clientfd[client] < 0)
{
- D("Connection already closed ???\n");
D_RETURN_(-1);
}
+ D("Closing connection %i\n", client);
efsd_monitor_cleanup_client(client);
+ efsd_meta_monitor_cleanup_client(client);
close(clientfd[client]);
clientfd[client] = -1;
+
D_RETURN_(0);
}
@@ -1210,6 +1229,7 @@
efsd_monitor_init();
efsd_stat_init();
efsd_meta_init();
+ efsd_meta_monitor_init();
efsd_filetype_init();
main_initialize(argv[0]);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_meta.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- efsd_meta.c 2001/11/16 16:44:15 1.14
+++ efsd_meta.c 2001/11/26 01:06:38 1.15
@@ -40,19 +40,18 @@
#include <efsd_debug.h>
#include <efsd_macros.h>
#include <efsd_misc.h>
+#include <efsd_hash.h>
+#include <efsd_monitor.h>
#include <efsd_statcache.h>
#include <efsd_lock.h>
-#include <efsd_meta.h>
#include <efsd_fs.h>
-
-
+#include <efsd_meta_monitor.h>
+#include <efsd_meta.h>
+/* This lock manages concurrent access to metadata dbs */
EfsdLock *meta_lock;
static char * meta_get_user_metadata_filename(void);
-static int meta_db_get_file(char *filename,
- char *dbfile, int db_len,
- char *key, int key_len, int create);
static int meta_db_set_data(EfsdSetMetadataCmd *esmc, char *key_base, char *dbfile);
@@ -96,136 +95,6 @@
D_RETURN_(s);
}
-static int
-meta_db_get_file(char *filename,
- char *dbfile, int db_len,
- char *key, int key_len, int create)
-{
- char s[MAXPATHLEN], filename_copy[MAXPATHLEN];
- char *path, *file;
- int use_home_dir = FALSE;
- struct stat st;
-
- D_ENTER;
-
- if (!filename || filename[0] != '/')
- {
- D("Invalid filename\n");
- errno = ENOENT;
- D_RETURN_(FALSE);
- }
-
- snprintf(filename_copy, MAXPATHLEN, "%s", filename);
- path = filename_copy;
-
- file = strrchr(filename_copy, '/');
- if (!file)
- {
- /* Something's wrong -- this is supposed to be
- a chanonical path ...
- */
- D("Couldn't find '/' in filename '%s'\n", filename);
- errno = EINVAL;
- D_RETURN_(FALSE);
- }
-
- /* terminate the string where the path ends,
- cutting of the filename...
- */
- *file = '\0';
- file++;
-
- /* file is now the filename only, path is now the path only. */
-
- if (*path == '\0')
- {
- path = "/";
- snprintf(s, MAXPATHLEN, "/%s", EFSD_META_DIR_NAME);
- }
- else
- {
- snprintf(s, MAXPATHLEN, "%s/%s", path, EFSD_META_DIR_NAME);
- }
-
- /* s is now the metadata directory for the given file, out
- in the filesystem. Check if the directory exists
- and is accessible.
- */
-
- if (efsd_misc_file_exists(s))
- {
- if (efsd_misc_file_writeable(s) &&
- efsd_misc_file_execable(s))
- /* Can access and manipulate --> use it. */
- use_home_dir = FALSE;
- else
- /* No access --> need to put metadata in home dir */
- use_home_dir = TRUE;
- }
- else
- {
- if (efsd_misc_file_writeable(path) &&
- efsd_misc_file_execable(path))
- {
- if (!efsd_stat(path, &st))
- {
- use_home_dir = TRUE;
- }
- else
- {
- if (!create)
- {
- D("Not existant metadata dir %s, no create -- returning false.\n", s);
- D_RETURN_(FALSE);
- }
-
- /* We're told to create the metadata directory, so try it ... */
- umask(000);
-
- if (mkdir(s, st.st_mode) < 0)
- use_home_dir = TRUE;
- else
- use_home_dir = FALSE;
-
- umask(077);
- }
- }
- else
- {
- use_home_dir = TRUE;
- }
- }
-
- /* We use different keys to access metadata, depending on
- whether we're in the global directory in the user's home
- or locally out in the filesystem. When we're in the home
- dir, we use the full path and filename. When we're local,
- we just use the file name, without the path.
-
- By doing this we can rename an entire directory
- branch without having to adjust all the metadata
- file names in the subtree.
- */
-
- if (use_home_dir)
- {
- snprintf(dbfile, db_len, "%s/%s",
- efsd_misc_get_user_dir(), EFSD_META_FILE_NAME);
-
- snprintf(key, key_len, "/meta%s", filename);
- }
- else
- {
- snprintf(dbfile, db_len, "%s/%s",
- s, meta_get_user_metadata_filename());
-
- snprintf(key, key_len, "/meta/%s", file);
- }
- D("Returning success.\n");
-
- D_RETURN_(TRUE);
-}
-
int
efsd_meta_copy_data(char *from_file, char *to_file)
@@ -245,16 +114,16 @@
D("Copying metadata from file %s to %s\n", from_file, to_file);
- if (!meta_db_get_file(from_file,
- from_db_file, MAXPATHLEN,
- from_key, MAXPATHLEN,
- FALSE))
+ if (!efsd_meta_get_file_info(from_file,
+ from_db_file, MAXPATHLEN,
+ from_key, MAXPATHLEN,
+ FALSE))
D_RETURN_(FALSE);
- if (!meta_db_get_file(to_file,
- to_db_file, MAXPATHLEN,
- to_key, MAXPATHLEN,
- TRUE))
+ if (!efsd_meta_get_file_info(to_file,
+ to_db_file, MAXPATHLEN,
+ to_key, MAXPATHLEN,
+ TRUE))
D_RETURN_(FALSE);
D("From %s %s to %s %s\n", from_db_file, from_key, to_db_file, to_key);
@@ -342,7 +211,7 @@
D("Removing metadata of file %s\n", file);
- if (!meta_db_get_file(file,
+ if (!efsd_meta_get_file_info(file,
db_file, MAXPATHLEN,
key, MAXPATHLEN,
FALSE))
@@ -392,7 +261,11 @@
D_RETURN_(0);
}
+ efsd_meta_monitor_notify(esmc->file, esmc->key, esmc->datatype,
+ esmc->data_len, esmc->data);
+
snprintf(key, MAXPATHLEN, "%s%s", key_base, esmc->key);
+
switch (esmc->datatype)
{
@@ -553,8 +426,8 @@
esmc = &(ec->efsd_set_metadata_cmd);
efsd_misc_remove_trailing_slashes(esmc->file);
- meta_db_get_file(esmc->file, db_file, MAXPATHLEN,
- key_base, MAXPATHLEN, TRUE /* create */);
+ efsd_meta_get_file_info(esmc->file, db_file, MAXPATHLEN,
+ key_base, MAXPATHLEN, TRUE /* create */);
D("Writing to %s for %s\n", db_file, esmc->file);
@@ -580,8 +453,8 @@
egmc = &(ec->efsd_get_metadata_cmd);
efsd_misc_remove_trailing_slashes(egmc->file);
- if (meta_db_get_file(egmc->file, db_file, MAXPATHLEN,
- key_base, MAXPATHLEN, FALSE) == FALSE)
+ if (efsd_meta_get_file_info(egmc->file, db_file, MAXPATHLEN,
+ key_base, MAXPATHLEN, FALSE) == FALSE)
D_RETURN_(NULL);
success = meta_db_get_data(egmc, key_base, db_file, data_len);
@@ -632,3 +505,140 @@
D_RETURN;
}
+
+
+int
+efsd_meta_get_file_info(char *filename,
+ char *dbfile, int db_len,
+ char *key, int key_len, int create)
+{
+ char s[MAXPATHLEN], filename_copy[MAXPATHLEN];
+ char *path, *file;
+ int use_home_dir = FALSE;
+ struct stat st;
+
+ D_ENTER;
+
+ if (!filename || filename[0] != '/')
+ {
+ D("Invalid filename\n");
+ errno = ENOENT;
+ D_RETURN_(FALSE);
+ }
+
+ snprintf(filename_copy, MAXPATHLEN, "%s", filename);
+ path = filename_copy;
+
+ file = strrchr(filename_copy, '/');
+ if (!file)
+ {
+ /* Something's wrong -- this is supposed to be
+ a chanonical path ...
+ */
+ D("Couldn't find '/' in filename '%s'\n", filename);
+ errno = EINVAL;
+ D_RETURN_(FALSE);
+ }
+
+ /* terminate the string where the path ends,
+ cutting of the filename...
+ */
+ *file = '\0';
+ file++;
+
+ /* file is now the filename only, path is now the path only. */
+
+ if (*path == '\0')
+ {
+ path = "/";
+ snprintf(s, MAXPATHLEN, "/%s", EFSD_META_DIR_NAME);
+ }
+ else
+ {
+ snprintf(s, MAXPATHLEN, "%s/%s", path, EFSD_META_DIR_NAME);
+ }
+
+ /* s is now the metadata directory for the given file, out
+ in the filesystem. Check if the directory exists
+ and is accessible.
+ */
+
+ if (efsd_misc_file_exists(s))
+ {
+ if (efsd_misc_file_readable(s) &&
+ efsd_misc_file_execable(s))
+ /* Can access and manipulate --> use it. */
+ use_home_dir = FALSE;
+ else
+ /* No access --> need to put metadata in home dir */
+ use_home_dir = TRUE;
+ }
+ else
+ {
+ if (efsd_misc_file_readable(path) &&
+ efsd_misc_file_execable(path))
+ {
+ if (!efsd_stat(path, &st))
+ {
+ use_home_dir = TRUE;
+ }
+ else
+ {
+ if (!create)
+ {
+ D("Not existant metadata dir %s, no create -- returning false.\n", s);
+ D_RETURN_(FALSE);
+ }
+
+ /* We're told to create the metadata directory, so try it ... */
+ umask(000);
+
+ if (mkdir(s, st.st_mode) < 0)
+ use_home_dir = TRUE;
+ else
+ use_home_dir = FALSE;
+
+ umask(077);
+ }
+ }
+ else
+ {
+ use_home_dir = TRUE;
+ }
+ }
+
+ /* We use different keys to access metadata, depending on
+ whether we're in the global directory in the user's home
+ or locally out in the filesystem. When we're in the home
+ dir, we use the full path and filename. When we're local,
+ we just use the file name, without the path.
+
+ By doing this we can rename an entire directory
+ branch without having to adjust all the metadata
+ file names in the subtree.
+ */
+
+ if (use_home_dir)
+ {
+ if (dbfile)
+ snprintf(dbfile, db_len, "%s/%s",
+ efsd_misc_get_user_dir(), EFSD_META_FILE_NAME);
+
+ if (key)
+ snprintf(key, key_len, "/meta%s", filename);
+ }
+ else
+ {
+ if (dbfile)
+ snprintf(dbfile, db_len, "%s/%s",
+ s, meta_get_user_metadata_filename());
+
+ if (key)
+ snprintf(key, key_len, "/meta/%s", file);
+ }
+ D("Returning success.\n");
+
+ D_RETURN_(TRUE);
+}
+
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_meta.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- efsd_meta.h 2001/11/16 16:44:15 1.6
+++ efsd_meta.h 2001/11/26 01:06:38 1.7
@@ -96,4 +96,26 @@
*/
void efsd_meta_idle(void);
+
+/**
+ * efsd_meta_get_file_info - Returns info about metadata for a file
+ * @filename: The full path name of the file.
+ * @dbfile: Result pointer to location of db file for @filename.
+ * @db_len: Length of string to write result into.
+ * @key: Result pointer to metadata key prefix for @filename.
+ * @key_len: Length of string to write result into.
+ * @create: Flag which causes the metadata directory to be created if it doesn't exist yet.
+ *
+ * This is a helper function that looks at the given
+ * filename and returns the location of the metadata
+ * db file and the key prefix that depends on the location
+ * of the file (it can be just the file name or the full
+ * path).
+ *
+ * Returns TRUE if operation was successfull, FALSE otherwise.
+ */
+int efsd_meta_get_file_info(char *filename,
+ char *dbfile, int db_len,
+ char *key, int key_len, int create);
+
#endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_misc.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -3 -r1.34 -r1.35
--- efsd_misc.c 2001/11/16 16:44:15 1.34
+++ efsd_misc.c 2001/11/26 01:06:38 1.35
@@ -34,6 +34,7 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <pwd.h>
#ifdef __EMX__
#include <stdlib.h>
@@ -119,6 +120,39 @@
}
+int
+efsd_misc_file_readable(char *filename)
+{
+ struct stat st;
+
+ D_ENTER;
+
+ if (!filename)
+ D_RETURN_(FALSE);
+
+ if (!efsd_stat(filename, &st))
+ D_RETURN_(FALSE);
+
+ if (st.st_uid == geteuid())
+ {
+ if (st.st_mode & S_IRUSR)
+ D_RETURN_(TRUE);
+ }
+ else if (st.st_gid == getgid())
+ {
+ if (st.st_mode & S_IRGRP)
+ D_RETURN_(TRUE);
+ }
+ else
+ {
+ if (st.st_mode & S_IROTH)
+ D_RETURN_(TRUE);
+ }
+
+ D_RETURN_(FALSE);
+}
+
+
int
efsd_misc_file_execable(char *filename)
{
@@ -460,27 +494,25 @@
void
efsd_misc_create_efsd_dir(void)
{
- char *dir = NULL;
- char s[MAXPATHLEN];
+ struct passwd *pw = NULL;
+ char dir[MAXPATHLEN];
+ char s[MAXPATHLEN];
D_ENTER;
-
- dir = getenv("HOME");
-
- /* I'm not using getenv("TMPDIR") --
- * I don't see TMPDIR on Linux, FreeBSD
- * or Solaris here...
- */
- if (!dir)
- dir = "/tmp";
-
- snprintf(s, sizeof(s), "%s/.e", dir);
+ if ( (pw = getpwuid(geteuid())))
+ {
+ snprintf(dir, MAXPATHLEN, "%s/.e", pw->pw_dir);
+ }
+ else
+ {
+ snprintf(dir, MAXPATHLEN, "/tmp/.efsd_%u", geteuid());
+ }
- if (!efsd_misc_file_is_dir(s))
- efsd_misc_mkdir(s);
+ if (!efsd_misc_file_is_dir(dir))
+ efsd_misc_mkdir(dir);
- snprintf(s, sizeof(s), "%s/.e/efsd", dir);
+ snprintf(s, sizeof(s), "%s/efsd", dir);
if (!efsd_misc_file_is_dir(s))
efsd_misc_mkdir(s);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_misc.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- efsd_misc.h 2001/11/16 16:44:15 1.22
+++ efsd_misc.h 2001/11/26 01:06:38 1.23
@@ -25,15 +25,18 @@
#ifndef __efsd_misc_h
#define __efsd_misc_h
+
+/* These do the obvious ... */
int efsd_misc_file_exists(char *filename);
int efsd_misc_file_is_dir(char *filename);
+int efsd_misc_file_readable(char *filename);
int efsd_misc_file_writeable(char *filename);
int efsd_misc_file_execable(char *filename);
int efsd_misc_file_is_dotfile(char *filename);
/* Checks if file paths are identical after making
them chanonic -- returns < 0 on error, FALSE
- if files differ, TRUE otherwise.
+ if files differ, TRUE otherwise. Not an inode check.
*/
int efsd_misc_files_identical(char *file1, char *file2);
@@ -43,8 +46,14 @@
*/
int efsd_misc_remove(char *filename);
+/* Wrapper to rename() that updates the stat cache
+ and handles metadata properly. Returns TRUE on
+ success, FALSE otherwise.
+*/
int efsd_misc_rename(char *file1, char *file2);
+/* Simple mkdir wrapper.
+ */
int efsd_misc_mkdir(char *filename);
void efsd_misc_remove_trailing_slashes(char *path);
int efsd_misc_is_absolute_path(char *path);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_monitor.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- efsd_monitor.c 2001/11/16 16:44:15 1.20
+++ efsd_monitor.c 2001/11/26 01:06:38 1.21
@@ -67,10 +67,6 @@
static void monitor_free(EfsdMonitor *m);
-static EfsdMonitorRequest *monitor_request_new(int client, EfsdFileCmd *cmd);
-
-static void monitor_request_free(EfsdMonitorRequest *emr);
-
/* Increment use count for file monitor, or start
new monitor if file is not monitored yet.
*/
@@ -191,7 +187,7 @@
m->clients = NULL;
m->files = efsd_dca_new();
- emr = monitor_request_new(client, &com->efsd_file_cmd);
+ emr = efsd_monitor_request_new(client, &com->efsd_file_cmd);
m->clients = efsd_list_prepend(m->clients, emr);
@@ -237,7 +233,7 @@
FREE(m->filename);
FREE(m->fam_req);
- efsd_list_free(m->clients, (EfsdFunc)monitor_request_free);
+ efsd_list_free(m->clients, (EfsdFunc)efsd_monitor_request_free);
efsd_dca_free(m->files);
#if USE_THREADS
@@ -250,54 +246,6 @@
}
-static EfsdMonitorRequest *
-monitor_request_new(int client, EfsdFileCmd *cmd)
-{
- EfsdMonitorRequest *emr;
-
- D_ENTER;
-
- emr = NEW(EfsdMonitorRequest);
- memset(emr, 0, sizeof(EfsdMonitorRequest));
-
- emr->client = client;
- emr->id = cmd->id;
-
- /* Unhook (not free) the options from the command, so
- that they don't get freed in the normal command
- cleanup. They will get cleaned up when we see the
- acknowledge event and the EfsdMonitorRequest is freed.
- */
-
- if (cmd->num_options > 0)
- {
- emr->num_options = cmd->num_options;
- emr->options = cmd->options;
- cmd->num_options = 0;
- cmd->options = NULL;
- }
-
- D_RETURN_(emr);
-}
-
-
-static void
-monitor_request_free(EfsdMonitorRequest *emr)
-{
- int i;
-
- D_ENTER;
-
- for (i = 0; i < emr->num_options; i++)
- efsd_option_cleanup(&emr->options[i]);
-
- FREE(emr->options);
- FREE(emr);
-
- D_RETURN;
-}
-
-
static void
monitor_hash_item_free(EfsdHashItem *it)
{
@@ -345,6 +293,54 @@
}
+EfsdMonitorRequest *
+efsd_monitor_request_new(int client, EfsdFileCmd *cmd)
+{
+ EfsdMonitorRequest *emr;
+
+ D_ENTER;
+
+ emr = NEW(EfsdMonitorRequest);
+ memset(emr, 0, sizeof(EfsdMonitorRequest));
+
+ emr->client = client;
+ emr->id = cmd->id;
+
+ /* Unhook (not free) the options from the command, so
+ that they don't get freed in the normal command
+ cleanup. They will get cleaned up when we see the
+ acknowledge event and the EfsdMonitorRequest is freed.
+ */
+
+ if (cmd->num_options > 0)
+ {
+ emr->num_options = cmd->num_options;
+ emr->options = cmd->options;
+ cmd->num_options = 0;
+ cmd->options = NULL;
+ }
+
+ D_RETURN_(emr);
+}
+
+
+void
+efsd_monitor_request_free(EfsdMonitorRequest *emr)
+{
+ int i;
+
+ D_ENTER;
+
+ for (i = 0; i < emr->num_options; i++)
+ efsd_option_cleanup(&emr->options[i]);
+
+ FREE(emr->options);
+ FREE(emr);
+
+ D_RETURN;
+}
+
+
void
efsd_monitor_send_filechange_events(EfsdMonitor *m, EfsdMonitorRequest *emr)
{
@@ -453,7 +449,7 @@
m->filename, m->internal_use_count, m->client_use_count);
}
- emr = monitor_request_new(client, &com->efsd_file_cmd);
+ emr = efsd_monitor_request_new(client, &com->efsd_file_cmd);
m->clients = efsd_list_prepend(m->clients, emr);
UNLOCK(&m->use_count_mutex);
@@ -575,7 +571,7 @@
if (!m->is_receiving_exist_events)
{
m->clients = efsd_list_remove(m->clients, l2,
- (EfsdFunc)monitor_request_free);
+ (EfsdFunc)efsd_monitor_request_free);
}
else
{
@@ -592,7 +588,7 @@
if (!m->is_receiving_exist_events)
{
m->clients = efsd_list_remove(m->clients, l2,
- (EfsdFunc)monitor_request_free);
+ (EfsdFunc)efsd_monitor_request_free);
}
else
{
@@ -830,7 +826,7 @@
}
-int
+void
efsd_monitor_cleanup_client(int client)
{
EfsdList *l;
@@ -862,7 +858,7 @@
client, m->filename, m->internal_use_count, m->client_use_count);
D("Removing client %i from monitor for %s\n", client, m->filename);
- m->clients = efsd_list_remove(m->clients, l, (EfsdFunc)monitor_request_free);
+ m->clients = efsd_list_remove(m->clients, l, (EfsdFunc)efsd_monitor_request_free);
if (m->client_use_count == 0 && m->internal_use_count == 0)
{
@@ -877,7 +873,7 @@
efsd_lock_release_read_access(monitors_lock);
efsd_hash_it_free(it);
- D_RETURN_(FALSE);
+ D_RETURN;
}
@@ -900,7 +896,7 @@
{
LOCK(&m->use_count_mutex);
m->clients = efsd_list_remove(m->clients, l,
- (EfsdFunc)monitor_request_free);
+ (EfsdFunc)efsd_monitor_request_free);
UNLOCK(&m->use_count_mutex);
}
}
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_monitor.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- efsd_monitor.h 2001/08/03 08:36:23 1.10
+++ efsd_monitor.h 2001/11/26 01:06:38 1.11
@@ -72,7 +72,7 @@
/* Which clients monitor this file,
and with what command id.
- list<EfsdFamRequest*>.
+ list<EfsdMonitorRequest*>.
*/
EfsdList *clients;
@@ -118,6 +118,10 @@
void efsd_monitor_init(void);
void efsd_monitor_cleanup(void);
+EfsdMonitorRequest *efsd_monitor_request_new(int client, EfsdFileCmd *cmd);
+void efsd_monitor_request_free(EfsdMonitorRequest *emr);
+
+
/* This one frees the monitor and removes it from
the list of registered monitors.
*/
@@ -141,7 +145,7 @@
/* Check for all monitors if they are requested by CLIENT
and in that case release those requests.
*/
-int efsd_monitor_cleanup_client(int client);
+void efsd_monitor_cleanup_client(int client);
/* Checks all monitoring requests for a particular monitor
and removes those requests that are no longer valid.
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_stack.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- efsd_stack.c 2001/08/23 14:25:50 1.2
+++ efsd_stack.c 2001/11/26 01:06:38 1.3
@@ -29,6 +29,14 @@
#include <stdio.h>
#include <stdlib.h>
+#ifdef DEBUG
+#undef DEBUG
+#endif
+
+#ifdef DEBUG_NEST
+#undef DEBUG_NEST
+#endif
+
#include <efsd_macros.h>
#include <efsd_debug.h>
#include <efsd_misc.h>
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/efsd_types.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- efsd_types.c 2001/08/01 08:53:04 1.18
+++ efsd_types.c 2001/11/26 01:06:38 1.19
@@ -74,8 +74,10 @@
case EFSD_CMD_CHMOD:
case EFSD_CMD_STARTMON_FILE:
case EFSD_CMD_STARTMON_DIR:
+ case EFSD_CMD_STARTMON_META:
case EFSD_CMD_STOPMON_FILE:
case EFSD_CMD_STOPMON_DIR:
+ case EFSD_CMD_STOPMON_META:
case EFSD_CMD_LISTDIR:
case EFSD_CMD_STAT:
case EFSD_CMD_LSTAT:
@@ -148,11 +150,24 @@
switch (ee_src->type)
{
case EFSD_EVENT_FILECHANGE:
- ee_dst->efsd_filechange_event.file = strdup(ee_src->efsd_filechange_event.file);
+ ee_dst->efsd_filechange_event.file =
+ strdup(ee_src->efsd_filechange_event.file);
break;
+ case EFSD_EVENT_METADATA_CHANGE:
+ ee_dst->efsd_metachange_event.file =
+ strdup(ee_src->efsd_metachange_event.file);
+
+ ee_dst->efsd_metachange_event.key =
+ strdup(ee_src->efsd_metachange_event.key);
+
+ d = malloc(sizeof(char) * ee_src->efsd_metachange_event.data_len);
+ memcpy(d, ee_src->efsd_metachange_event.data, ee_src->efsd_metachange_event.data_len);
+ ee_dst->efsd_metachange_event.data = d;
+ break;
case EFSD_EVENT_REPLY:
efsd_cmd_duplicate(&(ee_src->efsd_reply_event.command),
&(ee_dst->efsd_reply_event.command));
+
d = malloc(sizeof(char) * ee_src->efsd_reply_event.data_len);
memcpy(d, ee_src->efsd_reply_event.data, ee_src->efsd_reply_event.data_len);
ee_dst->efsd_reply_event.data = d;
@@ -194,13 +209,15 @@
case EFSD_CMD_MAKEDIR:
case EFSD_CMD_STOPMON_FILE:
case EFSD_CMD_STOPMON_DIR:
+ case EFSD_CMD_STOPMON_META:
+ case EFSD_CMD_STARTMON_DIR:
+ case EFSD_CMD_STARTMON_FILE:
+ case EFSD_CMD_STARTMON_META:
case EFSD_CMD_STAT:
case EFSD_CMD_LSTAT:
case EFSD_CMD_GETFILETYPE:
case EFSD_CMD_READLINK:
case EFSD_CMD_LISTDIR:
- case EFSD_CMD_STARTMON_DIR:
- case EFSD_CMD_STARTMON_FILE:
case EFSD_CMD_COPY:
case EFSD_CMD_MOVE:
case EFSD_CMD_SYMLINK:
@@ -259,8 +276,13 @@
switch (ev->type)
{
case EFSD_EVENT_REPLY:
- FREE(ev->efsd_reply_event.data);
+ FREE(ev->efsd_reply_event.data);
efsd_cmd_cleanup(&ev->efsd_reply_event.command);
+ break;
+ case EFSD_EVENT_METADATA_CHANGE:
+ FREE(ev->efsd_metachange_event.data);
+ FREE(ev->efsd_metachange_event.key);
+ FREE(ev->efsd_metachange_event.file);
break;
case EFSD_EVENT_FILECHANGE:
FREE(ev->efsd_filechange_event.file);
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/libefsd.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -3 -r1.54 -r1.55
--- libefsd.c 2001/11/16 22:05:36 1.54
+++ libefsd.c 2001/11/26 01:06:38 1.55
@@ -74,21 +74,26 @@
};
-static int send_command(EfsdConnection *ec, EfsdCommand *com);
-static EfsdCmdId get_next_id(void);
+static char *libefsd_get_full_path(char *file);
+static int libefsd_send_command(EfsdConnection *ec, EfsdCommand *com);
+static EfsdCmdId libefsd_get_next_id(void);
+
+static EfsdCmdId libefsd_file_cmd_absolute(EfsdConnection *ec, EfsdCommandType type,
+ int num_files, char **files,
+ int num_options, EfsdOption *ops);
+
+static EfsdCmdId libefsd_file_cmd(EfsdConnection *ec, EfsdCommandType type,
+ int num_files, char **files,
+ int num_options, EfsdOption *ops);
-static EfsdCmdId file_cmd(EfsdConnection *ec, EfsdCommandType type,
- int num_files, char **files,
- int num_options, EfsdOption *ops);
-
-static EfsdCmdId set_metadata_internal(EfsdConnection *ec, char *key, char *filename,
- EfsdDatatype datatype, int data_len, void *data);
+static EfsdCmdId libefsd_set_metadata_internal(EfsdConnection *ec, char *key, char *filename,
+ EfsdDatatype datatype, int data_len, void *data);
-static void cmd_queue_add_command(EfsdConnection *ec, EfsdCommand *com);
-static void cmd_queue_process(EfsdConnection *ec);
+static void libefsd_cmd_queue_add_command(EfsdConnection *ec, EfsdCommand *com);
+static void libefsd_cmd_queue_process(EfsdConnection *ec);
static char*
-get_full_path(char *file)
+libefsd_get_full_path(char *file)
{
char cwd[MAXPATHLEN];
char *result = NULL;
@@ -124,7 +129,7 @@
static int
-send_command(EfsdConnection *ec, EfsdCommand *com)
+libefsd_send_command(EfsdConnection *ec, EfsdCommand *com)
{
D_ENTER;
@@ -133,8 +138,8 @@
if (!efsd_queue_empty(ec->cmd_q))
{
- cmd_queue_add_command(ec, com);
- cmd_queue_process(ec);
+ libefsd_cmd_queue_add_command(ec, com);
+ libefsd_cmd_queue_process(ec);
}
else
{
@@ -145,7 +150,7 @@
D_RETURN_(-1);
}
- cmd_queue_add_command(ec, com);
+ libefsd_cmd_queue_add_command(ec, com);
}
}
@@ -154,7 +159,7 @@
static EfsdCmdId
-get_next_id(void)
+libefsd_get_next_id(void)
{
static EfsdCmdId id_counter = 0;
@@ -163,32 +168,24 @@
}
-static EfsdCmdId
-file_cmd(EfsdConnection *ec, EfsdCommandType type,
- int num_files, char **files,
- int num_options, EfsdOption *ops)
+static EfsdCmdId
+libefsd_file_cmd_absolute(EfsdConnection *ec, EfsdCommandType type,
+ int num_files, char **files,
+ int num_options, EfsdOption *ops)
{
char **full_files = NULL;
int i, used_files;
- EfsdCommand cmd;
EfsdCmdId id;
D_ENTER;
-
- if (!ec || !files)
- D_RETURN_(-1);
-
- memset(&cmd, 0, sizeof(EfsdCommand));
- cmd.type = type;
- cmd.efsd_file_cmd.id = get_next_id();
-
+ /* Array gets freed in efsd_cmd_cleanup() ... */
full_files = malloc(sizeof(char*) * num_files);
/* Hook in full paths of all given files, if possible. */
for (i = 0, used_files = 0; i < num_files; i++)
{
- full_files[used_files] = get_full_path(files[i]);
+ full_files[used_files] = libefsd_get_full_path(files[i]);
if (full_files[used_files])
used_files++;
}
@@ -202,13 +199,35 @@
FREE(full_files);
D_RETURN_(-1);
}
-
+
full_files = realloc(full_files, sizeof(char*) * used_files);
- num_files = used_files;
}
+ id = libefsd_file_cmd(ec, type, used_files, full_files, num_options, ops);
+
+ D_RETURN_(id);
+}
+
+
+static EfsdCmdId
+libefsd_file_cmd(EfsdConnection *ec, EfsdCommandType type,
+ int num_files, char **files,
+ int num_options, EfsdOption *ops)
+{
+ EfsdCommand cmd;
+ EfsdCmdId id;
+
+ D_ENTER;
+
+ if (!ec || !files)
+ D_RETURN_(-1);
+
+ memset(&cmd, 0, sizeof(EfsdCommand));
+
+ cmd.type = type;
+ cmd.efsd_file_cmd.id = libefsd_get_next_id();
cmd.efsd_file_cmd.num_files = num_files;
- cmd.efsd_file_cmd.files = full_files;
+ cmd.efsd_file_cmd.files = files;
/* Hook in any options: */
if ((num_options > 0) && (ops))
@@ -218,7 +237,7 @@
}
/* And send it! */
- if (send_command(ec, &cmd) < 0)
+ if (libefsd_send_command(ec, &cmd) < 0)
{
efsd_cmd_cleanup(&cmd);
D_RETURN_(-1);
@@ -231,8 +250,8 @@
static EfsdCmdId
-set_metadata_internal(EfsdConnection *ec, char *key, char *filename,
- EfsdDatatype datatype, int data_len, void *data)
+libefsd_set_metadata_internal(EfsdConnection *ec, char *key, char *filename,
+ EfsdDatatype datatype, int data_len, void *data)
{
EfsdCommand cmd;
EfsdCmdId id;
@@ -245,12 +264,12 @@
memset(&cmd, 0, sizeof(EfsdCommand));
cmd.type = EFSD_CMD_SETMETA;
- cmd.efsd_set_metadata_cmd.id = get_next_id();
+ cmd.efsd_set_metadata_cmd.id = libefsd_get_next_id();
cmd.efsd_set_metadata_cmd.datatype = datatype;
cmd.efsd_set_metadata_cmd.data_len = data_len;
cmd.efsd_set_metadata_cmd.data = data;
cmd.efsd_set_metadata_cmd.key = strdup(key);
- cmd.efsd_set_metadata_cmd.file = get_full_path(filename);
+ cmd.efsd_set_metadata_cmd.file = libefsd_get_full_path(filename);
if (!cmd.efsd_set_metadata_cmd.file)
goto error_return;
@@ -265,7 +284,7 @@
}
*/
- if (send_command(ec, &cmd) < 0)
+ if (libefsd_send_command(ec, &cmd) < 0)
goto error_return;
id = cmd.efsd_set_metadata_cmd.id;
@@ -279,7 +298,7 @@
static void
-cmd_queue_add_command(EfsdConnection *ec, EfsdCommand *com)
+libefsd_cmd_queue_add_command(EfsdConnection *ec, EfsdCommand *com)
{
EfsdCommand *com_copy;
@@ -297,7 +316,7 @@
static void
-cmd_queue_process(EfsdConnection *ec)
+libefsd_cmd_queue_process(EfsdConnection *ec)
{
EfsdCommand *cmd;
@@ -329,7 +348,8 @@
/* Efsd API starts here --------------------------------------------- */
-EfsdConnection * efsd_open(void)
+EfsdConnection *
+efsd_open(void)
{
struct sockaddr_un cli_sun;
EfsdConnection *ec;
@@ -374,7 +394,8 @@
}
-int efsd_get_connection_fd(EfsdConnection *ec)
+int
+efsd_get_connection_fd(EfsdConnection *ec)
{
D_ENTER;
@@ -385,7 +406,8 @@
}
-int efsd_close(EfsdConnection *ec)
+int
+efsd_close(EfsdConnection *ec)
{
EfsdCommand cmd;
@@ -397,7 +419,7 @@
memset(&cmd, 0, sizeof(EfsdCommand));
cmd.type = EFSD_CMD_CLOSE;
- if (send_command(ec, &cmd) < 0)
+ if (libefsd_send_command(ec, &cmd) < 0)
{
D_RETURN_(-1);
}
@@ -490,7 +512,7 @@
if (!ec)
D_RETURN_(-1);
- cmd_queue_process(ec);
+ libefsd_cmd_queue_process(ec);
D_RETURN_(efsd_queue_empty(ec->cmd_q));
}
@@ -505,9 +527,9 @@
D_ENTER;
if (ops)
- result = file_cmd(ec, EFSD_CMD_REMOVE, num_files, files, ops->num_used, ops->ops);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_REMOVE, num_files, files, ops->num_used, ops->ops);
else
- result = file_cmd(ec, EFSD_CMD_REMOVE, num_files, files, 0, NULL);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_REMOVE, num_files, files, 0, NULL);
FREE(ops);
@@ -523,9 +545,9 @@
D_ENTER;
if (ops)
- result = file_cmd(ec, EFSD_CMD_MOVE, num_files, files, ops->num_used, ops->ops);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_MOVE, num_files, files, ops->num_used, ops->ops);
else
- result = file_cmd(ec, EFSD_CMD_MOVE, num_files, files, 0, NULL);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_MOVE, num_files, files, 0, NULL);
FREE(ops);
@@ -541,9 +563,9 @@
D_ENTER;
if (ops)
- result = file_cmd(ec, EFSD_CMD_COPY, num_files, files, ops->num_used, ops->ops);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_COPY, num_files, files, ops->num_used, ops->ops);
else
- result = file_cmd(ec, EFSD_CMD_COPY, num_files, files, 0, NULL);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_COPY, num_files, files, 0, NULL);
FREE(ops);
@@ -560,7 +582,7 @@
D_ENTER;
files[0] = from_file; files[1] = to_file;
- result = file_cmd(ec, EFSD_CMD_SYMLINK, 2, files, 0, NULL);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_SYMLINK, 2, files, 0, NULL);
D_RETURN_(result);
}
@@ -575,9 +597,9 @@
D_ENTER;
if (ops)
- result = file_cmd(ec, EFSD_CMD_LISTDIR, 1, &dirname, ops->num_used, ops->ops);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_LISTDIR, 1, &dirname, ops->num_used, ops->ops);
else
- result = file_cmd(ec, EFSD_CMD_LISTDIR, 1, &dirname, 0, NULL);
+ result = libefsd_file_cmd_absolute(ec, EFSD_CMD_LISTDIR, 1, &dirname, 0, NULL);
FREE(ops);
@@ -589,7 +611,7 @@
efsd_makedir(EfsdConnection *ec, char *dirname)
{
D_ENTER;
- D_RETURN_(file_cmd(ec, EFSD_CMD_MAKEDIR, 1, &dirname, 0, NULL));
+ D_RETURN_(libefsd_file_cmd_absolute(ec, EFSD_CMD_MAKEDIR, 1, &dirname, 0, NULL));
}
@@ -606,14 +628,14 @@
memset(&cmd, 0, sizeof(EfsdCommand));
cmd.type = EFSD_CMD_CHMOD;
- cmd.efsd_chmod_cmd.id = get_next_id();
+ cmd.efsd_chmod_cmd.id = libefsd_get_next_id();
cmd.efsd_chmod_cmd.mode = mode;
- cmd.efsd_chmod_cmd.file = get_full_path(filename);
+ cmd.efsd_chmod_cmd.file = libefsd_get_full_path(filename);
if (!cmd.efsd_chmod_cmd.file)
goto error_return;
- if (send_command(ec, &cmd) < 0)
+ if (libefsd_send_command(ec, &cmd) < 0)
goto error_return;
id = cmd.efsd_chmod_cmd.id;
@@ -634,8 +656,8 @@
D_ENTER;
- id = set_metadata_internal(ec, key, filename, datatype,
- datalength, data);
+ id = libefsd_set_metadata_internal(ec, key, filename, datatype,
+ datalength, data);
D_RETURN_(id);
}
@@ -649,8 +671,8 @@
D_ENTER;
- id = set_metadata_internal(ec, key, filename, EFSD_INT,
- sizeof(int), &val);
+ id = libefsd_set_metadata_internal(ec, key, filename, EFSD_INT,
+ sizeof(int), &val);
D_RETURN_(id);
}
@@ -664,8 +686,8 @@
D_ENTER;
- id = set_metadata_internal(ec, key, filename, EFSD_FLOAT,
- sizeof(float), &val);
+ id = libefsd_set_metadata_internal(ec, key, filename, EFSD_FLOAT,
+ sizeof(float), &val);
D_RETURN_(id);
}
@@ -679,8 +701,8 @@
D_ENTER;
- id = set_metadata_internal(ec, key, filename, EFSD_STRING,
- strlen(val) + 1, val);
+ id = libefsd_set_metadata_internal(ec, key, filename, EFSD_STRING,
+ strlen(val) + 1, val);
D_RETURN_(id);
}
@@ -701,10 +723,10 @@
memset(&cmd, 0, sizeof(EfsdCommand));
cmd.type = EFSD_CMD_GETMETA;
- cmd.efsd_get_metadata_cmd.id = get_next_id();
+ cmd.efsd_get_metadata_cmd.id = libefsd_get_next_id();
cmd.efsd_get_metadata_cmd.datatype = datatype;
cmd.efsd_get_metadata_cmd.key = strdup(key);
- cmd.efsd_get_metadata_cmd.file = get_full_path(filename);
+ cmd.efsd_get_metadata_cmd.file = libefsd_get_full_path(filename);
if (!cmd.efsd_get_metadata_cmd.file)
goto error_return;
@@ -719,7 +741,7 @@
}
*/
- if (send_command(ec, &cmd) < 0)
+ if (libefsd_send_command(ec, &cmd) < 0)
goto error_return;
id = cmd.efsd_get_metadata_cmd.id;
@@ -737,15 +759,22 @@
{
D_ENTER;
- if ((ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA))
+ if (!ee)
+ D_RETURN_(0);
+
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA))
+ {
+ D_RETURN_(ee->efsd_reply_event.command.
+ efsd_get_metadata_cmd.datatype);
+ }
+
+ if (ee->type == EFSD_EVENT_METADATA_CHANGE)
{
- D_RETURN_(0);
+ D_RETURN_(ee->efsd_metachange_event.datatype);
}
- D_RETURN_(ee->efsd_reply_event.command.
- efsd_get_metadata_cmd.datatype);
+ D_RETURN_(0);
}
@@ -754,19 +783,26 @@
{
D_ENTER;
- if ((!val) ||
- (ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA) ||
+ if (!val || !ee)
+ D_RETURN_(0);
+
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA) &&
(ee->efsd_reply_event.command.
- efsd_get_metadata_cmd.datatype != EFSD_INT)
- )
+ efsd_get_metadata_cmd.datatype == EFSD_INT))
{
- D_RETURN_(0);
+ *val = *((int*)ee->efsd_reply_event.data);
+ D_RETURN_(1);
}
- *val = *((int*)ee->efsd_reply_event.data);
- D_RETURN_(1);
+ if ((ee->type == EFSD_EVENT_METADATA_CHANGE) &&
+ (ee->efsd_metachange_event.datatype == EFSD_INT))
+ {
+ *val = *((int*)ee->efsd_metachange_event.data);
+ D_RETURN_(1);
+ }
+
+ D_RETURN_(0);
}
@@ -775,19 +811,26 @@
{
D_ENTER;
- if ((!val) ||
- (ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA) ||
+ if (!val || !ee)
+ D_RETURN_(0);
+
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA) &&
(ee->efsd_reply_event.command.
- efsd_get_metadata_cmd.datatype != EFSD_FLOAT)
- )
+ efsd_get_metadata_cmd.datatype == EFSD_FLOAT))
+ {
+ *val = *((float*)ee->efsd_reply_event.data);
+ D_RETURN_(1);
+ }
+
+ if ((ee->type == EFSD_EVENT_METADATA_CHANGE) &&
+ (ee->efsd_metachange_event.datatype == EFSD_FLOAT))
{
- D_RETURN_(0);
+ *val = *((float*)ee->efsd_metachange_event.data);
+ D_RETURN_(1);
}
- *val = *((float*)ee->efsd_reply_event.data);
- D_RETURN_(1);
+ D_RETURN_(0);
}
@@ -796,50 +839,54 @@
{
D_ENTER;
- if ((ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA) ||
+ if (!ee)
+ D_RETURN_(NULL);
+
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA) &&
(ee->efsd_reply_event.command.
- efsd_get_metadata_cmd.datatype != EFSD_STRING)
- )
+ efsd_get_metadata_cmd.datatype == EFSD_STRING))
{
- D_RETURN_(NULL);
+ D_RETURN_((char*)ee->efsd_reply_event.data);
}
+
+ if ((ee->type == EFSD_EVENT_METADATA_CHANGE) &&
+ (ee->efsd_metachange_event.datatype == EFSD_STRING))
+ {
+ D_RETURN_((char*)ee->efsd_metachange_event.data);
+ }
- D_RETURN_(strdup((char*)ee->efsd_reply_event.data));
+ D_RETURN_(NULL);
}
void *
efsd_metadata_get_raw(EfsdEvent *ee, int *data_len)
{
- void *result;
-
D_ENTER;
- if ((ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA) ||
+ if (!ee || !data_len)
+ D_RETURN_(NULL);
+
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA) &&
(ee->efsd_reply_event.command.
- efsd_get_metadata_cmd.datatype != EFSD_FLOAT)
- )
+ efsd_get_metadata_cmd.datatype == EFSD_RAW))
{
- D_RETURN_(NULL);
- }
-
- if (data_len)
- {
*data_len = ee->efsd_reply_event.data_len;
+
+ D_RETURN_(ee->efsd_reply_event.data);
}
- if ((result = malloc(ee->efsd_reply_event.data_len)) == NULL)
+ if ((ee->type == EFSD_EVENT_METADATA_CHANGE) &&
+ (ee->efsd_metachange_event.datatype == EFSD_RAW))
{
- D_RETURN_(NULL);
- }
-
- memcpy(result, ee->efsd_reply_event.data, ee->efsd_reply_event.data_len);
+ *data_len = ee->efsd_metachange_event.data_len;
- D_RETURN_(result);
+ D_RETURN_(ee->efsd_metachange_event.data);
+ }
+
+ D_RETURN_(NULL);
}
@@ -848,14 +895,18 @@
{
D_ENTER;
- if ((ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA))
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA))
{
- D_RETURN_(NULL);
+ D_RETURN_((char*)ee->efsd_reply_event.command.efsd_get_metadata_cmd.key);
}
- D_RETURN_(ee->efsd_reply_event.command.efsd_get_metadata_cmd.key);
+ if (ee->type == EFSD_EVENT_METADATA_CHANGE)
+ {
+ D_RETURN_((char*)ee->efsd_metachange_event.key);
+ }
+
+ D_RETURN_(NULL);
}
@@ -864,14 +915,18 @@
{
D_ENTER;
- if ((ee->type != EFSD_EVENT_REPLY) ||
- (ee->efsd_reply_event.command.type !=
- EFSD_CMD_GETMETA))
+ if ((ee->type == EFSD_EVENT_REPLY) &&
+ (ee->efsd_reply_event.command.type == EFSD_CMD_GETMETA))
{
- D_RETURN_(NULL);
+ D_RETURN_((char*)ee->efsd_reply_event.command.efsd_get_metadata_cmd.file);
+ }
+
+ if (ee->type == EFSD_EVENT_METADATA_CHANGE)
+ {
+ D_RETURN_((char*)ee->efsd_metachange_event.file);
}
- D_RETURN_(ee->efsd_reply_event.command.efsd_get_metadata_cmd.file);
+ D_RETURN_(NULL);
}
@@ -897,9 +952,9 @@
type = EFSD_CMD_STARTMON_FILE;
if (ops)
- result = file_cmd(ec, type, 1, &filename, ops->num_used, ops->ops);
+ result = libefsd_file_cmd_absolute(ec, type, 1, &filename, ops->num_used, ops->ops);
else
- result = file_cmd(ec, type, 1, &filename, 0, NULL);
+ result = libefsd_file_cmd_absolute(ec, type, 1, &filename, 0, NULL);
FREE(ops);
@@ -919,15 +974,51 @@
else
type = EFSD_CMD_STOPMON_FILE;
- D_RETURN_(file_cmd(ec, type, 1, &filename, 0, NULL));
+ D_RETURN_(libefsd_file_cmd_absolute(ec, type, 1, &filename, 0, NULL));
}
EfsdCmdId
+efsd_start_monitor_metadata(EfsdConnection *ec, char *filename, char *key)
+{
+ char **file_key_pair = NULL;
+
+ D_ENTER;
+
+ if (!filename || !*filename || !key || !*key)
+ D_RETURN_(-1);
+
+ file_key_pair = malloc(sizeof(char*) * 2);
+ file_key_pair[0] = libefsd_get_full_path(filename);
+ file_key_pair[1] = strdup(key);
+
+ D_RETURN_(libefsd_file_cmd(ec, EFSD_CMD_STARTMON_META, 2, file_key_pair, 0, NULL));
+}
+
+
+EfsdCmdId
+efsd_stop_monitor_metadata(EfsdConnection *ec, char *filename, char *key)
+{
+ char **file_key_pair = NULL;
+
+ D_ENTER;
+
+ if (!filename || !*filename || !key || !*key)
+ D_RETURN_(-1);
+
+ file_key_pair = malloc(sizeof(char*) * 2);
+ file_key_pair[0] = libefsd_get_full_path(filename);
+ file_key_pair[1] = strdup(key);
+
+ D_RETURN_(libefsd_file_cmd(ec, EFSD_CMD_STOPMON_META, 2, file_key_pair, 0, NULL));
+}
+
+
+EfsdCmdId
efsd_stat(EfsdConnection *ec, char *filename)
{
D_ENTER;
- D_RETURN_(file_cmd(ec, EFSD_CMD_STAT, 1, &filename, 0, NULL));
+ D_RETURN_(libefsd_file_cmd_absolute(ec, EFSD_CMD_STAT, 1, &filename, 0, NULL));
}
@@ -935,7 +1026,7 @@
efsd_lstat(EfsdConnection *ec, char *filename)
{
D_ENTER;
- D_RETURN_(file_cmd(ec, EFSD_CMD_LSTAT, 1, &filename, 0, NULL));
+ D_RETURN_(libefsd_file_cmd_absolute(ec, EFSD_CMD_LSTAT, 1, &filename, 0, NULL));
}
@@ -943,7 +1034,7 @@
efsd_readlink(EfsdConnection *ec, char *filename)
{
D_ENTER;
- D_RETURN_(file_cmd(ec, EFSD_CMD_READLINK, 1, &filename, 0, NULL));
+ D_RETURN_(libefsd_file_cmd_absolute(ec, EFSD_CMD_READLINK, 1, &filename, 0, NULL));
}
@@ -951,7 +1042,7 @@
efsd_get_filetype(EfsdConnection *ec, char *filename)
{
D_ENTER;
- D_RETURN_(file_cmd(ec, EFSD_CMD_GETFILETYPE, 1, &filename, 0, NULL));
+ D_RETURN_(libefsd_file_cmd_absolute(ec, EFSD_CMD_GETFILETYPE, 1, &filename, 0, NULL));
}
@@ -1107,7 +1198,7 @@
char *
-efsd_reply_filename(EfsdEvent *ee)
+efsd_event_filename(EfsdEvent *ee)
{
D_ENTER;
@@ -1117,6 +1208,9 @@
if (ee->type == EFSD_EVENT_FILECHANGE)
D_RETURN_(ee->efsd_filechange_event.file);
+ if (ee->type == EFSD_EVENT_METADATA_CHANGE)
+ D_RETURN_(ee->efsd_metachange_event.file);
+
switch (ee->efsd_reply_event.command.type)
{
case EFSD_CMD_REMOVE:
@@ -1153,7 +1247,7 @@
EfsdCmdId
-efsd_reply_id(EfsdEvent *ee)
+efsd_event_id(EfsdEvent *ee)
{
D_ENTER;
@@ -1163,6 +1257,9 @@
if (ee->type == EFSD_EVENT_FILECHANGE)
D_RETURN_(ee->efsd_filechange_event.id);
+ if (ee->type == EFSD_EVENT_METADATA_CHANGE)
+ D_RETURN_(ee->efsd_metachange_event.id);
+
switch (ee->efsd_reply_event.command.type)
{
case EFSD_CMD_REMOVE:
@@ -1199,16 +1296,24 @@
void *
-efsd_reply_data(EfsdEvent *ee)
+efsd_event_data(EfsdEvent *ee)
{
D_ENTER;
if (!ee)
D_RETURN_(NULL);
-
- if (ee->type != EFSD_EVENT_REPLY)
- D_RETURN_(NULL);
- D_RETURN_(ee->efsd_reply_event.data);
+ switch (ee->type)
+ {
+ case EFSD_EVENT_REPLY:
+ D_RETURN_(ee->efsd_reply_event.data);
+ break;
+ case EFSD_EVENT_METADATA_CHANGE:
+ D_RETURN_(ee->efsd_metachange_event.data);
+ break;
+ default:
+ }
+
+ D_RETURN_(NULL);
}
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/libefsd.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -3 -r1.43 -r1.44
--- libefsd.h 2001/11/16 16:44:15 1.43
+++ libefsd.h 2001/11/26 01:06:38 1.44
@@ -460,36 +460,37 @@
/**
- * efsd_reply_filename - returns filename contained in an event.
+ * efsd_event_filename - returns filename contained in an event.
* @ee: The EfsdEvent.
*
- * Convenience function to access the filenames in reply or
- * filechange events. If the event is a reply event and the
+ * Convenience function to access the filenames in received
+ * events. If the event is a reply event and the
* contained command is an efsd_file_cmd, it returns the first file
- * (efsd_file_cmd.files[0]). Returns %NULL if no file could be
- * found.
+ * (efsd_file_cmd.files[0]). For filechange events, it returns
+ * efsd_filechange_event.file. Returns %NULL otherwise.
*/
-char *efsd_reply_filename(EfsdEvent *ee);
+char *efsd_event_filename(EfsdEvent *ee);
/**
- * efsd_reply_id - returns command id contained in an event.
+ * efsd_event_id - returns command id contained in an event.
* @ee: The EfsdEvent.
*
- * Convenience function to access the command ID in reply or
- * filechange events. Returns -1 if no ID is contained in the event.
+ * Convenience function to access the command ID in received
+ * events. Returns -1 if no ID is contained in the event.
*/
-EfsdCmdId efsd_reply_id(EfsdEvent *ee);
+EfsdCmdId efsd_event_id(EfsdEvent *ee);
/**
- * efsd_reply_data - returns data contained in a reply event
+ * efsd_event_data - returns data contained in a event
* @ee: The EfsdEvent.
*
- * Convenience function access the data returned in a reply
- * event. Returns NULL if an error occured.
+ * Convenience function access the data returned in a received
+ * event. Returns NULL if the event does not contain any
+ * returned data, or if the command is not applicable.
*/
-void *efsd_reply_data(EfsdEvent *ee);
+void *efsd_event_data(EfsdEvent *ee);
/**
@@ -533,6 +534,31 @@
* be sent to the client that requested the monitoring to be stopped.
*/
EfsdCmdId efsd_stop_monitor(EfsdConnection *ec, char *filename, int dir_mode);
+
+
+/**
+ * efsd_start_monitor_metadata - starts monitoring metadata.
+ * @ec: The Efsd connection.
+ * @filename: The file with metadata entries to be monitored.
+ * @key: The key of the metadata item that is to be monitored.
+ *
+ * This command requests monitoring of the metadata associated
+ * to the given @key on the given @filename. The client issuing
+ * this command will receive events of type %EFSD_EVENT_METADATA_CHANGE
+ * when the specified metadata entry changes.
+ */
+EfsdCmdId efsd_start_monitor_metadata(EfsdConnection *ec, char *filename, char *key);
+
+/**
+ * efsd_stop_monitor_metadata - stops monitoring metadata.
+ * @ec: The Efsd connection.
+ * @filename: The file with a metadata entry that is monitored.
+ * @key: The key of the metadata item that no longer needs to be monitored.
+ *
+ * This command stops monitoring of the metadata associated
+ * to the given @key on the given @filename.
+ */
+EfsdCmdId efsd_stop_monitor_metadata(EfsdConnection *ec, char *filename, char *key);
/**
* efsd_stat - returns the result of stat() on a file.
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/efsd/efsd/libefsd_misc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- libefsd_misc.c 2001/09/30 18:35:07 1.3
+++ libefsd_misc.c 2001/11/26 01:06:38 1.4
@@ -34,6 +34,7 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <pwd.h>
#ifdef __EMX__
#include <stdlib.h>
@@ -88,31 +89,22 @@
char *
misc_get_user_dir(void)
{
- char *dir = NULL;
- static char s[4096] = "\0";
-
+ static char s[4096] = "\0";
+ struct passwd *pw = NULL;
+
D_ENTER;
if (s[0] != '\0')
D_RETURN_(s);
-
- dir = getenv("HOME");
-
- /* I'm not using getenv("TMPDIR") --
- * I don't see TMPDIR on Linux, FreeBSD
- * or Solaris here...
- */
-
- /* FIXME -- I need to properly handle the case
- where I cannot determine the home directory.
- This will break if multiple users run E on the
- same machine:
- */
-
- if (!dir)
- dir = "/tmp";
- snprintf(s, sizeof(s), "%s/.e/efsd", dir);
+ if ( (pw = getpwuid(geteuid())))
+ {
+ snprintf(s, MAXPATHLEN, "%s/.e/efsd", pw->pw_dir);
+ }
+ else
+ {
+ snprintf(s, MAXPATHLEN, "/tmp/.e_%u/efsd", geteuid());
+ }
D_RETURN_(s);
}
|