]>
Commit | Line | Data |
---|---|---|
715f6251 | 1 | /* |
2 | * This file is part of the SPL: Solaris Porting Layer. | |
3 | * | |
4 | * Copyright (c) 2008 Lawrence Livermore National Security, LLC. | |
5 | * Produced at Lawrence Livermore National Laboratory | |
6 | * Written by: | |
7 | * Brian Behlendorf <behlendorf1@llnl.gov>, | |
8 | * Herb Wartens <wartens2@llnl.gov>, | |
9 | * Jim Garlick <garlick@llnl.gov> | |
10 | * UCRL-CODE-235197 | |
11 | * | |
12 | * This is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This is distributed in the hope that it will be useful, but WITHOUT | |
18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
20 | * for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License along | |
23 | * with this program; if not, write to the Free Software Foundation, Inc., | |
24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
25 | */ | |
26 | ||
9490c148 | 27 | #include <sys/kobj.h> |
28 | #include "config.h" | |
29 | ||
937879f1 | 30 | #ifdef DEBUG_SUBSYSTEM |
31 | #undef DEBUG_SUBSYSTEM | |
32 | #endif | |
33 | ||
34 | #define DEBUG_SUBSYSTEM S_KOBJ | |
35 | ||
9490c148 | 36 | struct _buf * |
37 | kobj_open_file(const char *name) | |
38 | { | |
39 | struct _buf *file; | |
4b171585 | 40 | vnode_t *vp; |
41 | int rc; | |
937879f1 | 42 | ENTRY; |
9490c148 | 43 | |
4b171585 | 44 | if ((rc = vn_open(name, UIO_SYSSPACE, FREAD, 0644, &vp, 0, 0))) |
937879f1 | 45 | RETURN((_buf_t *)-1UL); |
9490c148 | 46 | |
4b171585 | 47 | file = kmalloc(sizeof(_buf_t), GFP_KERNEL); |
48 | file->vp = vp; | |
9490c148 | 49 | |
937879f1 | 50 | RETURN(file); |
9490c148 | 51 | } /* kobj_open_file() */ |
52 | EXPORT_SYMBOL(kobj_open_file); | |
53 | ||
54 | void | |
55 | kobj_close_file(struct _buf *file) | |
56 | { | |
937879f1 | 57 | ENTRY; |
4b171585 | 58 | VOP_CLOSE(file->vp, 0, 0, 0, 0, 0); |
59 | VN_RELE(file->vp); | |
60 | kfree(file); | |
937879f1 | 61 | EXIT; |
9490c148 | 62 | } /* kobj_close_file() */ |
63 | EXPORT_SYMBOL(kobj_close_file); | |
64 | ||
65 | int | |
4b171585 | 66 | kobj_read_file(struct _buf *file, char *buf, ssize_t size, offset_t off) |
9490c148 | 67 | { |
937879f1 | 68 | ENTRY; |
69 | RETURN(vn_rdwr(UIO_READ, file->vp, buf, size, off, | |
70 | UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL)); | |
9490c148 | 71 | } /* kobj_read_file() */ |
72 | EXPORT_SYMBOL(kobj_read_file); | |
73 | ||
74 | int | |
75 | kobj_get_filesize(struct _buf *file, uint64_t *size) | |
76 | { | |
4b171585 | 77 | vattr_t vap; |
9490c148 | 78 | int rc; |
937879f1 | 79 | ENTRY; |
9490c148 | 80 | |
4b171585 | 81 | rc = VOP_GETATTR(file->vp, &vap, 0, 0, NULL); |
9490c148 | 82 | if (rc) |
937879f1 | 83 | RETURN(rc); |
9490c148 | 84 | |
4b171585 | 85 | *size = vap.va_size; |
86 | ||
937879f1 | 87 | RETURN(rc); |
9490c148 | 88 | } /* kobj_get_filesize() */ |
89 | EXPORT_SYMBOL(kobj_get_filesize); |