/*
 * Copyright (c)2004 The DragonFly Project.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *   Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 *   Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 * 
 *   Neither the name of the DragonFly Project nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

/*
 * diskutil.h
 * $Id: diskutil.h,v 1.1 2004/07/09 23:25:40 cpressey Exp $
 */

#include <stdio.h>

#ifndef __DISKUTIL_H_
#define __DISKUTIL_H_

/*** TYPES ***/

struct system_storage {
	struct disk *disk_head;
	struct disk *disk_tail;
	struct disk *selected_disk;
	struct slice *selected_slice;
	long ram;			/* amount of physical memory in MB */
};

struct disk {
	struct disk *next;
	struct disk *prev;
	struct slice *slice_head;
	struct slice *slice_tail;
	char *desc;			/* from dmesg */
	char *device;			/* `ad' or `da' */
	int number;			/* 0 on up */
	long capacity;			/* in megabytes */
	int we_formatted;		/* we formatted it */
};

struct slice {
	struct slice *next;
	struct slice *prev;
	struct subpartition *subpartition_head;
	struct subpartition *subpartition_tail;
	char *desc;			/* from fdisk */
	int number;			/* 1 - 4 or more */
	long capacity;			/* in megabytes */
};

struct subpartition {
	struct subpartition *next;
	struct subpartition *prev;
	char letter;			/* 'a' = root partition */
	char *mountpoint;		/* includes leading slash */
	long capacity;			/* in megabytes, -1 = "rest of disk" */
	int softupdates;
	long fsize;
	long bsize;
	int is_swap;
};

/*** PROTOTYPES ***/

struct system_storage	*system_storage_new(void);
void			 system_storage_free(struct system_storage *);

struct disk		*disk_new(struct system_storage *, char *);
struct disk		*disk_find(struct system_storage *, char *);
void			 disks_free(struct system_storage *);
void			 discover_disks(struct system_storage *);
void			 discover_storage(struct system_storage *);

struct slice		*slice_new(struct disk *, int, int, long, long);
struct slice		*slice_find(struct disk *, int);
void			 slices_free(struct slice *);

struct subpartition	*subpartition_new(struct slice *, char *, long,
					  int, long, long);
int			 subpartition_count(struct slice *);
struct subpartition	*subpartition_find(struct slice *, char *, ...);
struct subpartition	*subpartition_find_capacity(struct slice *, long);
void		 	 subpartitions_free(struct slice *);

long			 measure_physical_memory(struct system_storage *);
long			 measure_activated_swap(void);
long			 measure_activated_swap_from_slice(struct disk *, struct slice *);
long			 measure_activated_swap_from_disk(struct disk *);

#endif /* !__DISKUTIL_H_ */
