From 543c1d43aca89e9d4533459f853c1ef984137b3e Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Tue, 4 Jun 2024 10:44:38 +0300 Subject: [PATCH] support serial in iso9660 rock ridge 1.12 Signed-off-by: Avi Deitcher --- filesystem/iso9660/finalize.go | 12 +++++-- filesystem/iso9660/rockridge.go | 64 +++------------------------------ 2 files changed, 14 insertions(+), 62 deletions(-) diff --git a/filesystem/iso9660/finalize.go b/filesystem/iso9660/finalize.go index 6bd3d265..2dc057c2 100644 --- a/filesystem/iso9660/finalize.go +++ b/filesystem/iso9660/finalize.go @@ -84,6 +84,7 @@ type finalizeFileInfo struct { // content in memory content of file. If this is anything other than nil, including a zero-length slice, // then this content is used, rather than anything on disk. content []byte + serial uint64 } func finalizeFileInfoFromFile(p, fullPath string, fi fs.FileInfo) (*finalizeFileInfo, error) { @@ -913,9 +914,12 @@ func walkTree(workspace string) ([]*finalizeFileInfo, map[string]*finalizeFileIn } // make everything relative to the workspace _ = os.Chdir(workspace) - dirList := make(map[string]*finalizeFileInfo) - fileList := make([]*finalizeFileInfo, 0) - var entry *finalizeFileInfo + var ( + dirList = make(map[string]*finalizeFileInfo) + fileList = make([]*finalizeFileInfo, 0) + entry *finalizeFileInfo + serial uint64 + ) err = filepath.Walk(".", func(fp string, fi os.FileInfo, err error) error { if err != nil { return fmt.Errorf("error walking path %s: %v", fp, err) @@ -929,6 +933,8 @@ func walkTree(workspace string) ([]*finalizeFileInfo, map[string]*finalizeFileIn if err != nil { return err } + entry.serial = serial + serial++ // we will have to save it as its parent parentDir := filepath.Dir(fp) diff --git a/filesystem/iso9660/rockridge.go b/filesystem/iso9660/rockridge.go index b3cb38d3..ed20a1d7 100644 --- a/filesystem/iso9660/rockridge.go +++ b/filesystem/iso9660/rockridge.go @@ -6,8 +6,6 @@ import ( "os" "sort" "time" - - "github.com/djherbis/times" ) const ( @@ -96,58 +94,6 @@ func (r *rockRidgeExtension) GetFilename(de *directoryEntry) (string, error) { } return name, nil } -func (r *rockRidgeExtension) GetFileExtensionsOld(fp string, isSelf, isParent bool) ([]directoryEntrySystemUseExtension, error) { - // we always do PX, TF, NM, SL order - ret := []directoryEntrySystemUseExtension{} - // do not follow symlinks - fi, err := os.Lstat(fp) - if err != nil { - return nil, fmt.Errorf("error reading file %s: %v", fp, err) - } - - t, err := times.Lstat(fp) - if err != nil { - return nil, fmt.Errorf("error reading times %s: %v", fp, err) - } - - // PX - nlink, uid, gid := statt(fi) - mtime := fi.ModTime() - atime := t.AccessTime() - ctime := t.ChangeTime() - - ret = append(ret, rockRidgePosixAttributes{ - mode: fi.Mode(), - linkCount: nlink, - uid: uid, - gid: gid, - length: r.pxLength, - }) - // TF - tf := rockRidgeTimestamps{longForm: false, stamps: []rockRidgeTimestamp{ - {timestampType: rockRidgeTimestampModify, time: mtime}, - {timestampType: rockRidgeTimestampAccess, time: atime}, - {timestampType: rockRidgeTimestampAttribute, time: ctime}, - }} - - ret = append(ret, tf) - // NM - if !isSelf && !isParent { - ret = append(ret, rockRidgeName{name: fi.Name()}) - } - // SL - if fi.Mode()&os.ModeSymlink == os.ModeSymlink { - // need the target if it is a symlink - target, err := os.Readlink(fp) - if err != nil { - return nil, fmt.Errorf("error reading symlink target at %s", fp) - } - ret = append(ret, rockRidgeSymlink{continued: false, name: target}) - } - - return ret, nil -} - func (r *rockRidgeExtension) GetFileExtensions(ffi *finalizeFileInfo, isSelf, isParent bool) ([]directoryEntrySystemUseExtension, error) { // we always do PX, TF, NM, SL order ret := []directoryEntrySystemUseExtension{} @@ -161,6 +107,7 @@ func (r *rockRidgeExtension) GetFileExtensions(ffi *finalizeFileInfo, isSelf, is uid: ffi.UID(), gid: ffi.GID(), length: r.pxLength, + serial: ffi.serial, }) // TF tf := rockRidgeTimestamps{longForm: false, stamps: []rockRidgeTimestamp{ @@ -328,7 +275,7 @@ type rockRidgePosixAttributes struct { linkCount uint32 uid uint32 gid uint32 - serial uint32 + serial uint64 } func (d rockRidgePosixAttributes) Equal(o directoryEntrySystemUseExtension) bool { @@ -397,8 +344,7 @@ func (d rockRidgePosixAttributes) Data() []byte { binary.LittleEndian.PutUint32(ret[24:28], d.gid) binary.BigEndian.PutUint32(ret[28:32], d.gid) if d.length == 44 { - binary.LittleEndian.PutUint32(ret[32:36], d.serial) - binary.BigEndian.PutUint32(ret[36:40], d.serial) + binary.LittleEndian.PutUint64(ret[32:40], d.serial) } return ret } @@ -462,9 +408,9 @@ func (r *rockRidgeExtension) parsePosixAttributes(b []byte) (directoryEntrySyste m |= uint32(os.ModeNamedPipe) } - var serial uint32 + var serial uint64 if len(b) == 44 { - serial = binary.LittleEndian.Uint32(b[36:40]) + serial = binary.LittleEndian.Uint64(b[36:44]) } return rockRidgePosixAttributes{ mode: os.FileMode(m),