aboutsummaryrefslogtreecommitdiffstats
path: root/fs/affs/dir.c
blob: 548efd0ee98cd9e8e5449abde56d0c2821afaed4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 *  linux/fs/affs/dir.c
 *
 *  (c) 1996  Hans-Joachim Widmaier - Rewritten
 *
 *  (C) 1993  Ray Burr - Modified for Amiga FFS filesystem.
 *
 *  (C) 1992  Eric Youngdale Modified for ISO 9660 filesystem.
 *
 *  (C) 1991  Linus Torvalds - minix filesystem
 *
 *  affs directory handling functions
 *
 */

#include "affs.h"

static int affs_readdir(struct file *, void *, filldir_t);

struct file_operations affs_dir_operations = {
	.read		= generic_read_dir,
	.readdir	= affs_readdir,
	.fsync		= file_fsync,
};

/*
 * directories can handle most operations...
 */
struct inode_operations affs_dir_inode_operations = {
	.create		= affs_create,
	.lookup		= affs_lookup,
	.link		= affs_link,
	.unlink		= affs_unlink,
	.symlink	= affs_symlink,
	.mkdir		= affs_mkdir,
	.rmdir		= affs_rmdir,
	.rename		= affs_rename,
	.setattr	= affs_notify_change,
};

static int
affs_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
	struct inode		*inode = filp->f_dentry->d_inode;
	struct super_block	*sb = inode->i_sb;
	struct buffer_head	*dir_bh;
	struct buffer_head	*fh_bh;
	unsigned char		*name;
	int			 namelen;
	u32			 i;
	int			 hash_pos;
	int			 chain_pos;
	u32			 f_pos;
	u32			 ino;
	int			 stored;
	int			 res;

	pr_debug("AFFS: readdir(ino=%lu,f_pos=%lx)\n",inode->i_ino,(unsigned long)filp->f_pos);

	stored = 0;
	res    = -EIO;
	dir_bh = NULL;
	fh_bh  = NULL;
	f_pos  = filp->f_pos;

	if (f_pos == 0) {
		filp->private_data = (void *)0;
		if (filldir(dirent, ".", 1, f_pos, inode->i_ino, DT_DIR) < 0)
			return 0;
		filp->f_pos = f_pos = 1;
		stored++;
	}
	if (f_pos == 1) {
		if (filldir(dirent, "..", 2, f_pos, parent_ino(filp->f_dentry), DT_DIR) < 0)
			return stored;
		filp->f_pos = f_pos = 2;
		stored++;
	}

	affs_lock_dir(inode);
	chain_pos = (f_pos - 2) & 0xffff;
	hash_pos  = (f_pos - 2) >> 16;
	if (chain_pos == 0xffff) {
		affs_warning(sb, "readdir", "More than 65535 entries in chain");
		chain_pos = 0;
		hash_pos++;
		filp->f_pos = ((hash_pos << 16) | chain_pos) + 2;
	}
	dir_bh = affs_bread(sb, inode->i_ino);
	if (!dir_bh)
		goto readdir_out;

	/* If the directory hasn't changed since the last call to readdir(),
	 * we can jump directly to where we left off.
	 */
	ino = (u32)(long)filp->private_data;
	if (ino && filp->f_version == inode->i_version) {
		pr_debug("AFFS: readdir() left off=%d\n", ino);
		goto inside;
	}

	ino = be32_to_cpu(AFFS_HEAD(dir_bh)->table[hash_pos]);
	for (i = 0; ino && i < chain_pos; i++) {
		fh_bh = affs_bread(sb, ino);
		if (!fh_bh) {
			affs_error(sb, "readdir","Cannot read block %d", i);
			goto readdir_out;
		}
		ino = be32_to_cpu(AFFS_TAIL(sb, fh_bh)->hash_chain);
		affs_brelse(fh_bh);
		fh_bh = NULL;
	}
	if (ino)
		goto inside;
	hash_pos++;

	for (; hash_pos < AFFS_SB(sb)->s_hashsize; hash_pos++) {
		ino = be32_to_cpu(AFFS_HEAD(dir_bh)->table[hash_pos]);
		if (!ino)
			continue;
		f_pos = (hash_pos << 16) + 2;
inside:
		do {
			fh_bh = affs_bread(sb, ino);
			if (!fh_bh) {
				affs_error(sb, "readdir","Cannot read block %d", ino);
				goto readdir_done;
			}

			namelen = min(AFFS_TAIL(sb, fh_bh)->name[0], (u8)30);
			name = AFFS_TAIL(sb, fh_bh)->name + 1;
			pr_debug("AFFS: readdir(): filldir(\"%.*s\", ino=%u), hash=%d, f_pos=%x\n",
				 namelen, name, ino, hash_pos, f_pos);
			if (filldir(dirent, name, namelen, f_pos, ino, DT_UNKNOWN) < 0)
				goto readdir_done;
			stored++;
			f_pos++;
			ino = be32_to_cpu(AFFS_TAIL(sb, fh_bh)->hash_chain);
			affs_brelse(fh_bh);
			fh_bh = NULL;
		} while (ino);
	}
