Ejemplo n.º 1
0
func (s *Superblock) findAtBlock(name InodeName, ra io.ReaderAt, off int64) (int64, error) {
	var r io.Reader = qio.NewReader(ra, off)
	r = bufio.NewReader(io.LimitReader(r, BlockSize))
	var buf [unsafe.Sizeof(InodeIndex{})]byte
	var index *InodeIndex
	for {
		n, err := r.Read(buf[:])
		if err != nil {
			return 0, err
		}
		if n != len(buf) {
			return 0, ErrNotFound.Trace()
		}
		index = (*InodeIndex)(unsafe.Pointer(&buf))
		if index.Name.IsEmpty() {
			return 0, ErrNotFound.Trace()
		}
		s.inodeAddr[index.Name] = index.Address
	}

	if addr, ok := s.inodeAddr[name]; ok {
		return addr, nil
	}
	return 0, ErrNotFound.Trace()
}
Ejemplo n.º 2
0
func BenchmarkBlockRead(b *testing.B) {
	defer test.New(b)
	writeN(b.N, nil)

	b.ResetTimer()
	ins, err := New(root, 0, DefaultBit)
	test.Nil(err)
	w := qio.NewReader(ins, 0)
	buf := make([]byte, benchmarkSize)
	for i := 0; i < b.N; i++ {
		n, err := w.Read(buf)
		test.Nil(err)
		b.SetBytes(int64(n))
	}
}