Bug 36562 - Syscall.chown arguments must be int, not uint to accept libc -1 for no change
Summary: Syscall.chown arguments must be int, not uint to accept libc -1 for no change
Status: RESOLVED ANSWERED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 4.2.0 (C6)
Hardware: All Linux
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-12-03 21:14 UTC by kcd
Modified: 2015-12-07 21:53 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description kcd 2015-12-03 21:14:50 UTC
See https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs#L3830

   public static extern int chown (string path, uint owner, uint group);
should be
   public static extern int chown (string path, int owner, int group);

To allow for 
   If the owner or group is specified as -1, then that ID is not changed.
   http://man7.org/linux/man-pages/man2/chown.2.html


This workaround has worked for me so far
    private const uint NO_CHANGE_ID = 4294967295; //int -1

Where i can use 
    int result = Mono.Unix.Native.Syscall.chown(path, ownerId, NO_CHANGE_ID);
or
    int result = Mono.Unix.Native.Syscall.chown(path, NO_CHANGE_ID, groupId);
Comment 1 Jonathan Pryor 2015-12-07 21:53:50 UTC
On OS X, Linux, and Android (Linux), uid_t is actually an unsigned integer, i.e. a `uint`, which is why Syscall.chown() uses `uint` as the parameter type.

Additionally, this is trivially worked around by using `unchecked`:

    int r = Syscall.chown(path, unchecked((uint)-1), groupId);