# ufs.c File Reference

`#include <vfs/vfs.h>`
`#include <ufs/ufs.h>`
`#include <ufs/ffs.h>`
`#include <lib/kprintf.h>`
`#include <lib/kmalloc.h>`
`#include <ubixos/kpanic.h>`
`#include <lib/string.h>`

Include dependency graph for ufs.c:

Go to the source code of this file.

## Defines

#define | DBPERVBLK (VBLKSIZE / DEV_BSIZE)
#define | DIP(field) fs->fs_magic == FS_UFS1_MAGIC ? dp1.field : dp2.field
#define | INDIRPERVBLK(fs) (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT))
#define | INO_TO_VBA(fs, ipervblk, x)
#define | INO_TO_VBO(ipervblk, x) ((x) % ipervblk)
#define | INOPB(fs) ((fs)->fs_inopb)
#define | IPERVBLK(fs) (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT))
#define | VBLKMASK (VBLKSIZE - 1)
#define | VBLKSHIFT 12
#define | VBLKSIZE (1 << VBLKSHIFT)

## Functions

static int | dskread (void *buf, u_int64_t block, size_t count, fileDescriptor *fd)
static __inline int | fsfind (const char *name, ino_t *ino, fileDescriptor *fd)
static ssize_t | fsread (ino_t inode, void *buf, size_t nbyte, fileDescriptor *fd)
static ino_t | lookup (const char *path, fileDescriptor *fd)
int | ufs_init ()
int | ufs_initialize (struct vfs_mountPoint *mp)
static int | ufs_openFile (const char *file, fileDescriptor *fd)
int | ufs_readFile (fileDescriptor *fd, char *data, uInt32 offset, long size)
int | ufs_writeFile (fileDescriptor *fd, char *data, uInt32 offset, long size)

## Variables

static int | sblock_try [] = SBLOCKSEARCH

## Define Documentation

#define DBPERVBLK (VBLKSIZE / DEV_BSIZE)

Definition at line 41 of file ufs.c.

Referenced by fsread().

#define DIP | ( | field |  | ) | fs->fs_magic == FS_UFS1_MAGIC ? dp1.field : dp2.field

Definition at line 73 of file ufs.c.

Referenced by fsread().

#define INDIRPERVBLK | ( | fs |  | ) | (NINDIR(fs) / ((fs)->fs_bsize >> VBLKSHIFT))

Definition at line 42 of file ufs.c.

Referenced by fsread().

#define INO_TO_VBA | ( | fs,
|  | ipervblk,
|  | x |  | ) |

Value:

    (fsbtodb(fs, cgimin(fs, ino_to_cg(fs, x))) + \
        (((x) % (fs)->fs_ipg) / (ipervblk) * DBPERVBLK))

Definition at line 45 of file ufs.c.

Referenced by fsread().

#define INO_TO_VBO | ( | ipervblk,
|  | x |  | ) | ((x) % ipervblk)

Definition at line 48 of file ufs.c.

Referenced by fsread().

#define INOPB | ( | fs |  | ) | ((fs)->fs_inopb)

Definition at line 44 of file ufs.c.

#define IPERVBLK | ( | fs |  | ) | (INOPB(fs) / ((fs)->fs_bsize >> VBLKSHIFT))

Definition at line 43 of file ufs.c.

Referenced by fsread().

#define VBLKMASK (VBLKSIZE - 1)

Definition at line 40 of file ufs.c.

Referenced by fsread().

#define VBLKSHIFT 12

Definition at line 38 of file ufs.c.

#define VBLKSIZE (1 << VBLKSHIFT)

Definition at line 39 of file ufs.c.

## Function Documentation

static int dskread | ( | void * | buf,
|  | u_int64_t | block,
|  | size_t | count,
|  | fileDescriptor * | fd |
| ) |  |  | `[static]`

Definition at line 51 of file ufs.c.

References vfs_mountPoint::device, device_node::devInfo, device_interface::info, fileDescriptorStruct::mp, and device_interface::read.

Referenced by fsread().

static __inline int fsfind | ( | const char * | name,
|  | ino_t * | ino,
|  | fileDescriptor * | fd |
| ) |  |  | `[static]`

Definition at line 214 of file ufs.c.

References dirent::d_fileno, dirent::d_name, dirent::d_reclen, dirent::d_type, DEV_BSIZE, fsread(), fileDescriptorStruct::offset, and strcmp().

Referenced by lookup().

Here is the call graph for this function:

static ssize_t fsread | ( | ino_t | inode,
|  | void * | buf,
|  | size_t | nbyte,
|  | fileDescriptor * | fd |
| ) |  |  | `[static]`

Definition at line 77 of file ufs.c.

References dmadat::blkbuf, blkoff, DBPERVBLK, DEV_BSHIFT, DEV_BSIZE, ufs2_dinode::di_db, ufs2_dinode::di_ib, ufs2_dinode::di_size, DIP, fileDescriptorStruct::dmadat, fileDescriptorStruct::dsk_meta, dskread(), fs::fs_magic, FS_UFS1_MAGIC, FS_UFS2_MAGIC, fsbtodb, dmadat::indbuf, INDIRPERVBLK, INO_TO_VBA, INO_TO_VBO, IPERVBLK, kprintf(), lblkno, MAXBSIZE, memcpy(), NDADDR, NINDIR, fileDescriptorStruct::offset, dmadat::sbbuf, sblksize, sblock_try, fileDescriptorStruct::size, VBLKMASK, VBLKSHIFT, and VBLKSIZE.

Referenced by fsfind(), ufs_openFile(), and ufs_readFile().

Here is the call graph for this function:

static ino_t lookup | ( | const char * | path,
|  | fileDescriptor * | fd |
| ) |  |  | `[static]`

Definition at line 236 of file ufs.c.

References DT_DIR, DT_REG, fsfind(), kprintf(), MAXNAMLEN, memcpy(), name, and ROOTINO.

Referenced by ufs_openFile().

Here is the call graph for this function:

int ufs_init | ( |  | ) |

Definition at line 314 of file ufs.c.

References kpanic(), NULL, ufs_initialize(), ufs_openFile(), ufs_readFile(), ufs_writeFile(), vfsRegisterFS(), and x1.

Here is the call graph for this function:

int ufs_initialize | ( | struct vfs_mountPoint * | mp | ) |

Definition at line 309 of file ufs.c.

References x1.

static int ufs_openFile | ( | const char * | file,
|  | fileDescriptor * | fd |
| ) |  |  | `[static]`

Definition at line 272 of file ufs.c.

References fileDescriptorStruct::dmadat, fsread(), fileDescriptorStruct::ino, kmalloc(), lookup(), fileDescriptorStruct::offset, fileDescriptorStruct::perms, and x1.

Referenced by ufs_init().

Here is the call graph for this function:

int ufs_readFile | ( | fileDescriptor * | fd,
|  | char * | data,
|  | uInt32 | offset,
|  | long | size |
| ) |  |  |

Definition at line 291 of file ufs.c.

References fsread(), and fileDescriptorStruct::ino.

Referenced by ufs_init().

Here is the call graph for this function:

int ufs_writeFile | ( | fileDescriptor * | fd,
|  | char * | data,
|  | uInt32 | offset,
|  | long | size |
| ) |  |  |

Definition at line 295 of file ufs.c.

References kprintf().

Referenced by ufs_init().

Here is the call graph for this function:

## Variable Documentation

int sblock_try[] = SBLOCKSEARCH`[static]`

Definition at line 66 of file ufs.c.

Referenced by fsread().