internal static Result GetMountNameAndSubPath(out MountName mountName, out U8Span subPath, U8Span path) { UnsafeHelpers.SkipParamInit(out mountName); subPath = default; int mountLen = 0; int maxMountLen = Math.Min(path.Length, PathTools.MountNameLengthMax); if (WindowsPath.IsWindowsDrive(path) || WindowsPath.IsUnc(path)) { StringUtils.Copy(mountName.Name, CommonPaths.HostRootFileSystemMountName); mountName.Name[PathTools.MountNameLengthMax] = StringTraits.NullTerminator; subPath = path; return(Result.Success); } for (int i = 0; i <= maxMountLen; i++) { if (path[i] == PathTools.MountSeparator) { mountLen = i; break; } } if (mountLen == 0) { return(ResultFs.InvalidMountName.Log()); } if (mountLen > maxMountLen) { return(ResultFs.InvalidMountName.Log()); } if (mountLen <= 0) { return(ResultFs.InvalidMountName.Log()); } U8Span subPathTemp = path.Slice(mountLen + 1); if (subPathTemp.Length == 0 || (subPathTemp[0] != DirectorySeparator && subPathTemp[0] != AltDirectorySeparator)) { return(ResultFs.InvalidPathFormat.Log()); } path.Value.Slice(0, mountLen).CopyTo(mountName.Name); mountName.Name[mountLen] = StringTraits.NullTerminator; subPath = subPathTemp; return(Result.Success); }
public async Task A_mount_can_be_found_by_name() { await using Composer services = new(); var sut = services.Resolve <Gw2Client>(); const MountName name = MountName.Skyscale; var actual = await sut.Mounts.GetMountByName(name); Assert.Equal(name, actual.Value.Id); }
public Task <IReplica <Mount> > GetMountByName( MountName mountName, Language?language = default, MissingMemberBehavior missingMemberBehavior = default, CancellationToken cancellationToken = default ) { MountByNameRequest request = new(mountName) { Language = language, MissingMemberBehavior = missingMemberBehavior }; return(request.SendAsync(http, cancellationToken)); }
public Result Open(ulong applicationId) { lock (_locker) { // Find an existing storage entry for this application ID or get an empty one Result rc = FindOrGetUnusedEntry(out int index, applicationId); if (rc.IsFailure()) { return(rc); } ref Entry entry = ref Entries[index]; if (entry.RefCount != 0) { return(ResultBcat.TargetLocked.Log()); } // Get the mount name var mountName = new MountName(); var sb = new U8StringBuilder(mountName.Name); sb.Append(DeliveryCacheMountNamePrefix) .AppendFormat(index, 'd', 2); // Mount the save if enabled if (!DisableStorage) { rc = Server.GetFsClient() .MountBcatSaveData(new U8Span(mountName.Name), new Ncm.ApplicationId(applicationId)); if (rc.IsFailure()) { if (ResultFs.TargetNotFound.Includes(rc)) { return(ResultBcat.SaveDataNotFound.LogConverted(rc)); } return(rc); } } // Update the storage entry entry.ApplicationId = applicationId; entry.RefCount++; return(Result.Success); }
/// <summary>Formats a mount name for use in a request.</summary> /// <param name="mountName">Self-explanatory.</param> /// <returns>The mount name formatted as a string.</returns> /// <exception cref="NotSupportedException">Could not format that mount name.</exception> public static string FormatMountName(MountName mountName) => mountName switch {