Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/makefs/msdos/msdosfs_vnops.c
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "ffs/buf.h" | |||||
#include <fs/msdosfs/bpb.h> | #include <fs/msdosfs/bpb.h> | ||||
#include "msdos/direntry.h" | #include "msdos/direntry.h" | ||||
#include <fs/msdosfs/denode.h> | #include <fs/msdosfs/denode.h> | ||||
#include <fs/msdosfs/fat.h> | #include <fs/msdosfs/fat.h> | ||||
#include <fs/msdosfs/msdosfsmount.h> | #include <fs/msdosfs/msdosfsmount.h> | ||||
#undef clrbuf | |||||
#include "ffs/buf.h" | |||||
#include "makefs.h" | #include "makefs.h" | ||||
#include "msdos.h" | #include "msdos.h" | ||||
/* | /* | ||||
* Some general notes: | * Some general notes: | ||||
* | * | ||||
* In the ufs filesystem the inodes, superblocks, and indirect blocks are | * In the ufs filesystem the inodes, superblocks, and indirect blocks are | ||||
* read/written using the vnode for the filesystem. Blocks that represent | * read/written using the vnode for the filesystem. Blocks that represent | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | msdosfs_findslot(struct denode *dp, struct componentname *cnp) | ||||
int slotcount; | int slotcount; | ||||
int slotoffset = 0; | int slotoffset = 0; | ||||
int frcn; | int frcn; | ||||
u_long cluster; | u_long cluster; | ||||
int blkoff; | int blkoff; | ||||
u_int diroff; | u_int diroff; | ||||
int blsize; | int blsize; | ||||
struct msdosfsmount *pmp; | struct msdosfsmount *pmp; | ||||
struct buf *bp = 0; | struct m_buf *bp = 0; | ||||
struct direntry *dep; | struct direntry *dep; | ||||
u_char dosfilename[12]; | u_char dosfilename[12]; | ||||
int wincnt = 1; | int wincnt = 1; | ||||
int chksum = -1, chksum_ok; | int chksum = -1, chksum_ok; | ||||
int olddos = 1; | int olddos = 1; | ||||
pmp = dp->de_pmp; | pmp = dp->de_pmp; | ||||
Show All 38 Lines | msdosfs_findslot(struct denode *dp, struct componentname *cnp) | ||||
*/ | */ | ||||
diroff = 0; | diroff = 0; | ||||
for (frcn = 0; diroff < dp->de_FileSize; frcn++) { | for (frcn = 0; diroff < dp->de_FileSize; frcn++) { | ||||
if ((error = pcbmap(dp, frcn, &bn, &cluster, &blsize)) != 0) { | if ((error = pcbmap(dp, frcn, &bn, &cluster, &blsize)) != 0) { | ||||
if (error == E2BIG) | if (error == E2BIG) | ||||
break; | break; | ||||
return (error); | return (error); | ||||
} | } | ||||
error = bread(pmp->pm_devvp, bn, blsize, 0, &bp); | error = bread((void *)pmp->pm_devvp, bn, blsize, 0, &bp); | ||||
if (error) { | if (error) { | ||||
return (error); | return (error); | ||||
} | } | ||||
for (blkoff = 0; blkoff < blsize; | for (blkoff = 0; blkoff < blsize; | ||||
blkoff += sizeof(struct direntry), | blkoff += sizeof(struct direntry), | ||||
diroff += sizeof(struct direntry)) { | diroff += sizeof(struct direntry)) { | ||||
dep = (struct direntry *)(bp->b_data + blkoff); | dep = (struct direntry *)(bp->b_data + blkoff); | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
bad: | bad: | ||||
errno = error; | errno = error; | ||||
return NULL; | return NULL; | ||||
} | } | ||||
static int | static int | ||||
msdosfs_updatede(struct denode *dep) | msdosfs_updatede(struct denode *dep) | ||||
{ | { | ||||
struct buf *bp; | struct m_buf *bp; | ||||
struct direntry *dirp; | struct direntry *dirp; | ||||
int error; | int error; | ||||
dep->de_flag &= ~DE_MODIFIED; | dep->de_flag &= ~DE_MODIFIED; | ||||
error = readde(dep, &bp, &dirp); | error = m_readde(dep, &bp, &dirp); | ||||
if (error) | if (error) | ||||
return error; | return error; | ||||
DE_EXTERNALIZE(dirp, dep); | DE_EXTERNALIZE(dirp, dep); | ||||
error = bwrite(bp); | error = bwrite(bp); | ||||
return error; | return error; | ||||
} | } | ||||
/* | /* | ||||
* Write data to a file or directory. | * Write data to a file or directory. | ||||
*/ | */ | ||||
static int | static int | ||||
msdosfs_wfile(const char *path, struct denode *dep, fsnode *node) | msdosfs_wfile(const char *path, struct denode *dep, fsnode *node) | ||||
{ | { | ||||
int error, fd; | int error, fd; | ||||
size_t osize = dep->de_FileSize; | size_t osize = dep->de_FileSize; | ||||
struct stat *st = &node->inode->st; | struct stat *st = &node->inode->st; | ||||
size_t nsize, offs; | size_t nsize, offs; | ||||
struct msdosfsmount *pmp = dep->de_pmp; | struct msdosfsmount *pmp = dep->de_pmp; | ||||
struct buf *bp; | struct m_buf *bp; | ||||
char *dat; | char *dat; | ||||
u_long cn = 0; | u_long cn = 0; | ||||
error = 0; /* XXX: gcc/vax */ | error = 0; /* XXX: gcc/vax */ | ||||
MSDOSFS_DPRINTF(("%s(diroff %lu, dirclust %lu, startcluster %lu)\n", | MSDOSFS_DPRINTF(("%s(diroff %lu, dirclust %lu, startcluster %lu)\n", | ||||
__func__, dep->de_diroffset, dep->de_dirclust, | __func__, dep->de_diroffset, dep->de_dirclust, | ||||
dep->de_StartCluster)); | dep->de_StartCluster)); | ||||
if (st->st_size == 0) | if (st->st_size == 0) | ||||
Show All 36 Lines | for (offs = 0; offs < nsize;) { | ||||
if ((error = pcbmap(dep, cn++, &bn, NULL, &blsize)) != 0) { | if ((error = pcbmap(dep, cn++, &bn, NULL, &blsize)) != 0) { | ||||
MSDOSFS_DPRINTF(("%s: pcbmap %lu", | MSDOSFS_DPRINTF(("%s: pcbmap %lu", | ||||
__func__, (unsigned long)bn)); | __func__, (unsigned long)bn)); | ||||
goto out; | goto out; | ||||
} | } | ||||
MSDOSFS_DPRINTF(("%s(cn=%lu, bn=%llu, blsize=%d)\n", | MSDOSFS_DPRINTF(("%s(cn=%lu, bn=%llu, blsize=%d)\n", | ||||
__func__, cn, (unsigned long long)bn, blsize)); | __func__, cn, (unsigned long long)bn, blsize)); | ||||
if ((error = bread(pmp->pm_devvp, bn, blsize, 0, &bp)) != 0) { | if ((error = bread((void *)pmp->pm_devvp, bn, blsize, 0, | ||||
&bp)) != 0) { | |||||
MSDOSFS_DPRINTF(("bread %d\n", error)); | MSDOSFS_DPRINTF(("bread %d\n", error)); | ||||
goto out; | goto out; | ||||
} | } | ||||
cpsize = MIN((nsize - offs), blsize - on); | cpsize = MIN((nsize - offs), blsize - on); | ||||
memcpy(bp->b_data + on, dat + offs, cpsize); | memcpy(bp->b_data + on, dat + offs, cpsize); | ||||
bwrite(bp); | bwrite(bp); | ||||
offs += cpsize; | offs += cpsize; | ||||
} | } | ||||
Show All 35 Lines | |||||
msdosfs_mkdire(const char *path, struct denode *pdep, fsnode *node) { | msdosfs_mkdire(const char *path, struct denode *pdep, fsnode *node) { | ||||
struct denode ndirent; | struct denode ndirent; | ||||
struct denode *dep; | struct denode *dep; | ||||
struct componentname cn; | struct componentname cn; | ||||
struct msdosfsmount *pmp = pdep->de_pmp; | struct msdosfsmount *pmp = pdep->de_pmp; | ||||
int error; | int error; | ||||
u_long newcluster, pcl, bn; | u_long newcluster, pcl, bn; | ||||
struct direntry *denp; | struct direntry *denp; | ||||
struct buf *bp; | struct m_buf *bp; | ||||
cn.cn_nameptr = node->name; | cn.cn_nameptr = node->name; | ||||
cn.cn_namelen = strlen(node->name); | cn.cn_namelen = strlen(node->name); | ||||
/* | /* | ||||
* If this is the root directory and there is no space left we | * If this is the root directory and there is no space left we | ||||
* can't do anything. This is because the root directory can not | * can't do anything. This is because the root directory can not | ||||
* change size. | * change size. | ||||
*/ | */ | ||||
Show All 19 Lines | msdosfs_mkdire(const char *path, struct denode *pdep, fsnode *node) { | ||||
* Now fill the cluster with the "." and ".." entries. And write | * Now fill the cluster with the "." and ".." entries. And write | ||||
* the cluster to disk. This way it is there for the parent | * the cluster to disk. This way it is there for the parent | ||||
* directory to be pointing at if there were a crash. | * directory to be pointing at if there were a crash. | ||||
*/ | */ | ||||
bn = cntobn(pmp, newcluster); | bn = cntobn(pmp, newcluster); | ||||
MSDOSFS_DPRINTF(("%s(newcluster %lu, bn=%lu)\n", | MSDOSFS_DPRINTF(("%s(newcluster %lu, bn=%lu)\n", | ||||
__func__, newcluster, bn)); | __func__, newcluster, bn)); | ||||
/* always succeeds */ | /* always succeeds */ | ||||
bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0, 0); | bp = getblk((void *)pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0, 0); | ||||
memset(bp->b_data, 0, pmp->pm_bpcluster); | memset(bp->b_data, 0, pmp->pm_bpcluster); | ||||
memcpy(bp->b_data, &dosdirtemplate, sizeof dosdirtemplate); | memcpy(bp->b_data, &dosdirtemplate, sizeof dosdirtemplate); | ||||
denp = (struct direntry *)bp->b_data; | denp = (struct direntry *)bp->b_data; | ||||
putushort(denp[0].deStartCluster, newcluster); | putushort(denp[0].deStartCluster, newcluster); | ||||
putushort(denp[0].deCDate, ndirent.de_CDate); | putushort(denp[0].deCDate, ndirent.de_CDate); | ||||
putushort(denp[0].deCTime, ndirent.de_CTime); | putushort(denp[0].deCTime, ndirent.de_CTime); | ||||
denp[0].deCHundredth = ndirent.de_CHun; | denp[0].deCHundredth = ndirent.de_CHun; | ||||
putushort(denp[0].deADate, ndirent.de_ADate); | putushort(denp[0].deADate, ndirent.de_ADate); | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |