mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-05-28 17:11:20 +02:00
feat(sd): add filesystem type selection for SD card format (exFAT/FAT32)
Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
@@ -67,6 +67,8 @@ interface StorageFilePageProps {
|
||||
onUnmountSDStorage?: () => void;
|
||||
onFormatSDStorage?: () => void;
|
||||
onMountSDStorage?: () => void;
|
||||
fsType?: 'exfat' | 'fat32';
|
||||
onFsTypeChange?: (value: 'exfat' | 'fat32') => void;
|
||||
}
|
||||
|
||||
export const FileManager: React.FC<StorageFilePageProps> = ({
|
||||
@@ -79,6 +81,8 @@ export const FileManager: React.FC<StorageFilePageProps> = ({
|
||||
onResetSDStorage,
|
||||
onUnmountSDStorage,
|
||||
onFormatSDStorage,
|
||||
fsType,
|
||||
onFsTypeChange,
|
||||
}) => {
|
||||
const { $at } = useReactAt();
|
||||
|
||||
@@ -251,6 +255,18 @@ export const FileManager: React.FC<StorageFilePageProps> = ({
|
||||
</p>
|
||||
{sdMountStatus !== "none" && (
|
||||
<div className="pt-2">
|
||||
<div className="w-full space-y-2">
|
||||
<p className="w-full text-left text-xs text-slate-700 dark:text-slate-300">
|
||||
{$at("Choose the file system for MicroSD formatting")}
|
||||
</p>
|
||||
<select
|
||||
value={fsType || "fat32"}
|
||||
onChange={(e) => onFsTypeChange?.(e.target.value as 'exfat' | 'fat32')}
|
||||
style={{ width: "100%", padding: "8px", borderRadius: "4px" }}
|
||||
>
|
||||
<option value="fat32">FAT32</option>
|
||||
<option value="exfat">exFAT</option>
|
||||
</select>
|
||||
<AntdButton
|
||||
disabled={loading}
|
||||
danger={true}
|
||||
@@ -258,9 +274,10 @@ export const FileManager: React.FC<StorageFilePageProps> = ({
|
||||
onClick={handleFormatWrapper}
|
||||
className="w-full text-red-500 dark:text-red-400 border-red-200 dark:border-red-800"
|
||||
>
|
||||
{$at("Format MicroSD Card")}
|
||||
{$at("Format MicroSD Card")} ({(fsType || "fat32")})
|
||||
</AntdButton>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -318,6 +335,8 @@ export const FileManager: React.FC<StorageFilePageProps> = ({
|
||||
onUnmountSDStorage={handleUnmountWrapper}
|
||||
onFormatSDStorage={handleFormatWrapper}
|
||||
syncStorage={syncStorage}
|
||||
fsType={fsType}
|
||||
onFsTypeChange={onFsTypeChange}
|
||||
/>
|
||||
|
||||
{uploadFile ? (
|
||||
@@ -504,6 +523,8 @@ interface ActionButtonsSectionProps {
|
||||
onUnmountSDStorage?: () => void;
|
||||
onFormatSDStorage?: () => void;
|
||||
syncStorage: () => void;
|
||||
fsType?: 'exfat' | 'fat32';
|
||||
onFsTypeChange?: (value: 'exfat' | 'fat32') => void;
|
||||
}
|
||||
|
||||
const ActionButtonsSection: React.FC<ActionButtonsSectionProps> = ({
|
||||
@@ -512,21 +533,36 @@ const ActionButtonsSection: React.FC<ActionButtonsSectionProps> = ({
|
||||
showSDManagement,
|
||||
onUnmountSDStorage,
|
||||
onFormatSDStorage,
|
||||
fsType,
|
||||
onFsTypeChange,
|
||||
}) => {
|
||||
const { $at } = useReactAt();
|
||||
|
||||
if (mediaType === "sd" && showSDManagement) {
|
||||
return (
|
||||
<div className="flex animate-fadeIn justify-between gap-2 opacity-0"
|
||||
<div className="animate-fadeIn space-y-2 opacity-0"
|
||||
style={{ animationDuration: "0.7s", animationDelay: "0.25s" }}
|
||||
>
|
||||
<div className="w-full space-y-2">
|
||||
<p className="w-full text-left text-xs text-slate-700 dark:text-slate-300">
|
||||
{$at("Choose the file system for MicroSD formatting")}
|
||||
</p>
|
||||
<select
|
||||
value={fsType || "fat32"}
|
||||
onChange={(e) => onFsTypeChange?.(e.target.value as 'exfat' | 'fat32')}
|
||||
style={{ width: "100%", padding: "8px", borderRadius: "4px" }}
|
||||
>
|
||||
<option value="fat32">FAT32</option>
|
||||
<option value="exfat">exFAT</option>
|
||||
</select>
|
||||
<AntdButton
|
||||
disabled={loading}
|
||||
type="primary"
|
||||
danger={true}
|
||||
onClick={onFormatSDStorage}
|
||||
className="w-full text-red-500 dark:text-red-400 border-red-200 dark:border-red-800"
|
||||
>{$at("Format MicroSD Card")}</AntdButton>
|
||||
>{$at("Format MicroSD Card")} ({(fsType || "fat32")})</AntdButton>
|
||||
</div>
|
||||
<AntdButton
|
||||
disabled={loading}
|
||||
type="primary"
|
||||
|
||||
@@ -9,6 +9,7 @@ export default function SDFilePage() {
|
||||
const { $at } = useReactAt();
|
||||
const [send] = useJsonRpc();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [fsType, setFsType] = useState<'exfat' | 'fat32'>('fat32');
|
||||
|
||||
const handleResetSDStorage = async () => {
|
||||
setLoading(true);
|
||||
@@ -37,11 +38,11 @@ export default function SDFilePage() {
|
||||
};
|
||||
|
||||
const handleFormatSDStorage = async () => {
|
||||
if (!window.confirm($at("Formatting the SD card will erase all data. Continue?"))) {
|
||||
if (!window.confirm($at(`Formatting the SD card as ${fsType.toUpperCase()} will erase all data. Continue?`))) {
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
send("formatSDStorage", { confirm: true }, res => {
|
||||
send("formatSDStorage", { confirm: true, fsType }, res => {
|
||||
if ("error" in res) {
|
||||
notifications.error(res.error.data || res.error.message);
|
||||
setLoading(false);
|
||||
@@ -54,6 +55,7 @@ export default function SDFilePage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<FileManager
|
||||
mediaType="sd"
|
||||
returnTo="/sd-files"
|
||||
@@ -65,6 +67,9 @@ export default function SDFilePage() {
|
||||
onResetSDStorage={handleResetSDStorage}
|
||||
onUnmountSDStorage={handleUnmountSDStorage}
|
||||
onFormatSDStorage={handleFormatSDStorage}
|
||||
fsType={fsType}
|
||||
onFsTypeChange={setFsType}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ export default function ImageManager({
|
||||
const [sdMountStatus, setSDMountStatus] = useState<"ok" | "none" | "fail" | null>(storageType === 'sd' ? null : 'ok');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [uploadFile, setUploadFile] = useState<string | null>(null);
|
||||
const [fsType, setFsType] = useState<'exfat' | 'fat32'>('fat32');
|
||||
const filesPerPage = 5;
|
||||
|
||||
const percentageUsed = useMemo(() => {
|
||||
@@ -170,7 +171,7 @@ export default function ImageManager({
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
send("formatSDStorage", { confirm: true }, res => {
|
||||
send("formatSDStorage", { confirm: true, fsType }, res => {
|
||||
if ("error" in res) {
|
||||
notifications.error(res.error.data || res.error.message);
|
||||
setLoading(false);
|
||||
@@ -347,6 +348,18 @@ export default function ImageManager({
|
||||
</p>
|
||||
{sdMountStatus !== "none" && (
|
||||
<div className="pt-2">
|
||||
<div className="mx-auto w-full max-w-[360px] space-y-2">
|
||||
<p className="w-full text-left text-xs text-slate-700 dark:text-slate-300">
|
||||
{$at("Choose the file system for MicroSD formatting")}
|
||||
</p>
|
||||
<select
|
||||
value={fsType}
|
||||
onChange={(e) => setFsType(e.target.value as 'exfat' | 'fat32')}
|
||||
style={{ width: "100%", padding: "8px", borderRadius: "4px" }}
|
||||
>
|
||||
<option value="fat32">FAT32</option>
|
||||
<option value="exfat">exFAT</option>
|
||||
</select>
|
||||
<AntdButton
|
||||
disabled={loading}
|
||||
danger={true}
|
||||
@@ -354,9 +367,10 @@ export default function ImageManager({
|
||||
onClick={handleFormatSDStorage}
|
||||
className="w-full text-red-500 dark:text-red-400 border-red-200 dark:border-red-800"
|
||||
>
|
||||
{$at("Format MicroSD Card")}
|
||||
{$at("Format MicroSD Card")} ({fsType})
|
||||
</AntdButton>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -493,16 +507,29 @@ export default function ImageManager({
|
||||
</div>
|
||||
|
||||
{unmountApi && storageType === 'sd' && (
|
||||
<div className="flex animate-fadeIn justify-between gap-2 opacity-0"
|
||||
<div className="animate-fadeIn space-y-2 opacity-0"
|
||||
style={{ animationDuration: "0.7s", animationDelay: "0.25s" }}
|
||||
>
|
||||
<div className="w-full space-y-2">
|
||||
<p className="w-full text-left text-xs text-slate-700 dark:text-slate-300">
|
||||
{$at("Choose the file system for MicroSD formatting")}
|
||||
</p>
|
||||
<select
|
||||
value={fsType}
|
||||
onChange={(e) => setFsType(e.target.value as 'exfat' | 'fat32')}
|
||||
style={{ width: "100%", padding: "8px", borderRadius: "4px" }}
|
||||
>
|
||||
<option value="fat32">FAT32</option>
|
||||
<option value="exfat">exFAT</option>
|
||||
</select>
|
||||
<AntdButton
|
||||
disabled={loading}
|
||||
type="primary"
|
||||
danger={true}
|
||||
onClick={handleFormatSDStorage}
|
||||
className="w-full text-red-500 dark:text-red-400 border-red-200 dark:border-red-800"
|
||||
>{$at("Format MicroSD Card")}</AntdButton>
|
||||
>{$at("Format MicroSD Card")} ({fsType})</AntdButton>
|
||||
</div>
|
||||
<AntdButton
|
||||
disabled={loading}
|
||||
type="primary"
|
||||
|
||||
@@ -782,7 +782,11 @@ func rpcUnmountSDStorage() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func rpcFormatSDStorage(confirm bool) error {
|
||||
func rpcFormatSDStorage(confirm bool, fsType string) error {
|
||||
validFsTypes := map[string]bool{"exfat": true, "fat32": true}
|
||||
if !validFsTypes[fsType] {
|
||||
fsType = "fat32"
|
||||
}
|
||||
if !confirm {
|
||||
return fmt.Errorf("format not confirmed")
|
||||
}
|
||||
@@ -864,7 +868,13 @@ func rpcFormatSDStorage(confirm bool) error {
|
||||
return fmt.Errorf("failed to stat sd partition: %w", err)
|
||||
}
|
||||
|
||||
mkfsOut, mkfsErr := exec.Command("mkfs.vfat", "-F", "32", "-n", "PICOKVM", "/dev/mmcblk1p1").CombinedOutput()
|
||||
var mkfsCmd *exec.Cmd
|
||||
if fsType == "exfat" {
|
||||
mkfsCmd = exec.Command("mkfs.exfat", "-n", "PICOKVM", "/dev/mmcblk1p1")
|
||||
} else {
|
||||
mkfsCmd = exec.Command("mkfs.vfat", "-F", "32", "-n", "PICOKVM", "/dev/mmcblk1p1")
|
||||
}
|
||||
mkfsOut, mkfsErr := mkfsCmd.CombinedOutput()
|
||||
if mkfsErr != nil {
|
||||
return fmt.Errorf("failed to format sdcard: %w: %s", mkfsErr, strings.TrimSpace(string(mkfsOut)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user