📄 jfs_endian.c
字号:
/* * Copyright (c) International Business Machines Corp., 2000-2002 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "jfs_endian.h"#include <stdlib.h>#include <stdio.h>#include <time.h>#include "devices.h"#if __BYTE_ORDER == __BIG_ENDIAN/*-------------------------------------------------------------------- * NAME: ujfs_swap_dbmap * * FUNCTION: Change endianness of dbmap structure * * PARAMETERS: * dbm_t - dbmap structure * * RETURNS: NONE */void ujfs_swap_dbmap(struct dbmap *dbm_t){ int i; /* struct dbmap in jfs_dmap.h */ dbm_t->dn_mapsize = __le64_to_cpu(dbm_t->dn_mapsize); dbm_t->dn_nfree = __le64_to_cpu(dbm_t->dn_nfree); dbm_t->dn_l2nbperpage = __le32_to_cpu(dbm_t->dn_l2nbperpage); dbm_t->dn_numag = __le32_to_cpu(dbm_t->dn_numag); dbm_t->dn_maxlevel = __le32_to_cpu(dbm_t->dn_maxlevel); dbm_t->dn_maxag = __le32_to_cpu(dbm_t->dn_maxag); dbm_t->dn_agpref = __le32_to_cpu(dbm_t->dn_agpref); dbm_t->dn_aglevel = __le32_to_cpu(dbm_t->dn_aglevel); dbm_t->dn_agheigth = __le32_to_cpu(dbm_t->dn_agheigth); dbm_t->dn_agwidth = __le32_to_cpu(dbm_t->dn_agwidth); dbm_t->dn_agstart = __le32_to_cpu(dbm_t->dn_agstart); dbm_t->dn_agl2size = __le32_to_cpu(dbm_t->dn_agl2size); for (i = 0; i < MAXAG; i++) dbm_t->dn_agfree[i] = __le64_to_cpu(dbm_t->dn_agfree[i]); dbm_t->dn_agsize = __le64_to_cpu(dbm_t->dn_agsize);}/*-------------------------------------------------------------------- * NAME: ujfs_swap_dinode * * FUNCTION: Change endianness of dinode structure * * PARAMETERS: * dinode - dinode structure * * RETURNS: NONE */void ujfs_swap_dinode(struct dinode *di, int32_t mode, uint32_t sb_flag){ int i; dtpage_t *p; /* struct dinode in jfs_dinode.h */ di->di_inostamp = __le32_to_cpu(di->di_inostamp); di->di_fileset = __le32_to_cpu(di->di_fileset); di->di_number = __le32_to_cpu(di->di_number); di->di_gen = __le32_to_cpu(di->di_gen); di->di_size = __le64_to_cpu(di->di_size); di->di_nblocks = __le64_to_cpu(di->di_nblocks); di->di_nlink = __le32_to_cpu(di->di_nlink); di->di_uid = __le32_to_cpu(di->di_uid); di->di_gid = __le32_to_cpu(di->di_gid); /* struct timestruc_t */ di->di_atime.tv_sec = __le32_to_cpu(di->di_atime.tv_sec); di->di_atime.tv_nsec = __le32_to_cpu(di->di_atime.tv_nsec); /* struct timestruc_t */ di->di_ctime.tv_sec = __le32_to_cpu(di->di_ctime.tv_sec); di->di_ctime.tv_nsec = __le32_to_cpu(di->di_ctime.tv_nsec); /* struct timestruc_t */ di->di_mtime.tv_sec = __le32_to_cpu(di->di_mtime.tv_sec); di->di_mtime.tv_nsec = __le32_to_cpu(di->di_mtime.tv_nsec); /* struct timestruc_t */ di->di_otime.tv_sec = __le32_to_cpu(di->di_otime.tv_sec); di->di_otime.tv_nsec = __le32_to_cpu(di->di_otime.tv_nsec); /* dxd_t di_acl; */ di->di_acl.size = __le32_to_cpu(di->di_acl.size); /* dxd_t di_ea; */ di->di_ea.size = __le32_to_cpu(di->di_ea.size); di->di_acltype = __le32_to_cpu(di->di_acltype); if (mode == GET) { /* if reading from disk, swap before use in 'if' that follows */ di->di_mode = __le32_to_cpu(di->di_mode); di->di_next_index = __le32_to_cpu(di->di_next_index); } if (ISDIR(di->di_mode)) { /* cast di_btroot to dtree and swap it */ p = (dtpage_t *) & (di->di_btroot); if (p->header.flag & BT_ROOT) ujfs_swap_dtpage_t(p, sb_flag); if ((sb_flag & JFS_DIR_INDEX) == JFS_DIR_INDEX) { if (di->di_next_index > MAX_INLINE_DIRTABLE_ENTRY + 1) /* cast di_dirtable to xtree and swap it */ ujfs_swap_xtpage_t((xtpage_t *) & (di->di_dirtable)); } } else if (ISREG(di->di_mode) || ISLNK(di->di_mode)) { /* cast di_btroot to xtree and swap it */ ujfs_swap_xtpage_t((xtpage_t *) & (di->di_btroot)); } if (mode == PUT) { di->di_mode = __le32_to_cpu(di->di_mode); di->di_next_index = __le32_to_cpu(di->di_next_index); }}/*-------------------------------------------------------------------- * NAME: ujfs_swap_dinomap * * FUNCTION: Change endianness of struct dinomap structure * * PARAMETERS: * dim_t - struct dinomap structure * * RETURNS: NONE */void ujfs_swap_dinomap(struct dinomap *dim_t){ int i; /* struct dinomap in jfs_imap.h */ dim_t->in_freeiag = __le32_to_cpu(dim_t->in_freeiag); dim_t->in_nextiag = __le32_to_cpu(dim_t->in_nextiag); dim_t->in_numinos = __le32_to_cpu(dim_t->in_numinos); dim_t->in_numfree = __le32_to_cpu(dim_t->in_numfree); dim_t->in_nbperiext = __le32_to_cpu(dim_t->in_nbperiext); dim_t->in_l2nbperiext = __le32_to_cpu(dim_t->in_l2nbperiext); dim_t->in_diskblock = __le32_to_cpu(dim_t->in_diskblock); dim_t->in_maxag = __le32_to_cpu(dim_t->in_maxag); for (i = 0; i < MAXAG; i++) { dim_t->in_agctl[i].inofree = __le32_to_cpu(dim_t->in_agctl[i].inofree); dim_t->in_agctl[i].extfree = __le32_to_cpu(dim_t->in_agctl[i].extfree); dim_t->in_agctl[i].numinos = __le32_to_cpu(dim_t->in_agctl[i].numinos); dim_t->in_agctl[i].numfree = __le32_to_cpu(dim_t->in_agctl[i].numfree); }}/*-------------------------------------------------------------------- * NAME: ujfs_swap_dmap * * FUNCTION: Change endianness of dmap structure * * PARAMETERS: * dm_t - dmap structure * * RETURNS: NONE */void ujfs_swap_dmap(struct dmap *dm_t){ int i; /* struct dmap in jfs_dmap.h */ dm_t->nblocks = __le32_to_cpu(dm_t->nblocks); dm_t->nfree = __le32_to_cpu(dm_t->nfree); dm_t->start = __le64_to_cpu(dm_t->start); /* struct dmaptree tree; */ dm_t->tree.nleafs = __le32_to_cpu(dm_t->tree.nleafs); dm_t->tree.l2nleafs = __le32_to_cpu(dm_t->tree.l2nleafs); dm_t->tree.leafidx = __le32_to_cpu(dm_t->tree.leafidx); dm_t->tree.height = __le32_to_cpu(dm_t->tree.height); for (i = 0; i < LPERDMAP; i++) { dm_t->wmap[i] = __le32_to_cpu(dm_t->wmap[i]); dm_t->pmap[i] = __le32_to_cpu(dm_t->pmap[i]); }}/*-------------------------------------------------------------------- * NAME: ujfs_swap_dmapctl * * FUNCTION: Change endianness of dmapctl structure * * PARAMETERS: * dmc_t - dmapctl structure * * RETURNS: NONE */void ujfs_swap_dmapctl(struct dmapctl *dmc_t){ /* struct dmapctl in jfs_dmap.h */ dmc_t->nleafs = __le32_to_cpu(dmc_t->nleafs); dmc_t->l2nleafs = __le32_to_cpu(dmc_t->l2nleafs); dmc_t->leafidx = __le32_to_cpu(dmc_t->leafidx); dmc_t->height = __le32_to_cpu(dmc_t->height);}/*-------------------------------------------------------------------- * NAME: ujfs_swap_dtpage_t * * FUNCTION: Change endianness of dtpage_t structure * * PARAMETERS: * dtp_t - dtpage_t structure * * RETURNS: NONE */void ujfs_swap_dtpage_t(dtpage_t * dtp_t, uint32_t sb_flag){ struct dtslot *dtslot; int index, i, j, DtlHdrDataLen, len; int8_t *stbl; int lastslot; /* dtpage_t in jfs_dtree.h */ if (dtp_t->header.flag & BT_ROOT) { /* root page */ dtroot_t *dtroot = (dtroot_t *) dtp_t; dtroot->header.idotdot = __le32_to_cpu(dtroot->header.idotdot); stbl = dtroot->header.stbl; lastslot = DTROOTMAXSLOT - 1; } else { /* non-root page */ dtp_t->header.next = __le64_to_cpu(dtp_t->header.next); dtp_t->header.prev = __le64_to_cpu(dtp_t->header.prev); stbl = (int8_t *) & dtp_t->slot[dtp_t->header.stblindex]; lastslot = DTPAGEMAXSLOT - 1; } if (dtp_t->header.flag & BT_LEAF) { struct ldtentry *ldtentry; for (i = 0; i < dtp_t->header.nextindex; i++) { /* * leaf node entry head-only segment */ index = stbl[i]; /* Don't let bad dtree make us go outside of page */ if (index > lastslot) continue; ldtentry = (struct ldtentry *) &dtp_t->slot[index]; ldtentry->inumber = __le32_to_cpu(ldtentry->inumber); if ((sb_flag & JFS_DIR_INDEX) == JFS_DIR_INDEX) DtlHdrDataLen = DTLHDRDATALEN; else DtlHdrDataLen = DTLHDRDATALEN_LEGACY; len = ldtentry->namlen; for (j = 0; j < MIN(ldtentry->namlen, DtlHdrDataLen); j++) ldtentry->name[j] = __le16_to_cpu(ldtentry->name[j]); len -= DtlHdrDataLen; ldtentry->index = __le32_to_cpu(ldtentry->index); index = ldtentry->next; /* * additional segments */ while ((index != -1) && (len > 0)) { if (index > lastslot) break; dtslot = &dtp_t->slot[index]; for (j = 0; j < DTSLOTDATALEN; j++) dtslot->name[j] = __le16_to_cpu(dtslot->name[j]); len -= DTSLOTDATALEN; index = dtslot->next; } } } else { /* BT_INTERNAL */ struct idtentry *idtentry; for (i = 0; i < dtp_t->header.nextindex; i++) { /* * internal node entry head-only segment */ index = stbl[i]; /* Don't let bad dtree make us go outside of page */ if (index > lastslot) continue; idtentry = (struct idtentry *) &dtp_t->slot[index]; len = idtentry->namlen; for (j = 0; j < MIN(idtentry->namlen, DTIHDRDATALEN); j++) idtentry->name[j] = __le16_to_cpu(idtentry->name[j]); len -= DTIHDRDATALEN; index = idtentry->next; /* * additional segments
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -