replacing file contents in a vfs module

Jakub Szarlat jakubjs at wehi.EDU.AU
Tue Apr 21 19:48:10 MDT 2015


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


cheers,
Jakub 


----- Original Message -----
From: "Richard Sharpe" <realrichardsharpe at gmail.com>
To: "Jakub Szarlat" <jakubjs at wehi.edu.au>
Cc: "samba-technical" <samba-technical at lists.samba.org>
Sent: Tuesday, 21 April, 2015 2:29:14 PM
Subject: Re: replacing file contents in a vfs module

On Mon, Apr 20, 2015 at 5:00 PM, Jakub Szarlat <jakubjs at wehi.edu.au> wrote:
> Hi Richard
>
> Thank you for your suggestion. I've added a pread function to my module.
>  However it only returns the data size that is equal to that of the original file. Is
> this defined in the fsp?

This is what you would have to do:

    struct my_struct *p_var = NULL;
    p_var = (struct my_struct *)VFS_FETCH_FSP_EXTENSION(handle, fsp);

   if (!p_var) {
       /* Get the fd for that special file from my_struct and use it
to return the data */
   } else {
      return SMB_VFS_NEXT_PREAD(...);
   }

Of course, in the open routine you will need to detect that the file
is offline and add the FSP extension.

There is some info here:

https://wiki.samba.org/index.php/Writing_a_Samba_VFS_Module#Extending_the_Samba_files_struct_structure


> cheers,
> Jakub
>
>
> ----- Original Message -----
> From: "Richard Sharpe" <realrichardsharpe at gmail.com>
> To: "Jakub Szarlat" <jakubjs at wehi.edu.au>
> Cc: "samba-technical" <samba-technical at lists.samba.org>
> Sent: Monday, 20 April, 2015 1:05:15 PM
> Subject: Re: replacing file contents in a vfs module
>
> On Sun, Apr 19, 2015 at 7:36 PM, Jakub Szarlat <jakubjs at wehi.edu.au> wrote:
>> Hi
>>
>> I'm writing a vfs module to handle the blocking of file access ot our offline files (we use Quantum Stornext as our file system). Everything is working fine except that unlike windows the Mac has no appreciation of offlien files and does not display an icon overlay to visualize the files status. (Blocking does work)
>>
>> So the idea I had is to present a different ._ corresponding file which would contain a custom icon when a file is offline. I attempted this by changing the smb_fname->base_name in my vfs open_fn function. However this causes an inode does not match error. How can I redirect which file is open without modifying the original?
>
> How about you an an FSP extension for those files that are offline and
> keep the info you need to return the content of the special file in
> the FSP extension?
>
> --
> Regards,
> Richard Sharpe
> (何以解憂?唯有杜康。--曹操)
>
> ______________________________________________________________________
> The information in this email is confidential and intended solely for the addressee.
> You must not disclose, forward, print or use it without the permission of the sender.
> ______________________________________________________________________



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

______________________________________________________________________
The information in this email is confidential and intended solely for the addressee.
You must not disclose, forward, print or use it without the permission of the sender.
______________________________________________________________________


More information about the samba-technical mailing list