pseudofs_fileno.c (93818) | pseudofs_fileno.c (97940) |
---|---|
1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * | 1/*- 2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs_fileno.c 93818 2002-04-04 21:03:38Z jhb $ | 28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs_fileno.c 97940 2002-06-06 16:59:24Z des $ |
29 */ 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/lock.h> 35#include <sys/malloc.h> 36#include <sys/mutex.h> --- 38 unchanged lines hidden (view full) --- 75 76/* 77 * Initialize fileno bitmap 78 */ 79void 80pfs_fileno_init(struct pfs_info *pi) 81{ 82 struct pfs_bitmap *pb; | 29 */ 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/lock.h> 35#include <sys/malloc.h> 36#include <sys/mutex.h> --- 38 unchanged lines hidden (view full) --- 75 76/* 77 * Initialize fileno bitmap 78 */ 79void 80pfs_fileno_init(struct pfs_info *pi) 81{ 82 struct pfs_bitmap *pb; |
83 | 83 |
84 MALLOC(pb, struct pfs_bitmap *, sizeof *pb, 85 M_PFSFILENO, M_WAITOK|M_ZERO); 86 87 mtx_lock(&pi->pi_mutex); | 84 MALLOC(pb, struct pfs_bitmap *, sizeof *pb, 85 M_PFSFILENO, M_WAITOK|M_ZERO); 86 87 mtx_lock(&pi->pi_mutex); |
88 | 88 |
89 pb->pb_bitmap[0] = 07; 90 pb->pb_used = 3; 91 pi->pi_bitmap = pb; 92 pi->pi_root->pn_fileno = 2; 93 94 mtx_unlock(&pi->pi_mutex); 95} 96 97/* 98 * Tear down fileno bitmap 99 */ 100void 101pfs_fileno_uninit(struct pfs_info *pi) 102{ 103 struct pfs_bitmap *pb, *npb; 104 int used; | 89 pb->pb_bitmap[0] = 07; 90 pb->pb_used = 3; 91 pi->pi_bitmap = pb; 92 pi->pi_root->pn_fileno = 2; 93 94 mtx_unlock(&pi->pi_mutex); 95} 96 97/* 98 * Tear down fileno bitmap 99 */ 100void 101pfs_fileno_uninit(struct pfs_info *pi) 102{ 103 struct pfs_bitmap *pb, *npb; 104 int used; |
105 | 105 |
106 mtx_lock(&pi->pi_mutex); | 106 mtx_lock(&pi->pi_mutex); |
107 | 107 |
108 pb = pi->pi_bitmap; 109 pi->pi_bitmap = NULL; | 108 pb = pi->pi_bitmap; 109 pi->pi_bitmap = NULL; |
110 | 110 |
111 mtx_unlock(&pi->pi_mutex); 112 113 for (used = 0; pb; pb = npb) { 114 npb = pb->pb_next; 115 used += pb->pb_used; 116 FREE(pb, M_PFSFILENO); 117 } 118#if 0 --- 10 unchanged lines hidden (view full) --- 129pfs_get_fileno(struct pfs_info *pi) 130{ 131 struct pfs_bitmap *pb, *ppb; 132 u_int32_t fileno; 133 unsigned int *p; 134 int i; 135 136 mtx_lock(&pi->pi_mutex); | 111 mtx_unlock(&pi->pi_mutex); 112 113 for (used = 0; pb; pb = npb) { 114 npb = pb->pb_next; 115 used += pb->pb_used; 116 FREE(pb, M_PFSFILENO); 117 } 118#if 0 --- 10 unchanged lines hidden (view full) --- 129pfs_get_fileno(struct pfs_info *pi) 130{ 131 struct pfs_bitmap *pb, *ppb; 132 u_int32_t fileno; 133 unsigned int *p; 134 int i; 135 136 mtx_lock(&pi->pi_mutex); |
137 | 137 |
138 /* look for the first page with free bits */ 139 for (ppb = NULL, pb = pi->pi_bitmap; pb; ppb = pb, pb = pb->pb_next) 140 if (pb->pb_used != PFS_BITMAP_BITS) 141 break; 142 143 /* out of pages? */ 144 if (pb == NULL) { 145 mtx_unlock(&pi->pi_mutex); --- 6 unchanged lines hidden (view full) --- 152 pb->pb_offset = ppb->pb_offset + PFS_BITMAP_BITS; 153 ppb->pb_next = pb; 154 } 155 156 /* find the first free slot */ 157 for (i = 0; i < PFS_BITMAP_SIZE; ++i) 158 if (pb->pb_bitmap[i] != UINT_MAX) 159 break; | 138 /* look for the first page with free bits */ 139 for (ppb = NULL, pb = pi->pi_bitmap; pb; ppb = pb, pb = pb->pb_next) 140 if (pb->pb_used != PFS_BITMAP_BITS) 141 break; 142 143 /* out of pages? */ 144 if (pb == NULL) { 145 mtx_unlock(&pi->pi_mutex); --- 6 unchanged lines hidden (view full) --- 152 pb->pb_offset = ppb->pb_offset + PFS_BITMAP_BITS; 153 ppb->pb_next = pb; 154 } 155 156 /* find the first free slot */ 157 for (i = 0; i < PFS_BITMAP_SIZE; ++i) 158 if (pb->pb_bitmap[i] != UINT_MAX) 159 break; |
160 | 160 |
161 /* find the first available bit and flip it */ 162 fileno = pb->pb_offset + i * PFS_SLOT_BITS; 163 p = &pb->pb_bitmap[i]; 164 for (i = 0; i < PFS_SLOT_BITS; ++i, ++fileno) 165 if ((*p & (unsigned int)(1 << i)) == 0) 166 break; 167 KASSERT(i < PFS_SLOT_BITS, 168 ("slot has free bits, yet doesn't")); 169 *p |= (unsigned int)(1 << i); 170 ++pb->pb_used; | 161 /* find the first available bit and flip it */ 162 fileno = pb->pb_offset + i * PFS_SLOT_BITS; 163 p = &pb->pb_bitmap[i]; 164 for (i = 0; i < PFS_SLOT_BITS; ++i, ++fileno) 165 if ((*p & (unsigned int)(1 << i)) == 0) 166 break; 167 KASSERT(i < PFS_SLOT_BITS, 168 ("slot has free bits, yet doesn't")); 169 *p |= (unsigned int)(1 << i); 170 ++pb->pb_used; |
171 | 171 |
172 mtx_unlock(&pi->pi_mutex); | 172 mtx_unlock(&pi->pi_mutex); |
173 | 173 |
174 return fileno; 175} 176 177/* 178 * Free a file number 179 */ 180static void 181pfs_free_fileno(struct pfs_info *pi, u_int32_t fileno) 182{ 183 struct pfs_bitmap *pb; 184 unsigned int *p; 185 int i; 186 187 mtx_lock(&pi->pi_mutex); | 174 return fileno; 175} 176 177/* 178 * Free a file number 179 */ 180static void 181pfs_free_fileno(struct pfs_info *pi, u_int32_t fileno) 182{ 183 struct pfs_bitmap *pb; 184 unsigned int *p; 185 int i; 186 187 mtx_lock(&pi->pi_mutex); |
188 | 188 |
189 /* find the right page */ 190 for (pb = pi->pi_bitmap; 191 pb && fileno >= PFS_BITMAP_BITS; 192 pb = pb->pb_next, fileno -= PFS_BITMAP_BITS) 193 /* nothing */ ; 194 KASSERT(pb, 195 ("fileno isn't in any bitmap")); 196 --- 13 unchanged lines hidden (view full) --- 210 * Allocate a file number 211 */ 212void 213pfs_fileno_alloc(struct pfs_info *pi, struct pfs_node *pn) 214{ 215 /* make sure our parent has a file number */ 216 if (pn->pn_parent && !pn->pn_parent->pn_fileno) 217 pfs_fileno_alloc(pi, pn->pn_parent); | 189 /* find the right page */ 190 for (pb = pi->pi_bitmap; 191 pb && fileno >= PFS_BITMAP_BITS; 192 pb = pb->pb_next, fileno -= PFS_BITMAP_BITS) 193 /* nothing */ ; 194 KASSERT(pb, 195 ("fileno isn't in any bitmap")); 196 --- 13 unchanged lines hidden (view full) --- 210 * Allocate a file number 211 */ 212void 213pfs_fileno_alloc(struct pfs_info *pi, struct pfs_node *pn) 214{ 215 /* make sure our parent has a file number */ 216 if (pn->pn_parent && !pn->pn_parent->pn_fileno) 217 pfs_fileno_alloc(pi, pn->pn_parent); |
218 | 218 |
219 switch (pn->pn_type) { 220 case pfstype_root: 221 case pfstype_dir: 222 case pfstype_file: 223 case pfstype_symlink: 224 case pfstype_procdir: 225 pn->pn_fileno = pfs_get_fileno(pi); 226 break; --- 12 unchanged lines hidden (view full) --- 239 KASSERT(pn->pn_parent->pn_parent != NULL, 240 ("pfstype_parent node has no grandparent")); 241 pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno; 242 break; 243 case pfstype_none: 244 KASSERT(0, 245 ("pfs_fileno_alloc() called for pfstype_none node")); 246 break; | 219 switch (pn->pn_type) { 220 case pfstype_root: 221 case pfstype_dir: 222 case pfstype_file: 223 case pfstype_symlink: 224 case pfstype_procdir: 225 pn->pn_fileno = pfs_get_fileno(pi); 226 break; --- 12 unchanged lines hidden (view full) --- 239 KASSERT(pn->pn_parent->pn_parent != NULL, 240 ("pfstype_parent node has no grandparent")); 241 pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno; 242 break; 243 case pfstype_none: 244 KASSERT(0, 245 ("pfs_fileno_alloc() called for pfstype_none node")); 246 break; |
247 } | 247 } |
248 249#if 0 250 printf("pfs_fileno_alloc(): %s: ", pi->pi_name); 251 if (pn->pn_parent) { 252 if (pn->pn_parent->pn_parent) { 253 printf("%s/", pn->pn_parent->pn_parent->pn_name); 254 } 255 printf("%s/", pn->pn_parent->pn_name); --- 29 unchanged lines hidden --- | 248 249#if 0 250 printf("pfs_fileno_alloc(): %s: ", pi->pi_name); 251 if (pn->pn_parent) { 252 if (pn->pn_parent->pn_parent) { 253 printf("%s/", pn->pn_parent->pn_parent->pn_name); 254 } 255 printf("%s/", pn->pn_parent->pn_name); --- 29 unchanged lines hidden --- |