GNOME Bugzilla – Bug 505042
support standard::allocated-size
Last modified: 2014-06-05 20:37:20 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?
Makes sense to me; I'd probably go with the allocated-size attribute, but thats up to Alex.
Looking again, G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE and G_FILE_ATTRIBUTE_UNIX_BLOCKS are exactly what you want, no ?
I guess they are. I totally missed them.
I tried those attributes but unless I am doing something wrong they do not seem to work...
Created attachment 101501 [details] gvfs-du.c Here is a first cut at a gvfs-du program to test that functionality
Created attachment 101586 [details] [review] patch The problem is due to a typo in the ifdef.
Thanks, please commit.
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...
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.
(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.
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.
(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.
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.
Er - whoops. Misconstrued this bug's topic.
Created attachment 128642 [details] [review] standard::allocated-size attribute
will also need patches for various gvfs backends, of course...
commited the glib patch
Further work required is support in whatever gvfs backends make sense.
Comment on attachment 128642 [details] [review] standard::allocated-size attribute Marking patch as committed to get it off the to-review-patches list.
Created attachment 277706 [details] [review] smb: Implement standard::allocated-size
Created attachment 277707 [details] [review] afc: Implement standard::allocated-size
These are the only two backends that could support it, from what I can see.
Review of attachment 277706 [details] [review]: Looks good, thanks!
Review of attachment 277707 [details] [review]: Looks good, thanks!
Pushed to master as ebdd9bd. Thanks for the review!