am 4553b08d: sdcard: Implement statfs, stat time values and change mount point to /mnt/sdcard
Merge commit '4553b08d7555a103fdbe8623a9cbd826a7e413ff' into gingerbread-plus-aosp * commit '4553b08d7555a103fdbe8623a9cbd826a7e413ff': sdcard: Implement statfs, stat time values and change mount point to /mnt/sdcard
This commit is contained in:
commit
b1fb953877
1 changed files with 36 additions and 5 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statfs.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@
|
||||||
* usage: sdcard <path> <uid> <gid>
|
* usage: sdcard <path> <uid> <gid>
|
||||||
*
|
*
|
||||||
* It must be run as root, but will change to uid/gid as soon as it
|
* It must be run as root, but will change to uid/gid as soon as it
|
||||||
* mounts a filesystem on /sdcard. It will refuse to run if uid or
|
* mounts a filesystem on /mnt/sdcard. It will refuse to run if uid or
|
||||||
* gid are zero.
|
* gid are zero.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
@ -72,6 +73,8 @@
|
||||||
|
|
||||||
#define FUSE_UNKNOWN_INO 0xffffffff
|
#define FUSE_UNKNOWN_INO 0xffffffff
|
||||||
|
|
||||||
|
#define MOUNT_POINT "/mnt/sdcard"
|
||||||
|
|
||||||
struct handle {
|
struct handle {
|
||||||
struct node *node;
|
struct node *node;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
@ -143,7 +146,12 @@ void attr_from_stat(struct fuse_attr *attr, struct stat *s)
|
||||||
attr->ino = s->st_ino;
|
attr->ino = s->st_ino;
|
||||||
attr->size = s->st_size;
|
attr->size = s->st_size;
|
||||||
attr->blocks = s->st_blocks;
|
attr->blocks = s->st_blocks;
|
||||||
/* TODO: time */
|
attr->atime = s->st_atime;
|
||||||
|
attr->mtime = s->st_mtime;
|
||||||
|
attr->ctime = s->st_ctime;
|
||||||
|
attr->atimensec = s->st_atime_nsec;
|
||||||
|
attr->mtimensec = s->st_mtime_nsec;
|
||||||
|
attr->ctimensec = s->st_ctime_nsec;
|
||||||
attr->mode = s->st_mode;
|
attr->mode = s->st_mode;
|
||||||
attr->nlink = s->st_nlink;
|
attr->nlink = s->st_nlink;
|
||||||
|
|
||||||
|
|
@ -580,7 +588,30 @@ void handle_fuse_request(struct fuse *fuse, struct fuse_in_header *hdr, void *da
|
||||||
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
|
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
|
||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
// case FUSE_STATFS:
|
case FUSE_STATFS: { /* getattr_in -> attr_out */
|
||||||
|
struct statfs stat;
|
||||||
|
struct fuse_statfs_out out;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
TRACE("STATFS\n");
|
||||||
|
|
||||||
|
if (statfs(fuse->root.name, &stat)) {
|
||||||
|
fuse_status(fuse, hdr->unique, -errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&out, 0, sizeof(out));
|
||||||
|
out.st.blocks = stat.f_blocks;
|
||||||
|
out.st.bfree = stat.f_bfree;
|
||||||
|
out.st.bavail = stat.f_bavail;
|
||||||
|
out.st.files = stat.f_files;
|
||||||
|
out.st.ffree = stat.f_ffree;
|
||||||
|
out.st.bsize = stat.f_bsize;
|
||||||
|
out.st.namelen = stat.f_namelen;
|
||||||
|
out.st.frsize = stat.f_frsize;
|
||||||
|
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
|
||||||
|
return;
|
||||||
|
}
|
||||||
case FUSE_RELEASE: { /* release_in -> */
|
case FUSE_RELEASE: { /* release_in -> */
|
||||||
struct fuse_release_in *req = data;
|
struct fuse_release_in *req = data;
|
||||||
struct handle *h = id_to_ptr(req->fh);
|
struct handle *h = id_to_ptr(req->fh);
|
||||||
|
|
@ -729,7 +760,7 @@ int main(int argc, char **argv)
|
||||||
path = argv[1];
|
path = argv[1];
|
||||||
|
|
||||||
/* cleanup from previous instance, if necessary */
|
/* cleanup from previous instance, if necessary */
|
||||||
umount2("/sdcard", 2);
|
umount2(MOUNT_POINT, 2);
|
||||||
|
|
||||||
fd = open("/dev/fuse", O_RDWR);
|
fd = open("/dev/fuse", O_RDWR);
|
||||||
if (fd < 0){
|
if (fd < 0){
|
||||||
|
|
@ -740,7 +771,7 @@ int main(int argc, char **argv)
|
||||||
sprintf(opts, "fd=%i,rootmode=40000,default_permissions,allow_other,"
|
sprintf(opts, "fd=%i,rootmode=40000,default_permissions,allow_other,"
|
||||||
"user_id=%d,group_id=%d", fd, uid, gid);
|
"user_id=%d,group_id=%d", fd, uid, gid);
|
||||||
|
|
||||||
res = mount("/dev/fuse", "/sdcard", "fuse", MS_NOSUID | MS_NODEV, opts);
|
res = mount("/dev/fuse", MOUNT_POINT, "fuse", MS_NOSUID | MS_NODEV, opts);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
ERROR("cannot mount fuse filesystem (%d)\n", errno);
|
ERROR("cannot mount fuse filesystem (%d)\n", errno);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue