From: "Michał Poczwardowski" <dmp0x7c5@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: "Michał Poczwardowski" <dmp0x7c5@gmail.com>
Subject: [RFC v1 obexd 08/11] fuse: Add write operation
Date: Sun, 21 Oct 2012 19:05:28 +0200 [thread overview]
Message-ID: <1350839131-12042-8-git-send-email-dmp0x7c5@gmail.com> (raw)
In-Reply-To: <1350839131-12042-1-git-send-email-dmp0x7c5@gmail.com>
---
fuse/helpers.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
fuse/helpers.h | 3 +++
fuse/obexfuse.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 92 insertions(+), 0 deletions(-)
diff --git a/fuse/helpers.c b/fuse/helpers.c
index 9b453e0..b807f15 100644
--- a/fuse/helpers.c
+++ b/fuse/helpers.c
@@ -577,3 +577,48 @@ struct gobexhlp_buffer *gobexhlp_get(struct gobexhlp_session* session,
return buffer;
}
+
+static gssize async_put_producer(void *buf, gsize len, gpointer user_data)
+{
+ gssize size;
+ struct gobexhlp_session *session = user_data;
+ struct gobexhlp_buffer *buffer = session->buffer;
+
+ size = buffer->size - buffer->tmpsize;
+
+ if (size > len)
+ size = len;
+
+ g_obex_suspend(session->obex);
+ g_obex_resume(session->obex);
+
+ if (size == 0)
+ return 0;
+
+ memcpy(buf, buffer->data + buffer->tmpsize, size);
+ buffer->tmpsize += size;
+
+ return size;
+}
+
+void gobexhlp_put(struct gobexhlp_session* session,
+ struct gobexhlp_buffer *buffer,
+ const char *path)
+{
+ struct gobexhlp_location *l;
+ l = get_location(path);
+
+ g_print("gobexhlp_put(%s%s)\n", l->dir, l->file);
+
+ gobexhlp_setpath(session, l->dir);
+ buffer->tmpsize = 0;
+ session->buffer = buffer;
+ request_new(session, g_strdup_printf("put %s", path));
+ g_obex_put_req(session->obex, async_put_producer,
+ complete_func, session, &session->err,
+ G_OBEX_HDR_NAME, l->file,
+ G_OBEX_HDR_INVALID);
+ free_location(l);
+ request_wait_free(session);
+}
+
diff --git a/fuse/helpers.h b/fuse/helpers.h
index 50c750d..95987c4 100644
--- a/fuse/helpers.h
+++ b/fuse/helpers.h
@@ -56,4 +56,7 @@ struct stat *gobexhlp_getattr(struct gobexhlp_session* session,
const char *path);
struct gobexhlp_buffer *gobexhlp_get(struct gobexhlp_session* session,
const char *path);
+void gobexhlp_put(struct gobexhlp_session* session,
+ struct gobexhlp_buffer *buffer,
+ const char *path);
diff --git a/fuse/obexfuse.c b/fuse/obexfuse.c
index 9fe2dea..900e6d7 100644
--- a/fuse/obexfuse.c
+++ b/fuse/obexfuse.c
@@ -174,11 +174,55 @@ static int obexfuse_read(const char *path, char *buf, size_t size,
return asize;
}
+static int obexfuse_write(const char *path, const char *buf, size_t size,
+ off_t offset, struct fuse_file_info *fi)
+{
+ gsize nsize;
+ struct gobexhlp_buffer *file_buffer = (struct gobexhlp_buffer*)fi->fh;
+
+ if (file_buffer->size < offset + size) {
+ nsize = offset + size;
+ file_buffer->data = g_realloc(file_buffer->data, nsize);
+ file_buffer->size = nsize;
+ } else {
+ nsize = file_buffer->size;
+ }
+
+ file_buffer->edited = TRUE;
+ memcpy(file_buffer->data + offset, buf, size);
+
+ return size;
+}
+
+static int obexfuse_truncate(const char *path, off_t offset)
+{
+ /*
+ * Allow to change the size of a file.
+ */
+ return 0;
+}
+
+static int obexfuse_release(const char *path, struct fuse_file_info *fi)
+{
+ struct gobexhlp_buffer *file_buffer = (struct gobexhlp_buffer*)fi->fh;
+
+ if (file_buffer->edited == TRUE)
+ gobexhlp_put(session, file_buffer, path); /* send to device */
+
+ g_free(file_buffer->data);
+ g_free(file_buffer);
+
+ return session->status;
+}
+
static struct fuse_operations obexfuse_oper = {
.readdir = obexfuse_readdir,
.getattr = obexfuse_getattr,
.open = obexfuse_open,
.read = obexfuse_read,
+ .write = obexfuse_write,
+ .truncate = obexfuse_truncate,
+ .release = obexfuse_release,
.init = obexfuse_init,
.destroy = obexfuse_destroy,
};
--
1.7.8.6
next prev parent reply other threads:[~2012-10-21 17:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-21 17:05 [RFC v1 obexd 01/11] fuse: Add initial obexfuse files, fuse main and options parse Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 02/11] build: Add --enable-fuse for obexfuse Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 03/11] fuse: Add obexhlp_connect/disconnect functions with helpers Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 04/11] fuse: Add request helpers and setpath operation Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 05/11] fuse: Add readdir operation Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 06/11] fuse: Add getattr operation Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 07/11] fuse: Add open and read operations plus location helpers Michał Poczwardowski
2012-10-21 17:05 ` Michał Poczwardowski [this message]
2012-10-21 17:05 ` [RFC v1 obexd 09/11] fuse: Add touch operation Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 10/11] fuse: Add unlink/rmdir operation Michał Poczwardowski
2012-10-21 17:05 ` [RFC v1 obexd 11/11] fuse: Add rename operation Michał Poczwardowski
2012-10-26 14:10 ` [RFC v1 obexd 01/11] fuse: Add initial obexfuse files, fuse main and options parse Luiz Augusto von Dentz
2012-10-26 14:14 ` Luiz Augusto von Dentz
2012-10-27 23:24 ` Michał Poczwardowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1350839131-12042-8-git-send-email-dmp0x7c5@gmail.com \
--to=dmp0x7c5@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox