summaryrefslogtreecommitdiffstats
path: root/sys/qcam/qcam-os.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/qcam/qcam-os.c')
-rw-r--r--sys/qcam/qcam-os.c202
1 files changed, 114 insertions, 88 deletions
diff --git a/sys/qcam/qcam-os.c b/sys/qcam/qcam-os.c
index e73933d9..2c959e72 100644
--- a/sys/qcam/qcam-os.c
+++ b/sys/qcam/qcam-os.c
@@ -48,22 +48,50 @@ OTHER DEALINGS IN THE SOFTWARE.
#include "qcam.h"
#include "qcam-Linux.h"
-int __inline__ read_lpstatus(const struct qcam *q) { return inb(q->port+1); }
-int read_lpcontrol(const struct qcam *q) { return inb(q->port+2); }
-int read_lpdata(const struct qcam *q) { return inb(q->port); }
-void write_lpdata(const struct qcam *q, int d) { outb(d,q->port); }
-void write_lpcontrol(const struct qcam *q, int d) { outb(d,q->port+2); }
+int __inline__
+read_lpstatus (const struct qcam *q)
+{
+ return inb (q->port + 1);
+}
+
+int
+read_lpcontrol (const struct qcam *q)
+{
+ return inb (q->port + 2);
+}
+
+int
+read_lpdata (const struct qcam *q)
+{
+ return inb (q->port);
+}
-int enable_ports(const struct qcam *q)
+void
+write_lpdata (const struct qcam *q, int d)
{
- if(q->port<0x278) return 1; /* Better safe than sorry */
- if(q->port>0x3bc) return 1;
- return (ioperm(q->port, 3, 1));
+ outb (d, q->port);
}
-int disable_ports(const struct qcam *q)
+void
+write_lpcontrol (const struct qcam *q, int d)
{
- return (ioperm(q->port, 3, 0));
+ outb (d, q->port + 2);
+}
+
+int
+enable_ports (const struct qcam *q)
+{
+ if (q->port < 0x278)
+ return 1; /* Better safe than sorry */
+ if (q->port > 0x3bc)
+ return 1;
+ return (ioperm (q->port, 3, 1));
+}
+
+int
+disable_ports (const struct qcam *q)
+{
+ return (ioperm (q->port, 3, 0));
}
/* Lock port. This is currently sub-optimal, and is begging to be
@@ -81,121 +109,118 @@ int disable_ports(const struct qcam *q)
* multiple processes (eg. qcam) taking "snapshots" can peacefully coexist.
* - Dave Plonka (plonka@carroll1.cc.edu)
*/
-int qc_lock_wait(struct qcam *q, int wait)
+int
+qc_lock_wait (struct qcam *q, int wait)
{
#if 1
static struct flock sfl;
- if (-1 == q->fd) /* we've yet to open the lock file */
- {
- static char lockfile[128];
-
- sprintf(lockfile,"/var/run/LOCK.qcam.0x%x",q->port);
- if (-1 == (q->fd = open(lockfile, O_WRONLY | O_CREAT, 0666)))
- {
- perror("open");
- return 1;
- }
+ if (-1 == q->fd) { /* we've yet to open the lock file */
+ static char lockfile[128];
+ sprintf (lockfile, "/var/run/LOCK.qcam.0x%x", q->port);
+ if (-1 == (q->fd = open (lockfile, O_WRONLY | O_CREAT, 0666))) {
+ perror ("open");
+ return 1;
+ }
#ifdef TESTING
- fprintf(stderr, "%s - %d: %s open(2)ed\n", __FILE__, __LINE__, lockfile);
+ fprintf (stderr, "%s - %d: %s open(2)ed\n", __FILE__, __LINE__, lockfile);
#endif
- /* initialize the l_type memver to lock the file exclusively */
- sfl.l_type = F_WRLCK;
+ /* initialize the l_type memver to lock the file exclusively */
+ sfl.l_type = F_WRLCK;
}
-
#ifdef TESTING
- if (0 != fcntl(q->fd, F_SETLK, &sfl)) /* non-blocking set lock */
+ if (0 != fcntl (q->fd, F_SETLK, &sfl)) /* non-blocking set lock */
#else
- if (0 != fcntl(q->fd, wait? F_SETLKW : F_SETLK, &sfl))
+ if (0 != fcntl (q->fd, wait ? F_SETLKW : F_SETLK, &sfl))
#endif
{
#ifdef TESTING
- perror("fcntl");
- if (EAGAIN != errno || !wait) return 1;
-
- fprintf(stderr, "%s - %d: waiting for exclusive lock on fd %d...\n", __FILE__, __LINE__, q->fd);
+ perror ("fcntl");
+ if (EAGAIN != errno || !wait)
+ return 1;
+
+ fprintf (stderr, "%s - %d: waiting for exclusive lock on fd %d...\n",
+ __FILE__, __LINE__, q->fd);
- if (0 != fcntl(q->fd, F_SETLKW, &sfl)) /* "blocking" set lock */
+ if (0 != fcntl (q->fd, F_SETLKW, &sfl)) /* "blocking" set lock */
#endif
- {
- perror("fcntl");
- return 1;
- }
+ {
+ perror ("fcntl");
+ return 1;
+ }
}
-
#ifdef TESTING
- fprintf(stderr, "%s - %d: fd %d locked exclusively\n", __FILE__, __LINE__, q->fd);
+ fprintf (stderr, "%s - %d: fd %d locked exclusively\n", __FILE__, __LINE__,
+ q->fd);
#endif
#else
char lockfile[128], tmp[128];
struct stat statbuf;
- sprintf(lockfile,"/var/run/LOCK.qcam.0x%x",q->port);
- sprintf(tmp,"%s-%d",lockfile,getpid());
+ sprintf (lockfile, "/var/run/LOCK.qcam.0x%x", q->port);
+ sprintf (tmp, "%s-%d", lockfile, getpid ());
- if ((creat(tmp,0)==-1) ||
- (link(tmp,lockfile)==-1) ||
- (stat(tmp,&statbuf)==-1) ||
- (statbuf.st_nlink==1))
- {
+ if ((creat (tmp, 0) == -1) ||
+ (link (tmp, lockfile) == -1) ||
+ (stat (tmp, &statbuf) == -1) || (statbuf.st_nlink == 1)) {
#ifdef DEBUGQC
- perror("QuickCam Locked");
- if(unlink(tmp)==-1)
- perror("Error unlinking temp file.");
+ perror ("QuickCam Locked");
+ if (unlink (tmp) == -1)
+ perror ("Error unlinking temp file.");
#else
- unlink(tmp);
+ unlink (tmp);
#endif
return 1;
}
-
- unlink(tmp);
- if (chown(lockfile,getuid(),getgid())==-1)
- perror("Chown problems");
+
+ unlink (tmp);
+ if (chown (lockfile, getuid (), getgid ()) == -1)
+ perror ("Chown problems");
#endif
return 0;
}
-int qc_lock(struct qcam *q)
+int
+qc_lock (struct qcam *q)
{
#if 1
- return qc_lock_wait(q, 1 /*wait*/);
+ return qc_lock_wait (q, 1 /*wait */ );
#else
- return qc_lock_wait(q, 0 /*don't wait*/);
+ return qc_lock_wait (q, 0 /*don't wait */ );
#endif
}
/* Unlock port */
-int qc_unlock(struct qcam *q)
+int
+qc_unlock (struct qcam *q)
{
static struct flock sfl;
+
#if 1
- if (-1 == q->fd)
- { /* port was not locked */
- return 1;
+ if (-1 == q->fd) { /* port was not locked */
+ return 1;
}
/* clear the exclusive lock */
sfl.l_type = F_UNLCK;
- if (0 != fcntl(q->fd, F_SETLK, &sfl))
- {
- perror("fcntl");
- return 1;
+ if (0 != fcntl (q->fd, F_SETLK, &sfl)) {
+ perror ("fcntl");
+ return 1;
}
-
#ifdef TESTING
- fprintf(stderr, "%s - %d: fd %d unlocked\n", __FILE__, __LINE__, q->fd);
+ fprintf (stderr, "%s - %d: fd %d unlocked\n", __FILE__, __LINE__, q->fd);
#endif
#else
char lockfile[128];
- sprintf(lockfile,"/var/run/LOCK.qcam.0x%x",q->port);
- unlink(lockfile); /* What would I do with an error? */
+ sprintf (lockfile, "/var/run/LOCK.qcam.0x%x", q->port);
+ unlink (lockfile); /* What would I do with an error? */
#endif
return 0;
@@ -205,28 +230,28 @@ int qc_unlock(struct qcam *q)
/* Probe for camera. Returns 0 if found, 1 if not found, sets
q->port.*/
-int qc_probe(struct qcam *q)
+int
+qc_probe (struct qcam *q)
{
- int ioports[]={0x378, 0x278, 0x3bc,0};
- int i=0;
+ int ioports[] = { 0x378, 0x278, 0x3bc, 0 };
+ int i = 0;
/* Attempt to get permission to access IO ports. Must be root */
- while(ioports[i]!=0) {
- q->port=ioports[i++];
+ while (ioports[i] != 0) {
+ q->port = ioports[i++];
- if (qc_open(q)) {
- perror("Can't get I/O permission");
- exit(1);
+ if (qc_open (q)) {
+ perror ("Can't get I/O permission");
+ exit (1);
}
- if(qc_detect(q)) {
- fprintf(stderr,"QuickCam detected at 0x%x\n",q->port);
- qc_close(q);
- return(0);
- }
- else
- qc_close(q);
+ if (qc_detect (q)) {
+ fprintf (stderr, "QuickCam detected at 0x%x\n", q->port);
+ qc_close (q);
+ return (0);
+ } else
+ qc_close (q);
}
return 1;
@@ -240,10 +265,11 @@ usleep(0)'s, and that's too slow -- qc_start was taking over a second
to run. This seems to help, but if anyone has a good
speed-independent pause routine, please tell me. -- Scott */
-void qc_wait(int val)
+void
+qc_wait (int val)
{
int i;
-
- while(val--)
- for(i=0;i<50000;i++);
+
+ while (val--)
+ for (i = 0; i < 50000; i++);
}