]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/darwin.c
xfs: refactor superblock verifiers
[thirdparty/xfsprogs-dev.git] / libfrog / darwin.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2003,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include <sys/disk.h>
8 #include <sys/stat.h>
9 #include <sys/mount.h>
10 #include <sys/ioctl.h>
11 #include <sys/sysctl.h>
12 #include "libxfs.h"
13
14 int platform_has_uuid = 1;
15 extern char *progname;
16
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
21 int
22 platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
23 {
24 return 0;
25 }
26
27 int
28 platform_check_iswritable(char *name, char *block, struct stat *s)
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);
45 return writable == 0;
46 }
47
48 int
49 platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
50 {
51 return fatal;
52 }
53
54 void
55 platform_flush_device(int fd, dev_t device)
56 {
57 ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
58 }
59
60 void
61 platform_findsizes(char *path, int fd, long long *sz, int *bsz)
62 {
63 uint64_t size;
64 struct stat st;
65
66 if (fstat(fd, &st) < 0) {
67 fprintf(stderr,
68 _("%s: cannot stat the device file \"%s\": %s\n"),
69 progname, path, strerror(errno));
70 exit(1);
71 }
72 if ((st.st_mode & S_IFMT) == S_IFREG) {
73 *sz = (long long)(st.st_size >> 9);
74 *bsz = BBSIZE;
75 return;
76 }
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 }
82 *sz = (long long)size;
83 *bsz = BBSIZE;
84 }
85
86 char *
87 platform_findrawpath(char *path)
88 {
89 return path;
90 }
91
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)
106 {
107 return sizeof(void *);
108 }
109
110 int
111 platform_nproc(void)
112 {
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;
121 }
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 }