Skip to contentSkip to conversation

UBIFS: Implement read-only UBIFS support in U-Boot (Part 1)

PATCH New Stefan Roese 2 participants 3 messages Mar 12, 2009 – Mar 19, 2009 UBI file system (UBIFS)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/8 UBIFS: Implement read-only UBIFS support in U-Boot (Part 1)

This patchset adds UBIFS read-only support to U-Boot. The following commands are implemented:

- ubifsmount
Mount an UBIFS volume

- ubifsls
List a directory of the mounted UBIFS volume

- ubifsload
Load a file from the mounted UBIFS volume to memory

The U-Boot UBIFS implementation is largely a direct copy from the current Linux version (2.6.29-rc6). As already done in the UBI version we have an "abstraction layer" to redefine or remove some OS calls (e.g. mutex_lock() ...). This makes it possible to use the original Linux code with very little changes. And by this we can better update to later Linux versions.

I removed some of the Linux features that are not used in the U-Boot version (e.g. garbage-collection, write support).

CC Artem Bityutskiy <[email protected]>
CC Adrian Hunter <[email protected]>

---
Changes in v2:
- Now symbolic links are handled correctly

 fs/ubifs/budget.c |  113 +++++++++++++++
 fs/ubifs/crc16.c  |   60 ++++++++
 fs/ubifs/crc16.h  |   30 ++++
 fs/ubifs/debug.c  |  156 +++++++++++++++++++++
 fs/ubifs/debug.h  |  392 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 751 insertions(+), 0 deletions(-)
 create mode 100644 fs/ubifs/budget.c
 create mode 100644 fs/ubifs/crc16.c
 create mode 100644 fs/ubifs/crc16.h
 create mode 100644 fs/ubifs/debug.c
 create mode 100644 fs/ubifs/debug.h
fs/ubifs/budget.c new file +113 -0
new file mode 100644
index 0000000..85377ea
@@ -0,0 +1,113 @@
+/*
+ * This file is part of UBIFS.
+ *
+ * Copyright (C) 2006-2008 Nokia Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Adrian Hunter
+ *          Artem Bityutskiy (???????????????? ??????????)
+ */
+
+/*
+ * This file implements the budgeting sub-system which is responsible for UBIFS
+ * space management.
+ *
+ * Factors such as compression, wasted space at the ends of LEBs, space in other
+ * journal heads, the effect of updates on the index, and so on, make it
+ * impossible to accurately predict the amount of space needed. Consequently
+ * approximations are used.
+ */
+
+#include "ubifs.h"
+#include <linux/math64.h>
+
+/**
+ * ubifs_calc_min_idx_lebs - calculate amount of eraseblocks for the index.
+ * @c: UBIFS file-system description object
+ *
+ * This function calculates and returns the number of eraseblocks which should
+ * be kept for index usage.
+ */
+int ubifs_calc_min_idx_lebs(struct ubifs_info *c)
+{
+	int idx_lebs, eff_leb_size = c->leb_size - c->max_idx_node_sz;
+	long long idx_size;
+
+	idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx;
+
+	/* And make sure we have thrice the index size of space reserved */
+	idx_size = idx_size + (idx_size << 1);
+
+	/*
+	 * We do not maintain 'old_idx_size' as 'old_idx_lebs'/'old_idx_bytes'
+	 * pair, nor similarly the two variables for the new index size, so we
+	 * have to do this costly 64-bit division on fast-path.
+	 */
+	idx_size += eff_leb_size - 1;
+	idx_lebs = div_u64(idx_size, eff_leb_size);
+	/*
+	 * The index head is not available for the in-the-gaps method, so add an
+	 * extra LEB to compensate.
+	 */
+	idx_lebs += 1;
+	if (idx_lebs < MIN_INDEX_LEBS)
+		idx_lebs = MIN_INDEX_LEBS;
+	return idx_lebs;
+}
+
+/**
+ * ubifs_reported_space - calculate reported free space.
+ * @c: the UBIFS file-system description object
+ * @free: amount of free space
+ *
+ * This function calculates amount of free space which will be reported to
+ * user-space. User-space application tend to expect that if the file-system
+ * (e.g., via the 'statfs()' call) reports that it has N bytes available, they
+ * are able to write a file of size N. UBIFS attaches node headers to each data
+ * node and it has to write indexing nodes as well. This introduces additional
+ * overhead, and UBIFS has to report slightly less free space to meet the above
+ * expectations.
+ *
+ * This function assumes free space is made up of uncompressed data nodes and
+ * full index nodes (one per data node, tripled because we always allow enough
+ * space to write the index thrice).
+ *
+ * Note, the calculation is pessimistic, which means that most of the time
+ * UBIFS reports less space than it actually has.
+ */
+long long ubifs_reported_space(const struct ubifs_info *c, long long free)
+{
+	int divisor, factor, f;
+
+	/*
+	 * Reported space size is @free * X, where X is UBIFS block size
+	 * divided by UBIFS block size + all overhead one data block
+	 * introduces. The overhead is the node header + indexing overhead.
+	 *
+	 * Indexing overhead calculations are based on the following formula:
+	 * I = N/(f - 1) + 1, where I - number of indexing nodes, N - number
+	 * of data nodes, f - fanout. Because effective UBIFS fanout is twice
+	 * as less than maximum fanout, we assume that each data node
+	 * introduces 3 * @c->max_idx_node_sz / (@c->fanout/2 - 1) bytes.
+	 * Note, the multiplier 3 is because UBIFS reserves thrice as more space
+	 * for the index.
+	 */
+	f = c->fanout > 3 ? c->fanout >> 1 : 2;
+	factor = UBIFS_BLOCK_SIZE;
+	divisor = UBIFS_MAX_DATA_NODE_SZ;
+	divisor += (c->max_idx_node_sz * 3) / (f - 1);
+	free *= factor;
+	return div_u64(free, divisor);
+}
fs/ubifs/crc16.c new file +60 -0

