[XFS] endianess annotations for xfs_attr_shortform_t

SGI-PV: 943272
SGI-Modid: xfs-linux-melb:xfs-kern:25501a

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nathan Scott <nathans@sgi.com>
This commit is contained in:
Nathan Scott 2006-03-17 17:29:25 +11:00
parent c0f054e7a4
commit 3b244aa81e
3 changed files with 30 additions and 35 deletions

View File

@ -194,7 +194,7 @@ xfs_attr_shortform_create(xfs_da_args_t *args)
xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK); xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK);
hdr = (xfs_attr_sf_hdr_t *)ifp->if_u1.if_data; hdr = (xfs_attr_sf_hdr_t *)ifp->if_u1.if_data;
hdr->count = 0; hdr->count = 0;
INT_SET(hdr->totsize, ARCH_CONVERT, sizeof(*hdr)); hdr->totsize = cpu_to_be16(sizeof(*hdr));
xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
} }
@ -224,8 +224,7 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
ASSERT(ifp->if_flags & XFS_IFINLINE); ASSERT(ifp->if_flags & XFS_IFINLINE);
sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT); for (i = 0; i < sf->hdr.count; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
#ifdef DEBUG #ifdef DEBUG
if (sfe->namelen != args->namelen) if (sfe->namelen != args->namelen)
continue; continue;
@ -248,13 +247,13 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff)
sfe = (xfs_attr_sf_entry_t *)((char *)sf + offset); sfe = (xfs_attr_sf_entry_t *)((char *)sf + offset);
sfe->namelen = args->namelen; sfe->namelen = args->namelen;
INT_SET(sfe->valuelen, ARCH_CONVERT, args->valuelen); sfe->valuelen = args->valuelen;
sfe->flags = (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE : sfe->flags = (args->flags & ATTR_SECURE) ? XFS_ATTR_SECURE :
((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0); ((args->flags & ATTR_ROOT) ? XFS_ATTR_ROOT : 0);
memcpy(sfe->nameval, args->name, args->namelen); memcpy(sfe->nameval, args->name, args->namelen);
memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen); memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen);
INT_MOD(sf->hdr.count, ARCH_CONVERT, 1); sf->hdr.count++;
INT_MOD(sf->hdr.totsize, ARCH_CONVERT, size); be16_add(&sf->hdr.totsize, size);
xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
xfs_sbversion_add_attr2(mp, args->trans); xfs_sbversion_add_attr2(mp, args->trans);
@ -277,7 +276,7 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
base = sizeof(xfs_attr_sf_hdr_t); base = sizeof(xfs_attr_sf_hdr_t);
sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data; sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
end = INT_GET(sf->hdr.count, ARCH_CONVERT); end = sf->hdr.count;
for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe), for (i = 0; i < end; sfe = XFS_ATTR_SF_NEXTENTRY(sfe),
base += size, i++) { base += size, i++) {
size = XFS_ATTR_SF_ENTSIZE(sfe); size = XFS_ATTR_SF_ENTSIZE(sfe);
@ -300,11 +299,11 @@ xfs_attr_shortform_remove(xfs_da_args_t *args)
* Fix up the attribute fork data, covering the hole * Fix up the attribute fork data, covering the hole
*/ */
end = base + size; end = base + size;
totsize = INT_GET(sf->hdr.totsize, ARCH_CONVERT); totsize = be16_to_cpu(sf->hdr.totsize);
if (end != totsize) if (end != totsize)
memmove(&((char *)sf)[base], &((char *)sf)[end], totsize - end); memmove(&((char *)sf)[base], &((char *)sf)[end], totsize - end);
INT_MOD(sf->hdr.count, ARCH_CONVERT, -1); sf->hdr.count--;
INT_MOD(sf->hdr.totsize, ARCH_CONVERT, -size); be16_add(&sf->hdr.totsize, -size);
/* /*
* Fix up the start offset of the attribute fork * Fix up the start offset of the attribute fork
@ -360,7 +359,7 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
ASSERT(ifp->if_flags & XFS_IFINLINE); ASSERT(ifp->if_flags & XFS_IFINLINE);
sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT); for (i = 0; i < sf->hdr.count;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
if (sfe->namelen != args->namelen) if (sfe->namelen != args->namelen)
continue; continue;
@ -391,7 +390,7 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
ASSERT(args->dp->i_d.di_aformat == XFS_IFINLINE); ASSERT(args->dp->i_d.di_aformat == XFS_IFINLINE);
sf = (xfs_attr_shortform_t *)args->dp->i_afp->if_u1.if_data; sf = (xfs_attr_shortform_t *)args->dp->i_afp->if_u1.if_data;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT); for (i = 0; i < sf->hdr.count;
sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) { sfe = XFS_ATTR_SF_NEXTENTRY(sfe), i++) {
if (sfe->namelen != args->namelen) if (sfe->namelen != args->namelen)
continue; continue;
@ -404,14 +403,14 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
((sfe->flags & XFS_ATTR_ROOT) != 0)) ((sfe->flags & XFS_ATTR_ROOT) != 0))
continue; continue;
if (args->flags & ATTR_KERNOVAL) { if (args->flags & ATTR_KERNOVAL) {
args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT); args->valuelen = sfe->valuelen;
return(XFS_ERROR(EEXIST)); return(XFS_ERROR(EEXIST));
} }
if (args->valuelen < INT_GET(sfe->valuelen, ARCH_CONVERT)) { if (args->valuelen < sfe->valuelen) {
args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT); args->valuelen = sfe->valuelen;
return(XFS_ERROR(ERANGE)); return(XFS_ERROR(ERANGE));
} }
args->valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT); args->valuelen = sfe->valuelen;
memcpy(args->value, &sfe->nameval[args->namelen], memcpy(args->value, &sfe->nameval[args->namelen],
args->valuelen); args->valuelen);
return(XFS_ERROR(EEXIST)); return(XFS_ERROR(EEXIST));
@ -438,7 +437,7 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
dp = args->dp; dp = args->dp;
ifp = dp->i_afp; ifp = dp->i_afp;
sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data;
size = INT_GET(sf->hdr.totsize, ARCH_CONVERT); size = be16_to_cpu(sf->hdr.totsize);
tmpbuffer = kmem_alloc(size, KM_SLEEP); tmpbuffer = kmem_alloc(size, KM_SLEEP);
ASSERT(tmpbuffer != NULL); ASSERT(tmpbuffer != NULL);
memcpy(tmpbuffer, ifp->if_u1.if_data, size); memcpy(tmpbuffer, ifp->if_u1.if_data, size);
@ -481,11 +480,11 @@ xfs_attr_shortform_to_leaf(xfs_da_args_t *args)
nargs.oknoent = 1; nargs.oknoent = 1;
sfe = &sf->list[0]; sfe = &sf->list[0];
for (i = 0; i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) { for (i = 0; i < sf->hdr.count; i++) {
nargs.name = (char *)sfe->nameval; nargs.name = (char *)sfe->nameval;
nargs.namelen = sfe->namelen; nargs.namelen = sfe->namelen;
nargs.value = (char *)&sfe->nameval[nargs.namelen]; nargs.value = (char *)&sfe->nameval[nargs.namelen];
nargs.valuelen = INT_GET(sfe->valuelen, ARCH_CONVERT); nargs.valuelen = sfe->valuelen;
nargs.hashval = xfs_da_hashname((char *)sfe->nameval, nargs.hashval = xfs_da_hashname((char *)sfe->nameval,
sfe->namelen); sfe->namelen);
nargs.flags = (sfe->flags & XFS_ATTR_SECURE) ? ATTR_SECURE : nargs.flags = (sfe->flags & XFS_ATTR_SECURE) ? ATTR_SECURE :
@ -560,10 +559,8 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
* If the buffer is large enough, do not bother with sorting. * If the buffer is large enough, do not bother with sorting.
* Note the generous fudge factor of 16 overhead bytes per entry. * Note the generous fudge factor of 16 overhead bytes per entry.
*/ */
if ((dp->i_afp->if_bytes + INT_GET(sf->hdr.count, ARCH_CONVERT) * 16) if ((dp->i_afp->if_bytes + sf->hdr.count * 16) < context->bufsize) {
< context->bufsize) { for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
for (i = 0, sfe = &sf->list[0];
i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
attrnames_t *namesp; attrnames_t *namesp;
if (((context->flags & ATTR_SECURE) != 0) != if (((context->flags & ATTR_SECURE) != 0) !=
@ -584,14 +581,13 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
if (context->flags & ATTR_KERNOVAL) { if (context->flags & ATTR_KERNOVAL) {
ASSERT(context->flags & ATTR_KERNAMELS); ASSERT(context->flags & ATTR_KERNAMELS);
context->count += namesp->attr_namelen + context->count += namesp->attr_namelen +
INT_GET(sfe->namelen, ARCH_CONVERT) + 1; sfe->namelen + 1;
} }
else { else {
if (xfs_attr_put_listent(context, namesp, if (xfs_attr_put_listent(context, namesp,
(char *)sfe->nameval, (char *)sfe->nameval,
(int)sfe->namelen, (int)sfe->namelen,
(int)INT_GET(sfe->valuelen, (int)sfe->valuelen))
ARCH_CONVERT)))
break; break;
} }
sfe = XFS_ATTR_SF_NEXTENTRY(sfe); sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
@ -603,7 +599,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
/* /*
* It didn't all fit, so we have to sort everything on hashval. * It didn't all fit, so we have to sort everything on hashval.
*/ */
sbsize = INT_GET(sf->hdr.count, ARCH_CONVERT) * sizeof(*sbuf); sbsize = sf->hdr.count * sizeof(*sbuf);
sbp = sbuf = kmem_alloc(sbsize, KM_SLEEP); sbp = sbuf = kmem_alloc(sbsize, KM_SLEEP);
/* /*
@ -611,8 +607,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
* the relevant info from only those that match into a buffer. * the relevant info from only those that match into a buffer.
*/ */
nsbuf = 0; nsbuf = 0;
for (i = 0, sfe = &sf->list[0]; for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
i < INT_GET(sf->hdr.count, ARCH_CONVERT); i++) {
if (unlikely( if (unlikely(
((char *)sfe < (char *)sf) || ((char *)sfe < (char *)sf) ||
((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) { ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) {
@ -696,7 +691,7 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
} else { } else {
if (xfs_attr_put_listent(context, namesp, if (xfs_attr_put_listent(context, namesp,
sbp->name, sbp->namelen, sbp->name, sbp->namelen,
INT_GET(sbp->valuelen, ARCH_CONVERT))) sbp->valuelen))
break; break;
} }
cursor->offset++; cursor->offset++;

View File

@ -32,8 +32,8 @@ struct xfs_inode;
*/ */
typedef struct xfs_attr_shortform { typedef struct xfs_attr_shortform {
struct xfs_attr_sf_hdr { /* constant-structure header block */ struct xfs_attr_sf_hdr { /* constant-structure header block */
__uint16_t totsize; /* total bytes in shortform list */ __be16 totsize; /* total bytes in shortform list */
__uint8_t count; /* count of active entries */ __u8 count; /* count of active entries */
} hdr; } hdr;
struct xfs_attr_sf_entry { struct xfs_attr_sf_entry {
__uint8_t namelen; /* actual length of name (no NULL) */ __uint8_t namelen; /* actual length of name (no NULL) */
@ -66,8 +66,8 @@ typedef struct xfs_attr_sf_sort {
#define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \ #define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \
((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep))) ((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep)))
#define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \ #define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \
(INT_GET(((xfs_attr_shortform_t *) \ (be16_to_cpu(((xfs_attr_shortform_t *) \
((dp)->i_afp->if_u1.if_data))->hdr.totsize, ARCH_CONVERT)) ((dp)->i_afp->if_u1.if_data))->hdr.totsize))
#if defined(XFS_ATTR_TRACE) #if defined(XFS_ATTR_TRACE)
/* /*

View File

@ -506,7 +506,7 @@ xfs_iformat(
switch (INT_GET(dip->di_core.di_aformat, ARCH_CONVERT)) { switch (INT_GET(dip->di_core.di_aformat, ARCH_CONVERT)) {
case XFS_DINODE_FMT_LOCAL: case XFS_DINODE_FMT_LOCAL:
atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip); atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
size = (int)INT_GET(atp->hdr.totsize, ARCH_CONVERT); size = be16_to_cpu(atp->hdr.totsize);
error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK, size); error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK, size);
break; break;
case XFS_DINODE_FMT_EXTENTS: case XFS_DINODE_FMT_EXTENTS: