From eccea1980d961a6ac6ab4cf3294edce8ca6e9c11 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sat, 26 Jul 2008 16:22:14 -0700 Subject: [PATCH] add fstat, stat R=ken OCL=13497 CL=13497 --- src/syscall/Makefile | 1 + src/syscall/stat_amd64_darwin.go | 49 +++++++++++++++++ src/syscall/stat_amd64_linux.go | 47 +++++++++++++++++ src/syscall/syscall.go | 8 ++- src/syscall/syscall_amd64_darwin.s | 70 +++++++++---------------- src/syscall/syscall_amd64_linux.s | 84 +++++++++++------------------- 6 files changed, 159 insertions(+), 100 deletions(-) create mode 100644 src/syscall/stat_amd64_darwin.go create mode 100644 src/syscall/stat_amd64_linux.go diff --git a/src/syscall/Makefile b/src/syscall/Makefile index fc21794c70f..c5257b6a5fb 100644 --- a/src/syscall/Makefile +++ b/src/syscall/Makefile @@ -13,6 +13,7 @@ PKG=syscall.a OFILES=\ syscall.$O \ errstr_$(GOOS).$O \ + stat_$(GOARCH)_$(GOOS).$O \ syscall_$(GOARCH)_$(GOOS).$O \ diff --git a/src/syscall/stat_amd64_darwin.go b/src/syscall/stat_amd64_darwin.go new file mode 100644 index 00000000000..84a09d2bddf --- /dev/null +++ b/src/syscall/stat_amd64_darwin.go @@ -0,0 +1,49 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package syscall + +func stat(*byte, *Stat) (ret int64, errno int64); +func fstat(int64, *Stat) (ret int64, errno int64); + +export Stat +export stat, fstat + +// Stat and relatives for Linux + +type dev_t uint32; +type ino_t uint64; +type mode_t uint16; +type nlink_t uint16; +type uid_t uint32; +type gid_t uint32; +type off_t int64; +type blksize_t int64; +type blkcnt_t int64; +type time_t int64; + +type Timespec struct { + tv_sec time_t; + tv_nsec int64; +} + +type Stat struct { + st_dev dev_t; /* ID of device containing file */ + st_mode mode_t; /* protection */ + st_nlink nlink_t; /* number of hard links */ + st_ino ino_t; /* inode number */ + st_uid uid_t; /* user ID of owner */ + st_gid gid_t; /* group ID of owner */ + st_rdev dev_t; /* device ID (if special file) */ + st_atime Timespec; /* time of last access */ + st_mtime Timespec; /* time of last modification */ + st_ctime Timespec; /* time of last status change */ + st_birthtimespec Timespec; /* birth time */ + st_size off_t; /* total size, in bytes */ + st_blocks blkcnt_t; /* number of blocks allocated */ + st_blksize blksize_t; /* blocksize for filesystem I/O */ + st_flags uint32; + st_gen uint32; + st_qspare[2] int64; +} diff --git a/src/syscall/stat_amd64_linux.go b/src/syscall/stat_amd64_linux.go new file mode 100644 index 00000000000..92d99e4caa4 --- /dev/null +++ b/src/syscall/stat_amd64_linux.go @@ -0,0 +1,47 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package syscall + +func stat(*byte, *Stat) (ret int64, errno int64); +func fstat(int64, *Stat) (ret int64, errno int64); + +export Stat +export stat, fstat + +// Stat and relatives for Linux + +type dev_t uint64; +type ino_t uint64; +type mode_t uint32; +type nlink_t uint64; +type uid_t uint32; +type gid_t uint32; +type off_t int64; +type blksize_t int64; +type blkcnt_t int64; +type time_t int64; + +type Timespec struct { + tv_sec time_t; + tv_nsec int64; +} + +type Stat struct { + st_dev dev_t; /* ID of device containing file */ + st_ino ino_t; /* inode number */ + st_nlink nlink_t; /* number of hard links */ + st_mode mode_t; /* protection */ + st_uid uid_t; /* user ID of owner */ + st_gid gid_t; /* group ID of owner */ + pad0 int32; + st_rdev dev_t; /* device ID (if special file) */ + st_size off_t; /* total size, in bytes */ + st_blksize blksize_t; /* blocksize for filesystem I/O */ + st_blocks blkcnt_t; /* number of blocks allocated */ + st_atime Timespec; /* time of last access */ + st_mtime Timespec; /* time of last modification */ + st_ctime Timespec; /* time of last status change */ +} + diff --git a/src/syscall/syscall.go b/src/syscall/syscall.go index 49d7401ed47..f6277d414f6 100644 --- a/src/syscall/syscall.go +++ b/src/syscall/syscall.go @@ -4,8 +4,12 @@ package syscall -// for simplicity of addressing in assembler, all integers are 64 bits -// in these calling sequences. +/* + * These calls have signatures that are independent of operating system. + * + * For simplicity of addressing in assembler, all integers are 64 bits + * in these calling sequences. + */ func open(*byte, int64) (ret int64, errno int64); func close(int64) (ret int64, errno int64); diff --git a/src/syscall/syscall_amd64_darwin.s b/src/syscall/syscall_amd64_darwin.s index a87352e8e2b..3f32ff653b9 100644 --- a/src/syscall/syscall_amd64_darwin.s +++ b/src/syscall/syscall_amd64_darwin.s @@ -6,13 +6,6 @@ // System calls for AMD64, Darwin // -//TEXT syscall·exit(SB),1,$-8 -// MOVL 8(SP), DI // arg 1 exit status -// MOVL $(0x2000000+1), AX // syscall entry -// SYSCALL -// CALL notok(SB) -// RET - TEXT syscall·open(SB),1,$-8 MOVQ 8(SP), DI MOVQ 16(SP), SI @@ -67,41 +60,28 @@ TEXT syscall·write(SB),1,$-8 MOVQ $0, 40(SP) RET -//TEXT fstat(SB),1,$-8 -// MOVL 8(SP), DI -// MOVQ 16(SP), SI -// MOVL $(0x2000000+339), AX // syscall entry; really fstat64 -// SYSCALL -// RET -// -//TEXT syscall·sigaction(SB),1,$-8 -// MOVL 8(SP), DI // arg 1 sig -// MOVQ 16(SP), SI // arg 2 act -// MOVQ 24(SP), DX // arg 3 oact -// MOVQ 24(SP), CX // arg 3 oact -// MOVQ 24(SP), R10 // arg 3 oact -// MOVL $(0x2000000+46), AX // syscall entry -// SYSCALL -// JCC 2(PC) -// CALL notok(SB) -// RET -// -//TEXT sigtramp(SB),1,$24 -// MOVL DX,0(SP) -// MOVQ CX,8(SP) -// MOVQ R8,16(SP) -// CALL sighandler(SB) -// RET -// -//TEXT syscall·mmap(SB),1,$-8 -// MOVQ 8(SP), DI // arg 1 addr -// MOVL 16(SP), SI // arg 2 len -// MOVL 20(SP), DX // arg 3 prot -// MOVL 24(SP), R10 // arg 4 flags -// MOVL 28(SP), R8 // arg 5 fid -// MOVL 32(SP), R9 // arg 6 offset -// MOVL $(0x2000000+197), AX // syscall entry -// SYSCALL -// JCC 2(PC) -// CALL notok(SB) -// RET +TEXT syscall·stat(SB),1,$-8 + MOVQ 8(SP), DI + MOVQ 16(SP), SI + MOVL $(0x2000000+338), AX // syscall entry + SYSCALL + JCC 4(PC) + MOVQ $-1, 24(SP) + MOVQ AX, 32(SP) + RET + MOVQ AX, 24(SP) + MOVQ $0, 32(SP) + RET + +TEXT syscall·fstat(SB),1,$-8 + MOVQ 8(SP), DI + MOVQ 16(SP), SI + MOVL $(0x2000000+339), AX // syscall entry + SYSCALL + JCC 4(PC) + MOVQ $-1, 24(SP) + MOVQ AX, 32(SP) + RET + MOVQ AX, 24(SP) + MOVQ $0, 32(SP) + RET diff --git a/src/syscall/syscall_amd64_linux.s b/src/syscall/syscall_amd64_linux.s index 9690a96362a..7eab69fc0d8 100644 --- a/src/syscall/syscall_amd64_linux.s +++ b/src/syscall/syscall_amd64_linux.s @@ -6,12 +6,6 @@ // System calls for AMD64, Linux // -//TEXT sys·exit(SB),1,$0-8 -// MOVL 8(SP), DI -// MOVL $60, AX -// SYSCALL -// RET - TEXT syscall·open(SB),1,$0-16 MOVQ 8(SP), DI MOVQ 16(SP), SI @@ -42,13 +36,6 @@ TEXT syscall·close(SB),1,$0-16 MOVQ $0, 24(SP) RET -//TEXT fstat(SB),1,$0-16 -// MOVL 8(SP), DI -// MOVQ 16(SP), SI -// MOVL $5, AX // syscall entry -// SYSCALL -// RET - TEXT syscall·read(SB),1,$0-16 MOVL 8(SP), DI MOVQ 16(SP), SI @@ -81,43 +68,34 @@ TEXT syscall·write(SB),1,$0-16 MOVQ $0, 40(SP) RET -//TEXT sys·rt_sigaction(SB),1,$0-32 -// MOVL 8(SP), DI -// MOVQ 16(SP), SI -// MOVQ 24(SP), DX -// MOVQ 32(SP), CX -// MOVL CX, R10 -// MOVL $13, AX // syscall entry -// SYSCALL -// RET -// -//TEXT sigtramp(SB),1,$24-16 -// MOVQ DI,0(SP) -// MOVQ SI,8(SP) -// MOVQ DX,16(SP) -// CALL sighandler(SB) -// RET -// -//TEXT sys·mmap(SB),1,$0-32 -// MOVQ 8(SP), DI -// MOVL 16(SP), SI -// MOVL 20(SP), DX -// MOVL 24(SP), CX -// MOVL 28(SP), R8 -// MOVL 32(SP), R9 -// -///* flags arg for ANON is 1000 but sb 20 */ -// MOVL CX, AX -// ANDL $~0x1000, CX -// ANDL $0x1000, AX -// SHRL $7, AX -// ORL AX, CX -// -// MOVL CX, R10 -// MOVL $9, AX // syscall entry -// SYSCALL -// CMPQ AX, $0xfffffffffffff001 -// JLS 2(PC) -// CALL notok(SB) -// RET -// +TEXT syscall·stat(SB),1,$0-16 + MOVQ 8(SP), DI + MOVQ 16(SP), SI + MOVQ $0, DX + MOVQ $5, AX // syscall entry + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS 5(PC) + MOVQ $-1, 24(SP) + NEGQ AX + MOVQ AX, 32(SP) + RET + MOVQ AX, 24(SP) + MOVQ $0, 32(SP) + RET + +TEXT syscall·fstat(SB),1,$0-16 + MOVL 8(SP), DI + MOVQ 16(SP), SI + MOVQ $0, DX + MOVQ $5, AX // syscall entry + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS 5(PC) + MOVQ $-1, 24(SP) + NEGQ AX + MOVQ AX, 32(SP) + RET + MOVQ AX, 24(SP) + MOVQ $0, 32(SP) + RET