]>
Commit | Line | Data |
---|---|---|
4f1631ae | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2003,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
4f1631ae | 4 | * |
da23017d NS |
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 | |
4f1631ae RC |
7 | * published by the Free Software Foundation. |
8 | * | |
da23017d NS |
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. | |
4f1631ae | 13 | * |
da23017d NS |
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 | |
4f1631ae RC |
17 | */ |
18 | ||
6b803e5a | 19 | #include "libxfs.h" |
4f1631ae | 20 | #include <sys/stat.h> |
850173f0 | 21 | #include <sys/disk.h> |
4f1631ae RC |
22 | #include <sys/mount.h> |
23 | #include <sys/ioctl.h> | |
cd3b56ff | 24 | #include <sys/sysctl.h> |
4f1631ae | 25 | |
e321f629 | 26 | int platform_has_uuid = 1; |
4f1631ae RC |
27 | extern char *progname; |
28 | ||
29 | int | |
f594a0d1 | 30 | platform_check_ismounted(char *name, char *block, struct stat *s, int verbose) |
4f1631ae | 31 | { |
f594a0d1 | 32 | struct stat st; |
850173f0 RC |
33 | int cnt, i; |
34 | struct statfs *fsinfo; | |
4f1631ae RC |
35 | |
36 | if (!s) { | |
f594a0d1 | 37 | if (stat(block, &st) < 0) |
4f1631ae | 38 | return 0; |
4f1631ae RC |
39 | s = &st; |
40 | } | |
850173f0 | 41 | |
4f1631ae RC |
42 | /* Remember, FreeBSD can now mount char devices! -- adrian */ |
43 | if (((st.st_mode & S_IFMT) != S_IFBLK) && | |
da23017d | 44 | ((st.st_mode & S_IFMT) != S_IFCHR)) |
4f1631ae RC |
45 | return 0; |
46 | ||
850173f0 RC |
47 | if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) { |
48 | fprintf(stderr, | |
49 | _("%s: %s possibly contains a mounted filesystem\n"), | |
50 | progname, name); | |
51 | return 1; | |
52 | } | |
53 | ||
54 | for (i = 0; i < cnt; i++) { | |
55 | if (strcmp (name, fsinfo[i].f_mntfromname) != 0) | |
56 | continue; | |
da23017d | 57 | |
850173f0 RC |
58 | if (verbose) |
59 | fprintf(stderr, | |
60 | _("%s: %s contains a mounted filesystem\n"), | |
61 | progname, name); | |
62 | break; | |
63 | } | |
64 | ||
af43ca9f | 65 | return i < cnt; |
4f1631ae RC |
66 | } |
67 | ||
68 | int | |
f594a0d1 | 69 | platform_check_iswritable(char *name, char *block, struct stat *s) |
4f1631ae | 70 | { |
850173f0 RC |
71 | int cnt, i; |
72 | struct statfs *fsinfo; | |
73 | ||
74 | if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) { | |
75 | fprintf(stderr, _("%s: %s contains a possibly writable, " | |
76 | "mounted filesystem\n"), progname, name); | |
7f510afb | 77 | return 1; |
850173f0 RC |
78 | } |
79 | ||
80 | for (i = 0; i < cnt; i++) { | |
81 | if (strcmp (name, fsinfo[i].f_mntfromname) != 0) | |
82 | continue; | |
da23017d | 83 | |
850173f0 RC |
84 | if (fsinfo[i].f_flags &= MNT_RDONLY) |
85 | break; | |
86 | } | |
87 | ||
88 | if (i == cnt) { | |
89 | fprintf(stderr, _("%s: %s contains a mounted and writable " | |
90 | "filesystem\n"), progname, name); | |
7f510afb | 91 | return 1; |
850173f0 | 92 | } |
f02037ce | 93 | return 0; |
4f1631ae RC |
94 | } |
95 | ||
edd45774 TS |
96 | int |
97 | platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal) | |
4f1631ae | 98 | { |
edd45774 | 99 | return fatal; |
4f1631ae RC |
100 | } |
101 | ||
102 | void | |
ac419944 | 103 | platform_flush_device(int fd, dev_t device) |
4f1631ae | 104 | { |
ac419944 | 105 | return; |
4f1631ae RC |
106 | } |
107 | ||
f02037ce NS |
108 | void |
109 | platform_findsizes(char *path, int fd, long long *sz, int *bsz) | |
4f1631ae | 110 | { |
f02037ce | 111 | struct stat st; |
14f8b681 | 112 | int64_t size; |
81043eae | 113 | uint ssize; |
dfc130f3 | 114 | |
f02037ce | 115 | if (fstat(fd, &st) < 0) { |
1707056a | 116 | fprintf(stderr, _("%s: " |
f02037ce | 117 | "cannot stat the device file \"%s\": %s\n"), |
4f1631ae RC |
118 | progname, path, strerror(errno)); |
119 | exit(1); | |
120 | } | |
850173f0 | 121 | |
4f1631ae | 122 | if ((st.st_mode & S_IFMT) == S_IFREG) { |
f02037ce | 123 | *sz = (long long)(st.st_size >> 9); |
850173f0 | 124 | *bsz = 512; |
f02037ce | 125 | return; |
4f1631ae RC |
126 | } |
127 | ||
850173f0 | 128 | if ((st.st_mode & S_IFMT) != S_IFCHR) { |
b52923f3 | 129 | fprintf(stderr, _("%s: Not a device or file: \"%s\"\n"), |
850173f0 RC |
130 | progname, path); |
131 | exit(1); | |
132 | } | |
da23017d | 133 | |
850173f0 | 134 | if (ioctl(fd, DIOCGMEDIASIZE, &size) != 0) { |
b52923f3 | 135 | fprintf(stderr, _("%s: DIOCGMEDIASIZE failed on \"%s\": %s\n"), |
850173f0 RC |
136 | progname, path, strerror(errno)); |
137 | exit(1); | |
138 | } | |
da23017d | 139 | |
850173f0 RC |
140 | if (ioctl(fd, DIOCGSECTORSIZE, &ssize) != 0) { |
141 | fprintf(stderr, _("%s: " | |
142 | "DIOCGSECTORSIZE failed on \"%s\": %s\n"), | |
143 | progname, path, strerror(errno)); | |
144 | exit(1); | |
145 | } | |
146 | ||
147 | *sz = (long long) (size / ssize); | |
148 | *bsz = (int)ssize; | |
4f1631ae | 149 | } |
cb5b3ef4 | 150 | |
cb5b3ef4 MV |
151 | char * |
152 | platform_findrawpath(char *path) | |
153 | { | |
b74a1f6a | 154 | return path; |
cb5b3ef4 | 155 | } |
1aef52f8 | 156 | |
b74a1f6a NS |
157 | char * |
158 | platform_findblockpath(char *path) | |
159 | { | |
160 | return path; | |
161 | } | |
162 | ||
163 | int | |
164 | platform_direct_blockdev(void) | |
165 | { | |
166 | return 0; | |
167 | } | |
168 | ||
169 | int | |
170 | platform_align_blockdev(void) | |
1aef52f8 | 171 | { |
af43ca9f | 172 | return sizeof(void *); |
1aef52f8 | 173 | } |
3b6ac903 MV |
174 | |
175 | int | |
176 | platform_nproc(void) | |
177 | { | |
2556c98b BN |
178 | int ncpu; |
179 | size_t len = sizeof(ncpu); | |
180 | static int mib[2] = {CTL_HW, HW_NCPU}; | |
181 | ||
182 | if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0) | |
183 | ncpu = 1; | |
184 | ||
185 | return ncpu; | |
186 | } | |
187 | ||
188 | unsigned long | |
189 | platform_physmem(void) | |
190 | { | |
191 | unsigned long physmem; | |
192 | size_t len = sizeof(physmem); | |
193 | static int mib[2] = {CTL_HW, HW_PHYSMEM}; | |
194 | ||
195 | if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) { | |
196 | fprintf(stderr, _("%s: can't determine memory size\n"), | |
197 | progname); | |
198 | exit(1); | |
199 | } | |
200 | return physmem >> 10; | |
3b6ac903 | 201 | } |