Cross Reference: meta_stat.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
lvm
/
libmeta
/
common
/
meta_stat.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
N/A
/*
2
N/A
* CDDL HEADER START
2
N/A
*
2
N/A
* The contents of this file are subject to the terms of the
2
N/A
* Common Development and Distribution License, Version 1.0 only
2
N/A
* (the "License"). You may not use this file except in compliance
2
N/A
* with the License.
2
N/A
*
2
N/A
* You can obtain a copy of the license at
usr
/
src
/
OPENSOLARIS.LICENSE
2
N/A
* or
http://www.opensolaris.org/os/licensing
.
2
N/A
* See the License for the specific language governing permissions
2
N/A
* and limitations under the License.
2
N/A
*
2
N/A
* When distributing Covered Code, include this CDDL HEADER in each
2
N/A
* file and include the License file at
usr
/
src
/
OPENSOLARIS.LICENSE
.
2
N/A
* If applicable, add the following below this CDDL HEADER, with the
2
N/A
* fields enclosed by brackets "[]" replaced with your own identifying
2
N/A
* information: Portions Copyright [yyyy] [name of copyright owner]
2
N/A
*
2
N/A
* CDDL HEADER END
2
N/A
*/
2
N/A
2
N/A
/*
2
N/A
* Copyright (c) 1992, 1993, 1994, 2000 by Sun Microsystems, Inc.
2
N/A
* All rights reserved.
2
N/A
*/
2
N/A
2
N/A
#
pragma
ident
"%Z%%M% %I% %E% SMI"
2
N/A
2
N/A
/*
2
N/A
* Caching stat function
2
N/A
*/
2
N/A
2
N/A
#
include
<
meta.h
>
2
N/A
2
N/A
#
define
MD_NUM_STAT_HEAD
16
2
N/A
2
N/A
struct
statcache
{
2
N/A
struct
statcache
*
sc_next
;
2
N/A
struct
stat
sc_stat
;
2
N/A
char
*
sc_filename
;
2
N/A
};
2
N/A
2
N/A
static
struct
statcache
*
statcache_head
[
MD_NUM_STAT_HEAD
] =
2
N/A
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2
N/A
2
N/A
int
2
N/A
meta_stat
(
const
char
*
filename
,
struct
stat
*
sbp
)
2
N/A
{
2
N/A
struct
statcache
*
scp
;
2
N/A
int
hash
;
2
N/A
char
*
cp
;
2
N/A
2
N/A
hash
= 0;
2
N/A
for
(
cp
= (
char
*)
filename
; *
cp
!= 0;
cp
++)
2
N/A
hash
+= *
cp
;
2
N/A
2
N/A
hash
&=
0xf
;
2
N/A
2
N/A
for
(
scp
=
statcache_head
[
hash
];
scp
!=
NULL
;
scp
=
scp
->
sc_next
)
2
N/A
if
(
strcmp
(
filename
,
scp
->
sc_filename
) == 0)
2
N/A
break
;
2
N/A
if
(
scp
) {
2
N/A
(
void
)
memcpy
((
caddr_t
)
sbp
, (
caddr_t
)&
scp
->
sc_stat
,
2
N/A
sizeof
(*
sbp
));
2
N/A
return
(0);
2
N/A
}
2
N/A
if
(
stat
(
filename
,
sbp
) != 0)
2
N/A
return
(-
1
);
2
N/A
2
N/A
if
(!
S_ISBLK
(
sbp
->
st_mode
) && !
S_ISCHR
(
sbp
->
st_mode
))
2
N/A
return
(-
1
);
2
N/A
2
N/A
scp
= (
struct
statcache
*)
malloc
(
sizeof
(*
scp
));
2
N/A
if
(
scp
!=
NULL
) {
2
N/A
(
void
)
memcpy
((
caddr_t
)&
scp
->
sc_stat
, (
caddr_t
)
sbp
,
2
N/A
sizeof
(*
sbp
));
2
N/A
scp
->
sc_filename
=
strdup
(
filename
);
2
N/A
if
(
scp
->
sc_filename
==
NULL
) {
2
N/A
free
((
char
*)
scp
);
2
N/A
return
(0);
2
N/A
}
2
N/A
scp
->
sc_next
=
statcache_head
[
hash
];
2
N/A
statcache_head
[
hash
] =
scp
;
2
N/A
}
2
N/A
return
(0);
2
N/A
}
2
N/A
2
N/A
void
2
N/A
metaflushstatcache
(
void
)
2
N/A
{
2
N/A
struct
statcache
*p, *n;
2
N/A
int
i;
2
N/A
2
N/A
for
(i = 0; i <
MD_NUM_STAT_HEAD
; i++) {
2
N/A
for
(p =
statcache_head
[i], n =
NULL
; p !=
NULL
; p = n) {
2
N/A
n = p->
sc_next
;
2
N/A
Free
(p->
sc_filename
);
2
N/A
Free
(p);
2
N/A
}
2
N/A
statcache_head
[i] =
NULL
;
2
N/A
}
2
N/A
}