locate provides a function to locate sectors location and size of the compound file.
()
| 774 | // locate provides a function to locate sectors location and size of the |
| 775 | // compound file. |
| 776 | func (c *cfb) locate() []int { |
| 777 | var miniStreamSectorSize, FATSectorSize int |
| 778 | for i := 0; i < len(c.sectors); i++ { |
| 779 | sector := c.sectors[i] |
| 780 | if len(sector.content) == 0 { |
| 781 | continue |
| 782 | } |
| 783 | size := len(sector.content) |
| 784 | if size > 0 { |
| 785 | if size < 0x1000 { |
| 786 | miniStreamSectorSize += (size + 0x3F) >> 6 |
| 787 | } else { |
| 788 | FATSectorSize += (size + 0x01FF) >> 9 |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | directorySectors := (len(c.paths) + 3) >> 2 |
| 793 | miniStreamSectors := (miniStreamSectorSize + 7) >> 3 |
| 794 | miniFATSectors := (miniStreamSectorSize + 0x7F) >> 7 |
| 795 | sectors := miniStreamSectors + FATSectorSize + directorySectors + miniFATSectors |
| 796 | FATSectors := (sectors + 0x7F) >> 7 |
| 797 | DIFATSectors := 0 |
| 798 | if FATSectors > 109 { |
| 799 | DIFATSectors = int(math.Ceil((float64(FATSectors) - 109) / 0x7F)) |
| 800 | } |
| 801 | for ((sectors + FATSectors + DIFATSectors + 0x7F) >> 7) > FATSectors { |
| 802 | FATSectors++ |
| 803 | if FATSectors <= 109 { |
| 804 | DIFATSectors = 0 |
| 805 | } else { |
| 806 | DIFATSectors = int(math.Ceil((float64(FATSectors) - 109) / 0x7F)) |
| 807 | } |
| 808 | } |
| 809 | location := []int{1, DIFATSectors, FATSectors, miniFATSectors, directorySectors, FATSectorSize, miniStreamSectorSize, 0} |
| 810 | c.sectors[0].size = miniStreamSectorSize << 6 |
| 811 | c.sectors[0].start = location[0] + location[1] + location[2] + location[3] + location[4] + location[5] |
| 812 | location[7] = c.sectors[0].start + ((location[6] + 7) >> 3) |
| 813 | return location |
| 814 | } |
| 815 | |
| 816 | // writeMSAT provides a function to write compound file master sector allocation |
| 817 | // table. |
no outgoing calls