OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [archive/] [tar/] [common.go] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
// Package tar implements access to tar archives.
6
// It aims to cover most of the variations, including those produced
7
// by GNU and BSD tars.
8
//
9
// References:
10
//   http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5
11
//   http://www.gnu.org/software/tar/manual/html_node/Standard.html
12
package tar
13
 
14
import "time"
15
 
16
const (
17
        blockSize = 512
18
 
19
        // Types
20
        TypeReg           = '0'    // regular file
21
        TypeRegA          = '\x00' // regular file
22
        TypeLink          = '1'    // hard link
23
        TypeSymlink       = '2'    // symbolic link
24
        TypeChar          = '3'    // character device node
25
        TypeBlock         = '4'    // block device node
26
        TypeDir           = '5'    // directory
27
        TypeFifo          = '6'    // fifo node
28
        TypeCont          = '7'    // reserved
29
        TypeXHeader       = 'x'    // extended header
30
        TypeXGlobalHeader = 'g'    // global extended header
31
)
32
 
33
// A Header represents a single header in a tar archive.
34
// Some fields may not be populated.
35
type Header struct {
36
        Name       string    // name of header file entry
37
        Mode       int64     // permission and mode bits
38
        Uid        int       // user id of owner
39
        Gid        int       // group id of owner
40
        Size       int64     // length in bytes
41
        ModTime    time.Time // modified time
42
        Typeflag   byte      // type of header entry
43
        Linkname   string    // target name of link
44
        Uname      string    // user name of owner
45
        Gname      string    // group name of owner
46
        Devmajor   int64     // major number of character or block device
47
        Devminor   int64     // minor number of character or block device
48
        AccessTime time.Time // access time
49
        ChangeTime time.Time // status change time
50
}
51
 
52
var zeroBlock = make([]byte, blockSize)
53
 
54
// POSIX specifies a sum of the unsigned byte values, but the Sun tar uses signed byte values.
55
// We compute and return both.
56
func checksum(header []byte) (unsigned int64, signed int64) {
57
        for i := 0; i < len(header); i++ {
58
                if i == 148 {
59
                        // The chksum field (header[148:156]) is special: it should be treated as space bytes.
60
                        unsigned += ' ' * 8
61
                        signed += ' ' * 8
62
                        i += 7
63
                        continue
64
                }
65
                unsigned += int64(header[i])
66
                signed += int64(int8(header[i]))
67
        }
68
        return
69
}
70
 
71
type slicer []byte
72
 
73
func (sp *slicer) next(n int) (b []byte) {
74
        s := *sp
75
        b, *sp = s[0:n], s[n:]
76
        return
77
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.