summaryrefslogtreecommitdiff
path: root/ufs/dir.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1998-10-20 19:20:07 +0000
committerRoland McGrath <roland@gnu.org>1998-10-20 19:20:07 +0000
commit0d3ef933e246eb5279b84b2dff6615698428f4c3 (patch)
tree5554572296be5f61a1e2657bb26404fd2280ce51 /ufs/dir.c
parent291dcfb19c661c9f91e015ad9beb39aac737926b (diff)
1998-09-04 Roland McGrath <roland@baalperazim.frob.com>
* dir.c (diskfs_lookup_hard): Fix defn with `const'. (diskfs_direnter_hard): Likewise. (dirscanblock): Likewise. * inode.c (diskfs_create_symlink_hook, create_symlink_hook): Likewise. (diskfs_set_translator): Likewise.
Diffstat (limited to 'ufs/dir.c')
-rw-r--r--ufs/dir.c172
1 files changed, 86 insertions, 86 deletions
diff --git a/ufs/dir.c b/ufs/dir.c
index bdf84be6..01432829 100644
--- a/ufs/dir.c
+++ b/ufs/dir.c
@@ -1,5 +1,5 @@
/* Directory management routines
- Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation
+ Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -64,8 +64,8 @@ struct dirstat
/* Index of this directory block. */
int idx;
-
- /* For stat COMPRESS, this is the address (inside mapbuf)
+
+ /* For stat COMPRESS, this is the address (inside mapbuf)
of the first direct in the directory block to be compressed. */
/* For stat HERE_TIS, SHRINK, and TAKE, this is the entry referenced. */
struct directory_entry *entry;
@@ -82,21 +82,21 @@ struct dirstat
size_t diskfs_dirstat_size = sizeof (struct dirstat);
/* Initialize DS such that diskfs_drop_dirstat will ignore it. */
-void
+void
diskfs_null_dirstat (struct dirstat *ds)
{
ds->type = LOOKUP;
}
-static error_t
-dirscanblock (vm_address_t blockoff, struct node *dp, int idx, char *name,
- int namelen, enum lookup_type type, struct dirstat *ds,
- ino_t *inum);
+static error_t
+dirscanblock (vm_address_t blockoff, struct node *dp, int idx,
+ const char *name, int namelen, enum lookup_type type,
+ struct dirstat *ds, ino_t *inum);
/* Implement the diskfs_lookup from the diskfs library. See
<hurd/diskfs.h> for the interface specification. */
error_t
-diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
+diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
struct node **npp, struct dirstat *ds, struct protid *cred)
{
error_t err;
@@ -113,7 +113,7 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
int blockaddr;
int idx, lastidx;
int looped;
-
+
if ((type == REMOVE) || (type == RENAME))
assert (npp);
@@ -122,12 +122,12 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
spec_dotdot = type & SPEC_DOTDOT;
type &= ~SPEC_DOTDOT;
-
+
namelen = strlen (name);
if (namelen > MAXNAMLEN)
return ENAMETOOLONG;
-
+
try_again:
if (ds)
{
@@ -157,10 +157,10 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
mach_port_deallocate (mach_task_self (), memobj);
inum = 0;
-
+
if (!diskfs_check_readonly ())
dp->dn_set_atime = 1;
-
+
/* Start the lookup at DP->dn->dir_idx. */
idx = dp->dn->dir_idx;
if (idx * DIRBLKSIZ > dp->dn_stat.st_size)
@@ -221,7 +221,7 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
goto out;
}
}
-
+
/* We are looking up .. */
/* Check to see if this is the root of the filesystem. */
else if (dp->dn->number == 2)
@@ -229,7 +229,7 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
err = EAGAIN;
goto out;
}
-
+
/* We can't just do diskfs_cached_lookup, because we would then deadlock.
So we do this. Ick. */
else if (retry_dotdot)
@@ -263,11 +263,11 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
retry_dotdot = inum;
goto try_again;
}
-
+
/* Here below are the spec dotdot cases. */
else if (type == RENAME || type == REMOVE)
np = ifind (inum);
-
+
else if (type == LOOKUP)
{
diskfs_nput (dp);
@@ -278,7 +278,7 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
else
assert (0);
}
-
+
if ((type == CREATE || type == RENAME) && !inum && ds && ds->stat == LOOKING)
{
/* We didn't find any room, so mark ds to extend the dir */
@@ -304,7 +304,7 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
ds->mapbuf = buf;
ds->mapextent = buflen;
}
-
+
if (np)
{
assert (npp);
@@ -338,8 +338,8 @@ diskfs_lookup_hard (struct node *dp, char *name, enum lookup_type type,
diskfs_lookup. If found, set *INUM to the inode number, else
return ENOENT. */
static error_t
-dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
- int namelen, enum lookup_type type,
+dirscanblock (vm_address_t blockaddr, struct node *dp, int idx,
+ const char *name, int namelen, enum lookup_type type,
struct dirstat *ds, ino_t *inum)
{
int nfree = 0;
@@ -351,7 +351,7 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
int looking = 0;
int countcopies = 0;
int consider_compress = 0;
-
+
if (ds && (ds->stat == LOOKING
|| ds->stat == COMPRESS))
{
@@ -365,11 +365,11 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
prevoff = currentoff, currentoff += read_disk_entry (entry->d_reclen))
{
entry = (struct directory_entry *)currentoff;
-
+
if (!entry->d_reclen
|| read_disk_entry (entry->d_reclen) % 4
|| DIRECT_NAMLEN (entry) > MAXNAMLEN
- || (currentoff + read_disk_entry (entry->d_reclen)
+ || (currentoff + read_disk_entry (entry->d_reclen)
> blockaddr + DIRBLKSIZ)
|| entry->d_name[DIRECT_NAMLEN (entry)]
|| DIRSIZ (DIRECT_NAMLEN (entry)) > read_disk_entry (entry->d_reclen)
@@ -379,16 +379,16 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
dp->dn->number, currentoff - blockaddr + idx * DIRBLKSIZ);
return ENOENT;
}
-
+
if (looking || countcopies)
{
int thisfree;
-
+
/* Count how much free space this entry has in it. */
if (entry->d_ino == 0)
thisfree = read_disk_entry (entry->d_reclen);
else
- thisfree = (read_disk_entry (entry->d_reclen)
+ thisfree = (read_disk_entry (entry->d_reclen)
- DIRSIZ (DIRECT_NAMLEN (entry)));
/* If this isn't at the front of the block, then it will
@@ -396,9 +396,9 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
number of bytes there too. */
if (countcopies && currentoff != blockaddr)
nbytes += DIRSIZ (DIRECT_NAMLEN (entry));
-
+
if (ds->stat == COMPRESS && nbytes > ds->nbytes)
- /* The previously found compress is better than
+ /* The previously found compress is better than
this one, so don't bother counting any more. */
countcopies = 0;
@@ -415,9 +415,9 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
nfree += thisfree;
if (nfree >= needed)
consider_compress = 1;
- }
+ }
}
-
+
if (entry->d_ino)
nentries++;
@@ -428,7 +428,7 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
break;
}
- if (consider_compress
+ if (consider_compress
&& (ds->type == LOOKING
|| (ds->type == COMPRESS && ds->nbytes > nbytes)))
{
@@ -438,7 +438,7 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
ds->idx = idx;
ds->nbytes = nbytes;
}
-
+
if (currentoff >= blockaddr + DIRBLKSIZ)
{
int i;
@@ -448,9 +448,9 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
down how many entries there were. */
if (!dp->dn->dirents)
{
- dp->dn->dirents = malloc ((dp->dn_stat.st_size / DIRBLKSIZ)
+ dp->dn->dirents = malloc ((dp->dn_stat.st_size / DIRBLKSIZ)
* sizeof (int));
- for (i = 0; i < dp->dn_stat.st_size/DIRBLKSIZ; i++)
+ for (i = 0; i < dp->dn_stat.st_size/DIRBLKSIZ; i++)
dp->dn->dirents[i] = -1;
}
/* Make sure the count is correct if there is one now. */
@@ -460,7 +460,7 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
return ENOENT;
}
-
+
/* We have found the required name. */
if (ds && type == CREATE)
@@ -486,7 +486,7 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx, char *name,
the preceding lookup call, and only if that call returned ENOENT. */
error_t
diskfs_direnter_hard(struct node *dp,
- char *name,
+ const char *name,
struct node *np,
struct dirstat *ds,
struct protid *cred)
@@ -496,21 +496,21 @@ diskfs_direnter_hard(struct node *dp,
int needed = DIRSIZ (namelen);
int oldneeded;
vm_address_t fromoff, tooff;
- int totfreed;
+ int totfreed;
error_t err;
off_t oldsize = 0;
assert (ds->type == CREATE);
-
+
dp->dn_set_mtime = 1;
switch (ds->stat)
{
case TAKE:
/* We are supposed to consume this slot. */
- assert (ds->entry->d_ino == 0
+ assert (ds->entry->d_ino == 0
&& read_disk_entry (ds->entry->d_reclen) >= needed);
-
+
write_disk_entry (ds->entry->d_ino, np->dn->number);
DIRECT_NAMLEN (ds->entry) = namelen;
if (direct_symlink_extension)
@@ -518,27 +518,27 @@ diskfs_direnter_hard(struct node *dp,
bcopy (name, ds->entry->d_name, namelen + 1);
break;
-
+
case SHRINK:
/* We are supposed to take the extra space at the end
of this slot. */
oldneeded = DIRSIZ (DIRECT_NAMLEN (ds->entry));
assert (read_disk_entry (ds->entry->d_reclen) - oldneeded >= needed);
-
+
new = (struct directory_entry *) ((vm_address_t) ds->entry + oldneeded);
write_disk_entry (new->d_ino, np->dn->number);
- write_disk_entry (new->d_reclen,
+ write_disk_entry (new->d_reclen,
read_disk_entry (ds->entry->d_reclen) - oldneeded);
DIRECT_NAMLEN (new) = namelen;
if (direct_symlink_extension)
new->d_type = IFTODT (np->dn_stat.st_mode);
bcopy (name, new->d_name, namelen + 1);
-
+
write_disk_entry (ds->entry->d_reclen, oldneeded);
-
+
break;
-
+
case COMPRESS:
/* We are supposed to move all the entries to the
front of the block, giving each the minimum
@@ -566,7 +566,7 @@ diskfs_direnter_hard(struct node *dp,
totfreed = (vm_address_t) ds->entry + DIRBLKSIZ - tooff;
assert (totfreed >= needed);
-
+
new = (struct directory_entry *) tooff;
write_disk_entry (new->d_ino, np->dn->number);
write_disk_entry (new->d_reclen, totfreed);
@@ -579,7 +579,7 @@ diskfs_direnter_hard(struct node *dp,
case EXTEND:
/* Extend the file. */
assert (needed <= DIRBLKSIZ);
-
+
oldsize = dp->dn_stat.st_size;
while (oldsize + DIRBLKSIZ > dp->allocsize)
{
@@ -603,7 +603,7 @@ diskfs_direnter_hard(struct node *dp,
new->d_type = IFTODT (np->dn_stat.st_mode);
bcopy (name, new->d_name, namelen + 1);
break;
-
+
default:
assert (0);
}
@@ -611,10 +611,10 @@ diskfs_direnter_hard(struct node *dp,
dp->dn_set_mtime = 1;
vm_deallocate (mach_task_self (), ds->mapbuf, ds->mapextent);
-
+
if (ds->stat != EXTEND)
{
- /* If we are keeping count of this block, then keep the count up
+ /* If we are keeping count of this block, then keep the count up
to date. */
if (dp->dn->dirents && dp->dn->dirents[ds->idx] != -1)
dp->dn->dirents[ds->idx]++;
@@ -626,10 +626,10 @@ diskfs_direnter_hard(struct node *dp,
anything at all. */
if (dp->dn->dirents)
{
- dp->dn->dirents = realloc (dp->dn->dirents,
+ dp->dn->dirents = realloc (dp->dn->dirents,
(dp->dn_stat.st_size / DIRBLKSIZ
* sizeof (int)));
- for (i = oldsize / DIRBLKSIZ;
+ for (i = oldsize / DIRBLKSIZ;
i < dp->dn_stat.st_size / DIRBLKSIZ;
i++)
dp->dn->dirents[i] = -1;
@@ -638,14 +638,14 @@ diskfs_direnter_hard(struct node *dp,
}
else
{
- dp->dn->dirents = malloc (dp->dn_stat.st_size / DIRBLKSIZ
+ dp->dn->dirents = malloc (dp->dn_stat.st_size / DIRBLKSIZ
* sizeof (int));
for (i = 0; i < dp->dn_stat.st_size / DIRBLKSIZ; i++)
dp->dn->dirents[i] = -1;
dp->dn->dirents[ds->idx] = 1;
}
}
-
+
diskfs_file_update (dp, 1);
return 0;
@@ -662,7 +662,7 @@ diskfs_dirremove_hard(struct node *dp,
{
assert (ds->type == REMOVE);
assert (ds->stat == HERE_TIS);
-
+
dp->dn_set_mtime = 1;
if (ds->preventry == 0)
@@ -671,7 +671,7 @@ diskfs_dirremove_hard(struct node *dp,
{
assert ((vm_address_t) ds->entry - (vm_address_t) ds->preventry
== read_disk_entry (ds->preventry->d_reclen));
- write_disk_entry (ds->preventry->d_reclen,
+ write_disk_entry (ds->preventry->d_reclen,
(read_disk_entry (ds->preventry->d_reclen)
+ read_disk_entry (ds->entry->d_reclen)));
}
@@ -684,27 +684,27 @@ diskfs_dirremove_hard(struct node *dp,
to date. */
if (dp->dn->dirents && dp->dn->dirents[ds->idx] != -1)
dp->dn->dirents[ds->idx]--;
-
+
diskfs_file_update (dp, 1);
return 0;
}
-
+
/* Following a lookup call for RENAME, this changes the inode number
- on a directory entry. DP is the directory being changed; NP is
- the new node being linked in; DP is the cached information returned
+ on a directory entry. DP is the directory being changed; NP is
+ the new node being linked in; DP is the cached information returned
by lookup. This call is only valid if the directory has been locked
continuously since the call to lookup, and only if that call
succeeded. */
error_t
-diskfs_dirrewrite_hard(struct node *dp,
+diskfs_dirrewrite_hard(struct node *dp,
struct node *np,
struct dirstat *ds)
{
assert (ds->type == RENAME);
assert (ds->stat == HERE_TIS);
-
+
dp->dn_set_mtime = 1;
write_disk_entry (ds->entry->d_ino, np->dn->number);
if (direct_symlink_extension)
@@ -712,7 +712,7 @@ diskfs_dirrewrite_hard(struct node *dp,
dp->dn_set_mtime = 1;
vm_deallocate (mach_task_self (), ds->mapbuf, ds->mapextent);
-
+
diskfs_file_update (dp, 1);
return 0;
@@ -737,7 +737,7 @@ diskfs_dirempty(struct node *dp,
return 0;
buf = 0;
-
+
err = vm_map (mach_task_self (), &buf, dp->dn_stat.st_size, 0,
1, memobj, 0, 0, VM_PROT_READ, VM_PROT_READ, 0);
mach_port_deallocate (mach_task_self (), memobj);
@@ -746,7 +746,7 @@ diskfs_dirempty(struct node *dp,
if (!diskfs_check_readonly ())
dp->dn_set_atime = 1;
- for (curoff = buf;
+ for (curoff = buf;
curoff < buf + dp->dn_stat.st_size;
curoff += read_disk_entry (entry->d_reclen))
{
@@ -766,7 +766,7 @@ diskfs_dirempty(struct node *dp,
return 0;
}
}
- if (!diskfs_check_readonly ())
+ if (!diskfs_check_readonly ())
dp->dn_set_atime = 1;
if (diskfs_synchronous)
diskfs_node_update (dp, 1);
@@ -802,12 +802,12 @@ count_dirents (struct node *dp, int nb, char *buf)
assert (dp->dn->dirents);
assert ((nb + 1) * DIRBLKSIZ <= dp->dn_stat.st_size);
-
+
err = diskfs_node_rdwr (dp, buf, nb * DIRBLKSIZ, DIRBLKSIZ, 0, 0, &amt);
if (err)
return err;
assert (amt == DIRBLKSIZ);
-
+
for (offinblk = buf;
offinblk < buf + DIRBLKSIZ;
offinblk += read_disk_entry (entry->d_reclen))
@@ -816,7 +816,7 @@ count_dirents (struct node *dp, int nb, char *buf)
if (entry->d_ino)
count++;
}
-
+
assert (dp->dn->dirents[nb] == -1 || dp->dn->dirents[nb] == count);
dp->dn->dirents[nb] = count;
return 0;
@@ -825,8 +825,8 @@ count_dirents (struct node *dp, int nb, char *buf)
/* Implement the disikfs_get_directs callback as described in
<hurd/diskfs.h>. */
error_t
-diskfs_get_directs (struct node *dp,
- int entry,
+diskfs_get_directs (struct node *dp,
+ int entry,
int nentries,
char **data,
u_int *datacnt,
@@ -846,7 +846,7 @@ diskfs_get_directs (struct node *dp,
int allocsize;
int checklen;
struct dirent *userp;
-
+
nblks = dp->dn_stat.st_size/DIRBLKSIZ;
if (!dp->dn->dirents)
@@ -864,7 +864,7 @@ diskfs_get_directs (struct node *dp,
if (allocsize > *datacnt)
vm_allocate (mach_task_self (), (vm_address_t *) data, allocsize, 1);
-
+
/* Scan through the entries to find ENTRY. If we encounter
a -1 in the process then stop to fill it. When we run
off the end, ENTRY is too big. */
@@ -885,10 +885,10 @@ diskfs_get_directs (struct node *dp,
break;
curentry += dp->dn->dirents[blkno];
-
+
bufvalid = 0;
}
-
+
if (blkno == nblks)
{
*datacnt = 0;
@@ -911,15 +911,15 @@ diskfs_get_directs (struct node *dp,
assert (checklen == DIRBLKSIZ);
bufvalid = 1;
}
- for (i = 0, bufp = buf;
- i < entry - curentry && bufp - buf < DIRBLKSIZ;
+ for (i = 0, bufp = buf;
+ i < entry - curentry && bufp - buf < DIRBLKSIZ;
(bufp
- += read_disk_entry (((struct directory_entry *)bufp)->d_reclen)),
+ += read_disk_entry (((struct directory_entry *)bufp)->d_reclen)),
i++)
;
/* Make sure we didn't run off the end. */
assert (bufp - buf < DIRBLKSIZ);
- }
+ }
i = 0;
datap = *data;
@@ -931,7 +931,7 @@ diskfs_get_directs (struct node *dp,
{
if (!bufvalid)
{
- err = diskfs_node_rdwr (dp, buf, blkno * DIRBLKSIZ, DIRBLKSIZ,
+ err = diskfs_node_rdwr (dp, buf, blkno * DIRBLKSIZ, DIRBLKSIZ,
0, 0, &checklen);
if (err)
return err;
@@ -962,17 +962,17 @@ diskfs_get_directs (struct node *dp,
bufvalid = 0;
}
}
-
+
/* We've copied all we can. If we allocated our own array
but didn't fill all of it, then free whatever memory we didn't use. */
if (allocsize > *datacnt)
{
if (round_page (datap - *data) < allocsize)
- vm_deallocate (mach_task_self (),
+ vm_deallocate (mach_task_self (),
(vm_address_t) (*data + round_page (datap - *data)),
allocsize - round_page (datap - *data));
}
-
+
/* Set variables for return */
*datacnt = datap - *data;
*amt = i;