1998-08-20 08:19:55 +00:00
|
|
|
/* $NetBSD: ufs.c,v 1.20 1998/03/01 07:15:39 ross Exp $ */
|
|
|
|
|
|
|
|
/*-
|
2002-06-21 06:18:05 +00:00
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Marshall
|
|
|
|
* Kirk McKusick and Network Associates Laboratories, the Security
|
|
|
|
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
|
|
|
|
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
|
|
|
|
* research program
|
|
|
|
*
|
|
|
|
* Copyright (c) 1982, 1989, 1993
|
1998-08-20 08:19:55 +00:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* The Mach Operating System project at Carnegie-Mellon University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2016-09-06 15:17:35 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1998-08-20 08:19:55 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1990, 1991 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Author: David Golub
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 22:28:01 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Stand-alone file reading package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2002-05-12 20:58:18 +00:00
|
|
|
#include <sys/disklabel.h>
|
1998-08-20 08:19:55 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
#include "stand.h"
|
|
|
|
#include "string.h"
|
|
|
|
|
1998-09-18 22:58:01 +00:00
|
|
|
static int ufs_open(const char *path, struct open_file *f);
|
2018-02-23 20:18:09 +00:00
|
|
|
static int ufs_write(struct open_file *f, const void *buf, size_t size,
|
|
|
|
size_t *resid);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int ufs_close(struct open_file *f);
|
|
|
|
static int ufs_read(struct open_file *f, void *buf, size_t size, size_t *resid);
|
|
|
|
static off_t ufs_seek(struct open_file *f, off_t offset, int where);
|
|
|
|
static int ufs_stat(struct open_file *f, struct stat *sb);
|
2000-04-29 20:47:10 +00:00
|
|
|
static int ufs_readdir(struct open_file *f, struct dirent *d);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
struct fs_ops ufs_fsops = {
|
2000-04-29 20:47:10 +00:00
|
|
|
"ufs",
|
|
|
|
ufs_open,
|
|
|
|
ufs_close,
|
|
|
|
ufs_read,
|
2001-12-11 00:03:10 +00:00
|
|
|
ufs_write,
|
2000-04-29 20:47:10 +00:00
|
|
|
ufs_seek,
|
|
|
|
ufs_stat,
|
|
|
|
ufs_readdir
|
1998-08-20 08:19:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In-core open file.
|
|
|
|
*/
|
|
|
|
struct file {
|
|
|
|
off_t f_seekp; /* seek pointer */
|
|
|
|
struct fs *f_fs; /* pointer to super-block */
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode {
|
|
|
|
struct ufs1_dinode di1;
|
|
|
|
struct ufs2_dinode di2;
|
|
|
|
} f_di; /* copy of on-disk inode */
|
2017-02-15 19:50:26 +00:00
|
|
|
int f_nindir[UFS_NIADDR];
|
1998-08-20 08:19:55 +00:00
|
|
|
/* number of blocks mapped by
|
|
|
|
indirect block at level i */
|
2017-02-15 19:50:26 +00:00
|
|
|
char *f_blk[UFS_NIADDR]; /* buffer for indirect block at
|
1998-08-20 08:19:55 +00:00
|
|
|
level i */
|
2017-02-15 19:50:26 +00:00
|
|
|
size_t f_blksize[UFS_NIADDR];
|
1998-08-20 08:19:55 +00:00
|
|
|
/* size of buffer */
|
2017-02-15 19:50:26 +00:00
|
|
|
ufs2_daddr_t f_blkno[UFS_NIADDR];/* disk address of block in buffer */
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t f_buf_blkno; /* block number of data block */
|
1998-08-20 08:19:55 +00:00
|
|
|
char *f_buf; /* buffer for data block */
|
|
|
|
size_t f_buf_size; /* size of data block */
|
|
|
|
};
|
2002-06-21 06:18:05 +00:00
|
|
|
#define DIP(fp, field) \
|
|
|
|
((fp)->f_fs->fs_magic == FS_UFS1_MAGIC ? \
|
|
|
|
(fp)->f_di.di1.field : (fp)->f_di.di2.field)
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
static int read_inode(ino_t, struct open_file *);
|
2002-06-21 06:18:05 +00:00
|
|
|
static int block_map(struct open_file *, ufs2_daddr_t, ufs2_daddr_t *);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int buf_read_file(struct open_file *, char **, size_t *);
|
2018-02-23 20:18:09 +00:00
|
|
|
static int buf_write_file(struct open_file *, const char *, size_t *);
|
1998-08-20 08:19:55 +00:00
|
|
|
static int search_directory(char *, struct open_file *, ino_t *);
|
2018-01-26 00:58:32 +00:00
|
|
|
static int ufs_use_sa_read(void *, off_t, void **, int);
|
|
|
|
|
|
|
|
/* from ffs_subr.c */
|
|
|
|
int ffs_sbget(void *, struct fs **, off_t, char *,
|
|
|
|
int (*)(void *, off_t, void **, int));
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read a new inode into a file structure.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
read_inode(inumber, f)
|
|
|
|
ino_t inumber;
|
|
|
|
struct open_file *f;
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
struct fs *fs = fp->f_fs;
|
1998-08-20 08:19:55 +00:00
|
|
|
char *buf;
|
|
|
|
size_t rsize;
|
|
|
|
int rc;
|
|
|
|
|
1998-09-26 01:42:40 +00:00
|
|
|
if (fs == NULL)
|
|
|
|
panic("fs == NULL");
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Read inode and save it.
|
|
|
|
*/
|
1998-09-26 01:42:40 +00:00
|
|
|
buf = malloc(fs->fs_bsize);
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(1);
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
|
2016-12-30 19:06:29 +00:00
|
|
|
fsbtodb(fs, ino_to_fsba(fs, inumber)), fs->fs_bsize,
|
1998-08-20 08:19:55 +00:00
|
|
|
buf, &rsize);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
if (rsize != fs->fs_bsize) {
|
|
|
|
rc = EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fp->f_fs->fs_magic == FS_UFS1_MAGIC)
|
|
|
|
fp->f_di.di1 = ((struct ufs1_dinode *)buf)
|
|
|
|
[ino_to_fsbo(fs, inumber)];
|
|
|
|
else
|
|
|
|
fp->f_di.di2 = ((struct ufs2_dinode *)buf)
|
|
|
|
[ino_to_fsbo(fs, inumber)];
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear out the old buffers
|
|
|
|
*/
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
int level;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
for (level = 0; level < UFS_NIADDR; level++)
|
1998-08-20 08:19:55 +00:00
|
|
|
fp->f_blkno[level] = -1;
|
|
|
|
fp->f_buf_blkno = -1;
|
|
|
|
}
|
2004-09-04 14:54:01 +00:00
|
|
|
fp->f_seekp = 0;
|
1998-08-20 08:19:55 +00:00
|
|
|
out:
|
1998-09-26 01:42:40 +00:00
|
|
|
free(buf);
|
1998-08-20 08:19:55 +00:00
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an offset in a file, find the disk block number that
|
|
|
|
* contains that block.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
block_map(f, file_block, disk_block_p)
|
|
|
|
struct open_file *f;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t file_block;
|
|
|
|
ufs2_daddr_t *disk_block_p; /* out */
|
1998-08-20 08:19:55 +00:00
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
struct fs *fs = fp->f_fs;
|
1998-08-20 08:19:55 +00:00
|
|
|
int level;
|
|
|
|
int idx;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t ind_block_num;
|
1998-08-20 08:19:55 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Index structure of an inode:
|
|
|
|
*
|
2017-02-15 19:50:26 +00:00
|
|
|
* di_db[0..UFS_NDADDR-1] hold block numbers for blocks
|
|
|
|
* 0..UFS_NDADDR-1
|
1998-08-20 08:19:55 +00:00
|
|
|
*
|
|
|
|
* di_ib[0] index block 0 is the single indirect block
|
|
|
|
* holds block numbers for blocks
|
2017-02-15 19:50:26 +00:00
|
|
|
* UFS_NDADDR .. UFS_NDADDR + NINDIR(fs)-1
|
1998-08-20 08:19:55 +00:00
|
|
|
*
|
|
|
|
* di_ib[1] index block 1 is the double indirect block
|
|
|
|
* holds block numbers for INDEX blocks for blocks
|
2017-02-15 19:50:26 +00:00
|
|
|
* UFS_NDADDR + NINDIR(fs) ..
|
|
|
|
* UFS_NDADDR + NINDIR(fs) + NINDIR(fs)**2 - 1
|
1998-08-20 08:19:55 +00:00
|
|
|
*
|
|
|
|
* di_ib[2] index block 2 is the triple indirect block
|
|
|
|
* holds block numbers for double-indirect
|
|
|
|
* blocks for blocks
|
2017-02-15 19:50:26 +00:00
|
|
|
* UFS_NDADDR + NINDIR(fs) + NINDIR(fs)**2 ..
|
|
|
|
* UFS_NDADDR + NINDIR(fs) + NINDIR(fs)**2
|
1998-08-20 08:19:55 +00:00
|
|
|
* + NINDIR(fs)**3 - 1
|
|
|
|
*/
|
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
if (file_block < UFS_NDADDR) {
|
1998-08-20 08:19:55 +00:00
|
|
|
/* Direct block. */
|
2002-06-21 06:18:05 +00:00
|
|
|
*disk_block_p = DIP(fp, di_db[file_block]);
|
1998-08-20 08:19:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
file_block -= UFS_NDADDR;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nindir[0] = NINDIR
|
|
|
|
* nindir[1] = NINDIR**2
|
|
|
|
* nindir[2] = NINDIR**3
|
|
|
|
* etc
|
|
|
|
*/
|
2017-02-15 19:50:26 +00:00
|
|
|
for (level = 0; level < UFS_NIADDR; level++) {
|
1998-08-20 08:19:55 +00:00
|
|
|
if (file_block < fp->f_nindir[level])
|
|
|
|
break;
|
|
|
|
file_block -= fp->f_nindir[level];
|
|
|
|
}
|
2017-02-15 19:50:26 +00:00
|
|
|
if (level == UFS_NIADDR) {
|
1998-08-20 08:19:55 +00:00
|
|
|
/* Block number too high */
|
|
|
|
return (EFBIG);
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
ind_block_num = DIP(fp, di_ib[level]);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
for (; level >= 0; level--) {
|
|
|
|
if (ind_block_num == 0) {
|
|
|
|
*disk_block_p = 0; /* missing */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp->f_blkno[level] != ind_block_num) {
|
|
|
|
if (fp->f_blk[level] == (char *)0)
|
|
|
|
fp->f_blk[level] =
|
1998-09-26 01:42:40 +00:00
|
|
|
malloc(fs->fs_bsize);
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(1);
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
|
2016-12-30 19:06:29 +00:00
|
|
|
fsbtodb(fp->f_fs, ind_block_num),
|
1998-08-20 08:19:55 +00:00
|
|
|
fs->fs_bsize,
|
|
|
|
fp->f_blk[level],
|
|
|
|
&fp->f_blksize[level]);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
if (fp->f_blksize[level] != fs->fs_bsize)
|
|
|
|
return (EIO);
|
|
|
|
fp->f_blkno[level] = ind_block_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level > 0) {
|
|
|
|
idx = file_block / fp->f_nindir[level - 1];
|
|
|
|
file_block %= fp->f_nindir[level - 1];
|
|
|
|
} else
|
|
|
|
idx = file_block;
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fp->f_fs->fs_magic == FS_UFS1_MAGIC)
|
|
|
|
ind_block_num = ((ufs1_daddr_t *)fp->f_blk[level])[idx];
|
|
|
|
else
|
|
|
|
ind_block_num = ((ufs2_daddr_t *)fp->f_blk[level])[idx];
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*disk_block_p = ind_block_num;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-12-11 00:03:10 +00:00
|
|
|
/*
|
|
|
|
* Write a portion of a file from an internal buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
buf_write_file(f, buf_p, size_p)
|
|
|
|
struct open_file *f;
|
2018-02-23 20:18:09 +00:00
|
|
|
const char *buf_p;
|
2001-12-11 00:03:10 +00:00
|
|
|
size_t *size_p; /* out */
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
struct fs *fs = fp->f_fs;
|
2001-12-11 00:03:10 +00:00
|
|
|
long off;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs_lbn_t file_block;
|
|
|
|
ufs2_daddr_t disk_block;
|
2001-12-11 00:03:10 +00:00
|
|
|
size_t block_size;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the starting block address and offset.
|
|
|
|
*/
|
|
|
|
off = blkoff(fs, fp->f_seekp);
|
|
|
|
file_block = lblkno(fs, fp->f_seekp);
|
2002-06-21 06:18:05 +00:00
|
|
|
block_size = sblksize(fs, DIP(fp, di_size), file_block);
|
2001-12-11 00:03:10 +00:00
|
|
|
|
|
|
|
rc = block_map(f, file_block, &disk_block);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
if (disk_block == 0)
|
2002-06-21 06:18:05 +00:00
|
|
|
/* Because we can't allocate space on the drive */
|
|
|
|
return (EFBIG);
|
2001-12-11 00:03:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Truncate buffer at end of file, and at the end of
|
|
|
|
* this block.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
if (*size_p > DIP(fp, di_size) - fp->f_seekp)
|
|
|
|
*size_p = DIP(fp, di_size) - fp->f_seekp;
|
2001-12-11 00:03:10 +00:00
|
|
|
if (*size_p > block_size - off)
|
|
|
|
*size_p = block_size - off;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't entirely occlude the block and it's not
|
|
|
|
* in memory already, read it in first.
|
|
|
|
*/
|
|
|
|
if (((off > 0) || (*size_p + off < block_size)) &&
|
|
|
|
(file_block != fp->f_buf_blkno)) {
|
|
|
|
|
|
|
|
if (fp->f_buf == (char *)0)
|
|
|
|
fp->f_buf = malloc(fs->fs_bsize);
|
|
|
|
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(4);
|
2001-12-11 00:03:10 +00:00
|
|
|
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
|
2016-12-30 19:06:29 +00:00
|
|
|
fsbtodb(fs, disk_block),
|
2001-12-11 00:03:10 +00:00
|
|
|
block_size, fp->f_buf, &fp->f_buf_size);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
fp->f_buf_blkno = file_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the user data into the cached block.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
bcopy(buf_p, fp->f_buf + off, *size_p);
|
2001-12-11 00:03:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the block out to storage.
|
|
|
|
*/
|
|
|
|
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(4);
|
2001-12-11 00:03:10 +00:00
|
|
|
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
|
2016-12-30 19:06:29 +00:00
|
|
|
fsbtodb(fs, disk_block),
|
2001-12-11 00:03:10 +00:00
|
|
|
block_size, fp->f_buf, &fp->f_buf_size);
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Read a portion of a file into an internal buffer. Return
|
|
|
|
* the location in the buffer and the amount in the buffer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
buf_read_file(f, buf_p, size_p)
|
|
|
|
struct open_file *f;
|
|
|
|
char **buf_p; /* out */
|
|
|
|
size_t *size_p; /* out */
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
struct fs *fs = fp->f_fs;
|
1998-08-20 08:19:55 +00:00
|
|
|
long off;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs_lbn_t file_block;
|
|
|
|
ufs2_daddr_t disk_block;
|
1998-08-20 08:19:55 +00:00
|
|
|
size_t block_size;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
off = blkoff(fs, fp->f_seekp);
|
|
|
|
file_block = lblkno(fs, fp->f_seekp);
|
2002-06-21 06:18:05 +00:00
|
|
|
block_size = sblksize(fs, DIP(fp, di_size), file_block);
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if (file_block != fp->f_buf_blkno) {
|
2001-12-11 00:03:10 +00:00
|
|
|
if (fp->f_buf == (char *)0)
|
|
|
|
fp->f_buf = malloc(fs->fs_bsize);
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = block_map(f, file_block, &disk_block);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
if (disk_block == 0) {
|
|
|
|
bzero(fp->f_buf, block_size);
|
|
|
|
fp->f_buf_size = block_size;
|
|
|
|
} else {
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(4);
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
|
2016-12-30 19:06:29 +00:00
|
|
|
fsbtodb(fs, disk_block),
|
1998-08-20 08:19:55 +00:00
|
|
|
block_size, fp->f_buf, &fp->f_buf_size);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
fp->f_buf_blkno = file_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return address of byte in buffer corresponding to
|
|
|
|
* offset, and size of remainder of buffer after that
|
|
|
|
* byte.
|
|
|
|
*/
|
|
|
|
*buf_p = fp->f_buf + off;
|
|
|
|
*size_p = block_size - off;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* But truncate buffer at end of file.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
if (*size_p > DIP(fp, di_size) - fp->f_seekp)
|
|
|
|
*size_p = DIP(fp, di_size) - fp->f_seekp;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search a directory for a name and return its
|
|
|
|
* i_number.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
search_directory(name, f, inumber_p)
|
|
|
|
char *name;
|
|
|
|
struct open_file *f;
|
|
|
|
ino_t *inumber_p; /* out */
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
struct direct *dp;
|
1998-08-20 08:19:55 +00:00
|
|
|
struct direct *edp;
|
|
|
|
char *buf;
|
|
|
|
size_t buf_size;
|
|
|
|
int namlen, length;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
length = strlen(name);
|
|
|
|
|
|
|
|
fp->f_seekp = 0;
|
2002-06-21 06:18:05 +00:00
|
|
|
while (fp->f_seekp < DIP(fp, di_size)) {
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = buf_read_file(f, &buf, &buf_size);
|
|
|
|
if (rc)
|
|
|
|
return (rc);
|
|
|
|
|
|
|
|
dp = (struct direct *)buf;
|
|
|
|
edp = (struct direct *)(buf + buf_size);
|
|
|
|
while (dp < edp) {
|
|
|
|
if (dp->d_ino == (ino_t)0)
|
|
|
|
goto next;
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
if (fp->f_fs->fs_maxsymlinklen <= 0)
|
|
|
|
namlen = dp->d_type;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
namlen = dp->d_namlen;
|
|
|
|
if (namlen == length &&
|
|
|
|
!strcmp(name, dp->d_name)) {
|
|
|
|
/* found entry */
|
|
|
|
*inumber_p = dp->d_ino;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
dp = (struct direct *)((char *)dp + dp->d_reclen);
|
|
|
|
}
|
|
|
|
fp->f_seekp += buf_size;
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a file.
|
|
|
|
*/
|
|
|
|
static int
|
1998-09-18 22:58:01 +00:00
|
|
|
ufs_open(upath, f)
|
|
|
|
const char *upath;
|
1998-08-20 08:19:55 +00:00
|
|
|
struct open_file *f;
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
char *cp, *ncp;
|
|
|
|
int c;
|
1998-08-20 08:19:55 +00:00
|
|
|
ino_t inumber, parent_inumber;
|
|
|
|
struct file *fp;
|
|
|
|
struct fs *fs;
|
2002-06-21 06:18:05 +00:00
|
|
|
int i, rc;
|
1998-08-20 08:19:55 +00:00
|
|
|
size_t buf_size;
|
|
|
|
int nlinks = 0;
|
|
|
|
char namebuf[MAXPATHLEN+1];
|
|
|
|
char *buf = NULL;
|
1998-09-18 22:58:01 +00:00
|
|
|
char *path = NULL;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* allocate file system specific data structure */
|
|
|
|
fp = malloc(sizeof(struct file));
|
|
|
|
bzero(fp, sizeof(struct file));
|
|
|
|
f->f_fsdata = (void *)fp;
|
|
|
|
|
2018-01-26 00:58:32 +00:00
|
|
|
/* read super block */
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(1);
|
This change is some refactoring of Mark Johnston's changes in r329375
to fix the memory leak that I introduced in r328426. Instead of
trying to clear up the possible memory leak in all the clients, I
ensure that it gets cleaned up in the source (e.g., ffs_sbget ensures
that memory is always freed if it returns an error).
The original change in r328426 was a bit sparse in its description.
So I am expanding on its description here (thanks cem@ and rgrimes@
for your encouragement for my longer commit messages).
In preparation for adding check hashing to superblocks, r328426 is
a refactoring of the code to get the reading/writing of the superblock
into one place. Unlike the cylinder group reading/writing which
ends up in two places (ffs_getcg/ffs_geom_strategy in the kernel
and cgget/cgput in libufs), I have the core superblock functions
just in the kernel (ffs_sbfetch/ffs_sbput in ffs_subr.c which is
already imported into utilities like fsck_ffs as well as libufs to
implement sbget/sbput). The ffs_sbfetch and ffs_sbput functions
take a function pointer to do the actual I/O for which there are
four variants:
ffs_use_bread / ffs_use_bwrite for the in-kernel filesystem
g_use_g_read_data / g_use_g_write_data for kernel geom clients
ufs_use_sa_read for the standalone code (stand/libsa/ufs.c
but not stand/libsa/ufsread.c which is size constrained)
use_pread / use_pwrite for libufs
Uses of these interfaces are in the UFS filesystem, geoms journal &
label, libsa changes, and libufs. They also permeate out into the
filesystem utilities fsck_ffs, newfs, growfs, clri, dump, quotacheck,
fsirand, fstyp, and quot. Some of these utilities should probably be
converted to directly use libufs (like dumpfs was for example), but
there does not seem to be much win in doing so.
Tested by: Peter Holm (pho@)
2018-03-02 04:34:53 +00:00
|
|
|
if ((rc = ffs_sbget(f, &fs, -1, "stand", ufs_use_sa_read)) != 0)
|
1998-08-20 08:19:55 +00:00
|
|
|
goto out;
|
2018-01-26 00:58:32 +00:00
|
|
|
fp->f_fs = fs;
|
1998-08-20 08:19:55 +00:00
|
|
|
/*
|
|
|
|
* Calculate indirect block levels.
|
|
|
|
*/
|
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t mult;
|
2002-03-21 23:39:28 +00:00
|
|
|
int level;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
mult = 1;
|
2017-02-15 19:50:26 +00:00
|
|
|
for (level = 0; level < UFS_NIADDR; level++) {
|
1998-08-20 08:19:55 +00:00
|
|
|
mult *= NINDIR(fs);
|
|
|
|
fp->f_nindir[level] = mult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
inumber = UFS_ROOTINO;
|
1998-08-20 08:19:55 +00:00
|
|
|
if ((rc = read_inode(inumber, f)) != 0)
|
|
|
|
goto out;
|
|
|
|
|
1998-09-18 22:58:01 +00:00
|
|
|
cp = path = strdup(upath);
|
|
|
|
if (path == NULL) {
|
|
|
|
rc = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
while (*cp) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove extra separators
|
|
|
|
*/
|
|
|
|
while (*cp == '/')
|
|
|
|
cp++;
|
|
|
|
if (*cp == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that current node is a directory.
|
|
|
|
*/
|
2018-03-17 01:48:27 +00:00
|
|
|
if ((DIP(fp, di_mode) & UFS_IFMT) != UFS_IFDIR) {
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get next component of path name.
|
|
|
|
*/
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
int len = 0;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
ncp = cp;
|
|
|
|
while ((c = *cp) != '\0' && c != '/') {
|
2017-02-09 17:47:01 +00:00
|
|
|
if (++len > UFS_MAXNAMLEN) {
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up component in current directory.
|
|
|
|
* Save directory inumber in case we find a
|
|
|
|
* symbolic link.
|
|
|
|
*/
|
|
|
|
parent_inumber = inumber;
|
|
|
|
rc = search_directory(ncp, f, &inumber);
|
|
|
|
*cp = c;
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open next component.
|
|
|
|
*/
|
|
|
|
if ((rc = read_inode(inumber, f)) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for symbolic link.
|
|
|
|
*/
|
2018-03-17 01:48:27 +00:00
|
|
|
if ((DIP(fp, di_mode) & UFS_IFMT) == UFS_IFLNK) {
|
2002-06-21 06:18:05 +00:00
|
|
|
int link_len = DIP(fp, di_size);
|
1998-08-20 08:19:55 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(cp);
|
|
|
|
|
|
|
|
if (link_len + len > MAXPATHLEN ||
|
|
|
|
++nlinks > MAXSYMLINKS) {
|
|
|
|
rc = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(cp, &namebuf[link_len], len + 1);
|
|
|
|
|
|
|
|
if (link_len < fs->fs_maxsymlinklen) {
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fp->f_fs->fs_magic == FS_UFS1_MAGIC)
|
|
|
|
cp = (caddr_t)(fp->f_di.di1.di_db);
|
|
|
|
else
|
|
|
|
cp = (caddr_t)(fp->f_di.di2.di_db);
|
|
|
|
bcopy(cp, namebuf, (unsigned) link_len);
|
1998-08-20 08:19:55 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Read file for symbolic link
|
|
|
|
*/
|
|
|
|
size_t buf_size;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t disk_block;
|
2002-03-21 23:39:28 +00:00
|
|
|
struct fs *fs = fp->f_fs;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if (!buf)
|
1998-09-26 01:42:40 +00:00
|
|
|
buf = malloc(fs->fs_bsize);
|
2002-06-21 06:18:05 +00:00
|
|
|
rc = block_map(f, (ufs2_daddr_t)0, &disk_block);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
2014-12-22 20:42:36 +00:00
|
|
|
twiddle(1);
|
1998-08-20 08:19:55 +00:00
|
|
|
rc = (f->f_dev->dv_strategy)(f->f_devdata,
|
2016-12-30 19:06:29 +00:00
|
|
|
F_READ, fsbtodb(fs, disk_block),
|
1998-08-20 08:19:55 +00:00
|
|
|
fs->fs_bsize, buf, &buf_size);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
bcopy((char *)buf, namebuf, (unsigned)link_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If relative pathname, restart at parent directory.
|
|
|
|
* If absolute pathname, restart at root.
|
|
|
|
*/
|
|
|
|
cp = namebuf;
|
|
|
|
if (*cp != '/')
|
|
|
|
inumber = parent_inumber;
|
|
|
|
else
|
2017-02-15 19:50:26 +00:00
|
|
|
inumber = (ino_t)UFS_ROOTINO;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
if ((rc = read_inode(inumber, f)) != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Found terminal component.
|
|
|
|
*/
|
|
|
|
rc = 0;
|
2004-09-04 14:54:01 +00:00
|
|
|
fp->f_seekp = 0;
|
1998-08-20 08:19:55 +00:00
|
|
|
out:
|
|
|
|
if (buf)
|
1998-09-26 01:42:40 +00:00
|
|
|
free(buf);
|
1998-09-18 22:58:01 +00:00
|
|
|
if (path)
|
|
|
|
free(path);
|
1998-08-20 08:19:55 +00:00
|
|
|
if (rc) {
|
|
|
|
if (fp->f_buf)
|
1998-09-26 01:42:40 +00:00
|
|
|
free(fp->f_buf);
|
1998-08-20 08:19:55 +00:00
|
|
|
free(fp->f_fs);
|
|
|
|
free(fp);
|
|
|
|
}
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2018-01-26 00:58:32 +00:00
|
|
|
/*
|
|
|
|
* A read function for use by standalone-layer routines.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ufs_use_sa_read(void *devfd, off_t loc, void **bufp, int size)
|
|
|
|
{
|
|
|
|
struct open_file *f;
|
|
|
|
size_t buf_size;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
f = (struct open_file *)devfd;
|
|
|
|
if ((*bufp = malloc(size)) == NULL)
|
|
|
|
return (ENOSPC);
|
|
|
|
error = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, loc / DEV_BSIZE,
|
|
|
|
size, *bufp, &buf_size);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (buf_size != size)
|
|
|
|
return (EIO);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-08-20 08:19:55 +00:00
|
|
|
static int
|
|
|
|
ufs_close(f)
|
|
|
|
struct open_file *f;
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
1998-08-20 08:19:55 +00:00
|
|
|
int level;
|
|
|
|
|
|
|
|
f->f_fsdata = (void *)0;
|
|
|
|
if (fp == (struct file *)0)
|
|
|
|
return (0);
|
|
|
|
|
2017-02-15 19:50:26 +00:00
|
|
|
for (level = 0; level < UFS_NIADDR; level++) {
|
1998-08-20 08:19:55 +00:00
|
|
|
if (fp->f_blk[level])
|
1998-09-26 01:42:40 +00:00
|
|
|
free(fp->f_blk[level]);
|
1998-08-20 08:19:55 +00:00
|
|
|
}
|
|
|
|
if (fp->f_buf)
|
1998-09-26 01:42:40 +00:00
|
|
|
free(fp->f_buf);
|
|
|
|
free(fp->f_fs);
|
1998-08-20 08:19:55 +00:00
|
|
|
free(fp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a portion of a file into kernel memory.
|
|
|
|
* Cross block boundaries when necessary.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ufs_read(f, start, size, resid)
|
|
|
|
struct open_file *f;
|
|
|
|
void *start;
|
|
|
|
size_t size;
|
|
|
|
size_t *resid; /* out */
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
size_t csize;
|
1998-08-20 08:19:55 +00:00
|
|
|
char *buf;
|
|
|
|
size_t buf_size;
|
|
|
|
int rc = 0;
|
2002-03-21 23:39:28 +00:00
|
|
|
char *addr = start;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
while (size != 0) {
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fp->f_seekp >= DIP(fp, di_size))
|
1998-08-20 08:19:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
rc = buf_read_file(f, &buf, &buf_size);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
|
|
|
|
csize = size;
|
|
|
|
if (csize > buf_size)
|
|
|
|
csize = buf_size;
|
|
|
|
|
|
|
|
bcopy(buf, addr, csize);
|
|
|
|
|
|
|
|
fp->f_seekp += csize;
|
|
|
|
addr += csize;
|
|
|
|
size -= csize;
|
|
|
|
}
|
|
|
|
if (resid)
|
|
|
|
*resid = size;
|
|
|
|
return (rc);
|
|
|
|
}
|
2001-12-11 00:03:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to a portion of an already allocated file.
|
|
|
|
* Cross block boundaries when necessary. Can not
|
|
|
|
* extend the file.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ufs_write(f, start, size, resid)
|
|
|
|
struct open_file *f;
|
2018-02-23 20:18:09 +00:00
|
|
|
const void *start;
|
2001-12-11 00:03:10 +00:00
|
|
|
size_t size;
|
|
|
|
size_t *resid; /* out */
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
2001-12-11 00:03:10 +00:00
|
|
|
size_t csize;
|
|
|
|
int rc = 0;
|
2018-02-23 20:18:09 +00:00
|
|
|
const char *addr = start;
|
2001-12-11 00:03:10 +00:00
|
|
|
|
|
|
|
csize = size;
|
|
|
|
while ((size != 0) && (csize != 0)) {
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fp->f_seekp >= DIP(fp, di_size))
|
2001-12-11 00:03:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (csize >= 512) csize = 512; /* XXX */
|
|
|
|
|
|
|
|
rc = buf_write_file(f, addr, &csize);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
|
|
|
|
fp->f_seekp += csize;
|
|
|
|
addr += csize;
|
|
|
|
size -= csize;
|
|
|
|
}
|
|
|
|
if (resid)
|
|
|
|
*resid = size;
|
|
|
|
return (rc);
|
|
|
|
}
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
static off_t
|
|
|
|
ufs_seek(f, offset, where)
|
|
|
|
struct open_file *f;
|
|
|
|
off_t offset;
|
|
|
|
int where;
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
switch (where) {
|
|
|
|
case SEEK_SET:
|
|
|
|
fp->f_seekp = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
fp->f_seekp += offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
2002-06-21 06:18:05 +00:00
|
|
|
fp->f_seekp = DIP(fp, di_size) - offset;
|
1998-08-20 08:19:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-01-21 20:12:23 +00:00
|
|
|
errno = EINVAL;
|
1998-08-20 08:19:55 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (fp->f_seekp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ufs_stat(f, sb)
|
|
|
|
struct open_file *f;
|
|
|
|
struct stat *sb;
|
|
|
|
{
|
2002-03-21 23:39:28 +00:00
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
1998-08-20 08:19:55 +00:00
|
|
|
|
|
|
|
/* only important stuff */
|
2002-06-21 06:18:05 +00:00
|
|
|
sb->st_mode = DIP(fp, di_mode);
|
|
|
|
sb->st_uid = DIP(fp, di_uid);
|
|
|
|
sb->st_gid = DIP(fp, di_gid);
|
|
|
|
sb->st_size = DIP(fp, di_size);
|
1998-08-20 08:19:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-04-29 20:47:10 +00:00
|
|
|
static int
|
|
|
|
ufs_readdir(struct open_file *f, struct dirent *d)
|
|
|
|
{
|
|
|
|
struct file *fp = (struct file *)f->f_fsdata;
|
|
|
|
struct direct *dp;
|
|
|
|
char *buf;
|
|
|
|
size_t buf_size;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assume that a directory entry will not be split across blocks
|
|
|
|
*/
|
|
|
|
again:
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fp->f_seekp >= DIP(fp, di_size))
|
2000-04-29 20:47:10 +00:00
|
|
|
return (ENOENT);
|
|
|
|
error = buf_read_file(f, &buf, &buf_size);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
dp = (struct direct *)buf;
|
|
|
|
fp->f_seekp += dp->d_reclen;
|
|
|
|
if (dp->d_ino == (ino_t)0)
|
|
|
|
goto again;
|
|
|
|
d->d_type = dp->d_type;
|
|
|
|
strcpy(d->d_name, dp->d_name);
|
|
|
|
return (0);
|
|
|
|
}
|