60 lines not on this page · raw message

fs/ubifs/crc16.h new file +30 -0
new file mode 100644
index 0000000..9443c08
@@ -0,0 +1,30 @@
+/*
+ *	crc16.h - CRC-16 routine
+ *
+ * Implements the standard CRC-16:
+ *   Width 16
+ *   Poly  0x8005 (x^16 + x^15 + x^2 + 1)
+ *   Init  0
+ *
+ * Copyright (c) 2005 Ben Gardner <[email protected]>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
+
+#ifndef __CRC16_H
+#define __CRC16_H
+
+#include <linux/types.h>
+
+extern u16 const crc16_table[256];
+
+extern u16 crc16(u16 crc, const u8 *buffer, size_t len);
+
+static inline u16 crc16_byte(u16 crc, const u8 data)
+{
+	return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff];
+}
+
+#endif /* __CRC16_H */
+
fs/ubifs/debug.c new file +156 -0

156 lines not on this page · raw message

fs/ubifs/debug.h new file +392 -0

392 lines not on this page · raw message

Signature · 1 line
1.6.1.3
#1 lore raw

PATCH v2 1/8 UBIFS: Implement read-only UBIFS support in U-Boot (Part 1)

Dear Stefan Roese,

Quoted 20 lines · In message <[email protected]> you wrote:

--===============2128501430==

This patchset adds UBIFS read-only support to U-Boot. The following commands are implemented:

- ubifsmount
Mount an UBIFS volume

- ubifsls
List a directory of the mounted UBIFS volume

- ubifsload
Load a file from the mounted UBIFS volume to memory

The U-Boot UBIFS implementation is largely a direct copy from the current Linux version (2.6.29-rc6). As already done in the UBI version we have an "abstraction layer" to redefine or remove some OS calls (e.g. mutex_lock() ...). This makes it possible to use the original Linux code with very little changes. And by this we can better update to later Linux versions.

Quoted 6 lines

I removed some of the Linux features that are not used in the U-Boot version (e.g. garbage-collection, write support).

CC Artem Bityutskiy <[email protected]>
CC Adrian Hunter <[email protected]>

I don't understand the split of this patchset into 8 patches, which all use the very same subject (= commit title line) and commit message.

It seems the splitting was done just for size reasons, not taking into account any logic parts that belong together or bi-sectability.

Please explain why this is not just a single commit?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The face of war has never changed.  Surely it is more logical to heal
than to kill.
	-- Surak of Vulcan, "The Savage Curtain", stardate 5906.5
#2 lore raw

PATCH v2 1/8 UBIFS: Implement read-only UBIFS support in U-Boot (Part 1)

Hi Wolfgang,

Quoted 26 lines · Wolfgang Denk
Quoted 19 lines

This patchset adds UBIFS read-only support to U-Boot. The following commands are implemented:

- ubifsmount
Mount an UBIFS volume

- ubifsls
List a directory of the mounted UBIFS volume

- ubifsload
Load a file from the mounted UBIFS volume to memory

The U-Boot UBIFS implementation is largely a direct copy from the current Linux version (2.6.29-rc6). As already done in the UBI version we have an "abstraction layer" to redefine or remove some OS calls (e.g. mutex_lock() ...). This makes it possible to use the original Linux code with very little changes. And by this we can better update to later Linux versions.

Quoted 6 lines

I removed some of the Linux features that are not used in the U-Boot version (e.g. garbage-collection, write support).

CC Artem Bityutskiy <[email protected]>
CC Adrian Hunter <[email protected]>
Quoted 6 lines

I don't understand the split of this patchset into 8 patches, which all use the very same subject (= commit title line) and commit message.

It seems the splitting was done just for size reasons, not taking into account any logic parts that belong together or bi-sectability.

Correct. Even though it should still be git bisectable.

Quoted 1 line

Please explain why this is not just a single commit?

Sure. It's the list limit. It was my understanding that patches > 100k usually are not accepted on the list. This UBIFS support is approx. 500k in total, so I didn't even try to send it as a single patch.

OK, I'll send the patch to list again in a short while.

Best regards,
Stefan

=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================