file.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package udf
  2. import (
  3. "io"
  4. "os"
  5. "time"
  6. )
  7. type File struct {
  8. Udf *Udf
  9. Fid *FileIdentifierDescriptor
  10. fe *FileEntry
  11. fileEntryPosition uint64
  12. }
  13. func (f *File) GetFileEntryPosition() int64 {
  14. return int64(f.fileEntryPosition)
  15. }
  16. func (f *File) GetFileOffset() int64 {
  17. return SECTOR_SIZE * (int64(f.FileEntry().AllocationDescriptors[0].Location) + int64(f.Udf.PartitionStart()))
  18. }
  19. func (f *File) FileEntry() *FileEntry {
  20. if f.fe == nil {
  21. f.fileEntryPosition = f.Fid.ICB.Location
  22. f.fe = NewFileEntry(f.Udf.ReadSector(f.Udf.PartitionStart() + f.fileEntryPosition))
  23. }
  24. return f.fe
  25. }
  26. func (f *File) NewReader() *io.SectionReader {
  27. return io.NewSectionReader(f.Udf.r, f.GetFileOffset(), f.Size())
  28. }
  29. func (f *File) Name() string {
  30. return f.Fid.FileIdentifier
  31. }
  32. func (f *File) Mode() os.FileMode {
  33. var mode os.FileMode
  34. perms := os.FileMode(f.FileEntry().Permissions)
  35. mode |= ((perms >> 0) & 7) << 0
  36. mode |= ((perms >> 5) & 7) << 3
  37. mode |= ((perms >> 10) & 7) << 6
  38. if f.IsDir() {
  39. mode |= os.ModeDir
  40. }
  41. return mode
  42. }
  43. func (f *File) Size() int64 {
  44. return int64(f.FileEntry().InformationLength)
  45. }
  46. func (f *File) ModTime() time.Time {
  47. return f.FileEntry().ModificationTime
  48. }
  49. func (f *File) IsDir() bool {
  50. // TODO :Fix! This field always 0 :(
  51. return f.FileEntry().ICBTag.FileType == 4
  52. }
  53. func (f *File) Sys() interface{} {
  54. return f.Fid
  55. }
  56. func (f *File) ReadDir() []File {
  57. return f.Udf.ReadDir(f.FileEntry())
  58. }