replacing file contents in a vfs module

Richard Sharpe realrichardsharpe at gmail.com
Tue Apr 21 20:20:54 MDT 2015


On Tue, Apr 21, 2015 at 6:48 PM, Jakub Szarlat <jakubjs at wehi.edu.au> wrote:
> Hi Richard.
>
> The issue I'm still having is the length value passed to pread. Even though my pread function stores the full string into the data variable. The data sent to the client is only equal to the length value. I'm not sure where this is set to and passed as the 4th parameter.
>
> This is my test pread function
>
>
> static ssize_t stornext_pread(vfs_handle_struct *handle, files_struct *fsp,
>                            void *data, size_t n, off_t offset)
> {
>         ssize_t result;
>         int fh;
>
>
>         if( strcmp(fsp->fsp_name->base_name,"aaa/test.txt")==0){
>                 fh = open("/tmp/test.txt",O_RDONLY);
>                 //result= pread(fh,data,n,offset);
>                 result= read(fh,data,1024);
>                 close(fh);
>                 DEBUG(1, ("PREAD file name: '%s' %d %d %d\n",  data,n,fsp->fh->pos,strlen(data)));
>                 fsp->fh->pos=0;
>                 return result;
>         }else{
>                 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
>         }
>         //result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
>
>         return result;
> }
>
> This is the debug data I get from my PREAD
>   PREAD file name: 'Tes hello there
>   ����� ' 12 0 22
>
> but client reading the file only gets
> Tes hello th

So, you didn't print out the value of result, so you do not know how
many bytes the read actually returned. Maybe it only returned  12
bytes, which appears to be what was asked for.

It seems like your earlier stat call is saying that the file is only
12 bytes long.

Even though you asked it to read 1024 bytes and there was 15 bytes in
the file, if the client only asks for 12, that is all it will get, I
guess.

Did you grab a capture to see what was being returned in the Get Info call etc?

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list