Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
libcore
Commits
721ceca2
Commit
721ceca2
authored
11 years ago
by
Elliott Hughes
Browse files
Options
Download
Email Patches
Plain Diff
Switch libcore from statfs to statvfs.
Change-Id: I5115b9203ce6b11c37c0eb41fbc84fa5962ce196
parent
210b16cc
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
101 deletions
+110
-101
luni/src/main/java/java/io/File.java
luni/src/main/java/java/io/File.java
+4
-4
luni/src/main/java/libcore/io/ForwardingOs.java
luni/src/main/java/libcore/io/ForwardingOs.java
+2
-2
luni/src/main/java/libcore/io/Os.java
luni/src/main/java/libcore/io/Os.java
+2
-3
luni/src/main/java/libcore/io/Posix.java
luni/src/main/java/libcore/io/Posix.java
+2
-2
luni/src/main/java/libcore/io/StructStatFs.java
luni/src/main/java/libcore/io/StructStatFs.java
+0
-61
luni/src/main/java/libcore/io/StructStatVfs.java
luni/src/main/java/libcore/io/StructStatVfs.java
+71
-0
luni/src/main/native/Portability.h
luni/src/main/native/Portability.h
+1
-3
luni/src/main/native/libcore_io_Posix.cpp
luni/src/main/native/libcore_io_Posix.cpp
+28
-26
No files found.
luni/src/main/java/java/io/File.java
View file @
721ceca2
...
...
@@ -27,7 +27,7 @@ import libcore.io.ErrnoException;
import
libcore.io.IoUtils
;
import
libcore.io.Libcore
;
import
libcore.io.StructStat
;
import
libcore.io.StructStat
F
s
;
import
libcore.io.StructStat
Vf
s
;
import
org.apache.harmony.luni.util.DeleteOnExit
;
import
static
libcore
.
io
.
OsConstants
.*;
...
...
@@ -1130,7 +1130,7 @@ public class File implements Serializable, Comparable<File> {
*/
public
long
getTotalSpace
()
{
try
{
StructStat
F
s
sb
=
Libcore
.
os
.
statfs
(
path
);
StructStat
Vf
s
sb
=
Libcore
.
os
.
stat
v
fs
(
path
);
return
sb
.
f_blocks
*
sb
.
f_bsize
;
// total block count * block size in bytes.
}
catch
(
ErrnoException
errnoException
)
{
return
0
;
...
...
@@ -1152,7 +1152,7 @@ public class File implements Serializable, Comparable<File> {
*/
public
long
getUsableSpace
()
{
try
{
StructStat
F
s
sb
=
Libcore
.
os
.
statfs
(
path
);
StructStat
Vf
s
sb
=
Libcore
.
os
.
stat
v
fs
(
path
);
return
sb
.
f_bavail
*
sb
.
f_bsize
;
// non-root free block count * block size in bytes.
}
catch
(
ErrnoException
errnoException
)
{
return
0
;
...
...
@@ -1170,7 +1170,7 @@ public class File implements Serializable, Comparable<File> {
*/
public
long
getFreeSpace
()
{
try
{
StructStat
F
s
sb
=
Libcore
.
os
.
statfs
(
path
);
StructStat
Vf
s
sb
=
Libcore
.
os
.
stat
v
fs
(
path
);
return
sb
.
f_bfree
*
sb
.
f_bsize
;
// free block count * block size in bytes.
}
catch
(
ErrnoException
errnoException
)
{
return
0
;
...
...
This diff is collapsed.
Click to expand it.
luni/src/main/java/libcore/io/ForwardingOs.java
View file @
721ceca2
...
...
@@ -54,7 +54,7 @@ public class ForwardingOs implements Os {
public
int
fcntlFlock
(
FileDescriptor
fd
,
int
cmd
,
StructFlock
arg
)
throws
ErrnoException
{
return
os
.
fcntlFlock
(
fd
,
cmd
,
arg
);
}
public
void
fdatasync
(
FileDescriptor
fd
)
throws
ErrnoException
{
os
.
fdatasync
(
fd
);
}
public
StructStat
fstat
(
FileDescriptor
fd
)
throws
ErrnoException
{
return
os
.
fstat
(
fd
);
}
public
StructStat
F
s
fstatfs
(
FileDescriptor
fd
)
throws
ErrnoException
{
return
os
.
fstatfs
(
fd
);
}
public
StructStat
Vf
s
fstat
v
fs
(
FileDescriptor
fd
)
throws
ErrnoException
{
return
os
.
fstat
v
fs
(
fd
);
}
public
void
fsync
(
FileDescriptor
fd
)
throws
ErrnoException
{
os
.
fsync
(
fd
);
}
public
void
ftruncate
(
FileDescriptor
fd
,
long
length
)
throws
ErrnoException
{
os
.
ftruncate
(
fd
,
length
);
}
public
String
gai_strerror
(
int
error
)
{
return
os
.
gai_strerror
(
error
);
}
...
...
@@ -128,7 +128,7 @@ public class ForwardingOs implements Os {
public
FileDescriptor
socket
(
int
domain
,
int
type
,
int
protocol
)
throws
ErrnoException
{
return
os
.
socket
(
domain
,
type
,
protocol
);
}
public
void
socketpair
(
int
domain
,
int
type
,
int
protocol
,
FileDescriptor
fd1
,
FileDescriptor
fd2
)
throws
ErrnoException
{
os
.
socketpair
(
domain
,
type
,
protocol
,
fd1
,
fd2
);
}
public
StructStat
stat
(
String
path
)
throws
ErrnoException
{
return
os
.
stat
(
path
);
}
public
StructStat
F
s
statfs
(
String
path
)
throws
ErrnoException
{
return
os
.
statfs
(
path
);
}
public
StructStat
Vf
s
stat
v
fs
(
String
path
)
throws
ErrnoException
{
return
os
.
stat
v
fs
(
path
);
}
public
String
strerror
(
int
errno
)
{
return
os
.
strerror
(
errno
);
}
public
String
strsignal
(
int
signal
)
{
return
os
.
strsignal
(
signal
);
}
public
void
symlink
(
String
oldPath
,
String
newPath
)
throws
ErrnoException
{
os
.
symlink
(
oldPath
,
newPath
);
}
...
...
This diff is collapsed.
Click to expand it.
luni/src/main/java/libcore/io/Os.java
View file @
721ceca2
...
...
@@ -45,7 +45,7 @@ public interface Os {
public
int
fcntlFlock
(
FileDescriptor
fd
,
int
cmd
,
StructFlock
arg
)
throws
ErrnoException
;
public
void
fdatasync
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
StructStat
fstat
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
StructStat
F
s
fstatfs
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
StructStat
Vf
s
fstat
v
fs
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
void
fsync
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
void
ftruncate
(
FileDescriptor
fd
,
long
length
)
throws
ErrnoException
;
public
String
gai_strerror
(
int
error
);
...
...
@@ -121,8 +121,7 @@ public interface Os {
public
FileDescriptor
socket
(
int
domain
,
int
type
,
int
protocol
)
throws
ErrnoException
;
public
void
socketpair
(
int
domain
,
int
type
,
int
protocol
,
FileDescriptor
fd1
,
FileDescriptor
fd2
)
throws
ErrnoException
;
public
StructStat
stat
(
String
path
)
throws
ErrnoException
;
/* TODO: replace statfs with statvfs. */
public
StructStatFs
statfs
(
String
path
)
throws
ErrnoException
;
public
StructStatVfs
statvfs
(
String
path
)
throws
ErrnoException
;
public
String
strerror
(
int
errno
);
public
String
strsignal
(
int
signal
);
public
void
symlink
(
String
oldPath
,
String
newPath
)
throws
ErrnoException
;
...
...
This diff is collapsed.
Click to expand it.
luni/src/main/java/libcore/io/Posix.java
View file @
721ceca2
...
...
@@ -48,7 +48,7 @@ public final class Posix implements Os {
public
native
int
fcntlFlock
(
FileDescriptor
fd
,
int
cmd
,
StructFlock
arg
)
throws
ErrnoException
;
public
native
void
fdatasync
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
native
StructStat
fstat
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
native
StructStat
F
s
fstatfs
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
native
StructStat
Vf
s
fstat
v
fs
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
native
void
fsync
(
FileDescriptor
fd
)
throws
ErrnoException
;
public
native
void
ftruncate
(
FileDescriptor
fd
,
long
length
)
throws
ErrnoException
;
public
native
String
gai_strerror
(
int
error
);
...
...
@@ -172,7 +172,7 @@ public final class Posix implements Os {
public
native
FileDescriptor
socket
(
int
domain
,
int
type
,
int
protocol
)
throws
ErrnoException
;
public
native
void
socketpair
(
int
domain
,
int
type
,
int
protocol
,
FileDescriptor
fd1
,
FileDescriptor
fd2
)
throws
ErrnoException
;
public
native
StructStat
stat
(
String
path
)
throws
ErrnoException
;
public
native
StructStat
F
s
statfs
(
String
path
)
throws
ErrnoException
;
public
native
StructStat
Vf
s
stat
v
fs
(
String
path
)
throws
ErrnoException
;
public
native
String
strerror
(
int
errno
);
public
native
String
strsignal
(
int
signal
);
public
native
void
symlink
(
String
oldPath
,
String
newPath
)
throws
ErrnoException
;
...
...
This diff is collapsed.
Click to expand it.
luni/src/main/java/libcore/io/StructStatFs.java
deleted
100644 → 0
View file @
210b16cc
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
libcore.io
;
/**
* File information returned by fstatfs(2) and statfs(2).
*
* TODO: this should be {@code struct statvfs}, but Bionic doesn't support that yet.
* @hide until the TODO is fixed.
*/
public
final
class
StructStatFs
{
/** File system block size (used for block counts). */
public
final
long
f_bsize
;
/*unsigned long*/
/** Total block count. */
public
final
long
f_blocks
;
/*fsblkcnt_t*/
/** Free block count. */
public
final
long
f_bfree
;
/*fsblkcnt_t*/
/** Free block count available to non-root. */
public
final
long
f_bavail
;
/*fsblkcnt_t*/
/** Total file (inode) count. */
public
final
long
f_files
;
/*fsfilcnt_t*/
/** Free file (inode) count. */
public
final
long
f_ffree
;
/*fsfilcnt_t*/
/** Maximum filename length. */
public
final
long
f_namemax
;
/*unsigned long*/
/** Fundamental file system block size. */
public
final
long
f_frsize
;
/*unsigned long*/
StructStatFs
(
long
f_bsize
,
long
f_blocks
,
long
f_bfree
,
long
f_bavail
,
long
f_files
,
long
f_ffree
,
long
f_namemax
,
long
f_frsize
)
{
this
.
f_bsize
=
f_bsize
;
this
.
f_blocks
=
f_blocks
;
this
.
f_bfree
=
f_bfree
;
this
.
f_bavail
=
f_bavail
;
this
.
f_files
=
f_files
;
this
.
f_ffree
=
f_ffree
;
this
.
f_namemax
=
f_namemax
;
this
.
f_frsize
=
f_frsize
;
}
}
This diff is collapsed.
Click to expand it.
luni/src/main/java/libcore/io/StructStatVfs.java
0 → 100644
View file @
721ceca2
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
libcore.io
;
/**
* File information returned by fstatvfs(2) and statvfs(2).
*/
public
final
class
StructStatVfs
{
/** File system block size (used for block counts). */
public
final
long
f_bsize
;
/*unsigned long*/
/** Fundamental file system block size. */
public
final
long
f_frsize
;
/*unsigned long*/
/** Total block count. */
public
final
long
f_blocks
;
/*fsblkcnt_t*/
/** Free block count. */
public
final
long
f_bfree
;
/*fsblkcnt_t*/
/** Free block count available to non-root. */
public
final
long
f_bavail
;
/*fsblkcnt_t*/
/** Total file (inode) count. */
public
final
long
f_files
;
/*fsfilcnt_t*/
/** Free file (inode) count. */
public
final
long
f_ffree
;
/*fsfilcnt_t*/
/** Free file (inode) count available to non-root. */
public
final
long
f_favail
;
/*fsfilcnt_t*/
/** File system id. */
public
final
long
f_fsid
;
/*unsigned long*/
/** Bit mask of ST_* flags. */
public
final
long
f_flag
;
/*unsigned long*/
/** Maximum filename length. */
public
final
long
f_namemax
;
/*unsigned long*/
StructStatVfs
(
long
f_bsize
,
long
f_frsize
,
long
f_blocks
,
long
f_bfree
,
long
f_bavail
,
long
f_files
,
long
f_ffree
,
long
f_favail
,
long
f_fsid
,
long
f_flag
,
long
f_namemax
)
{
this
.
f_bsize
=
f_bsize
;
this
.
f_frsize
=
f_frsize
;
this
.
f_blocks
=
f_blocks
;
this
.
f_bfree
=
f_bfree
;
this
.
f_bavail
=
f_bavail
;
this
.
f_files
=
f_files
;
this
.
f_ffree
=
f_ffree
;
this
.
f_favail
=
f_favail
;
this
.
f_fsid
=
f_fsid
;
this
.
f_flag
=
f_flag
;
this
.
f_namemax
=
f_namemax
;
}
}
This diff is collapsed.
Click to expand it.
luni/src/main/native/Portability.h
View file @
721ceca2
...
...
@@ -72,9 +72,7 @@ static inline int mincore(void* addr, size_t length, unsigned char* vec) {
#include <byteswap.h>
#include <sys/sendfile.h>
// For statfs(3).
#include <sys/vfs.h> // Bionic doesn't have <sys/statvfs.h>
#include <sys/statvfs.h>
#endif
...
...
This diff is collapsed.
Click to expand it.
luni/src/main/native/libcore_io_Posix.cpp
View file @
721ceca2
...
...
@@ -246,26 +246,28 @@ static jobject makeStructStat(JNIEnv* env, const struct stat& sb) {
static_cast
<
jlong
>
(
sb
.
st_blocks
));
}
static
jobject
makeStructStat
F
s
(
JNIEnv
*
env
,
const
struct
statfs
&
sb
)
{
static
jobject
makeStructStat
Vf
s
(
JNIEnv
*
env
,
const
struct
stat
v
fs
&
sb
)
{
#if defined(__APPLE__)
// Mac OS has no f_namelen field in struct statfs.
jlong
max_name_length
=
255
;
// __DARWIN_MAXNAMLEN
#else
// Until Mac OS 10.7, these were 32-bit fields.
STATIC_ASSERT
(
sizeof
(
sb
.
f_bavail
)
==
sizeof
(
jlong
),
statfs_not_64_bit
);
STATIC_ASSERT
(
sizeof
(
sb
.
f_bfree
)
==
sizeof
(
jlong
),
statfs_not_64_bit
);
STATIC_ASSERT
(
sizeof
(
sb
.
f_blocks
)
==
sizeof
(
jlong
),
statfs_not_64_bit
);
jlong
max_name_length
=
static_cast
<
jlong
>
(
sb
.
f_namelen
);
jlong
max_name_length
=
static_cast
<
jlong
>
(
sb
.
f_namemax
);
#endif
static
jmethodID
ctor
=
env
->
GetMethodID
(
JniConstants
::
structStatFsClass
,
"<init>"
,
"(JJJJJJJJ)V"
);
return
env
->
NewObject
(
JniConstants
::
structStatFsClass
,
ctor
,
static_cast
<
jlong
>
(
sb
.
f_bsize
),
static_cast
<
jlong
>
(
sb
.
f_blocks
),
static_cast
<
jlong
>
(
sb
.
f_bfree
),
static_cast
<
jlong
>
(
sb
.
f_bavail
),
static_cast
<
jlong
>
(
sb
.
f_files
),
static_cast
<
jlong
>
(
sb
.
f_ffree
),
max_name_length
,
static_cast
<
jlong
>
(
sb
.
f_frsize
));
static
jmethodID
ctor
=
env
->
GetMethodID
(
JniConstants
::
structStatVfsClass
,
"<init>"
,
"(JJJJJJJJJJJ)V"
);
return
env
->
NewObject
(
JniConstants
::
structStatVfsClass
,
ctor
,
static_cast
<
jlong
>
(
sb
.
f_bsize
),
static_cast
<
jlong
>
(
sb
.
f_frsize
),
static_cast
<
jlong
>
(
sb
.
f_blocks
),
static_cast
<
jlong
>
(
sb
.
f_bfree
),
static_cast
<
jlong
>
(
sb
.
f_bavail
),
static_cast
<
jlong
>
(
sb
.
f_files
),
static_cast
<
jlong
>
(
sb
.
f_ffree
),
static_cast
<
jlong
>
(
sb
.
f_favail
),
static_cast
<
jlong
>
(
sb
.
f_fsid
),
static_cast
<
jlong
>
(
sb
.
f_flag
),
max_name_length
);
}
static
jobject
makeStructLinger
(
JNIEnv
*
env
,
const
struct
linger
&
l
)
{
...
...
@@ -571,15 +573,15 @@ static jobject Posix_fstat(JNIEnv* env, jobject, jobject javaFd) {
return
makeStructStat
(
env
,
sb
);
}
static
jobject
Posix_fstatfs
(
JNIEnv
*
env
,
jobject
,
jobject
javaFd
)
{
static
jobject
Posix_fstat
v
fs
(
JNIEnv
*
env
,
jobject
,
jobject
javaFd
)
{
int
fd
=
jniGetFDFromFileDescriptor
(
env
,
javaFd
);
struct
statfs
sb
;
int
rc
=
TEMP_FAILURE_RETRY
(
fstatfs
(
fd
,
&
sb
));
struct
stat
v
fs
sb
;
int
rc
=
TEMP_FAILURE_RETRY
(
fstat
v
fs
(
fd
,
&
sb
));
if
(
rc
==
-
1
)
{
throwErrnoException
(
env
,
"fstatfs"
);
throwErrnoException
(
env
,
"fstat
v
fs"
);
return
NULL
;
}
return
makeStructStat
F
s
(
env
,
sb
);
return
makeStructStat
Vf
s
(
env
,
sb
);
}
static
void
Posix_fsync
(
JNIEnv
*
env
,
jobject
,
jobject
javaFd
)
{
...
...
@@ -1253,18 +1255,18 @@ static jobject Posix_stat(JNIEnv* env, jobject, jstring javaPath) {
return
doStat
(
env
,
javaPath
,
false
);
}
static
jobject
Posix_statfs
(
JNIEnv
*
env
,
jobject
,
jstring
javaPath
)
{
static
jobject
Posix_stat
v
fs
(
JNIEnv
*
env
,
jobject
,
jstring
javaPath
)
{
ScopedUtfChars
path
(
env
,
javaPath
);
if
(
path
.
c_str
()
==
NULL
)
{
return
NULL
;
}
struct
statfs
sb
;
int
rc
=
TEMP_FAILURE_RETRY
(
statfs
(
path
.
c_str
(),
&
sb
));
struct
stat
v
fs
sb
;
int
rc
=
TEMP_FAILURE_RETRY
(
stat
v
fs
(
path
.
c_str
(),
&
sb
));
if
(
rc
==
-
1
)
{
throwErrnoException
(
env
,
"statfs"
);
throwErrnoException
(
env
,
"stat
v
fs"
);
return
NULL
;
}
return
makeStructStat
F
s
(
env
,
sb
);
return
makeStructStat
Vf
s
(
env
,
sb
);
}
static
jstring
Posix_strerror
(
JNIEnv
*
env
,
jobject
,
jint
errnum
)
{
...
...
@@ -1377,7 +1379,7 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD
(
Posix
,
fcntlFlock
,
"(Ljava/io/FileDescriptor;ILlibcore/io/StructFlock;)I"
),
NATIVE_METHOD
(
Posix
,
fdatasync
,
"(Ljava/io/FileDescriptor;)V"
),
NATIVE_METHOD
(
Posix
,
fstat
,
"(Ljava/io/FileDescriptor;)Llibcore/io/StructStat;"
),
NATIVE_METHOD
(
Posix
,
fstatfs
,
"(Ljava/io/FileDescriptor;)Llibcore/io/StructStat
F
s;"
),
NATIVE_METHOD
(
Posix
,
fstat
v
fs
,
"(Ljava/io/FileDescriptor;)Llibcore/io/StructStat
Vf
s;"
),
NATIVE_METHOD
(
Posix
,
fsync
,
"(Ljava/io/FileDescriptor;)V"
),
NATIVE_METHOD
(
Posix
,
ftruncate
,
"(Ljava/io/FileDescriptor;J)V"
),
NATIVE_METHOD
(
Posix
,
gai_strerror
,
"(I)Ljava/lang/String;"
),
...
...
@@ -1446,7 +1448,7 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD
(
Posix
,
socket
,
"(III)Ljava/io/FileDescriptor;"
),
NATIVE_METHOD
(
Posix
,
socketpair
,
"(IIILjava/io/FileDescriptor;Ljava/io/FileDescriptor;)V"
),
NATIVE_METHOD
(
Posix
,
stat
,
"(Ljava/lang/String;)Llibcore/io/StructStat;"
),
NATIVE_METHOD
(
Posix
,
statfs
,
"(Ljava/lang/String;)Llibcore/io/StructStat
F
s;"
),
NATIVE_METHOD
(
Posix
,
stat
v
fs
,
"(Ljava/lang/String;)Llibcore/io/StructStat
Vf
s;"
),
NATIVE_METHOD
(
Posix
,
strerror
,
"(I)Ljava/lang/String;"
),
NATIVE_METHOD
(
Posix
,
strsignal
,
"(I)Ljava/lang/String;"
),
NATIVE_METHOD
(
Posix
,
symlink
,
"(Ljava/lang/String;Ljava/lang/String;)V"
),
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment