2020-05-19 16:11:56 +00:00
|
|
|
package storiface
|
|
|
|
|
2020-05-28 23:33:00 +00:00
|
|
|
import (
|
2020-12-01 23:35:55 +00:00
|
|
|
"context"
|
2020-05-28 23:33:00 +00:00
|
|
|
"errors"
|
2020-12-01 23:39:55 +00:00
|
|
|
|
2020-12-01 23:35:55 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2021-05-18 07:32:30 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-05-28 23:33:00 +00:00
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2023-05-25 13:55:12 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/fr32"
|
2020-05-28 23:33:00 +00:00
|
|
|
)
|
2020-05-19 16:11:56 +00:00
|
|
|
|
|
|
|
var ErrSectorNotFound = errors.New("sector not found")
|
2020-05-26 08:25:17 +00:00
|
|
|
|
|
|
|
type UnpaddedByteIndex uint64
|
2020-05-28 23:33:00 +00:00
|
|
|
|
|
|
|
func (i UnpaddedByteIndex) Padded() PaddedByteIndex {
|
|
|
|
return PaddedByteIndex(abi.UnpaddedPieceSize(i).Padded())
|
|
|
|
}
|
|
|
|
|
2021-05-18 07:32:30 +00:00
|
|
|
func (i UnpaddedByteIndex) Valid() error {
|
|
|
|
if i%127 != 0 {
|
|
|
|
return xerrors.Errorf("unpadded byte index must be a multiple of 127")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-05-25 13:55:12 +00:00
|
|
|
func UnpaddedFloor(n uint64) UnpaddedByteIndex {
|
|
|
|
return UnpaddedByteIndex(n / uint64(fr32.UnpaddedFr32Chunk) * uint64(fr32.UnpaddedFr32Chunk))
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnpaddedCeil(n uint64) UnpaddedByteIndex {
|
|
|
|
return UnpaddedByteIndex((n + uint64(fr32.UnpaddedFr32Chunk-1)) / uint64(fr32.UnpaddedFr32Chunk) * uint64(fr32.UnpaddedFr32Chunk))
|
|
|
|
}
|
|
|
|
|
2020-05-28 23:33:00 +00:00
|
|
|
type PaddedByteIndex uint64
|
2020-12-01 23:35:55 +00:00
|
|
|
|
2022-01-18 10:25:04 +00:00
|
|
|
type RGetter func(ctx context.Context, id abi.SectorID) (sealed cid.Cid, update bool, err error)
|