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

« back to all changes in this revision

Viewing changes to fsck/fsckea.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-2002
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
 
 *   COMPONENT_NAME: jfs fsck
19
 
 *
20
 
 *   FUNCTIONS:
21
 
 *              jfs_ValidateFEAList
22
 
 *
23
 
 *   NOTES:
24
 
 *       This module was created by copying jfs_ValidateFEAList from
25
 
 *       jfs_ea.c
26
 
 *
27
 
 *       Any changes to this code in jfs_ea.c require corresponding
28
 
 *       changes here.
29
 
 *
30
17
 */
31
 
 
32
 
#define INCL_DOSERRORS
33
 
#define INCL_DOSPROCESS
34
 
 
35
 
#define _cdecl __cdecl
36
 
 
37
18
#include "xfsck.h"
38
 
 
39
 
/* some macros for dealing with variable length EA lists.
40
 
 */
41
 
 
42
 
#define FEA_SIZE(ea) ((ea)->cbValue + (ea)->cbName + 1 + sizeof (FEA))
43
 
#define NEXT_FEA(ea) ((FEA*)(((char *) (ea)) + (FEA_SIZE (ea))))
 
19
#include "jfs_byteorder.h"
 
20
 
 
21
/* some macros for dealing with variable length EA lists. */
 
22
#define FEA_SIZE(ea) (__le16_to_cpu((ea)->cbValue) + (ea)->cbName + 1 + \
 
23
                      sizeof (struct FEA))
 
24
#define NEXT_FEA(ea) ((struct FEA*)(((char *) (ea)) + (FEA_SIZE (ea))))
44
25
 
45
26
#define GEA_SIZE(ea) ((ea)->cbName + sizeof (GEA))
46
27
#define NEXT_GEA(ea) ((GEA*)(((char *) (ea)) + (GEA_SIZE (ea))))
57
38
 * jfs_ValidateFEAList -- validate structure of an FEALIST
58
39
 */
59
40
 
60
 
int jfs_ValidateFEAList ( FEALIST        *pfeal,
61
 
                          unsigned long  *poError )
 
41
int jfs_ValidateFEAList(struct FEALIST *pfeal, int size, unsigned long *poError)
62
42
{
63
 
  unsigned short  cbLeft;     /* count of bytes left in FEA list */
64
 
  PFEA    pfea = pfeal->list; /* pointer to current FEA */
65
 
  unsigned short  cbFEA;      /* count of bytes in current FEA */
66
 
 
67
 
  if ((cbLeft = (unsigned short) pfeal->cbList - sizeof (pfeal->cbList)) == 0)
68
 
    return 0;
69
 
 
70
 
  do {
71
 
    /* check for our reserved bits
72
 
     */
73
 
    if (pfea->fEA & ~(FEA_NEEDEA) || cbLeft < sizeof *pfea)
74
 
      return ERROR_EA_LIST_INCONSISTENT;
75
 
 
76
 
    cbFEA = FEA_SIZE (pfea);
77
 
    pfea = NEXT_FEA (pfea);
78
 
 
79
 
    if (cbLeft < cbFEA) {
80
 
      *poError = (((char *) pfea) - ((char *) pfeal));
81
 
      return ERROR_EA_LIST_INCONSISTENT;
82
 
    }
83
 
 
84
 
  } while ((cbLeft -= cbFEA) > 0);
85
 
 
86
 
  return 0;
 
43
        unsigned int cbLeft;    /* count of bytes left in FEA list */
 
44
        struct FEA *pfea = pfeal->list; /* pointer to current FEA */
 
45
        unsigned int cbFEA;     /* count of bytes in current FEA */
 
46
 
 
47
        cbLeft = __le32_to_cpu(pfeal->cbList);
 
48
        if (size !=  cbLeft)
 
49
                return ERROR_EA_LIST_INCONSISTENT;
 
50
 
 
51
        cbLeft -= sizeof (pfeal->cbList);
 
52
 
 
53
        if (cbLeft == 0)
 
54
                return 0;
 
55
 
 
56
        do {
 
57
                /* check for our reserved bits
 
58
                 */
 
59
                if (pfea->fEA & ~(FEA_NEEDEA) || cbLeft < sizeof *pfea)
 
60
                        return ERROR_EA_LIST_INCONSISTENT;
 
61
 
 
62
                cbFEA = FEA_SIZE(pfea);
 
63
                pfea = NEXT_FEA(pfea);
 
64
 
 
65
                if (cbLeft < cbFEA) {
 
66
                        *poError = (((char *) pfea) - ((char *) pfeal));
 
67
                        return ERROR_EA_LIST_INCONSISTENT;
 
68
                }
 
69
 
 
70
        } while ((cbLeft -= cbFEA) > 0);
 
71
 
 
72
        return 0;
87
73
}