Skip to content

Commit

Permalink
add SetSize and set both st_size and st_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
whoozle committed Dec 30, 2023
1 parent 142893d commit b4878ef
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions fuse/fuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ namespace
static bool IsStorage(FuseId id)
{ return id.Inode >= MtpStorageShift && id.Inode <= MtpObjectShift; }

static void SetSize(struct stat & st, size_t size)
{
st.st_size = size;
st.st_blocks = (size + 511) / 512;
}

mtp::StorageId FuseIdToStorageId(FuseId id) const
{
if (!IsStorage(id))
Expand Down Expand Up @@ -139,7 +145,7 @@ namespace
attr.st_mode = FuseEntry::GetMode(oi.ObjectFormat);
attr.st_atime = attr.st_mtime = mtp::ConvertDateTime(oi.ModificationDate);
attr.st_ctime = mtp::ConvertDateTime(oi.CaptureDate);
attr.st_size = oi.ObjectCompressedSize != mtp::MaxObjectSize? oi.ObjectCompressedSize: _session->GetObjectIntegerProperty(id, mtp::ObjectProperty::ObjectSize);
SetSize(attr, oi.ObjectCompressedSize != mtp::MaxObjectSize? oi.ObjectCompressedSize: _session->GetObjectIntegerProperty(id, mtp::ObjectProperty::ObjectSize));
attr.st_nlink = 1;
}

Expand Down Expand Up @@ -292,7 +298,7 @@ namespace
//size
GetObjectPropertyList<mtp::u64>(parent, objects, mtp::ObjectProperty::ObjectSize,
[this](ObjectId objectId, mtp::u64 size)
{ _objectAttrs[objectId].st_size = size; });
{ SetSize(_objectAttrs[objectId], size); });

//mtime
try
Expand Down Expand Up @@ -615,7 +621,7 @@ namespace
{
mtp::debug("truncating file to ", newSize);
tr->Truncate(newSize);
_objectAttrs[objectId].st_size = newSize;
SetSize(_objectAttrs[objectId], newSize);
}

tr->Send(off, mtp::ByteArray(buf, buf + size));
Expand Down Expand Up @@ -676,8 +682,8 @@ namespace
off_t newSize = attr->st_size;
ObjectEditSessionPtr tr = GetTransaction(inode);
tr->Truncate(newSize);
entry.attr.st_size = newSize;
_objectAttrs[FromFuse(inode)].st_size = newSize;
SetSize(entry.attr, newSize);
SetSize(_objectAttrs[FromFuse(inode)], newSize);
}
entry.ReplyAttr();
}
Expand Down

0 comments on commit b4878ef

Please sign in to comment.