]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/darwin.c
libxfs: warn about deprecation of irix, freebsd, darwin
[thirdparty/xfsprogs-dev.git] / libxfs / darwin.c
1 /*
2 * Copyright (c) 2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18
19 #include <sys/disk.h>
20 #include <sys/stat.h>
21 #include <sys/mount.h>
22 #include <sys/ioctl.h>
23 #include <sys/sysctl.h>
24 #include "libxfs.h"
25
26 int platform_has_uuid = 1;
27 extern char *progname;
28
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
33 int
34 platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
35 {
36 return 0;
37 }
38
39 int
40 platform_check_iswritable(char *name, char *block, struct stat *s)
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);
57 return writable == 0;
58 }
59
60 int
61 platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
62 {
63 return fatal;
64 }
65
66 void
67 platform_flush_device(int fd, dev_t device)
68 {
69 ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
70 }
71
72 void
73 platform_findsizes(char *path, int fd, long long *sz, int *bsz)
74 {
75 uint64_t size;
76 struct stat st;
77
78 if (fstat(fd, &st) < 0) {
79 fprintf(stderr,
80 _("%s: cannot stat the device file \"%s\": %s\n"),
81 progname, path, strerror(errno));
82 exit(1);
83 }
84 if ((st.st_mode & S_IFMT) == S_IFREG) {
85 *sz = (long long)(st.st_size >> 9);
86 *bsz = BBSIZE;
87 return;
88 }
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 }
94 *sz = (long long)size;
95 *bsz = BBSIZE;
96 }
97
98 char *
99 platform_findrawpath(char *path)
100 {
101 return path;
102 }
103
104 char *
105 platform_findblockpath(char *path)
106 {
107 return path;
108 }
109
110 int
111 platform_direct_blockdev(void)
112 {
113 return 0;
114 }
115
116 int
117 platform_align_blockdev(void)
118 {
119 return sizeof(void *);
120 }
121
122 int
123 platform_nproc(void)
124 {
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;
133 }
134
135 unsigned long
136 platform_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 }