update 2026-11-20 19:53
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
// Import (texte lsblk, JSON lsblk -J, JSON exporté par l'outil) et export.
|
||||
// LVM / crypt / loop sont ignorés à l'import (RAID md géré).
|
||||
const PFX = '[\\s│├└─|`\\-]*';
|
||||
|
||||
function addImported(d, list) {
|
||||
list.forEach(x => {
|
||||
if (x === '[SWAP]') d.fstype = 'swap';
|
||||
else { d.mounts.push({ mp: x, subvol: '' }); if (!d.fstype) d.fstype = '?'; }
|
||||
});
|
||||
}
|
||||
|
||||
// un mdX apparaît sous chacun de ses membres : on ne le crée qu'une fois
|
||||
function raidFor(name, o, level, member) {
|
||||
let r = Object.values(S.devs).find(x => x.kind === 'raid' && x.name === name);
|
||||
const fresh = !r;
|
||||
if (fresh) r = mk({ ...o, kind: 'raid', name, level, members: [] });
|
||||
if (!r.members.includes(member.id)) r.members.push(member.id);
|
||||
member.fstype = 'linux_raid_member'; member.mounts = [];
|
||||
return fresh ? r : null;
|
||||
}
|
||||
|
||||
function fromText(t) {
|
||||
let disk = null, par = null, last = null;
|
||||
const re = new RegExp('^' + PFX + '(\\S+)\\s+(\\d+:\\d+)\\s+(\\d)\\s+([\\d.,]+[BKMGT]?)\\s+(\\d)\\s+(\\S+)\\s*(.*)$', 'i');
|
||||
const cont = new RegExp('^' + PFX + '(\\/\\S*|\\[SWAP\\])\\s*$');
|
||||
t.split('\n').forEach(l => {
|
||||
const m = l.replace(/\r$/, '').match(re);
|
||||
if (m) {
|
||||
const [, name, majmin, rm, size, ro, type, mt] = m;
|
||||
const o = { name, majmin, rm, ro, size: sz(size) }, rl = type.match(/^raid(\d+)$/i);
|
||||
last = null;
|
||||
if (type === 'disk') { disk = mk({ ...o, kind: 'disk' }); S.order.push(disk.id); last = par = disk; }
|
||||
else if (type === 'part' && disk) { last = par = mk({ ...o, kind: 'part', parent: disk.id }); disk.children.push(last.id); }
|
||||
else if (rl && par) last = raidFor(name, o, +rl[1], par);
|
||||
if (last && mt.trim()) addImported(last, [mt.trim()]);
|
||||
} else if (last) {
|
||||
const c = l.match(cont);
|
||||
if (c) addImported(last, [c[1]]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fromJSON(j) {
|
||||
const base = (b, kind) => {
|
||||
const mp = (b.mountpoints || [b.mountpoint]).filter(Boolean);
|
||||
const swap = mp.includes('[SWAP]');
|
||||
return { kind, name: b.name, majmin: b['maj:min'], size: sz(b.size), rm: +b.rm ? '1' : '0', ro: +b.ro ? '1' : '0',
|
||||
uuid: b.uuid || '', fstype: swap ? 'swap' : (b.fstype || (mp.length ? '?' : '')), label: b.label || '',
|
||||
used: b.fsused ? sz(b.fsused) : null, mounts: swap ? [] : mp.map(x => ({ mp: x, subvol: '' })) };
|
||||
};
|
||||
const raids = (b, m) => (b.children || []).forEach(c => { if (/^raid\d+$/i.test(c.type)) raidFor(c.name, base(c, 'raid'), +c.type.slice(4), m); });
|
||||
(j.blockdevices || []).forEach(b => {
|
||||
if (b.type !== 'disk') return;
|
||||
const d = mk(base(b, 'disk')); S.order.push(d.id); raids(b, d);
|
||||
(b.children || []).forEach(c => {
|
||||
if (c.type !== 'part') return;
|
||||
const p = mk({ ...base(c, 'part'), parent: d.id }); d.children.push(p.id); raids(c, p);
|
||||
});
|
||||
});
|
||||
groupPools();
|
||||
}
|
||||
|
||||
// btrfs multi-device : mêmes UUID -> un pool (profil inconnu), montages regroupés sur le membre principal
|
||||
function groupPools() {
|
||||
const g = {};
|
||||
Object.values(S.devs).forEach(d => { if (d.fstype === 'btrfs' && d.uuid) (g[d.uuid] = g[d.uuid] || []).push(d); });
|
||||
Object.values(g).filter(a => a.length > 1).forEach(a => {
|
||||
const id = 'pool' + uid(), prim = a.find(d => d.mounts.length) || a[0];
|
||||
S.pools[id] = { id, profile: '?', label: prim.label || '', usable: null, members: a.map(d => d.id), primary: prim.id };
|
||||
a.forEach(d => { d.pool = id; if (d !== prim) { prim.mounts.push(...d.mounts); d.mounts = []; } });
|
||||
});
|
||||
}
|
||||
|
||||
function importAny(text) {
|
||||
text = text.trim();
|
||||
if (!text) return 'Colle une sortie lsblk (texte ou JSON).';
|
||||
const bak = { devs: S.devs, order: S.order, pools: S.pools };
|
||||
S.devs = {}; S.order = []; S.pools = {};
|
||||
try {
|
||||
if (text[0] === '{') { const j = JSON.parse(text); if (j.devs) { S.devs = j.devs; S.order = j.order; S.pools = j.pools || {}; } else fromJSON(j); }
|
||||
else fromText(text);
|
||||
if (!S.order.length) throw 0;
|
||||
S.sel = S.order[0];
|
||||
return '';
|
||||
} catch (e) { S.devs = bak.devs; S.order = bak.order; S.pools = bak.pools; return 'Import impossible : format non reconnu.'; }
|
||||
}
|
||||
|
||||
function toText() {
|
||||
const R = rows(false); if (!R.length) return '';
|
||||
const w = Math.max(4, ...R.map(r => r.name.length)) + 1;
|
||||
const head = 'NAME'.padEnd(w) + 'MAJ:MIN'.padEnd(8) + 'RM'.padEnd(3) + 'SIZE'.padEnd(8) + 'RO'.padEnd(3) + 'TYPE'.padEnd(6) + 'MOUNTPOINTS';
|
||||
return [head, ...R.map(r => r.cont
|
||||
? r.name.padEnd(w + 28) + r.mount
|
||||
: r.name.padEnd(w) + r.d.majmin.padEnd(8) + r.d.rm.padEnd(3) + fmtLsblk(r.d.size).padEnd(8) + r.d.ro.padEnd(3) + typeOf(r.d).padEnd(6) + r.mount)].join('\n');
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// État + logique métier. Tailles en octets.
|
||||
const S = { devs: {}, order: [], pools: {}, sel: null };
|
||||
const U = { B: 1, K: 1024, M: 1024 ** 2, G: 1024 ** 3, T: 1024 ** 4 };
|
||||
const FS = ['ext4', 'btrfs', 'xfs', 'vfat', 'ntfs', 'zfs', 'swap'];
|
||||
let seq = 0;
|
||||
const uid = () => 'x' + (++seq) + Math.random().toString(36).slice(2, 6);
|
||||
|
||||
const unitOf = b => b >= U.T ? ['T', U.T] : b >= U.G ? ['G', U.G] : b >= U.M ? ['M', U.M] : ['K', U.K];
|
||||
const num = (x, d) => String(+x.toFixed(d)).replace('.', ',');
|
||||
const fmtIEC = b => { const [u, v] = unitOf(b); return num(b / v, 2) + ' ' + u + 'io'; };
|
||||
const fmtLsblk = b => { const [u, v] = unitOf(b); return num(b / v, 1) + u; };
|
||||
const sz = x => { // "463,2G" | 1234 | "1234" -> octets
|
||||
if (typeof x === 'number') return x;
|
||||
const m = String(x).match(/^([\d.,]+)\s*([BKMGT])?/i);
|
||||
return m ? parseFloat(m[1].replace(',', '.')) * U[(m[2] || 'B').toUpperCase()] : 0;
|
||||
};
|
||||
|
||||
const diskOf = d => d.kind === 'disk' ? d : d.kind === 'part' ? S.devs[d.parent] : null;
|
||||
const free = d => d.size - d.children.reduce((a, c) => a + S.devs[c].size, 0);
|
||||
|
||||
function mk(o) {
|
||||
const d = { id: uid(), fstype: '', label: '', used: null, mounts: [], children: [], rm: '0', ro: '0', ...o };
|
||||
S.devs[d.id] = d;
|
||||
return d;
|
||||
}
|
||||
const nextNvmeMinor = () => 1 + Math.max(-1, ...Object.values(S.devs).filter(d => d.majmin.startsWith('259:')).map(d => +d.majmin.split(':')[1]));
|
||||
|
||||
function addDisk(size, media) {
|
||||
const names = Object.values(S.devs).filter(d => d.kind === 'disk').map(d => d.name);
|
||||
let i = 0, name, majmin;
|
||||
if (media === 'nvme') { while (names.includes(`nvme${i}n1`)) i++; name = `nvme${i}n1`; majmin = '259:' + nextNvmeMinor(); }
|
||||
else { while (names.includes('sd' + String.fromCharCode(97 + i))) i++; name = 'sd' + String.fromCharCode(97 + i); majmin = '8:' + i * 16; }
|
||||
const d = mk({ kind: 'disk', name, size, majmin, rm: media === 'sd' ? '0' : '0' });
|
||||
S.order.push(d.id);
|
||||
return d;
|
||||
}
|
||||
|
||||
function addPart(disk, size, fstype) {
|
||||
if (disk.pool) dissolvePool(disk.pool);
|
||||
disk.fstype = ''; disk.mounts = []; // disque entier -> partitionné
|
||||
const n = 1 + Math.max(0, ...disk.children.map(c => parseInt(S.devs[c].name.match(/(\d+)$/)[1])));
|
||||
const nv = disk.name.startsWith('nvme');
|
||||
const base = +disk.majmin.split(':')[1];
|
||||
const p = mk({ kind: 'part', name: disk.name + (nv ? 'p' : '') + n, size, parent: disk.id, fstype,
|
||||
majmin: nv ? '259:' + nextNvmeMinor() : '8:' + (base + n) });
|
||||
disk.children.push(p.id);
|
||||
return p;
|
||||
}
|
||||
|
||||
function setFs(d, fstype, label) { d.fstype = fstype; d.label = label; d.mounts = []; d.used = null; }
|
||||
|
||||
function addMount(d, mp, subvol) {
|
||||
if (!d.fstype || d.fstype === 'swap') return 'Formate d\'abord (hors swap).';
|
||||
if (!mp.startsWith('/')) return 'Le point de montage doit commencer par /.';
|
||||
if (Object.values(S.devs).some(x => x.mounts.some(m => m.mp === mp))) return `${mp} est déjà monté.`;
|
||||
d.mounts.push({ mp, subvol });
|
||||
return '';
|
||||
}
|
||||
|
||||
const RAID_MIN = { 0: 2, 1: 2, 5: 3, 6: 4, 10: 4 };
|
||||
const typeOf = d => d.kind === 'raid' ? 'raid' + d.level : d.kind;
|
||||
const eligible = () => Object.values(S.devs).filter(d => (d.kind === 'part' || (d.kind === 'disk' && !d.children.length))
|
||||
&& !d.mounts.length && d.fstype !== 'swap' && d.fstype !== 'linux_raid_member' && !d.pool);
|
||||
|
||||
function addRaid(ids, level) {
|
||||
if (ids.length < RAID_MIN[level]) return `RAID ${level} : au moins ${RAID_MIN[level]} membres.`;
|
||||
if (level === 10 && ids.length % 2) return 'RAID 10 : nombre pair de membres.';
|
||||
const s = ids.map(i => S.devs[i].size), min = Math.min(...s), n = s.length;
|
||||
const size = level === 0 ? s.reduce((a, b) => a + b, 0) : level === 1 ? min : level === 5 ? min * (n - 1) : level === 6 ? min * (n - 2) : min * n / 2;
|
||||
const names = Object.values(S.devs).map(d => d.name); let i = 0;
|
||||
while (names.includes('md' + i)) i++;
|
||||
const r = mk({ kind: 'raid', name: 'md' + i, level, size, majmin: '9:' + i, members: ids });
|
||||
ids.forEach(m => { S.devs[m].fstype = 'linux_raid_member'; });
|
||||
S.sel = r.id;
|
||||
return '';
|
||||
}
|
||||
|
||||
const freeMembers = r => r.members.forEach(m => { const x = S.devs[m]; if (x && x.fstype === 'linux_raid_member') x.fstype = ''; });
|
||||
function dropRaids(id) {
|
||||
Object.values(S.devs).filter(r => r.kind === 'raid' && r.members.includes(id)).forEach(r => { freeMembers(r); delete S.devs[r.id]; });
|
||||
}
|
||||
|
||||
// Pool btrfs multi-périphériques : pas de mdX, tous les membres sont "btrfs",
|
||||
// le montage n'est affiché que sur le membre principal (comme lsblk).
|
||||
const BTRFS_MIN = { single: 2, raid0: 2, raid1: 2, raid1c3: 3, raid10: 4, raid5: 2, raid6: 3 };
|
||||
const host = d => d.pool ? S.devs[S.pools[d.pool].primary] : d;
|
||||
|
||||
function addPool(ids, profile, label) {
|
||||
if (ids.length < BTRFS_MIN[profile]) return `btrfs ${profile} : au moins ${BTRFS_MIN[profile]} périphériques.`;
|
||||
const s = ids.map(i => S.devs[i].size), sum = s.reduce((a, b) => a + b, 0), max = Math.max(...s);
|
||||
const usable = { single: sum, raid0: sum, raid1: Math.min(sum / 2, sum - max), raid1c3: Math.min(sum / 3, (sum - max) / 2),
|
||||
raid10: sum / 2, raid5: sum - max, raid6: sum - 2 * max }[profile];
|
||||
const id = 'pool' + uid();
|
||||
S.pools[id] = { id, profile, label, usable, members: ids, primary: ids[0] };
|
||||
ids.forEach(i => { const d = S.devs[i]; d.fstype = 'btrfs'; d.pool = id; d.label = label; d.mounts = []; d.used = null; });
|
||||
S.sel = ids[0];
|
||||
return '';
|
||||
}
|
||||
|
||||
function dissolvePool(pid) {
|
||||
const p = S.pools[pid]; if (!p) return;
|
||||
p.members.forEach(m => { const d = S.devs[m]; if (d) { d.fstype = ''; d.pool = null; d.label = ''; d.mounts = []; } });
|
||||
delete S.pools[pid];
|
||||
}
|
||||
function dropPool(id) { const d = S.devs[id]; if (d && d.pool) dissolvePool(d.pool); }
|
||||
|
||||
function delDev(id) {
|
||||
const d = S.devs[id]; if (!d) return;
|
||||
if (d.kind === 'raid') freeMembers(d); else { dropRaids(id); dropPool(id); }
|
||||
if (d.kind === 'disk') { d.children.forEach(c => { dropRaids(c); dropPool(c); delete S.devs[c]; }); S.order = S.order.filter(x => x !== id); }
|
||||
else if (d.kind === 'part' && S.devs[d.parent]) S.devs[d.parent].children = S.devs[d.parent].children.filter(x => x !== id);
|
||||
delete S.devs[id];
|
||||
S.sel = null;
|
||||
}
|
||||
|
||||
// Lignes de l'arbre lsblk (1 ligne par point de montage, comme le vrai lsblk)
|
||||
// all=true : un pool btrfs affiche ses montages sur chaque membre (all=false : comme le vrai lsblk, membre principal seul)
|
||||
const mountTexts = (d, all) => d.fstype === 'swap' ? ['[SWAP]'] : (all ? host(d) : d).mounts.map(m => m.mp);
|
||||
function rows(all = true) {
|
||||
const out = [];
|
||||
const add = (d, name, pfx) => {
|
||||
const m = mountTexts(d, all);
|
||||
out.push({ d, name, mount: m[0] || '' });
|
||||
m.slice(1).forEach(x => out.push({ d, name: pfx, mount: x, cont: true }));
|
||||
};
|
||||
const raids = (d, ind) => Object.values(S.devs).filter(r => r.kind === 'raid' && r.members.includes(d.id)).forEach(r => add(r, ind + '└─' + r.name, ''));
|
||||
S.order.forEach(id => {
|
||||
const d = S.devs[id]; add(d, d.name, ''); raids(d, '');
|
||||
d.children.forEach((c, i) => {
|
||||
const last = i === d.children.length - 1, p = S.devs[c];
|
||||
add(p, (last ? '└─' : '├─') + p.name, last ? '' : '│'); raids(p, last ? ' ' : '│ ');
|
||||
});
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
const save = () => { try { localStorage.setItem('lsblk-mgr', JSON.stringify({ devs: S.devs, order: S.order, pools: S.pools })); } catch (e) {} };
|
||||
const load = () => { try { const j = JSON.parse(localStorage.getItem('lsblk-mgr')); if (j && j.devs) { S.devs = j.devs; S.order = j.order; S.pools = j.pools || {}; S.sel = S.order[0] || null; } } catch (e) {} };
|
||||
@@ -0,0 +1,119 @@
|
||||
const $ = id => document.getElementById(id);
|
||||
const esc = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
||||
const COL = { ext4: '#8be9fd', btrfs: '#bd93f9', xfs: '#ffb86c', vfat: '#ff79c6', ntfs: '#f1fa8c', zfs: '#50fa7b', swap: '#ff5555', '?': '#a0a4bd', linux_raid_member: '#c9a0ff', '': '#6272a4' };
|
||||
const fsLabel = f => f === '?' ? 'inconnu' : f === 'linux_raid_member' ? 'membre RAID' : f || 'non formaté';
|
||||
const colorOf = d => COL[d.fstype] || COL['?'];
|
||||
const fsName = d => fsLabel(d.fstype);
|
||||
const sel = () => S.devs[S.sel];
|
||||
let err = '';
|
||||
|
||||
const poolTag = p => p.pool && S.pools[p.pool] ? ` <small class="dim">pool ${S.pools[p.pool].profile === '?' ? '' : S.pools[p.pool].profile + ' '}×${S.pools[p.pool].members.length}</small>` : '';
|
||||
const mountHtml = p => p.fstype === 'swap' ? '[SWAP]'
|
||||
: host(p).mounts.map(m => esc(m.mp) + (m.subvol ? ` <small class="dim">(subvol=${esc(m.subvol)})</small>` : '')).join('<br>');
|
||||
|
||||
function renderTree() {
|
||||
const R = rows();
|
||||
$('tree').innerHTML = !R.length ? '<span class="dim">rien à afficher — ajoute un disque ou importe un lsblk</span>' :
|
||||
'<div class="row head"><span>NAME</span><span>MAJ:MIN</span><span>RM</span><span>SIZE</span><span>RO</span><span>TYPE</span><span>MOUNTPOINTS</span></div>' +
|
||||
R.map(r => `<div class="row ${r.d.id === S.sel ? 'sel' : ''}" data-act="sel" data-id="${r.d.id}"><span class="n-${r.d.kind}">${esc(r.name)}</span>` +
|
||||
(r.cont ? '<span></span>'.repeat(5)
|
||||
: `<span class="dim">${r.d.majmin}</span><span class="dim">${r.d.rm}</span><span>${fmtLsblk(r.d.size)}</span><span class="dim">${r.d.ro}</span><span class="or">${typeOf(r.d)}</span>`) +
|
||||
`<span class="${r.mount === '[SWAP]' ? 'sw' : 'mt'}">${esc(r.mount)}</span></div>`).join('');
|
||||
}
|
||||
|
||||
function renderDetail() {
|
||||
const d = sel();
|
||||
if (!d) { $('detail').innerHTML = '<span class="dim">clique un disque ou une partition</span>'; return; }
|
||||
if (d.kind === 'raid') {
|
||||
$('detail').innerHTML = `<div class="info"><b>${esc(d.name)}</b> · RAID ${d.level} · ${fmtIEC(d.size)} · ${d.majmin} · ${fsName(d)} · <span class="mt">${mountHtml(d)}</span></div>` +
|
||||
'<table><tr><th>Membre</th><th>Taille</th></tr>' + d.members.map(m => `<tr data-act="sel" data-id="${m}"><td>${esc(S.devs[m].name)}</td><td>${fmtIEC(S.devs[m].size)}</td></tr>`).join('') + '</table>';
|
||||
return;
|
||||
}
|
||||
const dk = diskOf(d), fr = free(dk);
|
||||
const parts = dk.children.length ? dk.children.map(c => S.devs[c]) : (dk.fstype ? [dk] : []);
|
||||
const pct = s => s / dk.size * 100;
|
||||
const gauge = parts.map(p => `<div class="seg ${p.id === S.sel ? 'on' : ''}" data-act="sel" data-id="${p.id}" style="flex:${p.size} 1 0;background:${colorOf(p)}" title="${esc(p.name)} · ${fsName(p)} · ${fmtIEC(p.size)}">${pct(p.size) > 7 ? esc(p.name) : ''}</div>`).join('') +
|
||||
(fr > 0 ? `<div class="seg free" style="flex:${fr} 1 0" title="non alloué · ${fmtIEC(fr)}">${pct(fr) > 7 ? 'libre' : ''}</div>` : '');
|
||||
const fss = [...new Set(parts.map(p => p.fstype))];
|
||||
const legend = fss.map(f => `<span><i style="background:${COL[f] || COL['?']}"></i>${fsLabel(f)}</span>`).join('') + (fr > 0 ? '<span><i style="background:#34374a"></i>non alloué</span>' : '');
|
||||
$('detail').innerHTML =
|
||||
`<div class="info"><b>${esc(dk.name)}</b> · ${fmtIEC(dk.size)} · ${dk.majmin} · ${dk.children.length} partition(s) · <b>${fmtIEC(fr)}</b> libre</div>` +
|
||||
`<div class="gauge">${gauge}</div><div class="legend">${legend}</div>` +
|
||||
(parts.length ? '<table><tr><th>Partition</th><th>FS</th><th>Montages</th><th>Étiquette</th><th>Taille</th><th>Utilisé</th></tr>' +
|
||||
parts.map(p => `<tr class="${p.id === S.sel ? 'sel' : ''}" data-act="sel" data-id="${p.id}"><td>${esc(p.name)}</td><td><span class="dot" style="background:${colorOf(p)}"></span>${fsName(p)}${poolTag(p)}</td><td class="mt">${mountHtml(p)}</td><td>${esc(p.label)}</td><td>${fmtIEC(p.size)}</td><td>${p.used != null ? fmtIEC(p.used) : '—'}</td></tr>`).join('') + '</table>' : '');
|
||||
}
|
||||
|
||||
function renderDevPanel() {
|
||||
const d = sel();
|
||||
if (!d) { $('devPanel').innerHTML = '<p class="hint">Aucune sélection.</p>'; return; }
|
||||
const pool = d.pool && S.pools[d.pool], h = host(d);
|
||||
const canFs = !pool && !(d.kind === 'disk' && d.children.length);
|
||||
$('devPanel').innerHTML = `<div class="info"><b>${esc(d.name)}</b> · ${fmtIEC(d.size)} · ${fsName(d)}</div>` +
|
||||
(pool ? `<p class="hint">Pool btrfs <b>${esc(pool.label || '(sans étiquette)')}</b> · profil ${pool.profile === '?' ? 'inconnu' : pool.profile} · ${pool.members.length} périphériques${pool.usable != null ? ' · utilisable ≈ ' + fmtIEC(pool.usable) : ''}<br>Membres : ${pool.members.map(m => esc(S.devs[m].name)).join(', ')}<br>Montages portés par <b>${esc(h.name)}</b>.</p><button class="ghost" data-act="unpool">Dissoudre le pool</button>` : '') +
|
||||
(canFs ? `<label>Système de fichiers</label><select id="fsSel">${['', ...FS].map(f => `<option value="${f}" ${f === d.fstype ? 'selected' : ''}>${f || '— non formaté —'}</option>`).join('')}</select>
|
||||
<label>Étiquette</label><input id="lblIn" value="${esc(d.label)}"><button data-act="fmt">Formater (efface les montages)</button>` : pool ? '' : '<p class="hint">Disque partitionné : sélectionne une partition pour la formater/monter.</p>') +
|
||||
(h.fstype && h.fstype !== 'swap' ? `<label>Points de montage (${h.mounts.length})</label>` +
|
||||
h.mounts.map((m, i) => `<div class="mnt"><span>${esc(m.mp)}${m.subvol ? ` <small class="dim">(subvol=${esc(m.subvol)})</small>` : ''}</span><button data-act="umount" data-i="${i}">✕</button></div>`).join('') +
|
||||
`<div class="r2" style="grid-template-columns:1fr 1fr;margin-top:6px"><input id="mpIn" placeholder="/home"><input id="svIn" placeholder="sous-volume (@home)"></div><button data-act="mount">+ Ajouter un montage</button>` : '') +
|
||||
'<button class="ghost" data-act="del">Supprimer</button>';
|
||||
}
|
||||
|
||||
function render() {
|
||||
save();
|
||||
const d = sel(), dk = d && diskOf(d);
|
||||
$('pTarget').textContent = dk ? `sur ${dk.name} — libre : ${fmtIEC(free(dk))}` : 'sélectionne un disque ou une de ses partitions';
|
||||
$('err').textContent = err;
|
||||
renderTree(); renderDetail(); renderDevPanel();
|
||||
const el = eligible();
|
||||
$('raidPool').innerHTML = el.length ? el.map(x => `<label class="chk"><input type="checkbox" class="rchk" value="${x.id}">${esc(x.name)} · ${fmtIEC(x.size)}</label>`).join('') : '<p class="hint">aucun périphérique libre (non monté, hors RAID)</p>';
|
||||
}
|
||||
|
||||
function download(name, text) {
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(new Blob([text], { type: 'application/json' }));
|
||||
a.download = name; a.click(); URL.revokeObjectURL(a.href);
|
||||
}
|
||||
|
||||
const ACT = {
|
||||
sel: t => { S.sel = t.dataset.id; },
|
||||
addDisk: () => {
|
||||
const v = +$('dSize').value, u = $('dUnit').value;
|
||||
if (!(v > 0)) { err = 'Taille invalide.'; return; }
|
||||
const mult = $('dDec').checked ? { K: 1e3, M: 1e6, G: 1e9, T: 1e12 }[u] : U[u];
|
||||
S.sel = addDisk(Math.round(v * mult), $('dMedia').value).id;
|
||||
},
|
||||
addPart: () => {
|
||||
const d = sel(), dk = d && diskOf(d);
|
||||
if (!dk) { err = 'Sélectionne un disque.'; return; }
|
||||
const b = Math.round(+$('pSize').value * U[$('pUnit').value]);
|
||||
if (!(b > 0)) { err = 'Taille invalide.'; return; }
|
||||
if (b > free(dk)) { err = `Espace insuffisant (libre : ${fmtIEC(free(dk))}).`; return; }
|
||||
S.sel = addPart(dk, b, $('pFs').value).id;
|
||||
},
|
||||
fmt: () => { const d = sel(); if (d && !d.children.length && !d.pool) setFs(d, $('fsSel').value, $('lblIn').value.trim()); },
|
||||
mount: () => { const d = sel(); if (d) err = addMount(host(d), $('mpIn').value.trim(), $('svIn').value.trim()); },
|
||||
umount: t => { const d = sel(); if (d) host(d).mounts.splice(+t.dataset.i, 1); },
|
||||
del: () => { const d = sel(); if (d && confirm(`Supprimer ${d.name}${d.children.length ? ' et ses partitions' : ''} ?`)) delDev(d.id); },
|
||||
raid: () => {
|
||||
const ids = [...document.querySelectorAll('.rchk:checked')].map(c => c.value), [k, v] = $('rLevel').value.split(':');
|
||||
err = k === 'md' ? addRaid(ids, +v) : addPool(ids, v, $('rLabel').value.trim());
|
||||
},
|
||||
unpool: () => { const d = sel(); if (d && d.pool) dissolvePool(d.pool); },
|
||||
reset: () => { if (confirm('Tout réinitialiser ?')) { S.devs = {}; S.order = []; S.pools = {}; S.sel = null; } },
|
||||
imp: () => { if (!S.order.length || confirm('Remplacer la configuration actuelle ?')) err = importAny($('impTxt').value); },
|
||||
exTxt: () => { $('expTxt').value = toText(); },
|
||||
copy: () => { navigator.clipboard && navigator.clipboard.writeText($('expTxt').value); },
|
||||
exJson: () => download('lsblk-manager.json', JSON.stringify({ devs: S.devs, order: S.order, pools: S.pools }, null, 2)),
|
||||
};
|
||||
|
||||
document.addEventListener('click', e => {
|
||||
const t = e.target.closest('[data-act]'); if (!t) return;
|
||||
err = ''; ACT[t.dataset.act](t); render();
|
||||
});
|
||||
$('impFile').addEventListener('change', e => {
|
||||
const f = e.target.files[0]; if (!f) return;
|
||||
f.text().then(txt => { if (!S.order.length || confirm('Remplacer la configuration actuelle ?')) { err = importAny(txt); } render(); e.target.value = ''; });
|
||||
});
|
||||
|
||||
$('pFs').innerHTML = ['', ...FS].map(f => `<option value="${f}">${f || '— non formaté —'}</option>`).join('');
|
||||
load(); render();
|
||||
Reference in New Issue
Block a user