Samba and MS Shadow Copy

Ken Cross kcross at nssolutions.com
Mon Aug 4 17:22:31 GMT 2003


Samba-folk:

Microsoft's Shadow Copy is their version of snapshots for NTFS.  It is
standard in Windows Server 2003.  Windows Explorer can very conveniently
view "Previous Versions" of files and/or directories.  (To add this feature
to Explorer on XP or Win2k SP3 or higher, see
http://www.microsoft.com/downloads/details.aspx?FamilyID=e382358f-33c3-4de7-
acd8-a33ac92d295e)

Some file systems, including ours at Network Storage Solutions, have
snapshot capability.  Adding this support in Samba involves the 3 steps
described below.  (Much of this is extremely vendor-specific, so sample code
wouldn't mean much on another file system.)

All of this applies to SAMBA_3_0.


-----------------------

1.  Handle the request.

The request from the Windows client is an NT IOCTL, 0x00144064.  It must be
added to the switch statement in call_nt_transact_ioctl in smbd/nttrans.c.
See attached diff files.



-----------------------

2.  Provide a VFS handler.

This is a new VFS function and must be added to vfs.h and vfs_macros.h, and
a default handler added to vfs.c and vfs-wrap.c.  See attached diff files
and the documentation about those modules.

The VFS handler is passed 2 arguments: "max_data_count", the maximum amount
of data (bytes) that can be returned; and "pdata", a pointer to:

typedef struct

{

    uint32      num_volumes;    /* Total number of shadow volumes currently
mounted */                                              
    uint32      num_labels;     /* Number of volume labels in the "labels"
array */                                                 
    uint32      data_size;      /* Total bytes being sent back */

    smb_ucs2_t  labels[2];      /* Concatenated list of null-terminated UCS2
(2-byte) labels */                                     
} SHADOW_COPY_DATA;


num_volumes is the number of snapshots available for this volume.
Determining this value is highly dependent on the file system.

data_size should be 50 * num_volumes, since each label is exactly 50 bytes
long (24 UCS2 characters + 1 UCS2 null terminator).

If max_data_count == sizeof( SHADOW_COPY_DATA ) == 16, then the handler must
compute num_volumes and data_size, and the other elements must be zero.
Nothing should be returned in labels.

If max_data_count > 16, then fill the labels array with UCS2 strings in
*exactly* this format:

   @GMT-YYYY.MM.DD-HH.MM.SS

which is the timestamp of the snapshot, e.g., "@GMT-2003.03.03-03.04.04".
Set num_labels to the number of labels provided (should be the same as
num_volumes).



-----------------------

3.  Convert Shadow Copy filenames to snapshot filenames.

A VFS routine must intercept any file operations that may reference a Shadow
Copy filename.  

For example, "@GMT-2003.03.03-03.04.04/File.txt" would be the snapshot of
"File.txt" taken March 3, 2003 at 3:04:04 GMT.  So if that snapshot was
mounted on /mnt/snap1234, the string would be converted to
"/mnt/snap1234/File.txt".

This must be done for any file operation that takes a path for an argument.
There are a *lot* of them, especially if you include ACL operations and/or
extended attributes.



-----------------------

Limitations in Windows Explorer

MS only has up to 64 Shadow Copies available.  If your file system has more
(we have 4096), you must limit the list sent to Windows Explorer to the most
recent 250 snapshots.  Otherwise, it chokes.



-----------------------

DISCLAIMER

This information has been developed through the usual tedious process of
reverse-engineering.  I make no claims about its accuracy or whether it will
stay this way.  All I can say is that it seems to work for me at the moment.


Ken
________________________________

Ken Cross

Network Storage Solutions
Phone 865.675.4070 ext 31
kcross at nssolutions.com 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ntioctl_h.diff
Type: application/octet-stream
Size: 588 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030804/e4139d26/ntioctl_h.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nttrans_c.diff
Type: application/octet-stream
Size: 2182 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030804/e4139d26/nttrans_c.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vfs_c.diff
Type: application/octet-stream
Size: 521 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030804/e4139d26/vfs_c.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vfs_h.diff
Type: application/octet-stream
Size: 1374 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030804/e4139d26/vfs_h.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vfs_macros_h.diff
Type: application/octet-stream
Size: 2496 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030804/e4139d26/vfs_macros_h.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vfs-wrap_c.diff
Type: application/octet-stream
Size: 592 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030804/e4139d26/vfs-wrap_c.obj


More information about the samba-technical mailing list