-
Notifications
You must be signed in to change notification settings - Fork 0
UnixStorageInfo Struct
Represents detailed information about a file or directory on a Unix-based file system.
Namespace: Rheo.Storage.Information
Assembly: Rheo.Storage.dll
public struct UnixStorageInfo : IStorageInfoStruct- IStorageInfoStruct
| Property | Type | Description |
|---|---|---|
| Attributes | FileAttributes | Gets or sets the file attributes. |
| Size | UInt64 | Gets or sets the size in bytes. |
| CreationTime | DateTime | Gets or sets the creation time. |
| LastWriteTime | DateTime | Gets or sets the last write time. |
| LastAccessTime | DateTime | Gets or sets the last access time. |
| OwnerId | UInt32 | Gets or sets the owner identifier (UID on Unix). |
| GroupId | UInt32 | Gets or sets the group identifier (GID on Unix). |
| Mode | UInt32 | Gets or sets the file mode (permissions and type). |
| SymlinkTarget | String | Gets or sets the target path if the file is a symbolic link. |
This structure provides file metadata commonly retrieved from Unix file system queries, including attributes, size, timestamps, ownership, permissions, and symbolic link information. Some fields may have platform-specific interpretations; for example, OwnerId and GroupId correspond to user and group IDs on Unix systems, while Mode reflects Unix file permissions and type. Not all fields may be meaningful or populated on non-Unix platforms.
Gets or sets the file attributes.
public FileAttributes Attributes { get; set; }The file attributes flags.
Gets or sets the size in bytes.
public ulong Size { get; set; }The file size in bytes.
Gets or sets the creation time.
public DateTime CreationTime { get; set; }The creation timestamp.
On many Unix systems, creation time may not be available and this may reflect the change time (ctime) instead.
Gets or sets the last write time.
public DateTime LastWriteTime { get; set; }The last modification timestamp (mtime).
Gets or sets the last access time.
public DateTime LastAccessTime { get; set; }The last access timestamp (atime).
Gets or sets the owner identifier.
public uint OwnerId { get; set; }The user ID (UID) on Unix systems, or a partial SID on Windows.
On Unix systems, this corresponds to the st_uid field from the stat structure.
Gets or sets the group identifier.
public uint GroupId { get; set; }The group ID (GID) on Unix systems.
On Unix systems, this corresponds to the st_gid field from the stat structure.
Gets or sets the file mode (permissions and type).
public uint Mode { get; set; }The file mode value.
On Unix systems, this corresponds to the st_mode field and includes both file type and permission bits. Common values include:
- File permissions (0777, 0644, etc.)
- File type bits (S_IFREG, S_IFDIR, S_IFLNK, etc.)
Gets or sets the target path if the file is a symbolic link.
public string? SymlinkTarget { get; set; }The target path, or null if not a symbolic link.
The following example demonstrates accessing Unix-specific storage details:
using Rheo.Storage.Information;
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
var fileInfo = new FileInformation("/home/user/document.txt");
if (fileInfo.TryGetUnixStorageInfo(out var unixInfo))
{
Console.WriteLine($"Owner UID: {unixInfo.OwnerId}");
Console.WriteLine($"Group GID: {unixInfo.GroupId}");
Console.WriteLine($"Mode: {Convert.ToString(unixInfo.Mode, 8)}");
if (unixInfo.SymlinkTarget != null)
{
Console.WriteLine($"Symlink Target: {unixInfo.SymlinkTarget}");
}
}
}The following example shows how to check Unix file permissions:
using Rheo.Storage.Information;
const uint S_IRUSR = 0x100; // Owner read
const uint S_IWUSR = 0x080; // Owner write
const uint S_IXUSR = 0x040; // Owner execute
var fileInfo = new FileInformation("/usr/bin/tool");
if (fileInfo.TryGetUnixStorageInfo(out var unixInfo))
{
bool ownerCanRead = (unixInfo.Mode & S_IRUSR) != 0;
bool ownerCanWrite = (unixInfo.Mode & S_IWUSR) != 0;
bool ownerCanExecute = (unixInfo.Mode & S_IXUSR) != 0;
Console.WriteLine($"Owner Permissions:");
Console.WriteLine($" Read: {ownerCanRead}");
Console.WriteLine($" Write: {ownerCanWrite}");
Console.WriteLine($" Execute: {ownerCanExecute}");
}The following example demonstrates symbolic link handling:
using Rheo.Storage.Information;
var fileInfo = new FileInformation("/home/user/link");
if (fileInfo.TryGetUnixStorageInfo(out var unixInfo))
{
if (unixInfo.SymlinkTarget != null)
{
Console.WriteLine($"Symbolic link points to: {unixInfo.SymlinkTarget}");
// Follow the link
if (File.Exists(unixInfo.SymlinkTarget))
{
var targetInfo = new FileInformation(unixInfo.SymlinkTarget);
Console.WriteLine($"Target size: {targetInfo.FormattedSize}");
}
}
}The following example shows how to format Unix permissions as a string:
using Rheo.Storage.Information;
string FormatPermissions(uint mode)
{
var perms = new char[9];
// Owner permissions
perms[0] = (mode & 0x100) != 0 ? 'r' : '-';
perms[1] = (mode & 0x080) != 0 ? 'w' : '-';
perms[2] = (mode & 0x040) != 0 ? 'x' : '-';
// Group permissions
perms[3] = (mode & 0x020) != 0 ? 'r' : '-';
perms[4] = (mode & 0x010) != 0 ? 'w' : '-';
perms[5] = (mode & 0x008) != 0 ? 'x' : '-';
// Other permissions
perms[6] = (mode & 0x004) != 0 ? 'r' : '-';
perms[7] = (mode & 0x002) != 0 ? 'w' : '-';
perms[8] = (mode & 0x001) != 0 ? 'x' : '-';
return new string(perms);
}
var fileInfo = new FileInformation("/etc/passwd");
if (fileInfo.TryGetUnixStorageInfo(out var unixInfo))
{
Console.WriteLine($"Permissions: {FormatPermissions(unixInfo.Mode)}");
}This struct is not thread-safe. Instances should not be modified from multiple threads simultaneously.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress