| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: lfs_cleanerd.c,v 1.22 2009/10/09 16:35:17 pooka Exp $ */ | | 1 | /* $NetBSD: lfs_cleanerd.c,v 1.23 2010/02/16 23:13:13 mlelstv Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2005 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2005 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Konrad E. Schroder <perseant@hhhh.org>. | | 8 | * by Konrad E. Schroder <perseant@hhhh.org>. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -193,26 +193,27 @@ init_unmounted_fs(struct clfs *fs, char | | | @@ -193,26 +193,27 @@ init_unmounted_fs(struct clfs *fs, char |
193 | * If we can't get the Ifile, this is not an LFS (or the kernel is | | 193 | * If we can't get the Ifile, this is not an LFS (or the kernel is |
194 | * too old to support the fcntl). | | 194 | * too old to support the fcntl). |
195 | * XXX Merge this and init_unmounted_fs, switching on whether | | 195 | * XXX Merge this and init_unmounted_fs, switching on whether |
196 | * XXX "fsname" is a dir or a char special device. Should | | 196 | * XXX "fsname" is a dir or a char special device. Should |
197 | * XXX also be able to read unmounted devices out of fstab, the way | | 197 | * XXX also be able to read unmounted devices out of fstab, the way |
198 | * XXX fsck does. | | 198 | * XXX fsck does. |
199 | */ | | 199 | */ |
200 | int | | 200 | int |
201 | init_fs(struct clfs *fs, char *fsname) | | 201 | init_fs(struct clfs *fs, char *fsname) |
202 | { | | 202 | { |
203 | struct statvfs sf; | | 203 | struct statvfs sf; |
204 | int rootfd; | | 204 | int rootfd; |
205 | int i; | | 205 | int i; |
| | | 206 | void *sbuf; |
206 | | | 207 | |
207 | /* | | 208 | /* |
208 | * Get the raw device from the block device. | | 209 | * Get the raw device from the block device. |
209 | * XXX this is ugly. Is there a way to discover the raw device | | 210 | * XXX this is ugly. Is there a way to discover the raw device |
210 | * XXX for a given mount point? | | 211 | * XXX for a given mount point? |
211 | */ | | 212 | */ |
212 | if (kops.ko_statvfs(fsname, &sf, ST_WAIT) < 0) | | 213 | if (kops.ko_statvfs(fsname, &sf, ST_WAIT) < 0) |
213 | return -1; | | 214 | return -1; |
214 | fs->clfs_dev = malloc(strlen(sf.f_mntfromname) + 2); | | 215 | fs->clfs_dev = malloc(strlen(sf.f_mntfromname) + 2); |
215 | if (fs->clfs_dev == NULL) { | | 216 | if (fs->clfs_dev == NULL) { |
216 | syslog(LOG_ERR, "couldn't malloc device name string: %m"); | | 217 | syslog(LOG_ERR, "couldn't malloc device name string: %m"); |
217 | return -1; | | 218 | return -1; |
218 | } | | 219 | } |
| @@ -223,30 +224,40 @@ init_fs(struct clfs *fs, char *fsname) | | | @@ -223,30 +224,40 @@ init_fs(struct clfs *fs, char *fsname) |
223 | return -1; | | 224 | return -1; |
224 | } | | 225 | } |
225 | | | 226 | |
226 | /* Find the Ifile and open it */ | | 227 | /* Find the Ifile and open it */ |
227 | if ((rootfd = kops.ko_open(fsname, O_RDONLY, 0)) < 0) | | 228 | if ((rootfd = kops.ko_open(fsname, O_RDONLY, 0)) < 0) |
228 | return -2; | | 229 | return -2; |
229 | if (kops.ko_fcntl(rootfd, LFCNIFILEFH, &fs->clfs_ifilefh) < 0) | | 230 | if (kops.ko_fcntl(rootfd, LFCNIFILEFH, &fs->clfs_ifilefh) < 0) |
230 | return -3; | | 231 | return -3; |
231 | if ((fs->clfs_ifilefd = kops.ko_fhopen(&fs->clfs_ifilefh, | | 232 | if ((fs->clfs_ifilefd = kops.ko_fhopen(&fs->clfs_ifilefh, |
232 | sizeof(fs->clfs_ifilefh), O_RDONLY)) < 0) | | 233 | sizeof(fs->clfs_ifilefh), O_RDONLY)) < 0) |
233 | return -4; | | 234 | return -4; |
234 | kops.ko_close(rootfd); | | 235 | kops.ko_close(rootfd); |
235 | | | 236 | |
| | | 237 | sbuf = malloc(LFS_SBPAD); |
| | | 238 | if (sbuf == NULL) { |
| | | 239 | syslog(LOG_ERR, "couldn't malloc superblock buffer"); |
| | | 240 | return -1; |
| | | 241 | } |
| | | 242 | |
236 | /* Load in the superblock */ | | 243 | /* Load in the superblock */ |
237 | if (kops.ko_pread(fs->clfs_devfd, &(fs->lfs_dlfs), sizeof(struct dlfs), | | 244 | if (kops.ko_pread(fs->clfs_devfd, sbuf, LFS_SBPAD, LFS_LABELPAD) < 0) { |
238 | LFS_LABELPAD) < 0) | | 245 | free(sbuf); |
239 | return -1; | | 246 | return -1; |
| | | 247 | } |
| | | 248 | |
| | | 249 | memcpy(&(fs->lfs_dlfs), sbuf, sizeof(struct dlfs)); |
| | | 250 | free(sbuf); |
240 | | | 251 | |
241 | /* If this is not a version 2 filesystem, complain and exit */ | | 252 | /* If this is not a version 2 filesystem, complain and exit */ |
242 | if (fs->lfs_version != 2) { | | 253 | if (fs->lfs_version != 2) { |
243 | syslog(LOG_ERR, "%s: not a version 2 LFS", fsname); | | 254 | syslog(LOG_ERR, "%s: not a version 2 LFS", fsname); |
244 | return -1; | | 255 | return -1; |
245 | } | | 256 | } |
246 | | | 257 | |
247 | /* Assume fsname is the mounted name */ | | 258 | /* Assume fsname is the mounted name */ |
248 | strncpy((char *)fs->lfs_fsmnt, fsname, MNAMELEN); | | 259 | strncpy((char *)fs->lfs_fsmnt, fsname, MNAMELEN); |
249 | | | 260 | |
250 | /* Set up vnodes for Ifile and raw device */ | | 261 | /* Set up vnodes for Ifile and raw device */ |
251 | fs->lfs_ivnode = fd_vget(fs->clfs_ifilefd, fs->lfs_bsize, 0, 0); | | 262 | fs->lfs_ivnode = fd_vget(fs->clfs_ifilefd, fs->lfs_bsize, 0, 0); |
252 | fs->clfs_devvp = fd_vget(fs->clfs_devfd, fs->lfs_fsize, fs->lfs_ssize, | | 263 | fs->clfs_devvp = fd_vget(fs->clfs_devfd, fs->lfs_fsize, fs->lfs_ssize, |