Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.os;
     18 
     19 /**
     20  * Retrieve overall information about the space on a filesystem.  This is a
     21  * Wrapper for Unix statfs().
     22  */
     23 public class StatFs {
     24     /**
     25      * Construct a new StatFs for looking at the stats of the
     26      * filesystem at <var>path</var>.  Upon construction, the stat of
     27      * the file system will be performed, and the values retrieved available
     28      * from the methods on this class.
     29      *
     30      * @param path A path in the desired file system to state.
     31      */
     32     public StatFs(String path) { native_setup(path); }
     33 
     34     /**
     35      * Perform a restat of the file system referenced by this object.  This
     36      * is the same as re-constructing the object with the same file system
     37      * path, and the new stat values are available upon return.
     38      */
     39     public void restat(String path) { native_restat(path); }
     40 
     41     @Override
     42     protected void finalize() { native_finalize(); }
     43 
     44     /**
     45      * The size, in bytes, of a block on the file system.  This corresponds
     46      * to the Unix statfs.f_bsize field.
     47      */
     48     public native int getBlockSize();
     49 
     50     /**
     51      * The total number of blocks on the file system.  This corresponds
     52      * to the Unix statfs.f_blocks field.
     53      */
     54     public native int getBlockCount();
     55 
     56     /**
     57      * The total number of blocks that are free on the file system, including
     58      * reserved blocks (that are not available to normal applications).  This
     59      * corresponds to the Unix statfs.f_bfree field.  Most applications will
     60      * want to use {@link #getAvailableBlocks()} instead.
     61      */
     62     public native int getFreeBlocks();
     63 
     64     /**
     65      * The number of blocks that are free on the file system and available to
     66      * applications.  This corresponds to the Unix statfs.f_bavail field.
     67      */
     68     public native int getAvailableBlocks();
     69 
     70     private int mNativeContext;
     71     private native void native_restat(String path);
     72     private native void native_setup(String path);
     73     private native void native_finalize();
     74 }
     75