本文整理匯總了Golang中syscall.Fsync函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fsync函數的具體用法?Golang Fsync怎麽用?Golang Fsync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fsync函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFSync
func TestFSync(t *testing.T) {
tc := NewTestCase(t)
defer tc.Cleanup()
contents := []byte{1, 2, 3}
if err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700); err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
f, err := os.OpenFile(tc.mountFile, os.O_WRONLY, 0)
if err != nil {
t.Fatalf("OpenFile(%q): %v", tc.mountFile, err)
}
defer f.Close()
if _, err := f.WriteString("hello there"); err != nil {
t.Fatalf("WriteString failed: %v", err)
}
// How to really test fsync ?
err = syscall.Fsync(int(f.Fd()))
if err != nil {
t.Errorf("fsync returned: %v", err)
}
}
示例2: TestCreate
func TestCreate(t *testing.T) {
t.Parallel()
f := &create1{}
mnt, err := fstestutil.MountedT(t, fstestutil.SimpleFS{f})
if err != nil {
t.Fatal(err)
}
defer mnt.Close()
// uniform umask needed to make os.Create's 0666 into something
// reproducible
defer syscall.Umask(syscall.Umask(0022))
ff, err := os.Create(mnt.Dir + "/foo")
if err != nil {
t.Fatalf("create1 WriteFile: %v", err)
}
defer ff.Close()
err = syscall.Fsync(int(ff.Fd()))
if err != nil {
t.Fatalf("Fsync = %v", err)
}
if f.f.RecordedFsync() == (fuse.FsyncRequest{}) {
t.Errorf("never received expected fsync call")
}
ff.Close()
}
示例3: test
func (w *write) test(path string, t *testing.T) {
log.Printf("pre-write Create")
f, err := os.Create(path)
if err != nil {
t.Fatalf("Create: %v", err)
}
log.Printf("pre-write Write")
n, err := f.Write([]byte(hi))
if err != nil {
t.Fatalf("Write: %v", err)
}
if n != len(hi) {
t.Fatalf("short write; n=%d; hi=%d", n, len(hi))
}
err = syscall.Fsync(int(f.Fd()))
if err != nil {
t.Fatalf("Fsync = %v", err)
}
if !<-w.seen.fsync {
t.Errorf("never received expected fsync call")
}
log.Printf("pre-write Close")
err = f.Close()
if err != nil {
t.Fatalf("Close: %v", err)
}
log.Printf("post-write Close")
if got := string(gather(w.seen.data)); got != hi {
t.Errorf("writeAll = %q, want %q", got, hi)
}
}
示例4: main
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s", Help)
os.Exit(1)
}
flag.Parse()
dir, err := os.Getwd()
if err != nil {
fatal.Fatalln(err)
}
// "To flush all open files on a volume, call FlushFileBuffers with a handle to the volume.
// The caller must have administrative privileges. For more information, see Running with Special Privileges."
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85).aspx
fp := filepath.VolumeName(dir)
file, err := os.Open(fp)
if err != nil {
fatal.Fatalln(err)
}
err = syscall.Fsync(syscall.Handle(file.Fd()))
if err != nil {
fatal.Fatalln(err)
}
}
示例5: Fsync
func (f *file) Fsync(flags int) (code fuse.Status) {
f.fdLock.Lock()
r := fuse.ToStatus(syscall.Fsync(int(f.fd.Fd())))
f.fdLock.Unlock()
return r
}
示例6: Fsync
func (f *loopbackFile) Fsync(flags int) (code fuse.Status) {
f.lock.Lock()
r := fuse.ToStatus(syscall.Fsync(int(f.File.Fd())))
f.lock.Unlock()
return r
}
示例7: main
func main() {
var rval int = sysexits.OK
args := os.Args
if len(args) < 2 {
usage()
}
for _, f := range args[1:] {
if fd, err := syscall.Open(f, syscall.O_RDONLY, 0777); err != nil {
log.Printf("open %s: %v\n", f, err)
if rval == sysexits.OK {
rval = sysexits.NOINPUT
}
continue
} else {
if errf := syscall.Fsync(fd); errf != nil {
log.Printf("fsync %s:%v\n", f, errf)
if rval == sysexits.OK {
rval = sysexits.OSERR
}
}
syscall.Close(fd)
}
}
os.Exit(rval)
}
示例8: save
// Save the snapshot to a file
func (ss *Snapshot) save() error {
// Write machine state to temporary buffer.
// open file
file, err := os.OpenFile(ss.Path, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer file.Close()
b, err := json.Marshal(ss)
// Generate checksum.
checksum := crc32.ChecksumIEEE(b)
// Write snapshot with checksum.
if _, err = fmt.Fprintf(file, "%08x\n", checksum); err != nil {
return err
}
if _, err = file.Write(b); err != nil {
return err
}
// force the change writting to disk
syscall.Fsync(int(file.Fd()))
return err
}
示例9: ObjDeleteHandler
func ObjDeleteHandler(writer http.ResponseWriter, request *http.Request, vars map[string]string, config ServerConfig) {
hash_dir := ObjHashDir(vars, config)
if os.MkdirAll(hash_dir, 0770) != nil {
ErrorResponse(writer, 500)
return
}
file_name := fmt.Sprintf("%s/%s.ts", hash_dir, request.Header.Get("X-Timestamp"))
data_file := PrimaryFile(hash_dir)
temp_file, err := ioutil.TempFile(ObjTempDir(vars, config), "PUT")
if err != nil {
ErrorResponse(writer, 500)
return
}
defer temp_file.Close()
metadata := make(map[string]interface{})
metadata["X-Timestamp"] = request.Header.Get("X-Timestamp")
metadata["name"] = fmt.Sprintf("/%s/%s/%s", vars["account"], vars["container"], vars["obj"])
WriteMetadata(int(temp_file.Fd()), metadata)
syscall.Fsync(int(temp_file.Fd()))
syscall.Rename(temp_file.Name(), file_name)
UpdateContainer("DELETE", metadata, request, vars)
go CleanupHashDir(hash_dir)
go InvalidateHash(hash_dir)
if !strings.HasSuffix(data_file, ".data") {
ErrorResponse(writer, 404)
} else {
ErrorResponse(writer, 204)
}
}
示例10: Fsync
func (f *AzukiFile) Fsync(flags int) (code fuse.Status) {
f.lock.Lock()
r := fuse.ToStatus(syscall.Fsync(int(f.File.Fd())))
f.lock.Unlock()
go event.Notify(event.Fsync, f.File.Name())
return r
}
示例11: Save
// Save the snapshot to a file
func (ss *Snapshot) Save() error {
// Write machine state to temporary buffer.
var b bytes.Buffer
if _, err := fmt.Fprintf(&b, "%v", 2); err != nil {
return err
}
// Generate checksum.
checksum := crc32.ChecksumIEEE(b.Bytes())
// open file
file, err := os.OpenFile(ss.path, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer file.Close()
// Write snapshot with checksum.
if _, err = fmt.Fprintf(file, "%08x\n%v\n%v\n", checksum, ss.lastIndex,
ss.lastTerm); err != nil {
return err
}
if _, err = file.Write(ss.state); err != nil {
return err
}
// force the change writting to disk
syscall.Fsync(int(file.Fd()))
return err
}
示例12: Sync
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func (f *File) Sync() error {
if err := f.checkValid("sync"); err != nil {
return err
}
if e := syscall.Fsync(f.fd); e != nil {
return &PathError{"sync", f.name, e}
}
return nil
}
示例13: Sync
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func (f *File) Sync() error {
if f == nil {
return ErrInvalid
}
if e := syscall.Fsync(f.fd); e != nil {
return NewSyscallError("fsync", e)
}
return nil
}
示例14: Sync
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func (file *File) Sync() (err Error) {
if file == nil {
return EINVAL
}
if e := syscall.Fsync(file.fd); e != 0 {
return NewSyscallError("fsync", e)
}
return nil
}
示例15: Sync
// Sync commits the current contents of the file to stable storage.
// Typically, this means flushing the file system's in-memory copy
// of recently written data to disk.
func (f *File) Sync() (err error) {
if f == nil {
return syscall.EINVAL
}
if e := syscall.Fsync(f.fd); e != nil {
return NewSyscallError("fsync", e)
}
return nil
}