]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/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
;
30 platform_check_ismounted(char *name
, char *block
, struct stat
*s
, int verbose
)
34 struct statfs
*fsinfo
;
37 if (stat(block
, &st
) < 0)
42 /* Remember, FreeBSD can now mount char devices! -- adrian */
43 if (((st
.st_mode
& S_IFMT
) != S_IFBLK
) &&
44 ((st
.st_mode
& S_IFMT
) != S_IFCHR
))
47 if ((cnt
= getmntinfo(&fsinfo
, MNT_NOWAIT
)) == 0) {
49 _("%s: %s possibly contains a mounted filesystem\n"),
54 for (i
= 0; i
< cnt
; i
++) {
55 if (strcmp (name
, fsinfo
[i
].f_mntfromname
) != 0)
60 _("%s: %s contains a mounted filesystem\n"),
69 platform_check_iswritable(char *name
, char *block
, struct stat
*s
)
72 struct statfs
*fsinfo
;
74 if ((cnt
= getmntinfo(&fsinfo
, MNT_NOWAIT
)) == 0) {
75 fprintf(stderr
, _("%s: %s contains a possibly writable, "
76 "mounted filesystem\n"), progname
, name
);
80 for (i
= 0; i
< cnt
; i
++) {
81 if (strcmp (name
, fsinfo
[i
].f_mntfromname
) != 0)
84 if (fsinfo
[i
].f_flags
&= MNT_RDONLY
)
89 fprintf(stderr
, _("%s: %s contains a mounted and writable "
90 "filesystem\n"), progname
, name
);
97 platform_set_blocksize(int fd
, char *path
, dev_t device
, int blocksize
, int fatal
)
103 platform_flush_device(int fd
, dev_t device
)
109 platform_findsizes(char *path
, int fd
, long long *sz
, int *bsz
)
115 if (fstat(fd
, &st
) < 0) {
116 fprintf(stderr
, _("%s: "
117 "cannot stat the device file \"%s\": %s\n"),
118 progname
, path
, strerror(errno
));
122 if ((st
.st_mode
& S_IFMT
) == S_IFREG
) {
123 *sz
= (long long)(st
.st_size
>> 9);
128 if ((st
.st_mode
& S_IFMT
) != S_IFCHR
) {
129 fprintf(stderr
, _("%s: Not a device or file: \"%s\"\n"),
134 if (ioctl(fd
, DIOCGMEDIASIZE
, &size
) != 0) {
135 fprintf(stderr
, _("%s: DIOCGMEDIASIZE failed on \"%s\": %s\n"),
136 progname
, path
, strerror(errno
));
140 if (ioctl(fd
, DIOCGSECTORSIZE
, &ssize
) != 0) {
141 fprintf(stderr
, _("%s: "
142 "DIOCGSECTORSIZE failed on \"%s\": %s\n"),
143 progname
, path
, strerror(errno
));
147 *sz
= (long long) (size
/ ssize
);
152 platform_findrawpath(char *path
)
158 platform_findblockpath(char *path
)
164 platform_direct_blockdev(void)
170 platform_align_blockdev(void)
172 return sizeof(void *);
179 size_t len
= sizeof(ncpu
);
180 static int mib
[2] = {CTL_HW
, HW_NCPU
};
182 if (sysctl(mib
, 2, &ncpu
, &len
, NULL
, 0) < 0)
189 platform_physmem(void)
191 unsigned long physmem
;
192 size_t len
= sizeof(physmem
);
193 static int mib
[2] = {CTL_HW
, HW_PHYSMEM
};
195 if (sysctl(mib
, 2, &physmem
, &len
, NULL
, 0) < 0) {
196 fprintf(stderr
, _("%s: can't determine memory size\n"),
200 return physmem
>> 10;