MCPcopy Index your code
hub / github.com/RustPython/RustPython / stat_basic_info_to_stat

Function stat_basic_info_to_stat

crates/common/src/fileutils.rs:355–441  ·  view source on GitHub ↗
(info: &FILE_STAT_BASIC_INFORMATION)

Source from the content-addressed store, hash-verified

353 }
354
355 pub fn stat_basic_info_to_stat(info: &FILE_STAT_BASIC_INFORMATION) -> StatStruct {
356 use windows_sys::Win32::Storage::FileSystem;
357 use windows_sys::Win32::System::Ioctl;
358
359 const S_IFMT: u16 = self::S_IFMT as _;
360 const S_IFDIR: u16 = self::S_IFDIR as _;
361 const S_IFCHR: u16 = self::S_IFCHR as _;
362 const S_IFIFO: u16 = self::S_IFIFO as _;
363 const S_IFLNK: u16 = self::S_IFLNK as _;
364
365 let mut st_mode = attributes_to_mode(info.FileAttributes);
366 let st_size = info.EndOfFile as u64;
367 let st_birthtime = large_integer_to_time_t_nsec(info.CreationTime);
368 let st_ctime = large_integer_to_time_t_nsec(info.ChangeTime);
369 let st_mtime = large_integer_to_time_t_nsec(info.LastWriteTime);
370 let st_atime = large_integer_to_time_t_nsec(info.LastAccessTime);
371 let st_nlink = info.NumberOfLinks as _;
372 let st_dev = info.VolumeSerialNumber as u32;
373 // File systems with less than 128-bits zero pad into this field
374 let st_ino = info.FileId128;
375 // bpo-37834: Only actual symlinks set the S_IFLNK flag. But lstat() will
376 // open other name surrogate reparse points without traversing them. To
377 // detect/handle these, check st_file_attributes and st_reparse_tag.
378 let st_reparse_tag = info.ReparseTag;
379 if info.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT != 0
380 && info.ReparseTag == IO_REPARSE_TAG_SYMLINK
381 {
382 // set the bits that make this a symlink
383 st_mode = (st_mode & !S_IFMT) | S_IFLNK;
384 }
385 let st_file_attributes = info.FileAttributes;
386 match info.DeviceType {
387 FileSystem::FILE_DEVICE_DISK
388 | Ioctl::FILE_DEVICE_VIRTUAL_DISK
389 | Ioctl::FILE_DEVICE_DFS
390 | FileSystem::FILE_DEVICE_CD_ROM
391 | Ioctl::FILE_DEVICE_CONTROLLER
392 | Ioctl::FILE_DEVICE_DATALINK => {}
393 Ioctl::FILE_DEVICE_DISK_FILE_SYSTEM
394 | Ioctl::FILE_DEVICE_CD_ROM_FILE_SYSTEM
395 | Ioctl::FILE_DEVICE_NETWORK_FILE_SYSTEM => {
396 st_mode = (st_mode & !S_IFMT) | 0x6000; // _S_IFBLK
397 }
398 Ioctl::FILE_DEVICE_CONSOLE
399 | Ioctl::FILE_DEVICE_NULL
400 | Ioctl::FILE_DEVICE_KEYBOARD
401 | Ioctl::FILE_DEVICE_MODEM
402 | Ioctl::FILE_DEVICE_MOUSE
403 | Ioctl::FILE_DEVICE_PARALLEL_PORT
404 | Ioctl::FILE_DEVICE_PRINTER
405 | Ioctl::FILE_DEVICE_SCREEN
406 | Ioctl::FILE_DEVICE_SERIAL_PORT
407 | Ioctl::FILE_DEVICE_SOUND => {
408 st_mode = (st_mode & !S_IFMT) | S_IFCHR;
409 }
410 Ioctl::FILE_DEVICE_NAMED_PIPE => {
411 st_mode = (st_mode & !S_IFMT) | S_IFIFO;
412 }

Callers 1

win32_xstat_implFunction · 0.85

Calls 2

attributes_to_modeFunction · 0.70

Tested by

no test coverage detected