Skip to content

Commit

Permalink
gui tools:update lib ext4
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Jul 31, 2023
1 parent 3e57a71 commit 9ffd29c
Show file tree
Hide file tree
Showing 83 changed files with 24,850 additions and 3,033 deletions.
2 changes: 1 addition & 1 deletion quard_star_tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Quard Star Tools是Quard Star Tutorial项目的一个子项目。其基于Qt编
- QTelnet.cpp fork自https://github.com/silderan/QTelnet.git
- qtermwidget fork自https://github.com/lxqt/qtermwidget (去除了pty部分的实现,因为原项目不支持windows平台,本项目不需要pty部分因此去除后可跨平台使用。)
- QFontIcon fork自https://github.com/dridk/QFontIcon
- ext4 fork自https://github.com/ggetchev/pyext4
- lwext4 fork自https://github.com/gkostka/lwext4
- ff15 fork自http://elm-chan.org/fsw/ff/arc/ff15.zip
- jffs2 fork自https://github.com/rickardp/jffs2extract
- treemodel.cpp fork自https://github.com/chocoball/QTreeViewTest
93 changes: 64 additions & 29 deletions quard_star_tools/boardview/boardwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <QTime>

#include "jffs2extract.h"
#include "ext4_module.h"
#include "blockdev_port.h"
#include "ff.h"
#include "treemodel.h"

Expand Down Expand Up @@ -136,21 +136,39 @@ class FSViewWindow : public QTreeView
}

void setExt4FSImgView(QString rootFSImgPath,uint64_t offset, uint64_t size) {
bool read_only = true;
resetView();
setWindowTitle(rootFSImgPath);
QFileInfo fi(rootFSImgPath);
mode->set_root_timestamp((uint32_t)fi.birthTime().toUTC().toSecsSinceEpoch());
QFile fs_img(rootFSImgPath);
fs_img.open(QIODevice::ReadOnly);
fs_img.open(read_only?QIODevice::ReadOnly:QIODevice::ReadWrite);
uint8_t *addr = fs_img.map(offset,size);
ext4_init(addr,size);
lwext_init(addr,size);
struct ext4_blockdev * bd = ext4_blockdev_get();
ext4_device_register(bd, "ext4_fs");
ext4_mount("ext4_fs", "/", read_only);
if(!read_only) {
ext4_recover("/");
ext4_journal_start("/");
ext4_cache_write_back("/", 1);
}
listExt4FSAll("/",rootIndex);
ext4_close();
if(!read_only) {
ext4_cache_write_back("/", 0);
ext4_journal_stop("/");
}
ext4_umount("/");
ext4_device_unregister("ext4_fs");
fs_img.unmap(addr);
fs_img.close();
}

