Upgrade to Pro — share decks privately, control downloads, hide ads and more …

nanafshiを使って簡単に作るFUSEの動的ファイル

 nanafshiを使って簡単に作るFUSEの動的ファイル

Ryotaro Tamura

February 12, 2019
Tweet

More Decks by Ryotaro Tamura

Other Decks in Programming

Transcript

  1. ͑

  2. ઃఆྫ shell: /bin/bash services: - name: dir files: - name:

    now read: command: date - name: writable write: async: true command: echo $FUSE_STDIN >> /tmp/file
  3. ಈ࡞ྫ $ nanafshi -c config.yml /mnt/nanafshi $ tree /mnt/nanafshi /mnt/nanafshi

    └── dir ├── now └── writable $ cat /mnt/nanafshi/dir/now Tue Feb 12 14:53:56 JST 2019
  4. ࣮૷ྫ func (n CommandFile) Open(flags uint32, ctx *fuse.Context) (nodefs.File, fuse.Status)

    { if flags&fuse.O_ANYWRITE != 0 { return nodefs.NewDevNullFile(), fuse.OK } p, err := n.ReadFile(ctx) if err != nil { return nil, fuse.EIO } return &nodefs.WithFlags{ File: nodefs.NewDataFile(p), FuseFlags: fuse.FOPEN_DIRECT_IO, }, fuse.OK } wJOPEF΁ͷૢ࡞ΛJOUFSGBDFͱͯ͠ఆٛͯ͘͠ΕͯΔͷͰͦΕΛຬͨ͢
  5. ࣮૷ྫ func (n CommandFile) ReadFile(ctx *fuse.Context) ([]byte, error) { cmd,

    err := n.ReadCommand.Command.Build(conf.Shell, n.makeEnv(ctx)) if err != nil { return nil, err } out, err := cmd.Output() if err != nil { return nil, err } return out, nil } w'JMFTZTUFNͷίΞ࣮૷