| 1 |
package fat |
| 2 |
|
| 3 |
type File struct { |
| 4 |
chain *ClusterChain |
| 5 |
dir *Directory |
| 6 |
entry *DirectoryClusterEntry |
| 7 |
} |
| 8 |
|
| 9 |
func (f *File) Read(p []byte) (n int, err error) { |
| 10 |
return f.chain.Read(p) |
| 11 |
} |
| 12 |
|
| 13 |
func (f *File) Write(p []byte) (n int, err error) { |
| 14 |
lastByte := f.chain.writeOffset + uint32(len(p)) |
| 15 |
if lastByte > f.entry.fileSize { |
| 16 |
|
| 17 |
f.entry.fileSize = lastByte |
| 18 |
|
| 19 |
|
| 20 |
if err := f.dir.dirCluster.WriteToDevice(f.dir.device, f.dir.fat); err != nil { |
| 21 |
return 0, err |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
return f.chain.Write(p) |
| 26 |
} |