void setFatFSImgView(QString rootFSImgPath,uint64_t offset, uint64_t size) {
resetView();
setWindowTitle(rootFSImgPath);
QFileInfo fi(rootFSImgPath);
mode->set_root_timestamp((uint32_t)fi.birthTime().toUTC().toSecsSinceEpoch());
QFile fs_img(rootFSImgPath);
fs_img.open(QIODevice::ReadOnly);
uint8_t *addr = fs_img.map(offset,size);
Expand All @@ -166,6 +184,8 @@ class FSViewWindow : public QTreeView
void setJffs2FSImgView(QString rootFSImgPath,uint64_t offset, uint64_t size) {
resetView();
setWindowTitle(rootFSImgPath);
QFileInfo fi(rootFSImgPath);
mode->set_root_timestamp((uint32_t)fi.birthTime().toUTC().toSecsSinceEpoch());
QFile fs_img(rootFSImgPath);
fs_img.open(QIODevice::ReadOnly);
uint8_t *addr = fs_img.map(offset,size);
Expand All @@ -177,6 +197,7 @@ class FSViewWindow : public QTreeView

void resetView(void) {
mode->removeTree(rootIndex);
mode->set_root_timestamp(0);
rootIndex = mode->addTree("/", 0, 0, 0, QModelIndex());
expand(rootIndex);
}
Expand All @@ -200,39 +221,53 @@ class FSViewWindow : public QTreeView
FSView_LAST
};
void listExt4FSAll(QString path, QModelIndex index) {
uint64_t msize = ext4_list_contents(path.toStdString().c_str(), NULL);
uint8_t *mdata = new uint8_t[msize];
ext4_list_contents(path.toStdString().c_str(), mdata);
uint8_t * p = mdata;
while(p != (mdata + msize)) {
struct ext4_ino_usr_map * mm = (struct ext4_ino_usr_map *) p;
QString filename(QByteArray(mm->name,mm->size));
switch(mm->type) {
case FSView_DIR :
const ext4_direntry *de;
ext4_dir d;
ext4_dir_open(&d, path.toStdString().c_str());
de = ext4_dir_entry_next(&d);
while (de) {
uint32_t timestamp = 0;
QString filename(QByteArray((const char*)de->name,de->name_length));
if(filename == "." || filename == "..") {
de = ext4_dir_entry_next(&d);
continue;
}
QString filePath;
if(path != "/")
filePath = path + "/" + filename;
else
filePath = "/" + filename;
ext4_ctime_get(filePath.toStdString().c_str(),&timestamp);
switch(de->inode_type) {
case FSView_REG_FILE:
{
QModelIndex modelIndex = mode->addTree(filename, mm->type, 0, mm->ctime, index);
ext4_file fd;
ext4_fopen(&fd, filePath.toStdString().c_str(), "rb");
uint32_t size = ext4_fsize(&fd);
ext4_fclose(&fd);
mode->addTree(filename, de->inode_type, size, timestamp, index);
break;
}
case FSView_FIFO:
case FSView_CHARDEV:
case FSView_BLOCKDEV:
case FSView_SYMLINK:
case FSView_SOCKET:
default:
mode->addTree(filename, de->inode_type, 0, timestamp, index);
break;
case FSView_DIR:
QModelIndex modelIndex = mode->addTree(filename, de->inode_type, 0, timestamp, index);
if(path != "/")
listExt4FSAll(path + "/" + filename, modelIndex);
else
listExt4FSAll("/" + filename, modelIndex);
break;
}
case FSView_REG_FILE :
default :
{
uint64_t rsize = ext4_get_contents(mm->ino, NULL);
uint8_t *rdata = new uint8_t[rsize];
ext4_get_contents(mm->ino, rdata);
uint64_t size = *(uint64_t *)(rdata+8);
mode->addTree(filename, mm->type, size, mm->ctime, index);
free(rdata);
break;
}
}
p += sizeof(struct ext4_ino_usr_map) + mm->size;

de = ext4_dir_entry_next(&d);
}
delete [] mdata;
ext4_dir_close(&d);
qApp->processEvents();
}

Expand Down
30 changes: 22 additions & 8 deletions quard_star_tools/boardview/treemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TreeItem
} ;

TreeModel::TreeModel(QTreeView *parent) :
QAbstractItemModel(parent),m_parent(parent)
QAbstractItemModel(parent),m_roottimestamp(0),m_parent(parent)
{
m_pRootItem = new TreeItem(" ", 0, NULL) ;
}
Expand All @@ -80,6 +80,11 @@ TreeModel::~TreeModel()
delete m_pRootItem ;
}

void TreeModel::set_root_timestamp(uint32_t timestamp)
{
m_roottimestamp = timestamp;
}

QVariant TreeModel::data(const QModelIndex &index, int role) const
{
if ( role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::DecorationRole && role != (Qt::UserRole + 1)) { return QVariant() ; }
Expand All @@ -101,15 +106,15 @@ QVariant TreeModel::data(const QModelIndex &index, int role) const
switch (p->type()) {
case UNKNOWN:
if(index.column() == 0 && role == Qt::DecorationRole) {
return QVariant();
return QIcon(QFontIcon::icon(QChar(0xf1c0)));
} else if(index.column() == 0 && role == Qt::DisplayRole) {
return p->data();
} else if (index.column() == 1 && role == Qt::DisplayRole) {
return tr("Kind");
return tr("Root");
} else if (index.column() == 2 && role == Qt::DisplayRole) {
return tr("Size");
} else if (index.column() == 3 && role == Qt::DisplayRole) {
return tr("Date");
return p->childCount();
} else if (index.column() == 3 && role == Qt::DisplayRole) {
return QDateTime::fromSecsSinceEpoch(m_roottimestamp).toString("yyyy-MM-dd hh:mm:ss");
}
break;
case REG_FILE:
Expand Down Expand Up @@ -281,8 +286,17 @@ QModelIndex TreeModel::parent(const QModelIndex &child) const

QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 ) {
return m_pRootItem->data() ;
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
switch(section) {
case 0:
return tr("Name");
case 1:
return tr("Kind");
case 2:
return tr("Size");
case 3:
return tr("Date");
}
}
return QVariant() ;
}
Expand Down
2 changes: 2 additions & 0 deletions quard_star_tools/boardview/treemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TreeModel : public QAbstractItemModel
explicit TreeModel(QTreeView *parent = 0);
~TreeModel() ;

void set_root_timestamp(uint32_t timestamp) ;
QVariant data(const QModelIndex &index, int role) const ;
int rowCount(const QModelIndex &parent) const ;
int columnCount(const QModelIndex &parent) const ;
Expand Down Expand Up @@ -47,6 +48,7 @@ public slots:

private:
TreeItem *m_pRootItem ;
uint32_t m_roottimestamp;
QTreeView *m_parent;
};

Expand Down
Loading

0 comments on commit 9ffd29c

Please sign in to comment.