]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libfrog/darwin.c
xfs: hoist xfs_scrub_agfl_walk to libxfs as xfs_agfl_walk
[thirdparty/xfsprogs-dev.git] / libfrog / darwin.c
CommitLineData
93d9f139 1/*
da23017d
NS
2 * Copyright (c) 2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
93d9f139 4 *
da23017d
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
93d9f139
NS
7 * published by the Free Software Foundation.
8 *
da23017d
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
93d9f139 13 *
da23017d
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
93d9f139
NS
17 */
18
19#include <sys/disk.h>
20#include <sys/stat.h>
21#include <sys/mount.h>
22#include <sys/ioctl.h>
2556c98b 23#include <sys/sysctl.h>
6b803e5a 24#include "libxfs.h"
93d9f139 25
e321f629 26int platform_has_uuid = 1;
93d9f139
NS
27extern char *progname;
28
a8502cc4
ES
29#warning "Darwin support is deprecated and planned for removal in July 2018"
30#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
31#error "Remove this line if you'd like to continue the build"
32
93d9f139 33int
f594a0d1 34platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
93d9f139
NS
35{
36 return 0;
37}
38
39int
f594a0d1 40platform_check_iswritable(char *name, char *block, struct stat *s)
93d9f139
NS
41{
42 int fd, writable;
43
44 if ((fd = open(block, O_RDONLY, 0)) < 0) {
45 fprintf(stderr, _("%s: "
46 "error opening the device special file \"%s\": %s\n"),
47 progname, block, strerror(errno));
48 exit(1);
49 }
50
51 if (ioctl(fd, DKIOCISWRITABLE, &writable) < 0) {
52 fprintf(stderr, _("%s: can't tell if \"%s\" is writable: %s\n"),
53 progname, block, strerror(errno));
54 exit(1);
55 }
56 close(fd);
af43ca9f 57 return writable == 0;
93d9f139
NS
58}
59
edd45774
TS
60int
61platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
93d9f139 62{
edd45774 63 return fatal;
74668075
NS
64}
65
93d9f139 66void
ac419944 67platform_flush_device(int fd, dev_t device)
93d9f139
NS
68{
69 ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
70}
71
f02037ce
NS
72void
73platform_findsizes(char *path, int fd, long long *sz, int *bsz)
93d9f139 74{
14f8b681 75 uint64_t size;
f594a0d1 76 struct stat st;
93d9f139 77
f594a0d1 78 if (fstat(fd, &st) < 0) {
93d9f139
NS
79 fprintf(stderr,
80 _("%s: cannot stat the device file \"%s\": %s\n"),
81 progname, path, strerror(errno));
82 exit(1);
83 }
f02037ce
NS
84 if ((st.st_mode & S_IFMT) == S_IFREG) {
85 *sz = (long long)(st.st_size >> 9);
86 *bsz = BBSIZE;
87 return;
93d9f139 88 }
93d9f139
NS
89 if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) {
90 fprintf(stderr, _("%s: can't determine device size: %s\n"),
91 progname, strerror(errno));
92 exit(1);
93 }
f02037ce
NS
94 *sz = (long long)size;
95 *bsz = BBSIZE;
93d9f139 96}
cb5b3ef4 97
cb5b3ef4
MV
98char *
99platform_findrawpath(char *path)
100{
b74a1f6a 101 return path;
cb5b3ef4 102}
1aef52f8 103
b74a1f6a
NS
104char *
105platform_findblockpath(char *path)
106{
107 return path;
108}
109
110int
111platform_direct_blockdev(void)
112{
113 return 0;
114}
115
116int
117platform_align_blockdev(void)
1aef52f8 118{
af43ca9f 119 return sizeof(void *);
1aef52f8 120}
3b6ac903
MV
121
122int
123platform_nproc(void)
124{
2556c98b
BN
125 int ncpu;
126 size_t len = sizeof(ncpu);
127 static int mib[2] = {CTL_HW, HW_NCPU};
128
129 if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
130 ncpu = 1;
131
132 return ncpu;
3b6ac903 133}
2556c98b
BN
134
135unsigned long
136platform_physmem(void)
137{
138 unsigned long physmem;
139 size_t len = sizeof(physmem);
140 static int mib[2] = {CTL_HW, HW_PHYSMEM};
141
142 if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
143 fprintf(stderr, _("%s: can't determine memory size\n"),
144 progname);
145 exit(1);
146 }
147 return physmem >> 10;
148}