You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

5 years ago
6 years ago
5 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. "log"
  7. "os"
  8. "google.golang.org/protobuf/proto"
  9. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  10. "github.com/seaweedfs/seaweedfs/weed/util"
  11. )
  12. var (
  13. metaFile = flag.String("meta", "", "meta file generated via fs.meta.save")
  14. )
  15. func main() {
  16. flag.Parse()
  17. dst, err := os.OpenFile(*metaFile, os.O_RDONLY, 0644)
  18. if err != nil {
  19. log.Fatalf("failed to open %s: %v", *metaFile, err)
  20. }
  21. defer dst.Close()
  22. err = walkMetaFile(dst)
  23. if err != nil {
  24. log.Fatalf("failed to visit %s: %v", *metaFile, err)
  25. }
  26. }
  27. func walkMetaFile(dst *os.File) error {
  28. sizeBuf := make([]byte, 4)
  29. for {
  30. if n, err := dst.Read(sizeBuf); n != 4 {
  31. if err == io.EOF {
  32. return nil
  33. }
  34. return err
  35. }
  36. size := util.BytesToUint32(sizeBuf)
  37. data := make([]byte, int(size))
  38. if n, err := dst.Read(data); n != len(data) {
  39. return err
  40. }
  41. fullEntry := &filer_pb.FullEntry{}
  42. if err := proto.Unmarshal(data, fullEntry); err != nil {
  43. return err
  44. }
  45. fmt.Fprintf(os.Stdout, "file %s %v\n", util.FullPath(fullEntry.Dir).Child(fullEntry.Entry.Name), fullEntry.Entry.Attributes.String())
  46. for i, chunk := range fullEntry.Entry.Chunks {
  47. fmt.Fprintf(os.Stdout, " chunk: %d %v %d,%x%08x\n", i+1, chunk, chunk.Fid.VolumeId, chunk.Fid.FileKey, chunk.Fid.Cookie)
  48. }
  49. }
  50. }