Fix arm/x86(32) linux stat (#153)

* Fix sys_fstat

i'm pretty sure it was totally wrong before, in terms of how it laid
out the struct

I'm based this on using arm-linux-gnueabi-gcc -E
which shows me this struct:

struct stat
  {
    __dev_t st_dev;
    unsigned short int __pad1;

    __ino_t st_ino;

    __mode_t st_mode;
    __nlink_t st_nlink;
    __uid_t st_uid;
    __gid_t st_gid;
    __dev_t st_rdev;
    unsigned short int __pad2;

    __off_t st_size;

    __blksize_t st_blksize;

    __blkcnt_t st_blocks;
# 72 "/usr/arm-linux-gnueabi/include/bits/stat.h" 3
    struct timespec st_atim;
    struct timespec st_mtim;
    struct timespec st_ctim;
# 87 "/usr/arm-linux-gnueabi/include/bits/stat.h" 3
    unsigned long int __glibc_reserved4;
    unsigned long int __glibc_reserved5;

  };

* Add stat32

* Minor
This commit is contained in:
Mark Mossberg
2017-04-20 14:03:35 -04:00
committed by GitHub
parent 87073d9985
commit 4ad028b0df

View File

@@ -1535,7 +1535,7 @@ class Linux(object):
0x0000008d: self.sys_getpriority,
0x00000092: self.sys_writev32,
0x000000c0: self.sys_mmap2,
0x000000c3: self.sys_stat64,
0x000000c3: self.sys_stat32,
0x000000c5: self.sys_fstat,
0x000000c7: self.sys_getuid,
0x000000c8: self.sys_getgid,
@@ -1789,8 +1789,17 @@ class Linux(object):
:param buf: a buffer where data about the file will be stored.
:return: C{0} on success.
'''
return self._stat(cpu, path, buf, True)
def sys_stat32(self, cpu, path, buf):
return self._stat(cpu, path, buf, False)
def _stat(self, cpu, path, buf, is64bit):
fd = self.sys_open(cpu, path, 0, 'r')
ret = self.sys_fstat64(cpu, fd, buf)
if is64bit:
ret = self.sys_fstat64(cpu, fd, buf)
else:
ret = self.sys_fstat(cpu, fd, buf)
self.sys_close(cpu, fd)
return ret
@@ -1938,26 +1947,22 @@ class SLinux(Linux):
'''
stat = self.files[fd].stat()
bufstat = ''
bufstat += struct.pack('<L', stat.st_dev)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<Q', stat.st_dev)
bufstat += struct.pack('<L', 0) # pad1
bufstat += struct.pack('<L', stat.st_ino)
bufstat += struct.pack('<L', stat.st_mode)
bufstat += struct.pack('<L', stat.st_nlink)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', 0) # uid
bufstat += struct.pack('<L', 0) # gid
bufstat += struct.pack('<Q', 0) # rdev
bufstat += struct.pack('<L', 0) # pad2
bufstat += struct.pack('<L', stat.st_size)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('<L', stat.st_blksize)
bufstat += struct.pack('<L', stat.st_blocks)
bufstat += struct.pack('<L', 0)
bufstat += struct.pack('d', stat.st_atime)
bufstat += struct.pack('d', stat.st_ctime)
bufstat += struct.pack('d', stat.st_mtime)
bufstat += struct.pack('<Q', stat.st_atime)
bufstat += struct.pack('<Q', stat.st_ctime)
bufstat += struct.pack('<Q', stat.st_mtime)
cpu.write_bytes(buf, bufstat)
return 0