2006-01-30 21:43:32 +03:00
|
|
|
/*
|
2006-06-21 03:43:20 +04:00
|
|
|
* (C)opyright MMVI Kris Maglione <fbsdaemon at gmail dot com>
|
2006-01-30 21:43:32 +03:00
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
2006-06-24 04:26:24 +04:00
|
|
|
#include <stdarg.h>
|
2006-01-30 21:43:32 +03:00
|
|
|
#include <stdio.h>
|
2006-06-19 12:58:08 +04:00
|
|
|
#include <stdlib.h>
|
2006-01-30 21:43:32 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2006-01-31 15:25:23 +03:00
|
|
|
#include "wm.h"
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
/* Datatypes: */
|
2006-06-20 09:40:07 +04:00
|
|
|
/**************/
|
2006-06-19 12:58:08 +04:00
|
|
|
typedef struct Dirtab Dirtab;
|
|
|
|
struct Dirtab {
|
|
|
|
char *name;
|
|
|
|
unsigned char qtype;
|
|
|
|
unsigned int type;
|
|
|
|
unsigned int perm;
|
2006-06-08 12:54:19 +04:00
|
|
|
};
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-20 06:13:29 +04:00
|
|
|
typedef struct FidLink FidLink;
|
|
|
|
struct FidLink {
|
|
|
|
FidLink *next;
|
|
|
|
Fid *fid;
|
|
|
|
};
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
typedef struct FileId FileId;
|
|
|
|
struct FileId {
|
|
|
|
FileId *next;
|
|
|
|
union {
|
|
|
|
void *ref;
|
2006-06-20 06:13:29 +04:00
|
|
|
char *buf;
|
2006-06-19 12:58:08 +04:00
|
|
|
Bar *bar;
|
|
|
|
Bar **bar_p;
|
|
|
|
View *view;
|
|
|
|
Client *client;
|
2006-06-30 03:02:51 +04:00
|
|
|
Ruleset *rule;
|
2006-06-19 12:58:08 +04:00
|
|
|
BlitzColor *col;
|
|
|
|
};
|
|
|
|
unsigned int id;
|
|
|
|
unsigned int index;
|
|
|
|
Dirtab tab;
|
|
|
|
unsigned short nref;
|
|
|
|
};
|
2006-06-08 12:54:19 +04:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
/* Constants */
|
2006-06-20 09:40:07 +04:00
|
|
|
/*************/
|
2006-06-19 12:58:08 +04:00
|
|
|
enum { /* Dirs */
|
2006-06-21 22:21:15 +04:00
|
|
|
FsRoot, FsDClient, FsDClients, FsDBars,
|
2006-06-20 14:12:49 +04:00
|
|
|
FsDTag, FsDTags,
|
2006-06-19 12:58:08 +04:00
|
|
|
/* Files */
|
2006-06-21 22:36:48 +04:00
|
|
|
FsFBar, FsFCctl, FsFColRules,
|
2006-06-21 06:06:02 +04:00
|
|
|
FsFCtags, FsFEvent, FsFKeys, FsFRctl,
|
2006-06-20 14:12:49 +04:00
|
|
|
FsFTagRules, FsFTctl, FsFTindex,
|
2006-06-21 06:06:02 +04:00
|
|
|
FsFprops
|
2006-06-19 12:58:08 +04:00
|
|
|
};
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
/* Error messages */
|
|
|
|
static char
|
2006-06-20 10:45:32 +04:00
|
|
|
*Enoperm = "permission denied",
|
|
|
|
*Enofile = "file not found",
|
|
|
|
*Ebadvalue = "bad value",
|
2006-06-21 06:06:02 +04:00
|
|
|
*Einterrupted = "interrupted",
|
|
|
|
*Ebadcmd = "bad command";
|
2006-06-20 09:40:07 +04:00
|
|
|
|
|
|
|
/* Macros */
|
2006-06-19 12:58:08 +04:00
|
|
|
#define QID(t, i) (((long long)((t)&0xFF)<<32)|((i)&0xFFFFFFFF))
|
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
/* Global Vars */
|
|
|
|
/***************/
|
2006-06-19 12:58:08 +04:00
|
|
|
FileId *free_fileid = nil;
|
2006-06-23 04:47:32 +04:00
|
|
|
P9Req *pending_event_reads = nil;
|
2006-06-20 06:13:29 +04:00
|
|
|
FidLink *pending_event_fids;
|
2006-06-19 12:58:08 +04:00
|
|
|
P9Srv p9srv = {
|
|
|
|
.open= fs_open,
|
|
|
|
.walk= fs_walk,
|
|
|
|
.read= fs_read,
|
|
|
|
.stat= fs_stat,
|
|
|
|
.write= fs_write,
|
|
|
|
.clunk= fs_clunk,
|
|
|
|
.flush= fs_flush,
|
|
|
|
.attach=fs_attach,
|
|
|
|
.create=fs_create,
|
|
|
|
.remove=fs_remove,
|
|
|
|
.freefid=fs_freefid
|
|
|
|
};
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-30 04:02:52 +04:00
|
|
|
/* ad-hoc file tree. Empty names ("") indicate dynamic entries to be filled
|
2006-06-19 12:58:08 +04:00
|
|
|
* in by lookup_file */
|
|
|
|
static Dirtab
|
2006-06-23 04:47:32 +04:00
|
|
|
dirtab_root[]= {{".", P9QTDIR, FsRoot, 0500|P9DMDIR },
|
|
|
|
{"rbar", P9QTDIR, FsDBars, 0700|P9DMDIR },
|
|
|
|
{"lbar", P9QTDIR, FsDBars, 0700|P9DMDIR },
|
|
|
|
{"client", P9QTDIR, FsDClients, 0500|P9DMDIR },
|
|
|
|
{"tag", P9QTDIR, FsDTags, 0500|P9DMDIR },
|
|
|
|
{"ctl", P9QTAPPEND, FsFRctl, 0600|P9DMAPPEND },
|
|
|
|
{"colrules", P9QTFILE, FsFColRules, 0600 },
|
|
|
|
{"event", P9QTFILE, FsFEvent, 0600 },
|
|
|
|
{"keys", P9QTFILE, FsFKeys, 0600 },
|
|
|
|
{"tagrules", P9QTFILE, FsFTagRules, 0600 },
|
2006-06-19 12:58:08 +04:00
|
|
|
{nil}},
|
2006-06-23 04:47:32 +04:00
|
|
|
dirtab_clients[]={{".", P9QTDIR, FsDClients, 0500|P9DMDIR },
|
|
|
|
{"", P9QTDIR, FsDClient, 0500|P9DMDIR },
|
2006-06-19 12:58:08 +04:00
|
|
|
{nil}},
|
2006-06-23 04:47:32 +04:00
|
|
|
dirtab_client[]= {{".", P9QTDIR, FsDClient, 0500|P9DMDIR },
|
|
|
|
{"ctl", P9QTAPPEND, FsFCctl, 0600|P9DMAPPEND },
|
|
|
|
{"tags", P9QTFILE, FsFCtags, 0600 },
|
|
|
|
{"props", P9QTFILE, FsFprops, 0400 },
|
2006-06-19 12:58:08 +04:00
|
|
|
{nil}},
|
2006-06-23 04:47:32 +04:00
|
|
|
dirtab_bars[]= {{".", P9QTDIR, FsDBars, 0700|P9DMDIR },
|
|
|
|
{"", P9QTFILE, FsFBar, 0600 },
|
2006-06-19 12:58:08 +04:00
|
|
|
{nil}},
|
2006-06-23 04:47:32 +04:00
|
|
|
dirtab_tags[]= {{".", P9QTDIR, FsDTags, 0500|P9DMDIR },
|
|
|
|
{"", P9QTDIR, FsDTag, 0500|P9DMDIR },
|
2006-06-19 12:58:08 +04:00
|
|
|
{nil}},
|
2006-06-23 04:47:32 +04:00
|
|
|
dirtab_tag[]= {{".", P9QTDIR, FsDTag, 0500|P9DMDIR },
|
|
|
|
{"ctl", P9QTAPPEND, FsFTctl, 0600|P9DMAPPEND },
|
|
|
|
{"index", P9QTFILE, FsFTindex, 0400 },
|
2006-06-19 12:58:08 +04:00
|
|
|
{nil}};
|
|
|
|
/* Writing the lists separately and using an array of their references
|
|
|
|
* removes the need for casting and allows for C90 conformance,
|
|
|
|
* since otherwise we would need to use compound literals */
|
|
|
|
static Dirtab *dirtab[] = {
|
|
|
|
[FsRoot] dirtab_root,
|
2006-06-21 22:21:15 +04:00
|
|
|
[FsDBars] dirtab_bars,
|
2006-06-19 12:58:08 +04:00
|
|
|
[FsDClients] dirtab_clients,
|
|
|
|
[FsDClient] dirtab_client,
|
|
|
|
[FsDTags] dirtab_tags,
|
2006-06-20 06:40:45 +04:00
|
|
|
[FsDTag] dirtab_tag,
|
2006-06-19 12:58:08 +04:00
|
|
|
};
|
2006-02-10 17:59:30 +03:00
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
/* Utility Functions */
|
|
|
|
/*********************/
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
/* get_file/free_file save and reuse old FileId structs
|
|
|
|
* since so many of them are needed for so many
|
|
|
|
* purposes */
|
|
|
|
static FileId *
|
|
|
|
get_file() {
|
|
|
|
FileId *temp;
|
|
|
|
if(!free_fileid) {
|
|
|
|
unsigned int i = 15;
|
|
|
|
temp = cext_emallocz(sizeof(FileId) * i);
|
|
|
|
for(; i; i--) {
|
|
|
|
temp->next = free_fileid;
|
|
|
|
free_fileid = temp++;
|
2006-03-05 18:48:14 +03:00
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
temp = free_fileid;
|
|
|
|
free_fileid = temp->next;
|
|
|
|
temp->nref = 1;
|
|
|
|
temp->next = nil;
|
|
|
|
return temp;
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
static void
|
|
|
|
free_file(FileId *f) {
|
|
|
|
if(--f->nref)
|
|
|
|
return;
|
|
|
|
free(f->tab.name);
|
|
|
|
f->next = free_fileid;
|
|
|
|
free_fileid = f;
|
|
|
|
}
|
2006-05-01 21:39:26 +04:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
/* This function's name belies it's true purpose. It increases
|
2006-06-30 04:02:52 +04:00
|
|
|
* the reference counts of the FileId list */
|
2006-06-19 12:58:08 +04:00
|
|
|
static void
|
|
|
|
clone_files(FileId *f) {
|
|
|
|
for(; f; f=f->next)
|
|
|
|
cext_assert(f->nref++);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
/* This should be moved to libixp */
|
|
|
|
static void
|
2006-06-23 04:47:32 +04:00
|
|
|
write_buf(P9Req *r, void *buf, unsigned int len) {
|
2006-06-20 09:40:07 +04:00
|
|
|
if(r->ifcall.offset >= len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
len -= r->ifcall.offset;
|
|
|
|
if(len > r->ifcall.count)
|
|
|
|
len = r->ifcall.count;
|
|
|
|
/* XXX: mallocz is not really needed here */
|
|
|
|
r->ofcall.data = cext_emallocz(len);
|
|
|
|
memcpy(r->ofcall.data, buf + r->ifcall.offset, len);
|
|
|
|
r->ofcall.count = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be moved to libixp */
|
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
write_to_buf(P9Req *r, void *buf, unsigned int *len, unsigned int max) {
|
2006-06-20 09:40:07 +04:00
|
|
|
unsigned int offset, count;
|
|
|
|
|
2006-06-23 04:47:32 +04:00
|
|
|
offset = (r->fid->omode&P9OAPPEND) ? *len : r->ifcall.offset;
|
2006-06-20 09:40:07 +04:00
|
|
|
if(offset > *len || r->ifcall.count == 0) {
|
|
|
|
r->ofcall.count = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = r->ifcall.count;
|
|
|
|
if(max && (count > max - offset))
|
|
|
|
count = max - offset;
|
|
|
|
|
|
|
|
*len = offset + count;
|
|
|
|
|
|
|
|
if(max == 0) {
|
|
|
|
*(void **)buf = realloc(*(void **)buf, *len + 1);
|
|
|
|
cext_assert(*(void **)buf);
|
|
|
|
buf = *(void **)buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buf + offset, r->ifcall.data, count);
|
|
|
|
r->ofcall.count = count;
|
2006-06-26 06:18:00 +04:00
|
|
|
((char *)buf)[offset+count] = '\0';
|
2006-06-20 09:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be moved to libixp */
|
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
data_to_cstring(P9Req *r) {
|
2006-06-20 09:40:07 +04:00
|
|
|
unsigned int i;
|
2006-06-21 22:21:15 +04:00
|
|
|
i = r->ifcall.count;
|
|
|
|
if(!i || r->ifcall.data[i - 1] != '\n')
|
|
|
|
r->ifcall.data = realloc(r->ifcall.data, ++i);
|
2006-06-20 09:40:07 +04:00
|
|
|
cext_assert(r->ifcall.data);
|
2006-06-21 22:21:15 +04:00
|
|
|
r->ifcall.data[i - 1] = '\0';
|
2006-06-20 09:40:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be moved to liblitz */
|
|
|
|
char *
|
|
|
|
parse_colors(char **buf, int *buflen, BlitzColor *col) {
|
|
|
|
unsigned int i;
|
|
|
|
if(*buflen < 23 || 3 != sscanf(*buf, "#%06x #%06x #%06x", &i,&i,&i))
|
|
|
|
return Ebadvalue;
|
|
|
|
(*buflen) -= 23;
|
|
|
|
bcopy(*buf, col->colstr, 23);
|
2006-06-22 13:03:42 +04:00
|
|
|
blitz_loadcolor(&blz, col);
|
2006-06-20 09:40:07 +04:00
|
|
|
|
|
|
|
(*buf) += 23;
|
|
|
|
if(**buf == '\n' || **buf == ' ') {
|
|
|
|
(*buf)++;
|
|
|
|
(*buflen)--;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-06-21 06:06:02 +04:00
|
|
|
char *
|
2006-06-24 03:16:31 +04:00
|
|
|
message_root(char *message)
|
2006-06-21 06:06:02 +04:00
|
|
|
{
|
|
|
|
unsigned int n;
|
|
|
|
|
2006-06-24 13:15:41 +04:00
|
|
|
if(!strchr(message, ' ')) {
|
2006-06-25 17:16:03 +04:00
|
|
|
snprintf(buffer, BUFFER_SIZE, "%s ", message);
|
|
|
|
message = buffer;
|
2006-06-24 13:15:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!strncmp(message, "quit ", 5))
|
2006-06-21 06:06:02 +04:00
|
|
|
srv.running = 0;
|
2006-06-24 13:15:41 +04:00
|
|
|
else if(!strncmp(message, "view ", 5))
|
2006-06-21 06:06:02 +04:00
|
|
|
select_view(&message[5]);
|
2006-06-24 13:15:41 +04:00
|
|
|
else if(!strncmp(message, "selcolors ", 10)) {
|
2006-06-21 06:06:02 +04:00
|
|
|
message += 10;
|
|
|
|
n = strlen(message);
|
2006-06-21 06:52:40 +04:00
|
|
|
return parse_colors(&message, &n, &def.selcolor);
|
2006-06-24 13:15:41 +04:00
|
|
|
}else if(!strncmp(message, "normcolors ", 11)) {
|
2006-06-21 06:06:02 +04:00
|
|
|
message += 11;
|
|
|
|
n = strlen(message);
|
2006-06-21 06:52:40 +04:00
|
|
|
return parse_colors(&message, &n, &def.normcolor);
|
2006-06-24 13:15:41 +04:00
|
|
|
}else if(!strncmp(message, "font ", 5)) {
|
2006-06-21 06:06:02 +04:00
|
|
|
message += 5;
|
|
|
|
free(def.font.fontstr);
|
|
|
|
def.font.fontstr = strdup(message);
|
2006-06-22 13:03:42 +04:00
|
|
|
blitz_loadfont(&blz, &def.font);
|
2006-06-24 13:15:41 +04:00
|
|
|
}else if(!strncmp(message, "border ", 7)) {
|
|
|
|
message += 7;
|
|
|
|
n = (unsigned int)strtol(message, &message, 10);
|
|
|
|
if(*message)
|
|
|
|
return Ebadvalue;
|
|
|
|
def.border = n;
|
|
|
|
}else if(!strncmp(message, "grabmod ", 8)) {
|
2006-06-21 06:06:02 +04:00
|
|
|
message += 8;
|
|
|
|
unsigned long mod;
|
|
|
|
mod = mod_key_of_str(message);
|
2006-06-21 06:52:40 +04:00
|
|
|
if(!(mod & (Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)))
|
2006-06-21 06:06:02 +04:00
|
|
|
return Ebadvalue;
|
|
|
|
cext_strlcpy(def.grabmod, message, sizeof(def.grabmod));
|
|
|
|
def.mod = mod;
|
|
|
|
if(view)
|
2006-06-30 04:02:52 +04:00
|
|
|
restack_view(screen->sel);
|
2006-06-24 13:15:41 +04:00
|
|
|
}else
|
|
|
|
return Ebadcmd;
|
|
|
|
|
|
|
|
return nil;
|
2006-06-21 06:06:02 +04:00
|
|
|
}
|
|
|
|
|
2006-06-21 06:27:19 +04:00
|
|
|
char *
|
|
|
|
read_root_ctl()
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
2006-06-30 04:02:52 +04:00
|
|
|
if(screen->sel)
|
|
|
|
i += snprintf(&buffer[i], (BUFFER_SIZE - i), "view %s\n", screen->sel->name);
|
2006-06-25 17:16:03 +04:00
|
|
|
i += snprintf(&buffer[i], (BUFFER_SIZE - i), "selcolors %s\n", def.selcolor.colstr);
|
|
|
|
i += snprintf(&buffer[i], (BUFFER_SIZE - i), "normcolors %s\n", def.normcolor.colstr);
|
|
|
|
i += snprintf(&buffer[i], (BUFFER_SIZE - i), "font %s\n", def.font.fontstr);
|
|
|
|
i += snprintf(&buffer[i], (BUFFER_SIZE - i), "grabmod %s\n", def.grabmod);
|
|
|
|
i += snprintf(&buffer[i], (BUFFER_SIZE - i), "border %d\n", def.border);
|
|
|
|
return buffer;
|
2006-06-21 06:27:19 +04:00
|
|
|
}
|
|
|
|
|
2006-06-21 06:06:02 +04:00
|
|
|
|
2006-06-20 10:45:32 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
respond_event(P9Req *r) {
|
2006-06-20 10:45:32 +04:00
|
|
|
FileId *f = r->fid->aux;
|
|
|
|
if(f->buf) {
|
2006-06-20 16:32:19 +04:00
|
|
|
r->ofcall.data = (void *)f->buf;
|
2006-06-20 10:45:32 +04:00
|
|
|
r->ofcall.count = strlen(f->buf);
|
|
|
|
respond(r, nil);
|
|
|
|
f->buf = nil;
|
|
|
|
}else{
|
|
|
|
r->aux = pending_event_reads;
|
|
|
|
pending_event_reads = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
void
|
2006-06-24 04:26:24 +04:00
|
|
|
write_event(char *format, ...) {
|
2006-06-20 09:40:07 +04:00
|
|
|
unsigned int len, slen;
|
2006-06-24 04:26:24 +04:00
|
|
|
va_list ap;
|
2006-06-20 09:40:07 +04:00
|
|
|
FidLink *f;
|
|
|
|
FileId *fi;
|
2006-06-23 04:47:32 +04:00
|
|
|
P9Req *aux;
|
2006-06-20 09:40:07 +04:00
|
|
|
|
2006-06-24 04:26:24 +04:00
|
|
|
va_start(ap, format);
|
2006-06-25 17:16:03 +04:00
|
|
|
vsnprintf(buffer, BUFFER_SIZE, format, ap);
|
2006-06-24 13:15:41 +04:00
|
|
|
va_end(ap);
|
2006-06-24 04:26:24 +04:00
|
|
|
|
2006-06-25 17:16:03 +04:00
|
|
|
if(!(len = strlen(buffer)))
|
2006-06-24 13:15:41 +04:00
|
|
|
return;
|
2006-06-20 09:40:07 +04:00
|
|
|
for(f=pending_event_fids; f; f=f->next) {
|
|
|
|
fi = f->fid->aux;
|
|
|
|
slen = fi->buf ? strlen(fi->buf) : 0;
|
|
|
|
fi->buf = realloc(fi->buf, slen + len + 1);
|
2006-06-24 13:15:41 +04:00
|
|
|
fi->buf[slen] = '\0';
|
2006-06-25 17:16:03 +04:00
|
|
|
strcat(fi->buf, buffer);
|
2006-06-20 09:40:07 +04:00
|
|
|
}
|
|
|
|
while((aux = pending_event_reads)) {
|
|
|
|
pending_event_reads = pending_event_reads->aux;
|
|
|
|
respond_event(aux);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dostat(Stat *s, unsigned int len, FileId *f) {
|
|
|
|
s->type = 0;
|
|
|
|
s->dev = 0;
|
|
|
|
s->qid.path = QID(f->tab.type, f->id);
|
|
|
|
s->qid.version = 0;
|
|
|
|
s->qid.type = f->tab.qtype;
|
|
|
|
s->mode = f->tab.perm;
|
|
|
|
s->atime = time(nil);
|
|
|
|
s->mtime = time(nil);
|
|
|
|
s->length = len;
|
|
|
|
s->name = f->tab.name;
|
2006-06-22 11:28:39 +04:00
|
|
|
s->uid = user;
|
|
|
|
s->gid = user;
|
|
|
|
s->muid = user;
|
2006-06-20 09:40:07 +04:00
|
|
|
}
|
|
|
|
|
2006-06-20 10:45:32 +04:00
|
|
|
/* lookup_file */
|
|
|
|
/***************/
|
2006-06-19 12:58:08 +04:00
|
|
|
/* All lookups and directory organization should be performed through
|
|
|
|
* lookup_file, mostly through the dirtabs[] tree. */
|
|
|
|
static FileId *
|
|
|
|
lookup_file(FileId *parent, char *name)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-06-19 12:58:08 +04:00
|
|
|
FileId *ret, *file, **last;
|
|
|
|
Dirtab *dir;
|
2006-06-08 12:54:19 +04:00
|
|
|
Client *c;
|
2006-06-19 12:58:08 +04:00
|
|
|
View *v;
|
|
|
|
Bar *b;
|
|
|
|
unsigned int i, id;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-23 04:47:32 +04:00
|
|
|
if(!(parent->tab.perm & P9DMDIR))
|
2006-06-19 12:58:08 +04:00
|
|
|
return nil;
|
2006-02-10 17:59:30 +03:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
dir = dirtab[parent->tab.type];
|
|
|
|
last = &ret;
|
|
|
|
ret = nil;
|
|
|
|
|
|
|
|
for(; dir->name; dir++) {
|
|
|
|
/* Dynamic dirs */
|
|
|
|
if(!*dir->name) { /* strlen(dir->name) == 0 */
|
|
|
|
switch(parent->tab.type) {
|
|
|
|
case FsDClients:
|
|
|
|
if(!name || !strncmp(name, "sel", 4)) {
|
|
|
|
if((c = sel_client())) {
|
|
|
|
file = get_file();
|
|
|
|
*last = file;
|
|
|
|
last = &file->next;
|
|
|
|
file->ref = c;
|
|
|
|
file->id = c->id;
|
|
|
|
file->index = idx_of_client(c);
|
2006-06-20 14:12:49 +04:00
|
|
|
file->tab = *dir;
|
2006-06-19 12:58:08 +04:00
|
|
|
file->tab.name = strdup("sel");
|
|
|
|
}if(name) goto LastItem;
|
|
|
|
}
|
|
|
|
if(name) {
|
|
|
|
id = (unsigned int)strtol(name, &name, 10);
|
|
|
|
if(*name) goto NextItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
for(c=client; c; c=c->next, i++) {
|
|
|
|
if(!name || i == id) {
|
|
|
|
file = get_file();
|
|
|
|
*last = file;
|
|
|
|
last = &file->next;
|
|
|
|
file->ref = c;
|
|
|
|
file->id = c->id;
|
|
|
|
file->tab = *dir;
|
2006-06-21 22:36:48 +04:00
|
|
|
file->tab.name = cext_emallocz(16);
|
|
|
|
snprintf(file->tab.name, 16, "%d", i);
|
2006-06-19 12:58:08 +04:00
|
|
|
if(name) goto LastItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FsDTags:
|
|
|
|
if(!name || !strncmp(name, "sel", 4)) {
|
2006-06-30 04:02:52 +04:00
|
|
|
if(screen->sel) {
|
2006-06-19 12:58:08 +04:00
|
|
|
file = get_file();
|
|
|
|
*last = file;
|
|
|
|
last = &file->next;
|
2006-06-30 04:02:52 +04:00
|
|
|
file->ref = screen->sel;
|
|
|
|
file->id = screen->sel->id;
|
2006-06-19 12:58:08 +04:00
|
|
|
file->tab = *dir;
|
|
|
|
file->tab.name = strdup("sel");
|
|
|
|
}if(name) goto LastItem;
|
|
|
|
}
|
|
|
|
for(v=view; v; v=v->next) {
|
|
|
|
if(!name || !strcmp(name, v->name)) {
|
|
|
|
file = get_file();
|
|
|
|
*last = file;
|
|
|
|
last = &file->next;
|
|
|
|
file->ref = v;
|
|
|
|
file->id = v->id;
|
|
|
|
file->tab = *dir;
|
|
|
|
file->tab.name = strdup(v->name);
|
|
|
|
if(name) goto LastItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-06-21 22:21:15 +04:00
|
|
|
case FsDBars:
|
2006-06-19 12:58:08 +04:00
|
|
|
for(b=*parent->bar_p; b; b=b->next) {
|
|
|
|
if(!name || !strcmp(name, b->name)) {
|
|
|
|
file = get_file();
|
|
|
|
*last = file;
|
|
|
|
last = &file->next;
|
|
|
|
file->ref = b;
|
|
|
|
file->id = b->id;
|
|
|
|
file->tab = *dir;
|
|
|
|
file->tab.name = strdup(b->name);
|
|
|
|
if(name) goto LastItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
}else /* Static dirs */
|
|
|
|
if(!name || !strcmp(name, dir->name)) {
|
|
|
|
file = get_file();
|
|
|
|
*last = file;
|
|
|
|
last = &file->next;
|
|
|
|
file->id = 0;
|
|
|
|
file->ref = parent->ref;
|
|
|
|
file->index = parent->index;
|
|
|
|
file->tab = *dir;
|
|
|
|
file->tab.name = strdup(file->tab.name);
|
|
|
|
|
|
|
|
/* Special considerations: */
|
|
|
|
switch(file->tab.type) {
|
2006-06-21 22:21:15 +04:00
|
|
|
case FsDBars:
|
2006-06-19 12:58:08 +04:00
|
|
|
if(!strncmp(file->tab.name, "lbar", 5))
|
2006-06-30 04:02:52 +04:00
|
|
|
file->ref = &screen[0].lbar;
|
2006-06-19 12:58:08 +04:00
|
|
|
else
|
2006-06-30 04:02:52 +04:00
|
|
|
file->ref = &screen[0].rbar;
|
2006-06-19 12:58:08 +04:00
|
|
|
break;
|
|
|
|
case FsFColRules:
|
|
|
|
file->ref = &def.colrules;
|
|
|
|
break;
|
|
|
|
case FsFTagRules:
|
|
|
|
file->ref = &def.tagrules;
|
|
|
|
break;
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
if(name) goto LastItem;
|
2006-01-31 19:52:14 +03:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
NextItem:
|
|
|
|
continue;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
LastItem:
|
|
|
|
*last = nil;
|
|
|
|
return ret;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
/* Service Functions */
|
|
|
|
/*********************/
|
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_attach(P9Req *r) {
|
2006-06-20 09:40:07 +04:00
|
|
|
FileId *f = get_file();
|
|
|
|
f->tab = dirtab[FsRoot][0];
|
|
|
|
f->tab.name = strdup("/");
|
|
|
|
f->ref = nil; /* shut up valgrind */
|
|
|
|
r->fid->aux = f;
|
|
|
|
r->fid->qid.type = f->tab.qtype;
|
|
|
|
r->fid->qid.path = QID(f->tab.type, 0);
|
|
|
|
r->ofcall.qid = r->fid->qid;
|
|
|
|
respond(r, nil);
|
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_walk(P9Req *r) {
|
2006-06-19 12:58:08 +04:00
|
|
|
FileId *f, *nf;
|
|
|
|
int i;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
f = r->fid->aux;
|
2006-02-03 22:02:37 +03:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
clone_files(f);
|
|
|
|
for(i=0; i < r->ifcall.nwname; i++) {
|
|
|
|
if(!strncmp(r->ifcall.wname[i], "..", 3)) {
|
|
|
|
if(f->next) {
|
|
|
|
nf=f;
|
|
|
|
f=f->next;
|
|
|
|
free_file(nf);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
nf = lookup_file(f, r->ifcall.wname[i]);
|
|
|
|
if(!nf)
|
|
|
|
break;
|
|
|
|
cext_assert(!nf->next);
|
2006-06-23 04:21:24 +04:00
|
|
|
if(strncmp(r->ifcall.wname[i], ".", 2)) {
|
|
|
|
nf->next = f;
|
|
|
|
f = nf;
|
|
|
|
}
|
2006-03-07 19:22:36 +03:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
r->ofcall.wqid[i].type = f->tab.qtype;
|
|
|
|
r->ofcall.wqid[i].path = QID(f->tab.type, f->id);
|
|
|
|
}
|
|
|
|
/* There should be a way to do this on freefid() */
|
|
|
|
if(i < r->ifcall.nwname) {
|
|
|
|
while((nf = f)) {
|
|
|
|
f=f->next;
|
|
|
|
free_file(nf);
|
2006-04-13 19:41:58 +04:00
|
|
|
}
|
2006-06-19 12:58:08 +04:00
|
|
|
return respond(r, Enofile);
|
2006-03-23 18:07:18 +03:00
|
|
|
}
|
2006-06-08 12:54:19 +04:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
/* Remove refs for r->fid if no new fid */
|
|
|
|
/* If Fids were ref counted, this could be
|
|
|
|
* done in their decref function */
|
|
|
|
if(r->ifcall.fid == r->ifcall.newfid) {
|
|
|
|
nf=r->fid->aux;
|
|
|
|
r->fid->aux = f;
|
|
|
|
while((nf = f)) {
|
|
|
|
f=f->next;
|
|
|
|
free_file(nf);
|
|
|
|
}
|
2006-06-08 12:54:19 +04:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
r->newfid->aux = f;
|
|
|
|
r->ofcall.nwqid = i;
|
|
|
|
respond(r, nil);
|
2006-06-08 12:54:19 +04:00
|
|
|
}
|
|
|
|
|
2006-06-24 01:38:29 +04:00
|
|
|
unsigned int
|
|
|
|
fs_size(FileId *f) {
|
|
|
|
switch(f->tab.type) {
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case FsFColRules:
|
|
|
|
case FsFTagRules:
|
|
|
|
return f->rule->size;
|
|
|
|
case FsFKeys:
|
|
|
|
return def.keyssz;
|
|
|
|
case FsFCtags:
|
|
|
|
return strlen(f->client->tags);
|
|
|
|
case FsFprops:
|
|
|
|
return strlen(f->client->props);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_stat(P9Req *r) {
|
2006-06-19 12:58:08 +04:00
|
|
|
Stat s;
|
|
|
|
int size;
|
|
|
|
unsigned char *buf;
|
|
|
|
|
2006-06-24 01:38:29 +04:00
|
|
|
dostat(&s, fs_size(r->fid->aux), r->fid->aux);
|
2006-06-19 12:58:08 +04:00
|
|
|
r->ofcall.nstat = size = ixp_sizeof_stat(&s);
|
|
|
|
buf = cext_emallocz(size);
|
|
|
|
r->ofcall.stat = buf;
|
|
|
|
|
|
|
|
ixp_pack_stat(&buf, &size, &s);
|
|
|
|
respond(r, nil);
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_read(P9Req *r) {
|
2006-06-21 22:36:48 +04:00
|
|
|
char *buf;
|
2006-06-19 12:58:08 +04:00
|
|
|
FileId *f, *tf;
|
|
|
|
int n, offset;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
f = r->fid->aux;
|
|
|
|
|
2006-06-23 04:47:32 +04:00
|
|
|
if(f->tab.perm & P9DMDIR && f->tab.perm & 0400) {
|
2006-06-19 12:58:08 +04:00
|
|
|
Stat s;
|
|
|
|
offset = 0;
|
|
|
|
size = r->ifcall.count;
|
|
|
|
buf = cext_emallocz(size);
|
|
|
|
r->ofcall.data = buf;
|
|
|
|
|
|
|
|
tf = f = lookup_file(f, nil);
|
2006-06-24 05:22:04 +04:00
|
|
|
/* Note: f->tab.name == "." so we skip it */
|
2006-06-19 12:58:08 +04:00
|
|
|
for(f=f->next; f; f=f->next) {
|
2006-06-24 01:38:29 +04:00
|
|
|
dostat(&s, fs_size(f), f);
|
2006-06-19 12:58:08 +04:00
|
|
|
n = ixp_sizeof_stat(&s);
|
|
|
|
if(offset >= r->ifcall.offset) {
|
|
|
|
if(size < n)
|
|
|
|
break;
|
2006-06-21 22:36:48 +04:00
|
|
|
ixp_pack_stat((unsigned char **)&buf, &size, &s);
|
2006-06-19 12:58:08 +04:00
|
|
|
}
|
|
|
|
offset += n;
|
2006-05-17 12:36:56 +04:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
while((f = tf)) {
|
|
|
|
tf=tf->next;
|
|
|
|
free_file(f);
|
|
|
|
}
|
2006-05-17 12:36:56 +04:00
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
r->ofcall.count = r->ifcall.count - size;
|
2006-06-22 10:36:13 +04:00
|
|
|
return respond(r, nil);
|
2006-06-19 12:58:08 +04:00
|
|
|
}else{
|
|
|
|
switch(f->tab.type) {
|
|
|
|
case FsFprops:
|
|
|
|
write_buf(r, (void *)f->client->props, strlen(f->client->props));
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFColRules:
|
|
|
|
case FsFTagRules:
|
|
|
|
write_buf(r, (void *)f->rule->string, f->rule->size);
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFKeys:
|
|
|
|
write_buf(r, (void *)def.keys, def.keyssz);
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFCtags:
|
|
|
|
write_buf(r, (void *)f->client->tags, strlen(f->client->tags));
|
|
|
|
return respond(r, nil);
|
2006-06-20 14:12:49 +04:00
|
|
|
case FsFTctl:
|
2006-06-20 06:40:45 +04:00
|
|
|
write_buf(r, (void *)f->view->name, strlen(f->view->name));
|
|
|
|
return respond(r, nil);
|
2006-06-20 08:35:50 +04:00
|
|
|
case FsFBar:
|
|
|
|
write_buf(r, (void *)f->bar->buf, strlen(f->bar->buf));
|
|
|
|
return respond(r, nil);
|
2006-06-21 06:27:19 +04:00
|
|
|
case FsFRctl:
|
|
|
|
buf = read_root_ctl();
|
|
|
|
write_buf(r, buf, strlen(buf));
|
|
|
|
return respond(r, nil);
|
2006-06-20 14:12:49 +04:00
|
|
|
case FsFCctl:
|
2006-06-19 12:58:08 +04:00
|
|
|
if(r->ifcall.offset)
|
|
|
|
return respond(r, nil);
|
2006-06-21 22:36:48 +04:00
|
|
|
r->ofcall.data = cext_emallocz(16);
|
|
|
|
n = snprintf(r->ofcall.data, 16, "%d", f->index);
|
2006-06-19 12:58:08 +04:00
|
|
|
cext_assert(n >= 0);
|
|
|
|
r->ofcall.count = n;
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFTindex:
|
|
|
|
buf = view_index(f->view);
|
2006-06-21 22:36:48 +04:00
|
|
|
n = strlen(buf);
|
2006-06-19 12:58:08 +04:00
|
|
|
write_buf(r, (void *)buf, n);
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFEvent:
|
2006-06-20 06:13:29 +04:00
|
|
|
respond_event(r);
|
2006-06-19 12:58:08 +04:00
|
|
|
return;
|
2006-03-23 18:07:18 +03:00
|
|
|
}
|
|
|
|
}
|
2006-06-24 05:22:04 +04:00
|
|
|
/* This is an assert because it should this should not be called if
|
|
|
|
* the file is not open for reading. */
|
2006-06-22 10:36:13 +04:00
|
|
|
cext_assert(!"Read called on an unreadable file");
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
/* This function needs to be seriously cleaned up */
|
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_write(P9Req *r) {
|
2006-06-19 12:58:08 +04:00
|
|
|
FileId *f;
|
2006-06-24 05:22:04 +04:00
|
|
|
char *errstr = nil;
|
2006-06-19 12:58:08 +04:00
|
|
|
unsigned int i;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-06-22 10:36:13 +04:00
|
|
|
if(r->ifcall.count == 0)
|
|
|
|
return respond(r, nil);
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
f = r->fid->aux;
|
|
|
|
switch(f->tab.type) {
|
|
|
|
case FsFColRules:
|
|
|
|
case FsFTagRules:
|
|
|
|
write_to_buf(r, &f->rule->string, &f->rule->size, 0);
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFKeys:
|
|
|
|
write_to_buf(r, &def.keys, &def.keyssz, 0);
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFCtags:
|
|
|
|
data_to_cstring(r);
|
|
|
|
i=strlen(f->client->tags);
|
|
|
|
write_to_buf(r, &f->client->tags, &i, 255);
|
|
|
|
r->ofcall.count = i- r->ifcall.offset;
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFBar:
|
|
|
|
/* XXX: This should validate after each write */
|
|
|
|
i = strlen(f->bar->buf);
|
|
|
|
write_to_buf(r, &f->bar->buf, &i, 279);
|
2006-06-27 06:21:09 +04:00
|
|
|
r->ofcall.count = i - r->ifcall.offset;
|
2006-06-19 12:58:08 +04:00
|
|
|
return respond(r, nil);
|
2006-06-19 18:05:02 +04:00
|
|
|
case FsFCctl:
|
|
|
|
data_to_cstring(r);
|
2006-06-21 22:36:48 +04:00
|
|
|
if((errstr = message_client(f->client, r->ifcall.data)))
|
2006-06-19 18:05:02 +04:00
|
|
|
return respond(r, errstr);
|
|
|
|
r->ofcall.count = r->ifcall.count;
|
|
|
|
return respond(r, nil);
|
2006-06-19 12:58:08 +04:00
|
|
|
case FsFTctl:
|
|
|
|
data_to_cstring(r);
|
2006-06-21 22:36:48 +04:00
|
|
|
if((errstr = message_view(f->view, r->ifcall.data)))
|
2006-06-19 12:58:08 +04:00
|
|
|
return respond(r, errstr);
|
|
|
|
r->ofcall.count = r->ifcall.count;
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFRctl:
|
|
|
|
data_to_cstring(r);
|
2006-06-24 13:15:41 +04:00
|
|
|
{ unsigned int n;
|
2006-06-21 06:06:02 +04:00
|
|
|
char *toks[32];
|
|
|
|
n = cext_tokenize(toks, 32, r->ifcall.data, '\n');
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
if(errstr)
|
|
|
|
message_root(toks[i]);
|
|
|
|
else
|
|
|
|
errstr = message_root(toks[i]);
|
|
|
|
}
|
|
|
|
}
|
2006-06-24 13:15:41 +04:00
|
|
|
if(errstr)
|
|
|
|
return respond(r, errstr);
|
2006-06-19 12:58:08 +04:00
|
|
|
r->ofcall.count = r->ifcall.count;
|
|
|
|
return respond(r, nil);
|
|
|
|
case FsFEvent:
|
2006-06-24 13:15:41 +04:00
|
|
|
if(r->ifcall.data[r->ifcall.count-1] == '\n')
|
|
|
|
write_event("%.*s", r->ifcall.count, r->ifcall.data);
|
|
|
|
else
|
|
|
|
write_event("%.*s\n", r->ifcall.count, r->ifcall.data);
|
2006-06-19 12:58:08 +04:00
|
|
|
r->ofcall.count = r->ifcall.count;
|
|
|
|
return respond(r, nil);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
2006-06-24 05:22:04 +04:00
|
|
|
/* This is an assert because it should this should not be called if
|
|
|
|
* the file is not open for writing. */
|
2006-06-22 10:36:13 +04:00
|
|
|
cext_assert(!"Write called on an unwritable file");
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_open(P9Req *r) {
|
2006-06-20 09:40:07 +04:00
|
|
|
FidLink *fl;
|
|
|
|
FileId *f = r->fid->aux;
|
|
|
|
switch(f->tab.type) {
|
|
|
|
case FsFEvent:
|
|
|
|
fl = cext_emallocz(sizeof(FidLink));
|
|
|
|
fl->fid = r->fid;
|
|
|
|
fl->next = pending_event_fids;
|
|
|
|
pending_event_fids = fl;
|
|
|
|
break;
|
|
|
|
}
|
2006-06-23 04:47:32 +04:00
|
|
|
if((r->ifcall.mode&3) == P9OEXEC)
|
2006-06-22 10:36:13 +04:00
|
|
|
return respond(r, Enoperm);
|
2006-06-23 04:47:32 +04:00
|
|
|
if((r->ifcall.mode&3) != P9OREAD && !(f->tab.perm & 0200))
|
2006-06-22 10:36:13 +04:00
|
|
|
return respond(r, Enoperm);
|
2006-06-23 04:47:32 +04:00
|
|
|
if((r->ifcall.mode&3) != P9OWRITE && !(f->tab.perm & 0400))
|
2006-06-22 10:36:13 +04:00
|
|
|
return respond(r, Enoperm);
|
2006-06-27 02:37:33 +04:00
|
|
|
if((r->ifcall.mode&~(3|P9OAPPEND|P9OTRUNC)))
|
2006-06-22 10:36:13 +04:00
|
|
|
return respond(r, Enoperm);
|
2006-06-27 06:21:09 +04:00
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
respond(r, nil);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_create(P9Req *r) {
|
2006-06-20 09:40:07 +04:00
|
|
|
FileId *f = r->fid->aux;
|
|
|
|
switch(f->tab.type) {
|
|
|
|
default:
|
|
|
|
/* XXX: This should be taken care of by the library */
|
|
|
|
return respond(r, Enoperm);
|
2006-06-21 22:21:15 +04:00
|
|
|
case FsDBars:
|
2006-06-20 09:40:07 +04:00
|
|
|
if(!strlen(r->ifcall.name))
|
|
|
|
return respond(r, Ebadvalue);
|
|
|
|
create_bar(f->bar_p, r->ifcall.name);
|
|
|
|
f = lookup_file(f, r->ifcall.name);
|
|
|
|
if(!f)
|
|
|
|
return respond(r, Enofile);
|
2006-06-27 13:58:40 +04:00
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
r->ofcall.qid.type = f->tab.qtype;
|
|
|
|
r->ofcall.qid.path = QID(f->tab.type, f->id);
|
2006-06-22 10:52:45 +04:00
|
|
|
f->next = r->fid->aux;
|
|
|
|
r->fid->aux = f;
|
2006-06-20 09:40:07 +04:00
|
|
|
respond(r, nil);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_remove(P9Req *r) {
|
2006-06-20 09:40:07 +04:00
|
|
|
FileId *f = r->fid->aux;
|
|
|
|
switch(f->tab.type) {
|
|
|
|
default:
|
|
|
|
/* XXX: This should be taken care of by the library */
|
|
|
|
return respond(r, Enoperm);
|
|
|
|
case FsFBar:
|
|
|
|
destroy_bar(f->next->bar_p, f->bar);
|
2006-06-30 04:02:52 +04:00
|
|
|
draw_bar(screen);
|
2006-06-20 09:40:07 +04:00
|
|
|
respond(r, nil);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 02:25:49 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_clunk(P9Req *r) {
|
2006-06-20 02:25:49 +04:00
|
|
|
Client *c;
|
2006-06-20 07:58:20 +04:00
|
|
|
FidLink **fl, *ft;
|
2006-06-20 02:25:49 +04:00
|
|
|
char *buf;
|
|
|
|
int i;
|
|
|
|
FileId *f = r->fid->aux;
|
|
|
|
|
|
|
|
switch(f->tab.type) {
|
2006-06-20 13:34:11 +04:00
|
|
|
case FsFColRules:
|
|
|
|
update_rules(&f->rule->rule, f->rule->string);
|
|
|
|
break;
|
2006-06-20 02:25:49 +04:00
|
|
|
case FsFTagRules:
|
|
|
|
update_rules(&f->rule->rule, f->rule->string);
|
|
|
|
for(c=client; c; c=c->next)
|
|
|
|
apply_rules(c);
|
|
|
|
update_views();
|
|
|
|
break;
|
|
|
|
case FsFKeys:
|
|
|
|
update_keys();
|
|
|
|
break;
|
|
|
|
case FsFCtags:
|
|
|
|
apply_tags(f->client, f->client->tags);
|
|
|
|
update_views();
|
|
|
|
draw_frame(f->client->sel);
|
|
|
|
break;
|
|
|
|
case FsFBar:
|
|
|
|
buf = f->bar->buf;
|
|
|
|
i = strlen(f->bar->buf);
|
2006-06-22 13:03:42 +04:00
|
|
|
parse_colors(&buf, &i, &f->bar->brush.color);
|
2006-06-26 06:18:00 +04:00
|
|
|
while(i > 0 && buf[i - 1] == '\n')
|
2006-06-20 02:25:49 +04:00
|
|
|
buf[--i] = '\0';
|
2006-06-22 13:46:39 +04:00
|
|
|
cext_strlcpy(f->bar->text, buf, sizeof(f->bar->text));
|
2006-06-30 04:02:52 +04:00
|
|
|
draw_bar(screen);
|
2006-06-20 02:25:49 +04:00
|
|
|
break;
|
2006-06-20 06:13:29 +04:00
|
|
|
case FsFEvent:
|
|
|
|
for(fl=&pending_event_fids; *fl; fl=&(*fl)->next)
|
|
|
|
if((*fl)->fid == r->fid) {
|
2006-06-20 07:58:20 +04:00
|
|
|
ft = *fl;
|
2006-06-20 06:13:29 +04:00
|
|
|
*fl = (*fl)->next;
|
2006-06-20 07:58:20 +04:00
|
|
|
f = ft->fid->aux;
|
|
|
|
free(f->buf);
|
|
|
|
free(ft);
|
2006-06-20 06:13:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-06-20 02:25:49 +04:00
|
|
|
}
|
|
|
|
respond(r, nil);
|
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
void
|
2006-06-23 04:47:32 +04:00
|
|
|
fs_flush(P9Req *r) {
|
|
|
|
P9Req **t;
|
|
|
|
for(t=&pending_event_reads; *t; t=(P9Req **)&(*t)->aux)
|
2006-06-19 12:58:08 +04:00
|
|
|
if(*t == r->oldreq) {
|
|
|
|
*t = (*t)->aux;
|
|
|
|
respond(r->oldreq, Einterrupted);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
respond(r, nil);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-06-19 12:58:08 +04:00
|
|
|
void
|
2006-06-20 09:40:07 +04:00
|
|
|
fs_freefid(Fid *f) {
|
|
|
|
FileId *id, *tid;
|
2006-06-20 06:13:29 +04:00
|
|
|
|
2006-06-20 09:40:07 +04:00
|
|
|
for(id=f->aux; id; id = tid) {
|
|
|
|
tid = id->next;
|
|
|
|
free_file(id);
|
2006-06-19 12:58:08 +04:00
|
|
|
}
|
|
|
|
}
|