changeset 21674:74d09d421f72

support for writing over smb shares
author nicodvb
date Tue, 19 Dec 2006 22:31:10 +0000
parents 38cbc1a55fb5
children ca7914b0cf5e
files stream/stream_smb.c
diffstat 1 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/stream/stream_smb.c	Tue Dec 19 21:11:58 2006 +0000
+++ b/stream/stream_smb.c	Tue Dec 19 22:31:10 2006 +0000
@@ -55,6 +55,20 @@
    if (temp[0]) strncpy(password, temp, pwmaxlen - 1);
 }
 
+static int control(stream_t *s, int cmd, void *arg) {
+  switch(cmd) {
+    case STREAM_CTRL_GET_SIZE: {
+      off_t size = smbc_lseek(s->fd,0,SEEK_END);
+      smbc_lseek(s->fd,s->pos,SEEK_SET);
+      if(size != (off_t)-1) {
+        *((off_t*)arg) = size;
+        return 1;
+      }
+    }
+  }
+  return STREAM_UNSUPORTED;
+}
+
 static int seek(stream_t *s,off_t newpos) {
   s->pos = newpos;
   if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) {
@@ -90,7 +104,7 @@
   if(mode == STREAM_READ)
     m = O_RDONLY;
   else if (mode == STREAM_WRITE) //who's gonna do that ?
-    m = O_WRONLY;
+    m = O_RDWR|O_CREAT;
   else {
     mp_msg(MSGT_OPEN, MSGL_ERR, "[smb] Unknown open mode %d\n", mode);
     m_struct_free (&stream_opts, opts);
@@ -117,20 +131,23 @@
     return STREAM_ERROR;
   }
   
+  stream->flags = mode;
+  len = 0;
+  if(mode == STREAM_READ) {
   len = smbc_lseek(fd,0,SEEK_END);
   smbc_lseek (fd, 0, SEEK_SET);
-  if (len <= 0)
-    stream->flags = 0;
-  else {
-    stream->flags = STREAM_READ | STREAM_SEEK;
-    stream->end_pos = len;
+  }
+  if(len > 0 || mode == STREAM_WRITE) {
+    stream->flags |= STREAM_SEEK;
     stream->seek = seek;
+    if(mode == STREAM_READ) stream->end_pos = len;
   }
   stream->type = STREAMTYPE_SMB;
   stream->fd = fd;
   stream->fill_buffer = fill_buffer;
   stream->write_buffer = write_buffer;
   stream->close = close_f;
+  stream->control = control;
   
   m_struct_free(&stream_opts, opts);
   return STREAM_OK;