// Creating a directory junction on windows involves dealing with reparse
// points and the DeviceIoControl function, and this code is a skeleton of
// what can be found here:
//
// http://www.flexhex.com/docs/articles/hard-links.phtml
Creating a directory junction on windows involves dealing with reparse
points and the DeviceIoControl function, and this code is a skeleton of
what can be found here.


Creating a directory junction on windows involves dealing with reparse points and the DeviceIoControl function and this code is a skeleton of what can be found here .
fn create_junction(src: &Path, dst: &Path) -> io::Result<()> {
        let f = try!(opendir(src, true));
        let h = f.handle().raw();
        unsafe {
            let mut data = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
            let mut db = data.as_mut_ptr()
                            as *mut c::REPARSE_MOUNTPOINT_DATA_BUFFER;
            let mut buf = &mut (*db).ReparseTarget as *mut _;
            let mut i = 0;
            let v = br"\??\";
            let v = v.iter().map(|x| *x as u16);
            for c in v.chain(dst.as_os_str().encode_wide()) {
                *buf.offset(i) = c;
                i += 1;
            }
            *buf.offset(i) = 0;
            i += 1;
            (*db).ReparseTag = c::IO_REPARSE_TAG_MOUNT_POINT;
            (*db).ReparseTargetMaximumLength = (i * 2) as libc::WORD;
            (*db).ReparseTargetLength = ((i - 1) * 2) as libc::WORD;
            (*db).ReparseDataLength =
                    (*db).ReparseTargetLength as libc::DWORD + 12;
            let mut ret = 0;
            cvt(c::DeviceIoControl(h as *mut _,
                                   c::FSCTL_SET_REPARSE_POINT,
                                   data.as_ptr() as *mut _,
                                   (*db).ReparseDataLength + 8,
                                   ptr::null_mut(), 0,
                                   &mut ret,
                                   ptr::null_mut())).map(|_| ())
        }
    }
fn create_junction ( src : & Path , dst : & Path ) -> io :: Result < ( ) > { let f = try ! ( opendir ( src true ) ) ; let h = f . handle ( ) . raw ( ) ; unsafe { let mut data = [ 0u8 ; c :: MAXIMUM_REPARSE_DATA_BUFFER_SIZE ] ; let mut db = data . as_mut_ptr ( ) as * mut c :: REPARSE_MOUNTPOINT_DATA_BUFFER ; let mut buf = & mut ( * db ) . ReparseTarget as * mut _ ; let mut i = 0 ; let v = br"\??\" ; let v = v . iter ( ) . map ( | x | * x as u16 ) ; for c in v . chain ( dst . as_os_str ( ) . encode_wide ( ) ) { * buf . offset ( i ) = c ; i += 1 ; } * buf . offset ( i ) = 0 ; i += 1 ; ( * db ) . ReparseTag = c :: IO_REPARSE_TAG_MOUNT_POINT ; ( * db ) . ReparseTargetMaximumLength = ( i * 2 ) as libc :: WORD ; ( * db ) . ReparseTargetLength = ( ( i - 1 ) * 2 ) as libc :: WORD ; ( * db ) . ReparseDataLength = ( * db ) . ReparseTargetLength as libc :: DWORD + 12 ; let mut ret = 0 ; cvt ( c :: DeviceIoControl ( h as * mut _ , c :: FSCTL_SET_REPARSE_POINT , data . as_ptr ( ) as * mut _ , ( * db ) . ReparseDataLength + 8 , ptr :: null_mut ( ) , 0 , & mut ret , ptr :: null_mut ( ) ) ) . map ( | _ | ( ) ) } }
Creating a directory junction on windows involves dealing with reparse
points and the DeviceIoControl function, and this code is a skeleton of
what can be found here:
Creating a directory junction on windows involves dealing with reparse points and the DeviceIoControl function and this code is a skeleton of what can be found here :
src
&Path
dst
&Path