[haiku-commits] Change in haiku[master]: ufs2: Super block is detected successfully.

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 10 May 2020 10:55:08 +0000

From <suhelmehta@xxxxxxxxxxx>:

suhelmehta@xxxxxxxxxxx has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/2657 ;)


Change subject: ufs2: Super block is detected successfully.
......................................................................

ufs2: Super block is detected successfully.
---
M src/add-ons/kernel/file_systems/ufs2/Volume.cpp
M src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp
M src/add-ons/kernel/file_systems/ufs2/ufs2.h
3 files changed, 146 insertions(+), 56 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/57/2657/1

diff --git a/src/add-ons/kernel/file_systems/ufs2/Volume.cpp 
b/src/add-ons/kernel/file_systems/ufs2/Volume.cpp
index 5ac6afc..58410a7 100644
--- a/src/add-ons/kernel/file_systems/ufs2/Volume.cpp
+++ b/src/add-ons/kernel/file_systems/ufs2/Volume.cpp
@@ -8,11 +8,11 @@

 //#define TRACE_UFS2
 #ifdef TRACE_UFS2
-#      define TRACE(x...) dprintf("\33[34mufs2:\33[0m " x)
-#else
 #      define TRACE(x...) ;
+#else
+#      define TRACE(x...) dprintf("\33[34mufs2:\33[0m " x);
 #endif
-#   define ERROR(x...) dprintf("\33[34mexfat:\33[0m " x)
+#   define ERROR(x...) dprintf("\33[34mufs2:\33[0m " x)


 bool
@@ -33,18 +33,18 @@


 Volume::Volume(fs_volume *volume)
-    : fFSVolume(volume)
+       : fFSVolume(volume)
 {
        fFlags = 0;
        mutex_init(&fLock, "ufs2 volume");
-       TRACE("Volume::Volume() : Initialising volume");
+       TRACE("Volume::Volume() : Initialising volume\n");
 }


 Volume::~Volume()
 {
        mutex_destroy(&fLock);
-       TRACE("Volume::Destructor : Removing Volume");
+       TRACE("Volume::Destructor : Removing Volume\n");
 }


@@ -54,9 +54,10 @@
        if (read_pos(fd, UFS2_SUPER_BLOCK_OFFSET, superBlock,
                sizeof(ufs2_super_block)) != sizeof(ufs2_super_block))
                return B_IO_ERROR;
+

        if (!superBlock->IsValid()) {
-               ERROR("invalid superblock! Identify failed!!\n");
+               ERROR("Invalid superblock! Identify failed!!\n");
                return B_BAD_VALUE;
        }

@@ -78,7 +79,7 @@
                TRACE("Volume is read write\n");
        }

