Commit 0b69760b authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Linus Torvalds

HPFS: Fix endianity. Make hpfs work on big-endian machines

Fix endianity. Make hpfs work on big-endian machines.
Signed-off-by: default avatarMikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bc8728ee
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
static int chk_if_allocated(struct super_block *s, secno sec, char *msg) static int chk_if_allocated(struct super_block *s, secno sec, char *msg)
{ {
struct quad_buffer_head qbh; struct quad_buffer_head qbh;
unsigned *bmp; u32 *bmp;
if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail; if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail;
if ((bmp[(sec & 0x3fff) >> 5] >> (sec & 0x1f)) & 1) { if ((cpu_to_le32(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f)) & 1) {
hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec); hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec);
goto fail1; goto fail1;
} }
...@@ -26,7 +26,7 @@ static int chk_if_allocated(struct super_block *s, secno sec, char *msg) ...@@ -26,7 +26,7 @@ static int chk_if_allocated(struct super_block *s, secno sec, char *msg)
if (sec >= hpfs_sb(s)->sb_dirband_start && sec < hpfs_sb(s)->sb_dirband_start + hpfs_sb(s)->sb_dirband_size) { if (sec >= hpfs_sb(s)->sb_dirband_start && sec < hpfs_sb(s)->sb_dirband_start + hpfs_sb(s)->sb_dirband_size) {
unsigned ssec = (sec - hpfs_sb(s)->sb_dirband_start) / 4; unsigned ssec = (sec - hpfs_sb(s)->sb_dirband_start) / 4;
if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) goto fail; if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) goto fail;
if ((bmp[ssec >> 5] >> (ssec & 0x1f)) & 1) { if ((le32_to_cpu(bmp[ssec >> 5]) >> (ssec & 0x1f)) & 1) {
hpfs_error(s, "sector '%s' - %08x not allocated in directory bitmap", msg, sec); hpfs_error(s, "sector '%s' - %08x not allocated in directory bitmap", msg, sec);
goto fail1; goto fail1;
} }
...@@ -82,10 +82,6 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne ...@@ -82,10 +82,6 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne
ret = bs + nr; ret = bs + nr;
goto rt; goto rt;
} }
/*if (!tstbits(bmp, nr + n, n + forward)) {
ret = bs + nr + n;
goto rt;
}*/
q = nr + n; b = 0; q = nr + n; b = 0;
while ((a = tstbits(bmp, q, n + forward)) != 0) { while ((a = tstbits(bmp, q, n + forward)) != 0) {
q += a; q += a;
...@@ -102,14 +98,14 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne ...@@ -102,14 +98,14 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne
goto rt; goto rt;
} }
nr >>= 5; nr >>= 5;
/*for (i = nr + 1; i != nr; i++, i &= 0x1ff) {*/ /*for (i = nr + 1; i != nr; i++, i &= 0x1ff) */
i = nr; i = nr;
do { do {
if (!bmp[i]) goto cont; if (!le32_to_cpu(bmp[i])) goto cont;
if (n + forward >= 0x3f && bmp[i] != -1) goto cont; if (n + forward >= 0x3f && le32_to_cpu(bmp[i]) != 0xffffffff) goto cont;
q = i<<5; q = i<<5;
if (i > 0) { if (i > 0) {
unsigned k = bmp[i-1]; unsigned k = le32_to_cpu(bmp[i-1]);
while (k & 0x80000000) { while (k & 0x80000000) {
q--; k <<= 1; q--; k <<= 1;
} }
...@@ -129,12 +125,12 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne ...@@ -129,12 +125,12 @@ static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigne
} while (i != nr); } while (i != nr);
rt: rt:
if (ret) { if (ret) {
if (hpfs_sb(s)->sb_chk && ((ret >> 14) != (bs >> 14) || (bmp[(ret & 0x3fff) >> 5] | ~(((1 << n) - 1) << (ret & 0x1f))) != 0xffffffff)) { if (hpfs_sb(s)->sb_chk && ((ret >> 14) != (bs >> 14) || (le32_to_cpu(bmp[(ret & 0x3fff) >> 5]) | ~(((1 << n) - 1) << (ret & 0x1f))) != 0xffffffff)) {
hpfs_error(s, "Allocation doesn't work! Wanted %d, allocated at %08x", n, ret); hpfs_error(s, "Allocation doesn't work! Wanted %d, allocated at %08x", n, ret);
ret = 0; ret = 0;
goto b; goto b;
} }
bmp[(ret & 0x3fff) >> 5] &= ~(((1 << n) - 1) << (ret & 0x1f)); bmp[(ret & 0x3fff) >> 5] &= cpu_to_le32(~(((1 << n) - 1) << (ret & 0x1f)));
hpfs_mark_4buffers_dirty(&qbh); hpfs_mark_4buffers_dirty(&qbh);
} }
b: b:
...@@ -240,10 +236,10 @@ static secno alloc_in_dirband(struct super_block *s, secno near) ...@@ -240,10 +236,10 @@ static secno alloc_in_dirband(struct super_block *s, secno near)
int hpfs_alloc_if_possible(struct super_block *s, secno sec) int hpfs_alloc_if_possible(struct super_block *s, secno sec)
{ {
struct quad_buffer_head qbh; struct quad_buffer_head qbh;
unsigned *bmp; u32 *bmp;
if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "aip"))) goto end; if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "aip"))) goto end;
if (bmp[(sec & 0x3fff) >> 5] & (1 << (sec & 0x1f))) { if (le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) & (1 << (sec & 0x1f))) {
bmp[(sec & 0x3fff) >> 5] &= ~(1 << (sec & 0x1f)); bmp[(sec & 0x3fff) >> 5] &= cpu_to_le32(~(1 << (sec & 0x1f)));
hpfs_mark_4buffers_dirty(&qbh); hpfs_mark_4buffers_dirty(&qbh);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
return 1; return 1;
...@@ -258,7 +254,7 @@ int hpfs_alloc_if_possible(struct super_block *s, secno sec) ...@@ -258,7 +254,7 @@ int hpfs_alloc_if_possible(struct super_block *s, secno sec)
void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n) void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n)
{ {
struct quad_buffer_head qbh; struct quad_buffer_head qbh;
unsigned *bmp; u32 *bmp;
struct hpfs_sb_info *sbi = hpfs_sb(s); struct hpfs_sb_info *sbi = hpfs_sb(s);
/*printk("2 - ");*/ /*printk("2 - ");*/
if (!n) return; if (!n) return;
...@@ -273,12 +269,12 @@ void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n) ...@@ -273,12 +269,12 @@ void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n)
return; return;
} }
new_tst: new_tst:
if ((bmp[(sec & 0x3fff) >> 5] >> (sec & 0x1f) & 1)) { if ((le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f) & 1)) {
hpfs_error(s, "sector %08x not allocated", sec); hpfs_error(s, "sector %08x not allocated", sec);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
return; return;
} }
bmp[(sec & 0x3fff) >> 5] |= 1 << (sec & 0x1f); bmp[(sec & 0x3fff) >> 5] |= cpu_to_le32(1 << (sec & 0x1f));
if (!--n) { if (!--n) {
hpfs_mark_4buffers_dirty(&qbh); hpfs_mark_4buffers_dirty(&qbh);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
...@@ -303,13 +299,13 @@ int hpfs_check_free_dnodes(struct super_block *s, int n) ...@@ -303,13 +299,13 @@ int hpfs_check_free_dnodes(struct super_block *s, int n)
int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14; int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14;
int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff; int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff;
int i, j; int i, j;
unsigned *bmp; u32 *bmp;
struct quad_buffer_head qbh; struct quad_buffer_head qbh;
if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) { if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) {
for (j = 0; j < 512; j++) { for (j = 0; j < 512; j++) {
unsigned k; unsigned k;
if (!bmp[j]) continue; if (!le32_to_cpu(bmp[j])) continue;
for (k = bmp[j]; k; k >>= 1) if (k & 1) if (!--n) { for (k = le32_to_cpu(bmp[j]); k; k >>= 1) if (k & 1) if (!--n) {
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
return 0; return 0;
} }
...@@ -328,10 +324,10 @@ int hpfs_check_free_dnodes(struct super_block *s, int n) ...@@ -328,10 +324,10 @@ int hpfs_check_free_dnodes(struct super_block *s, int n)
chk_bmp: chk_bmp:
if (bmp) { if (bmp) {
for (j = 0; j < 512; j++) { for (j = 0; j < 512; j++) {
unsigned k; u32 k;
if (!bmp[j]) continue; if (!le32_to_cpu(bmp[j])) continue;
for (k = 0xf; k; k <<= 4) for (k = 0xf; k; k <<= 4)
if ((bmp[j] & k) == k) { if ((le32_to_cpu(bmp[j]) & k) == k) {
if (!--n) { if (!--n) {
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
return 0; return 0;
...@@ -355,12 +351,12 @@ void hpfs_free_dnode(struct super_block *s, dnode_secno dno) ...@@ -355,12 +351,12 @@ void hpfs_free_dnode(struct super_block *s, dnode_secno dno)
hpfs_free_sectors(s, dno, 4); hpfs_free_sectors(s, dno, 4);
} else { } else {
struct quad_buffer_head qbh; struct quad_buffer_head qbh;
unsigned *bmp; u32 *bmp;
unsigned ssec = (dno - hpfs_sb(s)->sb_dirband_start) / 4; unsigned ssec = (dno - hpfs_sb(s)->sb_dirband_start) / 4;
if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) { if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) {
return; return;
} }
bmp[ssec >> 5] |= 1 << (ssec & 0x1f); bmp[ssec >> 5] |= cpu_to_le32(1 << (ssec & 0x1f));
hpfs_mark_4buffers_dirty(&qbh); hpfs_mark_4buffers_dirty(&qbh);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
} }
...@@ -382,13 +378,13 @@ struct dnode *hpfs_alloc_dnode(struct super_block *s, secno near, ...@@ -382,13 +378,13 @@ struct dnode *hpfs_alloc_dnode(struct super_block *s, secno near,
return NULL; return NULL;
} }
memset(d, 0, 2048); memset(d, 0, 2048);
d->magic = DNODE_MAGIC; d->magic = cpu_to_le32(DNODE_MAGIC);
d->first_free = 52; d->first_free = cpu_to_le32(52);
d->dirent[0] = 32; d->dirent[0] = 32;
d->dirent[2] = 8; d->dirent[2] = 8;
d->dirent[30] = 1; d->dirent[30] = 1;
d->dirent[31] = 255; d->dirent[31] = 255;
d->self = *dno; d->self = cpu_to_le32(*dno);
return d; return d;
} }
...@@ -402,10 +398,10 @@ struct fnode *hpfs_alloc_fnode(struct super_block *s, secno near, fnode_secno *f ...@@ -402,10 +398,10 @@ struct fnode *hpfs_alloc_fnode(struct super_block *s, secno near, fnode_secno *f
return NULL; return NULL;
} }
memset(f, 0, 512); memset(f, 0, 512);
f->magic = FNODE_MAGIC; f->magic = cpu_to_le32(FNODE_MAGIC);
f->ea_offs = 0xc4; f->ea_offs = cpu_to_le16(0xc4);
f->btree.n_free_nodes = 8; f->btree.n_free_nodes = 8;
f->btree.first_free = 8; f->btree.first_free = cpu_to_le16(8);
return f; return f;
} }
...@@ -419,10 +415,10 @@ struct anode *hpfs_alloc_anode(struct super_block *s, secno near, anode_secno *a ...@@ -419,10 +415,10 @@ struct anode *hpfs_alloc_anode(struct super_block *s, secno near, anode_secno *a
return NULL; return NULL;
} }
memset(a, 0, 512); memset(a, 0, 512);
a->magic = ANODE_MAGIC; a->magic = cpu_to_le32(ANODE_MAGIC);
a->self = *ano; a->self = cpu_to_le32(*ano);
a->btree.n_free_nodes = 40; a->btree.n_free_nodes = 40;
a->btree.n_used_nodes = 0; a->btree.n_used_nodes = 0;
a->btree.first_free = 8; a->btree.first_free = cpu_to_le16(8);
return a; return a;
} }
This diff is collapsed.
...@@ -88,9 +88,9 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -88,9 +88,9 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
hpfs_error(inode->i_sb, "not a directory, fnode %08lx", hpfs_error(inode->i_sb, "not a directory, fnode %08lx",
(unsigned long)inode->i_ino); (unsigned long)inode->i_ino);
} }
if (hpfs_inode->i_dno != fno->u.external[0].disk_secno) { if (hpfs_inode->i_dno != le32_to_cpu(fno->u.external[0].disk_secno)) {
e = 1; e = 1;
hpfs_error(inode->i_sb, "corrupted inode: i_dno == %08x, fnode -> dnode == %08x", hpfs_inode->i_dno, fno->u.external[0].disk_secno); hpfs_error(inode->i_sb, "corrupted inode: i_dno == %08x, fnode -> dnode == %08x", hpfs_inode->i_dno, le32_to_cpu(fno->u.external[0].disk_secno));
} }
brelse(bh); brelse(bh);
if (e) { if (e) {
...@@ -156,7 +156,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -156,7 +156,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
goto again; goto again;
} }
tempname = hpfs_translate_name(inode->i_sb, de->name, de->namelen, lc, de->not_8x3); tempname = hpfs_translate_name(inode->i_sb, de->name, de->namelen, lc, de->not_8x3);
if (filldir(dirent, tempname, de->namelen, old_pos, de->fnode, DT_UNKNOWN) < 0) { if (filldir(dirent, tempname, de->namelen, old_pos, le32_to_cpu(de->fnode), DT_UNKNOWN) < 0) {
filp->f_pos = old_pos; filp->f_pos = old_pos;
if (tempname != de->name) kfree(tempname); if (tempname != de->name) kfree(tempname);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
...@@ -221,7 +221,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name ...@@ -221,7 +221,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
* Get inode number, what we're after. * Get inode number, what we're after.
*/ */
ino = de->fnode; ino = le32_to_cpu(de->fnode);
/* /*
* Go find or make an inode. * Go find or make an inode.
...@@ -236,7 +236,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name ...@@ -236,7 +236,7 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
hpfs_init_inode(result); hpfs_init_inode(result);
if (de->directory) if (de->directory)
hpfs_read_inode(result); hpfs_read_inode(result);
else if (de->ea_size && hpfs_sb(dir->i_sb)->sb_eas) else if (le32_to_cpu(de->ea_size) && hpfs_sb(dir->i_sb)->sb_eas)
hpfs_read_inode(result); hpfs_read_inode(result);
else { else {
result->i_mode |= S_IFREG; result->i_mode |= S_IFREG;
...@@ -261,19 +261,19 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name ...@@ -261,19 +261,19 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, struct name
*/ */
if (!result->i_ctime.tv_sec) { if (!result->i_ctime.tv_sec) {
if (!(result->i_ctime.tv_sec = local_to_gmt(dir->i_sb, de->creation_date))) if (!(result->i_ctime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(de->creation_date))))
result->i_ctime.tv_sec = 1; result->i_ctime.tv_sec = 1;
result->i_ctime.tv_nsec = 0; result->i_ctime.tv_nsec = 0;
result->i_mtime.tv_sec = local_to_gmt(dir->i_sb, de->write_date); result->i_mtime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(de->write_date));
result->i_mtime.tv_nsec = 0; result->i_mtime.tv_nsec = 0;
result->i_atime.tv_sec = local_to_gmt(dir->i_sb, de->read_date); result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(de->read_date));
result->i_atime.tv_nsec = 0; result->i_atime.tv_nsec = 0;
hpfs_result->i_ea_size = de->ea_size; hpfs_result->i_ea_size = le32_to_cpu(de->ea_size);
if (!hpfs_result->i_ea_mode && de->read_only) if (!hpfs_result->i_ea_mode && de->read_only)
result->i_mode &= ~0222; result->i_mode &= ~0222;
if (!de->directory) { if (!de->directory) {
if (result->i_size == -1) { if (result->i_size == -1) {
result->i_size = de->file_size; result->i_size = le32_to_cpu(de->file_size);
result->i_data.a_ops = &hpfs_aops; result->i_data.a_ops = &hpfs_aops;
hpfs_i(result)->mmu_private = result->i_size; hpfs_i(result)->mmu_private = result->i_size;
/* /*
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -84,7 +84,6 @@ struct hpfs_sb_info { ...@@ -84,7 +84,6 @@ struct hpfs_sb_info {
unsigned *sb_bmp_dir; /* main bitmap directory */ unsigned *sb_bmp_dir; /* main bitmap directory */
unsigned sb_c_bitmap; /* current bitmap */ unsigned sb_c_bitmap; /* current bitmap */
unsigned sb_max_fwd_alloc; /* max forwad allocation */ unsigned sb_max_fwd_alloc; /* max forwad allocation */
/*unsigned sb_mounting : 1;*/
int sb_timeshift; int sb_timeshift;
}; };
...@@ -100,7 +99,7 @@ struct quad_buffer_head { ...@@ -100,7 +99,7 @@ struct quad_buffer_head {
static inline dnode_secno de_down_pointer (struct hpfs_dirent *de) static inline dnode_secno de_down_pointer (struct hpfs_dirent *de)
{ {
CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n")); CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n"));
return *(dnode_secno *) ((void *) de + de->length - 4); return le32_to_cpu(*(dnode_secno *) ((void *) de + le16_to_cpu(de->length) - 4));
} }
/* The first dir entry in a dnode */ /* The first dir entry in a dnode */
...@@ -114,41 +113,41 @@ static inline struct hpfs_dirent *dnode_first_de (struct dnode *dnode) ...@@ -114,41 +113,41 @@ static inline struct hpfs_dirent *dnode_first_de (struct dnode *dnode)
static inline struct hpfs_dirent *dnode_end_de (struct dnode *dnode) static inline struct hpfs_dirent *dnode_end_de (struct dnode *dnode)
{ {
CHKCOND(dnode->first_free>=0x14 && dnode->first_free<=0xa00,("HPFS: dnode_end_de: dnode->first_free = %d\n",(int)dnode->first_free)); CHKCOND(le32_to_cpu(dnode->first_free)>=0x14 && le32_to_cpu(dnode->first_free)<=0xa00,("HPFS: dnode_end_de: dnode->first_free = %x\n",(unsigned)le32_to_cpu(dnode->first_free)));
return (void *) dnode + dnode->first_free; return (void *) dnode + le32_to_cpu(dnode->first_free);
} }
/* The dir entry after dir entry de */ /* The dir entry after dir entry de */
static inline struct hpfs_dirent *de_next_de (struct hpfs_dirent *de) static inline struct hpfs_dirent *de_next_de (struct hpfs_dirent *de)
{ {
CHKCOND(de->length>=0x20 && de->length<0x800,("HPFS: de_next_de: de->length = %d\n",(int)de->length)); CHKCOND(le16_to_cpu(de->length)>=0x20 && le16_to_cpu(de->length)<0x800,("HPFS: de_next_de: de->length = %x\n",(unsigned)le16_to_cpu(de->length)));
return (void *) de + de->length; return (void *) de + le16_to_cpu(de->length);
} }
static inline struct extended_attribute *fnode_ea(struct fnode *fnode) static inline struct extended_attribute *fnode_ea(struct fnode *fnode)
{ {
return (struct extended_attribute *)((char *)fnode + fnode->ea_offs + fnode->acl_size_s); return (struct extended_attribute *)((char *)fnode + le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s));
} }
static inline struct extended_attribute *fnode_end_ea(struct fnode *fnode) static inline struct extended_attribute *fnode_end_ea(struct fnode *fnode)
{ {
return (struct extended_attribute *)((char *)fnode + fnode->ea_offs + fnode->acl_size_s + fnode->ea_size_s); return (struct extended_attribute *)((char *)fnode + le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s));
} }
static inline struct extended_attribute *next_ea(struct extended_attribute *ea) static inline struct extended_attribute *next_ea(struct extended_attribute *ea)
{ {
return (struct extended_attribute *)((char *)ea + 5 + ea->namelen + ea->valuelen); return (struct extended_attribute *)((char *)ea + 5 + ea->namelen + le16_to_cpu(ea->valuelen));
} }
static inline secno ea_sec(struct extended_attribute *ea) static inline secno ea_sec(struct extended_attribute *ea)
{ {
return *(secno *)((char *)ea + 9 + ea->namelen); return le32_to_cpu(*((secno *)((char *)ea + 9 + ea->namelen)));
} }
static inline secno ea_len(struct extended_attribute *ea) static inline secno ea_len(struct extended_attribute *ea)
{ {
return *(secno *)((char *)ea + 5 + ea->namelen); return le32_to_cpu(*((secno *)((char *)ea + 5 + ea->namelen)));
} }
static inline char *ea_data(struct extended_attribute *ea) static inline char *ea_data(struct extended_attribute *ea)
...@@ -173,13 +172,13 @@ static inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src) ...@@ -173,13 +172,13 @@ static inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src)
dst->not_8x3 = n; dst->not_8x3 = n;
} }
static inline unsigned tstbits(unsigned *bmp, unsigned b, unsigned n) static inline unsigned tstbits(u32 *bmp, unsigned b, unsigned n)
{ {
int i; int i;
if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n; if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
if (!((bmp[(b & 0x3fff) >> 5] >> (b & 0x1f)) & 1)) return 1; if (!((le32_to_cpu(bmp[(b & 0x3fff) >> 5]) >> (b & 0x1f)) & 1)) return 1;
for (i = 1; i < n; i++) for (i = 1; i < n; i++)
if (/*b+i < 0x4000 &&*/ !((bmp[((b+i) & 0x3fff) >> 5] >> ((b+i) & 0x1f)) & 1)) if (!((le32_to_cpu(bmp[((b+i) & 0x3fff) >> 5]) >> ((b+i) & 0x1f)) & 1))
return i + 1; return i + 1;
return 0; return 0;
} }
......
...@@ -115,8 +115,8 @@ void hpfs_read_inode(struct inode *i) ...@@ -115,8 +115,8 @@ void hpfs_read_inode(struct inode *i)
i->i_mode |= S_IFDIR; i->i_mode |= S_IFDIR;
i->i_op = &hpfs_dir_iops; i->i_op = &hpfs_dir_iops;
i->i_fop = &hpfs_dir_ops; i->i_fop = &hpfs_dir_ops;
hpfs_inode->i_parent_dir = fnode->up; hpfs_inode->i_parent_dir = le32_to_cpu(fnode->up);
hpfs_inode->i_dno = fnode->u.external[0].disk_secno; hpfs_inode->i_dno = le32_to_cpu(fnode->u.external[0].disk_secno);
if (hpfs_sb(sb)->sb_chk >= 2) { if (hpfs_sb(sb)->sb_chk >= 2) {
struct buffer_head *bh0; struct buffer_head *bh0;
if (hpfs_map_fnode(sb, hpfs_inode->i_parent_dir, &bh0)) brelse(bh0); if (hpfs_map_fnode(sb, hpfs_inode->i_parent_dir, &bh0)) brelse(bh0);
...@@ -132,7 +132,7 @@ void hpfs_read_inode(struct inode *i) ...@@ -132,7 +132,7 @@ void hpfs_read_inode(struct inode *i)
i->i_op = &hpfs_file_iops; i->i_op = &hpfs_file_iops;
i->i_fop = &hpfs_file_ops; i->i_fop = &hpfs_file_ops;
i->i_nlink = 1; i->i_nlink = 1;
i->i_size = fnode->file_size; i->i_size = le32_to_cpu(fnode->file_size);
i->i_blocks = ((i->i_size + 511) >> 9) + 1; i->i_blocks = ((i->i_size + 511) >> 9) + 1;
i->i_data.a_ops = &hpfs_aops; i->i_data.a_ops = &hpfs_aops;
hpfs_i(i)->mmu_private = i->i_size; hpfs_i(i)->mmu_private = i->i_size;
...@@ -143,7 +143,7 @@ void hpfs_read_inode(struct inode *i) ...@@ -143,7 +143,7 @@ void hpfs_read_inode(struct inode *i)
static void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode) static void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode)
{ {
struct hpfs_inode_info *hpfs_inode = hpfs_i(i); struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
/*if (fnode->acl_size_l || fnode->acl_size_s) { /*if (le32_to_cpu(fnode->acl_size_l) || le16_to_cpu(fnode->acl_size_s)) {
Some unknown structures like ACL may be in fnode, Some unknown structures like ACL may be in fnode,
we'd better not overwrite them we'd better not overwrite them
hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 stuctures", i->i_ino); hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 stuctures", i->i_ino);
...@@ -218,30 +218,30 @@ void hpfs_write_inode_nolock(struct inode *i) ...@@ -218,30 +218,30 @@ void hpfs_write_inode_nolock(struct inode *i)
} }
} else de = NULL; } else de = NULL;
if (S_ISREG(i->i_mode)) { if (S_ISREG(i->i_mode)) {
fnode->file_size = i->i_size; fnode->file_size = cpu_to_le32(i->i_size);
if (de) de->file_size = i->i_size; if (de) de->file_size = cpu_to_le32(i->i_size);
} else if (S_ISDIR(i->i_mode)) { } else if (S_ISDIR(i->i_mode)) {
fnode->file_size = 0; fnode->file_size = cpu_to_le32(0);
if (de) de->file_size = 0; if (de) de->file_size = cpu_to_le32(0);
} }
hpfs_write_inode_ea(i, fnode); hpfs_write_inode_ea(i, fnode);
if (de) { if (de) {
de->write_date = gmt_to_local(i->i_sb, i->i_mtime.tv_sec); de->write_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_mtime.tv_sec));
de->read_date = gmt_to_local(i->i_sb, i->i_atime.tv_sec); de->read_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_atime.tv_sec));
de->creation_date = gmt_to_local(i->i_sb, i->i_ctime.tv_sec); de->creation_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_ctime.tv_sec));
de->read_only = !(i->i_mode & 0222); de->read_only = !(i->i_mode & 0222);
de->ea_size = hpfs_inode->i_ea_size; de->ea_size = cpu_to_le32(hpfs_inode->i_ea_size);
hpfs_mark_4buffers_dirty(&qbh); hpfs_mark_4buffers_dirty(&qbh);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
} }
if (S_ISDIR(i->i_mode)) { if (S_ISDIR(i->i_mode)) {
if ((de = map_dirent(i, hpfs_inode->i_dno, "\001\001", 2, NULL, &qbh))) { if ((de = map_dirent(i, hpfs_inode->i_dno, "\001\001", 2, NULL, &qbh))) {
de->write_date = gmt_to_local(i->i_sb, i->i_mtime.tv_sec); de->write_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_mtime.tv_sec));
de->read_date = gmt_to_local(i->i_sb, i->i_atime.tv_sec); de->read_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_atime.tv_sec));
de->creation_date = gmt_to_local(i->i_sb, i->i_ctime.tv_sec); de->creation_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_ctime.tv_sec));
de->read_only = !(i->i_mode & 0222); de->read_only = !(i->i_mode & 0222);
de->ea_size = /*hpfs_inode->i_ea_size*/0; de->ea_size = cpu_to_le32(/*hpfs_inode->i_ea_size*/0);
de->file_size = 0; de->file_size = cpu_to_le32(0);
hpfs_mark_4buffers_dirty(&qbh); hpfs_mark_4buffers_dirty(&qbh);
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
} else } else
......
...@@ -21,7 +21,7 @@ unsigned int *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block, ...@@ -21,7 +21,7 @@ unsigned int *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
hpfs_error(s, "hpfs_map_bitmap called with bad parameter: %08x at %s", bmp_block, id); hpfs_error(s, "hpfs_map_bitmap called with bad parameter: %08x at %s", bmp_block, id);
return NULL; return NULL;
} }
sec = hpfs_sb(s)->sb_bmp_dir[bmp_block]; sec = le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[bmp_block]);
if (!sec || sec > hpfs_sb(s)->sb_fs_size-4) { if (!sec || sec > hpfs_sb(s)->sb_fs_size-4) {
hpfs_error(s, "invalid bitmap block pointer %08x -> %08x at %s", bmp_block, sec, id); hpfs_error(s, "invalid bitmap block pointer %08x -> %08x at %s", bmp_block, sec, id);
return NULL; return NULL;
...@@ -46,18 +46,18 @@ unsigned char *hpfs_load_code_page(struct super_block *s, secno cps) ...@@ -46,18 +46,18 @@ unsigned char *hpfs_load_code_page(struct super_block *s, secno cps)
struct code_page_data *cpd; struct code_page_data *cpd;
struct code_page_directory *cp = hpfs_map_sector(s, cps, &bh, 0); struct code_page_directory *cp = hpfs_map_sector(s, cps, &bh, 0);
if (!cp) return NULL; if (!cp) return NULL;
if (cp->magic != CP_DIR_MAGIC) { if (le32_to_cpu(cp->magic) != CP_DIR_MAGIC) {
printk("HPFS: Code page directory magic doesn't match (magic = %08x)\n", cp->magic); printk("HPFS: Code page directory magic doesn't match (magic = %08x)\n", le32_to_cpu(cp->magic));
brelse(bh); brelse(bh);
return NULL; return NULL;
} }
if (!cp->n_code_pages) { if (!le32_to_cpu(cp->n_code_pages)) {
printk("HPFS: n_code_pages == 0\n"); printk("HPFS: n_code_pages == 0\n");
brelse(bh); brelse(bh);
return NULL; return NULL;
} }
cpds = cp->array[0].code_page_data; cpds = le32_to_cpu(cp->array[0].code_page_data);
cpi = cp->array[0].index; cpi = le16_to_cpu(cp->array[0].index);
brelse(bh); brelse(bh);
if (cpi >= 3) { if (cpi >= 3) {
...@@ -66,12 +66,12 @@ unsigned char *hpfs_load_code_page(struct super_block *s, secno cps) ...@@ -66,12 +66,12 @@ unsigned char *hpfs_load_code_page(struct super_block *s, secno cps)
} }
if (!(cpd = hpfs_map_sector(s, cpds, &bh, 0))) return NULL; if (!(cpd = hpfs_map_sector(s, cpds, &bh, 0))) return NULL;
if ((unsigned)cpd->offs[cpi] > 0x178) { if (le16_to_cpu(cpd->offs[cpi]) > 0x178) {
printk("HPFS: Code page index out of sector\n"); printk("HPFS: Code page index out of sector\n");
brelse(bh); brelse(bh);
return NULL; return NULL;
} }
ptr = (unsigned char *)cpd + cpd->offs[cpi] + 6; ptr = (unsigned char *)cpd + le16_to_cpu(cpd->offs[cpi]) + 6;
if (!(cp_table = kmalloc(256, GFP_KERNEL))) { if (!(cp_table = kmalloc(256, GFP_KERNEL))) {
printk("HPFS: out of memory for code page table\n"); printk("HPFS: out of memory for code page table\n");
brelse(bh); brelse(bh);
...@@ -125,7 +125,7 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea ...@@ -125,7 +125,7 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea
if (hpfs_sb(s)->sb_chk) { if (hpfs_sb(s)->sb_chk) {
struct extended_attribute *ea; struct extended_attribute *ea;
struct extended_attribute *ea_end; struct extended_attribute *ea_end;
if (fnode->magic != FNODE_MAGIC) { if (le32_to_cpu(fnode->magic) != FNODE_MAGIC) {
hpfs_error(s, "bad magic on fnode %08lx", hpfs_error(s, "bad magic on fnode %08lx",
(unsigned long)ino); (unsigned long)ino);
goto bail; goto bail;
...@@ -138,7 +138,7 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea ...@@ -138,7 +138,7 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea
(unsigned long)ino); (unsigned long)ino);
goto bail; goto bail;
} }
if (fnode->btree.first_free != if (le16_to_cpu(fnode->btree.first_free) !=
8 + fnode->btree.n_used_nodes * (fnode->btree.internal ? 8 : 12)) { 8 + fnode->btree.n_used_nodes * (fnode->btree.internal ? 8 : 12)) {
hpfs_error(s, hpfs_error(s,
"bad first_free pointer in fnode %08lx", "bad first_free pointer in fnode %08lx",
...@@ -146,12 +146,12 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea ...@@ -146,12 +146,12 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea
goto bail; goto bail;
} }
} }
if (fnode->ea_size_s && ((signed int)fnode->ea_offs < 0xc4 || if (le16_to_cpu(fnode->ea_size_s) && (le16_to_cpu(fnode->ea_offs) < 0xc4 ||
(signed int)fnode->ea_offs + fnode->acl_size_s + fnode->ea_size_s > 0x200)) { le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s) > 0x200)) {
hpfs_error(s, hpfs_error(s,
"bad EA info in fnode %08lx: ea_offs == %04x ea_size_s == %04x", "bad EA info in fnode %08lx: ea_offs == %04x ea_size_s == %04x",
(unsigned long)ino, (unsigned long)ino,
fnode->ea_offs, fnode->ea_size_s); le16_to_cpu(fnode->ea_offs), le16_to_cpu(fnode->ea_size_s));
goto bail; goto bail;
} }
ea = fnode_ea(fnode); ea = fnode_ea(fnode);
...@@ -178,16 +178,20 @@ struct anode *hpfs_map_anode(struct super_block *s, anode_secno ano, struct buff ...@@ -178,16 +178,20 @@ struct anode *hpfs_map_anode(struct super_block *s, anode_secno ano, struct buff
if (hpfs_sb(s)->sb_chk) if (hpfs_chk_sectors(s, ano, 1, "anode")) return NULL; if (hpfs_sb(s)->sb_chk) if (hpfs_chk_sectors(s, ano, 1, "anode")) return NULL;
if ((anode = hpfs_map_sector(s, ano, bhp, ANODE_RD_AHEAD))) if ((anode = hpfs_map_sector(s, ano, bhp, ANODE_RD_AHEAD)))
if (hpfs_sb(s)->sb_chk) { if (hpfs_sb(s)->sb_chk) {
if (anode->magic != ANODE_MAGIC || anode->self != ano) { if (le32_to_cpu(anode->magic) != ANODE_MAGIC) {
hpfs_error(s, "bad magic on anode %08x", ano); hpfs_error(s, "bad magic on anode %08x", ano);
goto bail; goto bail;
} }
if (le32_to_cpu(anode->self) != ano) {
hpfs_error(s, "self pointer invalid on anode %08x", ano);
goto bail;
}
if ((unsigned)anode->btree.n_used_nodes + (unsigned)anode->btree.n_free_nodes != if ((unsigned)anode->btree.n_used_nodes + (unsigned)anode->btree.n_free_nodes !=
(anode->btree.internal ? 60 : 40)) { (anode->btree.internal ? 60 : 40)) {
hpfs_error(s, "bad number of nodes in anode %08x", ano); hpfs_error(s, "bad number of nodes in anode %08x", ano);
goto bail; goto bail;
} }
if (anode->btree.first_free != if (le16_to_cpu(anode->btree.first_free) !=
8 + anode->btree.n_used_nodes * (anode->btree.internal ? 8 : 12)) { 8 + anode->btree.n_used_nodes * (anode->btree.internal ? 8 : 12)) {
hpfs_error(s, "bad first_free pointer in anode %08x", ano); hpfs_error(s, "bad first_free pointer in anode %08x", ano);
goto bail; goto bail;
...@@ -219,26 +223,26 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno, ...@@ -219,26 +223,26 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno,
unsigned p, pp = 0; unsigned p, pp = 0;
unsigned char *d = (unsigned char *)dnode; unsigned char *d = (unsigned char *)dnode;
int b = 0; int b = 0;
if (dnode->magic != DNODE_MAGIC) { if (le32_to_cpu(dnode->magic) != DNODE_MAGIC) {
hpfs_error(s, "bad magic on dnode %08x", secno); hpfs_error(s, "bad magic on dnode %08x", secno);
goto bail; goto bail;
} }
if (dnode->self != secno) if (le32_to_cpu(dnode->self) != secno)
hpfs_error(s, "bad self pointer on dnode %08x self = %08x", secno, dnode->self); hpfs_error(s, "bad self pointer on dnode %08x self = %08x", secno, le32_to_cpu(dnode->self));
/* Check dirents - bad dirents would cause infinite /* Check dirents - bad dirents would cause infinite
loops or shooting to memory */ loops or shooting to memory */
if (dnode->first_free > 2048/* || dnode->first_free < 84*/) { if (le32_to_cpu(dnode->first_free) > 2048) {
hpfs_error(s, "dnode %08x has first_free == %08x", secno, dnode->first_free); hpfs_error(s, "dnode %08x has first_free == %08x", secno, le32_to_cpu(dnode->first_free));
goto bail; goto bail;
} }
for (p = 20; p < dnode->first_free; p += d[p] + (d[p+1] << 8)) { for (p = 20; p < le32_to_cpu(dnode->first_free); p += d[p] + (d[p+1] << 8)) {
struct hpfs_dirent *de = (struct hpfs_dirent *)((char *)dnode + p); struct hpfs_dirent *de = (struct hpfs_dirent *)((char *)dnode + p);
if (de->length > 292 || (de->length < 32) || (de->length & 3) || p + de->length > 2048) { if (le16_to_cpu(de->length) > 292 || (le16_to_cpu(de->length) < 32) || (le16_to_cpu(de->length) & 3) || p + le16_to_cpu(de->length) > 2048) {
hpfs_error(s, "bad dirent size in dnode %08x, dirent %03x, last %03x", secno, p, pp); hpfs_error(s, "bad dirent size in dnode %08x, dirent %03x, last %03x", secno, p, pp);
goto bail; goto bail;
} }
if (((31 + de->namelen + de->down*4 + 3) & ~3) != de->length) { if (((31 + de->namelen + de->down*4 + 3) & ~3) != le16_to_cpu(de->length)) {
if (((31 + de->namelen + de->down*4 + 3) & ~3) < de->length && s->s_flags & MS_RDONLY) goto ok; if (((31 + de->namelen + de->down*4 + 3) & ~3) < le16_to_cpu(de->length) && s->s_flags & MS_RDONLY) goto ok;
hpfs_error(s, "namelen does not match dirent size in dnode %08x, dirent %03x, last %03x", secno, p, pp); hpfs_error(s, "namelen does not match dirent size in dnode %08x, dirent %03x, last %03x", secno, p, pp);
goto bail; goto bail;
} }
...@@ -251,7 +255,7 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno, ...@@ -251,7 +255,7 @@ struct dnode *hpfs_map_dnode(struct super_block *s, unsigned secno,
pp = p; pp = p;
} }
if (p != dnode->first_free) { if (p != le32_to_cpu(dnode->first_free)) {
hpfs_error(s, "size on last dirent does not match first_free; dnode %08x", secno); hpfs_error(s, "size on last dirent does not match first_free; dnode %08x", secno);
goto bail; goto bail;
} }
...@@ -277,7 +281,7 @@ dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino) ...@@ -277,7 +281,7 @@ dnode_secno hpfs_fnode_dno(struct super_block *s, ino_t ino)
if (!fnode) if (!fnode)
return 0; return 0;
dno = fnode->u.external[0].disk_secno; dno = le32_to_cpu(fnode->u.external[0].disk_secno);
brelse(bh); brelse(bh);
return dno; return dno;
} }
...@@ -37,8 +37,8 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -37,8 +37,8 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
if (!(mode & 0222)) dee.read_only = 1; if (!(mode & 0222)) dee.read_only = 1;
/*dee.archive = 0;*/ /*dee.archive = 0;*/
dee.hidden = name[0] == '.'; dee.hidden = name[0] == '.';
dee.fnode = fno; dee.fnode = cpu_to_le32(fno);
dee.creation_date = dee.write_date = dee.read_date = gmt_to_local(dir->i_sb, get_seconds()); dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
result = new_inode(dir->i_sb); result = new_inode(dir->i_sb);
if (!result) if (!result)
goto bail2; goto bail2;
...@@ -46,7 +46,7 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -46,7 +46,7 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
result->i_ino = fno; result->i_ino = fno;
hpfs_i(result)->i_parent_dir = dir->i_ino; hpfs_i(result)->i_parent_dir = dir->i_ino;
hpfs_i(result)->i_dno = dno; hpfs_i(result)->i_dno = dno;
result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, dee.creation_date); result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
result->i_ctime.tv_nsec = 0; result->i_ctime.tv_nsec = 0;
result->i_mtime.tv_nsec = 0; result->i_mtime.tv_nsec = 0;
result->i_atime.tv_nsec = 0; result->i_atime.tv_nsec = 0;
...@@ -69,21 +69,21 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -69,21 +69,21 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
} }
fnode->len = len; fnode->len = len;
memcpy(fnode->name, name, len > 15 ? 15 : len); memcpy(fnode->name, name, len > 15 ? 15 : len);
fnode->up = dir->i_ino; fnode->up = cpu_to_le32(dir->i_ino);
fnode->dirflag = 1; fnode->dirflag = 1;
fnode->btree.n_free_nodes = 7; fnode->btree.n_free_nodes = 7;
fnode->btree.n_used_nodes = 1; fnode->btree.n_used_nodes = 1;
fnode->btree.first_free = 0x14; fnode->btree.first_free = cpu_to_le16(0x14);
fnode->u.external[0].disk_secno = dno; fnode->u.external[0].disk_secno = cpu_to_le32(dno);
fnode->u.external[0].file_secno = -1; fnode->u.external[0].file_secno = cpu_to_le32(-1);
dnode->root_dnode = 1; dnode->root_dnode = 1;
dnode->up = fno; dnode->up = cpu_to_le32(fno);
de = hpfs_add_de(dir->i_sb, dnode, "\001\001", 2, 0); de = hpfs_add_de(dir->i_sb, dnode, "\001\001", 2, 0);
de->creation_date = de->write_date = de->read_date = gmt_to_local(dir->i_sb, get_seconds()); de->creation_date = de->write_date = de->read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
if (!(mode & 0222)) de->read_only = 1; if (!(mode & 0222)) de->read_only = 1;
de->first = de->directory = 1; de->first = de->directory = 1;
/*de->hidden = de->system = 0;*/ /*de->hidden = de->system = 0;*/
de->fnode = fno; de->fnode = cpu_to_le32(fno);
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
brelse(bh); brelse(bh);
hpfs_mark_4buffers_dirty(&qbh0); hpfs_mark_4buffers_dirty(&qbh0);
...@@ -137,8 +137,8 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struc ...@@ -137,8 +137,8 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struc
if (!(mode & 0222)) dee.read_only = 1; if (!(mode & 0222)) dee.read_only = 1;
dee.archive = 1; dee.archive = 1;
dee.hidden = name[0] == '.'; dee.hidden = name[0] == '.';
dee.fnode = fno; dee.fnode = cpu_to_le32(fno);
dee.creation_date = dee.write_date = dee.read_date = gmt_to_local(dir->i_sb, get_seconds()); dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
result = new_inode(dir->i_sb); result = new_inode(dir->i_sb);
if (!result) if (!result)
...@@ -152,7 +152,7 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struc ...@@ -152,7 +152,7 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struc
result->i_fop = &hpfs_file_ops; result->i_fop = &hpfs_file_ops;
result->i_nlink = 1; result->i_nlink = 1;
hpfs_i(result)->i_parent_dir = dir->i_ino; hpfs_i(result)->i_parent_dir = dir->i_ino;
result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, dee.creation_date); result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
result->i_ctime.tv_nsec = 0; result->i_ctime.tv_nsec = 0;
result->i_mtime.tv_nsec = 0; result->i_mtime.tv_nsec = 0;
result->i_atime.tv_nsec = 0; result->i_atime.tv_nsec = 0;
...@@ -173,7 +173,7 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struc ...@@ -173,7 +173,7 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, struc
} }
fnode->len = len; fnode->len = len;
memcpy(fnode->name, name, len > 15 ? 15 : len); memcpy(fnode->name, name, len > 15 ? 15 : len);
fnode->up = dir->i_ino; fnode->up = cpu_to_le32(dir->i_ino);
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
brelse(bh); brelse(bh);
...@@ -225,8 +225,8 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t ...@@ -225,8 +225,8 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t
if (!(mode & 0222)) dee.read_only = 1; if (!(mode & 0222)) dee.read_only = 1;
dee.archive = 1; dee.archive = 1;
dee.hidden = name[0] == '.'; dee.hidden = name[0] == '.';
dee.fnode = fno; dee.fnode = cpu_to_le32(fno);
dee.creation_date = dee.write_date = dee.read_date = gmt_to_local(dir->i_sb, get_seconds()); dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
result = new_inode(dir->i_sb); result = new_inode(dir->i_sb);
if (!result) if (!result)
...@@ -235,7 +235,7 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t ...@@ -235,7 +235,7 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t
hpfs_init_inode(result); hpfs_init_inode(result);
result->i_ino = fno; result->i_ino = fno;
hpfs_i(result)->i_parent_dir = dir->i_ino; hpfs_i(result)->i_parent_dir = dir->i_ino;
result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, dee.creation_date); result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
result->i_ctime.tv_nsec = 0; result->i_ctime.tv_nsec = 0;
result->i_mtime.tv_nsec = 0; result->i_mtime.tv_nsec = 0;
result->i_atime.tv_nsec = 0; result->i_atime.tv_nsec = 0;
...@@ -256,7 +256,7 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t ...@@ -256,7 +256,7 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t
} }
fnode->len = len; fnode->len = len;
memcpy(fnode->name, name, len > 15 ? 15 : len); memcpy(fnode->name, name, len > 15 ? 15 : len);
fnode->up = dir->i_ino; fnode->up = cpu_to_le32(dir->i_ino);
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
insert_inode_hash(result); insert_inode_hash(result);
...@@ -300,8 +300,8 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy ...@@ -300,8 +300,8 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy
memset(&dee, 0, sizeof dee); memset(&dee, 0, sizeof dee);
dee.archive = 1; dee.archive = 1;
dee.hidden = name[0] == '.'; dee.hidden = name[0] == '.';
dee.fnode = fno; dee.fnode = cpu_to_le32(fno);
dee.creation_date = dee.write_date = dee.read_date = gmt_to_local(dir->i_sb, get_seconds()); dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
result = new_inode(dir->i_sb); result = new_inode(dir->i_sb);
if (!result) if (!result)
...@@ -309,7 +309,7 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy ...@@ -309,7 +309,7 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy
result->i_ino = fno; result->i_ino = fno;
hpfs_init_inode(result); hpfs_init_inode(result);
hpfs_i(result)->i_parent_dir = dir->i_ino; hpfs_i(result)->i_parent_dir = dir->i_ino;
result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, dee.creation_date); result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
result->i_ctime.tv_nsec = 0; result->i_ctime.tv_nsec = 0;
result->i_mtime.tv_nsec = 0; result->i_mtime.tv_nsec = 0;
result->i_atime.tv_nsec = 0; result->i_atime.tv_nsec = 0;
...@@ -332,7 +332,7 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy ...@@ -332,7 +332,7 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy
} }
fnode->len = len; fnode->len = len;
memcpy(fnode->name, name, len > 15 ? 15 : len); memcpy(fnode->name, name, len > 15 ? 15 : len);
fnode->up = dir->i_ino; fnode->up = cpu_to_le32(dir->i_ino);
hpfs_set_ea(result, fnode, "SYMLINK", symlink, strlen(symlink)); hpfs_set_ea(result, fnode, "SYMLINK", symlink, strlen(symlink));
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
brelse(bh); brelse(bh);
...@@ -382,7 +382,7 @@ static int hpfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -382,7 +382,7 @@ static int hpfs_unlink(struct inode *dir, struct dentry *dentry)
if (de->directory) if (de->directory)
goto out1; goto out1;
fno = de->fnode; fno = le32_to_cpu(de->fnode);
r = hpfs_remove_dirent(dir, dno, de, &qbh, 1); r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
switch (r) { switch (r) {
case 1: case 1:
...@@ -465,7 +465,7 @@ static int hpfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -465,7 +465,7 @@ static int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
if (n_items) if (n_items)
goto out1; goto out1;
fno = de->fnode; fno = le32_to_cpu(de->fnode);
r = hpfs_remove_dirent(dir, dno, de, &qbh, 1); r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
switch (r) { switch (r) {
case 1: case 1:
...@@ -608,7 +608,7 @@ static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -608,7 +608,7 @@ static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
drop_nlink(old_dir); drop_nlink(old_dir);
} }
if ((fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) { if ((fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) {
fnode->up = new_dir->i_ino; fnode->up = cpu_to_le32(new_dir->i_ino);
fnode->len = new_len; fnode->len = new_len;
memcpy(fnode->name, new_name, new_len>15?15:new_len); memcpy(fnode->name, new_name, new_len>15?15:new_len);
if (new_len < 15) memset(&fnode->name[new_len], 0, 15 - new_len); if (new_len < 15) memset(&fnode->name[new_len], 0, 15 - new_len);
......
...@@ -135,7 +135,7 @@ static unsigned count_bitmaps(struct super_block *s) ...@@ -135,7 +135,7 @@ static unsigned count_bitmaps(struct super_block *s)
n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14; n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
count = 0; count = 0;
for (n = 0; n < n_bands; n++) for (n = 0; n < n_bands; n++)
count += hpfs_count_one_bitmap(s, hpfs_sb(s)->sb_bmp_dir[n]); count += hpfs_count_one_bitmap(s, le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[n]));
return count; return count;
} }
...@@ -509,9 +509,9 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -509,9 +509,9 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3; if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3;
/* Check magics */ /* Check magics */
if (/*bootblock->magic != BB_MAGIC if (/*le16_to_cpu(bootblock->magic) != BB_MAGIC
||*/ superblock->magic != SB_MAGIC ||*/ le32_to_cpu(superblock->magic) != SB_MAGIC
|| spareblock->magic != SP_MAGIC) { || le32_to_cpu(spareblock->magic) != SP_MAGIC) {
if (!silent) printk("HPFS: Bad magic ... probably not HPFS\n"); if (!silent) printk("HPFS: Bad magic ... probably not HPFS\n");
goto bail4; goto bail4;
} }
...@@ -532,12 +532,12 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -532,12 +532,12 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
s->s_op = &hpfs_sops; s->s_op = &hpfs_sops;
s->s_d_op = &hpfs_dentry_operations; s->s_d_op = &hpfs_dentry_operations;
sbi->sb_root = superblock->root; sbi->sb_root = le32_to_cpu(superblock->root);
sbi->sb_fs_size = superblock->n_sectors; sbi->sb_fs_size = le32_to_cpu(superblock->n_sectors);
sbi->sb_bitmaps = superblock->bitmaps; sbi->sb_bitmaps = le32_to_cpu(superblock->bitmaps);
sbi->sb_dirband_start = superblock->dir_band_start; sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start);
sbi->sb_dirband_size = superblock->n_dir_band; sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band);
sbi->sb_dmap = superblock->dir_band_bitmap; sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap);
sbi->sb_uid = uid; sbi->sb_uid = uid;
sbi->sb_gid = gid; sbi->sb_gid = gid;
sbi->sb_mode = 0777 & ~umask; sbi->sb_mode = 0777 & ~umask;
...@@ -555,7 +555,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -555,7 +555,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
sbi->sb_max_fwd_alloc = 0xffffff; sbi->sb_max_fwd_alloc = 0xffffff;
/* Load bitmap directory */ /* Load bitmap directory */
if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, superblock->bitmaps))) if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, le32_to_cpu(superblock->bitmaps))))
goto bail4; goto bail4;
/* Check for general fs errors*/ /* Check for general fs errors*/
...@@ -573,7 +573,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -573,7 +573,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
mark_buffer_dirty(bh2); mark_buffer_dirty(bh2);
} }
if (spareblock->hotfixes_used || spareblock->n_spares_used) { if (le32_to_cpu(spareblock->hotfixes_used) || le32_to_cpu(spareblock->n_spares_used)) {
if (errs >= 2) { if (errs >= 2) {
printk("HPFS: Hotfixes not supported here, try chkdsk\n"); printk("HPFS: Hotfixes not supported here, try chkdsk\n");
mark_dirty(s, 0); mark_dirty(s, 0);
...@@ -583,7 +583,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -583,7 +583,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
if (errs == 0) printk("HPFS: Proceeding, but your filesystem will be probably corrupted by this driver...\n"); if (errs == 0) printk("HPFS: Proceeding, but your filesystem will be probably corrupted by this driver...\n");
else printk("HPFS: This driver may read bad files or crash when operating on disk with hotfixes.\n"); else printk("HPFS: This driver may read bad files or crash when operating on disk with hotfixes.\n");
} }
if (spareblock->n_dnode_spares != spareblock->n_dnode_spares_free) { if (le32_to_cpu(spareblock->n_dnode_spares) != le32_to_cpu(spareblock->n_dnode_spares_free)) {
if (errs >= 2) { if (errs >= 2) {
printk("HPFS: Spare dnodes used, try chkdsk\n"); printk("HPFS: Spare dnodes used, try chkdsk\n");
mark_dirty(s, 0); mark_dirty(s, 0);
...@@ -594,17 +594,17 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -594,17 +594,17 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
} }
if (chk) { if (chk) {
unsigned a; unsigned a;
if (superblock->dir_band_end - superblock->dir_band_start + 1 != superblock->n_dir_band || if (le32_to_cpu(superblock->dir_band_end) - le32_to_cpu(superblock->dir_band_start) + 1 != le32_to_cpu(superblock->n_dir_band) ||
superblock->dir_band_end < superblock->dir_band_start || superblock->n_dir_band > 0x4000) { le32_to_cpu(superblock->dir_band_end) < le32_to_cpu(superblock->dir_band_start) || le32_to_cpu(superblock->n_dir_band) > 0x4000) {
hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x", hpfs_error(s, "dir band size mismatch: dir_band_start==%08x, dir_band_end==%08x, n_dir_band==%08x",
superblock->dir_band_start, superblock->dir_band_end, superblock->n_dir_band); le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->dir_band_end), le32_to_cpu(superblock->n_dir_band));
goto bail4; goto bail4;
} }
a = sbi->sb_dirband_size; a = sbi->sb_dirband_size;
sbi->sb_dirband_size = 0; sbi->sb_dirband_size = 0;
if (hpfs_chk_sectors(s, superblock->dir_band_start, superblock->n_dir_band, "dir_band") || if (hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_start), le32_to_cpu(superblock->n_dir_band), "dir_band") ||
hpfs_chk_sectors(s, superblock->dir_band_bitmap, 4, "dir_band_bitmap") || hpfs_chk_sectors(s, le32_to_cpu(superblock->dir_band_bitmap), 4, "dir_band_bitmap") ||
hpfs_chk_sectors(s, superblock->bitmaps, 4, "bitmaps")) { hpfs_chk_sectors(s, le32_to_cpu(superblock->bitmaps), 4, "bitmaps")) {
mark_dirty(s, 0); mark_dirty(s, 0);
goto bail4; goto bail4;
} }
...@@ -612,8 +612,8 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -612,8 +612,8 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
} else printk("HPFS: You really don't want any checks? You are crazy...\n"); } else printk("HPFS: You really don't want any checks? You are crazy...\n");
/* Load code page table */ /* Load code page table */
if (spareblock->n_code_pages) if (le32_to_cpu(spareblock->n_code_pages))
if (!(sbi->sb_cp_table = hpfs_load_code_page(s, spareblock->code_page_dir))) if (!(sbi->sb_cp_table = hpfs_load_code_page(s, le32_to_cpu(spareblock->code_page_dir))))
printk("HPFS: Warning: code page support is disabled\n"); printk("HPFS: Warning: code page support is disabled\n");
brelse(bh2); brelse(bh2);
...@@ -642,13 +642,13 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent) ...@@ -642,13 +642,13 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
if (!de) if (!de)
hpfs_error(s, "unable to find root dir"); hpfs_error(s, "unable to find root dir");
else { else {
root->i_atime.tv_sec = local_to_gmt(s, de->read_date); root->i_atime.tv_sec = local_to_gmt(s, le32_to_cpu(de->read_date));
root->i_atime.tv_nsec = 0; root->i_atime.tv_nsec = 0;
root->i_mtime.tv_sec = local_to_gmt(s, de->write_date); root->i_mtime.tv_sec = local_to_gmt(s, le32_to_cpu(de->write_date));
root->i_mtime.tv_nsec = 0; root->i_mtime.tv_nsec = 0;
root->i_ctime.tv_sec = local_to_gmt(s, de->creation_date); root->i_ctime.tv_sec = local_to_gmt(s, le32_to_cpu(de->creation_date));
root->i_ctime.tv_nsec = 0; root->i_ctime.tv_nsec = 0;
hpfs_i(root)->i_ea_size = de->ea_size; hpfs_i(root)->i_ea_size = le16_to_cpu(de->ea_size);
hpfs_i(root)->i_parent_dir = root->i_ino; hpfs_i(root)->i_parent_dir = root->i_ino;
if (root->i_size == -1) if (root->i_size == -1)
root->i_size = 2048; root->i_size = 2048;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment