diff options
Diffstat (limited to 'fs/ubifs/budget.c')
-rw-r--r-- | fs/ubifs/budget.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c index 9ef630a594ca..7851480a6cea 100644 --- a/fs/ubifs/budget.c +++ b/fs/ubifs/budget.c | |||
@@ -702,6 +702,51 @@ void ubifs_release_dirty_inode_budget(struct ubifs_info *c, | |||
702 | } | 702 | } |
703 | 703 | ||
704 | /** | 704 | /** |
705 | * ubifs_reported_space - calculate reported free space. | ||
706 | * @c: the UBIFS file-system description object | ||
707 | * @free: amount of free space | ||
708 | * | ||
709 | * This function calculates amount of free space which will be reported to | ||
710 | * user-space. User-space application tend to expect that if the file-system | ||
711 | * (e.g., via the 'statfs()' call) reports that it has N bytes available, they | ||
712 | * are able to write a file of size N. UBIFS attaches node headers to each data | ||
713 | * node and it has to write indexind nodes as well. This introduces additional | ||
714 | * overhead, and UBIFS it has to report sligtly less free space to meet the | ||
715 | * above expectetion. | ||
716 | * | ||
717 | * This function assumes free space is made up of uncompressed data nodes and | ||
718 | * full index nodes (one per data node, tripled because we always allow enough | ||
719 | * space to write the index thrice). | ||
720 | * | ||
721 | * Note, the calculation is pessimistic, which means that most of the time | ||
722 | * UBIFS reports less space than it actually has. | ||
723 | */ | ||
724 | long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free) | ||
725 | { | ||
726 | int divisor, factor; | ||
727 | |||
728 | /* | ||
729 | * Reported space size is @free * X, where X is UBIFS block size | ||
730 | * divided by UBIFS block size + all overhead one data block | ||
731 | * introduces. The overhead is the node header + indexing overhead. | ||
732 | * | ||
733 | * Indexing overhead is calculations are based on the following | ||
734 | * formula: I = N/(f - 1) + 1, where I - number of indexing nodes, N - | ||
735 | * number of data nodes, f - fanout. Because effective UBIFS fanout is | ||
736 | * twice as less than maximum fanout, we assume that each data node | ||
737 | * introduces 3 * @c->max_idx_node_sz / (@c->fanout/2 - 1) bytes. | ||
738 | * Note, the multiplier 3 is because UBIFS reseves thrice as more space | ||
739 | * for the index. | ||
740 | */ | ||
741 | factor = UBIFS_BLOCK_SIZE; | ||
742 | divisor = UBIFS_MAX_DATA_NODE_SZ; | ||
743 | divisor += (c->max_idx_node_sz * 3) / ((c->fanout >> 1) - 1); | ||
744 | free *= factor; | ||
745 | do_div(free, divisor); | ||
746 | return free; | ||
747 | } | ||
748 | |||
749 | /** | ||
705 | * ubifs_budg_get_free_space - return amount of free space. | 750 | * ubifs_budg_get_free_space - return amount of free space. |
706 | * @c: UBIFS file-system description object | 751 | * @c: UBIFS file-system description object |
707 | * | 752 | * |