Skip to content

Commit

Permalink
fix osx fstatat to use 32 bit stat type, as cannot find how to call t…
Browse files Browse the repository at this point in the history
…o get 64 bit one

Signed-off-by: Justin Cormack <justin@specialbusservice.com>
  • Loading branch information
justincormack committed Jan 9, 2016
1 parent 8a0a6ad commit 602a2b3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
1 change: 0 additions & 1 deletion syscall/bsd/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ int mkfifoat(int dirfd, const char *pathname, mode_t mode);
int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
int faccessat(int dirfd, const char *pathname, int mode, int flags);
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
int futimens(int fd, const struct timespec times[2]);
int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
Expand Down
1 change: 1 addition & 0 deletions syscall/freebsd/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ int cap_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds);
ssize_t cap_ioctls_get(int fd, unsigned long *cmds, size_t maxcmds);
int cap_fcntls_limit(int fd, uint32_t fcntlrights);
int cap_fcntls_get(int fd, uint32_t *fcntlrightsp);
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
int __sys_utimes(const char *filename, const struct timeval times[2]);
int __sys_futimes(int, const struct timeval times[2]);
Expand Down
2 changes: 2 additions & 0 deletions syscall/netbsd/ffifunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ int __nanosleep50(const struct timespec *req, struct timespec *rem);
int __timer_settime50(timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec * old_value);
int __timer_gettime50(timer_t timerid, struct itimerspec *curr_value);
int __adjtime50(const struct timeval *delta, struct timeval *olddelta);
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
]]

1 change: 1 addition & 0 deletions syscall/openbsd/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ struct sigaction {
append [[
int reboot(int howto);
int ioctl(int d, unsigned long request, void *arg);
int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
/* not syscalls, but using for now */
int grantpt(int fildes);
Expand Down
3 changes: 2 additions & 1 deletion syscall/osx/c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ local C = setmetatable({}, {
})

-- new stat structure, else get legacy one; could use syscalls instead
-- does not work for fstatat
C.stat = C.stat64
C.fstat = C.fstat64
C.lstat = C.lstat64
Expand All @@ -56,7 +57,7 @@ function C.getdirentries(fd, buf, len, basep)
end
]]

-- cannot find these anywhere!
-- cannot find these anywhere! Apparently not there since 64 bit inodes?
--C.getdirentries = ffi.C._getdirentries
--C.sigaction = ffi.C._sigaction

Expand Down
25 changes: 23 additions & 2 deletions syscall/osx/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ typedef int64_t blkcnt_t;
typedef int32_t blksize_t;
typedef int32_t suseconds_t;
typedef uint16_t nlink_t;
typedef uint64_t ino_t; // at least on recent desktop; TODO define as ino64_t
typedef uint64_t ino64_t;
typedef uint32_t ino_t;
typedef long time_t;
typedef int32_t daddr_t;
typedef unsigned long clock_t;
Expand Down Expand Up @@ -158,7 +159,7 @@ struct stat {
dev_t st_dev;
mode_t st_mode;
nlink_t st_nlink;
ino_t st_ino;
ino64_t st_ino;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
Expand All @@ -174,6 +175,25 @@ struct stat {
int32_t st_lspare;
int64_t st_qspare[2];
};
struct stat32 {
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
struct timespec st_atimespec;
struct timespec st_mtimespec;
struct timespec st_ctimespec;
off_t st_size;
blkcnt_t st_blocks;
blksize_t st_blksize;
uint32_t st_flags;
uint32_t st_gen;
int32_t st_lspare;
int64_t st_qspare[2];
};
union sigval {
int sival_int;
void *sival_ptr;
Expand Down Expand Up @@ -292,6 +312,7 @@ int mount(const char *type, const char *dir, int flags, void *data);
int stat64(const char *path, struct stat *sb);
int lstat64(const char *path, struct stat *sb);
int fstat64(int fd, struct stat *sb);
int fstatat(int dirfd, const char *pathname, struct stat32 *buf, int flags);
int _getdirentries(int fd, char *buf, int nbytes, long *basep);
int _sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
Expand Down
8 changes: 8 additions & 0 deletions syscall/osx/syscalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ function S.clock_get_time(clock_serv, cur_time)
return cur_time
end

-- cannot find out how to get new stat type from fstatat
function S.fstatat(fd, path, buf, flags)
if not buf then buf = t.stat32() end
local ret, err = C.fstatat(c.AT_FDCWD[fd], path, buf, c.AT[flags])
if ret == -1 then return nil, t.error(err or errno()) end
return buf
end

return S

end
Expand Down
3 changes: 3 additions & 0 deletions syscall/osx/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ end

addtype(types, "stat", "struct stat", mt.stat)

-- for fstatat where we can'tseem to get 64 bit version at present
addtype(types, "stat32", "struct stat32", mt.stat)

local signames = {}
local duplicates = {LWT = true, IOT = true, CLD = true, POLL = true}
for k, v in pairs(c.SIG) do
Expand Down

0 comments on commit 602a2b3

Please sign in to comment.