func (e *Ext2Parser) getDirList(dirpath string, ignoreDot bool) ([]fsparser.FileInfo, error) {
	arg := fmt.Sprintf("%s:%s", e.imagepath, dirpath)
	params := "-la"
	if e.selinux {
		params += "Z"
	}
	if e.capabilities {
		params += "C"
	}
	out, err := exec.Command(e2ToolsLs, params, arg).CombinedOutput()
	if err != nil {
		if !strings.EqualFold(string(out), "File not found by ext2_lookup") {
			fmt.Fprintln(os.Stderr, err)
		}
		return nil, err
	}
	var dir []fsparser.FileInfo
	lines := strings.Split(string(out), "\n")
	for _, fline := range lines {
		if len(fline) > 1 && fline[0] != '>' {
			fi := e.parseFileLine(fline)
			if !ignoreDot || (fi.Name != "." && fi.Name != "..") {
				dir = append(dir, fi)
			}
		}
	}
	return dir, nil
}
ignoreDot=true: will filter out "." and ".." files from the directory listing
package extparser
import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"
	"github.com/cruise-automation/fwanalyzer/pkg/capability"
	"github.com/cruise-automation/fwanalyzer/pkg/fsparser"
)
type Ext2Parser struct {
	fileinfoReg  *regexp.Regexp
	regexString  string
	selinux      bool
	capabilities bool
	imagepath    string
}
const (
	e2ToolsCp = "e2cp"
	e2ToolsLs = "e2ls"
)
func New(imagepath string, selinux, capabilities bool) *Ext2Parser {
	parser := &Ext2Parser{
		regexString:  `^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+-\w+-\d+)\s+(\d+:\d+)\s+([\S ]+)`,
		imagepath:    imagepath,
		selinux:      false,
		capabilities: false,
	}
	if selinux && seLinuxSupported() {
		parser.enableSeLinux()
	}
	if capabilities && capabilitiesSupported() {
		parser.enableCapabilities()
	}
	parser.fileinfoReg = regexp.MustCompile(parser.regexString)
	return parser
}
func (e *Ext2Parser) ImageName() string {
	return e.imagepath
}
func (e *Ext2Parser) enableSeLinux() {
	e.regexString = e.regexString + `\t\s+(\S+)`
	e.selinux = true
}
func (e *Ext2Parser) enableCapabilities() {
	if !e.selinux {
		e.regexString = e.regexString + `\t`
	}
	e.regexString = e.regexString + `\s+(\S+)`
	e.capabilities = true
}
func (e *Ext2Parser) parseFileLine(line string) fsparser.FileInfo {
	res := e.fileinfoReg.FindAllStringSubmatch(line, -1)
	var fi fsparser.FileInfo
	size, _ := strconv.Atoi(res[0][5])
	fi.Size = int64(size)
	fi.Mode, _ = strconv.ParseUint(res[0][2], 8, 32)
	fi.Uid, _ = strconv.Atoi(res[0][3])
	fi.Gid, _ = strconv.Atoi(res[0][4])
	fi.Name = res[0][8]
	if fi.IsLink() && strings.Contains(fi.Name, " -> ") {
		parts := strings.Split(fi.Name, " -> ")
		fi.Name = parts[0]
		fi.LinkTarget = parts[1]
	}
	if e.selinux {
		fi.SELinuxLabel = res[0][9]
	} else {
		fi.SELinuxLabel = fsparser.SELinuxNoLabel
	}
	if e.capabilities {
		idx := 9
		if e.selinux {
			idx = 10
		}
		if res[0][idx] != "-" {
			fi.Capabilities, _ = capability.New(res[0][idx])
		}
	}
	return fi
}