2 * Copyright (C) 2008 dhewg, #wiidev efnet
4 * Copyright (C) 2006 Mike Melanson (mike at multimedia.cx)
6 * this file is part of wiifuse
7 * http://wiibrew.org/index.php?title=Wiifuse
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
36 int fs_tree_getattr (const char *path
, struct stat
*stbuf
) {
37 struct image_file
*image
= (struct image_file
*)
38 fuse_get_context ()->private_data
;
41 node
= tree_find_entry (image
->tree
, path
);
45 memset (stbuf
, 0, sizeof (struct stat
));
49 stbuf
->st_mode
= S_IFDIR
|
50 S_IRUSR
| S_IRGRP
| S_IROTH
|
51 S_IXUSR
| S_IXGRP
| S_IXOTH
;
52 stbuf
->st_nlink
= 2 + node
->nsubdirs
;
65 stbuf
->st_mode
= S_IFREG
| S_IRUSR
| S_IRGRP
| S_IROTH
;
67 stbuf
->st_size
= node
->v2
;
68 stbuf
->st_blocks
= node
->v2
/ 512;
72 stbuf
->st_mode
= S_IFLNK
| S_IRWXU
| S_IRWXG
| S_IRWXO
;
74 stbuf
->st_size
= node
->v2
;
78 stbuf
->st_uid
= image
->st
.st_uid
;
79 stbuf
->st_gid
= image
->st
.st_gid
;
80 stbuf
->st_atime
= image
->st
.st_atime
;
81 stbuf
->st_mtime
= image
->st
.st_mtime
;
82 stbuf
->st_ctime
= image
->st
.st_ctime
;
87 int fs_tree_open (const char *path
, struct fuse_file_info
*fi
) {
88 struct image_file
*image
= (struct image_file
*)
89 fuse_get_context ()->private_data
;
92 if (fi
->flags
& O_WRONLY
)
95 node
= tree_find_entry (image
->tree
, path
);
103 int fs_tree_read (const char *path
, char *buf
, size_t size
,
104 off_t offset
, struct fuse_file_info
*fi
) {
105 struct image_file
*image
= (struct image_file
*)
106 fuse_get_context ()->private_data
;
113 node
= tree_find_entry (image
->tree
, path
);
117 if (node
->type
== TREE_DIR
)
120 if (offset
>= node
->v2
)
123 pos
= node
->v1
+ offset
;
125 if (offset
+ size
> node
->v2
)
126 size
= node
->v2
- offset
;
128 switch (node
->type
) {
130 pthread_mutex_lock (&image
->mutex
);
131 ret
= io_read (buf
, size
, image
,
132 image
->parts
[node
->part
].offset
+ pos
);
133 pthread_mutex_unlock (&image
->mutex
);
137 pthread_mutex_lock (&image
->mutex
);
138 ret
= io_read_part (buf
, size
, image
, node
->part
, pos
);
139 pthread_mutex_unlock (&image
->mutex
);
143 sprintf (buf
, "%llu\n", node
->v1
);
148 sprintf (buf
, "0x%02x\n", (u8
) node
->v1
);
152 case TREE_HEX_UINT16
:
153 sprintf (buf
, "0x%04x\n", (u16
) node
->v1
);
157 case TREE_HEX_UINT32
:
158 sprintf (buf
, "0x%08x\n", (u32
) node
->v1
);
162 case TREE_HEX_UINT64
:
163 sprintf (buf
, "0x%016llx\n", node
->v1
);
168 memcpy (buf
, pos
, size
);
173 buf
[0] = (char) node
->v1
;
179 memcpy (buf
, pos
, size
);
180 buf
[size
- 1] = '\n';
196 int fs_tree_readlink (const char *path
, char *buf
, size_t size
) {
197 struct image_file
*image
= (struct image_file
*)
198 fuse_get_context ()->private_data
;
201 node
= tree_find_entry (image
->tree
, path
);
205 if (node
->type
!= TREE_SYMLINK
)
208 strncpy (buf
, node
->v1
, size
);
214 int fs_tree_opendir (const char *path
, struct fuse_file_info
*fi
) {
215 struct image_file
*image
= (struct image_file
*)
216 fuse_get_context ()->private_data
;
217 struct tree
*node
= tree_find_entry (image
->tree
, path
);
224 if (node
->type
!= TREE_DIR
)
230 int fs_tree_readdir (const char *path
, void *buf
, fuse_fill_dir_t filler
,
231 off_t offset
, struct fuse_file_info
*fi
) {
232 struct image_file
*image
= (struct image_file
*)
233 fuse_get_context ()->private_data
;
239 node
= tree_find_entry (image
->tree
, path
);
244 if (node
->type
!= TREE_DIR
)
247 filler (buf
, ".", NULL
, 0);
248 filler (buf
, "..", NULL
, 0);
252 filler (buf
, node
->name
, NULL
, 0);
259 int fs_tree_statfs (const char *path
, struct statvfs
*svfs
) {
260 struct image_file
*image
= (struct image_file
*)
261 fuse_get_context ()->private_data
;
265 memset (svfs
, 0, sizeof (struct statvfs
));
268 svfs
->f_blocks
= image
->nbytes
;
269 svfs
->f_files
= image
->nfiles
;
274 void fs_tree_get_ops (struct fuse_operations
*fs_ops
) {
275 memset (fs_ops
, 0, sizeof (struct fuse_operations
));
277 fs_ops
->getattr
= fs_tree_getattr
;
278 fs_ops
->open
= fs_tree_open
;
279 fs_ops
->read
= fs_tree_read
;
280 fs_ops
->opendir
= fs_tree_opendir
;
281 fs_ops
->readdir
= fs_tree_readdir
;
282 fs_ops
->readlink
= fs_tree_readlink
;
283 fs_ops
->statfs
= fs_tree_statfs
;