]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/darwin.c
xfsprogs: replace [fl]stat64 by equivalent [fl]stat
[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 int
30 platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
31 {
32 return 0;
33 }
34
35 int
36 platform_check_iswritable(char *name, char *block, struct stat *s)
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);
53 return writable == 0;
54 }
55
56 int
57 platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
58 {
59 return fatal;
60 }
61
62 void
63 platform_flush_device(int fd, dev_t device)
64 {
65 ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
66 }
67
68 void
69 platform_findsizes(char *path, int fd, long long *sz, int *bsz)
70 {
71 __uint64_t size;
72 struct stat st;
73
74 if (fstat(fd, &st) < 0) {
75 fprintf(stderr,
76 _("%s: cannot stat the device file \"%s\": %s\n"),
77 progname, path, strerror(errno));
78 exit(1);
79 }
80 if ((st.st_mode & S_IFMT) == S_IFREG) {
81 *sz = (long long)(st.st_size >> 9);
82 *bsz = BBSIZE;
83 return;
84 }
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 }
90 *sz = (long long)size;
91 *bsz = BBSIZE;
92 }
93
94 char *
95 platform_findrawpath(char *path)
96 {
97 return path;
98 }
99
100 char *
101 platform_findblockpath(char *path)
102 {
103 return path;
104 }
105
106 int
107 platform_direct_blockdev(void)
108 {
109 return 0;
110 }
111
112 int
113 platform_align_blockdev(void)
114 {
115 return sizeof(void *);
116 }
117
118 int
119 platform_nproc(void)
120 {
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;
129 }
130
131 unsigned long
132 platform_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 }