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

fstat not return right file-size when compile it with -m32 #6203

Closed
bitbegin opened this issue Nov 6, 2020 · 4 comments
Closed

fstat not return right file-size when compile it with -m32 #6203

bitbegin opened this issue Nov 6, 2020 · 4 comments

Comments

@bitbegin
Copy link

bitbegin commented Nov 6, 2020

Environment

Microsoft Windows [Version 10.0.20236.1005]
(c) 2020 Microsoft Corporation. All rights reserved.

Release:        20.04
Linux version 4.19.128-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Tue Jun 23 12:58:10 UTC 2020

Steps to reproduce

prepare tools:

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386

sudo apt-get install gcc
sudo apt-get install gcc-multilib

source code:

#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    char *infile;
    int fd;
    struct stat finfo;
    if (argc != 2)
    {
            fprintf(stderr, "Too many arguments.\n");
            exit(1);
    }

    infile = argv[1];
    fd = open(infile, O_RDONLY);

    fstat(fd, &finfo);
    printf("file: %s, size: %ld\n", infile, finfo.st_size);
}

compile it with gcc -o test test.c, and run ./test test.c, get file: test.c, size: 418, it's right;

compile it with gcc -m32 -o test test.c, and run ./test test.c, get file: test.c, size: -135036928, it's not right!

Expected behavior

the result with -m32 flag should also right.

Actual behavior

fstat not return right file-size when compile it with -m32.

@hiiamboris
Copy link

Worth noting: wrong results are only returned for files on (auto)mounted Windows partitions. That is, for the above test to fail you have to place test.c anywhere in /mnt/c/ or similar path.

@bitbegin
Copy link
Author

bitbegin commented Nov 6, 2020

if you run it in ~/ folder, return size ok. if you run it in other place like /mnt/d, the size will be not right

@therealkenc
Copy link
Collaborator

therealkenc commented Nov 10, 2020

Thanks for the submission and the nice repro. Interesting catch; was able to reproduce. Fascinatingly, the program has the same behavior on a Real Linux™ box with a mounted CIFS share to Windows.

image

Note the fstat64(2) does return 418. I've tried for a couple of hours to justify the behavior, but cannot. It is unexpected behavior alright, but also not unique to WSL.

Copy link
Contributor

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants