From 4f1631ae3e220b668c06600f05a196cf0a20e518 Mon Sep 17 00:00:00 2001 From: Russell Cattelan Date: Wed, 2 Apr 2003 17:18:32 +0000 Subject: [PATCH] Add initial FreeBSD support to xfs cmds Add freebsd flags... note this should be handled better via autoconf --- include/builddefs.in | 4 + include/platform_defs.h.in | 48 ++++++++- include/xfs_arch.h | 2 + libxfs/freebsd.c | 194 +++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 libxfs/freebsd.c diff --git a/include/builddefs.in b/include/builddefs.in index 98089f8bf..95792e1bd 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -103,6 +103,10 @@ endif ifeq ($(PKG_PLATFORM),irix) PLDLIBS = -ldisk -lgen endif +ifeq ($(PKG_PLATFORM),freebsd) +PLDLIBS = -L/usr/local/lib -lintl +CFLAGS += -I/usr/local/include +endif GCFLAGS += $(OPTIMIZER) $(DEBUG) -funsigned-char -Wall -I$(TOPDIR)/include \ -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\" \ diff --git a/include/platform_defs.h.in b/include/platform_defs.h.in index d7a1fca84..532753ebf 100644 --- a/include/platform_defs.h.in +++ b/include/platform_defs.h.in @@ -104,6 +104,48 @@ typedef unsigned char uchar_t; #endif typedef enum { B_FALSE,B_TRUE } boolean_t; +#elif defined(__FreeBSD__) +#include +#include +#include +#include +#include +#include +/* 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 */ @@ -114,9 +156,9 @@ typedef enum { B_FALSE,B_TRUE } boolean_t; #include #include -#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); diff --git a/include/xfs_arch.h b/include/xfs_arch.h index 4629bc745..164510175 100644 --- a/include/xfs_arch.h +++ b/include/xfs_arch.h @@ -60,9 +60,11 @@ /* generic swapping macros */ +#if defined(__linux__) #define INT_SWAP16(type,var) ((typeof(type))(__swab16((__u16)(var)))) #define INT_SWAP32(type,var) ((typeof(type))(__swab32((__u32)(var)))) #define INT_SWAP64(type,var) ((typeof(type))(__swab64((__u64)(var)))) +#endif #define INT_SWAP(type, var) \ ((sizeof(type) == 8) ? INT_SWAP64(type,var) : \ diff --git a/libxfs/freebsd.c b/libxfs/freebsd.c new file mode 100644 index 000000000..c6e1efa63 --- /dev/null +++ b/libxfs/freebsd.c @@ -0,0 +1,194 @@ +/* + * 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 +#include +#include +#include +#include +#include + +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; +} -- 2.47.2