]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/freebsd.c
xfs_repair: don't assert on bad '.' entry in no-modify mode
[thirdparty/xfsprogs-dev.git] / libxfs / freebsd.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 "libxfs.h"
20 #include <sys/stat.h>
21 #include <sys/disk.h>
22 #include <sys/mount.h>
23 #include <sys/ioctl.h>
24 #include <sys/sysctl.h>
25
26 int platform_has_uuid = 1;
27 extern char *progname;
28
29 #warning "FreeBSD 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 struct stat st;
37 int cnt, i;
38 struct statfs *fsinfo;
39
40 if (!s) {
41 if (stat(block, &st) < 0)
42 return 0;
43 s = &st;
44 }
45
46 /* Remember, FreeBSD can now mount char devices! -- adrian */
47 if (((st.st_mode & S_IFMT) != S_IFBLK) &&
48 ((st.st_mode & S_IFMT) != S_IFCHR))
49 return 0;
50
51 if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
52 fprintf(stderr,
53 _("%s: %s possibly contains a mounted filesystem\n"),
54 progname, name);
55 return 1;
56 }
57
58 for (i = 0; i < cnt; i++) {
59 if (strcmp (name, fsinfo[i].f_mntfromname) != 0)
60 continue;
61
62 if (verbose)
63 fprintf(stderr,
64 _("%s: %s contains a mounted filesystem\n"),
65 progname, name);
66 break;
67 }
68
69 return i < cnt;
70 }
71
72 int
73 platform_check_iswritable(char *name, char *block, struct stat *s)
74 {
75 int cnt, i;
76 struct statfs *fsinfo;
77
78 if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
79 fprintf(stderr, _("%s: %s contains a possibly writable, "
80 "mounted filesystem\n"), progname, name);
81 return 1;
82 }
83
84 for (i = 0; i < cnt; i++) {
85 if (strcmp (name, fsinfo[i].f_mntfromname) != 0)
86 continue;
87
88 if (fsinfo[i].f_flags &= MNT_RDONLY)
89 break;
90 }
91
92 if (i == cnt) {
93 fprintf(stderr, _("%s: %s contains a mounted and writable "
94 "filesystem\n"), progname, name);
95 return 1;
96 }
97 return 0;
98 }
99
100 int
101 platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
102 {
103 return fatal;
104 }
105
106 void
107 platform_flush_device(int fd, dev_t device)
108 {
109 return;
110 }
111
112 void
113 platform_findsizes(char *path, int fd, long long *sz, int *bsz)
114 {
115 struct stat st;
116 int64_t size;
117 uint ssize;
118
119 if (fstat(fd, &st) < 0) {
120 fprintf(stderr, _("%s: "
121 "cannot stat the device file \"%s\": %s\n"),
122 progname, path, strerror(errno));
123 exit(1);
124 }
125
126 if ((st.st_mode & S_IFMT) == S_IFREG) {
127 *sz = (long long)(st.st_size >> 9);
128 *bsz = 512;
129 return;
130 }
131
132 if ((st.st_mode & S_IFMT) != S_IFCHR) {
133 fprintf(stderr, _("%s: Not a device or file: \"%s\"\n"),
134 progname, path);
135 exit(1);
136 }
137
138 if (ioctl(fd, DIOCGMEDIASIZE, &size) != 0) {
139 fprintf(stderr, _("%s: DIOCGMEDIASIZE failed on \"%s\": %s\n"),
140 progname, path, strerror(errno));
141 exit(1);
142 }
143
144 if (ioctl(fd, DIOCGSECTORSIZE, &ssize) != 0) {
145 fprintf(stderr, _("%s: "
146 "DIOCGSECTORSIZE failed on \"%s\": %s\n"),
147 progname, path, strerror(errno));
148 exit(1);
149 }
150
151 *sz = (long long) (size / ssize);
152 *bsz = (int)ssize;
153 }
154
155 char *
156 platform_findrawpath(char *path)
157 {
158 return path;
159 }
160
161 char *
162 platform_findblockpath(char *path)
163 {
164 return path;
165 }
166
167 int
168 platform_direct_blockdev(void)
169 {
170 return 0;
171 }
172
173 int
174 platform_align_blockdev(void)
175 {
176 return sizeof(void *);
177 }
178
179 int
180 platform_nproc(void)
181 {
182 int ncpu;
183 size_t len = sizeof(ncpu);
184 static int mib[2] = {CTL_HW, HW_NCPU};
185
186 if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
187 ncpu = 1;
188
189 return ncpu;
190 }
191
192 unsigned long
193 platform_physmem(void)
194 {
195 unsigned long physmem;
196 size_t len = sizeof(physmem);
197 static int mib[2] = {CTL_HW, HW_PHYSMEM};
198
199 if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
200 fprintf(stderr, _("%s: can't determine memory size\n"),
201 progname);
202 exit(1);
203 }
204 return physmem >> 10;
205 }