#endif
typedef enum { B_FALSE,B_TRUE } boolean_t;
+#elif defined(__FreeBSD__)
+#include <sys/stat.h>
+#include <libgen.h>
+#include <machine/endian.h>
+#include <sys/param.h>
+#include <paths.h>
+#include <ctype.h>
+/* FreeBSD file API is 64-bit aware */
+#define fstat64 fstat
+#define ftruncate64 ftruncate
+#define lseek64 lseek
+#define stat64 stat
+#define pwrite64 pwrite
+#define pread64 pread
+#define memalign(a,size) valloc(size)
+
+typedef u_int8_t __u8;
+typedef int8_t __s8;
+typedef u_int16_t __u16;
+typedef int16_t __s16;
+typedef u_int32_t __u32;
+typedef int32_t __s32;
+typedef u_int64_t __u64;
+typedef int64_t __s64;
+
+#define constpp char * const *
+
+#define EFSCORRUPTED 990 /* Filesystem is corrupted */
+
+typedef off_t xfs_off_t;
+typedef __uint64_t xfs_ino_t;
+typedef __uint32_t xfs_dev_t;
+typedef __int64_t xfs_daddr_t;
+typedef char* xfs_caddr_t;
+
+
+#ifndef _UCHAR_T_DEFINED
+typedef unsigned char uchar_t;
+#define _UCHAR_T_DEFINED 1
+#endif
+typedef enum { B_FALSE,B_TRUE } boolean_t;
+#define HAVE_FID 1
#elif defined(__APPLE__) /* Darwin */
#include <sys/mount.h>
#include <sys/syscall.h>
-#ifndef SYS_fsctl
-#define SYS_fsctl 242
-#endif
+# ifndef SYS_fsctl
+# define SYS_fsctl 242
+# endif
static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
{
return syscall(SYS_fsctl, path, cmd, p, 0);
--- /dev/null
+/*
+ * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+#define ustat __kernel_ustat
+#include <libxfs.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <sys/ioctl.h>
+#include <sys/diskslice.h>
+#include <sys/disklabel.h>
+
+extern char *progname;
+
+int
+platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
+{
+ struct stat st;
+
+ if (!s) {
+ if (stat(block, &st) < 0)
+ return 0;
+ if ((st.st_mode & S_IFMT) != S_IFBLK)
+ return 0;
+ s = &st;
+ }
+ /* Remember, FreeBSD can now mount char devices! -- adrian */
+ if (((st.st_mode & S_IFMT) != S_IFBLK) &&
+ ((st.st_mode & S_IFMT) != S_IFCHR))
+ return 0;
+
+ return 0;
+}
+
+int
+platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
+{
+ int sts = 0;
+ return sts;
+}
+
+void
+platform_set_blocksize(int fd, char *path, int blocksize)
+{
+}
+
+void
+platform_flush_device(int fd)
+{
+}
+
+/*
+ * Get disk slice and partition information.
+ */
+static __int64_t
+getdisksize(int fd, const char *fname)
+{
+ //struct diskslices ds;
+ struct disklabel dl, *lp;
+ const char *s1, *s2;
+ char *s;
+ int slice, part, fd1, i, e;
+ __int64_t size = 0LL;
+
+ slice = part = -1;
+ s1 = fname;
+ if ((s2 = strrchr(s1, '/')))
+ s1 = s2 + 1;
+ for (s2 = s1; *s2 && !isdigit(*s2); s2++);
+ if (!*s2 || s2 == s1)
+ s2 = NULL;
+ else
+ while (isdigit(*++s2));
+ s1 = s2;
+ if (s2 && *s2 == 's') {
+ slice = strtol(s2 + 1, &s, 10);
+ if (slice < 1 || slice > MAX_SLICES - BASE_SLICE)
+ s2 = NULL;
+ else {
+ slice = BASE_SLICE + slice - 1;
+ s2 = s;
+ }
+ }
+ if (s2 && *s2 >= 'a' && *s2 <= 'a' + MAXPARTITIONS - 1) {
+ if (slice == -1)
+ slice = COMPATIBILITY_SLICE;
+ part = *s2++ - 'a';
+ }
+ if (!s2 || (*s2 && *s2 != '.')) {
+ fprintf(stderr, "%s: can't figure out partition info\n",
+ progname);
+ exit(1);
+ }
+
+ if (slice == -1 || part != -1) {
+ lp = &dl;
+ i = ioctl(fd, DIOCGDINFO, lp);
+ if (i == -1 && slice != -1 && part == -1) {
+ e = errno;
+ if (!(s = strdup(fname))) {
+ fprintf(stderr, "%s: %s\n",
+ progname, strerror(errno));
+ exit(1);
+ }
+ s[s1 - fname] = 0;
+ if ((fd1 = open(s, O_RDONLY)) != -1) {
+ i = ioctl(fd1, DIOCGDINFO, lp);
+ close(fd1);
+ }
+ free(s);
+ errno = e;
+ }
+ if (i == -1) {
+ fprintf(stderr, "%s: can't read disk label: %s\n",
+ progname, strerror(errno));
+ exit(1);
+ }
+ if (slice == -1 || part != -1) {
+ if (part == -1)
+ part = RAW_PART;
+ if (part >= lp->d_npartitions ||
+ !lp->d_partitions[part].p_size) {
+ fprintf(stderr, "%s: partition %s is unavailable\n",
+ progname, fname);
+ exit(1);
+ }
+ size = lp->d_partitions[part].p_size;
+ }
+ }
+ return size;
+}
+
+__int64_t
+platform_findsize(char *path)
+{
+ int fd;
+ struct stat st;
+ __int64_t size;
+
+ /* Test to see if we are dealing with a regular file rather than a
+ * block device, if we are just use the size returned by stat64
+ */
+ if (stat(path, &st) < 0) {
+ fprintf(stderr, "%s: "
+ "cannot stat the device special file \"%s\": %s\n",
+ progname, path, strerror(errno));
+ exit(1);
+ }
+ if ((st.st_mode & S_IFMT) == S_IFREG) {
+ return (__int64_t)(st.st_size >> 9);
+ }
+
+ if ((fd = open(path, 0)) < 0) {
+ fprintf(stderr, "%s: "
+ "error opening the device special file \"%s\": %s\n",
+ progname, path, strerror(errno));
+ exit(1);
+ }
+
+ size = getdisksize(fd, path);
+
+ close(fd);
+
+ return size;
+}