public static List <ReadOnlyMemory <byte> > Scan(ReadOnlySpan <byte> path) { //Console.WriteLine($"Scan: {path.GetString()}"); var dirFd = RawDirs.opendir(RawDirs.ToNullTerm(path.ToArray())); if (dirFd == IntPtr.Zero) { throw new Exception($"Error opening directory {path.GetString()} - {LibC.errno}"); } var contents = new List <ReadOnlyMemory <byte> >(); Console.Write($"\u000d-------- [Scanning: {path.GetString()}]\u001b[K\u001b[J\u000d"); int ct = 0; while (true) { var dir = RawDirs.readdir_wrap(dirFd, false); // Don't remove the null if (dir == null) { break; } ct++; var d = dir.Value; if (ct % 1000 == 0) { Console.Write($"\u000d{ct.ToString("00000000")}\u000d"); } //Console.WriteLine($"See {d.d_name.GetString()}"); contents.Add(d.d_name.AsMemory <byte>()); } Console.Write($"\u000d-------- [Scanned: {path.GetString()} ({contents.Count} entries)]\u001b[K\u001b[J\u000d"); RawDirs.closedir(dirFd); return(contents); }
public override int ReadDir(ReadOnlySpan <byte> path, ulong offset, ReadDirFlags flags, DirectoryContent content, ref FuseFileInfo fi, Guid fileGuid) { if (debug) { Console.WriteLine($"NeoFS::ReadDir({RawDirs.HR(path)},{offset},{flags})"); } path = base.TransformPath(path); // We only have the low level calls, so we need to do opendir/readdir ourself var dirFd = RawDirs.opendir(RawDirs.ToNullTerm(path.ToArray())); if (dirFd == IntPtr.Zero) { return(0); } content.AddEntry("."); // This can eat strings content.AddEntry(".."); while (true) { var dir = RawDirs.readdir_wrap(dirFd, false); // Don't remove the null if (dir == null) { break; } var d = dir.Value; if (debug) { Console.WriteLine($"{RawDirs.HR(path)} -> {RawDirs.HR(d.d_name)}"); } content.AddEntry(d.d_name.AsSpan()); } RawDirs.closedir(dirFd); return(0); }