summaryrefslogtreecommitdiff
path: root/ufs-fsck/fsck.h
blob: ca8f2dfded0026274ae0518ba30364040463019d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

/* 
   Copyright (C) 1994 Free Software Foundation, Inc.
   Written by Michael I. Bushnell.

   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

#include <sys/types.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include "../ufs/fs.h"
#include "../ufs/dinode.h"
#include "../ufs/dir.h"

/* Type of an inode */
#define UNALLOC 0
#define REG 1
#define DIRECTORY 2
#define BADDIR 3

/* Added to directories in pass 2 */
#define DIR_REF 4	/* dir has been found in connectivity search */

/* State of each inode (set by pass 1) */
char *inodestate;

/* Number of links claimed by each inode (set by pass 1) */
nlink_t *linkcount;

/* Number of links found to each inode (set by pass 2) */
nlink_t *linkfound;

/* DT_foo type of each inode (set by pass 1) */
char *typemap;

/* Map of blocks allocated */
char *blockmap;


/* Command line flags */ 
int nowrite;			/* all questions fail */
int noquery;			/* all questions succeed */


enum contret
{
  RET_STOP,
  RET_GOOD,
  RET_BAD,
};


/* One of these structures is set up for each directory by
   pass 1 and used by passes 2 and 3. */
struct dirinfo
{
  struct inoinfo *i_nexthash;	/* next entry in hash chain */
  ino_t i_number;		/* inode entry of this dir */
  ino_t i_parent;		/* inode entry of parent */
  ino_t i_dotdot;		/* inode number of `..' */
  ino_t i_dot;			/* inode number of `.' */
  ino_t i_isize;		/* size of inode */
  u_int i_numblks;		/* size of block array in bytes */
  daddr_t i_blks[0];		/* array of inode block addresses */
};

/* Array of all the dirinfo structures in inode number order */
struct dirinfo **dirarray;

/* Array of all thi dirinfo structures sorted by their first
   block address */
struct dirinfo **dirsorted;

int dirarrayused;		/* number of directories */
int dirarraysize;		/* alloced size of dirarray/dirsorted */

struct dups {
	struct dups *next;
	daddr_t dup;
};
struct dups *duplist;		/* head of dup list */
struct dups *muldup;		/* end of unique duplicate dup block numbers */


struct fs *sblock;

daddr_t maxfsblock;
int maxino;
int direct_symlink_extension;

int newinofmt;

int preen;

int readfd, writefd;

int fsmodified;

int lfdir;
char lfname[];
mode_t lfmode;


#define NBBY 8
#define howmany(x,y) (((x)+((y)-1))/(y))
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
#define isclr(a, i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#define isset(a, i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<(i)%NBBY))
#define DEV_BSIZE 512

#define setbmap(blkno) setbit (blockmap, blkno)
#define testbmap(blkno) isset (blockmap, blkno)
#define clrbmap(blkno) clrbit (blockmap, blkno)

#define DI_MODE(dp) (((dp)->di_modeh << 16) | (dp)->di_model)


     
int setup (char *);
void pass1 (), pass1b (), pass2 (), pass3 (), pass4 (), pass5 ();

void readblock (daddr_t, void *, size_t);
void writeblock (daddr_t, void *, size_t);

void getinode (ino_t, struct dinode *);
void write_inode (ino_t, struct dinode *);
void clear_inode (ino_t, struct dinode *);

daddr_t allocblk (int);
int check_range (daddr_t, int);

ino_t allocino (ino_t, mode_t);
void freeino (ino_t);
ino_t allocdir (ino_t, ino_t, mode_t);

int makeentry (ino_t, ino_t, char *);
int changeino (ino_t, char *, ino_t);

int linkup (ino_t, ino_t);

void datablocks_iterate (struct dinode *, int (*)(daddr_t, int, off_t));
void allblock_iterate (struct dinode *, int (*)(daddr_t, int, off_t));

void record_directory (struct dinode *, ino_t);

void pinode (ino_t);

int reply (char *);
int pfatal (char *, ...)  __attribute__ ((format (printf, 1, 2)));
void errexit (char *, ...) __attribute__ ((format (printf, 1, 2),
					   noreturn));
int pwarn (char *, ...) __attribute__ ((format (printf, 1, 2)));