After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 505042 - support standard::allocated-size
support standard::allocated-size
Status: RESOLVED FIXED
Product: gvfs
Classification: Core
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gvfs-maint
gvfs-maint
Depends on:
Blocks:
 
 
Reported: 2007-12-22 14:02 UTC by Paolo Borelli
Modified: 2014-06-05 20:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gvfs-du.c (5.47 KB, text/plain)
2007-12-23 13:53 UTC, Paolo Borelli
  Details
patch (884 bytes, patch)
2007-12-25 16:02 UTC, Paolo Borelli
committed Details | Review
Preliminary patch (10.52 KB, patch)
2008-01-21 23:44 UTC, Patrick Hulin
none Details | Review
standard::allocated-size attribute (3.10 KB, patch)
2009-02-13 14:37 UTC, Allison Karlitskaya (desrt)
committed Details | Review
smb: Implement standard::allocated-size (950 bytes, patch)
2014-06-02 05:33 UTC, Ross Lagerwall
committed Details | Review
afc: Implement standard::allocated-size (1.18 KB, patch)
2014-06-02 05:33 UTC, Ross Lagerwall
committed Details | Review

Description Paolo Borelli 2007-12-22 14:02:56 UTC
I was quickly looking what was needed to port something like gnome-utils' baobab to gio.

As far as I can see we are missing an API to get the real size allocated on disk by a file. With gnome-vfs you could do:

if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT) != 0)
	alloc_size = dir_info->block_count * BLOCK_SIZE;

I guess we could add some attributes to gfileinfo to get this where it makes sense. Maybe a standard::block-count attribute and a filesystem::block-size attribute? Or is it better simply a standard::allocated-size attrribute?
Comment 1 Matthias Clasen 2007-12-22 15:46:44 UTC
Makes sense to me; I'd probably go with the allocated-size attribute, but thats up to Alex.
Comment 2 Matthias Clasen 2007-12-22 22:24:12 UTC
Looking again, 
G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE and G_FILE_ATTRIBUTE_UNIX_BLOCKS are exactly what you want, no ?
Comment 3 Paolo Borelli 2007-12-23 02:17:59 UTC
I guess they are. I totally missed them.
Comment 4 Paolo Borelli 2007-12-23 13:52:26 UTC
I tried those attributes but unless I am doing something wrong they do not seem to work...
Comment 5 Paolo Borelli 2007-12-23 13:53:49 UTC
Created attachment 101501 [details]
gvfs-du.c

Here is a first cut at a gvfs-du program to test that functionality
Comment 6 Paolo Borelli 2007-12-25 16:02:20 UTC
Created attachment 101586 [details] [review]
patch

The problem is due to a typo in the ifdef.
Comment 7 Matthias Clasen 2007-12-25 20:55:53 UTC
Thanks, please commit.
Comment 8 Paolo Borelli 2007-12-25 21:27:36 UTC
Committed.

What about the gvfs-du program? Do you think it could a useful addition to gvfs-ls, gvfs-cat etc? If yes I guess I could fix a couple of issues in it...
Comment 9 Alexander Larsson 2008-01-03 12:00:53 UTC
G_FILE_ATTRIBUTE_UNIX_BLOCKS is kinda unix specific though. Maybe we want to have a real allocated size without having to know magic unix specific things, like that blocks are always 512 bytes.
Comment 10 Mathias Hasselmann (IRC: tbf) 2008-01-03 12:39:36 UTC
(In reply to comment #9)
> G_FILE_ATTRIBUTE_UNIX_BLOCKS is kinda unix specific though. Maybe we want to
> have a real allocated size without having to know magic unix specific things,
> like that blocks are always 512 bytes.
> 

Just that blocks seldomly are 512 bytes those days: ext2 allows 1024, 2048 and 4096, but not 512. XFS is 512..4096. FAT and NTFS  block size varies from 512 to 32768/65536 bytes.

Disk-usage programs, like du (or gvfs-du) are expected to report disk usage rounded up to multiples of the file systems block size. So some kind of G_FILE_ATTRIBUTE_BLOCKS (size in fs blocks), or G_FILE_ATTRIBUTE_BLOCK_SIZE (block size of the underlying file system) would be quite useful, I guess.

But agreed: G_FILE_ATTRIBUTE_UNIX_BLOCKS itself really looks crufty.
Comment 11 Alexander Larsson 2008-01-04 10:16:04 UTC
Its true that the actual blocks used by filesystems are not 512 bytes anymore, however, this has no affect on the ages-old stat() API. Check the manpage for instance:

       The st_blocks field indicates the number of blocks allocated to the  file,  512-byte  units.   (This  may  be  smaller  than
       st_size/512 when the file has holes.)

       The  st_blksize  field  gives the "preferred" blocksize for efficient file system I/O.  (Writing to a file in smaller chunks
       may cause an inefficient read-modify-rewrite.)

the st_blksize field is totally unrelated to st_blocks, which is always in 512 byte units.

I don't see any reason to propagate this block using thing in the gio API, it breaks down anyway in presence of things like tail-merging. We might as well report the actual use in bytes.
Comment 12 Mathias Hasselmann (IRC: tbf) 2008-01-04 10:22:47 UTC
(In reply to comment #11)
> I don't see any reason to propagate this block using thing in the gio API, it
> breaks down anyway in presence of things like tail-merging. We might as well
> report the actual use in bytes.
> 
Absolutely make sense to report actual use in bytes. Has the advantage of having one central place where it's done right, and has the advantage of raising new programmer's awareness, when seeing two well documented size properties close together.

Comment 13 Patrick Hulin 2008-01-21 23:44:55 UTC
Created attachment 103382 [details] [review]
Preliminary patch

Still one major problem that needs ironing out, not sure if it's in GIO or in here - segfault when clicking the "scan home" button.
Comment 14 Patrick Hulin 2008-01-21 23:46:22 UTC
Er - whoops. Misconstrued this bug's topic.
Comment 15 Allison Karlitskaya (desrt) 2009-02-13 14:37:26 UTC
Created attachment 128642 [details] [review]
standard::allocated-size attribute
Comment 16 Allison Karlitskaya (desrt) 2009-02-13 14:39:24 UTC
will also need patches for various gvfs backends, of course...
Comment 17 Alexander Larsson 2009-02-16 14:22:52 UTC
commited the glib patch
Comment 18 Alexander Larsson 2009-02-25 14:58:12 UTC
Further work required is support in whatever gvfs backends make sense.
Comment 19 Christian Kellner 2009-10-01 15:31:27 UTC
Comment on attachment 128642 [details] [review]
standard::allocated-size attribute

Marking patch as committed to get it off the to-review-patches list.
Comment 20 Ross Lagerwall 2014-06-02 05:33:25 UTC
Created attachment 277706 [details] [review]
smb: Implement standard::allocated-size
Comment 21 Ross Lagerwall 2014-06-02 05:33:31 UTC
Created attachment 277707 [details] [review]
afc: Implement standard::allocated-size
Comment 22 Ross Lagerwall 2014-06-02 05:34:55 UTC
These are the only two backends that could support it, from what I can see.
Comment 23 Ondrej Holy 2014-06-05 14:41:51 UTC
Review of attachment 277706 [details] [review]:

Looks good, thanks!
Comment 24 Ondrej Holy 2014-06-05 14:42:26 UTC
Review of attachment 277707 [details] [review]:

Looks good, thanks!
Comment 25 Ross Lagerwall 2014-06-05 20:36:50 UTC
Pushed to master as ebdd9bd. Thanks for the review!