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

Fix the style for bitflags! #503

Merged
merged 3 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#497](https://github.com/nix-rust/nix/pull/497))
- Added `major` and `minor` in `::nix::sys::stat` for decomposing `dev_t`
([#508](https://github.com/nix-rust/nix/pull/508))
- Fixed the style of many bitflags and use `libc` in more places.
([#503](https://github.com/nix-rust/nix/pull/503))

### Changed
- `epoll_ctl` now could accept None as argument `event`
Expand Down
112 changes: 56 additions & 56 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,38 +137,38 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
mod consts {
use libc::{self, c_int, c_uint};

bitflags! {
libc_bitflags! {
pub flags SpliceFFlags: c_uint {
const SPLICE_F_MOVE = libc::SPLICE_F_MOVE,
const SPLICE_F_NONBLOCK = libc::SPLICE_F_NONBLOCK,
const SPLICE_F_MORE = libc::SPLICE_F_MORE,
const SPLICE_F_GIFT = libc::SPLICE_F_GIFT,
SPLICE_F_MOVE,
SPLICE_F_NONBLOCK,
SPLICE_F_MORE,
SPLICE_F_GIFT,
}
}

bitflags!(
pub flags OFlag: c_int {
const O_ACCMODE = 0o00000003,
const O_RDONLY = 0o00000000,
const O_WRONLY = 0o00000001,
const O_RDWR = 0o00000002,
const O_CREAT = 0o00000100,
const O_EXCL = 0o00000200,
const O_NOCTTY = 0o00000400,
const O_TRUNC = 0o00001000,
const O_APPEND = 0o00002000,
const O_NONBLOCK = 0o00004000,
const O_DSYNC = 0o00010000,
const O_DIRECT = 0o00040000,
const O_ACCMODE = libc::O_ACCMODE,
const O_RDONLY = libc::O_RDONLY,
const O_WRONLY = libc::O_WRONLY,
const O_RDWR = libc::O_RDWR,
const O_CREAT = libc::O_CREAT,
const O_EXCL = libc::O_EXCL,
const O_NOCTTY = libc::O_NOCTTY,
const O_TRUNC = libc::O_TRUNC,
const O_APPEND = libc::O_APPEND,
const O_NONBLOCK = libc::O_NONBLOCK,
const O_DSYNC = libc::O_DSYNC,
const O_DIRECT = libc::O_DIRECT,
const O_LARGEFILE = 0o00100000,
const O_DIRECTORY = 0o00200000,
const O_NOFOLLOW = 0o00400000,
const O_DIRECTORY = libc::O_DIRECTORY,
const O_NOFOLLOW = libc::O_NOFOLLOW,
const O_NOATIME = 0o01000000,
const O_CLOEXEC = 0o02000000,
const O_SYNC = 0o04000000,
const O_CLOEXEC = libc::O_CLOEXEC,
const O_SYNC = libc::O_SYNC,
const O_PATH = 0o10000000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking this PR, but if these are missing in libc would you be up for adding them there? Then we could have a followup PR here to use only libc-defined constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it would be a good idea to get more constants upstream and to fix their types. I've already filed rust-lang/libc#503 and rust-lang/libc#504 which is progress towards this goal.

That being said, my main interest in this was to fix the value of O_TMPFILE in a non-hacky way. I might do more at a later stage, but I have less motivation to do so now that my use-case has been fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and rust-lang/libc#506 as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah no pressure to do it, and certainly not on this PR. I'll probably do a few myself over the coming days.

const O_TMPFILE = 0o20000000,
const O_NDELAY = O_NONBLOCK.bits
const O_TMPFILE = libc::O_TMPFILE,
const O_NDELAY = libc::O_NDELAY,
}
);

Expand All @@ -191,27 +191,27 @@ mod consts {

#[cfg(any(target_os = "macos", target_os = "ios"))]
mod consts {
use libc::c_int;
use libc::{self, c_int};

bitflags!(
pub flags OFlag: c_int {
const O_ACCMODE = 0x0000003,
const O_RDONLY = 0x0000000,
const O_WRONLY = 0x0000001,
const O_RDWR = 0x0000002,
const O_CREAT = 0x0000200,
const O_EXCL = 0x0000800,
const O_NOCTTY = 0x0020000,
const O_TRUNC = 0x0000400,
const O_APPEND = 0x0000008,
const O_NONBLOCK = 0x0000004,
const O_DSYNC = 0x0400000,
const O_DIRECTORY = 0x0100000,
const O_NOFOLLOW = 0x0000100,
const O_CLOEXEC = 0x1000000,
const O_SYNC = 0x0000080,
const O_ACCMODE = libc::O_ACCMODE,
const O_RDONLY = libc::O_RDONLY,
const O_WRONLY = libc::O_WRONLY,
const O_RDWR = libc::O_RDWR,
const O_CREAT = libc::O_CREAT,
const O_EXCL = libc::O_EXCL,
const O_NOCTTY = libc::O_NOCTTY,
const O_TRUNC = libc::O_TRUNC,
const O_APPEND = libc::O_APPEND,
const O_NONBLOCK = libc::O_NONBLOCK,
const O_DSYNC = libc::O_DSYNC,
const O_DIRECTORY = libc::O_DIRECTORY,
const O_NOFOLLOW = libc::O_NOFOLLOW,
const O_CLOEXEC = libc::O_CLOEXEC,
const O_SYNC = libc::O_SYNC,
const O_NDELAY = O_NONBLOCK.bits,
const O_FSYNC = O_SYNC.bits
const O_FSYNC = libc::O_FSYNC,
}
);

Expand All @@ -224,26 +224,26 @@ mod consts {

#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
mod consts {
use libc::c_int;
use libc::{self, c_int};

bitflags!(
pub flags OFlag: c_int {
const O_ACCMODE = 0x0000003,
const O_RDONLY = 0x0000000,
const O_WRONLY = 0x0000001,
const O_RDWR = 0x0000002,
const O_CREAT = 0x0000200,
const O_EXCL = 0x0000800,
const O_NOCTTY = 0x0008000,
const O_TRUNC = 0x0000400,
const O_APPEND = 0x0000008,
const O_NONBLOCK = 0x0000004,
const O_ACCMODE = libc::O_ACCMODE,
const O_RDONLY = libc::O_RDONLY,
const O_WRONLY = libc::O_WRONLY,
const O_RDWR = libc::O_RDWR,
const O_CREAT = libc::O_CREAT,
const O_EXCL = libc::O_EXCL,
const O_NOCTTY = libc::O_NOCTTY,
const O_TRUNC = libc::O_TRUNC,
const O_APPEND = libc::O_APPEND,
const O_NONBLOCK = libc::O_NONBLOCK,
const O_DIRECTORY = 0x0020000,
const O_NOFOLLOW = 0x0000100,
const O_CLOEXEC = 0x0100000,
const O_SYNC = 0x0000080,
const O_NDELAY = O_NONBLOCK.bits,
const O_FSYNC = O_SYNC.bits,
const O_NOFOLLOW = libc::O_NOFOLLOW,
const O_CLOEXEC = libc::O_CLOEXEC,
const O_SYNC = libc::O_SYNC,
const O_NDELAY = libc::O_NDELAY,
const O_FSYNC = libc::O_FSYNC,
const O_SHLOCK = 0x0000080,
const O_EXLOCK = 0x0000020,
const O_DIRECT = 0x0010000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here re non-libc constants & defining them upstream

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// warnings even though the macro expands into something with allow(dead_code)
#![allow(dead_code)]
#![cfg_attr(test, deny(warnings))]
#![recursion_limit = "500"]

#[macro_use]
extern crate bitflags;
Expand Down
69 changes: 33 additions & 36 deletions src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,45 @@ use {Errno, Result, NixPath};

bitflags!(
pub flags MsFlags: c_ulong {
const MS_RDONLY = 1 << 0, // Mount read-only
const MS_NOSUID = 1 << 1, // Ignore suid and sgid bits
const MS_NODEV = 1 << 2, // Disallow access to device special files
const MS_NOEXEC = 1 << 3, // Disallow program execution
const MS_SYNCHRONOUS = 1 << 4, // Writes are synced at once
const MS_REMOUNT = 1 << 5, // Alter flags of a mounted FS
const MS_MANDLOCK = 1 << 6, // Allow mandatory locks on a FS
const MS_DIRSYNC = 1 << 7, // Directory modifications are synchronous
const MS_NOATIME = 1 << 10, // Do not update access times
const MS_NODIRATIME = 1 << 11, // Do not update directory access times
const MS_BIND = 1 << 12, // Linux 2.4.0 - Bind directory at different place
const MS_MOVE = 1 << 13,
const MS_REC = 1 << 14,
const MS_VERBOSE = 1 << 15, // Deprecated
const MS_SILENT = 1 << 15,
const MS_POSIXACL = 1 << 16,
const MS_UNBINDABLE = 1 << 17,
const MS_PRIVATE = 1 << 18,
const MS_SLAVE = 1 << 19,
const MS_SHARED = 1 << 20,
const MS_RELATIME = 1 << 21,
const MS_KERNMOUNT = 1 << 22,
const MS_I_VERSION = 1 << 23,
const MS_STRICTATIME = 1 << 24,
const MS_RDONLY = libc::MS_RDONLY, // Mount read-only
const MS_NOSUID = libc::MS_NOSUID, // Ignore suid and sgid bits
const MS_NODEV = libc::MS_NODEV, // Disallow access to device special files
const MS_NOEXEC = libc::MS_NOEXEC, // Disallow program execution
const MS_SYNCHRONOUS = libc::MS_SYNCHRONOUS, // Writes are synced at once
const MS_REMOUNT = libc::MS_REMOUNT, // Alter flags of a mounted FS
const MS_MANDLOCK = libc::MS_MANDLOCK, // Allow mandatory locks on a FS
const MS_DIRSYNC = libc::MS_DIRSYNC, // Directory modifications are synchronous
const MS_NOATIME = libc::MS_NOATIME, // Do not update access times
const MS_NODIRATIME = libc::MS_NODIRATIME, // Do not update directory access times
const MS_BIND = libc::MS_BIND, // Linux 2.4.0 - Bind directory at different place
const MS_MOVE = libc::MS_MOVE,
const MS_REC = libc::MS_REC,
const MS_VERBOSE = 1 << 15, // Deprecated
const MS_SILENT = libc::MS_SILENT,
const MS_POSIXACL = libc::MS_POSIXACL,
const MS_UNBINDABLE = libc::MS_UNBINDABLE,
const MS_PRIVATE = libc::MS_PRIVATE,
const MS_SLAVE = libc::MS_SLAVE,
const MS_SHARED = libc::MS_SHARED,
const MS_RELATIME = libc::MS_RELATIME,
const MS_KERNMOUNT = libc::MS_KERNMOUNT,
const MS_I_VERSION = libc::MS_I_VERSION,
const MS_STRICTATIME = libc::MS_STRICTATIME,
const MS_NOSEC = 1 << 28,
const MS_BORN = 1 << 29,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again :-)

const MS_ACTIVE = 1 << 30,
const MS_NOUSER = 1 << 31,
const MS_RMT_MASK = MS_RDONLY.bits
| MS_SYNCHRONOUS.bits
| MS_MANDLOCK.bits
| MS_I_VERSION.bits,
const MS_MGC_VAL = 0xC0ED0000,
const MS_MGC_MSK = 0xffff0000
const MS_ACTIVE = libc::MS_ACTIVE,
const MS_NOUSER = libc::MS_NOUSER,
const MS_RMT_MASK = libc::MS_RMT_MASK,
const MS_MGC_VAL = libc::MS_MGC_VAL,
const MS_MGC_MSK = libc::MS_MGC_MSK,
}
);

bitflags!(
libc_bitflags!(
pub flags MntFlags: c_int {
const MNT_FORCE = 1 << 0,
const MNT_DETACH = 1 << 1,
const MNT_EXPIRE = 1 << 2
MNT_FORCE,
MNT_DETACH,
MNT_EXPIRE,
}
);

Expand Down
34 changes: 17 additions & 17 deletions src/sys/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ use ::Error;

bitflags!(
#[repr(C)]
pub flags EpollFlags: u32 {
const EPOLLIN = 0x001,
const EPOLLPRI = 0x002,
const EPOLLOUT = 0x004,
const EPOLLRDNORM = 0x040,
const EPOLLRDBAND = 0x080,
const EPOLLWRNORM = 0x100,
const EPOLLWRBAND = 0x200,
const EPOLLMSG = 0x400,
const EPOLLERR = 0x008,
const EPOLLHUP = 0x010,
const EPOLLRDHUP = 0x2000,
pub flags EpollFlags: libc::c_int {
const EPOLLIN = libc::EPOLLIN,
const EPOLLPRI = libc::EPOLLPRI,
const EPOLLOUT = libc::EPOLLOUT,
const EPOLLRDNORM = libc::EPOLLRDNORM,
const EPOLLRDBAND = libc::EPOLLRDBAND,
const EPOLLWRNORM = libc::EPOLLWRNORM,
const EPOLLWRBAND = libc::EPOLLWRBAND,
const EPOLLMSG = libc::EPOLLMSG,
const EPOLLERR = libc::EPOLLERR,
const EPOLLHUP = libc::EPOLLHUP,
const EPOLLRDHUP = libc::EPOLLRDHUP,
const EPOLLEXCLUSIVE = 1 << 28,
const EPOLLWAKEUP = 1 << 29,
const EPOLLONESHOT = 1 << 30,
const EPOLLET = 1 << 31
const EPOLLWAKEUP = libc::EPOLLWAKEUP,
const EPOLLONESHOT = libc::EPOLLONESHOT,
const EPOLLET = libc::EPOLLET,
}
);

Expand All @@ -48,15 +48,15 @@ pub struct EpollEvent {

impl EpollEvent {
pub fn new(events: EpollFlags, data: u64) -> Self {
EpollEvent { event: libc::epoll_event { events: events.bits(), u64: data } }
EpollEvent { event: libc::epoll_event { events: events.bits() as u32, u64: data } }
}

pub fn empty() -> Self {
unsafe { mem::zeroed::<EpollEvent>() }
}

pub fn events(&self) -> EpollFlags {
EpollFlags::from_bits(self.event.events).unwrap()
EpollFlags::from_bits(self.event.events as libc::c_int).unwrap()
}

pub fn data(&self) -> u64 {
Expand Down
Loading