]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/darwin.c
xfs_repair: remove unused fs_has_extflgbit_allowed
[thirdparty/xfsprogs-dev.git] / libxfs / 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
29int
f594a0d1 30platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
93d9f139
NS
31{
32 return 0;
33}
34
35int
f594a0d1 36platform_check_iswritable(char *name, char *block, struct stat *s)
93d9f139
NS
37{
38 int fd, writable;
39
40 if ((fd = open(block, O_RDONLY, 0)) < 0) {
41 fprintf(stderr, _("%s: "
42 "error opening the device special file \"%s\": %s\n"),
43 progname, block, strerror(errno));
44 exit(1);
45 }
46
47 if (ioctl(fd, DKIOCISWRITABLE, &writable) < 0) {
48 fprintf(stderr, _("%s: can't tell if \"%s\" is writable: %s\n"),
49 progname, block, strerror(errno));
50 exit(1);
51 }
52 close(fd);
af43ca9f 53 return writable == 0;
93d9f139
NS
54}
55
edd45774
TS
56int
57platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
93d9f139 58{
edd45774 59 return fatal;
74668075
NS
60}
61
93d9f139 62void
ac419944 63platform_flush_device(int fd, dev_t device)
93d9f139
NS
64{
65 ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
66}
67
f02037ce
NS
68void
69platform_findsizes(char *path, int fd, long long *sz, int *bsz)
93d9f139 70{
14f8b681 71 uint64_t size;
f594a0d1 72 struct stat st;
93d9f139 73
f594a0d1 74 if (fstat(fd, &st) < 0) {
93d9f139
NS
75 fprintf(stderr,
76 _("%s: cannot stat the device file \"%s\": %s\n"),
77 progname, path, strerror(errno));
78 exit(1);
79 }
f02037ce
NS
80 if ((st.st_mode & S_IFMT) == S_IFREG) {
81 *sz = (long long)(st.st_size >> 9);
82 *bsz = BBSIZE;
83 return;
93d9f139 84 }
93d9f139
NS
85 if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) {
86 fprintf(stderr, _("%s: can't determine device size: %s\n"),
87 progname, strerror(errno));
88 exit(1);
89 }
f02037ce
NS
90 *sz = (long long)size;
91 *bsz = BBSIZE;
93d9f139 92}
cb5b3ef4 93
cb5b3ef4
MV
94char *
95platform_findrawpath(char *path)
96{
b74a1f6a 97 return path;
cb5b3ef4 98}
1aef52f8 99
b74a1f6a
NS
100char *
101platform_findblockpath(char *path)
102{
103 return path;
104}
105
106int
107platform_direct_blockdev(void)
108{
109 return 0;
110}
111
112int
113platform_align_blockdev(void)
1aef52f8 114{
af43ca9f 115 return sizeof(void *);
1aef52f8 116}
3b6ac903
MV
117
118int
119platform_nproc(void)
120{
2556c98b
BN
121 int ncpu;
122 size_t len = sizeof(ncpu);
123 static int mib[2] = {CTL_HW, HW_NCPU};
124
125 if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
126 ncpu = 1;
127
128 return ncpu;
3b6ac903 129}
2556c98b
BN
130
131unsigned long
132platform_physmem(void)
133{
134 unsigned long physmem;
135 size_t len = sizeof(physmem);
136 static int mib[2] = {CTL_HW, HW_PHYSMEM};
137
138 if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
139 fprintf(stderr, _("%s: can't determine memory size\n"),
140 progname);
141 exit(1);
142 }
143 return physmem >> 10;
144}