]> git.proxmox.com Git - mirror_zfs.git/blob - modules/spl/spl-kobj.c
e78cd9244fdb64811abf5f1f60f85b07fdf983ec
[mirror_zfs.git] / modules / spl / spl-kobj.c
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
27 #include <sys/kobj.h>
28
29 #ifdef DEBUG_SUBSYSTEM
30 #undef DEBUG_SUBSYSTEM
31 #endif
32
33 #define DEBUG_SUBSYSTEM S_KOBJ
34
35 struct _buf *
36 kobj_open_file(const char *name)
37 {
38 struct _buf *file;
39 vnode_t *vp;
40 int rc;
41 ENTRY;
42
43 file = kmalloc(sizeof(_buf_t), GFP_KERNEL);
44 if (file == NULL)
45 RETURN((_buf_t *)-1UL);
46
47 if ((rc = vn_open(name, UIO_SYSSPACE, FREAD, 0644, &vp, 0, 0))) {
48 kfree(file);
49 RETURN((_buf_t *)-1UL);
50 }
51
52 file->vp = vp;
53
54 RETURN(file);
55 } /* kobj_open_file() */
56 EXPORT_SYMBOL(kobj_open_file);
57
58 void
59 kobj_close_file(struct _buf *file)
60 {
61 ENTRY;
62 VOP_CLOSE(file->vp, 0, 0, 0, 0, 0);
63 VN_RELE(file->vp);
64 kfree(file);
65 EXIT;
66 } /* kobj_close_file() */
67 EXPORT_SYMBOL(kobj_close_file);
68
69 int
70 kobj_read_file(struct _buf *file, char *buf, ssize_t size, offset_t off)
71 {
72 ENTRY;
73 RETURN(vn_rdwr(UIO_READ, file->vp, buf, size, off,
74 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL));
75 } /* kobj_read_file() */
76 EXPORT_SYMBOL(kobj_read_file);
77
78 int
79 kobj_get_filesize(struct _buf *file, uint64_t *size)
80 {
81 vattr_t vap;
82 int rc;
83 ENTRY;
84
85 rc = VOP_GETATTR(file->vp, &vap, 0, 0, NULL);
86 if (rc)
87 RETURN(rc);
88
89 *size = vap.va_size;
90
91 RETURN(rc);
92 } /* kobj_get_filesize() */
93 EXPORT_SYMBOL(kobj_get_filesize);