root / lab4 / .minix-src / include / sys / extent.h @ 13
History | View | Annotate | Download (4.46 KB)
1 | 13 | up20180614 | /* $NetBSD: extent.h,v 1.19 2012/01/27 18:53:10 para Exp $ */
|
---|---|---|---|
2 | |||
3 | /*-
|
||
4 | * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
|
||
5 | * All rights reserved.
|
||
6 | *
|
||
7 | * This code is derived from software contributed to The NetBSD Foundation
|
||
8 | * by Jason R. Thorpe.
|
||
9 | *
|
||
10 | * Redistribution and use in source and binary forms, with or without
|
||
11 | * modification, are permitted provided that the following conditions
|
||
12 | * are met:
|
||
13 | * 1. Redistributions of source code must retain the above copyright
|
||
14 | * notice, this list of conditions and the following disclaimer.
|
||
15 | * 2. Redistributions in binary form must reproduce the above copyright
|
||
16 | * notice, this list of conditions and the following disclaimer in the
|
||
17 | * documentation and/or other materials provided with the distribution.
|
||
18 | *
|
||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||
29 | * POSSIBILITY OF SUCH DAMAGE.
|
||
30 | */
|
||
31 | |||
32 | #ifndef _SYS_EXTENT_H_
|
||
33 | #define _SYS_EXTENT_H_
|
||
34 | |||
35 | #include <sys/queue.h> |
||
36 | #include <sys/mutex.h> |
||
37 | #include <sys/condvar.h> |
||
38 | |||
39 | struct extent_region {
|
||
40 | LIST_ENTRY(extent_region) er_link; /* link in region list */
|
||
41 | u_long er_start; /* start of region */
|
||
42 | u_long er_end; /* end of region */
|
||
43 | int er_flags; /* misc. flags */ |
||
44 | }; |
||
45 | |||
46 | /* er_flags */
|
||
47 | #define ER_ALLOC 0x01 /* region descriptor dynamically allocated */ |
||
48 | |||
49 | struct extent {
|
||
50 | const char *ex_name; /* name of extent */ |
||
51 | kmutex_t ex_lock; /* lock on this extent */
|
||
52 | kcondvar_t ex_cv; /* synchronization */
|
||
53 | /* allocated regions in extent */
|
||
54 | LIST_HEAD(, extent_region) ex_regions; |
||
55 | u_long ex_start; /* start of extent */
|
||
56 | u_long ex_end; /* end of extent */
|
||
57 | int ex_flags; /* misc. information */ |
||
58 | }; |
||
59 | |||
60 | struct extent_fixed {
|
||
61 | struct extent fex_extent; /* MUST BE FIRST */ |
||
62 | /* freelist of region descriptors */
|
||
63 | LIST_HEAD(, extent_region) fex_freelist; |
||
64 | void * fex_storage; /* storage space for descriptors */ |
||
65 | size_t fex_storagesize; /* size of storage space */
|
||
66 | }; |
||
67 | |||
68 | /* ex_flags; for internal use only */
|
||
69 | #define EXF_FIXED 0x01 /* extent uses fixed storage */ |
||
70 | #define EXF_NOCOALESCE 0x02 /* coalescing of regions not allowed */ |
||
71 | #define EXF_FLWANTED 0x08 /* someone asleep on freelist */ |
||
72 | |||
73 | #define EXF_BITS "\20\4FLWANTED\2NOCOALESCE\1FIXED" |
||
74 | |||
75 | /* misc. flags passed to extent functions */
|
||
76 | #define EX_NOWAIT 0x00 /* not safe to sleep */ |
||
77 | #define EX_WAITOK 0x01 /* safe to sleep */ |
||
78 | #define EX_FAST 0x02 /* take first fit in extent_alloc() */ |
||
79 | #define EX_CATCH 0x04 /* catch signals while sleeping */ |
||
80 | #define EX_NOCOALESCE 0x08 /* create a non-coalescing extent */ |
||
81 | #define EX_MALLOCOK 0x10 /* safe to call kmem_alloc() */ |
||
82 | #define EX_WAITSPACE 0x20 /* wait for space to become free */ |
||
83 | #define EX_BOUNDZERO 0x40 /* boundary lines start at 0 */ |
||
84 | |||
85 | /*
|
||
86 | * Special place holders for "alignment" and "boundary" arguments,
|
||
87 | * in the event the caller doesn't wish to use those features.
|
||
88 | */
|
||
89 | #define EX_NOALIGN 1 /* don't do alignment */ |
||
90 | #define EX_NOBOUNDARY 0 /* don't do boundary checking */ |
||
91 | |||
92 | #if defined(_KERNEL) || defined(_EXTENT_TESTING)
|
||
93 | #define EXTENT_FIXED_STORAGE_SIZE(_nregions) \
|
||
94 | (ALIGN(sizeof(struct extent_fixed)) + \ |
||
95 | ((ALIGN(sizeof(struct extent_region))) * \ |
||
96 | (_nregions))) |
||
97 | |||
98 | struct extent *extent_create(const char *, u_long, u_long, |
||
99 | void *, size_t, int); |
||
100 | void extent_destroy(struct extent *); |
||
101 | int extent_alloc_subregion1(struct extent *, u_long, u_long, |
||
102 | u_long, u_long, u_long, u_long, int, u_long *);
|
||
103 | int extent_alloc_subregion(struct extent *, u_long, u_long, |
||
104 | u_long, u_long, u_long, int, u_long *);
|
||
105 | int extent_alloc_region(struct extent *, u_long, u_long, int); |
||
106 | int extent_alloc1(struct extent *, u_long, u_long, u_long, u_long, int, |
||
107 | u_long *); |
||
108 | int extent_alloc(struct extent *, u_long, u_long, u_long, int, u_long *); |
||
109 | int extent_free(struct extent *, u_long, u_long, int); |
||
110 | void extent_print(struct extent *); |
||
111 | void extent_init(void); |
||
112 | |||
113 | #endif /* _KERNEL || _EXTENT_TESTING */ |
||
114 | |||
115 | #endif /* ! _SYS_EXTENT_H_ */ |