Debian Codegraph @

compat/lib/dumprestore.c

raw symbols SCIP
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <[email protected]>, 1994-1997
5 * Stelian Pop <[email protected]>, 1999-2000
6 * Stelian Pop <[email protected]> - AlcĂ´ve <www.alcove.com>, 2000-2002
7 */
8
9 /*
10 * Copyright (c) 1980, 1993
11 * The Regents of the University of California. All rights reserved.
12 * (c) UNIX System Laboratories, Inc.
13 * All or some portions of this file are derived from material licensed
14 * to the University of California by American Telephone and Telegraph
15 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
16 * the permission of UNIX System Laboratories, Inc.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 3. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 */
42
43 #include "config.h" // IWYU pragma: keep
44 #include "compat/include/protocols/dumprestore.h"
45 #include "common/shared_globals.h"
46
47 #include <stdint.h>
48
49 // IWYU pragma: no_include "dump_globals.h"
50 #include "common/shared_globals.h" // IWYU pragma: keep
51
52 long long u_spcl_c_tapea(void) {
53 return spcl.c_tapea_lo | (((uint64_t)spcl.c_tapea_hi) << 32);
54 }
55
56 void u_spcl_c_tapea_set(uint64_t v) {
57 spcl.c_tapea_lo = v & 0xffffffffull;
58 spcl.c_tapea_hi = v >> 32;
59 }
60
61 void u_spcl_c_tapea_add(uint64_t inc) {
62 u_spcl_c_tapea_set(u_spcl_c_tapea() + inc);
63 }
64
65 long long u_spcl_c_firstrec(const struct s_spcl *buf) {
66 return buf->c_firstrec_lo | (((uint64_t)buf->c_firstrec_hi) << 32);
67 }
68
69 void u_spcl_c_firstrec_set(uint64_t v) {
70 spcl.c_firstrec_lo = v & 0xffffffffull;
71 spcl.c_firstrec_hi = v >> 32;
72 }
73
74 int tapebuf_getcompressed(const struct tapebuf* tb)
75 {
76 return *(const uint32_t*)tb & 1;
77 }
78 int tapebuf_getflags(const struct tapebuf* tb)
79 {
80 return (*(const uint32_t*)tb&0xe) >> 1;
81 }
82 int tapebuf_getlength(const struct tapebuf* tb)
83 {
84 return *(const uint32_t*)tb >> 4;
85 }
86
87 void tapebuf_setcompressed(struct tapebuf* tb, uint32_t v)
88 {
89 *(uint32_t*)tb &= ~1;
90 *(uint32_t*)tb |= (v&1);
91 }
92 void tapebuf_setflags(struct tapebuf* tb, uint32_t v)
93 {
94 *(uint32_t*)tb &= ~0xe;
95 *(uint32_t*)tb |= (v&0x07) << 1;
96 }
97 void tapebuf_setlength(struct tapebuf* tb, uint32_t v)
98 {
99 *(uint32_t*)tb &= 0xf;
100 *(uint32_t*)tb |= (v&((1<<28)-1)) << 4;
101 }
102
103 uint32_t get_s_addr_length(const uint8_t* ptr) {
104 /*
105 * 1 - 64 encoded as 0-63 in n V[0] = (0nnnnnnf) (f is the data/sparse flag)
106 * if ( V[0] < 128 ) return (*V >> 1) + 1 )
107 * 65 - 16384 encoded as 0-16319 in Nn V[0] = (1nnnnnnf) V[1] = (NNNNNNNN)
108 * if (V[0] >= 128) return V[1]*64 + ((V[0]>>1)&63) + 65;
109 * 128 values left unused for future special cases (V[1] = 255) 1nnnnnnn 11111111
110 * if get_s_addr_length() >=65 then length is encoded in two bytes else in one.
111 */
112 if (*ptr < 128)
113 return (*ptr>>1)+1;
114 return *(ptr+1)*64 + ((*ptr>>1)&63) + 65;
115 }