2008-03-11 23:54:40 +03:00
|
|
|
#include <sys/kobj.h>
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
struct _buf *
|
|
|
|
kobj_open_file(const char *name)
|
|
|
|
{
|
|
|
|
struct _buf *file;
|
2008-03-12 23:52:46 +03:00
|
|
|
vnode_t *vp;
|
|
|
|
int rc;
|
2008-03-11 23:54:40 +03:00
|
|
|
|
2008-03-12 23:52:46 +03:00
|
|
|
if ((rc = vn_open(name, UIO_SYSSPACE, FREAD, 0644, &vp, 0, 0)))
|
2008-03-11 23:54:40 +03:00
|
|
|
return ((_buf_t *)-1UL);
|
|
|
|
|
2008-03-12 23:52:46 +03:00
|
|
|
file = kmalloc(sizeof(_buf_t), GFP_KERNEL);
|
|
|
|
file->vp = vp;
|
2008-03-11 23:54:40 +03:00
|
|
|
|
|
|
|
return file;
|
|
|
|
} /* kobj_open_file() */
|
|
|
|
EXPORT_SYMBOL(kobj_open_file);
|
|
|
|
|
|
|
|
void
|
|
|
|
kobj_close_file(struct _buf *file)
|
|
|
|
{
|
2008-03-12 23:52:46 +03:00
|
|
|
VOP_CLOSE(file->vp, 0, 0, 0, 0, 0);
|
|
|
|
VN_RELE(file->vp);
|
|
|
|
kfree(file);
|
2008-03-11 23:54:40 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
} /* kobj_close_file() */
|
|
|
|
EXPORT_SYMBOL(kobj_close_file);
|
|
|
|
|
|
|
|
int
|
2008-03-12 23:52:46 +03:00
|
|
|
kobj_read_file(struct _buf *file, char *buf, ssize_t size, offset_t off)
|
2008-03-11 23:54:40 +03:00
|
|
|
{
|
2008-03-12 23:52:46 +03:00
|
|
|
return vn_rdwr(UIO_READ, file->vp, buf, size, off,
|
|
|
|
UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
|
2008-03-11 23:54:40 +03:00
|
|
|
} /* kobj_read_file() */
|
|
|
|
EXPORT_SYMBOL(kobj_read_file);
|
|
|
|
|
|
|
|
int
|
|
|
|
kobj_get_filesize(struct _buf *file, uint64_t *size)
|
|
|
|
{
|
2008-03-12 23:52:46 +03:00
|
|
|
vattr_t vap;
|
2008-03-11 23:54:40 +03:00
|
|
|
int rc;
|
|
|
|
|
2008-03-12 23:52:46 +03:00
|
|
|
rc = VOP_GETATTR(file->vp, &vap, 0, 0, NULL);
|
2008-03-11 23:54:40 +03:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2008-03-12 23:52:46 +03:00
|
|
|
*size = vap.va_size;
|
|
|
|
|
2008-03-11 23:54:40 +03:00
|
|
|
return rc;
|
|
|
|
} /* kobj_get_filesize() */
|
|
|
|
EXPORT_SYMBOL(kobj_get_filesize);
|