-       DeviceOpener opener(deviceName, (flags & B_MOUNT_READ_ONLY) != 0
+       DeviceOpener opener(deviceName, (flags & B_MOUNT_READ_ONLY) != 0
                                                                        ? 
O_RDONLY:O_RDWR);
        fDevice = opener.Device();
        if (fDevice < B_OK) {
diff --git a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp 
b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp
index 5e0adc1..295ede0 100644
--- a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp
+++ b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp
@@ -2,6 +2,8 @@
  * Copyright 2020 Suhel Mehta, mehtasuhel@xxxxxxxxx
  * All rights reserved. Distributed under the terms of the MIT License.
  */
+
+
 #include "system_dependencies.h"
 #include "ufs2.h"
 #include "Volume.h"
@@ -11,6 +13,7 @@
 #else
 #define TRACE(x...) ;
 #endif
+#   define ERROR(x...) dprintf("\33[34mufs2:\33[0m " x)


 struct identify_cookie
@@ -75,7 +78,21 @@
 ufs2_mount(fs_volume *_volume, const char *device, uint32 flags,
                  const char *args, ino_t *_rootID)
 {
-       return B_NOT_SUPPORTED;
+       TRACE("Tracing mount()");
+       Volume* volume = new(std::nothrow) Volume(_volume);
+       if (volume == NULL)
+               return B_NO_MEMORY;
+
+       _volume->private_volume = volume;
+       //_volume->ops = &gufs2VolumeOps;
+
+       status_t status = volume->Mount(device, flags);
+       if (status != B_OK){
+               ERROR("Failed mounting the volume. Error: %s\n", 
strerror(status));
+               delete volume;
+               return status;
+       }
+       return B_OK;
 }


diff --git a/src/add-ons/kernel/file_systems/ufs2/ufs2.h 
b/src/add-ons/kernel/file_systems/ufs2/ufs2.h
index 142f98d..25000ea 100644
--- a/src/add-ons/kernel/file_systems/ufs2/ufs2.h
+++ b/src/add-ons/kernel/file_systems/ufs2/ufs2.h
@@ -12,9 +12,43 @@
 #define UFS2_SUPER_BLOCK_OFFSET                65536
 #define MAXMNTLEN                                      512
 #define        MAXCSBUFS                                       32
+#define UFS2_MAXMNTLEN                         468
+#define UFS2_MAXCSBUFS                         31
+#define UFS2_MAXVOLLEN                         32
+#define        UFS2_NOCSPTRS                           28
+
+struct ufs2_csum {
+       uint32  cs_ndir;        /* number of directories */
+       uint32  cs_nbfree;      /* number of free blocks */
+       uint32  cs_nifree;      /* number of free inodes */
+       uint32  cs_nffree;      /* number of free frags */
+};
+
+
+struct ufs2_csum_total {
+       uint64  cs_ndir;        /* number of directories */
+       uint64  cs_nbfree;      /* number of free blocks */
+       uint64  cs_nifree;      /* number of free inodes */
+       uint64  cs_nffree;      /* number of free frags */
+       uint64   cs_numclusters;        /* number of free clusters */
+       uint64   cs_spare[3];   /* future expansion */
+};
+
+struct ufs2_timeval {
+       uint32  tv_sec;
+       uint32  tv_usec;
+};

 struct ufs2_super_block {
-       uint32  ufs2_link;              /* linked list of file systems */
+       union{
+               struct{
+                       uint32  ufs2_link;
+               }ufs_42;
+               struct{
+                       uint32  ufs2_state;
+               }ufs2_sun;
+               //ufs2_link
+       }ufs2_uo;               /* linked list of file systems */
        uint32  ufs2_rolled;            /* logging only: fs fully rolled */
        uint32  ufs2_sblkno;            /* addr of super-block in filesys */
        uint32  ufs2_cblkno;            /* offset of cyl-block in filesys */
@@ -22,18 +56,18 @@
        uint32  ufs2_dblkno;            /* offset of first data after cg */
        uint32  ufs2_cgoffset;          /* cylinder group offset in cylinder */
        uint32  ufs2_cgmask;            /* used to calc mod ufs2_ntrak */
-       uint64  ufs2_time;              /* last time written */
-       uint64  ufs2_size;              /* number of blocks in fs */
-       uint64  ufs2_dsize;             /* number of data blocks in fs */
+       uint32  ufs2_time;              /* last time written */
+       uint32  ufs2_size;              /* number of blocks in fs */
+       uint32  ufs2_dsize;             /* number of data blocks in fs */
        uint32  ufs2_ncg;                       /* number of cylinder groups */
        uint32  ufs2_bsize;             /* size of basic blocks in fs */
-       uint32  ufs2_fsize;             /* size of frag blocks in fs */
-       uint32  ufs2_frag;              /* number of frags in a block in fs */
+       uint32  ufs2_fsize;             /* size of fragments blocks in fs */
+       uint32  ufs2_frag;              /* number of fragments in a block in fs 
*/
        uint32  ufs2_minfree;           /* minimum percentage of free blocks */
        uint32  ufs2_rotdelay;          /* num of ms for optimal next block */
        uint32  ufs2_rps;                       /* disk revolutions per second 
*/
        /* these fields can be computed from the others */
-       uint32  ufs2_bmask;             /* ``blkoff'' calc of blk offsets */
+       uint32  ufs2_bmask;             //'blkoff' calc of blk offsets or blk 
address mask
        uint32  ufs2_fmask;             /* ``fragoff'' calc of frag offsets */
        uint32  ufs2_bshift;            /* ``lblkno'' calc of logical blkno */
        uint32  ufs2_fshift;            /* ``numfrags'' calc number of frags */
@@ -51,22 +85,20 @@
        uint32  ufs2_nspf;              /* value of NSPF */
        /* yet another configuration parameter */
        uint32  ufs2_optim;             /* optimization preference, see below */
-       /* these fields are derived from the hardware */
-       /* USL SVR4 compatibility */
-#ifdef _LITTLE_ENDIAN
-                       /*
-                        *       * USL SVR4 compatibility
-                        */
-                       uint32  ufs2_state;             /* file system state 
time stamp */
-#else
-               uint32  ufs2_npsect;            /* # sectors/track including 
spares */
-#endif
-       uint32 ufs2_si;                 /* summary info state - lufs only */
+       union{
+               struct{
+                       uint32  ufs2_npsect;            /* # sectors/track 
including spares */
+               }ufs2_sun;
+               struct{
+                       uint32  ufs2_state;
+               }ufs2_sunx86;
+       }ufs2_u1;
+       uint32 ufs2_interleave;         /* hardware sector interleave */
        uint32  ufs2_trackskew;         /* sector 0 skew, per track */
        uint32  ufs2_id[2];             /* file system id */
        /* sizes determined by number of cylinder groups and their sizes */
-       uint64  ufs2_csaddr;            /* blk addr of cyl grp summary area */
-       uint32          ufs2_cssize;            /* size of cyl grp summary area 
*/
+       uint32  ufs2_csaddr;            /* blk addr of cyl grp summary area */
+       uint32  ufs2_cssize;            /* size of cyl grp summary area */
        uint32  ufs2_cgsize;            /* cylinder group size */
        /* these fields are derived from the hardware */
        uint32  ufs2_ntrak;             /* tracks per cylinder */
@@ -78,39 +110,79 @@
        uint32  ufs2_cpg;                       /* cylinders per group */
        uint32  ufs2_ipg;                       /* inodes per group */
        uint32  ufs2_fpg;                       /* blocks per group * ufs2_frag 
*/
+       struct  ufs2_csum       ufs2_cstotal;
        /* these fields are cleared at mount time */
-       uint32  ufs2_fmod;              /* super block modified flag */
-       uint32  ufs2_clean;             /* file system state flag */
-       uint32  ufs2_ronly;             /* mounted read-only flag */
-       uint32  ufs2_flags;             /* largefiles flag, etc. */
-       uint32  ufs2_fsmnt[MAXMNTLEN];  /* name mounted on */
+       char    ufs2_fmod;              /* super block modified flag */
+       char    ufs2_clean;             /* file system state flag */
+       char    ufs2_ronly;             /* mounted read-only flag */
+       char    ufs2_flags;             /* largefiles flag, etc. */
+       union{
+               struct {
+                       char    ufs2_fsmnt[UFS2_MAXMNTLEN];/* name mounted on */
+                       uint32  ufs2_cgrotor;   /* last cg searched */
+                       uint32  ufs2_csp[UFS2_MAXCSBUFS];/*list of ufs2_cs info 
buffers */
+                       uint32  ufs2_maxcluster;
+                       uint32  ufs2_cpc;               /* cyl per cycle in 
postbl */
+                       uint16  ufs2_opostbl[16][8]; /* old rotation block list 
head */
+               } ufs2_u1;
+               struct {
+                       char    ufs2_fsmnt[UFS2_MAXMNTLEN];     /* name mounted 
on */
+                       unsigned char   ufs2_volname[UFS2_MAXVOLLEN]; /* volume 
name */
+                       uint64  ufs2_swuid;             /* system-wide uid   
712*/
+                       uint32  ufs2_pad;       /* due to alignment of fs_swuid 
*/
+                       uint32  ufs2_cgrotor;     /* last cg searched */
+                       uint32  ufs2_ocsp[UFS2_NOCSPTRS]; /*list of fs_cs info 
buffers */
+                       uint32  ufs2_contigdirs;/*# of contiguously allocated 
dirs */
+                       uint32  ufs2_csp;       /* cg summary info buffer for 
fs_cs */
+                       uint32  ufs2_maxcluster;
+                       uint32  ufs2_active;/* used by snapshots to track fs */
+                       uint32  ufs2_old_cpc;   /* cyl per cycle in postbl */
+                       uint32  ufs2_maxbsize;/*maximum blocking factor 
permitted */
+                       uint32  ufs2_sparecon64[31];/*old rotation block list 
head */
+                       uint64  ufs2_sblockloc; /* byte offset of standard 
superblock */
+                       struct  ufs2_csum_total fs_cstotal;/*cylinder summary 
information*/
+                       struct  ufs2_timeval    fs_time;                /* last 
time written */
+                       uint64  ufs2_size;              /* number of fragments 
in fs */
+                       uint64  ufs2_dsize;     /*fragements that can be stored 
in file data */
+                       uint64  ufs2_csaddr;    /* blk addr of cyl grp summary 
area */
+                       uint64  ufs2_pendingblocks;/* blocks in process of 
being freed */
+                       uint32  ufs2_pendinginodes;/*inodes in process of being 
freed */
+               } ufs2_u2;
+       }ufs2_u11;
+       union{
+               struct {
+                       uint32  fs_sparecon[53];/* reserved for future 
constants */
+                       uint32  fs_reclaim;
+                       uint32  fs_sparecon2[1];
+                       uint32  fs_state;       /* file system state time stamp 
*/
+                       uint32  fs_qbmask[2];   /* ~usb_bmask */
+                       uint32  fs_qfmask[2];   /* ~usb_fmask */
+               } ufs2_sun;
+               struct {
+                       uint32  fs_sparecon[53];/* reserved for future 
constants */
+                       uint32  fs_reclaim;
+                       uint32  fs_sparecon2[1];
+                       uint32  fs_npsect;      /* # sectors/track including 
spares */
+                       uint32  fs_qbmask[2];   /* ~usb_bmask */
+                       uint32  fs_qfmask[2];   /* ~usb_fmask */
+               } ufs2_sunx86;
+               struct {
+                       uint32  fs_sparecon[49];/* reserved for future 
constants */
+                       uint32  ufs2_contigsumsize;/* size of cluster summary 
array */
+                       uint32  fs_maxsymlinklen;/* max length of an internal 
symlink */
+                       uint32  fs_inodefmt;    /* format of on-disk inodes */
+                       uint32  fs_maxfilesize[2];      /* max representable 
file size */
+                       uint32  fs_qbmask[2];   /* ~usb_bmask */
+                       uint32  fs_qfmask[2];   /* ~usb_fmask */
+                       uint32  fs_state;       /* file system state time stamp 
*/
+               } ufs2_44;
+       }ufs2_u22;
        /* these fields retain the current block allocation info */
-       uint32  ufs2_cgrotor;           /* last cg searched */
-       union {                         /* ufs2_cs (csum) info */
-               uint32 ufs2_csp_pad[MAXCSBUFS];
-               struct csum *ufs2_csp;
-       } ufs2_u;
-       uint32  ufs2_cpc;                       /* cyl per cycle in postbl */
-       uint64  ufs2_opostbl[16][8];    /* old rotation block list head */
-       uint32  ufs2_sparecon[51];      /* reserved for future constants */
-       uint32  ufs2_version;           /* minor version of ufs */
-       uint32  ufs2_logbno;            /* block # of embedded log */
-       uint32  ufs2_reclaim;           /* reclaim open, deleted files */
-       uint32  ufs2_sparecon2;         /* reserved for future constant */
-#ifdef _LITTLE_ENDIAN
-       /* USL SVR4 compatibility */
-       uint32  ufs2_npsect;            /* # sectors/track including spares */
-#else
-       uint32  ufs2_state;             /* file system state time stamp */
-#endif
-       uint64  ufs2_qbmask;            /* ~ufs2_bmask - for use with quad size 
*/
-       uint64  ufs2_qfmask;            /* ~ufs2_fmask - for use with quad size 
*/
-       uint32  ufs2_postblformat;      /* format of positional layout tables */
        uint32  ufs2_nrpos;             /* number of rotaional positions */
        uint32  ufs2_postbloff;         /* (short) rotation block list head */
        uint32  ufs2_rotbloff;          /* (uchar_t) blocks for each rotation */
        uint32  ufs2_magic;             /* magic number */
-       uint32  ufs2_space[1];          /* list of blocks for each rotation */
+       char    ufs2_space[1];          /* list of blocks for each rotation */
        bool    IsValid();
 };


--
To view, visit https://review.haiku-os.org/c/haiku/+/2657
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ibba1a1f75a92dee8a2052a53a700b6008252db54
Gerrit-Change-Number: 2657
Gerrit-PatchSet: 1
Gerrit-Owner: suhelmehta@xxxxxxxxxxx
Gerrit-MessageType: newchange

Other related posts: