diff options
author | Cristian RodrÃguez <crrodriguez@opensuse.org> | 2013-12-02 21:29:54 -0300 |
---|---|---|
committer | Cristian RodrÃguez <crrodriguez@opensuse.org> | 2013-12-02 21:29:54 -0300 |
commit | 8fa46f9dc1c0f5e4367eb9258aa509bc65c842b3 (patch) | |
tree | b643fcc87a5130a2bb00285e4dca17c4fe5ddafd | |
parent | a2075c01898c607270c4ac2b3b4093b2275c4ff0 (diff) | |
download | quota-tools-8fa46f9dc1c0f5e4367eb9258aa509bc65c842b3.tar.gz |
Use libc byteswapping routines not kernel ones
macros/functions from endian.h are the proper, documented userspace
interface to use.
-rw-r--r-- | convertquota.c | 32 | ||||
-rw-r--r-- | quotacheck_v2.c | 76 | ||||
-rw-r--r-- | quotaio.c | 2 | ||||
-rw-r--r-- | quotaio_tree.c | 44 | ||||
-rw-r--r-- | quotaio_v2.c | 126 |
5 files changed, 140 insertions, 140 deletions
diff --git a/convertquota.c b/convertquota.c index efaee71..76bd1e8 100644 --- a/convertquota.c +++ b/convertquota.c @@ -15,7 +15,7 @@ #include <errno.h> #include <getopt.h> -#include <asm/byteorder.h> +#include <endian.h> #include "pot.h" #include "common.h" @@ -137,14 +137,14 @@ typedef char *dqbuf_t; static inline void endian_disk2memdqblk(struct util_dqblk *m, struct v2r0_disk_dqblk *d) { - m->dqb_ihardlimit = __be32_to_cpu(d->dqb_ihardlimit); - m->dqb_isoftlimit = __be32_to_cpu(d->dqb_isoftlimit); - m->dqb_bhardlimit = __be32_to_cpu(d->dqb_bhardlimit); - m->dqb_bsoftlimit = __be32_to_cpu(d->dqb_bsoftlimit); - m->dqb_curinodes = __be32_to_cpu(d->dqb_curinodes); - m->dqb_curspace = __be64_to_cpu(d->dqb_curspace); - m->dqb_itime = __be64_to_cpu(d->dqb_itime); - m->dqb_btime = __be64_to_cpu(d->dqb_btime); + m->dqb_ihardlimit = be32toh(d->dqb_ihardlimit); + m->dqb_isoftlimit = be32toh(d->dqb_isoftlimit); + m->dqb_bhardlimit = be32toh(d->dqb_bhardlimit); + m->dqb_bsoftlimit = be32toh(d->dqb_bsoftlimit); + m->dqb_curinodes = be32toh(d->dqb_curinodes); + m->dqb_curspace = be64toh(d->dqb_curspace); + m->dqb_itime = be64toh(d->dqb_itime); + m->dqb_btime = be64toh(d->dqb_btime); } /* Is given dquot empty? */ @@ -186,7 +186,7 @@ static void endian_report_block(int fd, uint blk, char *bitmap) memset(&dquot, 0, sizeof(dquot)); dquot.dq_h = qn; endian_disk2memdqblk(&dquot.dq_dqb, ddata + i); - dquot.dq_id = __be32_to_cpu(ddata[i].dqb_id); + dquot.dq_id = be32toh(ddata[i].dqb_id); if (qn->qh_ops->commit_dquot(&dquot, COMMIT_ALL) < 0) errstr(_("Cannot commit dquot for id %u: %s\n"), (uint)dquot.dq_id, strerror(errno)); @@ -203,14 +203,14 @@ static void endian_report_tree(int fd, uint blk, int depth, char *bitmap) read_blk(fd, blk, buf); if (depth == QT_TREEDEPTH - 1) { for (i = 0; i < QT_BLKSIZE >> 2; i++) { - blk = __be32_to_cpu(ref[i]); + blk = be32toh(ref[i]); if (blk && !get_bit(bitmap, blk)) endian_report_block(fd, blk, bitmap); } } else { for (i = 0; i < QT_BLKSIZE >> 2; i++) - if ((blk = __be32_to_cpu(ref[i]))) + if ((blk = be32toh(ref[i]))) endian_report_tree(fd, blk, depth + 1, bitmap); } freedqbuf(buf); @@ -239,7 +239,7 @@ static int endian_check_header(int fd, int type) errstr(_("Cannot read header of old quotafile.\n")); return -1; } - if (__be32_to_cpu(head.dqh_magic) != file_magics[type] || __be32_to_cpu(head.dqh_version) > known_versions[type]) { + if (be32toh(head.dqh_magic) != file_magics[type] || be32toh(head.dqh_version) > known_versions[type]) { errstr(_("Bad file magic or version (probably not quotafile with bad endianity).\n")); return -1; } @@ -254,9 +254,9 @@ static int endian_load_info(int fd, int type) errstr(_("Cannot read information about old quotafile.\n")); return -1; } - qn->qh_info.u.v2_mdqi.dqi_flags = __be32_to_cpu(dinfo.dqi_flags); - qn->qh_info.dqi_bgrace = __be32_to_cpu(dinfo.dqi_bgrace); - qn->qh_info.dqi_igrace = __be32_to_cpu(dinfo.dqi_igrace); + qn->qh_info.u.v2_mdqi.dqi_flags = be32toh(dinfo.dqi_flags); + qn->qh_info.dqi_bgrace = be32toh(dinfo.dqi_bgrace); + qn->qh_info.dqi_igrace = be32toh(dinfo.dqi_igrace); return 0; } diff --git a/quotacheck_v2.c b/quotacheck_v2.c index c85cba0..de4293f 100644 --- a/quotacheck_v2.c +++ b/quotacheck_v2.c @@ -12,7 +12,7 @@ #include <errno.h> #include <stdarg.h> #include <stdlib.h> -#include <asm/byteorder.h> +#include <endian.h> #include "pot.h" #include "common.h" @@ -67,10 +67,10 @@ static int check_info(char *filename, int fd, int type) return -1; } - blocks = __le32_to_cpu(dinfo.dqi_blocks); - freeblk = __le32_to_cpu(dinfo.dqi_free_blk); - freeent = __le32_to_cpu(dinfo.dqi_free_entry); - dflags = __le32_to_cpu(dinfo.dqi_flags); + blocks = le32toh(dinfo.dqi_blocks); + freeblk = le32toh(dinfo.dqi_free_blk); + freeent = le32toh(dinfo.dqi_free_entry); + dflags = le32toh(dinfo.dqi_flags); filesize = lseek(fd, 0, SEEK_END); if (check_blkref(freeblk, blocks) < 0 || dflags & ~V2_DQF_MASK || check_blkref(freeent, blocks) < 0 || (filesize + QT_BLKSIZE - 1) >> QT_BLKSIZE_BITS != blocks) { @@ -86,8 +86,8 @@ static int check_info(char *filename, int fd, int type) old_info[type].u.v2_mdqi.dqi_qtree.dqi_blocks); } else { - old_info[type].dqi_bgrace = __le32_to_cpu(dinfo.dqi_bgrace); - old_info[type].dqi_igrace = __le32_to_cpu(dinfo.dqi_igrace); + old_info[type].dqi_bgrace = le32toh(dinfo.dqi_bgrace); + old_info[type].dqi_igrace = le32toh(dinfo.dqi_igrace); old_info[type].u.v2_mdqi.dqi_qtree.dqi_blocks = blocks; old_info[type].u.v2_mdqi.dqi_flags = dflags; } @@ -133,23 +133,23 @@ static void blk_corrupted(int *corrupted, uint * lblk, uint blk, char *fmtstr, . /* Convert dist quota format to utility one - copy just needed fields */ static void v2r0_disk2utildqblk(struct util_dqblk *u, struct v2r0_disk_dqblk *d) { - u->dqb_ihardlimit = __le32_to_cpu(d->dqb_ihardlimit); - u->dqb_isoftlimit = __le32_to_cpu(d->dqb_isoftlimit); - u->dqb_bhardlimit = __le32_to_cpu(d->dqb_bhardlimit); - u->dqb_bsoftlimit = __le32_to_cpu(d->dqb_bsoftlimit); - u->dqb_itime = __le64_to_cpu(d->dqb_itime); - u->dqb_btime = __le64_to_cpu(d->dqb_btime); + u->dqb_ihardlimit = le32toh(d->dqb_ihardlimit); + u->dqb_isoftlimit = le32toh(d->dqb_isoftlimit); + u->dqb_bhardlimit = le32toh(d->dqb_bhardlimit); + u->dqb_bsoftlimit = le32toh(d->dqb_bsoftlimit); + u->dqb_itime = le64toh(d->dqb_itime); + u->dqb_btime = le64toh(d->dqb_btime); } /* Convert dist quota format to utility one - copy just needed fields */ static void v2r1_disk2utildqblk(struct util_dqblk *u, struct v2r1_disk_dqblk *d) { - u->dqb_ihardlimit = __le64_to_cpu(d->dqb_ihardlimit); - u->dqb_isoftlimit = __le64_to_cpu(d->dqb_isoftlimit); - u->dqb_bhardlimit = __le64_to_cpu(d->dqb_bhardlimit); - u->dqb_bsoftlimit = __le64_to_cpu(d->dqb_bsoftlimit); - u->dqb_itime = __le64_to_cpu(d->dqb_itime); - u->dqb_btime = __le64_to_cpu(d->dqb_btime); + u->dqb_ihardlimit = le64toh(d->dqb_ihardlimit); + u->dqb_isoftlimit = le64toh(d->dqb_isoftlimit); + u->dqb_bhardlimit = le64toh(d->dqb_bhardlimit); + u->dqb_bsoftlimit = le64toh(d->dqb_bsoftlimit); + u->dqb_itime = le64toh(d->dqb_itime); + u->dqb_btime = le64toh(d->dqb_btime); } /* Put one entry info memory */ @@ -163,10 +163,10 @@ static int buffer_entry(dqbuf_t buf, uint blk, int *corrupted, uint * lblk, int if (detected_versions[type] == 0) { v2r0_disk2utildqblk(&mdq, (struct v2r0_disk_dqblk *)ddq); - id = __le32_to_cpu(((struct v2r0_disk_dqblk *)ddq)->dqb_id); + id = le32toh(((struct v2r0_disk_dqblk *)ddq)->dqb_id); } else { v2r1_disk2utildqblk(&mdq, (struct v2r1_disk_dqblk *)ddq); - id = __le32_to_cpu(((struct v2r1_disk_dqblk *)ddq)->dqb_id); + id = le32toh(((struct v2r1_disk_dqblk *)ddq)->dqb_id); } cd = lookup_dquot(id, type); @@ -271,12 +271,12 @@ static int check_data_blk(int fd, uint blk, int type, uint blocks, int * corrupt SET_BLK(blk); check_read_blk(fd, blk, buf); - if (check_blkref(__le32_to_cpu(head->dqdh_next_free), blocks) < 0) + if (check_blkref(le32toh(head->dqdh_next_free), blocks) < 0) blk_corrupted(corrupted, lblk, blk, _("Illegal free block reference to block %u"), - __le32_to_cpu(head->dqdh_next_free)); - if (__le16_to_cpu(head->dqdh_entries) > qtree_dqstr_in_blk(info)) + le32toh(head->dqdh_next_free)); + if (le16toh(head->dqdh_entries) > qtree_dqstr_in_blk(info)) blk_corrupted(corrupted, lblk, blk, _("Corrupted number of used entries (%u)"), - (uint) __le16_to_cpu(head->dqdh_entries)); + (uint) le16toh(head->dqdh_entries)); for (i = 0; i < qtree_dqstr_in_blk(info); i++) if (!qtree_entry_unused(info, dd + i * info->dqi_entry_size)) if (buffer_entry(buf, blk, corrupted, lblk, i, type) < 0) { @@ -299,15 +299,15 @@ static int check_tree_blk(int fd, uint blk, int depth, int type, uint blocks, in check_read_blk(fd, blk, buf); for (i = 0; i < QT_BLKSIZE >> 2; i++) if (depth < QT_TREEDEPTH - 1) { - if (check_tree_ref(blk, __le32_to_cpu(r[i]), blocks, 1, corrupted, lblk) >= 0 && - __le32_to_cpu(r[i])) /* Isn't block OK? */ - if (check_tree_blk(fd, __le32_to_cpu(r[i]), depth + 1, type, blocks, corrupted, lblk) < 0) { + if (check_tree_ref(blk, le32toh(r[i]), blocks, 1, corrupted, lblk) >= 0 && + le32toh(r[i])) /* Isn't block OK? */ + if (check_tree_blk(fd, le32toh(r[i]), depth + 1, type, blocks, corrupted, lblk) < 0) { freedqbuf(buf); return -1; } } - else if (check_tree_ref(blk, __le32_to_cpu(r[i]), blocks, 0, corrupted, lblk) >= 0 && __le32_to_cpu(r[i])) - if (!GET_BLK(__le32_to_cpu(r[i])) && check_data_blk(fd, __le32_to_cpu(r[i]), type, blocks, corrupted, lblk) < 0) { + else if (check_tree_ref(blk, le32toh(r[i]), blocks, 0, corrupted, lblk) >= 0 && le32toh(r[i])) + if (!GET_BLK(le32toh(r[i])) && check_data_blk(fd, le32toh(r[i]), type, blocks, corrupted, lblk) < 0) { freedqbuf(buf); return -1; } @@ -325,13 +325,13 @@ int v2_detect_version(char *filename, int fd, int type) err = read(fd, &head, sizeof(head)); if (err < 0 || err != sizeof(head)) return -1; - if (__le32_to_cpu(head.dqh_magic) != magics[type] || - __le32_to_cpu(head.dqh_version) > known_versions[type]) { + if (le32toh(head.dqh_magic) != magics[type] || + le32toh(head.dqh_version) > known_versions[type]) { errstr(_("Quota file %s has corrupted headers. You have to specify quota format on command line.\n"), filename); return -1; } - ver = __le32_to_cpu(head.dqh_version); + ver = le32toh(head.dqh_version); if (ver == 0) return QF_VFSV0; return QF_VFSV1; @@ -353,21 +353,21 @@ static int check_header(char *filename, int fd, int type, int version) filename); return -1; } - if (__le32_to_cpu(head.dqh_magic) != magics[type] || - __le32_to_cpu(head.dqh_version) > known_versions[type]) { + if (le32toh(head.dqh_magic) != magics[type] || + le32toh(head.dqh_version) > known_versions[type]) { errstr(_("WARNING - Quota file %s has corrupted headers\n"), filename); } - if (__le32_to_cpu(head.dqh_version) != version) { + if (le32toh(head.dqh_version) != version) { errstr(_("Quota file format version %d does not match the one " "specified on command line (%d). Quota file header " "may be corrupted.\n"), - __le32_to_cpu(head.dqh_version), version); + le32toh(head.dqh_version), version); if (!ask_yn(_("Continue checking assuming version from command line?"), 1)) return -1; detected_versions[type] = version; } else - detected_versions[type] = __le32_to_cpu(head.dqh_version); + detected_versions[type] = le32toh(head.dqh_version); debug(FL_DEBUG, _("Headers checked.\n")); return 0; @@ -15,7 +15,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/file.h> -#include <asm/byteorder.h> +#include <endian.h> #include "pot.h" #include "bylabel.h" diff --git a/quotaio_tree.c b/quotaio_tree.c index 9f87889..3922951 100644 --- a/quotaio_tree.c +++ b/quotaio_tree.c @@ -85,7 +85,7 @@ static int get_free_dqblk(struct quota_handle *h) if (info->dqi_free_blk) { blk = info->dqi_free_blk; read_blk(h, blk, buf); - info->dqi_free_blk = __le32_to_cpu(dh->dqdh_next_free); + info->dqi_free_blk = le32toh(dh->dqdh_next_free); } else { memset(buf, 0, QT_BLKSIZE); @@ -107,8 +107,8 @@ static void put_free_dqblk(struct quota_handle *h, dqbuf_t buf, uint blk) struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree; - dh->dqdh_next_free = __cpu_to_le32(info->dqi_free_blk); - dh->dqdh_prev_free = __cpu_to_le32(0); + dh->dqdh_next_free = htole32(info->dqi_free_blk); + dh->dqdh_prev_free = htole32(0); dh->dqdh_entries = __cpu_to_le16(0); info->dqi_free_blk = blk; mark_quotafile_info_dirty(h); @@ -120,9 +120,9 @@ static void remove_free_dqentry(struct quota_handle *h, dqbuf_t buf, uint blk) { dqbuf_t tmpbuf = getdqbuf(); struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; - uint nextblk = __le32_to_cpu(dh->dqdh_next_free), prevblk = + uint nextblk = le32toh(dh->dqdh_next_free), prevblk = - __le32_to_cpu(dh->dqdh_prev_free); + le32toh(dh->dqdh_prev_free); if (nextblk) { read_blk(h, nextblk, tmpbuf); @@ -139,7 +139,7 @@ static void remove_free_dqentry(struct quota_handle *h, dqbuf_t buf, uint blk) mark_quotafile_info_dirty(h); } freedqbuf(tmpbuf); - dh->dqdh_next_free = dh->dqdh_prev_free = __cpu_to_le32(0); + dh->dqdh_next_free = dh->dqdh_prev_free = htole32(0); write_blk(h, blk, buf); /* No matter whether write succeeds block is out of list */ } @@ -150,12 +150,12 @@ static void insert_free_dqentry(struct quota_handle *h, dqbuf_t buf, uint blk) struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; struct qtree_mem_dqinfo *info = &h->qh_info.u.v2_mdqi.dqi_qtree; - dh->dqdh_next_free = __cpu_to_le32(info->dqi_free_entry); - dh->dqdh_prev_free = __cpu_to_le32(0); + dh->dqdh_next_free = htole32(info->dqi_free_entry); + dh->dqdh_prev_free = htole32(0); write_blk(h, blk, buf); if (info->dqi_free_entry) { read_blk(h, info->dqi_free_entry, tmpbuf); - ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_prev_free = __cpu_to_le32(blk); + ((struct qt_disk_dqdbheader *)tmpbuf)->dqdh_prev_free = htole32(blk); write_blk(h, info->dqi_free_entry, tmpbuf); } freedqbuf(tmpbuf); @@ -190,9 +190,9 @@ static uint find_free_dqentry(struct quota_handle *h, struct dquot *dquot, int * info->dqi_free_entry = blk; mark_quotafile_info_dirty(h); } - if (__le16_to_cpu(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) /* Block will be full? */ + if (le16toh(dh->dqdh_entries) + 1 >= qtree_dqstr_in_blk(info)) /* Block will be full? */ remove_free_dqentry(h, buf, blk); - dh->dqdh_entries = __cpu_to_le16(__le16_to_cpu(dh->dqdh_entries) + 1); + dh->dqdh_entries = __cpu_to_le16(le16toh(dh->dqdh_entries) + 1); /* Find free structure in block */ ddquot = buf + sizeof(struct qt_disk_dqdbheader); for (i = 0; @@ -229,7 +229,7 @@ static int do_insert_tree(struct quota_handle *h, struct dquot *dquot, uint * tr else read_blk(h, *treeblk, buf); ref = (u_int32_t *) buf; - newblk = __le32_to_cpu(ref[get_index(dquot->dq_id, depth)]); + newblk = le32toh(ref[get_index(dquot->dq_id, depth)]); if (!newblk) newson = 1; if (depth == QT_TREEDEPTH - 1) { @@ -241,7 +241,7 @@ static int do_insert_tree(struct quota_handle *h, struct dquot *dquot, uint * tr else ret = do_insert_tree(h, dquot, &newblk, depth + 1); if (newson && ret >= 0) { - ref[get_index(dquot->dq_id, depth)] = __cpu_to_le32(newblk); + ref[get_index(dquot->dq_id, depth)] = htole32(newblk); write_blk(h, *treeblk, buf); } else if (newact && ret < 0) @@ -292,8 +292,8 @@ static void free_dqentry(struct quota_handle *h, struct dquot *dquot, uint blk) (uint) (dquot->dq_dqb.u.v2_mdqb.dqb_off >> QT_BLKSIZE_BITS)); read_blk(h, blk, buf); dh = (struct qt_disk_dqdbheader *)buf; - dh->dqdh_entries = __cpu_to_le16(__le16_to_cpu(dh->dqdh_entries) - 1); - if (!__le16_to_cpu(dh->dqdh_entries)) { /* Block got free? */ + dh->dqdh_entries = __cpu_to_le16(le16toh(dh->dqdh_entries) - 1); + if (!le16toh(dh->dqdh_entries)) { /* Block got free? */ remove_free_dqentry(h, buf, blk); put_free_dqblk(h, buf, blk); } @@ -301,7 +301,7 @@ static void free_dqentry(struct quota_handle *h, struct dquot *dquot, uint blk) memset(buf + (dquot->dq_dqb.u.v2_mdqb.dqb_off & ((1 << QT_BLKSIZE_BITS) - 1)), 0, info->dqi_entry_size); - if (__le16_to_cpu(dh->dqdh_entries) == qtree_dqstr_in_blk(info) - 1) /* First free entry? */ + if (le16toh(dh->dqdh_entries) == qtree_dqstr_in_blk(info) - 1) /* First free entry? */ insert_free_dqentry(h, buf, blk); /* This will also write data block */ else write_blk(h, blk, buf); @@ -318,7 +318,7 @@ static void remove_tree(struct quota_handle *h, struct dquot *dquot, uint * blk, u_int32_t *ref = (u_int32_t *) buf; read_blk(h, *blk, buf); - newblk = __le32_to_cpu(ref[get_index(dquot->dq_id, depth)]); + newblk = le32toh(ref[get_index(dquot->dq_id, depth)]); if (depth == QT_TREEDEPTH - 1) { free_dqentry(h, dquot, newblk); newblk = 0; @@ -328,7 +328,7 @@ static void remove_tree(struct quota_handle *h, struct dquot *dquot, uint * blk, if (!newblk) { int i; - ref[get_index(dquot->dq_id, depth)] = __cpu_to_le32(0); + ref[get_index(dquot->dq_id, depth)] = htole32(0); for (i = 0; i < QT_BLKSIZE && !buf[i]; i++); /* Block got empty? */ /* Don't put the root block into the free block list */ if (i == QT_BLKSIZE && *blk != QT_TREEOFF) { @@ -379,7 +379,7 @@ static loff_t find_tree_dqentry(struct quota_handle *h, struct dquot *dquot, uin read_blk(h, blk, buf); ret = 0; - blk = __le32_to_cpu(ref[get_index(dquot->dq_id, depth)]); + blk = le32toh(ref[get_index(dquot->dq_id, depth)]); if (!blk) /* No reference? */ goto out_buf; if (depth < QT_TREEDEPTH - 1) @@ -451,7 +451,7 @@ static int report_block(struct dquot *dquot, uint blk, char *bitmap, read_blk(dquot->dq_h, blk, buf); dh = (struct qt_disk_dqdbheader *)buf; ddata = buf + sizeof(struct qt_disk_dqdbheader); - entries = __le16_to_cpu(dh->dqdh_entries); + entries = le16toh(dh->dqdh_entries); for (i = 0; i < qtree_dqstr_in_blk(info); i++, ddata += info->dqi_entry_size) if (!qtree_entry_unused(info, ddata)) { info->dqi_ops->disk2mem_dqblk(dquot, ddata); @@ -478,7 +478,7 @@ static int report_tree(struct dquot *dquot, uint blk, int depth, char *bitmap, read_blk(dquot->dq_h, blk, buf); if (depth == QT_TREEDEPTH - 1) { for (i = 0; i < QT_BLKSIZE >> 2; i++) { - blk = __le32_to_cpu(ref[i]); + blk = le32toh(ref[i]); check_reference(dquot->dq_h, blk); if (blk && !get_bit(bitmap, blk)) entries += report_block(dquot, blk, bitmap, process_dquot); @@ -486,7 +486,7 @@ static int report_tree(struct dquot *dquot, uint blk, int depth, char *bitmap, } else { for (i = 0; i < QT_BLKSIZE >> 2; i++) - if ((blk = __le32_to_cpu(ref[i]))) { + if ((blk = le32toh(ref[i]))) { check_reference(dquot->dq_h, blk); entries += report_tree(dquot, blk, depth + 1, bitmap, process_dquot); diff --git a/quotaio_v2.c b/quotaio_v2.c index 06be04e..56a549f 100644 --- a/quotaio_v2.c +++ b/quotaio_v2.c @@ -12,7 +12,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <asm/byteorder.h> +#include <endian.h> #include "pot.h" #include "common.h" @@ -55,18 +55,18 @@ static void v2r0_disk2memdqblk(struct dquot *dquot, void *dp) struct util_dqblk *m = &dquot->dq_dqb; struct v2r0_disk_dqblk *d = dp, empty; - dquot->dq_id = __le32_to_cpu(d->dqb_id); - m->dqb_ihardlimit = __le32_to_cpu(d->dqb_ihardlimit); - m->dqb_isoftlimit = __le32_to_cpu(d->dqb_isoftlimit); - m->dqb_bhardlimit = __le32_to_cpu(d->dqb_bhardlimit); - m->dqb_bsoftlimit = __le32_to_cpu(d->dqb_bsoftlimit); - m->dqb_curinodes = __le32_to_cpu(d->dqb_curinodes); - m->dqb_curspace = __le64_to_cpu(d->dqb_curspace); - m->dqb_itime = __le64_to_cpu(d->dqb_itime); - m->dqb_btime = __le64_to_cpu(d->dqb_btime); + dquot->dq_id = le32toh(d->dqb_id); + m->dqb_ihardlimit = le32toh(d->dqb_ihardlimit); + m->dqb_isoftlimit = le32toh(d->dqb_isoftlimit); + m->dqb_bhardlimit = le32toh(d->dqb_bhardlimit); + m->dqb_bsoftlimit = le32toh(d->dqb_bsoftlimit); + m->dqb_curinodes = le32toh(d->dqb_curinodes); + m->dqb_curspace = le64toh(d->dqb_curspace); + m->dqb_itime = le64toh(d->dqb_itime); + m->dqb_btime = le64toh(d->dqb_btime); memset(&empty, 0, sizeof(struct v2r0_disk_dqblk)); - empty.dqb_itime = __cpu_to_le64(1); + empty.dqb_itime = htole64(1); if (!memcmp(&empty, dp, sizeof(struct v2r0_disk_dqblk))) m->dqb_itime = 0; } @@ -80,17 +80,17 @@ static void v2r0_mem2diskdqblk(void *dp, struct dquot *dquot) struct v2r0_disk_dqblk *d = dp; struct qtree_mem_dqinfo *info = &dquot->dq_h->qh_info.u.v2_mdqi.dqi_qtree; - d->dqb_ihardlimit = __cpu_to_le32(m->dqb_ihardlimit); - d->dqb_isoftlimit = __cpu_to_le32(m->dqb_isoftlimit); - d->dqb_bhardlimit = __cpu_to_le32(m->dqb_bhardlimit); - d->dqb_bsoftlimit = __cpu_to_le32(m->dqb_bsoftlimit); - d->dqb_curinodes = __cpu_to_le32(m->dqb_curinodes); - d->dqb_curspace = __cpu_to_le64(m->dqb_curspace); - d->dqb_itime = __cpu_to_le64(m->dqb_itime); - d->dqb_btime = __cpu_to_le64(m->dqb_btime); - d->dqb_id = __cpu_to_le32(dquot->dq_id); + d->dqb_ihardlimit = htole32(m->dqb_ihardlimit); + d->dqb_isoftlimit = htole32(m->dqb_isoftlimit); + d->dqb_bhardlimit = htole32(m->dqb_bhardlimit); + d->dqb_bsoftlimit = htole32(m->dqb_bsoftlimit); + d->dqb_curinodes = htole32(m->dqb_curinodes); + d->dqb_curspace = htole64(m->dqb_curspace); + d->dqb_itime = htole64(m->dqb_itime); + d->dqb_btime = htole64(m->dqb_btime); + d->dqb_id = htole32(dquot->dq_id); if (qtree_entry_unused(info, dp)) - d->dqb_itime = __cpu_to_le64(1); + d->dqb_itime = htole64(1); } static int v2r0_is_id(void *dp, struct dquot *dquot) @@ -100,7 +100,7 @@ static int v2r0_is_id(void *dp, struct dquot *dquot) if (qtree_entry_unused(info, dp)) return 0; - return __le32_to_cpu(d->dqb_id) == dquot->dq_id; + return le32toh(d->dqb_id) == dquot->dq_id; } /* @@ -111,18 +111,18 @@ static void v2r1_disk2memdqblk(struct dquot *dquot, void *dp) struct util_dqblk *m = &dquot->dq_dqb; struct v2r1_disk_dqblk *d = dp, empty; - dquot->dq_id = __le32_to_cpu(d->dqb_id); - m->dqb_ihardlimit = __le64_to_cpu(d->dqb_ihardlimit); - m->dqb_isoftlimit = __le64_to_cpu(d->dqb_isoftlimit); - m->dqb_bhardlimit = __le64_to_cpu(d->dqb_bhardlimit); - m->dqb_bsoftlimit = __le64_to_cpu(d->dqb_bsoftlimit); - m->dqb_curinodes = __le64_to_cpu(d->dqb_curinodes); - m->dqb_curspace = __le64_to_cpu(d->dqb_curspace); - m->dqb_itime = __le64_to_cpu(d->dqb_itime); - m->dqb_btime = __le64_to_cpu(d->dqb_btime); + dquot->dq_id = le32toh(d->dqb_id); + m->dqb_ihardlimit = le64toh(d->dqb_ihardlimit); + m->dqb_isoftlimit = le64toh(d->dqb_isoftlimit); + m->dqb_bhardlimit = le64toh(d->dqb_bhardlimit); + m->dqb_bsoftlimit = le64toh(d->dqb_bsoftlimit); + m->dqb_curinodes = le64toh(d->dqb_curinodes); + m->dqb_curspace = le64toh(d->dqb_curspace); + m->dqb_itime = le64toh(d->dqb_itime); + m->dqb_btime = le64toh(d->dqb_btime); memset(&empty, 0, sizeof(struct v2r1_disk_dqblk)); - empty.dqb_itime = __cpu_to_le64(1); + empty.dqb_itime = htole64(1); if (!memcmp(&empty, dp, sizeof(struct v2r1_disk_dqblk))) m->dqb_itime = 0; } @@ -135,18 +135,18 @@ static void v2r1_mem2diskdqblk(void *dp, struct dquot *dquot) struct util_dqblk *m = &dquot->dq_dqb; struct v2r1_disk_dqblk *d = dp; - d->dqb_ihardlimit = __cpu_to_le64(m->dqb_ihardlimit); - d->dqb_isoftlimit = __cpu_to_le64(m->dqb_isoftlimit); - d->dqb_bhardlimit = __cpu_to_le64(m->dqb_bhardlimit); - d->dqb_bsoftlimit = __cpu_to_le64(m->dqb_bsoftlimit); - d->dqb_curinodes = __cpu_to_le64(m->dqb_curinodes); - d->dqb_curspace = __cpu_to_le64(m->dqb_curspace); - d->dqb_itime = __cpu_to_le64(m->dqb_itime); - d->dqb_btime = __cpu_to_le64(m->dqb_btime); - d->dqb_id = __cpu_to_le32(dquot->dq_id); + d->dqb_ihardlimit = htole64(m->dqb_ihardlimit); + d->dqb_isoftlimit = htole64(m->dqb_isoftlimit); + d->dqb_bhardlimit = htole64(m->dqb_bhardlimit); + d->dqb_bsoftlimit = htole64(m->dqb_bsoftlimit); + d->dqb_curinodes = htole64(m->dqb_curinodes); + d->dqb_curspace = htole64(m->dqb_curspace); + d->dqb_itime = htole64(m->dqb_itime); + d->dqb_btime = htole64(m->dqb_btime); + d->dqb_id = htole32(dquot->dq_id); d->dqb_pad = 0; /* Initialize because of qtree_entry_unused() scan */ if (qtree_entry_unused(&dquot->dq_h->qh_info.u.v2_mdqi.dqi_qtree, dp)) - d->dqb_itime = __cpu_to_le64(1); + d->dqb_itime = htole64(1); } static int v2r1_is_id(void *dp, struct dquot *dquot) @@ -156,7 +156,7 @@ static int v2r1_is_id(void *dp, struct dquot *dquot) if (qtree_entry_unused(info, dp)) return 0; - return __le32_to_cpu(d->dqb_id) == dquot->dq_id; + return le32toh(d->dqb_id) == dquot->dq_id; } static struct qtree_fmt_operations v2r0_fmt_ops = { @@ -176,12 +176,12 @@ static struct qtree_fmt_operations v2r1_fmt_ops = { */ static inline void v2_disk2memdqinfo(struct util_dqinfo *m, struct v2_disk_dqinfo *d) { - m->dqi_bgrace = __le32_to_cpu(d->dqi_bgrace); - m->dqi_igrace = __le32_to_cpu(d->dqi_igrace); - m->u.v2_mdqi.dqi_flags = __le32_to_cpu(d->dqi_flags) & V2_DQF_MASK; - m->u.v2_mdqi.dqi_qtree.dqi_blocks = __le32_to_cpu(d->dqi_blocks); - m->u.v2_mdqi.dqi_qtree.dqi_free_blk = __le32_to_cpu(d->dqi_free_blk); - m->u.v2_mdqi.dqi_qtree.dqi_free_entry = __le32_to_cpu(d->dqi_free_entry); + m->dqi_bgrace = le32toh(d->dqi_bgrace); + m->dqi_igrace = le32toh(d->dqi_igrace); + m->u.v2_mdqi.dqi_flags = le32toh(d->dqi_flags) & V2_DQF_MASK; + m->u.v2_mdqi.dqi_qtree.dqi_blocks = le32toh(d->dqi_blocks); + m->u.v2_mdqi.dqi_qtree.dqi_free_blk = le32toh(d->dqi_free_blk); + m->u.v2_mdqi.dqi_qtree.dqi_free_entry = le32toh(d->dqi_free_entry); } /* @@ -189,12 +189,12 @@ static inline void v2_disk2memdqinfo(struct util_dqinfo *m, struct v2_disk_dqinf */ static inline void v2_mem2diskdqinfo(struct v2_disk_dqinfo *d, struct util_dqinfo *m) { - d->dqi_bgrace = __cpu_to_le32(m->dqi_bgrace); - d->dqi_igrace = __cpu_to_le32(m->dqi_igrace); - d->dqi_flags = __cpu_to_le32(m->u.v2_mdqi.dqi_flags & V2_DQF_MASK); - d->dqi_blocks = __cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_blocks); - d->dqi_free_blk = __cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_free_blk); - d->dqi_free_entry = __cpu_to_le32(m->u.v2_mdqi.dqi_qtree.dqi_free_entry); + d->dqi_bgrace = htole32(m->dqi_bgrace); + d->dqi_igrace = htole32(m->dqi_igrace); + d->dqi_flags = htole32(m->u.v2_mdqi.dqi_flags & V2_DQF_MASK); + d->dqi_blocks = htole32(m->u.v2_mdqi.dqi_qtree.dqi_blocks); + d->dqi_free_blk = htole32(m->u.v2_mdqi.dqi_qtree.dqi_free_blk); + d->dqi_free_entry = htole32(m->u.v2_mdqi.dqi_qtree.dqi_free_entry); } /* Convert kernel quotablock format to utility one */ @@ -250,14 +250,14 @@ static int v2_check_file(int fd, int type, int fmt) else return 0; - if (__le32_to_cpu(h.dqh_magic) != file_magics[type]) { - if (__be32_to_cpu(h.dqh_magic) == file_magics[type]) + if (le32toh(h.dqh_magic) != file_magics[type]) { + if (be32toh(h.dqh_magic) == file_magics[type]) die(3, _("Your quota file is stored in wrong endianity. Please use convertquota(8) to convert it.\n")); return 0; } - if (__le32_to_cpu(h.dqh_version) > known_versions[type]) + if (le32toh(h.dqh_version) > known_versions[type]) return 0; - if (version != __le32_to_cpu(h.dqh_version)) + if (version != le32toh(h.dqh_version)) return 0; return 1; } @@ -303,9 +303,9 @@ static int v2_init_io(struct quota_handle *h) if (!QIO_ENABLED(h)) v2_disk2memdqinfo(&h->qh_info, &ddqinfo); else /* We need just the number of blocks */ - h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks = __le32_to_cpu(ddqinfo.dqi_blocks); + h->qh_info.u.v2_mdqi.dqi_qtree.dqi_blocks = le32toh(ddqinfo.dqi_blocks); - if (__le32_to_cpu(header.dqh_version) == 0) { + if (le32toh(header.dqh_version) == 0) { h->qh_info.u.v2_mdqi.dqi_qtree.dqi_entry_size = sizeof(struct v2r0_disk_dqblk); h->qh_info.u.v2_mdqi.dqi_qtree.dqi_ops = &v2r0_fmt_ops; h->qh_info.dqi_max_b_limit = ~(uint32_t)0; @@ -345,8 +345,8 @@ static int v2_new_io(struct quota_handle *h) return -1; /* Write basic quota header */ - ddqheader.dqh_magic = __cpu_to_le32(file_magics[h->qh_type]); - ddqheader.dqh_version = __cpu_to_le32(version); + ddqheader.dqh_magic = htole32(file_magics[h->qh_type]); + ddqheader.dqh_version = htole32(version); lseek(h->qh_fd, 0, SEEK_SET); if (write(h->qh_fd, &ddqheader, sizeof(ddqheader)) != sizeof(ddqheader)) return -1; |