Add raw device write param

This commit is contained in:
dschmenk 2013-09-10 14:51:40 -07:00
parent 7bd16d07b3
commit 0910f55817
2 changed files with 43 additions and 32 deletions

View File

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
/usr/local/bin/fusea2pi $1 $2 -o uid=`id -u` -o gid=`id -g` /usr/local/bin/fusea2pi $1 -o uid=`id -u` -o gid=`id -g` $2

View File

@ -7,7 +7,8 @@
#include <pthread.h> #include <pthread.h>
#include <errno.h> #include <errno.h>
#include <sys/time.h> #include <sys/time.h>
#define FALSE 0
#define TRUE (!FALSE)
/* /*
* ProDOS Commands. * ProDOS Commands.
*/ */
@ -113,6 +114,10 @@ static unsigned int volblks[16];
pthread_mutex_t a2pi_busy = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t a2pi_busy = PTHREAD_MUTEX_INITIALIZER;
#define A2PI_WAIT pthread_mutex_lock(&a2pi_busy) #define A2PI_WAIT pthread_mutex_lock(&a2pi_busy)
#define A2PI_RELEASE pthread_mutex_unlock(&a2pi_busy) #define A2PI_RELEASE pthread_mutex_unlock(&a2pi_busy)
/*
* Raw device write flag.
*/
int raw_dev_write = FALSE;
/* /*
* Filename & date/time conversion routines. * Filename & date/time conversion routines.
*/ */
@ -211,12 +216,12 @@ struct stat *unix_stat(struct stat *stbuf, int storage, int access, int blocks,
memset(stbuf, 0, sizeof(struct stat)); memset(stbuf, 0, sizeof(struct stat));
if (storage == 0x0F || storage == 0x0D) if (storage == 0x0F || storage == 0x0D)
{ {
stbuf->st_mode = (access & 0xC3 == 0xC3) ? S_IFDIR | 0744 : S_IFDIR | 0544; stbuf->st_mode = (access & 0xC3) == 0xC3 ? S_IFDIR | 0744 : S_IFDIR | 0544;
stbuf->st_nlink = 2; stbuf->st_nlink = 2;
} }
else else
{ {
stbuf->st_mode = (access & 0xC3 == 0xC3) ? S_IFREG | 0644 : S_IFREG | 0444; stbuf->st_mode = (access & 0xC3) == 0xC3 ? S_IFREG | 0644 : S_IFREG | 0444;
stbuf->st_nlink = 1; stbuf->st_nlink = 1;
stbuf->st_blocks = blocks; stbuf->st_blocks = blocks;
stbuf->st_size = size; stbuf->st_size = size;
@ -766,7 +771,7 @@ static int cache_get_file_info(const char *path, int *access, int *type, int *au
drive = (path[4] - '1') & 0x01; drive = (path[4] - '1') & 0x01;
*storage = 0x100; *storage = 0x100;
*type = 0x00; *type = 0x00;
*access = 0xC3; *access = raw_dev_write ? 0xC3 : 0x01;
*aux = 0; *aux = 0;
*numblks = volblks[slot | (drive << 3)]; *numblks = volblks[slot | (drive << 3)];
*size = *numblks*512; *size = *numblks*512;
@ -981,7 +986,7 @@ static int a2pi_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
strcpy(filename, "s0d0.po"); strcpy(filename, "s0d0.po");
filename[1] = slot + '0'; filename[1] = slot + '0';
filename[3] = drive + '1'; filename[3] = drive + '1';
straw.st_mode = S_IFREG | 0644; straw.st_mode = raw_dev_write ? S_IFREG | 0644 : S_IFREG | 0444;
straw.st_nlink = 1; straw.st_nlink = 1;
straw.st_blocks = volblks[i]; straw.st_blocks = volblks[i];
straw.st_size = straw.st_blocks * 512; straw.st_size = straw.st_blocks * 512;
@ -1191,36 +1196,37 @@ static int a2pi_write(const char *path, const char *buf, size_t size, off_t offs
cachepath[0] = '\0'; cachepath[0] = '\0';
if (IS_ROOT_DIR(path)) if (IS_ROOT_DIR(path))
{ {
#if 0 if (raw_dev_write)
if (IS_RAW_DEV(strlen(path), path))
{ {
slot = (path[2] - '0') & 0x07; if (IS_RAW_DEV(strlen(path), path))
drive = (path[4] - '1') & 0x01;
unit = (slot << 4) | (drive << 7);
devsize = volblks[slot | (drive << 3)] * 512;
if (offset > devsize)
return 0;
if ((offset + size) > devsize)
size = devsize - offset;
if (offset & 0x01FF)
return 0; /* force block aligned writes */
if (size & 0x01FF)
return 0; /* force block sized writes */
blkcnt = size >> 9;
iblk = offset >> 9;
while (blkcnt--)
{ {
if ((refnum = prodos_write_block(unit, buf, iblk)) < 0) slot = (path[2] - '0') & 0x07;
return prodos_map_errno(refnum); drive = (path[4] - '1') & 0x01;
buf += 512; unit = (slot << 4) | (drive << 7);
iblk++; devsize = volblks[slot | (drive << 3)] * 512;
if (offset > devsize)
return 0;
if ((offset + size) > devsize)
size = devsize - offset;
if (offset & 0x01FF)
return 0; /* force block aligned writes */
if (size & 0x01FF)
return 0; /* force block sized writes */
blkcnt = size >> 9;
iblk = offset >> 9;
while (blkcnt--)
{
if ((refnum = prodos_write_block(unit, buf, iblk)) < 0)
return prodos_map_errno(refnum);
buf += 512;
iblk++;
}
return size;
} }
return size; return -ENOENT;
} }
return -ENOENT; else
#else return -EACCES;
return -EACCES;
#endif
} }
if ((refnum = prodos_open(prodos_path(path, NULL, NULL, NULL), &io_buff)) > 0) if ((refnum = prodos_open(prodos_path(path, NULL, NULL, NULL), &io_buff)) > 0)
{ {
@ -1353,6 +1359,11 @@ int main(int argc, char *argv[])
volblks[0x06] = 280; volblks[0x06] = 280;
if (volblks[0x0E] == 0) if (volblks[0x0E] == 0)
volblks[0x0E] = 280; volblks[0x0E] = 280;
if (strcmp(argv[argc - 1], "+rw") == 0)
{
raw_dev_write = TRUE;
argc--;
}
umask(0); umask(0);
return fuse_main(argc, argv, &a2pi_oper, NULL); return fuse_main(argc, argv, &a2pi_oper, NULL);
} }