Page 1 of 1

what are the fields in os.stat

Posted: Sun Sep 23, 2018 8:51 am
by rhubarbdog
os.stat returns a tuple what does each number represent?
i'm guessing the 7 element `os.stat()[6]` is the number of bytes the file takes up.
How could i have researched this myself i couldn't find any `os.c` or `os.py` file at https://github.com/micropython/micropython/

Re: what are the fields in os.stat

Posted: Sun Sep 23, 2018 10:07 am
by Roberthh
The tuple follows the python standard, explained e.g. here:
https://www.tutorialspoint.com/python3/os_stat.htm
But due to the limitation of the FAT file system, only a few members have reasonable value.
os.stat()[0] tells the file type, regular or directory.
os.stat()[6] is the file size
os.stat()[7], os.stat()[8], os.stat()[9] are all the same and tell the modification time. For that value to be correct, the time has to be set.
The place where this is implemented is micropython/extmod/vfs_fat.c, line 293ff

Re: what are the fields in os.stat

Posted: Thu Dec 09, 2021 4:15 pm
by tecdroid
btw. why isn't this put into a tiny class like fsstatvs? I mean, this shouldn't be that much effort and makes uos a little more like python os..