2 * common.c - miscellaneous functions used by both the kernel helper and
5 * Copyright (C) 2004-2007, Michal Januszewski <spock@gentoo.org>
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License v2. See the file COPYING in the main directory of this archive for
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
31 int dev_create(char *fn
, char *sys
)
34 unsigned int major
= 0, minor
= 0;
38 // if (!access(fn, W_OK | R_OK))
41 fd
= open(sys
, O_RDONLY
);
52 sscanf(buf
, "%u:%u", &major
, &minor
);
58 res
= mknod(fn
, 0600 | S_IFCHR
, makedev(major
, minor
));
63 int fb_open(int fb
, bool create
)
71 snprintf(dev
, 64, PATH_DEV
"/fb%d", fb
);
72 if ((c
= open(dev
, O_RDWR
)) == -1) {
73 snprintf(dev
, 64, PATH_DEV
"/fb/%d", fb
);
74 c
= open(dev
, O_RDWR
);
77 if (c
== -1 && create
&& first
) {
79 snprintf(dev
, 64, PATH_DEV
"/fb%d", fb
);
80 snprintf(sys
, 128, PATH_SYS
"/class/graphics/fb%d/dev", fb
);
81 if (!dev_create(dev
, sys
))
90 return mmap(NULL
, fbd
.fix
.line_length
* fbd
.var
.yres
,
91 PROT_WRITE
| PROT_READ
, MAP_SHARED
, fb
,
92 fbd
.var
.yoffset
* fbd
.fix
.line_length
);
97 munmap(fb
, fbd
.fix
.line_length
* fbd
.var
.yres
);
100 int fb_get_settings(int fb
)
102 if (ioctl(fb
, FBIOGET_VSCREENINFO
, &fbd
.var
) == -1) {
103 iprint(MSG_ERROR
, "Failed to get fb_var info. (errno=%d)\n", errno
);
107 if (ioctl(fb
, FBIOGET_FSCREENINFO
, &fbd
.fix
) == -1) {
108 iprint(MSG_ERROR
, "Failed to get fb_fix info. (errno=%d)\n", errno
);
112 fbd
.bytespp
= (fbd
.var
.bits_per_pixel
+ 7) >> 3;
114 /* Check if optimized code can be used. We use special optimizations for
115 * 24/32bpp modes in which all color components have a length of 8 bits. */
116 if (fbd
.bytespp
< 3 || fbd
.var
.blue
.length
!= 8 || fbd
.var
.green
.length
!= 8 || fbd
.var
.red
.length
!= 8) {
119 if (fbd
.fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
120 fbd
.blen
= fbd
.glen
= fbd
.rlen
= min(min(fbd
.var
.red
.length
, fbd
.var
.green
.length
),fbd
.var
.blue
.length
);
122 fbd
.rlen
= fbd
.var
.red
.length
;
123 fbd
.glen
= fbd
.var
.green
.length
;
124 fbd
.blen
= fbd
.var
.blue
.length
;
129 /* Compute component offsets (ie. indexes in an array of u8's) */
130 fbd
.ro
= (fbd
.var
.red
.offset
>> 3);
131 fbd
.go
= (fbd
.var
.green
.offset
>> 3);
132 fbd
.bo
= (fbd
.var
.blue
.offset
>> 3);
134 if (endianess
== big
) {
135 fbd
.ro
= fbd
.bytespp
- 1 - fbd
.ro
;
136 fbd
.go
= fbd
.bytespp
- 1 - fbd
.go
;
137 fbd
.bo
= fbd
.bytespp
- 1 - fbd
.bo
;
144 int cfg_check_sanity(stheme_t
*theme
, u8 mode
)
148 /* Verbose mode needs a config file for the exact video mode that is
149 * currently in use. */
150 if (mode
== 'v' && (fbd
.var
.xres
!= theme
->xres
|| fbd
.var
.yres
!= theme
->yres
))
153 /* If the user specified invalid values for the text field - correct it.
154 * Also setup default values (text field covering the whole screen). */
155 if (theme
->tx
> fbd
.var
.xres
)
158 if (theme
->ty
> fbd
.var
.yres
)
161 if (theme
->tw
> fbd
.var
.xres
|| theme
->tw
== 0)
162 theme
->tw
= fbd
.var
.xres
;
164 if (theme
->th
> fbd
.var
.yres
|| theme
->th
== 0)
165 theme
->th
= fbd
.var
.yres
;
167 if (fbd
.var
.bits_per_pixel
== 8) {
168 pic
= (mode
== 'v') ? theme
->pic256
: theme
->silentpic256
;
171 iprint(MSG_ERROR
, "No 8bpp %s picture specified in the theme.\n", (mode
== 'v') ? "verbose" : "silent");
175 pic
= (mode
== 'v') ? theme
->pic
: theme
->silentpic
;
178 iprint(MSG_ERROR
, "No %s picture specified in the theme.\n", (mode
== 'v') ? "verbose" : "silent");
186 int tty_open(int tty
)
196 snprintf(dev
, 64, PATH_DEV
"/tty%d", tty
);
197 if ((c
= open(dev
, O_RDWR
| O_NOCTTY
)) == -1) {
198 snprintf(dev
, 64, PATH_DEV
"/vc/%d", tty
);
199 c
= open(dev
, O_RDWR
| O_NOCTTY
);
203 if (c
== -1 && first
) {
205 snprintf(dev
, 64, PATH_DEV
"/tty%d", tty
);
206 snprintf(sys
, 128, PATH_SYS
"/class/tty/tty%d/dev", tty
);
207 if (!dev_create(dev
, sys
))