-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Merge TarEntry's DeviceMajor and DeviceMinor into a single API #68974
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsBackground and motivationIn the initial PR implementing the new The device major and device minor values are used in Unix to uniquely identify character device and block device files. The suggestion to merge them into a single API makes sense because:
API ProposalThe major and minor numbers are available in Ustar, Pax and Gnu. public abstract partial class PosixTarEntry : TarEntry
{
internal PosixTarEntry() { }
- public int DeviceMajor { get; set; }
- public int DeviceMinor { get; set; }
public string GroupName { get; set; }
public string UserName { get; set; }
+ public (int, int) GetDeviceIdentifiers();
+ public void SetDeviceIdentifiers(int deviceMajor, int deviceMinor);
} API UsageInstead of: // Get
int major = entry.DeviceMajor;
int minor = entry.DeviceMinor;
// Set
entry.DeviceMajor = newMajor;
entry.DeviceMinor = newMinor; We would have: // Get
(int major, int minor) = entry.GetDeviceIdentifiers();
// Set
entry.SetDeviceIdentifiers(newMajor, newMinor); Or with the alternative design: // Get
entry.GetDeviceIdentifiers(out int major, out int minor); Alternative Designsa) Instead of returning a tuple, get the values as public abstract partial class PosixTarEntry : TarEntry
{
+ public void GetDeviceIdentifiers(out int deviceMajor, out int deviceMinor);
} b) Keep the APIs as they are, letting the user consume the major and minor separately, even if they are internally retrieved or set together. RisksCreating character or block devices is rare, and they are file types that are only available in some Unix filesystems. I am not aware of any particular use cases where the user would only need to retrieve the device major individually or the device minor individually. @tmds can you think of any? These are all new APIs in .NET 7.0, so we have time to decide better designs where applicable. @bartonjs @adamsitnik @jozkee let me know what you think.
|
I don't think Steve's suggestion was to merge these in the public API, just to merge the two SystemNative functions into one. For the API I quite strongly believe they should just be the parallel properties like they already are. |
I believe I:
For the latter, what is the use case for these? How are they consumed? Will developers need to compare versions, and if so, we expect them to do so with major and minor independently? |
In all my use cases while working on tar and device files, they are consumed together. I have not found a case where they need to be consumed separately. I'd love to hear @tmds opinion, maybe there is a case where they are needed separately. |
BTW I already did that :) runtime/src/libraries/Common/src/Interop/Unix/System.Native/Interop.DeviceFiles.cs Lines 25 to 26 in 2389815
runtime/src/native/libs/System.Native/pal_io.c Lines 773 to 779 in 2389815
|
Ah, I missed that part. My bad.
99.99999%: No use case, just exposing data from the file format. The epsilon target is someone writing their own file extractor and they want to re-create a block or character device node. In that case, whatever API they want to call will be one of a) two separate calls, b) one call with SxS parameters, or c) one call with ValueTuple'd parameters. For (a) and (b), SxS here are better, since we're not packing them up then unpacking them again. For (c) it doesn't really matter, since it's easy enough to pack the two properties into a ValueTuple on their call. And, given that As a ValueTuple:
As SxS properties:
In my mind, clearly, the ValueTuple-ification is all cost, no gain. |
Thanks for the input, I agree that having the separate properties @stephentoub I'm inclined to close this proposal based on the above. Do you have any objections? |
From Jeremy's description it sounds like we don't actually expect anyone to use these, and they're only here in the name of fidelity to the underlying data. In which case usability doesn't matter and it's fine to keep them separate. |
Background and motivation
In the initial PR implementing the new
System.Formats.Tar
APIs, @stephentoub suggested we consider merging theDeviceMajor
andDeviceMajor
public properties into one.The device major and device minor values are used in Unix to uniquely identify character device and block device files.
The suggestion to merge them into a single API makes sense because:
TarEntry
header.API Proposal
The major and minor numbers are available in Ustar, Pax and Gnu.
API Usage
Instead of:
We would have:
Or with the alternative design:
Alternative Designs
a) Instead of returning a tuple, get the values as
out
:public abstract partial class PosixTarEntry : TarEntry { + public void GetDeviceIdentifiers(out int deviceMajor, out int deviceMinor); }
b) Keep the APIs as they are, letting the user consume the major and minor separately, even if they are internally retrieved or set together.
Risks
Creating character or block devices is rare, and they are file types that are only available in some Unix filesystems. I am not aware of any particular use cases where the user would only need to retrieve the device major individually or the device minor individually. @tmds can you think of any?
These are all new APIs in .NET 7.0, so we have time to decide better designs where applicable.
@bartonjs @adamsitnik @jozkee @jeffhandley let me know what you think.
The text was updated successfully, but these errors were encountered: