~ubuntu-branches/debian/stretch/jfsutils/stretch

« back to all changes in this revision

Viewing changes to fsck/fsckwsp.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Hornburg (Racke)
  • Date: 2005-01-07 10:12:20 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050107101220-ka3f7smw42zysmk1
Tags: 1.1.7-1
* new upstream release (Closes: #289106)
* start synopsis with lowercase

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *   Copyright (c) International Business Machines  Corp., 2000
 
2
 *   Copyright (C) International Business Machines Corp., 2000-2004
3
3
 *
4
4
 *   This program is free software;  you can redistribute it and/or modify
5
5
 *   it under the terms of the GNU General Public License as published by
6
 
 *   the Free Software Foundation; either version 2 of the License, or
 
6
 *   the Free Software Foundation; either version 2 of the License, or 
7
7
 *   (at your option) any later version.
8
 
 *
 
8
 * 
9
9
 *   This program is distributed in the hope that it will be useful,
10
10
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12
12
 *   the GNU General Public License for more details.
13
13
 *
14
14
 *   You should have received a copy of the GNU General Public License
15
 
 *   along with this program;  if not, write to the Free Software
 
15
 *   along with this program;  if not, write to the Free Software 
16
16
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
 
 *
18
 
 *   MODULE_NAME:               fsckwsp.c
19
 
 *
20
 
 *   COMPONENT_NAME:    jfs utilities
21
 
 *
22
 
 *   FUNCTIONS:
23
 
 *              alloc_vlarge_buffer
24
 
 *              blkall_decrement_owners
25
 
 *              blkall_increment_owners
26
 
 *              blkall_ref_check
27
 
 *              dire_buffer_alloc
28
 
 *              dire_buffer_release
29
 
 *              directory_buffers_alloc
30
 
 *              directory_buffers_release
31
 
 *              dtreeQ_dequeue
32
 
 *              dtreeQ_enqueue
33
 
 *              dtreeQ_get_elem
34
 
 *              dtreeQ_rel_elem
35
 
 *              establish_agg_workspace
36
 
 *              establish_ea_iobuf
37
 
 *              establish_fs_workspace
38
 
 *              establish_io_buffers
39
 
 *              establish_wsp_block_map_ctl
40
 
 *              extent_record
41
 
 *              extent_unrecord
42
 
 *              fsck_alloc_fsblks
43
 
 *              fsck_dealloc_fsblks
44
 
 *              fscklog_end
45
 
 *              fscklog_init
46
 
 *              fscklog_start
47
 
 *              get_inode_extension
48
 
 *              get_inorecptr
49
 
 *              get_inorecptr_first
50
 
 *              get_inorecptr_next
51
 
 *              init_agg_record
52
 
 *              process_extent
53
 
 *              release_inode_extension
54
 
 *              release_logredo_allocs
55
 
 *              temp_inode_buf_alloc
56
 
 *              temp_inode_buf_release
57
 
 *              temp_node_buf_alloc
58
 
 *              treeQ_dequeue
59
 
 *              treeQ_enqueue
60
 
 *              treeQ_get_elem
61
 
 *              treeQ_rel_elem
62
 
 *              treeStack_pop
63
 
 *              treeStack_push
64
 
 *              workspace_release
65
 
 *              alloc_wrksp
66
 
 *              alloc_wsp_extent
67
 
 *              dupall_extract_blkrec
68
 
 *              dupall_find_blkrec
69
 
 *              dupall_get_blkrec
70
 
 *              dupall_insert_blkrec
71
 
 *              establish_wsp_block_map
72
 
 *              extent_1stref_chk
73
 
 *              extent_record_dupchk
74
 
 *              fsblk_count_avail
75
 
 *              fsblk_next_avail
76
 
 *              inorec_agg_search
77
 
 *              inorec_agg_search_insert
78
 
 *              inorec_fs_search
79
 
 *              inorec_fs_search_insert
80
 
 *              locate_inode
81
 
 *              treeStack_get_elem
82
 
 *              treeStack_rel_elem
83
 
 *
84
 
 */
85
 
 
86
 
/*
87
 
 * defines and includes common among the xfsck modules
88
 
 */
 
17
 */
 
18
/* defines and includes common among the fsck.jfs modules */
89
19
#include "xfsckint.h"
90
20
#include <time.h>
91
21
#include <unistd.h>
92
22
 
93
 
/* endian routines */
94
23
#include <errno.h>
95
 
extern uint32_t type_jfs;
96
 
extern void ujfs_swap_fsck_blk_map_page( fsck_blk_map_page_t  * );
97
 
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
98
 
 *
99
 
 * buffer for endian swapping structures
100
 
 *
101
 
 *     buffer used when needed in individual routines
102
 
 */
103
 
extern char *swap_buf_ptr;
104
 
 
105
24
 
106
25
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
107
26
 *
133
52
 *
134
53
 *      defined in xchkdsk.c
135
54
 */
136
 
extern char message_parm_0[];
137
 
extern char message_parm_1[];
138
 
extern char message_parm_2[];
139
 
extern char message_parm_3[];
140
 
extern char message_parm_4[];
141
 
extern char message_parm_5[];
142
 
extern char message_parm_6[];
143
 
extern char message_parm_7[];
144
 
extern char message_parm_8[];
145
 
extern char message_parm_9[];
146
 
 
147
 
extern char *msgprms[];
148
 
extern int16_t  msgprmidx[];
149
 
 
150
 
extern char *terse_msg_ptr;
 
55
 
151
56
extern char *verbose_msg_ptr;
152
57
 
153
58
extern struct tm *fsck_DateTime;
154
59
 
155
 
extern char *MsgText[];
156
 
 
157
60
extern char *Vol_Label;
158
61
 
159
62
extern UniChar uni_LSFN_NAME[];
165
68
 *
166
69
 *      defined in xchkdsk.c
167
70
 */
168
 
extern HFILE  Dev_IOPort;
169
 
extern uint32_t  Dev_blksize;
170
 
 
171
 
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
172
 
 *
173
 
 * The current processing phase.
174
 
 *
175
 
 *      defined in xchkdsk.c
176
 
 *      constants defining possible values are defined in xfsck.h
177
 
 */
178
 
extern int current_fsck_phase;
 
71
extern HFILE Dev_IOPort;
 
72
extern uint32_t Dev_blksize;
179
73
 
180
74
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
181
75
 *
193
87
 *
194
88
 */
195
89
 
196
 
retcode_t alloc_wsp_extent ( reg_idx_t, int );
197
 
 
198
 
retcode_t dupall_extract_blkrec ( dupall_blkrec_ptr, dupall_blkrec_tkn );
199
 
 
200
 
retcode_t dupall_find_blkrec ( fsblkidx_t, dupall_blkrec_ptr *,
201
 
                               dupall_blkrec_tkn * );
202
 
 
203
 
retcode_t dupall_get_blkrec ( dupall_blkrec_ptr * );
204
 
 
205
 
retcode_t dupall_insert_blkrec ( fsblkidx_t );
206
 
 
207
 
retcode_t establish_wsp_block_map ( void );
208
 
 
209
 
retcode_t extent_1stref_chk ( fsblkidx_t, fsblkidx_t, int8_t, int8_t,
210
 
                              fsck_msg_info_ptr, fsck_inode_recptr );
211
 
 
212
 
retcode_t extent_record_dupchk ( fsblkidx_t, fsblkidx_t, int8_t, int8_t, int8_t,
213
 
                                 fsck_msg_info_ptr, fsck_inode_recptr );
214
 
 
215
 
retcode_t fsblk_count_avail( fsck_bitmap_ptr, int32_t*, int32_t*, int32_t, int32_t * );
216
 
 
217
 
retcode_t fsblk_next_avail( fsck_bitmap_ptr,  int32_t, int32_t, int32_t *,
218
 
                            int32_t *, int * );
219
 
 
220
 
retcode_t inorec_agg_search( uint32_t, fsck_inode_recptr * );           
221
 
 
222
 
retcode_t inorec_agg_search_insert( uint32_t, fsck_inode_recptr * );  
223
 
 
224
 
retcode_t inorec_fs_search( uint32_t, fsck_inode_recptr * );            
225
 
 
226
 
retcode_t inorec_fs_search_insert( uint32_t, fsck_inode_recptr * );    
227
 
 
228
 
void locate_inode( uint32_t, int32_t *, int32_t *, int32_t * );                    
229
 
 
230
 
retcode_t treeStack_get_elem ( treeStack_ptr * );
231
 
 
232
 
retcode_t treeStack_rel_elem ( treeStack_ptr );
233
 
 
 
90
int alloc_wsp_extent(uint32_t, int);
 
91
 
 
92
void dupall_extract_blkrec(struct dupall_blkrec *);
 
93
 
 
94
struct dupall_blkrec *dupall_find_blkrec(int64_t, int64_t);
 
95
 
 
96
struct dupall_blkrec *dupall_get_blkrec(void);
 
97
 
 
98
int dupall_insert_blkrec(int64_t, int64_t, struct dupall_blkrec **);
 
99
 
 
100
int establish_wsp_block_map(void);
 
101
 
 
102
int extent_1stref_chk(int64_t, int64_t, int8_t, int8_t,
 
103
                      struct fsck_ino_msg_info *, struct fsck_inode_record *);
 
104
 
 
105
int extent_record_dupchk(int64_t, int64_t, int8_t, int8_t, int8_t,
 
106
                         struct fsck_ino_msg_info *,
 
107
                         struct fsck_inode_record *);
 
108
 
 
109
int fsblk_count_avail(uint32_t *, int32_t *, int32_t *, int32_t, int32_t *);
 
110
 
 
111
int fsblk_next_avail(uint32_t *, int32_t, int32_t, int32_t *, int32_t *, int *);
 
112
 
 
113
int inorec_agg_search(uint32_t, struct fsck_inode_record **);
 
114
 
 
115
int inorec_agg_search_insert(uint32_t, struct fsck_inode_record **);
 
116
 
 
117
int inorec_fs_search(uint32_t, struct fsck_inode_record **);
 
118
 
 
119
int inorec_fs_search_insert(uint32_t, struct fsck_inode_record **);
 
120
 
 
121
void locate_inode(uint32_t, int32_t *, int32_t *, int32_t *);
 
122
 
 
123
int treeStack_get_elem(struct treeStack_record **);
 
124
 
 
125
int treeStack_rel_elem(struct treeStack_record *);
234
126
 
235
127
/*
236
128
 * The following are used for reporting storage related errors
240
132
 
241
133
/* VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV */
242
134
 
243
 
 
244
135
/****************************************************************************
245
136
 * NAME: alloc_vlarge_buffer
246
137
 *
258
149
 *      success: FSCK_OK
259
150
 *      failure: something else
260
151
 */
261
 
retcode_t alloc_vlarge_buffer( )
 
152
int alloc_vlarge_buffer()
262
153
{
263
 
  retcode_t  avb_rc = FSCK_OK;
264
 
 
265
 
  agg_recptr->vlarge_buf_ptr = (char *) malloc(VLARGE_BUFSIZE);
266
 
  agg_recptr->vlarge_buf_length = VLARGE_BUFSIZE;
267
 
  agg_recptr->vlarge_current_use = NOT_CURRENTLY_USED;
268
 
 
269
 
  return( avb_rc );
270
 
}  /* end alloc_vlarge_buffer() */
271
 
 
 
154
        int avb_rc = FSCK_OK;
 
155
 
 
156
        if ((agg_recptr->vlarge_buf_ptr =
 
157
             (char *) malloc(VLARGE_BUFSIZE)) != NULL) {
 
158
                agg_recptr->vlarge_buf_length = VLARGE_BUFSIZE;
 
159
                agg_recptr->vlarge_current_use = NOT_CURRENTLY_USED;
 
160
        } else {
 
161
                avb_rc = ENOMEM;
 
162
                fsck_send_msg(MSG_OSO_INSUFF_MEMORY);
 
163
        }
 
164
 
 
165
        return (avb_rc);
 
166
}
272
167
 
273
168
/****************************************************************************
274
169
 * NAME: alloc_wrksp
285
180
 *                               will return the address of the dynamic storage
286
181
 *                               allocated for the caller
287
182
 *
288
 
 * NOTES:
289
 
 *
290
183
 * RETURNS:
291
184
 *      success: FSCK_OK
292
185
 *      failure: something else
293
186
 */
294
 
retcode_t alloc_wrksp ( reg_idx_t  length,
295
 
                        int        dynstg_object,
296
 
                        int        for_logredo,
297
 
                        void       **addr_wrksp_ptr )
 
187
int alloc_wrksp(uint32_t length, int dynstg_object, int for_logredo,
 
188
                void **addr_wrksp_ptr)
298
189
{
299
 
  retcode_t  awsp_rc = FSCK_OK;
300
 
  char       *wsp_ptr = NULL;
301
 
  wsp_ext_rec_ptr  this_fer;
302
 
  reg_idx_t  bytes_avail;
303
 
  reg_idx_t  min_length;
304
 
 
305
 
  *addr_wrksp_ptr = NULL;      /* initialize return value */
306
 
  min_length = ((length + 7) / 8) * 8;  /* round up to an 8 byte boundary */
307
 
 
308
 
  while ( (wsp_ptr == NULL) && (awsp_rc == FSCK_OK) ) {
309
 
    this_fer = agg_recptr->wsp_extent_list;
310
 
 
311
 
    while ( (this_fer != NULL)  &&
312
 
            (wsp_ptr == NULL)   &&
313
 
            (awsp_rc == FSCK_OK)  ) {
314
 
      if ( (for_logredo) && !(this_fer->for_logredo) ) { 
315
 
          /*
316
 
           * requestor is logredo and
317
 
           * fer describes an allocation not for logredo
318
 
           */
319
 
        this_fer = this_fer->next;
320
 
      } else {  /* this fer describes an eligible allocation */
321
 
        bytes_avail = this_fer->extent_length - this_fer->last_byte_used;
322
 
        if ( bytes_avail >= min_length ) {  /* there's enough here */
323
 
          wsp_ptr = this_fer->extent_addr + this_fer->last_byte_used + 1;
324
 
          this_fer->last_byte_used += min_length;
325
 
        } else {  /* try the next fer */
326
 
          this_fer = this_fer->next;
327
 
        }  /* end else try the next fer */
328
 
      }  /* end else this fer describes an eligible allocation */
329
 
    }  /* end while */
330
 
 
331
 
    if ( (awsp_rc == FSCK_OK) && (wsp_ptr == NULL) ) {  
332
 
        /*
333
 
         * nothing fatal but we didn't find the
334
 
         * storage yet
335
 
         */
336
 
      awsp_rc = alloc_wsp_extent( min_length, for_logredo );  /*
337
 
                            * will allocate some number of memory segments
338
 
                            *  and put the fer describing it on the beginning
339
 
                            *  of the list.
340
 
                            */
341
 
    }  /* end nothing fatal but we didn't find the storage yet */
342
 
  }  /* end while */
343
 
 
344
 
  if ( awsp_rc == FSCK_OK ) {  /* we allocated virtual storage */
345
 
    /*
346
 
     * now initialize the storage
347
 
     */
348
 
    memset( (void *) wsp_ptr, 0, length );
349
 
 
350
 
    *addr_wrksp_ptr = (void *) wsp_ptr;  /* set the return value */
351
 
  }  /* end we allocated virtual storage */
352
 
 
353
 
  return( awsp_rc );
354
 
}  /* end alloc_wrksp */
355
 
 
 
190
        int awsp_rc = FSCK_OK;
 
191
        char *wsp_ptr = NULL;
 
192
        struct wsp_ext_rec *this_fer;
 
193
        uint32_t bytes_avail;
 
194
        uint32_t min_length;
 
195
 
 
196
        *addr_wrksp_ptr = NULL;
 
197
        /* round up to an 8 byte boundary */
 
198
        min_length = ((length + 7) / 8) * 8;
 
199
 
 
200
        while ((wsp_ptr == NULL) && (awsp_rc == FSCK_OK)) {
 
201
                this_fer = agg_recptr->wsp_extent_list;
 
202
 
 
203
                while ((this_fer != NULL) && (wsp_ptr == NULL)
 
204
                       && (awsp_rc == FSCK_OK)) {
 
205
                        if ((for_logredo) && !(this_fer->for_logredo)) {
 
206
                                /*
 
207
                                 * requestor is logredo and
 
208
                                 * fer describes an allocation not for logredo
 
209
                                 */
 
210
                                this_fer = this_fer->next;
 
211
                        } else {
 
212
                                /* this fer describes an eligible allocation */
 
213
                                bytes_avail =
 
214
                                    this_fer->extent_length -
 
215
                                    this_fer->last_byte_used;
 
216
                                if (bytes_avail >= min_length) {
 
217
                                        /* there's enough here */
 
218
                                        wsp_ptr =
 
219
                                            this_fer->extent_addr +
 
220
                                            this_fer->last_byte_used + 1;
 
221
                                        this_fer->last_byte_used += min_length;
 
222
                                } else {
 
223
                                        /* try the next fer */
 
224
                                        this_fer = this_fer->next;
 
225
                                }
 
226
                        }
 
227
                }
 
228
 
 
229
                if ((awsp_rc == FSCK_OK) && (wsp_ptr == NULL)) {
 
230
                        /*
 
231
                         * nothing fatal but we didn't find the
 
232
                         * storage yet
 
233
                         */
 
234
                        /*
 
235
                         * will allocate some number of memory segments
 
236
                         *  and put the fer describing it on the beginning
 
237
                         *  of the list.
 
238
                         */
 
239
                        awsp_rc = alloc_wsp_extent(min_length, for_logredo);
 
240
                }
 
241
        }
 
242
 
 
243
        if (awsp_rc == FSCK_OK) {
 
244
                /* we allocated virtual storage */
 
245
                /*
 
246
                 * now initialize the storage
 
247
                 */
 
248
                memset((void *) wsp_ptr, 0, length);
 
249
 
 
250
                /* set the return value */
 
251
                *addr_wrksp_ptr = (void *) wsp_ptr;
 
252
        }
 
253
        return (awsp_rc);
 
254
}
356
255
 
357
256
/****************************************************************************
358
257
 * NAME: alloc_wsp_extent
366
265
 *      minimum_length - input - minimum number of bytes of contiguous storage
367
266
 *                               needed
368
267
 *
369
 
 * NOTES:
370
 
 *
371
268
 * RETURNS:
372
269
 *      success: FSCK_OK
373
270
 *      failure: something else
374
271
 */
375
 
retcode_t alloc_wsp_extent ( reg_idx_t  minimum_length,
376
 
                             int        for_logredo      )
 
272
int alloc_wsp_extent(uint32_t minimum_length, int for_logredo)
377
273
{
378
 
  retcode_t  awe_rc = FSCK_OK;
379
 
  wsp_ext_rec_ptr  new_fer;
380
 
  int32_t    extent_length = MEMSEGSIZE;
381
 
  char       *extent_addr = NULL;
382
 
  int8_t     from_high_memory = 0;
383
 
 
384
 
  /*
385
 
   * the user has specified the minimum needed.  We must allocate
386
 
   * at least 16 more than that because we're going to use 16 bytes
387
 
   * at the beginning to keep track of it.
388
 
   */
389
 
  while ( extent_length < (minimum_length + 16) ) {
390
 
    extent_length += MEMSEGSIZE;
391
 
  }
392
 
 
393
 
  wsp_dynstg_object = dynstg_iobufs;
394
 
  wsp_dynstg_action = dynstg_allocation;
395
 
 
396
 
  extent_addr = (char *) malloc(extent_length);
397
 
 
398
 
  if ( extent_addr == NULL ) { /* allocation failure */
399
 
    awe_rc = FSCK_FAILED_DYNSTG_EXHAUST4;
400
 
    if ( ! for_logredo ) {
401
 
      sprintf( message_parm_0, "%d", wsp_dynstg_action );
402
 
      msgprms[0] = message_parm_0;
403
 
      msgprmidx[0] = 0;
404
 
      sprintf( message_parm_1, "%d", dynstg_wspext );
405
 
      msgprms[1] = message_parm_1;
406
 
      msgprmidx[1] = 0;
407
 
      fsck_send_msg( fsck_EXHDYNSTG, 0, 2 );
408
 
    }  /* end not for logredo */
409
 
  } else {  /* got the dynamic storage  */
410
 
    /*
411
 
     * use the first 16 bytes of it to keep track of it
412
 
     */
413
 
    new_fer = (wsp_ext_rec_ptr) extent_addr;
414
 
    new_fer->extent_length = extent_length;
415
 
    new_fer->for_logredo = for_logredo;
416
 
    new_fer->from_high_memory = from_high_memory;
417
 
    new_fer->extent_addr = extent_addr;
418
 
    new_fer->last_byte_used = sizeof(fsck_extent_record) - 1;
419
 
 
420
 
    new_fer->next = agg_recptr->wsp_extent_list;
421
 
    agg_recptr->wsp_extent_list = new_fer;
422
 
  }  /* end else got the dynamic storage */
423
 
 
424
 
  return( awe_rc );
425
 
}  /* end alloc_wsp_extent */
426
 
 
 
274
        int awe_rc = FSCK_OK;
 
275
        struct wsp_ext_rec *new_fer;
 
276
        int32_t extent_length = MEMSEGSIZE;
 
277
        char *extent_addr = NULL;
 
278
        int8_t from_high_memory = 0;
 
279
 
 
280
        /*
 
281
         * the user has specified the minimum needed.  We must allocate
 
282
         * at least 16 more than that because we're going to use 16 bytes
 
283
         * at the beginning to keep track of it.
 
284
         */
 
285
        while (extent_length < (minimum_length + 16)) {
 
286
                extent_length += MEMSEGSIZE;
 
287
        }
 
288
 
 
289
        wsp_dynstg_object = dynstg_iobufs;
 
290
        wsp_dynstg_action = dynstg_allocation;
 
291
 
 
292
        extent_addr = (char *) malloc(extent_length);
 
293
 
 
294
        if (extent_addr == NULL) {
 
295
                /* allocation failure */
 
296
                awe_rc = FSCK_FAILED_DYNSTG_EXHAUST4;
 
297
                if (!for_logredo) {
 
298
                        fsck_send_msg(fsck_EXHDYNSTG, wsp_dynstg_action,
 
299
                                      dynstg_wspext);
 
300
                }
 
301
        } else {
 
302
                /* got the dynamic storage  */
 
303
                /*
 
304
                 * use the first 16 bytes of it to keep track of it
 
305
                 */
 
306
                new_fer = (struct wsp_ext_rec *) extent_addr;
 
307
                new_fer->extent_length = extent_length;
 
308
                new_fer->for_logredo = for_logredo;
 
309
                new_fer->from_high_memory = from_high_memory;
 
310
                new_fer->extent_addr = extent_addr;
 
311
                new_fer->last_byte_used = sizeof (struct wsp_ext_rec) - 1;
 
312
 
 
313
                new_fer->next = agg_recptr->wsp_extent_list;
 
314
                agg_recptr->wsp_extent_list = new_fer;
 
315
        }
 
316
        return (awe_rc);
 
317
}
427
318
 
428
319
/****************************************************************************
429
 
 * NAME: blkall_decrement_owners
 
320
 * NAME: blkall_mark_free
430
321
 *
431
 
 * FUNCTION: Adjust the fsck workspace to show one less owner for the
432
 
 *           indicated block.
 
322
 * FUNCTION: Adjust the fsck workspace to show the indicated blocks are no
 
323
 *           longer used.
433
324
 *
434
325
 * PARAMETERS:
435
 
 *      blk_num  - input - ordinal number of the filesystem block whose owner
436
 
 *                         count is to be adjusted.
437
 
 *
438
 
 * NOTES:
 
326
 *      first_block  - input - ordinal number of the first filesystem block
 
327
 *                             whose owner count is to be adjusted.
 
328
 *      last_block   - input - ordinal number of the last filesystem block
 
329
 *                             whose owner count is to be adjusted.
439
330
 *
440
331
 * RETURNS:
441
332
 *      success: FSCK_OK
442
333
 *      failure: something else
 
334
 *
 
335
 * NOTE:
 
336
 *      This could be written to be more efficient, but it's a big
 
337
 *      improvement over how it used to be.
443
338
 */
444
 
retcode_t blkall_decrement_owners ( fsblkidx_t  blk_num )
 
339
int blkall_mark_free(int64_t first_block, int64_t last_block)
445
340
{
446
 
  retcode_t    ddo_rc = FSCK_OK;
447
 
  dupall_blkrec_ptr  this_blkrec;
448
 
  dupall_blkrec_tkn  this_blktkn;
449
 
  mappgidx_t   page_num;
450
 
  reg_idx_t    word_offset;
451
 
  fsck_dword_bitmask_t  bit_mask;
452
 
  blk_pageptr  this_page;
453
 
  fsck_bitmap_ptr  this_word;
454
 
 
455
 
  /*
456
 
   * if the given block number is a multiply-allocated block,
457
 
   * decrement its count of inode owners.
458
 
   */
459
 
  ddo_rc = dupall_find_blkrec( blk_num, &this_blkrec, &this_blktkn );
460
 
  if ( this_blkrec != NULL ) {  /* block is multiply-allocated */
461
 
    this_blkrec->owner_count--;
462
 
 
463
 
    if ( this_blkrec->owner_count == 1 ) {  /* now only singly-allocated */
464
 
      if ( !(this_blkrec->first_ref_resolved) ) {
465
 
        agg_recptr->unresolved_1stref_count--;
466
 
      }
467
 
      agg_recptr->dup_block_count--;
468
 
      ddo_rc = dupall_extract_blkrec( this_blkrec, this_blktkn ); /* take
469
 
                          * the block off the list of multiply-allocated
470
 
                          * blocks
471
 
                          */
472
 
    }  /* end now only singly-allocated */
473
 
  } else {  /* the block is not multiply-allocated */
474
 
    ddo_rc = blkmap_find_bit( blk_num, &page_num, &word_offset, &bit_mask);
475
 
    ddo_rc = blkmap_get_page( page_num, &this_page );
476
 
    if ( ddo_rc == FSCK_OK ) { /* got the page */
477
 
      this_word = (fsck_bitmap_ptr) ((char *) this_page + word_offset);
478
 
      (*this_word) &= ~bit_mask;  /*
479
 
                          * mark it not allocated at all
480
 
                          */
481
 
      ddo_rc = blkmap_put_page( page_num );  /* write it to workspace */
482
 
    }  /* end got the page */
483
 
  }  /* end the block is not multiply-allocated */
484
 
 
485
 
  return( ddo_rc );
486
 
}  /* end blkall_decrement_owners() */
487
 
 
 
341
        int64_t blk_num;
 
342
        int ddo_rc = FSCK_OK;
 
343
        int64_t page_num;
 
344
        int64_t last_page_num = -1;
 
345
        uint32_t word_offset;
 
346
        uint32_t bit_mask;
 
347
        struct fsck_blk_map_page *this_page;
 
348
        uint32_t *this_word;
 
349
 
 
350
        for (blk_num = first_block; blk_num <= last_block; blk_num++) {
 
351
                blkmap_find_bit(blk_num, &page_num, &word_offset, &bit_mask);
 
352
                if (page_num != last_page_num) {
 
353
                        if (last_page_num != -1)
 
354
                                blkmap_put_page(last_page_num);
 
355
                        ddo_rc = blkmap_get_page(page_num, &this_page);
 
356
                        if (ddo_rc)
 
357
                                return ddo_rc;
 
358
                        last_page_num = page_num;
 
359
                }
 
360
                this_word = (uint32_t *) ((char *) this_page + word_offset);
 
361
                /* mark it not allocated */
 
362
                (*this_word) &= ~bit_mask;
 
363
        }
 
364
 
 
365
        if (last_page_num != -1)
 
366
                blkmap_put_page(last_page_num);
 
367
 
 
368
        return (FSCK_OK);
 
369
}
488
370
 
489
371
/****************************************************************************
490
372
 * NAME: blkall_increment_owners
493
375
 *           indicated block.
494
376
 *
495
377
 * PARAMETERS:
496
 
 *      blk_num  - input - ordinal number of the filesystem block whose owner
497
 
 *                         count is to be adjusted.
498
 
 *
499
 
 * NOTES:
 
378
 *      first_block  - input - ordinal number of the first filesystem block
 
379
 *                             whose owner count is to be adjusted.
 
380
 *      last_block   - input - ordinal number of the first filesystem block
 
381
 *                             whose owner count is to be adjusted.
 
382
 *      msg_info_ptr - input - information needed to issue messages for this
 
383
 *                             extent.  If NULL, no messages will be issued
500
384
 *
501
385
 * RETURNS:
502
 
 *      success: FSCK_OK
503
 
 *      failure: something else
 
386
 *      success: 0, or 1 if multiply-allocated blocks found
 
387
 *      failure: something less than 0
504
388
 */
505
 
retcode_t blkall_increment_owners ( fsblkidx_t  blk_num )
 
389
int blkall_increment_owners(int64_t first_block,
 
390
                            int64_t last_block,
 
391
                            struct fsck_ino_msg_info *msg_info_ptr)
506
392
{
507
 
  retcode_t    dio_rc = FSCK_OK;
508
 
  dupall_blkrec_ptr  this_blkrec;
509
 
  dupall_blkrec_tkn  this_blktkn;
510
 
  mappgidx_t   page_num;
511
 
  reg_idx_t    word_offset;
512
 
  fsck_dword_bitmask_t  bit_mask;
513
 
  blk_pageptr  this_page;
514
 
  fsck_bitmap_ptr  this_word;
515
 
  int          is_a_dup = 0;
516
 
 
517
 
  dio_rc = blkmap_find_bit( blk_num, &page_num, &word_offset, &bit_mask );
518
 
  dio_rc = blkmap_get_page( page_num, &this_page );
519
 
 
520
 
  if ( dio_rc == FSCK_OK ) { /* got the page */
521
 
    this_word = (fsck_bitmap_ptr) ((char *) this_page + word_offset);
522
 
 
523
 
    if ( ((*this_word) & bit_mask) != bit_mask ) { 
524
 
        /*
525
 
         * not allocated yet
526
 
         */
527
 
      (*this_word) |= bit_mask; /* mark it allocated */
528
 
      dio_rc = blkmap_put_page( page_num );  /* write it to workspace */
529
 
      if ( dio_rc != FSCK_OK ) {
530
 
        dio_rc = FSCK_FAILED_WRITE_FBLKMP;
531
 
      }  /* end failure here is fatal but return code is in the ... */
532
 
    } else {  /* already allocated */
533
 
      is_a_dup = 1;
534
 
      dio_rc = dupall_find_blkrec( blk_num, &this_blkrec, &this_blktkn );
535
 
 
536
 
      if ( this_blkrec != NULL ) {  /* block is already multiply-allocated */
537
 
        this_blkrec->owner_count++;  /* increment owners */
538
 
      } else {  /* else this is the 2nd owner */
539
 
        dio_rc = dupall_insert_blkrec( blk_num );
540
 
        agg_recptr->dup_block_count++;
541
 
        agg_recptr->unresolved_1stref_count++;
542
 
      }  /* end else this is the 2nd owner */
543
 
    }  /* end else already allocated */
544
 
  }  /* end got the page */
545
 
 
546
 
  if ( dio_rc == FSCK_OK ) {
547
 
    dio_rc = is_a_dup;
548
 
  }
549
 
 
550
 
  return( dio_rc );
551
 
}  /* end blkall_increment_owners() */
552
 
 
 
393
        int dio_rc;
 
394
        int64_t blk_num;
 
395
        int64_t page_num;
 
396
        int64_t last_page_num = -1;
 
397
        uint32_t word_offset;
 
398
        uint32_t bit_mask;
 
399
        struct fsck_blk_map_page *this_page;
 
400
        uint32_t *this_word;
 
401
        int is_a_dup = 0;
 
402
        int64_t first_in_dup_range = 0;
 
403
        int32_t size_of_dup_range = 0;
 
404
 
 
405
        for (blk_num = first_block; blk_num <= last_block; blk_num++) {
 
406
                blkmap_find_bit(blk_num, &page_num, &word_offset, &bit_mask);
 
407
                if (page_num != last_page_num) {
 
408
                        if (last_page_num != -1)
 
409
                                blkmap_put_page(last_page_num);
 
410
                        dio_rc = blkmap_get_page(page_num, &this_page);
 
411
                        if (dio_rc)
 
412
                                return dio_rc;
 
413
                        last_page_num = page_num;
 
414
                }
 
415
                this_word = (uint32_t *) ((char *) this_page + word_offset);
 
416
 
 
417
                if (((*this_word) & bit_mask) != bit_mask) {
 
418
                        /*
 
419
                         * not allocated yet
 
420
                         */
 
421
                        /* mark it allocated */
 
422
                        (*this_word) |= bit_mask;
 
423
 
 
424
                        /* Record previously found duplicate range */
 
425
                        if (size_of_dup_range) {
 
426
                                if (msg_info_ptr)
 
427
                                    fsck_send_msg(fsck_DUPBLKREF,
 
428
                                        size_of_dup_range,
 
429
                                        (long long) first_in_dup_range,
 
430
                                        fsck_ref_msg(msg_info_ptr->msg_inotyp),
 
431
                                        fsck_ref_msg(msg_info_ptr->msg_inopfx),
 
432
                                        msg_info_ptr->msg_inonum);
 
433
                                dio_rc = dupall_insert_blkrec(
 
434
                                                first_in_dup_range,
 
435
                                                first_in_dup_range +
 
436
                                                        size_of_dup_range - 1,
 
437
                                                NULL);
 
438
                                if (dio_rc)
 
439
                                        return dio_rc;
 
440
                                agg_recptr->dup_block_count++;
 
441
                                agg_recptr->unresolved_1stref_count++;
 
442
                                size_of_dup_range = 0;
 
443
                                first_in_dup_range = 0;
 
444
                                is_a_dup = 1;
 
445
                        }
 
446
                } else {
 
447
                        /* already allocated */
 
448
                        if (!size_of_dup_range++)
 
449
                                first_in_dup_range = blk_num;
 
450
                }
 
451
        }
 
452
 
 
453
        if (last_page_num != -1)
 
454
                blkmap_put_page(last_page_num);
 
455
 
 
456
        /* Record duplicate range */
 
457
        if (size_of_dup_range) {
 
458
                if (msg_info_ptr)
 
459
                    fsck_send_msg(fsck_DUPBLKREF, size_of_dup_range,
 
460
                                  (long long) first_in_dup_range,
 
461
                                  fsck_ref_msg(msg_info_ptr->msg_inotyp),
 
462
                                  fsck_ref_msg(msg_info_ptr->msg_inopfx),
 
463
                                  msg_info_ptr->msg_inonum);
 
464
                dio_rc = dupall_insert_blkrec(first_in_dup_range,
 
465
                                first_in_dup_range + size_of_dup_range - 1,
 
466
                                NULL);
 
467
                if (dio_rc)
 
468
                        return dio_rc;
 
469
                agg_recptr->dup_block_count++;
 
470
                agg_recptr->unresolved_1stref_count++;
 
471
                is_a_dup = 1;
 
472
        }
 
473
 
 
474
        return (is_a_dup);
 
475
}
553
476
 
554
477
/****************************************************************************
555
 
 * NAME: blkall_ref_check
 
478
 * NAME: blkall_split_blkrec
556
479
 *
557
 
 * FUNCTION: Determine whether the given block is multiply-allocated and, if
558
 
 *           so, whether the first reference to it is unresolved.  (In this
559
 
 *           case, the current reference must be the first reference.)
 
480
 * FUNCTION: Split the current duplicate block record
560
481
 *
561
482
 * PARAMETERS:
562
 
 *      blk_num       - input - ordinal number of the filesystem block to be
563
 
 *                              checked
564
 
 *      ref_resolved  - input - pointer to a variable in which the results of the
565
 
 *                              query are returned.  If the current reference is
566
 
 *                              the first reference to a multiply-allocated block,
567
 
 *                              -1 is returned.  Otherwise, 0 is returned.
568
 
 *
569
 
 * NOTES:
570
 
 *
 
483
 *      blkrec        - input - duplicate block record to be split
 
484
 *      first_block   - input - first block of range whose intersection with
 
485
 *                              blkrec causes the split
 
486
 *      last_block    - input - last block of range whose intersection with
 
487
 *                              blkrec causes the split
571
488
 * RETURNS:
572
489
 *      success: FSCK_OK
573
490
 *      failure: something else
574
491
 */
575
 
retcode_t blkall_ref_check ( fsblkidx_t  blk_num,
576
 
                             int         *ref_resolved )
 
492
int blkall_split_blkrec(struct dupall_blkrec *blkrec,
 
493
                     int64_t first_block,
 
494
                     int64_t last_block)
577
495
{
578
 
  retcode_t  brc_rc = FSCK_OK;
579
 
  dupall_blkrec_ptr  this_blkrec;
580
 
  dupall_blkrec_tkn  this_blktkn;
581
 
 
582
 
  /*
583
 
   * if the given block number is a multiply-allocated block with
584
 
   * an unresolved first reference, this must be that first reference
585
 
   */
586
 
  brc_rc = dupall_find_blkrec( blk_num, &this_blkrec, &this_blktkn );
587
 
 
588
 
  if ( (brc_rc == FSCK_OK) && (this_blkrec != NULL) ) {  
589
 
      /*
590
 
       * block is multiply-allocated
591
 
       */
592
 
    if ( this_blkrec->first_ref_resolved == 0 ) { 
593
 
        /*
594
 
         * haven't seen the first ref yet
595
 
         */
596
 
      this_blkrec->first_ref_resolved = 1;
597
 
      agg_recptr->unresolved_1stref_count--;
598
 
      *ref_resolved = -1;
599
 
    } else {  /* we have already resolved the first ref for this block */
600
 
      *ref_resolved = 0;
601
 
    }  /* end else we have already resolved the first ref ... */
602
 
  } else {  /* block is not multiply-allocated */
603
 
    *ref_resolved = 0;
604
 
  }  /* end else block is not multiply-allocated */
605
 
 
606
 
  return( brc_rc );
607
 
}  /* end blkall_ref_check () */
608
 
 
 
496
        int bsb_rc = FSCK_OK;
 
497
        struct dupall_blkrec *new_blkrec;
 
498
        int64_t temp;
 
499
 
 
500
        if (blkrec->first_blk < first_block) {
 
501
                temp = blkrec->last_blk;
 
502
                blkrec->last_blk = first_block - 1;
 
503
                bsb_rc = dupall_insert_blkrec(first_block, temp, &new_blkrec);
 
504
                if (bsb_rc)
 
505
                        return bsb_rc;
 
506
                new_blkrec->first_ref_resolved = blkrec->first_ref_resolved;
 
507
                new_blkrec->owner_count = blkrec->owner_count;
 
508
                agg_recptr->dup_block_count++;
 
509
                if (!new_blkrec->first_ref_resolved)
 
510
                        agg_recptr->unresolved_1stref_count++;
 
511
 
 
512
                blkrec = new_blkrec;
 
513
        }
 
514
 
 
515
        if (blkrec->last_blk > last_block) {
 
516
                temp = blkrec->last_blk;
 
517
                blkrec->last_blk = last_block;
 
518
                bsb_rc = dupall_insert_blkrec(first_block, temp, &new_blkrec);
 
519
                if (bsb_rc)
 
520
                        return bsb_rc;
 
521
                new_blkrec->first_ref_resolved = blkrec->first_ref_resolved;
 
522
                new_blkrec->owner_count = blkrec->owner_count;
 
523
                agg_recptr->dup_block_count++;
 
524
                if (!new_blkrec->first_ref_resolved)
 
525
                        agg_recptr->unresolved_1stref_count++;
 
526
        }
 
527
 
 
528
        return FSCK_OK;
 
529
}
609
530
 
610
531
/****************************************************************************
611
532
 * NAME: dire_buffer_alloc
618
539
 *                                the address of the allocated buffer (or
619
540
 *                                NULL if no buffer could be allocated)
620
541
 *
621
 
 * NOTES:
622
 
 *
623
542
 * RETURNS:
624
543
 *      success: FSCK_OK
625
544
 *      failure: something else
626
545
 */
627
 
retcode_t dire_buffer_alloc ( dtpage_t  **addr_dnode_ptr )
 
546
int dire_buffer_alloc(dtpage_t ** addr_dnode_ptr)
628
547
{
629
 
  retcode_t  rba_rc = FSCK_OK;
630
 
  reg_idx_t  bufrec_length, bytes_available;
631
 
  recon_bufrec_ptr  bufrec_ptr;
632
 
 
633
 
  if ( agg_recptr->recon_buf_stack != NULL ) {  /* stack not empty */
634
 
    bufrec_ptr = agg_recptr->recon_buf_stack;
635
 
    agg_recptr->recon_buf_stack = bufrec_ptr->stack_next;
636
 
 
637
 
    bufrec_ptr->stack_next = NULL;
638
 
    bufrec_ptr->dnode_blkoff = 0;
639
 
    bufrec_ptr->dnode_byteoff = 0;
640
 
    *addr_dnode_ptr = &(bufrec_ptr->dnode_buf);
641
 
  } else {  /* the stack is empty */
642
 
    bufrec_length = sizeof( struct recon_buf_record );
643
 
    bytes_available = agg_recptr->recon_buf_extent->extent_length -
644
 
                      agg_recptr->recon_buf_extent->last_byte_used;
645
 
 
646
 
    if ( bytes_available < bufrec_length ) {  
647
 
        /* we've used up a whole
648
 
         * extent of dynamic storage -- something
649
 
         * strange is going on
650
 
         */
651
 
      *addr_dnode_ptr = NULL;
652
 
      rba_rc = FSCK_INSUFDSTG4RECON;
653
 
    } else {  /* there is enough dynamic storage for another one */
654
 
      bufrec_ptr = (recon_bufrec_ptr)
655
 
                   (agg_recptr->recon_buf_extent->extent_addr +
656
 
                    agg_recptr->recon_buf_extent->last_byte_used + 1);
657
 
      agg_recptr->recon_buf_extent->last_byte_used += bufrec_length;
658
 
      /*
659
 
       * now initialize the record
660
 
       */
661
 
      wsp_dynstg_object = dynstg_recondnodebuf;
662
 
      wsp_dynstg_action = dynstg_initialization;
663
 
      memset( (void *) bufrec_ptr, 0, bufrec_length );
664
 
      *addr_dnode_ptr = &(bufrec_ptr->dnode_buf);
665
 
    }  /* end else there is enough dynamic storage for another one */
666
 
  }  /* end else the stack is empty */
667
 
 
668
 
  return( rba_rc );
669
 
}  /* end dire_buffer_alloc */
670
 
 
 
548
        int rba_rc = FSCK_OK;
 
549
        uint32_t bufrec_length, bytes_available;
 
550
        struct recon_buf_record *bufrec_ptr;
 
551
 
 
552
        if (agg_recptr->recon_buf_stack != NULL) {
 
553
                /* stack not empty */
 
554
                bufrec_ptr = agg_recptr->recon_buf_stack;
 
555
                agg_recptr->recon_buf_stack = bufrec_ptr->stack_next;
 
556
 
 
557
                bufrec_ptr->stack_next = NULL;
 
558
                bufrec_ptr->dnode_blkoff = 0;
 
559
                bufrec_ptr->dnode_byteoff = 0;
 
560
                *addr_dnode_ptr = &(bufrec_ptr->dnode_buf);
 
561
        } else {
 
562
                /* the stack is empty */
 
563
                bufrec_length = sizeof (struct recon_buf_record);
 
564
                bytes_available = agg_recptr->recon_buf_extent->extent_length -
 
565
                    agg_recptr->recon_buf_extent->last_byte_used;
 
566
 
 
567
                if (bytes_available < bufrec_length) {
 
568
                        /* we've used up a whole
 
569
                         * extent of dynamic storage -- something
 
570
                         * strange is going on
 
571
                         */
 
572
                        *addr_dnode_ptr = NULL;
 
573
                        rba_rc = FSCK_INSUFDSTG4RECON;
 
574
                } else {
 
575
                        /* there is enough dynamic storage for another one */
 
576
                        bufrec_ptr = (struct recon_buf_record *)
 
577
                            (agg_recptr->recon_buf_extent->extent_addr +
 
578
                             agg_recptr->recon_buf_extent->last_byte_used + 1);
 
579
                        agg_recptr->recon_buf_extent->last_byte_used +=
 
580
                            bufrec_length;
 
581
                        /*
 
582
                         * now initialize the record
 
583
                         */
 
584
                        wsp_dynstg_object = dynstg_recondnodebuf;
 
585
                        wsp_dynstg_action = dynstg_initialization;
 
586
                        memset((void *) bufrec_ptr, 0, bufrec_length);
 
587
                        *addr_dnode_ptr = &(bufrec_ptr->dnode_buf);
 
588
                }
 
589
        }
 
590
        return (rba_rc);
 
591
}
671
592
 
672
593
/****************************************************************************
673
594
 * NAME: dire_buffer_release
678
599
 * PARAMETERS:
679
600
 *      dnode_ptr  - input - the address of the buffer to release
680
601
 *
681
 
 * NOTES:
682
 
 *
683
602
 * RETURNS:
684
603
 *      success: FSCK_OK
685
604
 *      failure: something else
686
605
 */
687
 
retcode_t dire_buffer_release ( dtpage_t  *dnode_ptr )
 
606
int dire_buffer_release(dtpage_t * dnode_ptr)
688
607
{
689
 
  retcode_t  rbr_rc = FSCK_OK;
690
 
  recon_bufrec_ptr  bufrec_ptr;
691
 
 
692
 
  bufrec_ptr = (recon_bufrec_ptr) dnode_ptr;
693
 
  bufrec_ptr->stack_next = agg_recptr->recon_buf_stack;
694
 
  agg_recptr->recon_buf_stack = bufrec_ptr;
695
 
 
696
 
  return( rbr_rc );
697
 
}  /* end dire_buffer_release */
698
 
 
 
608
        int rbr_rc = FSCK_OK;
 
609
        struct recon_buf_record *bufrec_ptr;
 
610
 
 
611
        bufrec_ptr = (struct recon_buf_record *) dnode_ptr;
 
612
        bufrec_ptr->stack_next = agg_recptr->recon_buf_stack;
 
613
        agg_recptr->recon_buf_stack = bufrec_ptr;
 
614
 
 
615
        return (rbr_rc);
 
616
}
699
617
 
700
618
/****************************************************************************
701
619
 * NAME: directory_buffers_alloc
706
624
 *              I/O buffers while inserting and removing directory entries
707
625
 *              during file system repair processing.
708
626
 *
709
 
 * PARAMETERS:  none
710
 
 *
711
627
 * NOTES:       The directory buffers are the only use of the VeryLarge Buffer
712
628
 *              during Phase 6 processing.
713
629
 *
720
636
 *      success: FSCK_OK
721
637
 *      failure: something else
722
638
 */
723
 
retcode_t directory_buffers_alloc( )
 
639
int directory_buffers_alloc()
724
640
{
725
 
  retcode_t  dba_rc = FSCK_OK;
726
 
 
727
 
  agg_recptr->vlarge_current_use = USED_FOR_DIRPAGE_BUFS;
728
 
  agg_recptr->recon_buf_extent =
729
 
  (wsp_ext_rec_ptr) agg_recptr->vlarge_buf_ptr;
730
 
 
731
 
  agg_recptr->recon_buf_extent->next = NULL;
732
 
  agg_recptr->recon_buf_extent->extent_length =
733
 
      agg_recptr->vlarge_buf_length;
734
 
  agg_recptr->recon_buf_extent->extent_addr =
735
 
      (char *) agg_recptr->recon_buf_extent;
736
 
  agg_recptr->recon_buf_extent->last_byte_used =
737
 
      sizeof(fsck_extent_record) - 1;
738
 
 
739
 
  return( dba_rc );
740
 
}  /* end directory_buffers_alloc */
741
 
 
 
641
        int dba_rc = FSCK_OK;
 
642
 
 
643
        agg_recptr->vlarge_current_use = USED_FOR_DIRPAGE_BUFS;
 
644
        agg_recptr->recon_buf_extent =
 
645
            (struct wsp_ext_rec *) agg_recptr->vlarge_buf_ptr;
 
646
 
 
647
        agg_recptr->recon_buf_extent->next = NULL;
 
648
        agg_recptr->recon_buf_extent->extent_length =
 
649
            agg_recptr->vlarge_buf_length;
 
650
        agg_recptr->recon_buf_extent->extent_addr =
 
651
            (char *) agg_recptr->recon_buf_extent;
 
652
        agg_recptr->recon_buf_extent->last_byte_used =
 
653
            sizeof (struct wsp_ext_rec) - 1;
 
654
 
 
655
        return (dba_rc);
 
656
}
742
657
 
743
658
/****************************************************************************
744
659
 * NAME: directory_buffers_release
756
671
 *      success: FSCK_OK
757
672
 *      failure: something else
758
673
 */
759
 
retcode_t directory_buffers_release ( )
760
 
{            
761
 
  retcode_t  dbr_rc = FSCK_OK;
762
 
 
763
 
  if ( agg_recptr->recon_buf_extent != NULL ) {  /* something is allocated */
764
 
    agg_recptr->recon_buf_extent = NULL;
765
 
    agg_recptr->vlarge_current_use = NOT_CURRENTLY_USED;
766
 
  }  /* end something is allocated */
767
 
 
768
 
  return( dbr_rc );
769
 
}  /* end directory_buffers_release */
770
 
 
 
674
int directory_buffers_release()
 
675
{
 
676
        int dbr_rc = FSCK_OK;
 
677
 
 
678
        if (agg_recptr->recon_buf_extent != NULL) {
 
679
                /* something is allocated */
 
680
                agg_recptr->recon_buf_extent = NULL;
 
681
                agg_recptr->vlarge_current_use = NOT_CURRENTLY_USED;
 
682
        }
 
683
        return (dbr_rc);
 
684
}
771
685
 
772
686
/****************************************************************************
773
687
 * NAME: dtreeQ_dequeue
786
700
 *      success: FSCK_OK
787
701
 *      failure: something else
788
702
 */
789
 
retcode_t dtreeQ_dequeue ( dtreeQ_elem_ptr  *dtreeQ_elptr )
 
703
int dtreeQ_dequeue(struct dtreeQelem **dtreeQ_elptr)
790
704
{
791
 
  retcode_t  dQd_rc = FSCK_OK;
792
 
 
793
 
  *dtreeQ_elptr = agg_recptr->dtreeQ_front;
794
 
 
795
 
  if ( agg_recptr->dtreeQ_back == agg_recptr->dtreeQ_front ) {  /* empty */
796
 
    agg_recptr->dtreeQ_back = agg_recptr->dtreeQ_front = NULL;
797
 
  } else {  /* not empty */
798
 
    agg_recptr->dtreeQ_front = agg_recptr->dtreeQ_front->next;
799
 
    agg_recptr->dtreeQ_front->prev = NULL;
800
 
  }  /* end else not empty */
801
 
 
802
 
  return( dQd_rc );
803
 
}  /* end dtreeQ_dequeue */
804
 
 
 
705
        int dQd_rc = FSCK_OK;
 
706
 
 
707
        *dtreeQ_elptr = agg_recptr->dtreeQ_front;
 
708
 
 
709
        if (agg_recptr->dtreeQ_back == agg_recptr->dtreeQ_front) {
 
710
                /* empty */
 
711
                agg_recptr->dtreeQ_back = agg_recptr->dtreeQ_front = NULL;
 
712
        } else {
 
713
                /* not empty */
 
714
                agg_recptr->dtreeQ_front = agg_recptr->dtreeQ_front->next;
 
715
                agg_recptr->dtreeQ_front->prev = NULL;
 
716
        }
 
717
        return (dQd_rc);
 
718
}
805
719
 
806
720
/****************************************************************************
807
721
 * NAME: dtreeQ_enqueue
818
732
 *      success: FSCK_OK
819
733
 *      failure: something else
820
734
 */
821
 
retcode_t dtreeQ_enqueue ( dtreeQ_elem_ptr  dtreeQ_elptr )
 
735
int dtreeQ_enqueue(struct dtreeQelem *dtreeQ_elptr)
822
736
{
823
 
  retcode_t  dQe_rc = FSCK_OK;
824
 
 
825
 
  if ( agg_recptr->dtreeQ_back == NULL ) {  /* empty queue */
826
 
    agg_recptr->dtreeQ_back = agg_recptr->dtreeQ_front = dtreeQ_elptr;
827
 
    dtreeQ_elptr->prev = dtreeQ_elptr->next = NULL;
828
 
  } else {  /* queue not empty */
829
 
    dtreeQ_elptr->next = NULL;
830
 
    dtreeQ_elptr->prev = agg_recptr->dtreeQ_back;
831
 
    agg_recptr->dtreeQ_back->next = dtreeQ_elptr;
832
 
    agg_recptr->dtreeQ_back = dtreeQ_elptr;
833
 
  }  /* end else queue not empty */
834
 
 
835
 
  return( dQe_rc );
836
 
}  /* end dtreeQ_enqueue  */
837
 
 
 
737
        int dQe_rc = FSCK_OK;
 
738
 
 
739
        if (agg_recptr->dtreeQ_back == NULL) {
 
740
                /* empty queue */
 
741
                agg_recptr->dtreeQ_back = agg_recptr->dtreeQ_front =
 
742
                    dtreeQ_elptr;
 
743
                dtreeQ_elptr->prev = dtreeQ_elptr->next = NULL;
 
744
        } else {
 
745
                /* queue not empty */
 
746
                dtreeQ_elptr->next = NULL;
 
747
                dtreeQ_elptr->prev = agg_recptr->dtreeQ_back;
 
748
                agg_recptr->dtreeQ_back->next = dtreeQ_elptr;
 
749
                agg_recptr->dtreeQ_back = dtreeQ_elptr;
 
750
        }
 
751
 
 
752
        return (dQe_rc);
 
753
}
838
754
 
839
755
/****************************************************************************
840
756
 * NAME: dtreeQ_get_elem
845
761
 *      addr_dtreeQ_ptr  - input - pointer to a variable in which the address
846
762
 *                                 of the new element should be returned.
847
763
 *
848
 
 * NOTES:
849
 
 *
850
764
 * RETURNS:
851
765
 *      success: FSCK_OK
852
766
 *      failure: something else
853
767
 */
854
 
retcode_t dtreeQ_get_elem ( dtreeQ_elem_ptr  *addr_dtreeQ_ptr )
 
768
int dtreeQ_get_elem(struct dtreeQelem **addr_dtreeQ_ptr)
855
769
{
856
 
  retcode_t  dge_rc = FSCK_OK;
857
 
  int        I_am_logredo = 0;
858
 
 
859
 
  if ( agg_recptr->free_dtreeQ != NULL ) { /* free list isn't empty */
860
 
    *addr_dtreeQ_ptr = agg_recptr->free_dtreeQ;
861
 
    agg_recptr->free_dtreeQ = agg_recptr->free_dtreeQ->next;
862
 
    memset( (void *) (*addr_dtreeQ_ptr), 0, dtreeQ_elem_length );
863
 
  } else {  /* else the free list is empty */
864
 
    dge_rc = alloc_wrksp( dtreeQ_elem_length, dynstg_dtreeQ_elem,
865
 
                          I_am_logredo, (void**) addr_dtreeQ_ptr );
866
 
  }  /* end else the free list is empty */
867
 
 
868
 
  return( dge_rc );
869
 
}  /* end dtreeQ_get_elem */
870
 
 
 
770
        int dge_rc = FSCK_OK;
 
771
        int I_am_logredo = 0;
 
772
 
 
773
        if (agg_recptr->free_dtreeQ != NULL) {
 
774
                /* free list isn't empty */
 
775
                *addr_dtreeQ_ptr = agg_recptr->free_dtreeQ;
 
776
                agg_recptr->free_dtreeQ = agg_recptr->free_dtreeQ->next;
 
777
                memset((void *) (*addr_dtreeQ_ptr), 0, dtreeQ_elem_length);
 
778
        } else {
 
779
                /* else the free list is empty */
 
780
                dge_rc = alloc_wrksp(dtreeQ_elem_length, dynstg_dtreeQ_elem,
 
781
                                     I_am_logredo, (void **) addr_dtreeQ_ptr);
 
782
        }
 
783
 
 
784
        return (dge_rc);
 
785
}
871
786
 
872
787
/****************************************************************************
873
788
 * NAME: dtreeQ_rel_elem
877
792
 * PARAMETERS:
878
793
 *      dtreeQ_elptr  - input - the address of the element to release
879
794
 *
880
 
 * NOTES:
881
 
 *
882
795
 * RETURNS:
883
796
 *      success: FSCK_OK
884
797
 *      failure: something else
885
798
 */
886
 
retcode_t dtreeQ_rel_elem ( dtreeQ_elem_ptr  dtreeQ_elptr )
 
799
int dtreeQ_rel_elem(struct dtreeQelem *dtreeQ_elptr)
887
800
{
888
 
  retcode_t  dQre_rc = FSCK_OK;
889
 
 
890
 
  dtreeQ_elptr->next = agg_recptr->free_dtreeQ;
891
 
  agg_recptr->free_dtreeQ = dtreeQ_elptr;
892
 
 
893
 
  return( dQre_rc );
894
 
}  /* end dtreeQ_rel_elem */
895
 
 
 
801
        int dQre_rc = FSCK_OK;
 
802
 
 
803
        dtreeQ_elptr->next = agg_recptr->free_dtreeQ;
 
804
        agg_recptr->free_dtreeQ = dtreeQ_elptr;
 
805
 
 
806
        return (dQre_rc);
 
807
}
896
808
 
897
809
/****************************************************************************
898
810
 * NAME: dupall_extract_blkrec
902
814
 *
903
815
 * PARAMETERS:
904
816
 *      block_recptr  - input - the address of the record to remove
905
 
 *      block_rectkn  - input - the token which was returned with the address
906
 
 *                              from the find operation.
907
817
 *
908
818
 * NOTES:  The duplicate allocation list is described in the aggregate record,
909
819
 *         field: dup_alloc_lst
910
 
 *
911
 
 *         The token actually contains the address of the list record which
912
 
 *         points to the record to remove (or NULL if the record is at the
913
 
 *         beginning of the list).  This is needed to avoid searching the
914
 
 *         list again since the list is only singly-linked.
915
 
 *
916
 
 * RETURNS:
917
 
 *      success: FSCK_OK
918
 
 *      failure: something else
919
820
 */
920
 
retcode_t dupall_extract_blkrec ( dupall_blkrec_ptr  block_recptr,
921
 
                                  dupall_blkrec_tkn  block_rectkn )
 
821
void dupall_extract_blkrec(struct dupall_blkrec *block_recptr)
 
822
 
922
823
{
923
 
  retcode_t  deb_rc = FSCK_OK;
924
 
 
925
 
  /*
926
 
   * remove it from the list of multiply-allocated block
927
 
   */
928
 
 
929
 
  if ( block_rectkn == NULL ) { /* first in list */
930
 
    agg_recptr->dup_alloc_lst = block_recptr->next;
931
 
  } else {  /* not at front of list */
932
 
    block_rectkn->next = block_recptr->next;
933
 
  }  /* end else not at front of list */
934
 
 
935
 
  /*
936
 
   * release it for reuse
937
 
   */
938
 
  block_recptr->next = agg_recptr->free_dupall_blkrec;
939
 
  agg_recptr->free_dupall_blkrec = block_recptr;
940
 
 
941
 
  return( deb_rc );
942
 
}  /* end dupall_extract_blkrec()  */
943
 
 
 
824
        /*
 
825
         * remove it from the list of multiply-allocated block
 
826
         */
 
827
 
 
828
        if (block_recptr->prev)
 
829
                block_recptr->prev->next = block_recptr->next;
 
830
        else    /* first in list */
 
831
                agg_recptr->dup_alloc_lst = block_recptr->next;
 
832
 
 
833
        if (block_recptr->next)
 
834
                block_recptr->next->prev = block_recptr->prev;
 
835
 
 
836
        /*
 
837
         * release it for reuse
 
838
         */
 
839
        block_recptr->next = agg_recptr->free_dupall_blkrec;
 
840
        agg_recptr->free_dupall_blkrec = block_recptr;
 
841
}
944
842
 
945
843
/****************************************************************************
946
844
 * NAME: dupall_find_blkrec
949
847
 *            allocation list.
950
848
 *
951
849
 * PARAMETERS:
952
 
 *      block_number  - input - ordinal number of the filesystem block to match
953
 
 *      block_recptr  - input - pointer to a variable in which to return the
954
 
 *                              address of the record found.  If no record is
955
 
 *                              found, NULL is returned.
956
 
 *      block_rectkn  - input - pointer to a variable in which to return a token
957
 
 *                              if a record is found.  If no record is found,
958
 
 *                              NULL is returned.
 
850
 *      first_block  - input - ordinal number of the first filesystem block
 
851
 *      last_block  - input - ordinal number of the last filesystem block
959
852
 *
960
853
 * NOTES:  The duplicate allocation list is described in the aggregate record,
961
854
 *         field: dup_alloc_lst
962
855
 *
963
 
 *         The token actually contains the address of the list record which
964
 
 *         points to the record found (or NULL if the record is at the
965
 
 *         beginning of the list).  This is a required input to certain other
966
 
 *         routines which operate on the duplicate allocation list.
967
 
 *
968
856
 * RETURNS:
969
 
 *      success: FSCK_OK
970
 
 *      failure: something else
 
857
 *      success: record found
 
858
 *      failure: NULL
971
859
 */
972
 
retcode_t dupall_find_blkrec ( fsblkidx_t         block_number,
973
 
                               dupall_blkrec_ptr  *block_recptr,
974
 
                               dupall_blkrec_tkn  *block_rectkn  )
 
860
struct dupall_blkrec *dupall_find_blkrec(int64_t first_block,
 
861
                                         int64_t last_block)
975
862
{
976
 
  retcode_t  dfb_rc = FSCK_OK;
977
 
  dupall_blkrec_ptr  prev_blkrec, this_blkrec;
978
 
  int        dfb_done = 0;
979
 
 
980
 
  prev_blkrec = NULL;
981
 
  this_blkrec = agg_recptr->dup_alloc_lst;
982
 
 
983
 
  if ( this_blkrec == NULL ) {  /* empty list */
984
 
    dfb_done = 1;
985
 
  } else {  /* list of multiply-allocated blocks is not empty */
986
 
 
987
 
    while ( !dfb_done ) {
988
 
      if ( this_blkrec->blk_number == block_number ) {  /* found match */
989
 
        dfb_done = 1;
990
 
      } else if ( this_blkrec->blk_number > block_number ) {  
991
 
          /*
992
 
           * won't be a match
993
 
           */
994
 
        dfb_done = 1;
995
 
        prev_blkrec = NULL;
996
 
        this_blkrec = NULL;
997
 
      } else if ( this_blkrec->next == NULL ) {  /* end of list */
998
 
        dfb_done = 1;
999
 
        prev_blkrec = NULL;
1000
 
        this_blkrec = NULL;
1001
 
      } else {  /* try the next one */
1002
 
        prev_blkrec = this_blkrec;
1003
 
        this_blkrec = this_blkrec->next;
1004
 
      }  /* end else try the next one */
1005
 
    }  /* end while */
1006
 
  }  /* end else list of multiply-allocated blocks is not empty */
1007
 
 
1008
 
  *block_recptr = this_blkrec;
1009
 
  *block_rectkn = prev_blkrec;
1010
 
 
1011
 
  return( dfb_rc );
1012
 
}  /* end dupall_find_blkrec() */
1013
 
 
 
863
        struct dupall_blkrec *this_blkrec;
 
864
 
 
865
        for (this_blkrec = agg_recptr->dup_alloc_lst;
 
866
             this_blkrec && this_blkrec->first_blk <= last_block;
 
867
             this_blkrec = this_blkrec->next) {
 
868
                if (this_blkrec->last_blk >= first_block)
 
869
                        return this_blkrec;
 
870
        }
 
871
        return NULL;
 
872
}
1014
873
 
1015
874
/****************************************************************************
1016
875
 * NAME: dupall_get_blkrec
1019
878
 *           block record.
1020
879
 *
1021
880
 * PARAMETERS:
1022
 
 *      addr_blkrec_ptr  - input - pointer to a variable in which the address
1023
 
 *                                 of the new record will be returned.
1024
 
 *
1025
 
 * NOTES:
 
881
 *      none
1026
882
 *
1027
883
 * RETURNS:
1028
 
 *      success: FSCK_OK
1029
 
 *      failure: something else
 
884
 *      success: address of record
 
885
 *      failure: NULL
1030
886
 */
1031
 
retcode_t dupall_get_blkrec ( dupall_blkrec_ptr  *addr_blkrec_ptr )
 
887
struct dupall_blkrec *dupall_get_blkrec(void)
1032
888
{
1033
 
  retcode_t  dgb_rc = FSCK_OK;
1034
 
  int        I_am_logredo = 0;
1035
 
 
1036
 
  if ( agg_recptr->free_dupall_blkrec != NULL ) { /* free list isn't empty */
1037
 
    *addr_blkrec_ptr = agg_recptr->free_dupall_blkrec;
1038
 
    agg_recptr->free_dupall_blkrec = agg_recptr->free_dupall_blkrec->next;
1039
 
  } else {  /* else the free list is empty */
1040
 
    dgb_rc = alloc_wrksp( dupall_blkrec_length, dynstg_dupall_blkrec,
1041
 
                          I_am_logredo, (void **) addr_blkrec_ptr );
1042
 
  }  /* end else the free list is empty */
1043
 
 
1044
 
  return( dgb_rc );
1045
 
}  /* end dupall_get_blkrec */
1046
 
 
 
889
        struct dupall_blkrec *addr_blkrec_ptr;
 
890
        int dgb_rc = FSCK_OK;
 
891
 
 
892
        if (agg_recptr->free_dupall_blkrec != NULL) {
 
893
                /* free list isn't empty */
 
894
                addr_blkrec_ptr = agg_recptr->free_dupall_blkrec;
 
895
                agg_recptr->free_dupall_blkrec = addr_blkrec_ptr->next;
 
896
        } else {
 
897
                /* else the free list is empty */
 
898
                dgb_rc = alloc_wrksp(dupall_blkrec_length, dynstg_dupall_blkrec,
 
899
                                     0, (void **) &addr_blkrec_ptr);
 
900
        }
 
901
        if (dgb_rc == FSCK_OK)
 
902
                return addr_blkrec_ptr;
 
903
 
 
904
        return NULL;
 
905
}
1047
906
 
1048
907
/*****************************************************************************
1049
908
 * NAME: dupall_insert_blkrec
1050
909
 *
1051
 
 * FUNCTION: Allocate a duplicate allocation record for the given block and
1052
 
 *           insert it into the sorted, singly-linked list of duplicate
 
910
 * FUNCTION: Allocate a duplicate allocation record for the given blocks and
 
911
 *           insert it into the sorted, doubly-linked list of duplicate
1053
912
 *           allocation records.
1054
913
 *
1055
914
 * PARAMETERS:
1056
 
 *      block_num  - input - the block number for which the record is to be
1057
 
 *                           allocated.
 
915
 *      first_block - input - the first block number for which the record is
 
916
 *                            to be allocated.
 
917
 *      last_block - input - the last block number for which the record is
 
918
 *                           to be allocated.
1058
919
 *
1059
920
 * NOTES:  The duplicate allocation list is described in the aggregate record,
1060
921
 *         field: dup_alloc_lst
1063
924
 *      success: FSCK_OK
1064
925
 *      failure: something else
1065
926
 */
1066
 
retcode_t dupall_insert_blkrec ( fsblkidx_t  block_num )
 
927
int dupall_insert_blkrec(int64_t first_block, int64_t last_block,
 
928
                         struct dupall_blkrec **blkrec)
1067
929
{
1068
 
  retcode_t  dib_rc = FSCK_OK;
1069
 
  dupall_blkrec_ptr  new_blkrec, prev_blkrec, this_blkrec;
1070
 
  int        dib_done = 0;
1071
 
 
1072
 
  dib_rc = dupall_get_blkrec( &new_blkrec );
1073
 
 
1074
 
  if ( dib_rc == FSCK_OK ) {  /* got a block record */
1075
 
    new_blkrec->blk_number = block_num;
1076
 
    new_blkrec->owner_count = 2;
1077
 
 
1078
 
    if ( agg_recptr->dup_alloc_lst == NULL ) { /* list now empty */
1079
 
      new_blkrec->next = NULL;
1080
 
      agg_recptr->dup_alloc_lst = new_blkrec;
1081
 
    } else {  /* list not empty */
1082
 
      if ( agg_recptr->dup_alloc_lst->blk_number > block_num ) {  
1083
 
          /*
1084
 
           * goes at front
1085
 
           */
1086
 
        new_blkrec->next = agg_recptr->dup_alloc_lst;
1087
 
        agg_recptr->dup_alloc_lst = new_blkrec;
1088
 
      } else { /* doesn't go at the front */
1089
 
        prev_blkrec = agg_recptr->dup_alloc_lst;
1090
 
        this_blkrec = agg_recptr->dup_alloc_lst->next;
1091
 
        while ( !dib_done ) {
1092
 
          if ( this_blkrec == NULL ) {  /* goes at the end */
1093
 
            new_blkrec->next = NULL;
1094
 
            prev_blkrec->next = new_blkrec;
1095
 
            dib_done = 1;
1096
 
          } else if ( this_blkrec->blk_number > block_num ) { 
1097
 
              /*
1098
 
               * goes in front of this one
1099
 
               */
1100
 
            new_blkrec->next = this_blkrec;
1101
 
            prev_blkrec->next = new_blkrec;
1102
 
            dib_done = 1;
1103
 
          } else {  /* try the next one */
1104
 
            prev_blkrec = this_blkrec;
1105
 
            this_blkrec = this_blkrec->next;
1106
 
          }  /* end try the next one */
1107
 
        }  /* end while */
1108
 
      }  /* end else doesn't go at the front */
1109
 
    }  /* end list not empty */
1110
 
  }  /* end got a block record */
1111
 
 
1112
 
  return( dib_rc );
1113
 
}  /* end dupall_insert_blkrec() */
1114
 
 
 
930
        struct dupall_blkrec *new_blkrec;
 
931
        struct dupall_blkrec *prev_blkrec;
 
932
        struct dupall_blkrec *this_blkrec;
 
933
        int dib_done = 0;
 
934
 
 
935
        new_blkrec = dupall_get_blkrec();
 
936
 
 
937
        if (new_blkrec == NULL)
 
938
                return FSCK_FAILED_DYNSTG_EXHAUST1;
 
939
 
 
940
        if (blkrec)
 
941
                *blkrec = new_blkrec;
 
942
 
 
943
        /* got a block record */
 
944
        new_blkrec->first_blk = first_block;
 
945
        new_blkrec->last_blk = last_block;
 
946
        new_blkrec->owner_count = 2;
 
947
 
 
948
        if (agg_recptr->dup_alloc_lst == NULL) {
 
949
                /* list now empty */
 
950
                new_blkrec->next = NULL;
 
951
                new_blkrec->prev = NULL;
 
952
                agg_recptr->dup_alloc_lst = new_blkrec;
 
953
 
 
954
                return FSCK_OK;
 
955
        }
 
956
 
 
957
        /* list not empty */
 
958
        if (agg_recptr->dup_alloc_lst->first_blk > first_block) {
 
959
                /*
 
960
                 * goes at front
 
961
                 */
 
962
                new_blkrec->next = agg_recptr->dup_alloc_lst;
 
963
                new_blkrec->prev = NULL;
 
964
                agg_recptr->dup_alloc_lst = new_blkrec;
 
965
 
 
966
                return FSCK_OK;
 
967
        }
 
968
 
 
969
        /* doesn't go at the front */
 
970
        prev_blkrec = agg_recptr->dup_alloc_lst;
 
971
        this_blkrec = agg_recptr->dup_alloc_lst->next;
 
972
        while (!dib_done) {
 
973
                if (this_blkrec == NULL) {
 
974
                        /* goes at the end */
 
975
                        new_blkrec->next = NULL;
 
976
                        new_blkrec->prev = prev_blkrec;
 
977
                        prev_blkrec->next = new_blkrec;
 
978
                        dib_done = 1;
 
979
                } else if (this_blkrec->first_blk > first_block) {
 
980
                        /*
 
981
                         * goes in front of this one
 
982
                         */
 
983
                        new_blkrec->next = this_blkrec;
 
984
                        new_blkrec->prev = prev_blkrec;
 
985
                        prev_blkrec->next = new_blkrec;
 
986
                        this_blkrec->prev = new_blkrec;
 
987
                        dib_done = 1;
 
988
                } else {
 
989
                        /* try the next one */
 
990
                        prev_blkrec = this_blkrec;
 
991
                        this_blkrec = this_blkrec->next;
 
992
                }
 
993
        }
 
994
        return FSCK_OK;
 
995
}
1115
996
 
1116
997
/****************************************************************************
1117
998
 * NAME: establish_agg_workspace
1127
1008
 *      success: FSCK_OK
1128
1009
 *      failure: something else
1129
1010
 */
1130
 
retcode_t establish_agg_workspace ( )
 
1011
int establish_agg_workspace()
1131
1012
{
1132
 
  retcode_t  eaw_rc = FSCK_OK;
1133
 
  reg_idx_t  mapsize_bytes;
1134
 
  int        I_am_logredo = 0;
1135
 
 
1136
 
  /*
1137
 
   * establish the fsck workspace block map
1138
 
   */
1139
 
  eaw_rc = establish_wsp_block_map( );
1140
 
 
1141
 
  if ( eaw_rc == FSCK_OK ) {  /* block map has been established */
1142
 
    agg_recptr->agg_imap.num_iags = 1;
1143
 
    agg_recptr->agg_imap.bkd_inodes = INOSPEREXT;
1144
 
    agg_recptr->agg_imap.unused_bkd_inodes = INOSPEREXT - 4;
1145
 
    agg_recptr->inode_count = INOSPEREXT;  /* in release 1 there is always
1146
 
                                 * exactly one extent of inodes allocated
1147
 
                                 * for the aggregate
1148
 
                                 */
1149
 
    /*
1150
 
     * now establish the fsck aggregate imap workspace
1151
 
     */
1152
 
    mapsize_bytes = agg_recptr->agg_imap.num_iags *
1153
 
                    sizeof(struct fsck_iag_record);
1154
 
    eaw_rc = alloc_wrksp( mapsize_bytes, dynstg_agg_iagtbl,
1155
 
                          I_am_logredo,
1156
 
                          (void **) &(agg_recptr->agg_imap.iag_tbl) );
1157
 
    if ( eaw_rc == FSCK_OK ) { /* AIM workspace established */
1158
 
      /*
1159
 
       * now establish the fsck aggregate inode table workspace
1160
 
       *
1161
 
       * (since there is always exactly one inode extent, we don't
1162
 
       * bother with an IAG table of pointers to extent address tables
1163
 
       * or with an extent address table of pointers to inode record
1164
 
       * address tables.)
1165
 
       */
1166
 
      eaw_rc = alloc_wrksp( inode_tbl_length, dynstg_ait_inotbl,
1167
 
                            I_am_logredo,
1168
 
                            (void **) &(agg_recptr->AIT_ext0_tbl) );
1169
 
      memcpy( (void *) &(agg_recptr->AIT_ext0_tbl->eyecatcher),
1170
 
              (void *) "InodeTbl", 8 );                             
1171
 
    }  /* end AIM workspace established */                          
1172
 
  }  /* end block map has been established */
1173
 
 
1174
 
  return( eaw_rc );
1175
 
}  /* end establish_agg_workspace */
1176
 
 
 
1013
        int eaw_rc = FSCK_OK;
 
1014
        uint32_t mapsize_bytes;
 
1015
        int I_am_logredo = 0;
 
1016
 
 
1017
        /*
 
1018
         * establish the fsck workspace block map
 
1019
         */
 
1020
        eaw_rc = establish_wsp_block_map();
 
1021
 
 
1022
        if (eaw_rc == FSCK_OK) {
 
1023
                /* block map has been established */
 
1024
                agg_recptr->agg_imap.num_iags = 1;
 
1025
                agg_recptr->agg_imap.bkd_inodes = INOSPEREXT;
 
1026
                agg_recptr->agg_imap.unused_bkd_inodes = INOSPEREXT - 4;
 
1027
                /* in release 1 there is always
 
1028
                 * exactly one extent of inodes allocated
 
1029
                 * for the aggregate
 
1030
                 */
 
1031
                agg_recptr->inode_count = INOSPEREXT;
 
1032
                /*
 
1033
                 * now establish the fsck aggregate imap workspace
 
1034
                 */
 
1035
                mapsize_bytes =
 
1036
                    agg_recptr->agg_imap.num_iags *
 
1037
                    sizeof (struct fsck_iag_record);
 
1038
                eaw_rc =
 
1039
                    alloc_wrksp(mapsize_bytes, dynstg_agg_iagtbl, I_am_logredo,
 
1040
                                (void **) &(agg_recptr->agg_imap.iag_tbl));
 
1041
                if (eaw_rc == FSCK_OK) {
 
1042
                        /* AIM workspace established */
 
1043
                        /*
 
1044
                         * now establish the fsck aggregate inode table workspace
 
1045
                         *
 
1046
                         * (since there is always exactly one inode extent, we don't
 
1047
                         * bother with an IAG table of pointers to extent address tables
 
1048
                         * or with an extent address table of pointers to inode record
 
1049
                         * address tables.)
 
1050
                         */
 
1051
                        eaw_rc =
 
1052
                            alloc_wrksp(inode_tbl_length, dynstg_ait_inotbl,
 
1053
                                        I_am_logredo,
 
1054
                                        (void **) &(agg_recptr->AIT_ext0_tbl));
 
1055
                        memcpy((void *) &(agg_recptr->AIT_ext0_tbl->eyecatcher),
 
1056
                               (void *) "InodeTbl", 8);
 
1057
                }
 
1058
        }
 
1059
        return (eaw_rc);
 
1060
}
1177
1061
 
1178
1062
/****************************************************************************
1179
1063
 * NAME: establish_ea_iobuf
1190
1074
 *      success: FSCK_OK
1191
1075
 *      failure: something else
1192
1076
 */
1193
 
retcode_t establish_ea_iobuf( )
 
1077
int establish_ea_iobuf()
1194
1078
{
1195
 
  retcode_t  eei_rc = FSCK_OK;
1196
 
 
1197
 
  agg_recptr->vlarge_current_use = USED_FOR_EA_BUF;
1198
 
  agg_recptr->ea_buf_ptr = agg_recptr->vlarge_buf_ptr;
1199
 
 
1200
 
  wsp_dynstg_action = dynstg_initialization;
1201
 
  memset( (void *) (agg_recptr->ea_buf_ptr), '\0', EA_IO_BUFSIZE );
1202
 
 
1203
 
  agg_recptr->ea_buf_length = agg_recptr->vlarge_buf_length;
1204
 
  agg_recptr->ea_buf_data_len = 0;
1205
 
  agg_recptr->ea_agg_offset = 0;
1206
 
 
1207
 
  return( eei_rc );
1208
 
}  /* end establish_ea_iobuf */
1209
 
 
 
1079
        int eei_rc = FSCK_OK;
 
1080
 
 
1081
        agg_recptr->vlarge_current_use = USED_FOR_EA_BUF;
 
1082
        agg_recptr->ea_buf_ptr = agg_recptr->vlarge_buf_ptr;
 
1083
 
 
1084
        wsp_dynstg_action = dynstg_initialization;
 
1085
        memset((void *) (agg_recptr->ea_buf_ptr), '\0', EA_IO_BUFSIZE);
 
1086
 
 
1087
        agg_recptr->ea_buf_length = agg_recptr->vlarge_buf_length;
 
1088
        agg_recptr->ea_buf_data_len = 0;
 
1089
        agg_recptr->ea_agg_offset = 0;
 
1090
 
 
1091
        return (eei_rc);
 
1092
}
1210
1093
 
1211
1094
/****************************************************************************
1212
1095
 * NAME: establish_fs_workspace
1222
1105
 *      success: FSCK_OK
1223
1106
 *      failure: something else
1224
1107
 */
1225
 
retcode_t establish_fs_workspace ( )
 
1108
int establish_fs_workspace()
1226
1109
{
1227
 
  retcode_t      efsw_rc = FSCK_OK;
1228
 
  reg_idx_t      mapsize_bytes;
1229
 
  reg_idx_t      buffer_size;
1230
 
  int            aggregate_inode, which_ait = 0;
1231
 
  inoidx_t       inoidx;
1232
 
  dinode_t       *inoptr;
1233
 
  int            I_am_logredo = 0;
1234
 
  IAG_tblptr     IAGtbl;                                             
1235
 
  inoext_tblptr  inoexttbl;                                      
1236
 
  ino_tblptr     inotbl;                                             
1237
 
 
1238
 
  /*
1239
 
   * allocate a buffer in which path names can be constructed
1240
 
   */
1241
 
  buffer_size = (JFS_PATH_MAX + 2) * sizeof( char );
1242
 
  efsw_rc = alloc_wrksp( buffer_size, dynstg_fsit_map,
1243
 
                         I_am_logredo,
1244
 
                         (void **) &(agg_recptr->path_buffer) );
1245
 
 
1246
 
  if ( efsw_rc == FSCK_OK ) {  /* got it */
1247
 
    agg_recptr->path_buffer_length = buffer_size;
1248
 
    /*
1249
 
     * Figure out how many IAGs have been allocated for the fileset.
1250
 
     * (Note that in release 1 there is always exactly 1 fileset in the
1251
 
     * aggregate)
1252
 
     *
1253
 
     * At this point the aggregate inode describing the fileset has been
1254
 
     * validated.  The data described by that inode is 1 page of control
1255
 
     * information plus some number of IAGs.  di_size is the number of
1256
 
     * bytes allocated for that data.
1257
 
     */
1258
 
    if ( agg_recptr->primary_ait_4part2 ) {
1259
 
      which_ait = fsck_primary;
1260
 
      efsw_rc = ait_special_read_ext1( fsck_primary );
1261
 
      if ( efsw_rc != FSCK_OK ) {  /* read failed */
1262
 
        report_readait_error( efsw_rc,
1263
 
                              FSCK_FAILED_CANTREADAITEXTC,
1264
 
                              fsck_primary );
1265
 
        efsw_rc = FSCK_FAILED_CANTREADAITEXTC;
1266
 
      }  /* end read failed */
1267
 
    } else {
1268
 
      which_ait = fsck_secondary;
1269
 
      efsw_rc = ait_special_read_ext1( fsck_secondary );
1270
 
      if ( efsw_rc != FSCK_OK ) {  /* read failed */
1271
 
        report_readait_error( efsw_rc,
1272
 
                              FSCK_FAILED_CANTREADAITEXTD,
1273
 
                              fsck_secondary );
1274
 
        efsw_rc = FSCK_FAILED_CANTREADAITEXTD;
1275
 
      }  /* end read failed */
1276
 
    }
1277
 
  }  /* end got it */
1278
 
 
1279
 
  if ( efsw_rc == FSCK_OK ) { /* got the first AIT extent */
1280
 
    aggregate_inode = -1;
1281
 
    inoidx = FILESYSTEM_I;
1282
 
    efsw_rc = inode_get( aggregate_inode, which_ait, inoidx, &inoptr );
1283
 
 
1284
 
    if ( efsw_rc == FSCK_OK ) {  /* got the fileset IT inode */
1285
 
      agg_recptr->fset_imap.num_iags = (inoptr->di_size/SIZE_OF_MAP_PAGE) - 1;
1286
 
      agg_recptr->fset_inode_count = agg_recptr->fset_imap.num_iags * INOSPERIAG; /*
1287
 
                                 * a high estimate of the inodes
1288
 
                                 * allocated for the fileset
1289
 
                                 */
1290
 
      /*
1291
 
        * now establish the fsck fileset imap workspace
1292
 
        */
1293
 
      if (efsw_rc == FSCK_OK ) { /* inode map established */
1294
 
        mapsize_bytes = agg_recptr->fset_imap.num_iags *
1295
 
                        sizeof(struct fsck_iag_record);
1296
 
        efsw_rc = alloc_wrksp( mapsize_bytes, dynstg_agg_iagtbl,
1297
 
                               I_am_logredo,
1298
 
                               (void **) &(agg_recptr->fset_imap.iag_tbl) );
1299
 
        if ( efsw_rc == FSCK_OK ) {  /* inode map workspace allocated */
1300
 
          /*
1301
 
           * now establish the fsck fileset imap workspace
1302
 
           *
1303
 
           * We start out knowing that IAG 0, extent 0 is allocated and
1304
 
           * has an inode in use.  We'll allocate enough to cover that.
1305
 
           */
1306
 
          mapsize_bytes = 8 +
1307
 
                          agg_recptr->fset_imap.num_iags * sizeof(inoext_tblptr); 
1308
 
          efsw_rc = alloc_wrksp( mapsize_bytes, dynstg_fsit_iagtbl,
1309
 
                                 I_am_logredo, (void **) &IAGtbl );               
1310
 
          if ( efsw_rc == FSCK_OK ) {  /* we got the IAG table */
1311
 
            memcpy( (void *) &(IAGtbl->eyecatcher), (void *) "FSAITIAG", 8 ); 
1312
 
            agg_recptr->FSIT_IAG_tbl = IAGtbl;                                      
1313
 
 
1314
 
            efsw_rc = alloc_wrksp( inode_ext_tbl_length, dynstg_fsit_inoexttbl,
1315
 
                                   I_am_logredo, (void **) &inoexttbl ); 
1316
 
            if ( efsw_rc == FSCK_OK ) {  /* we got the inode extent table */
1317
 
              memcpy( (void *) &(inoexttbl->eyecatcher), (void *) "FSAITEXT", 8 );
1318
 
              IAGtbl->inoext_tbl[0] = inoexttbl;                                  
1319
 
              efsw_rc = alloc_wrksp( inode_tbl_length, dynstg_fsit_inotbl,
1320
 
                                     I_am_logredo, (void **) &inotbl );    
1321
 
              if ( efsw_rc == FSCK_OK ) {  /* we got the inode table */
1322
 
                memcpy( (void *) &(inotbl->eyecatcher), (void *) "FSAITINO", 8 );
1323
 
                inoexttbl->inotbl[0] = inotbl;                                   
1324
 
              }  /* end we got the inode table */                                  
1325
 
            }  /* end we got the inode extent table */
1326
 
          }  /* end we got the IAG table */
1327
 
        }  /* end inode map workspace allocated */
1328
 
      }  /* end inode map established */
1329
 
    }  /* end got the fileset IT inode */
1330
 
  }  /* end got the first AIT extent */
1331
 
 
1332
 
  return( efsw_rc );
1333
 
}  /* end establish_fs_workspace */
1334
 
 
 
1110
        int efsw_rc = FSCK_OK;
 
1111
        uint32_t mapsize_bytes;
 
1112
        uint32_t buffer_size;
 
1113
        int aggregate_inode, which_ait = 0;
 
1114
        uint32_t inoidx;
 
1115
        struct dinode *inoptr;
 
1116
        int I_am_logredo = 0;
 
1117
        struct IAG_tbl_t *IAGtbl;
 
1118
        struct inode_ext_tbl_t *inoexttbl;
 
1119
        struct inode_tbl_t *inotbl;
 
1120
 
 
1121
        /*
 
1122
         * allocate a buffer in which path names can be constructed
 
1123
         */
 
1124
        buffer_size = (JFS_PATH_MAX + 2) * sizeof (char);
 
1125
        efsw_rc = alloc_wrksp(buffer_size, dynstg_fsit_map,
 
1126
                              I_am_logredo,
 
1127
                              (void **) &(agg_recptr->path_buffer));
 
1128
 
 
1129
        if (efsw_rc == FSCK_OK) {
 
1130
                /* got it */
 
1131
                agg_recptr->path_buffer_length = buffer_size;
 
1132
                /*
 
1133
                 * Figure out how many IAGs have been allocated for the fileset.
 
1134
                 * (Note that in release 1 there is always exactly 1 fileset in the
 
1135
                 * aggregate)
 
1136
                 *
 
1137
                 * At this point the aggregate inode describing the fileset has been
 
1138
                 * validated.  The data described by that inode is 1 page of control
 
1139
                 * information plus some number of IAGs.  di_size is the number of
 
1140
                 * bytes allocated for that data.
 
1141
                 */
 
1142
                if (agg_recptr->primary_ait_4part2) {
 
1143
                        which_ait = fsck_primary;
 
1144
                        efsw_rc = ait_special_read_ext1(fsck_primary);
 
1145
                        if (efsw_rc != FSCK_OK) {
 
1146
                                /* read failed */
 
1147
                                report_readait_error(efsw_rc,
 
1148
                                                     FSCK_FAILED_CANTREADAITEXTC,
 
1149
                                                     fsck_primary);
 
1150
                                efsw_rc = FSCK_FAILED_CANTREADAITEXTC;
 
1151
                        }
 
1152
                } else {
 
1153
                        which_ait = fsck_secondary;
 
1154
                        efsw_rc = ait_special_read_ext1(fsck_secondary);
 
1155
                        if (efsw_rc != FSCK_OK) {
 
1156
                                /* read failed */
 
1157
                                report_readait_error(efsw_rc,
 
1158
                                                     FSCK_FAILED_CANTREADAITEXTD,
 
1159
                                                     fsck_secondary);
 
1160
                                efsw_rc = FSCK_FAILED_CANTREADAITEXTD;
 
1161
                        }
 
1162
                }
 
1163
        }
 
1164
        if (efsw_rc != FSCK_OK)
 
1165
                goto efsw_exit;
 
1166
                
 
1167
        /* got the first AIT extent */
 
1168
        aggregate_inode = -1;
 
1169
        inoidx = FILESYSTEM_I;
 
1170
        efsw_rc = inode_get(aggregate_inode, which_ait, inoidx, &inoptr);
 
1171
 
 
1172
        if (efsw_rc != FSCK_OK)
 
1173
                goto efsw_exit;
 
1174
                
 
1175
        /* got the fileset IT inode */
 
1176
        agg_recptr->fset_imap.num_iags = 
 
1177
            (inoptr->di_size / SIZE_OF_MAP_PAGE) - 1;
 
1178
        /*
 
1179
         * a high estimate of the inodes
 
1180
         * allocated for the fileset
 
1181
         */
 
1182
        agg_recptr->fset_inode_count =
 
1183
            agg_recptr->fset_imap.num_iags * INOSPERIAG;
 
1184
        /*
 
1185
         * now establish the fsck fileset imap workspace
 
1186
         */
 
1187
        if (efsw_rc != FSCK_OK)
 
1188
                goto efsw_exit;
 
1189
                
 
1190
        /* inode map established */
 
1191
        mapsize_bytes = agg_recptr->fset_imap.num_iags * 
 
1192
            sizeof (struct fsck_iag_record);
 
1193
        efsw_rc = alloc_wrksp(mapsize_bytes, dynstg_agg_iagtbl, I_am_logredo,
 
1194
                              (void **) &(agg_recptr->fset_imap.iag_tbl));
 
1195
        if (efsw_rc != FSCK_OK)
 
1196
                goto efsw_exit;
 
1197
                
 
1198
        /* inode map workspace allocated */
 
1199
        /*
 
1200
         * now establish the fsck fileset imap workspace
 
1201
         *
 
1202
         * We start out knowing that IAG 0, extent 0 is allocated and
 
1203
         * has an inode in use.  We'll allocate enough to cover that.
 
1204
         */
 
1205
        mapsize_bytes = 8 + agg_recptr->fset_imap.num_iags * 
 
1206
            sizeof (struct inode_ext_tbl_t *);
 
1207
        efsw_rc = alloc_wrksp(mapsize_bytes, dynstg_fsit_iagtbl,
 
1208
                              I_am_logredo, (void **) &IAGtbl);
 
1209
        if (efsw_rc != FSCK_OK)
 
1210
                goto efsw_exit;
 
1211
                
 
1212
        /* we got the IAG table */
 
1213
        memcpy((void *)&(IAGtbl->eyecatcher), (void *) "FSAITIAG", 8);
 
1214
        agg_recptr->FSIT_IAG_tbl = IAGtbl;
 
1215
        efsw_rc = alloc_wrksp(inode_ext_tbl_length, dynstg_fsit_inoexttbl,
 
1216
                              I_am_logredo, (void **) &inoexttbl);
 
1217
        if (efsw_rc != FSCK_OK)
 
1218
                goto efsw_exit;
 
1219
                
 
1220
        /* we got the inode extent table */
 
1221
        memcpy((void *)&(inoexttbl->eyecatcher), (void *)"FSAITEXT", 8);
 
1222
        IAGtbl->inoext_tbl[0] = inoexttbl;
 
1223
        efsw_rc = alloc_wrksp(inode_tbl_length, dynstg_fsit_inotbl,
 
1224
                              I_am_logredo, (void **) &inotbl);
 
1225
        if (efsw_rc == FSCK_OK) {
 
1226
                /* we got the inode table */
 
1227
                memcpy((void *)&(inotbl->eyecatcher), (void *)"FSAITINO", 8);
 
1228
                inoexttbl->inotbl[0] = inotbl;
 
1229
        }
 
1230
        
 
1231
      efsw_exit:        
 
1232
        return (efsw_rc);
 
1233
}
1335
1234
 
1336
1235
/****************************************************************************
1337
1236
 * NAME: establish_io_buffers
1346
1245
 *      success: FSCK_OK
1347
1246
 *      failure: something else
1348
1247
 */
1349
 
retcode_t establish_io_buffers ( )
 
1248
int establish_io_buffers()
1350
1249
{
1351
 
  retcode_t  eiob_rc = FSCK_OK;
1352
 
  int        I_am_logredo = 0;
1353
 
 
1354
 
  eiob_rc = alloc_wrksp( IAG_IO_BUFSIZE, dynstg_iobufs,
1355
 
                         I_am_logredo,
1356
 
                         (void **) &(agg_recptr->iag_buf_ptr) );
1357
 
  if ( eiob_rc == FSCK_OK ) {  /* successful IAG allocation */
1358
 
    agg_recptr->iag_buf_length = sizeof(iag_t);
1359
 
    agg_recptr->iag_buf_data_len = 0;
1360
 
    agg_recptr->iag_agg_offset = 0;
1361
 
    agg_recptr->iag_buf_write = 0;
1362
 
    agg_recptr->bmapdm_buf_ptr = agg_recptr->iag_buf_ptr;
1363
 
    agg_recptr->bmapdm_buf_length = IAG_IO_BUFSIZE;
1364
 
    agg_recptr->bmapdm_buf_data_len = 0;
1365
 
    agg_recptr->bmapdm_agg_offset = 0;
1366
 
    agg_recptr->bmapdm_buf_write = 0;
1367
 
  }  /* end successful IAG allocation */
1368
 
 
1369
 
  if ( eiob_rc == FSCK_OK ) {  /* successful IAG allocation */
1370
 
    eiob_rc = alloc_wrksp( INODE_IO_BUFSIZE, dynstg_iobufs,
1371
 
                           I_am_logredo,
1372
 
                           (void **) &(agg_recptr->ino_buf_ptr) );
1373
 
  }  /* end successful ea buffer allocation */
1374
 
 
1375
 
  if ( eiob_rc == FSCK_OK ) {  /* successful inode allocation */
1376
 
    agg_recptr->ino_buf_length = INODE_IO_BUFSIZE;
1377
 
    agg_recptr->ino_buf_data_len = 0;
1378
 
    agg_recptr->ino_buf_agg_offset = 0;
1379
 
    agg_recptr->ino_buf_write = 0;
1380
 
 
1381
 
    eiob_rc = alloc_wrksp( NODE_IO_BUFSIZE, dynstg_iobufs,
1382
 
                           I_am_logredo,
1383
 
                           (void **) &(agg_recptr->node_buf_ptr) );
1384
 
  }  /* end successful inode allocation */
1385
 
 
1386
 
  if ( eiob_rc == FSCK_OK ) {  /* successful node allocation */
1387
 
    agg_recptr->node_buf_length = NODE_IO_BUFSIZE;
1388
 
    agg_recptr->node_buf_data_len = 0;
1389
 
    agg_recptr->node_agg_offset = 0;
1390
 
    agg_recptr->node_buf_write = 0;
1391
 
 
1392
 
    eiob_rc = alloc_wrksp( MAPLEAF_IO_BUFSIZE, dynstg_iobufs,
1393
 
                           I_am_logredo,
1394
 
                           (void **) &(agg_recptr->mapleaf_buf_ptr) );
1395
 
  }  /* end successful node allocation */
1396
 
 
1397
 
  if ( eiob_rc == FSCK_OK ) {  /* successful mapleaf allocation */
1398
 
    agg_recptr->mapleaf_buf_length = MAPLEAF_IO_BUFSIZE;
1399
 
    agg_recptr->mapleaf_buf_data_len = 0;
1400
 
    agg_recptr->mapleaf_agg_offset = 0;
1401
 
    agg_recptr->mapleaf_buf_write = 0;
1402
 
 
1403
 
    eiob_rc = alloc_wrksp( MAPCTL_IO_BUFSIZE, dynstg_iobufs,
1404
 
                           I_am_logredo,
1405
 
                           (void **) &(agg_recptr->mapctl_buf_ptr) );
1406
 
  }  /* end successful mapleaf allocation */
1407
 
 
1408
 
  if ( eiob_rc == FSCK_OK ) {  /* successful map control allocation */
1409
 
    agg_recptr->mapctl_buf_length = MAPCTL_IO_BUFSIZE;
1410
 
    agg_recptr->mapctl_buf_data_len = 0;
1411
 
    agg_recptr->mapctl_agg_offset = 0;
1412
 
    agg_recptr->mapctl_buf_write = 0;
1413
 
    eiob_rc = alloc_wrksp( BMAPLV_IO_BUFSIZE, dynstg_iobufs,
1414
 
                           I_am_logredo,
1415
 
                           (void **) &(agg_recptr->bmaplv_buf_ptr) );
1416
 
  }  /* end successful map control allocation */
1417
 
 
1418
 
  if ( eiob_rc == FSCK_OK ) {  /* successful map level allocation */
1419
 
    agg_recptr->bmaplv_buf_length = BMAPLV_IO_BUFSIZE;
1420
 
    agg_recptr->bmaplv_buf_data_len = 0;
1421
 
    agg_recptr->bmaplv_agg_offset = 0;
1422
 
    agg_recptr->bmaplv_buf_write = 0;
1423
 
  }  /* successful map level allocation */
1424
 
 
1425
 
  return( eiob_rc );
1426
 
}  /* end establish_io_buffers ( ) */
1427
 
 
 
1250
        int eiob_rc = FSCK_OK;
 
1251
        int I_am_logredo = 0;
 
1252
 
 
1253
        eiob_rc = alloc_wrksp(IAG_IO_BUFSIZE, dynstg_iobufs,
 
1254
                              I_am_logredo,
 
1255
                              (void **) &(agg_recptr->iag_buf_ptr));
 
1256
        if (eiob_rc == FSCK_OK) {
 
1257
                /* successful IAG allocation */
 
1258
                agg_recptr->iag_buf_length = sizeof (struct iag);
 
1259
                agg_recptr->iag_buf_data_len = 0;
 
1260
                agg_recptr->iag_agg_offset = 0;
 
1261
                agg_recptr->iag_buf_write = 0;
 
1262
                agg_recptr->bmapdm_buf_ptr = agg_recptr->iag_buf_ptr;
 
1263
                agg_recptr->bmapdm_buf_length = IAG_IO_BUFSIZE;
 
1264
                agg_recptr->bmapdm_buf_data_len = 0;
 
1265
                agg_recptr->bmapdm_agg_offset = 0;
 
1266
                agg_recptr->bmapdm_buf_write = 0;
 
1267
        }
 
1268
        if (eiob_rc == FSCK_OK) {
 
1269
                /* successful IAG allocation */
 
1270
                eiob_rc = alloc_wrksp(INODE_IO_BUFSIZE, dynstg_iobufs,
 
1271
                                      I_am_logredo,
 
1272
                                      (void **) &(agg_recptr->ino_buf_ptr));
 
1273
        }
 
1274
        if (eiob_rc == FSCK_OK) {
 
1275
                /* successful inode allocation */
 
1276
                agg_recptr->ino_buf_length = INODE_IO_BUFSIZE;
 
1277
                agg_recptr->ino_buf_data_len = 0;
 
1278
                agg_recptr->ino_buf_agg_offset = 0;
 
1279
                agg_recptr->ino_buf_write = 0;
 
1280
 
 
1281
                eiob_rc = alloc_wrksp(NODE_IO_BUFSIZE, dynstg_iobufs,
 
1282
                                      I_am_logredo,
 
1283
                                      (void **) &(agg_recptr->node_buf_ptr));
 
1284
        }
 
1285
        if (eiob_rc == FSCK_OK) {
 
1286
                /* successful node allocation */
 
1287
                agg_recptr->node_buf_length = NODE_IO_BUFSIZE;
 
1288
                agg_recptr->node_buf_data_len = 0;
 
1289
                agg_recptr->node_agg_offset = 0;
 
1290
                agg_recptr->node_buf_write = 0;
 
1291
 
 
1292
                eiob_rc = alloc_wrksp(NODE_IO_BUFSIZE, dynstg_iobufs,
 
1293
                                      I_am_logredo,
 
1294
                                      (void **) &(agg_recptr->dnode_buf_ptr));
 
1295
        }
 
1296
        if (eiob_rc == FSCK_OK) {
 
1297
                /* successful dnode allocation */
 
1298
                agg_recptr->dnode_buf_length = NODE_IO_BUFSIZE;
 
1299
                agg_recptr->dnode_buf_data_len = 0;
 
1300
                agg_recptr->dnode_agg_offset = 0;
 
1301
                agg_recptr->dnode_buf_write = 0;
 
1302
 
 
1303
                eiob_rc = alloc_wrksp(MAPLEAF_IO_BUFSIZE, dynstg_iobufs,
 
1304
                                      I_am_logredo,
 
1305
                                      (void **) &(agg_recptr->mapleaf_buf_ptr));
 
1306
        }
 
1307
        if (eiob_rc == FSCK_OK) {
 
1308
                /* successful mapleaf allocation */
 
1309
                agg_recptr->mapleaf_buf_length = MAPLEAF_IO_BUFSIZE;
 
1310
                agg_recptr->mapleaf_buf_data_len = 0;
 
1311
                agg_recptr->mapleaf_agg_offset = 0;
 
1312
                agg_recptr->mapleaf_buf_write = 0;
 
1313
 
 
1314
                eiob_rc = alloc_wrksp(MAPCTL_IO_BUFSIZE, dynstg_iobufs,
 
1315
                                      I_am_logredo,
 
1316
                                      (void **) &(agg_recptr->mapctl_buf_ptr));
 
1317
        }
 
1318
        if (eiob_rc == FSCK_OK) {
 
1319
                /* successful map control allocation */
 
1320
                agg_recptr->mapctl_buf_length = MAPCTL_IO_BUFSIZE;
 
1321
                agg_recptr->mapctl_buf_data_len = 0;
 
1322
                agg_recptr->mapctl_agg_offset = 0;
 
1323
                agg_recptr->mapctl_buf_write = 0;
 
1324
                eiob_rc = alloc_wrksp(BMAPLV_IO_BUFSIZE, dynstg_iobufs,
 
1325
                                      I_am_logredo,
 
1326
                                      (void **) &(agg_recptr->bmaplv_buf_ptr));
 
1327
        }
 
1328
        if (eiob_rc == FSCK_OK) {
 
1329
                /* successful map level allocation */
 
1330
                agg_recptr->bmaplv_buf_length = BMAPLV_IO_BUFSIZE;
 
1331
                agg_recptr->bmaplv_buf_data_len = 0;
 
1332
                agg_recptr->bmaplv_agg_offset = 0;
 
1333
                agg_recptr->bmaplv_buf_write = 0;
 
1334
        }
 
1335
        return (eiob_rc);
 
1336
}
1428
1337
 
1429
1338
/****************************************************************************
1430
1339
 * NAME: establish_wsp_block_map
1448
1357
 *      success: FSCK_OK
1449
1358
 *      failure: something else
1450
1359
 */
1451
 
retcode_t establish_wsp_block_map ( )
 
1360
int establish_wsp_block_map()
1452
1361
{
1453
 
  retcode_t   ewbm_rc = FSCK_OK;
1454
 
  int32_t     blkmap_size_bytes;
1455
 
  int32_t     blkmap_size_in_pages;
1456
 
  int32_t     idx;
1457
 
  fsblkidx_t  this_device_offset;
1458
 
 
1459
 
  int I_am_logredo = 0;
1460
 
 
1461
 
  ewbm_rc = establish_wsp_block_map_ctl();
1462
 
 
1463
 
  if ( ewbm_rc == FSCK_OK ) {  /* allocated and initialized blk map ctl page */
1464
 
    blkmap_size_bytes = agg_recptr->ondev_wsp_byte_length;
1465
 
    agg_recptr->blkmp_pagecount = blkmap_size_bytes / BYTESPERPAGE;
1466
 
    agg_recptr->blkmp_agg_offset = agg_recptr->ondev_wsp_byte_offset +
1467
 
                                   BYTESPERPAGE; /*
1468
 
                                     * whether or not we actually write
1469
 
                                     * to the on-disk fsck workspace,
1470
 
                                     * this buffer represents it logically.
1471
 
                                     */
1472
 
    agg_recptr->blkmp_blkmp_offset = 0;
1473
 
    agg_recptr->blkmp_buf_data_len = 0;
1474
 
    agg_recptr->blkmp_buf_write = 0;
1475
 
    agg_recptr->blkmp_blkmp_offset = 0;
1476
 
    agg_recptr->blkmp_buf_data_len = 0;
1477
 
    agg_recptr->blkmp_buf_write = 0;
1478
 
 
1479
 
    if ( agg_recptr->processing_readonly ) {  /* can't touch the aggregate */
1480
 
      ewbm_rc = alloc_wrksp( blkmap_size_bytes, dynstg_blkmap,
1481
 
                             I_am_logredo,
1482
 
                             (void **) &(agg_recptr->blkmp_buf_ptr) );
1483
 
      if ( ewbm_rc == FSCK_OK ) {  /* allocated and initialized block map */
1484
 
        wsp_dynstg_object = 0;
1485
 
        wsp_dynstg_action = 0;
1486
 
        agg_recptr->blkmp_buf_length = blkmap_size_bytes;
1487
 
        agg_recptr->blkmp_buf_data_len = agg_recptr->blkmp_buf_length;
1488
 
      }  /* end allocated and initialized block map */
1489
 
    } else {  /* use storage reserved for fsck in the aggregate */
1490
 
      ewbm_rc = alloc_wrksp( BLKMP_IO_BUFSIZE, dynstg_blkmap_buf,
1491
 
                             I_am_logredo,
1492
 
                             (void **) &(agg_recptr->blkmp_buf_ptr) );
1493
 
      if ( ewbm_rc == FSCK_OK ) {  /* allocated and initialized block map */
1494
 
        agg_recptr->blkmp_buf_length = BLKMP_IO_BUFSIZE;
1495
 
        agg_recptr->blkmp_buf_data_len = agg_recptr->blkmp_buf_length;
1496
 
        ewbm_rc = blkmap_put_ctl_page( agg_recptr->blkmp_ctlptr );
1497
 
        if ( ewbm_rc == FSCK_OK ) {  /* successful write to Block Map Control Page */
1498
 
          blkmap_size_in_pages = blkmap_size_bytes / BYTESPERPAGE;  /* this
1499
 
                                     * is guaranteed (by mkfs) to be an even
1500
 
                                     * number
1501
 
                                     */
1502
 
          for ( idx=1;
1503
 
              ((idx < blkmap_size_in_pages) && (ewbm_rc == FSCK_OK)  );
1504
 
              idx++ ) {  /* for each map page (after the control page) */
1505
 
 
1506
 
            this_device_offset = agg_recptr->ondev_wsp_byte_offset +
1507
 
                                 (idx*BYTESPERPAGE);
1508
 
 
1509
 
            /* swap if on big endian machine */
1510
 
            if (type_jfs & JFS_SWAP_BYTES) {
1511
 
                memcpy( swap_buf_ptr, agg_recptr->blkmp_buf_ptr, BYTESPERPAGE);
1512
 
                ujfs_swap_fsck_blk_map_page( (fsck_blk_map_page_t *) swap_buf_ptr );
1513
 
                ewbm_rc = ujfs_rw_diskblocks( Dev_IOPort,
1514
 
                                              this_device_offset,
1515
 
                                              BYTESPERPAGE,
1516
 
                                              swap_buf_ptr,
1517
 
                                              PUT ); /*
1518
 
                                         * write the initialized buffer page to
1519
 
                                         * the map page on disk
1520
 
                                         */
1521
 
            } else {
1522
 
 
1523
 
              ewbm_rc = ujfs_rw_diskblocks( Dev_IOPort,
1524
 
                                            this_device_offset,
1525
 
                                            BYTESPERPAGE,
1526
 
                                            (void *) agg_recptr->blkmp_buf_ptr,
1527
 
                                            PUT ); /*
1528
 
                                       * write the initialized buffer page to
1529
 
                                       * the map page on disk
1530
 
                                       */
1531
 
            }
1532
 
            if ( ewbm_rc != FSCK_OK ) {  /* I/O failure */
1533
 
              /*
1534
 
               * message to user
1535
 
               */
1536
 
              msgprms[0] = message_parm_0;
1537
 
              msgprmidx[0] = fsck_metadata;
1538
 
              msgprms[1] = Vol_Label;
1539
 
              msgprmidx[1] = 0;
1540
 
              sprintf( message_parm_2, "%d", 1 );
1541
 
              msgprms[2] = message_parm_2;
1542
 
              msgprmidx[2] = 0;
1543
 
              fsck_send_msg( fsck_URCVWRT, 0, 3 );
1544
 
              /*
1545
 
               * message to debugger
1546
 
               */
1547
 
              sprintf( message_parm_0, "%d", ewbm_rc );
1548
 
              msgprms[0] = message_parm_0;
1549
 
              msgprmidx[0] = 0;
1550
 
              msgprms[1] = msgprms[0];
1551
 
              msgprmidx[1] = msgprmidx[0];
1552
 
              sprintf( message_parm_2, "%d", fsck_WRITE );
1553
 
              msgprms[2] = message_parm_2;
1554
 
              msgprmidx[2] = 0;
1555
 
              sprintf( message_parm_3, "%lld", (long long)this_device_offset );
1556
 
              msgprms[3] = message_parm_3;
1557
 
              msgprmidx[3] = 0;
1558
 
              sprintf( message_parm_4, "%d", BYTESPERPAGE );
1559
 
              msgprms[4] = message_parm_4;
1560
 
              msgprmidx[4] = 0;
1561
 
              sprintf( message_parm_5, "%d", -1 );
1562
 
              msgprms[5] = message_parm_5;
1563
 
              msgprmidx[5] = 0;
1564
 
              fsck_send_msg( fsck_ERRONWSP, 0, 6 );
1565
 
            }  /* end I/O failure */
1566
 
          }  /* end for each map page */
1567
 
        }  /* end successful write to Block Map Control Page */
1568
 
      }  /* end allocated and initialized block map */
1569
 
    }  /* end else use storage reserved for fsck in the aggregate */
1570
 
  }  /* end allocated and initialized blk map ctl page */
1571
 
 
1572
 
  return( ewbm_rc );
1573
 
}  /* end establish_wsp_block_map ( ) */
1574
 
 
 
1362
        int ewbm_rc = FSCK_OK;
 
1363
        int32_t blkmap_size_bytes;
 
1364
        int32_t blkmap_size_in_pages;
 
1365
        int32_t idx;
 
1366
        int64_t this_device_offset;
 
1367
 
 
1368
        int I_am_logredo = 0;
 
1369
 
 
1370
        ewbm_rc = establish_wsp_block_map_ctl();
 
1371
 
 
1372
        if (ewbm_rc != FSCK_OK)
 
1373
                goto ewbm_exit;
 
1374
                
 
1375
        /* allocated and initialized blk map ctl page */
 
1376
        blkmap_size_bytes = agg_recptr->ondev_wsp_byte_length;
 
1377
        agg_recptr->blkmp_pagecount = blkmap_size_bytes / BYTESPERPAGE;
 
1378
        /*
 
1379
         * whether or not we actually write to the on-disk 
 
1380
         * fsck workspace, this buffer represents it logically.
 
1381
         */
 
1382
        agg_recptr->blkmp_agg_offset =
 
1383
            agg_recptr->ondev_wsp_byte_offset + BYTESPERPAGE;
 
1384
        agg_recptr->blkmp_blkmp_offset = 0;
 
1385
        agg_recptr->blkmp_buf_data_len = 0;
 
1386
        agg_recptr->blkmp_buf_write = 0;
 
1387
        agg_recptr->blkmp_blkmp_offset = 0;
 
1388
        agg_recptr->blkmp_buf_data_len = 0;
 
1389
        agg_recptr->blkmp_buf_write = 0;
 
1390
 
 
1391
        if (agg_recptr->processing_readonly) {
 
1392
                /* can't touch the aggregate */
 
1393
                ewbm_rc = alloc_wrksp(blkmap_size_bytes, dynstg_blkmap,
 
1394
                                      I_am_logredo,
 
1395
                                      (void **) &(agg_recptr->blkmp_buf_ptr));
 
1396
                if (ewbm_rc == FSCK_OK) {
 
1397
                        /* allocated and initialized block map */
 
1398
                        wsp_dynstg_object = 0;
 
1399
                        wsp_dynstg_action = 0;
 
1400
                        agg_recptr->blkmp_buf_length = blkmap_size_bytes;
 
1401
                        agg_recptr->blkmp_buf_data_len = 
 
1402
                            agg_recptr->blkmp_buf_length;
 
1403
                }
 
1404
                goto ewbm_exit;         
 
1405
        }
 
1406
        /* use storage reserved for fsck in the aggregate */
 
1407
        ewbm_rc = alloc_wrksp(BLKMP_IO_BUFSIZE, dynstg_blkmap_buf, I_am_logredo,
 
1408
                              (void **) &(agg_recptr->blkmp_buf_ptr));
 
1409
        if (ewbm_rc != FSCK_OK)
 
1410
                goto ewbm_exit;
 
1411
                        
 
1412
        /* allocated and initialized block map */
 
1413
        agg_recptr->blkmp_buf_length = BLKMP_IO_BUFSIZE;
 
1414
        agg_recptr->blkmp_buf_data_len = agg_recptr->blkmp_buf_length;
 
1415
        ewbm_rc = blkmap_put_ctl_page(agg_recptr->blkmp_ctlptr);
 
1416
        if (ewbm_rc != FSCK_OK)
 
1417
                goto ewbm_exit;
 
1418
                        
 
1419
        /* successful write to Block Map Control Page */
 
1420
        /* this is guaranteed (by mkfs) to be an even number */
 
1421
        blkmap_size_in_pages = blkmap_size_bytes / BYTESPERPAGE;
 
1422
        /* Swap to little-endian */
 
1423
        ujfs_swap_fsck_blk_map_page(agg_recptr->blkmp_buf_ptr);
 
1424
        for (idx = 1; ((idx < blkmap_size_in_pages) && 
 
1425
             (ewbm_rc == FSCK_OK)); idx++) {
 
1426
                /* for each map page (after the control page) */
 
1427
                this_device_offset = agg_recptr->ondev_wsp_byte_offset + 
 
1428
                    (idx * BYTESPERPAGE);
 
1429
                /*
 
1430
                 * write the initialized buffer page to
 
1431
                 * the map page on disk
 
1432
                 */
 
1433
                ewbm_rc = ujfs_rw_diskblocks(Dev_IOPort, this_device_offset, 
 
1434
                                    BYTESPERPAGE,
 
1435
                                    (void *) agg_recptr->blkmp_buf_ptr, PUT);
 
1436
                if (ewbm_rc != FSCK_OK) {
 
1437
                        /* I/O failure */
 
1438
                        /*
 
1439
                         * message to user
 
1440
                         */
 
1441
                        fsck_send_msg(fsck_URCVWRT, fsck_ref_msg(fsck_metadata),
 
1442
                                      Vol_Label, 1);
 
1443
                        /*
 
1444
                         * message to debugger
 
1445
                         */
 
1446
                        fsck_send_msg(fsck_ERRONWSP, ewbm_rc, ewbm_rc, fsck_WRITE,
 
1447
                                      (long long)this_device_offset,
 
1448
                                      BYTESPERPAGE, -1);
 
1449
                }
 
1450
        }
 
1451
        /* Swap back to cpu-endian */
 
1452
        ujfs_swap_fsck_blk_map_page(agg_recptr->blkmp_buf_ptr);
 
1453
        
 
1454
      ewbm_exit:        
 
1455
        return (ewbm_rc);
 
1456
}
1575
1457
 
1576
1458
/****************************************************************************
1577
1459
 * NAME: establish_wsp_block_map_ctl
1596
1478
 *      success: FSCK_OK
1597
1479
 *      failure: something else
1598
1480
 */
1599
 
retcode_t establish_wsp_block_map_ctl ( )
 
1481
int establish_wsp_block_map_ctl()
1600
1482
{
1601
 
  retcode_t   ewbmc_rc = FSCK_OK;
1602
 
  time_t      Current_Time;
1603
 
  fsblkidx_t  this_device_offset = 0;
1604
 
  int         I_am_logredo = 0;
1605
 
 
1606
 
  ewbmc_rc = alloc_wrksp( sizeof(fsck_blk_map_hdr_t), dynstg_blkmap_hdr,
1607
 
                          I_am_logredo,
1608
 
                          (void **) &(agg_recptr->blkmp_ctlptr) );
1609
 
 
1610
 
  if ( ewbmc_rc == FSCK_OK ) {  /* allocated and initialized blk map ctl page */
1611
 
    strncpy( agg_recptr->blkmp_ctlptr->hdr.eyecatcher, fbmh_eyecatcher_string,
1612
 
             strlen(fbmh_eyecatcher_string));  /* fill eyecatcher */
1613
 
    agg_recptr->blkmp_ctlptr->hdr.super_buff_addr = (char *) sb_ptr;
1614
 
    agg_recptr->blkmp_ctlptr->hdr.agg_record_addr = (char *) agg_recptr;
1615
 
    agg_recptr->blkmp_ctlptr->hdr.bmap_record_addr = (char *) bmap_recptr;
1616
 
    agg_recptr->blkmp_ctlptr->hdr.fscklog_full = agg_recptr->fscklog_full;
1617
 
    agg_recptr->blkmp_ctlptr->hdr.fscklog_buf_allocated =
1618
 
    agg_recptr->fscklog_buf_allocated;
1619
 
    agg_recptr->blkmp_ctlptr->hdr.fscklog_buf_alloc_err =
1620
 
    agg_recptr->fscklog_buf_alloc_err;
1621
 
    agg_recptr->blkmp_ctlptr->hdr.fscklog_agg_offset =
1622
 
    agg_recptr->ondev_fscklog_byte_offset;
1623
 
 
1624
 
    Current_Time = time(NULL);
1625
 
    fsck_DateTime = localtime( &Current_Time );
1626
 
    if ( fsck_DateTime->tm_year > 2000 ) {
1627
 
      sprintf( &(agg_recptr->blkmp_ctlptr->hdr.start_time[0]), "%d/%d/%d%d.%d.%d",
1628
 
               fsck_DateTime->tm_mon + 1, fsck_DateTime->tm_mday, ((fsck_DateTime->tm_year + 1900)%2000),
1629
 
               fsck_DateTime->tm_hour, fsck_DateTime->tm_min, fsck_DateTime->tm_sec );
1630
 
    } else {
1631
 
      sprintf( &(agg_recptr->blkmp_ctlptr->hdr.start_time[0]), "%d/%d/%d%d.%d.%d",
1632
 
               fsck_DateTime->tm_mon + 1, fsck_DateTime->tm_mday, ((fsck_DateTime->tm_year + 1900)%1900),
1633
 
               fsck_DateTime->tm_hour, fsck_DateTime->tm_min, fsck_DateTime->tm_sec );
1634
 
    }
1635
 
 
1636
 
    if ( !(agg_recptr->processing_readonly) ) {  
1637
 
        /*
1638
 
         * use storage reserved for fsck in the
1639
 
         * aggregate
1640
 
         */
1641
 
      ewbmc_rc = blkmap_put_ctl_page( agg_recptr->blkmp_ctlptr );
1642
 
      if ( ewbmc_rc != FSCK_OK ) {  /* I/O failure */
1643
 
        /*
1644
 
         * message to user
1645
 
         */
1646
 
        msgprms[0] = message_parm_0;
1647
 
        msgprmidx[0] = fsck_metadata;
1648
 
        msgprms[1] = Vol_Label;
1649
 
        msgprmidx[1] = 0;
1650
 
        sprintf( message_parm_2, "%d", 1 );
1651
 
        msgprms[2] = message_parm_2;
1652
 
        msgprmidx[2] = 0;
1653
 
        fsck_send_msg( fsck_URCVWRT, 0, 3 );
1654
 
        /*
1655
 
         * message to debugger
1656
 
         */
1657
 
        sprintf( message_parm_0, "%d", ewbmc_rc );
1658
 
        msgprms[0] = message_parm_0;
1659
 
        msgprmidx[0] = 0;
1660
 
        msgprms[1] = msgprms[0];
1661
 
        msgprmidx[1] = msgprmidx[0];
1662
 
        sprintf( message_parm_2, "%d", fsck_WRITE );
1663
 
        msgprms[2] = message_parm_2;
1664
 
        msgprmidx[2] = 0;
1665
 
        sprintf( message_parm_3, "%lld", (long long)this_device_offset );
1666
 
        msgprms[3] = message_parm_3;
1667
 
        msgprmidx[3] = 0;
1668
 
        sprintf( message_parm_4, "%d", BYTESPERPAGE );
1669
 
        msgprms[4] = message_parm_4;
1670
 
        msgprmidx[4] = 0;
1671
 
        sprintf( message_parm_5, "%d", -1 );
1672
 
        msgprms[5] = message_parm_5;
1673
 
        msgprmidx[5] = 0;
1674
 
        fsck_send_msg( fsck_ERRONWSP, 0, 6 );
1675
 
      }  /* end I/O failure */
1676
 
    }  /* end else use storage reserved for fsck in the aggregate */
1677
 
  }  /* end allocated and initialized blk map ctl page */
1678
 
 
1679
 
  return( ewbmc_rc );
1680
 
}  /* end establish_wsp_block_map_ctl ( ) */
1681
 
 
 
1483
        int ewbmc_rc = FSCK_OK;
 
1484
        time_t Current_Time;
 
1485
        int64_t this_device_offset = 0;
 
1486
        int I_am_logredo = 0;
 
1487
 
 
1488
        ewbmc_rc =
 
1489
            alloc_wrksp(sizeof (struct fsck_blk_map_hdr), dynstg_blkmap_hdr,
 
1490
                        I_am_logredo, (void **) &(agg_recptr->blkmp_ctlptr));
 
1491
 
 
1492
        if (ewbmc_rc == FSCK_OK) {
 
1493
                /* allocated and initialized blk map ctl page */
 
1494
                /* fill eyecatcher */
 
1495
                strncpy(agg_recptr->blkmp_ctlptr->hdr.eyecatcher,
 
1496
                        fbmh_eyecatcher_string, strlen(fbmh_eyecatcher_string));
 
1497
                agg_recptr->blkmp_ctlptr->hdr.super_buff_addr = (char *) sb_ptr;
 
1498
                agg_recptr->blkmp_ctlptr->hdr.agg_record_addr =
 
1499
                    (char *) agg_recptr;
 
1500
                agg_recptr->blkmp_ctlptr->hdr.bmap_record_addr =
 
1501
                    (char *) bmap_recptr;
 
1502
                agg_recptr->blkmp_ctlptr->hdr.fscklog_full =
 
1503
                    agg_recptr->fscklog_full;
 
1504
                agg_recptr->blkmp_ctlptr->hdr.fscklog_buf_allocated =
 
1505
                    agg_recptr->fscklog_buf_allocated;
 
1506
                agg_recptr->blkmp_ctlptr->hdr.fscklog_buf_alloc_err =
 
1507
                    agg_recptr->fscklog_buf_alloc_err;
 
1508
                agg_recptr->blkmp_ctlptr->hdr.fscklog_agg_offset =
 
1509
                    agg_recptr->ondev_fscklog_byte_offset;
 
1510
 
 
1511
                Current_Time = time(NULL);
 
1512
                fsck_DateTime = localtime(&Current_Time);
 
1513
                sprintf(&(agg_recptr->blkmp_ctlptr->hdr.start_time[0]),
 
1514
                        "%d/%d/%d %d:%02d:%02d", fsck_DateTime->tm_mon + 1,
 
1515
                        fsck_DateTime->tm_mday, 
 
1516
                        (fsck_DateTime->tm_year + 1900),
 
1517
                        fsck_DateTime->tm_hour, fsck_DateTime->tm_min,
 
1518
                        fsck_DateTime->tm_sec);
 
1519
 
 
1520
                if (!(agg_recptr->processing_readonly)) {
 
1521
                        /*
 
1522
                         * use storage reserved for fsck in the
 
1523
                         * aggregate
 
1524
                         */
 
1525
                        ewbmc_rc =
 
1526
                            blkmap_put_ctl_page(agg_recptr->blkmp_ctlptr);
 
1527
                        if (ewbmc_rc != FSCK_OK) {
 
1528
                                /* I/O failure */
 
1529
                                /*
 
1530
                                 * message to user
 
1531
                                 */
 
1532
                                fsck_send_msg(fsck_URCVWRT, fsck_ref_msg(fsck_metadata),
 
1533
                                              Vol_Label, 1);
 
1534
                                /*
 
1535
                                 * message to debugger
 
1536
                                 */
 
1537
                                fsck_send_msg(fsck_ERRONWSP, ewbmc_rc, ewbmc_rc, fsck_WRITE,
 
1538
                                              (long long) this_device_offset,
 
1539
                                              BYTESPERPAGE, -1);
 
1540
                        }
 
1541
                }
 
1542
        }
 
1543
        return (ewbmc_rc);
 
1544
}
1682
1545
 
1683
1546
/*****************************************************************************
1684
1547
 * NAME: extent_1stref_chk
1699
1562
 *      ino_recptr    - input - pointer to the fsck inode record describing the
1700
1563
 *                              inode to which this extent is allocated
1701
1564
 *
1702
 
 * NOTES:  As fsck scans the inodes sequentially, recording the blocks allocated,
1703
 
 *         it doesn't know a particular block is multiply-allocated until the
1704
 
 *         second reference is detected.  At that time the first reference to the
1705
 
 *         block is unresolved since no list of owners is built (only a count of
1706
 
 *         owners, in which a 1 in the bit map represents a count of 1).
 
1565
 * NOTES:  As fsck scans the inodes sequentially, recording the blocks
 
1566
 *         allocated, it doesn't know a particular block is multiply-allocated
 
1567
 *         until the second reference is detected.  At that time the first
 
1568
 *         reference to the block is unresolved since no list of owners is
 
1569
 *         built (only a count of owners, in which a 1 in the bit map
 
1570
 *         represents a count of 1).
1707
1571
 *
1708
 
 *         After all inodes have been scanned and their block allocations recorded,
1709
 
 *         if any multiply-allocated blocks have been detected, the inodes are
1710
 
 *         scanned sequentially again until all first references to
1711
 
 *         multiply-allocated blocks are resolved.  This routine is invoked during
1712
 
 *         that rescan.
 
1572
 *         After all inodes have been scanned and their block allocations
 
1573
 *         recorded, if any multiply-allocated blocks have been detected, the
 
1574
 *         inodes are scanned sequentially again until all first references to
 
1575
 *         multiply-allocated blocks are resolved.  This routine is invoked
 
1576
 *         during that rescan.
1713
1577
 *
1714
1578
 * RETURNS:
1715
1579
 *      success: FSCK_OK
1716
1580
 *      failure: something else
1717
1581
 */
1718
 
retcode_t extent_1stref_chk ( fsblkidx_t         first_block,
1719
 
                              fsblkidx_t         last_block,
1720
 
                              int8_t             is_EA,
1721
 
                              int8_t             is_ACL,
1722
 
                              fsck_msg_info_ptr  msg_info_ptr,
1723
 
                              fsck_inode_recptr  ino_recptr   )
 
1582
int extent_1stref_chk(int64_t first_block,
 
1583
                      int64_t last_block,
 
1584
                      int8_t is_EA,
 
1585
                      int8_t is_ACL,
 
1586
                      struct fsck_ino_msg_info *msg_info_ptr,
 
1587
                      struct fsck_inode_record *ino_recptr)
1724
1588
{
1725
 
  retcode_t   eq_rc = FSCK_OK;
1726
 
  fsblkidx_t  blkidx;
1727
 
  fsblkidx_t  first_in_dup_range = 0;
1728
 
  reg_idx_t   size_of_dup_range = 0;
1729
 
  int         is_dup = 0;
1730
 
  int         dups_detected = 0;
1731
 
 
1732
 
  for ( blkidx = first_block;
1733
 
      ((blkidx <= last_block) &&
1734
 
       (eq_rc == FSCK_OK) &&
1735
 
       (agg_recptr->unresolved_1stref_count > 0));
1736
 
       blkidx++ ) {
1737
 
    eq_rc = blkall_ref_check( blkidx, &is_dup );  /* see if this contains the first
1738
 
                                      * reference to some multiply-allocated
1739
 
                                      * block
1740
 
                                      */
1741
 
    if ( eq_rc == FSCK_OK ) {
1742
 
      if ( is_dup ) {  /* a block that's already allocated */
1743
 
        if ( size_of_dup_range == 0 ) {  /* this is a new range */
1744
 
          dups_detected = 1;
1745
 
          first_in_dup_range = blkidx;
1746
 
          size_of_dup_range = 1;
1747
 
        } else {  /* else not a new range */
1748
 
          size_of_dup_range++;
1749
 
        }  /* end else not a new range */
1750
 
      } else {  /* it's not already allocated */
1751
 
        if ( size_of_dup_range > 0 ) {  /* just finished a range */
1752
 
          sprintf( message_parm_0, "%d", size_of_dup_range );
1753
 
          msgprms[0] = message_parm_0;
1754
 
          msgprmidx[0] = 0;
1755
 
          sprintf( message_parm_1, "%lld", (long long)first_in_dup_range );
1756
 
          msgprms[1] = message_parm_1;
1757
 
          msgprmidx[1] = 0;
1758
 
          msgprms[2] = message_parm_2;
1759
 
          msgprmidx[2] = msg_info_ptr->msg_inotyp;
1760
 
          msgprms[3] = message_parm_3;
1761
 
          msgprmidx[3] = msg_info_ptr->msg_inopfx;
1762
 
          sprintf( message_parm_4, "%d", msg_info_ptr->msg_inonum );
1763
 
          msgprms[4] = message_parm_4;
1764
 
          msgprmidx[4] = 0;
1765
 
          fsck_send_msg( fsck_DUPBLKREF, 0, 5 );
1766
 
          size_of_dup_range = 0;
1767
 
        }  /* end just finished a range */
1768
 
      }  /* end else it's not already allocated */
1769
 
    }
1770
 
  }  /* end for */
1771
 
  if ( (eq_rc == FSCK_OK) && (size_of_dup_range > 0) ) {  
1772
 
      /*
1773
 
       * last block(s) finished a range
1774
 
       */
1775
 
    sprintf( message_parm_0, "%d", size_of_dup_range );
1776
 
    msgprms[0] = message_parm_0;
1777
 
    msgprmidx[0] = 0;
1778
 
    sprintf( message_parm_1, "%lld", (long long)first_in_dup_range );
1779
 
    msgprms[1] = message_parm_1;
1780
 
    msgprmidx[1] = 0;
1781
 
    msgprms[2] = message_parm_2;
1782
 
    msgprmidx[2] = msg_info_ptr->msg_inotyp;
1783
 
    msgprms[3] = message_parm_3;
1784
 
    msgprmidx[3] = msg_info_ptr->msg_inopfx;
1785
 
    sprintf( message_parm_4, "%d", msg_info_ptr->msg_inonum );
1786
 
    msgprms[4] = message_parm_4;
1787
 
    msgprmidx[4] = 0;
1788
 
    fsck_send_msg( fsck_DUPBLKREF, 0, 5 );
1789
 
    size_of_dup_range = 0;
1790
 
  }  /* end last block(s) finished a range */
1791
 
 
1792
 
  if ( eq_rc == FSCK_OK ) {  /* nothing fatal yet */
1793
 
    if ( dups_detected ) {  /* claims at least 1 multiply allocated block */
1794
 
      ino_recptr->involved_in_dups = 1;
1795
 
      msgprms[0] = message_parm_0;
1796
 
      msgprmidx[0] = msg_info_ptr->msg_inopfx;
1797
 
      sprintf( message_parm_1, "%d", msg_info_ptr->msg_inonum );
1798
 
      msgprms[1] = message_parm_1;
1799
 
      msgprmidx[1] = 0;
1800
 
      fsck_send_msg( fsck_DUPBLKREFS, 0, 2 );
1801
 
      if ( !(inode_is_metadata(ino_recptr)) ) {  /* not a metadata inode */
1802
 
        if ( is_EA ) {  /* an extended attributes extent */
1803
 
          ino_recptr->clr_ea_fld = 1;
1804
 
          agg_recptr->corrections_needed = 1;
1805
 
        } else if ( is_ACL ) {  /* an Access Control List */
1806
 
          ino_recptr->clr_acl_fld = 1;
1807
 
          agg_recptr->corrections_needed = 1;
1808
 
        } else {  /* internal node or data */
1809
 
          ino_recptr->selected_to_rls = 1;
1810
 
          agg_recptr->corrections_needed = 1;
1811
 
        }  /* end not an extended attributes extent */
1812
 
      }  /* end else this is not a metadata inode */
1813
 
    }  /* end claims at least 1 multiply allocated block */
1814
 
  }  /* end nothing fatal yet */
1815
 
 
1816
 
  return( eq_rc );
1817
 
}  /* end of extent_1stref_chk () */
1818
 
 
1819
 
 
1820
 
/*****************************************************************************
1821
 
 * NAME: extent_record
 
1589
        int eq_rc = FSCK_OK;
 
1590
        int64_t blkidx;
 
1591
        int64_t first_in_dup_range = 0;
 
1592
        uint32_t size_of_dup_range = 0;
 
1593
        int is_dup = 0;
 
1594
        int dups_detected = 0;
 
1595
        struct dupall_blkrec *blkrec;
 
1596
 
 
1597
        while (agg_recptr->unresolved_1stref_count) {
 
1598
                blkrec = dupall_find_blkrec(first_block, last_block);
 
1599
                if (!blkrec)
 
1600
                        break;
 
1601
                if (blkrec->first_ref_resolved) {
 
1602
                        if (blkrec->last_blk <= last_block) {
 
1603
                                first_block = blkrec->last_blk + 1;
 
1604
                                continue;
 
1605
                        }
 
1606
                        break;
 
1607
                }
 
1608
                /*
 
1609
                 * If the record goes outside this extent, we need to split
 
1610
                 * it, since we are only interested in the intersection of
 
1611
                 * the record and this extent
 
1612
                 */
 
1613
                if ((blkrec->first_blk < first_block) ||
 
1614
                    (blkrec->last_blk > last_block)) {
 
1615
                        eq_rc = blkall_split_blkrec(blkrec, first_block,
 
1616
                                                    last_block);
 
1617
                        if (eq_rc)
 
1618
                                return eq_rc;
 
1619
                        /*
 
1620
                         * Check if the split caused the current record to
 
1621
                         * precede the extent we are processing
 
1622
                         */
 
1623
                        if (blkrec->first_blk < first_block)
 
1624
                                continue;
 
1625
                }
 
1626
                dups_detected = 1;
 
1627
                blkrec->first_ref_resolved = 1;
 
1628
                agg_recptr->unresolved_1stref_count--;
 
1629
 
 
1630
                if (msg_info_ptr) {
 
1631
                        size_of_dup_range =
 
1632
                                blkrec->last_blk - blkrec->first_blk + 1;
 
1633
                        fsck_send_msg(fsck_DUPBLKREF, size_of_dup_range,
 
1634
                                      (long long) blkrec->first_blk,
 
1635
                                      fsck_ref_msg(msg_info_ptr->msg_inotyp),
 
1636
                                      fsck_ref_msg(msg_info_ptr->msg_inopfx),
 
1637
                                      msg_info_ptr->msg_inonum);
 
1638
                }
 
1639
        }
 
1640
 
 
1641
        if (dups_detected && msg_info_ptr) {
 
1642
                ino_recptr->involved_in_dups = 1;
 
1643
                fsck_send_msg(fsck_DUPBLKREFS,
 
1644
                              fsck_ref_msg(msg_info_ptr->msg_inopfx),
 
1645
                              msg_info_ptr->msg_inonum);
 
1646
                if (!(inode_is_metadata(ino_recptr))) {
 
1647
                        agg_recptr->corrections_needed = 1;
 
1648
                        if (is_EA)
 
1649
                                ino_recptr->clr_ea_fld = 1;
 
1650
                        else if (is_ACL)
 
1651
                                ino_recptr->clr_acl_fld = 1;
 
1652
                        else
 
1653
                                ino_recptr->selected_to_rls = 1;
 
1654
                }
 
1655
        }
 
1656
        return (FSCK_OK);
 
1657
}
 
1658
 
 
1659
/****************************************************************************
 
1660
 * NAME: blkall_ref_check
1822
1661
 *
1823
 
 * FUNCTION:  Record that each of the blocks in the given extent is allocated
1824
 
 *            to some inode.
 
1662
 * FUNCTION: Determine whether the given blocks are multiply-allocated and, if
 
1663
 *           so, whether the first reference to it is unresolved.  (In this
 
1664
 *           case, the current reference must be the first reference.)
1825
1665
 *
1826
1666
 * PARAMETERS:
1827
 
 *      first_block   - input - ordinal number of the first block in the extent
1828
 
 *                              to check
1829
 
 *      last_block    - input - ordinal number of the last block in the extent
1830
 
 *                              to check
1831
 
 *
1832
 
 * NOTES:  Under certain special circumstances, it is necessary to record that
1833
 
 *         each block in some extent are allocated, and IT IS ALREADY KNOWN
1834
 
 *         that the extent is valid and that the blocks are not multiply
1835
 
 *         allocated.  (Rather, that no duplicate references to the blocks
1836
 
 *         have yet been detected and the block map currently indicates them
1837
 
 *         to be unallocated.)
1838
 
 *
1839
 
 *         This function could be accomplished using routine extent_record_dupchk
1840
 
 *         but, for performance reasons, this streamlined routine exists to
1841
 
 *         minimize processing time.
1842
 
 *
1843
 
 *         To be precise, before this routine is invoked for an extent,
1844
 
 *               o routine extent_record_dupchk was invoked for the extent, then
1845
 
 *                 extent_unrecord was invoked for the extent.
1846
 
 *
1847
 
 *            OR o after all block allocations were recorded in the fsck workspace
1848
 
 *                 block map, and then the block map was adjusted as needed for
1849
 
 *                 inode repairs, the block map was scanned to find an extent
1850
 
 *                 of available blocks.  This routine is then called to record
1851
 
 *                 the allocation of those blocks.
1852
 
 *
1853
 
 *            OR o possibly some other path which accomplishes the same effect.
1854
 
 *                 (I.e., this may not be an exhaustive list)
 
1667
 *      first_block - input - ordinal number of the first filesystem block to
 
1668
 *                            be checked
 
1669
 *      last_block  - input - ordinal number of the last filesystem block to
 
1670
 *                            be checked
1855
1671
 *
1856
1672
 * RETURNS:
1857
1673
 *      success: FSCK_OK
1858
1674
 *      failure: something else
1859
1675
 */
1860
 
retcode_t extent_record ( fsblkidx_t  first_block,
1861
 
                          fsblkidx_t  last_block   )
 
1676
int blkall_ref_check(int64_t first_block, int64_t last_block)
1862
1677
{
1863
 
  retcode_t   er_rc = FSCK_OK;
1864
 
  fsblkidx_t  blkidx;
1865
 
 
1866
 
  for ( blkidx = first_block;
1867
 
      (blkidx <= last_block) && (er_rc >= FSCK_OK);
1868
 
      blkidx++ ) {
1869
 
    er_rc = blkall_increment_owners( blkidx );
1870
 
  }  /* end for */
1871
 
 
1872
 
  return( er_rc );
1873
 
}  /* end of extent_record () */
1874
 
 
 
1678
        return extent_1stref_chk(first_block, last_block, 0, 0, 0, 0);
 
1679
}
1875
1680
 
1876
1681
/*****************************************************************************
1877
1682
 * NAME: extent_record_dupchk
1890
1695
 *                              to check
1891
1696
 *      is_EA         - input - !0 => the extent contains an inode's EA
1892
1697
 *                               0 => the extent contains something else
1893
 
 *      msg_info_ptr  - input - pointer to a data area containing information
1894
 
 *                              needed to issue messages for this extent
 
1698
 *      msg_info_ptr  - input - information needed to issue messages for this
 
1699
 *                              extent.  If NULL, no messages will be issued
1895
1700
 *      ino_recptr    - input - pointer to the fsck inode record describing the
1896
1701
 *                              inode to which this extent is allocated
1897
1702
 *
1898
 
 * NOTES:
1899
 
 *
1900
 
 * RETURNS:
1901
 
 *      success: FSCK_OK
1902
 
 *      failure: something else
1903
 
 */
1904
 
retcode_t extent_record_dupchk ( fsblkidx_t         first_block,
1905
 
                                 fsblkidx_t         last_block,
1906
 
                                 int8_t             range_adj,
1907
 
                                 int8_t             is_EA,
1908
 
                                 int8_t             is_ACL,
1909
 
                                 fsck_msg_info_ptr  msg_info_ptr,
1910
 
                                 fsck_inode_recptr  ino_recptr   )
1911
 
{
1912
 
  retcode_t   erd_rc = FSCK_OK;
1913
 
  fsblkidx_t  block_idx;
1914
 
  int         is_a_dup = 0;
1915
 
  int         dups_detected = 0;
1916
 
  fsblkidx_t  first_in_dup_range = 0;
1917
 
  reg_idx_t   size_of_dup_range = 0;
1918
 
 
1919
 
  if ( range_adj ) { /* the xad described an invalid range */
1920
 
    msgprms[0] = message_parm_0;
1921
 
    msgprmidx[0] = msg_info_ptr->msg_dxdtyp;
1922
 
    msgprms[1] = message_parm_1;
1923
 
    msgprmidx[1] = msg_info_ptr->msg_inotyp;
1924
 
    msgprms[2] = message_parm_2;
1925
 
    msgprmidx[2] = msg_info_ptr->msg_inopfx;
1926
 
    sprintf( message_parm_3, "%d", msg_info_ptr->msg_inonum );
1927
 
    msgprms[3] = message_parm_3;
1928
 
    msgprmidx[3] = 0;
1929
 
    fsck_send_msg( fsck_BADBLKNO, 0, 4 );
1930
 
  }  /* end the xad described an invalid range */
1931
 
  for ( block_idx = first_block;
1932
 
      ((block_idx <= last_block) && (erd_rc >= FSCK_OK));
1933
 
      block_idx++ )  { /* for each block */
1934
 
    erd_rc = blkall_increment_owners( block_idx );
1935
 
    if ( erd_rc >= 0 ) {
1936
 
      is_a_dup = erd_rc;
1937
 
      erd_rc = FSCK_OK;
1938
 
    }
1939
 
    if ( is_a_dup ) {  /* it's a block that's already allocated */
1940
 
      if ( size_of_dup_range == 0 ) {  /* this is a new range */
1941
 
        dups_detected = 1;
1942
 
        first_in_dup_range = block_idx;
1943
 
        size_of_dup_range = 1;
1944
 
      } else {  /* else not a new range */
1945
 
        size_of_dup_range++;
1946
 
      }  /* end else not a new range */
1947
 
    } else {  /* it's not already allocated */
1948
 
      if ( size_of_dup_range > 0 ) {  /* just finished a range */
1949
 
        sprintf( message_parm_0, "%d", size_of_dup_range );
1950
 
        msgprms[0] = message_parm_0;
1951
 
        msgprmidx[0] = 0;
1952
 
        sprintf( message_parm_1, "%lld", (long long)first_in_dup_range );
1953
 
        msgprms[1] = message_parm_1;
1954
 
        msgprmidx[1] = 0;
1955
 
        msgprms[2] = message_parm_2;
1956
 
        msgprmidx[2] = msg_info_ptr->msg_inotyp;
1957
 
        msgprms[3] = message_parm_3;
1958
 
        msgprmidx[3] = msg_info_ptr->msg_inopfx;
1959
 
        sprintf( message_parm_4, "%d", msg_info_ptr->msg_inonum );
1960
 
        msgprms[4] = message_parm_4;
1961
 
        msgprmidx[4] = 0;
1962
 
        fsck_send_msg( fsck_DUPBLKREF, 0, 5 );
1963
 
        size_of_dup_range = 0;
1964
 
      }  /* end just finished a range */
1965
 
    }  /* end else it's not already allocated */
1966
 
  }  /* end for block_idx */
1967
 
  if ( (erd_rc == FSCK_OK) && (size_of_dup_range > 0) ) {  
1968
 
      /*
1969
 
       * last block(s) finished a range
1970
 
       */
1971
 
    sprintf( message_parm_0, "%d", size_of_dup_range );
1972
 
    msgprms[0] = message_parm_0;
1973
 
    msgprmidx[0] = 0;
1974
 
    sprintf( message_parm_1, "%lld", (long long)first_in_dup_range );
1975
 
    msgprms[1] = message_parm_1;
1976
 
    msgprmidx[1] = 0;
1977
 
    msgprms[2] = message_parm_2;
1978
 
    msgprmidx[2] = msg_info_ptr->msg_inotyp;
1979
 
    msgprms[3] = message_parm_3;
1980
 
    msgprmidx[3] = msg_info_ptr->msg_inopfx;
1981
 
    sprintf( message_parm_4, "%d", msg_info_ptr->msg_inonum );
1982
 
    msgprms[4] = message_parm_4;
1983
 
    msgprmidx[4] = 0;
1984
 
    fsck_send_msg( fsck_DUPBLKREF, 0, 5 );
1985
 
    size_of_dup_range = 0;
1986
 
  }  /* end last block(s) finished a range */
1987
 
  if ( erd_rc == FSCK_OK ) {  /* nothing fatal yet */
1988
 
    if ( dups_detected ) {  /* claims at least 1 multiply allocated block */
1989
 
      ino_recptr->involved_in_dups = 1;
1990
 
      msgprms[0] = message_parm_0;
1991
 
      msgprmidx[0] = msg_info_ptr->msg_inopfx;
1992
 
      sprintf( message_parm_1, "%d", msg_info_ptr->msg_inonum );
1993
 
      msgprms[1] = message_parm_1;
1994
 
      msgprmidx[1] = 0;
1995
 
      fsck_send_msg( fsck_DUPBLKREFS, 0, 2 );
1996
 
      if ( !(inode_is_metadata(ino_recptr)) ) {  /* not a metadata inode */
1997
 
        if ( is_EA ) {  /* an extended attributes extent */
1998
 
          ino_recptr->clr_ea_fld = 1;
1999
 
          agg_recptr->corrections_needed = 1;
2000
 
        } else if ( is_ACL ) {  /* an extended attributes extent */
2001
 
          ino_recptr->clr_acl_fld = 1;
2002
 
          agg_recptr->corrections_needed = 1;
2003
 
        } else {  /* internal node or data */
2004
 
          ino_recptr->selected_to_rls = 1;
2005
 
          agg_recptr->corrections_needed = 1;
2006
 
        }  /* end not an extended attributes extent */
2007
 
      }  /* end else this is not a metadata inode */
2008
 
    }  /* end claims at least 1 multiply allocated block */
2009
 
  }  /* end nothing fatal yet */
2010
 
 
2011
 
  return( erd_rc );
2012
 
}  /* end of extent_record_dupchk () */
2013
 
 
 
1703
 * RETURNS:
 
1704
 *      success: FSCK_OK
 
1705
 *      failure: something else
 
1706
 */
 
1707
int extent_record_dupchk(int64_t first_block,
 
1708
                         int64_t last_block,
 
1709
                         int8_t range_adj,
 
1710
                         int8_t is_EA,
 
1711
                         int8_t is_ACL,
 
1712
                         struct fsck_ino_msg_info *msg_info_ptr,
 
1713
                         struct fsck_inode_record *ino_recptr)
 
1714
{
 
1715
        int erd_rc = FSCK_OK;
 
1716
        int dups_detected = 0;
 
1717
        struct dupall_blkrec *this_blkrec;
 
1718
 
 
1719
        if (range_adj) {
 
1720
                /* the xad described an invalid range */
 
1721
                fsck_send_msg(fsck_BADBLKNO,
 
1722
                              fsck_ref_msg(msg_info_ptr->msg_dxdtyp),
 
1723
                              fsck_ref_msg(msg_info_ptr->msg_inotyp),
 
1724
                              fsck_ref_msg(msg_info_ptr->msg_inopfx),
 
1725
                              msg_info_ptr->msg_inonum);
 
1726
        }
 
1727
 
 
1728
        /*
 
1729
         * Look for duplicate blocks already detected for this extent
 
1730
         */
 
1731
        while (first_block <= last_block) {
 
1732
                this_blkrec = dupall_find_blkrec(first_block, last_block);
 
1733
                if (!this_blkrec)
 
1734
                        break;
 
1735
 
 
1736
                /*
 
1737
                 * If this record goes beyond the extent, we need to split it.
 
1738
                 */
 
1739
                if ((this_blkrec->first_blk < first_block) ||
 
1740
                    (this_blkrec->last_blk > last_block)) {
 
1741
                        erd_rc = blkall_split_blkrec(this_blkrec, first_block,
 
1742
                                                     last_block);
 
1743
                        if (erd_rc)
 
1744
                                return erd_rc;
 
1745
                        /*
 
1746
                         * Check if the split caused the current record to
 
1747
                         * precede the extent we are processing
 
1748
                         */
 
1749
                        if (this_blkrec->first_blk < first_block)
 
1750
                                continue;
 
1751
                }
 
1752
 
 
1753
                /*
 
1754
                 * Take care of the blocks preceding this record (if any)
 
1755
                 */
 
1756
                if (first_block < this_blkrec->first_blk) {
 
1757
                        erd_rc = blkall_increment_owners(first_block,
 
1758
                                                this_blkrec->first_blk - 1,
 
1759
                                                msg_info_ptr);
 
1760
                        if (erd_rc < 0)
 
1761
                                return erd_rc;
 
1762
                        else if (erd_rc)
 
1763
                                dups_detected = 1;
 
1764
                }
 
1765
 
 
1766
                this_blkrec->owner_count++;
 
1767
                first_block = this_blkrec->last_blk + 1;
 
1768
        }
 
1769
 
 
1770
        /*
 
1771
         * Take care of any remaining blocks
 
1772
         */
 
1773
        if (first_block <= last_block) {
 
1774
                erd_rc = blkall_increment_owners(first_block, last_block,
 
1775
                                                 msg_info_ptr);
 
1776
                if (erd_rc < 0)
 
1777
                        return erd_rc;
 
1778
                else if (erd_rc)
 
1779
                        dups_detected = 1;
 
1780
        }
 
1781
        if (dups_detected && msg_info_ptr) {
 
1782
                /* claims at least 1 multiply allocated block */
 
1783
                ino_recptr->involved_in_dups = 1;
 
1784
                fsck_send_msg(fsck_DUPBLKREFS,
 
1785
                              fsck_ref_msg(msg_info_ptr->msg_inopfx),
 
1786
                              msg_info_ptr->msg_inonum);
 
1787
                if (!(inode_is_metadata(ino_recptr))) {
 
1788
                        agg_recptr->corrections_needed = 1;
 
1789
                        if (is_EA)
 
1790
                                ino_recptr->clr_ea_fld = 1;
 
1791
                        else if (is_ACL)
 
1792
                                ino_recptr->clr_acl_fld = 1;
 
1793
                        else
 
1794
                                ino_recptr->selected_to_rls = 1;
 
1795
                }
 
1796
        }
 
1797
        return (FSCK_OK);
 
1798
}
 
1799
 
 
1800
/*****************************************************************************
 
1801
 * NAME: extent_record
 
1802
 *
 
1803
 * FUNCTION:  Record that each of the blocks in the given extent is allocated
 
1804
 *            to some inode.
 
1805
 *
 
1806
 * PARAMETERS:
 
1807
 *      first_block   - input - ordinal number of the first block in the extent
 
1808
 *                              to check
 
1809
 *      last_block    - input - ordinal number of the last block in the extent
 
1810
 *                              to check
 
1811
 *
 
1812
 * NOTES:  Originally, this was intended to be a streamlined version of
 
1813
 *         extent_record_dupchk, called only when the extent was known to
 
1814
 *         not be multilply allocated.  However, it really wasn't any more
 
1815
 *         efficient, so its simpler to just call extent_record_dupchk here.
 
1816
 *
 
1817
 * RETURNS:
 
1818
 *      success: FSCK_OK
 
1819
 *      failure: something else
 
1820
 */
 
1821
int extent_record(int64_t first_block, int64_t last_block)
 
1822
{
 
1823
        return extent_record_dupchk(first_block, last_block, 0, 0, 0, 0, 0);
 
1824
}
2014
1825
 
2015
1826
/*****************************************************************************
2016
1827
 * NAME: extent_unrecord
2033
1844
 *         this streamlined routine exists to minimize processing time.
2034
1845
 *
2035
1846
 *         Examples of these circumstances include:
2036
 
 *            o Storage allocated for an inode's EA is valid, but the B+Tree
2037
 
 *              rooted in the inode is structurally corrupt.  Then the portions
2038
 
 *              of the tree which were recorded before the corruption was detected
2039
 
 *              were backed out using routines which include validation code, and
2040
 
 *              finally this routine is called to 'unrecord' the storage allocated
2041
 
 *              for the EA.
2042
 
 *
2043
 
 *            o The B+Tree rooted in an inode was verified structurally correct,
2044
 
 *              but the di_nblocks in the inode was found to be inconsistent with
2045
 
 *              the tree.  In this case we assume the tree to be corrupt and
2046
 
 *              back it out of the fsck workspace block map immediately.  This
2047
 
 *              routine would be used for that purpose since the tree has already
2048
 
 *              been verified structurally correct.
2049
 
 *
2050
 
 *            o An inode has been found to be valid, but claims ownership of at
2051
 
 *              least one block claimed by another inode. At least one of the
2052
 
 *              inodes is actually damaged.  The user has given permission to
2053
 
 *              delete this inode, and so we need to decrement the number of
2054
 
 *              owners for each block allocated to this inode.  This routine
2055
 
 *              would be used for that purpose since the tree has already been
2056
 
 *              verified structurally correct.
 
1847
 *          o Storage allocated for an inode's EA is valid, but the B+Tree
 
1848
 *            rooted in the inode is structurally corrupt.  Then the portions
 
1849
 *            of the tree which were recorded before the corruption was detected
 
1850
 *            were backed out using routines which include validation code, and
 
1851
 *            finally this routine is called to 'unrecord' the storage allocated
 
1852
 *            for the EA.
 
1853
 *
 
1854
 *          o The B+Tree rooted in an inode was verified structurally correct,
 
1855
 *            but the di_nblocks in the inode was found to be inconsistent with
 
1856
 *            the tree.  In this case we assume the tree to be corrupt and
 
1857
 *            back it out of the fsck workspace block map immediately.  This
 
1858
 *            routine would be used for that purpose since the tree has already
 
1859
 *            been verified structurally correct.
 
1860
 *
 
1861
 *          o An inode has been found to be valid, but claims ownership of at
 
1862
 *            least one block claimed by another inode. At least one of the
 
1863
 *            inodes is actually damaged.  The user has given permission to
 
1864
 *            delete this inode, and so we need to decrement the number of
 
1865
 *            owners for each block allocated to this inode.  This routine
 
1866
 *            would be used for that purpose since the tree has already been
 
1867
 *            verified structurally correct.
2057
1868
 *
2058
1869
 *
2059
1870
 * RETURNS:
2060
1871
 *      success: FSCK_OK
2061
1872
 *      failure: something else
2062
1873
 */
2063
 
retcode_t extent_unrecord ( fsblkidx_t  first_block,
2064
 
                            fsblkidx_t  last_block  )
 
1874
int extent_unrecord(int64_t first_block, int64_t last_block)
2065
1875
{
2066
 
  retcode_t   eu_rc = FSCK_OK;
2067
 
  fsblkidx_t  blkidx;
2068
 
 
2069
 
  for ( blkidx = first_block;
2070
 
      (blkidx <= last_block) && (eu_rc >= FSCK_OK);
2071
 
      blkidx++ ) {
2072
 
    eu_rc = blkall_decrement_owners( blkidx );
2073
 
  }  /* end for */
2074
 
 
2075
 
  return( eu_rc );
2076
 
}  /* end of extent_unrecord () */
2077
 
 
 
1876
        int eu_rc = FSCK_OK;
 
1877
        struct dupall_blkrec *this_blkrec;
 
1878
 
 
1879
        while (first_block <= last_block) {
 
1880
                this_blkrec = dupall_find_blkrec(first_block, last_block);
 
1881
                if (!this_blkrec)
 
1882
                        break;
 
1883
 
 
1884
                /*
 
1885
                 * If this record goes beyond the extent, we need to split it.
 
1886
                 */
 
1887
                if ((this_blkrec->first_blk < first_block) ||
 
1888
                    (this_blkrec->last_blk > last_block)) {
 
1889
                        eu_rc = blkall_split_blkrec(this_blkrec, first_block,
 
1890
                                                    last_block);
 
1891
                        if (eu_rc)
 
1892
                                return eu_rc;
 
1893
                        /*
 
1894
                         * Check if the split caused the current record to
 
1895
                         * precede the extent we are processing
 
1896
                         */
 
1897
                        if (this_blkrec->first_blk < first_block)
 
1898
                                continue;
 
1899
                }
 
1900
 
 
1901
                /*
 
1902
                 * Take care of the blocks preceding this record (if any)
 
1903
                 */
 
1904
                if (first_block < this_blkrec->first_blk) {
 
1905
                        eu_rc = blkall_mark_free(first_block,
 
1906
                                                 this_blkrec->first_blk - 1);
 
1907
                        if (eu_rc)
 
1908
                                return eu_rc;
 
1909
                }
 
1910
 
 
1911
                this_blkrec->owner_count--;
 
1912
                if (this_blkrec->owner_count == 1) {
 
1913
                        /* No longer a duplicate */
 
1914
                        if (!this_blkrec->first_ref_resolved)
 
1915
                                agg_recptr->unresolved_1stref_count--;
 
1916
                        agg_recptr->dup_block_count--;
 
1917
 
 
1918
                        dupall_extract_blkrec(this_blkrec);
 
1919
                }
 
1920
                first_block = this_blkrec->last_blk + 1;
 
1921
        }
 
1922
 
 
1923
        /*
 
1924
         * Take care of any remaining blocks
 
1925
         */
 
1926
        if (first_block <= last_block)
 
1927
                eu_rc = blkall_mark_free(first_block, last_block);
 
1928
 
 
1929
        return (eu_rc);
 
1930
}
2078
1931
 
2079
1932
/****************************************************************************
2080
1933
 * NAME: fsblk_count_avail
2105
1958
 *                            with the block described by wspbits, wordidx, and
2106
1959
 *                            bitidx when the routine was entered.
2107
1960
 *
2108
 
 * NOTES:
2109
 
 *
2110
1961
 * RETURNS:
2111
1962
 *      success: FSCK_OK
2112
1963
 *      failure: something else
2113
1964
 */
2114
 
retcode_t fsblk_count_avail ( fsck_bitmap_ptr  wspbits,
2115
 
                              int32_t          *wordidx,
2116
 
                              int32_t          *bitidx,
2117
 
                              int32_t          num_wanted,
2118
 
                              int32_t          *num_avail   )
 
1965
int fsblk_count_avail(uint32_t * wspbits,
 
1966
                      int32_t * wordidx,
 
1967
                      int32_t * bitidx, int32_t num_wanted, int32_t * num_avail)
2119
1968
{
2120
 
  retcode_t  fbca_rc = FSCK_OK;
2121
 
  int        done_counting = 0;
2122
 
  fsck_dword_bitmask_t  bitmask;
2123
 
 
2124
 
  *num_avail = 0;
2125
 
  while ( ((*wordidx) < LPERDMAP) && (!done_counting) ) {
2126
 
    bitmask = 0x80000000u;
2127
 
    bitmask = bitmask >> (*bitidx);
2128
 
    while ( ((*bitidx) < DBWORD) && (!done_counting) ) {
2129
 
      if ( wspbits[*wordidx] & bitmask ) {  /* this one's not available */
2130
 
        done_counting = -1;
2131
 
      } else {  /* this one's available */
2132
 
        (*num_avail)++;
2133
 
        if ( (*num_avail) == num_wanted ) {
2134
 
          done_counting = -1;
2135
 
        } else {
2136
 
          bitmask = bitmask >> 1;
2137
 
        }
2138
 
        (*bitidx)++;
2139
 
      }  /* end this one's available */
2140
 
    }  /* end while bitidx */
2141
 
    if ( !done_counting ) {
2142
 
      *bitidx = 0;
2143
 
      *wordidx += 1;
2144
 
    }
2145
 
  }  /* end while wordidx */
2146
 
 
2147
 
  return( fbca_rc );
2148
 
}  /* end fsblk_count_avail */
2149
 
 
 
1969
        int fbca_rc = FSCK_OK;
 
1970
        int done_counting = 0;
 
1971
        uint32_t bitmask;
 
1972
 
 
1973
        *num_avail = 0;
 
1974
        while (((*wordidx) < LPERDMAP) && (!done_counting)) {
 
1975
                bitmask = 0x80000000u;
 
1976
                bitmask = bitmask >> (*bitidx);
 
1977
                while (((*bitidx) < DBWORD) && (!done_counting)) {
 
1978
                        if (wspbits[*wordidx] & bitmask) {
 
1979
                                /* this one's not available */
 
1980
                                done_counting = -1;
 
1981
                        } else {
 
1982
                                /* this one's available */
 
1983
                                (*num_avail)++;
 
1984
                                if ((*num_avail) == num_wanted) {
 
1985
                                        done_counting = -1;
 
1986
                                } else {
 
1987
                                        bitmask = bitmask >> 1;
 
1988
                                }
 
1989
                                (*bitidx)++;
 
1990
                        }
 
1991
                }               /* end while bitidx */
 
1992
                if (!done_counting) {
 
1993
                        *bitidx = 0;
 
1994
                        *wordidx += 1;
 
1995
                }
 
1996
        }
 
1997
 
 
1998
        return (fbca_rc);
 
1999
}
2150
2000
 
2151
2001
/****************************************************************************
2152
2002
 * NAME: fsblk_next_avail
2174
2024
 *                                        0 => no available block was found in the
2175
2025
 *                                             given page at/after the specified start
2176
2026
 *
2177
 
 * NOTES:
2178
 
 *
2179
2027
 * RETURNS:
2180
2028
 *      success: FSCK_OK
2181
2029
 *      failure: something else
2182
2030
 */
2183
 
retcode_t fsblk_next_avail ( fsck_bitmap_ptr  wspbits,
2184
 
                             int32_t          startword,
2185
 
                             int32_t          startbit,
2186
 
                             int32_t          *foundword,
2187
 
                             int32_t          *foundbit,
2188
 
                             int              *block_found )
 
2031
int fsblk_next_avail(uint32_t * wspbits,
 
2032
                     int32_t startword,
 
2033
                     int32_t startbit,
 
2034
                     int32_t * foundword, int32_t * foundbit, int *block_found)
2189
2035
{
2190
 
  retcode_t  fbna_rc = FSCK_OK;
2191
 
  int32_t    wordidx, bitidx, firstbit;
2192
 
  fsck_dword_bitmask_t  bitmask;
2193
 
  fsck_dword_bitmask_t  mask_all_on = 0xFFFFFFFFu;
2194
 
 
2195
 
  *block_found = 0;
2196
 
  firstbit = startbit;
2197
 
  for ( wordidx = startword;
2198
 
      ( (wordidx < LPERDMAP) && (!(*block_found)) );
2199
 
      wordidx++ ) {
2200
 
    if ( wspbits[wordidx] != mask_all_on ) {  /* a zero in this map word */
2201
 
      bitmask = 0x80000000u;
2202
 
      bitmask = bitmask >> firstbit;
2203
 
      for ( bitidx = firstbit;
2204
 
          ( (bitidx < DBWORD) && (!(*block_found)) );
2205
 
          bitidx++ ) {
2206
 
        if ( !(wspbits[wordidx] & bitmask) ) {  /* it's available */
2207
 
          *foundword = wordidx;
2208
 
          *foundbit = bitidx;
2209
 
          *block_found = -1;
2210
 
        } else {  /* it's in use */
2211
 
          bitmask = bitmask >> 1;
2212
 
        }  /* end else it's in use */
2213
 
      }  /* end for bitidx */
2214
 
    }  /* end a zero in this map word */
2215
 
    firstbit = 0;
2216
 
  }  /* end for wordidx */
2217
 
 
2218
 
  return( fbna_rc );
2219
 
}  /* end fsblk_next_avail */
2220
 
 
 
2036
        int fbna_rc = FSCK_OK;
 
2037
        int32_t wordidx, bitidx, firstbit;
 
2038
        uint32_t bitmask;
 
2039
        uint32_t mask_all_on = 0xFFFFFFFFu;
 
2040
 
 
2041
        *block_found = 0;
 
2042
        firstbit = startbit;
 
2043
        for (wordidx = startword; ((wordidx < LPERDMAP) && (!(*block_found)));
 
2044
             wordidx++) {
 
2045
                if (wspbits[wordidx] != mask_all_on) {
 
2046
                        /* a zero in this map word */
 
2047
                        bitmask = 0x80000000u;
 
2048
                        bitmask = bitmask >> firstbit;
 
2049
                        for (bitidx = firstbit;
 
2050
                             ((bitidx < DBWORD) && (!(*block_found)));
 
2051
                             bitidx++) {
 
2052
                                if (!(wspbits[wordidx] & bitmask)) {
 
2053
                                        /* it's available */
 
2054
                                        *foundword = wordidx;
 
2055
                                        *foundbit = bitidx;
 
2056
                                        *block_found = -1;
 
2057
                                } else {
 
2058
                                        /* it's in use */
 
2059
                                        bitmask = bitmask >> 1;
 
2060
                                }
 
2061
                        }
 
2062
                }
 
2063
                firstbit = 0;
 
2064
        }
 
2065
        return (fbna_rc);
 
2066
}
2221
2067
 
2222
2068
/****************************************************************************
2223
2069
 * NAME: fsck_alloc_fsblks
2259
2105
 *      success: FSCK_OK
2260
2106
 *      failure: something else
2261
2107
 */
2262
 
retcode_t fsck_alloc_fsblks ( int32_t     blocks_wanted,
2263
 
                              fsblkidx_t  *blocks        )
 
2108
int fsck_alloc_fsblks(int32_t blocks_wanted, int64_t * blocks)
2264
2109
{
2265
 
  retcode_t    fafsb_rc = FSCK_OK;
2266
 
  mappgidx_t   wsp_pagenum = 0;
2267
 
  blk_pageptr  wsp_page = NULL;
2268
 
  int32_t      this_word = 0, this_bit = 0;
2269
 
  int32_t      found_word = -1, found_bit = -1;
2270
 
  int          found_a_block;
2271
 
  int32_t      blocks_found = 0;
2272
 
  fsck_bitmap_ptr  wsp_bits;
2273
 
 
2274
 
  *blocks = 0;
2275
 
 
2276
 
  while ( (wsp_pagenum < agg_recptr->blkmp_pagecount) &&
2277
 
          (blocks_found != blocks_wanted)             &&
2278
 
          (fafsb_rc == FSCK_OK)                          ) {
2279
 
    fafsb_rc = blkmap_get_page( wsp_pagenum, &wsp_page );
2280
 
    if ( fafsb_rc == FSCK_OK ) {  /* got a page */
2281
 
      wsp_bits = (fsck_bitmap_ptr) wsp_page;
2282
 
      this_word = 0;
2283
 
      this_bit = 0;
2284
 
      found_a_block = 0;
2285
 
      blocks_found = 0;
2286
 
      fafsb_rc = fsblk_next_avail( wsp_bits, this_word, this_bit,
2287
 
                                   &found_word, &found_bit, &found_a_block );
2288
 
      while ( (found_a_block) &&
2289
 
              (fafsb_rc == FSCK_OK) &&
2290
 
              (blocks_found != blocks_wanted) ) {
2291
 
        this_word = found_word;
2292
 
        this_bit = found_bit;
2293
 
        blocks_found = 0;
2294
 
 
2295
 
        fafsb_rc = fsblk_count_avail( wsp_bits, &found_word, &found_bit,
2296
 
                                      blocks_wanted, &blocks_found );
2297
 
        if ( fafsb_rc == FSCK_OK ) {  /* nothing bizarre happened */
2298
 
          if ( blocks_found == blocks_wanted ) {  /* success! */
2299
 
            *blocks = (wsp_pagenum << log2BITSPERPAGE) +
2300
 
                      (this_word << log2BITSPERDWORD) +
2301
 
                      this_bit;
2302
 
          } else {  /* nothing useful yet */
2303
 
            this_word = found_word;  /* word containing 1st 1 after the zeroes */
2304
 
            this_bit = found_bit;    /* bit postion in that word */
2305
 
            found_a_block = 0;
2306
 
            fafsb_rc = fsblk_next_avail( wsp_bits, this_word, this_bit,
2307
 
                                         &found_word, &found_bit,
2308
 
                                         &found_a_block );
2309
 
          }  /* end else nothing useful yet */
2310
 
        }  /* end nothing bizarre happened */
2311
 
      }  /* end while */
2312
 
      if ( (fafsb_rc == FSCK_OK) && (!found_a_block) ) {  /* no avail block found */
2313
 
        wsp_pagenum++;               /* maybe in the next page */
2314
 
      }  /* end no avail block found */
2315
 
    }  /* end got a page */
2316
 
  }  /* end while */
2317
 
 
2318
 
  if ( fafsb_rc == FSCK_OK ) {  /* nothing fatal along the way */
2319
 
    if ( (*blocks) == 0 ) {  /* didn't find the blocks */
2320
 
      fafsb_rc = FSCK_BLKSNOTAVAILABLE;
2321
 
      sprintf( message_parm_0, "%d", blocks_wanted );
2322
 
      msgprms[0] = message_parm_0;
2323
 
      msgprmidx[0] = 0;
2324
 
      fsck_send_msg( fsck_EXHFILSYSSTG, 0, 1 );
2325
 
    } else if ( (*blocks) > agg_recptr->highest_valid_fset_datablk ) {  
2326
 
        /*
2327
 
         * the first available blocks were in the work area
2328
 
         */
2329
 
      *blocks = 0;
2330
 
      fafsb_rc = FSCK_BLKSNOTAVAILABLE;
2331
 
      sprintf( message_parm_0, "%d", blocks_wanted );
2332
 
      msgprms[0] = message_parm_0;
2333
 
      msgprmidx[0] = 0;
2334
 
      fsck_send_msg( fsck_EXHFILSYSSTG, 0, 1 );
2335
 
    } else {  /* we found the requested blocks */
2336
 
      fafsb_rc = extent_record( *blocks, (*blocks + blocks_wanted - 1) ); /*
2337
 
                                 * allocate these blocks for the caller
2338
 
                                 * by marking them 'in use' in the fsck
2339
 
                                 * workspace block map
2340
 
                                 */
2341
 
    }  /* end else we found the requested blocks */
2342
 
  }  /* end nothing fatal along the way */
2343
 
 
2344
 
  return( fafsb_rc );
2345
 
}  /* end fsck_alloc_fsblks */
2346
 
 
 
2110
        int fafsb_rc = FSCK_OK;
 
2111
        int64_t wsp_pagenum = 0;
 
2112
        struct fsck_blk_map_page *wsp_page = NULL;
 
2113
        int32_t this_word = 0, this_bit = 0;
 
2114
        int32_t found_word = -1, found_bit = -1;
 
2115
        int found_a_block;
 
2116
        int32_t blocks_found = 0;
 
2117
        uint32_t *wsp_bits;
 
2118
 
 
2119
        *blocks = 0;
 
2120
 
 
2121
        while ((wsp_pagenum < agg_recptr->blkmp_pagecount) &&
 
2122
               (blocks_found != blocks_wanted) && (fafsb_rc == FSCK_OK)) {
 
2123
                fafsb_rc = blkmap_get_page(wsp_pagenum, &wsp_page);
 
2124
                if (fafsb_rc == FSCK_OK) {
 
2125
                        /* got a page */
 
2126
                        wsp_bits = (uint32_t *) wsp_page;
 
2127
                        this_word = 0;
 
2128
                        this_bit = 0;
 
2129
                        found_a_block = 0;
 
2130
                        blocks_found = 0;
 
2131
                        fafsb_rc =
 
2132
                            fsblk_next_avail(wsp_bits, this_word, this_bit,
 
2133
                                             &found_word, &found_bit,
 
2134
                                             &found_a_block);
 
2135
                        while ((found_a_block) && (fafsb_rc == FSCK_OK)
 
2136
                               && (blocks_found != blocks_wanted)) {
 
2137
                                this_word = found_word;
 
2138
                                this_bit = found_bit;
 
2139
                                blocks_found = 0;
 
2140
 
 
2141
                                fafsb_rc =
 
2142
                                    fsblk_count_avail(wsp_bits, &found_word,
 
2143
                                                      &found_bit, blocks_wanted,
 
2144
                                                      &blocks_found);
 
2145
                                if (fafsb_rc == FSCK_OK) {
 
2146
                                        /* nothing bizarre happened */
 
2147
                                        if (blocks_found == blocks_wanted) {
 
2148
                                                /* success! */
 
2149
                                                *blocks =
 
2150
                                                    (wsp_pagenum <<
 
2151
                                                     log2BITSPERPAGE) +
 
2152
                                                    (this_word <<
 
2153
                                                     log2BITSPERDWORD) +
 
2154
                                                    this_bit;
 
2155
                                        } else {
 
2156
                                                /* word containing 1st 1 after the zeroes */
 
2157
                                                this_word = found_word;
 
2158
                                                /* bit postion in that word */
 
2159
                                                this_bit = found_bit;
 
2160
                                                found_a_block = 0;
 
2161
                                                fafsb_rc =
 
2162
                                                    fsblk_next_avail(wsp_bits,
 
2163
                                                                     this_word,
 
2164
                                                                     this_bit,
 
2165
                                                                     &found_word,
 
2166
                                                                     &found_bit,
 
2167
                                                                     &found_a_block);
 
2168
                                        }
 
2169
                                }
 
2170
                        }
 
2171
                        if ((fafsb_rc == FSCK_OK) && (!found_a_block)) {
 
2172
                                /* no avail block found */
 
2173
                                /* maybe in the next page */
 
2174
                                wsp_pagenum++;
 
2175
                        }
 
2176
                }
 
2177
        }
 
2178
 
 
2179
        if (fafsb_rc == FSCK_OK) {
 
2180
                /* nothing fatal along the way */
 
2181
                if ((*blocks) == 0) {
 
2182
                        /* didn't find the blocks */
 
2183
                        fafsb_rc = FSCK_BLKSNOTAVAILABLE;
 
2184
                        fsck_send_msg(fsck_EXHFILSYSSTG, blocks_wanted);
 
2185
                } else if ((*blocks) > agg_recptr->highest_valid_fset_datablk) {
 
2186
                        /*
 
2187
                         * the first available blocks were in the work area
 
2188
                         */
 
2189
                        *blocks = 0;
 
2190
                        fafsb_rc = FSCK_BLKSNOTAVAILABLE;
 
2191
                        fsck_send_msg(fsck_EXHFILSYSSTG, blocks_wanted);
 
2192
                } else {
 
2193
                        /* we found the requested blocks */
 
2194
                        /*
 
2195
                         * allocate these blocks for the caller
 
2196
                         * by marking them 'in use' in the fsck
 
2197
                         * workspace block map
 
2198
                         */
 
2199
                        fafsb_rc =
 
2200
                            extent_record(*blocks,
 
2201
                                          (*blocks + blocks_wanted - 1));
 
2202
                }
 
2203
        }
 
2204
        return (fafsb_rc);
 
2205
}
2347
2206
 
2348
2207
/****************************************************************************
2349
2208
 * NAME: fsck_dealloc_fsblks
2376
2235
 *      success: FSCK_OK
2377
2236
 *      failure: something else
2378
2237
 */
2379
 
retcode_t fsck_dealloc_fsblks ( int32_t     blk_length,
2380
 
                                fsblkidx_t  first_blk  )
 
2238
int fsck_dealloc_fsblks(int32_t blk_length, int64_t first_blk)
2381
2239
{
2382
 
  retcode_t  fdfsb_rc = FSCK_OK;
2383
 
 
2384
 
  fdfsb_rc = extent_unrecord( first_blk, (first_blk + blk_length - 1) ); /*
2385
 
                                 * deallocate these blocks by marking
2386
 
                                 * them 'available' in the fsck workspace
2387
 
                                 * block map
2388
 
                                 */
2389
 
 
2390
 
  return( fdfsb_rc );
2391
 
}  /* end fsck_dealloc_fsblks */
2392
 
 
 
2240
        int fdfsb_rc = FSCK_OK;
 
2241
 
 
2242
        /*
 
2243
           * deallocate these blocks by marking
 
2244
           * them 'available' in the fsck workspace
 
2245
           * block map
 
2246
         */
 
2247
        fdfsb_rc = extent_unrecord(first_blk, (first_blk + blk_length - 1));
 
2248
 
 
2249
        return (fdfsb_rc);
 
2250
}
2393
2251
 
2394
2252
/****************************************************************************
2395
2253
 * NAME: fscklog_end
2405
2263
 * RETURNS:
2406
2264
 *      success: FSCK_OK
2407
2265
 */
2408
 
retcode_t fscklog_end ( )
 
2266
int fscklog_end()
2409
2267
{
2410
 
  retcode_t  fle_rc = FSCK_OK;
2411
 
  int32_t    buffer_bytes_left;
2412
 
  /*
2413
 
   * If there's a partial buffer, write it to the device
2414
 
   */
2415
 
  if ( agg_recptr->fscklog_buf_data_len > 0 ) {  
2416
 
      /*
2417
 
       * there's something in there to be written
2418
 
       */
2419
 
    buffer_bytes_left = agg_recptr->fscklog_buf_length -
2420
 
                        agg_recptr->fscklog_buf_data_len;
2421
 
    agg_recptr->fscklog_last_msghdr->entry_length += buffer_bytes_left;
2422
 
    fscklog_put_buffer();
2423
 
  }  /* end there's something in there to be written */
2424
 
 
2425
 
  agg_recptr->fscklog_buf_allocated = 0; /*
2426
 
                         * disable logging for the duration
2427
 
                         */
2428
 
 
2429
 
  return( fle_rc );
2430
 
}  /* end fscklog_end */
2431
 
 
 
2268
        int fle_rc = FSCK_OK;
 
2269
        int32_t buffer_bytes_left;
 
2270
        /*
 
2271
         * If there's a partial buffer, write it to the device
 
2272
         */
 
2273
        if (agg_recptr->fscklog_buf_data_len > 0) {
 
2274
                /*
 
2275
                 * there's something in there to be written
 
2276
                 */
 
2277
                buffer_bytes_left = agg_recptr->fscklog_buf_length -
 
2278
                    agg_recptr->fscklog_buf_data_len;
 
2279
                agg_recptr->fscklog_last_msghdr->entry_length +=
 
2280
                    __le16_to_cpu((int16_t) buffer_bytes_left);
 
2281
                fscklog_put_buffer();
 
2282
        }
 
2283
        /* disable logging for the duration */
 
2284
        agg_recptr->fscklog_buf_allocated = 0;
 
2285
 
 
2286
        return (fle_rc);
 
2287
}
2432
2288
 
2433
2289
/****************************************************************************
2434
2290
 * NAME: fscklog_init
2448
2304
 * RETURNS:
2449
2305
 *      success: FSCK_OK
2450
2306
 */
2451
 
retcode_t fscklog_init ( )
 
2307
int fscklog_init()
2452
2308
{
2453
 
  retcode_t      fli_rc = FSCK_OK;
2454
 
  agg_byteidx_t  log_bytes_left;
2455
 
  struct fsck_blk_map_page  *tmpbuf_addr = NULL;
2456
 
  struct fsck_blk_map_page  *tmp_buf_ptr;
2457
 
  reg_idx_t      tmp_buf_data_len;
2458
 
  agg_byteidx_t  tmp_agg_offset;
2459
 
  agg_byteidx_t  tmp_log_offset;
2460
 
 
2461
 
  if ( agg_recptr->processing_readwrite ) {  /* have write access */
2462
 
    /*
2463
 
     * this is safe because we do it before calling logredo
2464
 
     */
2465
 
    tmpbuf_addr = (struct fsck_blk_map_page *) malloc(FSCKLOG_BUFSIZE);
2466
 
 
2467
 
    if ( tmpbuf_addr == NULL ) {  /* didn't get the space */
2468
 
      fsck_send_msg( fsck_CANTINITSVCLOG, 0, 0 );  /* log this fact so
2469
 
                       * that any residual messages will be ignored
2470
 
                       */
2471
 
    } else {  /* temp buffer allocated */
2472
 
      agg_recptr->initializing_fscklog = 1;
2473
 
      memset( (void *) tmpbuf_addr, 0, FSCKLOG_BUFSIZE );
2474
 
      /*
2475
 
       * save the current fscklog values
2476
 
       */
2477
 
      tmp_buf_ptr = agg_recptr->fscklog_buf_ptr;
2478
 
      tmp_buf_data_len = agg_recptr->fscklog_buf_data_len;
2479
 
      tmp_agg_offset = agg_recptr->fscklog_agg_offset;
2480
 
      tmp_log_offset = agg_recptr->fscklog_log_offset;
2481
 
      /*
2482
 
       * store values to describe the temp buffer
2483
 
       */
2484
 
      agg_recptr->fscklog_buf_ptr = tmpbuf_addr;
2485
 
      agg_recptr->fscklog_buf_data_len = FSCKLOG_BUFSIZE;
2486
 
 
2487
 
      log_bytes_left = (agg_recptr->ondev_fscklog_byte_length / 2) -
2488
 
                       agg_recptr->fscklog_log_offset;
2489
 
      while ( log_bytes_left >= agg_recptr->fscklog_buf_length ) {
2490
 
        fscklog_put_buffer();
2491
 
        log_bytes_left = (agg_recptr->ondev_fscklog_byte_length / 2) -
2492
 
                         agg_recptr->fscklog_log_offset;
2493
 
      }  /* end while */
2494
 
 
2495
 
      free( (void *) tmpbuf_addr );
2496
 
      /*
2497
 
       * restore the actual fscklog values
2498
 
       */
2499
 
      agg_recptr->fscklog_buf_ptr = tmp_buf_ptr;
2500
 
      agg_recptr->fscklog_buf_data_len = tmp_buf_data_len;
2501
 
      agg_recptr->fscklog_agg_offset = tmp_agg_offset;
2502
 
      agg_recptr->fscklog_log_offset = tmp_log_offset;
2503
 
 
2504
 
      agg_recptr->initializing_fscklog = 0;
2505
 
    }  /* end else temp buffer allocated */
2506
 
  }  /* end have write access */
2507
 
 
2508
 
  return( fli_rc );
2509
 
}  /* end fscklog_init */
2510
 
 
 
2309
        int fli_rc = FSCK_OK;
 
2310
        int64_t log_bytes_left;
 
2311
        struct fsck_blk_map_page *tmpbuf_addr = NULL;
 
2312
        struct fsck_blk_map_page *tmp_buf_ptr;
 
2313
        uint32_t tmp_buf_data_len;
 
2314
        int64_t tmp_agg_offset;
 
2315
        int64_t tmp_log_offset;
 
2316
 
 
2317
        if (agg_recptr->processing_readwrite) {
 
2318
                /* have write access */
 
2319
                /*
 
2320
                 * this is safe because we do it before calling logredo
 
2321
                 */
 
2322
                tmpbuf_addr =
 
2323
                    (struct fsck_blk_map_page *) malloc(FSCKLOG_BUFSIZE);
 
2324
 
 
2325
                if (tmpbuf_addr == NULL) {
 
2326
                        /* didn't get the space */
 
2327
                        /* log this fact so that any residual messages will be ignored */
 
2328
                        fsck_send_msg(fsck_CANTINITSVCLOG);
 
2329
                } else {
 
2330
                        /* temp buffer allocated */
 
2331
                        agg_recptr->initializing_fscklog = 1;
 
2332
                        memset((void *) tmpbuf_addr, 0, FSCKLOG_BUFSIZE);
 
2333
                        /*
 
2334
                         * save the current fscklog values
 
2335
                         */
 
2336
                        tmp_buf_ptr = agg_recptr->fscklog_buf_ptr;
 
2337
                        tmp_buf_data_len = agg_recptr->fscklog_buf_data_len;
 
2338
                        tmp_agg_offset = agg_recptr->fscklog_agg_offset;
 
2339
                        tmp_log_offset = agg_recptr->fscklog_log_offset;
 
2340
                        /*
 
2341
                         * store values to describe the temp buffer
 
2342
                         */
 
2343
                        agg_recptr->fscklog_buf_ptr = tmpbuf_addr;
 
2344
                        agg_recptr->fscklog_buf_data_len = FSCKLOG_BUFSIZE;
 
2345
 
 
2346
                        log_bytes_left =
 
2347
                            (agg_recptr->ondev_fscklog_byte_length / 2) -
 
2348
                            agg_recptr->fscklog_log_offset;
 
2349
                        while (log_bytes_left >= agg_recptr->fscklog_buf_length) {
 
2350
                                fscklog_put_buffer();
 
2351
                                log_bytes_left =
 
2352
                                    (agg_recptr->ondev_fscklog_byte_length /
 
2353
                                     2) - agg_recptr->fscklog_log_offset;
 
2354
                        }       /* end while */
 
2355
 
 
2356
                        free((void *) tmpbuf_addr);
 
2357
                        /*
 
2358
                         * restore the actual fscklog values
 
2359
                         */
 
2360
                        agg_recptr->fscklog_buf_ptr = tmp_buf_ptr;
 
2361
                        agg_recptr->fscklog_buf_data_len = tmp_buf_data_len;
 
2362
                        agg_recptr->fscklog_agg_offset = tmp_agg_offset;
 
2363
                        agg_recptr->fscklog_log_offset = tmp_log_offset;
 
2364
 
 
2365
                        agg_recptr->initializing_fscklog = 0;
 
2366
                }
 
2367
        }
 
2368
        return (fli_rc);
 
2369
}
2511
2370
 
2512
2371
/****************************************************************************
2513
2372
 * NAME: fscklog_start
2525
2384
 * RETURNS:
2526
2385
 *      success: FSCK_OK
2527
2386
 */
2528
 
retcode_t fscklog_start ( )
 
2387
int fscklog_start()
2529
2388
{
2530
 
  retcode_t  fls_rc = FSCK_OK;
2531
 
  retcode_t  iml_rc = FSCK_OK;
2532
 
  int        I_am_logredo = 0;
2533
 
 
2534
 
  iml_rc = alloc_wrksp( FSCKLOG_BUFSIZE, dynstg_iobufs,
2535
 
                        I_am_logredo,
2536
 
                        (void **) &(agg_recptr->fscklog_buf_ptr) );
2537
 
 
2538
 
  if ( iml_rc == FSCK_OK ) {  /* successful fsck service log buffer alloc */
2539
 
    agg_recptr->fscklog_buf_length = FSCKLOG_BUFSIZE;
2540
 
    agg_recptr->fscklog_buf_data_len = 0;
2541
 
    agg_recptr->fscklog_log_offset = 0;
2542
 
    agg_recptr->fscklog_full = 0;
2543
 
    agg_recptr->fscklog_buf_allocated = -1;
2544
 
    agg_recptr->fscklog_buf_alloc_err = 0;
2545
 
  } else {
2546
 
    agg_recptr->fscklog_buf_allocated = 0;
2547
 
    agg_recptr->fscklog_buf_alloc_err = -1;
2548
 
  }
2549
 
 
2550
 
  return( fls_rc );
2551
 
}  /* end fscklog_start */
2552
 
 
 
2389
        int fls_rc = FSCK_OK;
 
2390
        int iml_rc = FSCK_OK;
 
2391
        int I_am_logredo = 0;
 
2392
 
 
2393
        iml_rc = alloc_wrksp(FSCKLOG_BUFSIZE, dynstg_iobufs,
 
2394
                             I_am_logredo,
 
2395
                             (void **) &(agg_recptr->fscklog_buf_ptr));
 
2396
 
 
2397
        if (iml_rc == FSCK_OK) {
 
2398
                /* successful fsck service log buffer alloc */
 
2399
                agg_recptr->fscklog_buf_length = FSCKLOG_BUFSIZE;
 
2400
                agg_recptr->fscklog_buf_data_len = 0;
 
2401
                agg_recptr->fscklog_log_offset = 0;
 
2402
                agg_recptr->fscklog_full = 0;
 
2403
                agg_recptr->fscklog_buf_allocated = -1;
 
2404
                agg_recptr->fscklog_buf_alloc_err = 0;
 
2405
        } else {
 
2406
                agg_recptr->fscklog_buf_allocated = 0;
 
2407
                agg_recptr->fscklog_buf_alloc_err = -1;
 
2408
        }
 
2409
 
 
2410
        return (fls_rc);
 
2411
}
2553
2412
 
2554
2413
/****************************************************************************
2555
2414
 * NAME: get_inode_extension
2560
2419
 *      inoext_ptr  - input - pointer to a variable in which the address of the
2561
2420
 *                            new inode extension will be returned.
2562
2421
 *
2563
 
 * NOTES:
2564
 
 *
2565
2422
 * RETURNS:
2566
2423
 *      success: FSCK_OK
2567
2424
 *      failure: something else
2568
2425
 */
2569
 
retcode_t get_inode_extension ( fsck_inode_extptr  *inoext_ptr )
 
2426
int get_inode_extension(struct fsck_inode_ext_record **inoext_ptr)
2570
2427
{
2571
 
  retcode_t  gir_rc = FSCK_OK;
2572
 
  int        I_am_logredo = 0;
2573
 
 
2574
 
  if ( agg_recptr->free_inode_extens != NULL ) {
2575
 
    *inoext_ptr = agg_recptr->free_inode_extens;
2576
 
    agg_recptr->free_inode_extens = agg_recptr->free_inode_extens->next;
2577
 
    memset ( *inoext_ptr, 0, sizeof(struct fsck_inode_ext_record) );
2578
 
  } else {
2579
 
    gir_rc = alloc_wrksp( sizeof(struct fsck_inode_ext_record),
2580
 
                          dynstg_inoextrec, I_am_logredo,
2581
 
                          (void **) inoext_ptr );
2582
 
  }
2583
 
 
2584
 
  return( gir_rc );
2585
 
}  /* end get_inode_extension */
2586
 
 
 
2428
        int gir_rc = FSCK_OK;
 
2429
        int I_am_logredo = 0;
 
2430
 
 
2431
        if (agg_recptr->free_inode_extens != NULL) {
 
2432
                *inoext_ptr = agg_recptr->free_inode_extens;
 
2433
                agg_recptr->free_inode_extens =
 
2434
                    agg_recptr->free_inode_extens->next;
 
2435
                memset(*inoext_ptr, 0, sizeof (struct fsck_inode_ext_record));
 
2436
        } else {
 
2437
                gir_rc = alloc_wrksp(sizeof (struct fsck_inode_ext_record),
 
2438
                                     dynstg_inoextrec, I_am_logredo,
 
2439
                                     (void **) inoext_ptr);
 
2440
        }
 
2441
 
 
2442
        return (gir_rc);
 
2443
}
2587
2444
 
2588
2445
/****************************************************************************
2589
2446
 * NAME: get_inorecptr
2610
2467
 *                                of the found (or newly allocated) record will
2611
2468
 *                                be returned
2612
2469
 *
2613
 
 * NOTES:
2614
 
 *
2615
2470
 * RETURNS:
2616
2471
 *      success: FSCK_OK
2617
2472
 *      failure: something else
2618
2473
 */
2619
 
retcode_t get_inorecptr ( int                is_aggregate,
2620
 
                          int                alloc,
2621
 
                          inoidx_t           inonum,
2622
 
                          fsck_inode_recptr  *addr_inorecptr )
 
2474
int get_inorecptr(int is_aggregate,
 
2475
                  int alloc,
 
2476
                  uint32_t inonum, struct fsck_inode_record **addr_inorecptr)
2623
2477
{
2624
 
  retcode_t  gir_rc = FSCK_OK;
2625
 
 
2626
 
  if ( is_aggregate ) {  /* for an aggregate inode */
2627
 
    if ( alloc ) {  /* request is to allocate if not found */
2628
 
      gir_rc = inorec_agg_search_insert( inonum, addr_inorecptr );         
2629
 
    } else {  /* search only */
2630
 
      gir_rc = inorec_agg_search( inonum, addr_inorecptr );                
2631
 
    }  /* end else search only */
2632
 
  } else {  /* for a fileset inode */
2633
 
    if ( alloc ) {  /* request is to allocate if not found */
2634
 
      gir_rc = inorec_fs_search_insert( inonum, addr_inorecptr );        
2635
 
    } else {  /* search only */
2636
 
      gir_rc = inorec_fs_search( inonum, addr_inorecptr );                  
2637
 
    }  /* end else search only */
2638
 
  }  /* end else for a fileset inode */
2639
 
 
2640
 
  return( gir_rc );
2641
 
}  /* end get_inorecptr */
2642
 
 
 
2478
        int gir_rc = FSCK_OK;
 
2479
 
 
2480
        if (is_aggregate) {
 
2481
                /* for an aggregate inode */
 
2482
                if (alloc) {
 
2483
                        /* request is to allocate if not found */
 
2484
                        gir_rc =
 
2485
                            inorec_agg_search_insert(inonum, addr_inorecptr);
 
2486
                } else {
 
2487
                        /* search only */
 
2488
                        gir_rc = inorec_agg_search(inonum, addr_inorecptr);
 
2489
                }
 
2490
        } else {
 
2491
                /* for a fileset inode */
 
2492
                if (alloc) {
 
2493
                        /* request is to allocate if not found */
 
2494
                        gir_rc =
 
2495
                            inorec_fs_search_insert(inonum, addr_inorecptr);
 
2496
                } else {
 
2497
                        /* search only */
 
2498
                        gir_rc = inorec_fs_search(inonum, addr_inorecptr);
 
2499
                }
 
2500
        }
 
2501
 
 
2502
        return (gir_rc);
 
2503
}
2643
2504
 
2644
2505
/****************************************************************************
2645
2506
 * NAME: get_inorecptr_first
2682
2543
 *      success: FSCK_OK
2683
2544
 *      failure: something else
2684
2545
 */
2685
 
retcode_t get_inorecptr_first ( int                is_aggregate,
2686
 
                                inoidx_t           *inonum,
2687
 
                                fsck_inode_recptr  *addr_inorecptr  )
 
2546
int get_inorecptr_first(int is_aggregate,
 
2547
                        uint32_t * inonum,
 
2548
                        struct fsck_inode_record **addr_inorecptr)
2688
2549
{
2689
 
  retcode_t      girf_rc = FSCK_OK;
2690
 
  int32_t        iagidx, extidx, inoidx;                                                
2691
 
  inoext_tblptr  inoexttbl;                                                   
2692
 
  ino_tblptr     inotbl;                                                         
2693
 
 
2694
 
  /*
2695
 
   * find first active aggregate inode record
2696
 
   */
2697
 
  if ( is_aggregate ) {  /* for an aggregate inode */
2698
 
    if ( agg_recptr->AIT_ext0_tbl == NULL ) {                          
2699
 
      girf_rc = FSCK_INTERNAL_ERROR_68;                                
2700
 
 
2701
 
      sprintf( message_parm_0, "%d", girf_rc );                        
2702
 
      msgprms[0] = message_parm_0;                                     
2703
 
      msgprmidx[0] = 0;                                                
2704
 
      sprintf( message_parm_1, "%d", 0 );                              
2705
 
      msgprms[1] = message_parm_1;                                     
2706
 
      msgprmidx[1] = 0;                                                
2707
 
      sprintf( message_parm_2, "%d", 0 );                              
2708
 
      msgprms[2] = message_parm_2;                                     
2709
 
      msgprmidx[2] = 0;                                                
2710
 
      sprintf( message_parm_3, "%d", 0 );                              
2711
 
      msgprms[3] = message_parm_3;                                     
2712
 
      msgprmidx[3] = 0;                                                
2713
 
      fsck_send_msg( fsck_INTERNALERROR, 0, 4 );                       
2714
 
    } else {                                                                             
2715
 
      /*
2716
 
       * the first allocated aggregate inode is inode 1,
2717
 
       * by definition.
2718
 
       */
2719
 
      inoidx = 1;                                                                 
2720
 
      *addr_inorecptr =
2721
 
      agg_recptr->AIT_ext0_tbl->inorectbl[inoidx];    
2722
 
      agg_recptr->agg_last_inoidx = inoidx;            
2723
 
    }                                                  
2724
 
 
2725
 
  /*
2726
 
   * find first active fileset inode record
2727
 
   */
2728
 
  } else {  /* for a fileset inode */                                    
2729
 
    if ( agg_recptr->FSIT_IAG_tbl == NULL ) { 
2730
 
      girf_rc = FSCK_INTERNAL_ERROR_69;                           
2731
 
      sprintf( message_parm_0, "%d", girf_rc );                   
2732
 
      msgprms[0] = message_parm_0;                                
2733
 
      msgprmidx[0] = 0;                                           
2734
 
      sprintf( message_parm_1, "%d", 0 );                         
2735
 
      msgprms[1] = message_parm_1;                                
2736
 
      msgprmidx[1] = 0;                                           
2737
 
      sprintf( message_parm_2, "%d", 0 );                         
2738
 
      msgprms[2] = message_parm_2;                                
2739
 
      msgprmidx[2] = 0;                                           
2740
 
      sprintf( message_parm_3, "%d", 0 );                         
2741
 
      msgprms[3] = message_parm_3;                                
2742
 
      msgprmidx[3] = 0;                                           
2743
 
      fsck_send_msg( fsck_INTERNALERROR, 0, 4 );                  
2744
 
    } else {  /* the table is allocated */
2745
 
      /*
2746
 
       * IAG 0 is always the first active IAG in the
2747
 
       * fileset and extent 0 is always the first active
2748
 
       * extent since inode 2 (the root dir) is always
2749
 
       * the first active inode.
2750
 
       */
2751
 
      iagidx = 0;                                                             
2752
 
      extidx = 0;                                                             
2753
 
      inoidx = 2;                                                             
2754
 
 
2755
 
      inoexttbl = agg_recptr->FSIT_IAG_tbl->inoext_tbl[iagidx];   
2756
 
      inotbl = inoexttbl->inotbl[extidx];                                 
2757
 
      *addr_inorecptr = inotbl->inorectbl[inoidx];                        
2758
 
      /*
2759
 
       * set things up for find next
2760
 
       */
2761
 
      agg_recptr->fs_last_iagidx = iagidx;                                  
2762
 
      agg_recptr->fs_last_extidx = extidx;                                  
2763
 
      agg_recptr->fs_last_inoidx = inoidx;                                  
2764
 
    }  /* end else the table is allocated */
2765
 
  }  /* end else for a fileset inode */
2766
 
 
2767
 
  if ( girf_rc == FSCK_OK ) {  /* got one */
2768
 
    *inonum = (*addr_inorecptr)->inonum;
2769
 
  }
2770
 
 
2771
 
  return( girf_rc );
2772
 
}  /* end get_inorecptr_first */
2773
 
 
 
2550
        int girf_rc = FSCK_OK;
 
2551
        int32_t iagidx, extidx, inoidx;
 
2552
        struct inode_ext_tbl_t *inoexttbl;
 
2553
        struct inode_tbl_t *inotbl;
 
2554
 
 
2555
        /*
 
2556
         * find first active aggregate inode record
 
2557
         */
 
2558
        if (is_aggregate) {     /* for an aggregate inode */
 
2559
                if (agg_recptr->AIT_ext0_tbl == NULL) {
 
2560
                        girf_rc = FSCK_INTERNAL_ERROR_68;
 
2561
 
 
2562
                        fsck_send_msg(fsck_INTERNALERROR, girf_rc, 0, 0, 0);
 
2563
                } else {
 
2564
                        /*
 
2565
                         * the first allocated aggregate inode is inode 1,
 
2566
                         * by definition.
 
2567
                         */
 
2568
                        inoidx = 1;
 
2569
                        *addr_inorecptr =
 
2570
                            agg_recptr->AIT_ext0_tbl->inorectbl[inoidx];
 
2571
                        agg_recptr->agg_last_inoidx = inoidx;
 
2572
                }
 
2573
 
 
2574
                /*
 
2575
                 * find first active fileset inode record
 
2576
                 */
 
2577
        } else {
 
2578
                /* for a fileset inode */
 
2579
                if (agg_recptr->FSIT_IAG_tbl == NULL) {
 
2580
                        girf_rc = FSCK_INTERNAL_ERROR_69;
 
2581
                        fsck_send_msg(fsck_INTERNALERROR, girf_rc, 0, 0, 0);
 
2582
                } else {
 
2583
                        /* the table is allocated */
 
2584
                        /*
 
2585
                         * IAG 0 is always the first active IAG in the
 
2586
                         * fileset and extent 0 is always the first active
 
2587
                         * extent since inode 2 (the root dir) is always
 
2588
                         * the first active inode.
 
2589
                         */
 
2590
                        iagidx = 0;
 
2591
                        extidx = 0;
 
2592
                        inoidx = 2;
 
2593
 
 
2594
                        inoexttbl =
 
2595
                            agg_recptr->FSIT_IAG_tbl->inoext_tbl[iagidx];
 
2596
                        inotbl = inoexttbl->inotbl[extidx];
 
2597
                        *addr_inorecptr = inotbl->inorectbl[inoidx];
 
2598
                        /*
 
2599
                         * set things up for find next
 
2600
                         */
 
2601
                        agg_recptr->fs_last_iagidx = iagidx;
 
2602
                        agg_recptr->fs_last_extidx = extidx;
 
2603
                        agg_recptr->fs_last_inoidx = inoidx;
 
2604
                }
 
2605
        }
 
2606
 
 
2607
        if (girf_rc == FSCK_OK) {
 
2608
                /* got one */
 
2609
                *inonum = (*addr_inorecptr)->inonum;
 
2610
        }
 
2611
        return (girf_rc);
 
2612
}
2774
2613
 
2775
2614
/****************************************************************************
2776
2615
 * NAME: get_inorecptr_next
2819
2658
 *      success: FSCK_OK
2820
2659
 *      failure: something else
2821
2660
 */
2822
 
retcode_t get_inorecptr_next ( int                is_aggregate,
2823
 
                               inoidx_t           *inonum,
2824
 
                               fsck_inode_recptr  *addr_inorecptr )
 
2661
int get_inorecptr_next(int is_aggregate,
 
2662
                       uint32_t * inonum,
 
2663
                       struct fsck_inode_record **addr_inorecptr)
2825
2664
{
2826
 
  retcode_t      girn_rc = FSCK_OK;
2827
 
  int32_t        iagidx, extidx, inoidx;                                                     
2828
 
  int32_t        extidx_init, inoidx_init;                                                   
2829
 
  inoext_tblptr  inoexttbl;                                                        
2830
 
  ino_tblptr     inotbl;                                                              
2831
 
 
2832
 
  /*
2833
 
   * find next active aggregate inode record
2834
 
   */
2835
 
  if ( is_aggregate ) {  /* for an aggregate inode */
2836
 
    if ( agg_recptr->AIT_ext0_tbl == NULL ) {                                    
2837
 
      girn_rc = FSCK_INTERNAL_ERROR_54;                                   
2838
 
      sprintf( message_parm_0, "%d", girn_rc );                           
2839
 
      msgprms[0] = message_parm_0;                                        
2840
 
      msgprmidx[0] = 0;                                                   
2841
 
      sprintf( message_parm_1, "%d", 0 );                                 
2842
 
      msgprms[1] = message_parm_1;                                        
2843
 
      msgprmidx[1] = 0;                                                   
2844
 
      sprintf( message_parm_2, "%d", 0 );                                 
2845
 
      msgprms[2] = message_parm_2;                                        
2846
 
      msgprmidx[2] = 0;                                                   
2847
 
      sprintf( message_parm_3, "%d", 0 );                                 
2848
 
      msgprms[3] = message_parm_3;                                        
2849
 
      msgprmidx[3] = 0;                                                   
2850
 
      fsck_send_msg( fsck_INTERNALERROR, 0, 4 );                          
2851
 
    } else {                                                                        
2852
 
      *addr_inorecptr = NULL;                                                
2853
 
      for ( inoidx = agg_recptr->agg_last_inoidx + 1;
2854
 
          ( (inoidx < INOSPEREXT) && (*addr_inorecptr == NULL) );
2855
 
          inoidx++ ) {                                                                 
2856
 
        agg_recptr->agg_last_inoidx = inoidx;                           
2857
 
        if ( agg_recptr->AIT_ext0_tbl->inorectbl[inoidx] != NULL ) {
2858
 
          *addr_inorecptr = agg_recptr->AIT_ext0_tbl->inorectbl[inoidx];
2859
 
        }  /* end if */
2860
 
      }  /* end for */
2861
 
    }  /* end else */
2862
 
 
2863
 
  /*
2864
 
   * find next active fileset inode record
2865
 
   */
2866
 
  } else {  /* for a fileset inode */
2867
 
    if ( agg_recptr->FSIT_IAG_tbl == NULL ) {                             
2868
 
      girn_rc = FSCK_INTERNAL_ERROR_55;                          
2869
 
      sprintf( message_parm_0, "%d", girn_rc );                  
2870
 
      msgprms[0] = message_parm_0;                               
2871
 
      msgprmidx[0] = 0;                                          
2872
 
      sprintf( message_parm_1, "%d", 0 );                        
2873
 
      msgprms[1] = message_parm_1;                               
2874
 
      msgprmidx[1] = 0;                                          
2875
 
      sprintf( message_parm_2, "%d", 0 );                        
2876
 
      msgprms[2] = message_parm_2;                               
2877
 
      msgprmidx[2] = 0;                                          
2878
 
      sprintf( message_parm_3, "%d", 0 );                        
2879
 
      msgprms[3] = message_parm_3;                               
2880
 
      msgprmidx[3] = 0;                                          
2881
 
      fsck_send_msg( fsck_INTERNALERROR, 0, 4 );                 
2882
 
    } else {  /* the table is allocated */
2883
 
      extidx_init = agg_recptr->fs_last_extidx;             
2884
 
      inoidx_init = agg_recptr->fs_last_inoidx + 1;         
2885
 
      *addr_inorecptr = NULL;                               
2886
 
      for ( iagidx = agg_recptr->fs_last_iagidx;
2887
 
          ( (iagidx < agg_recptr->fset_imap.num_iags) &&
2888
 
            (*addr_inorecptr == NULL) );
2889
 
          iagidx++) {                                                     
2890
 
        agg_recptr->fs_last_iagidx = iagidx;                         
2891
 
        if ( agg_recptr->FSIT_IAG_tbl->inoext_tbl[iagidx] != NULL ) { 
2892
 
          inoexttbl = agg_recptr->FSIT_IAG_tbl->inoext_tbl[iagidx]; 
2893
 
          for ( extidx = extidx_init;
2894
 
              ( (extidx < EXTSPERIAG) &&
2895
 
                (*addr_inorecptr == NULL) );
2896
 
              extidx++) {                                                 
2897
 
            agg_recptr->fs_last_extidx = extidx;            
2898
 
            if ( inoexttbl->inotbl[extidx] != NULL ) { 
2899
 
              inotbl = inoexttbl->inotbl[extidx];           
2900
 
              for ( inoidx = inoidx_init;
2901
 
                  ( (inoidx < INOSPEREXT) &&
2902
 
                    (*addr_inorecptr == NULL) );
2903
 
                  inoidx++) {                                             
2904
 
                agg_recptr->fs_last_inoidx = inoidx;        
2905
 
                if ( inotbl->inorectbl[inoidx] != NULL ) {  
2906
 
                  *addr_inorecptr = inotbl->inorectbl[inoidx];
2907
 
                }  /* end if */
2908
 
              }  /* end for inoidx */
2909
 
            }  /* end if the inode table is allocated */
2910
 
            inoidx_init = 0;                          
2911
 
          }  /* end for extidx */
2912
 
        }  /* end if the ext table is allocated */
2913
 
        extidx_init = 0;                        
2914
 
      }  /* end for iagidx */
2915
 
    }  /* end else the table is allocated */
2916
 
  }  /* end else for a fileset inode */
2917
 
 
2918
 
  if ( ((*addr_inorecptr) != NULL) && (girn_rc == FSCK_OK) ) {  /* got one */
2919
 
    *inonum = (*addr_inorecptr)->inonum;
2920
 
  }
2921
 
 
2922
 
  return( girn_rc );
2923
 
}  /* end get_inorecptr_next */
2924
 
 
 
2665
        int girn_rc = FSCK_OK;
 
2666
        int32_t iagidx, extidx, inoidx;
 
2667
        int32_t extidx_init, inoidx_init;
 
2668
        struct inode_ext_tbl_t *inoexttbl;
 
2669
        struct inode_tbl_t *inotbl;
 
2670
 
 
2671
        /*
 
2672
         * find next active aggregate inode record
 
2673
         */
 
2674
        if (is_aggregate) {
 
2675
                /* for an aggregate inode */
 
2676
                if (agg_recptr->AIT_ext0_tbl == NULL) {
 
2677
                        girn_rc = FSCK_INTERNAL_ERROR_54;
 
2678
                        fsck_send_msg(fsck_INTERNALERROR, girn_rc, 0, 0, 0);
 
2679
                } else {
 
2680
                        *addr_inorecptr = NULL;
 
2681
                        for (inoidx = agg_recptr->agg_last_inoidx + 1;
 
2682
                             ((inoidx < INOSPEREXT)
 
2683
                              && (*addr_inorecptr == NULL)); inoidx++) {
 
2684
                                agg_recptr->agg_last_inoidx = inoidx;
 
2685
                                if (agg_recptr->AIT_ext0_tbl->
 
2686
                                    inorectbl[inoidx] != NULL) {
 
2687
                                        *addr_inorecptr =
 
2688
                                            agg_recptr->AIT_ext0_tbl->
 
2689
                                            inorectbl[inoidx];
 
2690
                                }
 
2691
                        }
 
2692
                }
 
2693
                goto girn_set_exit;
 
2694
        }
 
2695
        
 
2696
        if (agg_recptr->FSIT_IAG_tbl == NULL) {
 
2697
                girn_rc = FSCK_INTERNAL_ERROR_55;
 
2698
                fsck_send_msg(fsck_INTERNALERROR, girn_rc, 0, 0, 0);
 
2699
                goto girn_set_exit;
 
2700
        }
 
2701
        
 
2702
        /* the table is allocated */
 
2703
        extidx_init = agg_recptr->fs_last_extidx;
 
2704
        inoidx_init = agg_recptr->fs_last_inoidx + 1;
 
2705
        *addr_inorecptr = NULL;
 
2706
        for (iagidx = agg_recptr->fs_last_iagidx;
 
2707
             ((iagidx < agg_recptr->fset_imap.num_iags) &&
 
2708
              (*addr_inorecptr == NULL)); iagidx++) {
 
2709
                agg_recptr->fs_last_iagidx = iagidx;
 
2710
                if (agg_recptr->FSIT_IAG_tbl->
 
2711
                    inoext_tbl[iagidx] != NULL) {
 
2712
                        inoexttbl = 
 
2713
                            agg_recptr->FSIT_IAG_tbl->inoext_tbl[iagidx];
 
2714
                        for (extidx = extidx_init; ((extidx < EXTSPERIAG)
 
2715
                              && (*addr_inorecptr == NULL)); extidx++) {
 
2716
                                agg_recptr->fs_last_extidx = extidx;
 
2717
                                if (inoexttbl->inotbl[extidx] != NULL) {
 
2718
                                        inotbl = inoexttbl->inotbl[extidx];
 
2719
                                        for (inoidx = inoidx_init;
 
2720
                                             ((inoidx < INOSPEREXT) &&
 
2721
                                              (*addr_inorecptr == NULL));
 
2722
                                             inoidx++) {
 
2723
                                                agg_recptr->fs_last_inoidx = 
 
2724
                                                    inoidx;
 
2725
                                                if (inotbl->inorectbl[inoidx] !=
 
2726
                                                    NULL) {
 
2727
                                                        *addr_inorecptr =
 
2728
                                                            inotbl->inorectbl
 
2729
                                                            [inoidx];
 
2730
                                                }
 
2731
                                        }
 
2732
                                }
 
2733
                                inoidx_init = 0;
 
2734
                        }
 
2735
                }
 
2736
                extidx_init = 0;
 
2737
        }
 
2738
 
 
2739
      girn_set_exit:
 
2740
        if (((*addr_inorecptr) != NULL) && (girn_rc == FSCK_OK)) {
 
2741
                /* got one */
 
2742
                *inonum = (*addr_inorecptr)->inonum;
 
2743
        }
 
2744
 
 
2745
        return (girn_rc);
 
2746
}
2925
2747
 
2926
2748
/****************************************************************************
2927
2749
 * NAME: init_agg_record
2937
2759
 *      success: FSCK_OK
2938
2760
 *      failure: something else
2939
2761
 */
2940
 
retcode_t init_agg_record( )
 
2762
int init_agg_record()
2941
2763
{
2942
 
  retcode_t  iar_rc = FSCK_OK;
2943
 
 
2944
 
  memset ( agg_recptr, 0, sizeof(fsck_agg_record) );
2945
 
  memcpy( (void *) &(agg_recptr->eyecatcher), (void *) "fsckagrc", 8 );
2946
 
  memcpy( (void *) &(agg_recptr->this_inode.eyecatcher),
2947
 
          (void *) "thisinod", 8 );
2948
 
  memcpy( (void *) &(agg_recptr->agg_imap_eyecatcher),
2949
 
          (void *) "agg imap", 8 );
2950
 
  memcpy( (void *) &(agg_recptr->fset_imap_eyecatcher),
2951
 
          (void *) "fsetimap", 8 );
2952
 
  memcpy( (void *) &(agg_recptr->AIT_eyecatcher),
2953
 
          (void *) "agg ITbl", 8 );                                                    
2954
 
  memcpy( (void *) &(agg_recptr->FSIT_eyecatcher),
2955
 
          (void *) "fsetITbl", 8 );                                                    
2956
 
  memcpy( (void *) &(agg_recptr->flags_eyecatcher),
2957
 
          (void *) "aggflags", 8 );
2958
 
  memcpy( (void *) &(agg_recptr->fais.eyecatcher),
2959
 
          (void *) "faisinfo", 8 );
2960
 
  memcpy( (void *) &(agg_recptr->vlarge_info_eyecatcher),
2961
 
          (void *) "vlargebf", 8 );
2962
 
  memcpy( (void *) &(agg_recptr->fscklog_info_eyecatcher),
2963
 
          (void *) "fscklog ", 8 );
2964
 
  memcpy( (void *) &(agg_recptr->blkmp_info_eyecatcher),
2965
 
          (void *) "blkmpbuf", 8 );
2966
 
  memcpy( (void *) &(agg_recptr->ea_info_eyecatcher),
2967
 
          (void *) "eabuffer", 8 );
2968
 
  memcpy( (void *) &(agg_recptr->iag_info_eyecatcher),
2969
 
          (void *) "iag buf ", 8 );
2970
 
  memcpy( (void *) &(agg_recptr->mapctl_info_eyecatcher),
2971
 
          (void *) "mapctbuf", 8 );
2972
 
  memcpy( (void *) &(agg_recptr->maplf_info_eyecatcher),
2973
 
          (void *) "maplfbuf", 8 );
2974
 
  memcpy( (void *) &(agg_recptr->bmplv_info_eyecatcher),
2975
 
          (void *) "bmplvbuf", 8 );
2976
 
  memcpy( (void *) &(agg_recptr->bmpdm_info_eyecatcher),
2977
 
          (void *) "bmpdmbuf", 8 );
2978
 
  memcpy( (void *) &(agg_recptr->inobuf_info_eyecatcher),
2979
 
          (void *) "inodebuf", 8 );
2980
 
  memcpy( (void *) &(agg_recptr->nodbuf_info_eyecatcher),
2981
 
          (void *) "node buf", 8 );
2982
 
  memcpy( (void *) &(agg_recptr->agg_AGTbl_eyecatcher),
2983
 
          (void *) "aggAGTbl", 8 );
2984
 
  memcpy( (void *) &(agg_recptr->fset_AGTbl_eyecatcher),
2985
 
          (void *) "fs AGTbl", 8 );
2986
 
  memcpy( (void *) &(agg_recptr->amap_eyecatcher),
2987
 
          (void *) "iagiamap", 8 );
2988
 
  memcpy( (void *) &(agg_recptr->fextsumm_eyecatcher),
2989
 
          (void *) "fextsumm", 8 );
2990
 
  memcpy( (void *) &(agg_recptr->finosumm_eyecatcher),
2991
 
          (void *) "finosumm", 8 );
2992
 
 
2993
 
  /* do the conversions from character to UniCharacter */
2994
 
 
2995
 
  agg_recptr->tree_height = 0;
2996
 
  agg_recptr->delim_char = '/';                   /* single char    */
2997
 
  agg_recptr->UniChar_LSFN_NAME = uni_LSFN_NAME;  /* store the address  */
2998
 
  agg_recptr->UniChar_lsfn_name = uni_lsfn_name;  /* store the address  */
2999
 
  agg_recptr->agg_imap.ag_tbl = &(agg_recptr->agg_AGTbl[0]);
3000
 
  agg_recptr->fset_imap.ag_tbl = &(agg_recptr->fset_AGTbl[0]);
3001
 
  /*
3002
 
   * start the messaging level out as 'show everything'
3003
 
   * It may be reset lower when the parms have been parsed.
3004
 
   */
3005
 
  agg_recptr->effective_msg_level = fsck_verbose;
3006
 
  /*
3007
 
   * check to see whether standard out has been redirected, and
3008
 
   * set the flag accordingly.
3009
 
   */  
3010
 
  if ( isatty( STDOUT_FILENO ) )
3011
 
    agg_recptr->stdout_redirected = 0;
3012
 
  else
3013
 
    agg_recptr->stdout_redirected = 1;
3014
 
 
3015
 
  return( iar_rc );
3016
 
}  /* end init_agg_record */
3017
 
 
 
2764
        int iar_rc = FSCK_OK;
 
2765
 
 
2766
        memset(agg_recptr, 0, sizeof (struct fsck_agg_record));
 
2767
        memcpy((void *) &(agg_recptr->eyecatcher), (void *) "fsckagrc", 8);
 
2768
        memcpy((void *) &(agg_recptr->this_inode.eyecatcher),
 
2769
               (void *) "thisinod", 8);
 
2770
        memcpy((void *) &(agg_recptr->agg_imap_eyecatcher), (void *) "agg imap",
 
2771
               8);
 
2772
        memcpy((void *) &(agg_recptr->fset_imap_eyecatcher),
 
2773
               (void *) "fsetimap", 8);
 
2774
        memcpy((void *) &(agg_recptr->AIT_eyecatcher), (void *) "agg ITbl", 8);
 
2775
        memcpy((void *) &(agg_recptr->FSIT_eyecatcher), (void *) "fsetITbl", 8);
 
2776
        memcpy((void *) &(agg_recptr->flags_eyecatcher), (void *) "aggflags",
 
2777
               8);
 
2778
        memcpy((void *) &(agg_recptr->fais.eyecatcher), (void *) "faisinfo", 8);
 
2779
        memcpy((void *) &(agg_recptr->vlarge_info_eyecatcher),
 
2780
               (void *) "vlargebf", 8);
 
2781
        memcpy((void *) &(agg_recptr->fscklog_info_eyecatcher),
 
2782
               (void *) "fscklog ", 8);
 
2783
        memcpy((void *) &(agg_recptr->blkmp_info_eyecatcher),
 
2784
               (void *) "blkmpbuf", 8);
 
2785
        memcpy((void *) &(agg_recptr->ea_info_eyecatcher), (void *) "eabuffer",
 
2786
               8);
 
2787
        memcpy((void *) &(agg_recptr->iag_info_eyecatcher), (void *) "iag buf ",
 
2788
               8);
 
2789
        memcpy((void *) &(agg_recptr->mapctl_info_eyecatcher),
 
2790
               (void *) "mapctbuf", 8);
 
2791
        memcpy((void *) &(agg_recptr->maplf_info_eyecatcher),
 
2792
               (void *) "maplfbuf", 8);
 
2793
        memcpy((void *) &(agg_recptr->bmplv_info_eyecatcher),
 
2794
               (void *) "bmplvbuf", 8);
 
2795
        memcpy((void *) &(agg_recptr->bmpdm_info_eyecatcher),
 
2796
               (void *) "bmpdmbuf", 8);
 
2797
        memcpy((void *) &(agg_recptr->inobuf_info_eyecatcher),
 
2798
               (void *) "inodebuf", 8);
 
2799
        memcpy((void *) &(agg_recptr->nodbuf_info_eyecatcher),
 
2800
               (void *) "node buf", 8);
 
2801
        memcpy((void *) &(agg_recptr->dnodbuf_info_eyecatcher),
 
2802
               (void *) "dnodebuf", 8);
 
2803
        memcpy((void *) &(agg_recptr->agg_AGTbl_eyecatcher),
 
2804
               (void *) "aggAGTbl", 8);
 
2805
        memcpy((void *) &(agg_recptr->fset_AGTbl_eyecatcher),
 
2806
               (void *) "fs AGTbl", 8);
 
2807
        memcpy((void *) &(agg_recptr->amap_eyecatcher), (void *) "iagiamap", 8);
 
2808
        memcpy((void *) &(agg_recptr->fextsumm_eyecatcher), (void *) "fextsumm",
 
2809
               8);
 
2810
        memcpy((void *) &(agg_recptr->finosumm_eyecatcher), (void *) "finosumm",
 
2811
               8);
 
2812
 
 
2813
        /* do the conversions from character to UniCharacter */
 
2814
 
 
2815
        agg_recptr->tree_height = 0;
 
2816
        agg_recptr->delim_char = '/';
 
2817
        agg_recptr->UniChar_LSFN_NAME = uni_LSFN_NAME;
 
2818
        agg_recptr->UniChar_lsfn_name = uni_lsfn_name;
 
2819
        agg_recptr->agg_imap.ag_tbl = &(agg_recptr->agg_AGTbl[0]);
 
2820
        agg_recptr->fset_imap.ag_tbl = &(agg_recptr->fset_AGTbl[0]);
 
2821
        /*
 
2822
         * start the messaging level out as 'show everything'
 
2823
         * It may be reset lower when the parms have been parsed.
 
2824
         */
 
2825
        agg_recptr->effective_msg_level = fsck_verbose;
 
2826
        /*
 
2827
         * check to see whether standard out has been redirected, and
 
2828
         * set the flag accordingly.
 
2829
         */
 
2830
        if (isatty(STDOUT_FILENO))
 
2831
                agg_recptr->stdout_redirected = 0;
 
2832
        else
 
2833
                agg_recptr->stdout_redirected = 1;
 
2834
 
 
2835
        return (iar_rc);
 
2836
}
3018
2837
 
3019
2838
/****************************************************************************
3020
2839
 * NAME: inorec_agg_search
3028
2847
 *
3029
2848
 * PARAMETERS:  none
3030
2849
 *
3031
 
 * NOTES:       
3032
 
 *
3033
2850
 * RETURNS:
3034
2851
 *      success: FSCK_OK
3035
2852
 *      failure: something else
3036
2853
 */
3037
 
retcode_t inorec_agg_search( uint32_t           inonum,
3038
 
                             fsck_inode_recptr  *addr_inorecptr )
 
2854
int inorec_agg_search(uint32_t inonum,
 
2855
                      struct fsck_inode_record **addr_inorecptr)
3039
2856
{
3040
 
  retcode_t  ias_rc = FSCK_OK;
3041
 
 
3042
 
  *addr_inorecptr = NULL;
3043
 
  if ( agg_recptr->AIT_ext0_tbl == NULL ) {
3044
 
    ias_rc = FSCK_INTERNAL_ERROR_17;
3045
 
    sprintf( message_parm_0, "%d", ias_rc );
3046
 
    msgprms[0] = message_parm_0;
3047
 
    msgprmidx[0] = 0;
3048
 
    sprintf( message_parm_1, "%d", inonum );
3049
 
    msgprms[1] = message_parm_1;
3050
 
    msgprmidx[1] = 0;
3051
 
    sprintf( message_parm_2, "%d", 0 );
3052
 
    msgprms[2] = message_parm_2;
3053
 
    msgprmidx[2] = 0;
3054
 
    sprintf( message_parm_3, "%d", 0 );
3055
 
    msgprms[3] = message_parm_3;
3056
 
    msgprmidx[3] = 0;
3057
 
    fsck_send_msg( fsck_INTERNALERROR, 0, 4 );
3058
 
  } else {
3059
 
    *addr_inorecptr = agg_recptr->AIT_ext0_tbl->inorectbl[inonum];
3060
 
  }
3061
 
 
3062
 
  return( ias_rc );
3063
 
}  /* end inorec_agg_search() */
3064
 
 
 
2857
        int ias_rc = FSCK_OK;
 
2858
 
 
2859
        *addr_inorecptr = NULL;
 
2860
        if (agg_recptr->AIT_ext0_tbl == NULL) {
 
2861
                ias_rc = FSCK_INTERNAL_ERROR_17;
 
2862
                fsck_send_msg(fsck_INTERNALERROR, ias_rc, inonum, 0, 0);
 
2863
        } else {
 
2864
                *addr_inorecptr = agg_recptr->AIT_ext0_tbl->inorectbl[inonum];
 
2865
        }
 
2866
 
 
2867
        return (ias_rc);
 
2868
}
3065
2869
 
3066
2870
/****************************************************************************
3067
2871
 * NAME: inorec_agg_search_insert
3076
2880
 *
3077
2881
 * PARAMETERS:  none
3078
2882
 *
3079
 
 * NOTES:       
3080
 
 *
3081
2883
 * RETURNS:
3082
2884
 *      success: FSCK_OK
3083
2885
 *      failure: something else
3084
2886
 */
3085
 
retcode_t inorec_agg_search_insert( uint32_t           inonum,
3086
 
                                    fsck_inode_recptr  *addr_inorecptr )
 
2887
int inorec_agg_search_insert(uint32_t inonum,
 
2888
                             struct fsck_inode_record **addr_inorecptr)
3087
2889
{
3088
 
  retcode_t  iasi_rc = FSCK_OK;
3089
 
  fsck_inode_recptr  new_inorecptr;
3090
 
  int        I_am_logredo = 0;
3091
 
 
3092
 
  *addr_inorecptr = NULL;
3093
 
  if ( agg_recptr->AIT_ext0_tbl == NULL ) {
3094
 
    iasi_rc = FSCK_INTERNAL_ERROR_48;
3095
 
    sprintf( message_parm_0, "%d", iasi_rc );
3096
 
    msgprms[0] = message_parm_0;
3097
 
    msgprmidx[0] = 0;
3098
 
    sprintf( message_parm_1, "%d", inonum );
3099
 
    msgprms[1] = message_parm_1;
3100
 
    msgprmidx[1] = 0;
3101
 
    sprintf( message_parm_2, "%d", 0 );
3102
 
    msgprms[2] = message_parm_2;
3103
 
    msgprmidx[2] = 0;
3104
 
    sprintf( message_parm_3, "%d", 0 );
3105
 
    msgprms[3] = message_parm_3;
3106
 
    msgprmidx[3] = 0;
3107
 
    fsck_send_msg( fsck_INTERNALERROR, 0, 4 );
3108
 
  } else {  /* the table is initialized */
3109
 
    if ( agg_recptr->AIT_ext0_tbl->inorectbl[inonum] == NULL ) {  /* not allocated*/
3110
 
      iasi_rc = alloc_wrksp( inode_record_length, dynstg_inorec,
3111
 
                             I_am_logredo, (void **) &new_inorecptr );
3112
 
      if ( iasi_rc == FSCK_OK ) {
3113
 
        new_inorecptr->inonum = inonum;
3114
 
        agg_recptr->AIT_ext0_tbl->inorectbl[inonum] = new_inorecptr;
3115
 
      }
3116
 
    }
3117
 
    if ( iasi_rc == FSCK_OK ) {
3118
 
      *addr_inorecptr = agg_recptr->AIT_ext0_tbl->inorectbl[inonum];
3119
 
    }
3120
 
  }
3121
 
 
3122
 
  return( iasi_rc );
3123
 
}  /* end inorec_agg_search_insert() */
3124
 
 
 
2890
        int iasi_rc = FSCK_OK;
 
2891
        struct fsck_inode_record *new_inorecptr;
 
2892
        int I_am_logredo = 0;
 
2893
 
 
2894
        *addr_inorecptr = NULL;
 
2895
        if (agg_recptr->AIT_ext0_tbl == NULL) {
 
2896
                iasi_rc = FSCK_INTERNAL_ERROR_48;
 
2897
                fsck_send_msg(fsck_INTERNALERROR, iasi_rc, inonum, 0, 0);
 
2898
        } else {
 
2899
                /* the table is initialized */
 
2900
                if (agg_recptr->AIT_ext0_tbl->inorectbl[inonum] == NULL) {
 
2901
                        /* not allocated */
 
2902
                        iasi_rc =
 
2903
                            alloc_wrksp(inode_record_length, dynstg_inorec,
 
2904
                                        I_am_logredo, (void **) &new_inorecptr);
 
2905
                        if (iasi_rc == FSCK_OK) {
 
2906
                                new_inorecptr->inonum = inonum;
 
2907
                                agg_recptr->AIT_ext0_tbl->inorectbl[inonum] =
 
2908
                                    new_inorecptr;
 
2909
                        }
 
2910
                }
 
2911
                if (iasi_rc == FSCK_OK) {
 
2912
                        *addr_inorecptr =
 
2913
                            agg_recptr->AIT_ext0_tbl->inorectbl[inonum];
 
2914
                }
 
2915
        }
 
2916
 
 
2917
        return (iasi_rc);
 
2918
}
3125
2919
 
3126
2920
/****************************************************************************
3127
2921
 * NAME: inorec_fs_search
3135
2929
 *
3136
2930
 * PARAMETERS:  none
3137
2931
 *
3138
 
 * NOTES:       
3139
 
 *
3140
2932
 * RETURNS:
3141
2933
 *      success: FSCK_OK
3142
2934
 *      failure: something else
3143
2935
 */
3144
 
retcode_t inorec_fs_search( uint32_t           inonum,
3145
 
                            fsck_inode_recptr  *addr_inorecptr )
 
2936
int inorec_fs_search(uint32_t inonum, struct fsck_inode_record **addr_inorecptr)
3146
2937
{
3147
 
  retcode_t      ifs_rc = FSCK_OK;
3148
 
  int32_t        iag_in_agg, ext_in_iag, ino_in_ext;
3149
 
  inoext_tblptr  inoexttbl;
3150
 
  ino_tblptr     inotbl;
3151
 
 
3152
 
  *addr_inorecptr = NULL;
3153
 
  if ( agg_recptr->FSIT_IAG_tbl == NULL ) {
3154
 
    ifs_rc = FSCK_INTERNAL_ERROR_49;
3155
 
    sprintf( message_parm_0, "%d", ifs_rc );
3156
 
    msgprms[0] = message_parm_0;
3157
 
    msgprmidx[0] = 0;
3158
 
    sprintf( message_parm_1, "%d", inonum );
3159
 
    msgprms[1] = message_parm_1;
3160
 
    msgprmidx[1] = 0;
3161
 
    sprintf( message_parm_2, "%d", 0 );
3162
 
    msgprms[2] = message_parm_2;
3163
 
    msgprmidx[2] = 0;
3164
 
    sprintf( message_parm_3, "%d", 0 );
3165
 
    msgprms[3] = message_parm_3;
3166
 
    msgprmidx[3] = 0;
3167
 
    fsck_send_msg( fsck_INTERNALERROR, 0, 4 );
3168
 
  } else {  /* the IAG table is initialized */
3169
 
    locate_inode( inonum, &iag_in_agg, &ext_in_iag, &ino_in_ext );
3170
 
    if ( iag_in_agg < agg_recptr->fset_imap.num_iags ) {  /* IAG num in range */
3171
 
      if ( agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg] != NULL ) {  /* ext table alloc */
3172
 
        inoexttbl = agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg];
3173
 
        if ( inoexttbl->inotbl[ext_in_iag] != NULL ) {  /* inode table allocated */
3174
 
          inotbl = inoexttbl->inotbl[ext_in_iag];
3175
 
          *addr_inorecptr = inotbl->inorectbl[ino_in_ext];
3176
 
        }  /* end extent's inode table is allocated */
3177
 
      }  /* end IAG's extent table is allocated */
3178
 
    }  /* end IAG number in range */
3179
 
  }  /* end else IAG table is initialized */
3180
 
 
3181
 
  return( ifs_rc );
3182
 
}  /* end inorec_fs_search() */
3183
 
 
 
2938
        int ifs_rc = FSCK_OK;
 
2939
        int32_t iag_in_agg, ext_in_iag, ino_in_ext;
 
2940
        struct inode_ext_tbl_t *inoexttbl;
 
2941
        struct inode_tbl_t *inotbl;
 
2942
 
 
2943
        *addr_inorecptr = NULL;
 
2944
        if (agg_recptr->FSIT_IAG_tbl == NULL) {
 
2945
                ifs_rc = FSCK_INTERNAL_ERROR_49;
 
2946
                fsck_send_msg(fsck_INTERNALERROR, ifs_rc, inonum, 0, 0);
 
2947
        } else {
 
2948
                /* the IAG table is initialized */
 
2949
                locate_inode(inonum, &iag_in_agg, &ext_in_iag, &ino_in_ext);
 
2950
                if (iag_in_agg < agg_recptr->fset_imap.num_iags) {
 
2951
                        /* IAG num in range */
 
2952
                        if (agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg] !=
 
2953
                            NULL) {
 
2954
                                /* ext table alloc */
 
2955
                                inoexttbl =
 
2956
                                    agg_recptr->FSIT_IAG_tbl->
 
2957
                                    inoext_tbl[iag_in_agg];
 
2958
                                if (inoexttbl->inotbl[ext_in_iag] != NULL) {
 
2959
                                        /* inode table allocated */
 
2960
                                        inotbl = inoexttbl->inotbl[ext_in_iag];
 
2961
                                        *addr_inorecptr =
 
2962
                                            inotbl->inorectbl[ino_in_ext];
 
2963
                                }
 
2964
                        }
 
2965
                }
 
2966
        }
 
2967
 
 
2968
        return (ifs_rc);
 
2969
}
3184
2970
 
3185
2971
/****************************************************************************
3186
2972
 * NAME: inorec_fs_search_insert
3193
2979
 *                If not found, create a record to represent the inode,
3194
2980
 *                insert it into the structure, and return its address.
3195
2981
 *
3196
 
 * PARAMETERS:  none
3197
 
 *
3198
2982
 * NOTES:       
3199
2983
 *
3200
2984
 * RETURNS:
3201
2985
 *      success: FSCK_OK
3202
2986
 *      failure: something else
3203
2987
 */
3204
 
retcode_t inorec_fs_search_insert( uint32_t           inonum,
3205
 
                                   fsck_inode_recptr  *addr_inorecptr )
 
2988
int inorec_fs_search_insert(uint32_t inonum,
 
2989
                            struct fsck_inode_record **addr_inorecptr)
3206
2990
{
3207
 
  retcode_t      ifsi_rc = FSCK_OK;
3208
 
  int32_t        iag_in_agg, ext_in_iag, ino_in_ext;
3209
 
  inoext_tblptr  inoexttbl = 0, new_inoexttbl;
3210
 
  ino_tblptr     inotbl = 0, new_inotbl;
3211
 
  fsck_inode_recptr  new_inorecptr;
3212
 
  int            I_am_logredo = 0;
3213
 
 
3214
 
  *addr_inorecptr = NULL;
3215
 
  if ( agg_recptr->FSIT_IAG_tbl == NULL ) {
3216
 
    ifsi_rc = FSCK_INTERNAL_ERROR_67;
3217
 
    sprintf( message_parm_0, "%d", ifsi_rc );
3218
 
    msgprms[0] = message_parm_0;
3219
 
    msgprmidx[0] = 0;
3220
 
    sprintf( message_parm_1, "%d", inonum );
3221
 
    msgprms[1] = message_parm_1;
3222
 
    msgprmidx[1] = 0;
3223
 
    sprintf( message_parm_2, "%d", 0 );
3224
 
    msgprms[2] = message_parm_2;
3225
 
    msgprmidx[2] = 0;
3226
 
    sprintf( message_parm_3, "%d", 0 );
3227
 
    msgprms[3] = message_parm_3;
3228
 
    msgprmidx[3] = 0;
3229
 
    fsck_send_msg( fsck_INTERNALERROR, 0, 4 );
3230
 
  } else {  /* the IAG table is initialized */
3231
 
    locate_inode( inonum, &iag_in_agg, &ext_in_iag, &ino_in_ext );
3232
 
    if ( iag_in_agg < agg_recptr->fset_imap.num_iags ) {  
3233
 
        /*
3234
 
         * the IAG number is in range
3235
 
         */
3236
 
      if ( agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg] == NULL ) {  
3237
 
          /*
3238
 
           * extent table not allocated
3239
 
           */
3240
 
        ifsi_rc = alloc_wrksp( inode_ext_tbl_length, dynstg_inoexttbl,
3241
 
                               I_am_logredo, (void **) &new_inoexttbl );
3242
 
        if ( ifsi_rc == FSCK_OK ) {
3243
 
          memcpy( (void *) &(new_inoexttbl->eyecatcher),
3244
 
                  (void *) "InoExTbl", 8 );
3245
 
          agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg] =
3246
 
          new_inoexttbl;
3247
 
        }
3248
 
      }  /* end IAG's extent table is not allocated */
3249
 
 
3250
 
      if ( ifsi_rc == FSCK_OK ) {
3251
 
        inoexttbl = agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg];
3252
 
 
3253
 
        if ( inoexttbl->inotbl[ext_in_iag] == NULL ) {  
3254
 
            /*
3255
 
             * the inode table is not allocated
3256
 
             */
3257
 
          ifsi_rc = alloc_wrksp( inode_tbl_length, dynstg_inotbl,
3258
 
                                 I_am_logredo, (void **) &new_inotbl );
3259
 
          if ( ifsi_rc == FSCK_OK ) {
3260
 
            memcpy( (void *) &(new_inotbl->eyecatcher),
3261
 
                    (void *) "InodeTbl", 8 );
3262
 
            inoexttbl->inotbl[ext_in_iag] = new_inotbl;
3263
 
          }
3264
 
        }  /* end extent's inode table is not allocated */
3265
 
      }
3266
 
 
3267
 
      if ( ifsi_rc == FSCK_OK ) {
3268
 
        inotbl = inoexttbl->inotbl[ext_in_iag];
3269
 
 
3270
 
        if ( inotbl->inorectbl[ino_in_ext] == NULL ) {  
3271
 
            /*
3272
 
             * the inode record is not allocated
3273
 
             */
3274
 
          ifsi_rc = alloc_wrksp( inode_record_length, dynstg_inorec,
3275
 
                                 I_am_logredo, (void **) &new_inorecptr );
3276
 
          if ( ifsi_rc == FSCK_OK ) {
3277
 
            new_inorecptr->inonum = inonum;
3278
 
            inotbl->inorectbl[ino_in_ext] = new_inorecptr;
3279
 
          }
3280
 
        }  /* end inode record not allocated */
3281
 
      }
3282
 
 
3283
 
      if ( ifsi_rc == FSCK_OK ) {
3284
 
        *addr_inorecptr = inotbl->inorectbl[ino_in_ext];
3285
 
      }
3286
 
    }  /* end IAG number in range */
3287
 
  }  /* end else IAG table is initialized */
3288
 
 
3289
 
  return( ifsi_rc );
3290
 
}  /* end inorec_fs_search_insert() */
3291
 
 
 
2991
        int ifsi_rc = FSCK_OK;
 
2992
        int32_t iag_in_agg, ext_in_iag, ino_in_ext;
 
2993
        struct inode_ext_tbl_t *inoexttbl = 0;
 
2994
        struct inode_ext_tbl_t *new_inoexttbl;
 
2995
        struct inode_tbl_t *inotbl = 0;
 
2996
        struct inode_tbl_t *new_inotbl;
 
2997
        struct fsck_inode_record *new_inorecptr;
 
2998
        int I_am_logredo = 0;
 
2999
 
 
3000
        *addr_inorecptr = NULL;
 
3001
        if (agg_recptr->FSIT_IAG_tbl == NULL) {
 
3002
                ifsi_rc = FSCK_INTERNAL_ERROR_67;
 
3003
                fsck_send_msg(fsck_INTERNALERROR, ifsi_rc, inonum, 0, 0);
 
3004
                goto ifsi_exit;         
 
3005
        }
 
3006
        
 
3007
        /* the IAG table is initialized */
 
3008
        locate_inode(inonum, &iag_in_agg, &ext_in_iag, &ino_in_ext);
 
3009
        if (iag_in_agg >= agg_recptr->fset_imap.num_iags)
 
3010
                goto ifsi_exit;
 
3011
                
 
3012
        /*
 
3013
         * the IAG number is in range
 
3014
         */
 
3015
        if (agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg] == NULL) {
 
3016
                /*
 
3017
                 * extent table not allocated
 
3018
                 */
 
3019
                ifsi_rc = alloc_wrksp(inode_ext_tbl_length, dynstg_inoexttbl, 
 
3020
                                      I_am_logredo, (void **) &new_inoexttbl);
 
3021
                if (ifsi_rc == FSCK_OK) {
 
3022
                        memcpy((void *)&(new_inoexttbl->eyecatcher),
 
3023
                               (void *) "InoExTbl", 8);
 
3024
                        agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg] =
 
3025
                            new_inoexttbl;
 
3026
                }
 
3027
        }
 
3028
        if (ifsi_rc == FSCK_OK) {
 
3029
                inoexttbl = agg_recptr->FSIT_IAG_tbl->inoext_tbl[iag_in_agg];
 
3030
 
 
3031
                if (inoexttbl->inotbl[ext_in_iag] == NULL) {
 
3032
                        /*
 
3033
                         * the inode table is not allocated
 
3034
                         */
 
3035
                        ifsi_rc = alloc_wrksp(inode_tbl_length, dynstg_inotbl,
 
3036
                                              I_am_logredo,
 
3037
                                              (void **) &new_inotbl);
 
3038
                        if (ifsi_rc == FSCK_OK) {
 
3039
                                memcpy((void *)&(new_inotbl->eyecatcher),
 
3040
                                       (void *) "InodeTbl", 8);
 
3041
                                inoexttbl->inotbl[ext_in_iag] = new_inotbl;
 
3042
                        }
 
3043
                }
 
3044
        }
 
3045
 
 
3046
        if (ifsi_rc == FSCK_OK) {
 
3047
                inotbl = inoexttbl->inotbl[ext_in_iag];
 
3048
 
 
3049
                if (inotbl->inorectbl[ino_in_ext] == NULL) {
 
3050
                        /*
 
3051
                         * the inode record is not allocated
 
3052
                         */
 
3053
                        ifsi_rc = alloc_wrksp(inode_record_length, 
 
3054
                                              dynstg_inorec,
 
3055
                                              I_am_logredo,
 
3056
                                              (void **)&new_inorecptr);
 
3057
                        if (ifsi_rc == FSCK_OK) {
 
3058
                                new_inorecptr->inonum = inonum;
 
3059
                                inotbl->inorectbl[ino_in_ext] = new_inorecptr;
 
3060
                        }
 
3061
                }
 
3062
        }
 
3063
 
 
3064
        if (ifsi_rc == FSCK_OK) {
 
3065
                *addr_inorecptr = inotbl->inorectbl[ino_in_ext];
 
3066
        }
 
3067
        
 
3068
      ifsi_exit:        
 
3069
        return (ifsi_rc);
 
3070
}
3292
3071
 
3293
3072
/****************************************************************************
3294
3073
 * NAME: locate_inode
3299
3078
 *
3300
3079
 * PARAMETERS:  none
3301
3080
 *
3302
 
 * NOTES:       
3303
 
 *
3304
3081
 * RETURNS:             none
3305
3082
 */
3306
 
void locate_inode( uint32_t  inonum,
3307
 
                   int32_t   *iag_in_agg,
3308
 
                   int32_t   *ext_in_iag,
3309
 
                   int32_t   *ino_in_ext  )
 
3083
void locate_inode(uint32_t inonum, int32_t * iag_in_agg, int32_t * ext_in_iag,
 
3084
                  int32_t * ino_in_ext)
3310
3085
{
3311
 
  int32_t  extinagg;
3312
 
 
3313
 
  *iag_in_agg = inonum >> L2INOSPERIAG;
3314
 
  extinagg = inonum >> L2INOSPEREXT;
3315
 
  *ext_in_iag = extinagg - ((*iag_in_agg) * EXTSPERIAG);
3316
 
  *ino_in_ext = inonum - (extinagg << L2INOSPEREXT);
3317
 
 
3318
 
}  /* end locate_inode() */
3319
 
 
 
3086
        int32_t extinagg;
 
3087
 
 
3088
        *iag_in_agg = inonum >> L2INOSPERIAG;
 
3089
        extinagg = inonum >> L2INOSPEREXT;
 
3090
        *ext_in_iag = extinagg - ((*iag_in_agg) * EXTSPERIAG);
 
3091
        *ino_in_ext = inonum - (extinagg << L2INOSPEREXT);
 
3092
 
 
3093
}
3320
3094
 
3321
3095
/*****************************************************************************
3322
3096
 * NAME: process_extent
3352
3126
 *      desired_action   - input - { FSCK_RECORD | FSCK_RECORD_DUPCHECK |
3353
3127
 *                                   FSCK_UNRECORD | FSCK_QUERY }
3354
3128
 *
3355
 
 * NOTES:
3356
 
 *
3357
3129
 * RETURNS:
3358
3130
 *      success: FSCK_OK
3359
3131
 *      failure: something else
3360
3132
 */
3361
 
retcode_t process_extent ( fsck_inode_recptr  inorecptr,
3362
 
                           reg_idx_t          extent_length,
3363
 
                           fsblkidx_t         extent_addr,
3364
 
                           int8_t             is_EA,
3365
 
                           int8_t             is_ACL,
3366
 
                           fsck_msg_info_ptr  msg_info_ptr,
3367
 
                           reg_idx_t          *adjusted_length,
3368
 
                           int8_t             *extent_is_valid,
3369
 
                           int                desired_action   )
 
3133
int process_extent(struct fsck_inode_record *inorecptr,
 
3134
                   uint32_t extent_length,
 
3135
                   int64_t extent_addr,
 
3136
                   int8_t is_EA,
 
3137
                   int8_t is_ACL,
 
3138
                   struct fsck_ino_msg_info *msg_info_ptr,
 
3139
                   uint32_t * adjusted_length,
 
3140
                   int8_t * extent_is_valid, int desired_action)
3370
3141
{
3371
 
  retcode_t   ve_rc = FSCK_OK;
3372
 
  fsblkidx_t  first_valid;
3373
 
  fsblkidx_t  last_valid;
3374
 
  int8_t      range_adjusted = 0;
3375
 
 
3376
 
  if ( inorecptr->inode_type == metadata_inode ) {
3377
 
    first_valid = extent_addr;
3378
 
  } else {
3379
 
    first_valid = (extent_addr < agg_recptr->lowest_valid_fset_datablk)
3380
 
                  ? agg_recptr->lowest_valid_fset_datablk
3381
 
                  : extent_addr;
3382
 
  }
3383
 
  last_valid =
3384
 
      ((extent_addr + extent_length) >
3385
 
       agg_recptr->highest_valid_fset_datablk)
3386
 
      ? agg_recptr->highest_valid_fset_datablk
3387
 
      : extent_addr + extent_length -1;
3388
 
 
3389
 
  if ( ( (first_valid > agg_recptr->highest_valid_fset_datablk) &&
3390
 
         (inorecptr->inode_type != metadata_inode)                   ) ||  /*
3391
 
             * starts after end of valid fset area AND
3392
 
             * isn't a meta data inode OR
3393
 
             */
3394
 
       ( (last_valid < agg_recptr->lowest_valid_fset_datablk)  &&
3395
 
         (inorecptr->inode_type != metadata_inode)                   ) ||  /*
3396
 
             * ends before the beginning of valid fset area AND
3397
 
             * isn't a meta data inode OR
3398
 
             */
3399
 
       (last_valid < first_valid) ) {  /* ends before it starts */
3400
 
    *adjusted_length = 0;
3401
 
    *extent_is_valid = 0;
3402
 
    if ( is_EA ) {      /* this is an extended attributes extent */
3403
 
      inorecptr->clr_ea_fld = 1;
3404
 
      inorecptr->ignore_ea_blks = 1;
3405
 
      agg_recptr->corrections_needed = 1;
3406
 
    } else if ( is_ACL ) {      /* this is an access control list extent */
3407
 
      inorecptr->clr_acl_fld = 1;
3408
 
      inorecptr->ignore_acl_blks = 1;
3409
 
      agg_recptr->corrections_needed = 1;
3410
 
    } else {  /* either a node (internal or leaf) or data */
3411
 
      inorecptr->selected_to_rls = 1;
3412
 
      inorecptr->ignore_alloc_blks = 1;
3413
 
      agg_recptr->corrections_needed = 1;
3414
 
    }  /* end either a node (internal or leaf) or data */
3415
 
  } else {  /* not out of the question */
3416
 
    *adjusted_length = last_valid - first_valid + 1;
3417
 
    if ( (first_valid != extent_addr)  ||
3418
 
         (last_valid != (extent_addr + extent_length - 1)) ) { 
3419
 
        /* at least some
3420
 
         * blocks are not valid for the fileset
3421
 
         */
3422
 
      range_adjusted = -1;
3423
 
      *extent_is_valid = 0;
3424
 
      if ( is_EA ) {      /* this is an extended attributes extent */
3425
 
        inorecptr->clr_ea_fld = 1;
3426
 
        agg_recptr->corrections_needed = 1;
3427
 
      } else if ( is_ACL ) {      /* this is an access control list extent */
3428
 
        inorecptr->clr_acl_fld = 1;
3429
 
        agg_recptr->corrections_needed = 1;
3430
 
      } else {  /* either a node (internal or leaf) or data */
3431
 
        inorecptr->selected_to_rls = 1;
3432
 
        agg_recptr->corrections_needed = 1;
3433
 
      }  /* end either a node (internal or leaf) or data */
3434
 
    } else { /* else the extent is ok */
3435
 
      *extent_is_valid = -1;
3436
 
    }  /* end else the extent is ok */
3437
 
    /*
3438
 
     * Finally, depending on the parm passed by the caller,
3439
 
     *
3440
 
     *   either: record the ownership of the blocks which are within
3441
 
     *           range and keep a count of multiply allocated blocks.
3442
 
     *
3443
 
     *   or:     reverse notations made in the workspace for the ownership
3444
 
     *           of blocks which are within range and decrement the count
3445
 
     *           of multiply allocated blocks.
3446
 
     *
3447
 
     *   or:     check the extent to see if it contains the first reference
3448
 
     *           to any multiply allocated block for which the first
3449
 
     *           reference is still unresolved.
3450
 
     */
3451
 
    switch ( desired_action ) {
3452
 
      case FSCK_RECORD:
3453
 
        ve_rc = extent_record( first_valid, last_valid );
3454
 
        break;
3455
 
      case FSCK_RECORD_DUPCHECK:
3456
 
        ve_rc = extent_record_dupchk( first_valid, last_valid,
3457
 
                                      range_adjusted, is_EA, is_ACL,
3458
 
                                      msg_info_ptr, inorecptr );
3459
 
        break;
3460
 
      case FSCK_UNRECORD:
3461
 
        ve_rc = extent_unrecord( first_valid, last_valid );
3462
 
        break;
3463
 
      case FSCK_QUERY:
3464
 
        ve_rc = extent_1stref_chk( first_valid, last_valid,
3465
 
                                   is_EA, is_ACL, msg_info_ptr, inorecptr );
3466
 
        break;
3467
 
      default:
3468
 
        ve_rc = FSCK_INTERNAL_ERROR_7;    /* shouldn't ever get here */
3469
 
    }  /* end switch */
3470
 
  }  /* end else not out of the question */
3471
 
 
3472
 
  return( ve_rc );
3473
 
}  /* end of process_extent () */
3474
 
 
 
3142
        int ve_rc = FSCK_OK;
 
3143
        int64_t first_valid;
 
3144
        int64_t last_valid;
 
3145
        int8_t range_adjusted = 0;
 
3146
 
 
3147
        if (inorecptr->inode_type == metadata_inode) {
 
3148
                first_valid = extent_addr;
 
3149
        } else {
 
3150
                first_valid =
 
3151
                    (extent_addr < agg_recptr->lowest_valid_fset_datablk)
 
3152
                    ? agg_recptr->lowest_valid_fset_datablk : extent_addr;
 
3153
        }
 
3154
        last_valid =
 
3155
            ((extent_addr + extent_length) >
 
3156
             agg_recptr->highest_valid_fset_datablk)
 
3157
            ? agg_recptr->highest_valid_fset_datablk : extent_addr +
 
3158
            extent_length - 1;
 
3159
 
 
3160
        if (((first_valid > agg_recptr->highest_valid_fset_datablk)
 
3161
             && (inorecptr->inode_type != metadata_inode)) ||
 
3162
            /*
 
3163
             * starts after end of valid fset area AND
 
3164
             * isn't a meta data inode OR
 
3165
             */
 
3166
            ((last_valid < agg_recptr->lowest_valid_fset_datablk)
 
3167
             && (inorecptr->inode_type != metadata_inode)) ||
 
3168
            /*
 
3169
             * ends before the beginning of valid fset area AND
 
3170
             * isn't a meta data inode OR
 
3171
             */
 
3172
            (last_valid < first_valid)) {
 
3173
                /* ends before it starts */
 
3174
 
 
3175
                *adjusted_length = 0;
 
3176
                *extent_is_valid = 0;
 
3177
                if (is_EA) {
 
3178
                        /* this is an extended attributes extent */
 
3179
                        inorecptr->clr_ea_fld = 1;
 
3180
                        inorecptr->ignore_ea_blks = 1;
 
3181
                        agg_recptr->corrections_needed = 1;
 
3182
                } else if (is_ACL) {
 
3183
                        /* this is an access control list extent */
 
3184
                        inorecptr->clr_acl_fld = 1;
 
3185
                        inorecptr->ignore_acl_blks = 1;
 
3186
                        agg_recptr->corrections_needed = 1;
 
3187
                } else {
 
3188
                        /* either a node (internal or leaf) or data */
 
3189
                        inorecptr->selected_to_rls = 1;
 
3190
                        inorecptr->ignore_alloc_blks = 1;
 
3191
                        agg_recptr->corrections_needed = 1;
 
3192
                }
 
3193
        } else {
 
3194
                /* not out of the question */
 
3195
                *adjusted_length = last_valid - first_valid + 1;
 
3196
                if ((first_valid != extent_addr) ||
 
3197
                    (last_valid != (extent_addr + extent_length - 1))) {
 
3198
                        /* at least some
 
3199
                         * blocks are not valid for the fileset
 
3200
                         */
 
3201
                        range_adjusted = -1;
 
3202
                        *extent_is_valid = 0;
 
3203
                        if (is_EA) {
 
3204
                                /* this is an extended attributes extent */
 
3205
                                inorecptr->clr_ea_fld = 1;
 
3206
                                agg_recptr->corrections_needed = 1;
 
3207
                        } else if (is_ACL) {
 
3208
                                /* this is an access control list extent */
 
3209
                                inorecptr->clr_acl_fld = 1;
 
3210
                                agg_recptr->corrections_needed = 1;
 
3211
                        } else {
 
3212
                                /* either a node (internal or leaf) or data */
 
3213
                                inorecptr->selected_to_rls = 1;
 
3214
                                agg_recptr->corrections_needed = 1;
 
3215
                        }
 
3216
                } else {
 
3217
                        /* else the extent is ok */
 
3218
                        *extent_is_valid = -1;
 
3219
                }
 
3220
                /*
 
3221
                 * Finally, depending on the parm passed by the caller,
 
3222
                 *
 
3223
                 *   either: record the ownership of the blocks which are within
 
3224
                 *           range and keep a count of multiply allocated blocks.
 
3225
                 *
 
3226
                 *   or:     reverse notations made in the workspace for the ownership
 
3227
                 *           of blocks which are within range and decrement the count
 
3228
                 *           of multiply allocated blocks.
 
3229
                 *
 
3230
                 *   or:     check the extent to see if it contains the first reference
 
3231
                 *           to any multiply allocated block for which the first
 
3232
                 *           reference is still unresolved.
 
3233
                 */
 
3234
                switch (desired_action) {
 
3235
                case FSCK_RECORD:
 
3236
                        ve_rc = extent_record(first_valid, last_valid);
 
3237
                        break;
 
3238
                case FSCK_RECORD_DUPCHECK:
 
3239
                        ve_rc = extent_record_dupchk(first_valid, last_valid,
 
3240
                                                     range_adjusted, is_EA,
 
3241
                                                     is_ACL, msg_info_ptr,
 
3242
                                                     inorecptr);
 
3243
                        break;
 
3244
                case FSCK_UNRECORD:
 
3245
                        ve_rc = extent_unrecord(first_valid, last_valid);
 
3246
                        break;
 
3247
                case FSCK_QUERY:
 
3248
                        ve_rc = extent_1stref_chk(first_valid, last_valid,
 
3249
                                                  is_EA, is_ACL, msg_info_ptr,
 
3250
                                                  inorecptr);
 
3251
                        break;
 
3252
                default:
 
3253
                        ve_rc = FSCK_INTERNAL_ERROR_7;
 
3254
                }
 
3255
        }
 
3256
 
 
3257
        return (ve_rc);
 
3258
}
3475
3259
 
3476
3260
/****************************************************************************
3477
3261
 * NAME: release_inode_extension
3481
3265
 * PARAMETERS:
3482
3266
 *      inoext_ptr  - input - address of the extension record to release
3483
3267
 *
3484
 
 * NOTES:
3485
 
 *
3486
3268
 * RETURNS:
3487
3269
 *      success: FSCK_OK
3488
3270
 *      failure: something else
3489
3271
 */
3490
 
retcode_t release_inode_extension ( fsck_inode_extptr  inoext_ptr )
 
3272
int release_inode_extension(struct fsck_inode_ext_record *inoext_ptr)
3491
3273
{
3492
 
  retcode_t  rir_rc = FSCK_OK;
3493
 
 
3494
 
  inoext_ptr->next = agg_recptr->free_inode_extens;
3495
 
  agg_recptr->free_inode_extens = inoext_ptr;
3496
 
 
3497
 
  return( rir_rc );
3498
 
}  /* end release_inode_extension */
3499
 
 
 
3274
        int rir_rc = FSCK_OK;
 
3275
 
 
3276
        inoext_ptr->next = agg_recptr->free_inode_extens;
 
3277
        agg_recptr->free_inode_extens = inoext_ptr;
 
3278
 
 
3279
        return (rir_rc);
 
3280
}
3500
3281
 
3501
3282
/****************************************************************************
3502
3283
 * NAME: release_logredo_allocs
3507
3288
 *
3508
3289
 * PARAMETERS:  none
3509
3290
 *
3510
 
 * NOTES:
3511
 
 *
3512
3291
 * RETURNS:
3513
3292
 *      success: FSCK_OK
3514
3293
 *      failure: something else
3515
3294
 */
3516
 
retcode_t release_logredo_allocs( )
 
3295
int release_logredo_allocs()
3517
3296
{
3518
 
  retcode_t  rla_rc = FSCK_OK;
3519
 
  wsp_ext_rec_ptr  this_fer;
3520
 
 
3521
 
  this_fer = agg_recptr->wsp_extent_list;
3522
 
 
3523
 
  while ( (this_fer != NULL)  &&  (rla_rc == FSCK_OK)  ) {
3524
 
    if ( this_fer->for_logredo ) {
3525
 
      this_fer->last_byte_used = sizeof(fsck_extent_record) - 1;
3526
 
    }
3527
 
    this_fer = this_fer->next;
3528
 
  }  /* end while */
3529
 
 
3530
 
  return( rla_rc );
3531
 
}  /* end release_logredo_allocs()      */
3532
 
 
 
3297
        int rla_rc = FSCK_OK;
 
3298
        struct wsp_ext_rec *this_fer;
 
3299
 
 
3300
        this_fer = agg_recptr->wsp_extent_list;
 
3301
 
 
3302
        while ((this_fer != NULL) && (rla_rc == FSCK_OK)) {
 
3303
                if (this_fer->for_logredo) {
 
3304
                        this_fer->last_byte_used =
 
3305
                            sizeof (struct wsp_ext_rec) - 1;
 
3306
                }
 
3307
                this_fer = this_fer->next;
 
3308
        }
 
3309
 
 
3310
        return (rla_rc);
 
3311
}
3533
3312
 
3534
3313
/****************************************************************************
3535
3314
 * NAME: temp_inode_buf_alloc
3549
3328
 *      success: FSCK_OK
3550
3329
 *      failure: something else
3551
3330
 */
3552
 
retcode_t temp_inode_buf_alloc ( char  **addr_buf_ptr )
 
3331
int temp_inode_buf_alloc(char **addr_buf_ptr)
3553
3332
{
3554
 
  retcode_t  tiba_rc = FSCK_OK;
3555
 
 
3556
 
  agg_recptr->vlarge_current_use = USED_FOR_INOEXT_BUF;
3557
 
  *addr_buf_ptr = (char *) agg_recptr->vlarge_buf_ptr;
3558
 
 
3559
 
  memset( (void *) (*addr_buf_ptr), '\0', VLARGE_BUFSIZE );
3560
 
 
3561
 
  return( tiba_rc );
3562
 
}  /* end temp_inode_buf_alloc ( ) */
3563
 
 
 
3333
        int tiba_rc = FSCK_OK;
 
3334
 
 
3335
        agg_recptr->vlarge_current_use = USED_FOR_INOEXT_BUF;
 
3336
        *addr_buf_ptr = (char *) agg_recptr->vlarge_buf_ptr;
 
3337
 
 
3338
        memset((void *) (*addr_buf_ptr), '\0', VLARGE_BUFSIZE);
 
3339
 
 
3340
        return (tiba_rc);
 
3341
}
3564
3342
 
3565
3343
/****************************************************************************
3566
3344
 * NAME: temp_inode_buf_release
3570
3348
 *
3571
3349
 * PARAMETERS:
3572
3350
 *      buf_ptr  - input - address of the buffer to release
3573
 
 * NOTES:
3574
3351
 *
3575
3352
 * RETURNS:
3576
3353
 *      success: FSCK_OK
3577
3354
 *      failure: something else
3578
3355
 */
3579
 
retcode_t temp_inode_buf_release ( char  *buf_ptr )
 
3356
int temp_inode_buf_release(char *buf_ptr)
3580
3357
{
3581
 
  retcode_t  tibr_rc = FSCK_OK;
3582
 
 
3583
 
  agg_recptr->vlarge_current_use = NOT_CURRENTLY_USED;
3584
 
 
3585
 
  return( tibr_rc );
3586
 
}  /* end temp_inode_buf_release() */
3587
 
 
 
3358
        int tibr_rc = FSCK_OK;
 
3359
 
 
3360
        agg_recptr->vlarge_current_use = NOT_CURRENTLY_USED;
 
3361
 
 
3362
        return (tibr_rc);
 
3363
}
3588
3364
 
3589
3365
/****************************************************************************
3590
3366
 * NAME: temp_node_buf_alloc
3604
3380
 *      success: FSCK_OK
3605
3381
 *      failure: something else
3606
3382
 */
3607
 
retcode_t temp_node_buf_alloc ( char  **addr_buf_ptr )
 
3383
int temp_node_buf_alloc(char **addr_buf_ptr)
3608
3384
{
3609
 
  retcode_t  tnba_rc = FSCK_OK;
3610
 
  int        I_am_logredo = 0;
3611
 
 
3612
 
  tnba_rc = alloc_wrksp( XTPAGE_SIZE, dynstg_tmpinoiobuf,
3613
 
                         I_am_logredo, (void **) addr_buf_ptr );
3614
 
 
3615
 
  if ( (*addr_buf_ptr) == NULL ) { /* allocation failure */
3616
 
    tnba_rc = FSCK_FAILED_DYNSTG_EXHAUST7;
3617
 
    sprintf( message_parm_0, "%d", wsp_dynstg_action );
3618
 
    msgprms[0] = message_parm_0;
3619
 
    msgprmidx[0] = 0;
3620
 
    sprintf( message_parm_1, "%d", dynstg_wspext );
3621
 
    msgprms[1] = message_parm_1;
3622
 
    msgprmidx[1] = 0;
3623
 
    fsck_send_msg( fsck_EXHDYNSTG, 0, 2 );
3624
 
  }  /* end allocation failure */
3625
 
 
3626
 
  return( tnba_rc );
3627
 
}  /* end temp_node_buf_alloc ( ) */
3628
 
 
 
3385
        int tnba_rc = FSCK_OK;
 
3386
        int I_am_logredo = 0;
 
3387
 
 
3388
        tnba_rc = alloc_wrksp(XTPAGE_SIZE, dynstg_tmpinoiobuf,
 
3389
                              I_am_logredo, (void **) addr_buf_ptr);
 
3390
 
 
3391
        if ((*addr_buf_ptr) == NULL) {
 
3392
                /* allocation failure */
 
3393
                tnba_rc = FSCK_FAILED_DYNSTG_EXHAUST7;
 
3394
                fsck_send_msg(fsck_EXHDYNSTG, wsp_dynstg_action, dynstg_wspext);
 
3395
        }
 
3396
        return (tnba_rc);
 
3397
}
3629
3398
 
3630
3399
/****************************************************************************
3631
3400
 * NAME: treeQ_dequeue
3647
3416
 *      success: FSCK_OK
3648
3417
 *      failure: something else
3649
3418
 */
3650
 
retcode_t treeQ_dequeue ( treeQ_elem_ptr  *treeQ_elptr )
 
3419
int treeQ_dequeue(struct treeQelem **treeQ_elptr)
3651
3420
{
3652
 
  retcode_t  tQd_rc = FSCK_OK;
3653
 
 
3654
 
  *treeQ_elptr = agg_recptr->treeQ_front;
3655
 
  if ( agg_recptr->treeQ_back == agg_recptr->treeQ_front ) {  /* empty */
3656
 
    agg_recptr->treeQ_back = agg_recptr->treeQ_front = NULL;
3657
 
  } else {  /* not empty */
3658
 
    agg_recptr->treeQ_front = agg_recptr->treeQ_front->next;
3659
 
    agg_recptr->treeQ_front->prev = NULL;
3660
 
  }  /* end else not empty */
3661
 
 
3662
 
  return( tQd_rc );
3663
 
}  /* end treeQ_dequeue */
3664
 
 
 
3421
        int tQd_rc = FSCK_OK;
 
3422
 
 
3423
        *treeQ_elptr = agg_recptr->treeQ_front;
 
3424
        if (agg_recptr->treeQ_back == agg_recptr->treeQ_front) {
 
3425
                /* empty */
 
3426
                agg_recptr->treeQ_back = agg_recptr->treeQ_front = NULL;
 
3427
        } else {
 
3428
                /* not empty */
 
3429
                agg_recptr->treeQ_front = agg_recptr->treeQ_front->next;
 
3430
                agg_recptr->treeQ_front->prev = NULL;
 
3431
        }
 
3432
 
 
3433
        return (tQd_rc);
 
3434
}
3665
3435
 
3666
3436
/****************************************************************************
3667
3437
 * NAME: treeQ_enqueue
3679
3449
 *      success: FSCK_OK
3680
3450
 *      failure: something else
3681
3451
 */
3682
 
retcode_t treeQ_enqueue ( treeQ_elem_ptr  treeQ_elptr )
 
3452
int treeQ_enqueue(struct treeQelem *treeQ_elptr)
3683
3453
{
3684
 
  retcode_t  tep_rc = FSCK_OK;
3685
 
 
3686
 
  if ( agg_recptr->treeQ_back == NULL ) {  /* empty queue */
3687
 
    agg_recptr->treeQ_back = agg_recptr->treeQ_front = treeQ_elptr;
3688
 
    treeQ_elptr->prev = treeQ_elptr->next = NULL;
3689
 
  } else {  /* queue not empty */
3690
 
    treeQ_elptr->next = NULL;
3691
 
    treeQ_elptr->prev = agg_recptr->treeQ_back;
3692
 
    agg_recptr->treeQ_back->next = treeQ_elptr;
3693
 
    agg_recptr->treeQ_back = treeQ_elptr;
3694
 
  }  /* end else queue not empty */
3695
 
 
3696
 
  return( tep_rc );
3697
 
}  /* end treeQ_enqueue  */
3698
 
 
 
3454
        int tep_rc = FSCK_OK;
 
3455
 
 
3456
        if (agg_recptr->treeQ_back == NULL) {
 
3457
                /* empty queue */
 
3458
                agg_recptr->treeQ_back = agg_recptr->treeQ_front = treeQ_elptr;
 
3459
                treeQ_elptr->prev = treeQ_elptr->next = NULL;
 
3460
        } else {
 
3461
                /* queue not empty */
 
3462
                treeQ_elptr->next = NULL;
 
3463
                treeQ_elptr->prev = agg_recptr->treeQ_back;
 
3464
                agg_recptr->treeQ_back->next = treeQ_elptr;
 
3465
                agg_recptr->treeQ_back = treeQ_elptr;
 
3466
        }
 
3467
 
 
3468
        return (tep_rc);
 
3469
}
3699
3470
 
3700
3471
/****************************************************************************
3701
3472
 * NAME: treeQ_get_elem
3706
3477
 *      addr_treeQ_ptr  - input - pointer to a variable in which to return
3707
3478
 *                                the address of the element allocated.
3708
3479
 *
3709
 
 * NOTES:
3710
 
 *
3711
3480
 * RETURNS:
3712
3481
 *      success: FSCK_OK
3713
3482
 *      failure: something else
3714
3483
 */
3715
 
retcode_t treeQ_get_elem ( treeQ_elem_ptr  *addr_treeQ_ptr )
 
3484
int treeQ_get_elem(struct treeQelem **addr_treeQ_ptr)
3716
3485
{
3717
 
  retcode_t  gte_rc = FSCK_OK;
3718
 
  int        I_am_logredo = 0;
3719
 
 
3720
 
  if ( agg_recptr->free_treeQ != NULL ) { /* free list isn't empty */
3721
 
    *addr_treeQ_ptr = agg_recptr->free_treeQ;
3722
 
    agg_recptr->free_treeQ = agg_recptr->free_treeQ->next;
3723
 
    memset( (void *) (*addr_treeQ_ptr), 0, treeQ_elem_length );
3724
 
  } else {  /* else the free list is empty */
3725
 
    gte_rc = alloc_wrksp( treeQ_elem_length, dynstg_treeQ_elem,
3726
 
                          I_am_logredo,
3727
 
                          (void **) addr_treeQ_ptr );
3728
 
  }  /* end else the free list is empty */
3729
 
 
3730
 
  return( gte_rc );
3731
 
}  /* end treeQ_get_elem */
3732
 
 
 
3486
        int gte_rc = FSCK_OK;
 
3487
        int I_am_logredo = 0;
 
3488
 
 
3489
        if (agg_recptr->free_treeQ != NULL) {
 
3490
                /* free list isn't empty */
 
3491
                *addr_treeQ_ptr = agg_recptr->free_treeQ;
 
3492
                agg_recptr->free_treeQ = agg_recptr->free_treeQ->next;
 
3493
                memset((void *) (*addr_treeQ_ptr), 0, treeQ_elem_length);
 
3494
        } else {
 
3495
                /* else the free list is empty */
 
3496
                gte_rc = alloc_wrksp(treeQ_elem_length, dynstg_treeQ_elem,
 
3497
                                     I_am_logredo, (void **) addr_treeQ_ptr);
 
3498
        }
 
3499
 
 
3500
        return (gte_rc);
 
3501
}
3733
3502
 
3734
3503
/****************************************************************************
3735
3504
 *
3740
3509
 * PARAMETERS:
3741
3510
 *      treeQ_elptr  - input - the address of the element to release
3742
3511
 *
3743
 
 * NOTES:
3744
 
 *
3745
3512
 * RETURNS:
3746
3513
 *      success: FSCK_OK
3747
3514
 *      failure: something else
3748
3515
 */
3749
 
retcode_t treeQ_rel_elem ( treeQ_elem_ptr  treeQ_elptr )
 
3516
int treeQ_rel_elem(struct treeQelem *treeQ_elptr)
3750
3517
{
3751
 
  retcode_t  tre_rc = FSCK_OK;
3752
 
 
3753
 
  treeQ_elptr->next = agg_recptr->free_treeQ;
3754
 
  agg_recptr->free_treeQ = treeQ_elptr;
3755
 
 
3756
 
  return( tre_rc );
3757
 
}  /* end treeQ_rel_elem */
3758
 
 
 
3518
        int tre_rc = FSCK_OK;
 
3519
 
 
3520
        treeQ_elptr->next = agg_recptr->free_treeQ;
 
3521
        agg_recptr->free_treeQ = treeQ_elptr;
 
3522
 
 
3523
        return (tre_rc);
 
3524
}
3759
3525
 
3760
3526
/****************************************************************************
3761
3527
 * NAME: treeStack_get_elem
3766
3532
 *      addr_treeStack_ptr  - input - pointer to a variable in which the address
3767
3533
 *                                 of the new element should be returned.
3768
3534
 *
3769
 
 * NOTES:
3770
 
 *
3771
3535
 * RETURNS:
3772
3536
 *      success: FSCK_OK
3773
3537
 *      failure: something else
3774
3538
 */
3775
 
retcode_t treeStack_get_elem ( treeStack_ptr  *addr_treeStack_ptr )
 
3539
int treeStack_get_elem(struct treeStack_record **addr_treeStack_ptr)
3776
3540
{
3777
 
  retcode_t  tSge_rc = FSCK_OK;
3778
 
  int        I_am_logredo = 0;
3779
 
 
3780
 
  if ( agg_recptr->free_treeStack != NULL ) { /* free list isn't empty */
3781
 
    *addr_treeStack_ptr = agg_recptr->free_treeStack;
3782
 
    agg_recptr->free_treeStack = agg_recptr->free_treeStack->next;
3783
 
    memset( (void *) (*addr_treeStack_ptr), 0, treeStack_elem_length );
3784
 
  } else {  /* else the free list is empty */
3785
 
    tSge_rc = alloc_wrksp( treeStack_elem_length,
3786
 
                           dynstg_treeStack_elem, I_am_logredo,
3787
 
                           (void**) addr_treeStack_ptr );
3788
 
  }  /* end else the free list is empty */
3789
 
 
3790
 
  return( tSge_rc );
3791
 
}  /* end treeStack_get_elem */
3792
 
 
 
3541
        int tSge_rc = FSCK_OK;
 
3542
        int I_am_logredo = 0;
 
3543
 
 
3544
        if (agg_recptr->free_treeStack != NULL) {
 
3545
                /* free list isn't empty */
 
3546
                *addr_treeStack_ptr = agg_recptr->free_treeStack;
 
3547
                agg_recptr->free_treeStack = agg_recptr->free_treeStack->next;
 
3548
                memset((void *) (*addr_treeStack_ptr), 0,
 
3549
                       treeStack_elem_length);
 
3550
        } else {
 
3551
                /* else the free list is empty */
 
3552
                tSge_rc = alloc_wrksp(treeStack_elem_length,
 
3553
                                      dynstg_treeStack_elem, I_am_logredo,
 
3554
                                      (void **) addr_treeStack_ptr);
 
3555
        }
 
3556
 
 
3557
        return (tSge_rc);
 
3558
}
3793
3559
 
3794
3560
/****************************************************************************
3795
3561
 * NAME: treeStack_rel_elem
3799
3565
 * PARAMETERS:
3800
3566
 *      treeStack_elptr  - input - the address of the element to release
3801
3567
 *
3802
 
 * NOTES:
3803
 
 *
3804
3568
 * RETURNS:
3805
3569
 *      success: FSCK_OK
3806
3570
 *      failure: something else
3807
3571
 */
3808
 
retcode_t treeStack_rel_elem ( treeStack_ptr  treeStack_elptr )
 
3572
int treeStack_rel_elem(struct treeStack_record *treeStack_elptr)
3809
3573
{
3810
 
  retcode_t  tSre_rc = FSCK_OK;
3811
 
 
3812
 
  treeStack_elptr->next = agg_recptr->free_treeStack;
3813
 
  agg_recptr->free_treeStack = treeStack_elptr;
3814
 
 
3815
 
  return( tSre_rc );
3816
 
}  /* end treeStack_rel_elem */
3817
 
 
 
3574
        int tSre_rc = FSCK_OK;
 
3575
 
 
3576
        treeStack_elptr->next = agg_recptr->free_treeStack;
 
3577
        agg_recptr->free_treeStack = treeStack_elptr;
 
3578
 
 
3579
        return (tSre_rc);
 
3580
}
3818
3581
 
3819
3582
/****************************************************************************
3820
3583
 * NAME: treeStack_pop
3833
3596
 *      success: FSCK_OK
3834
3597
 *      failure: something else
3835
3598
 */
3836
 
retcode_t treeStack_pop ( fsck_inode_recptr  *addr_inorecptr )
 
3599
int treeStack_pop(struct fsck_inode_record **addr_inorecptr)
3837
3600
{
3838
 
  retcode_t      tSp_rc = FSCK_OK;
3839
 
  treeStack_ptr  top_elem;
3840
 
 
3841
 
  if ( agg_recptr->treeStack != NULL ) {
3842
 
    top_elem = agg_recptr->treeStack;
3843
 
    agg_recptr->treeStack = top_elem->next;
3844
 
    *addr_inorecptr = top_elem->inorec;
3845
 
    tSp_rc = treeStack_rel_elem( top_elem );
3846
 
  } else {
3847
 
    *addr_inorecptr = NULL;
3848
 
  }
3849
 
 
3850
 
  return( tSp_rc );
3851
 
}  /* end treeStack_pop */
3852
 
 
 
3601
        int tSp_rc = FSCK_OK;
 
3602
        struct treeStack_record *top_elem;
 
3603
 
 
3604
        if (agg_recptr->treeStack != NULL) {
 
3605
                top_elem = agg_recptr->treeStack;
 
3606
                agg_recptr->treeStack = top_elem->next;
 
3607
                *addr_inorecptr = top_elem->inorec;
 
3608
                tSp_rc = treeStack_rel_elem(top_elem);
 
3609
        } else {
 
3610
                *addr_inorecptr = NULL;
 
3611
        }
 
3612
 
 
3613
        return (tSp_rc);
 
3614
}
3853
3615
 
3854
3616
/****************************************************************************
3855
3617
 * NAME: treeStack_push
3866
3628
 *      success: FSCK_OK
3867
3629
 *      failure: something else
3868
3630
 */
3869
 
retcode_t treeStack_push ( fsck_inode_recptr  inorecptr )
 
3631
int treeStack_push(struct fsck_inode_record *inorecptr)
3870
3632
{
3871
 
  retcode_t      tSp_rc = FSCK_OK;
3872
 
  treeStack_ptr  new_elem;
3873
 
 
3874
 
  tSp_rc = treeStack_get_elem( &new_elem );
3875
 
  if ( tSp_rc == FSCK_OK ) {
3876
 
    new_elem->inorec = inorecptr;
3877
 
    new_elem->next = agg_recptr->treeStack;
3878
 
    agg_recptr->treeStack = new_elem;
3879
 
  }
3880
 
 
3881
 
  return( tSp_rc );
3882
 
}  /* end treeStack_push */
3883
 
 
 
3633
        int tSp_rc = FSCK_OK;
 
3634
        struct treeStack_record *new_elem;
 
3635
 
 
3636
        tSp_rc = treeStack_get_elem(&new_elem);
 
3637
        if (tSp_rc == FSCK_OK) {
 
3638
                new_elem->inorec = inorecptr;
 
3639
                new_elem->next = agg_recptr->treeStack;
 
3640
                agg_recptr->treeStack = new_elem;
 
3641
        }
 
3642
 
 
3643
        return (tSp_rc);
 
3644
}
3884
3645
 
3885
3646
/*****************************************************************************
3886
3647
 * NAME: workspace_release
3890
3651
 *
3891
3652
 * PARAMETERS: none
3892
3653
 *
3893
 
 * NOTES:
3894
 
 *
3895
3654
 * RETURNS:
3896
3655
 *      success: FSCK_OK
3897
3656
 *      failure: something else
3898
3657
 */
3899
 
retcode_t workspace_release ( )
 
3658
int workspace_release()
3900
3659
{
3901
 
  retcode_t  wr_rc = FSCK_OK;
3902
 
  wsp_ext_rec_ptr  this_fer, next_fer;
3903
 
  /*
3904
 
   * If the very large buffer is (still) allocated, release it.
3905
 
   */
3906
 
  if ( agg_recptr->vlarge_buf_ptr != NULL ) {
3907
 
    free( (void *) agg_recptr->vlarge_buf_ptr );
3908
 
    agg_recptr->vlarge_buf_ptr = NULL;
3909
 
    agg_recptr->ea_buf_ptr = NULL;
3910
 
    agg_recptr->recon_buf_extent = NULL;
3911
 
  }
3912
 
  /*
3913
 
   * release the allocated extents
3914
 
   */
3915
 
  this_fer = agg_recptr->wsp_extent_list;
3916
 
  while ( this_fer != NULL ) {  /* for each extent record */
3917
 
    next_fer = this_fer->next; /* the one after this one (if any) */
3918
 
    if ( ! this_fer->from_high_memory ) {
3919
 
      free( (void *) this_fer->extent_addr );  /* free the extent this
3920
 
                            * fer describes (and occupies)
3921
 
                            */
3922
 
    }
3923
 
    this_fer = next_fer;     /* go on to the next one in the list */
3924
 
  }  /* end for each extent record */
 
3660
        int wr_rc = FSCK_OK;
 
3661
        struct wsp_ext_rec *this_fer;
 
3662
        struct wsp_ext_rec *next_fer;
 
3663
        /*
 
3664
         * If the very large buffer is (still) allocated, release it.
 
3665
         */
 
3666
        if (agg_recptr->vlarge_buf_ptr != NULL) {
 
3667
                free((void *) agg_recptr->vlarge_buf_ptr);
 
3668
                agg_recptr->vlarge_buf_ptr = NULL;
 
3669
                agg_recptr->ea_buf_ptr = NULL;
 
3670
                agg_recptr->recon_buf_extent = NULL;
 
3671
        }
 
3672
        /*
 
3673
         * release the allocated extents
 
3674
         */
 
3675
        this_fer = agg_recptr->wsp_extent_list;
 
3676
        while (this_fer != NULL) {
 
3677
                /* for each extent record */
 
3678
                /* the one after this one (if any) */
 
3679
                next_fer = this_fer->next;
 
3680
                if (!this_fer->from_high_memory) {
 
3681
                        /* free the extent this
 
3682
                         * fer describes (and occupies)
 
3683
                         */
 
3684
                        free((void *) this_fer->extent_addr);
 
3685
                }
 
3686
                /* go on to the next one in the list */
 
3687
                this_fer = next_fer;
 
3688
        }
3925
3689
 
3926
 
  return( wr_rc );
3927
 
}  /* end of workspace_release () */
 
3690
        return (wr_rc);
 
3691
}