mirror of
https://github.com/golang/go
synced 2024-11-21 18:14:42 -07:00
syscall: fix Ftruncate under linux/arm5
Fixes #1714. R=rsc, bradfitzgo CC=golang-dev https://golang.org/cl/4441056
This commit is contained in:
parent
c94db30ec9
commit
d5864454dc
@ -567,8 +567,8 @@ func checkSize(t *testing.T, f *File, size int64) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
f := newFile("TestTruncate", t)
|
||||
func TestFTruncate(t *testing.T) {
|
||||
f := newFile("TestFTruncate", t)
|
||||
defer Remove(f.Name())
|
||||
defer f.Close()
|
||||
|
||||
@ -585,6 +585,24 @@ func TestTruncate(t *testing.T) {
|
||||
checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
f := newFile("TestTruncate", t)
|
||||
defer Remove(f.Name())
|
||||
defer f.Close()
|
||||
|
||||
checkSize(t, f, 0)
|
||||
f.Write([]byte("hello, world\n"))
|
||||
checkSize(t, f, 13)
|
||||
Truncate(f.Name(), 10)
|
||||
checkSize(t, f, 10)
|
||||
Truncate(f.Name(), 1024)
|
||||
checkSize(t, f, 1024)
|
||||
Truncate(f.Name(), 0)
|
||||
checkSize(t, f, 0)
|
||||
f.Write([]byte("surprise!"))
|
||||
checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
|
||||
}
|
||||
|
||||
// Use TempDir() to make sure we're on a local file system,
|
||||
// so that timings are not distorted by latency and caching.
|
||||
// On NFS, timings can be off due to caching of meta-data on
|
||||
|
@ -24,7 +24,6 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
|
||||
}
|
||||
|
||||
// Pread and Pwrite are special: they insert padding before the int64.
|
||||
// (Ftruncate and truncate are not; go figure.)
|
||||
|
||||
func Pread(fd int, p []byte, offset int64) (n int, errno int) {
|
||||
var _p0 unsafe.Pointer
|
||||
@ -48,6 +47,20 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
|
||||
return
|
||||
}
|
||||
|
||||
func Ftruncate(fd int, length int64) (errno int) {
|
||||
// ARM EABI requires 64-bit arguments should be put in a pair
|
||||
// of registers from an even register number.
|
||||
_, _, e1 := Syscall6(SYS_FTRUNCATE64, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0)
|
||||
errno = int(e1)
|
||||
return
|
||||
}
|
||||
|
||||
func Truncate(path string, length int64) (errno int) {
|
||||
_, _, e1 := Syscall6(SYS_TRUNCATE64, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, uintptr(length), uintptr(length>>32), 0, 0)
|
||||
errno = int(e1)
|
||||
return
|
||||
}
|
||||
|
||||
// Seek is defined in assembly.
|
||||
|
||||
func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
|
||||
@ -72,7 +85,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
|
||||
//sys Fchown(fd int, uid int, gid int) (errno int)
|
||||
//sys Fstat(fd int, stat *Stat_t) (errno int) = SYS_FSTAT64
|
||||
//sys Fstatfs(fd int, buf *Statfs_t) (errno int) = SYS_FSTATFS64
|
||||
//sys Ftruncate(fd int, length int64) (errno int) = SYS_FTRUNCATE64
|
||||
//sysnb Getegid() (egid int)
|
||||
//sysnb Geteuid() (euid int)
|
||||
//sysnb Getgid() (gid int)
|
||||
@ -92,7 +104,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
|
||||
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, errno int)
|
||||
//sys Stat(path string, stat *Stat_t) (errno int) = SYS_STAT64
|
||||
//sys Statfs(path string, buf *Statfs_t) (errno int) = SYS_STATFS64
|
||||
//sys Truncate(path string, length int64) (errno int) = SYS_TRUNCATE64
|
||||
|
||||
// Vsyscalls on amd64.
|
||||
//sysnb Gettimeofday(tv *Timeval) (errno int)
|
||||
|
@ -970,14 +970,6 @@ func Fstatfs(fd int, buf *Statfs_t) (errno int) {
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Ftruncate(fd int, length int64) (errno int) {
|
||||
_, _, e1 := Syscall(SYS_FTRUNCATE64, uintptr(fd), uintptr(length>>32), uintptr(length))
|
||||
errno = int(e1)
|
||||
return
|
||||
}
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Getegid() (egid int) {
|
||||
r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0)
|
||||
egid = int(r0)
|
||||
@ -1132,14 +1124,6 @@ func Statfs(path string, buf *Statfs_t) (errno int) {
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Truncate(path string, length int64) (errno int) {
|
||||
_, _, e1 := Syscall(SYS_TRUNCATE64, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(length>>32), uintptr(length))
|
||||
errno = int(e1)
|
||||
return
|
||||
}
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Gettimeofday(tv *Timeval) (errno int) {
|
||||
_, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0)
|
||||
errno = int(e1)
|
||||
|
Loading…
Reference in New Issue
Block a user