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

std: use more LFS functions on Linux #31668

Merged
merged 4 commits into from
Feb 16, 2016
Merged

std: use more LFS functions on Linux #31668

merged 4 commits into from
Feb 16, 2016

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Feb 15, 2016

This follows the pattern already used for stat functions from #31551. Now
ftruncate, lseek, and readdir_r use their explicit 64-bit variants for
LFS support, using wider off_t and dirent types. This also updates to
open64, which uses no different types but implies the O_LARGEFILE flag.

Non-Linux platforms just map their normal functions to the 64-bit names.

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+ c84ab39

Neat!

@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Feb 15, 2016
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 16, 2016
This follows the pattern already used for stat functions from rust-lang#31551.  Now
`ftruncate`, `lseek`, and `readdir_r` use their explicit 64-bit variants for
LFS support, using wider `off_t` and `dirent` types.  This also updates to
`open64`, which uses no different types but implies the `O_LARGEFILE` flag.

Non-Linux platforms just map their normal functions to the 64-bit names.

r? @alexcrichton
@Stebalien
Copy link
Contributor

What happens if someone writes the following on a 32bit platform?

let file = File::from_raw_fd(libc::open(...)); // non LFS open
file.set_len(u32::MAX + 1);

I assume (hope) this fails gracefully (or succeeds) but doesn't do anything weird.

@cuviper
Copy link
Member Author

cuviper commented Feb 16, 2016

@Stebalien good question -- assuming you do cast that u32::MAX+1 to u64 first... ;)

We'll also assume your file wasn't already >=2GB, or that libc::open would immediately fail.

AFAICT Rust doesn't care at all, so it's up to the kernel's behavior. System call ftruncate64 calls do_sys_ftruncate with small=0, so it skips the LFS check. Your file should grow as desired. So I guess if you then did a non-LFS libc::fstat you'd now get EOVERFLOW.

Actually, the old behavior would have been the "weird" one, silently taking size as off_t (32-bit) to make your u32::MAX+1 a nice fat 0. Say goodbye to your file contents. 👋 In fact, any size greater than i32::MAX would have behaved really badly before.

@bors
Copy link
Contributor

bors commented Feb 16, 2016

⌛ Testing commit c84ab39 with merge 28bcafa...

bors added a commit that referenced this pull request Feb 16, 2016
This follows the pattern already used for stat functions from #31551.  Now
`ftruncate`, `lseek`, and `readdir_r` use their explicit 64-bit variants for
LFS support, using wider `off_t` and `dirent` types.  This also updates to
`open64`, which uses no different types but implies the `O_LARGEFILE` flag.

Non-Linux platforms just map their normal functions to the 64-bit names.

r? @alexcrichton
@bors bors merged commit c84ab39 into rust-lang:master Feb 16, 2016
@Stebalien
Copy link
Contributor

@cuviper Thanks. I just wanted to make sure that mixing and matching LFS/non LFS syscalls wouldn't' cause any problems (for backwards comparability).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants