Getting back into it. Maybe.

This commit is contained in:
Caleb Gardner
2021-04-04 09:39:28 -05:00
parent 28f39cf315
commit 7cf15d48c7
4 changed files with 46 additions and 36 deletions
-10
View File
@@ -404,13 +404,3 @@ func (w *Writer) Contains(filepath string) bool {
}
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
View File
@@ -27,8 +27,8 @@ func (f *fragment) addFragment(fil *fileHolder) {
}
//TODO: give info about the frags for the frag table.
func (w *Writer) writeFragments(write io.WriterAt, off int64) (curOffset int64, err error) {
curOffset = off
func (w *Writer) writeFragments(write io.WriterAt, off int64) (newOff int64, err error) {
newOff = off
var buf bytes.Buffer
var byts []byte
var n int
@@ -50,8 +50,8 @@ func (w *Writer) writeFragments(write io.WriterAt, off int64) (curOffset int64,
} else {
byts = buf.Bytes()
}
n, err = write.WriteAt(byts, curOffset)
curOffset += int64(n)
n, err = write.WriteAt(byts, newOff)
newOff += int64(n)
if err != nil {
return
}
@@ -62,7 +62,8 @@ func (w *Writer) writeFragments(write io.WriterAt, off int64) (curOffset int64,
func (w *Writer) addToFragments(fil *fileHolder) {
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) {
//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.
@@ -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
View File
@@ -1,9 +1,16 @@
package squashfs
import "io"
func (w *Writer) countInodes() (out uint32) {
out++ //for the root directory
for _, files := range w.structure {
out++
out += uint32(len(files))
}
return
}
func (w *Writer) writeInodeTable(wrt io.WriterAt, off int64) (newOff int64, err error) {
newOff = off
return
}
+32 -1
View File
@@ -4,9 +4,20 @@ import (
"errors"
"io"
"math"
"os"
"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.
//
//Not working. Yet.
@@ -32,5 +43,25 @@ func (w *Writer) WriteTo(write io.Writer) (int64, error) {
MajorVersion: 4,
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])
}
}
}
}
}