Home | History | Annotate | Download | only in dump
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one
      3  * or more contributor license agreements.  See the NOTICE file
      4  * distributed with this work for additional information
      5  * regarding copyright ownership.  The ASF licenses this file
      6  * to you under the Apache License, Version 2.0 (the
      7  * "License"); you may not use this file except in compliance
      8  * with the License.  You may obtain a copy of the License at
      9  *
     10  * http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing,
     13  * software distributed under the License is distributed on an
     14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15  * KIND, either express or implied.  See the License for the
     16  * specific language governing permissions and limitations
     17  * under the License.
     18  */
     19 package org.apache.commons.compress.archivers.dump;
     20 
     21 import java.io.IOException;
     22 import java.util.Date;
     23 
     24 import org.apache.commons.compress.archivers.zip.ZipEncoding;
     25 
     26 /**
     27  * This class represents identifying information about a Dump archive volume.
     28  * It consists the archive's dump date, label, hostname, device name and possibly
     29  * last mount point plus the volume's volume id andfirst record number.
     30  *
     31  * For the corresponding C structure see the header of {@link DumpArchiveEntry}.
     32  */
     33 public class DumpArchiveSummary {
     34     private long dumpDate;
     35     private long previousDumpDate;
     36     private int volume;
     37     private String label;
     38     private int level;
     39     private String filesys;
     40     private String devname;
     41     private String hostname;
     42     private int flags;
     43     private int firstrec;
     44     private int ntrec;
     45 
     46     DumpArchiveSummary(final byte[] buffer, final ZipEncoding encoding) throws IOException {
     47         dumpDate = 1000L * DumpArchiveUtil.convert32(buffer, 4);
     48         previousDumpDate = 1000L * DumpArchiveUtil.convert32(buffer, 8);
     49         volume = DumpArchiveUtil.convert32(buffer, 12);
     50         label = DumpArchiveUtil.decode(encoding, buffer, 676, DumpArchiveConstants.LBLSIZE).trim();
     51         level = DumpArchiveUtil.convert32(buffer, 692);
     52         filesys = DumpArchiveUtil.decode(encoding, buffer, 696, DumpArchiveConstants.NAMELEN).trim();
     53         devname = DumpArchiveUtil.decode(encoding, buffer, 760, DumpArchiveConstants.NAMELEN).trim();
     54         hostname = DumpArchiveUtil.decode(encoding, buffer, 824, DumpArchiveConstants.NAMELEN).trim();
     55         flags = DumpArchiveUtil.convert32(buffer, 888);
     56         firstrec = DumpArchiveUtil.convert32(buffer, 892);
     57         ntrec = DumpArchiveUtil.convert32(buffer, 896);
     58 
     59         //extAttributes = DumpArchiveUtil.convert32(buffer, 900);
     60     }
     61 
     62     /**
     63      * Get the date of this dump.
     64      * @return the date of this dump.
     65      */
     66     public Date getDumpDate() {
     67         return new Date(dumpDate);
     68     }
     69 
     70     /**
     71      * Set dump date.
     72      * @param dumpDate the dump date
     73      */
     74     public void setDumpDate(final Date dumpDate) {
     75         this.dumpDate = dumpDate.getTime();
     76     }
     77 
     78     /**
     79      * Get the date of the previous dump at this level higher.
     80      * @return dumpdate may be null
     81      */
     82     public Date getPreviousDumpDate() {
     83         return new Date(previousDumpDate);
     84     }
     85 
     86     /**
     87      * Set previous dump date.
     88      * @param previousDumpDate the previous dump dat
     89      */
     90     public void setPreviousDumpDate(final Date previousDumpDate) {
     91         this.previousDumpDate = previousDumpDate.getTime();
     92     }
     93 
     94     /**
     95      * Get volume (tape) number.
     96      * @return volume (tape) number.
     97      */
     98     public int getVolume() {
     99         return volume;
    100     }
    101 
    102     /**
    103      * Set volume (tape) number.
    104      * @param volume the volume number
    105      */
    106     public void setVolume(final int volume) {
    107         this.volume = volume;
    108     }
    109 
    110     /**
    111      * Get the level of this dump. This is a number between 0 and 9, inclusive,
    112      * and a level 0 dump is a complete dump of the partition. For any other dump
    113      * 'n' this dump contains all files that have changed since the last dump
    114      * at this level or lower. This is used to support different levels of
    115      * incremental backups.
    116      * @return dump level
    117      */
    118     public int getLevel() {
    119         return level;
    120     }
    121 
    122     /**
    123      * Set level.
    124      * @param level the level
    125      */
    126     public void setLevel(final int level) {
    127         this.level = level;
    128     }
    129 
    130     /**
    131      * Get dump label. This may be autogenerated or it may be specified
    132      * bu the user.
    133      * @return dump label
    134      */
    135     public String getLabel() {
    136         return label;
    137     }
    138 
    139     /**
    140      * Set dump label.
    141      * @param label the label
    142      */
    143     public void setLabel(final String label) {
    144         this.label = label;
    145     }
    146 
    147     /**
    148      * Get the last mountpoint, e.g., /home.
    149      * @return last mountpoint
    150      */
    151     public String getFilesystem() {
    152         return filesys;
    153     }
    154 
    155     /**
    156      * Set the last mountpoint.
    157      * @param filesystem the last mountpoint
    158      */
    159     public void setFilesystem(final String filesystem) {
    160         this.filesys = filesystem;
    161     }
    162 
    163     /**
    164      * Get the device name, e.g., /dev/sda3 or /dev/mapper/vg0-home.
    165      * @return device name
    166      */
    167     public String getDevname() {
    168         return devname;
    169     }
    170 
    171     /**
    172      * Set the device name.
    173      * @param devname the device name
    174      */
    175     public void setDevname(final String devname) {
    176         this.devname = devname;
    177     }
    178 
    179     /**
    180      * Get the hostname of the system where the dump was performed.
    181      * @return hostname the host name
    182      */
    183     public String getHostname() {
    184         return hostname;
    185     }
    186 
    187     /**
    188      * Set the hostname.
    189      * @param hostname the host name
    190      */
    191     public void setHostname(final String hostname) {
    192         this.hostname = hostname;
    193     }
    194 
    195     /**
    196      * Get the miscellaneous flags. See below.
    197      * @return flags
    198      */
    199     public int getFlags() {
    200         return flags;
    201     }
    202 
    203     /**
    204      * Set the miscellaneous flags.
    205      * @param flags flags
    206      */
    207     public void setFlags(final int flags) {
    208         this.flags = flags;
    209     }
    210 
    211     /**
    212      * Get the inode of the first record on this volume.
    213      * @return inode of the first record on this volume.
    214      */
    215     public int getFirstRecord() {
    216         return firstrec;
    217     }
    218 
    219     /**
    220      * Set the inode of the first record.
    221      * @param firstrec the first record
    222      */
    223     public void setFirstRecord(final int firstrec) {
    224         this.firstrec = firstrec;
    225     }
    226 
    227     /**
    228      * Get the number of records per tape block. This is typically
    229      * between 10 and 32.
    230      * @return the number of records per tape block
    231      */
    232     public int getNTRec() {
    233         return ntrec;
    234     }
    235 
    236     /**
    237      * Set the number of records per tape block.
    238      * @param ntrec the number of records per tape block
    239      */
    240     public void setNTRec(final int ntrec) {
    241         this.ntrec = ntrec;
    242     }
    243 
    244     /**
    245      * Is this the new header format? (We do not currently support the
    246      * old format.)
    247      *
    248      * @return true if using new header format
    249      */
    250     public boolean isNewHeader() {
    251         return (flags & 0x0001) == 0x0001;
    252     }
    253 
    254     /**
    255      * Is this the new inode format? (We do not currently support the
    256      * old format.)
    257      * @return true if using new inode format
    258      */
    259     public boolean isNewInode() {
    260         return (flags & 0x0002) == 0x0002;
    261     }
    262 
    263     /**
    264      * Is this volume compressed? N.B., individual blocks may or may not be compressed.
    265      * The first block is never compressed.
    266      * @return true if volume is compressed
    267      */
    268     public boolean isCompressed() {
    269         return (flags & 0x0080) == 0x0080;
    270     }
    271 
    272     /**
    273      * Does this volume only contain metadata?
    274      * @return true if volume only contains meta-data
    275      */
    276     public boolean isMetaDataOnly() {
    277         return (flags & 0x0100) == 0x0100;
    278     }
    279 
    280     /**
    281      * Does this volume cotain extended attributes.
    282      * @return true if volume cotains extended attributes.
    283      */
    284     public boolean isExtendedAttributes() {
    285         return (flags & 0x8000) == 0x8000;
    286     }
    287 
    288     @Override
    289     public int hashCode() {
    290         int hash = 17;
    291 
    292         if (label != null) {
    293             hash = label.hashCode();
    294         }
    295 
    296         hash += 31 * dumpDate;
    297 
    298         if (hostname != null) {
    299             hash = (31 * hostname.hashCode()) + 17;
    300         }
    301 
    302         if (devname != null) {
    303             hash = (31 * devname.hashCode()) + 17;
    304         }
    305 
    306         return hash;
    307     }
    308 
    309     @Override
    310     public boolean equals(final Object o) {
    311         if (this == o) {
    312             return true;
    313         }
    314 
    315         if (o == null || !o.getClass().equals(getClass())) {
    316             return false;
    317         }
    318 
    319         final DumpArchiveSummary rhs = (DumpArchiveSummary) o;
    320 
    321         if (dumpDate != rhs.dumpDate) {
    322             return false;
    323         }
    324 
    325         if ((getHostname() == null) ||
    326                 !getHostname().equals(rhs.getHostname())) {
    327             return false;
    328         }
    329 
    330         if ((getDevname() == null) || !getDevname().equals(rhs.getDevname())) {
    331             return false;
    332         }
    333 
    334         return true;
    335     }
    336 }
    337