readdir_done:
	filp->f_pos = f_pos;
	filp->f_version = inode->i_version;
	filp->private_data = (void *)(long)ino;
	res = stored;

readdir_out:
	affs_brelse(dir_bh);
	affs_brelse(fh_bh);
	affs_unlock_dir(inode);
	pr_debug("AFFS: readdir()=%d\n", stored);
	return res;
}
ovi@ucsd.edu> * G400 support * * (following author is not in any relation with this code, but his code * is included in this driver) * * Based on framebuffer driver for VBE 2.0 compliant graphic boards * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> * * (following author is not in any relation with this code, but his ideas * were used when writing this driver) * * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk> * */ #include "matroxfb_accel.h" #include "matroxfb_DAC1064.h" #include "matroxfb_Ti3026.h" #include "matroxfb_misc.h" #define curr_ydstorg(x) ((x)->curr.ydstorg.pixels) #define mga_ydstlen(y,l) mga_outl(M_YDSTLEN | M_EXEC, ((y) << 16) | (l)) static inline void matrox_cfb4_pal(u_int32_t* pal) { unsigned int i; for (i = 0; i < 16; i++) { pal[i] = i * 0x11111111U; } } static inline void matrox_cfb8_pal(u_int32_t* pal) { unsigned int i; for (i = 0; i < 16; i++) { pal[i] = i * 0x01010101U; } } static void matroxfb_copyarea(struct fb_info* info, const struct fb_copyarea* area); static void matroxfb_fillrect(struct fb_info* info, const struct fb_fillrect* rect); static void matroxfb_imageblit(struct fb_info* info, const struct fb_image* image); static void matroxfb_cfb4_fillrect(struct fb_info* info, const struct fb_fillrect* rect); static void matroxfb_cfb4_copyarea(struct fb_info* info, const struct fb_copyarea* area); void matrox_cfbX_init(struct matrox_fb_info *minfo) { u_int32_t maccess; u_int32_t mpitch; u_int32_t mopmode; int accel; DBG(__func__) mpitch = minfo->fbcon.var.xres_virtual; minfo->fbops.fb_copyarea = cfb_copyarea; minfo->fbops.fb_fillrect = cfb_fillrect; minfo->fbops.fb_imageblit = cfb_imageblit; minfo->fbops.fb_cursor = NULL; accel = (minfo->fbcon.var.accel_flags & FB_ACCELF_TEXT) == FB_ACCELF_TEXT; switch (minfo->fbcon.var.bits_per_pixel) { case 4: maccess = 0x00000000; /* accelerate as 8bpp video */ mpitch = (mpitch >> 1) | 0x8000; /* disable linearization */ mopmode = M_OPMODE_4BPP; matrox_cfb4_pal(minfo->cmap); if (accel && !(mpitch & 1)) { minfo->fbops.fb_copyarea = matroxfb_cfb4_copyarea; minfo->fbops.fb_fillrect = matroxfb_cfb4_fillrect; } break; case 8: maccess = 0x00000000; mopmode = M_OPMODE_8BPP; matrox_cfb8_pal(minfo->cmap); if (accel) { minfo->fbops.fb_copyarea = matroxfb_copyarea; minfo->fbops.fb_fillrect = matroxfb_fillrect; minfo->fbops.fb_imageblit = matroxfb_imageblit; } break; case 16: if (minfo->fbcon.var.green.length == 5) maccess = 0xC0000001; else maccess = 0x40000001; mopmode = M_OPMODE_16BPP; if (accel) { minfo->fbops.fb_copyarea = matroxfb_copyarea; minfo->fbops.fb_fillrect = matroxfb_fillrect; minfo->fbops.fb_imageblit = matroxfb_imageblit; } break; case 24: maccess = 0x00000003; mopmode = M_OPMODE_24BPP; if (accel) { minfo->fbops.fb_copyarea = matroxfb_copyarea; minfo->fbops.fb_fillrect = matroxfb_fillrect; minfo->fbops.fb_imageblit = matroxfb_imageblit; } break; case 32: maccess = 0x00000002; mopmode = M_OPMODE_32BPP; if (accel) { minfo->fbops.fb_copyarea = matroxfb_copyarea; minfo->fbops.fb_fillrect = matroxfb_fillrect; minfo->fbops.fb_imageblit = matroxfb_imageblit; } break; default: maccess = 0x00000000; mopmode = 0x00000000; break; /* turn off acceleration!!! */ } mga_fifo(8); mga_outl(M_PITCH, mpitch); mga_outl(M_YDSTORG, curr_ydstorg(minfo)); if (minfo->capable.plnwt) mga_outl(M_PLNWT, -1); if (minfo->capable.srcorg) { mga_outl(M_SRCORG, 0); mga_outl(M_DSTORG, 0); } mga_outl(M_OPMODE, mopmode); mga_outl(M_CXBNDRY, 0xFFFF0000); mga_outl(M_YTOP, 0); mga_outl(M_YBOT, 0x01FFFFFF); mga_outl(M_MACCESS, maccess); minfo->accel.m_dwg_rect = M_DWG_TRAP | M_DWG_SOLID | M_DWG_ARZERO | M_DWG_SGNZERO | M_DWG_SHIFTZERO; if (isMilleniumII(minfo)) minfo->accel.m_dwg_rect |= M_DWG_TRANSC; minfo->accel.m_opmode = mopmode; minfo->accel.m_access = maccess; minfo->accel.m_pitch = mpitch; } EXPORT_SYMBOL(matrox_cfbX_init); static void matrox_accel_restore_maccess(struct matrox_fb_info *minfo) { mga_outl(M_MACCESS, minfo->accel.m_access); mga_outl(M_PITCH, minfo->accel.m_pitch); } static void matrox_accel_bmove(struct matrox_fb_info *minfo, int vxres, int sy, int sx, int dy, int dx, int height, int width) { int start, end; CRITFLAGS DBG(__func__) CRITBEGIN if ((dy < sy) || ((dy == sy) && (dx <= sx))) { mga_fifo(4); matrox_accel_restore_maccess(minfo); mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_SGNZERO | M_DWG_BFCOL | M_DWG_REPLACE); mga_outl(M_AR5, vxres); width--; start = sy*vxres+sx+curr_ydstorg(minfo); end = start+width; } else { mga_fifo(5); matrox_accel_restore_maccess(minfo); mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_BFCOL | M_DWG_REPLACE); mga_outl(M_SGN, 5); mga_outl(M_AR5, -vxres); width--; end = (sy+height-1)*vxres+sx+curr_ydstorg(minfo); start = end+width; dy += height-1; } mga_fifo(6); matrox_accel_restore_maccess(minfo); mga_outl(M_AR0, end); mga_outl(M_AR3, start); mga_outl(M_FXBNDRY, ((dx+width)<<16) | dx); mga_ydstlen(dy, height); WaitTillIdle(); CRITEND } static void matrox_accel_bmove_lin(struct matrox_fb_info *minfo, int vxres, int sy, int sx, int dy, int dx, int height, int width) { int start, end; CRITFLAGS DBG(__func__) CRITBEGIN if ((dy < sy) || ((dy == sy) && (dx <= sx))) { mga_fifo(4); matrox_accel_restore_maccess(minfo); mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_SGNZERO | M_DWG_BFCOL | M_DWG_REPLACE); mga_outl(M_AR5, vxres); width--; start = sy*vxres+sx+curr_ydstorg(minfo); end = start+width; } else { mga_fifo(5); matrox_accel_restore_maccess(minfo); mga_outl(M_DWGCTL, M_DWG_BITBLT | M_DWG_SHIFTZERO | M_DWG_BFCOL | M_DWG_REPLACE); mga_outl(M_SGN, 5); mga_outl(M_AR5, -vxres); width--; end = (sy+height-1)*vxres+sx+curr_ydstorg(minfo); start = end+width; dy += height-1; } mga_fifo(7); matrox_accel_restore_maccess(minfo); mga_outl(M_AR0, end); mga_outl(M_AR3, start); mga_outl(M_FXBNDRY, ((dx+width)<<16) | dx); mga_outl(M_YDST, dy*vxres >> 5); mga_outl(M_LEN | M_EXEC, height); WaitTillIdle(); CRITEND } static void matroxfb_cfb4_copyarea(struct fb_info* info, const struct fb_copyarea* area) { struct matrox_fb_info *minfo = info2minfo(info); if ((area->sx | area->dx | area->width) & 1) cfb_copyarea(info, area); else matrox_accel_bmove_lin(minfo, minfo->fbcon.var.xres_virtual >> 1, area->sy, area->sx >> 1, area->dy, area->dx >> 1, area->height, area->width >> 1); } static void matroxfb_copyarea(struct fb_info* info, const struct fb_copyarea* area) { struct matrox_fb_info *minfo = info2minfo(info); matrox_accel_bmove(minfo, minfo->fbcon.var.xres_virtual, area->sy, area->sx, area->dy, area->dx, area->height, area->width); } static void matroxfb_accel_clear(struct matrox_fb_info *minfo, u_int32_t color, int sy, int sx, int height, int width) { CRITFLAGS DBG(__func__) CRITBEGIN mga_fifo(7); matrox_accel_restore_maccess(minfo); mga_outl(M_DWGCTL, minfo->accel.m_dwg_rect | M_DWG_REPLACE); mga_outl(M_FCOL, color); mga_outl(M_FXBNDRY, ((sx + width) << 16) | sx); mga_ydstlen(sy, height); WaitTillIdle(); CRITEND } static void matroxfb_fillrect(struct fb_info* info, const struct fb_fillrect* rect) { struct matrox_fb_info *minfo = info2minfo(info); switch (rect->rop) { case ROP_COPY: matroxfb_accel_clear(minfo, ((u_int32_t *)info->pseudo_palette)[rect->color], rect->dy, rect->dx, rect->height, rect->width); break; } } static void matroxfb_cfb4_clear(struct matrox_fb_info *minfo, u_int32_t bgx, int sy, int sx, int height, int width) { int whattodo; CRITFLAGS DBG(__func__) CRITBEGIN whattodo = 0; if (sx & 1) { sx ++; if (!width) return; width --; whattodo = 1; } if (width & 1) {