From c0eaf0fad88f15c843098a43ca2cadbf009ce094 Mon Sep 17 00:00:00 2001 From: Jonathan Neuschäfer Date: Mon, 15 Aug 2011 22:10:09 +0200 Subject: fix common misspellings * Fix spelling with codespell[1] and manually review it. [1] http://git.profusion.mobi/cgit.cgi/lucas/codespell/ --- tmpfs/pager-stubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmpfs') diff --git a/tmpfs/pager-stubs.c b/tmpfs/pager-stubs.c index 361724a9..25d70fe2 100644 --- a/tmpfs/pager-stubs.c +++ b/tmpfs/pager-stubs.c @@ -24,7 +24,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ /* The user must define this function. For pager PAGER, read one page from offset PAGE. Set *BUF to be the address of the page, and set *WRITE_LOCK if the page must be provided read-only. - The only permissable error returns are EIO, EDQUOT, and ENOSPC. */ + The only permissible error returns are EIO, EDQUOT, and ENOSPC. */ error_t pager_read_page (struct user_pager_info *pager, vm_offset_t page, @@ -37,7 +37,7 @@ pager_read_page (struct user_pager_info *pager, /* The user must define this function. For pager PAGER, synchronously write one page from BUF to offset PAGE. In addition, mfree - (or equivalent) BUF. The only permissable error returns are EIO, + (or equivalent) BUF. The only permissible error returns are EIO, EDQUOT, and ENOSPC. */ error_t pager_write_page (struct user_pager_info *pager, -- cgit v1.2.3 From b378f6a008890a2f5497d63c1173a66151ef0915 Mon Sep 17 00:00:00 2001 From: Maksym Planeta Date: Sun, 20 Nov 2011 09:32:22 +0100 Subject: Work with memory object only after vm_map has been performed * tmpfs/node.c (diskfs_get_filemap): Work with memory object only after vm_map has been performed. --- tmpfs/node.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tmpfs') diff --git a/tmpfs/node.c b/tmpfs/node.c index 17fe8ce7..b2503a05 100644 --- a/tmpfs/node.c +++ b/tmpfs/node.c @@ -498,17 +498,18 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot) return MACH_PORT_NULL; } assert (np->dn->u.reg.memobj != MACH_PORT_NULL); - /* A new-fangled default pager lets us prevent user accesses - past the specified size of the file. */ - err = default_pager_object_set_size (np->dn->u.reg.memobj, - np->allocsize); - assert_perror (err); /* XXX we need to keep a reference to the object, or GNU Mach will terminate it when we release the map. */ vm_map (mach_task_self (), &np->dn->u.reg.memref, 4096, 0, 1, np->dn->u.reg.memobj, 0, 0, VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_NONE); + + /* A new-fangled default pager lets us prevent user accesses + past the specified size of the file. */ + err = default_pager_object_set_size (np->dn->u.reg.memobj, + np->allocsize); + assert_perror (err); } /* XXX always writable */ -- cgit v1.2.3 From 078937c89aa2c93796ba7b64c474c30ddbdad38a Mon Sep 17 00:00:00 2001 From: Ben Asselstine Date: Sun, 20 Nov 2011 11:00:26 +0100 Subject: Fix symlink support in tmpfs * node.c (create_symlink_hook): Set NP->dn_stat.st_size to the length of TARGET. (create_symlink_hook): Set NP->dn->type to DT_LNK. (diskfs_truncate): Do NP->allocsize check after symlink check. --- tmpfs/node.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tmpfs') diff --git a/tmpfs/node.c b/tmpfs/node.c index b2503a05..ccc077ca 100644 --- a/tmpfs/node.c +++ b/tmpfs/node.c @@ -332,6 +332,7 @@ static error_t create_symlink_hook (struct node *np, const char *target) { assert (np->dn->u.lnk == 0); + np->dn_stat.st_size = strlen (target); if (np->dn_stat.st_size > 0) { const size_t size = np->dn_stat.st_size + 1; @@ -339,6 +340,7 @@ create_symlink_hook (struct node *np, const char *target) if (np->dn->u.lnk == 0) return ENOSPC; memcpy (np->dn->u.lnk, target, size); + np->dn->type = DT_LNK; adjust_used (size); recompute_blocks (np); } @@ -382,9 +384,6 @@ diskfs_node_reload (struct node *node) error_t diskfs_truncate (struct node *np, off_t size) { - if (np->allocsize <= size) - return 0; - if (np->dn->type == DT_LNK) { free (np->dn->u.lnk); @@ -394,6 +393,9 @@ diskfs_truncate (struct node *np, off_t size) return 0; } + if (np->allocsize <= size) + return 0; + assert (np->dn->type == DT_REG); if (default_pager == MACH_PORT_NULL) -- cgit v1.2.3 From 4f8d31d72708f4ae08913e7f42fdc4e852597ed3 Mon Sep 17 00:00:00 2001 From: Maksym Planeta Date: Mon, 23 Jan 2012 23:27:06 +0200 Subject: Correct available space check. *tmpfs/node.c (diskfs_grow): Parameter size denotes new size, not delta. So available space check should take that into account. --- tmpfs/node.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tmpfs') diff --git a/tmpfs/node.c b/tmpfs/node.c index ccc077ca..9d3647f8 100644 --- a/tmpfs/node.c +++ b/tmpfs/node.c @@ -443,7 +443,8 @@ diskfs_grow (struct node *np, off_t size, struct protid *cred) return 0; size = round_page (size); - if (round_page (tmpfs_space_used + size) / vm_page_size > tmpfs_page_limit) + if (round_page (tmpfs_space_used + size - np->allocsize) + / vm_page_size > tmpfs_page_limit) return ENOSPC; if (default_pager == MACH_PORT_NULL) -- cgit v1.2.3 From 24b07e7a3e7ff8b48033de422f27db7c0a2c690d Mon Sep 17 00:00:00 2001 From: Maksym Planeta Date: Wed, 21 Mar 2012 22:43:51 +0200 Subject: Fix hard links accounting in tmpfs. * tmpfs/dir.c (diskfs_init_dir, diskfs_clear_directory): Fix hard link accounting in tmpfs for directories. --- tmpfs/dir.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tmpfs') diff --git a/tmpfs/dir.c b/tmpfs/dir.c index 65386e0a..4a0a60b5 100644 --- a/tmpfs/dir.c +++ b/tmpfs/dir.c @@ -29,6 +29,12 @@ diskfs_init_dir (struct node *dp, struct node *pdp, struct protid *cred) { dp->dn->u.dir.dotdot = pdp->dn; dp->dn->u.dir.entries = 0; + + /* Increase hardlink count for parent directory */ + pdp->dn_stat.st_nlink++; + /* Take '.' directory into account */ + dp->dn_stat.st_nlink++; + return 0; } @@ -40,6 +46,12 @@ diskfs_clear_directory (struct node *dp, struct node *pdp, return ENOTEMPTY; assert (dp->dn_stat.st_size == 0); assert (dp->dn->u.dir.dotdot == pdp->dn); + + /* Decrease hardlink count for parent directory */ + pdp->dn_stat.st_nlink--; + /* Take '.' directory into account */ + dp->dn_stat.st_nlink--; + return 0; } -- cgit v1.2.3 From bf1a2c7dd16ff547fdf00c5730f7476fa8e7bca0 Mon Sep 17 00:00:00 2001 From: Maksym Planeta Date: Mon, 23 Jan 2012 02:29:18 +0200 Subject: Correct handling of object size. * tmpfs/node.c (diskfs_truncate): Pass the original (non-rounded) size to default_pager_object_set_size. (diskfs_grow): Likewise. (diskfs_get_filemap): Do not set object size, as default_pager_object_create already sets it. --- tmpfs/node.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'tmpfs') diff --git a/tmpfs/node.c b/tmpfs/node.c index 9d3647f8..bce15370 100644 --- a/tmpfs/node.c +++ b/tmpfs/node.c @@ -403,13 +403,12 @@ diskfs_truncate (struct node *np, off_t size) np->dn_stat.st_size = size; + off_t set_size = size; size = round_page (size); - if (size == np->allocsize) - return 0; if (np->dn->u.reg.memobj != MACH_PORT_NULL) { - error_t err = default_pager_object_set_size (np->dn->u.reg.memobj, size); + error_t err = default_pager_object_set_size (np->dn->u.reg.memobj, set_size); if (err == MIG_BAD_ID) /* This is an old default pager. We have no way to truncate the memory object. Note that the behavior here will be wrong in @@ -442,6 +441,7 @@ diskfs_grow (struct node *np, off_t size, struct protid *cred) if (np->allocsize >= size) return 0; + off_t set_size = size; size = round_page (size); if (round_page (tmpfs_space_used + size - np->allocsize) / vm_page_size > tmpfs_page_limit) @@ -453,7 +453,7 @@ diskfs_grow (struct node *np, off_t size, struct protid *cred) if (np->dn->u.reg.memobj != MACH_PORT_NULL) { /* Increase the limit the memory object will allow to be accessed. */ - error_t err = default_pager_object_set_size (np->dn->u.reg.memobj, size); + error_t err = default_pager_object_set_size (np->dn->u.reg.memobj, set_size); if (err == MIG_BAD_ID) /* Old default pager, never limited it. */ err = 0; if (err) @@ -507,11 +507,6 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot) vm_map (mach_task_self (), &np->dn->u.reg.memref, 4096, 0, 1, np->dn->u.reg.memobj, 0, 0, VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_NONE); - - /* A new-fangled default pager lets us prevent user accesses - past the specified size of the file. */ - err = default_pager_object_set_size (np->dn->u.reg.memobj, - np->allocsize); assert_perror (err); } -- cgit v1.2.3 From 2ad066887faafa32ec7b30c31a8d0f11f030f7bb Mon Sep 17 00:00:00 2001 From: Maksym Planeta Date: Sat, 7 Jan 2012 19:16:35 +0200 Subject: Prevent auto-terminating of tmpfs due to idle. * tmpfs/tmpfs.c (diskfs_thread_function): New function. (main): Manually detach diskfs demuxer. --- tmpfs/tmpfs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tmpfs') diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c index cd67dd74..b72459fe 100644 --- a/tmpfs/tmpfs.c +++ b/tmpfs/tmpfs.c @@ -255,6 +255,30 @@ diskfs_append_args (char **argz, size_t *argz_len) return err; } +/* Handling of operations for the ports in diskfs_port_bucket, calling + * demuxer for each incoming message */ +static any_t +diskfs_thread_function (any_t demuxer) +{ + error_t err; + + do + { + ports_manage_port_operations_multithread (diskfs_port_bucket, + (ports_demuxer_type) demuxer, + 0, + 0, + 0); + err = diskfs_shutdown (0); + } + while (err); + + exit (0); + /* NOTREACHED */ + return (any_t) 0; +} + + /* Add our startup arguments to the standard diskfs set. */ static const struct argp_child startup_children[] = {{&diskfs_startup_argp}, {0}}; @@ -317,7 +341,9 @@ main (int argc, char **argv) if (err) error (4, err, "cannot create root directory"); - diskfs_spawn_first_thread (diskfs_demuxer); + /* Like diskfs_spawn_first_thread. But do it manually, without timeout */ + cthread_detach (cthread_fork ((cthread_fn_t) diskfs_thread_function, + (any_t) diskfs_demuxer)); /* Now that we are all set up to handle requests, and diskfs_root_node is set properly, it is safe to export our fsys control port to the -- cgit v1.2.3 From 7e15f3d69a83a34ac62cbbee944a0bfbfa92724e Mon Sep 17 00:00:00 2001 From: Maksym Planeta Date: Sun, 8 Apr 2012 13:37:05 +0300 Subject: Update '..' link for directory when moving it. * tmpfs/dir.c (struct dirstat): New field. (diskfs_lookup_hard): Record whether type is SPEC_DOTDOT in dotdot field of ds. (diskfs_dirrewrite_hard): If ds->dotdot is true, set dp->dn->u.dir.dotdot insteead of (ds->prevp)->dn. --- tmpfs/dir.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tmpfs') diff --git a/tmpfs/dir.c b/tmpfs/dir.c index 4a0a60b5..c0ae9785 100644 --- a/tmpfs/dir.c +++ b/tmpfs/dir.c @@ -150,6 +150,7 @@ diskfs_get_directs (struct node *dp, int entry, int n, struct dirstat { struct tmpfs_dirent **prevp; + int dotdot; }; const size_t diskfs_dirstat_size = sizeof (struct dirstat); @@ -178,6 +179,9 @@ diskfs_lookup_hard (struct node *dp, if (type == REMOVE || type == RENAME) assert (np); + if (ds) + ds->dotdot = type & SPEC_DOTDOT; + if (namelen == 1 && name[0] == '.') { if (np != 0) @@ -279,7 +283,11 @@ error_t diskfs_dirrewrite_hard (struct node *dp, struct node *np, struct dirstat *ds) { - (*ds->prevp)->dn = np->dn; + if (ds->dotdot) + dp->dn->u.dir.dotdot = np->dn; + else + (*ds->prevp)->dn = np->dn; + return 0; } -- cgit v1.2.3