]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
93d9f139 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2003,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
93d9f139 NS |
5 | */ |
6 | ||
7 | #include <sys/disk.h> | |
8 | #include <sys/stat.h> | |
9 | #include <sys/mount.h> | |
10 | #include <sys/ioctl.h> | |
2556c98b | 11 | #include <sys/sysctl.h> |
6b803e5a | 12 | #include "libxfs.h" |
93d9f139 | 13 | |
e321f629 | 14 | int platform_has_uuid = 1; |
93d9f139 NS |
15 | extern char *progname; |
16 | ||
a8502cc4 ES |
17 | #warning "Darwin support is deprecated and planned for removal in July 2018" |
18 | #warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port" | |
19 | #error "Remove this line if you'd like to continue the build" | |
20 | ||
93d9f139 | 21 | int |
f594a0d1 | 22 | platform_check_ismounted(char *name, char *block, struct stat *s, int verbose) |
93d9f139 NS |
23 | { |
24 | return 0; | |
25 | } | |
26 | ||
27 | int | |
f594a0d1 | 28 | platform_check_iswritable(char *name, char *block, struct stat *s) |
93d9f139 NS |
29 | { |
30 | int fd, writable; | |
31 | ||
32 | if ((fd = open(block, O_RDONLY, 0)) < 0) { | |
33 | fprintf(stderr, _("%s: " | |
34 | "error opening the device special file \"%s\": %s\n"), | |
35 | progname, block, strerror(errno)); | |
36 | exit(1); | |
37 | } | |
38 | ||
39 | if (ioctl(fd, DKIOCISWRITABLE, &writable) < 0) { | |
40 | fprintf(stderr, _("%s: can't tell if \"%s\" is writable: %s\n"), | |
41 | progname, block, strerror(errno)); | |
42 | exit(1); | |
43 | } | |
44 | close(fd); | |
af43ca9f | 45 | return writable == 0; |
93d9f139 NS |
46 | } |
47 | ||
edd45774 TS |
48 | int |
49 | platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal) | |
93d9f139 | 50 | { |
edd45774 | 51 | return fatal; |
74668075 NS |
52 | } |
53 | ||
93d9f139 | 54 | void |
ac419944 | 55 | platform_flush_device(int fd, dev_t device) |
93d9f139 NS |
56 | { |
57 | ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL); | |
58 | } | |
59 | ||
f02037ce NS |
60 | void |
61 | platform_findsizes(char *path, int fd, long long *sz, int *bsz) | |
93d9f139 | 62 | { |
14f8b681 | 63 | uint64_t size; |
f594a0d1 | 64 | struct stat st; |
93d9f139 | 65 | |
f594a0d1 | 66 | if (fstat(fd, &st) < 0) { |
93d9f139 NS |
67 | fprintf(stderr, |
68 | _("%s: cannot stat the device file \"%s\": %s\n"), | |
69 | progname, path, strerror(errno)); | |
70 | exit(1); | |
71 | } | |
f02037ce NS |
72 | if ((st.st_mode & S_IFMT) == S_IFREG) { |
73 | *sz = (long long)(st.st_size >> 9); | |
74 | *bsz = BBSIZE; | |
75 | return; | |
93d9f139 | 76 | } |
93d9f139 NS |
77 | if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) { |
78 | fprintf(stderr, _("%s: can't determine device size: %s\n"), | |
79 | progname, strerror(errno)); | |
80 | exit(1); | |
81 | } | |
f02037ce NS |
82 | *sz = (long long)size; |
83 | *bsz = BBSIZE; | |
93d9f139 | 84 | } |
cb5b3ef4 | 85 | |
cb5b3ef4 MV |
86 | char * |
87 | platform_findrawpath(char *path) | |
88 | { | |
b74a1f6a | 89 | return path; |
cb5b3ef4 | 90 | } |
1aef52f8 | 91 | |
b74a1f6a NS |
92 | char * |
93 | platform_findblockpath(char *path) | |
94 | { | |
95 | return path; | |
96 | } | |
97 | ||
98 | int | |
99 | platform_direct_blockdev(void) | |
100 | { | |
101 | return 0; | |
102 | } | |
103 | ||
104 | int | |
105 | platform_align_blockdev(void) | |
1aef52f8 | 106 | { |
af43ca9f | 107 | return sizeof(void *); |
1aef52f8 | 108 | } |
3b6ac903 MV |
109 | |
110 | int | |
111 | platform_nproc(void) | |
112 | { | |
2556c98b BN |
113 | int ncpu; |
114 | size_t len = sizeof(ncpu); | |
115 | static int mib[2] = {CTL_HW, HW_NCPU}; | |
116 | ||
117 | if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0) | |
118 | ncpu = 1; | |
119 | ||
120 | return ncpu; | |
3b6ac903 | 121 | } |
2556c98b BN |
122 | |
123 | unsigned long | |
124 | platform_physmem(void) | |
125 | { | |
126 | unsigned long physmem; | |
127 | size_t len = sizeof(physmem); | |
128 | static int mib[2] = {CTL_HW, HW_PHYSMEM}; | |
129 | ||
130 | if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) { | |
131 | fprintf(stderr, _("%s: can't determine memory size\n"), | |
132 | progname); | |
133 | exit(1); | |
134 | } | |
135 | return physmem >> 10; | |
136 | } |