1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use os::windows::prelude::*;
15 use io::{self, Error, SeekFrom};
17 use path::{Path, PathBuf};
21 use sys::handle::Handle;
22 use sys::time::SystemTime;
24 use sys_common::FromInner;
28 pub struct File { handle: Handle }
33 creation_time: c::FILETIME,
34 last_access_time: c::FILETIME,
35 last_write_time: c::FILETIME,
37 reparse_tag: c::DWORD,
40 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
43 reparse_tag: c::DWORD,
47 handle: FindNextFileHandle,
49 first: Option<c::WIN32_FIND_DATAW>,
52 struct FindNextFileHandle(c::HANDLE);
54 unsafe impl Send for FindNextFileHandle {}
55 unsafe impl Sync for FindNextFileHandle {}
59 data: c::WIN32_FIND_DATAW,
62 #[derive(Clone, Debug)]
63 pub struct OpenOptions {
73 access_mode: Option<c::DWORD>,
76 security_qos_flags: c::DWORD,
77 security_attributes: usize, // FIXME: should be a reference
80 #[derive(Clone, PartialEq, Eq, Debug)]
81 pub struct FilePermissions { attrs: c::DWORD }
84 pub struct DirBuilder;
86 impl fmt::Debug for ReadDir {
87 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
88 // This will only be called from std::fs::ReadDir, which will add a "ReadDir()" frame.
89 // Thus the result will be e g 'ReadDir("C:\")'
90 fmt::Debug::fmt(&*self.root, f)
94 impl Iterator for ReadDir {
95 type Item = io::Result<DirEntry>;
96 fn next(&mut self) -> Option<io::Result<DirEntry>> {
97 if let Some(first) = self.first.take() {
98 if let Some(e) = DirEntry::new(&self.root, &first) {
103 let mut wfd = mem::zeroed();
105 if c::FindNextFileW(self.handle.0, &mut wfd) == 0 {
106 if c::GetLastError() == c::ERROR_NO_MORE_FILES {
109 return Some(Err(Error::last_os_error()))
112 if let Some(e) = DirEntry::new(&self.root, &wfd) {
120 impl Drop for FindNextFileHandle {
122 let r = unsafe { c::FindClose(self.0) };
123 debug_assert!(r != 0);
128 fn new(root: &Arc<PathBuf>, wfd: &c::WIN32_FIND_DATAW) -> Option<DirEntry> {
129 match &wfd.cFileName[0..3] {
130 // check for '.' and '..'
132 &[46, 46, 0, ..] => return None,
142 pub fn path(&self) -> PathBuf {
143 self.root.join(&self.file_name())
146 pub fn file_name(&self) -> OsString {
147 let filename = super::truncate_utf16_at_nul(&self.data.cFileName);
148 OsString::from_wide(filename)
151 pub fn file_type(&self) -> io::Result<FileType> {
152 Ok(FileType::new(self.data.dwFileAttributes,
153 /* reparse_tag = */ self.data.dwReserved0))
156 pub fn metadata(&self) -> io::Result<FileAttr> {
158 attributes: self.data.dwFileAttributes,
159 creation_time: self.data.ftCreationTime,
160 last_access_time: self.data.ftLastAccessTime,
161 last_write_time: self.data.ftLastWriteTime,
162 file_size: ((self.data.nFileSizeHigh as u64) << 32) | (self.data.nFileSizeLow as u64),
163 reparse_tag: if self.data.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
164 // reserved unless this is a reparse point
165 self.data.dwReserved0
174 pub fn new() -> OpenOptions {
186 share_mode: c::FILE_SHARE_READ | c::FILE_SHARE_WRITE | c::FILE_SHARE_DELETE,
188 security_qos_flags: 0,
189 security_attributes: 0,
193 pub fn read(&mut self, read: bool) { self.read = read; }
194 pub fn write(&mut self, write: bool) { self.write = write; }
195 pub fn append(&mut self, append: bool) { self.append = append; }
196 pub fn truncate(&mut self, truncate: bool) { self.truncate = truncate; }
197 pub fn create(&mut self, create: bool) { self.create = create; }
198 pub fn create_new(&mut self, create_new: bool) { self.create_new = create_new; }
200 pub fn custom_flags(&mut self, flags: u32) { self.custom_flags = flags; }
201 pub fn access_mode(&mut self, access_mode: u32) { self.access_mode = Some(access_mode); }
202 pub fn share_mode(&mut self, share_mode: u32) { self.share_mode = share_mode; }
203 pub fn attributes(&mut self, attrs: u32) { self.attributes = attrs; }
204 pub fn security_qos_flags(&mut self, flags: u32) { self.security_qos_flags = flags; }
205 pub fn security_attributes(&mut self, attrs: c::LPSECURITY_ATTRIBUTES) {
206 self.security_attributes = attrs as usize;
209 fn get_access_mode(&self) -> io::Result<c::DWORD> {
210 const ERROR_INVALID_PARAMETER: i32 = 87;
212 match (self.read, self.write, self.append, self.access_mode) {
213 (.., Some(mode)) => Ok(mode),
214 (true, false, false, None) => Ok(c::GENERIC_READ),
215 (false, true, false, None) => Ok(c::GENERIC_WRITE),
216 (true, true, false, None) => Ok(c::GENERIC_READ | c::GENERIC_WRITE),
217 (false, _, true, None) => Ok(c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA),
218 (true, _, true, None) => Ok(c::GENERIC_READ |
219 (c::FILE_GENERIC_WRITE & !c::FILE_WRITE_DATA)),
220 (false, false, false, None) => Err(Error::from_raw_os_error(ERROR_INVALID_PARAMETER)),
224 fn get_creation_mode(&self) -> io::Result<c::DWORD> {
225 const ERROR_INVALID_PARAMETER: i32 = 87;
227 match (self.write, self.append) {
230 if self.truncate || self.create || self.create_new {
231 return Err(Error::from_raw_os_error(ERROR_INVALID_PARAMETER));
234 if self.truncate && !self.create_new {
235 return Err(Error::from_raw_os_error(ERROR_INVALID_PARAMETER));
239 Ok(match (self.create, self.truncate, self.create_new) {
240 (false, false, false) => c::OPEN_EXISTING,
241 (true, false, false) => c::OPEN_ALWAYS,
242 (false, true, false) => c::TRUNCATE_EXISTING,
243 (true, true, false) => c::CREATE_ALWAYS,
244 (_, _, true) => c::CREATE_NEW,
248 fn get_flags_and_attributes(&self) -> c::DWORD {
251 self.security_qos_flags |
252 if self.security_qos_flags != 0 { c::SECURITY_SQOS_PRESENT } else { 0 } |
253 if self.create_new { c::FILE_FLAG_OPEN_REPARSE_POINT } else { 0 }
258 pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
259 let path = to_u16s(path)?;
260 let handle = unsafe {
261 c::CreateFileW(path.as_ptr(),
262 opts.get_access_mode()?,
264 opts.security_attributes as *mut _,
265 opts.get_creation_mode()?,
266 opts.get_flags_and_attributes(),
269 if handle == c::INVALID_HANDLE_VALUE {
270 Err(Error::last_os_error())
272 Ok(File { handle: Handle::new(handle) })
276 pub fn fsync(&self) -> io::Result<()> {
277 cvt(unsafe { c::FlushFileBuffers(self.handle.raw()) })?;
281 pub fn datasync(&self) -> io::Result<()> { self.fsync() }
283 pub fn truncate(&self, size: u64) -> io::Result<()> {
284 let mut info = c::FILE_END_OF_FILE_INFO {
285 EndOfFile: size as c::LARGE_INTEGER,
287 let size = mem::size_of_val(&info);
289 c::SetFileInformationByHandle(self.handle.raw(),
290 c::FileEndOfFileInfo,
291 &mut info as *mut _ as *mut _,
297 pub fn file_attr(&self) -> io::Result<FileAttr> {
299 let mut info: c::BY_HANDLE_FILE_INFORMATION = mem::zeroed();
300 cvt(c::GetFileInformationByHandle(self.handle.raw(),
302 let mut attr = FileAttr {
303 attributes: info.dwFileAttributes,
304 creation_time: info.ftCreationTime,
305 last_access_time: info.ftLastAccessTime,
306 last_write_time: info.ftLastWriteTime,
307 file_size: ((info.nFileSizeHigh as u64) << 32) | (info.nFileSizeLow as u64),
310 if attr.is_reparse_point() {
311 let mut b = [0; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
312 if let Ok((_, buf)) = self.reparse_point(&mut b) {
313 attr.reparse_tag = buf.ReparseTag;
320 pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
321 self.handle.read(buf)
324 pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
325 self.handle.read_at(buf, offset)
328 pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
329 self.handle.write(buf)
332 pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
333 self.handle.write_at(buf, offset)
336 pub fn flush(&self) -> io::Result<()> { Ok(()) }
338 pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
339 let (whence, pos) = match pos {
340 // Casting to `i64` is fine, `SetFilePointerEx` reinterprets this
342 SeekFrom::Start(n) => (c::FILE_BEGIN, n as i64),
343 SeekFrom::End(n) => (c::FILE_END, n),
344 SeekFrom::Current(n) => (c::FILE_CURRENT, n),
346 let pos = pos as c::LARGE_INTEGER;
349 c::SetFilePointerEx(self.handle.raw(), pos,
355 pub fn duplicate(&self) -> io::Result<File> {
357 handle: self.handle.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?,
361 pub fn handle(&self) -> &Handle { &self.handle }
363 pub fn into_handle(self) -> Handle { self.handle }
365 fn reparse_point<'a>(&self,
366 space: &'a mut [u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE])
367 -> io::Result<(c::DWORD, &'a c::REPARSE_DATA_BUFFER)> {
371 c::DeviceIoControl(self.handle.raw(),
372 c::FSCTL_GET_REPARSE_POINT,
375 space.as_mut_ptr() as *mut _,
376 space.len() as c::DWORD,
380 Ok((bytes, &*(space.as_ptr() as *const c::REPARSE_DATA_BUFFER)))
384 fn readlink(&self) -> io::Result<PathBuf> {
385 let mut space = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
386 let (_bytes, buf) = self.reparse_point(&mut space)?;
388 let (path_buffer, subst_off, subst_len, relative) = match buf.ReparseTag {
389 c::IO_REPARSE_TAG_SYMLINK => {
390 let info: *const c::SYMBOLIC_LINK_REPARSE_BUFFER =
391 &buf.rest as *const _ as *const _;
392 (&(*info).PathBuffer as *const _ as *const u16,
393 (*info).SubstituteNameOffset / 2,
394 (*info).SubstituteNameLength / 2,
395 (*info).Flags & c::SYMLINK_FLAG_RELATIVE != 0)
397 c::IO_REPARSE_TAG_MOUNT_POINT => {
398 let info: *const c::MOUNT_POINT_REPARSE_BUFFER =
399 &buf.rest as *const _ as *const _;
400 (&(*info).PathBuffer as *const _ as *const u16,
401 (*info).SubstituteNameOffset / 2,
402 (*info).SubstituteNameLength / 2,
405 _ => return Err(io::Error::new(io::ErrorKind::Other,
406 "Unsupported reparse point type"))
408 let subst_ptr = path_buffer.offset(subst_off as isize);
409 let mut subst = slice::from_raw_parts(subst_ptr, subst_len as usize);
410 // Absolute paths start with an NT internal namespace prefix `\??\`
411 // We should not let it leak through.
412 if !relative && subst.starts_with(&[92u16, 63u16, 63u16, 92u16]) {
415 Ok(PathBuf::from(OsString::from_wide(subst)))
419 pub fn set_permissions(&self, perm: FilePermissions) -> io::Result<()> {
420 let mut info = c::FILE_BASIC_INFO {
425 FileAttributes: perm.attrs,
427 let size = mem::size_of_val(&info);
429 c::SetFileInformationByHandle(self.handle.raw(),
431 &mut info as *mut _ as *mut _,
438 impl FromInner<c::HANDLE> for File {
439 fn from_inner(handle: c::HANDLE) -> File {
440 File { handle: Handle::new(handle) }
444 impl fmt::Debug for File {
445 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
446 // FIXME(#24570): add more info here (e.g. mode)
447 let mut b = f.debug_struct("File");
448 b.field("handle", &self.handle.raw());
449 if let Ok(path) = get_path(&self) {
450 b.field("path", &path);
457 pub fn size(&self) -> u64 {
461 pub fn perm(&self) -> FilePermissions {
462 FilePermissions { attrs: self.attributes }
465 pub fn attrs(&self) -> u32 { self.attributes as u32 }
467 pub fn file_type(&self) -> FileType {
468 FileType::new(self.attributes, self.reparse_tag)
471 pub fn modified(&self) -> io::Result<SystemTime> {
472 Ok(SystemTime::from(self.last_write_time))
475 pub fn accessed(&self) -> io::Result<SystemTime> {
476 Ok(SystemTime::from(self.last_access_time))
479 pub fn created(&self) -> io::Result<SystemTime> {
480 Ok(SystemTime::from(self.creation_time))
483 pub fn modified_u64(&self) -> u64 {
484 to_u64(&self.last_write_time)
487 pub fn accessed_u64(&self) -> u64 {
488 to_u64(&self.last_access_time)
491 pub fn created_u64(&self) -> u64 {
492 to_u64(&self.creation_time)
495 fn is_reparse_point(&self) -> bool {
496 self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
500 fn to_u64(ft: &c::FILETIME) -> u64 {
501 (ft.dwLowDateTime as u64) | ((ft.dwHighDateTime as u64) << 32)
504 impl FilePermissions {
505 pub fn readonly(&self) -> bool {
506 self.attrs & c::FILE_ATTRIBUTE_READONLY != 0
509 pub fn set_readonly(&mut self, readonly: bool) {
511 self.attrs |= c::FILE_ATTRIBUTE_READONLY;
513 self.attrs &= !c::FILE_ATTRIBUTE_READONLY;
519 fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
522 reparse_tag: reparse_tag,
525 pub fn is_dir(&self) -> bool {
526 !self.is_symlink() && self.is_directory()
528 pub fn is_file(&self) -> bool {
529 !self.is_symlink() && !self.is_directory()
531 pub fn is_symlink(&self) -> bool {
532 self.is_reparse_point() && self.is_reparse_tag_name_surrogate()
534 pub fn is_symlink_dir(&self) -> bool {
535 self.is_symlink() && self.is_directory()
537 pub fn is_symlink_file(&self) -> bool {
538 self.is_symlink() && !self.is_directory()
540 fn is_directory(&self) -> bool {
541 self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
543 fn is_reparse_point(&self) -> bool {
544 self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
546 fn is_reparse_tag_name_surrogate(&self) -> bool {
547 self.reparse_tag & 0x20000000 != 0
552 pub fn new() -> DirBuilder { DirBuilder }
554 pub fn mkdir(&self, p: &Path) -> io::Result<()> {
557 c::CreateDirectoryW(p.as_ptr(), ptr::null_mut())
563 pub fn readdir(p: &Path) -> io::Result<ReadDir> {
564 let root = p.to_path_buf();
565 let star = p.join("*");
566 let path = to_u16s(&star)?;
569 let mut wfd = mem::zeroed();
570 let find_handle = c::FindFirstFileW(path.as_ptr(), &mut wfd);
571 if find_handle != c::INVALID_HANDLE_VALUE {
573 handle: FindNextFileHandle(find_handle),
574 root: Arc::new(root),
578 Err(Error::last_os_error())
583 pub fn unlink(p: &Path) -> io::Result<()> {
584 let p_u16s = to_u16s(p)?;
585 cvt(unsafe { c::DeleteFileW(p_u16s.as_ptr()) })?;
589 pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
590 let old = to_u16s(old)?;
591 let new = to_u16s(new)?;
593 c::MoveFileExW(old.as_ptr(), new.as_ptr(), c::MOVEFILE_REPLACE_EXISTING)
598 pub fn rmdir(p: &Path) -> io::Result<()> {
600 cvt(unsafe { c::RemoveDirectoryW(p.as_ptr()) })?;
604 pub fn remove_dir_all(path: &Path) -> io::Result<()> {
605 let filetype = lstat(path)?.file_type();
606 if filetype.is_symlink() {
607 // On Windows symlinks to files and directories are removed differently.
608 // rmdir only deletes dir symlinks and junctions, not file symlinks.
611 remove_dir_all_recursive(path)
615 fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
616 for child in readdir(path)? {
618 let child_type = child.file_type()?;
619 if child_type.is_dir() {
620 remove_dir_all_recursive(&child.path())?;
621 } else if child_type.is_symlink_dir() {
622 rmdir(&child.path())?;
624 unlink(&child.path())?;
630 pub fn readlink(path: &Path) -> io::Result<PathBuf> {
631 // Open the link with no access mode, instead of generic read.
632 // By default FILE_LIST_DIRECTORY is denied for the junction "C:\Documents and Settings", so
633 // this is needed for a common case.
634 let mut opts = OpenOptions::new();
636 opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT |
637 c::FILE_FLAG_BACKUP_SEMANTICS);
638 let file = File::open(&path, &opts)?;
642 pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
643 symlink_inner(src, dst, false)
646 pub fn symlink_inner(src: &Path, dst: &Path, dir: bool) -> io::Result<()> {
647 let src = to_u16s(src)?;
648 let dst = to_u16s(dst)?;
649 let flags = if dir { c::SYMBOLIC_LINK_FLAG_DIRECTORY } else { 0 };
650 // Formerly, symlink creation required the SeCreateSymbolicLink privilege. For the Windows 10
651 // Creators Update, Microsoft loosened this to allow unprivileged symlink creation if the
652 // computer is in Developer Mode, but SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE must be
653 // added to dwFlags to opt into this behaviour.
654 let result = cvt(unsafe {
655 c::CreateSymbolicLinkW(dst.as_ptr(), src.as_ptr(),
656 flags | c::SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) as c::BOOL
658 if let Err(err) = result {
659 if err.raw_os_error() == Some(c::ERROR_INVALID_PARAMETER as i32) {
660 // Older Windows objects to SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE,
661 // so if we encounter ERROR_INVALID_PARAMETER, retry without that flag.
663 c::CreateSymbolicLinkW(dst.as_ptr(), src.as_ptr(), flags) as c::BOOL
672 pub fn link(src: &Path, dst: &Path) -> io::Result<()> {
673 let src = to_u16s(src)?;
674 let dst = to_u16s(dst)?;
676 c::CreateHardLinkW(dst.as_ptr(), src.as_ptr(), ptr::null_mut())
681 pub fn stat(path: &Path) -> io::Result<FileAttr> {
682 let mut opts = OpenOptions::new();
683 // No read or write permissions are necessary
685 // This flag is so we can open directories too
686 opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS);
687 let file = File::open(path, &opts)?;
691 pub fn lstat(path: &Path) -> io::Result<FileAttr> {
692 let mut opts = OpenOptions::new();
693 // No read or write permissions are necessary
695 opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | c::FILE_FLAG_OPEN_REPARSE_POINT);
696 let file = File::open(path, &opts)?;
700 pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
703 cvt(c::SetFileAttributesW(p.as_ptr(), perm.attrs))?;
708 fn get_path(f: &File) -> io::Result<PathBuf> {
709 super::fill_utf16_buf(|buf, sz| unsafe {
710 c::GetFinalPathNameByHandleW(f.handle.raw(), buf, sz,
713 PathBuf::from(OsString::from_wide(buf))
717 pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
718 let mut opts = OpenOptions::new();
719 // No read or write permissions are necessary
721 // This flag is so we can open directories too
722 opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS);
723 let f = File::open(p, &opts)?;
727 pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
728 unsafe extern "system" fn callback(
729 _TotalFileSize: c::LARGE_INTEGER,
730 _TotalBytesTransferred: c::LARGE_INTEGER,
731 _StreamSize: c::LARGE_INTEGER,
732 StreamBytesTransferred: c::LARGE_INTEGER,
733 dwStreamNumber: c::DWORD,
734 _dwCallbackReason: c::DWORD,
735 _hSourceFile: c::HANDLE,
736 _hDestinationFile: c::HANDLE,
739 if dwStreamNumber == 1 {*(lpData as *mut i64) = StreamBytesTransferred;}
742 let pfrom = to_u16s(from)?;
743 let pto = to_u16s(to)?;
746 c::CopyFileExW(pfrom.as_ptr(), pto.as_ptr(), Some(callback),
747 &mut size as *mut _ as *mut _, ptr::null_mut(), 0)
753 pub fn symlink_junction<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
754 symlink_junction_inner(src.as_ref(), dst.as_ref())
757 // Creating a directory junction on windows involves dealing with reparse
758 // points and the DeviceIoControl function, and this code is a skeleton of
759 // what can be found here:
761 // http://www.flexhex.com/docs/articles/hard-links.phtml
763 fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> {
764 let d = DirBuilder::new();
767 let mut opts = OpenOptions::new();
769 opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT |
770 c::FILE_FLAG_BACKUP_SEMANTICS);
771 let f = File::open(junction, &opts)?;
772 let h = f.handle().raw();
775 let mut data = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
776 let db = data.as_mut_ptr()
777 as *mut c::REPARSE_MOUNTPOINT_DATA_BUFFER;
778 let buf = &mut (*db).ReparseTarget as *mut c::WCHAR;
780 // FIXME: this conversion is very hacky
782 let v = v.iter().map(|x| *x as u16);
783 for c in v.chain(target.as_os_str().encode_wide()) {
789 (*db).ReparseTag = c::IO_REPARSE_TAG_MOUNT_POINT;
790 (*db).ReparseTargetMaximumLength = (i * 2) as c::WORD;
791 (*db).ReparseTargetLength = ((i - 1) * 2) as c::WORD;
792 (*db).ReparseDataLength =
793 (*db).ReparseTargetLength as c::DWORD + 12;
796 cvt(c::DeviceIoControl(h as *mut _,
797 c::FSCTL_SET_REPARSE_POINT,
798 data.as_ptr() as *mut _,
799 (*db).ReparseDataLength + 8,
802 ptr::null_mut())).map(|_| ())