OpenFS 打开文件系统
(dir string, options *FSOptions)
| 39 | |
| 40 | // OpenFS 打开文件系统 |
| 41 | func OpenFS(dir string, options *FSOptions) (*FS, error) { |
| 42 | if !IsEnabled() { |
| 43 | return nil, errors.New("the fs only works under 64 bit system") |
| 44 | } |
| 45 | |
| 46 | if options == nil { |
| 47 | options = DefaultFSOptions |
| 48 | } else { |
| 49 | options.EnsureDefaults() |
| 50 | } |
| 51 | |
| 52 | var locker = fsutils.NewLocker(dir + "/fs") |
| 53 | err := locker.Lock() |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | |
| 58 | var fs = &FS{ |
| 59 | dir: dir, |
| 60 | bMap: map[string]*BlocksFile{}, |
| 61 | bList: linkedlist.NewList[string](), |
| 62 | bItemMap: map[string]*linkedlist.Item[string]{}, |
| 63 | closingBMap: map[string]zero.Zero{}, |
| 64 | closingBChan: make(chan *BlocksFile, 32), |
| 65 | mu: &sync.RWMutex{}, |
| 66 | opt: options, |
| 67 | syncTicker: time.NewTicker(1 * time.Second), |
| 68 | locker: locker, |
| 69 | } |
| 70 | go fs.init() |
| 71 | return fs, nil |
| 72 | } |
| 73 | |
| 74 | func (this *FS) init() { |
| 75 | go func() { |