github.com/jlowellwofford/u-root@v1.0.0/xcmds/archive/archive.go (about) 1 // Copyright 2013-2017 the u-root 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 // Archive archives files. 6 // 7 // 8 // Synopsis: 9 // archive d|e|t [-d] [args...] 10 // 11 // Description: 12 // The VTOC is at the front; we're not modeling tape drives or streams as 13 // in tar and cpio. This will greatly speed up listing the archive, 14 // modifying it, and so on. We think. Why a new tool? 15 // 16 // Options: 17 // d: decode 18 // e: toc (table of contents) 19 // t: toc (table of contents) 20 // -d: debug prints 21 package main 22 23 import ( 24 "flag" 25 "log" 26 "os" 27 ) 28 29 // You'll see the name VTOC used a lot. 30 // The Volume Table Of Contents (extra points for looking this 31 // up) is an array of structs listing the file names, and 32 // their info. We'll see how much is needed -- almost 33 // certainly more than we think. No attempt is made hee to be 34 // space efficient. Disks are big, and metadata is much the 35 // smallest part of it all. I think. 36 // The VTOC goes after the data, because the VTOC size 37 // is actually dependent on the values of the offsets in the 38 // individual structs. We have to write the data, fill in the 39 // VTOC, and write the encoded VTOC out. 40 // VTOC is a []file. 41 42 var ( 43 debug = func(string, ...interface{}) {} 44 d = flag.Bool("d", false, "Debug prints") 45 ) 46 47 func usage() { 48 log.Fatalf("Usage: archive d|e|t [args...]") 49 } 50 51 func main() { 52 var err error 53 flag.Parse() 54 if *d { 55 debug = log.Printf 56 } 57 58 a := flag.Args() 59 debug("Args %v", a) 60 if len(a) < 1 { 61 usage() 62 } 63 op := a[0] 64 65 switch op { 66 case "e": 67 err = encode(os.Stdout, a[1:]...) 68 case "t": 69 err = toc(a[1:]...) 70 case "d": 71 err = decode(a[1:]...) 72 default: 73 usage() 74 } 75 if err != nil { 76 log.Fatalf("%v", err) 77 } 78 }