Table of Contents

mtree parsing and manipulation library

Project description

FreeBSD currently includes several tools that work with file system hierarchy descriptions and each contains its own routines to parse and/or manipulate these descriptions.

This project attempts to improve this by designing a library to include all the common code, removing duplications from application code and allowing simple future extensions.

Approach to solving the problem

Develop a new libmtree library

The library will provide an API for specfile-related operations that are currently present in the mtree tool and other tools as well as additional manipulations (filter, merge, update and possibly others) that could be useful to applications in the future or allow expansion of the mtree tool.

The API will be designed to be intuitive, well documented and easily useable by applications.

Some code will be reused from existing applications, mainly from the mtree tool. All reused code will be verified and eventually adapted or rewritten to fit the required abstraction.

The library will include complete API documentation and unit tests.

Modify existing applications and libraries to use libmtree

Applications and libraries that contain mtree code will be modified to use libmtree instead:

The mtree tool itself will be distributed in the same source tree as libmtree. Both libmtree and mtree will be implemented portably.

Milestones

Timeline

Week 1 (May 25 - 31) Status
Create project skeleton with autotools support DONE
libmtree: Initial API design DONE
libmtree: Start implementing support functions DONE
Week 2 - 5 (June 1 - 26)
libmtree: Implement reading of mtree specs DONE
libmtree: Implement creation of mtree specs from directory structure DONE
libmtree: Implement writing of mtree specs DONE
libmtree: Implement comparison of/against mtree specs DONE
Provide initial mtree implementation of the current libmtree features DONE
Week 6 - 7 (June 29 - July 12)
libmtree: Implement spec filtering DONE
Implement remaining pieces of mtree DONE
Week 8 - 9 (July 13 - July 26)
libmtree: Implement additional API parts required by applications DONE
Port libarchive to libmtree DONE
Port makefs to libmtree DONE
Port xinstall to libmtree DONE
Week 10 - 11 (July 27 - August 9)
libmtree: Implement spec merging DONE
libmtree: Implement remaining tests DONE
Write libmtree and mtree manual pages DONE
Week 12 (August 10 - August 17)
Update the FreeBSD source tree to include libmtree and remove redundant code NOT DONE :(

TODO

libmtree, mtree

libarchive

makefs

Changes

The Code

Example

This is a simplified example demonstrating how to use the libmtree API:

#include <mtree.h>
#include <mtree_file.h>
 
int main(void)
{
	struct mtree_spec	*spec_yesterday, *spec_today;
	struct mtree_spec_diff	*diff;
	struct mtree_entry	*entries;
	FILE			*fp;
 
	/*
	 * Read specification from slash-bin-yesterday.mtree file into spec_yesterday.
	 */
	fp = fopen("slash-bin-yesterday.mtree", "r");
	spec_yesterday = mtree_spec_create();
	mtree_spec_read_spec_file(spec_yesterday, fp);
 
	/*
	 * Create specification by walking directory tree.
	 */
	spec_today = mtree_spec_create();
	mtree_spec_read_path(spec_today, "/bin");
 
	/*
	 * Compare file type and time of each file.
	 */
	diff = mtree_spec_diff_create(spec_yesterday, spec_today,
	    MTREE_KEYWORD_TIME |
	    MTREE_KEYWORD_TYPE, 0);
 
	entries = mtree_spec_diff_get_different(diff);
	if (entries != NULL) {
		printf("ALERT! == Some files have been changed! == ALERT!\n\n");
		while (entries != NULL) {
			struct mtree_entry *entry_yesterday, *entry_today;
 
			/*
			 * "entries" is a linked list of entries containing the entries that
			 * are different in each spec.
			 *
			 * As described in mtree_spec_diff(3), the entries are stored in pairs,
			 * first entry being from the first list, second being from the second
			 * list.
			 *
			 * Also, their keyword sets have been modified to include only the
			 * keywords that are different.
			 */
			entry_yesterday = entries;
			entry_today = mtree_entry_get_next(entry_yesterday);
 
			printf("%s\n", mtree_entry_get_path(entry_yesterday));
			if (mtree_entry_get_keywords(entry_yesterday) & MTREE_KEYWORD_TIME)
				printf("\tTime: %ld -> %ld\n",
				       mtree_entry_get_time(entry_yesterday)->tv_sec,
				       mtree_entry_get_time(entry_today)->tv_sec);
			if (mtree_entry_get_keywords(entry_yesterday) & MTREE_KEYWORD_TYPE)
				printf("\tType: %s -> %s\n",
				       mtree_entry_type_string(mtree_entry_get_type(entry_yesterday)),
				       mtree_entry_type_string(mtree_entry_get_type(entry_today)));
 
			entries = mtree_entry_get_next(entry_today);
		}
	}
}

API Design