소스 검색

Get libufs/block.c compiling without errors + 1st pass at ufsdat.h

Signed-off-by: Graham MacDonald <grahamamacdonald@gmail.com>
Graham MacDonald 6 년 전
부모
커밋
6c92c95ee0

+ 0 - 3
sys/include/ufs/freebsd_util.h

@@ -59,10 +59,7 @@ typedef	uint32_t ino_t;		/* inode number */
 typedef	uint32_t uid_t;		/* user id */
 typedef	uint32_t gid_t;		/* group id */
 typedef	uint16_t nlink_t;	/* link count */
-typedef	char *caddr_t;		/* core address */
 typedef	uint16_t mode_t;	/* permissions */
-typedef int64_t off_t;		/* File offset */
-typedef	uint32_t ino_t;		/* inode number */
 
 /*
  * The size of physical and logical block numbers and time fields in UFS.

+ 28 - 60
sys/include/ufs/libufs.h

@@ -27,9 +27,6 @@
  * $FreeBSD$
  */
 
-#ifndef	__LIBUFS_H__
-#define	__LIBUFS_H__
-
 /*
  * libufs structures.
  */
@@ -37,7 +34,7 @@
 /*
  * userland ufs disk.
  */
-struct uufsd {
+typedef struct Uufsd {
 	const char *d_name;	/* disk name */
 	int d_ufs;		/* decimal UFS version */
 	int d_fd;		/* raw device file descriptor */
@@ -48,12 +45,12 @@ struct uufsd {
 	ino_t d_inomin;		/* low inode */
 	ino_t d_inomax;		/* high inode */
 	union {
-		struct fs d_fs;	/* filesystem information */
+		Fs d_fs;	/* filesystem information */
 		char d_sb[MAXBSIZE];
 				/* superblock as buffer */
 	} d_sbunion;
 	union {
-		struct cg d_cg;	/* cylinder group */
+		Cg d_cg;	/* cylinder group */
 		char d_buf[MAXBSIZE];
 				/* cylinder group storage */
 	} d_cgunion;
@@ -64,33 +61,8 @@ struct uufsd {
 #define	d_fs	d_sbunion.d_fs
 #define	d_sb	d_sbunion.d_sb
 #define	d_cg	d_cgunion.d_cg
-};
+} Uufsd;
 
-/*
- * libufs macros (internal, non-exported).
- */
-#ifdef	_LIBUFS
-/*
- * Trace steps through libufs, to be used at entry and erroneous return.
- */
-static inline void
-ERROR(struct uufsd *u, const char *str)
-{
-
-#ifdef	_LIBUFS_DEBUGGING
-	if (str != NULL) {
-		fprintf(stderr, "libufs: %s", str);
-		if (errno != 0)
-			fprintf(stderr, ": %s", strerror(errno));
-		fprintf(stderr, "\n");
-	}
-#endif
-	if (u != NULL)
-		u->d_error = str;
-}
-#endif	/* _LIBUFS */
-
-__BEGIN_DECLS
 
 /*
  * libufs prototypes.
@@ -99,51 +71,47 @@ __BEGIN_DECLS
 /*
  * block.c
  */
-ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
-ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
-int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
+int32_t bread(Uufsd *, ufs2_daddr_t, void *, size_t);
+int32_t bwrite(Uufsd *, ufs2_daddr_t, const void *, size_t);
+void libufserror(Uufsd *u, const char *str);
 
 /*
  * cgroup.c
  */
-ufs2_daddr_t cgballoc(struct uufsd *);
-int cgbfree(struct uufsd *, ufs2_daddr_t, long);
-ino_t cgialloc(struct uufsd *);
-int cgread(struct uufsd *);
-int cgread1(struct uufsd *, int);
-int cgwrite(struct uufsd *);
-int cgwrite1(struct uufsd *, int);
+ufs2_daddr_t cgballoc(Uufsd *);
+int cgbfree(Uufsd *, ufs2_daddr_t, long);
+ino_t cgialloc(Uufsd *);
+int cgread(Uufsd *);
+int cgread1(Uufsd *, int);
+int cgwrite(Uufsd *);
+int cgwrite1(Uufsd *, int);
 
 /*
  * inode.c
  */
-int getino(struct uufsd *, void **, ino_t, int *);
-int putino(struct uufsd *);
+int getino(Uufsd *, void **, ino_t, int *);
+int putino(Uufsd *);
 
 /*
  * sblock.c
  */
-int sbread(struct uufsd *);
-int sbwrite(struct uufsd *, int);
+int sbread(Uufsd *);
+int sbwrite(Uufsd *, int);
 
 /*
  * type.c
  */
-int ufs_disk_close(struct uufsd *);
-int ufs_disk_fillout(struct uufsd *, const char *);
-int ufs_disk_fillout_blank(struct uufsd *, const char *);
-int ufs_disk_write(struct uufsd *);
+int ufs_disk_close(Uufsd *);
+int ufs_disk_fillout(Uufsd *, const char *);
+int ufs_disk_fillout_blank(Uufsd *, const char *);
+int ufs_disk_write(Uufsd *);
 
 /*
  * ffs_subr.c
  */
-void	ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
-void	ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
-void	ffs_fragacct(struct fs *, int, int32_t [], int);
-int	ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
-int	ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
-void	ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
-
-__END_DECLS
-
-#endif	/* __LIBUFS_H__ */
+void	ffs_clrblock(Fs *, uint8_t *, ufs1_daddr_t);
+void	ffs_clusteracct(Fs *, Cg *, ufs1_daddr_t, int);
+void	ffs_fragacct(Fs *, int, int32_t [], int);
+int	ffs_isblock(Fs *, uint8_t *, ufs1_daddr_t);
+int	ffs_isfreeblock(Fs *, uint8_t *, ufs1_daddr_t);
+void	ffs_setblock(Fs *, uint8_t *, ufs1_daddr_t);

+ 44 - 0
sys/include/ufs/ufsdat.h

@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ *
+ *	@(#)queue.h	8.5 (Berkeley) 8/20/94
+ * $FreeBSD$
+ */
+
+typedef char *caddr_t;		/* core address */
+typedef int64_t off_t;		/* File offset */
+typedef uint32_t ino_t;		/* inode number */
+
+/*
+ * MAXBSIZE -	Filesystems are made out of blocks of at most MAXBSIZE bytes
+ *		per block.  MAXBSIZE may be made larger without effecting
+ *		any existing filesystems as long as it does not exceed MAXPHYS,
+ *		and may be made smaller at the risk of not being able to use
+ *		filesystems which require a block size exceeding MAXBSIZE.
+ */
+#define MAXBSIZE	65536	/* must be power of 2 */

+ 1 - 0
sys/src/9/ufs/ffs/ffs_balloc.c

@@ -65,6 +65,7 @@
 #include "dat.h"
 #include "fns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_harvey.h"
 

+ 1 - 0
sys/src/9/ufs/ffs/ffs_inode.c

@@ -35,6 +35,7 @@
 #include "dat.h"
 #include "fns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_harvey.h"
 

+ 1 - 0
sys/src/9/ufs/ffs/ffs_snapshot.c

@@ -39,6 +39,7 @@
 #include "dat.h"
 #include "fns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_harvey.h"
 

+ 1 - 0
sys/src/9/ufs/ffs/ffs_subr.c

@@ -35,6 +35,7 @@
 #include "dat.h"
 #include "fns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_harvey.h"
 

+ 1 - 0
sys/src/9/ufs/ffs/ffs_vfsops.c

@@ -37,6 +37,7 @@
 #include "dat.h"
 #include "../../port/portfns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_mountpoint.h"
 #include "ufs_harvey.h"

+ 1 - 0
sys/src/9/ufs/ufs/ufs_vfsops.c

@@ -40,6 +40,7 @@
 #include "dat.h"
 #include "../../port/portfns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_harvey.h"
 

+ 1 - 0
sys/src/9/ufs/ufs_harvey.c

@@ -15,6 +15,7 @@
 #include "dat.h"
 #include "fns.h"
 
+#include <ufs/ufsdat.h>
 #include <ufs/freebsd_util.h>
 #include "ufs_harvey.h"
 #include "ufs_mountpoint.h"

+ 0 - 10
sys/src/9/ufs/ufs_harvey.h

@@ -106,16 +106,6 @@ typedef struct vnode {
 } vnode;
 
 
-/*
- * MAXBSIZE -	Filesystems are made out of blocks of at most MAXBSIZE bytes
- *		per block.  MAXBSIZE may be made larger without effecting
- *		any existing filesystems as long as it does not exceed MAXPHYS,
- *		and may be made smaller at the risk of not being able to use
- *		filesystems which require a block size exceeding MAXBSIZE.
- */
-#define MAXBSIZE	65536	/* must be power of 2 */
-
-
 /*
  * Flags to various vnode functions.
  */

+ 32 - 94
sys/src/libufs/block.c

@@ -25,34 +25,21 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-//#include <sys/cdefs.h>
+#include <u.h>
+#include <libc.h>
 
-//#include <sys/param.h>
-//#include <sys/mount.h>
-//#include <sys/disk.h>
-//#include <sys/disklabel.h>
-//#include <sys/stat.h>
-
-#include <ufs/ufsmount.h>
+#include <ufs/ufsdat.h>
 #include <ufs/dinode.h>
 #include <ffs/fs.h>
-
-//#include <errno.h>
-//#include <fcntl.h>
-//#include <stdio.h>
-//#include <stdlib.h>
-//#include <string.h>
-//#include <unistd.h>
-
 #include <ufs/libufs.h>
 
-ssize_t
-bread(struct uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size)
+int32_t
+bread(Uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size)
 {
 	void *p2;
-	ssize_t cnt;
+	int32_t cnt;
 
-	ERROR(disk, NULL);
+	libufserror(disk, nil);
 
 	p2 = data;
 	/*
@@ -63,22 +50,22 @@ bread(struct uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size)
 	 */
 	if (((intptr_t)data) & 0x3f) {
 		p2 = malloc(size);
-		if (p2 == NULL) {
-			ERROR(disk, "allocate bounce buffer");
+		if (p2 == nil) {
+			libufserror(disk, "allocate bounce buffer");
 			goto fail;
 		}
 	}
 	cnt = pread(disk->d_fd, p2, size, (off_t)(blockno * disk->d_bsize));
 	if (cnt == -1) {
-		ERROR(disk, "read error from block device");
+		libufserror(disk, "read error from block device");
 		goto fail;
 	}
 	if (cnt == 0) {
-		ERROR(disk, "end of file from block device");
+		libufserror(disk, "end of file from block device");
 		goto fail;
 	}
 	if ((size_t)cnt != size) {
-		ERROR(disk, "short read or read error from block device");
+		libufserror(disk, "short read or read error from block device");
 		goto fail;
 	}
 	if (p2 != data) {
@@ -93,18 +80,18 @@ fail:	memset(data, 0, size);
 	return (-1);
 }
 
-ssize_t
-bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size)
+int32_t
+bwrite(Uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size)
 {
-	ssize_t cnt;
+	int32_t cnt;
 	int rv;
-	void *p2 = NULL;
+	void *p2 = nil;
 
-	ERROR(disk, NULL);
+	libufserror(disk, nil);
 
 	rv = ufs_disk_write(disk);
 	if (rv == -1) {
-		ERROR(disk, "failed to open disk for writing");
+		libufserror(disk, "failed to open disk for writing");
 		return (-1);
 	}
 
@@ -116,85 +103,36 @@ bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size)
 	 */
 	if (((intptr_t)data) & 0x3f) {
 		p2 = malloc(size);
-		if (p2 == NULL) {
-			ERROR(disk, "allocate bounce buffer");
+		if (p2 == nil) {
+			libufserror(disk, "allocate bounce buffer");
 			return (-1);
 		}
 		memcpy(p2, data, size);
 		data = p2;
 	}
 	cnt = pwrite(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize));
-	if (p2 != NULL)
+	if (p2 != nil)
 		free(p2);
 	if (cnt == -1) {
-		ERROR(disk, "write error to block device");
+		libufserror(disk, "write error to block device");
 		return (-1);
 	}
 	if ((size_t)cnt != size) {
-		ERROR(disk, "short write to block device");
+		libufserror(disk, "short write to block device");
 		return (-1);
 	}
 
 	return (cnt);
 }
 
-#ifdef __FreeBSD_kernel__
-
-static int
-berase_helper(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
-{
-	off_t ioarg[2];
-
-	ioarg[0] = blockno * disk->d_bsize;
-	ioarg[1] = size;
-	return (ioctl(disk->d_fd, DIOCGDELETE, ioarg));
-}
-
-#else
-
-static int
-berase_helper(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
-{
-	char *zero_chunk;
-	off_t offset, zero_chunk_size, pwrite_size;
-	int rv;
-
-	offset = blockno * disk->d_bsize;
-	zero_chunk_size = 65536 * disk->d_bsize;
-	zero_chunk = calloc(1, zero_chunk_size);
-	if (zero_chunk == NULL) {
-		ERROR(disk, "failed to allocate memory");
-		return (-1);
-	}
-	while (size > 0) { 
-		pwrite_size = size;
-		if (pwrite_size > zero_chunk_size)
-			pwrite_size = zero_chunk_size;
-		rv = pwrite(disk->d_fd, zero_chunk, pwrite_size, offset);
-		if (rv == -1) {
-			ERROR(disk, "failed writing to disk");
-			break;
-		}
-		size -= rv;
-		offset += rv;
-		rv = 0;
-	}
-	free(zero_chunk);
-	return (rv);
-}
-
-#endif
-
-int
-berase(struct uufsd *disk, ufs2_daddr_t blockno, ufs2_daddr_t size)
+/*
+ * Trace steps through libufs, to be used at entry and erroneous return.
+ */
+void
+libufserror(Uufsd *u, const char *str)
 {
-	int rv;
-
-	ERROR(disk, NULL);
-	rv = ufs_disk_write(disk);
-	if (rv == -1) {
-		ERROR(disk, "failed to open disk for writing");
-		return(rv);
-	}
-	return (berase_helper(disk, blockno, size));
+	if (str != nil)
+		perror(str);
+	if (u != nil)
+		u->d_error = str;
 }

+ 3 - 0
sys/src/libufs/cgroup.c

@@ -25,6 +25,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <u.h>
+#include <libc.h>
+
 //#include <sys/cdefs.h>
 
 //#include <sys/param.h>

+ 1 - 1
sys/src/libufs/libufs_subr.c

@@ -153,7 +153,7 @@ ffs_clrblock(Fs *fs, uint8_t *cp, ufs1_daddr_t h)
  * put a block into the map
  */
 void
-ffs_setblock(Fs *fs, unsigned char *cp, ufs1_daddr_t h)
+ffs_setblock(Fs *fs, uint8_t *cp, ufs1_daddr_t h)
 {
 	switch ((int)fs->fs_frag) {
 

+ 3 - 0
sys/src/libufs/sblock.c

@@ -25,6 +25,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <u.h>
+#include <libc.h>
+
 //#include <sys/cdefs.h>
 
 //#include <sys/param.h>

+ 3 - 0
sys/src/libufs/type.c

@@ -25,6 +25,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <u.h>
+#include <libc.h>
+
 //#include <sys/cdefs.h>
 
 //#include <sys/param.h>