330 |
create_symlink_hook (struct node *np, const char *target) |
create_symlink_hook (struct node *np, const char *target) |
331 |
{ |
{ |
332 |
assert (np->dn->u.lnk == 0); |
assert (np->dn->u.lnk == 0); |
333 |
|
np->dn_stat.st_size = strlen (target); |
334 |
if (np->dn_stat.st_size > 0) |
if (np->dn_stat.st_size > 0) |
335 |
{ |
{ |
336 |
const size_t size = np->dn_stat.st_size + 1; |
const size_t size = np->dn_stat.st_size + 1; |
338 |
if (np->dn->u.lnk == 0) |
if (np->dn->u.lnk == 0) |
339 |
return ENOSPC; |
return ENOSPC; |
340 |
memcpy (np->dn->u.lnk, target, size); |
memcpy (np->dn->u.lnk, target, size); |
341 |
|
np->dn->type = DT_LNK; |
342 |
adjust_used (size); |
adjust_used (size); |
343 |
recompute_blocks (np); |
recompute_blocks (np); |
344 |
} |
} |
382 |
error_t |
error_t |
383 |
diskfs_truncate (struct node *np, off_t size) |
diskfs_truncate (struct node *np, off_t size) |
384 |
{ |
{ |
|
if (np->allocsize <= size) |
|
|
return 0; |
|
|
|
|
385 |
if (np->dn->type == DT_LNK) |
if (np->dn->type == DT_LNK) |
386 |
{ |
{ |
387 |
free (np->dn->u.lnk); |
free (np->dn->u.lnk); |
390 |
np->dn_stat.st_size = size; |
np->dn_stat.st_size = size; |
391 |
return 0; |
return 0; |
392 |
} |
} |
393 |
|
|
394 |
|
if (np->allocsize <= size) |
395 |
|
return 0; |
396 |
|
|
397 |
assert (np->dn->type == DT_REG); |
assert (np->dn->type == DT_REG); |
398 |
|
|