ggate.c (71ae6999b6b7e309df8e545ef5adf960375d848e) | ggate.c (122abe0385259048f1dbfcf673fdd173cf26ea09) |
---|---|
1/*- 2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 119 unchanged lines hidden (view full) --- 128} 129 130off_t 131g_gate_mediasize(int fd) 132{ 133 off_t mediasize; 134 struct stat sb; 135 | 1/*- 2 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 119 unchanged lines hidden (view full) --- 128} 129 130off_t 131g_gate_mediasize(int fd) 132{ 133 off_t mediasize; 134 struct stat sb; 135 |
136 if (fstat(fd, &sb) < 0) | 136 if (fstat(fd, &sb) == -1) |
137 g_gate_xlog("fstat(): %s.", strerror(errno)); 138 if (S_ISCHR(sb.st_mode)) { | 137 g_gate_xlog("fstat(): %s.", strerror(errno)); 138 if (S_ISCHR(sb.st_mode)) { |
139 if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) { | 139 if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) == -1) { |
140 g_gate_xlog("Can't get media size: %s.", 141 strerror(errno)); 142 } 143 } else if (S_ISREG(sb.st_mode)) { 144 mediasize = sb.st_size; 145 } else { 146 g_gate_xlog("Unsupported file system object."); 147 } 148 return (mediasize); 149} 150 151size_t 152g_gate_sectorsize(int fd) 153{ 154 size_t secsize; 155 struct stat sb; 156 | 140 g_gate_xlog("Can't get media size: %s.", 141 strerror(errno)); 142 } 143 } else if (S_ISREG(sb.st_mode)) { 144 mediasize = sb.st_size; 145 } else { 146 g_gate_xlog("Unsupported file system object."); 147 } 148 return (mediasize); 149} 150 151size_t 152g_gate_sectorsize(int fd) 153{ 154 size_t secsize; 155 struct stat sb; 156 |
157 if (fstat(fd, &sb) < 0) | 157 if (fstat(fd, &sb) == -1) |
158 g_gate_xlog("fstat(): %s.", strerror(errno)); 159 if (S_ISCHR(sb.st_mode)) { | 158 g_gate_xlog("fstat(): %s.", strerror(errno)); 159 if (S_ISCHR(sb.st_mode)) { |
160 if (ioctl(fd, DIOCGSECTORSIZE, &secsize) < 0) { | 160 if (ioctl(fd, DIOCGSECTORSIZE, &secsize) == -1) { |
161 g_gate_xlog("Can't get sector size: %s.", 162 strerror(errno)); 163 } 164 } else if (S_ISREG(sb.st_mode)) { 165 secsize = 512; 166 } else { 167 g_gate_xlog("Unsupported file system object."); 168 } 169 return (secsize); 170} 171 172void 173g_gate_open_device(void) 174{ 175 176 g_gate_devfd = open("/dev/" G_GATE_CTL_NAME, O_RDWR, 0); | 161 g_gate_xlog("Can't get sector size: %s.", 162 strerror(errno)); 163 } 164 } else if (S_ISREG(sb.st_mode)) { 165 secsize = 512; 166 } else { 167 g_gate_xlog("Unsupported file system object."); 168 } 169 return (secsize); 170} 171 172void 173g_gate_open_device(void) 174{ 175 176 g_gate_devfd = open("/dev/" G_GATE_CTL_NAME, O_RDWR, 0); |
177 if (g_gate_devfd < 0) | 177 if (g_gate_devfd == -1) |
178 err(EXIT_FAILURE, "open(/dev/%s)", G_GATE_CTL_NAME); 179} 180 181void 182g_gate_close_device(void) 183{ 184 185 close(g_gate_devfd); 186} 187 188void 189g_gate_ioctl(unsigned long req, void *data) 190{ 191 | 178 err(EXIT_FAILURE, "open(/dev/%s)", G_GATE_CTL_NAME); 179} 180 181void 182g_gate_close_device(void) 183{ 184 185 close(g_gate_devfd); 186} 187 188void 189g_gate_ioctl(unsigned long req, void *data) 190{ 191 |
192 if (ioctl(g_gate_devfd, req, data) < 0) { | 192 if (ioctl(g_gate_devfd, req, data) == -1) { |
193 g_gate_xlog("%s: ioctl(/dev/%s): %s.", getprogname(), 194 G_GATE_CTL_NAME, strerror(errno)); 195 } 196} 197 198void 199g_gate_destroy(int unit, int force) 200{ --- 15 unchanged lines hidden (view full) --- 216 return (O_WRONLY); 217 return (O_RDWR); 218} 219 220void 221g_gate_load_module(void) 222{ 223 | 193 g_gate_xlog("%s: ioctl(/dev/%s): %s.", getprogname(), 194 G_GATE_CTL_NAME, strerror(errno)); 195 } 196} 197 198void 199g_gate_destroy(int unit, int force) 200{ --- 15 unchanged lines hidden (view full) --- 216 return (O_WRONLY); 217 return (O_RDWR); 218} 219 220void 221g_gate_load_module(void) 222{ 223 |
224 if (modfind("g_gate") < 0) { | 224 if (modfind("g_gate") == -1) { |
225 /* Not present in kernel, try loading it. */ | 225 /* Not present in kernel, try loading it. */ |
226 if (kldload("geom_gate") < 0 || modfind("g_gate") < 0) { | 226 if (kldload("geom_gate") == -1 || modfind("g_gate") == -1) { |
227 if (errno != EEXIST) { 228 errx(EXIT_FAILURE, 229 "geom_gate module not available!"); 230 } 231 } 232 } 233} 234 --- 101 unchanged lines hidden --- | 227 if (errno != EEXIST) { 228 errx(EXIT_FAILURE, 229 "geom_gate module not available!"); 230 } 231 } 232 } 233} 234 --- 101 unchanged lines hidden --- |