[Win32utils-devel] Dir.create_junction with FFI

Heesob Park phasis at gmail.com
Fri May 18 03:44:57 UTC 2012


Hi,

2012/5/18 Daniel Berger <djberg96 at gmail.com>

> Hi,
>
> Try as I might, I just cannot get Dir.create_junction to work with FFI
> in the ffi branch of the win32-dir project. The problem is the
> REPARSE_JDATA_BUFFER struct. I'm just not sure how to set those
> members, specifically, the PathBuffer member. The target looks good,
> it's UTF-16LE encoded, but I can't make it work, despite trying
> several ways of defining the struct, and setting various struct
> members.
>
> A quick gist for reference: https://gist.github.com/2721257
>
> Help much appreciated!
>
>
The REPARSE_JDATA_BUFFER  is a kind of  the variable length structure.
The actual size of structure is determined by ReparseDataLength member.

Here is my trial.

# define sufficient size of structure.
class REPARSE_JDATA_BUFFER < FFI::Struct
    layout(
      :ReparseTag, :ulong,
      :ReparseDataLength, :ushort,
      :Reserved, :ushort,
      :SubstituteNameOffset, :ushort,
      :SubstituteNameLength, :ushort,
      :PrintNameOffset, :ushort,
      :PrintNameLength, :ushort,
      :PathBuffer, [:char, 1024]
    )
end

 # UTF-16LE encoded string
  target = "\\??\\".encode('UTF-16LE') + from_path

  rdb = REPARSE_JDATA_BUFFER.new
  rdb[:ReparseTag] = 2684354563 # IO_REPARSE_TAG_MOUNT_POINT
  rdb[:ReparseDataLength] = target.bytesize + 12
  rdb[:Reserved] = 0
  rdb[:SubstituteNameOffset] = 0
  rdb[:SubstituteNameLength] = target.bytesize
  rdb[:PrintNameOffset] = target.bytesize + 2
  rdb[:PrintNameLength] = 0
  rdb[:PathBuffer]  = target


Regards,
Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20120518/239606e1/attachment.html>


More information about the win32utils-devel mailing list