diff options
author | Roland McGrath <roland@gnu.org> | 2000-12-29 07:23:24 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2000-12-29 07:23:24 +0000 |
commit | f9ecfe1f1db44339c6a9fee07b843ab936f2c21e (patch) | |
tree | de187595711174c1a74cd7c816c5e454cbc5058a /tmpfs | |
parent | ce7fbed9739d385a2ed7dd1a813b1d45e506cf92 (diff) |
2000-12-28 Roland McGrath <roland@frob.com>
* node.c (recompute_blocks): New function, broken out of ...
(diskfs_cached_lookup): here. Now use call that.
(diskfs_set_translator): Likewise.
(create_symlink_hook): Likewise. Do nothing for zero-length target.
Diffstat (limited to 'tmpfs')
-rw-r--r-- | tmpfs/node.c | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/tmpfs/node.c b/tmpfs/node.c index b06fc3d0..65d1305a 100644 --- a/tmpfs/node.c +++ b/tmpfs/node.c @@ -120,6 +120,33 @@ diskfs_node_norefs (struct node *np) free (np); } +static void +recompute_blocks (struct node *np) +{ + struct disknode *const dn = np->dn; + struct stat *const st = np->dn_stat; + + st->st_blocks = sizeof *dn + dn->translen; + switch (dn->type) + { + case DT_REG: + np->allocsize = dn->u.reg.allocpages * vm_page_size; + st->st_blocks += np->allocsize; + break; + case DT_LNK: + st->st_blocks += st->st_size + 1; + break; + case DT_CHR: + case DT_DEV: + st->st_rdev = dn->u.chr; + break; + case DT_DIR: + st->st_blocks += dn->size; + break; + } + st->st_blocks = (st->st_blocks + 511) / 512; +} + error_t diskfs_cached_lookup (int inum, struct node **npp) { @@ -169,25 +196,7 @@ diskfs_cached_lookup (int inum, struct node **npp) st->st_rdev = 0; np->allocsize = 0; - st->st_blocks = sizeof *dn + dn->translen; - switch (dn->type) - { - case DT_REG: - np->allocsize = dn->u.reg.allocpages * vm_page_size; - st->st_blocks += np->allocsize; - break; - case DT_LNK: - st->st_blocks += st->st_size + 1; - break; - case DT_CHR: - case DT_DEV: - st->st_rdev = dn->u.chr; - break; - case DT_DIR: - st->st_blocks += dn->size; - break; - } - st->st_blocks = (st->st_blocks + 511) / 512; + recompute_blocks (np); } mutex_lock (&np->lock); @@ -298,25 +307,26 @@ diskfs_set_translator (struct node *np, memcpy (new, name, namelen); } adjust_used (namelen - np->dn->translen); - if (np->dn->translen != 0) - np->dn_stat.st_blocks -= (np->dn->translen + 511) / 512; - if (namelen != 0) - np->dn_stat.st_blocks += (namelen + 511) / 512; np->dn->trans = new; np->dn->translen = namelen; + recompute_blocks (np); return 0; } static error_t create_symlink_hook (struct node *np, const char *target) { - const size_t size = np->dn_stat.st_size + 1; - assert (np->dn->u.link == 0); - char *new = malloc (np->dn->u.lnk, size); - if (new == 0) - return ENOSPC; - memcpy (np->dn->u.lnk, target, size); - adjust_used (size); + assert (np->dn->u.lnk == 0); + if (np->dn_stat.st_size > 0) + { + const size_t size = np->dn_stat.st_size + 1; + char *const new = malloc (np->dn->u.lnk, size); + if (new == 0) + return ENOSPC; + memcpy (np->dn->u.lnk, target, size); + adjust_used (size); + recompute_blocks (np); + } return 0; } error_t (*diskfs_read_symlink_hook)(struct node *np, char *target) |