Skip to content
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

proposal: os: Chown expects int, but Linux uid_t/gid_t are uint32 #8537

Closed
gopherbot opened this issue Aug 16, 2014 · 4 comments
Closed

proposal: os: Chown expects int, but Linux uid_t/gid_t are uint32 #8537

gopherbot opened this issue Aug 16, 2014 · 4 comments
Labels
FrozenDueToAge Go2Cleanup Used by Ian and Robert for Go 2 organization. Unless you’re Ian or Robert, please do not use this. v2 A language change or incompatible library change
Milestone

Comments

@gopherbot
Copy link

Hi. I don't necessarily expect anything to change, but I wanted to record my
confusion/surprise in a place where others are likely to find it.

chown(2) takes takes uid_t and gid_t, which on Linux are unsigned 32-bit:
http://serverfault.com/questions/105260/how-big-in-bits-is-a-unix-uid

I have some code that deals with low-level kernel interfaces, where uids and gids are
most definitely uint32, and making those interact with os.Chown is what triggered this
issue.

Go will be confusing to use with userids 2147483648..4294967294. If you think nobody
will have that many users, consider containers and user namespaces; uids will not be
consumed in-order, like on traditional UNIX boxes.

And on 64-bit platforms, int is 64-bit, but uid values are only 32-bit, and that gets
silly too.

Background: In C, -1, when cast into uid_t (that is, uint32_t), is just 0xffffffff, the
highest possible unsigned value; it's not really signed, but just a shorthand for
"all bits set". In Go, trying to pass -1 as uint32 is a compiler error. This
sounds like the motivation for making the argument an int.
@ianlancetaylor
Copy link
Contributor

Comment 1:

It looks like we made an unfortunate choice here, but the Go 1 compatibility guarantee
prevents us from changing it.  As far as I can see the current code will work, albeit
awkwardly, so it's not essential to do anything today.  Marking as a Go 2 issue.

Labels changed: added repo-main, go2.

Status changed to LongTerm.

@griesemer
Copy link
Contributor

Comment 2:

Labels changed: added release-none.

@gopherbot gopherbot added longterm v2 A language change or incompatible library change labels Aug 25, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title os: uid_t and gid_t are unsigned 32-bit on Linux, yet os.Chown takes (signed) int os: Chown expects int but Linux uid_t/gid_t are uint32 Jun 17, 2017
@rsc rsc changed the title os: Chown expects int but Linux uid_t/gid_t are uint32 os: Chown expects int, but Linux uid_t/gid_t are uint32 Jun 17, 2017
@rsc
Copy link
Contributor

rsc commented Jun 17, 2017

cf #6495

@rsc rsc changed the title os: Chown expects int, but Linux uid_t/gid_t are uint32 proposal: os: Chown expects int, but Linux uid_t/gid_t are uint32 Jun 17, 2017
@ianlancetaylor ianlancetaylor added the Go2Cleanup Used by Ian and Robert for Go 2 organization. Unless you’re Ian or Robert, please do not use this. label Dec 6, 2017
@ianlancetaylor
Copy link
Contributor

Let's fold this into the more general #6495.

@golang golang locked and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Go2Cleanup Used by Ian and Robert for Go 2 organization. Unless you’re Ian or Robert, please do not use this. v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

4 participants