Getting back into it. Maybe.
This commit is contained in:
@@ -404,13 +404,3 @@ func (w *Writer) Contains(filepath string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//WriteToFilename creates the squashfs archive with the given filepath.
|
|
||||||
func (w *Writer) WriteToFilename(filepath string) error {
|
|
||||||
newFil, err := os.Create(filepath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = w.WriteTo(newFil)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|||||||
+6
-24
@@ -27,8 +27,8 @@ func (f *fragment) addFragment(fil *fileHolder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: give info about the frags for the frag table.
|
//TODO: give info about the frags for the frag table.
|
||||||
func (w *Writer) writeFragments(write io.WriterAt, off int64) (curOffset int64, err error) {
|
func (w *Writer) writeFragments(write io.WriterAt, off int64) (newOff int64, err error) {
|
||||||
curOffset = off
|
newOff = off
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
var byts []byte
|
var byts []byte
|
||||||
var n int
|
var n int
|
||||||
@@ -50,8 +50,8 @@ func (w *Writer) writeFragments(write io.WriterAt, off int64) (curOffset int64,
|
|||||||
} else {
|
} else {
|
||||||
byts = buf.Bytes()
|
byts = buf.Bytes()
|
||||||
}
|
}
|
||||||
n, err = write.WriteAt(byts, curOffset)
|
n, err = write.WriteAt(byts, newOff)
|
||||||
curOffset += int64(n)
|
newOff += int64(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,8 @@ func (w *Writer) writeFragments(write io.WriterAt, off int64) (curOffset int64,
|
|||||||
|
|
||||||
func (w *Writer) addToFragments(fil *fileHolder) {
|
func (w *Writer) addToFragments(fil *fileHolder) {
|
||||||
fragSize := fil.blockSizes[len(fil.blockSizes)-1]
|
fragSize := fil.blockSizes[len(fil.blockSizes)-1]
|
||||||
//only fragment if the final block is less then 80% of a full block or AlwaysFragment
|
//only fragment if the final block is less then 80% of a full block or AlwaysFragment.
|
||||||
|
//TODO: Make this check after looking at all fragment blocks. Below option is better, but this is easier to implement...
|
||||||
if w.Flags.AlwaysFragment || fragSize < uint32(float32(w.BlockSize)*0.8) {
|
if w.Flags.AlwaysFragment || fragSize < uint32(float32(w.BlockSize)*0.8) {
|
||||||
//Try to slot the fragment into a fragment that has the perfect size left. If not, just pick the first one.
|
//Try to slot the fragment into a fragment that has the perfect size left. If not, just pick the first one.
|
||||||
//TODO: possibly make this more efficient, possibly by calculating fragments all at once and seeing which combos match BlockSize perfectly.
|
//TODO: possibly make this more efficient, possibly by calculating fragments all at once and seeing which combos match BlockSize perfectly.
|
||||||
@@ -89,22 +90,3 @@ func (w *Writer) addToFragments(fil *fileHolder) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) calculateFragsAndBlockSizes() {
|
|
||||||
for _, files := range w.structure {
|
|
||||||
for i := range files {
|
|
||||||
files[i].fragIndex = -1
|
|
||||||
files[i].blockSizes = make([]uint32, files[i].size/uint64(w.BlockSize))
|
|
||||||
for j := range files[i].blockSizes {
|
|
||||||
files[i].blockSizes[j] = w.BlockSize
|
|
||||||
}
|
|
||||||
fragSize := uint32(files[i].size % uint64(w.BlockSize))
|
|
||||||
if fragSize > 0 {
|
|
||||||
files[i].blockSizes = append(files[i].blockSizes, fragSize)
|
|
||||||
if !w.Flags.NoFragments {
|
|
||||||
w.addToFragments(files[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+8
-1
@@ -1,9 +1,16 @@
|
|||||||
package squashfs
|
package squashfs
|
||||||
|
|
||||||
|
import "io"
|
||||||
|
|
||||||
func (w *Writer) countInodes() (out uint32) {
|
func (w *Writer) countInodes() (out uint32) {
|
||||||
|
out++ //for the root directory
|
||||||
for _, files := range w.structure {
|
for _, files := range w.structure {
|
||||||
out++
|
|
||||||
out += uint32(len(files))
|
out += uint32(len(files))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Writer) writeInodeTable(wrt io.WriterAt, off int64) (newOff int64, err error) {
|
||||||
|
newOff = off
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
+32
-1
@@ -4,9 +4,20 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//WriteToFilename creates the squashfs archive with the given filepath.
|
||||||
|
func (w *Writer) WriteToFilename(filepath string) error {
|
||||||
|
newFil, err := os.Create(filepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = w.WriteTo(newFil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
//WriteTo attempts to write the archive to the given io.Writer.
|
//WriteTo attempts to write the archive to the given io.Writer.
|
||||||
//
|
//
|
||||||
//Not working. Yet.
|
//Not working. Yet.
|
||||||
@@ -32,5 +43,25 @@ func (w *Writer) WriteTo(write io.Writer) (int64, error) {
|
|||||||
MajorVersion: 4,
|
MajorVersion: 4,
|
||||||
MinorVersion: 0,
|
MinorVersion: 0,
|
||||||
}
|
}
|
||||||
return 0, errors.New("i SAID DON'T")
|
return 0, errors.New("i said don't")
|
||||||
|
}
|
||||||
|
|
||||||
|
//splits up the size of files into
|
||||||
|
func (w *Writer) calculateFragsAndBlockSizes() {
|
||||||
|
for _, files := range w.structure {
|
||||||
|
for i := range files {
|
||||||
|
files[i].fragIndex = -1
|
||||||
|
files[i].blockSizes = make([]uint32, files[i].size/uint64(w.BlockSize))
|
||||||
|
for j := range files[i].blockSizes {
|
||||||
|
files[i].blockSizes[j] = w.BlockSize
|
||||||
|
}
|
||||||
|
fragSize := uint32(files[i].size % uint64(w.BlockSize))
|
||||||
|
if fragSize > 0 {
|
||||||
|
files[i].blockSizes = append(files[i].blockSizes, fragSize)
|
||||||
|
if !w.Flags.NoFragments {
|
||||||
|
w.addToFragments(files[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user