void init_block_cache(ext2fs_st *st) { int i; st->cache.blocks = st->cache.size / st->fsc.block_size; DBO(printf("ext2fs: block cache contains %d blocks\n",st->cache.blocks)); st->cache.block_cache = Heap$Malloc(st->heap, (sizeof(*st->cache.block_cache) * st->cache.blocks)); DBO(printf("ext2fs: block cache descriptors at [%p,%p)\n", st->cache.block_cache, (void *)st->cache.block_cache + (sizeof(*st->cache.block_cache) * st->cache.blocks) - 1)); MU_INIT(&st->cache.mu); CV_INIT(&st->cache.freebufs); LINK_INIT(&st->cache.bufs); for (i = 0; i < st->cache.blocks; i++) { struct buffer_head *buf; buf = &st->cache.block_cache[i]; LINK_ADD_TO_TAIL(&st->cache.bufs, buf); MU_INIT(&buf->mu); CV_INIT(&buf->cv); buf->st = st; buf->b_blocknr = 0; buf->state = buf_empty; buf->b_count = 0; buf->b_data = st->cache.buf+(i*st->fsc.block_size); buf->b_size = st->fsc.block_size; } }
bool IrisWind::SetActiveScaling (long lZoom) { ObjContainer OC (0, 0, 0, 0); ObjContainer oldOC = DBO().GetExtend(); // alten Ausschnitt merken bool fResult = false; Rectangle rcC (0, 0, 0, 0); for (int i = 0; i < 2; i++) { rcC = CanvasRect(); Rectangle rc; if (NULL != m_pDRO) { rc = ((DragRectangleObject *)m_pDRO) -> GetRect(); // Koordinaten kippen CoOrd tmpC = CoOrd(rc.Bottom() - rc.Top()); rc.Bottom() = CoOrd(rc.Top() - tmpC); } else rc = rcC; fResult = DBO().SetActiveScaling (lZoom, rc, rcC, OC); if (!fResult) break; // neuen Ausschnitt einstellen SetExtend (OC, lZoom); // bei Bedarf ScrollBars einblenden und initialisieren if (!InitWndScrollBars()) break; // einmal reicht, wenn Scrollbars nicht geändert wurden } // wenn Erfolgreich, dann alles neu einstellen if (fResult) { DELETE_OBJ (m_pDRO); // Übersichtsfenster bedienen if (OverViewCFlag && pOverView) pOverView -> SetActVP (CanvasRect()); actClip.Push (oldOC); // neu zeichnen LegendToRepaint = true; m_fRePaintFlag = true; RePaint(); } return fResult; }
// Anzeige des aktuellen Maßstabes -------------------------------------------- bool IrisWind :: SetMasstab (Rectangle R) { // wenn Rechteck entartet ist, dann nichts ändern if (R.Right() == R.Left()) return false; Rectangle CRc = CanvasRect(); if (CRc.Left() == CRc.Right()) return false; // Icon // Koordinaten in DB-Koordinaten umsetzen CoordTrans *pCT = DBO().pCT(); TX_ASSERT(NULL != pCT); if (NULL == pCT) return false; Point ptLO = R.UpperLeft(); Punkt LO = DCtoOC (ptLO); // Device --> Objekt Point ptRU = R.LowerRight(); Punkt RU = DCtoOC (ptRU); #if defined(_KOORD_ISDOUBLE) DoublePair P1 (LO.GetX(), LO.GetY()); DoublePair P2 (RU.GetX(), LO.GetY()); // über X-Koordinate berechnen #else double XLO, XRU, YLO, YRU; pCT() -> UnScale (LO, &XLO, &YLO); pCT() -> UnScale (RU, &XRU, &YRU); DoublePair P1 (XLO, YLO); DoublePair P2 (XRU, YLO); // über X-Koordinate berechnen #endif // _KOORD_ISDOUBLE double dX = 1.0; if (pCT -> hasDistEx()) { double dY = 1.0; pCT -> CoordTransDistanceEx (&P1, &P2, dX, dY); } else dX = pCT -> CoordTransDistance (&P1, &P2); DoublePair dimD; Dimension DotsPerMM (GetDotsPerMM (NULL, &dimD)); long M = (long)((fabs(dX) * 1000.0 * dimD.Width()) / ((double)(CRc.Right()-CRc.Left()))); // Maßstab muß positiv sein if (M < 0L) M = -M; if (0 != m_lFakeZoom) DEXN_ScalingChanged (m_lFakeZoom); else DEXN_ScalingChanged (M); return true; }
static IDCOffer_clp Mount_m(MountLocal_cl *self, IDCOffer_clp drive, uint32_t partition, MountLocal_Options options, Context_clp settings) { IDCOffer_clp res; ext2fs_st *st; Type_Any any; Heap_clp heap; struct inode *root = NULL; uint32_t blockcache_size = 1024*128; /* Size of blockcache in bytes */ CSClientStubMod_cl *stubmod_clp; TRC(printf("ext2fs: mount %d from %p\n", partition, drive)); /* It's probably a good idea to have a separate heap for the filesystem. For now let's just use Pvs(heap), but eventually create a stretch of our own. */ heap = Pvs(heap); if(!(st = Heap$Malloc(heap, sizeof(*st)))) { fprintf(stderr, "ext2fs: cannot allocate state.\n"); RAISE_MountLocal$Failure(); } /* Where is this declared? */ bzero(st, sizeof(*st)); /* Fill in the fields that we can initialise without accessing the filesystem */ st->heap = heap; st->entrymod = NAME_FIND("modules>EntryMod", EntryMod_clp); st->shmtransport = NAME_FIND("modules>ShmTransport", IDCTransport_clp); st->csidc = NAME_FIND("modules>CSIDCTransport", CSIDCTransport_clp); st->client.entry = Pvs(entry); /* It's not clearn how many entries we are going to require yet We probably want separate ones for the USDCallback and the FSClient offers. We need to arrange that the entry threads die properly when the FS is unmounted. */ /* Interpret mount flags */ st->fs.readonly = SET_IN(options,MountLocal_Option_ReadOnly); st->fs.debug = SET_IN(options,MountLocal_Option_Debug); /* Place the drive in the state. */ st->disk.partition = partition; st->disk.drive_offer = drive; st->disk.drive_binding = IDCOffer$Bind(drive, Pvs(gkpr), &any); st->disk.usddrive = NARROW(&any, USDDrive_clp); TRC(printf("ext2fs: state at [%p, %p]\n",st, (void *)st + sizeof(*st))); DBO(printf("ext2fs: debugging output is switched on\n")); /* Connect to the disk */ init_usd(st); /* We need a stretch shared between us and the USD to allow us to read and write metadata. We'll use this stretch as a cache of blocks read from the disk. Because we won't know the blocksize until we have managed to read the superblock, we'd better make this buffer a multiple of 8k long (8k is currently the maximum blocksize). */ st->cache.str = Gatekeeper$GetStretch(Pvs(gkpr), IDCOffer$PDID(drive), blockcache_size, SET_ELEM(Stretch_Right_Read) | SET_ELEM(Stretch_Right_Write), PAGE_WIDTH, PAGE_WIDTH); st->cache.buf = STR_RANGE(st->cache.str, &st->cache.size); TRC(printf("ext2fs: buf is %d bytes at %p\n", st->cache.size, st->cache.buf)); if (st->cache.size < blockcache_size) { printf("ext2fs: warning: couldn't allocate a large blockcache\n"); } /* Now we can get at the disk. Read the superblock, and calculate constants from it. */ if (!read_superblock(st)) { printf("ext2fs: couldn't read superblock\n"); shutdown_usd(st); RAISE_MountLocal$BadFS(MountLocal_Problem_BadSuperblock); } /* XXX should sanity check filesystem size with partition size */ TRC(printf("ext2fs: filesystem size %d blocks (%d phys)\n" " partition size %d blocks (%d phys)\n", st->superblock->s_blocks_count, PHYS_BLKS(st, st->superblock->s_blocks_count), LOGICAL_BLKS(st, st->disk.partition_size), st->disk.partition_size)); if (st->disk.partition_size < PHYS_BLKS(st, st->superblock->s_blocks_count)) { printf("WARNING - filesystem is larger than partition **********\n"); /* XXX should probably give up now */ } /* Now that we know the logical block size we can initialise the block cache */ init_block_cache(st); /* From this point on, all access to the filesystem should be done through the block cache. DON'T call logical_read, call bread instead. Remember to free blocks once you're finished with them. */ init_groups(st); if(!init_inodes(st)) { fprintf(stderr, "ext2fs: failed to initialise inode cache.\n"); shutdown_usd(st); RAISE_MountLocal$Failure(); } /* Checking this probably isn't a bad idea, but let's wait until later */ /* Ok, now we are capable of reading the root inode (I hope!) */ TRC(printf("ext2fs: checking root inode.\n")); root = get_inode(st, EXT2_ROOT_INO); if(!root) { fprintf(stderr, "ext2fs: failed to read root inode.\n"); shutdown_usd(st); RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot); } if(!S_ISDIR(root->i_mode)) { fprintf(stderr, "ext2fs: urk!\n" " inode %d does not refer to a directory\n", EXT2_ROOT_INO); shutdown_usd(st); RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot); } release_inode(st, root); /* *thinks* should probably do something about deallocating state if we fail, too. */ /* Initialise the list of clients */ LINK_INIT(&st->client.clients); /* We create a server for the local domain; it lives in the head of the list of clients. The call to CSIDCTransport$Offer() will set up client-side stubs for this domain and put them in the object table. */ create_client(st, &st->client.clients, NULL); /* Now we do all the export stuff */ CL_INIT(st->client.callback, &client_callback_ms, st); ANY_INIT(&any, Ext2_clp, &st->client.clients.cl); stubmod_clp = Heap$Malloc(st->heap, sizeof(*stubmod_clp)); CLP_INIT(stubmod_clp, &stubmod_ms, NULL); res = CSIDCTransport$Offer ( st->csidc, &any, FSClient_clp__code, stubmod_clp, &st->client.callback, /* XXX produces a warning */ st->heap, Pvs(gkpr), st->client.entry, &st->client.service); TRC(printf("ext2fs: offer at %p\n",res)); return res; }
static void init_usd(ext2fs_st *st) { USD_PartitionInfo info; Type_Any any; IDCOffer_clp partition; USDTRC(printf("ext2fs: Creating USDCallbacks\n")); { IDCTransport_clp shmt; IDCOffer_clp offer; IDCService_clp service; L1_st *l1_st; /* Get a heap writable by the USD domain */ st->disk.heap = Gatekeeper$GetHeap(Pvs(gkpr), IDCOffer$PDID(st->disk.drive_offer), 0, SET_ELEM(Stretch_Right_Read) | SET_ELEM(Stretch_Right_Write), True); /* The L1 callback executes there */ l1_st = Heap$Malloc(st->disk.heap, sizeof(L1_st)); l1_st->ext2fs_st = st; /* our state is read-only in USD domain */ st->disk.l1_callback = &(l1_st->l1_callback); CLP_INIT(st->disk.l1_callback, &L1_ms, l1_st); /* Create an offer for the L2 Callback */ CL_INIT(st->disk.l2_callback, &L2_ms, st); ANY_INIT(&any,USDCallback_clp, &st->disk.l2_callback); shmt = NAME_FIND ("modules>ShmTransport", IDCTransport_clp); offer = IDCTransport$Offer (shmt, &any, NULL, Pvs(heap), Pvs(gkpr), Pvs(entry), &service); /* Put it in the L1 callback's state record */ l1_st->l2_offer = offer; } USDTRC(printf("ext2fs: Getting USDCtl offer\n")); if(!USDDrive$GetPartition(st->disk.usddrive, st->disk.partition, st->disk.l1_callback, &partition)) { return; } USDTRC(printf("ext2fs: Binding to USDCtl offer\n")); /* Bind to the USD. Do this explicitly rather than through the object table; we don't want anybody else getting hold of this one. */ st->disk.binding = IDCOffer$Bind(partition, Pvs(gkpr), &any); st->disk.usdctl = NARROW(&any, USDCtl_clp); /* Find out some information */ USDTRC(printf("ext2fs: fetching partition info\n")); if(!USDDrive$GetPartitionInfo(st->disk.usddrive, st->disk.partition, &info)) { return; } st->disk.phys_block_size = info.blocksize; st->disk.partition_size = info.size; DBO(printf("ext2fs: blocksize %d, partition size %d blocks,\n" " partition type %s\n", st->disk.phys_block_size, st->disk.partition_size, info.osname)); FREE(info.osname); return; }