Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented IOCTL_GET_APFS_INFO ioctl #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ufs/ufsd/src/apfs/apfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,40 @@ int CApfsFileSystem::ReInit(
return CUnixFileSystem::ReInit( Options, Flags, Params );
}

int CApfsFileSystem::OnGetApfsInfo()
{
size_t BytesReturned = 0;
struct UFSD_VOLUME_APFS_INFO *info = (struct UFSD_VOLUME_APFS_INFO *) m_IO.OutBuffer;
for (unsigned int Idx = 0; Idx < m_pApfsSuper->GetMountedVolumesCount(); Idx++) {
if (BytesReturned + sizeof(struct UFSD_VOLUME_APFS_INFO) > m_IO.OutBufferSize)
{
if (m_IO.BytesReturned)
*m_IO.BytesReturned = BytesReturned;
return Idx ? ERR_MORE_DATA : ERR_INSUFFICIENT_BUFFER;
}
CApfsVolumeSb *vol = m_pApfsSuper->GetVolume(Idx);
apfs_vsb *volSb = vol->GetVolumeSb();
info[Idx] = {
.BlocksUsed = volSb->vsb_blocks_used,
.BlocksReserved = volSb->vsb_blocks_reserved,
.FilesCount = volSb->vsb_files_count,
.DirsCount = volSb->vsb_dirs_count,
.SymlinksCount = volSb->vsb_symlinks_count,
.SpecFilesCount = volSb->vsb_spec_files_count,
.SnapshotsCount = volSb->vsb_snapshots_count,
.Index = Idx,
.Encrypted = vol->IsEncrypted(),
.CaseSensitive = vol->IsCaseSensitive()
};
Memcpy2(info[Idx].SerialNumber, volSb->vsb_uuid, 0x10);
Memcpy2(info[Idx].VolumeName, volSb->vsb_volname, 0x100);
info[Idx].Creator[0] = '\0';
BytesReturned += sizeof(struct UFSD_VOLUME_APFS_INFO);
}
if (m_IO.BytesReturned)
*m_IO.BytesReturned = BytesReturned;
return ERR_NOERROR;
}

#ifdef UFSD_APFS_RO
/////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions ufs/ufsd/src/apfs/apfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ class CApfsFileSystem : public CUnixFileSystem
// Find cluster with the last checkpoint superblock
int FindCSBBlock(const apfs_sb* pMSB, UINT64& Block) const;

// Handler for IOCTL_GET_APFS_INFO
virtual int OnGetApfsInfo();

#ifndef UFSD_APFS_RO
//=================================================================
// APFS I/O handlers
//=================================================================

// Handler for IOCTL_GET_APFS_INFO
virtual int OnGetApfsInfo();

// Handler for IOCTL_GET_RETRIEVAL_POINTERS2
virtual int OnGetRetrievalPointers();

Expand Down
23 changes: 16 additions & 7 deletions ufs/ufsd/src/unixfs/unixfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,24 @@ int CUnixFileSystem::SetVolumeInfo(
}

int CUnixFileSystem::IoControl(
IN size_t ,
IN const void* ,
IN size_t ,
OUT void* ,
IN size_t ,
OUT size_t*
IN size_t FsIoControlCode,
IN const void* InBuffer,
IN size_t InBufferSize,
OUT void* OutBuffer,
IN size_t OutBufferSize,
OUT size_t* BytesReturned
)
{
return ERR_NOTIMPLEMENTED;
m_IO.InBuffer = InBuffer;
m_IO.InBufferSize = InBufferSize;
m_IO.OutBuffer = OutBuffer;
m_IO.OutBufferSize = OutBufferSize;
m_IO.BytesReturned = BytesReturned;
switch (FsIoControlCode) {
case IOCTL_GET_APFS_INFO:
return OnGetApfsInfo();
}
return ERR_NOTIMPLEMENTED;
}

int CUnixFileSystem::OnGetRetrievalPointers() { return ERR_NOTIMPLEMENTED; }
Expand Down