diff options
author | Eric Wong <normalperson@yhbt.net> | 2012-01-19 13:35:59 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2012-01-19 13:38:35 -0800 |
commit | 71c9a33c481346d974c2ea33d646d0c117a7b20c (patch) | |
tree | 903bd2fda0db9cba823faa99598d87e37cb142c4 | |
parent | 63459a67db01fb58e35ec21667cfdaff594be216 (diff) | |
download | cmogstored-71c9a33c481346d974c2ea33d646d0c117a7b20c.tar.gz |
This gives necessary flexibility in choosing open(2) flags (for Content-Range: uploads) without further complicating things.
-rw-r--r-- | cmogstored.h | 4 | ||||
-rw-r--r-- | dev.c | 2 | ||||
-rw-r--r-- | file.c | 4 | ||||
-rw-r--r-- | fs.c | 20 | ||||
-rw-r--r-- | http_put.c | 2 |
5 files changed, 16 insertions, 16 deletions
diff --git a/cmogstored.h b/cmogstored.h index ee6d318..6e2903e 100644 --- a/cmogstored.h +++ b/cmogstored.h @@ -274,7 +274,7 @@ enum mog_write_state mog_tryflush(int fd, struct mog_wbuf **); extern int (*mog_stat)(struct mog_svc *, const char *path, struct stat *sb); extern int (*mog_unlink)(struct mog_svc *, const char *path); extern int (*mog_open_read)(struct mog_svc *, const char *path); -extern int (*mog_open_excl)(struct mog_svc *, const char *path); +extern int (*mog_open_put)(struct mog_svc *, const char *path, int flags); extern int (*mog_rename)(struct mog_svc *, const char *old, const char *new); extern int (*mog_mkdir)(struct mog_svc *, const char *path, mode_t mode); void mog_cloexec_broken(void); @@ -359,7 +359,7 @@ void mog_intr_enable(void); /* file.c */ struct mog_fd * mog_file_open_read(struct mog_svc *, char *path); -struct mog_fd * mog_file_open_excl(struct mog_svc *, char *path); +struct mog_fd * mog_file_open_put(struct mog_svc *, char *path, int flags); int mog_file_fstat(struct mog_fd *, struct stat *); void mog_file_close(struct mog_fd *); @@ -78,7 +78,7 @@ int mog_dev_mkusage(const struct mog_dev *dev, struct mog_svc *svc) if (mog_unlink(svc, tmp_path) < 0 && errno != ENOENT) goto out; errno = 0; - fd = mog_open_excl(svc, tmp_path); + fd = mog_open_put(svc, tmp_path, O_EXCL|O_CREAT); if (fd < 0) goto out; if (fstatvfs(fd, &v) < 0) goto out; if (emit_usage(dev, svc, fd, &v) < 0) goto out; @@ -32,11 +32,11 @@ mog_file_open_read(struct mog_svc *svc, char *path) /* path must be a free()-able pointer */ struct mog_fd * -mog_file_open_excl(struct mog_svc *svc, char *path) +mog_file_open_put(struct mog_svc *svc, char *path, int flags) { struct mog_fd *mfd; struct mog_file *mfile; - int fd = mog_open_excl(svc, path); + int fd = mog_open_put(svc, path, flags); if (fd < 0) return NULL; @@ -22,15 +22,15 @@ */ #ifdef O_CLOEXEC static int noatime_flags = O_RDONLY | O_NOATIME | O_CLOEXEC; -static int excl_flags = O_RDWR | O_EXCL | O_CREAT | O_CLOEXEC; +static int put_flags = O_RDWR | O_CLOEXEC; void mog_cloexec_broken(void) { noatime_flags = O_RDONLY | O_NOATIME; - excl_flags = O_RDWR | O_EXCL | O_CREAT; + put_flags = O_RDWR; } #else /* O_CLOEXEC */ static int noatime_flags = O_RDONLY | O_NOATIME; -static const int excl_flags = O_RDWR | O_EXCL | O_CREAT; +static const int put_flags = O_RDWR; void mog_cloexec_broken(void) { /* already a given :P */ } #endif /* O_CLOEXEC */ @@ -67,13 +67,13 @@ static int mog_openpath_read(struct mog_svc *svc, const char *path) return fd; } -static int mog_openpath_excl(struct mog_svc *svc, const char *path) +static int mog_openpath_put(struct mog_svc *svc, const char *path, int flags) { int fd; char fspath[MY_PATHMAX]; GET_FSPATH(fspath, path); - fd = open(fspath, excl_flags, 0666); + fd = open(fspath, flags | put_flags, 0666); return fd; } @@ -107,18 +107,18 @@ static int mog_openat_read(struct mog_svc *svc, const char *path) return rc; } -static int mog_openat_excl(struct mog_svc *svc, const char *path) +static int mog_openat_put(struct mog_svc *svc, const char *path, int flags) { - int rc = openat(svc->dirfd, path + 1, excl_flags, 0666); + int rc = openat(svc->dirfd, path + 1, flags | put_flags, 0666); if (rc < 0 && errno == ENOSYS) - return mog_openpath_excl(svc, path); + return mog_openpath_put(svc, path, flags); return rc; } #else # define mog_openat_read mog_openpath_read -# define mog_openat_excl mog_openpath_excl +# define mog_openat_put mog_openpath_put #endif static int mog_unlinkpath(struct mog_svc *svc, const char *path) @@ -185,7 +185,7 @@ static int mog_mkdirat(struct mog_svc *svc, const char *path, mode_t mode) int (*mog_stat)(struct mog_svc *, const char *, struct stat *) = mog_statat; int (*mog_open_read)(struct mog_svc *, const char *) = mog_openat_read; -int (*mog_open_excl)(struct mog_svc *, const char *) = mog_openat_excl; +int (*mog_open_put)(struct mog_svc *, const char *, int) = mog_openat_put; int (*mog_unlink)(struct mog_svc *, const char *) = mog_unlinkat; int (*mog_rename)(struct mog_svc *, const char *, const char *) = mog_renameat; int (*mog_mkdir)(struct mog_svc *, const char *, mode_t) = mog_mkdirat; @@ -51,7 +51,7 @@ void mog_http_put(struct mog_http *http, char *buf, size_t buf_len) assert(http->forward == NULL && "already have http->forward"); assert(path[0] == '/' && "bad path"); - http->forward = mog_file_open_excl(http->svc, path); + http->forward = mog_file_open_put(http->svc, path, O_EXCL|O_CREAT); if (http->forward == NULL) goto err; if (buf_len == http->offset) return; |