Skip to content

Commit

Permalink
virtualfs: Remove getbuflen for text type virtual file.
Browse files Browse the repository at this point in the history
  • Loading branch information
wishstudio committed May 16, 2015
1 parent 9ed0382 commit 4d661c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
22 changes: 6 additions & 16 deletions src/fs/procfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ struct virtualfs_directory_desc sys_desc =
}
};

static int cpuinfo_getbuflen(int tag)
{
return 1024;
}

static void cpuinfo_gettext(int tag, char *buf)
static int cpuinfo_gettext(int tag, char *buf)
{
struct cpuid_t cpuid;

Expand Down Expand Up @@ -138,7 +133,7 @@ static void cpuinfo_gettext(int tag, char *buf)

char flags[256];
dbt_get_cpuinfo(flags);
ksprintf(buf,
return ksprintf(buf,
"processor\t: 0\n"
"vendor_id\t: %s\n"
"cpu family\t: %d\n"
Expand All @@ -162,19 +157,14 @@ static void cpuinfo_gettext(int tag, char *buf)
physical_address_bits, virtual_address_bits);
}

static struct virtualfs_text_desc cpuinfo_desc = VIRTUALFS_TEXT(cpuinfo_getbuflen, cpuinfo_gettext);

static int meminfo_getbuflen(int tag)
{
return 512;
}
static struct virtualfs_text_desc cpuinfo_desc = VIRTUALFS_TEXT(cpuinfo_gettext);

static void meminfo_gettext(int tag, char *buf)
static int meminfo_gettext(int tag, char *buf)
{
MEMORYSTATUSEX memory;
memory.dwLength = sizeof(memory);
GlobalMemoryStatusEx(&memory);
ksprintf(buf,
return ksprintf(buf,
"MemTotal: %13llu kB\n"
"MemFree: %13llu kB\n"
"HighTotal: %13llu kB\n"
Expand All @@ -189,7 +179,7 @@ static void meminfo_gettext(int tag, char *buf)
memory.ullTotalPageFile / 1024ULL, memory.ullAvailPageFile / 1024ULL);
}

static struct virtualfs_text_desc meminfo_desc = VIRTUALFS_TEXT(meminfo_getbuflen, meminfo_gettext);
static struct virtualfs_text_desc meminfo_desc = VIRTUALFS_TEXT(meminfo_gettext);

static const struct virtualfs_directory_desc procfs =
{
Expand Down
10 changes: 6 additions & 4 deletions src/fs/virtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,15 @@ static const struct file_ops virtualfs_text_ops =

static struct file *virtualfs_text_alloc(struct virtualfs_text_desc *desc, int tag)
{
int len = desc->getbuflen(tag);
struct virtualfs_text *file = (struct virtualfs_text *)kmalloc(sizeof(struct virtualfs_text) + len);
char buf[65536];
int len = desc->gettext(tag, buf);
struct virtualfs_text *file = (struct virtualfs_text *)kmalloc(sizeof(struct virtualfs_text) + len + 1);
file->base_file.op_vtable = &virtualfs_text_ops;
file->base_file.flags = O_RDONLY;
file->base_file.ref = 1;
desc->gettext(tag, file->text);
file->textlen = strlen(file->text);
file->textlen = len;
memcpy(file->text, buf, len);
file->text[len] = 0;
file->buflen = len;
file->position = 0;
return (struct file *)file;
Expand Down
6 changes: 2 additions & 4 deletions src/fs/virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ struct virtualfs_char_desc
struct virtualfs_text_desc
{
int type;
int (*getbuflen)(int tag);
void (*gettext)(int tag, char *buf);
int (*gettext)(int tag, char *buf);
};
#define VIRTUALFS_TEXT(_getbuflen, _gettext) \
#define VIRTUALFS_TEXT(_gettext) \
{ \
.type = VIRTUALFS_TYPE_TEXT, \
.getbuflen = _getbuflen, \
.gettext = _gettext, \
}

Expand Down

0 comments on commit 4d661c8

Please sign in to comment.