]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/freebsd.c
2 * Copyright (c) 2003,2005 Silicon Graphics, Inc.
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.
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.
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
22 #include <sys/mount.h>
23 #include <sys/ioctl.h>
24 #include <sys/sysctl.h>
26 int platform_has_uuid
= 1;
27 extern char *progname
;
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"
34 platform_check_ismounted(char *name
, char *block
, struct stat
*s
, int verbose
)
38 struct statfs
*fsinfo
;
41 if (stat(block
, &st
) < 0)
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
))
51 if ((cnt
= getmntinfo(&fsinfo
, MNT_NOWAIT
)) == 0) {
53 _("%s: %s possibly contains a mounted filesystem\n"),
58 for (i
= 0; i
< cnt
; i
++) {
59 if (strcmp (name
, fsinfo
[i
].f_mntfromname
) != 0)
64 _("%s: %s contains a mounted filesystem\n"),
73 platform_check_iswritable(char *name
, char *block
, struct stat
*s
)
76 struct statfs
*fsinfo
;
78 if ((cnt
= getmntinfo(&fsinfo
, MNT_NOWAIT
)) == 0) {
79 fprintf(stderr
, _("%s: %s contains a possibly writable, "
80 "mounted filesystem\n"), progname
, name
);
84 for (i
= 0; i
< cnt
; i
++) {
85 if (strcmp (name
, fsinfo
[i
].f_mntfromname
) != 0)
88 if (fsinfo
[i
].f_flags
&= MNT_RDONLY
)
93 fprintf(stderr
, _("%s: %s contains a mounted and writable "
94 "filesystem\n"), progname
, name
);
101 platform_set_blocksize(int fd
, char *path
, dev_t device
, int blocksize
, int fatal
)
107 platform_flush_device(int fd
, dev_t device
)
113 platform_findsizes(char *path
, int fd
, long long *sz
, int *bsz
)
119 if (fstat(fd
, &st
) < 0) {
120 fprintf(stderr
, _("%s: "
121 "cannot stat the device file \"%s\": %s\n"),
122 progname
, path
, strerror(errno
));
126 if ((st
.st_mode
& S_IFMT
) == S_IFREG
) {
127 *sz
= (long long)(st
.st_size
>> 9);
132 if ((st
.st_mode
& S_IFMT
) != S_IFCHR
) {
133 fprintf(stderr
, _("%s: Not a device or file: \"%s\"\n"),
138 if (ioctl(fd
, DIOCGMEDIASIZE
, &size
) != 0) {
139 fprintf(stderr
, _("%s: DIOCGMEDIASIZE failed on \"%s\": %s\n"),
140 progname
, path
, strerror(errno
));
144 if (ioctl(fd
, DIOCGSECTORSIZE
, &ssize
) != 0) {
145 fprintf(stderr
, _("%s: "
146 "DIOCGSECTORSIZE failed on \"%s\": %s\n"),
147 progname
, path
, strerror(errno
));
151 *sz
= (long long) (size
/ ssize
);
156 platform_findrawpath(char *path
)
162 platform_findblockpath(char *path
)
168 platform_direct_blockdev(void)
174 platform_align_blockdev(void)
176 return sizeof(void *);
183 size_t len
= sizeof(ncpu
);
184 static int mib
[2] = {CTL_HW
, HW_NCPU
};
186 if (sysctl(mib
, 2, &ncpu
, &len
, NULL
, 0) < 0)
193 platform_physmem(void)
195 unsigned long physmem
;
196 size_t len
= sizeof(physmem
);
197 static int mib
[2] = {CTL_HW
, HW_PHYSMEM
};
199 if (sysctl(mib
, 2, &physmem
, &len
, NULL
, 0) < 0) {
200 fprintf(stderr
, _("%s: can't determine memory size\n"),
204 return physmem
>> 10;