Home | History | Annotate | Download | only in system
      1 /*
      2  * Copyright (C) 2011 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.system;
     18 
     19 import libcore.util.Objects;
     20 
     21 /**
     22  * File information returned by {@link Os#fstat}, {@link Os#lstat}, and {@link Os#stat}.
     23  * Corresponds to C's {@code struct stat} from {@code <stat.h>}.
     24  */
     25 public final class StructStat {
     26     /** Device ID of device containing file. */
     27     public final long st_dev; /*dev_t*/
     28 
     29     /** File serial number (inode). */
     30     public final long st_ino; /*ino_t*/
     31 
     32     /** Mode (permissions) of file. */
     33     public final int st_mode; /*mode_t*/
     34 
     35     /** Number of hard links to the file. */
     36     public final long st_nlink; /*nlink_t*/
     37 
     38     /** User ID of file. */
     39     public final int st_uid; /*uid_t*/
     40 
     41     /** Group ID of file. */
     42     public final int st_gid; /*gid_t*/
     43 
     44     /** Device ID (if file is character or block special). */
     45     public final long st_rdev; /*dev_t*/
     46 
     47     /**
     48      * For regular files, the file size in bytes.
     49      * For symbolic links, the length in bytes of the pathname contained in the symbolic link.
     50      * For a shared memory object, the length in bytes.
     51      * For a typed memory object, the length in bytes.
     52      * For other file types, the use of this field is unspecified.
     53      */
     54     public final long st_size; /*off_t*/
     55 
     56     /** Seconds part of time of last access. */
     57     public final long st_atime; /*time_t*/
     58 
     59     /** StructTimespec with time of last access. */
     60     public final StructTimespec st_atim;
     61 
     62     /** Seconds part of time of last data modification. */
     63     public final long st_mtime; /*time_t*/
     64 
     65     /** StructTimespec with time of last modification. */
     66     public final StructTimespec st_mtim;
     67 
     68     /** Seconds part of time of last status change */
     69     public final long st_ctime; /*time_t*/
     70 
     71     /** StructTimespec with time of last status change. */
     72     public final StructTimespec st_ctim;
     73 
     74     /**
     75      * A file system-specific preferred I/O block size for this object.
     76      * For some file system types, this may vary from file to file.
     77      */
     78     public final long st_blksize; /*blksize_t*/
     79 
     80     /** Number of blocks allocated for this object. */
     81     public final long st_blocks; /*blkcnt_t*/
     82 
     83     /**
     84      * Constructs an instance with the given field values.
     85      */
     86     public StructStat(long st_dev, long st_ino, int st_mode, long st_nlink, int st_uid, int st_gid,
     87             long st_rdev, long st_size, long st_atime, long st_mtime, long st_ctime,
     88             long st_blksize, long st_blocks) {
     89         this(st_dev, st_ino, st_mode, st_nlink, st_uid, st_gid,
     90                 st_rdev, st_size, new StructTimespec(st_atime, 0L), new StructTimespec(st_mtime, 0L),
     91                 new StructTimespec(st_ctime, 0L), st_blksize, st_blocks);
     92     }
     93 
     94     /**
     95      * Constructs an instance with the given field values.
     96      */
     97     public StructStat(long st_dev, long st_ino, int st_mode, long st_nlink, int st_uid, int st_gid,
     98             long st_rdev, long st_size, StructTimespec st_atim, StructTimespec st_mtim,
     99             StructTimespec st_ctim, long st_blksize, long st_blocks) {
    100         this.st_dev = st_dev;
    101         this.st_ino = st_ino;
    102         this.st_mode = st_mode;
    103         this.st_nlink = st_nlink;
    104         this.st_uid = st_uid;
    105         this.st_gid = st_gid;
    106         this.st_rdev = st_rdev;
    107         this.st_size = st_size;
    108         this.st_atime = st_atim.tv_sec;
    109         this.st_mtime = st_mtim.tv_sec;
    110         this.st_ctime = st_ctim.tv_sec;
    111         this.st_atim = st_atim;
    112         this.st_mtim = st_mtim;
    113         this.st_ctim = st_ctim;
    114         this.st_blksize = st_blksize;
    115         this.st_blocks = st_blocks;
    116     }
    117 
    118     @Override public String toString() {
    119         return Objects.toString(this);
    120     }
    121 }
    122